Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled FIRRTL output format; minor refactoring, config and codestyle fixes #40

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ The list of arguments for `hls`-mode is presented below:
* `--config <PATH>`: *required* filesystem-path option; used to specify the file for a JSON latency configuration file. Its format is presented in *JSON Configuration* section.
* `--out-sv <PATH>`: *optional* filesystem-path option; used to specify the output SystemVerilog file.
* `--out-dfcir <PATH>`: *optional* filesystem-path option; used to specify the output DFCIR file.
* `--out-firrtl <PATH>`: *optional* filesystem-path option; used to specify the output FIRRTL file.
* `-a` or `-l`: *required* flag; used to specify the chosen scheduling strategy - either as-soon-as-possible or linear programming. **Exactly one of these flags has to be specified**.

**At least one of the `out-*` options has to be specified.**
Expand Down
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"config" : "",
"asap_scheduler" : false,
"lp_scheduler" : false,
"sv_out" : ""
"out_sv" : "",
"out_dfcir" : "",
"out_firrtl" : ""
}
}
2 changes: 1 addition & 1 deletion src/model/dfcir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ project(DFCIR LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
# TODO: Figure out how to pass Tablegen includes the other way.
# Issue #15 (https://github.com/ispras/utopia-hls/issues/15).
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
add_subdirectory(include)
add_subdirectory(lib)
1 change: 1 addition & 0 deletions src/model/dfcxx/include/dfcxx/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum Scheduler {
enum class OutputFormatID : uint8_t {
SystemVerilog = 0,
DFCIR,
FIRRTL,
// Utility value. Constains the number of elements in the enum.
COUNT
};
Expand Down
2 changes: 1 addition & 1 deletion src/model/dfcxx/includeDev/dfcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_subdirectory(IRbuilders)
add_subdirectory(IRbuilders)
12 changes: 12 additions & 0 deletions src/model/dfcxx/lib/dfcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ add_subdirectory(typebuilders)
add_subdirectory(vars)
add_subdirectory(varbuilders)

## By default LLVM, MLIR and DFCIR are compiled without RTTI, but not DFCxx.
## So using core Pass functionality from MLIR in converter.cpp causes
## linker-level errors ("undefined reference to `typeinfo for mlir::Pass'").
## The following lines explicitly disable RTTI for DFCxx.
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
set(DISABLE_RTTI_FLAG "/GR-")
else()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

set(DISABLE_RTTI_FLAG "-fno-rtti")
endif()
add_definitions(${DISABLE_RTTI_FLAG})

set(SOURCES
kernel.cpp
${IR_BUILDERS_SOURCES}
Expand Down Expand Up @@ -36,6 +47,7 @@ target_include_directories(DFCXX

## MLIRDFCIR is ensured to be compiled beforehand.
target_link_libraries(DFCXX
PRIVATE $<LINK_ONLY:MLIRPass>
PRIVATE $<LINK_ONLY:Utopia::MLIRDFCIR>
PRIVATE $<LINK_ONLY:CIRCTHW>
PRIVATE $<LINK_ONLY:CIRCTSV>
Expand Down
3 changes: 2 additions & 1 deletion src/model/dfcxx/lib/dfcxx/IRbuilders/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "dfcxx/IRbuilders/builder.h"

#include "circt/Dialect/FIRRTL/FIRRTLDialect.h"
#include "circt/Dialect/SV/SVDialect.h"
#include "dfcxx/IRbuilders/builder.h"
#include "mlir/Parser/Parser.h"

namespace dfcxx {
Expand Down
31 changes: 31 additions & 0 deletions src/model/dfcxx/lib/dfcxx/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,36 @@
#include "dfcxx/converter.h"

#include "circt/Conversion/Passes.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"

#include <memory>

namespace dfcxx {

class DFCIRDumperPass: public mlir::PassWrapper<DFCIRDumperPass, mlir::OperationPass<mlir::ModuleOp>> {
private:
llvm::raw_fd_ostream *stream;

public:
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DFCIRDumperPass)

DFCIRDumperPass() = default;

DFCIRDumperPass(llvm::raw_fd_ostream *stream) : DFCIRDumperPass() {
this->stream = stream;
}

void runOnOperation() override {
return getOperation()->print(*stream);
}

};

std::unique_ptr<mlir::Pass> createDFCIRDumperPass(llvm::raw_fd_ostream *stream) {
return std::make_unique<DFCIRDumperPass>(stream);
}

DFCIRConverter::DFCIRConverter(const DFLatencyConfig &config) {
this->config = LatencyConfig();
for (auto [op, latency]: config) {
Expand Down Expand Up @@ -42,6 +68,11 @@ bool DFCIRConverter::convertAndPrint(mlir::ModuleOp module,
break;
}

// Dump FIRRTL if the corresponding option is specified.
if (auto *stream = outputStreams[OUT_FORMAT_ID_INT(FIRRTL)]) {
pm.addPass(createDFCIRDumperPass(stream));
}

// Add FIRRTL->SystemVerilog passes if SystemVerilog output option is specified.
if (auto *stream = outputStreams[OUT_FORMAT_ID_INT(SystemVerilog)]) {
pm.addPass(circt::createLowerFIRRTLToHWPass());
Expand Down
6 changes: 6 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define LP_SCHEDULER_JSON "lp_scheduler"
#define OUT_SV_JSON "out_sv"
#define OUT_DFCIR_JSON "out_dfcir"
#define OUT_FIRRTL_JSON "out_firrtl"

//===----------------------------------------------------------------------===//
// CLI args/flags definitions
Expand All @@ -49,6 +50,7 @@
#define OUTPUT_GROUP "output"
#define OUT_SV_ARG CLI_ARG("out-sv")
#define OUT_DFCIR_ARG CLI_ARG("out-dfcir")
#define OUT_FIRRTL_ARG CLI_ARG("out-firrtl")

//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -185,6 +187,9 @@ struct HlsOptions final : public AppOptions {
outputGroup->add_option(OUT_DFCIR_ARG,
outNames[OUT_FORMAT_ID_INT(DFCIR)],
"Path to output unscheduled DFCIR");
outputGroup->add_option(OUT_FIRRTL_ARG,
outNames[OUT_FORMAT_ID_INT(FIRRTL)],
"Path to output scheduled FIRRTL");
outputGroup->require_option();
}

Expand All @@ -194,6 +199,7 @@ struct HlsOptions final : public AppOptions {
get(json, LP_SCHEDULER_JSON, lpScheduler);
get(json, OUT_SV_JSON, outNames[OUT_FORMAT_ID_INT(SystemVerilog)]);
get(json, OUT_DFCIR_JSON, outNames[OUT_FORMAT_ID_INT(DFCIR)]);
get(json, OUT_FIRRTL_JSON, outNames[OUT_FORMAT_ID_INT(FIRRTL)]);
}

std::string latConfigFile;
Expand Down
1 change: 1 addition & 0 deletions test/model/dfcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ set(DFCXX_TESTS
model/dfcxx/addconst.cpp
model/dfcxx/movingsum.cpp
model/dfcxx/idct.cpp
model/dfcxx/output_formats.cpp
PARENT_SCOPE
)
6 changes: 3 additions & 3 deletions test/model/dfcxx/addconst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, AddConstAddInt2Asap) {
AddConst kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2}
{dfcxx::ADD_INT, 2}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, AddConstAddInt2Linear) {
AddConst kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2}
{dfcxx::ADD_INT, 2}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}
}
12 changes: 6 additions & 6 deletions test/model/dfcxx/idct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, IdctAsap) {
IDCT kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 1},
{dfcxx::MUL_INT, 3},
{dfcxx::SUB_INT, 1}
{dfcxx::ADD_INT, 1},
{dfcxx::MUL_INT, 3},
{dfcxx::SUB_INT, 1}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}
Expand All @@ -28,9 +28,9 @@ TEST(DFCxx, IdctAsap) {
// TEST(DFCxx, IdctLinear) {
// IDCT kernel;
// DFLatencyConfig config = {
// {dfcxx::ADD_INT, 1},
// {dfcxx::MUL_INT, 3},
// {dfcxx::SUB_INT, 1}
// {dfcxx::ADD_INT, 1},
// {dfcxx::MUL_INT, 3},
// {dfcxx::SUB_INT, 1}
// };
// EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
// }
10 changes: 5 additions & 5 deletions test/model/dfcxx/matrixmul2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, MatrixMul2AddInt2MulInt3Asap) {
MatrixMul2 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3},
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3},
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, MatrixMul2AddInt2MulInt3Linear) {
MatrixMul2 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 2},
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 2},
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}
}
10 changes: 5 additions & 5 deletions test/model/dfcxx/movingsum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, MovingSumAddInt2Asap) {
MovingSum kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2}
{dfcxx::ADD_INT, 2}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, MovingSumAddInt2Linear) {
MovingSum kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2}
{dfcxx::ADD_INT, 2}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}

TEST(DFCxx, MovingSumAddInt8Asap) {
MovingSum kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 8}
{dfcxx::ADD_INT, 8}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, MovingSumAddInt8Linear) {
MovingSum kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 8}
{dfcxx::ADD_INT, 8}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}
}
8 changes: 4 additions & 4 deletions test/model/dfcxx/muxmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, MuxMulAddInt2MulInt3Asap) {
MuxMul kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, MuxMulAddInt2MulInt3Linear) {
MuxMul kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}
24 changes: 24 additions & 0 deletions test/model/dfcxx/output_formats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// Part of the Utopia HLS Project, under the Apache License v2.0
// SPDX-License-Identifier: Apache-2.0
// Copyright 2021-2024 ISP RAS (http://www.ispras.ru)
//
//===----------------------------------------------------------------------===//

#include "polynomial2/polynomial2.h"

#include "gtest/gtest.h"

static const Polynomial2 kernel;

static const DFLatencyConfig config =
{{dfcxx::ADD_INT, 2}, {dfcxx::MUL_INT, 3}};

TEST(DFCxxOutputFormats, FIRRTL) {
Polynomial2 kernel;
DFOutputPaths paths = {
{dfcxx::OutputFormatID::FIRRTL, NULLDEVICE}
};
EXPECT_EQ(kernel.compile(config, paths, dfcxx::ASAP), true);
}
16 changes: 8 additions & 8 deletions test/model/dfcxx/polynomial2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, Polynomial2AddInt2MulInt3Asap) {
Polynomial2 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, Polynomial2AddInt2MulInt3Linear) {
Polynomial2 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}

TEST(DFCxx, Polynomial2AddInt8MulInt15Asap) {
Polynomial2 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 8},
{dfcxx::MUL_INT, 15}
{dfcxx::ADD_INT, 8},
{dfcxx::MUL_INT, 15}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, Polynomial2AddInt8MulInt15Linear) {
Polynomial2 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 8},
{dfcxx::MUL_INT, 15}
{dfcxx::ADD_INT, 8},
{dfcxx::MUL_INT, 15}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}
8 changes: 4 additions & 4 deletions test/model/dfcxx/scalar3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ static const DFOutputPaths nullDevicePath =
TEST(DFCxx, Scalar3AddInt2MulInt3Asap) {
Scalar3 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::ASAP), true);
}

TEST(DFCxx, Scalar3AddInt2MulInt3Linear) {
Scalar3 kernel;
DFLatencyConfig config = {
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
{dfcxx::ADD_INT, 2},
{dfcxx::MUL_INT, 3}
};
EXPECT_EQ(kernel.compile(config, nullDevicePath, dfcxx::Linear), true);
}