From ff01b175d08961f4936e57aa047ebf324d66ab18 Mon Sep 17 00:00:00 2001 From: AnirudhK Date: Mon, 15 Jun 2026 01:47:23 -0400 Subject: [PATCH 1/7] Apply peterc changes to polygesit for HLS pragma handling --- tools/cgeist/Lib/pragmaHandlerHLS.cc | 54 +++++++++++++++++++ tools/cgeist/Lib/pragmaHandlerHLS.h | 51 ++++++++++++++++++ .../Test/HLS/AccessMemberArrayPartition.cpp | 43 +++++++++++++++ tools/cgeist/Test/HLS/Allocation.cpp | 23 ++++++++ tools/cgeist/Test/HLS/BasicArrayPartition.cpp | 12 +++++ tools/cgeist/Test/HLS/BindOp.cpp | 11 ++++ tools/cgeist/Test/HLS/BindStorage.cpp | 23 ++++++++ tools/cgeist/Test/HLS/Pipeline.cpp | 12 +++++ tools/cgeist/Test/HLS/Unroll.cpp | 13 +++++ tools/cgeist/driver.cc | 8 +++ 10 files changed, 250 insertions(+) create mode 100644 tools/cgeist/Lib/pragmaHandlerHLS.cc create mode 100644 tools/cgeist/Lib/pragmaHandlerHLS.h create mode 100644 tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp create mode 100644 tools/cgeist/Test/HLS/Allocation.cpp create mode 100644 tools/cgeist/Test/HLS/BasicArrayPartition.cpp create mode 100644 tools/cgeist/Test/HLS/BindOp.cpp create mode 100644 tools/cgeist/Test/HLS/BindStorage.cpp create mode 100644 tools/cgeist/Test/HLS/Pipeline.cpp create mode 100644 tools/cgeist/Test/HLS/Unroll.cpp diff --git a/tools/cgeist/Lib/pragmaHandlerHLS.cc b/tools/cgeist/Lib/pragmaHandlerHLS.cc new file mode 100644 index 000000000000..f7cd1f624906 --- /dev/null +++ b/tools/cgeist/Lib/pragmaHandlerHLS.cc @@ -0,0 +1,54 @@ +#include "pragmaHandlerHLS.h" +#include "clang/Frontend/ASTConsumers.h" +#include "clang/Frontend/MultiplexConsumer.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "mlir/IR/Builders.h" + +using namespace clang; + +std::vector g_HLSMetadata; + +PragmaHLSHandler::PragmaHLSHandler(std::vector &Metadata) + : PragmaHandler("HLS"), HLSMetaData(Metadata) {} + +void PragmaHLSHandler::HandlePragma(Preprocessor &PP, + PragmaIntroducer Introducer, + Token &PragmaTok) { + SourceManager &SM = PP.getSourceManager(); + Token Tok{}; + PP.Lex(Tok); + + if (Tok.isNot(tok::identifier)) return; + HLSPragmaMetaData P; + P.Name = StringRef(PP.getSpelling(Tok)).lower(); + P.Loc = Tok.getLocation(); + P.OffsetLoc = SM.getSpellingLineNumber(P.Loc); // ← add this line + PP.Lex(Tok); + + if (Tok.is(tok::eod)) { + HLSMetaData.push_back(P); + return; + } + + SourceLocation Start = Tok.getLocation(); + SourceLocation End = Start; + while (PP.Lex(Tok), Tok.isNot(tok::eod)) + End = Tok.getEndLoc(); + + // Extract raw text from source + bool Invalid = false; + const char *StartPtr = SM.getCharacterData(Start, &Invalid); + const char *EndPtr = SM.getCharacterData(End, &Invalid); + + if (!Invalid && StartPtr && EndPtr && EndPtr > StartPtr) { + StringRef RawPragma(StartPtr, EndPtr - StartPtr); + P.Args = RawPragma.str(); + } + llvm::outs() << "[HLS] pragma name: " << P.Name << " pragma args: " + << P.Args << "\n"; + HLSMetaData.push_back(P); +} + +void addPragmaHLSHandlers(Preprocessor &PP) { + PP.AddPragmaHandler(new PragmaHLSHandler(g_HLSMetadata)); +} \ No newline at end of file diff --git a/tools/cgeist/Lib/pragmaHandlerHLS.h b/tools/cgeist/Lib/pragmaHandlerHLS.h new file mode 100644 index 000000000000..6f979e213da2 --- /dev/null +++ b/tools/cgeist/Lib/pragmaHandlerHLS.h @@ -0,0 +1,51 @@ +#ifndef MLIR_TOOLS_MLIRCLANG_LIB_PRAGMAHANDLERHLS_H +#define MLIR_TOOLS_MLIRCLANG_LIB_PRAGMAHANDLERHLS_H + +#include "clang/Frontend/FrontendAction.h" +#include "clang/Lex/Pragma.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "mlir/IR/Operation.h" +#include +#include + +enum HLSPragmaType { + ArrayPartition, + ArrayReshape, + BindStorage, + BindOp, + Allocation, + Unroll, + Pipeline + }; + +/// Holds metadata parsed from #pragma HLS +struct HLSPragmaMetaData { + std::string Name; // e.g., "pipeline" + std::string Args; // e.g., "II=1" + clang::SourceLocation Loc; + mlir::Operation *Op = nullptr; + unsigned OffsetLoc = 0; +}; + +/// Handles the transition from Preprocessor (#pragma) to AST metadata +class PragmaHLSHandler : public clang::PragmaHandler { +public: + PragmaHLSHandler(std::vector &Metadata); + + void HandlePragma(clang::Preprocessor &PP, + clang::PragmaIntroducer Introducer, + clang::Token &PragmaTok) override; +private: + std::vector &HLSMetaData; +}; + +void addPragmaHLSHandlers(clang::Preprocessor &PP); + +// Global storage for HLS pragma metadata collected during parse. +// Populated by PragmaHLSHandler::HandlePragma, consumed in driver.cc +// after the MLIR pass pipeline runs. +extern std::vector g_HLSMetadata; + + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp b/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp new file mode 100644 index 000000000000..94b0c5dedd52 --- /dev/null +++ b/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp @@ -0,0 +1,43 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +struct C { + int A[8]; + int B[4]; +}; + +struct S { + int A[8]; + int B[4]; + C c; +}; + +int top(int input1[8], int input2[4]) { + S s; +#pragma HLS array_partition variable=s.A complete +#pragma HLS array_partition variable=s.c.A complete +#pragma HLS array_partition variable=s.B block factor=2 + for (int i = 0; i < 8; i++) { + s.A[i] = input1[i]; + s.c.A[i] = 2 * input1[i]; + } + for (int i = 0; i < 4; i++) { + s.B[i] = input2[i]; + s.c.B[i] = 2 * input2[i]; + } + + for (int i = 0; i < 8; i++) { + s.A[i] = s.A[i] + 1; + s.c.A[i] = s.c.A[i] + 1; + } + int sum = 0; + for (int i = 0; i < 8; i++) { + sum += s.A[i]; + sum += s.c.A[i]; + } + + return sum; + +} + +// CHECK: %alloca = memref.alloca() {hls.array_partition = [{kind = "complete", variable = "s.A"}, {kind = "complete", variable = "s.c.A"}, {factor = 2 : i32, kind = "block", variable = "s.B"}], polygeist.varname = "s"} + diff --git a/tools/cgeist/Test/HLS/Allocation.cpp b/tools/cgeist/Test/HLS/Allocation.cpp new file mode 100644 index 000000000000..7bea626fad52 --- /dev/null +++ b/tools/cgeist/Test/HLS/Allocation.cpp @@ -0,0 +1,23 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +template +DT foo(DT a, DT b) { + return a + b; +} + +// ------------------------------------------------------------ +// Top-level function that calls foo and foo +// ------------------------------------------------------------ +void top(int *out_int, float *out_float, int a, int b, float x, float y) { + +#pragma HLS ALLOCATION function instances=foo limit=1 +#pragma HLS ALLOCATION function instances=foo limit=1 + + int r1 = foo(a, b); + float r2 = foo(x, y); + + *out_int = r1; + *out_float = r2; +} + +// CHECK: hls.allocation = [{instances = "foo", limit = 1 : i32, type = "function"}, {instances = "foo", limit = 1 : i32, type = "function"} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/BasicArrayPartition.cpp b/tools/cgeist/Test/HLS/BasicArrayPartition.cpp new file mode 100644 index 000000000000..b2d2c446da37 --- /dev/null +++ b/tools/cgeist/Test/HLS/BasicArrayPartition.cpp @@ -0,0 +1,12 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +void basic_array_partition() { + int arr[8]; +#pragma HLS array_partition variable=arr complete + // Simple computation to test parallel access + for(int i = 0; i < 8; i++) { + arr[i] += 1; + } +} + +// CHECK: %alloca = memref.alloca() {hls.array_partition = [{kind = "complete", variable = "arr"}], polygeist.varname = "arr"} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/BindOp.cpp b/tools/cgeist/Test/HLS/BindOp.cpp new file mode 100644 index 000000000000..ac47fc746e35 --- /dev/null +++ b/tools/cgeist/Test/HLS/BindOp.cpp @@ -0,0 +1,11 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +int foo (int a, int b) { + int c, d; +#pragma HLS BIND_OP variable=c op=mul impl=fabric latency=2 + c = a*b; + d = a*c; + return d; +} + +// CHECK: {hls.bind_op = [{impl = "fabric", latency = 2 : i32, op = "mul"}], polygeist.ssa_names = ["c"]} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/BindStorage.cpp b/tools/cgeist/Test/HLS/BindStorage.cpp new file mode 100644 index 000000000000..bcec9b5b1bfe --- /dev/null +++ b/tools/cgeist/Test/HLS/BindStorage.cpp @@ -0,0 +1,23 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +void mac_top(int input[64], int &result) { +#pragma HLS bind_storage variable=weights type=ram_1p impl=bram +#pragma HLS bind_storage variable=bias type=ram_1p impl=lutram +#pragma HLS bind_storage variable=output type=ram_2p impl=uram latency=3 + int weights[64]; + int bias[16]; + int output[16]; + + for (int i = 0; i < 16; i++) { + output[i] = bias[i]; + for (int j = 0; j < 4; j++) + output[i] += input[i*4+j] * weights[i*4+j]; + } + for (int i = 0; i < 64; i++) { + result += output[i]; + } +} + +// CHECK: %alloca = memref.alloca() {hls.bind_storage = [{impl = "uram", latency = 3 : i32, type = "ram_2p", variable = "output"}], polygeist.varname = "output"} : memref<16xi32> +// CHECK: %alloca_0 = memref.alloca() {hls.bind_storage = [{impl = "lutram", type = "ram_1p", variable = "bias"}], polygeist.varname = "bias"} : memref<16xi32> +// CHECK: %alloca_1 = memref.alloca() {hls.bind_storage = [{impl = "bram", type = "ram_1p", variable = "weights"}], polygeist.varname = "weights"} : memref<64xi32> diff --git a/tools/cgeist/Test/HLS/Pipeline.cpp b/tools/cgeist/Test/HLS/Pipeline.cpp new file mode 100644 index 000000000000..c7d2e99619c2 --- /dev/null +++ b/tools/cgeist/Test/HLS/Pipeline.cpp @@ -0,0 +1,12 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + + +void my_kernel(int j) { + j = 0; + for(int i = 0; i < 10; ++i) { + #pragma HLS pipeline II=1 + j += 1; + } +} + +// CHECK: hls.pipeline = [{II = 1 : i32, rewind = false, style = "stp"}] \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/Unroll.cpp b/tools/cgeist/Test/HLS/Unroll.cpp new file mode 100644 index 000000000000..785ec1138e57 --- /dev/null +++ b/tools/cgeist/Test/HLS/Unroll.cpp @@ -0,0 +1,13 @@ +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +void fir_filter(int x[16], int h[8], int y[16]) { + for (int i = 0; i < 16; i++) { +#pragma HLS unroll + int acc = 0; + for (int j = 0; j < 8; j++) + acc += x[i-j] * h[j]; + y[i] = acc; + } +} + +// CHECK: {hls.unroll = [{factor = 0 : i32, skip_exit_check = false}]} \ No newline at end of file diff --git a/tools/cgeist/driver.cc b/tools/cgeist/driver.cc index b49eecdcfec5..812ed11cb08c 100644 --- a/tools/cgeist/driver.cc +++ b/tools/cgeist/driver.cc @@ -458,6 +458,9 @@ int emitBinary(char *Argv0, const char *filename, } #include "Lib/clang-mlir.cc" +#include "Lib/HandleHLS.h" +#include "Lib/PragmaHanderHLS.h" +#include "Lib/utils.h" int main(int argc, char **argv) { if (argc >= 1) { @@ -961,6 +964,11 @@ int main(int argc, char **argv) { } while (changed); }); + if (HLSAnnotate) { + ResolveScope(module.get(), g_HLSMetadata); + AttachMetadata(g_HLSMetadata); + } + if (EmitLLVM || !EmitAssembly || EmitOpenMPIR || EmitLLVMDialect) { mlir::PassManager pm2(&context); enablePrinting(pm2); From 857598a1adc6dce2645121ca635c2d2efd8a2487 Mon Sep 17 00:00:00 2001 From: AnirudhK Date: Mon, 15 Jun 2026 21:27:59 -0400 Subject: [PATCH 2/7] Additional changes to build polygeist --- tools/cgeist/CMakeLists.txt | 2 ++ tools/cgeist/Lib/clang-mlir.cc | 3 +++ tools/cgeist/Lib/clang-mlir.h | 5 +++++ tools/cgeist/Lib/utils.h | 2 ++ tools/cgeist/driver.cc | 2 +- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/cgeist/CMakeLists.txt b/tools/cgeist/CMakeLists.txt index 84b4a739e9df..fdcfad45f222 100644 --- a/tools/cgeist/CMakeLists.txt +++ b/tools/cgeist/CMakeLists.txt @@ -24,6 +24,8 @@ add_clang_executable(cgeist "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1as_main.cpp" "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1gen_reproducer_main.cpp" Lib/pragmaHandler.cc + Lib/pragmaHandlerHLS.cc + Lib/HandleHLS.cc Lib/AffineUtils.cc Lib/ValueCategory.cc Lib/utils.cc diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index b944cbda2e04..8a694f2df874 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -60,6 +60,9 @@ static cl::opt memRefABI("memref-abi", cl::init(true), cl::opt PrefixABI("prefix-abi", cl::init(""), cl::desc("Prefix for emitted symbols")); +cl::opt HLSAnnotate("hls-annotate", cl::init(false), + cl::desc("annotate hls pragmas")); + cl::opt CStyleMemRef("c-style-memref", cl::init(true), cl::desc("Use c style memrefs when possible")); diff --git a/tools/cgeist/Lib/clang-mlir.h b/tools/cgeist/Lib/clang-mlir.h index 117bcf162557..ccc4029ef60a 100644 --- a/tools/cgeist/Lib/clang-mlir.h +++ b/tools/cgeist/Lib/clang-mlir.h @@ -26,6 +26,8 @@ #include "mlir/Target/LLVMIR/TypeToLLVM.h" #include "polygeist/Ops.h" #include "pragmaHandler.h" +#include "pragmaHandlerHLS.h" +#include "HandleHLS.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/StmtVisitor.h" #include "clang/Lex/HeaderSearch.h" @@ -44,6 +46,8 @@ using namespace mlir; extern llvm::cl::opt PrefixABI; +extern llvm::cl::opt HLSAnnotate; + struct LoopContext { mlir::Value keepRunning; mlir::Value noBreak; @@ -96,6 +100,7 @@ struct MLIRASTConsumer : public ASTConsumer { addPragmaScopHandlers(PP, scopLocList); addPragmaEndScopHandlers(PP, scopLocList); addPragmaLowerToHandlers(PP, LTInfo); + addPragmaHLSHandlers(PP); } ~MLIRASTConsumer() {} diff --git a/tools/cgeist/Lib/utils.h b/tools/cgeist/Lib/utils.h index f80132c0b65e..e8af3dc420ce 100644 --- a/tools/cgeist/Lib/utils.h +++ b/tools/cgeist/Lib/utils.h @@ -12,6 +12,8 @@ #include "mlir/IR/Builders.h" #include "llvm/ADT/ArrayRef.h" +inline bool g_HLSpragmaAnnotate = false; + namespace mlir { class Operation; namespace func { diff --git a/tools/cgeist/driver.cc b/tools/cgeist/driver.cc index 812ed11cb08c..abd10d4c0107 100644 --- a/tools/cgeist/driver.cc +++ b/tools/cgeist/driver.cc @@ -459,7 +459,7 @@ int emitBinary(char *Argv0, const char *filename, #include "Lib/clang-mlir.cc" #include "Lib/HandleHLS.h" -#include "Lib/PragmaHanderHLS.h" +#include "Lib/pragmaHandlerHLS.h" #include "Lib/utils.h" int main(int argc, char **argv) { From 2af9f0aaa263a631773e5d5cb52e862c1dba5d12 Mon Sep 17 00:00:00 2001 From: AnirudhK Date: Mon, 15 Jun 2026 21:50:25 -0400 Subject: [PATCH 3/7] Add missing handle HLS files --- tools/cgeist/Lib/HandleHLS.cc | 541 ++++++++++++++++++++++++++++++++++ tools/cgeist/Lib/HandleHLS.h | 9 + 2 files changed, 550 insertions(+) create mode 100644 tools/cgeist/Lib/HandleHLS.cc create mode 100644 tools/cgeist/Lib/HandleHLS.h diff --git a/tools/cgeist/Lib/HandleHLS.cc b/tools/cgeist/Lib/HandleHLS.cc new file mode 100644 index 000000000000..a77ba7d0e1f2 --- /dev/null +++ b/tools/cgeist/Lib/HandleHLS.cc @@ -0,0 +1,541 @@ +#include "clang/Frontend/ASTConsumers.h" +#include "clang/Frontend/MultiplexConsumer.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/BuiltinAttributes.h" +#include "mlir/IR/Location.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringExtras.h" // for SplitString +#include "pragmaHandlerHLS.h" +#include "HandleHLS.h" + +using mlir::memref::AllocaOp; +using namespace llvm; + +unsigned getSourceInfo(mlir::Location loc) { + // 1. Base Case: Standard File/Line/Column + if (auto fileLoc = llvm::dyn_cast(loc)) { + return fileLoc.getLine(); + } + if (auto fusedLoc = llvm::dyn_cast(loc)) { + auto locations = fusedLoc.getLocations(); + if(locations.size() > 0) { + return getSourceInfo(locations[0]); + } + return 0; + } + // 3. Recursive Case: CallSite Locations (If inlining has occurred) + if (auto callLoc = llvm::dyn_cast(loc)) { + return getSourceInfo(callLoc.getCaller()); + } + // 4. Case: Name Location (e.g., loc("myVar"(...) ) + if (auto nameLoc = llvm::dyn_cast(loc)) { + return getSourceInfo(nameLoc.getChildLoc()); + } + return 0; +} + +void ResolveScope(mlir::ModuleOp MlirModule, + std::vector &HLSMetadata) { + + struct ScopeInfo { + mlir::Operation *Op; + unsigned StartLine; + unsigned EndLine; + }; + + std::vector Scopes; + + // --- Phase 1: Collect all scope ops and their line ranges --- + MlirModule.walk([&](mlir::Operation *Op) { + + if (llvm::isa(Op)) { + llvm::outs() << "[scope] op=" << Op->getName().getStringRef(); + } + + if (mlir::isa(Op)) + return; + + // Only ops that define a new scope (have regions) + if (Op->getNumRegions() == 0) + return; + + + + unsigned StartLine = getSourceInfo(Op->getLoc()); + if (StartLine == 0) + return; + // End line = max line of any nested op in this scope + unsigned EndLine = StartLine; + Op->walk([&](mlir::Operation *Nested) { + if (Nested == Op) + return; + unsigned Line = getSourceInfo(Nested->getLoc()); + if (Line > EndLine) + EndLine = Line; + }); + Scopes.push_back({Op, StartLine, EndLine}); + llvm::outs() << "[scope] op=" << Op->getName().getStringRef() + << " start=" << StartLine << " end=" << EndLine << "\n"; + }); + + + // --- Phase 1.5: Widen each func.func's StartLine to cover the gap from + // the previous function's end. This lets pragmas that appear above the + // first emitted op (between '{' and the first statement) — and pragmas + // between functions — attach to the function that follows them. + // Other scope ops (loops) keep their original tight range, so the + // innermost-loop preference still works. + std::vector Funcs; + for (auto &S : Scopes) + if (llvm::isa(S.Op)) + Funcs.push_back(&S); + + llvm::sort(Funcs, [](ScopeInfo *a, ScopeInfo *b) { + return a->EndLine < b->EndLine; + }); + + unsigned PrevEnd = 0; + for (auto *F : Funcs) { + F->StartLine = PrevEnd + 1; + PrevEnd = F->EndLine; + } + + // --- Phase 2: Match each pragma to its innermost containing scope --- + for (HLSPragmaMetaData &Meta : HLSMetadata) { + mlir::Operation *InnermostOp = nullptr; + unsigned InnermostSpan = UINT_MAX; + + for (auto &Scope : Scopes) { + // Pragma must fall within the scope's line range + if (Meta.OffsetLoc < Scope.StartLine || Meta.OffsetLoc > Scope.EndLine) + continue; + + // Prefer the tightest (innermost) enclosing scope + unsigned Span = Scope.EndLine - Scope.StartLine; + // After --raise-scf-to-affine, loops are affine.for; before that, scf.for/while. + bool CurrIsLoop = llvm::isa(Scope.Op); + bool BestIsLoop = InnermostOp && + llvm::isa(InnermostOp); + + if (Span < InnermostSpan || (CurrIsLoop && !BestIsLoop && Span == InnermostSpan)) { + InnermostSpan = Span; + InnermostOp = Scope.Op; + } + } + + if (InnermostOp) { + Meta.Op = InnermostOp; + llvm::outs() << "[HLS] pragma '" << Meta.Name + << "' at line " << Meta.OffsetLoc + << " attached to '" << InnermostOp->getName().getStringRef() + << "' (scope span " << InnermostSpan << " lines)"; + + if (auto SymAttr = InnermostOp->getAttrOfType( + mlir::SymbolTable::getSymbolAttrName())) + + llvm::outs() << " ['" << SymAttr.getValue() << "']"; + llvm::outs() << "\n"; + } else { + Meta.Op = nullptr; + llvm::outs() << "[HLS] Warning: pragma '" << Meta.Name + << "' at line " << Meta.OffsetLoc + << " could not be resolved to any scope\n"; + } + } +} + +// Helper: parse a key=value arg list into a StringMap +void ParseArgs(ArrayRef Args, + llvm::StringMap &KV, + SmallVectorImpl &Flags) { + for (StringRef Arg : Args) { + if (Arg.contains('=')) { + auto [Key, Val] = Arg.split('='); + KV[Key] = Val; + } else { + Flags.push_back(Arg); // bare keywords like "complete", "rewind", "skip_exit_check" + } + } +} + +// Helper: find a memref.alloca by base variable name inside a scope op. +// memref.alloca has no name attribute; we recover the variable name from +// either (a) a NameLoc on the op's location, or (b) a "polygeist.varname" +// string attribute attached at scan time. Either source works; the second +// is the fallback if locations have been rewritten by passes. +AllocaOp FindAlloca(mlir::Operation *ScopeOp, StringRef BaseName) { + AllocaOp Found; + ScopeOp->walk([&](AllocaOp Alloca) { + // (a) try NameLoc on the alloca's location + if (auto NL = llvm::dyn_cast(Alloca.getLoc())) { + if (NL.getName().getValue() == BaseName) { + Found = Alloca; + return; + } + } + // (b) try a polygeist.varname attribute + if (auto NameAttr = + Alloca->getAttrOfType("polygeist.varname")) { + if (NameAttr.getValue() == BaseName) { + Found = Alloca; + return; + } + } + }); + return Found; +} + + +mlir::Operation *FindOpByName(mlir::Operation *ScopeOp, llvm::StringRef Name) { + mlir::Operation *Found = nullptr; + ScopeOp->walk([&](mlir::Operation *Op) { + if (auto names = Op->getAttrOfType("polygeist.ssa_names")) { + for (auto attr : names) { + if (auto sa = llvm::dyn_cast(attr)) { + if (sa.getValue() == Name) { + Found = Op; + return mlir::WalkResult::interrupt(); + } + } + } + } + return mlir::WalkResult::advance(); + }); + return Found; +} + +// Helper: append a DictionaryAttr entry to an ArrayAttr on an op +void AppendAttrEntry(mlir::Operation *Op, StringRef AttrName, + mlir::DictionaryAttr Entry) { + mlir::Builder B(Op->getContext()); + SmallVector Entries; + if (auto Existing = Op->getAttrOfType(AttrName)) + Entries.append(Existing.begin(), Existing.end()); + Entries.push_back(Entry); + Op->setAttr(AttrName, B.getArrayAttr(Entries)); +} + +// Helper: parse integer from StringRef, returns -1 on failure +int ParseInt(StringRef S) { + int Val = -1; + S.getAsInteger(10, Val); + return Val; +} + +// ── array_partition ──────────────────────────────────────────────────────── +void HandleArrayPartition(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + StringRef VarPath = KV.lookup("variable"); + if (VarPath.empty()) { + llvm::outs() << "[HLS] Warning: array_partition missing variable=\n"; + return; + } + + StringRef Base = VarPath.split('.').first; + AllocaOp AttachOp = FindAlloca(Meta.Op, Base); + if (!AttachOp) { + llvm::outs() << "[HLS] Warning: array_partition could not find alloca '" + << Base << "'\n"; + return; + } + + mlir::Builder B(AttachOp.getContext()); + SmallVector Fields; + Fields.push_back(B.getNamedAttr("variable", B.getStringAttr(VarPath))); + + // kind: explicit key or bare flag (complete/block/cyclic), default complete + StringRef Kind = KV.count("type") ? KV["type"] : StringRef("complete"); + for (StringRef F : Flags) + if (F == "complete" || F == "block" || F == "cyclic") { Kind = F; break; } + Fields.push_back(B.getNamedAttr("kind", B.getStringAttr(Kind))); + + if (KV.count("factor")) + Fields.push_back(B.getNamedAttr("factor", + B.getI32IntegerAttr(ParseInt(KV["factor"])))); + if (KV.count("dim")) + Fields.push_back(B.getNamedAttr("dim", + B.getI32IntegerAttr(ParseInt(KV["dim"])))); + + AppendAttrEntry(AttachOp, "hls.array_partition", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached array_partition {variable=" << VarPath + << ", kind=" << Kind << "} to '" << Base << "'\n"; +} + +// ── array_reshape ────────────────────────────────────────────────────────── +// Same args as array_partition; semantics differ (word-width widening vs split) +void HandleArrayReshape(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + StringRef VarPath = KV.lookup("variable"); + if (VarPath.empty()) { + llvm::outs() << "[HLS] Warning: array_reshape missing variable=\n"; + return; + } + + StringRef Base = VarPath.split('.').first; + AllocaOp AttachOp = FindAlloca(Meta.Op, Base); + if (!AttachOp) { + llvm::outs() << "[HLS] Warning: array_reshape could not find alloca '" + << Base << "'\n"; + return; + } + + mlir::Builder B(AttachOp.getContext()); + SmallVector Fields; + Fields.push_back(B.getNamedAttr("variable", B.getStringAttr(VarPath))); + + StringRef Kind = KV.count("type") ? KV["type"] : StringRef("complete"); + for (StringRef F : Flags) + if (F == "complete" || F == "block" || F == "cyclic") { Kind = F; break; } + Fields.push_back(B.getNamedAttr("kind", B.getStringAttr(Kind))); + + if (KV.count("factor")) + Fields.push_back(B.getNamedAttr("factor", + B.getI32IntegerAttr(ParseInt(KV["factor"])))); + if (KV.count("dim")) + Fields.push_back(B.getNamedAttr("dim", + B.getI32IntegerAttr(ParseInt(KV["dim"])))); + + AppendAttrEntry(AttachOp, "hls.array_reshape", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached array_reshape {variable=" << VarPath + << ", kind=" << Kind << "} to '" << Base << "'\n"; +} + +// ── bind_storage ─────────────────────────────────────────────────────────── +// #pragma HLS bind_storage variable= type= +// impl= latency= +void HandleBindStorage(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + StringRef VarPath = KV.lookup("variable"); + if (VarPath.empty()) { + llvm::outs() << "[HLS] Warning: bind_storage missing variable=\n"; + return; + } + + StringRef Base = VarPath.split('.').first; + AllocaOp AttachOp = FindAlloca(Meta.Op, Base); + if (!AttachOp) { + llvm::outs() << "[HLS] Warning: bind_storage could not find alloca '" + << Base << "'\n"; + return; + } + + mlir::Builder B(AttachOp.getContext()); + SmallVector Fields; + Fields.push_back(B.getNamedAttr("variable", B.getStringAttr(VarPath))); + + if (KV.count("type")) + Fields.push_back(B.getNamedAttr("type", B.getStringAttr(KV["type"]))); + if (KV.count("impl")) + Fields.push_back(B.getNamedAttr("impl", B.getStringAttr(KV["impl"]))); + if (KV.count("latency")) + Fields.push_back(B.getNamedAttr("latency", + B.getI32IntegerAttr(ParseInt(KV["latency"])))); + + AppendAttrEntry(AttachOp, "hls.bind_storage", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached bind_storage {variable=" << VarPath << "} to '" + << Base << "'\n"; +} + +// ── bind_op ──────────────────────────────────────────────────────────────── +// #pragma HLS bind_op variable= op= +// impl= latency= +void HandleBindOp(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + StringRef VarPath = KV.lookup("variable"); + if (VarPath.empty()) { + llvm::outs() << "[HLS] Warning: bind_op missing variable=\n"; + return; + } + + StringRef Base = VarPath.split('.').first; + mlir::Operation *AttachOp = FindOpByName(Meta.Op, Base); + + if (!AttachOp) { + llvm::outs() << "[HLS] Warning: bind_op could not find producer for '" + << Base << "'\n"; + return; + } + + // Optionally: filter by op type matching the pragma's op= field + if (KV.count("op")) { + StringRef Want = KV["op"]; + bool ok = false; + if (Want == "mul") + ok = llvm::isa(AttachOp); + else if (Want == "add") + ok = llvm::isa(AttachOp); + // ... etc + if (!ok) { + llvm::outs() << "[HLS] Warning: bind_op variable=" << Base + << " op=" << Want << " but producer is " + << AttachOp->getName().getStringRef() << "\n"; + return; + } + } + + mlir::Builder B(AttachOp->getContext()); + SmallVector Fields; + if (KV.count("op")) Fields.push_back(B.getNamedAttr("op", B.getStringAttr(KV["op"]))); + if (KV.count("impl")) Fields.push_back(B.getNamedAttr("impl", B.getStringAttr(KV["impl"]))); + if (KV.count("latency")) Fields.push_back(B.getNamedAttr("latency", B.getI32IntegerAttr(ParseInt(KV["latency"])))); + + AppendAttrEntry(AttachOp, "hls.bind_op", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached bind_op {variable=" << VarPath << "} to '" + << Base << "'\n"; +} + +// ── allocation ───────────────────────────────────────────────────────────── +// #pragma HLS allocation instances= limit= type= +// No variable — attaches to the enclosing function/scope op directly +void HandleAllocation(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + if (!KV.count("instances") || !KV.count("limit")) { + llvm::outs() << "[HLS] Warning: allocation missing instances= or limit=\n"; + return; + } + + mlir::Builder B(Meta.Op->getContext()); + SmallVector Fields; + Fields.push_back(B.getNamedAttr("instances", + B.getStringAttr(KV["instances"]))); + Fields.push_back(B.getNamedAttr("limit", + B.getI32IntegerAttr(ParseInt(KV["limit"])))); + + // type= defaults to "function" + StringRef AllocType = KV.count("type") ? KV["type"] : StringRef("function"); + Fields.push_back(B.getNamedAttr("type", B.getStringAttr(AllocType))); + + AppendAttrEntry(Meta.Op, "hls.allocation", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached allocation {instances=" << KV["instances"] + << ", limit=" << KV["limit"] << "} to scope op\n"; +} + +// ── unroll ───────────────────────────────────────────────────────────────── +// #pragma HLS unroll [factor=] [skip_exit_check] +// No variable — attaches to the enclosing loop/scope op +void HandleUnroll(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + mlir::Builder B(Meta.Op->getContext()); + SmallVector Fields; + + // factor= absent means full unroll + if (KV.count("factor")) + Fields.push_back(B.getNamedAttr("factor", + B.getI32IntegerAttr(ParseInt(KV["factor"])))); + else + Fields.push_back(B.getNamedAttr("factor", B.getI32IntegerAttr(0))); // 0 = full + + bool SkipExitCheck = llvm::is_contained(Flags, StringRef("skip_exit_check")); + Fields.push_back(B.getNamedAttr("skip_exit_check", + B.getBoolAttr(SkipExitCheck))); + + // Attach directly to the scope op (loop body) + AppendAttrEntry(Meta.Op, "hls.unroll", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached unroll {factor=" + << (KV.count("factor") ? KV["factor"] : StringRef("full")) + << ", skip_exit_check=" << SkipExitCheck << "} to scope op\n"; +} + +// ── pipeline ─────────────────────────────────────────────────────────────── +// #pragma HLS pipeline [II=] [rewind] [style=stp|flp|frp] +// No variable — attaches to the enclosing function/loop scope op +void HandlePipeline(HLSPragmaMetaData &Meta) { + SmallVector Args; + SplitString(Meta.Args, Args); + + llvm::StringMap KV; + SmallVector Flags; + ParseArgs(Args, KV, Flags); + + mlir::Builder B(Meta.Op->getContext()); + SmallVector Fields; + + // II=0 means "let tool decide minimum" + int II = KV.count("II") ? ParseInt(KV["II"]) : 0; + Fields.push_back(B.getNamedAttr("II", B.getI32IntegerAttr(II))); + + bool Rewind = llvm::is_contained(Flags, StringRef("rewind")); + Fields.push_back(B.getNamedAttr("rewind", B.getBoolAttr(Rewind))); + + // style: stp (stall), flp (flushable), frp (free-running), default stp + StringRef Style = KV.count("style") ? KV["style"] : StringRef("stp"); + Fields.push_back(B.getNamedAttr("style", B.getStringAttr(Style))); + + // Attach directly to the scope op (function or loop) + AppendAttrEntry(Meta.Op, "hls.pipeline", B.getDictionaryAttr(Fields)); + llvm::outs() << "[HLS] Attached pipeline {II=" << II + << ", rewind=" << Rewind << ", style=" << Style + << "} to scope op\n"; +} + + + +void AttachMetadata(std::vector &HLSMetadata) { + for (HLSPragmaMetaData &Meta : HLSMetadata) { + llvm::outs() << "Arguments: " << Meta.Args << "\n"; + if (!Meta.Op) { + llvm::outs() << "[HLS] Warning: pragma '" << Meta.Name + << "' has no resolved scope, skipping\n"; + continue; + } + if (Meta.Name == "array_partition") HandleArrayPartition(Meta); + else if (Meta.Name == "array_reshape") HandleArrayReshape(Meta); + else if (Meta.Name == "bind_storage") HandleBindStorage(Meta); + else if (Meta.Name == "bind_op") HandleBindOp(Meta); + else if (Meta.Name == "allocation") HandleAllocation(Meta); + else if (Meta.Name == "unroll") HandleUnroll(Meta); + else if (Meta.Name == "pipeline") HandlePipeline(Meta); + } +} + diff --git a/tools/cgeist/Lib/HandleHLS.h b/tools/cgeist/Lib/HandleHLS.h new file mode 100644 index 000000000000..02f53a126473 --- /dev/null +++ b/tools/cgeist/Lib/HandleHLS.h @@ -0,0 +1,9 @@ +#include "clang/Frontend/ASTConsumers.h" +#include "clang/Frontend/MultiplexConsumer.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "mlir/IR/Builders.h" + +void ResolveScope(mlir::ModuleOp MlirModule, + std::vector &HLSMetadata); + +void AttachMetadata(std::vector &HLSMetadata); From 7dea8a72e76289d7a85a97e29d95d57480db5059 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Sat, 20 Jun 2026 03:35:43 -0400 Subject: [PATCH 4/7] fix lit test --- tools/cgeist/Lib/clang-mlir.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index 8a694f2df874..ef1a18fc43f7 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -584,6 +584,20 @@ mlir::Value MLIRScanner::createAllocOp(mlir::Type t, VarDecl *name, } assert(params.find(name) == params.end()); params[name] = ValueCategory(alloc, /*isReference*/ true); + + // Tag the underlying memref.alloca / llvm.alloca with the C variable name + // so HLS pragma resolution can find it later by name. + mlir::Operation *defining = alloc.getDefiningOp(); + while (auto castOp = + llvm::dyn_cast_or_null(defining)) { + defining = castOp.getSource().getDefiningOp(); + } + if (defining && (llvm::isa(defining) || + llvm::isa(defining))) { + defining->setAttr( + "polygeist.varname", + mlir::StringAttr::get(builder.getContext(), name->getName())); + } } return alloc; } From 7c34950790c1bee72f6275000fa1c015564205f8 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Sat, 20 Jun 2026 03:54:07 -0400 Subject: [PATCH 5/7] fix lit test (#4) --- tools/cgeist/Lib/clang-mlir.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index 8a694f2df874..ef1a18fc43f7 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -584,6 +584,20 @@ mlir::Value MLIRScanner::createAllocOp(mlir::Type t, VarDecl *name, } assert(params.find(name) == params.end()); params[name] = ValueCategory(alloc, /*isReference*/ true); + + // Tag the underlying memref.alloca / llvm.alloca with the C variable name + // so HLS pragma resolution can find it later by name. + mlir::Operation *defining = alloc.getDefiningOp(); + while (auto castOp = + llvm::dyn_cast_or_null(defining)) { + defining = castOp.getSource().getDefiningOp(); + } + if (defining && (llvm::isa(defining) || + llvm::isa(defining))) { + defining->setAttr( + "polygeist.varname", + mlir::StringAttr::get(builder.getContext(), name->getName())); + } } return alloc; } From 67edd40a7103e67dd533e5c278ccd76e7d646409 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Wed, 24 Jun 2026 03:43:14 -0400 Subject: [PATCH 6/7] second patch for clang-mlir --- tools/cgeist/Lib/clang-mlir.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index ef1a18fc43f7..bf63bba663f7 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -592,7 +592,7 @@ mlir::Value MLIRScanner::createAllocOp(mlir::Type t, VarDecl *name, llvm::dyn_cast_or_null(defining)) { defining = castOp.getSource().getDefiningOp(); } - if (defining && (llvm::isa(defining) || + if (HLSAnnotate && defining && (llvm::isa(defining) || llvm::isa(defining))) { defining->setAttr( "polygeist.varname", @@ -3036,6 +3036,20 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } } } + if (HLSAnnotate) { + if (auto DRE = dyn_cast(BO->getLHS()->IgnoreParenCasts())) { + if (auto VD = dyn_cast(DRE->getDecl())) { + if (auto *defOp = tostore.getDefiningOp()) { + SmallVector existing; + if (auto arr = defOp->getAttrOfType("polygeist.ssa_names")) + existing.append(arr.begin(), arr.end()); + existing.push_back(builder.getStringAttr(VD->getName())); + defOp->setAttr("polygeist.ssa_names", + builder.getArrayAttr(existing)); + } + } + } + } lhs.store(loc, builder, tostore); return lhs; } From c9233d389481854b19500687e2eb95232a4037e0 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Wed, 4 Nov 2026 05:02:59 -0500 Subject: [PATCH 7/7] Add Vitis HLS pragma extraction to cgeist, rebased onto upstream main. --- README.md | 4 +- debug.sh | 9 + docs/hls-pragmas.md | 603 + docs/xlx-real-headers.md | 61 + durbin_ref | Bin 0 -> 16992 bytes include/polygeist/Passes/Passes.h | 52 + lib/polygeist/Ops.cpp | 235 +- lib/polygeist/Passes/AffineCFG.cpp | 1359 +- lib/polygeist/Passes/AffineScalRep.cpp | 652 + lib/polygeist/Passes/CMakeLists.txt | 1 + lib/polygeist/Passes/CanonicalizeFor.cpp | 1080 +- .../Passes/ConvertPolygeistToLLVM.cpp | 16 + lib/polygeist/Passes/LoopRestructure.cpp | 19 +- lib/polygeist/Passes/ParallelLICM.cpp | 64 +- .../Passes/PolygeistCanonicalize.cpp | 62 + lib/polygeist/Passes/RaiseToAffine.cpp | 90 +- patches/llvm-project/0001-xlx-bitwidth.patch | 382 + patches/llvm-project/README.md | 45 + test/CMakeLists.txt | 1 + test/lit.cfg.py | 2 +- tools/cgeist/CMakeLists.txt | 210 +- tools/cgeist/Lib/CGCall.cc | 314 +- tools/cgeist/Lib/CGStmt.cc | 152 +- tools/cgeist/Lib/CGXlxBuiltin.cc | 519 + tools/cgeist/Lib/HLSAutoInline.cc | 1382 + tools/cgeist/Lib/HLSAutoInline.h | 108 + tools/cgeist/Lib/HLSPragma.cc | 1050 + tools/cgeist/Lib/HLSPragma.h | 160 + tools/cgeist/Lib/HLSPragmaInternal.h | 273 + tools/cgeist/Lib/HLSPragmaMaterialize.cc | 193 + tools/cgeist/Lib/HLSPragmaParse.cc | 518 + tools/cgeist/Lib/HLSPragmaSema.cc | 2477 ++ tools/cgeist/Lib/HLSPragmaSpec.cc | 285 + tools/cgeist/Lib/HandleHLS.cc | 541 - tools/cgeist/Lib/HandleHLS.h | 9 - tools/cgeist/Lib/ValueCategory.cc | 11 + tools/cgeist/Lib/XlxDeadStore.cc | 176 + tools/cgeist/Lib/XlxLoopScalarPromote.cc | 461 + tools/cgeist/Lib/XlxMathCore.cc | 138 + tools/cgeist/Lib/XlxMathCore.h | 58 + tools/cgeist/Lib/XlxProxyScalarize.cc | 669 + tools/cgeist/Lib/XlxStringBits.cc | 667 + tools/cgeist/Lib/XlxStringBits.h | 84 + tools/cgeist/Lib/clang-mlir.cc | 2528 +- tools/cgeist/Lib/clang-mlir.h | 107 +- tools/cgeist/Lib/pragmaHandlerHLS.cc | 54 - tools/cgeist/Lib/pragmaHandlerHLS.h | 51 - tools/cgeist/Lib/utils.h | 2 - .../Test/HLS/AccessMemberArrayPartition.cpp | 86 +- tools/cgeist/Test/HLS/Allocation.cpp | 46 +- tools/cgeist/Test/HLS/BasicArrayPartition.cpp | 24 +- tools/cgeist/Test/HLS/BindOp.cpp | 24 +- tools/cgeist/Test/HLS/BindStorage.cpp | 46 +- tools/cgeist/Test/HLS/HLSAllocation.cpp | 305 + tools/cgeist/Test/HLS/Inputs/vitis/README.md | 38 + .../Test/HLS/Inputs/vitis/ap_axi_sdata.h | 38 + tools/cgeist/Test/HLS/Inputs/vitis/ap_cint.h | 26 + tools/cgeist/Test/HLS/Inputs/vitis/ap_fixed.h | 520 + tools/cgeist/Test/HLS/Inputs/vitis/ap_int.h | 527 + .../cgeist/Test/HLS/Inputs/vitis/cgeist_flags | 5 + tools/cgeist/Test/HLS/Inputs/vitis/hls_half.h | 6 + tools/cgeist/Test/HLS/Inputs/vitis/hls_math.h | 418 + .../cgeist/Test/HLS/Inputs/vitis/hls_stream.h | 31 + .../cgeist/Test/HLS/Inputs/vitis/hls_vector.h | 44 + tools/cgeist/Test/HLS/Pipeline.cpp | 27 +- tools/cgeist/Test/HLS/Unroll.cpp | 24 +- tools/cgeist/Test/HLS/aggregate/aggregate.c | 69 + tools/cgeist/Test/HLS/aggregate/propagate.cpp | 81 + tools/cgeist/Test/HLS/alias/alias.c | 43 + .../cgeist/Test/HLS/allocation/allocation.cpp | 48 + .../cgeist/Test/HLS/array_partition/errors.c | 58 + .../inline-carry-partition.cpp | 131 + .../Test/HLS/array_partition/lowering.c | 43 + .../cgeist/Test/HLS/array_partition/options.c | 107 + .../Test/HLS/array_partition/variables.c | 131 + .../Test/HLS/array_reshape/array_reshape.c | 67 + tools/cgeist/Test/HLS/bind_op/bind_op.c | 79 + .../Test/HLS/bind_storage/bind_storage.c | 70 + .../Test/HLS/bind_storage/resource_core.c | 40 + tools/cgeist/Test/HLS/cache/cache.c | 30 + .../cgeist/Test/HLS/consumer/contract-shape.c | 50 + .../Test/HLS/consumer/hls-est-banking.c | 37 + .../Test/HLS/consumer/hls-est-pipeline.c | 62 + tools/cgeist/Test/HLS/dataflow/dataflow.c | 58 + tools/cgeist/Test/HLS/dependence/dependence.c | 81 + .../expression_balance/expression_balance.c | 43 + .../function_instantiate.c | 33 + .../Autoencoder__opt1/src/Autoencoder.cpp | 562 + .../Autoencoder__opt2/src/Autoencoder.cpp | 558 + .../Autoencoder__opt3/src/Autoencoder.cpp | 650 + .../Autoencoder__opt4/src/Autoencoder.cpp | 646 + .../Autoencoder__opt5/src/Autoencoder.cpp | 738 + .../src/DepthwiseSeparableConvBlock.cpp | 134 + .../src/DepthwiseSeparableConvBlock.cpp | 189 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../FeedForward__opt1/src/FeedForward.cpp | 229 + .../FeedForward__opt2/src/FeedForward.cpp | 231 + .../FeedForward__opt3/src/FeedForward.cpp | 333 + .../FeedForward__opt4/src/FeedForward.cpp | 317 + .../FeedForward__opt5/src/FeedForward.cpp | 305 + .../src/MultiHeadSelfAttention1.cpp | 734 + .../src/MultiHeadSelfAttention1.cpp | 738 + .../src/MultiHeadSelfAttention1.cpp | 1107 + .../src/MultiHeadSelfAttention1.cpp | 1064 + .../src/MultiHeadSelfAttention1.cpp | 1086 + .../stream_hls/ResMLP__opt1/src/ResMLP.cpp | 406 + .../stream_hls/ResMLP__opt2/src/ResMLP.cpp | 405 + .../stream_hls/ResMLP__opt3/src/ResMLP.cpp | 470 + .../stream_hls/ResMLP__opt4/src/ResMLP.cpp | 469 + .../stream_hls/ResMLP__opt5/src/ResMLP.cpp | 517 + .../ResidualBlock__opt1/src/ResidualBlock.cpp | 176 + .../ResidualBlock__opt2/src/ResidualBlock.cpp | 262 + .../ResidualBlock__opt3/src/ResidualBlock.cpp | 249 + .../ResidualBlock__opt4/src/ResidualBlock.cpp | 249 + .../ResidualBlock__opt5/src/ResidualBlock.cpp | 249 + .../Autoencoder__opt1/src/Autoencoder.cpp | 562 + .../Autoencoder__opt2/src/Autoencoder.cpp | 558 + .../Autoencoder__opt3/src/Autoencoder.cpp | 650 + .../Autoencoder__opt4/src/Autoencoder.cpp | 646 + .../Autoencoder__opt5/src/Autoencoder.cpp | 738 + .../src/DepthwiseSeparableConvBlock.cpp | 134 + .../src/DepthwiseSeparableConvBlock.cpp | 189 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../FeedForward__opt1/src/FeedForward.cpp | 229 + .../FeedForward__opt2/src/FeedForward.cpp | 231 + .../FeedForward__opt3/src/FeedForward.cpp | 333 + .../FeedForward__opt4/src/FeedForward.cpp | 317 + .../FeedForward__opt5/src/FeedForward.cpp | 305 + .../src/MultiHeadSelfAttention1.cpp | 734 + .../src/MultiHeadSelfAttention1.cpp | 738 + .../src/MultiHeadSelfAttention1.cpp | 1107 + .../src/MultiHeadSelfAttention1.cpp | 1064 + .../src/MultiHeadSelfAttention1.cpp | 1086 + .../ResMLP__opt1/src/ResMLP.cpp | 406 + .../ResMLP__opt2/src/ResMLP.cpp | 405 + .../ResMLP__opt3/src/ResMLP.cpp | 470 + .../ResMLP__opt4/src/ResMLP.cpp | 469 + .../ResMLP__opt5/src/ResMLP.cpp | 517 + .../ResidualBlock__opt1/src/ResidualBlock.cpp | 176 + .../ResidualBlock__opt2/src/ResidualBlock.cpp | 262 + .../ResidualBlock__opt3/src/ResidualBlock.cpp | 249 + .../ResidualBlock__opt4/src/ResidualBlock.cpp | 249 + .../ResidualBlock__opt5/src/ResidualBlock.cpp | 249 + .../atax__opt1/src/atax.cpp | 125 + .../atax__opt2/src/atax.cpp | 126 + .../atax__opt3/src/atax.cpp | 171 + .../atax__opt4/src/atax.cpp | 163 + .../atax__opt5/src/atax.cpp | 163 + .../bicg__opt1/src/bicg.cpp | 120 + .../bicg__opt2/src/bicg.cpp | 120 + .../bicg__opt3/src/bicg.cpp | 164 + .../bicg__opt4/src/bicg.cpp | 164 + .../bicg__opt5/src/bicg.cpp | 164 + .../gemm__opt1/src/gemm.cpp | 102 + .../gemm__opt2/src/gemm.cpp | 102 + .../gemm__opt3/src/gemm.cpp | 143 + .../gemm__opt4/src/gemm.cpp | 143 + .../gemm__opt5/src/gemm.cpp | 143 + .../gesummv__opt1/src/gesummv.cpp | 128 + .../gesummv__opt2/src/gesummv.cpp | 128 + .../gesummv__opt3/src/gesummv.cpp | 166 + .../gesummv__opt4/src/gesummv.cpp | 166 + .../gesummv__opt5/src/gesummv.cpp | 166 + .../k2mm__opt1/src/k2mm.cpp | 142 + .../k2mm__opt2/src/k2mm.cpp | 142 + .../k2mm__opt3/src/k2mm.cpp | 201 + .../k2mm__opt4/src/k2mm.cpp | 201 + .../k2mm__opt5/src/k2mm.cpp | 201 + .../k3mm__opt1/src/k3mm.cpp | 154 + .../k3mm__opt2/src/k3mm.cpp | 145 + .../k3mm__opt3/src/k3mm.cpp | 226 + .../k3mm__opt4/src/k3mm.cpp | 222 + .../k3mm__opt5/src/k3mm.cpp | 222 + .../src/k7mmseq_balanced.cpp | 315 + .../src/k7mmseq_balanced.cpp | 315 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_unbalanced.cpp | 315 + .../src/k7mmseq_unbalanced.cpp | 315 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmtree_balanced.cpp | 454 + .../src/k7mmtree_unbalanced.cpp | 445 + .../mvt__opt1/src/mvt.cpp | 137 + .../mvt__opt2/src/mvt.cpp | 138 + .../mvt__opt3/src/mvt.cpp | 194 + .../mvt__opt4/src/mvt.cpp | 186 + .../mvt__opt5/src/mvt.cpp | 186 + .../WIP/stream_hls/atax__opt1/src/atax.cpp | 125 + .../WIP/stream_hls/atax__opt2/src/atax.cpp | 126 + .../WIP/stream_hls/atax__opt3/src/atax.cpp | 171 + .../WIP/stream_hls/atax__opt4/src/atax.cpp | 163 + .../WIP/stream_hls/atax__opt5/src/atax.cpp | 163 + .../WIP/stream_hls/bicg__opt1/src/bicg.cpp | 120 + .../WIP/stream_hls/bicg__opt2/src/bicg.cpp | 120 + .../WIP/stream_hls/bicg__opt3/src/bicg.cpp | 164 + .../WIP/stream_hls/bicg__opt4/src/bicg.cpp | 164 + .../WIP/stream_hls/bicg__opt5/src/bicg.cpp | 164 + .../WIP/stream_hls/gemm__opt1/src/gemm.cpp | 102 + .../WIP/stream_hls/gemm__opt2/src/gemm.cpp | 102 + .../WIP/stream_hls/gemm__opt3/src/gemm.cpp | 143 + .../WIP/stream_hls/gemm__opt4/src/gemm.cpp | 143 + .../WIP/stream_hls/gemm__opt5/src/gemm.cpp | 143 + .../stream_hls/gesummv__opt1/src/gesummv.cpp | 128 + .../stream_hls/gesummv__opt2/src/gesummv.cpp | 128 + .../stream_hls/gesummv__opt3/src/gesummv.cpp | 166 + .../stream_hls/gesummv__opt4/src/gesummv.cpp | 166 + .../stream_hls/gesummv__opt5/src/gesummv.cpp | 166 + .../k15mmseq__opt5/src/k15mmseq.cpp | 936 + .../src/k15mmseq_imbalanced.cpp | 873 + .../k15mmseq_relu__opt5/src/k15mmseq_relu.cpp | 1303 + .../src/k15mmseq_relu_imbalanced.cpp | 1226 + .../k15mmtree__opt5/src/k15mmtree.cpp | 938 + .../src/k15mmtree_imbalanced.cpp | 872 + .../src/k15mmtree_relu.cpp | 1295 + .../src/k15mmtree_relu_imbalanced.cpp | 1220 + .../WIP/stream_hls/k2mm__opt1/src/k2mm.cpp | 142 + .../WIP/stream_hls/k2mm__opt2/src/k2mm.cpp | 142 + .../WIP/stream_hls/k2mm__opt3/src/k2mm.cpp | 201 + .../WIP/stream_hls/k2mm__opt4/src/k2mm.cpp | 201 + .../WIP/stream_hls/k2mm__opt5/src/k2mm.cpp | 201 + .../WIP/stream_hls/k3mm__opt1/src/k3mm.cpp | 154 + .../WIP/stream_hls/k3mm__opt2/src/k3mm.cpp | 145 + .../WIP/stream_hls/k3mm__opt3/src/k3mm.cpp | 226 + .../WIP/stream_hls/k3mm__opt4/src/k3mm.cpp | 222 + .../WIP/stream_hls/k3mm__opt5/src/k3mm.cpp | 222 + .../src/k7mmseq_balanced.cpp | 315 + .../src/k7mmseq_balanced.cpp | 315 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_unbalanced.cpp | 315 + .../src/k7mmseq_unbalanced.cpp | 315 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmtree_balanced.cpp | 454 + .../src/k7mmtree_unbalanced.cpp | 445 + .../WIP/stream_hls/mvt__opt1/src/mvt.cpp | 137 + .../WIP/stream_hls/mvt__opt2/src/mvt.cpp | 138 + .../WIP/stream_hls/mvt__opt3/src/mvt.cpp | 194 + .../WIP/stream_hls/mvt__opt4/src/mvt.cpp | 186 + .../WIP/stream_hls/mvt__opt5/src/mvt.cpp | 186 + .../src/DGNN-booster1-EvolveGCN.cpp | 1254 + .../src/DGNN-booster2-GCRN-M2.cpp | 1372 + .../src/GP_kernel_100_10_success_fixed.cpp | 1812 ++ .../src/GP_kernel_100_10_success.cpp | 1812 ++ .../Mask-Net_dataset/src/conv1x1_new.cc | 157 + .../Mask-Net_dataset/src/dwconv3x3_new.cc | 98 + .../Mask-Net_dataset/src/dwconv5x5.cc | 59 + .../Mask-Net_dataset/src/net_hls.cc | 1807 ++ .../Mask-Net_dataset/src/net_hls.h | 185 + .../SkyNet_dataset/src/conv1x1.cc | 142 + .../SkyNet_dataset/src/dwconv3x3.cc | 61 + .../SkyNet_dataset/src/net_hls.cc | 1223 + .../accelerators/SkyNet_dataset/src/net_hls.h | 147 + .../accelerators/edgemoe/include/add.hpp | 8 + .../edgemoe/include/attention.hpp | 30 + .../accelerators/edgemoe/include/conv.hpp | 11 + .../edgemoe/include/datatypes.hpp | 18 + .../accelerators/edgemoe/include/dcl.hpp | 9 + .../accelerators/edgemoe/include/gelu.hpp | 11 + .../accelerators/edgemoe/include/hardware.hpp | 30 + .../accelerators/edgemoe/include/kernel.hpp | 46 + .../edgemoe/include/layernorm.hpp | 21 + .../accelerators/edgemoe/include/linear.hpp | 46 + .../accelerators/edgemoe/include/model.hpp | 22 + .../accelerators/edgemoe/include/moe.hpp | 21 + .../accelerators/edgemoe/include/tbutil.hpp | 89 + .../accelerators/edgemoe/include/util.hpp | 99 + .../accelerators/edgemoe/src/ViT_compute.cpp | 208 + .../Inputs/accelerators/edgemoe/src/add.cpp | 20 + .../accelerators/edgemoe/src/attention.cpp | 494 + .../Inputs/accelerators/edgemoe/src/conv.cpp | 166 + .../Inputs/accelerators/edgemoe/src/gelu.cpp | 227 + .../accelerators/edgemoe/src/layernorm.cpp | 172 + .../accelerators/edgemoe/src/linear.cpp | 530 + .../Inputs/accelerators/edgemoe/src/moe.cpp | 436 + .../hlsfactory/Inputs/auto_ntt/BU/cpp/BU.cpp | 616 + .../hlsfactory/Inputs/auto_ntt/BU/cpp/ntt.h | 91 + .../hlsfactory/Inputs/auto_ntt/BU/src/tapa.h | 20 + .../Inputs/auto_ntt/BU/src/tapa/base/buffer.h | 30 + .../Inputs/auto_ntt/BU/src/tapa/base/mmap.h | 6 + .../Inputs/auto_ntt/BU/src/tapa/base/stream.h | 20 + .../Inputs/auto_ntt/BU/src/tapa/base/tapa.h | 12 + .../Inputs/auto_ntt/BU/src/tapa/base/task.h | 37 + .../Inputs/auto_ntt/BU/src/tapa/base/util.h | 96 + .../Inputs/auto_ntt/BU/src/tapa/host/buffer.h | 486 + .../auto_ntt/BU/src/tapa/host/coroutine.h | 14 + .../auto_ntt/BU/src/tapa/host/logging.h | 7 + .../Inputs/auto_ntt/BU/src/tapa/host/mmap.h | 566 + .../Inputs/auto_ntt/BU/src/tapa/host/stream.h | 874 + .../Inputs/auto_ntt/BU/src/tapa/host/tapa.h | 82 + .../Inputs/auto_ntt/BU/src/tapa/host/task.h | 198 + .../Inputs/auto_ntt/BU/src/tapa/host/util.h | 42 + .../Inputs/auto_ntt/BU/src/tapa/host/vec.h | 336 + .../Inputs/auto_ntt/BU/src/tapa/stream.h | 14 + .../Inputs/auto_ntt/BU/src/tapa/traits.h | 32 + .../auto_ntt/BU/src/tapa/xilinx/hls/buffer.h | 93 + .../auto_ntt/BU/src/tapa/xilinx/hls/logging.h | 49 + .../auto_ntt/BU/src/tapa/xilinx/hls/mmap.h | 40 + .../auto_ntt/BU/src/tapa/xilinx/hls/stream.h | 199 + .../auto_ntt/BU/src/tapa/xilinx/hls/tapa.h | 23 + .../auto_ntt/BU/src/tapa/xilinx/hls/task.h | 58 + .../auto_ntt/BU/src/tapa/xilinx/hls/util.h | 61 + .../auto_ntt/BU/src/tapa/xilinx/hls/vec.h | 391 + .../cpp/Mmap2Stream_tf_0_1_limbs.cpp | 574 + .../Mmap2Stream_tf_0_1_limbs/cpp/ntt.h | 91 + .../Mmap2Stream_tf_0_1_limbs/src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../src/tapa/host/vec.h | 336 + .../src/tapa/stream.h | 14 + .../src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../auto_ntt/NTT_kernel/cpp/NTT_kernel.cpp | 520 + .../Inputs/auto_ntt/NTT_kernel/cpp/ntt.h | 91 + .../Inputs/auto_ntt/NTT_kernel/src/tapa.h | 20 + .../NTT_kernel/src/tapa/base/buffer.h | 30 + .../auto_ntt/NTT_kernel/src/tapa/base/mmap.h | 6 + .../NTT_kernel/src/tapa/base/stream.h | 20 + .../auto_ntt/NTT_kernel/src/tapa/base/tapa.h | 12 + .../auto_ntt/NTT_kernel/src/tapa/base/task.h | 37 + .../auto_ntt/NTT_kernel/src/tapa/base/util.h | 96 + .../NTT_kernel/src/tapa/host/buffer.h | 486 + .../NTT_kernel/src/tapa/host/coroutine.h | 14 + .../NTT_kernel/src/tapa/host/logging.h | 7 + .../auto_ntt/NTT_kernel/src/tapa/host/mmap.h | 566 + .../NTT_kernel/src/tapa/host/stream.h | 874 + .../auto_ntt/NTT_kernel/src/tapa/host/tapa.h | 82 + .../auto_ntt/NTT_kernel/src/tapa/host/task.h | 198 + .../auto_ntt/NTT_kernel/src/tapa/host/util.h | 42 + .../auto_ntt/NTT_kernel/src/tapa/host/vec.h | 336 + .../auto_ntt/NTT_kernel/src/tapa/stream.h | 14 + .../auto_ntt/NTT_kernel/src/tapa/traits.h | 32 + .../NTT_kernel/src/tapa/xilinx/hls/buffer.h | 93 + .../NTT_kernel/src/tapa/xilinx/hls/logging.h | 49 + .../NTT_kernel/src/tapa/xilinx/hls/mmap.h | 40 + .../NTT_kernel/src/tapa/xilinx/hls/stream.h | 199 + .../NTT_kernel/src/tapa/xilinx/hls/tapa.h | 23 + .../NTT_kernel/src/tapa/xilinx/hls/task.h | 58 + .../NTT_kernel/src/tapa/xilinx/hls/util.h | 61 + .../NTT_kernel/src/tapa/xilinx/hls/vec.h | 391 + .../TFBuf_wiFW_0/cpp/TFBuf_wiFW_0.cpp | 541 + .../Inputs/auto_ntt/TFBuf_wiFW_0/cpp/ntt.h | 91 + .../Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa.h | 20 + .../TFBuf_wiFW_0/src/tapa/base/buffer.h | 30 + .../TFBuf_wiFW_0/src/tapa/base/mmap.h | 6 + .../TFBuf_wiFW_0/src/tapa/base/stream.h | 20 + .../TFBuf_wiFW_0/src/tapa/base/tapa.h | 12 + .../TFBuf_wiFW_0/src/tapa/base/task.h | 37 + .../TFBuf_wiFW_0/src/tapa/base/util.h | 96 + .../TFBuf_wiFW_0/src/tapa/host/buffer.h | 486 + .../TFBuf_wiFW_0/src/tapa/host/coroutine.h | 14 + .../TFBuf_wiFW_0/src/tapa/host/logging.h | 7 + .../TFBuf_wiFW_0/src/tapa/host/mmap.h | 566 + .../TFBuf_wiFW_0/src/tapa/host/stream.h | 874 + .../TFBuf_wiFW_0/src/tapa/host/tapa.h | 82 + .../TFBuf_wiFW_0/src/tapa/host/task.h | 198 + .../TFBuf_wiFW_0/src/tapa/host/util.h | 42 + .../auto_ntt/TFBuf_wiFW_0/src/tapa/host/vec.h | 336 + .../auto_ntt/TFBuf_wiFW_0/src/tapa/stream.h | 14 + .../auto_ntt/TFBuf_wiFW_0/src/tapa/traits.h | 32 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/mmap.h | 40 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/stream.h | 199 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/tapa.h | 23 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/task.h | 58 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/util.h | 61 + .../TFBuf_wiFW_0/src/tapa/xilinx/hls/vec.h | 391 + .../TFBuf_wiFW_1/cpp/TFBuf_wiFW_1.cpp | 541 + .../Inputs/auto_ntt/TFBuf_wiFW_1/cpp/ntt.h | 91 + .../Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa.h | 20 + .../TFBuf_wiFW_1/src/tapa/base/buffer.h | 30 + .../TFBuf_wiFW_1/src/tapa/base/mmap.h | 6 + .../TFBuf_wiFW_1/src/tapa/base/stream.h | 20 + .../TFBuf_wiFW_1/src/tapa/base/tapa.h | 12 + .../TFBuf_wiFW_1/src/tapa/base/task.h | 37 + .../TFBuf_wiFW_1/src/tapa/base/util.h | 96 + .../TFBuf_wiFW_1/src/tapa/host/buffer.h | 486 + .../TFBuf_wiFW_1/src/tapa/host/coroutine.h | 14 + .../TFBuf_wiFW_1/src/tapa/host/logging.h | 7 + .../TFBuf_wiFW_1/src/tapa/host/mmap.h | 566 + .../TFBuf_wiFW_1/src/tapa/host/stream.h | 874 + .../TFBuf_wiFW_1/src/tapa/host/tapa.h | 82 + .../TFBuf_wiFW_1/src/tapa/host/task.h | 198 + .../TFBuf_wiFW_1/src/tapa/host/util.h | 42 + .../auto_ntt/TFBuf_wiFW_1/src/tapa/host/vec.h | 336 + .../auto_ntt/TFBuf_wiFW_1/src/tapa/stream.h | 14 + .../auto_ntt/TFBuf_wiFW_1/src/tapa/traits.h | 32 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/mmap.h | 40 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/stream.h | 199 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/tapa.h | 23 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/task.h | 58 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/util.h | 61 + .../TFBuf_wiFW_1/src/tapa/xilinx/hls/vec.h | 391 + .../TFBuf_wiFW_2/cpp/TFBuf_wiFW_2.cpp | 541 + .../Inputs/auto_ntt/TFBuf_wiFW_2/cpp/ntt.h | 91 + .../Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa.h | 20 + .../TFBuf_wiFW_2/src/tapa/base/buffer.h | 30 + .../TFBuf_wiFW_2/src/tapa/base/mmap.h | 6 + .../TFBuf_wiFW_2/src/tapa/base/stream.h | 20 + .../TFBuf_wiFW_2/src/tapa/base/tapa.h | 12 + .../TFBuf_wiFW_2/src/tapa/base/task.h | 37 + .../TFBuf_wiFW_2/src/tapa/base/util.h | 96 + .../TFBuf_wiFW_2/src/tapa/host/buffer.h | 486 + .../TFBuf_wiFW_2/src/tapa/host/coroutine.h | 14 + .../TFBuf_wiFW_2/src/tapa/host/logging.h | 7 + .../TFBuf_wiFW_2/src/tapa/host/mmap.h | 566 + .../TFBuf_wiFW_2/src/tapa/host/stream.h | 874 + .../TFBuf_wiFW_2/src/tapa/host/tapa.h | 82 + .../TFBuf_wiFW_2/src/tapa/host/task.h | 198 + .../TFBuf_wiFW_2/src/tapa/host/util.h | 42 + .../auto_ntt/TFBuf_wiFW_2/src/tapa/host/vec.h | 336 + .../auto_ntt/TFBuf_wiFW_2/src/tapa/stream.h | 14 + .../auto_ntt/TFBuf_wiFW_2/src/tapa/traits.h | 32 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/mmap.h | 40 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/stream.h | 199 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/tapa.h | 23 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/task.h | 58 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/util.h | 61 + .../TFBuf_wiFW_2/src/tapa/xilinx/hls/vec.h | 391 + .../TFBuf_woFW_3/cpp/TFBuf_woFW_3.cpp | 537 + .../Inputs/auto_ntt/TFBuf_woFW_3/cpp/ntt.h | 91 + .../Inputs/auto_ntt/TFBuf_woFW_3/src/tapa.h | 20 + .../TFBuf_woFW_3/src/tapa/base/buffer.h | 30 + .../TFBuf_woFW_3/src/tapa/base/mmap.h | 6 + .../TFBuf_woFW_3/src/tapa/base/stream.h | 20 + .../TFBuf_woFW_3/src/tapa/base/tapa.h | 12 + .../TFBuf_woFW_3/src/tapa/base/task.h | 37 + .../TFBuf_woFW_3/src/tapa/base/util.h | 96 + .../TFBuf_woFW_3/src/tapa/host/buffer.h | 486 + .../TFBuf_woFW_3/src/tapa/host/coroutine.h | 14 + .../TFBuf_woFW_3/src/tapa/host/logging.h | 7 + .../TFBuf_woFW_3/src/tapa/host/mmap.h | 566 + .../TFBuf_woFW_3/src/tapa/host/stream.h | 874 + .../TFBuf_woFW_3/src/tapa/host/tapa.h | 82 + .../TFBuf_woFW_3/src/tapa/host/task.h | 198 + .../TFBuf_woFW_3/src/tapa/host/util.h | 42 + .../auto_ntt/TFBuf_woFW_3/src/tapa/host/vec.h | 336 + .../auto_ntt/TFBuf_woFW_3/src/tapa/stream.h | 14 + .../auto_ntt/TFBuf_woFW_3/src/tapa/traits.h | 32 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/mmap.h | 40 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/stream.h | 199 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/tapa.h | 23 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/task.h | 58 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/util.h | 61 + .../TFBuf_woFW_3/src/tapa/xilinx/hls/vec.h | 391 + .../cpp/dual_interface_FIFO_receive.cpp | 517 + .../dual_interface_FIFO_receive/cpp/ntt.h | 91 + .../dual_interface_FIFO_receive/src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../src/tapa/host/vec.h | 336 + .../src/tapa/stream.h | 14 + .../src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../cpp/dual_interface_FIFO_send.cpp | 514 + .../dual_interface_FIFO_send/cpp/ntt.h | 91 + .../dual_interface_FIFO_send/src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../src/tapa/host/vec.h | 336 + .../src/tapa/stream.h | 14 + .../src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../cpp/fwd_load_inv_store_poly_1_limbs.cpp | 1222 + .../fwd_load_inv_store_poly_1_limbs/cpp/ntt.h | 91 + .../src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../src/tapa/host/vec.h | 336 + .../src/tapa/stream.h | 14 + .../src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../cpp/fwd_store_inv_load_poly_1_limbs.cpp | 1222 + .../fwd_store_inv_load_poly_1_limbs/cpp/ntt.h | 91 + .../src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../src/tapa/host/vec.h | 336 + .../src/tapa/stream.h | 14 + .../src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../cpp/input_selector_single.cpp | 565 + .../auto_ntt/input_selector_single/cpp/ntt.h | 91 + .../auto_ntt/input_selector_single/src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../input_selector_single/src/tapa/host/vec.h | 336 + .../input_selector_single/src/tapa/stream.h | 14 + .../input_selector_single/src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../auto_ntt/output_slector_single/cpp/ntt.h | 91 + .../cpp/output_slector_single.cpp | 566 + .../auto_ntt/output_slector_single/src/tapa.h | 20 + .../src/tapa/base/buffer.h | 30 + .../src/tapa/base/mmap.h | 6 + .../src/tapa/base/stream.h | 20 + .../src/tapa/base/tapa.h | 12 + .../src/tapa/base/task.h | 37 + .../src/tapa/base/util.h | 96 + .../src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../src/tapa/host/mmap.h | 566 + .../src/tapa/host/stream.h | 874 + .../src/tapa/host/tapa.h | 82 + .../src/tapa/host/task.h | 198 + .../src/tapa/host/util.h | 42 + .../output_slector_single/src/tapa/host/vec.h | 336 + .../output_slector_single/src/tapa/stream.h | 14 + .../output_slector_single/src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../Inputs/auto_ntt/shuffler_buf/cpp/ntt.h | 91 + .../shuffler_buf/cpp/shuffler_buf.cpp | 989 + .../Inputs/auto_ntt/shuffler_buf/src/tapa.h | 20 + .../shuffler_buf/src/tapa/base/buffer.h | 30 + .../shuffler_buf/src/tapa/base/mmap.h | 6 + .../shuffler_buf/src/tapa/base/stream.h | 20 + .../shuffler_buf/src/tapa/base/tapa.h | 12 + .../shuffler_buf/src/tapa/base/task.h | 37 + .../shuffler_buf/src/tapa/base/util.h | 96 + .../shuffler_buf/src/tapa/host/buffer.h | 486 + .../shuffler_buf/src/tapa/host/coroutine.h | 14 + .../shuffler_buf/src/tapa/host/logging.h | 7 + .../shuffler_buf/src/tapa/host/mmap.h | 566 + .../shuffler_buf/src/tapa/host/stream.h | 874 + .../shuffler_buf/src/tapa/host/tapa.h | 82 + .../shuffler_buf/src/tapa/host/task.h | 198 + .../shuffler_buf/src/tapa/host/util.h | 42 + .../auto_ntt/shuffler_buf/src/tapa/host/vec.h | 336 + .../auto_ntt/shuffler_buf/src/tapa/stream.h | 14 + .../auto_ntt/shuffler_buf/src/tapa/traits.h | 32 + .../shuffler_buf/src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../shuffler_buf/src/tapa/xilinx/hls/mmap.h | 40 + .../shuffler_buf/src/tapa/xilinx/hls/stream.h | 199 + .../shuffler_buf/src/tapa/xilinx/hls/tapa.h | 23 + .../shuffler_buf/src/tapa/xilinx/hls/task.h | 58 + .../shuffler_buf/src/tapa/xilinx/hls/util.h | 61 + .../shuffler_buf/src/tapa/xilinx/hls/vec.h | 391 + .../Inputs/auto_ntt/shuffler_in/cpp/ntt.h | 91 + .../auto_ntt/shuffler_in/cpp/shuffler_in.cpp | 872 + .../Inputs/auto_ntt/shuffler_in/src/tapa.h | 20 + .../shuffler_in/src/tapa/base/buffer.h | 30 + .../auto_ntt/shuffler_in/src/tapa/base/mmap.h | 6 + .../shuffler_in/src/tapa/base/stream.h | 20 + .../auto_ntt/shuffler_in/src/tapa/base/tapa.h | 12 + .../auto_ntt/shuffler_in/src/tapa/base/task.h | 37 + .../auto_ntt/shuffler_in/src/tapa/base/util.h | 96 + .../shuffler_in/src/tapa/host/buffer.h | 486 + .../shuffler_in/src/tapa/host/coroutine.h | 14 + .../shuffler_in/src/tapa/host/logging.h | 7 + .../auto_ntt/shuffler_in/src/tapa/host/mmap.h | 566 + .../shuffler_in/src/tapa/host/stream.h | 874 + .../auto_ntt/shuffler_in/src/tapa/host/tapa.h | 82 + .../auto_ntt/shuffler_in/src/tapa/host/task.h | 198 + .../auto_ntt/shuffler_in/src/tapa/host/util.h | 42 + .../auto_ntt/shuffler_in/src/tapa/host/vec.h | 336 + .../auto_ntt/shuffler_in/src/tapa/stream.h | 14 + .../auto_ntt/shuffler_in/src/tapa/traits.h | 32 + .../shuffler_in/src/tapa/xilinx/hls/buffer.h | 93 + .../shuffler_in/src/tapa/xilinx/hls/logging.h | 49 + .../shuffler_in/src/tapa/xilinx/hls/mmap.h | 40 + .../shuffler_in/src/tapa/xilinx/hls/stream.h | 199 + .../shuffler_in/src/tapa/xilinx/hls/tapa.h | 23 + .../shuffler_in/src/tapa/xilinx/hls/task.h | 58 + .../shuffler_in/src/tapa/xilinx/hls/util.h | 61 + .../shuffler_in/src/tapa/xilinx/hls/vec.h | 391 + .../auto_ntt/shuffler_out_shift/cpp/ntt.h | 91 + .../cpp/shuffler_out_shift.cpp | 1029 + .../auto_ntt/shuffler_out_shift/src/tapa.h | 20 + .../shuffler_out_shift/src/tapa/base/buffer.h | 30 + .../shuffler_out_shift/src/tapa/base/mmap.h | 6 + .../shuffler_out_shift/src/tapa/base/stream.h | 20 + .../shuffler_out_shift/src/tapa/base/tapa.h | 12 + .../shuffler_out_shift/src/tapa/base/task.h | 37 + .../shuffler_out_shift/src/tapa/base/util.h | 96 + .../shuffler_out_shift/src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../shuffler_out_shift/src/tapa/host/mmap.h | 566 + .../shuffler_out_shift/src/tapa/host/stream.h | 874 + .../shuffler_out_shift/src/tapa/host/tapa.h | 82 + .../shuffler_out_shift/src/tapa/host/task.h | 198 + .../shuffler_out_shift/src/tapa/host/util.h | 42 + .../shuffler_out_shift/src/tapa/host/vec.h | 336 + .../shuffler_out_shift/src/tapa/stream.h | 14 + .../shuffler_out_shift/src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../auto_ntt/shuffler_out_shuff/cpp/ntt.h | 91 + .../cpp/shuffler_out_shuff.cpp | 1123 + .../auto_ntt/shuffler_out_shuff/src/tapa.h | 20 + .../shuffler_out_shuff/src/tapa/base/buffer.h | 30 + .../shuffler_out_shuff/src/tapa/base/mmap.h | 6 + .../shuffler_out_shuff/src/tapa/base/stream.h | 20 + .../shuffler_out_shuff/src/tapa/base/tapa.h | 12 + .../shuffler_out_shuff/src/tapa/base/task.h | 37 + .../shuffler_out_shuff/src/tapa/base/util.h | 96 + .../shuffler_out_shuff/src/tapa/host/buffer.h | 486 + .../src/tapa/host/coroutine.h | 14 + .../src/tapa/host/logging.h | 7 + .../shuffler_out_shuff/src/tapa/host/mmap.h | 566 + .../shuffler_out_shuff/src/tapa/host/stream.h | 874 + .../shuffler_out_shuff/src/tapa/host/tapa.h | 82 + .../shuffler_out_shuff/src/tapa/host/task.h | 198 + .../shuffler_out_shuff/src/tapa/host/util.h | 42 + .../shuffler_out_shuff/src/tapa/host/vec.h | 336 + .../shuffler_out_shuff/src/tapa/stream.h | 14 + .../shuffler_out_shuff/src/tapa/traits.h | 32 + .../src/tapa/xilinx/hls/buffer.h | 93 + .../src/tapa/xilinx/hls/logging.h | 49 + .../src/tapa/xilinx/hls/mmap.h | 40 + .../src/tapa/xilinx/hls/stream.h | 199 + .../src/tapa/xilinx/hls/tapa.h | 23 + .../src/tapa/xilinx/hls/task.h | 58 + .../src/tapa/xilinx/hls/util.h | 61 + .../src/tapa/xilinx/hls/vec.h | 391 + .../HLS/hlsfactory/Inputs/chstone/gsm/add.c | 159 + .../HLS/hlsfactory/Inputs/chstone/gsm/lpc.c | 321 + .../hlsfactory/Inputs/chstone/gsm/private.h | 50 + .../HLS/hlsfactory/Inputs/chstone/sha/sha.c | 218 + .../HLS/hlsfactory/Inputs/chstone/sha/sha.h | 1137 + .../source_code/src/debayer.cpp | 127 + .../source_code/src/dehaze.cpp | 266 + .../source_code/src/pipeline.cpp | 58 + .../source_code/src/pipeline.h | 74 + .../source_code/src/utils.cpp | 60 + .../source_code/src/whitebalance.cpp | 113 + .../src__debayer_csynth/debayer.cpp | 127 + .../src__debayer_csynth/dehaze.cpp | 266 + .../src__debayer_csynth/pipeline.cpp | 58 + .../src__debayer_csynth/pipeline.h | 74 + .../source_code/src__debayer_csynth/utils.cpp | 60 + .../src__debayer_csynth/whitebalance.cpp | 113 + .../source_code/src__script/debayer.cpp | 127 + .../source_code/src__script/dehaze.cpp | 266 + .../source_code/src__script/pipeline.cpp | 58 + .../source_code/src__script/pipeline.h | 74 + .../source_code/src__script/utils.cpp | 60 + .../source_code/src__script/whitebalance.cpp | 113 + .../Explainable-ML/source_code/cmodel/bp.h | 150 + .../source_code/cmodel/bp_single_class.h | 139 + .../Explainable-ML/source_code/cmodel/fp.h | 160 + .../Explainable-ML/source_code/gradient.h | 95 + .../Explainable-ML/source_code/io.h | 114 + .../Explainable-ML/source_code/tiled_conv.cpp | 770 + .../Explainable-ML/source_code/utils.h | 480 + .../source_code/HLS/config.h | 2 + .../source_code/HLS/flat.cpp | 253 + .../FLAT-acceleration/source_code/HLS/flat.h | 94 + .../source_code/HLS/systolic_array.cpp | 206 + .../HLS/test_systolic_array/systolic.cpp | 199 + .../HLS/test_systolic_array/systolic.h | 23 + .../source_code/HLS/utils.cpp | 234 + .../GIN_virtualnode_compute.cpp | 617 + .../source_code/gin_vn_base_hls/dcl.hpp | 103 + .../source_code/gin_vn_base_hls/main.cpp | 100 + .../GIN_virtualnode_compute.cpp | 771 + .../source_code/gin_vn_bitstream/dcl.hpp | 109 + .../GIN_virtualnode_compute.cpp | 813 + .../source_code/gin_vn_pipelined_hls/dcl.hpp | 108 + .../source_code/gin_vn_pipelined_hls/main.cpp | 102 + .../Ray-tracing/source_code/HLS/common.cpp | 230 + .../Ray-tracing/source_code/HLS/common.h | 69 + .../Ray-tracing/source_code/HLS/config.h | 0 .../Ray-tracing/source_code/HLS/fxp_sqrt.h | 104 + .../Ray-tracing/source_code/HLS/geometry.h | 32 + .../Ray-tracing/source_code/HLS/tb_common.h | 22 + .../source_code/HLS/trianglemesh.cpp | 478 + .../source_code/HLS/trianglemesh.h | 30 + .../source_code/golden_c/common.cpp | 116 + .../Ray-tracing/source_code/golden_c/common.h | 49 + .../source_code/golden_c/geometry.h | 16 + .../source_code/golden_c/tb_common.h | 15 + .../source_code/golden_c/trianglemesh.cpp | 240 + .../source_code/golden_c/trianglemesh.h | 26 + .../source_code/src_24Layers/config.h | 0 .../source_code/src_24Layers/conv.h | 308 + .../source_code/src_24Layers/conv_3x3.cpp | 36 + .../source_code/src_24Layers/utils.cpp | 671 + .../src_24Layers__conv_synth/config.h | 0 .../src_24Layers__conv_synth/conv.h | 308 + .../src_24Layers__conv_synth/conv_3x3.cpp | 36 + .../src_24Layers__yolov3_tiny_synth/config.h | 0 .../src_24Layers__yolov3_tiny_synth/conv.h | 308 + .../conv_1x1.cpp | 45 + .../conv_3x3_id16.cpp | 58 + .../conv_3x3_id3.cpp | 58 + .../conv_ver3.cpp | 58 + .../src_24Layers__yolov3_tiny_synth/utils.cpp | 671 + .../yolov3_tiny.cpp | 541 + .../source_code/src_4Layers/config.h | 0 .../source_code/src_4Layers/conv.h | 339 + .../source_code/src_4Layers/conv_3x3.cpp | 36 + .../source_code/src_4Layers/utils.cpp | 923 + .../src_4Layers__conv_synth/config.h | 0 .../src_4Layers__conv_synth/conv.h | 339 + .../src_4Layers__conv_synth/conv_3x3.cpp | 36 + .../src_4Layers__yolov3_tiny_synth/config.h | 0 .../src_4Layers__yolov3_tiny_synth/conv.h | 339 + .../conv_1x1.cpp | 45 + .../conv_3x3_id16.cpp | 167 + .../conv_3x3_id3.cpp | 58 + .../conv_ver3.cpp | 58 + .../src_4Layers__yolov3_tiny_synth/utils.cpp | 923 + .../yolov3_tiny.cpp | 770 + .../Analog-CIM/hls/baseline/cim_conv.cpp | 50 + .../Analog-CIM/hls/baseline/conv.h | 73 + .../hls/baseline/tiled_cim_conv.cpp | 57 + .../Analog-CIM/hls/baseline/utils.cpp | 104 + .../Analog-CIM/hls/baseline/utils.h | 43 + .../Analog-CIM/hls/optimized/cim_conv.cpp | 53 + .../Analog-CIM/hls/optimized/conv.h | 70 + .../hls/optimized/tiled_cim_conv.cpp | 57 + .../Analog-CIM/hls/optimized/utils.cpp | 104 + .../Analog-CIM/hls/optimized/utils.h | 43 + .../Analog-CIM/on-board/cim_conv.cpp | 50 + .../Analog-CIM/on-board/conv.h | 74 + .../Analog-CIM/on-board/tiled_cim_conv.cpp | 57 + .../Analog-CIM/on-board/utils.cpp | 104 + .../Analog-CIM/on-board/utils.h | 43 + .../Golden C/unoptimized/conv.h | 103 + .../Golden C/unoptimized/conv_3x3.cpp | 60 + .../Golden C/unoptimized/tiled_conv.cpp | 242 + .../Golden C/unoptimized/utils.cpp | 142 + .../Golden C/unoptimized/utils.h | 493 + .../DSC_Acceleration/HLS/optimized/conv.h | 103 + .../HLS/optimized/conv_3x3.cpp | 60 + .../HLS/optimized/tiled_conv.cpp | 241 + .../DSC_Acceleration/HLS/optimized/utils.cpp | 142 + .../DSC_Acceleration/HLS/optimized/utils.h | 493 + .../ECG_Classifier/HLS/Baseline/conv.h | 103 + .../ECG_Classifier/HLS/Baseline/conv1d.cpp | 676 + .../ECG_Classifier/HLS/Optimized/conv.h | 103 + .../ECG_Classifier/HLS/Optimized/conv1d.cpp | 641 + .../Eyeriss/convolution.cpp | 377 + .../Eyeriss/convolution.h | 22 + .../FocusedACO/FACO/src/ant.h | 149 + .../FACO/src/include/cxxopts/cxxopts.hpp | 2383 ++ .../FocusedACO/FACO/src/include/fmt/args.h | 238 + .../FocusedACO/FACO/src/include/fmt/chrono.h | 1190 + .../FocusedACO/FACO/src/include/fmt/color.h | 624 + .../FocusedACO/FACO/src/include/fmt/compile.h | 952 + .../FocusedACO/FACO/src/include/fmt/core.h | 1952 ++ .../FACO/src/include/fmt/format-inl.h | 2730 ++ .../FocusedACO/FACO/src/include/fmt/format.h | 4155 +++ .../FocusedACO/FACO/src/include/fmt/locale.h | 64 + .../FocusedACO/FACO/src/include/fmt/os.h | 491 + .../FocusedACO/FACO/src/include/fmt/ostream.h | 179 + .../FocusedACO/FACO/src/include/fmt/posix.h | 2 + .../FocusedACO/FACO/src/include/fmt/printf.h | 757 + .../FocusedACO/FACO/src/include/fmt/ranges.h | 467 + .../FocusedACO/FACO/src/json.hpp | 25855 ++++++++++++++++ .../FocusedACO/FACO/src/kd_tree.h | 467 + .../FocusedACO/FACO/src/local_search.cpp | 714 + .../FocusedACO/FACO/src/local_search.h | 41 + .../FocusedACO/FACO/src/logging.h | 149 + .../FocusedACO/FACO/src/pheromone.h | 156 + .../FocusedACO/FACO/src/problem_instance.h | 358 + .../FocusedACO/FACO/src/progargs.h | 89 + .../FocusedACO/FACO/src/rand.h | 142 + .../FocusedACO/FACO/src/utils.h | 116 + .../HLS/LocalSearchOptimized/two_opt_nn.cpp | 308 + .../include/cxxopts/cxxopts.hpp | 2383 ++ .../LocalSearchUnoptimized/include/fmt/args.h | 238 + .../include/fmt/chrono.h | 1190 + .../include/fmt/color.h | 624 + .../include/fmt/compile.h | 952 + .../LocalSearchUnoptimized/include/fmt/core.h | 1952 ++ .../include/fmt/format-inl.h | 2730 ++ .../include/fmt/format.h | 4155 +++ .../include/fmt/locale.h | 64 + .../LocalSearchUnoptimized/include/fmt/os.h | 491 + .../include/fmt/ostream.h | 179 + .../include/fmt/posix.h | 2 + .../include/fmt/printf.h | 757 + .../include/fmt/ranges.h | 467 + .../HLS/LocalSearchUnoptimized/two_opt_nn.cpp | 259 + .../FocusedACO/HLS/three-opt/three_opt_nn.cpp | 683 + .../GradCAM/src_hls/avg_pool/avg_pool.cpp | 93 + .../GradCAM/src_hls/avg_pool/avg_pool.hpp | 17 + .../GradCAM/src_hls/bundles.hpp | 51 + .../GradCAM/src_hls/cam/cam.cpp | 130 + .../GradCAM/src_hls/cam/max_idx.h | 22 + .../GradCAM/src_hls/conv1/conv.cpp | 44 + .../GradCAM/src_hls/conv1/conv1.cpp | 65 + .../GradCAM/src_hls/conv1/conv1.hpp | 13 + .../GradCAM/src_hls/conv1/io.cpp | 131 + .../GradCAM/src_hls/conv1/params.hpp | 28 + .../GradCAM/src_hls/conv_3x3_s1/conv.cpp | 55 + .../src_hls/conv_3x3_s1/conv_3x3_s1.cpp | 143 + .../src_hls/conv_3x3_s1/conv_3x3_s1.hpp | 59 + .../GradCAM/src_hls/conv_3x3_s1/io.cpp | 169 + .../GradCAM/src_hls/conv_3x3_s1/params.hpp | 15 + .../GradCAM/src_hls/conv_ds/conv_ds.cpp | 152 + .../GradCAM/src_hls/conv_ds/conv_ds.hpp | 50 + .../GradCAM/src_hls/linear_fc/linear_fc.cpp | 94 + .../GradCAM/src_hls/linear_fc/linear_fc.hpp | 14 + .../GradCAM/src_hls/maxpool/max_pool.cpp | 220 + .../GradCAM/src_hls/resize.hpp | 7 + .../GradCAM/src_hls/resnet18.cpp | 239 + .../GradCAM/src_hls/sim_util.hpp | 125 + .../GradCAM/src_hls/util.h | 23 + .../MersenneTwister/mersenneTwister.cpp | 86 + .../MersenneTwister/mersenneTwister.hpp | 30 + .../Monte-Carlo/Paths/optionValueAverage.cpp | 69 + .../Monte-Carlo/Paths/optionValueAverage.hpp | 11 + .../Random 100 Paths/genRandNums.cpp | 81 + .../Random 100 Paths/genRandNums.hpp | 26 + .../HLS_C/CSP_Layer1Layer2/conv.h | 247 + .../HLS_C/CSP_Layer1Layer2/utils.cpp | 578 + .../HLS_C/CSP_Layer1Layer2/yolov4_tiny.cpp | 66 + .../HLS_C/Conv2D_Layer1Layer2/GOLDEN/conv.h | 246 + .../HLS_C/Conv2D_Layer1Layer2/conv.h | 246 + .../HLS_C/Conv2D_Layer1Layer2/utils.cpp | 578 + .../HLS_C/Conv2D_Layer1Layer2/yolov4_tiny.cpp | 52 + .../HLS_C/Maxpool_Layer/conv.h | 85 + .../HLS_C/Maxpool_Layer/maxpool2D.cpp | 34 + .../HLS_C/Maxpool_Layer/tiled_maxpool2D.cpp | 69 + .../HLS_C/Maxpool_Layer/utils.cpp | 90 + .../HLS_C/Maxpool_Layer/utils.h | 32 + .../HLS_C/Project_L1/conv.h | 86 + .../HLS_C/Project_L1/conv_7x7.cpp | 82 + .../HLS_C/Project_L1/tiled_conv.cpp | 82 + .../HLS_C/Project_L1/utils.cpp | 148 + .../HLS_C/Project_L1/utils.h | 37 + .../HLS_C/Project_L2/conv.h | 86 + .../HLS_C/Project_L2/conv_7x7.cpp | 68 + .../HLS_C/Project_L2/tiled_conv.cpp | 82 + .../HLS_C/Project_L2/utils.cpp | 138 + .../HLS_C/Project_L2/utils.h | 37 + .../HLS_C/Project_L3/conv.h | 80 + .../HLS_C/Project_L3/conv_7x7.cpp | 60 + .../HLS_C/Project_L3/tiled_conv.cpp | 78 + .../HLS_C/Project_L3/utils.cpp | 138 + .../HLS_C/Project_L3/utils.h | 39 + .../HLS_C/Project_L4/conv.h | 80 + .../HLS_C/Project_L4/conv_7x7.cpp | 60 + .../HLS_C/Project_L4/tiled_conv.cpp | 78 + .../HLS_C/Project_L4/utils.cpp | 138 + .../HLS_C/Project_L4/utils.h | 39 + .../HLS_C/Project_L5/conv.h | 80 + .../HLS_C/Project_L5/conv_7x7.cpp | 60 + .../HLS_C/Project_L5/tiled_conv.cpp | 78 + .../HLS_C/Project_L5/utils.cpp | 138 + .../HLS_C/Project_L5/utils.h | 39 + .../HLS_C/Project_L6/conv.h | 80 + .../HLS_C/Project_L6/conv_7x7.cpp | 60 + .../HLS_C/Project_L6/tiled_conv.cpp | 78 + .../HLS_C/Project_L6/utils.cpp | 143 + .../HLS_C/Project_L6/utils.h | 39 + .../dcl.h | 22 + .../top.cpp | 218 + .../dcl.h | 19 + .../top.cpp | 167 + .../dcl.h | 23 + .../top.cpp | 159 + .../Hsuanchen_Fang_lab2/dcl.h | 24 + .../Hsuanchen_Fang_lab2/top.cpp | 286 + .../Hsuanchen_Fang_lab3/dcl.h | 40 + .../Hsuanchen_Fang_lab3/top.cpp | 81 + .../Mingyu_Zhang_lab2/dcl.h | 20 + .../Mingyu_Zhang_lab2/top.cpp | 115 + .../Mingyu_Zhang_lab3/dcl.h | 23 + .../Mingyu_Zhang_lab3/top.cpp | 129 + .../neural_hls_NeuroFPGA/top.h | 127 + .../neural_hls_NeuroFPGA/top_new.cpp | 477 + .../NeuroFPGA_Project/symbolic_HLS/top.cpp | 45 + .../16.h | 562 + .../32.h | 172 + .../64.h | 78 + .../dcl.h | 77 + .../top.cpp | 88 + .../Xiyin_Xue_Lab2_2025/dcl.h | 19 + .../Xiyin_Xue_Lab2_2025/top.cpp | 246 + .../Xiyin_xue_lab3/dcl.h | 22 + .../Xiyin_xue_lab3/top.cpp | 214 + .../dcl.h | 19 + .../top.cpp | 144 + .../dcl.h | 22 + .../top.cpp | 128 + .../dcl.h | 18 + .../top.cpp | 180 + .../dcl.h | 22 + .../top.cpp | 102 + .../dcl.h | 20 + .../top.cpp | 108 + .../dcl.h | 22 + .../top.cpp | 75 + .../Anuvab_Sen_lab_2_ECE_8893_spring_29/dcl.h | 19 + .../top.cpp | 207 + .../Anuvab_Sen_lab_3_ECE_8893_spring_29/dcl.h | 22 + .../top.cpp | 152 + .../dcl.h | 19 + .../top.cpp | 159 + .../arati_ganesh_ece8893_spring25_lab2/dcl.h | 20 + .../top.cpp | 254 + .../arati_ganesh_ece8893_spring25_lab3/dcl.h | 22 + .../matmul.h | 20 + .../top.cpp | 153 + .../dcl.h | 19 + .../top.cpp | 209 + .../dcl.h | 22 + .../top.cpp | 169 + .../barry_walker_lab_2/dcl.h | 27 + .../barry_walker_lab_2/top.cpp | 342 + .../barry_walker_lab_3/dcl.h | 29 + .../barry_walker_lab_3/top.cpp | 341 + .../connor_talley_lab_2/dcl.h | 24 + .../connor_talley_lab_2/top.cpp | 241 + .../connor_talley_lab_3/dcl.h | 40 + .../connor_talley_lab_3/top.cpp | 152 + .../dcl.h | 19 + .../top.cpp | 212 + .../dcl.h | 33 + .../spmm.cpp | 118 + .../spmm.h | 51 + .../top.cpp | 112 + .../ece8893_dataset_lab_1/0001/dcl.h | 23 + .../ece8893_dataset_lab_1/0001/top.cpp | 167 + .../ece8893_dataset_lab_1/0002/dcl.h | 23 + .../ece8893_dataset_lab_1/0002/top.cpp | 87 + .../gabriel_lopez_lugo_lab2/dcl.h | 33 + .../gabriel_lopez_lugo_lab2/top.cpp | 226 + .../gabriel_lopez_lugo_lab3/dcl.h | 31 + .../gabriel_lopez_lugo_lab3/top.cpp | 123 + .../hyungseok_bae_lab2_2025/dcl.h | 19 + .../hyungseok_bae_lab2_2025/top.cpp | 183 + .../hyungseok_bae_lab3_2025/dcl.h | 30 + .../hyungseok_bae_lab3_2025/top.cpp | 203 + .../kaihong_lin_lab2/dcl.h | 21 + .../kaihong_lin_lab2/top.cpp | 271 + .../kaihong_lin_lab3/dcl.h | 22 + .../kaihong_lin_lab3/top.cpp | 450 + .../kamya_hari_lab_2_2025/dcl.h | 19 + .../kamya_hari_lab_2_2025/top.cpp | 103 + .../kamya_hari_lab_3_2025/dcl.h | 22 + .../kamya_hari_lab_3_2025/top.cpp | 163 + .../dcl.h | 21 + .../top.cpp | 204 + .../dcl.h | 21 + .../top.cpp | 159 + .../lab2_hanchen/dcl.h | 21 + .../lab2_hanchen/top.cpp | 237 + .../lab2_sushkrutha/dcl.h | 18 + .../lab2_sushkrutha/top.cpp | 179 + .../lab3_hanchen/dcl.h | 23 + .../lab3_hanchen/top.cpp | 93 + .../lab3_sushkrutha/dcl.h | 22 + .../lab3_sushkrutha/top.cpp | 156 + .../ben_hall_lab2_2025_attention/dcl.h | 23 + .../ben_hall_lab2_2025_attention/top.cpp | 145 + .../dcl.h | 104 + .../top.cpp | 85 + .../max_beaulieu_Lab_3_2025/dcl.h | 19 + .../max_beaulieu_Lab_3_2025/top.cpp | 157 + .../lab2/dcl.h | 19 + .../lab2/top.cpp | 71 + .../lab3/dcl.h | 24 + .../lab3/top.cpp | 74 + .../minjun_kim_Lab2_2025/dcl.h | 19 + .../minjun_kim_Lab2_2025/top.cpp | 205 + .../minjun_kim_Lab3_2025/dcl.h | 25 + .../minjun_kim_Lab3_2025/top.cpp | 62 + .../mizanur_Lab2_2025/dcl.h | 21 + .../mizanur_Lab2_2025/top.cpp | 119 + .../mizanur_Lab3_2025/compute_SpMM.cpp | 120 + .../mizanur_Lab3_2025/dcl.h | 23 + .../mizanur_Lab3_2025/generate_matrices.cpp | 91 + .../mizanur_Lab3_2025/top.cpp | 103 + .../mohammad_zain_lab_2/dcl.h | 22 + .../mohammad_zain_lab_2/top.cpp | 219 + .../mohammad_zain_lab_3/dcl.h | 26 + .../mohammad_zain_lab_3/top.cpp | 103 + .../nayan_nair_ece8893_spring25_lab2/dcl.h | 19 + .../nayan_nair_ece8893_spring25_lab2/top.cpp | 104 + .../nayan_nair_ece8893_spring25_lab3/dcl.h | 24 + .../nayan_nair_ece8893_spring25_lab3/top.cpp | 74 + .../dcl.h | 9 + .../top.cpp | 507 + .../dcl.h | 25 + .../top.cpp | 251 + .../nikhil_p_ece8893_spring25_lab2/dcl.h | 30 + .../nikhil_p_ece8893_spring25_lab2/top.cpp | 316 + .../nikhil_p_ece8893_spring25_lab3/dcl.h | 37 + .../nikhil_p_ece8893_spring25_lab3/top.cpp | 208 + .../nikhil_s_ece8893_sp25_lab2/dcl.h | 19 + .../nikhil_s_ece8893_sp25_lab2/top.cpp | 71 + .../nikhil_s_ece8893_sp25_lab3/dcl.h | 22 + .../nikhil_s_ece8893_sp25_lab3/top.cpp | 88 + .../oscar_baglivio_lab_2/dcl.h | 21 + .../oscar_baglivio_lab_2/top.cpp | 126 + .../oscar_baglivio_lab_3/dcl.h | 22 + .../oscar_baglivio_lab_3/top.cpp | 114 + .../pengzhao_liu_Lab2_2025/dcl.h | 19 + .../pengzhao_liu_Lab2_2025/top.cpp | 103 + .../pengzhao_liu_Lab3_2025/dcl.h | 22 + .../pengzhao_liu_Lab3_2025/top.cpp | 238 + .../pranay_kamineny_lab2/dcl.h | 19 + .../pranay_kamineny_lab2/top.cpp | 178 + .../pranay_kamineny_lab3/dcl.h | 22 + .../pranay_kamineny_lab3/top.cpp | 108 + .../ritik_raj_lab2/dcl.h | 21 + .../ritik_raj_lab2/top.cpp | 129 + .../ritik_raj_lab3/dcl_dense.h | 21 + .../ritik_raj_lab3/top_dense.cpp | 53 + .../sahith_lab2_2025/dcl.h | 19 + .../sahith_lab2_2025/top.cpp | 100 + .../sahith_lab3_2025/dcl.h | 25 + .../sahith_lab3_2025/top.cpp | 139 + .../Shengxi_Liang_LAB2/dcl.h | 21 + .../Shengxi_Liang_LAB2/top.cpp | 178 + .../Shengxi_Liang_LAB3/dcl.h | 20 + .../Shengxi_Liang_LAB3/top.cpp | 173 + .../shibao_su_ece8893_lab2/dcl.h | 19 + .../shibao_su_ece8893_lab2/top.cpp | 146 + .../shibao_su_ece8893_lab3/dcl.h | 25 + .../shibao_su_ece8893_lab3/top.cpp | 118 + .../shreesahitya_balaje_lab2/dcl.h | 19 + .../shreesahitya_balaje_lab2/top.cpp | 178 + .../shreesahitya_balaje_lab3/dcl.h | 22 + .../shreesahitya_balaje_lab3/top.cpp | 163 + .../dcl.h | 19 + .../top.cpp | 256 + .../dcl.h | 20 + .../top.cpp | 220 + .../dcl.h | 19 + .../top.cpp | 132 + .../dcl.h | 22 + .../top.cpp | 87 + .../stefan_test_design/my_kernel.cpp | 7 + .../suyeon_yoon_lab3_spring25/dcl.h | 22 + .../suyeon_yoon_lab3_spring25/top.cpp | 63 + .../dcl.h | 19 + .../top.cpp | 108 + .../dcl.h | 20 + .../top.cpp | 141 + .../zihan_qi_lab2/dcl.h | 34 + .../zihan_qi_lab2/top.cpp | 157 + .../zihan_qi_lab3/dcl.h | 37 + .../zihan_qi_lab3/top.cpp | 123 + .../zijun_wang_ece8893_spring25_lab2/dcl.h | 29 + .../zijun_wang_ece8893_spring25_lab2/top.cpp | 150 + .../zijun_wang_ece8893_spring25_lab3/dcl.h | 33 + .../zijun_wang_ece8893_spring25_lab3/top.cpp | 181 + .../Inputs/flowgnn/dgn/src/DGN_compute.cc | 115 + .../Inputs/flowgnn/dgn/src/conv_layer.cc | 178 + .../Inputs/flowgnn/dgn/src/conv_layer.h | 16 + .../hlsfactory/Inputs/flowgnn/dgn/src/dcl.h | 119 + .../Inputs/flowgnn/dgn/src/finalize.cc | 105 + .../Inputs/flowgnn/dgn/src/finalize.h | 19 + .../Inputs/flowgnn/dgn/src/globals.cc | 24 + .../Inputs/flowgnn/dgn/src/linear.cc | 174 + .../Inputs/flowgnn/dgn/src/linear.h | 46 + .../Inputs/flowgnn/dgn/src/load_inputs.cc | 168 + .../Inputs/flowgnn/dgn/src/load_inputs.h | 32 + .../Inputs/flowgnn/dgn/src/message_passing.cc | 154 + .../Inputs/flowgnn/dgn/src/message_passing.h | 14 + .../Inputs/flowgnn/dgn/src/node_embedding.cc | 183 + .../Inputs/flowgnn/dgn/src/node_embedding.h | 14 + .../hlsfactory/Inputs/flowgnn/dgn/src/util.h | 25 + .../Inputs/flowgnn/dgn/testbench/testbench.h | 30 + .../Inputs/flowgnn/gat/src/GAT_compute.cc | 110 + .../Inputs/flowgnn/gat/src/conv_layer.cc | 195 + .../Inputs/flowgnn/gat/src/conv_layer.h | 20 + .../hlsfactory/Inputs/flowgnn/gat/src/dcl.h | 120 + .../Inputs/flowgnn/gat/src/finalize.cc | 198 + .../Inputs/flowgnn/gat/src/finalize.h | 16 + .../Inputs/flowgnn/gat/src/globals.cc | 23 + .../Inputs/flowgnn/gat/src/linear.cc | 161 + .../Inputs/flowgnn/gat/src/linear.h | 46 + .../Inputs/flowgnn/gat/src/load_inputs.cc | 227 + .../Inputs/flowgnn/gat/src/load_inputs.h | 24 + .../Inputs/flowgnn/gat/src/message_passing.cc | 201 + .../Inputs/flowgnn/gat/src/message_passing.h | 17 + .../Inputs/flowgnn/gat/src/node_embedding.cc | 271 + .../Inputs/flowgnn/gat/src/node_embedding.h | 18 + .../hlsfactory/Inputs/flowgnn/gat/src/util.h | 48 + .../Inputs/flowgnn/gat/testbench/testbench.h | 25 + .../Inputs/flowgnn/gcn/src/GCN_compute.cc | 113 + .../Inputs/flowgnn/gcn/src/conv_layer.cc | 119 + .../Inputs/flowgnn/gcn/src/conv_layer.h | 13 + .../hlsfactory/Inputs/flowgnn/gcn/src/dcl.h | 127 + .../Inputs/flowgnn/gcn/src/finalize.cc | 115 + .../Inputs/flowgnn/gcn/src/finalize.h | 16 + .../Inputs/flowgnn/gcn/src/globals.cc | 27 + .../Inputs/flowgnn/gcn/src/linear.cc | 161 + .../Inputs/flowgnn/gcn/src/linear.h | 46 + .../Inputs/flowgnn/gcn/src/load_inputs.cc | 215 + .../Inputs/flowgnn/gcn/src/load_inputs.h | 34 + .../Inputs/flowgnn/gcn/src/message_passing.cc | 172 + .../Inputs/flowgnn/gcn/src/message_passing.h | 15 + .../Inputs/flowgnn/gcn/src/node_embedding.cc | 169 + .../Inputs/flowgnn/gcn/src/node_embedding.h | 14 + .../hlsfactory/Inputs/flowgnn/gcn/src/util.h | 34 + .../Inputs/flowgnn/gcn/testbench/testbench.h | 34 + .../Inputs/flowgnn/gin/src/GIN_compute.cc | 100 + .../Inputs/flowgnn/gin/src/conv_layer.cc | 178 + .../Inputs/flowgnn/gin/src/conv_layer.h | 16 + .../hlsfactory/Inputs/flowgnn/gin/src/dcl.h | 126 + .../Inputs/flowgnn/gin/src/finalize.cc | 115 + .../Inputs/flowgnn/gin/src/finalize.h | 15 + .../Inputs/flowgnn/gin/src/globals.cc | 24 + .../Inputs/flowgnn/gin/src/linear.cc | 161 + .../Inputs/flowgnn/gin/src/linear.h | 46 + .../Inputs/flowgnn/gin/src/load_inputs.cc | 235 + .../Inputs/flowgnn/gin/src/load_inputs.h | 32 + .../Inputs/flowgnn/gin/src/message_passing.cc | 95 + .../Inputs/flowgnn/gin/src/message_passing.h | 14 + .../Inputs/flowgnn/gin/src/node_embedding.cc | 201 + .../Inputs/flowgnn/gin/src/node_embedding.h | 14 + .../hlsfactory/Inputs/flowgnn/gin/src/util.h | 34 + .../Inputs/flowgnn/gin/testbench/testbench.h | 29 + .../Inputs/flowgnn/pna/src/PNA_compute.cc | 100 + .../Inputs/flowgnn/pna/src/conv_layer.cc | 181 + .../Inputs/flowgnn/pna/src/conv_layer.h | 16 + .../hlsfactory/Inputs/flowgnn/pna/src/dcl.h | 137 + .../Inputs/flowgnn/pna/src/finalize.cc | 134 + .../Inputs/flowgnn/pna/src/finalize.h | 19 + .../Inputs/flowgnn/pna/src/globals.cc | 23 + .../Inputs/flowgnn/pna/src/linear.cc | 173 + .../Inputs/flowgnn/pna/src/linear.h | 46 + .../Inputs/flowgnn/pna/src/load_inputs.cc | 204 + .../Inputs/flowgnn/pna/src/load_inputs.h | 39 + .../Inputs/flowgnn/pna/src/message_passing.cc | 147 + .../Inputs/flowgnn/pna/src/message_passing.h | 16 + .../Inputs/flowgnn/pna/src/node_embedding.cc | 215 + .../Inputs/flowgnn/pna/src/node_embedding.h | 14 + .../hlsfactory/Inputs/flowgnn/pna/src/util.h | 48 + .../Inputs/flowgnn/pna/testbench/testbench.h | 29 + .../forgebench/Llama_GPT_module/top.cpp | 611 + .../Inputs/forgebench/Llama_GPT_module/top.h | 23 + .../forgebench/activation_module/top.cpp | 269 + .../Inputs/forgebench/activation_module/top.h | 29 + .../Inputs/forgebench/activation_op1/top.cpp | 269 + .../Inputs/forgebench/activation_op1/top.h | 29 + .../Inputs/forgebench/activation_op2/top.cpp | 269 + .../Inputs/forgebench/activation_op2/top.h | 29 + .../Inputs/forgebench/activation_op3/top.cpp | 269 + .../Inputs/forgebench/activation_op3/top.h | 29 + .../Inputs/forgebench/attention_op_p1/top.cpp | 159 + .../Inputs/forgebench/attention_op_p1/top.h | 9 + .../Inputs/forgebench/attention_op_p2/top.cpp | 159 + .../Inputs/forgebench/attention_op_p2/top.h | 9 + .../Inputs/forgebench/attention_op_p3/top.cpp | 159 + .../Inputs/forgebench/attention_op_p3/top.h | 9 + .../forgebench/attn_breakdown_module/top.cpp | 330 + .../forgebench/attn_breakdown_module/top.h | 25 + .../forgebench/attn_breakdown_op1/top.cpp | 330 + .../forgebench/attn_breakdown_op1/top.h | 25 + .../forgebench/attn_breakdown_op2/top.cpp | 330 + .../forgebench/attn_breakdown_op2/top.h | 25 + .../Inputs/forgebench/conv_A/top.cpp | 140 + .../hlsfactory/Inputs/forgebench/conv_A/top.h | 9 + .../Inputs/forgebench/conv_B/top.cpp | 140 + .../hlsfactory/Inputs/forgebench/conv_B/top.h | 9 + .../Inputs/forgebench/conv_C/top.cpp | 140 + .../hlsfactory/Inputs/forgebench/conv_C/top.h | 9 + .../forgebench/conv_block_module/top.cpp | 1200 + .../Inputs/forgebench/conv_block_module/top.h | 65 + .../Inputs/forgebench/conv_block_op1/top.cpp | 1128 + .../Inputs/forgebench/conv_block_op1/top.h | 65 + .../Inputs/forgebench/conv_block_op2/top.cpp | 1130 + .../Inputs/forgebench/conv_block_op2/top.h | 65 + .../Inputs/forgebench/conv_block_op3/top.cpp | 1130 + .../Inputs/forgebench/conv_block_op3/top.h | 65 + .../Inputs/forgebench/conv_module/top.cpp | 588 + .../Inputs/forgebench/conv_module/top.h | 44 + .../forgebench/diff_dims_module_large/top.cpp | 357 + .../forgebench/diff_dims_module_large/top.h | 13 + .../forgebench/diff_dims_module_small/top.cpp | 403 + .../forgebench/diff_dims_module_small/top.h | 13 + .../Inputs/forgebench/diff_dims_p1/top.cpp | 149 + .../Inputs/forgebench/diff_dims_p1/top.h | 9 + .../Inputs/forgebench/diff_dims_p2/top.cpp | 149 + .../Inputs/forgebench/diff_dims_p2/top.h | 9 + .../Inputs/forgebench/diff_dims_p3/top.cpp | 149 + .../Inputs/forgebench/diff_dims_p3/top.h | 9 + .../forgebench/diff_orders_module/top.cpp | 286 + .../forgebench/diff_orders_module/top.h | 13 + .../Inputs/forgebench/diff_orders_p1/top.cpp | 144 + .../Inputs/forgebench/diff_orders_p1/top.h | 9 + .../Inputs/forgebench/diff_orders_p2/top.cpp | 144 + .../Inputs/forgebench/diff_orders_p2/top.h | 9 + .../Inputs/forgebench/diff_orders_p3/top.cpp | 135 + .../Inputs/forgebench/diff_orders_p3/top.h | 9 + .../forgebench/gpt_transformer_p1/top.cpp | 367 + .../forgebench/gpt_transformer_p1/top.h | 9 + .../forgebench/llama_transformer_p2/top.cpp | 397 + .../forgebench/llama_transformer_p2/top.h | 9 + .../hlsfactory/Inputs/forgebench/mlp/top.cpp | 281 + .../hlsfactory/Inputs/forgebench/mlp/top.h | 9 + .../forgebench/mult_op_module_dot/top.cpp | 366 + .../forgebench/mult_op_module_dot/top.h | 13 + .../forgebench/mult_op_module_mm/top.cpp | 372 + .../Inputs/forgebench/mult_op_module_mm/top.h | 13 + .../forgebench/mult_op_module_mmv/top.cpp | 407 + .../forgebench/mult_op_module_mmv/top.h | 13 + .../Inputs/forgebench/mult_op_p1/top.cpp | 119 + .../Inputs/forgebench/mult_op_p1/top.h | 9 + .../Inputs/forgebench/mult_op_p2/top.cpp | 104 + .../Inputs/forgebench/mult_op_p2/top.h | 9 + .../Inputs/forgebench/mult_op_p3/top.cpp | 86 + .../Inputs/forgebench/mult_op_p3/top.h | 9 + .../Inputs/forgebench/testing_impl/top.cpp | 204 + .../Inputs/forgebench/testing_impl/top.h | 9 + .../Inputs/forgebench/testing_unroll/top.cpp | 250 + .../Inputs/forgebench/testing_unroll/top.h | 9 + .../forgebench/tiled_attn_module/top.cpp | 437 + .../Inputs/forgebench/tiled_attn_module/top.h | 10 + .../Inputs/forgebench/tiled_attn_p1/top.cpp | 159 + .../Inputs/forgebench/tiled_attn_p1/top.h | 9 + .../Inputs/forgebench/tiled_attn_p2/top.cpp | 159 + .../Inputs/forgebench/tiled_attn_p2/top.h | 9 + .../Inputs/forgebench/vec_mtx_module/top.cpp | 206 + .../Inputs/forgebench/vec_mtx_module/top.h | 10 + .../Inputs/forgebench/vec_mtx_p1/top.cpp | 121 + .../Inputs/forgebench/vec_mtx_p1/top.h | 9 + .../Inputs/forgebench/vec_mtx_p2/top.cpp | 114 + .../Inputs/forgebench/vec_mtx_p2/top.h | 9 + .../designs/fpga_gcn_qm9/gnn_builder_lib.h | 1860 ++ .../gnnbuilder/designs/fpga_gcn_qm9/model.cpp | 1160 + .../gnnbuilder/designs/fpga_gcn_qm9/model.h | 93 + .../designs/fpga_gin_qm9/gnn_builder_lib.h | 1860 ++ .../gnnbuilder/designs/fpga_gin_qm9/model.cpp | 1274 + .../gnnbuilder/designs/fpga_gin_qm9/model.h | 105 + .../designs/fpga_pna_qm9/gnn_builder_lib.h | 1860 ++ .../gnnbuilder/designs/fpga_pna_qm9/model.cpp | 1382 + .../gnnbuilder/designs/fpga_pna_qm9/model.h | 117 + .../designs/fpga_sage_qm9/gnn_builder_lib.h | 1860 ++ .../designs/fpga_sage_qm9/model.cpp | 1208 + .../gnnbuilder/designs/fpga_sage_qm9/model.h | 99 + .../vivado-target/sources/2mm/2mm.cpp | 55 + .../vivado-target/sources/2mm/2mm.h | 16 + .../vivado-target/sources/2mm/testbench.cpp | 17 + .../vivado-target/sources/3mm/3mm.cpp | 74 + .../vivado-target/sources/3mm/3mm.h | 16 + .../vivado-target/sources/3mm/testbench.cpp | 18 + .../vivado-target/sources/adi/adi.cpp | 110 + .../vivado-target/sources/adi/adi.h | 16 + .../vivado-target/sources/adi/testbench.cpp | 12 + .../vivado-target/sources/aes/aes.cpp | 247 + .../vivado-target/sources/aes/aes.h | 17 + .../vivado-target/sources/aes/testbench.cpp | 10 + .../sources/atax-medium/atax-medium.cpp | 36 + .../sources/atax-medium/atax-medium.h | 16 + .../sources/atax-medium/testbench.cpp | 10 + .../vivado-target/sources/atax/atax.cpp | 38 + .../vivado-target/sources/atax/atax.h | 16 + .../vivado-target/sources/atax/testbench.cpp | 12 + .../sources/bicg-large/bicg-large.cpp | 31 + .../sources/bicg-large/bicg-large.h | 16 + .../sources/bicg-large/testbench.cpp | 13 + .../sources/bicg-medium/bicg-medium.cpp | 35 + .../sources/bicg-medium/bicg-medium.h | 16 + .../sources/bicg-medium/testbench.cpp | 13 + .../vivado-target/sources/bicg/bicg.cpp | 37 + .../vivado-target/sources/bicg/bicg.h | 16 + .../vivado-target/sources/bicg/testbench.cpp | 13 + .../sources/correlation/correlation.cpp | 85 + .../sources/correlation/correlation.h | 16 + .../sources/correlation/testbench.cpp | 11 + .../sources/covariance/covariance.cpp | 58 + .../sources/covariance/covariance.h | 16 + .../sources/covariance/testbench.cpp | 12 + .../sources/doitgen-red/doitgen-red.cpp | 43 + .../sources/doitgen-red/doitgen-red.h | 16 + .../sources/doitgen-red/testbench.cpp | 9 + .../vivado-target/sources/doitgen/doitgen.cpp | 41 + .../vivado-target/sources/doitgen/doitgen.h | 16 + .../sources/doitgen/testbench.cpp | 12 + .../sources/fdtd-2d-large/fdtd-2d-large.cpp | 60 + .../sources/fdtd-2d-large/fdtd-2d-large.h | 16 + .../sources/fdtd-2d-large/testbench.cpp | 13 + .../vivado-target/sources/fdtd-2d/fdtd-2d.cpp | 61 + .../vivado-target/sources/fdtd-2d/fdtd-2d.h | 16 + .../sources/fdtd-2d/testbench.cpp | 13 + .../sources/gemm-blocked/gemm-blocked.cpp | 56 + .../sources/gemm-blocked/gemm-blocked.h | 16 + .../sources/gemm-blocked/testbench.cpp | 9 + .../sources/gemm-ncubed/gemm-ncubed.cpp | 37 + .../sources/gemm-ncubed/gemm-ncubed.h | 16 + .../sources/gemm-ncubed/testbench.cpp | 9 + .../sources/gemm-p-large/gemm-p-large.cpp | 42 + .../sources/gemm-p-large/gemm-p-large.h | 16 + .../sources/gemm-p-large/testbench.cpp | 14 + .../vivado-target/sources/gemm-p/gemm-p.cpp | 46 + .../vivado-target/sources/gemm-p/gemm-p.h | 16 + .../sources/gemm-p/testbench.cpp | 14 + .../sources/gemver-medium/gemver-medium.cpp | 66 + .../sources/gemver-medium/gemver-medium.h | 16 + .../sources/gemver-medium/testbench.cpp | 18 + .../vivado-target/sources/gemver/gemver.cpp | 70 + .../vivado-target/sources/gemver/gemver.h | 16 + .../sources/gemver/testbench.cpp | 18 + .../sources/gesummv-medium/gesummv-medium.cpp | 34 + .../sources/gesummv-medium/gesummv-medium.h | 16 + .../sources/gesummv-medium/testbench.cpp | 13 + .../vivado-target/sources/gesummv/gesummv.cpp | 37 + .../vivado-target/sources/gesummv/gesummv.h | 16 + .../sources/gesummv/testbench.cpp | 14 + .../vivado-target/sources/heat-3d/heat-3d.cpp | 62 + .../vivado-target/sources/heat-3d/heat-3d.h | 16 + .../sources/heat-3d/testbench.cpp | 10 + .../sources/jacobi-1d/jacobi-1d.cpp | 30 + .../sources/jacobi-1d/jacobi-1d.h | 16 + .../sources/jacobi-1d/testbench.cpp | 10 + .../sources/jacobi-2d/jacobi-2d.cpp | 42 + .../sources/jacobi-2d/jacobi-2d.h | 16 + .../sources/jacobi-2d/testbench.cpp | 10 + .../vivado-target/sources/md/md.cpp | 77 + .../hlsyn-vitis/vivado-target/sources/md/md.h | 16 + .../vivado-target/sources/md/testbench.cpp | 13 + .../sources/mvt-medium/mvt-medium.cpp | 39 + .../sources/mvt-medium/mvt-medium.h | 16 + .../sources/mvt-medium/testbench.cpp | 11 + .../vivado-target/sources/mvt/mvt.cpp | 41 + .../vivado-target/sources/mvt/mvt.h | 16 + .../vivado-target/sources/mvt/testbench.cpp | 11 + .../vivado-target/sources/nw/nw.cpp | 95 + .../hlsyn-vitis/vivado-target/sources/nw/nw.h | 16 + .../vivado-target/sources/nw/testbench.cpp | 12 + .../sources/seidel-2d/seidel-2d.cpp | 31 + .../sources/seidel-2d/seidel-2d.h | 16 + .../sources/seidel-2d/testbench.cpp | 9 + .../sources/spmv-crs/spmv-crs.cpp | 35 + .../vivado-target/sources/spmv-crs/spmv-crs.h | 16 + .../sources/spmv-crs/testbench.cpp | 11 + .../sources/spmv-ellpack/spmv-ellpack.cpp | 27 + .../sources/spmv-ellpack/spmv-ellpack.h | 16 + .../sources/spmv-ellpack/testbench.cpp | 10 + .../sources/stencil-3d/stencil-3d.cpp | 38 + .../sources/stencil-3d/stencil-3d.h | 16 + .../sources/stencil-3d/testbench.cpp | 10 + .../stencil_stencil2d/stencil_stencil2d.cpp | 36 + .../stencil_stencil2d/stencil_stencil2d.h | 16 + .../sources/stencil_stencil2d/testbench.cpp | 9 + .../symm-opt-medium/symm-opt-medium.cpp | 54 + .../sources/symm-opt-medium/symm-opt-medium.h | 16 + .../sources/symm-opt-medium/testbench.cpp | 11 + .../sources/symm-opt/symm-opt.cpp | 53 + .../vivado-target/sources/symm-opt/symm-opt.h | 16 + .../sources/symm-opt/testbench.cpp | 11 + .../vivado-target/sources/symm/symm.cpp | 47 + .../vivado-target/sources/symm/symm.h | 16 + .../vivado-target/sources/symm/testbench.cpp | 11 + .../vivado-target/sources/syr2k/syr2k.cpp | 46 + .../vivado-target/sources/syr2k/syr2k.h | 16 + .../vivado-target/sources/syr2k/testbench.cpp | 11 + .../vivado-target/sources/syrk/syrk.cpp | 43 + .../vivado-target/sources/syrk/syrk.h | 16 + .../vivado-target/sources/syrk/testbench.cpp | 10 + .../sources/trmm-opt/testbench.cpp | 9 + .../sources/trmm-opt/trmm-opt.cpp | 35 + .../vivado-target/sources/trmm-opt/trmm-opt.h | 16 + .../vivado-target/sources/trmm/testbench.cpp | 9 + .../vivado-target/sources/trmm/trmm.cpp | 34 + .../vivado-target/sources/trmm/trmm.h | 16 + .../Inputs/hp_fft_hls/n1024__UF1/FFT.cpp | 449 + .../Inputs/hp_fft_hls/n1024__UF1/FFT.h | 33 + .../Inputs/hp_fft_hls/n1024__UF16/FFT.cpp | 2771 ++ .../Inputs/hp_fft_hls/n1024__UF16/FFT.h | 33 + .../Inputs/hp_fft_hls/n1024__UF2/FFT.cpp | 619 + .../Inputs/hp_fft_hls/n1024__UF2/FFT.h | 33 + .../Inputs/hp_fft_hls/n1024__UF32/FFT.cpp | 470 + .../Inputs/hp_fft_hls/n1024__UF32/FFT.h | 33 + .../Inputs/hp_fft_hls/n1024__UF4/FFT.cpp | 630 + .../Inputs/hp_fft_hls/n1024__UF4/FFT.h | 33 + .../Inputs/hp_fft_hls/n1024__UF8/FFT.cpp | 1033 + .../Inputs/hp_fft_hls/n1024__UF8/FFT.h | 33 + .../n1024__no_StagePipeline/FFT.cpp | 78 + .../hp_fft_hls/n1024__no_StagePipeline/FFT.h | 30 + .../n1024__original_C_style/FFT.cpp | 92 + .../hp_fft_hls/n1024__original_C_style/FFT.h | 30 + .../Inputs/hp_fft_hls/n256__UF1/FFT.cpp | 443 + .../Inputs/hp_fft_hls/n256__UF1/FFT.h | 33 + .../Inputs/hp_fft_hls/n256__UF16/FFT.cpp | 2765 ++ .../Inputs/hp_fft_hls/n256__UF16/FFT.h | 33 + .../Inputs/hp_fft_hls/n256__UF2/FFT.cpp | 614 + .../Inputs/hp_fft_hls/n256__UF2/FFT.h | 33 + .../Inputs/hp_fft_hls/n256__UF32/FFT.cpp | 464 + .../Inputs/hp_fft_hls/n256__UF32/FFT.h | 33 + .../Inputs/hp_fft_hls/n256__UF4/FFT.cpp | 565 + .../Inputs/hp_fft_hls/n256__UF4/FFT.h | 33 + .../Inputs/hp_fft_hls/n256__UF8/FFT.cpp | 403 + .../Inputs/hp_fft_hls/n256__UF8/FFT.h | 33 + .../hp_fft_hls/n256__no_StagePipeline/FFT.cpp | 78 + .../hp_fft_hls/n256__no_StagePipeline/FFT.h | 30 + .../hp_fft_hls/n256__original_C_style/FFT.cpp | 92 + .../hp_fft_hls/n256__original_C_style/FFT.h | 30 + .../Inputs/machsuite/aes_table/aes.h | 23 + .../Inputs/machsuite/aes_table/aes_table.c | 156 + .../Inputs/machsuite/aes_table/support.h | 135 + .../Inputs/machsuite/aes_tableless/aes.h | 23 + .../machsuite/aes_tableless/aes_tableless.c | 161 + .../Inputs/machsuite/aes_tableless/support.h | 135 + .../Inputs/machsuite/backprop/backprop.c | 245 + .../Inputs/machsuite/backprop/backprop.h | 46 + .../Inputs/machsuite/backprop/support.h | 135 + .../Inputs/machsuite/bfs_bulk/bfs.c | 46 + .../Inputs/machsuite/bfs_bulk/bfs.h | 56 + .../Inputs/machsuite/bfs_bulk/support.h | 135 + .../Inputs/machsuite/bfs_queue/bfs.c | 61 + .../Inputs/machsuite/bfs_queue/bfs.h | 53 + .../Inputs/machsuite/bfs_queue/support.h | 135 + .../Inputs/machsuite/fft_transpose/fft.c | 407 + .../Inputs/machsuite/fft_transpose/fft.h | 30 + .../Inputs/machsuite/fft_transpose/support.h | 135 + .../Inputs/machsuite/gemm_blocked/gemm.c | 30 + .../Inputs/machsuite/gemm_blocked/gemm.h | 37 + .../Inputs/machsuite/gemm_blocked/support.h | 135 + .../Inputs/machsuite/gemm_ncubed/gemm.c | 20 + .../Inputs/machsuite/gemm_ncubed/gemm.h | 29 + .../Inputs/machsuite/gemm_ncubed/support.h | 135 + .../hlsfactory/Inputs/machsuite/md_grid/md.c | 55 + .../hlsfactory/Inputs/machsuite/md_grid/md.h | 41 + .../Inputs/machsuite/md_grid/support.h | 135 + .../hlsfactory/Inputs/machsuite/md_knn/md.c | 52 + .../hlsfactory/Inputs/machsuite/md_knn/md.h | 39 + .../Inputs/machsuite/md_knn/support.h | 135 + .../HLS/hlsfactory/Inputs/machsuite/nw/nw.c | 89 + .../HLS/hlsfactory/Inputs/machsuite/nw/nw.h | 21 + .../hlsfactory/Inputs/machsuite/nw/support.h | 135 + .../Inputs/machsuite/sort_merge/sort.c | 51 + .../Inputs/machsuite/sort_merge/sort.h | 17 + .../Inputs/machsuite/sort_merge/support.h | 135 + .../Inputs/machsuite/sort_radix/sort.c | 105 + .../Inputs/machsuite/sort_radix/sort.h | 37 + .../Inputs/machsuite/sort_radix/support.h | 135 + .../Inputs/machsuite/spmv_crs/spmv.c | 24 + .../Inputs/machsuite/spmv_crs/spmv.h | 27 + .../Inputs/machsuite/spmv_crs/support.h | 135 + .../Inputs/machsuite/spmv_ellpack/spmv.c | 21 + .../Inputs/machsuite/spmv_ellpack/spmv.h | 26 + .../Inputs/machsuite/spmv_ellpack/support.h | 135 + .../Inputs/machsuite/stencil2D/stencil.c | 19 + .../Inputs/machsuite/stencil2D/stencil.h | 29 + .../Inputs/machsuite/stencil2D/support.h | 135 + .../Inputs/machsuite/stencil3D/stencil.c | 52 + .../Inputs/machsuite/stencil3D/stencil.h | 33 + .../Inputs/machsuite/stencil3D/support.h | 135 + .../Inputs/machsuite/viterbi/support.h | 135 + .../Inputs/machsuite/viterbi/viterbi.c | 65 + .../Inputs/machsuite/viterbi/viterbi.h | 36 + .../Inputs/polybench/atax/src/atax.c | 35 + .../Inputs/polybench/atax/src/atax.h | 19 + .../Inputs/polybench/bicg/src/bicg.c | 39 + .../Inputs/polybench/bicg/src/bicg.h | 14 + .../Inputs/polybench/gemm/src/gemm.c | 40 + .../Inputs/polybench/gemm/src/gemm.h | 18 + .../Inputs/polybench/gesummv/src/gesummv.c | 44 + .../Inputs/polybench/gesummv/src/gesummv.h | 15 + .../Inputs/polybench/k2mm/src/k2mm.c | 55 + .../Inputs/polybench/k2mm/src/k2mm.h | 19 + .../Inputs/polybench/k3mm/src/k3mm.c | 61 + .../Inputs/polybench/k3mm/src/k3mm.h | 19 + .../hlsfactory/Inputs/polybench/mvt/src/mvt.c | 39 + .../hlsfactory/Inputs/polybench/mvt/src/mvt.h | 15 + .../Inputs/polybench/syr2k/src/syr2k.c | 59 + .../Inputs/polybench/syr2k/src/syr2k.h | 15 + .../Inputs/polybench/syrk/src/syrk.c | 45 + .../Inputs/polybench/syrk/src/syrk.h | 15 + .../polybench__fixed__medium/2mm/src/2mm.cpp | 42 + .../polybench__fixed__medium/2mm/src/2mm.h | 16 + .../polybench__fixed__medium/3mm/src/3mm.cpp | 52 + .../polybench__fixed__medium/3mm/src/3mm.h | 16 + .../atax/src/atax.cpp | 32 + .../polybench__fixed__medium/atax/src/atax.h | 13 + .../bicg/src/bicg.cpp | 34 + .../polybench__fixed__medium/bicg/src/bicg.h | 14 + .../cholesky/src/cholesky.cpp | 33 + .../cholesky/src/cholesky.h | 10 + .../correlation/src/correlation.cpp | 68 + .../correlation/src/correlation.h | 14 + .../covariance/src/covariance.cpp | 43 + .../covariance/src/covariance.h | 13 + .../doitgen/src/doitgen.cpp | 32 + .../doitgen/src/doitgen.h | 12 + .../durbin/src/durbin.cpp | 44 + .../durbin/src/durbin.h | 11 + .../fdtd-2d/src/fdtd-2d.cpp | 41 + .../fdtd-2d/src/fdtd-2d.h | 15 + .../floyd-warshall/src/floyd-warshall.cpp | 24 + .../floyd-warshall/src/floyd-warshall.h | 9 + .../gemm/src/gemm.cpp | 31 + .../polybench__fixed__medium/gemm/src/gemm.h | 14 + .../gemver/src/gemver.cpp | 43 + .../gemver/src/gemver.h | 20 + .../gesummv/src/gesummv.cpp | 35 + .../gesummv/src/gesummv.h | 16 + .../gramschmidt/src/gramschmidt.cpp | 44 + .../gramschmidt/src/gramschmidt.h | 12 + .../heat-3d/src/heat-3d.cpp | 43 + .../heat-3d/src/heat-3d.h | 12 + .../jacobi-1d/src/jacobi-1d.cpp | 28 + .../jacobi-1d/src/jacobi-1d.h | 12 + .../jacobi-2d/src/jacobi-2d.cpp | 30 + .../jacobi-2d/src/jacobi-2d.h | 12 + .../polybench__fixed__medium/lu/src/lu.cpp | 30 + .../polybench__fixed__medium/lu/src/lu.h | 10 + .../ludcmp/src/ludcmp.cpp | 53 + .../ludcmp/src/ludcmp.h | 13 + .../polybench__fixed__medium/mvt/src/mvt.cpp | 28 + .../polybench__fixed__medium/mvt/src/mvt.h | 14 + .../nussinov/src/nussinov.cpp | 39 + .../nussinov/src/nussinov.h | 9 + .../seidel-2d/src/seidel-2d.cpp | 26 + .../seidel-2d/src/seidel-2d.h | 11 + .../symm/src/symm.cpp | 33 + .../polybench__fixed__medium/symm/src/symm.h | 14 + .../syr2k/src/syr2k.cpp | 31 + .../syr2k/src/syr2k.h | 14 + .../syrk/src/syrk.cpp | 29 + .../polybench__fixed__medium/syrk/src/syrk.h | 13 + .../trisolv/src/trisolv.cpp | 27 + .../trisolv/src/trisolv.h | 12 + .../trmm/src/trmm.cpp | 26 + .../polybench__fixed__medium/trmm/src/trmm.h | 12 + .../polybench__fixed__mini/2mm/src/2mm.cpp | 42 + .../polybench__fixed__mini/2mm/src/2mm.h | 16 + .../polybench__fixed__mini/3mm/src/3mm.cpp | 52 + .../polybench__fixed__mini/3mm/src/3mm.h | 16 + .../polybench__fixed__mini/atax/src/atax.cpp | 32 + .../polybench__fixed__mini/atax/src/atax.h | 13 + .../polybench__fixed__mini/bicg/src/bicg.cpp | 34 + .../polybench__fixed__mini/bicg/src/bicg.h | 14 + .../cholesky/src/cholesky.cpp | 33 + .../cholesky/src/cholesky.h | 10 + .../correlation/src/correlation.cpp | 68 + .../correlation/src/correlation.h | 14 + .../covariance/src/covariance.cpp | 43 + .../covariance/src/covariance.h | 13 + .../doitgen/src/doitgen.cpp | 32 + .../doitgen/src/doitgen.h | 12 + .../durbin/src/durbin.cpp | 44 + .../durbin/src/durbin.h | 11 + .../fdtd-2d/src/fdtd-2d.cpp | 41 + .../fdtd-2d/src/fdtd-2d.h | 15 + .../floyd-warshall/src/floyd-warshall.cpp | 24 + .../floyd-warshall/src/floyd-warshall.h | 9 + .../polybench__fixed__mini/gemm/src/gemm.cpp | 31 + .../polybench__fixed__mini/gemm/src/gemm.h | 14 + .../gemver/src/gemver.cpp | 43 + .../gemver/src/gemver.h | 20 + .../gesummv/src/gesummv.cpp | 35 + .../gesummv/src/gesummv.h | 16 + .../gramschmidt/src/gramschmidt.cpp | 44 + .../gramschmidt/src/gramschmidt.h | 12 + .../heat-3d/src/heat-3d.cpp | 43 + .../heat-3d/src/heat-3d.h | 12 + .../jacobi-1d/src/jacobi-1d.cpp | 28 + .../jacobi-1d/src/jacobi-1d.h | 12 + .../jacobi-2d/src/jacobi-2d.cpp | 30 + .../jacobi-2d/src/jacobi-2d.h | 12 + .../polybench__fixed__mini/lu/src/lu.cpp | 30 + .../polybench__fixed__mini/lu/src/lu.h | 10 + .../ludcmp/src/ludcmp.cpp | 53 + .../ludcmp/src/ludcmp.h | 13 + .../polybench__fixed__mini/mvt/src/mvt.cpp | 28 + .../polybench__fixed__mini/mvt/src/mvt.h | 14 + .../nussinov/src/nussinov.cpp | 39 + .../nussinov/src/nussinov.h | 9 + .../seidel-2d/src/seidel-2d.cpp | 26 + .../seidel-2d/src/seidel-2d.h | 11 + .../polybench__fixed__mini/symm/src/symm.cpp | 33 + .../polybench__fixed__mini/symm/src/symm.h | 14 + .../syr2k/src/syr2k.cpp | 31 + .../polybench__fixed__mini/syr2k/src/syr2k.h | 14 + .../polybench__fixed__mini/syrk/src/syrk.cpp | 29 + .../polybench__fixed__mini/syrk/src/syrk.h | 13 + .../trisolv/src/trisolv.cpp | 27 + .../trisolv/src/trisolv.h | 12 + .../polybench__fixed__mini/trmm/src/trmm.cpp | 26 + .../polybench__fixed__mini/trmm/src/trmm.h | 12 + .../polybench__fixed__small/2mm/src/2mm.cpp | 42 + .../polybench__fixed__small/2mm/src/2mm.h | 16 + .../polybench__fixed__small/3mm/src/3mm.cpp | 52 + .../polybench__fixed__small/3mm/src/3mm.h | 16 + .../polybench__fixed__small/atax/src/atax.cpp | 32 + .../polybench__fixed__small/atax/src/atax.h | 13 + .../polybench__fixed__small/bicg/src/bicg.cpp | 34 + .../polybench__fixed__small/bicg/src/bicg.h | 14 + .../cholesky/src/cholesky.cpp | 33 + .../cholesky/src/cholesky.h | 10 + .../correlation/src/correlation.cpp | 68 + .../correlation/src/correlation.h | 14 + .../covariance/src/covariance.cpp | 43 + .../covariance/src/covariance.h | 13 + .../doitgen/src/doitgen.cpp | 32 + .../doitgen/src/doitgen.h | 12 + .../durbin/src/durbin.cpp | 44 + .../durbin/src/durbin.h | 11 + .../fdtd-2d/src/fdtd-2d.cpp | 41 + .../fdtd-2d/src/fdtd-2d.h | 15 + .../floyd-warshall/src/floyd-warshall.cpp | 24 + .../floyd-warshall/src/floyd-warshall.h | 9 + .../polybench__fixed__small/gemm/src/gemm.cpp | 31 + .../polybench__fixed__small/gemm/src/gemm.h | 14 + .../gemver/src/gemver.cpp | 43 + .../gemver/src/gemver.h | 20 + .../gesummv/src/gesummv.cpp | 35 + .../gesummv/src/gesummv.h | 16 + .../gramschmidt/src/gramschmidt.cpp | 44 + .../gramschmidt/src/gramschmidt.h | 12 + .../heat-3d/src/heat-3d.cpp | 43 + .../heat-3d/src/heat-3d.h | 12 + .../jacobi-1d/src/jacobi-1d.cpp | 28 + .../jacobi-1d/src/jacobi-1d.h | 12 + .../jacobi-2d/src/jacobi-2d.cpp | 30 + .../jacobi-2d/src/jacobi-2d.h | 12 + .../polybench__fixed__small/lu/src/lu.cpp | 30 + .../polybench__fixed__small/lu/src/lu.h | 10 + .../ludcmp/src/ludcmp.cpp | 53 + .../ludcmp/src/ludcmp.h | 13 + .../polybench__fixed__small/mvt/src/mvt.cpp | 28 + .../polybench__fixed__small/mvt/src/mvt.h | 14 + .../nussinov/src/nussinov.cpp | 39 + .../nussinov/src/nussinov.h | 9 + .../seidel-2d/src/seidel-2d.cpp | 26 + .../seidel-2d/src/seidel-2d.h | 11 + .../polybench__fixed__small/symm/src/symm.cpp | 33 + .../polybench__fixed__small/symm/src/symm.h | 14 + .../syr2k/src/syr2k.cpp | 31 + .../polybench__fixed__small/syr2k/src/syr2k.h | 14 + .../polybench__fixed__small/syrk/src/syrk.cpp | 29 + .../polybench__fixed__small/syrk/src/syrk.h | 13 + .../trisolv/src/trisolv.cpp | 27 + .../trisolv/src/trisolv.h | 12 + .../polybench__fixed__small/trmm/src/trmm.cpp | 26 + .../polybench__fixed__small/trmm/src/trmm.h | 12 + .../polybench__float__medium/2mm/src/2mm.cpp | 38 + .../polybench__float__medium/2mm/src/2mm.h | 14 + .../polybench__float__medium/3mm/src/3mm.cpp | 48 + .../polybench__float__medium/3mm/src/3mm.h | 14 + .../atax/src/atax.cpp | 28 + .../polybench__float__medium/atax/src/atax.h | 11 + .../bicg/src/bicg.cpp | 30 + .../polybench__float__medium/bicg/src/bicg.h | 12 + .../cholesky/src/cholesky.cpp | 29 + .../cholesky/src/cholesky.h | 8 + .../correlation/src/correlation.cpp | 64 + .../correlation/src/correlation.h | 12 + .../covariance/src/covariance.cpp | 39 + .../covariance/src/covariance.h | 11 + .../doitgen/src/doitgen.cpp | 28 + .../doitgen/src/doitgen.h | 10 + .../durbin/src/durbin.cpp | 40 + .../durbin/src/durbin.h | 9 + .../fdtd-2d/src/fdtd-2d.cpp | 37 + .../fdtd-2d/src/fdtd-2d.h | 13 + .../floyd-warshall/src/floyd-warshall.cpp | 21 + .../floyd-warshall/src/floyd-warshall.h | 8 + .../gemm/src/gemm.cpp | 27 + .../polybench__float__medium/gemm/src/gemm.h | 12 + .../gemver/src/gemver.cpp | 39 + .../gemver/src/gemver.h | 18 + .../gesummv/src/gesummv.cpp | 31 + .../gesummv/src/gesummv.h | 14 + .../gramschmidt/src/gramschmidt.cpp | 36 + .../gramschmidt/src/gramschmidt.h | 10 + .../heat-3d/src/heat-3d.cpp | 39 + .../heat-3d/src/heat-3d.h | 10 + .../jacobi-1d/src/jacobi-1d.cpp | 24 + .../jacobi-1d/src/jacobi-1d.h | 10 + .../jacobi-2d/src/jacobi-2d.cpp | 26 + .../jacobi-2d/src/jacobi-2d.h | 10 + .../polybench__float__medium/lu/src/lu.cpp | 26 + .../polybench__float__medium/lu/src/lu.h | 8 + .../ludcmp/src/ludcmp.cpp | 49 + .../ludcmp/src/ludcmp.h | 11 + .../polybench__float__medium/mvt/src/mvt.cpp | 24 + .../polybench__float__medium/mvt/src/mvt.h | 12 + .../nussinov/src/nussinov.cpp | 35 + .../nussinov/src/nussinov.h | 8 + .../seidel-2d/src/seidel-2d.cpp | 22 + .../seidel-2d/src/seidel-2d.h | 9 + .../symm/src/symm.cpp | 29 + .../polybench__float__medium/symm/src/symm.h | 12 + .../syr2k/src/syr2k.cpp | 27 + .../syr2k/src/syr2k.h | 12 + .../syrk/src/syrk.cpp | 25 + .../polybench__float__medium/syrk/src/syrk.h | 11 + .../trisolv/src/trisolv.cpp | 23 + .../trisolv/src/trisolv.h | 10 + .../trmm/src/trmm.cpp | 22 + .../polybench__float__medium/trmm/src/trmm.h | 10 + .../polybench__float__mini/2mm/src/2mm.cpp | 38 + .../polybench__float__mini/2mm/src/2mm.h | 14 + .../polybench__float__mini/3mm/src/3mm.cpp | 48 + .../polybench__float__mini/3mm/src/3mm.h | 14 + .../polybench__float__mini/atax/src/atax.cpp | 28 + .../polybench__float__mini/atax/src/atax.h | 11 + .../polybench__float__mini/bicg/src/bicg.cpp | 30 + .../polybench__float__mini/bicg/src/bicg.h | 12 + .../cholesky/src/cholesky.cpp | 29 + .../cholesky/src/cholesky.h | 8 + .../correlation/src/correlation.cpp | 64 + .../correlation/src/correlation.h | 12 + .../covariance/src/covariance.cpp | 39 + .../covariance/src/covariance.h | 11 + .../doitgen/src/doitgen.cpp | 28 + .../doitgen/src/doitgen.h | 10 + .../durbin/src/durbin.cpp | 40 + .../durbin/src/durbin.h | 9 + .../fdtd-2d/src/fdtd-2d.cpp | 37 + .../fdtd-2d/src/fdtd-2d.h | 13 + .../floyd-warshall/src/floyd-warshall.cpp | 21 + .../floyd-warshall/src/floyd-warshall.h | 8 + .../polybench__float__mini/gemm/src/gemm.cpp | 27 + .../polybench__float__mini/gemm/src/gemm.h | 12 + .../gemver/src/gemver.cpp | 39 + .../gemver/src/gemver.h | 18 + .../gesummv/src/gesummv.cpp | 31 + .../gesummv/src/gesummv.h | 14 + .../gramschmidt/src/gramschmidt.cpp | 36 + .../gramschmidt/src/gramschmidt.h | 10 + .../heat-3d/src/heat-3d.cpp | 39 + .../heat-3d/src/heat-3d.h | 10 + .../jacobi-1d/src/jacobi-1d.cpp | 24 + .../jacobi-1d/src/jacobi-1d.h | 10 + .../jacobi-2d/src/jacobi-2d.cpp | 26 + .../jacobi-2d/src/jacobi-2d.h | 10 + .../polybench__float__mini/lu/src/lu.cpp | 26 + .../polybench__float__mini/lu/src/lu.h | 8 + .../ludcmp/src/ludcmp.cpp | 49 + .../ludcmp/src/ludcmp.h | 11 + .../polybench__float__mini/mvt/src/mvt.cpp | 24 + .../polybench__float__mini/mvt/src/mvt.h | 12 + .../nussinov/src/nussinov.cpp | 35 + .../nussinov/src/nussinov.h | 8 + .../seidel-2d/src/seidel-2d.cpp | 22 + .../seidel-2d/src/seidel-2d.h | 9 + .../polybench__float__mini/symm/src/symm.cpp | 29 + .../polybench__float__mini/symm/src/symm.h | 12 + .../syr2k/src/syr2k.cpp | 27 + .../polybench__float__mini/syr2k/src/syr2k.h | 12 + .../polybench__float__mini/syrk/src/syrk.cpp | 25 + .../polybench__float__mini/syrk/src/syrk.h | 11 + .../trisolv/src/trisolv.cpp | 23 + .../trisolv/src/trisolv.h | 10 + .../polybench__float__mini/trmm/src/trmm.cpp | 22 + .../polybench__float__mini/trmm/src/trmm.h | 10 + .../polybench__float__small/2mm/src/2mm.cpp | 38 + .../polybench__float__small/2mm/src/2mm.h | 14 + .../polybench__float__small/3mm/src/3mm.cpp | 48 + .../polybench__float__small/3mm/src/3mm.h | 14 + .../polybench__float__small/atax/src/atax.cpp | 28 + .../polybench__float__small/atax/src/atax.h | 11 + .../polybench__float__small/bicg/src/bicg.cpp | 30 + .../polybench__float__small/bicg/src/bicg.h | 12 + .../cholesky/src/cholesky.cpp | 29 + .../cholesky/src/cholesky.h | 8 + .../correlation/src/correlation.cpp | 64 + .../correlation/src/correlation.h | 12 + .../covariance/src/covariance.cpp | 39 + .../covariance/src/covariance.h | 11 + .../doitgen/src/doitgen.cpp | 28 + .../doitgen/src/doitgen.h | 10 + .../durbin/src/durbin.cpp | 40 + .../durbin/src/durbin.h | 9 + .../fdtd-2d/src/fdtd-2d.cpp | 37 + .../fdtd-2d/src/fdtd-2d.h | 13 + .../floyd-warshall/src/floyd-warshall.cpp | 21 + .../floyd-warshall/src/floyd-warshall.h | 8 + .../polybench__float__small/gemm/src/gemm.cpp | 27 + .../polybench__float__small/gemm/src/gemm.h | 12 + .../gemver/src/gemver.cpp | 39 + .../gemver/src/gemver.h | 18 + .../gesummv/src/gesummv.cpp | 31 + .../gesummv/src/gesummv.h | 14 + .../gramschmidt/src/gramschmidt.cpp | 36 + .../gramschmidt/src/gramschmidt.h | 10 + .../heat-3d/src/heat-3d.cpp | 39 + .../heat-3d/src/heat-3d.h | 10 + .../jacobi-1d/src/jacobi-1d.cpp | 24 + .../jacobi-1d/src/jacobi-1d.h | 10 + .../jacobi-2d/src/jacobi-2d.cpp | 26 + .../jacobi-2d/src/jacobi-2d.h | 10 + .../polybench__float__small/lu/src/lu.cpp | 26 + .../polybench__float__small/lu/src/lu.h | 8 + .../ludcmp/src/ludcmp.cpp | 49 + .../ludcmp/src/ludcmp.h | 11 + .../polybench__float__small/mvt/src/mvt.cpp | 24 + .../polybench__float__small/mvt/src/mvt.h | 12 + .../nussinov/src/nussinov.cpp | 35 + .../nussinov/src/nussinov.h | 8 + .../seidel-2d/src/seidel-2d.cpp | 22 + .../seidel-2d/src/seidel-2d.h | 9 + .../polybench__float__small/symm/src/symm.cpp | 29 + .../polybench__float__small/symm/src/symm.h | 12 + .../syr2k/src/syr2k.cpp | 27 + .../polybench__float__small/syr2k/src/syr2k.h | 12 + .../polybench__float__small/syrk/src/syrk.cpp | 25 + .../polybench__float__small/syrk/src/syrk.h | 11 + .../trisolv/src/trisolv.cpp | 23 + .../trisolv/src/trisolv.h | 10 + .../polybench__float__small/trmm/src/trmm.cpp | 22 + .../polybench__float__small/trmm/src/trmm.h | 10 + .../2mm/src/2mm.cpp | 38 + .../2mm/src/2mm.h | 14 + .../3mm/src/3mm.cpp | 48 + .../3mm/src/3mm.h | 14 + .../atax/src/atax.cpp | 28 + .../atax/src/atax.h | 11 + .../bicg/src/bicg.cpp | 30 + .../bicg/src/bicg.h | 12 + .../cholesky/src/cholesky.cpp | 29 + .../cholesky/src/cholesky.h | 8 + .../correlation/src/correlation.cpp | 64 + .../correlation/src/correlation.h | 12 + .../covariance/src/covariance.cpp | 39 + .../covariance/src/covariance.h | 11 + .../doitgen/src/doitgen.cpp | 28 + .../doitgen/src/doitgen.h | 10 + .../durbin/src/durbin.cpp | 40 + .../durbin/src/durbin.h | 9 + .../fdtd-2d/src/fdtd-2d.cpp | 37 + .../fdtd-2d/src/fdtd-2d.h | 13 + .../floyd-warshall/src/floyd-warshall.cpp | 21 + .../floyd-warshall/src/floyd-warshall.h | 8 + .../gemm/src/gemm.cpp | 27 + .../gemm/src/gemm.h | 12 + .../gemver/src/gemver.cpp | 39 + .../gemver/src/gemver.h | 18 + .../gesummv/src/gesummv.cpp | 31 + .../gesummv/src/gesummv.h | 14 + .../gramschmidt/src/gramschmidt.cpp | 36 + .../gramschmidt/src/gramschmidt.h | 10 + .../heat-3d/src/heat-3d.cpp | 39 + .../heat-3d/src/heat-3d.h | 10 + .../jacobi-1d/src/jacobi-1d.cpp | 24 + .../jacobi-1d/src/jacobi-1d.h | 10 + .../jacobi-2d/src/jacobi-2d.cpp | 26 + .../jacobi-2d/src/jacobi-2d.h | 10 + .../lu/src/lu.cpp | 26 + .../lu/src/lu.h | 8 + .../ludcmp/src/ludcmp.cpp | 49 + .../ludcmp/src/ludcmp.h | 11 + .../mvt/src/mvt.cpp | 24 + .../mvt/src/mvt.h | 12 + .../nussinov/src/nussinov.cpp | 35 + .../nussinov/src/nussinov.h | 8 + .../seidel-2d/src/seidel-2d.cpp | 22 + .../seidel-2d/src/seidel-2d.h | 9 + .../symm/src/symm.cpp | 29 + .../symm/src/symm.h | 12 + .../syr2k/src/syr2k.cpp | 27 + .../syr2k/src/syr2k.h | 12 + .../syrk/src/syrk.cpp | 25 + .../syrk/src/syrk.h | 11 + .../trisolv/src/trisolv.cpp | 23 + .../trisolv/src/trisolv.h | 10 + .../trmm/src/trmm.cpp | 22 + .../trmm/src/trmm.h | 10 + .../23_pp4fpgas_unoptimized_fft/fft.h | 19 + .../23_pp4fpgas_unoptimized_fft/fft_sw.cpp | 76 + .../23_pp4fpgas_unoptimized_fft/tw_i.h | 33 + .../23_pp4fpgas_unoptimized_fft/tw_r.h | 33 + .../fft_stages.cpp | 72 + .../fft_streaming.h | 19 + .../24_pp4fpgas_multi_stage_fft/tw_i.h | 33 + .../24_pp4fpgas_multi_stage_fft/tw_r.h | 33 + .../25_pp4fpgas_huffman_encoding/huffman.h | 90 + .../huffman_canonize_tree.cpp | 35 + .../huffman_compute_bit_length.cpp | 42 + .../huffman_create_codeword.cpp | 39 + .../huffman_create_tree.cpp | 59 + .../huffman_encoding.cpp | 59 + .../huffman_filter.cpp | 18 + .../huffman_sort.cpp | 57 + .../huffman_truncate_tree.cpp | 50 + .../matrixmultiplication.cpp | 21 + .../26_pp4fpgas_matmul/matrixmultiplication.h | 11 + .../merge_sort_parallel.cpp | 52 + .../merge_sort_parallel.h | 4 + .../rosetta/3d-rendering/src/host/typedefs.h | 87 + .../3d-rendering/src/sdsoc/rendering.cpp | 346 + .../3d-rendering/src/sdsoc/rendering.h | 18 + .../Inputs/rosetta/BNN/cpp/accel/Accel.cpp | 854 + .../Inputs/rosetta/BNN/cpp/accel/Accel.h | 116 + .../Inputs/rosetta/BNN/cpp/accel/AccelPrint.h | 73 + .../rosetta/BNN/cpp/accel/AccelSchedule.h | 67 + .../Inputs/rosetta/BNN/cpp/accel/AccelTest.h | 91 + .../Inputs/rosetta/BNN/cpp/accel/Dense.h | 27 + .../Inputs/rosetta/BNN/cpp/accel/InputConv.h | 17 + .../Inputs/rosetta/BNN/cpp/utils/Common.h | 21 + .../Inputs/rosetta/BNN/cpp/utils/Debug.h | 26 + .../Inputs/rosetta/BNN/cpp/utils/Typedefs.h | 39 + .../digit-recognition/src/host/typedefs.h | 40 + .../digit-recognition/src/sdsoc/digitrec.cpp | 225 + .../digit-recognition/src/sdsoc/digitrec.h | 14 + .../face-detection/src/host/typedefs.h | 80 + .../face-detection/src/sdsoc/face_detect.cpp | 3441 ++ .../sdsoc/haar_dataEWC_with_partitioning.h | 18 + .../sdsoc/haar_dataRcc_with_partitioning.h | 42 + .../face-detection/src/sdsoc/haar_mapping.h | 6 + .../src/sdsoc__origin/face_detect_origin.cpp | 3441 ++ .../haar_dataEWC_with_partitioning.h | 18 + .../haar_dataRcc_with_partitioning.h | 42 + .../src/sdsoc__origin/haar_mapping.h | 6 + .../rosetta/optical-flow/src/host/typedefs.h | 58 + .../optical-flow/src/sdsoc/optical_flow.h | 24 + .../src/sdsoc/optical_flow_original.cpp | 475 + .../src/sdsoc__hls_template/optical_flow.cpp | 475 + .../src/sdsoc__hls_template/optical_flow.h | 24 + .../rosetta/spam-filter/src/host/typedefs.h | 84 + .../rosetta/spam-filter/src/sdsoc/lut.h | 2060 ++ .../rosetta/spam-filter/src/sdsoc/sgd.cpp | 202 + .../rosetta/spam-filter/src/sdsoc/sgd.h | 24 + .../Inputs/soda/soda__blur/blur.cpp | 1492 + .../Inputs/soda/soda__contrast/contrast.cpp | 5080 +++ .../Inputs/soda/soda__denoise2d/denoise2d.cpp | 1891 ++ .../Inputs/soda/soda__denoise3d/denoise3d.cpp | 1555 + .../Inputs/soda/soda__erosion/erosion.cpp | 2035 ++ .../Inputs/soda/soda__heat3d/heat3d.cpp | 787 + .../Inputs/soda/soda__jacobi2d/jacobi2d.cpp | 654 + .../Inputs/soda/soda__jacobi3d/jacobi3d.cpp | 787 + .../Inputs/soda/soda__seidel2d/seidel2d.cpp | 796 + .../Inputs/soda/soda__sobel2d/sobel2d.cpp | 1221 + .../Inputs/soda/soda__xcorr/xcorr.cpp | 2314 ++ .../hlsfactory/Inputs/spector_hls/dct/dct.cpp | 59 + .../Inputs/spector_hls/dct/params.h | 5 + .../Inputs/spector_hls/fir/fir_hls.cpp | 298 + .../Inputs/spector_hls/fir/fir_hls.h | 27 + .../Inputs/spector_hls/fir/params.h | 60 + .../spector_hls/histogram/histogram.cpp | 325 + .../Inputs/spector_hls/histogram/params.h | 69 + .../matrix_multiplication/matrix_mul.cpp | 16 + .../matrix_multiplication/matrix_mul.h | 10 + .../matrix_multiplication/params.h | 8 + .../spector_hls/mergesort/mergesort.cpp | 62 + .../Inputs/spector_hls/mergesort/params.h | 18 + .../Inputs/spector_hls/normals/normals.cpp | 95 + .../Inputs/spector_hls/normals/params.h | 12 + .../spector_hls/sobel_filter_x/params.h | 16 + .../Inputs/spector_hls/sobel_filter_x/sobel.h | 4 + .../sobel_filter_x/sobel_subdimx.cpp | 81 + .../spector_hls/sobel_filter_y/params.h | 16 + .../Inputs/spector_hls/sobel_filter_y/sobel.h | 4 + .../sobel_filter_y/sobel_subdimy.cpp | 82 + .../Inputs/spector_hls/spmv/params.h | 24 + .../Inputs/spector_hls/spmv/spmv.cpp | 69 + .../template_matching/fpga_temp_match.cpp | 82 + .../template_matching/fpga_temp_matching.h | 22 + .../spector_hls/template_matching/params.h | 20 + .../Autoencoder__opt1/src/Autoencoder.cpp | 562 + .../Autoencoder__opt2/src/Autoencoder.cpp | 558 + .../Autoencoder__opt3/src/Autoencoder.cpp | 650 + .../Autoencoder__opt4/src/Autoencoder.cpp | 646 + .../Autoencoder__opt5/src/Autoencoder.cpp | 738 + .../src/DepthwiseSeparableConvBlock.cpp | 134 + .../src/DepthwiseSeparableConvBlock.cpp | 189 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../src/DepthwiseSeparableConvBlock.cpp | 181 + .../FeedForward__opt1/src/FeedForward.cpp | 229 + .../FeedForward__opt2/src/FeedForward.cpp | 231 + .../FeedForward__opt3/src/FeedForward.cpp | 333 + .../FeedForward__opt4/src/FeedForward.cpp | 317 + .../FeedForward__opt5/src/FeedForward.cpp | 305 + .../src/MultiHeadSelfAttention1.cpp | 734 + .../src/MultiHeadSelfAttention1.cpp | 738 + .../src/MultiHeadSelfAttention1.cpp | 1107 + .../src/MultiHeadSelfAttention1.cpp | 1064 + .../src/MultiHeadSelfAttention1.cpp | 1086 + .../stream_hls/ResMLP__opt1/src/ResMLP.cpp | 406 + .../stream_hls/ResMLP__opt2/src/ResMLP.cpp | 405 + .../stream_hls/ResMLP__opt3/src/ResMLP.cpp | 470 + .../stream_hls/ResMLP__opt4/src/ResMLP.cpp | 469 + .../stream_hls/ResMLP__opt5/src/ResMLP.cpp | 517 + .../ResidualBlock__opt1/src/ResidualBlock.cpp | 176 + .../ResidualBlock__opt2/src/ResidualBlock.cpp | 262 + .../ResidualBlock__opt3/src/ResidualBlock.cpp | 249 + .../ResidualBlock__opt4/src/ResidualBlock.cpp | 249 + .../ResidualBlock__opt5/src/ResidualBlock.cpp | 249 + .../Inputs/stream_hls/atax__opt1/src/atax.cpp | 125 + .../Inputs/stream_hls/atax__opt2/src/atax.cpp | 126 + .../Inputs/stream_hls/atax__opt3/src/atax.cpp | 171 + .../Inputs/stream_hls/atax__opt4/src/atax.cpp | 163 + .../Inputs/stream_hls/atax__opt5/src/atax.cpp | 163 + .../Inputs/stream_hls/bicg__opt1/src/bicg.cpp | 120 + .../Inputs/stream_hls/bicg__opt2/src/bicg.cpp | 120 + .../Inputs/stream_hls/bicg__opt3/src/bicg.cpp | 164 + .../Inputs/stream_hls/bicg__opt4/src/bicg.cpp | 164 + .../Inputs/stream_hls/bicg__opt5/src/bicg.cpp | 164 + .../Inputs/stream_hls/gemm__opt1/src/gemm.cpp | 102 + .../Inputs/stream_hls/gemm__opt2/src/gemm.cpp | 102 + .../Inputs/stream_hls/gemm__opt3/src/gemm.cpp | 143 + .../Inputs/stream_hls/gemm__opt4/src/gemm.cpp | 143 + .../Inputs/stream_hls/gemm__opt5/src/gemm.cpp | 143 + .../stream_hls/gesummv__opt1/src/gesummv.cpp | 128 + .../stream_hls/gesummv__opt2/src/gesummv.cpp | 128 + .../stream_hls/gesummv__opt3/src/gesummv.cpp | 166 + .../stream_hls/gesummv__opt4/src/gesummv.cpp | 166 + .../stream_hls/gesummv__opt5/src/gesummv.cpp | 166 + .../Inputs/stream_hls/k2mm__opt1/src/k2mm.cpp | 142 + .../Inputs/stream_hls/k2mm__opt2/src/k2mm.cpp | 142 + .../Inputs/stream_hls/k2mm__opt3/src/k2mm.cpp | 201 + .../Inputs/stream_hls/k2mm__opt4/src/k2mm.cpp | 201 + .../Inputs/stream_hls/k2mm__opt5/src/k2mm.cpp | 201 + .../Inputs/stream_hls/k3mm__opt1/src/k3mm.cpp | 154 + .../Inputs/stream_hls/k3mm__opt2/src/k3mm.cpp | 145 + .../Inputs/stream_hls/k3mm__opt3/src/k3mm.cpp | 226 + .../Inputs/stream_hls/k3mm__opt4/src/k3mm.cpp | 222 + .../Inputs/stream_hls/k3mm__opt5/src/k3mm.cpp | 222 + .../src/k7mmseq_balanced.cpp | 315 + .../src/k7mmseq_balanced.cpp | 315 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_balanced.cpp | 454 + .../src/k7mmseq_unbalanced.cpp | 315 + .../src/k7mmseq_unbalanced.cpp | 315 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmseq_unbalanced.cpp | 449 + .../src/k7mmtree_balanced.cpp | 454 + .../src/k7mmtree_unbalanced.cpp | 445 + .../Inputs/stream_hls/mvt__opt1/src/mvt.cpp | 137 + .../Inputs/stream_hls/mvt__opt2/src/mvt.cpp | 138 + .../Inputs/stream_hls/mvt__opt3/src/mvt.cpp | 194 + .../Inputs/stream_hls/mvt__opt4/src/mvt.cpp | 186 + .../Inputs/stream_hls/mvt__opt5/src/mvt.cpp | 186 + .../fxp_sqrt.h | 104 + .../fxp_sqrt_top.cpp | 26 + .../fxp_sqrt_top.h | 36 + .../cpp_FIR.cpp | 28 + .../cpp_FIR.h | 88 + .../cpp_FIR.inc | 85 + .../window_fn_class.h | 109 + .../window_fn_top.cpp | 39 + .../window_fn_top.h | 45 + .../window_fn_class.h | 110 + .../window_fn_top.cpp | 39 + .../window_fn_top.h | 36 + .../cpp_ap_int_arith.cpp | 29 + .../cpp_ap_int_arith.h | 48 + .../loop_functions.cpp | 37 + .../loop_functions.h | 33 + .../loop_imperfect.cpp | 35 + .../loop_imperfect.h | 34 + .../loop_max_bounds.cpp | 31 + .../loop_max_bounds.h | 34 + .../loop_perfect.cpp | 35 + .../loop_perfect.h | 34 + .../loop_pipeline.cpp | 31 + .../loop_pipeline.h | 34 + .../loop_sequential.cpp | 35 + .../loop_sequential.h | 34 + .../loop_sequential_assert.cpp | 36 + .../loop_sequential_assert.h | 35 + .../loop_sequential.cpp | 38 + .../loop_sequential.h | 34 + .../malloc_removed.c | 139 + .../malloc_removed.h | 30 + .../pointer_cast_native.c | 123 + .../pointer_cast_native.h | 30 + .../pointer_double.c | 46 + .../pointer_double.h | 28 + .../example.cpp | 44 + .../example.cpp | 27 + .../mem_bottleneck.cpp | 28 + .../mem_bottleneck.h | 33 + .../mem_bottleneck_resolved.cpp | 35 + .../mem_bottleneck_resolved.h | 32 + .../ecc_flags.cpp | 57 + .../ecc_flags.h | 21 + .../hamming_window.c | 52 + .../hamming_window.h | 45 + .../vadd.cpp | 143 + .../Inputs/whetstone/whetstone/kernel.cpp | 270 + tools/cgeist/Test/HLS/hlsfactory/SUMMARY.md | 4581 +++ .../WIP__stream_hls__Autoencoder__opt1.test | 85 + .../WIP__stream_hls__Autoencoder__opt2.test | 81 + .../WIP__stream_hls__Autoencoder__opt3.test | 85 + .../WIP__stream_hls__Autoencoder__opt4.test | 81 + .../WIP__stream_hls__Autoencoder__opt5.test | 128 + ...ls__DepthwiseSeparableConvBlock__opt1.test | 36 + ...ls__DepthwiseSeparableConvBlock__opt2.test | 25 + ...ls__DepthwiseSeparableConvBlock__opt3.test | 39 + ...ls__DepthwiseSeparableConvBlock__opt4.test | 39 + ...ls__DepthwiseSeparableConvBlock__opt5.test | 39 + .../WIP__stream_hls__FeedForward__opt1.test | 39 + .../WIP__stream_hls__FeedForward__opt2.test | 41 + .../WIP__stream_hls__FeedForward__opt3.test | 83 + .../WIP__stream_hls__FeedForward__opt4.test | 73 + .../WIP__stream_hls__FeedForward__opt5.test | 63 + ...am_hls__MultiHeadSelfAttention1__opt1.test | 110 + ...am_hls__MultiHeadSelfAttention1__opt2.test | 114 + ...am_hls__MultiHeadSelfAttention1__opt3.test | 270 + ...am_hls__MultiHeadSelfAttention1__opt4.test | 242 + ...am_hls__MultiHeadSelfAttention1__opt5.test | 258 + .../WIP/WIP__stream_hls__ResMLP__opt1.test | 67 + .../WIP/WIP__stream_hls__ResMLP__opt2.test | 66 + .../WIP/WIP__stream_hls__ResMLP__opt3.test | 67 + .../WIP/WIP__stream_hls__ResMLP__opt4.test | 66 + .../WIP/WIP__stream_hls__ResMLP__opt5.test | 88 + .../WIP__stream_hls__ResidualBlock__opt1.test | 45 + .../WIP__stream_hls__ResidualBlock__opt2.test | 32 + .../WIP__stream_hls__ResidualBlock__opt3.test | 50 + .../WIP__stream_hls__ResidualBlock__opt4.test | 50 + .../WIP__stream_hls__ResidualBlock__opt5.test | 50 + ..._processed_dataset__Autoencoder__opt1.test | 85 + ..._processed_dataset__Autoencoder__opt2.test | 81 + ..._processed_dataset__Autoencoder__opt3.test | 85 + ..._processed_dataset__Autoencoder__opt4.test | 81 + ..._processed_dataset__Autoencoder__opt5.test | 128 + ...et__DepthwiseSeparableConvBlock__opt1.test | 36 + ...et__DepthwiseSeparableConvBlock__opt2.test | 25 + ...et__DepthwiseSeparableConvBlock__opt3.test | 39 + ...et__DepthwiseSeparableConvBlock__opt4.test | 39 + ...et__DepthwiseSeparableConvBlock__opt5.test | 39 + ..._processed_dataset__FeedForward__opt1.test | 39 + ..._processed_dataset__FeedForward__opt2.test | 41 + ..._processed_dataset__FeedForward__opt3.test | 83 + ..._processed_dataset__FeedForward__opt4.test | 73 + ..._processed_dataset__FeedForward__opt5.test | 63 + ...ataset__MultiHeadSelfAttention1__opt1.test | 110 + ...ataset__MultiHeadSelfAttention1__opt2.test | 114 + ...ataset__MultiHeadSelfAttention1__opt3.test | 270 + ...ataset__MultiHeadSelfAttention1__opt4.test | 242 + ...ataset__MultiHeadSelfAttention1__opt5.test | 258 + ...______processed_dataset__ResMLP__opt1.test | 67 + ...______processed_dataset__ResMLP__opt2.test | 66 + ...______processed_dataset__ResMLP__opt3.test | 67 + ...______processed_dataset__ResMLP__opt4.test | 66 + ...______processed_dataset__ResMLP__opt5.test | 88 + ...rocessed_dataset__ResidualBlock__opt1.test | 45 + ...rocessed_dataset__ResidualBlock__opt2.test | 32 + ...rocessed_dataset__ResidualBlock__opt3.test | 50 + ...rocessed_dataset__ResidualBlock__opt4.test | 50 + ...rocessed_dataset__ResidualBlock__opt5.test | 50 + ...ls______processed_dataset__atax__opt1.test | 24 + ...ls______processed_dataset__atax__opt2.test | 25 + ...ls______processed_dataset__atax__opt3.test | 43 + ...ls______processed_dataset__atax__opt4.test | 38 + ...ls______processed_dataset__atax__opt5.test | 38 + ...ls______processed_dataset__bicg__opt1.test | 23 + ...ls______processed_dataset__bicg__opt2.test | 23 + ...ls______processed_dataset__bicg__opt3.test | 41 + ...ls______processed_dataset__bicg__opt4.test | 41 + ...ls______processed_dataset__bicg__opt5.test | 41 + ...ls______processed_dataset__gemm__opt1.test | 21 + ...ls______processed_dataset__gemm__opt2.test | 21 + ...ls______processed_dataset__gemm__opt3.test | 39 + ...ls______processed_dataset__gemm__opt4.test | 39 + ...ls______processed_dataset__gemm__opt5.test | 39 + ..._____processed_dataset__gesummv__opt1.test | 25 + ..._____processed_dataset__gesummv__opt2.test | 25 + ..._____processed_dataset__gesummv__opt3.test | 40 + ..._____processed_dataset__gesummv__opt4.test | 40 + ..._____processed_dataset__gesummv__opt5.test | 40 + ...ls______processed_dataset__k2mm__opt1.test | 25 + ...ls______processed_dataset__k2mm__opt2.test | 25 + ...ls______processed_dataset__k2mm__opt3.test | 51 + ...ls______processed_dataset__k2mm__opt4.test | 51 + ...ls______processed_dataset__k2mm__opt5.test | 51 + ...ls______processed_dataset__k3mm__opt1.test | 24 + ...ls______processed_dataset__k3mm__opt2.test | 25 + ...ls______processed_dataset__k3mm__opt3.test | 56 + ...ls______processed_dataset__k3mm__opt4.test | 55 + ...ls______processed_dataset__k3mm__opt5.test | 55 + ...essed_dataset__k7mmseq_balanced__opt1.test | 41 + ...essed_dataset__k7mmseq_balanced__opt2.test | 41 + ...essed_dataset__k7mmseq_balanced__opt3.test | 103 + ...essed_dataset__k7mmseq_balanced__opt4.test | 103 + ...essed_dataset__k7mmseq_balanced__opt5.test | 103 + ...sed_dataset__k7mmseq_unbalanced__opt1.test | 41 + ...sed_dataset__k7mmseq_unbalanced__opt2.test | 41 + ...sed_dataset__k7mmseq_unbalanced__opt3.test | 98 + ...sed_dataset__k7mmseq_unbalanced__opt4.test | 98 + ...sed_dataset__k7mmseq_unbalanced__opt5.test | 98 + ...ssed_dataset__k7mmtree_balanced__opt5.test | 103 + ...ed_dataset__k7mmtree_unbalanced__opt5.test | 94 + ...hls______processed_dataset__mvt__opt1.test | 26 + ...hls______processed_dataset__mvt__opt2.test | 27 + ...hls______processed_dataset__mvt__opt3.test | 50 + ...hls______processed_dataset__mvt__opt4.test | 45 + ...hls______processed_dataset__mvt__opt5.test | 45 + .../WIP/WIP__stream_hls__atax__opt1.test | 24 + .../WIP/WIP__stream_hls__atax__opt2.test | 25 + .../WIP/WIP__stream_hls__atax__opt3.test | 43 + .../WIP/WIP__stream_hls__atax__opt4.test | 38 + .../WIP/WIP__stream_hls__atax__opt5.test | 38 + .../WIP/WIP__stream_hls__bicg__opt1.test | 23 + .../WIP/WIP__stream_hls__bicg__opt2.test | 23 + .../WIP/WIP__stream_hls__bicg__opt3.test | 41 + .../WIP/WIP__stream_hls__bicg__opt4.test | 41 + .../WIP/WIP__stream_hls__bicg__opt5.test | 41 + .../WIP/WIP__stream_hls__gemm__opt1.test | 21 + .../WIP/WIP__stream_hls__gemm__opt2.test | 21 + .../WIP/WIP__stream_hls__gemm__opt3.test | 39 + .../WIP/WIP__stream_hls__gemm__opt4.test | 39 + .../WIP/WIP__stream_hls__gemm__opt5.test | 39 + .../WIP/WIP__stream_hls__gesummv__opt1.test | 25 + .../WIP/WIP__stream_hls__gesummv__opt2.test | 25 + .../WIP/WIP__stream_hls__gesummv__opt3.test | 40 + .../WIP/WIP__stream_hls__gesummv__opt4.test | 40 + .../WIP/WIP__stream_hls__gesummv__opt5.test | 40 + .../WIP/WIP__stream_hls__k15mmseq__opt5.test | 197 + ...stream_hls__k15mmseq_imbalanced__opt5.test | 147 + .../WIP__stream_hls__k15mmseq_relu__opt5.test | 264 + ...m_hls__k15mmseq_relu_imbalanced__opt5.test | 203 + .../WIP/WIP__stream_hls__k15mmtree__opt5.test | 199 + ...tream_hls__k15mmtree_imbalanced__opt5.test | 147 + ...WIP__stream_hls__k15mmtree_relu__opt5.test | 259 + ..._hls__k15mmtree_relu_imbalanced__opt5.test | 201 + .../WIP/WIP__stream_hls__k2mm__opt1.test | 25 + .../WIP/WIP__stream_hls__k2mm__opt2.test | 25 + .../WIP/WIP__stream_hls__k2mm__opt3.test | 51 + .../WIP/WIP__stream_hls__k2mm__opt4.test | 51 + .../WIP/WIP__stream_hls__k2mm__opt5.test | 51 + .../WIP/WIP__stream_hls__k3mm__opt1.test | 24 + .../WIP/WIP__stream_hls__k3mm__opt2.test | 25 + .../WIP/WIP__stream_hls__k3mm__opt3.test | 56 + .../WIP/WIP__stream_hls__k3mm__opt4.test | 55 + .../WIP/WIP__stream_hls__k3mm__opt5.test | 55 + ...P__stream_hls__k7mmseq_balanced__opt1.test | 41 + ...P__stream_hls__k7mmseq_balanced__opt2.test | 41 + ...P__stream_hls__k7mmseq_balanced__opt3.test | 103 + ...P__stream_hls__k7mmseq_balanced__opt4.test | 103 + ...P__stream_hls__k7mmseq_balanced__opt5.test | 103 + ..._stream_hls__k7mmseq_unbalanced__opt1.test | 41 + ..._stream_hls__k7mmseq_unbalanced__opt2.test | 41 + ..._stream_hls__k7mmseq_unbalanced__opt3.test | 98 + ..._stream_hls__k7mmseq_unbalanced__opt4.test | 98 + ..._stream_hls__k7mmseq_unbalanced__opt5.test | 98 + ...__stream_hls__k7mmtree_balanced__opt5.test | 103 + ...stream_hls__k7mmtree_unbalanced__opt5.test | 94 + .../WIP/WIP__stream_hls__mvt__opt1.test | 26 + .../WIP/WIP__stream_hls__mvt__opt2.test | 27 + .../WIP/WIP__stream_hls__mvt__opt3.test | 50 + .../WIP/WIP__stream_hls__mvt__opt4.test | 45 + .../WIP/WIP__stream_hls__mvt__opt5.test | 45 + .../accelerators__DGNN_Booster_EvolveGCN.test | 150 + .../accelerators__DGNN_Booster_convLSTM.test | 211 + ...rs__GP_selection_kernel_fixed_dataset.test | 192 + ...rs__GP_selection_kernel_float_dataset.test | 198 + .../accelerators__Mask-Net_dataset.test | 62 + .../accelerators__SkyNet_dataset.test | 80 + .../accelerators/accelerators__edgemoe.test | 5 + .../HLS/hlsfactory/auto_ntt/auto_ntt__BU.test | 273 + .../auto_ntt__Mmap2Stream_tf_0_1_limbs.test | 263 + .../auto_ntt/auto_ntt__NTT_kernel.test | 230 + .../auto_ntt/auto_ntt__TFBuf_wiFW_0.test | 243 + .../auto_ntt/auto_ntt__TFBuf_wiFW_1.test | 243 + .../auto_ntt/auto_ntt__TFBuf_wiFW_2.test | 243 + .../auto_ntt/auto_ntt__TFBuf_woFW_3.test | 240 + ...auto_ntt__dual_interface_FIFO_receive.test | 241 + .../auto_ntt__dual_interface_FIFO_send.test | 239 + ..._ntt__fwd_load_inv_store_poly_1_limbs.test | 668 + ..._ntt__fwd_store_inv_load_poly_1_limbs.test | 668 + .../auto_ntt__input_selector_single.test | 259 + .../auto_ntt__output_slector_single.test | 259 + .../auto_ntt/auto_ntt__shuffler_buf.test | 463 + .../auto_ntt/auto_ntt__shuffler_in.test | 439 + .../auto_ntt__shuffler_out_shift.test | 541 + .../auto_ntt__shuffler_out_shuff.test | 609 + .../HLS/hlsfactory/chstone/chstone__gsm.test | 12 + .../HLS/hlsfactory/chstone/chstone__sha.test | 16 + ..._Dehazing-denoising__source_code__src.test | 27 + ...ing__source_code__src__debayer_csynth.test | 27 + ...g-denoising__source_code__src__script.test | 5 + ...022_fall__Explainable-ML__source_code.test | 83 + ...__FLAT-acceleration__source_code__HLS.test | 86 + ...source_code__HLS__test_systolic_array.test | 65 + ...al-node__source_code__gin_vn_base_hls.test | 118 + ...l-node__source_code__gin_vn_bitstream.test | 5 + ...de__source_code__gin_vn_pipelined_hls.test | 5 + ...2_fall__Ray-tracing__source_code__HLS.test | 117 + ...l__Ray-tracing__source_code__golden_c.test | 5 + ...lo-v3-tiny__source_code__src_24Layers.test | 5 + ...source_code__src_24Layers__conv_synth.test | 5 + ...code__src_24Layers__yolov3_tiny_synth.test | 74 + ...olo-v3-tiny__source_code__src_4Layers.test | 5 + ..._source_code__src_4Layers__conv_synth.test | 5 + ..._code__src_4Layers__yolov3_tiny_synth.test | 68 + ...023_spring__Analog-CIM__hls__baseline.test | 24 + ...23_spring__Analog-CIM__hls__optimized.test | 27 + ...893_2023_spring__Analog-CIM__on-board.test | 24 + ...C_Acceleration__Golden_C__unoptimized.test | 54 + ...ing__DSC_Acceleration__HLS__optimized.test | 59 + ...spring__ECG_Classifier__HLS__Baseline.test | 57 + ...pring__ECG_Classifier__HLS__Optimized.test | 69 + .../class_ece8893_2023_spring__Eyeriss.test | 42 + ...ece8893_2023_spring__FocusedACO__FACO.test | 13 + ...FocusedACO__HLS__LocalSearchOptimized.test | 33 + ...cusedACO__HLS__LocalSearchUnoptimized.test | 26 + ...23_spring__FocusedACO__HLS__three-opt.test | 19 + ...ece8893_2023_spring__GradCAM__src_hls.test | 161 + ...23_spring__GradCAM__src_hls__avg_pool.test | 24 + ...93_2023_spring__GradCAM__src_hls__cam.test | 17 + ..._2023_spring__GradCAM__src_hls__conv1.test | 23 + ...spring__GradCAM__src_hls__conv_3x3_s1.test | 37 + ...023_spring__GradCAM__src_hls__conv_ds.test | 30 + ...3_spring__GradCAM__src_hls__linear_fc.test | 16 + ...023_spring__GradCAM__src_hls__maxpool.test | 20 + ..._spring__Monte-Carlo__MersenneTwister.test | 12 + ...e8893_2023_spring__Monte-Carlo__Paths.test | 18 + ...spring__Monte-Carlo__Random 100 Paths.test | 15 + ...-Accelerator__HLS_C__CSP_Layer1Layer2.test | 21 + ...celerator__HLS_C__Conv2D_Layer1Layer2.test | 24 + ...iny-Accelerator__HLS_C__Maxpool_Layer.test | 16 + ...4-Tiny-Accelerator__HLS_C__Project_L1.test | 27 + ...4-Tiny-Accelerator__HLS_C__Project_L2.test | 27 + ...4-Tiny-Accelerator__HLS_C__Project_L3.test | 27 + ...4-Tiny-Accelerator__HLS_C__Project_L4.test | 27 + ...4-Tiny-Accelerator__HLS_C__Project_L5.test | 27 + ...4-Tiny-Accelerator__HLS_C__Project_L6.test | 27 + ...ba_Prasad_Padhy_ece8893_spring25_lab3.test | 49 + ...ngh_Chandrabhan_ece8893_spring25_lab2.test | 46 + ...ngh_Chandrabhan_ece8893_spring25_lab3.test | 27 + ...8893_spring_2025__Hsuanchen_Fang_lab2.test | 70 + ...8893_spring_2025__Hsuanchen_Fang_lab3.test | 29 + ...ce8893_spring_2025__Mingyu_Zhang_lab2.test | 27 + ...ce8893_spring_2025__Mingyu_Zhang_lab3.test | 44 + ...uroFPGA_Project__neural_hls_NeuroFPGA.test | 14 + ...2025__NeuroFPGA_Project__symbolic_HLS.test | 19 + ...unchips_Topic5_Modular_Multiplication.test | 25 + ...8893_spring_2025__Xiyin_Xue_Lab2_2025.test | 42 + ...s_ece8893_spring_2025__Xiyin_xue_lab3.test | 50 + ..._adithi_upadhya_ece8893_spring25_lab2.test | 28 + ..._adithi_upadhya_ece8893_spring25_lab3.test | 49 + ...haya_shivprasad_ece8893_spring25_lab2.test | 40 + ...haya_shivprasad_ece8893_spring25_lab3.test | 26 + ..._anirudh_tulasi_ece8893_spring25_lab2.test | 31 + ..._anirudh_tulasi_ece8893_spring25_lab3.test | 41 + ...__Anuvab_Sen_lab_2_ECE_8893_spring_29.test | 42 + ...__Anuvab_Sen_lab_3_ECE_8893_spring_29.test | 34 + ...ba_prasad_padhy_ece8893_spring25_lab2.test | 50 + ...5__arati_ganesh_ece8893_spring25_lab2.test | 47 + ...5__arati_ganesh_ece8893_spring25_lab3.test | 39 + ...Ayush_Saxena_lab_2_ECE_8893_spring_26.test | 40 + ...Ayush_Saxena_lab_3_ECE_8893_spring_26.test | 34 + ...e8893_spring_2025__barry_walker_lab_2.test | 58 + ...e8893_spring_2025__barry_walker_lab_3.test | 45 + ...8893_spring_2025__connor_talley_lab_2.test | 31 + ...8893_spring_2025__connor_talley_lab_3.test | 33 + ...avendra_maharaj_ece8893_spring25_lab2.test | 55 + ...avendra_maharaj_ece8893_spring25_lab3.test | 30 + ...ing_2025__ece8893_dataset_lab_1__0001.test | 5 + ...ing_2025__ece8893_dataset_lab_1__0002.test | 34 + ...3_spring2025__gabriel_lopez_lugo_lab2.test | 41 + ...3_spring2025__gabriel_lopez_lugo_lab3.test | 40 + ..._spring_2025__hyungseok_bae_lab2_2025.test | 29 + ..._spring_2025__hyungseok_bae_lab3_2025.test | 40 + ...ece8893_spring_2025__kaihong_lin_lab2.test | 57 + ...ece8893_spring_2025__kaihong_lin_lab3.test | 60 + ...93_spring_2025__kamya_hari_lab_2_2025.test | 34 + ...93_spring_2025__kamya_hari_lab_3_2025.test | 53 + ...hikeya_sharma_ece8893_spring_25_lab_2.test | 36 + ...hikeya_sharma_ece8893_spring_25_lab_3.test | 25 + ...ass_ece8893_spring_2025__lab2_hanchen.test | 19 + ..._ece8893_spring_2025__lab2_sushkrutha.test | 34 + ...ass_ece8893_spring_2025__lab3_hanchen.test | 28 + ..._ece8893_spring_2025__lab3_sushkrutha.test | 43 + ...methods__ben_hall_lab2_2025_attention.test | 39 + ...all_lab3_sparse_matrix_multiplication.test | 29 + ..._spring_2025__max_beaulieu_Lab_3_2025.test | 53 + ...michael_meng_ece_8893_spring_25__lab2.test | 16 + ...michael_meng_ece_8893_spring_25__lab3.test | 40 + ...893_spring_2025__minjun_kim_Lab2_2025.test | 47 + ...893_spring_2025__minjun_kim_Lab3_2025.test | 27 + ...ce8893_spring_2025__mizanur_Lab2_2025.test | 30 + ...ce8893_spring_2025__mizanur_Lab3_2025.test | 40 + ...8893_spring_2025__mohammad_zain_lab_2.test | 39 + ...8893_spring_2025__mohammad_zain_lab_3.test | 28 + ...025__nayan_nair_ece8893_spring25_lab2.test | 27 + ...025__nayan_nair_ece8893_spring25_lab3.test | 25 + ...chs_neural_kernel_ece8893_spring_2025.test | 76 + ...s_symbolic_kernel_ece8893_spring_2025.test | 44 + ..._2025__nikhil_p_ece8893_spring25_lab2.test | 32 + ..._2025__nikhil_p_ece8893_spring25_lab3.test | 36 + ...ring_2025__nikhil_s_ece8893_sp25_lab2.test | 16 + ...ring_2025__nikhil_s_ece8893_sp25_lab3.test | 26 + ...893_spring_2025__oscar_baglivio_lab_2.test | 28 + ...893_spring_2025__oscar_baglivio_lab_3.test | 28 + ...3_spring_2025__pengzhao_liu_Lab2_2025.test | 35 + ...3_spring_2025__pengzhao_liu_Lab3_2025.test | 38 + ...893_spring_2025__pranay_kamineny_lab2.test | 57 + ...893_spring_2025__pranay_kamineny_lab3.test | 38 + ...s_ece8893_spring_2025__ritik_raj_lab2.test | 34 + ...s_ece8893_spring_2025__ritik_raj_lab3.test | 24 + ...ece8893_spring_2025__sahith_lab2_2025.test | 5 + ...ece8893_spring_2025__sahith_lab3_2025.test | 41 + ...ece8893_spring_25__Shengxi_Liang_LAB2.test | 7 + ...ece8893_spring_25__Shengxi_Liang_LAB3.test | 39 + ...3_spring_2025__shibao_su_ece8893_lab2.test | 26 + ...3_spring_2025__shibao_su_ece8893_lab3.test | 40 + ...spring_2025__shreesahitya_balaje_lab2.test | 37 + ...spring_2025__shreesahitya_balaje_lab3.test | 44 + ...iddharth_khatri_ece8893_spring25_lab2.test | 34 + ...iddharth_khatri_ece8893_spring25_lab3.test | 49 + ...idhireddy_bommu_ece8893_spring25_lab2.test | 28 + ...idhireddy_bommu_ece8893_spring25_lab3.test | 26 + ...e8893_spring_2025__stefan_test_design.test | 10 + ...pring_2025__suyeon_yoon_lab3_spring25.test | 27 + ...u_varma_venkata_ece8893_spring25_lab2.test | 28 + ...u_varma_venkata_ece8893_spring25_lab3.test | 35 + ...ss_ece8893_spring_2025__zihan_qi_lab2.test | 42 + ...ss_ece8893_spring_2025__zihan_qi_lab3.test | 53 + ...025__zijun_wang_ece8893_spring25_lab2.test | 28 + ...025__zijun_wang_ece8893_spring25_lab3.test | 37 + .../HLS/hlsfactory/flowgnn/flowgnn__dgn.test | 203 + .../HLS/hlsfactory/flowgnn/flowgnn__gat.test | 237 + .../HLS/hlsfactory/flowgnn/flowgnn__gcn.test | 219 + .../HLS/hlsfactory/flowgnn/flowgnn__gin.test | 209 + .../HLS/hlsfactory/flowgnn/flowgnn__pna.test | 226 + .../forgebench__Llama_GPT_module.test | 80 + .../forgebench__activation_module.test | 41 + .../forgebench__activation_op1.test | 41 + .../forgebench__activation_op2.test | 41 + .../forgebench__activation_op3.test | 41 + .../forgebench__attention_op_p1.test | 20 + .../forgebench__attention_op_p2.test | 20 + .../forgebench__attention_op_p3.test | 20 + .../forgebench__attn_breakdown_module.test | 52 + .../forgebench__attn_breakdown_op1.test | 52 + .../forgebench__attn_breakdown_op2.test | 52 + .../forgebench/forgebench__conv_A.test | 26 + .../forgebench/forgebench__conv_B.test | 26 + .../forgebench/forgebench__conv_C.test | 26 + .../forgebench__conv_block_module.test | 99 + .../forgebench__conv_block_op1.test | 98 + .../forgebench__conv_block_op2.test | 97 + .../forgebench__conv_block_op3.test | 98 + .../forgebench/forgebench__conv_module.test | 55 + .../forgebench__diff_dims_module_large.test | 75 + .../forgebench__diff_dims_module_small.test | 74 + .../forgebench/forgebench__diff_dims_p1.test | 44 + .../forgebench/forgebench__diff_dims_p2.test | 44 + .../forgebench/forgebench__diff_dims_p3.test | 44 + .../forgebench__diff_orders_module.test | 67 + .../forgebench__diff_orders_p1.test | 40 + .../forgebench__diff_orders_p2.test | 40 + .../forgebench__diff_orders_p3.test | 40 + .../forgebench__gpt_transformer_p1.test | 33 + .../forgebench__llama_transformer_p2.test | 33 + .../forgebench/forgebench__mlp.test | 51 + .../forgebench__mult_op_module_dot.test | 69 + .../forgebench__mult_op_module_mm.test | 76 + .../forgebench__mult_op_module_mmv.test | 70 + .../forgebench/forgebench__mult_op_p1.test | 29 + .../forgebench/forgebench__mult_op_p2.test | 25 + .../forgebench/forgebench__mult_op_p3.test | 21 + .../forgebench/forgebench__testing_impl.test | 56 + .../forgebench__testing_unroll.test | 67 + .../forgebench__tiled_attn_module.test | 53 + .../forgebench/forgebench__tiled_attn_p1.test | 20 + .../forgebench/forgebench__tiled_attn_p2.test | 20 + .../forgebench__vec_mtx_module.test | 49 + .../forgebench/forgebench__vec_mtx_p1.test | 32 + .../forgebench/forgebench__vec_mtx_p2.test | 32 + tools/cgeist/Test/HLS/hlsfactory/generate.py | 548 + .../gnnbuilder__designs__fpga_gcn_qm9.test | 320 + .../gnnbuilder__designs__fpga_gin_qm9.test | 370 + .../gnnbuilder__designs__fpga_pna_qm9.test | 428 + .../gnnbuilder__designs__fpga_sage_qm9.test | 326 + ...yn-vitis__vivado-target__sources__2mm.test | 25 + ...yn-vitis__vivado-target__sources__3mm.test | 32 + ...yn-vitis__vivado-target__sources__adi.test | 24 + ...yn-vitis__vivado-target__sources__aes.test | 16 + ...__vivado-target__sources__atax-medium.test | 18 + ...n-vitis__vivado-target__sources__atax.test | 18 + ...s__vivado-target__sources__bicg-large.test | 17 + ...__vivado-target__sources__bicg-medium.test | 18 + ...n-vitis__vivado-target__sources__bicg.test | 18 + ...__vivado-target__sources__correlation.test | 27 + ...s__vivado-target__sources__covariance.test | 23 + ...__vivado-target__sources__doitgen-red.test | 20 + ...itis__vivado-target__sources__doitgen.test | 19 + ...vivado-target__sources__fdtd-2d-large.test | 26 + ...itis__vivado-target__sources__fdtd-2d.test | 26 + ..._vivado-target__sources__gemm-blocked.test | 21 + ...__vivado-target__sources__gemm-ncubed.test | 18 + ..._vivado-target__sources__gemm-p-large.test | 19 + ...vitis__vivado-target__sources__gemm-p.test | 19 + ...vivado-target__sources__gemver-medium.test | 29 + ...vitis__vivado-target__sources__gemver.test | 29 + ...ivado-target__sources__gesummv-medium.test | 18 + ...itis__vivado-target__sources__gesummv.test | 18 + ...itis__vivado-target__sources__heat-3d.test | 22 + ...is__vivado-target__sources__jacobi-1d.test | 16 + ...is__vivado-target__sources__jacobi-2d.test | 20 + ...syn-vitis__vivado-target__sources__md.test | 19 + ...s__vivado-target__sources__mvt-medium.test | 21 + ...yn-vitis__vivado-target__sources__mvt.test | 21 + ...syn-vitis__vivado-target__sources__nw.test | 18 + ...is__vivado-target__sources__seidel-2d.test | 16 + ...tis__vivado-target__sources__spmv-crs.test | 18 + ..._vivado-target__sources__spmv-ellpack.test | 16 + ...s__vivado-target__sources__stencil-3d.test | 17 + ...do-target__sources__stencil_stencil2d.test | 18 + ...vado-target__sources__symm-opt-medium.test | 19 + ...tis__vivado-target__sources__symm-opt.test | 19 + ...n-vitis__vivado-target__sources__symm.test | 18 + ...-vitis__vivado-target__sources__syr2k.test | 19 + ...n-vitis__vivado-target__sources__syrk.test | 18 + ...tis__vivado-target__sources__trmm-opt.test | 17 + ...n-vitis__vivado-target__sources__trmm.test | 17 + .../hp_fft_hls/hp_fft_hls__n1024__UF1.test | 236 + .../hp_fft_hls/hp_fft_hls__n1024__UF16.test | 244 + .../hp_fft_hls/hp_fft_hls__n1024__UF2.test | 248 + .../hp_fft_hls/hp_fft_hls__n1024__UF32.test | 237 + .../hp_fft_hls/hp_fft_hls__n1024__UF4.test | 232 + .../hp_fft_hls/hp_fft_hls__n1024__UF8.test | 233 + .../hp_fft_hls__n1024__no_StagePipeline.test | 30 + .../hp_fft_hls__n1024__original_C_style.test | 24 + .../hp_fft_hls/hp_fft_hls__n256__UF1.test | 198 + .../hp_fft_hls/hp_fft_hls__n256__UF16.test | 206 + .../hp_fft_hls/hp_fft_hls__n256__UF2.test | 210 + .../hp_fft_hls/hp_fft_hls__n256__UF32.test | 199 + .../hp_fft_hls/hp_fft_hls__n256__UF4.test | 195 + .../hp_fft_hls/hp_fft_hls__n256__UF8.test | 190 + .../hp_fft_hls__n256__no_StagePipeline.test | 30 + .../hp_fft_hls__n256__original_C_style.test | 24 + .../cgeist/Test/HLS/hlsfactory/lit.local.cfg | 83 + .../machsuite/machsuite__aes_table.test | 12 + .../machsuite/machsuite__aes_tableless.test | 11 + .../machsuite/machsuite__backprop.test | 24 + .../machsuite/machsuite__bfs_bulk.test | 10 + .../machsuite/machsuite__bfs_queue.test | 11 + .../machsuite/machsuite__fft_transpose.test | 17 + .../machsuite/machsuite__gemm_blocked.test | 10 + .../machsuite/machsuite__gemm_ncubed.test | 10 + .../machsuite/machsuite__md_grid.test | 10 + .../machsuite/machsuite__md_knn.test | 10 + .../hlsfactory/machsuite/machsuite__nw.test | 10 + .../machsuite/machsuite__sort_merge.test | 10 + .../machsuite/machsuite__sort_radix.test | 10 + .../machsuite/machsuite__spmv_crs.test | 10 + .../machsuite/machsuite__spmv_ellpack.test | 10 + .../machsuite/machsuite__stencil2D.test | 10 + .../machsuite/machsuite__stencil3D.test | 10 + .../machsuite/machsuite__viterbi.test | 11 + .../hlsfactory/polybench/polybench__atax.test | 14 + .../hlsfactory/polybench/polybench__bicg.test | 15 + .../hlsfactory/polybench/polybench__gemm.test | 14 + .../polybench/polybench__gesummv.test | 16 + .../hlsfactory/polybench/polybench__k2mm.test | 17 + .../hlsfactory/polybench/polybench__k3mm.test | 17 + .../hlsfactory/polybench/polybench__mvt.test | 15 + .../polybench/polybench__syr2k.test | 17 + .../hlsfactory/polybench/polybench__syrk.test | 14 + ...ucible__polybench__fixed__medium__2mm.test | 11 + ...ucible__polybench__fixed__medium__3mm.test | 11 + ...cible__polybench__fixed__medium__atax.test | 11 + ...cible__polybench__fixed__medium__bicg.test | 11 + ...e__polybench__fixed__medium__cholesky.test | 11 + ...polybench__fixed__medium__correlation.test | 11 + ..._polybench__fixed__medium__covariance.test | 11 + ...le__polybench__fixed__medium__doitgen.test | 11 + ...ble__polybench__fixed__medium__durbin.test | 12 + ...le__polybench__fixed__medium__fdtd-2d.test | 11 + ...ybench__fixed__medium__floyd-warshall.test | 11 + ...cible__polybench__fixed__medium__gemm.test | 11 + ...ble__polybench__fixed__medium__gemver.test | 11 + ...le__polybench__fixed__medium__gesummv.test | 11 + ...polybench__fixed__medium__gramschmidt.test | 11 + ...le__polybench__fixed__medium__heat-3d.test | 11 + ...__polybench__fixed__medium__jacobi-1d.test | 11 + ...__polybench__fixed__medium__jacobi-2d.test | 11 + ...ducible__polybench__fixed__medium__lu.test | 11 + ...ble__polybench__fixed__medium__ludcmp.test | 11 + ...ucible__polybench__fixed__medium__mvt.test | 11 + ...e__polybench__fixed__medium__nussinov.test | 11 + ...__polybench__fixed__medium__seidel-2d.test | 11 + ...cible__polybench__fixed__medium__symm.test | 11 + ...ible__polybench__fixed__medium__syr2k.test | 11 + ...cible__polybench__fixed__medium__syrk.test | 11 + ...le__polybench__fixed__medium__trisolv.test | 11 + ...cible__polybench__fixed__medium__trmm.test | 11 + ...oducible__polybench__fixed__mini__2mm.test | 11 + ...oducible__polybench__fixed__mini__3mm.test | 11 + ...ducible__polybench__fixed__mini__atax.test | 11 + ...ducible__polybench__fixed__mini__bicg.test | 11 + ...ble__polybench__fixed__mini__cholesky.test | 11 + ...__polybench__fixed__mini__correlation.test | 11 + ...e__polybench__fixed__mini__covariance.test | 11 + ...ible__polybench__fixed__mini__doitgen.test | 11 + ...cible__polybench__fixed__mini__durbin.test | 12 + ...ible__polybench__fixed__mini__fdtd-2d.test | 11 + ...olybench__fixed__mini__floyd-warshall.test | 11 + ...ducible__polybench__fixed__mini__gemm.test | 11 + ...cible__polybench__fixed__mini__gemver.test | 11 + ...ible__polybench__fixed__mini__gesummv.test | 11 + ...__polybench__fixed__mini__gramschmidt.test | 11 + ...ible__polybench__fixed__mini__heat-3d.test | 11 + ...le__polybench__fixed__mini__jacobi-1d.test | 11 + ...le__polybench__fixed__mini__jacobi-2d.test | 11 + ...roducible__polybench__fixed__mini__lu.test | 11 + ...cible__polybench__fixed__mini__ludcmp.test | 11 + ...oducible__polybench__fixed__mini__mvt.test | 11 + ...ble__polybench__fixed__mini__nussinov.test | 11 + ...le__polybench__fixed__mini__seidel-2d.test | 11 + ...ducible__polybench__fixed__mini__symm.test | 11 + ...ucible__polybench__fixed__mini__syr2k.test | 11 + ...ducible__polybench__fixed__mini__syrk.test | 11 + ...ible__polybench__fixed__mini__trisolv.test | 11 + ...ducible__polybench__fixed__mini__trmm.test | 11 + ...ducible__polybench__fixed__small__2mm.test | 11 + ...ducible__polybench__fixed__small__3mm.test | 11 + ...ucible__polybench__fixed__small__atax.test | 11 + ...ucible__polybench__fixed__small__bicg.test | 11 + ...le__polybench__fixed__small__cholesky.test | 11 + ..._polybench__fixed__small__correlation.test | 11 + ...__polybench__fixed__small__covariance.test | 11 + ...ble__polybench__fixed__small__doitgen.test | 11 + ...ible__polybench__fixed__small__durbin.test | 12 + ...ble__polybench__fixed__small__fdtd-2d.test | 11 + ...lybench__fixed__small__floyd-warshall.test | 11 + ...ucible__polybench__fixed__small__gemm.test | 11 + ...ible__polybench__fixed__small__gemver.test | 11 + ...ble__polybench__fixed__small__gesummv.test | 11 + ..._polybench__fixed__small__gramschmidt.test | 11 + ...ble__polybench__fixed__small__heat-3d.test | 11 + ...e__polybench__fixed__small__jacobi-1d.test | 11 + ...e__polybench__fixed__small__jacobi-2d.test | 11 + ...oducible__polybench__fixed__small__lu.test | 11 + ...ible__polybench__fixed__small__ludcmp.test | 11 + ...ducible__polybench__fixed__small__mvt.test | 11 + ...le__polybench__fixed__small__nussinov.test | 11 + ...e__polybench__fixed__small__seidel-2d.test | 11 + ...ucible__polybench__fixed__small__symm.test | 11 + ...cible__polybench__fixed__small__syr2k.test | 11 + ...ucible__polybench__fixed__small__syrk.test | 11 + ...ble__polybench__fixed__small__trisolv.test | 11 + ...ucible__polybench__fixed__small__trmm.test | 11 + ...ucible__polybench__float__medium__2mm.test | 11 + ...ucible__polybench__float__medium__3mm.test | 11 + ...cible__polybench__float__medium__atax.test | 11 + ...cible__polybench__float__medium__bicg.test | 11 + ...e__polybench__float__medium__cholesky.test | 11 + ...polybench__float__medium__correlation.test | 11 + ..._polybench__float__medium__covariance.test | 11 + ...le__polybench__float__medium__doitgen.test | 11 + ...ble__polybench__float__medium__durbin.test | 12 + ...le__polybench__float__medium__fdtd-2d.test | 11 + ...ybench__float__medium__floyd-warshall.test | 11 + ...cible__polybench__float__medium__gemm.test | 11 + ...ble__polybench__float__medium__gemver.test | 11 + ...le__polybench__float__medium__gesummv.test | 11 + ...polybench__float__medium__gramschmidt.test | 11 + ...le__polybench__float__medium__heat-3d.test | 11 + ...__polybench__float__medium__jacobi-1d.test | 11 + ...__polybench__float__medium__jacobi-2d.test | 11 + ...ducible__polybench__float__medium__lu.test | 11 + ...ble__polybench__float__medium__ludcmp.test | 11 + ...ucible__polybench__float__medium__mvt.test | 11 + ...e__polybench__float__medium__nussinov.test | 11 + ...__polybench__float__medium__seidel-2d.test | 11 + ...cible__polybench__float__medium__symm.test | 11 + ...ible__polybench__float__medium__syr2k.test | 11 + ...cible__polybench__float__medium__syrk.test | 11 + ...le__polybench__float__medium__trisolv.test | 11 + ...cible__polybench__float__medium__trmm.test | 11 + ...oducible__polybench__float__mini__2mm.test | 11 + ...oducible__polybench__float__mini__3mm.test | 11 + ...ducible__polybench__float__mini__atax.test | 11 + ...ducible__polybench__float__mini__bicg.test | 11 + ...ble__polybench__float__mini__cholesky.test | 11 + ...__polybench__float__mini__correlation.test | 11 + ...e__polybench__float__mini__covariance.test | 11 + ...ible__polybench__float__mini__doitgen.test | 11 + ...cible__polybench__float__mini__durbin.test | 12 + ...ible__polybench__float__mini__fdtd-2d.test | 11 + ...olybench__float__mini__floyd-warshall.test | 11 + ...ducible__polybench__float__mini__gemm.test | 11 + ...cible__polybench__float__mini__gemver.test | 11 + ...ible__polybench__float__mini__gesummv.test | 11 + ...__polybench__float__mini__gramschmidt.test | 11 + ...ible__polybench__float__mini__heat-3d.test | 11 + ...le__polybench__float__mini__jacobi-1d.test | 11 + ...le__polybench__float__mini__jacobi-2d.test | 11 + ...roducible__polybench__float__mini__lu.test | 11 + ...cible__polybench__float__mini__ludcmp.test | 11 + ...oducible__polybench__float__mini__mvt.test | 11 + ...ble__polybench__float__mini__nussinov.test | 11 + ...le__polybench__float__mini__seidel-2d.test | 11 + ...ducible__polybench__float__mini__symm.test | 11 + ...ucible__polybench__float__mini__syr2k.test | 11 + ...ducible__polybench__float__mini__syrk.test | 11 + ...ible__polybench__float__mini__trisolv.test | 11 + ...ducible__polybench__float__mini__trmm.test | 11 + ...ducible__polybench__float__small__2mm.test | 11 + ...ducible__polybench__float__small__3mm.test | 11 + ...ucible__polybench__float__small__atax.test | 11 + ...ucible__polybench__float__small__bicg.test | 11 + ...le__polybench__float__small__cholesky.test | 11 + ..._polybench__float__small__correlation.test | 11 + ...__polybench__float__small__covariance.test | 11 + ...ble__polybench__float__small__doitgen.test | 11 + ...ible__polybench__float__small__durbin.test | 12 + ...ble__polybench__float__small__fdtd-2d.test | 11 + ...lybench__float__small__floyd-warshall.test | 11 + ...ucible__polybench__float__small__gemm.test | 11 + ...ible__polybench__float__small__gemver.test | 11 + ...ble__polybench__float__small__gesummv.test | 11 + ..._polybench__float__small__gramschmidt.test | 11 + ...ble__polybench__float__small__heat-3d.test | 11 + ...e__polybench__float__small__jacobi-1d.test | 11 + ...e__polybench__float__small__jacobi-2d.test | 11 + ...oducible__polybench__float__small__lu.test | 11 + ...ible__polybench__float__small__ludcmp.test | 11 + ...ducible__polybench__float__small__mvt.test | 11 + ...le__polybench__float__small__nussinov.test | 11 + ...e__polybench__float__small__seidel-2d.test | 11 + ...ucible__polybench__float__small__symm.test | 11 + ...cible__polybench__float__small__syr2k.test | 11 + ...ucible__polybench__float__small__syrk.test | 11 + ...ble__polybench__float__small__trisolv.test | 11 + ...ucible__polybench__float__small__trmm.test | 11 + ...bench__float__unsafe__math__mini__2mm.test | 11 + ...bench__float__unsafe__math__mini__3mm.test | 11 + ...ench__float__unsafe__math__mini__atax.test | 11 + ...ench__float__unsafe__math__mini__bicg.test | 11 + ...__float__unsafe__math__mini__cholesky.test | 11 + ...loat__unsafe__math__mini__correlation.test | 11 + ...float__unsafe__math__mini__covariance.test | 11 + ...h__float__unsafe__math__mini__doitgen.test | 11 + ...ch__float__unsafe__math__mini__durbin.test | 12 + ...h__float__unsafe__math__mini__fdtd-2d.test | 11 + ...t__unsafe__math__mini__floyd-warshall.test | 11 + ...ench__float__unsafe__math__mini__gemm.test | 11 + ...ch__float__unsafe__math__mini__gemver.test | 11 + ...h__float__unsafe__math__mini__gesummv.test | 11 + ...loat__unsafe__math__mini__gramschmidt.test | 11 + ...h__float__unsafe__math__mini__heat-3d.test | 11 + ..._float__unsafe__math__mini__jacobi-1d.test | 11 + ..._float__unsafe__math__mini__jacobi-2d.test | 11 + ...ybench__float__unsafe__math__mini__lu.test | 11 + ...ch__float__unsafe__math__mini__ludcmp.test | 11 + ...bench__float__unsafe__math__mini__mvt.test | 11 + ...__float__unsafe__math__mini__nussinov.test | 11 + ..._float__unsafe__math__mini__seidel-2d.test | 11 + ...ench__float__unsafe__math__mini__symm.test | 11 + ...nch__float__unsafe__math__mini__syr2k.test | 11 + ...ench__float__unsafe__math__mini__syrk.test | 11 + ...h__float__unsafe__math__mini__trisolv.test | 11 + ...ench__float__unsafe__math__mini__trmm.test | 11 + ...pp4fpgas__23_pp4fpgas_unoptimized_fft.test | 10 + ...pp4fpgas__24_pp4fpgas_multi_stage_fft.test | 15 + ...p4fpgas__25_pp4fpgas_huffman_encoding.test | 41 + .../pp4fpgas__26_pp4fpgas_matmul.test | 13 + ...pgas__27_pp4fpgas_parallel_merge_sort.test | 15 + .../Test/HLS/hlsfactory/real_cgeist_flags | 26 + .../rosetta__3d-rendering__src__sdsoc.test | 29 + .../rosetta/rosetta__BNN__cpp__accel.test | 5 + ...osetta__digit-recognition__src__sdsoc.test | 39 + .../rosetta__face-detection__src__sdsoc.test | 136 + ...a__face-detection__src__sdsoc__origin.test | 150 + .../rosetta__optical-flow__src__sdsoc.test | 5 + ...ptical-flow__src__sdsoc__hls_template.test | 5 + .../rosetta__spam-filter__src__sdsoc.test | 25 + .../HLS/hlsfactory/soda/soda__soda__blur.test | 637 + .../hlsfactory/soda/soda__soda__contrast.test | 2209 ++ .../soda/soda__soda__denoise2d.test | 698 + .../soda/soda__soda__denoise3d.test | 542 + .../hlsfactory/soda/soda__soda__erosion.test | 894 + .../hlsfactory/soda/soda__soda__heat3d.test | 257 + .../hlsfactory/soda/soda__soda__jacobi2d.test | 200 + .../hlsfactory/soda/soda__soda__jacobi3d.test | 257 + .../hlsfactory/soda/soda__soda__seidel2d.test | 276 + .../hlsfactory/soda/soda__soda__sobel2d.test | 406 + .../hlsfactory/soda/soda__soda__xcorr.test | 973 + .../spector_hls/spector_hls__dct.test | 10 + .../spector_hls/spector_hls__fir.test | 37 + .../spector_hls/spector_hls__histogram.test | 18 + .../spector_hls__matrix_multiplication.test | 10 + .../spector_hls/spector_hls__mergesort.test | 20 + .../spector_hls/spector_hls__normals.test | 24 + .../spector_hls__sobel_filter_x.test | 17 + .../spector_hls__sobel_filter_y.test | 17 + .../spector_hls/spector_hls__spmv.test | 30 + .../spector_hls__template_matching.test | 26 + .../stream_hls__Autoencoder__opt1.test | 85 + .../stream_hls__Autoencoder__opt2.test | 81 + .../stream_hls__Autoencoder__opt3.test | 85 + .../stream_hls__Autoencoder__opt4.test | 81 + .../stream_hls__Autoencoder__opt5.test | 128 + ...ls__DepthwiseSeparableConvBlock__opt1.test | 36 + ...ls__DepthwiseSeparableConvBlock__opt2.test | 25 + ...ls__DepthwiseSeparableConvBlock__opt3.test | 39 + ...ls__DepthwiseSeparableConvBlock__opt4.test | 39 + ...ls__DepthwiseSeparableConvBlock__opt5.test | 39 + .../stream_hls__FeedForward__opt1.test | 39 + .../stream_hls__FeedForward__opt2.test | 41 + .../stream_hls__FeedForward__opt3.test | 83 + .../stream_hls__FeedForward__opt4.test | 73 + .../stream_hls__FeedForward__opt5.test | 63 + ...am_hls__MultiHeadSelfAttention1__opt1.test | 110 + ...am_hls__MultiHeadSelfAttention1__opt2.test | 114 + ...am_hls__MultiHeadSelfAttention1__opt3.test | 270 + ...am_hls__MultiHeadSelfAttention1__opt4.test | 242 + ...am_hls__MultiHeadSelfAttention1__opt5.test | 258 + .../stream_hls/stream_hls__ResMLP__opt1.test | 67 + .../stream_hls/stream_hls__ResMLP__opt2.test | 66 + .../stream_hls/stream_hls__ResMLP__opt3.test | 67 + .../stream_hls/stream_hls__ResMLP__opt4.test | 66 + .../stream_hls/stream_hls__ResMLP__opt5.test | 88 + .../stream_hls__ResidualBlock__opt1.test | 45 + .../stream_hls__ResidualBlock__opt2.test | 32 + .../stream_hls__ResidualBlock__opt3.test | 50 + .../stream_hls__ResidualBlock__opt4.test | 50 + .../stream_hls__ResidualBlock__opt5.test | 50 + .../stream_hls/stream_hls__atax__opt1.test | 24 + .../stream_hls/stream_hls__atax__opt2.test | 25 + .../stream_hls/stream_hls__atax__opt3.test | 43 + .../stream_hls/stream_hls__atax__opt4.test | 38 + .../stream_hls/stream_hls__atax__opt5.test | 38 + .../stream_hls/stream_hls__bicg__opt1.test | 23 + .../stream_hls/stream_hls__bicg__opt2.test | 23 + .../stream_hls/stream_hls__bicg__opt3.test | 41 + .../stream_hls/stream_hls__bicg__opt4.test | 41 + .../stream_hls/stream_hls__bicg__opt5.test | 41 + .../stream_hls/stream_hls__gemm__opt1.test | 21 + .../stream_hls/stream_hls__gemm__opt2.test | 21 + .../stream_hls/stream_hls__gemm__opt3.test | 39 + .../stream_hls/stream_hls__gemm__opt4.test | 39 + .../stream_hls/stream_hls__gemm__opt5.test | 39 + .../stream_hls/stream_hls__gesummv__opt1.test | 25 + .../stream_hls/stream_hls__gesummv__opt2.test | 25 + .../stream_hls/stream_hls__gesummv__opt3.test | 40 + .../stream_hls/stream_hls__gesummv__opt4.test | 40 + .../stream_hls/stream_hls__gesummv__opt5.test | 40 + .../stream_hls/stream_hls__k2mm__opt1.test | 25 + .../stream_hls/stream_hls__k2mm__opt2.test | 25 + .../stream_hls/stream_hls__k2mm__opt3.test | 51 + .../stream_hls/stream_hls__k2mm__opt4.test | 51 + .../stream_hls/stream_hls__k2mm__opt5.test | 51 + .../stream_hls/stream_hls__k3mm__opt1.test | 24 + .../stream_hls/stream_hls__k3mm__opt2.test | 25 + .../stream_hls/stream_hls__k3mm__opt3.test | 56 + .../stream_hls/stream_hls__k3mm__opt4.test | 55 + .../stream_hls/stream_hls__k3mm__opt5.test | 55 + .../stream_hls__k7mmseq_balanced__opt1.test | 41 + .../stream_hls__k7mmseq_balanced__opt2.test | 41 + .../stream_hls__k7mmseq_balanced__opt3.test | 103 + .../stream_hls__k7mmseq_balanced__opt4.test | 103 + .../stream_hls__k7mmseq_balanced__opt5.test | 103 + .../stream_hls__k7mmseq_unbalanced__opt1.test | 41 + .../stream_hls__k7mmseq_unbalanced__opt2.test | 41 + .../stream_hls__k7mmseq_unbalanced__opt3.test | 98 + .../stream_hls__k7mmseq_unbalanced__opt4.test | 98 + .../stream_hls__k7mmseq_unbalanced__opt5.test | 98 + .../stream_hls__k7mmtree_balanced__opt5.test | 103 + ...stream_hls__k7mmtree_unbalanced__opt5.test | 94 + .../stream_hls/stream_hls__mvt__opt1.test | 26 + .../stream_hls/stream_hls__mvt__opt2.test | 27 + .../stream_hls/stream_hls__mvt__opt3.test | 50 + .../stream_hls/stream_hls__mvt__opt4.test | 45 + .../stream_hls/stream_hls__mvt__opt5.test | 45 + ..._basic_examples_vhls_fixed_point_sqrt.test | 11 + ...es__02_basic_examples_vhls_fir_filter.test | 11 + ...examples_vhls_fixed_point_window_conv.test | 11 + ...mples_vhls_floating_point_window_conv.test | 11 + ..._05_basic_examples_vhls_ap_arithmetic.test | 10 + ...06_basic_examples_vhls_parallel_loops.test | 10 + ...7_basic_examples_vhls_imperfect_loops.test | 10 + ..._basic_examples_vhls_max_bounded_loop.test | 10 + ...ic_examples_vhls_perfect_nested_loops.test | 10 + ..._examples_vhls_pipelined_nested_loops.test | 10 + ...1_basic_examples_vhls_accs_sequential.test | 10 + ...12_basic_examples_vhls_accs_w_asserts.test | 10 + ...3_basic_examples_vhls_accs_w_dataflow.test | 11 + ..._14_basic_examples_vhls_static_memory.test | 11 + ...5_basic_examples_vhls_pointer_casting.test | 10 + ...16_basic_examples_vhls_double_pointer.test | 11 + ...es__17_basic_examples_vhls_axi_master.test | 12 + ...mples_vhls_axi_stream_no_side_channel.test | 12 + ...es_vhls_multi_array_access_bottleneck.test | 10 + ...vhls_resolved_array_access_bottleneck.test | 10 + ...ples__21_basic_examples_vhls_uram_ecc.test | 16 + ...mples_vhls_fixed_point_hamming_window.test | 11 + ...8_vitis_accel_examples_streaming_vadd.test | 17 + .../whetstone/whetstone__whetstone.test | 34 + tools/cgeist/Test/HLS/inline/inline.cpp | 77 + tools/cgeist/Test/HLS/interface/interface.c | 71 + tools/cgeist/Test/HLS/latency/latency.c | 69 + tools/cgeist/Test/HLS/lit.local.cfg | 43 + .../Test/HLS/loop_flatten/loop_flatten.c | 70 + tools/cgeist/Test/HLS/loop_merge/loop_merge.c | 54 + .../Test/HLS/loop_tripcount/loop_tripcount.c | 88 + tools/cgeist/Test/HLS/occurrence/occurrence.c | 44 + .../cgeist/Test/HLS/parse/case-and-spelling.c | 74 + tools/cgeist/Test/HLS/parse/cxx-constants.cpp | 55 + tools/cgeist/Test/HLS/parse/not-enabled.c | 17 + .../HLS/parse/pragma-operator-and-macros.c | 81 + tools/cgeist/Test/HLS/parse/syntax-errors.c | 60 + tools/cgeist/Test/HLS/parse/unknown.c | 95 + tools/cgeist/Test/HLS/parse/value-errors.c | 28 + .../cgeist/Test/HLS/performance/performance.c | 58 + tools/cgeist/Test/HLS/pipeline/errors.c | 69 + tools/cgeist/Test/HLS/pipeline/lowering.c | 46 + tools/cgeist/Test/HLS/pipeline/options.c | 136 + tools/cgeist/Test/HLS/pipeline/placement.c | 180 + tools/cgeist/Test/HLS/pipeline/trip_one.c | 53 + tools/cgeist/Test/HLS/placement/cxx.cpp | 57 + .../cgeist/Test/HLS/placement/lost-targets.c | 37 + tools/cgeist/Test/HLS/placement/macro-loops.c | 29 + .../Test/HLS/placement/scope-errors.cpp | 32 + tools/cgeist/Test/HLS/polybench/bicg.c | 100 + tools/cgeist/Test/HLS/polybench/generate.py | 200 + tools/cgeist/Test/HLS/polybench/gesummv.c | 108 + tools/cgeist/Test/HLS/polybench/hls-est-e2e.c | 71 + tools/cgeist/Test/HLS/polybench/k2mm.c | 134 + tools/cgeist/Test/HLS/polybench/k3mm.c | 140 + tools/cgeist/Test/HLS/polybench/mvt.c | 103 + tools/cgeist/Test/HLS/polybench/syr2k.c | 134 + tools/cgeist/Test/HLS/polybench/syrk.c | 104 + tools/cgeist/Test/HLS/protocol/protocol.c | 44 + .../realheaders/Inputs/extern-global-def.cpp | 4 + .../Inputs/extern-global-first.cpp | 10 + .../realheaders/Inputs/extern-global-init.cpp | 4 + .../Inputs/stream-member-cross-unit-b.cpp | 15 + .../Inputs/stream-member-cross-unit-c.cpp | 6 + .../Test/HLS/realheaders/ap-global-init.cpp | 70 + .../Test/HLS/realheaders/apint-types.cpp | 49 + .../Test/HLS/realheaders/array12-bram.cpp | 18 + .../HLS/realheaders/auto-inline-measure.cpp | 30 + .../Test/HLS/realheaders/bits-const.cpp | 93 + .../Test/HLS/realheaders/complex-assign.cpp | 37 + .../HLS/realheaders/compound-assign-mark.cpp | 44 + .../Test/HLS/realheaders/concat-ref.cpp | 47 + .../HLS/realheaders/extern-global-pragma.cpp | 24 + .../realheaders/extern-global-unused-def.cpp | 27 + .../Test/HLS/realheaders/fixed-accumulate.cpp | 25 + .../Test/HLS/realheaders/fixed-modes.cpp | 40 + .../Test/HLS/realheaders/header-pragma.cpp | 28 + tools/cgeist/Test/HLS/realheaders/hls-exp.cpp | 28 + .../cgeist/Test/HLS/realheaders/hls-task.cpp | 25 + .../cgeist/Test/HLS/realheaders/lit.local.cfg | 57 + .../loop-scalar-promote-affine-if.cpp | 23 + .../realheaders/loop-scalar-promote-for.cpp | 23 + .../loop-scalar-promote-live-out.cpp | 44 + .../realheaders/loop-scalar-promote-reset.cpp | 29 + .../HLS/realheaders/loop-scalar-promote.cpp | 32 + .../cgeist/Test/HLS/realheaders/math-core.cpp | 49 + .../Test/HLS/realheaders/memcpy-typed.cpp | 56 + .../Test/HLS/realheaders/mingw-names.cpp | 23 + .../HLS/realheaders/pragma-class-member.cpp | 27 + .../HLS/realheaders/pragma-dead-branch.cpp | 21 + .../HLS/realheaders/pragma-local-enum.cpp | 18 + .../realheaders/pragma-template-constants.cpp | 32 + .../HLS/realheaders/pragma-vitis-accepts.cpp | 40 + .../Test/HLS/realheaders/proxy-escape.cpp | 14 + .../realheaders/raise-variable-step-guard.cpp | 26 + .../HLS/realheaders/raise-variable-step.cpp | 20 + .../Test/HLS/realheaders/range-ref-switch.cpp | 23 + .../cgeist/Test/HLS/realheaders/range-ref.cpp | 62 + .../realheaders/shift-register-builtins.cpp | 24 + .../static-member-through-object.cpp | 14 + .../HLS/realheaders/stream-element-bits.cpp | 34 + .../HLS/realheaders/stream-global-depth.cpp | 28 + .../realheaders/stream-member-cross-unit.cpp | 32 + tools/cgeist/Test/HLS/realheaders/stream.cpp | 62 + .../Test/HLS/realheaders/string-ctor.cpp | 56 + .../Test/HLS/realheaders/vector-partition.cpp | 29 + .../Inputs/auto-inline-cross-unit-callee.cpp | 10 + .../array-of-struct-pointer-to-row.cpp | 25 + .../HLS/regressions/array-partition-merge.c | 118 + .../regressions/auto-inline-callee-unroll.c | 59 + .../auto-inline-callsite-constant-trip.cpp | 60 + .../regressions/auto-inline-cross-unit.cpp | 18 + .../auto-inline-invalid-source.cpp | 21 + .../HLS/regressions/auto-inline-review.cpp | 190 + .../auto-inline-rotated-size-nested.c | 60 + .../regressions/auto-inline-rotated-size.c | 53 + .../regressions/auto-inline-runtime-trip.cpp | 49 + .../Test/HLS/regressions/auto-inline-vitis.c | 392 + .../HLS/regressions/break-skips-condition.c | 43 + .../regressions/buffer-elim-remat-clobber.cpp | 27 + .../HLS/regressions/builtin-constant-call.c | 16 + .../regressions/call-array-shape-mismatch.c | 58 + .../Test/HLS/regressions/complex-arith.c | 78 + .../HLS/regressions/condition-variable.cpp | 64 + .../Test/HLS/regressions/counter-exit-value.c | 56 + .../regressions/dangling-constant-lookup.c | 14 + .../HLS/regressions/default-member-init.cpp | 20 + .../regressions/divrem-negative-dividend.c | 60 + .../HLS/regressions/dynamic-global-init.cpp | 47 + .../HLS/regressions/fabs-class-overload.cpp | 27 + .../HLS/regressions/float-compound-double.c | 49 + .../HLS/regressions/for-break-exit-value.c | 28 + .../regressions/function-by-source-name.cpp | 20 + .../Test/HLS/regressions/goto-unsupported.c | 16 + .../hlsfactory-bind-op-array-expression.c | 41 + .../hlsfactory-bind-storage-without-type.c | 17 + .../hlsfactory-constexpr-call-values.cpp | 33 + .../hlsfactory-latency-minus-one.c | 16 + .../hlsfactory-nested-scope-variable.cpp | 42 + .../hlsfactory-subscripted-variable.cpp | 49 + .../regressions/initlist-scalar-wrapper.cpp | 12 + .../HLS/regressions/inline-off-kept-call.c | 159 + .../inline-off-recursive-not-diagnosed.c | 10 + .../regressions/interface-later-pragma-wins.c | 17 + .../interface-maxi-axilite-same-port.c | 12 + .../HLS/regressions/keep-invariant-loops.c | 94 + .../HLS/regressions/keep-misfit-global.cpp | 54 + .../Test/HLS/regressions/narrow-arith-wrap.c | 109 + .../Test/HLS/regressions/narrow-cast-chain.c | 64 + .../regressions/narrow-const-representative.c | 60 + .../narrow-counter-assume-termination.c | 163 + .../regressions/narrow-counter-shared-start.c | 75 + .../HLS/regressions/narrow-counter-wrap.c | 133 + .../regressions/no-codegen-after-errors.cpp | 18 + .../HLS/regressions/nowrap-unsigned-read.c | 116 + .../HLS/regressions/nsdmi-scalar-brace.cpp | 19 + .../cgeist/Test/HLS/regressions/nullptr-t.cpp | 14 + .../regressions/orig-name-operator-crash.cpp | 18 + .../regressions/pointer-param-assign-array.c | 22 + .../Test/HLS/regressions/pointer-to-array.cpp | 30 + .../HLS/regressions/pow-promoted-argument.cpp | 18 + .../regressions/pragma-unexpected-number.c | 32 + .../Test/HLS/regressions/predec-lvalue.cpp | 17 + .../HLS/regressions/range-for-array-ref.cpp | 32 + .../Test/HLS/regressions/signed-nowrap-mark.c | 190 + .../regressions/store-forward-loop-carried.c | 295 + .../HLS/regressions/stream-io-dropped.cpp | 36 + .../regressions/struct-same-type-members.c | 71 + .../unknown-pragmas-false-conflict.c | 13 + .../HLS/regressions/while-conjunctive-bound.c | 65 + .../HLS/regressions/while-step-doubling.c | 22 + .../Test/HLS/regressions/wide-int-sub-const.c | 26 + .../HLS/regressions/zero-init-aggregates.cpp | 46 + tools/cgeist/Test/HLS/report/check-only.cpp | 53 + tools/cgeist/Test/HLS/report/report.c | 55 + tools/cgeist/Test/HLS/reset/reset.c | 37 + tools/cgeist/Test/HLS/stable/stable.c | 39 + tools/cgeist/Test/HLS/stream/stream.c | 72 + tools/cgeist/Test/HLS/top/top.c | 49 + tools/cgeist/Test/HLS/unroll/errors.c | 46 + .../Test/HLS/unroll/factor-expr-zero.cpp | 17 + tools/cgeist/Test/HLS/unroll/lowering.c | 21 + tools/cgeist/Test/HLS/unroll/options.c | 74 + tools/cgeist/Test/HLS/unroll/placement.c | 63 + .../Test/HLS/wrapper/Inputs/mini_fixed.h | 85 + .../Test/HLS/wrapper/attention_ctrl.cpp | 47 + .../Test/HLS/wrapper/attention_mirror.cpp | 47 + .../Test/HLS/wrapper/builtin_bit_cast.cpp | 19 + .../cgeist/Test/HLS/wrapper/wrapper_chain.cpp | 30 + .../cgeist/Test/HLS/wrapper/wrapper_ctor.cpp | 86 + .../Test/HLS/wrapper/wrapper_derived.cpp | 33 + .../Test/HLS/wrapper/wrapper_global.cpp | 42 + tools/cgeist/Test/HLS/wrapper/wrapper_not.cpp | 47 + tools/cgeist/Test/HLS/wrapper/wrapper_off.cpp | 27 + .../Test/HLS/wrapper/wrapper_sizeof.cpp | 27 + .../Test/HLS/wrapper/wrapper_static_local.cpp | 70 + .../cgeist/Test/HLS/wrapper/wrapper_type.cpp | 35 + .../Test/HLS/wrapper/wrapper_valueinit.cpp | 62 + tools/cgeist/Test/HLS/xlx/bit-builtins.cpp | 136 + tools/cgeist/Test/HLS/xlx/bitwidth.cpp | 53 + tools/cgeist/Test/HLS/xlx/builtin-gate.cpp | 15 + tools/cgeist/Test/HLS/xlx/dead-store.cpp | 59 + tools/cgeist/Test/HLS/xlx/lit.local.cfg | 25 + tools/cgeist/Test/HLS/xlx/pragma-variable.cpp | 61 + tools/cgeist/Test/HLS/xlx/string2bits.cpp | 69 + tools/cgeist/Test/HLS/xlx/union-pun.cpp | 41 + tools/cgeist/Test/HLS/xlx/wide-not.cpp | 18 + .../Test/Verification/cudaglobalcodegen.cu | 0 .../Test/Verification/float-compound-assign.c | 24 + tools/cgeist/Test/Verification/freecst.c | 0 tools/cgeist/Test/Verification/fscanf.c | 2 +- tools/cgeist/Test/Verification/hist.c | 54 +- .../Test/Verification/loop-exit-value.c | 43 + .../Test/Verification/store-forward-loop.c | 58 + .../Test/Verification/while-rotated-carry.c | 56 + tools/cgeist/Test/lit.cfg | 79 - tools/cgeist/XlxPrelude.inc.in | 2 + tools/cgeist/driver.cc | 277 +- tools/cgeist/include/xlx/xlx_prelude.h | 102 + tools/polymer/build_polymer_deps.sh | 0 tools/polymer/example/flow | 0 tools/polymer/example/handwritten/run-par.sh | 0 tools/polymer/example/handwritten/run.sh | 0 .../polymer/example/polybench/benchmark-polly | 0 tools/polymer/example/polybench/check-split | 0 tools/polymer/example/polybench/compile | 0 tools/polymer/example/polybench/eval-perf | 0 tools/polymer/example/polybench/execute | 0 tools/polymer/example/polybench/extract | 0 .../polymer/example/polybench/find-splittable | 0 .../polybench/list_num_polyhedral_stmts | 0 tools/polymer/example/polybench/opt | 0 .../example/polybench/sanity-check-data | 0 .../example/polybench/sanity-check-sched | 0 tools/polymer/example/polybench/search-split | 0 .../polybench/split-and-merge/eval-split-c | 0 .../split-and-merge/eval-split-c-batch | 0 .../polybench/split-and-merge/eval-split-mlir | 0 .../split-and-merge/eval-split-mlir-batch | 0 .../split-and-merge/eval-split-mlir-heuristic | 0 .../eval-split-mlir-heuristic-batch | 0 .../split-and-merge/eval-split-mlir-perf | 0 .../split-and-merge/report-timing.py | 0 tools/polymer/scripts/build-with-polygeist.sh | 0 tools/polymer/scripts/update-pluto.sh | 0 3239 files changed, 467882 insertions(+), 1717 deletions(-) create mode 100644 debug.sh create mode 100644 docs/hls-pragmas.md create mode 100644 docs/xlx-real-headers.md create mode 100644 durbin_ref create mode 100644 lib/polygeist/Passes/AffineScalRep.cpp create mode 100644 patches/llvm-project/0001-xlx-bitwidth.patch create mode 100644 patches/llvm-project/README.md create mode 100644 tools/cgeist/Lib/CGXlxBuiltin.cc create mode 100644 tools/cgeist/Lib/HLSAutoInline.cc create mode 100644 tools/cgeist/Lib/HLSAutoInline.h create mode 100644 tools/cgeist/Lib/HLSPragma.cc create mode 100644 tools/cgeist/Lib/HLSPragma.h create mode 100644 tools/cgeist/Lib/HLSPragmaInternal.h create mode 100644 tools/cgeist/Lib/HLSPragmaMaterialize.cc create mode 100644 tools/cgeist/Lib/HLSPragmaParse.cc create mode 100644 tools/cgeist/Lib/HLSPragmaSema.cc create mode 100644 tools/cgeist/Lib/HLSPragmaSpec.cc delete mode 100644 tools/cgeist/Lib/HandleHLS.cc delete mode 100644 tools/cgeist/Lib/HandleHLS.h create mode 100644 tools/cgeist/Lib/XlxDeadStore.cc create mode 100644 tools/cgeist/Lib/XlxLoopScalarPromote.cc create mode 100644 tools/cgeist/Lib/XlxMathCore.cc create mode 100644 tools/cgeist/Lib/XlxMathCore.h create mode 100644 tools/cgeist/Lib/XlxProxyScalarize.cc create mode 100644 tools/cgeist/Lib/XlxStringBits.cc create mode 100644 tools/cgeist/Lib/XlxStringBits.h delete mode 100644 tools/cgeist/Lib/pragmaHandlerHLS.cc delete mode 100644 tools/cgeist/Lib/pragmaHandlerHLS.h create mode 100644 tools/cgeist/Test/HLS/HLSAllocation.cpp create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/README.md create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/ap_axi_sdata.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/ap_cint.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/ap_fixed.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/ap_int.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/cgeist_flags create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/hls_half.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/hls_math.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/hls_stream.h create mode 100644 tools/cgeist/Test/HLS/Inputs/vitis/hls_vector.h create mode 100644 tools/cgeist/Test/HLS/aggregate/aggregate.c create mode 100644 tools/cgeist/Test/HLS/aggregate/propagate.cpp create mode 100644 tools/cgeist/Test/HLS/alias/alias.c create mode 100644 tools/cgeist/Test/HLS/allocation/allocation.cpp create mode 100644 tools/cgeist/Test/HLS/array_partition/errors.c create mode 100644 tools/cgeist/Test/HLS/array_partition/inline-carry-partition.cpp create mode 100644 tools/cgeist/Test/HLS/array_partition/lowering.c create mode 100644 tools/cgeist/Test/HLS/array_partition/options.c create mode 100644 tools/cgeist/Test/HLS/array_partition/variables.c create mode 100644 tools/cgeist/Test/HLS/array_reshape/array_reshape.c create mode 100644 tools/cgeist/Test/HLS/bind_op/bind_op.c create mode 100644 tools/cgeist/Test/HLS/bind_storage/bind_storage.c create mode 100644 tools/cgeist/Test/HLS/bind_storage/resource_core.c create mode 100644 tools/cgeist/Test/HLS/cache/cache.c create mode 100644 tools/cgeist/Test/HLS/consumer/contract-shape.c create mode 100644 tools/cgeist/Test/HLS/consumer/hls-est-banking.c create mode 100644 tools/cgeist/Test/HLS/consumer/hls-est-pipeline.c create mode 100644 tools/cgeist/Test/HLS/dataflow/dataflow.c create mode 100644 tools/cgeist/Test/HLS/dependence/dependence.c create mode 100644 tools/cgeist/Test/HLS/expression_balance/expression_balance.c create mode 100644 tools/cgeist/Test/HLS/function_instantiate/function_instantiate.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt1/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt2/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt3/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt4/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt5/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt1/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt2/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt3/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt4/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt5/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt1/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt2/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt3/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt4/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt5/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt1/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt2/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt3/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt4/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt5/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt1/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt2/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt3/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt4/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt5/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt1/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt2/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt3/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt4/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt5/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt1/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt2/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt3/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt4/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt5/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt1/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt2/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt3/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt4/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt5/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt1/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt2/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt3/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt4/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt5/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt1/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt2/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt3/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt4/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt5/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt1/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt2/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt3/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt4/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt5/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt1/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt2/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt3/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt4/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt5/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt1/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt2/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt3/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt4/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt5/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt1/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt2/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt3/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt4/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt5/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt1/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt2/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt3/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt4/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt5/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt1/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt2/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt3/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt4/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt5/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt1/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt2/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt3/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt4/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt5/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt1/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt2/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt3/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt4/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt5/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt1/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt2/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt3/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt4/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt5/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq__opt5/src/k15mmseq.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_imbalanced__opt5/src/k15mmseq_imbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu__opt5/src/k15mmseq_relu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu_imbalanced__opt5/src/k15mmseq_relu_imbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree__opt5/src/k15mmtree.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_imbalanced__opt5/src/k15mmtree_imbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu__opt5/src/k15mmtree_relu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu_imbalanced__opt5/src/k15mmtree_relu_imbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt1/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt2/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt3/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt4/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt5/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt1/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt2/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt3/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt4/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt5/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt1/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt2/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt3/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt4/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt5/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_EvolveGCN/src/DGNN-booster1-EvolveGCN.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_convLSTM/src/DGNN-booster2-GCRN-M2.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_fixed_dataset/src/GP_kernel_100_10_success_fixed.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_float_dataset/src/GP_kernel_100_10_success.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/conv1x1_new.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/dwconv3x3_new.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/dwconv5x5.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/conv1x1.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/dwconv3x3.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/add.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/attention.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/conv.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/datatypes.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/dcl.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/gelu.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/hardware.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/kernel.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/layernorm.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/linear.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/model.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/moe.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/tbutil.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/util.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/ViT_compute.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/add.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/attention.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/gelu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/layernorm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/linear.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/moe.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/BU.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/Mmap2Stream_tf_0_1_limbs.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/NTT_kernel.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/TFBuf_wiFW_0.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/TFBuf_wiFW_1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/TFBuf_wiFW_2.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/TFBuf_woFW_3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/dual_interface_FIFO_receive.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/dual_interface_FIFO_send.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/fwd_load_inv_store_poly_1_limbs.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/fwd_store_inv_load_poly_1_limbs.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/input_selector_single.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/output_slector_single.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/shuffler_buf.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/shuffler_in.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/shuffler_out_shift.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/ntt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/shuffler_out_shuff.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/coroutine.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/traits.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/buffer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/mmap.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/stream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/tapa.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/task.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/vec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/add.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/lpc.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/private.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/debayer.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/dehaze.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/pipeline.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/pipeline.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/whitebalance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/debayer.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/dehaze.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/pipeline.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/pipeline.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/whitebalance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/debayer.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/dehaze.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/pipeline.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/pipeline.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/whitebalance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp_single_class.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/fp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/gradient.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/io.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/systolic_array.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_base_hls/GIN_virtualnode_compute.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_base_hls/dcl.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_base_hls/main.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_bitstream/GIN_virtualnode_compute.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_bitstream/dcl.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_pipelined_hls/GIN_virtualnode_compute.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_pipelined_hls/dcl.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/GNN-virtual-node/source_code/gin_vn_pipelined_hls/main.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/common.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/common.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/fxp_sqrt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/geometry.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/tb_common.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/trianglemesh.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/HLS/trianglemesh.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/golden_c/common.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/golden_c/common.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/golden_c/geometry.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/golden_c/tb_common.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/golden_c/trianglemesh.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Ray-tracing/source_code/golden_c/trianglemesh.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers/conv_3x3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__conv_synth/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__conv_synth/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__conv_synth/conv_3x3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/conv_1x1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/conv_3x3_id16.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/conv_3x3_id3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/conv_ver3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_24Layers__yolov3_tiny_synth/yolov3_tiny.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers/conv_3x3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__conv_synth/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__conv_synth/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__conv_synth/conv_3x3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/config.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/conv_1x1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/conv_3x3_id16.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/conv_3x3_id3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/conv_ver3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Yolo-v3-tiny/source_code/src_4Layers__yolov3_tiny_synth/yolov3_tiny.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/baseline/cim_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/baseline/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/baseline/tiled_cim_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/baseline/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/baseline/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/optimized/cim_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/optimized/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/optimized/tiled_cim_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/optimized/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/hls/optimized/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/on-board/cim_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/on-board/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/on-board/tiled_cim_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/on-board/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Analog-CIM/on-board/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/Golden C/unoptimized/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/Golden C/unoptimized/conv_3x3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/Golden C/unoptimized/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/Golden C/unoptimized/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/Golden C/unoptimized/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/HLS/optimized/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/HLS/optimized/conv_3x3.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/HLS/optimized/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/HLS/optimized/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/DSC_Acceleration/HLS/optimized/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/ECG_Classifier/HLS/Baseline/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/ECG_Classifier/HLS/Baseline/conv1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/ECG_Classifier/HLS/Optimized/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/ECG_Classifier/HLS/Optimized/conv1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Eyeriss/convolution.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Eyeriss/convolution.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/ant.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/cxxopts/cxxopts.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/args.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/chrono.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/color.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/compile.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/core.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/format-inl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/format.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/locale.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/os.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/ostream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/posix.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/printf.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/include/fmt/ranges.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/json.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/kd_tree.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/local_search.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/local_search.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/logging.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/pheromone.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/problem_instance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/progargs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/rand.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/FACO/src/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchOptimized/two_opt_nn.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/cxxopts/cxxopts.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/args.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/chrono.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/color.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/compile.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/core.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/format-inl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/format.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/locale.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/os.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/ostream.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/posix.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/printf.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/include/fmt/ranges.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/LocalSearchUnoptimized/two_opt_nn.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/FocusedACO/HLS/three-opt/three_opt_nn.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/avg_pool/avg_pool.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/avg_pool/avg_pool.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/bundles.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/cam/cam.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/cam/max_idx.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv1/conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv1/conv1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv1/conv1.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv1/io.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv1/params.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_3x3_s1/conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_3x3_s1/conv_3x3_s1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_3x3_s1/conv_3x3_s1.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_3x3_s1/io.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_3x3_s1/params.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_ds/conv_ds.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/conv_ds/conv_ds.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/linear_fc/linear_fc.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/linear_fc/linear_fc.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/maxpool/max_pool.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/resize.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/resnet18.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/sim_util.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/GradCAM/src_hls/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Monte-Carlo/MersenneTwister/mersenneTwister.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Monte-Carlo/MersenneTwister/mersenneTwister.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Monte-Carlo/Paths/optionValueAverage.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Monte-Carlo/Paths/optionValueAverage.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Monte-Carlo/Random 100 Paths/genRandNums.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/Monte-Carlo/Random 100 Paths/genRandNums.hpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/CSP_Layer1Layer2/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/CSP_Layer1Layer2/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/CSP_Layer1Layer2/yolov4_tiny.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Conv2D_Layer1Layer2/GOLDEN/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Conv2D_Layer1Layer2/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Conv2D_Layer1Layer2/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Conv2D_Layer1Layer2/yolov4_tiny.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Maxpool_Layer/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Maxpool_Layer/maxpool2D.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Maxpool_Layer/tiled_maxpool2D.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Maxpool_Layer/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Maxpool_Layer/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L1/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L1/conv_7x7.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L1/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L1/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L1/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L2/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L2/conv_7x7.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L2/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L2/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L2/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L3/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L3/conv_7x7.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L3/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L3/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L3/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L4/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L4/conv_7x7.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L4/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L4/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L4/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L5/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L5/conv_7x7.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L5/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L5/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L5/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L6/conv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L6/conv_7x7.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L6/tiled_conv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L6/utils.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2023_spring/YOLOv4-Tiny-Accelerator/HLS_C/Project_L6/utils.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Apurba_Prasad_Padhy_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Apurba_Prasad_Padhy_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Gaurav_Singh_Chandrabhan_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Gaurav_Singh_Chandrabhan_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Gaurav_Singh_Chandrabhan_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Gaurav_Singh_Chandrabhan_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Hsuanchen_Fang_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Hsuanchen_Fang_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Hsuanchen_Fang_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Hsuanchen_Fang_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Mingyu_Zhang_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Mingyu_Zhang_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Mingyu_Zhang_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Mingyu_Zhang_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/NeuroFPGA_Project/neural_hls_NeuroFPGA/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/NeuroFPGA_Project/neural_hls_NeuroFPGA/top_new.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/NeuroFPGA_Project/symbolic_HLS/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Sunchips_Topic5_Modular_Multiplication/16.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Sunchips_Topic5_Modular_Multiplication/32.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Sunchips_Topic5_Modular_Multiplication/64.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Sunchips_Topic5_Modular_Multiplication/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Sunchips_Topic5_Modular_Multiplication/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Xiyin_Xue_Lab2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Xiyin_Xue_Lab2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Xiyin_xue_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/Xiyin_xue_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/adithi_upadhya_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/adithi_upadhya_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/adithi_upadhya_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/adithi_upadhya_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/akshaya_shivprasad_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/akshaya_shivprasad_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/akshaya_shivprasad_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/akshaya_shivprasad_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anirudh_tulasi_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anirudh_tulasi_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anirudh_tulasi_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anirudh_tulasi_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anuvab_sen_ece_8893_spring_29/Anuvab_Sen_lab_2_ECE_8893_spring_29/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anuvab_sen_ece_8893_spring_29/Anuvab_Sen_lab_2_ECE_8893_spring_29/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anuvab_sen_ece_8893_spring_29/Anuvab_Sen_lab_3_ECE_8893_spring_29/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/anuvab_sen_ece_8893_spring_29/Anuvab_Sen_lab_3_ECE_8893_spring_29/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/apurba_prasad_padhy_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/apurba_prasad_padhy_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/arati_ganesh_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/arati_ganesh_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/arati_ganesh_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/arati_ganesh_ece8893_spring25_lab3/matmul.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/arati_ganesh_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ayush_saxena_ece_8893_spring_26/Ayush_Saxena_lab_2_ECE_8893_spring_26/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ayush_saxena_ece_8893_spring_26/Ayush_Saxena_lab_2_ECE_8893_spring_26/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ayush_saxena_ece_8893_spring_26/Ayush_Saxena_lab_3_ECE_8893_spring_26/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ayush_saxena_ece_8893_spring_26/Ayush_Saxena_lab_3_ECE_8893_spring_26/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/barry_walker_lab_2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/barry_walker_lab_2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/barry_walker_lab_3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/barry_walker_lab_3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/connor_talley_lab_2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/connor_talley_lab_2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/connor_talley_lab_3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/connor_talley_lab_3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/davendra_maharaj_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/davendra_maharaj_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/davendra_maharaj_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/davendra_maharaj_ece8893_spring25_lab3/spmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/davendra_maharaj_ece8893_spring25_lab3/spmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/davendra_maharaj_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ece8893_dataset_lab_1/0001/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ece8893_dataset_lab_1/0001/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ece8893_dataset_lab_1/0002/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ece8893_dataset_lab_1/0002/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/gabriel_lopez_lugo_ece8893_spring2025/gabriel_lopez_lugo_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/gabriel_lopez_lugo_ece8893_spring2025/gabriel_lopez_lugo_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/gabriel_lopez_lugo_ece8893_spring2025/gabriel_lopez_lugo_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/gabriel_lopez_lugo_ece8893_spring2025/gabriel_lopez_lugo_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/hyungseok_bae_lab2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/hyungseok_bae_lab2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/hyungseok_bae_lab3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/hyungseok_bae_lab3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kaihong_lin_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kaihong_lin_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kaihong_lin_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kaihong_lin_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kamya_hari_lab_2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kamya_hari_lab_2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kamya_hari_lab_3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/kamya_hari_lab_3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/karthikeya_sharma_ece8893_spring_25_lab_2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/karthikeya_sharma_ece8893_spring_25_lab_2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/karthikeya_sharma_ece8893_spring_25_lab_3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/karthikeya_sharma_ece8893_spring_25_lab_3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab2_hanchen/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab2_hanchen/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab2_sushkrutha/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab2_sushkrutha/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab3_hanchen/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab3_hanchen/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab3_sushkrutha/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/lab3_sushkrutha/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/matrix_methods/ben_hall_lab2_2025_attention/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/matrix_methods/ben_hall_lab2_2025_attention/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/matrix_methods/ben_hall_lab3_sparse_matrix_multiplication/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/matrix_methods/ben_hall_lab3_sparse_matrix_multiplication/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/max_beaulieu_Lab_3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/max_beaulieu_Lab_3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/michael_meng_ece_8893_spring_25/lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/michael_meng_ece_8893_spring_25/lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/michael_meng_ece_8893_spring_25/lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/michael_meng_ece_8893_spring_25/lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/minjun_kim_Lab2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/minjun_kim_Lab2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/minjun_kim_Lab3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/minjun_kim_Lab3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mizanur_Lab2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mizanur_Lab2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mizanur_Lab3_2025/compute_SpMM.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mizanur_Lab3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mizanur_Lab3_2025/generate_matrices.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mizanur_Lab3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mohammad_zain_lab_2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mohammad_zain_lab_2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mohammad_zain_lab_3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/mohammad_zain_lab_3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nayan_nair_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nayan_nair_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nayan_nair_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nayan_nair_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/neuro_monarchs_neural_kernel_ece8893_spring_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/neuro_monarchs_neural_kernel_ece8893_spring_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/neuro_monarchs_symbolic_kernel_ece8893_spring_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/neuro_monarchs_symbolic_kernel_ece8893_spring_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_p_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_p_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_p_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_p_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_s_ece8893_sp25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_s_ece8893_sp25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_s_ece8893_sp25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/nikhil_s_ece8893_sp25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/oscar_baglivio_lab_2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/oscar_baglivio_lab_2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/oscar_baglivio_lab_3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/oscar_baglivio_lab_3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pengzhao_liu_Lab2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pengzhao_liu_Lab2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pengzhao_liu_Lab3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pengzhao_liu_Lab3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pranay_kamineny_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pranay_kamineny_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pranay_kamineny_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/pranay_kamineny_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ritik_raj_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ritik_raj_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ritik_raj_lab3/dcl_dense.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/ritik_raj_lab3/top_dense.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sahith_lab2_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sahith_lab2_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sahith_lab3_2025/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sahith_lab3_2025/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shengxi_liang_ece8893_spring_25/Shengxi_Liang_LAB2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shengxi_liang_ece8893_spring_25/Shengxi_Liang_LAB2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shengxi_liang_ece8893_spring_25/Shengxi_Liang_LAB3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shengxi_liang_ece8893_spring_25/Shengxi_Liang_LAB3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shibao_su_ece8893_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shibao_su_ece8893_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shibao_su_ece8893_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shibao_su_ece8893_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shreesahitya_balaje_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shreesahitya_balaje_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shreesahitya_balaje_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/shreesahitya_balaje_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/siddharth_khatri_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/siddharth_khatri_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/siddharth_khatri_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/siddharth_khatri_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sreenidhireddy_bommu_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sreenidhireddy_bommu_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sreenidhireddy_bommu_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/sreenidhireddy_bommu_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/stefan_test_design/my_kernel.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/suyeon_yoon_lab3_spring25/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/suyeon_yoon_lab3_spring25/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/vishnu_varma_venkata_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/vishnu_varma_venkata_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/vishnu_varma_venkata_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/vishnu_varma_venkata_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zihan_qi_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zihan_qi_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zihan_qi_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zihan_qi_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zijun_wang_ece8893_spring25_lab2/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zijun_wang_ece8893_spring25_lab2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zijun_wang_ece8893_spring25_lab3/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_spring_2025/zijun_wang_ece8893_spring25_lab3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/DGN_compute.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/conv_layer.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/conv_layer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/finalize.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/finalize.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/globals.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/linear.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/linear.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/load_inputs.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/load_inputs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/message_passing.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/message_passing.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/node_embedding.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/node_embedding.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/src/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/dgn/testbench/testbench.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/GAT_compute.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/conv_layer.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/conv_layer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/finalize.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/finalize.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/globals.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/linear.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/linear.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/load_inputs.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/load_inputs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/message_passing.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/message_passing.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/node_embedding.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/node_embedding.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/src/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gat/testbench/testbench.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/GCN_compute.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/conv_layer.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/conv_layer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/finalize.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/finalize.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/globals.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/linear.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/linear.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/load_inputs.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/load_inputs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/message_passing.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/message_passing.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/node_embedding.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/node_embedding.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/src/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gcn/testbench/testbench.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/GIN_compute.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/conv_layer.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/conv_layer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/finalize.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/finalize.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/globals.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/linear.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/linear.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/load_inputs.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/load_inputs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/message_passing.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/message_passing.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/node_embedding.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/node_embedding.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/src/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/gin/testbench/testbench.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/PNA_compute.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/conv_layer.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/conv_layer.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/dcl.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/finalize.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/finalize.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/globals.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/linear.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/linear.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/load_inputs.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/load_inputs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/message_passing.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/message_passing.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/node_embedding.cc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/node_embedding.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/src/util.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/flowgnn/pna/testbench/testbench.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/Llama_GPT_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/Llama_GPT_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_op1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_op1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_op2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_op2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_op3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/activation_op3/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attention_op_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attention_op_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attention_op_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attention_op_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attention_op_p3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attention_op_p3/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attn_breakdown_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attn_breakdown_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attn_breakdown_op1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attn_breakdown_op1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attn_breakdown_op2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/attn_breakdown_op2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_A/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_A/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_B/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_B/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_C/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_C/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_op1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_op1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_op2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_op2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_op3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_block_op3/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/conv_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_module_large/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_module_large/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_module_small/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_module_small/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_p3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_dims_p3/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_p3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/diff_orders_p3/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/gpt_transformer_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/gpt_transformer_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/llama_transformer_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/llama_transformer_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mlp/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mlp/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_module_dot/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_module_dot/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_module_mm/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_module_mm/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_module_mmv/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_module_mmv/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_p3/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/mult_op_p3/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/testing_impl/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/testing_impl/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/testing_unroll/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/testing_unroll/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/tiled_attn_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/tiled_attn_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/tiled_attn_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/tiled_attn_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/tiled_attn_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/tiled_attn_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/vec_mtx_module/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/vec_mtx_module/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/vec_mtx_p1/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/vec_mtx_p1/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/vec_mtx_p2/top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/forgebench/vec_mtx_p2/top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_gcn_qm9/gnn_builder_lib.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_gcn_qm9/model.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_gcn_qm9/model.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_gin_qm9/gnn_builder_lib.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_gin_qm9/model.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_gin_qm9/model.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_pna_qm9/gnn_builder_lib.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_pna_qm9/model.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_pna_qm9/model.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_sage_qm9/gnn_builder_lib.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_sage_qm9/model.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/gnnbuilder/designs/fpga_sage_qm9/model.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/2mm/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/2mm/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/2mm/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/3mm/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/3mm/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/3mm/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/adi/adi.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/adi/adi.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/adi/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/aes/aes.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/aes/aes.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/aes/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/atax-medium/atax-medium.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/atax-medium/atax-medium.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/atax-medium/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/atax/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/atax/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/atax/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg-large/bicg-large.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg-large/bicg-large.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg-large/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg-medium/bicg-medium.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg-medium/bicg-medium.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg-medium/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/bicg/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/correlation/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/correlation/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/correlation/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/covariance/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/covariance/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/covariance/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/doitgen-red/doitgen-red.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/doitgen-red/doitgen-red.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/doitgen-red/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/doitgen/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/doitgen/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/doitgen/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/fdtd-2d-large/fdtd-2d-large.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/fdtd-2d-large/fdtd-2d-large.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/fdtd-2d-large/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/fdtd-2d/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/fdtd-2d/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/fdtd-2d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-blocked/gemm-blocked.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-blocked/gemm-blocked.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-blocked/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-ncubed/gemm-ncubed.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-ncubed/gemm-ncubed.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-ncubed/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-p-large/gemm-p-large.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-p-large/gemm-p-large.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-p-large/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-p/gemm-p.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-p/gemm-p.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemm-p/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemver-medium/gemver-medium.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemver-medium/gemver-medium.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemver-medium/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemver/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemver/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gemver/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gesummv-medium/gesummv-medium.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gesummv-medium/gesummv-medium.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gesummv-medium/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gesummv/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gesummv/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/gesummv/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/heat-3d/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/heat-3d/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/heat-3d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/jacobi-1d/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/jacobi-1d/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/jacobi-1d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/jacobi-2d/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/jacobi-2d/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/jacobi-2d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/md/md.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/md/md.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/md/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/mvt-medium/mvt-medium.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/mvt-medium/mvt-medium.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/mvt-medium/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/mvt/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/mvt/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/mvt/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/nw/nw.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/nw/nw.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/nw/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/seidel-2d/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/seidel-2d/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/seidel-2d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/spmv-crs/spmv-crs.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/spmv-crs/spmv-crs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/spmv-crs/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/spmv-ellpack/spmv-ellpack.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/spmv-ellpack/spmv-ellpack.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/spmv-ellpack/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/stencil-3d/stencil-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/stencil-3d/stencil-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/stencil-3d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/stencil_stencil2d/stencil_stencil2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/stencil_stencil2d/stencil_stencil2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/stencil_stencil2d/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm-opt-medium/symm-opt-medium.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm-opt-medium/symm-opt-medium.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm-opt-medium/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm-opt/symm-opt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm-opt/symm-opt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm-opt/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/symm/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/syr2k/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/syr2k/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/syr2k/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/syrk/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/syrk/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/syrk/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/trmm-opt/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/trmm-opt/trmm-opt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/trmm-opt/trmm-opt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/trmm/testbench.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/trmm/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hlsyn-vitis/vivado-target/sources/trmm/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF1/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF1/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF16/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF16/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF2/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF2/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF32/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF32/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF4/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF4/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF8/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__UF8/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__no_StagePipeline/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__no_StagePipeline/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__original_C_style/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n1024__original_C_style/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF1/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF1/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF16/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF16/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF2/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF2/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF32/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF32/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF4/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF4/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF8/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__UF8/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__no_StagePipeline/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__no_StagePipeline/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__original_C_style/FFT.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/hp_fft_hls/n256__original_C_style/FFT.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/aes_table/aes.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/aes_table/aes_table.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/aes_table/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/aes_tableless/aes.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/aes_tableless/aes_tableless.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/aes_tableless/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/backprop/backprop.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/backprop/backprop.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/backprop/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/bfs_bulk/bfs.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/bfs_bulk/bfs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/bfs_bulk/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/bfs_queue/bfs.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/bfs_queue/bfs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/bfs_queue/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/fft_transpose/fft.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/fft_transpose/fft.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/fft_transpose/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/gemm_blocked/gemm.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/gemm_blocked/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/gemm_blocked/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/gemm_ncubed/gemm.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/gemm_ncubed/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/gemm_ncubed/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/md_grid/md.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/md_grid/md.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/md_grid/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/md_knn/md.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/md_knn/md.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/md_knn/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/nw/nw.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/nw/nw.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/nw/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/sort_merge/sort.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/sort_merge/sort.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/sort_merge/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/sort_radix/sort.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/sort_radix/sort.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/sort_radix/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/spmv_crs/spmv.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/spmv_crs/spmv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/spmv_crs/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/spmv_ellpack/spmv.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/spmv_ellpack/spmv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/spmv_ellpack/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/stencil2D/stencil.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/stencil2D/stencil.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/stencil2D/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/stencil3D/stencil.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/stencil3D/stencil.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/stencil3D/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/viterbi/support.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/viterbi/viterbi.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/machsuite/viterbi/viterbi.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/atax/src/atax.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/bicg/src/bicg.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/gemm/src/gemm.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/gesummv/src/gesummv.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/k2mm/src/k2mm.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/k2mm/src/k2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/k3mm/src/k3mm.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/k3mm/src/k3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/mvt/src/mvt.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/syr2k/src/syr2k.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/syrk/src/syrk.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__medium/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__mini/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__fixed__small/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__medium/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__mini/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__small/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/2mm/src/2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/2mm/src/2mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/3mm/src/3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/3mm/src/3mm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/atax/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/atax/src/atax.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/bicg/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/bicg/src/bicg.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/cholesky/src/cholesky.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/cholesky/src/cholesky.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/correlation/src/correlation.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/correlation/src/correlation.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/covariance/src/covariance.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/covariance/src/covariance.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/doitgen/src/doitgen.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/doitgen/src/doitgen.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/durbin/src/durbin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/durbin/src/durbin.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/fdtd-2d/src/fdtd-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/fdtd-2d/src/fdtd-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/floyd-warshall/src/floyd-warshall.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/floyd-warshall/src/floyd-warshall.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gemm/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gemm/src/gemm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gemver/src/gemver.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gemver/src/gemver.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gesummv/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gesummv/src/gesummv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gramschmidt/src/gramschmidt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/gramschmidt/src/gramschmidt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/heat-3d/src/heat-3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/heat-3d/src/heat-3d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/jacobi-1d/src/jacobi-1d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/jacobi-1d/src/jacobi-1d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/jacobi-2d/src/jacobi-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/jacobi-2d/src/jacobi-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/lu/src/lu.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/lu/src/lu.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/ludcmp/src/ludcmp.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/ludcmp/src/ludcmp.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/mvt/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/mvt/src/mvt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/nussinov/src/nussinov.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/nussinov/src/nussinov.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/seidel-2d/src/seidel-2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/seidel-2d/src/seidel-2d.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/symm/src/symm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/symm/src/symm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/syr2k/src/syr2k.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/syr2k/src/syr2k.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/syrk/src/syrk.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/syrk/src/syrk.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/trisolv/src/trisolv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/trisolv/src/trisolv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/trmm/src/trmm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/polybench__reproducible/polybench__float__unsafe__math__mini/trmm/src/trmm.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/23_pp4fpgas_unoptimized_fft/fft.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/23_pp4fpgas_unoptimized_fft/fft_sw.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/23_pp4fpgas_unoptimized_fft/tw_i.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/23_pp4fpgas_unoptimized_fft/tw_r.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/24_pp4fpgas_multi_stage_fft/fft_stages.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/24_pp4fpgas_multi_stage_fft/fft_streaming.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/24_pp4fpgas_multi_stage_fft/tw_i.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/24_pp4fpgas_multi_stage_fft/tw_r.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_canonize_tree.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_compute_bit_length.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_create_codeword.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_create_tree.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_encoding.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_filter.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_sort.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/25_pp4fpgas_huffman_encoding/huffman_truncate_tree.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/26_pp4fpgas_matmul/matrixmultiplication.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/26_pp4fpgas_matmul/matrixmultiplication.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/27_pp4fpgas_parallel_merge_sort/merge_sort_parallel.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/pp4fpgas/27_pp4fpgas_parallel_merge_sort/merge_sort_parallel.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/3d-rendering/src/host/typedefs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/3d-rendering/src/sdsoc/rendering.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/3d-rendering/src/sdsoc/rendering.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/Accel.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/Accel.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/AccelPrint.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/AccelSchedule.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/AccelTest.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/Dense.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/accel/InputConv.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/utils/Common.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/utils/Debug.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/BNN/cpp/utils/Typedefs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/digit-recognition/src/host/typedefs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/digit-recognition/src/sdsoc/digitrec.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/digit-recognition/src/sdsoc/digitrec.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/host/typedefs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc/face_detect.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc/haar_dataEWC_with_partitioning.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc/haar_dataRcc_with_partitioning.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc/haar_mapping.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc__origin/face_detect_origin.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc__origin/haar_dataEWC_with_partitioning.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc__origin/haar_dataRcc_with_partitioning.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/face-detection/src/sdsoc__origin/haar_mapping.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/optical-flow/src/host/typedefs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/optical-flow/src/sdsoc/optical_flow.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/optical-flow/src/sdsoc/optical_flow_original.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/optical-flow/src/sdsoc__hls_template/optical_flow.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/optical-flow/src/sdsoc__hls_template/optical_flow.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/spam-filter/src/host/typedefs.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/spam-filter/src/sdsoc/lut.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/spam-filter/src/sdsoc/sgd.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/rosetta/spam-filter/src/sdsoc/sgd.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__blur/blur.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__contrast/contrast.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__denoise2d/denoise2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__denoise3d/denoise3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__erosion/erosion.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__heat3d/heat3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__jacobi2d/jacobi2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__jacobi3d/jacobi3d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__seidel2d/seidel2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__sobel2d/sobel2d.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/soda/soda__xcorr/xcorr.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/dct/dct.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/dct/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/fir/fir_hls.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/fir/fir_hls.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/fir/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/histogram/histogram.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/histogram/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/matrix_multiplication/matrix_mul.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/matrix_multiplication/matrix_mul.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/matrix_multiplication/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/mergesort/mergesort.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/mergesort/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/normals/normals.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/normals/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/sobel_filter_x/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/sobel_filter_x/sobel.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/sobel_filter_x/sobel_subdimx.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/sobel_filter_y/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/sobel_filter_y/sobel.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/sobel_filter_y/sobel_subdimy.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/spmv/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/spmv/spmv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/template_matching/fpga_temp_match.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/template_matching/fpga_temp_matching.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/spector_hls/template_matching/params.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/Autoencoder__opt1/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/Autoencoder__opt2/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/Autoencoder__opt3/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/Autoencoder__opt4/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/Autoencoder__opt5/src/Autoencoder.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/FeedForward__opt1/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/FeedForward__opt2/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/FeedForward__opt3/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/FeedForward__opt4/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/FeedForward__opt5/src/FeedForward.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResMLP__opt1/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResMLP__opt2/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResMLP__opt3/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResMLP__opt4/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResMLP__opt5/src/ResMLP.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResidualBlock__opt1/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResidualBlock__opt2/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResidualBlock__opt3/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResidualBlock__opt4/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/ResidualBlock__opt5/src/ResidualBlock.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/atax__opt1/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/atax__opt2/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/atax__opt3/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/atax__opt4/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/atax__opt5/src/atax.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/bicg__opt1/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/bicg__opt2/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/bicg__opt3/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/bicg__opt4/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/bicg__opt5/src/bicg.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gemm__opt1/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gemm__opt2/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gemm__opt3/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gemm__opt4/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gemm__opt5/src/gemm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gesummv__opt1/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gesummv__opt2/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gesummv__opt3/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gesummv__opt4/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/gesummv__opt5/src/gesummv.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k2mm__opt1/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k2mm__opt2/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k2mm__opt3/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k2mm__opt4/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k2mm__opt5/src/k2mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k3mm__opt1/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k3mm__opt2/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k3mm__opt3/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k3mm__opt4/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k3mm__opt5/src/k3mm.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/mvt__opt1/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/mvt__opt2/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/mvt__opt3/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/mvt__opt4/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/stream_hls/mvt__opt5/src/mvt.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/01_basic_examples_vhls_fixed_point_sqrt/fxp_sqrt.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/01_basic_examples_vhls_fixed_point_sqrt/fxp_sqrt_top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/01_basic_examples_vhls_fixed_point_sqrt/fxp_sqrt_top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/02_basic_examples_vhls_fir_filter/cpp_FIR.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/02_basic_examples_vhls_fir_filter/cpp_FIR.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/02_basic_examples_vhls_fir_filter/cpp_FIR.inc create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/03_basic_examples_vhls_fixed_point_window_conv/window_fn_class.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/03_basic_examples_vhls_fixed_point_window_conv/window_fn_top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/03_basic_examples_vhls_fixed_point_window_conv/window_fn_top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/04_basic_examples_vhls_floating_point_window_conv/window_fn_class.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/04_basic_examples_vhls_floating_point_window_conv/window_fn_top.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/04_basic_examples_vhls_floating_point_window_conv/window_fn_top.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/05_basic_examples_vhls_ap_arithmetic/cpp_ap_int_arith.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/05_basic_examples_vhls_ap_arithmetic/cpp_ap_int_arith.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/06_basic_examples_vhls_parallel_loops/loop_functions.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/06_basic_examples_vhls_parallel_loops/loop_functions.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/07_basic_examples_vhls_imperfect_loops/loop_imperfect.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/07_basic_examples_vhls_imperfect_loops/loop_imperfect.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/08_basic_examples_vhls_max_bounded_loop/loop_max_bounds.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/08_basic_examples_vhls_max_bounded_loop/loop_max_bounds.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/09_basic_examples_vhls_perfect_nested_loops/loop_perfect.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/09_basic_examples_vhls_perfect_nested_loops/loop_perfect.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/10_basic_examples_vhls_pipelined_nested_loops/loop_pipeline.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/10_basic_examples_vhls_pipelined_nested_loops/loop_pipeline.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/11_basic_examples_vhls_accs_sequential/loop_sequential.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/11_basic_examples_vhls_accs_sequential/loop_sequential.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/12_basic_examples_vhls_accs_w_asserts/loop_sequential_assert.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/12_basic_examples_vhls_accs_w_asserts/loop_sequential_assert.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/13_basic_examples_vhls_accs_w_dataflow/loop_sequential.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/13_basic_examples_vhls_accs_w_dataflow/loop_sequential.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/14_basic_examples_vhls_static_memory/malloc_removed.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/14_basic_examples_vhls_static_memory/malloc_removed.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/15_basic_examples_vhls_pointer_casting/pointer_cast_native.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/15_basic_examples_vhls_pointer_casting/pointer_cast_native.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/16_basic_examples_vhls_double_pointer/pointer_double.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/16_basic_examples_vhls_double_pointer/pointer_double.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/17_basic_examples_vhls_axi_master/example.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/18_basic_examples_vhls_axi_stream_no_side_channel/example.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/19_basic_examples_vhls_multi_array_access_bottleneck/mem_bottleneck.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/19_basic_examples_vhls_multi_array_access_bottleneck/mem_bottleneck.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/20_basic_examples_vhls_resolved_array_access_bottleneck/mem_bottleneck_resolved.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/20_basic_examples_vhls_resolved_array_access_bottleneck/mem_bottleneck_resolved.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/21_basic_examples_vhls_uram_ecc/ecc_flags.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/21_basic_examples_vhls_uram_ecc/ecc_flags.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/22_basic_examples_vhls_fixed_point_hamming_window/hamming_window.c create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/22_basic_examples_vhls_fixed_point_hamming_window/hamming_window.h create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/vitis_examples/28_vitis_accel_examples_streaming_vadd/vadd.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/Inputs/whetstone/whetstone/kernel.cpp create mode 100644 tools/cgeist/Test/HLS/hlsfactory/SUMMARY.md create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__Autoencoder__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__Autoencoder__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__Autoencoder__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__Autoencoder__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__Autoencoder__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__DepthwiseSeparableConvBlock__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__DepthwiseSeparableConvBlock__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__DepthwiseSeparableConvBlock__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__DepthwiseSeparableConvBlock__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__DepthwiseSeparableConvBlock__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__FeedForward__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__FeedForward__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__FeedForward__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__FeedForward__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__FeedForward__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__MultiHeadSelfAttention1__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__MultiHeadSelfAttention1__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__MultiHeadSelfAttention1__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__MultiHeadSelfAttention1__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__MultiHeadSelfAttention1__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResMLP__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResMLP__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResMLP__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResMLP__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResMLP__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResidualBlock__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResidualBlock__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResidualBlock__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResidualBlock__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__ResidualBlock__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__Autoencoder__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__Autoencoder__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__Autoencoder__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__Autoencoder__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__Autoencoder__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__DepthwiseSeparableConvBlock__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__DepthwiseSeparableConvBlock__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__DepthwiseSeparableConvBlock__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__DepthwiseSeparableConvBlock__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__DepthwiseSeparableConvBlock__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__FeedForward__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__FeedForward__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__FeedForward__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__FeedForward__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__FeedForward__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__MultiHeadSelfAttention1__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__MultiHeadSelfAttention1__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__MultiHeadSelfAttention1__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__MultiHeadSelfAttention1__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__MultiHeadSelfAttention1__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResMLP__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResMLP__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResMLP__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResMLP__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResMLP__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResidualBlock__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResidualBlock__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResidualBlock__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResidualBlock__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__ResidualBlock__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__atax__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__atax__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__atax__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__atax__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__atax__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__bicg__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__bicg__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__bicg__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__bicg__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__bicg__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gemm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gemm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gemm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gemm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gemm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gesummv__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gesummv__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gesummv__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gesummv__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__gesummv__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k2mm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k2mm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k2mm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k2mm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k2mm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k3mm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k3mm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k3mm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k3mm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k3mm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_balanced__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_balanced__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_balanced__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_balanced__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_balanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_unbalanced__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_unbalanced__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_unbalanced__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_unbalanced__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmseq_unbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmtree_balanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__k7mmtree_unbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__mvt__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__mvt__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__mvt__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__mvt__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls______processed_dataset__mvt__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__atax__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__atax__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__atax__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__atax__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__atax__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__bicg__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__bicg__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__bicg__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__bicg__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__bicg__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gemm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gemm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gemm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gemm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gemm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gesummv__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gesummv__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gesummv__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gesummv__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__gesummv__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmseq__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmseq_imbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmseq_relu__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmseq_relu_imbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmtree__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmtree_imbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmtree_relu__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k15mmtree_relu_imbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k2mm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k2mm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k2mm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k2mm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k2mm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k3mm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k3mm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k3mm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k3mm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k3mm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_balanced__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_balanced__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_balanced__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_balanced__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_balanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_unbalanced__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_unbalanced__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_unbalanced__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_unbalanced__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmseq_unbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmtree_balanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__k7mmtree_unbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__mvt__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__mvt__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__mvt__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__mvt__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/WIP/WIP__stream_hls__mvt__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__DGNN_Booster_EvolveGCN.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__DGNN_Booster_convLSTM.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__GP_selection_kernel_fixed_dataset.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__GP_selection_kernel_float_dataset.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__Mask-Net_dataset.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__SkyNet_dataset.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/accelerators/accelerators__edgemoe.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__BU.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__Mmap2Stream_tf_0_1_limbs.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__NTT_kernel.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__TFBuf_wiFW_0.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__TFBuf_wiFW_1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__TFBuf_wiFW_2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__TFBuf_woFW_3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__dual_interface_FIFO_receive.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__dual_interface_FIFO_send.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__fwd_load_inv_store_poly_1_limbs.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__fwd_store_inv_load_poly_1_limbs.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__input_selector_single.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__output_slector_single.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__shuffler_buf.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__shuffler_in.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__shuffler_out_shift.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/auto_ntt/auto_ntt__shuffler_out_shuff.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/chstone/chstone__gsm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/chstone/chstone__sha.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Dehazing-denoising__source_code__src.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Dehazing-denoising__source_code__src__debayer_csynth.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Dehazing-denoising__source_code__src__script.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Explainable-ML__source_code.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__FLAT-acceleration__source_code__HLS.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__FLAT-acceleration__source_code__HLS__test_systolic_array.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__GNN-virtual-node__source_code__gin_vn_base_hls.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__GNN-virtual-node__source_code__gin_vn_bitstream.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__GNN-virtual-node__source_code__gin_vn_pipelined_hls.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Ray-tracing__source_code__HLS.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Ray-tracing__source_code__golden_c.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Yolo-v3-tiny__source_code__src_24Layers.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Yolo-v3-tiny__source_code__src_24Layers__conv_synth.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Yolo-v3-tiny__source_code__src_24Layers__yolov3_tiny_synth.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Yolo-v3-tiny__source_code__src_4Layers.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Yolo-v3-tiny__source_code__src_4Layers__conv_synth.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2022_fall/class_ece8893_2022_fall__Yolo-v3-tiny__source_code__src_4Layers__yolov3_tiny_synth.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Analog-CIM__hls__baseline.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Analog-CIM__hls__optimized.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Analog-CIM__on-board.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__DSC_Acceleration__Golden_C__unoptimized.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__DSC_Acceleration__HLS__optimized.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__ECG_Classifier__HLS__Baseline.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__ECG_Classifier__HLS__Optimized.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Eyeriss.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__FocusedACO__FACO.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__FocusedACO__HLS__LocalSearchOptimized.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__FocusedACO__HLS__LocalSearchUnoptimized.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__FocusedACO__HLS__three-opt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__avg_pool.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__cam.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__conv1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__conv_3x3_s1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__conv_ds.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__linear_fc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__GradCAM__src_hls__maxpool.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Monte-Carlo__MersenneTwister.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Monte-Carlo__Paths.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__Monte-Carlo__Random 100 Paths.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__CSP_Layer1Layer2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Conv2D_Layer1Layer2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Maxpool_Layer.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Project_L1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Project_L2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Project_L3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Project_L4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Project_L5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_2023_spring/class_ece8893_2023_spring__YOLOv4-Tiny-Accelerator__HLS_C__Project_L6.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Apurba_Prasad_Padhy_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Gaurav_Singh_Chandrabhan_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Gaurav_Singh_Chandrabhan_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Hsuanchen_Fang_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Hsuanchen_Fang_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Mingyu_Zhang_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Mingyu_Zhang_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__NeuroFPGA_Project__neural_hls_NeuroFPGA.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__NeuroFPGA_Project__symbolic_HLS.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Sunchips_Topic5_Modular_Multiplication.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Xiyin_Xue_Lab2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__Xiyin_xue_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__adithi_upadhya_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__adithi_upadhya_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__akshaya_shivprasad_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__akshaya_shivprasad_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__anirudh_tulasi_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__anirudh_tulasi_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__anuvab_sen_ece_8893_spring_29__Anuvab_Sen_lab_2_ECE_8893_spring_29.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__anuvab_sen_ece_8893_spring_29__Anuvab_Sen_lab_3_ECE_8893_spring_29.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__apurba_prasad_padhy_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__arati_ganesh_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__arati_ganesh_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__ayush_saxena_ece_8893_spring_26__Ayush_Saxena_lab_2_ECE_8893_spring_26.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__ayush_saxena_ece_8893_spring_26__Ayush_Saxena_lab_3_ECE_8893_spring_26.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__barry_walker_lab_2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__barry_walker_lab_3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__connor_talley_lab_2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__connor_talley_lab_3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__davendra_maharaj_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__davendra_maharaj_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__ece8893_dataset_lab_1__0001.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__ece8893_dataset_lab_1__0002.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__gabriel_lopez_lugo_ece8893_spring2025__gabriel_lopez_lugo_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__gabriel_lopez_lugo_ece8893_spring2025__gabriel_lopez_lugo_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__hyungseok_bae_lab2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__hyungseok_bae_lab3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__kaihong_lin_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__kaihong_lin_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__kamya_hari_lab_2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__kamya_hari_lab_3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__karthikeya_sharma_ece8893_spring_25_lab_2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__karthikeya_sharma_ece8893_spring_25_lab_3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__lab2_hanchen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__lab2_sushkrutha.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__lab3_hanchen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__lab3_sushkrutha.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__matrix_methods__ben_hall_lab2_2025_attention.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__matrix_methods__ben_hall_lab3_sparse_matrix_multiplication.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__max_beaulieu_Lab_3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__michael_meng_ece_8893_spring_25__lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__michael_meng_ece_8893_spring_25__lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__minjun_kim_Lab2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__minjun_kim_Lab3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__mizanur_Lab2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__mizanur_Lab3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__mohammad_zain_lab_2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__mohammad_zain_lab_3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__nayan_nair_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__nayan_nair_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__neuro_monarchs_neural_kernel_ece8893_spring_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__neuro_monarchs_symbolic_kernel_ece8893_spring_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__nikhil_p_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__nikhil_p_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__nikhil_s_ece8893_sp25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__nikhil_s_ece8893_sp25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__oscar_baglivio_lab_2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__oscar_baglivio_lab_3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__pengzhao_liu_Lab2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__pengzhao_liu_Lab3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__pranay_kamineny_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__pranay_kamineny_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__ritik_raj_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__ritik_raj_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__sahith_lab2_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__sahith_lab3_2025.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__shengxi_liang_ece8893_spring_25__Shengxi_Liang_LAB2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__shengxi_liang_ece8893_spring_25__Shengxi_Liang_LAB3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__shibao_su_ece8893_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__shibao_su_ece8893_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__shreesahitya_balaje_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__shreesahitya_balaje_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__siddharth_khatri_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__siddharth_khatri_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__sreenidhireddy_bommu_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__sreenidhireddy_bommu_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__stefan_test_design.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__suyeon_yoon_lab3_spring25.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__vishnu_varma_venkata_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__vishnu_varma_venkata_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__zihan_qi_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__zihan_qi_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__zijun_wang_ece8893_spring25_lab2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/class_ece8893_spring_2025/class_ece8893_spring_2025__zijun_wang_ece8893_spring25_lab3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/flowgnn/flowgnn__dgn.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/flowgnn/flowgnn__gat.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/flowgnn/flowgnn__gcn.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/flowgnn/flowgnn__gin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/flowgnn/flowgnn__pna.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__Llama_GPT_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__activation_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__activation_op1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__activation_op2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__activation_op3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__attention_op_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__attention_op_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__attention_op_p3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__attn_breakdown_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__attn_breakdown_op1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__attn_breakdown_op2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_A.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_B.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_C.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_block_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_block_op1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_block_op2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_block_op3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__conv_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_dims_module_large.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_dims_module_small.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_dims_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_dims_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_dims_p3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_orders_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_orders_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_orders_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__diff_orders_p3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__gpt_transformer_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__llama_transformer_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mlp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mult_op_module_dot.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mult_op_module_mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mult_op_module_mmv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mult_op_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mult_op_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__mult_op_p3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__testing_impl.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__testing_unroll.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__tiled_attn_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__tiled_attn_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__tiled_attn_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__vec_mtx_module.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__vec_mtx_p1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/forgebench/forgebench__vec_mtx_p2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/generate.py create mode 100644 tools/cgeist/Test/HLS/hlsfactory/gnnbuilder/gnnbuilder__designs__fpga_gcn_qm9.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/gnnbuilder/gnnbuilder__designs__fpga_gin_qm9.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/gnnbuilder/gnnbuilder__designs__fpga_pna_qm9.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/gnnbuilder/gnnbuilder__designs__fpga_sage_qm9.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__adi.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__aes.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__atax-medium.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__bicg-large.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__bicg-medium.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__doitgen-red.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__fdtd-2d-large.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gemm-blocked.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gemm-ncubed.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gemm-p-large.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gemm-p.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gemver-medium.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gesummv-medium.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__md.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__mvt-medium.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__nw.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__spmv-crs.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__spmv-ellpack.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__stencil-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__stencil_stencil2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__symm-opt-medium.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__symm-opt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__trmm-opt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hlsyn-vitis/hlsyn-vitis__vivado-target__sources__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__UF1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__UF16.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__UF2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__UF32.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__UF4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__UF8.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__no_StagePipeline.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n1024__original_C_style.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__UF1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__UF16.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__UF2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__UF32.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__UF4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__UF8.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__no_StagePipeline.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/hp_fft_hls/hp_fft_hls__n256__original_C_style.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/lit.local.cfg create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__aes_table.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__aes_tableless.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__backprop.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__bfs_bulk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__bfs_queue.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__fft_transpose.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__gemm_blocked.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__gemm_ncubed.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__md_grid.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__md_knn.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__nw.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__sort_merge.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__sort_radix.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__spmv_crs.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__spmv_ellpack.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__stencil2D.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__stencil3D.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/machsuite/machsuite__viterbi.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__k2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__k3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench/polybench__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__medium__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__mini__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__fixed__small__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__medium__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__mini__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__small__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__2mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__3mm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__atax.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__bicg.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__cholesky.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__correlation.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__covariance.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__doitgen.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__durbin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__fdtd-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__floyd-warshall.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__gemm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__gemver.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__gesummv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__gramschmidt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__heat-3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__jacobi-1d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__jacobi-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__lu.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__ludcmp.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__mvt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__nussinov.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__seidel-2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__symm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__syr2k.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__syrk.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__trisolv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/polybench__reproducible/polybench__reproducible__polybench__float__unsafe__math__mini__trmm.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/pp4fpgas/pp4fpgas__23_pp4fpgas_unoptimized_fft.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/pp4fpgas/pp4fpgas__24_pp4fpgas_multi_stage_fft.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/pp4fpgas/pp4fpgas__25_pp4fpgas_huffman_encoding.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/pp4fpgas/pp4fpgas__26_pp4fpgas_matmul.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/pp4fpgas/pp4fpgas__27_pp4fpgas_parallel_merge_sort.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/real_cgeist_flags create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__3d-rendering__src__sdsoc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__BNN__cpp__accel.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__digit-recognition__src__sdsoc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__face-detection__src__sdsoc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__face-detection__src__sdsoc__origin.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__optical-flow__src__sdsoc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__optical-flow__src__sdsoc__hls_template.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/rosetta/rosetta__spam-filter__src__sdsoc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__blur.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__contrast.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__denoise2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__denoise3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__erosion.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__heat3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__jacobi2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__jacobi3d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__seidel2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__sobel2d.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/soda/soda__soda__xcorr.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__dct.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__fir.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__histogram.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__matrix_multiplication.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__mergesort.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__normals.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__sobel_filter_x.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__sobel_filter_y.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__spmv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/spector_hls/spector_hls__template_matching.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__Autoencoder__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__Autoencoder__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__Autoencoder__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__Autoencoder__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__Autoencoder__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__DepthwiseSeparableConvBlock__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__DepthwiseSeparableConvBlock__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__DepthwiseSeparableConvBlock__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__DepthwiseSeparableConvBlock__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__DepthwiseSeparableConvBlock__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__FeedForward__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__FeedForward__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__FeedForward__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__FeedForward__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__FeedForward__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__MultiHeadSelfAttention1__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__MultiHeadSelfAttention1__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__MultiHeadSelfAttention1__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__MultiHeadSelfAttention1__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__MultiHeadSelfAttention1__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResMLP__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResMLP__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResMLP__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResMLP__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResMLP__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResidualBlock__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResidualBlock__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResidualBlock__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResidualBlock__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__ResidualBlock__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__atax__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__atax__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__atax__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__atax__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__atax__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__bicg__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__bicg__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__bicg__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__bicg__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__bicg__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gemm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gemm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gemm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gemm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gemm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gesummv__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gesummv__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gesummv__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gesummv__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__gesummv__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k2mm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k2mm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k2mm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k2mm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k2mm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k3mm__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k3mm__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k3mm__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k3mm__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k3mm__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_balanced__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_balanced__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_balanced__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_balanced__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_balanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_unbalanced__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_unbalanced__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_unbalanced__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_unbalanced__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmseq_unbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmtree_balanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__k7mmtree_unbalanced__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__mvt__opt1.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__mvt__opt2.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__mvt__opt3.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__mvt__opt4.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/stream_hls/stream_hls__mvt__opt5.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__01_basic_examples_vhls_fixed_point_sqrt.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__02_basic_examples_vhls_fir_filter.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__03_basic_examples_vhls_fixed_point_window_conv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__04_basic_examples_vhls_floating_point_window_conv.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__05_basic_examples_vhls_ap_arithmetic.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__06_basic_examples_vhls_parallel_loops.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__07_basic_examples_vhls_imperfect_loops.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__08_basic_examples_vhls_max_bounded_loop.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__09_basic_examples_vhls_perfect_nested_loops.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__10_basic_examples_vhls_pipelined_nested_loops.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__11_basic_examples_vhls_accs_sequential.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__12_basic_examples_vhls_accs_w_asserts.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__13_basic_examples_vhls_accs_w_dataflow.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__14_basic_examples_vhls_static_memory.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__15_basic_examples_vhls_pointer_casting.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__16_basic_examples_vhls_double_pointer.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__17_basic_examples_vhls_axi_master.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__18_basic_examples_vhls_axi_stream_no_side_channel.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__19_basic_examples_vhls_multi_array_access_bottleneck.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__20_basic_examples_vhls_resolved_array_access_bottleneck.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__21_basic_examples_vhls_uram_ecc.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__22_basic_examples_vhls_fixed_point_hamming_window.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/vitis_examples/vitis_examples__28_vitis_accel_examples_streaming_vadd.test create mode 100644 tools/cgeist/Test/HLS/hlsfactory/whetstone/whetstone__whetstone.test create mode 100644 tools/cgeist/Test/HLS/inline/inline.cpp create mode 100644 tools/cgeist/Test/HLS/interface/interface.c create mode 100644 tools/cgeist/Test/HLS/latency/latency.c create mode 100644 tools/cgeist/Test/HLS/lit.local.cfg create mode 100644 tools/cgeist/Test/HLS/loop_flatten/loop_flatten.c create mode 100644 tools/cgeist/Test/HLS/loop_merge/loop_merge.c create mode 100644 tools/cgeist/Test/HLS/loop_tripcount/loop_tripcount.c create mode 100644 tools/cgeist/Test/HLS/occurrence/occurrence.c create mode 100644 tools/cgeist/Test/HLS/parse/case-and-spelling.c create mode 100644 tools/cgeist/Test/HLS/parse/cxx-constants.cpp create mode 100644 tools/cgeist/Test/HLS/parse/not-enabled.c create mode 100644 tools/cgeist/Test/HLS/parse/pragma-operator-and-macros.c create mode 100644 tools/cgeist/Test/HLS/parse/syntax-errors.c create mode 100644 tools/cgeist/Test/HLS/parse/unknown.c create mode 100644 tools/cgeist/Test/HLS/parse/value-errors.c create mode 100644 tools/cgeist/Test/HLS/performance/performance.c create mode 100644 tools/cgeist/Test/HLS/pipeline/errors.c create mode 100644 tools/cgeist/Test/HLS/pipeline/lowering.c create mode 100644 tools/cgeist/Test/HLS/pipeline/options.c create mode 100644 tools/cgeist/Test/HLS/pipeline/placement.c create mode 100644 tools/cgeist/Test/HLS/pipeline/trip_one.c create mode 100644 tools/cgeist/Test/HLS/placement/cxx.cpp create mode 100644 tools/cgeist/Test/HLS/placement/lost-targets.c create mode 100644 tools/cgeist/Test/HLS/placement/macro-loops.c create mode 100644 tools/cgeist/Test/HLS/placement/scope-errors.cpp create mode 100644 tools/cgeist/Test/HLS/polybench/bicg.c create mode 100644 tools/cgeist/Test/HLS/polybench/generate.py create mode 100644 tools/cgeist/Test/HLS/polybench/gesummv.c create mode 100644 tools/cgeist/Test/HLS/polybench/hls-est-e2e.c create mode 100644 tools/cgeist/Test/HLS/polybench/k2mm.c create mode 100644 tools/cgeist/Test/HLS/polybench/k3mm.c create mode 100644 tools/cgeist/Test/HLS/polybench/mvt.c create mode 100644 tools/cgeist/Test/HLS/polybench/syr2k.c create mode 100644 tools/cgeist/Test/HLS/polybench/syrk.c create mode 100644 tools/cgeist/Test/HLS/protocol/protocol.c create mode 100644 tools/cgeist/Test/HLS/realheaders/Inputs/extern-global-def.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/Inputs/extern-global-first.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/Inputs/extern-global-init.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/Inputs/stream-member-cross-unit-b.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/Inputs/stream-member-cross-unit-c.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/ap-global-init.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/apint-types.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/array12-bram.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/auto-inline-measure.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/bits-const.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/complex-assign.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/compound-assign-mark.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/concat-ref.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/extern-global-pragma.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/extern-global-unused-def.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/fixed-accumulate.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/fixed-modes.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/header-pragma.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/hls-exp.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/hls-task.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/lit.local.cfg create mode 100644 tools/cgeist/Test/HLS/realheaders/loop-scalar-promote-affine-if.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/loop-scalar-promote-for.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/loop-scalar-promote-live-out.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/loop-scalar-promote-reset.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/loop-scalar-promote.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/math-core.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/memcpy-typed.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/mingw-names.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/pragma-class-member.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/pragma-dead-branch.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/pragma-local-enum.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/pragma-template-constants.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/pragma-vitis-accepts.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/proxy-escape.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/raise-variable-step-guard.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/raise-variable-step.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/range-ref-switch.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/range-ref.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/shift-register-builtins.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/static-member-through-object.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/stream-element-bits.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/stream-global-depth.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/stream-member-cross-unit.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/stream.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/string-ctor.cpp create mode 100644 tools/cgeist/Test/HLS/realheaders/vector-partition.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/Inputs/auto-inline-cross-unit-callee.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/array-of-struct-pointer-to-row.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/array-partition-merge.c create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-callee-unroll.c create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-callsite-constant-trip.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-cross-unit.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-invalid-source.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-review.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-rotated-size-nested.c create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-rotated-size.c create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-runtime-trip.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/auto-inline-vitis.c create mode 100644 tools/cgeist/Test/HLS/regressions/break-skips-condition.c create mode 100644 tools/cgeist/Test/HLS/regressions/buffer-elim-remat-clobber.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/builtin-constant-call.c create mode 100644 tools/cgeist/Test/HLS/regressions/call-array-shape-mismatch.c create mode 100644 tools/cgeist/Test/HLS/regressions/complex-arith.c create mode 100644 tools/cgeist/Test/HLS/regressions/condition-variable.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/counter-exit-value.c create mode 100644 tools/cgeist/Test/HLS/regressions/dangling-constant-lookup.c create mode 100644 tools/cgeist/Test/HLS/regressions/default-member-init.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/divrem-negative-dividend.c create mode 100644 tools/cgeist/Test/HLS/regressions/dynamic-global-init.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/fabs-class-overload.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/float-compound-double.c create mode 100644 tools/cgeist/Test/HLS/regressions/for-break-exit-value.c create mode 100644 tools/cgeist/Test/HLS/regressions/function-by-source-name.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/goto-unsupported.c create mode 100644 tools/cgeist/Test/HLS/regressions/hlsfactory-bind-op-array-expression.c create mode 100644 tools/cgeist/Test/HLS/regressions/hlsfactory-bind-storage-without-type.c create mode 100644 tools/cgeist/Test/HLS/regressions/hlsfactory-constexpr-call-values.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/hlsfactory-latency-minus-one.c create mode 100644 tools/cgeist/Test/HLS/regressions/hlsfactory-nested-scope-variable.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/hlsfactory-subscripted-variable.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/initlist-scalar-wrapper.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/inline-off-kept-call.c create mode 100644 tools/cgeist/Test/HLS/regressions/inline-off-recursive-not-diagnosed.c create mode 100644 tools/cgeist/Test/HLS/regressions/interface-later-pragma-wins.c create mode 100644 tools/cgeist/Test/HLS/regressions/interface-maxi-axilite-same-port.c create mode 100644 tools/cgeist/Test/HLS/regressions/keep-invariant-loops.c create mode 100644 tools/cgeist/Test/HLS/regressions/keep-misfit-global.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/narrow-arith-wrap.c create mode 100644 tools/cgeist/Test/HLS/regressions/narrow-cast-chain.c create mode 100644 tools/cgeist/Test/HLS/regressions/narrow-const-representative.c create mode 100644 tools/cgeist/Test/HLS/regressions/narrow-counter-assume-termination.c create mode 100644 tools/cgeist/Test/HLS/regressions/narrow-counter-shared-start.c create mode 100644 tools/cgeist/Test/HLS/regressions/narrow-counter-wrap.c create mode 100644 tools/cgeist/Test/HLS/regressions/no-codegen-after-errors.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/nowrap-unsigned-read.c create mode 100644 tools/cgeist/Test/HLS/regressions/nsdmi-scalar-brace.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/nullptr-t.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/orig-name-operator-crash.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/pointer-param-assign-array.c create mode 100644 tools/cgeist/Test/HLS/regressions/pointer-to-array.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/pow-promoted-argument.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/pragma-unexpected-number.c create mode 100644 tools/cgeist/Test/HLS/regressions/predec-lvalue.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/range-for-array-ref.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/signed-nowrap-mark.c create mode 100644 tools/cgeist/Test/HLS/regressions/store-forward-loop-carried.c create mode 100644 tools/cgeist/Test/HLS/regressions/stream-io-dropped.cpp create mode 100644 tools/cgeist/Test/HLS/regressions/struct-same-type-members.c create mode 100644 tools/cgeist/Test/HLS/regressions/unknown-pragmas-false-conflict.c create mode 100644 tools/cgeist/Test/HLS/regressions/while-conjunctive-bound.c create mode 100644 tools/cgeist/Test/HLS/regressions/while-step-doubling.c create mode 100644 tools/cgeist/Test/HLS/regressions/wide-int-sub-const.c create mode 100644 tools/cgeist/Test/HLS/regressions/zero-init-aggregates.cpp create mode 100644 tools/cgeist/Test/HLS/report/check-only.cpp create mode 100644 tools/cgeist/Test/HLS/report/report.c create mode 100644 tools/cgeist/Test/HLS/reset/reset.c create mode 100644 tools/cgeist/Test/HLS/stable/stable.c create mode 100644 tools/cgeist/Test/HLS/stream/stream.c create mode 100644 tools/cgeist/Test/HLS/top/top.c create mode 100644 tools/cgeist/Test/HLS/unroll/errors.c create mode 100644 tools/cgeist/Test/HLS/unroll/factor-expr-zero.cpp create mode 100644 tools/cgeist/Test/HLS/unroll/lowering.c create mode 100644 tools/cgeist/Test/HLS/unroll/options.c create mode 100644 tools/cgeist/Test/HLS/unroll/placement.c create mode 100644 tools/cgeist/Test/HLS/wrapper/Inputs/mini_fixed.h create mode 100644 tools/cgeist/Test/HLS/wrapper/attention_ctrl.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/attention_mirror.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/builtin_bit_cast.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_chain.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_ctor.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_derived.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_global.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_not.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_off.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_sizeof.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_static_local.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_type.cpp create mode 100644 tools/cgeist/Test/HLS/wrapper/wrapper_valueinit.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/bit-builtins.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/bitwidth.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/builtin-gate.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/dead-store.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/lit.local.cfg create mode 100644 tools/cgeist/Test/HLS/xlx/pragma-variable.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/string2bits.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/union-pun.cpp create mode 100644 tools/cgeist/Test/HLS/xlx/wide-not.cpp mode change 100755 => 100644 tools/cgeist/Test/Verification/cudaglobalcodegen.cu create mode 100644 tools/cgeist/Test/Verification/float-compound-assign.c mode change 100755 => 100644 tools/cgeist/Test/Verification/freecst.c create mode 100644 tools/cgeist/Test/Verification/loop-exit-value.c create mode 100644 tools/cgeist/Test/Verification/store-forward-loop.c create mode 100644 tools/cgeist/Test/Verification/while-rotated-carry.c delete mode 100644 tools/cgeist/Test/lit.cfg create mode 100644 tools/cgeist/XlxPrelude.inc.in create mode 100644 tools/cgeist/include/xlx/xlx_prelude.h mode change 100755 => 100644 tools/polymer/build_polymer_deps.sh mode change 100755 => 100644 tools/polymer/example/flow mode change 100755 => 100644 tools/polymer/example/handwritten/run-par.sh mode change 100755 => 100644 tools/polymer/example/handwritten/run.sh mode change 100755 => 100644 tools/polymer/example/polybench/benchmark-polly mode change 100755 => 100644 tools/polymer/example/polybench/check-split mode change 100755 => 100644 tools/polymer/example/polybench/compile mode change 100755 => 100644 tools/polymer/example/polybench/eval-perf mode change 100755 => 100644 tools/polymer/example/polybench/execute mode change 100755 => 100644 tools/polymer/example/polybench/extract mode change 100755 => 100644 tools/polymer/example/polybench/find-splittable mode change 100755 => 100644 tools/polymer/example/polybench/list_num_polyhedral_stmts mode change 100755 => 100644 tools/polymer/example/polybench/opt mode change 100755 => 100644 tools/polymer/example/polybench/sanity-check-data mode change 100755 => 100644 tools/polymer/example/polybench/sanity-check-sched mode change 100755 => 100644 tools/polymer/example/polybench/search-split mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-c mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-c-batch mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-mlir mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-mlir-batch mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-mlir-heuristic mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-mlir-heuristic-batch mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/eval-split-mlir-perf mode change 100755 => 100644 tools/polymer/example/polybench/split-and-merge/report-timing.py mode change 100755 => 100644 tools/polymer/scripts/build-with-polygeist.sh mode change 100755 => 100644 tools/polymer/scripts/update-pluto.sh diff --git a/README.md b/README.md index 0ac2df0e9f13..a1069738fe0d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,9 @@ cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS="mlir;clang" \ -DLLVM_TARGETS_TO_BUILD="host" \ -DLLVM_ENABLE_ASSERTIONS=ON \ - -DCMAKE_BUILD_TYPE=DEBUG + -DCMAKE_BUILD_TYPE=DEBUG \ + -DLLVM_PARALLEL_LINK_JOBS=1 -DLLVM_USE_LINKER=lld + ninja ninja check-mlir ``` diff --git a/debug.sh b/debug.sh new file mode 100644 index 000000000000..14af2e05ccbf --- /dev/null +++ b/debug.sh @@ -0,0 +1,9 @@ +T=/mnt/d/HLS/Polygeist/tools/cgeist/Test/polybench/linear-algebra/solvers/trisolv/trisolv.c +I=/mnt/d/HLS/Polygeist/tools/cgeist/Test/polybench/utilities +R=/mnt/d/HLS/Polygeist/llvm-project/build/lib/clang/18 + +# bare global cl::opt — no -mllvm wrapper +/mnt/d/HLS/Polygeist/build/bin/cgeist "$T" -resource-dir="$R" -I "$I" -O3 \ + --print-before-all -o /tmp/t.execm 2>/tmp/cg.log +echo "exit: $? lines: $(wc -l < /tmp/cg.log)" +grep -iE "Dump (Before|After)" /tmp/cg.log | tail -6 \ No newline at end of file diff --git a/docs/hls-pragmas.md b/docs/hls-pragmas.md new file mode 100644 index 000000000000..a81adf0588b2 --- /dev/null +++ b/docs/hls-pragmas.md @@ -0,0 +1,603 @@ +# HLS pragma extraction in cgeist + +This document is the single source of truth for how cgeist (the Polygeist +C/C++ front end) turns Vitis HLS `#pragma HLS ...` directives into MLIR +attributes, and for the attribute contract with `hls-est` (`~/circt`). + +Contents: + +1. [Usage](#1-usage) +2. [How it works](#2-how-it-works) +3. [Attribute conventions](#3-attribute-conventions) +4. [Pragma reference](#4-pragma-reference) +5. [Placement and name resolution](#5-placement-and-name-resolution) +6. [Diagnostics](#6-diagnostics) +7. [Preservation through the pipeline](#7-preservation-through-the-pipeline) +8. [Contract with hls-est](#8-contract-with-hls-est) +9. [Tests](#9-tests) +10. [Known limitations](#10-known-limitations) +- [Appendix A: pre-rewrite state](#appendix-a-pre-rewrite-state) + +--- + +## 1. Usage + +``` +cgeist kernel.c --function='*' -S --hls-annotate [--raise-scf-to-affine] [-O0..-O3] +``` + +| Flag | Effect | +|------|--------| +| `--hls-annotate` | Interpret `#pragma HLS` and emit `hls.*` attributes. Also tags local arrays with `polygeist.varname` / `hls.preserve` and functions with `hls.orig_name`. Without it, HLS pragmas are consumed silently (no attributes, no diagnostics) as before. | +| `--hls-pragma-report` | With `--hls-annotate`: after the pass pipeline, print one remark per pragma and outcome: the op(s) it was attached to, or why it was not applied. | +| `--hls-pragma-check-only` | With `--hls-annotate`: parse, place and validate the pragmas of **every** function definition in the translation unit (template instantiations included, `--function` ignored) without generating code, and report the AST-level targets (`loop 'L' in f (check-only)`). A lint mode, and a way to check designs cgeist cannot lower. Implies `--hls-pragma-report`. | + +Example report: + +``` +k.c:12:1: remark: '#pragma HLS pipeline II=1' -> affine.for (loop 'outer') in @kernel +k.c:15:1: remark: '#pragma HLS array_partition variable=buf cyclic factor=4' -> memref.alloca (variable 'buf') in @kernel +k.c:15:1: remark: '#pragma HLS array_partition variable=buf cyclic factor=4' -> memref.alloca (variable 'buf') in @top <- inlined copy +k.c:20:1: remark: '#pragma HLS unroll' -> not applied: the loop was removed during optimization +``` + +Errors (malformed or misplaced pragmas) make cgeist exit with status 1 after +printing clang-style diagnostics; warnings do not. + +## 2. How it works + +Code: `tools/cgeist/Lib/HLSPragma*.{h,cc}`. + +| Stage | File | What happens | +|-------|------|--------------| +| Parse (preprocessor) | `HLSPragmaParse.cc` | A catch-all pragma handler (registered without a name at the root namespace) recognises `HLS` in any case, lexes the rest of the pragma **with macro expansion**, and builds a `PragmaRecord`: kind, options, locations, normalized text. Options are checked against the spec table (`HLSPragmaSpec.cc`): known names, flag vs. value, value syntax (integer expression, enum member, variable path, list), duplicates, required options. Non-HLS pragmas without a handler behave exactly as in clang (ignored; `warn_pragma_ignored`). | +| Associate (AST) | `HLSPragmaSema.cc` | When cgeist starts emitting a function body, every pragma located inside that body (excluding nested lambda / local-class bodies) is bound to its target by `SourceLocation`, integer values are evaluated in the pragma's scope, semantic rules are checked, conflicts detected, and the attribute entries built. | +| Emit | `HLSPragmaSema.cc`, `HLSPragma.cc` | Function and parameter targets get their attributes immediately (`func.func` attributes / argument attributes). Globals get them when the translation unit ends. Loops, local variables and `bind_op` operations get a **location tag** (section 7). | +| Materialize (MLIR) | `HLSPragmaMaterialize.cc` | After the pass pipeline (`driver.cc`), every op whose location carries a tag receives the tag's attributes if it is the right kind of op; tags are then stripped from all locations. Targets that disappeared are reported. | + +Hooks in existing code (all small): `clang-mlir.h` (handler registration), +`clang-mlir.cc` (function entry, alloca creation, assignments, globals, end +of translation unit), `CGStmt.cc` (loop exit tests / `affine.for`), +`driver.cc` (materialization), `lib/polygeist/Passes/LoopRestructure.cpp` +(keeps tagged exit-test locations on the new `scf.while`). + +## 3. Attribute conventions + +* Every pragma kind `K` produces the attribute **`hls.K`**: an `ArrayAttr` of + `DictionaryAttr`, one entry per pragma instance, in source order. Several + pragmas on one target accumulate (e.g. partitioning two dimensions). +* Dictionary keys are the option names in lower case, except `II` (upper + case, as hls-est reads it) and `array_partition`/`array_reshape` `type`, + whose key is `kind` (historical hls-est contract). +* Value types: integers are `i32` `IntegerAttr`; flags are `BoolAttr`; enum + values are lower-case `StringAttr` (`dependence` `direction` is upper-case: + `"RAW"`); names are `StringAttr`; lists are `ArrayAttr`; floating + `performance` targets are `f64` `FloatAttr`. +* Options with a documented default are always present (so consumers never + guess); options without a default are omitted when not written. +* Variable/port pragmas record the name as written in `variable` (or `port`), + including member paths and subscripts (`s.x`, `psum[0]`). +* **`off`**: for loop/function pragmas, `K off` produces the unit attribute + `hls.K_off` instead of `hls.K`; for variable pragmas it produces + `hls.K_off = [{variable[, dim]}]`. +* Unknown pragmas: `hls.unknown_pragmas = ["", ...]` on the innermost + enclosing loop, else the function, plus a warning. + +Target ops: + +| Target | Op / place | +|--------|------------| +| loop | `affine.for`, `scf.for`, `scf.while`, `scf.parallel`, `affine.parallel` (whatever the loop is after the pipeline) | +| function | the `func.func` | +| parameter | argument attribute of the `func.func` (index counts `this` for methods) | +| local variable | its `memref.alloca` / `memref.alloc` / `llvm.alloca` | +| global or static local | its `memref.global` / `llvm.mlir.global` | +| `bind_op` | the arithmetic op assigned to the variable (`arith.muli`, `arith.addf`, `math.sqrt`, ...) | + +## 4. Pragma reference + +Notation: `int` = integer constant expression (literals, macros, `constexpr` +variables, enumerators, template arguments, calls to `constexpr` +functions); `enum{a,b}` = one of the listed values (case-insensitive); +**bold** = required; *pos* = the enum value may be written without `name=`. + +### 4.1 Loop and region pragmas + +Placement "loop": innermost enclosing loop body, error otherwise. +"loop/function": innermost enclosing loop body, otherwise the function. + +| Pragma | Placement | Options (type, default) | Attribute | +|--------|-----------|-------------------------|-----------| +| `pipeline` | loop/function | `II` int ≥ 1 (default 0 = not specified), `rewind` flag (false), `style` enum{stp,flp,frp} (stp), `enable_flush` flag, `off` | `hls.pipeline = [{II, rewind, style[, enable_flush]}]` / `hls.pipeline_off` | +| `unroll` | loop | `factor` int ≥ 1 (default 0 = complete), `skip_exit_check` flag (false), `off` | `hls.unroll = [{factor, skip_exit_check}]` / `hls.unroll_off` | +| `loop_flatten` | loop | `off` | `hls.loop_flatten = [{}]` / `hls.loop_flatten_off` | +| `loop_merge` | loop/function | `force` flag (false) | `hls.loop_merge = [{force}]` | +| `loop_tripcount` | loop | `min` int ≥ 0 (0), **`max`** int ≥ 0, `avg` int ≥ 0 ((min+max)/2) | `hls.loop_tripcount = [{min, max, avg}]` | +| `dependence` | loop/function | `variable`, `class` enum{array,pointer} *pos*, `type` enum{intra,inter} *pos* (inter), `direction` enum{raw,war,waw} *pos* (emitted upper-case), `distance` int ≥ 1, **`dependent`** flag (*pos* `true`/`false`) | `hls.dependence = [{...}]`, several allowed | +| `dataflow` | loop/function | `disable_start_propagation` flag (false) | `hls.dataflow = [{disable_start_propagation}]` | +| `latency` | loop/function | `min` int ≥ 0, `max` int ≥ 0 | `hls.latency = [{min?, max?}]` | +| `performance` | loop/function | `target_ti` number > 0, `target_tl` number > 0 (at least one), `unit` enum{cycle,sec} (cycle) | `hls.performance = [{target_ti?, target_tl?, unit}]` | + +Example (`--raise-scf-to-affine`): + +```c +for (int i = 0; i < 64; ++i) { +#pragma HLS pipeline II=2 +#pragma HLS loop_tripcount max=64 + a[i] = 3 * a[i]; +} +``` +```mlir +affine.for %arg1 = 0 to 64 { + ... +} {hls.loop_tripcount = [{avg = 32 : i32, max = 64 : i32, min = 0 : i32}], + hls.pipeline = [{II = 2 : i32, rewind = false, style = "stp"}]} +``` + +`do`-while loops (and loops with data-dependent exits) stay `scf.while`: +`} attributes {hls.pipeline = [...]}`. + +### 4.2 Function pragmas + +| Pragma | Placement | Options (type, default) | Attribute | +|--------|-----------|-------------------------|-----------| +| `inline` | function | `recursive` flag (false), `off` | `hls.inline = [{recursive}]` / `hls.inline_off` | +| `top` | function | **`name`** name | `hls.top = [{name}]` | +| `function_instantiate` | parameter | **`variable`** (a parameter) | argument attribute `hls.function_instantiate = [{variable}]` | +| `expression_balance` | loop/function | `off` | `hls.expression_balance = [{}]` / `hls.expression_balance_off` | +| `allocation` | loop/function | **`instances`** name list, **`limit`** int ≥ 1, `type` enum{function,operation} *pos* (function) | `hls.allocation = [{instances = [...], limit, type}]`, several allowed | +| `occurrence` | loop/function | **`cycle`** int ≥ 1 | `hls.occurrence = [{cycle}]` | +| `protocol` | loop/function | `mode` enum{fixed,floating} *pos* (floating) | `hls.protocol = [{mode}]` | +| `stable` | parameter, local or global | **`variable`** | `hls.stable = [{variable}]` (argument attribute, alloca, or global) | +| `reset` | global / static local | **`variable`**, `off` | `hls.reset = [{variable}]` / `hls.reset_off = [{variable}]` on the `memref.global` | + +```mlir +func.func @vadd(%arg0: memref {hls.interface = [...]}, ...) + attributes {hls.inline_off, hls.orig_name = "vadd", ...} +``` + +`inline off` is also honoured: cgeist's inliner (`-O1` and up; it registers +its own func-dialect inliner interface, `cgeist::hls::registerInlinerExtension`) +does not inline a call to a function carrying `hls.inline_off`, so the call +stays a `func.call` and the callee stays a function, as Vitis keeps it as its +own module. Calls inside loops are raised to affine like any other op. +One exception: an array argument that does not fit the shape the parameter +declares (C ignores an array parameter's first dimension, so `f(a)` with +`int a[32][4]` and `void f(int p[8][4])` is legal C) gives a `memref.cast` +from `memref<32x4xi32>` to `memref<8x4xi32>`, which is only valid once +inlining folds it away. Such a call is inlined as before, with a warning +(`'#pragma HLS inline off' of 'f' not honoured at this call: ...`). A row +argument (`f(a[k])`) is passed as a `polygeist.subindex` of the array. +`--hls-ignore-inline-off` restores the earlier behaviour (every call inlined), +for comparisons. Without `--hls-annotate` no pragma is read and every call is +inlined. + +Calls Vitis does not inline automatically stay calls too (`--hls-auto-inline`, +on by default with `--hls-annotate`; VITIS_NOTES N18 in the hls-est tree, +`Lib/HLSAutoInline.h`): for a caller C and a callee F without an inline +pragma, Vitis inlines all calls of F in C iff size(F) x calls(F in C) <= 100 +(calls counted after `#pragma HLS unroll` and after the complete unroll a +`pipeline` pragma implies for every loop nested in the pipelined loop or +function; size = clang's -O0 IR with the `always_inline` callees inlined, after +`sroa, early-cse, instcombine, simplifycfg, dce`, the pragma loops unrolled +first, without integer casts, plus size(G) - 2 per call of a G inlined into F +first); pointer / reference returns and `always_inline` callees (the Vitis +headers mark every ap_int / ap_fixed member so) are always inlined, and the +calls in an `always_inline` body count, and are kept, in the caller it is +inlined into; dataflow +processes (the calls at the top level of a `dataflow` function; a call inside +one of its loops follows the size rule) and callees holding a dataflow region +always kept. The kept calls and their +callees carry `hls.inline_auto_off` (`{calls, size}` on the call, `{size}` on +the callee). `--hls-auto-inline=false` inlines them as before; +`--hls-auto-inline-threshold`, `--hls-auto-inline-dataflow`, +`--hls-auto-inline-unroll-budget` (a function the unroll would make larger is +not unrolled for measuring; its size and calls are estimated from the trip +counts) and `--hls-auto-inline-report` (every decision on stderr) are the +knobs. + +### 4.3 Variable and port pragmas + +| Pragma | Target | Options (type, default) | Attribute | +|--------|--------|-------------------------|-----------| +| `array_partition` | variable | **`variable`**, `type` enum{cyclic,block,complete} *pos* (complete; key `kind`), `factor` int ≥ 1 (required for cyclic/block, ignored with a warning for complete), `dim` int ≥ 0 (1; 0 = all dims; ≤ rank), `off` | `hls.array_partition = [{variable, kind, factor?, dim}]` / `hls.array_partition_off = [{variable, dim}]` | +| `array_reshape` | variable | as `array_partition`, plus `object` flag | `hls.array_reshape = [...]` / `hls.array_reshape_off` | +| `bind_storage` | variable | **`variable`**, `type` enum{fifo,ram_1p,ram_1wnr,ram_2p,ram_s2p,ram_t2p,rom_1p,rom_2p,rom_np,xpm_memory (accepted by Vitis 2025.1, kernel w9r22i_c3_xpm)} (optional: Vitis accepts `impl` alone; no default is invented), `impl` enum{auto,bram,bram_ecc,lutram,uram,uram_ecc,srl,memory}, `latency` int ≥ −1 (−1 = auto) | `hls.bind_storage = [{variable, type?, impl?, latency?}]` | +| `resource` (legacy) | variable | **`variable`**, **`core`** name, `latency` int ≥ −1, `ports` name, `metadata` name | a memory core (`RAM_[_]`, `ROM_[_]`, `FIFO[_]`) is the bind_storage it names: `hls.bind_storage = [{variable, type, impl?, latency?}]` (`RAM_2P_BRAM` → type ram_2p, impl bram; Vitis 2025.1 gives the same RAM_2P_BRAM_1R1W for both, kernels w9r13p_rs_res / rs_bind, CIRCT VITIS_NOTES N98); an operator core (`Mul_LUT`, `AddSub_DSP`) stays `hls.resource = [{variable, core, ...}]` | +| `bind_op` | operation | **`variable`** (local or parameter), **`op`** enum{add,sub,mul,fadd,fsub,fmul,fdiv,fexp,flog,fsqrt,frsqrt,frecip,dadd,…,hsqrt}, `impl` enum{auto,dsp,fabric,meddsp,fulldsp,maxdsp,primitivedsp,qadder,vivado_dds}, `latency` int ≥ −1 (−1 = auto) | `hls.bind_op = [{variable, op, impl?, latency?}]` on each matching op assigned to the variable | +| `interface` | parameter, or function for `port=return` | **`mode`** enum{ap_none,ap_vld,ap_ack,ap_hs,ap_ovld,ap_fifo,ap_memory,bram,axis,s_axilite,m_axi,ap_ctrl_none,ap_ctrl_hs,ap_ctrl_chain,ap_stable} *pos*, **`port`**, `bundle` name, `offset` int or enum{off,direct,slave}, `depth`, `latency`, `max_widen_bitwidth`, `max_read_burst_length`, `max_write_burst_length`, `num_read_outstanding`, `num_write_outstanding`, `channel`, `interrupt` (ints), `register` flag, `register_mode` enum{both,forward,reverse,off}, `storage_type`, `storage_impl` enums, `clock`, `name` names | `hls.interface = [{mode, port, ...}]` | +| `stream` | variable | **`variable`**, `depth` int ≥ 1 (2), `type` enum{fifo,pipo,shared,unsync} (fifo), `off` | `hls.stream = [{variable, depth, type}]` / `hls.stream_off = [{variable}]` | +| `aggregate` | variable (also `variable=this` inside an instance member function: the function's object argument) | **`variable`**, `compact` enum{bit,byte,none,auto} (auto) | `hls.aggregate = [{variable, compact}]`; on a parameter it is also carried to the variable every call passes to it (an alloca, memref.global or the caller's parameter, transitively, before cgeist's inliner) with `from = ` (`--hls-propagate-aggregate`, on by default; Vitis aggregates the actual argument, hls-est VITIS_NOTES N37 S2 (b), (c)) | +| `disaggregate` | variable | **`variable`** | `hls.disaggregate = [{variable}]` | +| `alias` | function | **`ports`** name list (≥ 2 parameters), exactly one of `distance` int or `offset` int list (one per port) | `hls.alias = [{ports, distance | offset}]` on the function | +| `cache` | parameter | **`port`**, `lines` int ≥ 1, `depth` int ≥ 1 | argument attribute `hls.cache = [{port, lines?, depth?}]` | + +Examples: + +```c +int buf[16][8]; +#pragma HLS array_partition variable=buf cyclic factor=4 dim=2 +#pragma HLS array_partition variable=buf complete dim=1 +``` +```mlir +%alloca = memref.alloca() {hls.array_partition = [ + {dim = 2 : i32, factor = 4 : i32, kind = "cyclic", variable = "buf"}, + {dim = 1 : i32, kind = "complete", variable = "buf"}], + hls.preserve, polygeist.varname = "buf"} : memref<16x8xi32> +``` + +```c +void f(int a[8][4], int *p) { +#pragma HLS array_partition variable=a complete dim=2 +#pragma HLS interface m_axi port=p bundle=gmem offset=slave +#pragma HLS interface s_axilite port=p bundle=control +``` +```mlir +func.func @f(%arg0: memref {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "a"}]}, + %arg1: memref {hls.interface = [{bundle = "gmem", mode = "m_axi", offset = "slave", port = "p"}, + {bundle = "control", mode = "s_axilite", port = "p"}]}) +``` + +```c +int c = a * b; +#pragma HLS bind_op variable=c op=mul impl=dsp latency=3 +``` +```mlir +%0 = arith.muli %arg0, %arg1 {hls.bind_op = [{impl = "dsp", latency = 3 : i32, op = "mul", variable = "c"}]} : i32 +``` + +Syntax accepted everywhere: `#pragma HLS` / `#pragma hls` / any case; +`key=value`, `key = value`; `_Pragma("HLS ...")`; pragmas produced by macros +(including the `DO_PRAGMA(x) _Pragma(#x)` idiom); option values from +macros. Vivado positional spellings are accepted where listed (*pos*), e.g. +`#pragma HLS array_partition variable=a cyclic factor=2`, +`#pragma HLS interface m_axi port=x`, `#pragma HLS allocation function instances=f limit=1`, +`#pragma HLS dependence variable=a inter RAW false`. + +## 5. Placement and name resolution + +* A pragma belongs to the innermost function body containing it (a pragma + inside a lambda belongs to the lambda). Outside any function body it is an + error. Pragmas in functions that are never emitted (unused static + functions, uninstantiated templates) are neither applied nor validated; + the report says so. +* **Loops.** A loop's pragma region is its body, plus the space between the + header's `)` and a brace-less body; for `do`-while, between `do` and + `while`. The innermost loop whose region contains the pragma wins, so a + pragma after other statements, inside an `if` in the body, or in a + macro-generated loop, binds correctly. Loop kinds: `for`, `while`, + `do`-while, range-based `for`. A `pipeline` placed right before a loop + (outside it) applies to the function and warns. +* **Templates.** Each instantiation is associated separately, with template + arguments usable in option values (`factor=F`). +* **Variables** (`variable=`, `port=`, `ports=`), looked up at the pragma's + location: + 1. locals visible at the pragma (innermost scope first; C shadowing rules); + if none, a local declared *later* in an enclosing scope (Vitis accepts + pragmas before declarations); + 2. parameters of the function; + 3. globals and namespace-scope variables (through enclosing namespaces and + `using namespace`), static locals; + 4. a local declared in a nested scope that does *not* contain the pragma + (e.g. a buffer inside a loop, pragma at the top of the function), if it + is the only declaration of that name in the function — with a warning; + several such declarations are an ambiguity error. + 5. inside an instance member function (a constructor), a data member of the + function's class or of one of its bases: `variable=m_Val` is + `this->m_Val`, as Vitis parses the variable as an expression of the + function. An `array_partition` / `array_reshape` is recorded on the + `this` argument with the member path (`variable = "this.m_Val"`, + `member_path`) and carried to the object when the function is inlined; + any other pragma on a member is reported (warning) and dropped (CIRCT + OPEN_ISSUES O219 C1: Vitis_Libraries blas `WindowRm::m_Val`, security + aes `key_list`). + A class data member named outside a member function is an error. A leading + `&` (`variable=&s`) is dropped with Vitis' warning (HLS 207-5544). Paths: `s.a`, `p->a`, + `a[2]`, `s.rows[1]`; members and subscripts are type-checked (index range + for constant-size arrays). The whole variable's storage is annotated and + the path recorded. +* **Integer values** are evaluated in the same scope: literals (dec/hex/oct/ + bin), `+ - * / % << >> & | ^ ~` and parentheses, macros, `const`/ + `constexpr` variables, enumerators, qualified names (`cfg::kII`), template + arguments, and calls to `constexpr` functions or already-instantiated + `constexpr` function templates (`ceildiv(N, P)`). Names follow C++ lookup: + a `using Base::B;` declaration names the base's member, a member is also + found in the base classes, the first component may be a type template + parameter (`CholeskyTraits::INNER_II`) or a typedef of a class, and a static + data member's initializer is evaluated in the class template + specialization (CIRCT OPEN_ISSUES O219 C2). An enumerator of an unscoped + enum declared in the function body (`enum { fifo_depth = burst_len * 2 };`) + is found when no other lookup finds the name. +* **Dead arms.** A pragma in the arm of an `if` whose condition is a constant + (after template substitution) that the arm is not taken in is not emitted, + as clang's codegen skips a constant dead arm: `if (USE_URAM) { bind_storage + ... impl=URAM } else { bind_storage ... impl=BRAM }` applies one binding + (O219 C4). + +## 6. Diagnostics + +All diagnostics are clang-style with file:line:col. Errors stop cgeist +(exit status 1) before code generation. + +| Situation | Severity | Message (abridged) | +|-----------|----------|--------------------| +| `#pragma HLS` with no name / non-identifier | error | expected a pragma name after '#pragma HLS' | +| unknown pragma | warning | unknown HLS pragma 'X'; it is preserved in 'hls.unknown_pragmas' | +| unknown option | warning | unknown option 'X' in '#pragma HLS K'; ignored | +| bad option syntax | error | expected an option name ... / expected a value after 'X=' / option 'X' requires a value | +| bad value | error | invalid value 'V' for option 'X' in '#pragma HLS K': expected ... | +| option repeated | error | option 'X' is specified more than once (+ note) | +| missing required option | error | '#pragma HLS K' requires option 'X' (`loop_tripcount` without `max`: warning, the pragma is ignored, as Vitis ignores it: kernel w9r22i_c5_tripcount_nomax) | +| value not constant | error | cannot resolve 'N' to an integer constant / invalid integer expression | +| value out of range | error | option 'X' ... must be >= N / is out of range | +| outside a function | error | '#pragma HLS K' must be placed inside a function body | +| loop pragma outside a loop | error | ... must be placed inside a loop body (+ note if a loop follows) | +| `pipeline` right before a loop | warning | ... applies to the enclosing function ... | +| unknown variable | error | use of undeclared variable 'x' in '#pragma HLS K' | +| variable only in an unrelated nested scope | warning / error | 'x' is declared in a nested scope that does not contain ...; using that declaration / ... is ambiguous | +| bad member / subscript | error | no member named ... / subscripted value ... / index N is out of range ... | +| class data member | error / warning | ... names a class member ... (outside a member function) / ... names a data member of the object; the pragma is ignored (a pragma other than array_partition / array_reshape on a member) | +| `variable=&x` | warning | extra token before variable expression is ignored (HLS 207-5544) | +| array_partition on a scalar of class type (an `ap_uint`) | warning | ... on the scalar 'x' of type 'T' is ignored, as Vitis ignores it (kernel w9r22i_c7) | +| interface on a local variable | warning | 'x' in '#pragma HLS interface' is not a function parameter; the pragma is ignored (HLS 214-238, kernel w9r22i_c8); on a global it stays an error | +| wrong kind of variable | error | requires an array or pointer / is not a function parameter / requires a static or global variable / requires a local variable or parameter | +| partition semantics | error / warning | type=cyclic requires option 'factor'; dim=N is out of range ...; (w) 'factor' is ignored for complete partitioning; (w) factor=F exceeds the size S of dimension D | +| other semantics | error | min exceeds max; avg not within [min, max]; performance requires target_ti or target_tl; 'recursive' conflicts with 'off'; alias port count / distance-or-offset; interface mode/port=return mismatch | +| `off` plus other options | warning | option 'X' is ignored because '#pragma HLS K' has 'off' | +| conflicting pragmas on one target | error | '#pragma HLS K' conflicts with an earlier pragma on the same T (+ note) | +| two `array_partition` on one dimension that Vitis merges (same type: larger factor; `complete` over cyclic/block) | remark | '#pragma HLS array_partition' (cyclic factor=2) on dimension 1 of variable 'x' is dropped: the later pragma (cyclic factor=4) partitions it more finely, which Vitis keeps (+ note) | +| identical duplicate | warning | duplicate '#pragma HLS K' on the same T is ignored (+ note) | +| misplaced `dataflow` | warning | '#pragma HLS dataflow' is ignored: only a 'for' loop body or a function body supports the dataflow pragma (as Vitis, HLS 207-5576); e.g. in a nested `{ }` block or a `while` body | +| target removed by optimization | warning | the loop it applies to was removed ... / variable 'x' was promoted to registers or removed ... / the operation it binds was folded away ... | +| `bind_op` without a matching operation | warning | no matching operation is assigned to variable 'x' | +| global never emitted | warning | global 'g' is not used by any emitted function | + +Conflict keys: single-instance pragmas (pipeline, unroll, loop_flatten, +loop_merge, loop_tripcount, dataflow, latency, performance, inline, top, +expression_balance, occurrence, protocol) conflict per target, `off` +included; array_partition / array_reshape per (variable, dim) with `dim=0` +overlapping every dim, except that two array_partition pragmas Vitis merges +are merged (the same type keeps the larger factor, `complete` wins over +cyclic or block, a `dim=0` entry is split per dimension first; cyclic against +block stays an error, as in Vitis: [HLS 214-290]; VITIS_NOTES N17 (c) / N28 +in the hls-est tree; `--hls-reject-partition-conflicts` restores the error); bind_storage, stream, stable, reset, +function_instantiate, cache per variable; aggregate vs. disaggregate per +variable; bind_op per (variable, op); interface per (port, mode) — an m_axi +and an s_axilite interface on one port are the usual Vitis pattern; +dependence, allocation, alias and unknown pragmas only diagnose exact +duplicates. + +## 7. Preservation through the pipeline + +cgeist emits most loops as an unstructured CFG; `LoopRestructure`, +`CanonicalizeFor` and `RaiseSCFToAffine` later turn them into `scf.while`, +`scf.for` and `affine.for`, and the inliner, mem2reg, LICM, alloca +hoisting and canonicalization rewrite ops freely. Attributes set at codegen +would not survive that (and loops do not exist yet), so: + +* The op that identifies the target — the loop's **exit-test `cf.cond_br`** + (for/while/range-for/do-while) or the `affine.for` of a scop, the + **alloca** of a local, the **arithmetic op** of a `bind_op` — gets a + location `FusedLoc<{hls.tag = N}>[original]`. +* Every rewrite in the pipeline builds replacement ops with the old op's + location, and inlining wraps callee locations in `CallSiteLoc`, so the tag + follows the target, including every inlined copy. +* `LoopRestructure` is the one place where a new op takes a location from + somewhere else (the first op of the loop header). It now fuses the + metadata-carrying locations of the loop's exiting terminators into the new + `scf.while`'s location (a local change; without metadata the behaviour is + unchanged). +* After the pipeline, `cgeist::hls::materialize` gives each op the + attributes of the tags in its location — only if the op is of the right + kind (loop tags only on loop ops, etc.) — and strips the tags, so printed + debug locations are unchanged. +* A tagged target that no longer exists anywhere (dead loop, fully unrolled + loop, scalar promoted to a register, folded operation) gets a warning + unless its whole function was removed. + +`--hls-keep-invariant-loops` (default off): cgeist's LICM (`ParallelLICM`) +hoists an inner loop whose bounds and body do not depend on its enclosing +loop out of it (e.g. a reduction over `r` that does not use `j`, inside the +`j` loop). Vitis makes its pipeline / flatten decisions on the source loop +structure (OPEN_ISSUES O5 / VITIS_NOTES N14 in the hls-est tree), so with the +flag LICM does not hoist an op that is or contains a loop; other invariant +ops are still hoisted, also out of the kept loop. It needs `--parallel-licm` +(the default). + +Verified configurations (tests): `-O0`..`-O3`, `--raise-scf-to-affine`, +`--memref-fullrank`, inlining into callers (`-O1` and up), alloca hoisting +out of loops, partial unrolling and canonicalization with `polygeist-opt` +afterwards. + +## 8. Contract with hls-est + +hls-est (`~/circt/lib/Dialect/Resource`) reads: + +| Attribute | Reader | Shape | +|-----------|--------|-------| +| `hls.array_partition` | `MemoryInterface.cpp` `parsePartitionSpec`, `MemoryDS.cpp` `getPartitionSpecs`, `InferVitisSplitArray.cpp` | `[{kind: "cyclic"\|"block"\|"complete", factor?: i32, dim: i32 (1-based, 0 = all), variable: str}]` on `memref.alloca`/`memref.alloc`/`memref.global` or as a `func.func` argument attribute | +| `hls.pipeline` | `InferVitisSplitArray.cpp` | `[{II: i32, ...}]` on `affine.for`; `II > 0` is the user target, `0` = not specified | +| `hls.pipeline_off` | `InferVitisSplitArray.cpp` | unit attribute on `affine.for` | +| `polygeist.varname` | `InferVitisSplitArray.cpp` | `StringAttr` on the defining op of a memref | +| `hls.inline_off`, `hls.inline_auto_off` | `HlsInliner.cpp` (`--inline` keeps the calls), `CallInstances.cpp`, `MemrefBankClassification.cpp`, `BRAMAnalysis.cpp` (debug) | unit (`inline off`) / `{size: i64}` on the callee `func.func`, `{calls: i64, size: i64}` on each kept `func.call` (automatic inlining, section 4.2) | +| `hls.preserve` | Polygeist canonicalizer (`lib/polygeist/Ops.cpp`) | unit attribute on multi-element local `memref.alloca` | + +`hls.port_pressure`, `hls.debug_unroll` and the `hls.store_enable` op +belong to hls-est itself. + +### Breaking changes for hls-est + +**None.** No attribute name or shape that hls-est reads changed. The +following output differences are behaviour fixes within the existing +contract, listed because they change hls-est results on the same input: + +| Change | Before | After | Effect in hls-est | +|--------|--------|-------|-------------------| +| `pipeline off` | `hls.pipeline = [{II = 0, ...}]` (the loop was marked pipelined) | `hls.pipeline_off` | infer-vitis-split-array no longer treats such loops as pipelined | +| `array_partition` without `dim` | entry without `dim` | `dim = 1` always present | `getPartitionSpecs` (MemoryDS.cpp) no longer skips these entries | +| misplaced pragmas | attached by line-number heuristics to whatever op was nearest | attached to the right op, or a diagnostic | partitions/pipelines land where the source says | +| `pipeline` without `II` | `II = 0` | `II = 0` (unchanged, kept for compatibility) | none | +| no inline pragma, callee too large for Vitis's automatic inlining (N18) or a dataflow process | the callee was inlined into every caller | the calls stay `func.call` with `hls.inline_auto_off`, the callee a function (`--hls-auto-inline=false`: as before) | as for `inline off` | +| `inline off` | the callee was inlined into every caller (`-O1` and up) | the call stays a `func.call`, the callee a function with `hls.inline_off` (`--hls-ignore-inline-off`: as before) | the callee's arrays and loops are in their own function; hls-est sees calls | + +Unchanged but restated: `factor` is omitted for `complete`; +`polygeist.varname` and `hls.preserve` are produced exactly as before. + +Attributes not read by hls-est whose shape changed: `hls.allocation` +`instances` is now a list (`["foo"]`); `hls.bind_op` is attached to +the matching arithmetic op and records `variable` (the old +`polygeist.ssa_names` helper attribute is gone). + +## 9. Tests + +`tools/cgeist/Test/HLS/`, run with `ninja check-cgeist` or +`llvm-lit tools/cgeist/Test/HLS`. + +| Directory | Contents | +|-----------|----------| +| `parse/` | case/spelling/whitespace, `_Pragma`, macro-built pragmas and values, C++ constants, unknown pragmas/options, syntax and value errors, `--hls-annotate` off | +| one directory per pragma | options alone and together, defaults, placement, lowering (`-O0..-O3`, affine raising, inlining, unrolling), negative cases | +| `placement/` | C++ constructs, pragmas outside functions, macro-generated loops, targets removed by optimization | +| `consumer/` | exact hls-est attribute shapes (always runs); `hls-est-*.c` pipe cgeist output through hls-est (**REQUIRES: hls-est**) | +| `polybench/` | bicg, gesummv, 2mm, 3mm, mvt, syr2k, syrk from HLSFactory with their Tcl directives as pragmas; `generate.py` derives pragmas and expectations from the Tcl; `hls-est-e2e.c` runs all through the hls-est estimation pipeline | +| `hlsfactory/` | every HLSFactory design with synthesis sources, one `.test` each (see below) | +| `report/` | `--hls-pragma-report` | +| `regressions/` | one test per bug found while writing the tests | +| top level | the pre-rewrite tests, updated to the new contract | + +hls-est is found through `HLS_EST`, `PATH`, or `~/circt/build/{clion/,}bin` +(`lit.local.cfg`); without it the `REQUIRES: hls-est` tests are reported +UNSUPPORTED. + +### HLSFactory corpus + +`hlsfactory/generate.py` writes one test per design of the HLSFactory_v2 +catalogue (`D:\HLSFactory_v2\HLSFactory`, HLSFactory 1.1.0), read through the +hls-est harness's loader (`designs.load_hlsfactory_v2()` in +`~/circt/tools/hls-est-validate`), so the tests and the harness agree on every +design's key, top function, sources and include directories. It copies each +design's synthesis sources and headers into `hlsfactory/Inputs`, instantiating +HLSyn design-space placeholders (`auto{__PARA__Lk}` → 2, `auto{__TILE__Lk}` → +1, `pipeline auto{__PIPE__Lk}` → `pipeline`), and runs cgeist with the +harness's command for its default shim: the stand-in headers below with their +`cgeist_flags` (`%vitis_shim_flags`), the macros and `-std=` Vitis' front end +adds (`%vitis_frontend_cpp` / `_c99` / `_mixed`), `--raise-scf-to-affine +--memref-fullrank`. It chooses the strongest mode that works: + +| Mode | Checks | +|------|--------| +| full | the MLIR (`%hlsfactory_mlir`): the top function is emitted, with its argument types, the types of the array allocations in its body and of the module's globals; and every `--hls-pragma-report` line in order, nothing extra | +| errors | the design's own pragmas are invalid (e.g. a partition of an undeclared variable); the exact diagnostics | +| check-only | cgeist cannot lower the design for reasons unrelated to pragmas (quoted in the test) or takes over 3 minutes; `--hls-pragma-check-only` placement of every pragma | +| skip | nothing can be checked (clang cannot parse the design with the stand-in headers, or the top function is not emitted); the test is UNSUPPORTED and quotes the reason | + +`hlsfactory/SUMMARY.md` lists the modes, the outcome counts, every design +not compiled end to end with its reason, and every pragma not applied. +Expectations are the tool's output at generation time (regression tests +over real code); the non-applied outcomes in SUMMARY.md were reviewed when +generated, and the bugs they exposed have their own tests in +`regressions/hlsfactory-*`. + +`Inputs/vitis/` holds stand-ins for the Vitis headers (`ap_int.h`, +`ap_fixed.h`, `hls_stream.h`, `hls_math.h`, `hls_vector.h`, `hls_half.h`, +`ap_axi_sdata.h`, `ap_cint.h`) so HLS C++ can be parsed: a copy of the +hls-est harness's bit-exact `exactclass` shim (see `Inputs/vitis/README.md`). +`ap_int` / `ap_fixed<...>` are classes around a `_BitInt(W)`, which cgeist +lowers to `iW` with `--scalar-wrapper-abi`; every RUN line that uses +`%vitis_include` passes it. Stream operations are external calls. + +## 10. Known limitations + +* `goto` is an error ("'goto' is not supported by cgeist (its code would be + wrong)"): its code was silently wrong (a forward goto out of an `if` + dropped, a backward one running a body once, the code between a goto and + its label executed; CIRCT OPEN_ISSUES O27, held-out chstone dfadd / dfsin). + Test `regressions/goto-unsupported.c`. +* `inline` (on) only annotates the function; cgeist's inliner (at `-O1` and + up) inlines every other call anyway, so it needs nothing more. Functions + without a pragma are inlined too, including the ones Vitis keeps as their + own module on its own (large callees, VITIS_NOTES N14 R8 in the hls-est + tree). +* Scalars are promoted to registers by mem2reg; variable pragmas on scalars + (e.g. `stream` on an `int`) are reported as removed. +* Class data members cannot be named by `variable=`. +* Pragmas in functions that are not emitted are not validated (use + `--hls-pragma-check-only` to check every function body). +* Arrays of class objects passed as parameters (e.g. `hls::stream s[N]` + arguments) hit a pre-existing cgeist code generation bug (a `func.call` + operand type mismatch), independently of pragmas; many stream-based + HLSFactory designs are therefore tested in check-only mode. +* With `-immediate` (no pipeline) loops are still a CFG: loop pragmas are + not attached (no warning in that mode). +* Constexpr function calls in option values need an existing definition or + instantiation of the function (as when it is used elsewhere in the code). +* Pre-existing cgeist limitations unrelated to pragmas show up on some + real designs (e.g. copying whole struct array elements asserts in + `ValueCategory.cc`); the HLSFactory tests record these as expected + failures with the reason. + +--- + +## Appendix A: pre-rewrite state + +What existed before this rewrite and why it was replaced. + +### A.1 Code inventory + +| File | Role | +|------|------| +| `tools/cgeist/Lib/pragmaHandlerHLS.{h,cc}` | `PragmaHLSHandler`, registered for the exact namespace `HLS`. Stored a name, the *raw source text* of the options and the **line number** of the pragma into the global `g_HLSMetadata`. | +| `tools/cgeist/Lib/HandleHLS.{h,cc}` | `ResolveScope` + `AttachMetadata`, run by `driver.cc` **after** the whole MLIR pass pipeline. Handled 7 pragmas: `array_partition`, `array_reshape`, `bind_storage`, `bind_op`, `allocation`, `unroll`, `pipeline`. | +| `tools/cgeist/Lib/clang-mlir.cc` | Under `--hls-annotate`: tagged local allocas with `polygeist.varname` (multi-element arrays also `hls.preserve`), values stored by `x = ...` with `polygeist.ssa_names`, and every `func.func` with `hls.orig_name`. | +| `tools/cgeist/Lib/utils.h` | Unused `g_HLSpragmaAnnotate` global. | +| `lib/polygeist/Ops.cpp` | Canonicalizer keeps allocas that carry `hls.preserve`. | +| `tools/cgeist/Test/HLS/*.cpp` | 7 FileCheck tests (one CHECK line each; two were already failing) + `HLSAllocation.cpp` (no RUN line). | + +### A.2 How it worked + +1. The preprocessor handler recorded `(name, raw text, line)`. +2. After *all* optimization passes, `ResolveScope` collected every op with a + region, computed a `[first line, last line]` span from the + `FileLineColLoc`s of the op and its nested ops, and assigned each pragma + to the op with the smallest span containing the pragma's line. +3. `AttachMetadata` split the raw text on whitespace and built a + `DictionaryAttr`, appended to an `ArrayAttr` on the chosen op (or on an + alloca found by name inside it). + +### A.3 Defects (confirmed by running the old binary) + +Placement (the root problem: matching by line number after optimization): + +- Line-span matching is not structural. Loops created by `LoopRestructure` + take the location of the first op of the loop header (usually the loop + *condition*), and spans shift as passes hoist, sink, fold and inline, so a + pragma could land on the wrong loop, on an `scf.if`, or on the function. +- Two loops on one line were indistinguishable; pragmas before the first + statement of a function or between functions attached to the next + function; after inlining, `CallSiteLoc` lines pointed at the call site; + template instantiations shared lines. + +Parsing: + +- Only the exact spelling `HLS` was recognised: `#pragma hls ...` was + silently dropped (confirmed). +- Values came from the raw source text: macros were not expanded, `_Pragma` + gave scratch-buffer text; keys were case-sensitive; `key = value` was + mis-split; a failed integer parse produced `-1` as a real value. + +Semantics / emission: + +- `pipeline off` was emitted as a pipeline (`II = 0`) — confirmed. +- `array_partition` without `dim` omitted `dim`, which hls-est's + `getPartitionSpecs` skips. +- `unroll off` was ignored; nothing was validated; 20+ Vitis pragmas were + ignored without a diagnostic. + +Robustness: + +- An unknown variable in `array_partition` **segfaulted** cgeist + (confirmed), as did a macro-valued option (`factor=F`, confirmed): null + `AllocaOp` dereferences in `HandleArrayPartition` & co. +- `HandleBindOp` dereferenced a null op when no `polygeist.ssa_names` + matched; `HandleAllocation` silently dropped pragmas missing options; + parameters and globals were never considered as targets. diff --git a/docs/xlx-real-headers.md b/docs/xlx-real-headers.md new file mode 100644 index 000000000000..a26e8bed7570 --- /dev/null +++ b/docs/xlx-real-headers.md @@ -0,0 +1,61 @@ +# cgeist on the real Vitis HLS headers + +cgeist can compile HLS C++ against the headers of a Vitis HLS install +(`/common/technology/autopilot`, the tree the Vitis synthesis front end +reads) instead of stand-ins. Everything is opt-in; without the options below +cgeist's output is unchanged. + +## Command line + +The Vitis front end's own flags (`db/autopilot.flow.log` of any Vitis run): + +``` +-I -D__SYNTHESIS__ -D__VITIS_HLS__ -DAESL_SYN -D__HLS_SYN__ -D__DSP48E1__ +-include /etc/autopilot_ssdm_op.h -std=gnu++14 (C: -std=gnu99) +``` + +plus cgeist's Xilinx extensions: + +| Option | What | +|--------|------| +| `-Xclang -fxlx-bitwidth` | `int/unsigned __attribute__((bitwidth(N)))` (the headers' `ssdm_int`) is `_BitInt(N)`. Needs the patched clang (`patches/llvm-project/0001-xlx-bitwidth.patch`). | +| `-Xclang -fxlx-apint-promote` | a `_BitInt` no wider than `int` takes part in the integer promotions, as in Vitis' front end. | +| `--xlx-prelude` | force-includes declarations of the Xilinx bit builtins (`include/xlx/xlx_prelude.h`, compiled into cgeist); their calls are lowered to `arith` / `math` ops (`Lib/CGXlxBuiltin.cc`, ported from hls-llvm-project's `CGFPGABuiltin.cpp`). The lowering is active under `--xlx-prelude` or `--xlx-headers` only; without them a function of such a name is an ordinary call. | +| `--xlx-headers` | code generation the headers need: the proxy objects `ap_range_ref`, `ap_bit_ref`, `ap_concat_ref`, `af_range_ref`, `af_bit_ref` are inlined and scalarised, also when they are read inside the `if` / loop regions of the inlined helpers and when one proxy holds references to others (a concatenation of range or bit references), and so are the type-punning unions (`doubleToRawBits`) (`Lib/XlxProxyScalarize.cc`); a value constructed from a string literal (`ap_ufixed<25,11> t[] = {"0x1.a614p0", ...}`, the `_ssdm_string2bits` the Vitis front end folds) is a compile-time constant and such a static table a dense global (`Lib/XlxStringBits.cc`, the Vitis C simulation's conversion: prefixes, `e` / `p` exponents, all quantisation and overflow modes); struct fields of different MLIR types are kept apart; `ns::table[i]` is an ordinary global; a store that the next memory access in the same block overwrites is deleted, such as the guard `if (!op) Base::V = 0;` of the `ap_fixed` conversion (`etc/ap_fixed_base.h:691`), which Vitis' LLVM pipeline removes too (`Lib/XlxDeadStore.cc`); unused `linkonce_odr` functions are dropped. A proxy that still cannot be scalarised (e.g. one passed to a function that is not inlined) is an error (exit code 13), since a memref of a struct holding a memref is not valid MLIR. | +| `-Xclang -fnative-half-type -Xclang -fnative-half-arguments-and-returns` | `half` is `__fp16` with native arithmetic, arguments and returns (Vitis' `-fhls`). | +| `-Xclang -Wno-unknown-attributes` | silences `no_ctor`, `hls_preserve` (streams and the FFT IP only). | +| `--scalar-wrapper-abi` | `ap_int` / `ap_fixed` objects are their `iN`. | + +`-Xclang ` passes any argument to the clang frontend (cc1). + +Under `--xlx-headers` the pragma parser also accepts the forms the headers use: +a namespace-qualified `variable=ns::name`, and `variable=this` / `*this` +(reported and ignored: it names the object a member function runs on). Without +the option both are errors, as before. + +Under `-fxlx-bitwidth` a width below 1 is an error ("bit width must be at least +1") and a width above 8191, the ceiling of the open-source Xilinx front end +(hls-llvm-project `Type.h:1545,3131`), a warning; whether Vitis 2025.1 has the +same ceiling is unconfirmed. + +`ap_shift_reg` (`ap_shift_reg.h`): `__fpga_shift_register_peek(Array, Addr)` is +a load of `Array[Addr]` and `__fpga_shift_register_shift(DataIn, Array, Enable)` +an `scf.if (Enable)` around a loop moving every element one place up and a +store of DataIn at 0; the depth is the extent of the array the header casts to +a pointer (`Lib/CGXlxBuiltin.cc`; test `realheaders/shift-register-builtins.cpp`). + +## Tests + +`Test/HLS/xlx/` (no Vitis install needed; `bitwidth.cpp` needs the patched +clang, feature `xlx-bitwidth`) and `Test/HLS/realheaders/` (the install, from +`$VITIS_AUTOPILOT` or `/mnt/a/Vitis/2025.1/...`; UNSUPPORTED without it). + +## Not covered + +`hls::stream` (`__fpga_fifo_*`), `hls::task`, `ap_float`, the float / double +`hls_math` functions (closed bitcode), the DSP builtins, the FFT IP, and a +string constructor whose argument is not a string literal (it stays a call to +`_ssdm_string2bits`, which per the header "only takes const string and const +radix", etc/ap_fixed_base.h:458). How Vitis' closed front end rounds a decimal string that lies within +2^-(W-I+4) of a rounding boundary is unknown (the C simulation's sticky-bit +approximation and the exact value can differ there). diff --git a/durbin_ref b/durbin_ref new file mode 100644 index 0000000000000000000000000000000000000000..0439f908f347f6de9181e61f649aaa10bdb16667 GIT binary patch literal 16992 zcmeHOeQ;FQb-$|*BQR(s2U5kxW{ZUjPFQJ$5CU6fS4i;W2#i74q5(fv`++uD?e6Tp zwS}8B@(6p_QXJ~Zc=AU(W!jn6ZD%sHlj*ojYJ~ZAY(_Y7N|SafyNO4tgR96k#%|2^ zciuf`wfib%rv0aXWUuDk-#x!`&iy#=zPIn{z5C7X-mMibmy%Se9#SNY*J;Mjiiu5J z0QgnAT7vu@b+@_=a+S?#ygI$f(M#Tw=-f#lafg*kA!rj?-dkdXZ5OEuhppyF|m zUo|}x%mEh_vQSt4(d|?djZNws?K5h2px|VvBdZ zGJE>Ao2V*sFqW|*>Avk-;>kp$FE|j7pd$x|k_qmJsZHlJ#270uA6>}h&xQL3l{M#r zHVP}bj=udzFJhWjsT6bHv*k+ldn{+~j4h-(pMy+E?ssyZImtnv5l`2nq?<*2t&qS5zZMn%XwFFT z_;rbRxn~ix+E2Ms#M{3=wxm?EUl)j{u}Nz8>k{#FNb>u2i8zTJF@~RVZM#Sp?R=+S z3uJ%0F4}p&Ukk)9*2QvOjzBpAw)30>5Dq_`rS7r^e_nYK)`RSDWxS@$8sY zksmik&()l@BavVK4(R--LTLE*r->uEHR{?5AF(K8$+ZD-PTC;A5!3I95GC zu<@p~454@hMih#L`3d)m5i&f>2>Xq;{rVPyHMfl1v~lMB&BmFVm4@qrarKt96crrf z3TpBbQTK|jS%2!^NXJJ|tLzu|7^59urJ|AhxwY6h+VNuulWQ=n$uP1D)o(y{?MK^% z_Q`+hDJZ!=djgLK9t-RV^zAmD`Nc3!!)ZUV$@91Jc_VjL3ok?H$z5=-uD+)hXR*E# zrAE87r4Ge4y68dCtBcJjuG2+7itW0%6U7c)Jb+@SE~Zf2W*0|CFcL^TTB1_|>C0L= zp{4CwI;o{cv^1urN3}GrrQKSZ(9#|)O>60KEztuwTG*?lIxT%gOCCs3DEC2(y6Z=q zAsa8lU8#|-v7X#*Gw!;(O(=n@2m{}Tg)%N)youmq2AxLGD6QC@`^d=s&1rIJ3oFzx>^v{5d0k-ZKpjfQ)36UOMoE#ukiMh^B-_v2&k!#knyU5-*J%vU%q znhCh~F1|A3?!RQ@uJrnD^}5~#UG)L+T~}(LIAe^SsX(LC#>Pw8*8?}sxvT~w_nPtX zo4u}gV7vH-g*wil%Rj)etP{&3wENnOd+!fW#gd01qx|+vr@O!E-=TRGR@Y|SPy9>I z=&ve_97Z$auEz*6xBD)?w~yyzZ|-g56o>Ac#&2JR&)KMZ=~*N9sqY5naWsI|Z&1GU z^HKMOH(gQp-tnlrABJoCK5RBdFL1x7vp?$D_`3V>QJTremcBtj@6AmbYsQ`NpkAKE zc>1dlllrdLn~gliKXw!D*@>wy!@nqgzRMI1_p|SVo^s**_8wg|eZNvYM;ABZ+TM>f z(JP-vQ>SP)Og{f#xN?p@2+jK6g~m9xYyi;hyY3sC?1ZlOSjTP<@7;&Vq3fV=bjvttTm-9IN&aG;s?4|I3s^M^Cvb?K6wkJ~xUIG71LpS1I7JHLs%>JsKzjq%JU3s7hF z946Kh3%!oIy_eDpjoiilsW(2Mv)2&?ix_^*h9!RkIQ0$c!4;@W=l5A#ob9r4vHD-v zz!V9$K|e0g>bHtzv{`)##Eg4i^~*rIpQHMduBidktyJOnt?-McD=X*a2$UmGjzBpA z#TFY6R$Q&;LjxU4G3mj%;C>aio)F#*qNaj3e^4LU1$dA7boae30=0#!ZYH z8Rc!r2A10x*E6;mg^X67?t3N z(n%v$oLZdT+|kk5y{%`5r)$slon~OyuE5^i9UY6*0N&;$JmKt6YLjPGMjcYCn!PRY zs7Eb|B*Gp~L9u68pd^31 zw$?U0?7sb}nh~}6&Ij&a*SL~s^52JJ40f~_lGKZWh2tgEdv6sAf!eyx+J??rPiO7w z&f4ZcZTq&`la-?j{_wVA)z4RbtMa*u$^})m?Sa~6+W=-Tt_#$1r46X!9F8M1`TPq& zs;^?Gwx+wb&VIK#0ctVg!Naw=55d)d!*b6~G_V>NR5`fi>ZC1|95hzEX9D#BK z$`L3>pd5j61j-Rm^4*<$XD82@QI3r~W6Fnqc^F^aTxt@A>XxS)Q5iWLduJ zlkc@f|Iw{{l1zpxwV`|i=i$O_?0$3ysh5mwZ5z^`hLHq#oOHKUAKl6DijYU4tk!9q%*N(!sBcAVpZ!|J!n~}%%-NM zgE4C`JKzl^hnnK?Cv~&&60*EddRp2d1FbFX>j&1iMZ)3sQ2WLWZLKZM8`{Gg zeNkUqG};^uuWQ}Vg4ag#COVH*>X&$vRGMgB&^NO3y}XCjp99WiPiwRah4;+-y(^n5 z5A)3qejW32-HLq=3NBogDZgf9p3xWPF05+hI@DUFzK#O5EB686kJ$E~D_qyY|0N1@ z_5b8N{Cwm6zFq$v>h*i2=2@Jp{?}~#Wy(1pe`veaE7>O?wY+QF<7)N`qw!aOJ4z{A zT7p2;BW@@BS}E80-Qef4-vr*HO-u62Hs7EQ_)BQ@82CEeCFHz_c0c$#D%?u$r^3HQ zya+`Ynuq_!Jp8x7)3}cNbtN*cKeg>~-uXT*_xbP5Q_n^4)PLu=el(B$BzR9zzoqyw z`1*JZlG5-hL?h&?^IR7#8-*NEY1yA)m=ff%P z&lq3t_WzjB#%Zo+nCp@8PO$w6$9cTL{51a{zJNL?EyfSaT=QxLcsei6{(KR<$M!7E zy1}n3rEKW{)n9=(?2h|;lKxC{ezR3uw*=-D_HDrcp zBSQw3;iP#mo*W3q&9IeBXUt%BSm8FGibt$S82{Lu(}MPB#LQqi9Xw=45>^^}EYiWD zh>3ry4jqC^kz~TsDlrXb(*v;tdQ|v7C(5R|byr|}w~2qan%GRywRcBgd(Rfo*wABk z8>}_Db}4gP?<1XoUh|QyTX%Q&nSFuI-fq+0_TiTe9kg|$P`MdG7sIH@v2UbcjXfW~ zcArNi9JGSU9x`ev+KW=Cf!ecop_DMQJ+SN^6v?rnNE$mwk}2MlQsRe*qd~o~M7Fg! z3`%#NnBh#)91JGH*p=dJ#NHLd8(|8SV8e^q^9Wi9#}Z~X6A2f&;Ya--&ZTK3EzF5% zJekVyMx26sX?RoVNGh0);5=unban{SAyZVH#p9Um7w_FcCM}py4aVISfAoc(iwN>=ra^CY((q+@c{vDZMw6SN--8!XvkV-3{smyze zN)*bQIW%Mi2Y^;ujs0FLFEk} zN}xWCR$6QL!K_3up-V^NL2}?yDsCyS-Aylw-h)YqR%94CU9m7q+LPHE8RTnpFpNq> z(ysbq)gDqt3&EjS2+b!gsu`W5i^7XjsOYJXPWxPUr2iF1>mB;d!0pyf4YGzt_`@t1X?psW+6edqWOvwtU7DCp?PQfe+!!8CuXt^5$w}$ zh1}WxX@~!bmD*I0zDq7n5;x&4qkvVTeGL&O`zmEWv(sK=!MEV!F7lW4;pAGXZFatC zX;v2hx1pd@#J7#Y`b_qxPjLU`G>V_Z@jLJ(6Y-b*oa0R(k(xCWa`6}Z4`_=0m7h)7 z@c@eg;wSh46vh4r{MzyW`%6Ea{vv;Z0@Wq`m*?jc`?rfBqqHmZEflDIHWyln|BD4i z7s!@UG0NQ28lBhpH1_k2hkl1>EiUahXtn)5Ui!|I4F~9l1?iAODeY>lex`Sr*s6ct Ms4W&a92}zhZ%Ym(_y7O^ literal 0 HcmV?d00001 diff --git a/include/polygeist/Passes/Passes.h b/include/polygeist/Passes/Passes.h index fd4ab057da3d..ec4b810f56a6 100644 --- a/include/polygeist/Passes/Passes.h +++ b/include/polygeist/Passes/Passes.h @@ -28,7 +28,11 @@ class RewritePatternSet; class DominanceInfo; namespace polygeist { std::unique_ptr createParallelLICMPass(); +/// With `keepLoops`, LICM does not hoist a loop, or an op containing one, out +/// of an enclosing loop (cgeist --hls-keep-invariant-loops). +std::unique_ptr createParallelLICMPass(bool keepLoops); std::unique_ptr createPolygeistMem2RegPass(); +std::unique_ptr createPolygeistAffineScalarReplacementPass(); std::unique_ptr createLoopRestructurePass(); std::unique_ptr createInnerSerializationPass(); std::unique_ptr createSerializationPass(); @@ -80,6 +84,54 @@ void registerGpuSerializeToCubinPass(); void registerGpuSerializeToHsacoPass(); void populateForBreakToWhilePatterns(RewritePatternSet &patterns); + +// Facts about the C program that the frontend records on ops as discardable +// attributes and the raising passes trust (AffineCFG, CanonicalizeFor). cgeist +// removes the polygeist.* ones from its output unless +// -keep-frontend-assumptions is given; hls.uncounted stays. + +/// On an arith.addi / subi / muli: the C operation it computes has undefined +/// behaviour when its exact result does not fit the result type (signed +/// integer arithmetic at least as wide as int, C11 6.5p5, C++ [expr.pre]p4; +/// not under -fwrapv), so its result read signed is the exact result. On an +/// arith.index_cast from index to iN: the index value fits iN read signed. +constexpr llvm::StringLiteral kNoSignedWrapAttrName = "polygeist.nsw"; +/// On an arith.index_cast from index to iN: the index value fits iN read +/// unsigned. +constexpr llvm::StringLiteral kNoUnsignedWrapAttrName = "polygeist.nuw"; +/// On an scf.for that CanonicalizeFor raised from a while loop by assuming +/// that the loop terminates: its counter never wraps (see +/// -canonicalize-for-assume-termination in CanonicalizeFor.cpp). A BoolAttr: +/// true when the exit test reads the counter unsigned. +constexpr llvm::StringLiteral kCounterNoWrapAttrName = + "polygeist.counter_nowrap"; +/// On an scf.for / affine.for raised by that assumption whose exit test +/// compares its counter with a bound of a wider type that the counter is not +/// known to reach (`for (uint8_t i = 0; i < n; i++)`, int n): a loop whose +/// trip count the source does not bound. Kept in the output for hls-est +/// (Vitis does not collapse such a loop with its perfect inner nest, +/// hls-est-validate VITIS_NOTES.md N15). +constexpr llvm::StringLiteral kUncountedLoopAttrName = "hls.uncounted"; +/// On a func.func: its body (or the body of a function inlined into it) +/// accesses a volatile-qualified object, which cgeist does not represent on +/// memref accesses. No loop in such a function, and no loop that calls it, is +/// assumed to terminate (C11 6.8.5p6 excludes loops that access volatile +/// objects; -canonicalize-for-assume-termination in CanonicalizeFor.cpp). +/// Recorded per function, not per loop: the frontend's loops become scf.while +/// only in LoopRestructure, and a mark on a loop or on an access op would not +/// survive the rewrites before CanonicalizeFor. +constexpr llvm::StringLiteral kVolatileAccessAttrName = + "polygeist.volatile_access"; + +/// Canonicalization patterns that fold a chain of two marked add / sub with +/// constant operands, or of two marked mul by constants, into one marked op +/// (CanonicalizeFor.cpp). The arith patterns fold such chains through new ops +/// that would lose the mark. +void populateNoSignedWrapPatterns(RewritePatternSet &patterns); +/// Accesses through a memref.reinterpret_cast of an array argument whose +/// shape differs from the parameter's only in the first dimension use the +/// argument itself (PolygeistCanonicalize.cpp). +void populateArrayArgumentPatterns(RewritePatternSet &patterns); } // namespace polygeist } // namespace mlir diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index 926891b40611..7a0c6f20b920 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -1603,6 +1603,77 @@ class Memref2PointerIndex final : public OpRewritePattern { }; /// Simplify pointer2memref(memref2pointer(x)) to cast(x) +/// The element width in bytes (times the trailing dimensions) and the +/// trailing bounds of a copy between `dstTy` and `srcTy` of `len` bytes, or +/// false when the copy is not a whole number of rows of one element type. +static bool copyShape(MemRefType dstTy, MemRefType srcTy, Value len, + size_t &width, SmallVectorImpl &bounds) { + if (srcTy.getShape().size() != dstTy.getShape().size()) + return false; + if (dstTy.getElementType() != srcTy.getElementType()) + return false; + Type elTy = dstTy.getElementType(); + // `len` counts bytes of storage, so the element width is the type's size + // in bytes (sizeof), not its bit width divided by 8 rounded down: an i12 + // element (ap_uint<12>) occupies 2 bytes, and taking 1 copied twice the + // elements, past the end (CIRCT W9 round 8 review defect 1, probe + // mc12p.cpp). Which size an iN of a width whose byte count is not a power + // of two has depends on the source type (sizeof(ap_uint<24>) is 3 under + // the Vitis headers, sizeof(_BitInt(24)) is 4), so such elements, like + // x86_fp80, keep the byte-view copy. + width = 0; + if (auto IT = dyn_cast(elTy)) { + size_t bytes = llvm::divideCeil(IT.getWidth(), 8); + if (llvm::isPowerOf2_64(bytes)) + width = bytes; + } else if (auto FT = dyn_cast(elTy)) { + unsigned bits = FT.getWidth(); + if (bits == 16 || bits == 32 || bits == 64 || bits == 128) + width = bits / 8; + } + if (width == 0) + return false; + bool first = true; + bounds.clear(); + for (auto pair : llvm::zip(dstTy.getShape(), srcTy.getShape())) { + if (first) { + first = false; + continue; + } + if (std::get<0>(pair) != std::get<1>(pair)) + return false; + bounds.push_back(std::get<0>(pair)); + width *= std::get<0>(pair); + } + + SmallVector todo = {len}; + size_t factor = 1; + while (factor % width != 0 && todo.size()) { + Value len = todo.back(); + todo.pop_back(); + IntegerAttr constValue; + if (auto ext = len.getDefiningOp()) + todo.push_back(ext.getIn()); + else if (auto ext = len.getDefiningOp()) + todo.push_back(ext.getIn()); + else if (auto ext = len.getDefiningOp()) { + if (APInt(64, width).isPowerOf2() && + ext.getType().getIntOrFloatBitWidth() > + APInt(64, width).nearestLogBase2()) + todo.push_back(ext.getIn()); + } else if (auto ext = len.getDefiningOp()) + todo.push_back(ext.getIn()); + else if (auto mul = len.getDefiningOp()) { + todo.push_back(mul.getLhs()); + todo.push_back(mul.getRhs()); + } else if (matchPattern(len, m_Constant(&constValue))) { + factor *= constValue.getValue().getLimitedValue(); + } else + continue; + } + return factor % width == 0; +} + template class CopySimplification final : public OpRewritePattern { public: @@ -1615,72 +1686,44 @@ class CopySimplification final : public OpRewritePattern { auto dst = dstv.getDefiningOp(); if (!dst) return failure(); - - auto dstTy = dst.getSource().getType().cast(); - Value srcv = op.getSrc(); auto src = srcv.getDefiningOp(); if (!src) return failure(); - auto srcTy = src.getSource().getType().cast(); - if (srcTy.getShape().size() != dstTy.getShape().size()) - return failure(); - - if (dstTy.getElementType() != srcTy.getElementType()) - return failure(); - Type elTy = dstTy.getElementType(); + // memcpy(a, b, n) on arrays: clang converts each argument to void *, + // which cgeist emits as memref2pointer(pointer2memref( + // memref2pointer(a))). Look through such byte views to the typed arrays, + // so that the copy is element-wise in the arrays' own type (an i8 copy + // through pointers names no array: hls-est cannot bank it, while Vitis + // copies and partitions the typed array; OPEN_ISSUES O84 (a), kernel + // w9r8p_mc_cpy). When the typed arrays do not form a copy of whole rows + // of one element type, the byte views are copied as before. + auto typedBase = [](Value m) { + while (auto p2m = m.getDefiningOp()) { + auto m2p = + p2m.getSource().template getDefiningOp(); + if (!m2p) + break; + m = m2p.getSource(); + } + return m; + }; + Value dstBase = typedBase(dst.getSource()); + Value srcBase = typedBase(src.getSource()); size_t width = 1; - if (auto IT = dyn_cast(elTy)) - width = IT.getWidth() / 8; - else if (auto FT = dyn_cast(elTy)) - width = FT.getWidth() / 8; - else { - // TODO extend to llvm compatible type - return failure(); - } - bool first = true; SmallVector bounds; - for (auto pair : llvm::zip(dstTy.getShape(), srcTy.getShape())) { - if (first) { - first = false; - continue; - } - if (std::get<0>(pair) != std::get<1>(pair)) + if (!copyShape(dstBase.getType().cast(), + srcBase.getType().cast(), op.getLen(), width, + bounds)) { + dstBase = dst.getSource(); + srcBase = src.getSource(); + if (!copyShape(dstBase.getType().cast(), + srcBase.getType().cast(), op.getLen(), width, + bounds)) return failure(); - bounds.push_back(std::get<0>(pair)); - width *= std::get<0>(pair); - } - - SmallVector todo = {op.getLen()}; - size_t factor = 1; - while (factor % width != 0 && todo.size()) { - Value len = todo.back(); - todo.pop_back(); - IntegerAttr constValue; - if (auto ext = len.getDefiningOp()) - todo.push_back(ext.getIn()); - else if (auto ext = len.getDefiningOp()) - todo.push_back(ext.getIn()); - else if (auto ext = len.getDefiningOp()) { - if (APInt(64, width).isPowerOf2() && - ext.getType().getIntOrFloatBitWidth() > - APInt(64, width).nearestLogBase2()) - todo.push_back(ext.getIn()); - } else if (auto ext = len.getDefiningOp()) - todo.push_back(ext.getIn()); - else if (auto mul = len.getDefiningOp()) { - todo.push_back(mul.getLhs()); - todo.push_back(mul.getRhs()); - } else if (matchPattern(len, m_Constant(&constValue))) { - factor *= constValue.getValue().getLimitedValue(); - } else - continue; } - if (factor % width != 0) - return failure(); - Value c0 = rewriter.create(op.getLoc(), 0); Value c1 = rewriter.create(op.getLoc(), 1); SmallVector idxs; @@ -1706,8 +1749,8 @@ class CopySimplification final : public OpRewritePattern { rewriter.create( op.getLoc(), - rewriter.create(op.getLoc(), src.getSource(), idxs), - dst.getSource(), idxs); + rewriter.create(op.getLoc(), srcBase, idxs), + dstBase, idxs); rewriter.eraseOp(op); return success(); @@ -2159,14 +2202,24 @@ struct IfAndLazy : public OpRewritePattern { { SmallVector elseVals = otherYield.getOperands(); + // nextIf's else runs on two paths: prevIf took its other branch + // (then prevIf's results are otherYield's operands), or it took + // `yield`'s branch and nextIfCondition is false (then they are + // `yield`'s operands). Mapping the moved nextIf's else with the other + // branch's values was wrong code: `do { if (..) break; } while + // (++i > 0)` returned i without the increment (W8b). IRMapping elseMapping; elseMapping.map(prevIf.getResults(), otherYield.getOperands()); - SmallVector nextElseVals; - for (auto v : nextIf.elseYield().getOperands()) + IRMapping movedMapping; + movedMapping.map(prevIf.getResults(), yield.getOperands()); + SmallVector nextElseVals, movedElseVals; + for (auto v : nextIf.elseYield().getOperands()) { nextElseVals.push_back(elseMapping.lookupOrDefault(v)); + movedElseVals.push_back(movedMapping.lookupOrDefault(v)); + } elseVals.append(nextElseVals); otherYield->setOperands(elseVals); - nextIf.elseYield()->setOperands(nextElseVals); + nextIf.elseYield()->setOperands(movedElseVals); } SmallVector postTys; @@ -4972,6 +5025,9 @@ template struct BufferElimination : public OpRewritePattern { LogicalResult matchAndRewrite(T op, PatternRewriter &rewriter) const override { + if (op->hasAttr("hls.preserve")) + return failure(); + if (isCaptured(op)) return failure(); @@ -5176,6 +5232,8 @@ struct AffineBufferElimination : public OpRewritePattern { LogicalResult matchAndRewrite(T op, PatternRewriter &rewriter) const override { + if (op->hasAttr("hls.preserve")) + return failure(); SmallVector stores; LLVM_DEBUG(llvm::dbgs() << " Attempting affine buffer elim of: " << op << "\n"); @@ -5500,10 +5558,14 @@ struct AffineBufferElimination : public OpRewritePattern { } else { auto vop = V.getDefiningOp(); - if (DI.dominates((Operation *)vop, loc) && - DI.dominates((Operation *)vop, prevParent)) { + // A value computed before `loc` is used as it is. Computing it + // again at the load would re-read memory that may be written + // between its computation and the store: in a loop, + // `r = f(&s); g(r)` with f updating *s and g reading r + // through a reference re-ran f's arithmetic on the updated + // *s (OPEN_ISSUES O37, forgebench gpt_transformer_p1). + if (DI.dominates((Operation *)vop, loc)) continue; - } if (vop->getRegions().size()) { if (!isa { return true; }; + // The writes between `start` and the previous `tc` were already + // checked for this store: when the next `tc` is in the same block with + // the same start and the same values to recompute, only `tc` itself + // is new (the rewrite below only replaces loads inside `tc` and + // inserts read-only clones before them). Without this the scan from + // `start` is repeated for every `tc`, quadratic in the block length + // (OPEN_ISSUES O64 d: about 50 s of cgeist on forgebench + // attention_op_p1 under --xlx-headers). + Block *checkedBlock = nullptr; + Operation *checkedStart = nullptr; + Operation *nextUnchecked = nullptr; + SmallVector checkedRedo; + auto end = innerParent->getBlock()->end(); for (auto iter = innerParent->getNextNode()->getIterator();;) { if (iter == end) { @@ -5654,12 +5729,36 @@ struct AffineBufferElimination : public OpRewritePattern { while (start->getBlock() != tc.getBlock()) start = start->getParentOp(); assert(start); - while (true) { - checkOverwritingOp(start); - if (start == &tc) + // The values computed again at the load read memory where they + // were first computed: the writes to check start there, not at + // the store (O37). + for (Operation *r : toRedo) { + Operation *at = r; + while (at && at->getBlock() != tc.getBlock()) + at = at->getParentOp(); + if (!at) { + legal = false; + break; + } + if (at->isBeforeInBlock(start)) + start = at; + } + Operation *from = start; + if (legal && checkedBlock == tc.getBlock() && + checkedStart == start && checkedRedo == toRedo && + nextUnchecked == &tc) + from = &tc; + Operation *firstChecked = start; + while (legal) { + checkOverwritingOp(from); + if (from == &tc) break; - start = start->getNextNode(); + from = from->getNextNode(); } + checkedBlock = tc.getBlock(); + checkedStart = firstChecked; + checkedRedo = toRedo; + nextUnchecked = tc.getNextNode(); } if (!legal) diff --git a/lib/polygeist/Passes/AffineCFG.cpp b/lib/polygeist/Passes/AffineCFG.cpp index 7cf74c2a022c..20dbd16632e2 100644 --- a/lib/polygeist/Passes/AffineCFG.cpp +++ b/lib/polygeist/Passes/AffineCFG.cpp @@ -3,6 +3,7 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Arith/IR/Arith.h" +#include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/Dominance.h" @@ -13,12 +14,22 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "polygeist/Passes/Passes.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include #include #define DEBUG_TYPE "affine-cfg" using namespace mlir; + +/// Carries the `hls.*` marks of a memory access (CGCall.cc's +/// hls.ap_compound_assign on a store) to the access that replaces it. +static void copyHLSMarks(Operation *from, Operation *to) { + for (NamedAttribute a : from->getDiscardableAttrs()) + if (a.getName().getValue().starts_with("hls.")) + to->setAttr(a.getName(), a.getValue()); +} using namespace mlir::arith; using namespace polygeist; using namespace mlir::affine; @@ -32,8 +43,9 @@ bool isValidSymbolInt(Operation *defOp, bool recur) { return true; if (recur) { - if (isa(defOp)) + if (isa(defOp)) if (llvm::all_of(defOp->getOperands(), [&](Value v) { bool b = isValidSymbolInt(v, recur); // if (!b) @@ -83,6 +95,888 @@ bool isValidSymbolInt(Value value, bool recur) { return false; } +//===----------------------------------------------------------------------===// +// Exact raising of integer casts and arithmetic +//===----------------------------------------------------------------------===// +// +// An affine expression computes with mathematical integers. An iN value is a +// different integer read signed (index_cast, extsi) or unsigned +// (index_castui, extui), and the arith ops on iN compute modulo 2^N. Raising +// replaces an index by an affine expression over the values it is computed +// from, which is exact only while every step keeps the value: +// - a sign / zero extension of an iN, read with that signedness (an extsi +// read unsigned only when its input is provably non-negative); +// - a truncation index -> iN (index_cast / index_castui of an index) only +// when the index value provably fits the iN as it is read; +// - an add / sub / mul only when its exact result provably lies in the +// range of its type as it is read (its operands read the same way; a +// constant operand as whichever of the integers its bits stand for modulo +// 2^N keeps the result in that range: `k -= 5` of a uint8_t k is the i8 +// add of -5, read unsigned 251, and is k - 5 for k >= 5); +// - a div / rem of any width, index included, only when it is the affine +// floordiv / mod: a provably non-negative dividend (read as the map reads +// it) and a positive divisor. C's / and % truncate toward zero, floordiv +// and mod round down: (i - 5) / 2 is -2 for i = 0, (i - 5) floordiv 2 is +// -3. This is rounding, not overflow, so the width threshold below does +// not apply to it. +// The ranges come from the definitions (IntRangeOracle: constants, +// extensions, the bounds of affine.for / scf.for induction variables, sums +// and products of them). The raised expression reads each narrow input with +// the signedness the proof used, through an index_cast / index_castui of it. +// +// What is raised without a proof (the frontend's facts, Passes.h): +// - an add / sub / mul of at least 32 bits that cgeist marked polygeist.nsw: +// C signed arithmetic at least as wide as int, whose overflow is undefined +// behaviour, so its result read signed is the exact result. The range +// oracle reads such an op, read signed, as that exact result (the value +// its raised expression computes). Unmarked arithmetic of any width +// (unsigned int and unsigned long arithmetic, which wraps modulo 2^N: +// `(i * 0x7FFFFFFFu) / 0x7FFFFFFFu` is 0 for i = 3; arithmetic on promoted +// narrow operands; ops the canonicalizer rebuilt without the mark) needs +// the proof; index arithmetic never does; +// - an index_cast index -> iN marked polygeist.nsw (polygeist.nuw): the +// index value fits iN read signed (unsigned); CanonicalizeFor marks the +// counter of a loop it raised by assuming that the loop terminates; +// - integer casts at least 32 bits wide (truncations index -> i32 / i64, +// extensions, constants): the counters CanonicalizeFor creates for loops +// whose counter is as wide as int are assumed not to wrap +// (CanonicalizeFor, counterStaysInRange), and C reads every narrower +// integer through a conversion to at least int. +// Both facts are about the value read signed (a cast: the value of its +// input). Read unsigned (through an extui / index_castui), a negative iN +// value is 2^N more: (size_t)(unsigned)(i - 3) is 4294967293 for i = 0, where +// the raised i - 3 is -3, and (unsigned long)(unsigned)i of an int counter +// i = -3 is 4294967293 as well. A marked op, a wide sign extension and a +// wide truncation of an index read unsigned narrower than 64 bits are +// therefore raised (and an index -> i32 -> index round trip read unsigned +// folded, roundTripKeepsValue) only when the range oracle proves that signed +// value non-negative (unsignedReadKeepsValue); a truncation the frontend +// marked polygeist.nuw needs no proof. A 64-bit value read unsigned needs none +// either: it reaches an index only through an index_castui, which keeps its +// bits, so its index value is its signed value (an unsigned 64-bit value of +// 2^63 or more has no index value of its own; see raisableRange), and a +// wide divui / remui reads its operands signed (operandsUnsigned). +// Narrower arithmetic and casts do occur in the IR and wrap in ordinary +// programs: the `+=` / `-=` of a narrow C integer (built in its own width, so +// that a counter update stays an iN add), _BitInt / ap_int arithmetic, narrow +// loop counters (`uint8_t k = 10; k -= i` is 266 - i for i > 10; +// `(uint16_t)i` of an int8_t i = -8 is 65528). +// +// -affine-cfg-assume-nowrap-width=N (N > 0) restores the width rule of the +// earlier versions, for comparison: casts and add / sub / mul at least N bits +// wide (narrower than 64) are raised without a proof, marked or not, and +// narrower ones only with it (32: the former default; 64: every integer +// narrower than index needs the proof); it also raises them read unsigned +// without the non-negativity proof, as those versions did. + +static llvm::cl::opt AssumeNoWrapWidth( + "affine-cfg-assume-nowrap-width", llvm::cl::init(0), llvm::cl::Hidden, + llvm::cl::desc( + "0 (default): AffineCFG raises an integer add / sub / mul to an affine " + "expression without proving that it keeps the value only when the " + "frontend marked it polygeist.nsw (and it is at least 32 bits wide), " + "and integer casts at least 32 bits wide; N > 0: casts and arithmetic " + "at least N bits wide, marked or not (32: the former default; 64: " + "every integer narrower than index needs the proof)")); + +/// The width from which casts are raised without a proof. +static unsigned castNoWrapWidth() { + return AssumeNoWrapWidth ? (unsigned)AssumeNoWrapWidth : 32u; +} + +namespace { +using WideInt = __int128; +/// A closed interval of mathematical integers. +struct IntRange { + WideInt lo, hi; +}; +} // namespace + +/// Magnitude beyond which an IntRange is unbounded. +static constexpr WideInt kRangeInf = (WideInt)1 << 100; + +static IntRange unboundedRange() { return {-kRangeInf, kRangeInf}; } + +static IntRange clampRange(WideInt lo, WideInt hi) { + return {std::max(lo, -kRangeInf), std::min(hi, kRangeInf)}; +} + +static bool rangeWithin(IntRange r, IntRange in) { + return r.lo >= in.lo && r.hi <= in.hi; +} + +/// Width of an integer or index type (index: 64), 0 for any other type. +static unsigned intOrIndexWidth(Type t) { + if (t.isIndex()) + return 64; + if (auto it = t.dyn_cast()) + return it.getWidth(); + return 0; +} + +/// Whether a cast to, a constant of, or a div / rem in `t` is raised only +/// with a proof that it keeps the value (see above); an add / sub / mul: +/// needsNoWrapProof(Operation *). +static bool needsNoWrapProof(Type t) { + auto it = t.dyn_cast(); + return it && it.getWidth() < 64 && it.getWidth() < castNoWrapWidth(); +} + +/// Whether the integer op `op` is raised only with a proof that it keeps the +/// value (see above): an add / sub / mul unless it is index arithmetic or +/// marked polygeist.nsw and at least 32 bits wide (with +/// -affine-cfg-assume-nowrap-width=N: narrower than min(N, 64) bits); any +/// other op as needsNoWrapProof of its type. +static bool needsNoWrapProof(Operation *op) { + Type t = op->getResult(0).getType(); + if (!isa(op)) + return needsNoWrapProof(t); + auto it = t.dyn_cast(); + if (!it) + return false; + if (AssumeNoWrapWidth) + return it.getWidth() < 64 && it.getWidth() < AssumeNoWrapWidth; + return !(it.getWidth() >= 32 && + op->hasAttr(mlir::polygeist::kNoSignedWrapAttrName)); +} + +/// Whether the truncation `cast` (index_cast / index_castui of an index to +/// iN) is marked as keeping the value when its result is read `asUnsigned`. +static bool truncationMarkedExact(Operation *cast, bool asUnsigned) { + return cast && cast->hasAttr(asUnsigned + ? mlir::polygeist::kNoUnsignedWrapAttrName + : mlir::polygeist::kNoSignedWrapAttrName); +} + +/// The values of a `width`-bit integer read unsigned / signed. +static IntRange typeRange(unsigned width, bool asUnsigned) { + if (width == 0 || width > 96) + return unboundedRange(); + if (asUnsigned) + return {0, ((WideInt)1 << width) - 1}; + return {-((WideInt)1 << (width - 1)), ((WideInt)1 << (width - 1)) - 1}; +} + +/// The values an affine expression can stand for when it replaces a +/// `width`-bit integer read `asUnsigned`: typeRange within the range of index +/// (an unsigned 64-bit value of 2^63 or more has no index value). +static IntRange raisableRange(unsigned width, bool asUnsigned) { + IntRange r = typeRange(width, asUnsigned); + r.hi = std::min(r.hi, ((WideInt)1 << 63) - 1); + return r; +} + +static IntRange addRange(IntRange a, IntRange b) { + return clampRange(a.lo + b.lo, a.hi + b.hi); +} +static IntRange subRange(IntRange a, IntRange b) { + return clampRange(a.lo - b.hi, a.hi - b.lo); +} +static IntRange mulRange(IntRange a, IntRange b) { + const WideInt big = (WideInt)1 << 62; + for (WideInt x : {a.lo, a.hi, b.lo, b.hi}) + if (x > big || x < -big) + return unboundedRange(); + WideInt c[4] = {a.lo * b.lo, a.lo * b.hi, a.hi * b.lo, a.hi * b.hi}; + return clampRange(*std::min_element(c, c + 4), *std::max_element(c, c + 4)); +} +static IntRange unionRange(IntRange a, IntRange b) { + return {std::min(a.lo, b.lo), std::max(a.hi, b.hi)}; +} +/// floor / ceil of a / b for b > 0. +static WideInt floorDivW(WideInt a, WideInt b) { + WideInt q = a / b; + return (a % b != 0 && a < 0) ? q - 1 : q; +} +static WideInt ceilDivW(WideInt a, WideInt b) { + WideInt q = a / b; + return (a % b != 0 && a > 0) ? q + 1 : q; +} + +/// The exact result range of the integer add / sub / mul `op` for operand +/// ranges `a` and `b`. +static IntRange arithRange(Operation *op, IntRange a, IntRange b) { + if (isa(op)) + return addRange(a, b); + if (isa(op)) + return subRange(a, b); + return mulRange(a, b); +} + +/// The operand of the add / sub / mul `op` that is an integer constant (the +/// right one if both are), if any. +static std::optional constantOperand(Operation *op) { + for (unsigned i : {1u, 0u}) + if (op->getOperand(i).getDefiningOp()) + return i; + return std::nullopt; +} + +/// An iN constant stands for every integer congruent to it modulo 2^N, and an +/// iN add / sub / mul gives the same bits with any of them (MLIR folds +/// `subi x, 5` into `addi x, -5`; read unsigned, an i8 -5 is 251). For the +/// add / sub / mul `op` on iN (not index) whose operand `cIdx` is a constant +/// and whose other operand lies in `other`: the first of the constant read as +/// `asUnsigned`, that minus 2^N, that plus 2^N, for which the exact result +/// lies in the range of the iN read as `asUnsigned` (the result then is the +/// iN result read that way), if any: the uint8_t k - 5 for k in [5, 99] is +/// k + (-5), not k + 251. +static std::optional constantRepresentative(Operation *op, + unsigned cIdx, + IntRange other, + bool asUnsigned) { + Type t = op->getResult(0).getType(); + unsigned w = intOrIndexWidth(t); + auto ci = op->getOperand(cIdx).getDefiningOp(); + if (!ci || t.isIndex() || w == 0 || w > 64) + return std::nullopt; + APInt c = ci.getValue().cast().getValue(); + if (c.getBitWidth() != w) + return std::nullopt; + WideInt read = + asUnsigned ? (WideInt)c.getZExtValue() : (WideInt)c.getSExtValue(); + WideInt m = (WideInt)1 << w; + IntRange whole = raisableRange(w, asUnsigned); + for (WideInt rep : {read, read - m, read + m}) { + // The raised expression holds it as an int64_t affine constant. + if (rep < -((WideInt)1 << 63) || rep >= ((WideInt)1 << 63)) + continue; + IntRange cr{rep, rep}; + IntRange r = + cIdx == 0 ? arithRange(op, cr, other) : arithRange(op, other, cr); + if (rangeWithin(r, whole)) + return rep; + } + return std::nullopt; +} + +namespace { +/// The ranges integer values can take, as far as their definitions show +/// them; memoised for the lifetime of one oracle (one query, the IR fixed). +class IntRangeOracle { +public: + /// The values `v` can hold, read unsigned or signed (an index: signed). + IntRange get(Value v, bool asUnsigned) { return get(v, asUnsigned, 0); } + +private: + DenseMap, IntRange> cache; + + IntRange get(Value v, bool asUnsigned, unsigned depth) { + if (v.getType().isIndex()) + asUnsigned = false; + auto key = std::make_pair(v, (unsigned)asUnsigned); + auto it = cache.find(key); + if (it != cache.end()) + return it->second; + IntRange r = compute(v, asUnsigned, depth); + cache[key] = r; + return r; + } + + IntRange exprRange(AffineExpr e, ArrayRef dims, + ArrayRef syms) { + switch (e.getKind()) { + case AffineExprKind::Constant: { + WideInt c = e.cast().getValue(); + return {c, c}; + } + case AffineExprKind::DimId: + return dims[e.cast().getPosition()]; + case AffineExprKind::SymbolId: + return syms[e.cast().getPosition()]; + default: + break; + } + auto bin = e.cast(); + IntRange l = exprRange(bin.getLHS(), dims, syms); + IntRange r = exprRange(bin.getRHS(), dims, syms); + switch (e.getKind()) { + case AffineExprKind::Add: + return addRange(l, r); + case AffineExprKind::Mul: + return mulRange(l, r); + default: + break; + } + // floordiv / ceildiv / mod by a positive constant. + if (r.lo != r.hi || r.lo <= 0) + return unboundedRange(); + WideInt c = r.lo; + if (e.getKind() == AffineExprKind::FloorDiv) + return clampRange(floorDivW(l.lo, c), floorDivW(l.hi, c)); + if (e.getKind() == AffineExprKind::CeilDiv) + return clampRange(ceilDivW(l.lo, c), ceilDivW(l.hi, c)); + if (l.lo >= 0 && l.hi < c) + return l; + return {0, c - 1}; + } + + /// The range of the bound the map gives: the largest of its results (a + /// lower bound) or the smallest (an upper bound). + IntRange mapRange(AffineMap map, ValueRange operands, bool largest, + unsigned depth) { + SmallVector dims, syms; + for (auto en : llvm::enumerate(operands)) { + IntRange r = get(en.value(), false, depth + 1); + (en.index() < map.getNumDims() ? dims : syms).push_back(r); + } + std::optional res; + for (AffineExpr e : map.getResults()) { + IntRange r = exprRange(e, dims, syms); + if (!res) + res = r; + else if (largest) + res = IntRange{std::max(res->lo, r.lo), std::max(res->hi, r.hi)}; + else + res = IntRange{std::min(res->lo, r.lo), std::min(res->hi, r.hi)}; + } + return res ? *res : unboundedRange(); + } + + /// The range of an induction variable from the ranges of its loop's lower + /// and upper bound; a loop that never runs gives its lower bound. + static IntRange ivRange(IntRange lb, IntRange ub) { + if (ub.hi - 1 < lb.lo) + return {lb.lo, lb.lo}; + return {lb.lo, ub.hi - 1}; + } + + //===--------------------------------------------------------------------===// + // Index arithmetic as a linear combination of values, bounded through the + // bounds of the loops whose induction variables it contains: X = A - (iv - + // lb) of a countdown whose upper bound is A + 1 lies in [lb, A], which the + // intervals of A and iv alone do not show. + //===--------------------------------------------------------------------===// + + /// One value of a linear combination. Index casts of the same iN with the + /// same signedness are one atom (`base`, `kind`: 0 the value itself, 1 an + /// index_cast of it, 2 an index_castui), `rep` one of them. + struct LinearTerm { + Value base; + unsigned kind; + Value rep; + WideInt coeff; + }; + static constexpr WideInt kLinearMax = (WideInt)1 << 62; + + struct LinearForm { + SmallVector terms; + WideInt cst = 0; + // A coefficient or the constant left [-kLinearMax, kLinearMax]: no bound. + bool overflow = false; + + static bool big(WideInt x) { return x >= kLinearMax || x <= -kLinearMax; } + WideInt scaled(WideInt x, WideInt scale) { + if (big(x) || big(scale)) { + overflow = true; + return 0; + } + WideInt r = x * scale; + overflow |= big(r); + return r; + } + void add(const LinearForm &o, WideInt scale) { + overflow |= o.overflow; + cst += scaled(o.cst, scale); + overflow |= big(cst); + for (const LinearTerm &t : o.terms) { + WideInt c = scaled(t.coeff, scale); + bool merged = false; + for (LinearTerm &u : terms) + if (u.base == t.base && u.kind == t.kind) { + u.coeff += c; + overflow |= big(u.coeff); + merged = true; + break; + } + if (!merged) + terms.push_back({t.base, t.kind, t.rep, c}); + } + } + }; + + static LinearForm atom(Value v) { + LinearForm f; + Value base = v; + unsigned kind = 0; + if (auto c = v.getDefiningOp()) { + if (!c.getIn().getType().isIndex()) { + base = c.getIn(); + kind = 1; + } + } else if (auto c = v.getDefiningOp()) { + if (!c.getIn().getType().isIndex()) { + base = c.getIn(); + kind = 2; + } + } + f.terms.push_back({base, kind, v, 1}); + return f; + } + + /// The linear form of the affine expression `e` over `operands`, if it is + /// linear (no floordiv / ceildiv / mod, products by constants only). + std::optional linearExpr(AffineExpr e, ValueRange operands, + unsigned numDims, unsigned depth) { + switch (e.getKind()) { + case AffineExprKind::Constant: { + LinearForm f; + f.cst = e.cast().getValue(); + return f; + } + case AffineExprKind::DimId: + return linearize(operands[e.cast().getPosition()], + depth + 1); + case AffineExprKind::SymbolId: + return linearize( + operands[numDims + e.cast().getPosition()], + depth + 1); + case AffineExprKind::Add: { + auto bin = e.cast(); + auto l = linearExpr(bin.getLHS(), operands, numDims, depth); + auto r = linearExpr(bin.getRHS(), operands, numDims, depth); + if (!l || !r) + return std::nullopt; + l->add(*r, 1); + return l; + } + case AffineExprKind::Mul: { + auto bin = e.cast(); + auto c = bin.getRHS().dyn_cast(); + if (!c || c.getValue() <= -kLinearMax || c.getValue() >= kLinearMax) + return std::nullopt; + auto l = linearExpr(bin.getLHS(), operands, numDims, depth); + if (!l) + return std::nullopt; + LinearForm f; + f.add(*l, c.getValue()); + return f; + } + default: + return std::nullopt; + } + } + + /// `v` (index) as a linear combination of atoms. + LinearForm linearize(Value v, unsigned depth) { + APInt c; + if (matchPattern(v, m_ConstantInt(&c)) && c.getBitWidth() <= 64) { + LinearForm f; + f.cst = c.getSExtValue(); + return f; + } + Operation *op = v.getDefiningOp(); + if (!op || !v.getType().isIndex() || depth > 8) + return atom(v); + if (isa(op)) { + LinearForm f = linearize(op->getOperand(0), depth + 1); + f.add(linearize(op->getOperand(1), depth + 1), isa(op) ? 1 : -1); + return f; + } + if (isa(op)) { + for (unsigned i = 0; i < 2; ++i) { + APInt m; + if (matchPattern(op->getOperand(i), m_ConstantInt(&m)) && + m.getBitWidth() <= 64 && m.getSExtValue() > -kLinearMax && + m.getSExtValue() < kLinearMax) { + LinearForm f; + f.add(linearize(op->getOperand(1 - i), depth + 1), m.getSExtValue()); + return f; + } + } + return atom(v); + } + if (auto ap = dyn_cast(op)) + if (ap.getAffineMap().getNumResults() == 1) + if (auto f = linearExpr(ap.getAffineMap().getResult(0), + ap.getMapOperands(), + ap.getAffineMap().getNumDims(), depth)) + return *f; + return atom(v); + } + + /// The loop whose induction variable `v` is, if any. + static Operation *ivLoop(Value v) { + auto ba = v.dyn_cast(); + if (!ba) + return nullptr; + Operation *owner = ba.getOwner()->getParentOp(); + if (auto af = dyn_cast_or_null(owner)) + return af.getInductionVar() == v ? owner : nullptr; + if (auto sf = dyn_cast_or_null(owner)) + return sf.getInductionVar() == v ? owner : nullptr; + return nullptr; + } + + /// A lower bound of the induction variable of `loop` (`upper`: an upper + /// bound, ub - 1) as a linear form: any result of a max / min bound map + /// bounds it. + std::optional ivBound(Operation *loop, bool upper, + unsigned depth) { + if (auto af = dyn_cast(loop)) { + AffineMap map = upper ? af.getUpperBoundMap() : af.getLowerBoundMap(); + if (map.getNumResults() == 0) + return std::nullopt; + ValueRange ops = + upper ? af.getUpperBoundOperands() : af.getLowerBoundOperands(); + auto f = linearExpr(map.getResult(0), ops, map.getNumDims(), depth); + if (f && upper) + f->cst -= 1; + return f; + } + auto sf = cast(loop); + LinearForm f = + linearize(upper ? sf.getUpperBound() : sf.getLowerBound(), depth + 1); + if (upper) + f.cst -= 1; + return f; + } + + /// The smallest (`upper`: largest) value of `f`: induction variables are + /// replaced by their bounds, innermost loop first, then every remaining + /// atom by the end of its range. + WideInt linearExtreme(LinearForm f, bool upper, unsigned depth) { + for (unsigned iter = 0; iter < 16 && !f.overflow; ++iter) { + int pick = -1; + Operation *pickLoop = nullptr; + for (auto en : llvm::enumerate(f.terms)) { + if (en.value().kind != 0 || en.value().coeff == 0) + continue; + Operation *loop = ivLoop(en.value().base); + if (!loop) + continue; + if (!pickLoop || pickLoop->isProperAncestor(loop)) { + pick = en.index(); + pickLoop = loop; + } + } + if (pick < 0) + break; + LinearTerm t = f.terms[pick]; + // Maximising c * iv takes the largest iv for c > 0, the smallest for + // c < 0; minimising the reverse. + bool useUpper = upper ? t.coeff > 0 : t.coeff < 0; + std::optional b = ivBound(pickLoop, useUpper, depth); + if (!b) + break; + f.terms.erase(f.terms.begin() + pick); + f.add(*b, t.coeff); + } + if (f.overflow) + return upper ? kRangeInf : -kRangeInf; + WideInt r = f.cst; + for (const LinearTerm &t : f.terms) { + if (t.coeff == 0) + continue; + IntRange a = get(t.rep, false, depth + 1); + WideInt end = (upper == (t.coeff > 0)) ? a.hi : a.lo; + if (end >= kLinearMax || end <= -kLinearMax || t.coeff >= kLinearMax || + t.coeff <= -kLinearMax) + return upper ? kRangeInf : -kRangeInf; + r += t.coeff * end; + if (r >= kRangeInf || r <= -kRangeInf) + return upper ? kRangeInf : -kRangeInf; + } + return r; + } + + /// The range of the index value `v` from its linear form, when that + /// contains an induction variable (unbounded otherwise). + IntRange linearRange(Value v, unsigned depth) { + LinearForm f = linearize(v, 0); + bool hasIV = llvm::any_of(f.terms, [](const LinearTerm &t) { + return t.kind == 0 && t.coeff != 0 && ivLoop(t.base); + }); + if (!hasIV) + return unboundedRange(); + return clampRange(linearExtreme(f, false, depth), + linearExtreme(f, true, depth)); + } + + static IntRange intersectRange(IntRange a, IntRange b) { + IntRange r{std::max(a.lo, b.lo), std::min(a.hi, b.hi)}; + return r.lo <= r.hi ? r : a; + } + + IntRange compute(Value v, bool asUnsigned, unsigned depth) { + unsigned w = intOrIndexWidth(v.getType()); + if (w == 0) + return unboundedRange(); + IntRange whole = typeRange(w, asUnsigned); + if (depth > 12) + return whole; + auto fit = [&](IntRange r) { return rangeWithin(r, whole) ? r : whole; }; + + APInt c; + if (matchPattern(v, m_ConstantInt(&c))) { + if (c.getBitWidth() > 64) + return whole; + WideInt x = asUnsigned ? (WideInt)c.getZExtValue() + : (WideInt)c.getSExtValue(); + return {x, x}; + } + + if (auto ba = v.dyn_cast()) { + Operation *owner = ba.getOwner()->getParentOp(); + if (auto af = dyn_cast_or_null(owner)) { + if (af.getInductionVar() == v) + return fit(ivRange(mapRange(af.getLowerBoundMap(), + af.getLowerBoundOperands(), + /*largest=*/true, depth), + mapRange(af.getUpperBoundMap(), + af.getUpperBoundOperands(), + /*largest=*/false, depth))); + } else if (auto sf = dyn_cast_or_null(owner)) { + if (sf.getInductionVar() == v) + return fit(ivRange(get(sf.getLowerBound(), false, depth + 1), + get(sf.getUpperBound(), false, depth + 1))); + } else if (auto sp = dyn_cast_or_null(owner)) { + // Steps are positive (verifier), as for the loops above. + for (auto [i, iv] : llvm::enumerate(sp.getInductionVars())) + if (iv == v) + return fit( + ivRange(get(sp.getLowerBound()[i], false, depth + 1), + get(sp.getUpperBound()[i], false, depth + 1))); + } else if (auto ap = dyn_cast_or_null(owner)) { + for (auto [i, iv] : llvm::enumerate(ap.getIVs())) + if (iv == v) + return fit(ivRange( + mapRange(ap.getLowerBoundMap(i), ap.getLowerBoundsOperands(), + /*largest=*/true, depth), + mapRange(ap.getUpperBoundMap(i), ap.getUpperBoundsOperands(), + /*largest=*/false, depth))); + } + return whole; + } + + Operation *op = v.getDefiningOp(); + // CUDA's thread / block indices and dimensions (cgeist's threadIdx, + // blockIdx, blockDim, gridDim) are unsigned and below 2^31 (the largest + // dimension, gridDim.x, is at most 2^31 - 1). + if (isa( + op)) + return fit({0, ((WideInt)1 << 31) - 1}); + if (isa(op)) { + Value in = op->getOperand(0); + if (in.getType().isIndex()) // a truncation index -> iN + return fit(get(in, false, depth + 1)); + if (isa(op)) + return fit(get(in, true, depth + 1)); + IntRange r = get(in, false, depth + 1); + if (!asUnsigned || r.lo >= 0) + return fit(r); + if (r.hi < 0 && w <= 96) + return fit({r.lo + ((WideInt)1 << w), r.hi + ((WideInt)1 << w)}); + return whole; + } + if (auto tr = dyn_cast(op)) { + for (bool u : {asUnsigned, !asUnsigned}) { + IntRange r = get(tr.getIn(), u, depth + 1); + if (rangeWithin(r, whole)) + return r; + } + return whole; + } + if (isa(op)) { + IntRange a = get(op->getOperand(0), asUnsigned, depth + 1); + IntRange b = get(op->getOperand(1), asUnsigned, depth + 1); + IntRange r = arithRange(op, a, b); + if (v.getType().isIndex()) + return fit(intersectRange(r, linearRange(v, depth))); + // An op raised without a proof (polygeist.nsw), read signed, does not + // wrap (see above): its range is that of its raised expression. + if (!asUnsigned && !needsNoWrapProof(op)) + return r; + // A constant operand as the representative that keeps the result in + // range (constantRepresentative). + if (!rangeWithin(r, whole)) + if (auto ci = constantOperand(op)) + if (auto rep = constantRepresentative(op, *ci, *ci == 0 ? b : a, + asUnsigned)) { + IntRange cr{*rep, *rep}; + r = *ci == 0 ? arithRange(op, cr, b) : arithRange(op, a, cr); + } + return fit(r); + } + if (isa(op)) { + IntRange a = get(op->getOperand(0), asUnsigned, depth + 1); + IntRange b = get(op->getOperand(1), asUnsigned, depth + 1); + if (a.lo >= 0 && b.lo >= 0) + return {0, std::min(a.hi, b.hi)}; + if (a.lo >= 0) + return {0, a.hi}; + if (b.lo >= 0) + return {0, b.hi}; + return whole; + } + if (isa(op)) { + IntRange a = get(op->getOperand(0), true, depth + 1); + IntRange b = get(op->getOperand(1), true, depth + 1); + if (isa(op)) { + if (b.lo != b.hi || b.lo < 0 || b.lo >= (WideInt)w) + return fit({0, a.hi}); + return fit({a.lo >> (int)b.lo, a.hi >> (int)b.lo}); + } + // Division by zero is undefined: the divisor is at least 1. + WideInt bLo = std::max(b.lo, 1); + if (isa(op)) + return fit({0, std::min(a.hi, b.hi - 1)}); + return fit({a.lo / b.hi, a.hi / bLo}); + } + if (isa(op)) { + IntRange a = get(op->getOperand(0), false, depth + 1); + IntRange b = get(op->getOperand(1), false, depth + 1); + if (b.lo <= 0) + return whole; + if (isa(op)) + return fit({a.lo >= 0 ? 0 : std::max(a.lo, -(b.hi - 1)), + a.hi <= 0 ? 0 : std::min(a.hi, b.hi - 1)}); + WideInt q[4] = {a.lo / b.lo, a.lo / b.hi, a.hi / b.lo, a.hi / b.hi}; + return fit({*std::min_element(q, q + 4), *std::max_element(q, q + 4)}); + } + if (auto sel = dyn_cast(op)) + return unionRange(get(sel.getTrueValue(), asUnsigned, depth + 1), + get(sel.getFalseValue(), asUnsigned, depth + 1)); + if (isa(op) && !asUnsigned) { + IntRange a = get(op->getOperand(0), false, depth + 1); + IntRange b = get(op->getOperand(1), false, depth + 1); + if (isa(op)) + return {std::max(a.lo, b.lo), std::max(a.hi, b.hi)}; + return {std::min(a.lo, b.lo), std::min(a.hi, b.hi)}; + } + if (auto ap = dyn_cast(op)) + return fit(intersectRange(mapRange(ap.getAffineMap(), ap.getMapOperands(), + /*largest=*/true, depth), + linearRange(v, depth))); + if (auto mn = dyn_cast(op)) + return fit(mapRange(mn.getAffineMap(), mn.getMapOperands(), + /*largest=*/false, depth)); + if (auto mx = dyn_cast(op)) + return fit(mapRange(mx.getAffineMap(), mx.getMapOperands(), + /*largest=*/true, depth)); + return whole; + } +}; +} // namespace + +/// Whether an integer of type `readType` raised without a proof that it +/// keeps its value (a marked add / sub / mul, a cast at least 32 bits wide; +/// see above) keeps it when it is read `asUnsigned`, `signedValue` being what +/// it is exact as (the op's result read signed; a cast's input): read signed +/// or 64 bits wide, always; read unsigned and narrower, only when that value +/// is provably non-negative (a negative iN value read unsigned is 2^N more). +/// With -affine-cfg-assume-nowrap-width=N: always, as before. +static bool unsignedReadKeepsValue(IntRangeOracle &ranges, Type readType, + Value signedValue, bool asUnsigned) { + if (!asUnsigned || AssumeNoWrapWidth || intOrIndexWidth(readType) >= 64) + return true; + return ranges.get(signedValue, /*asUnsigned=*/false).lo >= 0; +} + +/// Strips from `v`, read as `asUnsigned` (an index: as is), the casts that +/// keep its value (see above): returns the innermost value reached and how it +/// is read there. With `indexCastsOnly`, only index_cast / index_castui. +static std::pair peelExactCasts(Value v, bool asUnsigned, + bool indexCastsOnly = false) { + if (v.getType().isIndex()) + asUnsigned = false; + IntRangeOracle ranges; + while (Operation *op = v.getDefiningOp()) { + bool indexCast = isa(op); + if (!indexCast && (indexCastsOnly || !isa(op))) + break; + Value in = op->getOperand(0); + Type outTy = v.getType(); + bool inUnsigned = false; + if (in.getType().isIndex()) { + // A truncation index -> iN: exact while the index fits the iN as read + // (provably, or as the frontend marked it). A wide one is assumed to + // fit; read unsigned, only a non-negative index does. + if (!truncationMarkedExact(op, asUnsigned) && + (needsNoWrapProof(outTy) + ? !rangeWithin(ranges.get(in, false), + typeRange(intOrIndexWidth(outTy), asUnsigned)) + : !unsignedReadKeepsValue(ranges, outTy, in, asUnsigned))) + break; + } else if (isa(op)) { + inUnsigned = true; + } else if (needsNoWrapProof(outTy) + ? asUnsigned && ranges.get(in, false).lo < 0 + : !unsignedReadKeepsValue(ranges, outTy, in, asUnsigned)) { + // A sign extension read unsigned: exact for a non-negative input only. + break; + } + v = in; + asUnsigned = !v.getType().isIndex() && inUnsigned; + } + return {v, asUnsigned}; +} + +/// How the operands of `op`, read as `asUnsigned`, are read: an add / sub / +/// mul that needs the proof reads them the same way, a narrow unsigned div / +/// rem unsigned, a signed one signed; an op raised without a proof (a marked +/// add / sub / mul, a wide div / rem) signed. +static bool operandsUnsigned(Operation *op, bool asUnsigned) { + if (!needsNoWrapProof(op)) + return false; + if (isa(op)) + return true; + if (isa(op)) + return false; + return asUnsigned; +} + +static bool isRaisedIntOp(Operation *op) { + return isa_and_nonnull(op); +} + +/// Whether the integer op `op` (isRaisedIntOp), read as `asUnsigned`, equals +/// the affine expression of its operands read as operandsUnsigned (see +/// above). An index add / sub / mul: no proof; a marked one: none read +/// signed, read unsigned the proof that it is non-negative +/// (unsignedReadKeepsValue); a div / rem of any width needs the floordiv / +/// mod proof. +static bool exactArith(Operation *op, bool asUnsigned) { + Type t = op->getResult(0).getType(); + bool divRem = isa(op); + IntRangeOracle ranges; + if (!divRem && !needsNoWrapProof(op)) + return unsignedReadKeepsValue(ranges, t, op->getResult(0), asUnsigned); + bool ou = operandsUnsigned(op, asUnsigned); + IntRange a = ranges.get(op->getOperand(0), ou); + IntRange b = ranges.get(op->getOperand(1), ou); + IntRange whole = raisableRange(intOrIndexWidth(t), asUnsigned); + if (!divRem) { + if (auto ci = constantOperand(op)) + return constantRepresentative(op, *ci, *ci == 0 ? b : a, asUnsigned) + .has_value(); + return rangeWithin(arithRange(op, a, b), whole); + } + // floordiv / mod is C's truncating / and % only for a non-negative + // dividend and a positive divisor (an unsigned divisor of 0 is undefined + // behaviour), at every width. + if (a.lo < 0 || (ou ? b.hi < 1 : b.lo < 1)) + return false; + if (!needsNoWrapProof(t)) + return true; + WideInt bLo = std::max(b.lo, 1); + IntRange r = isa(op) + ? IntRange{a.lo / b.hi, a.hi / bLo} + : IntRange{0, std::min(a.hi, b.hi - 1)}; + return rangeWithin(r, whole); +} + +/// The value of the integer constant `ci` read as `asUnsigned` (wide +/// constants as before: signed). +static int64_t constantRead(ConstantIntOp ci, bool asUnsigned) { + if (!asUnsigned || !needsNoWrapProof(ci.getType())) + return ci.value(); + return (int64_t)ci.getValue().cast().getValue().getZExtValue(); +} + +static bool isValidIndexAs(Value val, bool asUnsigned); + struct AffineApplyNormalizer { AffineApplyNormalizer(AffineMap map, ArrayRef operands, PatternRewriter &rewriter, DominanceInfo &DI); @@ -131,14 +1025,18 @@ static bool legalCondition(Value en, bool dim = false) { } } - while (auto ic = en.getDefiningOp()) - en = ic.getIn(); + // The index casts that keep the value (the normalizer strips at least + // these), then an op with a constant operand it raises exactly. + auto [stripped, strippedUnsigned] = + peelExactCasts(en, /*asUnsigned=*/false, /*indexCastsOnly=*/true); + en = stripped; if ((en.getDefiningOp() || en.getDefiningOp() || en.getDefiningOp() || en.getDefiningOp() || en.getDefiningOp()) && (en.getDefiningOp()->getOperand(1).getDefiningOp() || - en.getDefiningOp()->getOperand(1).getDefiningOp())) + en.getDefiningOp()->getOperand(1).getDefiningOp()) && + exactArith(en.getDefiningOp(), strippedUnsigned)) return true; // if (auto IC = dyn_cast_or_null(en.getDefiningOp())) { // if (!outer || legalCondition(IC.getOperand(), false)) return true; @@ -289,61 +1187,91 @@ AffineApplyNormalizer::AffineApplyNormalizer(AffineMap map, return expr; }; + // The narrow iN `v` read as `asUnsigned`, as an index map input: an + // index_cast / index_castui of it that dominates the rewritten op (a valid + // symbol if `v` is one), else a new one right after its definition. + auto indexInput = [&](Value v, bool asUnsigned) -> Value { + if (v.getType().isIndex()) + return v; + Operation *ip = nullptr; + if (rewriter.getInsertionBlock() && + rewriter.getInsertionPoint() != rewriter.getInsertionBlock()->end()) + ip = &*rewriter.getInsertionPoint(); + bool symbol = isValidSymbolInt(v, /*recur*/ false); + for (Operation *u : v.getUsers()) + if ((asUnsigned ? isa(u) : isa(u)) && + u->getResult(0).getType().isIndex() && ip && DI.dominates(u, ip) && + (!symbol || isValidSymbolInt(u->getResult(0), /*recur*/ false))) + return u->getResult(0); + PatternRewriter::InsertionGuard guard(rewriter); + if (Operation *def = v.getDefiningOp()) + rewriter.setInsertionPointAfter(def); + else + rewriter.setInsertionPointToStart(v.cast().getOwner()); + if (asUnsigned) + return rewriter.create(v.getLoc(), rewriter.getIndexType(), + v); + return rewriter.create(v.getLoc(), rewriter.getIndexType(), v); + }; + // 2. Compose affine::AffineApplyOps and dispatch dims or symbols. for (unsigned i = 0, e = operands.size(); i < e; ++i) { auto t = operands[i]; - auto decast = t; - while (true) { - if (auto idx = decast.getDefiningOp()) { - decast = idx.getIn(); - continue; - } - if (auto idx = decast.getDefiningOp()) { - decast = idx.getIn(); - continue; - } - if (auto idx = decast.getDefiningOp()) { - decast = idx.getIn(); - continue; - } - break; - } + // The casts that keep the value (peelExactCasts); `decast` is read as + // `decastUnsigned`. + auto [decast, decastUnsigned] = peelExactCasts(t, /*asUnsigned=*/false); + bool tUnsigned = false; if (!isValidSymbolInt(t, /*recur*/ false)) { t = decast; + tUnsigned = decastUnsigned; } + // An integer op becomes the affine expression of its operands only when + // that keeps its value (exactArith), its operands read as + // operandsUnsigned says. + auto exact = [](Value v, bool asUnsigned) { + Operation *op = v.getDefiningOp(); + return !isRaisedIntOp(op) || exactArith(op, asUnsigned); + }; + bool tOperandsUnsigned = isRaisedIntOp(t.getDefiningOp()) && + operandsUnsigned(t.getDefiningOp(), tUnsigned); + auto validIndex = [&](Value v) { + return isValidIndexAs(v, tOperandsUnsigned); + }; + // Only promote one at a time, lest we end up with two dimensions // multiplying each other. - if (((!isValidSymbolInt(t, /*recur*/ false) && + if (((!isValidSymbolInt(t, /*recur*/ false) && exact(t, tUnsigned) && (t.getDefiningOp() || t.getDefiningOp() || (t.getDefiningOp() && - ((isValidIndex(t.getDefiningOp()->getOperand(0)) && + ((validIndex(t.getDefiningOp()->getOperand(0)) && isValidSymbolInt(t.getDefiningOp()->getOperand(1))) || - (isValidIndex(t.getDefiningOp()->getOperand(1)) && + (validIndex(t.getDefiningOp()->getOperand(1)) && isValidSymbolInt(t.getDefiningOp()->getOperand(0)))) && !(fix(t.getDefiningOp()->getOperand(0), false) && fix(t.getDefiningOp()->getOperand(1), false)) ) || ((t.getDefiningOp() || t.getDefiningOp()) && - (isValidIndex(t.getDefiningOp()->getOperand(0)) && + (validIndex(t.getDefiningOp()->getOperand(0)) && isValidSymbolInt(t.getDefiningOp()->getOperand(1))) && (!(fix(t.getDefiningOp()->getOperand(0), false) && fix(t.getDefiningOp()->getOperand(1), false)))) || (t.getDefiningOp() && - (isValidIndex(t.getDefiningOp()->getOperand(0)) && + (validIndex(t.getDefiningOp()->getOperand(0)) && isValidSymbolInt(t.getDefiningOp()->getOperand(1)))) || (t.getDefiningOp() && - (isValidIndex(t.getDefiningOp()->getOperand(0)) && + (validIndex(t.getDefiningOp()->getOperand(0)) && isValidSymbolInt(t.getDefiningOp()->getOperand(1)))) || (t.getDefiningOp() && - (isValidIndex(t.getDefiningOp()->getOperand(0)) && + (validIndex(t.getDefiningOp()->getOperand(0)) && isValidSymbolInt(t.getDefiningOp()->getOperand(1)))) || t.getDefiningOp() || t.getDefiningOp())) || - ((decast.getDefiningOp() || decast.getDefiningOp() || + (exact(decast, decastUnsigned) && + (decast.getDefiningOp() || decast.getDefiningOp() || decast.getDefiningOp() || decast.getDefiningOp() || decast.getDefiningOp()) && (decast.getDefiningOp() @@ -353,119 +1281,163 @@ AffineApplyNormalizer::AffineApplyNormalizer(AffineMap map, ->getOperand(1) .getDefiningOp())))) { t = decast; + tUnsigned = decastUnsigned; LLVM_DEBUG(llvm::dbgs() << " Replacing: " << t << "\n"); + // The op's operands as map inputs: those of an op that needs the proof + // (needsNoWrapProof: a narrow op, an unmarked add / sub / mul) through + // an index cast with the signedness its proof read them with, its + // constants read that way; any other op's as before. + bool narrowOp = isRaisedIntOp(t.getDefiningOp()) && + needsNoWrapProof(t.getDefiningOp()); + bool inputsUnsigned = + narrowOp && operandsUnsigned(t.getDefiningOp(), tUnsigned); + auto input = [&](Value v) -> Value { + return narrowOp ? indexInput(v, inputsUnsigned) : v; + }; + auto cstValue = [&](ConstantIntOp ci) -> int64_t { + return narrowOp ? constantRead(ci, inputsUnsigned) : ci.value(); + }; + AffineMap affineApplyMap; SmallVector affineApplyOperands; // llvm::dbgs() << "\nop to start: " << t << "\n"; - if (auto op = t.getDefiningOp()) { + // A narrow add / sub / mul with a constant operand: the constant is the + // representative its proof used (constantRepresentative). + std::optional narrowCst; + std::optional narrowRep; + if (narrowOp && isa(t.getDefiningOp()) && + (narrowCst = constantOperand(t.getDefiningOp()))) { + IntRangeOracle ranges; + Operation *op = t.getDefiningOp(); + narrowRep = constantRepresentative( + op, *narrowCst, + ranges.get(op->getOperand(1 - *narrowCst), inputsUnsigned), + tUnsigned); + } + + if (narrowRep) { + Operation *op = t.getDefiningOp(); + AffineExpr c = + getAffineConstantExpr((int64_t)*narrowRep, op->getContext()); + AffineExpr x = getAffineSymbolExpr(0, op->getContext()); + AffineExpr lhs = *narrowCst == 0 ? c : x; + AffineExpr rhs = *narrowCst == 0 ? x : c; + affineApplyMap = AffineMap::get(0, 1, + isa(op) ? lhs + rhs + : isa(op) ? lhs - rhs + : lhs * rhs); + affineApplyOperands.push_back(input(op->getOperand(1 - *narrowCst))); + } else if (auto op = t.getDefiningOp()) { affineApplyMap = AffineMap::get(0, 2, getAffineSymbolExpr(0, op.getContext()) + getAffineSymbolExpr(1, op.getContext())); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } else if (auto op = t.getDefiningOp()) { affineApplyMap = AffineMap::get(0, 2, getAffineSymbolExpr(0, op.getContext()) - getAffineSymbolExpr(1, op.getContext())); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } else if (auto op = t.getDefiningOp()) { if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( - 0, 1, getAffineSymbolExpr(0, op.getContext()) * ci.value()); - affineApplyOperands.push_back(op.getLhs()); + 0, 1, getAffineSymbolExpr(0, op.getContext()) * cstValue(ci)); + affineApplyOperands.push_back(input(op.getLhs())); } else if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, getAffineSymbolExpr(0, op.getContext()) * ci.value()); - affineApplyOperands.push_back(op.getLhs()); + affineApplyOperands.push_back(input(op.getLhs())); } else { affineApplyMap = AffineMap::get(0, 2, getAffineSymbolExpr(0, op.getContext()) * getAffineSymbolExpr(1, op.getContext())); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } } else if (auto op = t.getDefiningOp()) { if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, - getAffineSymbolExpr(0, op.getContext()).floorDiv(ci.value())); - affineApplyOperands.push_back(op.getLhs()); + getAffineSymbolExpr(0, op.getContext()).floorDiv(cstValue(ci))); + affineApplyOperands.push_back(input(op.getLhs())); } else if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, getAffineSymbolExpr(0, op.getContext()).floorDiv(ci.value())); - affineApplyOperands.push_back(op.getLhs()); + affineApplyOperands.push_back(input(op.getLhs())); } else { affineApplyMap = AffineMap::get( 0, 2, getAffineSymbolExpr(0, op.getContext()) .floorDiv(getAffineSymbolExpr(1, op.getContext()))); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } } else if (auto op = t.getDefiningOp()) { if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, - getAffineSymbolExpr(0, op.getContext()).floorDiv(ci.value())); - affineApplyOperands.push_back(op.getLhs()); + getAffineSymbolExpr(0, op.getContext()).floorDiv(cstValue(ci))); + affineApplyOperands.push_back(input(op.getLhs())); } else if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, getAffineSymbolExpr(0, op.getContext()).floorDiv(ci.value())); - affineApplyOperands.push_back(op.getLhs()); + affineApplyOperands.push_back(input(op.getLhs())); } else { affineApplyMap = AffineMap::get( 0, 2, getAffineSymbolExpr(0, op.getContext()) .floorDiv(getAffineSymbolExpr(1, op.getContext()))); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } } else if (auto op = t.getDefiningOp()) { if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( - 0, 1, getAffineSymbolExpr(0, op.getContext()) % ci.value()); - affineApplyOperands.push_back(op.getLhs()); + 0, 1, getAffineSymbolExpr(0, op.getContext()) % cstValue(ci)); + affineApplyOperands.push_back(input(op.getLhs())); } else if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, getAffineSymbolExpr(0, op.getContext()) % ci.value()); - affineApplyOperands.push_back(op.getLhs()); + affineApplyOperands.push_back(input(op.getLhs())); } else { affineApplyMap = AffineMap::get(0, 2, getAffineSymbolExpr(0, op.getContext()) % getAffineSymbolExpr(1, op.getContext())); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } } else if (auto op = t.getDefiningOp()) { if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( - 0, 1, getAffineSymbolExpr(0, op.getContext()) % ci.value()); - affineApplyOperands.push_back(op.getLhs()); + 0, 1, getAffineSymbolExpr(0, op.getContext()) % cstValue(ci)); + affineApplyOperands.push_back(input(op.getLhs())); } else if (auto ci = op.getRhs().getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 1, getAffineSymbolExpr(0, op.getContext()) % ci.value()); - affineApplyOperands.push_back(op.getLhs()); + affineApplyOperands.push_back(input(op.getLhs())); } else { affineApplyMap = AffineMap::get(0, 2, getAffineSymbolExpr(0, op.getContext()) % getAffineSymbolExpr(1, op.getContext())); - affineApplyOperands.push_back(op.getLhs()); - affineApplyOperands.push_back(op.getRhs()); + affineApplyOperands.push_back(input(op.getLhs())); + affineApplyOperands.push_back(input(op.getRhs())); } } else if (auto op = t.getDefiningOp()) { affineApplyMap = AffineMap::get( - 0, 0, getAffineConstantExpr(op.value(), op.getContext())); + 0, 0, + getAffineConstantExpr(constantRead(op, tUnsigned), + op.getContext())); } else if (auto op = t.getDefiningOp()) { affineApplyMap = AffineMap::get( 0, 0, getAffineConstantExpr(op.value(), op.getContext())); @@ -537,6 +1509,21 @@ AffineApplyNormalizer::AffineApplyNormalizer(AffineMap map, } else llvm_unreachable("cannot move2"); } + // A narrow iN symbol, read as the casts stripped above it read it: a + // constant as that value, anything else through an index cast with + // that signedness. + if (needsNoWrapProof(t.getType())) { + if (auto ci = t.getDefiningOp()) { + AffineExpr c = getAffineConstantExpr(constantRead(ci, tUnsigned), + ci.getContext()); + if (i < numDims) + dimReplacements.push_back(c); + else + symReplacements.push_back(c); + continue; + } + t = indexInput(t, tUnsigned); + } if (i < numDims) { // b. The mathematical composition of AffineMap composes dims. dimReplacements.push_back(renumberOneDim(t)); @@ -611,34 +1598,64 @@ bool need(IntegerSet *map, SmallVectorImpl *operands) { return false; } +/// If `op` is an index cast (signed or unsigned), remember a cast of the same +/// kind of its input that is a valid affine symbol, so that the input is +/// re-cast through it (keeping the cast's signedness) rather than a new cast. +static void recordIndexCastOperand(Value op, IRMapping &indexMap, + PatternRewriter &builder, + DominanceInfo &DI) { + Operation *idx0 = op.getDefiningOp(); + if (!idx0 || !isa(idx0)) + return; + Value in = idx0->getOperand(0); + SmallVector attempt{op}; + for (auto &u : in.getUses()) { + Operation *idx = u.getOwner(); + if (idx != idx0 && idx->getName() == idx0->getName()) + if (DI.dominates(idx, &*builder.getInsertionPoint())) + attempt.push_back(idx->getResult(0)); + } + for (Value idx : attempt) { + if (affine::isValidSymbol(idx)) { + indexMap.map(in, idx); + break; + } + } +} + +/// Cast a non-index map operand to index. The signedness is taken from how the +/// value is otherwise widened in the IR: a value that only reaches index or a +/// wider integer through index_castui/extui (an unsigned C index) gets +/// index_castui; anything else keeps the signed index_cast. +static Value castOperandToIndex(OpBuilder &builder, Value op) { + bool hasUnsigned = false, hasSigned = false; + for (Operation *u : op.getUsers()) { + if (isa(u)) + hasUnsigned = true; + else if (isa(u)) + hasSigned = true; + } + if (hasUnsigned && !hasSigned) + return builder.create(op.getLoc(), builder.getIndexType(), + op); + return builder.create(op.getLoc(), builder.getIndexType(), op); +} + void fully2ComposeAffineMapAndOperands(PatternRewriter &builder, AffineMap *map, SmallVectorImpl *operands, DominanceInfo &DI) { IRMapping indexMap; - for (auto op : *operands) { - SmallVector attempt; - auto idx0 = op.getDefiningOp(); - attempt.push_back(idx0); - if (!idx0) - continue; - - for (auto &u : idx0.getIn().getUses()) { - if (auto idx = dyn_cast(u.getOwner())) - if (DI.dominates((Operation *)idx, &*builder.getInsertionPoint())) - attempt.push_back(idx); - } - - for (auto idx : attempt) { - if (affine::isValidSymbol(idx)) { - indexMap.map(idx.getIn(), idx); - break; - } - } - } + for (auto op : *operands) + recordIndexCastOperand(op, indexMap, builder, DI); assert(map->getNumInputs() == operands->size()); while (need(map, operands)) { + AffineMap prevMap = *map; + SmallVector prevOperands(operands->begin(), operands->end()); composeAffineMapAndOperands(map, operands, builder, DI); assert(map->getNumInputs() == operands->size()); + // Nothing left that can be raised exactly. + if (*map == prevMap && llvm::equal(*operands, prevOperands)) + break; } *map = simplifyAffineMap(*map); for (auto &op : *operands) { @@ -656,8 +1673,7 @@ void fully2ComposeAffineMapAndOperands(PatternRewriter &builder, AffineMap *map, else { PatternRewriter::InsertionGuard B(builder); builder.setInsertionPoint(toInsert); - op = builder.create(op.getLoc(), builder.getIndexType(), - op); + op = castOperandToIndex(builder, op); } } } @@ -668,30 +1684,17 @@ void fully2ComposeIntegerSetAndOperands(PatternRewriter &builder, SmallVectorImpl *operands, DominanceInfo &DI) { IRMapping indexMap; - for (auto op : *operands) { - SmallVector attempt; - auto idx0 = op.getDefiningOp(); - attempt.push_back(idx0); - if (!idx0) - continue; - - for (auto &u : idx0.getIn().getUses()) { - if (auto idx = dyn_cast(u.getOwner())) - if (DI.dominates((Operation *)idx, &*builder.getInsertionPoint())) - attempt.push_back(idx); - } - - for (auto idx : attempt) { - if (affine::isValidSymbol(idx)) { - indexMap.map(idx.getIn(), idx); - break; - } - } - } + for (auto op : *operands) + recordIndexCastOperand(op, indexMap, builder, DI); auto map = AffineMap::get(set->getNumDims(), set->getNumSymbols(), set->getConstraints(), set->getContext()); while (need(&map, operands)) { + AffineMap prevMap = map; + SmallVector prevOperands(operands->begin(), operands->end()); composeAffineMapAndOperands(&map, operands, builder, DI); + // Nothing left that can be raised exactly. + if (map == prevMap && llvm::equal(*operands, prevOperands)) + break; } map = simplifyAffineMap(map); *set = IntegerSet::get(map.getNumDims(), map.getNumSymbols(), @@ -711,8 +1714,7 @@ void fully2ComposeIntegerSetAndOperands(PatternRewriter &builder, else { PatternRewriter::InsertionGuard B(builder); builder.setInsertionPoint(toInsert); - op = builder.create(op.getLoc(), builder.getIndexType(), - op); + op = castOperandToIndex(builder, op); } } } @@ -918,17 +1920,41 @@ struct CanonicalizeAffineApply } }; +/// Whether the cast `inner` (index_cast / index_castui of `src` to `mid`) +/// followed by a cast back that reads `mid` as `asUnsigned` gives `src` again: +/// always for an iN -> index -> iN round trip (an extension, then its +/// truncation); for index -> iN -> index only when the index value fits iN +/// as it is read (needsNoWrapProof; provably, or as the frontend marked the +/// truncation: the counter casts CanonicalizeFor creates hold such values). +/// A wide iN is assumed to hold the index value read signed; read unsigned, +/// it needs a non-negative one (unsignedReadKeepsValue): the bound +/// (unsigned)i of an int counter i = -1 is 4294967295, not -1. +static bool roundTripKeepsValue(Operation *inner, bool asUnsigned) { + Value src = inner->getOperand(0); + Type mid = inner->getResult(0).getType(); + if (!src.getType().isIndex() || truncationMarkedExact(inner, asUnsigned)) + return true; + IntRangeOracle ranges; + if (!needsNoWrapProof(mid)) + return unsignedReadKeepsValue(ranges, mid, src, asUnsigned); + return rangeWithin(ranges.get(src, false), + typeRange(intOrIndexWidth(mid), asUnsigned)); +} + struct CanonicalizeIndexCast : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; LogicalResult matchAndRewrite(IndexCastOp indexcastOp, PatternRewriter &rewriter) const override { - // Fold IndexCast(IndexCast(x)) -> x - auto cast = indexcastOp.getOperand().getDefiningOp(); - if (cast && cast.getOperand().getType() == indexcastOp.getType()) { - mlir::Value vals[] = {cast.getOperand()}; - rewriter.replaceOp(indexcastOp, vals); + // Fold IndexCast(IndexCast(x)) -> x and IndexCast(IndexCastUI(x)) -> x + // when the round trip keeps the value (roundTripKeepsValue). + Operation *inner = indexcastOp.getOperand().getDefiningOp(); + if (isa_and_nonnull(inner) && + inner->getOperand(0).getType() == indexcastOp.getType() && + roundTripKeepsValue(inner, /*asUnsigned=*/false)) { + Value src = inner->getOperand(0); + rewriter.replaceOp(indexcastOp, src); return success(); } @@ -936,9 +1962,44 @@ struct CanonicalizeIndexCast : public OpRewritePattern { // A little hack because we go through int. Otherwise, the size // of the constant might need to change. if (auto cst = indexcastOp.getOperand().getDefiningOp()) { - rewriter.replaceOpWithNewOp(indexcastOp, cst.value()); + APInt v = cst.getValue().cast().getValue(); + if (v.getSignificantBits() <= 64) { + rewriter.replaceOpWithNewOp(indexcastOp, + v.getSExtValue()); + return success(); + } + } + return failure(); + } +}; + +/// The unsigned counterpart of CanonicalizeIndexCast: +/// IndexCastUI(IndexCastUI(x)) -> x and IndexCastUI(IndexCast(x)) -> x when +/// the types match and the round trip keeps the value (roundTripKeepsValue; +/// the index -> iN -> index round trip of an unsigned loop counter), and +/// IndexCastUI(constant) -> the zero-extended index constant. +struct CanonicalizeIndexCastUI : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(IndexCastUIOp indexcastOp, + PatternRewriter &rewriter) const override { + Operation *inner = indexcastOp.getOperand().getDefiningOp(); + if (isa_and_nonnull(inner) && + inner->getOperand(0).getType() == indexcastOp.getType() && + roundTripKeepsValue(inner, /*asUnsigned=*/true)) { + Value src = inner->getOperand(0); + rewriter.replaceOp(indexcastOp, src); return success(); } + + if (auto cst = indexcastOp.getOperand().getDefiningOp()) { + APInt v = cst.getValue().cast().getValue(); + if (indexcastOp.getType().isIndex() && v.getActiveBits() < 64) { + rewriter.replaceOpWithNewOp(indexcastOp, + v.getZExtValue()); + return success(); + } + } return failure(); } }; @@ -962,48 +2023,38 @@ mapOperands); return success(); }; */ -bool isValidIndex(Value val) { +bool isValidIndex(Value val) { return isValidIndexAs(val, false); } + +/// Whether `val`, read as `asUnsigned`, can be raised to an affine expression +/// of induction variables and symbols that keeps its value (see "Exact +/// raising of integer casts and arithmetic"); the normalizer raises exactly +/// what this accepts. +static bool isValidIndexAs(Value val, bool asUnsigned) { if (isValidSymbolInt(val)) return true; - if (auto cast = val.getDefiningOp()) - return isValidIndex(cast.getOperand()); - - if (auto cast = val.getDefiningOp()) - return isValidIndex(cast.getOperand()); - - if (auto cast = val.getDefiningOp()) - return isValidIndex(cast.getOperand()); - - if (auto bop = val.getDefiningOp()) - return isValidIndex(bop.getOperand(0)) && isValidIndex(bop.getOperand(1)); + auto [base, baseUnsigned] = peelExactCasts(val, asUnsigned); + if (base != val) + return isValidIndexAs(base, baseUnsigned); + if (isa_and_nonnull( + val.getDefiningOp())) + return false; // a cast that does not keep the value - if (auto bop = val.getDefiningOp()) - return (isValidIndex(bop.getOperand(0)) && - isValidSymbolInt(bop.getOperand(1))) || - (isValidIndex(bop.getOperand(1)) && - isValidSymbolInt(bop.getOperand(0))); - - if (auto bop = val.getDefiningOp()) - return (isValidIndex(bop.getOperand(0)) && - isValidSymbolInt(bop.getOperand(1))); - - if (auto bop = val.getDefiningOp()) - return (isValidIndex(bop.getOperand(0)) && - isValidSymbolInt(bop.getOperand(1))); - - if (auto bop = val.getDefiningOp()) { - return (isValidIndex(bop.getOperand(0)) && - bop.getOperand(1).getDefiningOp()); + if (Operation *bop = val.getDefiningOp(); isRaisedIntOp(bop)) { + if (!exactArith(bop, asUnsigned)) + return false; + bool ou = operandsUnsigned(bop, asUnsigned); + Value lhs = bop->getOperand(0), rhs = bop->getOperand(1); + if (isa(bop)) + return isValidIndexAs(lhs, ou) && isValidIndexAs(rhs, ou); + if (isa(bop)) + return (isValidIndexAs(lhs, ou) && isValidSymbolInt(rhs)) || + (isValidIndexAs(rhs, ou) && isValidSymbolInt(lhs)); + if (isa(bop)) + return isValidIndexAs(lhs, ou) && isValidSymbolInt(rhs); + return isValidIndexAs(lhs, ou) && rhs.getDefiningOp(); } - if (auto bop = val.getDefiningOp()) - return (isValidIndex(bop.getOperand(0)) && - bop.getOperand(1).getDefiningOp()); - - if (auto bop = val.getDefiningOp()) - return isValidIndex(bop.getOperand(0)) && isValidIndex(bop.getOperand(1)); - if (val.getDefiningOp()) return true; @@ -1299,9 +2350,10 @@ struct MoveStoreToAffine : public OpRewritePattern { fully2ComposeAffineMapAndOperands(rewriter, &map, &operands, DI); affine::canonicalizeMapAndOperands(&map, &operands); - rewriter.create(store.getLoc(), - store.getValueToStore(), - store.getMemRef(), map, operands); + auto newStore = rewriter.create( + store.getLoc(), store.getValueToStore(), store.getMemRef(), map, + operands); + copyHLSMarks(store, newStore); rewriter.eraseOp(store); return success(); } @@ -1372,8 +2424,11 @@ template <> void AffineFixup::replaceAffineOp( PatternRewriter &rewriter, affine::AffineStoreOp store, AffineMap map, ArrayRef mapOperands) const { - rewriter.replaceOpWithNewOp( - store, store.getValueToStore(), store.getMemRef(), map, mapOperands); + auto newStore = rewriter.create( + store.getLoc(), store.getValueToStore(), store.getMemRef(), map, + mapOperands); + copyHLSMarks(store, newStore); + rewriter.replaceOp(store, newStore->getResults()); } template <> void AffineFixup::replaceAffineOp( @@ -1556,7 +2611,7 @@ struct MoveIfToAffine : public OpRewritePattern { void AffineCFGPass::runOnOperation() { mlir::RewritePatternSet rpl(getOperation()->getContext()); rpl.add, AffineFixup, CanonicalizIfBounds, MoveStoreToAffine, MoveIfToAffine, MoveLoadToAffine, diff --git a/lib/polygeist/Passes/AffineScalRep.cpp b/lib/polygeist/Passes/AffineScalRep.cpp new file mode 100644 index 000000000000..e2e238706291 --- /dev/null +++ b/lib/polygeist/Passes/AffineScalRep.cpp @@ -0,0 +1,652 @@ +//===- AffineScalRep.cpp - Affine scalar replacement, non-affine aware ----===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// A copy of MLIR's affine scalar replacement (store-to-load forwarding, +// redundant load elimination and dead store elimination: `affineScalarReplace` +// and its helpers in mlir/lib/Dialect/Affine/Utils/Utils.cpp of the LLVM 18 +// tree this build uses) with one correctness fix. +// +// The upstream check that no write intervenes between the forwarded store (or +// load) and the replaced load uses the affine dependence analysis, which only +// models affine.for / affine.if: every other op holding a region is +// transparent to it. cgeist runs the pass while its loops are still scf.while +// / scf.for (before --raise-scf-to-affine, and for every loop that is never +// raised), so a write that follows the load in the body of such a loop looks +// like straight-line code after the load and is not seen to reach the load in +// the next iteration: `out[0] = 0; for (...) out[0] += a[i];` became a loop +// storing `a[i] + 0` (O23). Here an affine access found between the two ops +// that sits, together with the replaced load, inside a non-affine op whose +// region may run again (or whose regions / blocks may reach one another) and +// that does not enclose the store / load providing the value counts as an +// intervening effect, unless both accesses use indices that are fixed while +// the op runs and differ by a non-zero constant (index operands computed by +// identical side-effect-free ops, such as the separate arith.index_cast cgeist +// emits for every access, count as one value). +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/Affine/Analysis/AffineAnalysis.h" +#include "mlir/Dialect/Affine/Analysis/Utils.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/Affine/IR/AffineValueMap.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/IR/Dominance.h" +#include "mlir/Interfaces/ControlFlowInterfaces.h" +#include "mlir/Interfaces/LoopLikeInterface.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" +#include "mlir/Pass/Pass.h" +#include "polygeist/Passes/Passes.h" +#include "llvm/Support/Debug.h" + +#define DEBUG_TYPE "polygeist-affine-scalrep" + +using namespace mlir; +using namespace mlir::affine; + +namespace { + +/// Returns true if `value` is defined inside `op` (by an op nested in it or as +/// an argument of one of its blocks). +static bool isDefinedInside(Operation *op, Value value) { + Operation *def = value.getDefiningOp(); + if (!def) + def = cast(value).getOwner()->getParentOp(); + return def && op->isAncestor(def); +} + +/// Returns true if `x` and `y` always hold the same value: they are the same +/// SSA value, or the same result of two side-effect-free ops without regions +/// that have the same name, attributes, properties and types and operands that +/// hold the same values (at most `depth` ops deep). cgeist emits a separate +/// arith.index_cast for every access of `o[s]`, and nothing has merged them +/// when the forwarding first runs. An op without operands counts only if it +/// is a constant (two `llvm.mlir.undef` may differ). +static bool holdSameValue(Value x, Value y, unsigned depth = 4) { + if (x == y) + return true; + if (depth == 0 || x.getType() != y.getType()) + return false; + auto rx = dyn_cast(x), ry = dyn_cast(y); + if (!rx || !ry || rx.getResultNumber() != ry.getResultNumber()) + return false; + Operation *ox = rx.getOwner(), *oy = ry.getOwner(); + for (Operation *o : {ox, oy}) + if (o->getNumRegions() != 0 || !isMemoryEffectFree(o) || + (o->getNumOperands() == 0 && !o->hasTrait())) + return false; + return OperationEquivalence::isEquivalentTo( + ox, oy, + [&](Value l, Value r) { + return success(holdSameValue(l, r, depth - 1)); + }, + /*markEquivalent=*/nullptr, OperationEquivalence::IgnoreLocations); +} + +/// Returns true if the affine accesses `a` and `b` touch different elements +/// whenever they execute within one execution of `scope`: scalar accesses of +/// the same memref with the identity layout, every index operand defined +/// outside `scope` (so fixed while it runs) and access functions that differ +/// by a non-zero constant in some dimension. +static bool accessesDisjointWithin(Operation *scope, Operation *a, + Operation *b) { + // A vector access covers several elements from its index on. + if (isa(a) || + isa(b)) + return false; + MemRefAccess accA(a), accB(b); + if (accA.memref != accB.memref) + return false; + // Distinct indices are distinct elements only for an injective layout. + if (!cast(accA.memref.getType()).getLayout().isIdentity()) + return false; + AffineValueMap mapA, mapB, diff; + accA.getAccessMap(&mapA); + accB.getAccessMap(&mapB); + for (Value v : mapA.getOperands()) + if (isDefinedInside(scope, v)) + return false; + for (Value v : mapB.getOperands()) + if (isDefinedInside(scope, v)) + return false; + if (mapA.getNumResults() != mapB.getNumResults()) + return false; + // Give operands of `b` that hold the same value as an operand of `a` that + // operand, so the difference below cancels them. + SmallVector operandsB(mapB.getOperands()); + for (Value &vb : operandsB) + for (Value va : mapA.getOperands()) + if (holdSameValue(va, vb)) { + vb = va; + break; + } + mapB.reset(mapB.getAffineMap(), operandsB); + AffineValueMap::difference(mapA, mapB, &diff); + for (AffineExpr e : diff.getAffineMap().getResults()) + if (auto c = e.dyn_cast()) + if (c.getValue() != 0) + return true; + return false; +} + +/// Returns the region of `op` that contains `nested`. +static Region *getRegionContaining(Operation *op, Operation *nested) { + for (Region &r : op->getRegions()) + if (r.findAncestorOpInRegion(*nested)) + return &r; + return nullptr; +} + +/// The affine dependence analysis (`mayHaveEffect`) treats ops other than +/// affine.for / affine.if as transparent. Returns true if the affine access +/// `accessOp`, found while checking the ops between `start` and `memOp`, may +/// execute after `start` and before `memOp` through such an op: one that +/// encloses `accessOp` and `memOp` but not `start` (an op that encloses +/// `start` as well re-executes `start` before `memOp`) and whose region +/// holding `memOp` may run again after `accessOp` (a loop, or an op that does +/// not describe its control flow), or that holds the two in different regions +/// that may reach one another, or in different blocks of one region. Program +/// order inside one block of a region that runs at most once per execution of +/// the op is what the analysis models correctly. +static bool mayReachThroughNonAffineOp(Operation *start, Operation *memOp, + Operation *accessOp) { + for (Operation *x = memOp->getParentOp(); x && !x->isAncestor(start); + x = x->getParentOp()) { + if (!x->isProperAncestor(accessOp)) + continue; + if (isa(x)) + continue; + Region *memRegion = getRegionContaining(x, memOp); + Region *accRegion = getRegionContaining(x, accessOp); + if (!memRegion || !accRegion) + return true; + bool repeats = true; + auto branch = dyn_cast(x); + if (branch && !isa(x)) + repeats = branch.isRepetitiveRegion(memRegion->getRegionNumber()); + if (!repeats) { + if (memRegion == accRegion) { + if (memRegion->findAncestorBlockInRegion(*memOp->getBlock()) == + memRegion->findAncestorBlockInRegion(*accessOp->getBlock())) + continue; + } else if (insideMutuallyExclusiveRegions(accessOp, memOp)) { + continue; + } + } + if (accessesDisjointWithin(x, accessOp, memOp)) + continue; + LLVM_DEBUG(llvm::dbgs() << "intervening through " << x->getName() << ": " + << *accessOp << "\n"); + return true; + } + return false; +} + +/// Returns true if the memory operation of `destAccess` depends on `srcAccess` +/// inside of the innermost common surrounding affine loop between the two +/// accesses. +static bool mustReachAtInnermost(const MemRefAccess &srcAccess, + const MemRefAccess &destAccess) { + // Affine dependence analysis is possible only if both ops in the same + // AffineScope. + if (getAffineScope(srcAccess.opInst) != getAffineScope(destAccess.opInst)) + return false; + + unsigned nsLoops = + getNumCommonSurroundingLoops(*srcAccess.opInst, *destAccess.opInst); + DependenceResult result = + checkMemrefAccessDependence(srcAccess, destAccess, nsLoops + 1); + return hasDependence(result); +} + +/// Returns true if `srcMemOp` may have an effect on `destMemOp` within the +/// scope of the outermost `minSurroundingLoops` loops that surround them. +/// `srcMemOp` and `destMemOp` are expected to be affine read/write ops. +static bool mayHaveEffect(Operation *srcMemOp, Operation *destMemOp, + unsigned minSurroundingLoops) { + MemRefAccess srcAccess(srcMemOp); + MemRefAccess destAccess(destMemOp); + + // Affine dependence analysis here is applicable only if both ops operate on + // the same memref and if `srcMemOp` and `destMemOp` are in the same + // AffineScope. Also, we can only check if our affine scope is isolated from + // above; otherwise, values can from outside of the affine scope that the + // check below cannot analyze. + Region *srcScope = getAffineScope(srcMemOp); + if (srcAccess.memref == destAccess.memref && + srcScope == getAffineScope(destMemOp)) { + unsigned nsLoops = getNumCommonSurroundingLoops(*srcMemOp, *destMemOp); + FlatAffineValueConstraints dependenceConstraints; + for (unsigned d = nsLoops + 1; d > minSurroundingLoops; d--) { + DependenceResult result = checkMemrefAccessDependence( + srcAccess, destAccess, d, &dependenceConstraints, + /*dependenceComponents=*/nullptr); + // A dependence failure or the presence of a dependence implies a + // side effect. + if (!noDependence(result)) + return true; + } + // No side effect was seen. + return false; + } + // TODO: Check here if the memrefs alias: there is no side effect if + // `srcAccess.memref` and `destAccess.memref` don't alias. + return true; +} + +/// Returns true if no operation that may have the effect `EffectType` on the +/// location `memOp` accesses can execute after `start` and before `memOp`. +template +static bool hasNoInterveningEffect(Operation *start, T memOp) { + auto isLocallyAllocated = [](Value memref) { + auto *defOp = memref.getDefiningOp(); + return defOp && hasSingleEffect(defOp, memref); + }; + + // A boolean representing whether an intervening operation could have impacted + // memOp. + bool hasSideEffect = false; + + // Check whether the effect on memOp can be caused by a given operation op. + Value memref = memOp.getMemRef(); + std::function checkOperation = [&](Operation *op) { + // If the effect has alreay been found, early exit, + if (hasSideEffect) + return; + + if (auto memEffect = dyn_cast(op)) { + SmallVector effects; + memEffect.getEffects(effects); + + bool opMayHaveEffect = false; + for (auto effect : effects) { + // If op causes EffectType on a potentially aliasing location for + // memOp, mark as having the effect. + if (isa(effect.getEffect())) { + // TODO: This should be replaced with a check for no aliasing. + // Aliasing information should be passed to this method. + if (effect.getValue() && effect.getValue() != memref && + isLocallyAllocated(memref) && + isLocallyAllocated(effect.getValue())) + continue; + opMayHaveEffect = true; + break; + } + } + + if (!opMayHaveEffect) + return; + + // If the side effect comes from an affine read or write, try to + // prove the side effecting `op` cannot reach `memOp`. + if (isa(op)) { + // Polygeist: the dependence analysis below cannot see a path through + // a non-affine loop (O23). + if (mayReachThroughNonAffineOp(start, memOp, op)) { + hasSideEffect = true; + return; + } + // For ease, let's consider the case that `op` is a store and + // we're looking for other potential stores that overwrite memory after + // `start`, and before being read in `memOp`. In this case, we only + // need to consider other potential stores with depth > + // minSurroundingLoops since `start` would overwrite any store with a + // smaller number of surrounding loops before. + unsigned minSurroundingLoops = + getNumCommonSurroundingLoops(*start, *memOp); + if (mayHaveEffect(op, memOp, minSurroundingLoops)) + hasSideEffect = true; + return; + } + + // We have an op with a memory effect and we cannot prove if it + // intervenes. + hasSideEffect = true; + return; + } + + if (op->hasTrait()) { + // Recurse into the regions for this op and check whether the internal + // operations may have the side effect `EffectType` on memOp. + for (Region ®ion : op->getRegions()) + for (Block &block : region) + for (Operation &op : block) + checkOperation(&op); + return; + } + + // Otherwise, conservatively assume generic operations have the effect + // on the operation + hasSideEffect = true; + }; + + // Check all paths from ancestor op `parent` to the operation `to` for the + // effect. It is known that `to` must be contained within `parent`. + auto until = [&](Operation *parent, Operation *to) { + // TODO check only the paths from `parent` to `to`. + // Currently we fallback and check the entire parent op, rather than + // just the paths from the parent path, stopping after reaching `to`. + // This is conservatively correct, but could be made more aggressive. + assert(parent->isAncestor(to)); + checkOperation(parent); + }; + + // Check for all paths from operation `from` to operation `untilOp` for the + // given memory effect. + std::function recur = + [&](Operation *from, Operation *untilOp) { + assert( + from->getParentRegion()->isAncestor(untilOp->getParentRegion()) && + "Checking for side effect between two operations without a common " + "ancestor"); + + // If the operations are in different regions, recursively consider all + // path from `from` to the parent of `to` and all paths from the parent + // of `to` to `to`. + if (from->getParentRegion() != untilOp->getParentRegion()) { + recur(from, untilOp->getParentOp()); + until(untilOp->getParentOp(), untilOp); + return; + } + + // Now, assuming that `from` and `to` exist in the same region, perform + // a CFG traversal to check all the relevant operations. + + // Additional blocks to consider. + SmallVector todoBlocks; + { + // First consider the parent block of `from` an check all operations + // after `from`. + for (auto iter = ++from->getIterator(), end = from->getBlock()->end(); + iter != end && &*iter != untilOp; ++iter) { + checkOperation(&*iter); + } + + // If the parent of `from` doesn't contain `to`, add the successors + // to the list of blocks to check. + if (untilOp->getBlock() != from->getBlock()) + for (Block *succ : from->getBlock()->getSuccessors()) + todoBlocks.push_back(succ); + } + + SmallPtrSet done; + // Traverse the CFG until hitting `to`. + while (!todoBlocks.empty()) { + Block *blk = todoBlocks.pop_back_val(); + if (done.count(blk)) + continue; + done.insert(blk); + for (auto &op : *blk) { + if (&op == untilOp) + break; + checkOperation(&op); + if (&op == blk->getTerminator()) + for (Block *succ : blk->getSuccessors()) + todoBlocks.push_back(succ); + } + } + }; + recur(start, memOp); + return !hasSideEffect; +} + +/// Attempt to eliminate loadOp by replacing it with a value stored into memory +/// which the load is guaranteed to retrieve. This check involves three +/// components: 1) The store and load must be on the same location 2) The store +/// must dominate (and therefore must always occur prior to) the load 3) No +/// other operations will overwrite the memory loaded between the given load +/// and store. If such a value exists, the replaced `loadOp` will be added to +/// `loadOpsToErase` and its memref will be added to `memrefsToErase`. +static void forwardStoreToLoad(AffineReadOpInterface loadOp, + SmallVectorImpl &loadOpsToErase, + SmallPtrSetImpl &memrefsToErase, + DominanceInfo &domInfo) { + + // The store op candidate for forwarding that satisfies all conditions + // to replace the load, if any. + Operation *lastWriteStoreOp = nullptr; + + for (auto *user : loadOp.getMemRef().getUsers()) { + auto storeOp = dyn_cast(user); + if (!storeOp) + continue; + MemRefAccess srcAccess(storeOp); + MemRefAccess destAccess(loadOp); + + // 1. Check if the store and the load have mathematically equivalent + // affine access functions; this implies that they statically refer to the + // same single memref element. As an example this filters out cases like: + // store %A[%i0 + 1] + // load %A[%i0] + // store %A[%M] + // load %A[%N] + // Use the AffineValueMap difference based memref access equality checking. + if (srcAccess != destAccess) + continue; + + // 2. The store has to dominate the load op to be candidate. + if (!domInfo.dominates(storeOp, loadOp)) + continue; + + // 3. The store must reach the load. Access function equivalence only + // guarantees this for accesses in the same block. The load could be in a + // nested block that is unreachable. + if (storeOp->getBlock() != loadOp->getBlock() && + !mustReachAtInnermost(srcAccess, destAccess)) + continue; + + // 4. Ensure there is no intermediate operation which could replace the + // value in memory. + if (!hasNoInterveningEffect(storeOp, loadOp)) + continue; + + // We now have a candidate for forwarding. + assert(lastWriteStoreOp == nullptr && + "multiple simultaneous replacement stores"); + lastWriteStoreOp = storeOp; + } + + if (!lastWriteStoreOp) + return; + + // Perform the actual store to load forwarding. + Value storeVal = + cast(lastWriteStoreOp).getValueToStore(); + // Check if 2 values have the same shape. This is needed for affine vector + // loads and stores. + if (storeVal.getType() != loadOp.getValue().getType()) + return; + loadOp.getValue().replaceAllUsesWith(storeVal); + // Record the memref for a later sweep to optimize away. + memrefsToErase.insert(loadOp.getMemRef()); + // Record this to erase later. + loadOpsToErase.push_back(loadOp); +} + +// This attempts to find stores which have no impact on the final result. +// A writing op writeA will be eliminated if there exists an op writeB if +// 1) writeA and writeB have mathematically equivalent affine access functions. +// 2) writeB postdominates writeA. +// 3) There is no potential read between writeA and writeB. +static void findUnusedStore(AffineWriteOpInterface writeA, + SmallVectorImpl &opsToErase, + PostDominanceInfo &postDominanceInfo) { + + for (Operation *user : writeA.getMemRef().getUsers()) { + // Only consider writing operations. + auto writeB = dyn_cast(user); + if (!writeB) + continue; + + // The operations must be distinct. + if (writeB == writeA) + continue; + + // Both operations must lie in the same region. + if (writeB->getParentRegion() != writeA->getParentRegion()) + continue; + + // Both operations must write to the same memory. + MemRefAccess srcAccess(writeB); + MemRefAccess destAccess(writeA); + + if (srcAccess != destAccess) + continue; + + // writeB must postdominate writeA. + if (!postDominanceInfo.postDominates(writeB, writeA)) + continue; + + // There cannot be an operation which reads from memory between + // the two writes. + if (!hasNoInterveningEffect(writeA, writeB)) + continue; + + opsToErase.push_back(writeA); + break; + } +} + +// The load to load forwarding / redundant load elimination is similar to the +// store to load forwarding. +// loadA will be be replaced with loadB if: +// 1) loadA and loadB have mathematically equivalent affine access functions. +// 2) loadB dominates loadA. +// 3) There is no write between loadA and loadB. +static void loadCSE(AffineReadOpInterface loadA, + SmallVectorImpl &loadOpsToErase, + DominanceInfo &domInfo) { + SmallVector loadCandidates; + for (auto *user : loadA.getMemRef().getUsers()) { + auto loadB = dyn_cast(user); + if (!loadB || loadB == loadA) + continue; + + MemRefAccess srcAccess(loadB); + MemRefAccess destAccess(loadA); + + // 1. The accesses should be to be to the same location. + if (srcAccess != destAccess) { + continue; + } + + // 2. loadB should dominate loadA. + if (!domInfo.dominates(loadB, loadA)) + continue; + + // 3. There should not be a write between loadA and loadB. + if (!hasNoInterveningEffect(loadB.getOperation(), + loadA)) + continue; + + // Check if two values have the same shape. This is needed for affine vector + // loads. + if (loadB.getValue().getType() != loadA.getValue().getType()) + continue; + + loadCandidates.push_back(loadB); + } + + // Of the legal load candidates, use the one that dominates all others + // to minimize the subsequent need to loadCSE + Value loadB; + for (AffineReadOpInterface option : loadCandidates) { + if (llvm::all_of(loadCandidates, [&](AffineReadOpInterface depStore) { + return depStore == option || + domInfo.dominates(option.getOperation(), + depStore.getOperation()); + })) { + loadB = option.getValue(); + break; + } + } + + if (loadB) { + loadA.getValue().replaceAllUsesWith(loadB); + // Record this to erase later. + loadOpsToErase.push_back(loadA); + } +} + +/// Upstream `affine::affineScalarReplace` with the checks above. +static void affineScalarReplace(func::FuncOp f, DominanceInfo &domInfo, + PostDominanceInfo &postDomInfo) { + // Load op's whose results were replaced by those forwarded from stores. + SmallVector opsToErase; + + // A list of memref's that are potentially dead / could be eliminated. + SmallPtrSet memrefsToErase; + + // Walk all load's and perform store to load forwarding. + f.walk([&](AffineReadOpInterface loadOp) { + forwardStoreToLoad(loadOp, opsToErase, memrefsToErase, domInfo); + }); + for (auto *op : opsToErase) + op->erase(); + opsToErase.clear(); + + // Walk all store's and perform unused store elimination + f.walk([&](AffineWriteOpInterface storeOp) { + findUnusedStore(storeOp, opsToErase, postDomInfo); + }); + for (auto *op : opsToErase) + op->erase(); + opsToErase.clear(); + + // Check if the store fwd'ed memrefs are now left with only stores and + // deallocs and can thus be completely deleted. Note: the canonicalize pass + // should be able to do this as well, but we'll do it here since we collected + // these anyway. + for (auto memref : memrefsToErase) { + // If the memref hasn't been locally alloc'ed, skip. + Operation *defOp = memref.getDefiningOp(); + if (!defOp || !hasSingleEffect(defOp, memref)) + // TODO: if the memref was returned by a 'call' operation, we + // could still erase it if the call had no side-effects. + continue; + if (llvm::any_of(memref.getUsers(), [&](Operation *ownerOp) { + return !isa(ownerOp) && + !hasSingleEffect(ownerOp, memref); + })) + continue; + + // Erase all stores, the dealloc, and the alloc on the memref. + for (auto *user : llvm::make_early_inc_range(memref.getUsers())) + user->erase(); + defOp->erase(); + } + + // To eliminate as many loads as possible, run load CSE after eliminating + // stores. Otherwise, some stores are wrongly seen as having an intervening + // effect. + f.walk([&](AffineReadOpInterface loadOp) { + loadCSE(loadOp, opsToErase, domInfo); + }); + for (auto *op : opsToErase) + op->erase(); +} + +struct PolygeistAffineScalarReplacement + : public PassWrapper> { + MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(PolygeistAffineScalarReplacement) + StringRef getArgument() const final { return "polygeist-affine-scalrep"; } + StringRef getDescription() const final { + return "affine-scalrep that sees writes through non-affine loops"; + } + void runOnOperation() override { + affineScalarReplace(getOperation(), getAnalysis(), + getAnalysis()); + } +}; + +} // namespace + +std::unique_ptr +mlir::polygeist::createPolygeistAffineScalarReplacementPass() { + return std::make_unique(); +} diff --git a/lib/polygeist/Passes/CMakeLists.txt b/lib/polygeist/Passes/CMakeLists.txt index c385d548a428..5beee06b0e8c 100644 --- a/lib/polygeist/Passes/CMakeLists.txt +++ b/lib/polygeist/Passes/CMakeLists.txt @@ -1,6 +1,7 @@ add_mlir_dialect_library(MLIRPolygeistTransforms ConvertToOpaquePtr.cpp AffineCFG.cpp + AffineScalRep.cpp PolyhedralOpt.cpp AffineReduction.cpp CanonicalizeFor.cpp diff --git a/lib/polygeist/Passes/CanonicalizeFor.cpp b/lib/polygeist/Passes/CanonicalizeFor.cpp index d04487d4689f..a124d614095e 100644 --- a/lib/polygeist/Passes/CanonicalizeFor.cpp +++ b/lib/polygeist/Passes/CanonicalizeFor.cpp @@ -2,14 +2,20 @@ #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/SCF/Transforms/Passes.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" +#include "mlir/Interfaces/CallInterfaces.h" +#include "mlir/Interfaces/FunctionInterfaces.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "polygeist/Passes/Passes.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/CommandLine.h" using namespace mlir; using namespace mlir::scf; @@ -94,6 +100,30 @@ struct PropagateInLoopBody : public OpRewritePattern { // yield %r#0, %a2 // } // no use of %f#1 +// +// Picking the "continue" value changes what the for carries in %a after the +// iteration that clears %c. That is unobservable only when %f#1 is unused +// and %a itself is read nowhere but inside the `then` region of the guard +// (which never runs again once %c is false) and in its own slot of the +// `else` yield. Only that one yield slot is rewritten: the same inner value +// may also feed another slot, e.g. the copy of the counter whose result is +// used, that MoveWhileToFor creates next to the unused one. Rewriting the +// inner if's result for every user made `for (i = 0; i < n; i++) if (..) +// { ..; break; }` leave i one too high after the break (W8b review). +static bool carriedOnlyUnderGuard(BlockArgument regionArg, scf::IfOp guard, + unsigned slot) { + for (OpOperand &use : regionArg.getUses()) { + Operation *user = use.getOwner(); + if (guard.getThenRegion().isAncestor(user->getParentRegion())) + continue; + if (user == guard.elseYield().getOperation() && + use.getOperandNumber() == slot) + continue; + return false; + } + return true; +} + struct ForBreakAddUpgrade : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; @@ -169,7 +199,9 @@ struct ForBreakAddUpgrade : public OpRewritePattern { if (ifcond == trueYield) { // If never used, can always pick the "continue" value - if (res.use_empty()) { + if (res.use_empty() && + carriedOnlyUnderGuard(regionArg, outerIfOp, + opres2.getResultNumber())) { auto idx = topOp.cast().getResultNumber(); Value val = (negated ? innerIfOp.elseYield() : innerIfOp.thenYield()) @@ -188,11 +220,10 @@ struct ForBreakAddUpgrade : public OpRewritePattern { continue; } - rewriter.setInsertionPoint(innerIfOp); - auto cloned = rewriter.clone(*innerIfOp); - SmallVector results(cloned->getResults()); - results[idx] = val; - rewriter.replaceOp(innerIfOp, results); + scf::YieldOp thenYield = outerIfOp.thenYield(); + rewriter.updateRootInPlace(thenYield, [&] { + thenYield->setOperand(opres2.getResultNumber(), val); + }); changed = true; continue; } @@ -209,11 +240,15 @@ struct ForBreakAddUpgrade : public OpRewritePattern { } if (ifcond == trueYield) { // If never used, can always pick the "continue" value - if (res.use_empty()) { + if (res.use_empty() && + carriedOnlyUnderGuard(regionArg, outerIfOp, + opres2.getResultNumber())) { Value val = (negated ? innerSelOp.getFalseValue() : innerSelOp.getTrueValue()); - Value results[] = {val}; - rewriter.replaceOp(innerSelOp, results); + scf::YieldOp thenYield = outerIfOp.thenYield(); + rewriter.updateRootInPlace(thenYield, [&] { + thenYield->setOperand(opres2.getResultNumber(), val); + }); changed = true; continue; } @@ -252,7 +287,9 @@ struct ForBreakAddUpgrade : public OpRewritePattern { // Only do final hoisting on a variable which can be loop induction // replaced. // Otherwise additional work is added outside the break - if (res.use_empty()) { + if (res.use_empty() && + carriedOnlyUnderGuard(regionArg, outerIfOp, + opres2.getResultNumber())) { if (auto add = topOp.getDefiningOp()) { if (forOp.getRegion().isAncestor(add.getOperand(1).getParentRegion())) continue; @@ -274,14 +311,359 @@ struct ForBreakAddUpgrade : public OpRewritePattern { } }; +/// Integer values of up to 64 bits, signed or unsigned, and sums and small +/// products of them. +using WideInt = __int128; + +/// Width of an integer or index type (index: 64, the width the index casts +/// and the affine maps compute in); 0 for any other type. +static unsigned intWidth(Type t) { + if (t.isa()) + return 64; + if (auto it = t.dyn_cast()) + return it.getWidth(); + return 0; +} + +/// Smallest / largest value of a `width`-bit integer read as unsigned or +/// signed. +static WideInt viewMin(unsigned width, bool asUnsigned) { + return asUnsigned ? 0 : -((WideInt)1 << (width - 1)); +} +static WideInt viewMax(unsigned width, bool asUnsigned) { + return asUnsigned ? ((WideInt)1 << width) - 1 + : ((WideInt)1 << (width - 1)) - 1; +} + +/// The value of the integer constant `v` read as unsigned or signed. +static std::optional constantValue(Value v, bool asUnsigned) { + APInt c; + if (!matchPattern(v, m_ConstantInt(&c)) || c.getBitWidth() > 64) + return std::nullopt; + return asUnsigned ? (WideInt)c.getZExtValue() : (WideInt)c.getSExtValue(); +} + +/// The range of values the integer `v` can hold, read as unsigned or signed, +/// as far as its definition shows it: a constant is itself, extui(x) holds +/// x's unsigned range, extsi(x) x's signed range when read as signed; +/// anything else the whole range of its type. +static std::pair valueRange(Value v, bool asUnsigned) { + if (auto c = constantValue(v, asUnsigned)) + return {*c, *c}; + if (auto ext = v.getDefiningOp()) + return {0, viewMax(intWidth(ext.getIn().getType()), true)}; + if (auto ext = v.getDefiningOp()) + if (!asUnsigned) { + unsigned w = intWidth(ext.getIn().getType()); + return {viewMin(w, false), viewMax(w, false)}; + } + unsigned w = intWidth(v.getType()); + return {viewMin(w, asUnsigned), viewMax(w, asUnsigned)}; +} + +/// The range of the index value `v` when its definition bounds it: a +/// constant, an index_cast / index_castui of an integer (valueRange), or the +/// sum of two such values. +static std::optional> indexRange(Value v) { + if (auto c = constantValue(v, /*asUnsigned=*/false)) + return std::make_pair(*c, *c); + if (auto cast = v.getDefiningOp()) + if (intWidth(cast.getIn().getType()) <= 64) + return valueRange(cast.getIn(), /*asUnsigned=*/false); + if (auto cast = v.getDefiningOp()) + if (intWidth(cast.getIn().getType()) <= 64) + return valueRange(cast.getIn(), /*asUnsigned=*/true); + if (auto add = v.getDefiningOp()) { + auto a = indexRange(add.getLhs()), b = indexRange(add.getRhs()); + if (a && b) + return std::make_pair(a->first + b->first, a->second + b->second); + } + return std::nullopt; +} + +/// Width of C `int` on the targets cgeist compiles for: a signed counter +/// narrower than it is incremented in int and converted back. +static constexpr unsigned kCIntWidth = 32; + +// A while loop over a counter narrower than int whose range check +// (WhileToForHelper::counterStaysInRange) cannot show that the counter stays +// in range, because its bound is a runtime value that may lie beyond it +// (`for (uint8_t i = 0; i < n; i++)` with int n, which never ends for +// n > 255) or because a narrow bound lets a power-of-two step overshoot it +// (`for (uint8_t i = 0; i < m; i += 2)`, uint8_t m, which never ends for +// m = 255), is raised to a for loop by assuming that it terminates. C11 +// 6.8.5p6 and C++ [intro.progress] let an implementation assume that a loop +// whose controlling expression is not a constant expression terminates when +// it performs no input / output, no volatile access and no synchronisation or +// atomic operation; here that is a body without calls to functions cgeist +// cannot see into, atomics, fences, barriers or volatile LLVM loads and +// stores, in a function the frontend did not mark polygeist.volatile_access +// and calling no function so marked (cgeist does not represent C volatile on +// memref accesses; the frontend marks each function whose body accesses a +// volatile-qualified object, and inlining carries the mark to the caller, +// Passes.h). Such a loop terminates only +// if its counter never wraps: counting by +-2^k with a test read with the +// counter's own signedness, a wrap returns the counter to values the test +// has already accepted, so a loop that wrapped never ends. The raised loop is +// marked polygeist.counter_nowrap and the casts of its counter +// polygeist.nuw / polygeist.nsw (Passes.h), so that AffineCFG reads them as +// the induction variable; a loop whose bound is of a wider type than its +// counter is marked hls.uncounted as well. Not applied to a constant bound +// (the range check is exact there: such a loop never ends), to other steps +// (a wrap can be followed by a different residue that ends the loop) or to a +// signed counter compared unsigned (a negative value ends the loop). Vitis +// HLS pipelines such loops as it does the `int` ones (hls-est-validate +// VITIS_NOTES.md N15). +static llvm::cl::opt AssumeTermination( + "canonicalize-for-assume-termination", llvm::cl::init(true), + llvm::cl::Hidden, + llvm::cl::desc( + "Raise a while loop whose counter (narrower than int) is not " + "provably kept in range by its runtime bound to a for loop by " + "assuming that the loop terminates, so that the counter does not " + "wrap (C11 6.8.5p6); false keeps such loops as while loops")); + +/// Whether `root` holds an operation that makes running forever observable +/// (see AssumeTermination): a call to a function without a visible body (the +/// bodies of visible callees are searched in turn), an atomic operation, a +/// fence, a barrier, a volatile LLVM load / store, or a call to a function +/// marked polygeist.volatile_access. The mark on the function enclosing the +/// loop is checked by the caller (terminationImpliesNoWrap). +static bool mayDoObservableWork(Operation *root, + SmallPtrSetImpl &visited) { + WalkResult r = root->walk([&](Operation *op) { + if (isa(op) && + op->hasAttr(polygeist::kVolatileAccessAttrName)) + return WalkResult::interrupt(); + if (isa(op)) + return WalkResult::interrupt(); + if (auto ld = dyn_cast(op); ld && ld.getVolatile_()) + return WalkResult::interrupt(); + if (auto st = dyn_cast(op); st && st.getVolatile_()) + return WalkResult::interrupt(); + if (auto call = dyn_cast(op)) { + auto callee = + dyn_cast_or_null(call.resolveCallable()); + if (!callee || callee.isExternal()) + return WalkResult::interrupt(); + if (visited.insert(callee.getOperation()).second && + mayDoObservableWork(callee.getOperation(), visited)) + return WalkResult::interrupt(); + } + return WalkResult::advance(); + }); + return r.wasInterrupted(); +} + +/// ceil(a / b) for b > 0. +static WideInt ceilDivWide(WideInt a, WideInt b) { + WideInt q = a / b; + return (a % b != 0 && a > 0) ? q + 1 : q; +} + struct ForOpInductionReplacement : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; + /// The signedness of the index cast `v` is of `init`, if it is one. + static std::optional castOf(Value v, Value init) { + if (auto c = v.getDefiningOp()) + if (c.getIn() == init) + return true; + if (auto c = v.getDefiningOp()) + if (c.getIn() == init) + return false; + return std::nullopt; + } + + /// The signedness with which `bound` (a bound of the for) was cast from + /// `init`, possibly plus a constant (a countdown's init + 1): the signedness + /// MoveWhileToFor counted the loop's counter with. Only the choice of cast + /// for a counter as wide as int uses it, for any counter starting at `init`. + static std::optional boundCastOf(Value bound, Value init) { + if (auto add = bound.getDefiningOp()) + if (matchPattern(add.getRhs(), m_Constant())) + bound = add.getLhs(); + return castOf(bound, init); + } + + /// The counter's own signedness, when its values are those of the counter + /// MoveWhileToFor raised the for from, which counterStaysInRange kept in + /// that range: it starts at the lower bound, cast from `init`, and steps + /// with the loop (`sameValue`), or, counting down, the upper bound is that + /// cast plus one and it steps by minus the loop's step. Another counter + /// with the same start value (the same SSA value: a CSE'd constant, a + /// shared runtime start) but another step is not: `for (uint8_t i = 0, + /// j = 0; i < 10; i++, j += 30)` takes j to 270, which wraps. + static std::optional ownCastOf(scf::ForOp forOp, Value init, + bool sameValue, Value addStep) { + if (sameValue) + return castOf(forOp.getLowerBound(), init); + std::optional step = constantValue(forOp.getStep(), false); + std::optional inc = constantValue(addStep, false); + if (!step || !inc || *inc != -*step) + return std::nullopt; + auto add = forOp.getUpperBound().getDefiningOp(); + if (!add || !matchPattern(add.getRhs(), m_One())) + return std::nullopt; + return castOf(add.getLhs(), init); + } + + /// The loop's own counter in a loop MoveWhileToFor raised by assuming that + /// it terminates (polygeist.counter_nowrap, whose value is the signedness + /// its exit test reads the counter with): the signedness that ownCastOf + /// gives, or, once the start's cast to the bound has been folded to a + /// constant, the mark's for a constant start that is, read that way, the + /// lower bound (counting up with the loop's step) or the upper bound minus + /// one (counting down by it). Any counter with those values never wraps + /// in such a loop. std::nullopt for other counters and loops. + static std::optional assumedOwnCastOf(scf::ForOp forOp, Value init, + bool sameValue, Value addStep) { + auto mark = forOp->getAttrOfType(kCounterNoWrapAttrName); + if (!mark) + return std::nullopt; + bool view = mark.getValue(); + std::optional own = ownCastOf(forOp, init, sameValue, addStep); + if (own) + return *own == view ? own : std::nullopt; + std::optional start = constantValue(init, view); + if (!start) + return std::nullopt; + if (sameValue) { + std::optional lb = constantValue(forOp.getLowerBound(), false); + return lb && *lb == *start ? std::optional(view) : std::nullopt; + } + std::optional step = constantValue(forOp.getStep(), false); + std::optional inc = constantValue(addStep, false); + if (!step || !inc || *inc != -*step) + return std::nullopt; + std::optional ub = constantValue(forOp.getUpperBound(), false); + return ub && *ub == *start + 1 ? std::optional(view) : std::nullopt; + } + + /// How to cast the iN start `init` of the counter `like` (an iter_arg of + /// the for, or with `atExit` its result) to index; true is index_castui. + /// The counter is replaced by index_cast(X -> iN), X = start + k * inc in + /// index, and the folds downstream (AffineCFG's cast stripping, the + /// index_cast(index_cast) / index_castui(index_cast) round trips) read each + /// extui / extsi / index_cast* of it back as X. That is exact only while X + /// stays in the range of every view the counter is read with: [0, 2^N) + /// through extui / index_castui, [-2^(N-1), 2^(N-1)) through extsi / + /// index_cast. A call it is passed to is both views: after inlining, the + /// callee's parameter reads it with the callee's signedness, which the + /// upstream index_cast(index_cast) fold does not check. For a counter + /// narrower than int (its values cross 2^(N-1) in ordinary loops: a + /// uint8_t over 120..135) a cast is taken when + /// - every view is the counter's own signedness and its values are those + /// of the loop's own counter (ownCastOf): X is then the counter's + /// value, which never leaves that range (counterStaysInRange); + /// - or the range of X, from the bounds, steps and start as far as their + /// definitions show them, lies in every view. + /// std::nullopt when neither holds (e.g. a uint8_t counter read as + /// `(int8_t)i` while it runs over 120..135, or as both `i` and `(int8_t)i` + /// over 200..209): the counter then stays an iter_arg, whose own iN + /// arithmetic is exact. A counter as wide as int is assumed to stay below + /// 2^31 as before, and takes its own signedness when the bounds show it + /// (`int jj < unsigned row_end`: the for counts from index_castui(start), + /// so X is the induction variable), else the users' view. + static std::optional chooseInitCast(scf::ForOp forOp, Value init, + Value like, bool sameValue, + Value addStep, bool atExit) { + bool hasUnsigned = false, hasSigned = false; + for (Operation *u : like.getUsers()) { + if (isa(u)) + hasUnsigned = true; + else if (isa(u)) + hasSigned = true; + else if (isa(u)) + hasUnsigned = hasSigned = true; + } + bool usersView = hasUnsigned && !hasSigned; + unsigned w = intWidth(init.getType()); + // A counter as wide as int, or one no extension reads: its own + // signedness when the bounds show it (X is then the induction variable + // itself), else the users' view (a signed one when they disagree). + if (w >= kCIntWidth || (!hasUnsigned && !hasSigned)) { + std::optional own = boundCastOf(forOp.getLowerBound(), init); + if (!own) + own = boundCastOf(forOp.getUpperBound(), init); + return own ? *own : usersView; + } + std::optional own = ownCastOf(forOp, init, sameValue, addStep); + if (!own) + own = assumedOwnCastOf(forOp, init, sameValue, addStep); + if (own && (hasUnsigned ? *own : !*own) && !(hasUnsigned && hasSigned)) + return *own; + + auto lbR = indexRange(forOp.getLowerBound()); + auto ubR = indexRange(forOp.getUpperBound()); + auto stR = indexRange(forOp.getStep()); + if (!lbR || !ubR || !stR || stR->first <= 0) + return std::nullopt; + // X = start + d, d in [dLo, dHi]. + WideInt dLo = 0, dHi = 0; + WideInt incLo = 1, incHi = 1; + if (!sameValue) { + if (auto c = constantValue(addStep, /*asUnsigned=*/false)) { + incLo = incHi = *c; + } else { + incLo = viewMin(intWidth(addStep.getType()), false); + incHi = viewMax(intWidth(addStep.getType()), false); + } + } + if (!atExit) { + if (ubR->second <= lbR->first) // the body never runs: any cast + return usersView; + // iv - lb in [0, span]; with !sameValue, k = (iv - lb) / step. + WideInt span = ubR->second - 1 - lbR->first; + WideInt kHi = sameValue ? span : span / stR->first; + dLo = std::min(0, kHi * incLo); + dHi = std::max(0, kHi * incHi); + } else { + // trips steps of inc (of the loop's step with sameValue), trips = + // max(0, ceil((ub - lb) / step)) as the exit value is computed. + WideInt tLo = std::max( + 0, ceilDivWide(ubR->first - lbR->second, stR->second)); + WideInt tHi = std::max( + 0, ceilDivWide(ubR->second - lbR->first, stR->first)); + if (sameValue) { + incLo = stR->first; + incHi = stR->second; + } + const WideInt big = (WideInt)1 << 62; + if (tHi > big || incHi > big || incLo < -big) + return std::nullopt; + WideInt c[4] = {tLo * incLo, tLo * incHi, tHi * incLo, tHi * incHi}; + dLo = *std::min_element(c, c + 4); + dHi = *std::max_element(c, c + 4); + } + for (bool asUnsigned : {usersView, !usersView}) { + WideInt sLo = viewMin(w, asUnsigned), sHi = viewMax(w, asUnsigned); + if (auto c = constantValue(init, asUnsigned)) + sLo = sHi = *c; + WideInt lo = sLo + dLo, hi = sHi + dHi; + if ((!hasUnsigned || + (lo >= viewMin(w, true) && hi <= viewMax(w, true))) && + (!hasSigned || (lo >= viewMin(w, false) && hi <= viewMax(w, false)))) + return asUnsigned; + } + return std::nullopt; + } + + static Value castInit(PatternRewriter &rewriter, Location loc, Value init, + bool asUnsigned) { + if (asUnsigned) + return rewriter.create(loc, rewriter.getIndexType(), init); + return rewriter.create(loc, rewriter.getIndexType(), init); + } + LogicalResult matchAndRewrite(scf::ForOp forOp, PatternRewriter &rewriter) const final { // Defer until after the step is a constant, if possible - if (auto icast = forOp.getStep().getDefiningOp()) - if (matchPattern(icast.getIn(), m_Constant())) + if (auto *icast = forOp.getStep().getDefiningOp()) + if (isa(icast) && + matchPattern(icast->getOperand(0), m_Constant())) return failure(); bool canonicalize = false; Block &block = forOp.getRegion().front(); @@ -316,7 +698,34 @@ struct ForOpInductionReplacement : public OpRewritePattern { sameValue |= rattr.zext(maxWidth) == sattr.zext(maxWidth); } - if (!std::get<1>(it).use_empty()) { + // A narrow counter is replaced only when one cast of its start makes + // every read of it exact (chooseInitCast). + bool narrow = !std::get<0>(it).getType().isa(); + std::optional bodyCast, exitCast; + if (narrow && !std::get<1>(it).use_empty()) + bodyCast = chooseInitCast(forOp, std::get<0>(it), std::get<1>(it), + sameValue, addOp.getOperand(1), + /*atExit=*/false); + if (narrow && !std::get<2>(it).use_empty()) + exitCast = chooseInitCast(forOp, std::get<0>(it), std::get<2>(it), + sameValue, addOp.getOperand(1), + /*atExit=*/true); + // In a loop raised by assuming that it terminates (MoveWhileToFor, + // AssumeTermination), the loop's own counter never wraps: its value, + // read with its own signedness, is the index it is cast from, inside + // the loop and at its exit. The cast is marked so for AffineCFG. + std::optional ownNoWrap; + if (narrow) + ownNoWrap = assumedOwnCastOf(forOp, std::get<0>(it), sameValue, + addOp.getOperand(1)); + auto markOwnCast = [&](Value cast, std::optional chosen) { + if (ownNoWrap && chosen && *chosen == *ownNoWrap) + cast.getDefiningOp()->setAttr(*ownNoWrap ? kNoUnsignedWrapAttrName + : kNoSignedWrapAttrName, + rewriter.getUnitAttr()); + }; + + if (!std::get<1>(it).use_empty() && (!narrow || bodyCast)) { Value init = std::get<0>(it); rewriter.setInsertionPointToStart(&forOp.getRegion().front()); Value replacement = rewriter.create( @@ -338,10 +747,8 @@ struct ForOpInductionReplacement : public OpRewritePattern { rewriter.create(forOp.getLoc(), replacement, step); } - if (!init.getType().isa()) { - init = rewriter.create(forOp.getLoc(), - replacement.getType(), init); - } + if (narrow) + init = castInit(rewriter, forOp.getLoc(), init, *bodyCast); replacement = rewriter.create(forOp.getLoc(), init, replacement); @@ -349,6 +756,7 @@ struct ForOpInductionReplacement : public OpRewritePattern { if (!std::get<1>(it).getType().isa()) { replacement = rewriter.create( forOp.getLoc(), std::get<1>(it).getType(), replacement); + markOwnCast(replacement, bodyCast); } rewriter.updateRootInPlace( @@ -356,32 +764,33 @@ struct ForOpInductionReplacement : public OpRewritePattern { canonicalize = true; } - if (!std::get<2>(it).use_empty()) { + if (!std::get<2>(it).use_empty() && (!narrow || exitCast)) { Value init = std::get<0>(it); + Location loc = forOp.getLoc(); rewriter.setInsertionPoint(forOp); - Value replacement = rewriter.create( - forOp.getLoc(), forOp.getUpperBound(), forOp.getLowerBound()); - - if (!sameValue) - replacement = rewriter.create(forOp.getLoc(), replacement, - forOp.getStep()); - - if (!sameValue) { - Value step = addOp.getOperand(1); - - if (!step.getType().isa()) { - step = rewriter.create(forOp.getLoc(), - replacement.getType(), step); - } - - replacement = - rewriter.create(forOp.getLoc(), replacement, step); - } - - if (!init.getType().isa()) { - init = rewriter.create(forOp.getLoc(), - replacement.getType(), init); - } + // The counter leaves the loop at init + trips * inc (inc: the loop's + // step with sameValue), trips = max(0, ceil((ub - lb) / step)), the + // number of iterations (step > 0): none when the loop does not run + // (ub < lb), a last partial step counted whole (`i < 10; i += 3` + // leaves at 12). + Value trips = rewriter.create(loc, forOp.getUpperBound(), + forOp.getLowerBound()); + if (!matchPattern(forOp.getStep(), m_One())) + trips = rewriter.create(loc, trips, forOp.getStep()); + auto lbR = indexRange(forOp.getLowerBound()); + auto ubR = indexRange(forOp.getUpperBound()); + if (!lbR || !ubR || ubR->first < lbR->second) + trips = rewriter.create( + loc, trips, rewriter.create(loc, 0)); + Value inc = sameValue ? forOp.getStep() : addOp.getOperand(1); + if (!inc.getType().isa()) + inc = rewriter.create(loc, trips.getType(), inc); + Value replacement = trips; + if (!matchPattern(inc, m_One())) + replacement = rewriter.create(loc, trips, inc); + + if (narrow) + init = castInit(rewriter, forOp.getLoc(), init, *exitCast); replacement = rewriter.create(forOp.getLoc(), init, replacement); @@ -389,6 +798,7 @@ struct ForOpInductionReplacement : public OpRewritePattern { if (!std::get<1>(it).getType().isa()) { replacement = rewriter.create( forOp.getLoc(), std::get<1>(it).getType(), replacement); + markOwnCast(replacement, exitCast); } rewriter.updateRootInPlace( @@ -432,6 +842,9 @@ struct RemoveUnusedArgs : public OpRewritePattern { auto newForOp = rewriter.create(op.getLoc(), op.getLowerBound(), op.getUpperBound(), op.getStep(), usedOperands); + for (StringRef mark : {kCounterNoWrapAttrName, kUncountedLoopAttrName}) + if (Attribute a = op->getAttr(mark)) + newForOp->setAttr(mark, a); if (!newForOp.getBody()->empty()) rewriter.eraseOp(newForOp.getBody()->getTerminator()); @@ -659,6 +1072,11 @@ bool canMoveOpOutsideWhile(Operation *op, WhileOp loop) { return true; } +static bool isUnsignedPredicate(CmpIPredicate p) { + return p == CmpIPredicate::ult || p == CmpIPredicate::ule || + p == CmpIPredicate::ugt || p == CmpIPredicate::uge; +} + struct WhileToForHelper { WhileOp loop; CmpIOp cmpIOp; @@ -669,9 +1087,144 @@ struct WhileToForHelper { bool ub_addOne; bool ub_cloneMove; bool negativeStep; + // The counter's own values (its start and step) are read as unsigned: it is + // compared through an extui (an unsigned C counter narrower than its + // bound) or, unextended, with an unsigned predicate. + bool indVarUnsigned; + // The comparison is unsigned (ult/ule/ugt/uge): its bound is read as + // unsigned. + bool boundUnsigned; + // Which of lb / ub is the comparison's bound (the other is the counter's + // start). + bool lbIsBound; + bool ubIsBound; AddIOp addIOp; BlockArgument indVar; size_t afterArgIdx; + // Set by counterStaysInRange: the counter is not provably kept in range + // and the loop is raised by assuming that it terminates (AssumeTermination); + // with uncounted, its bound may lie beyond the counter's range. + bool assumedNoWrap = false; + bool uncounted = false; + + /// The for loop counts in index arithmetic, the while in the counter's own + /// iW arithmetic, which wraps modulo 2^W (arith.addi); they agree only if + /// the counter never leaves its range before the test fails, so a counter + /// narrower than int is raised only when that is provable. Such counters + /// wrap in C: unsigned ones modulo 2^W (defined), signed ones because their + /// `++` / `+=` is computed in int and converted back (implementation- + /// defined; clang and Vitis wrap). A counter as wide as int is assumed not + /// to wrap, as before: for a signed one that is C's undefined overflow, and + /// the IR cannot tell an unsigned one (`unsigned j < n`, which could wrap + /// at 2^32) from a signed one compared unsigned (`int jj < unsigned + /// row_end; jj += 4`, spector_hls/spmv: cmpi ult on i32 either way). + /// The range is that of the counter's values as the test reads them: + /// [0, 2^W) through an extui or an unextended unsigned compare, + /// [-2^(W-1), 2^(W-1)) through an extsi or an unextended signed compare, + /// [0, 2^(W-1)) through an extsi read by an unsigned compare (a negative + /// value is huge there). Counting up by s with `i < B` (`i <= B`), the + /// largest value that passes is at most B - 1 (B), and it plus s must stay + /// in range; counting down by d with `i > B` (`i >= B`), the smallest is at + /// least B + 1 (B), and it minus d must stay in range. A constant start + /// makes this exact (the last value is start + k * s); a runtime bound + /// counts with the largest (smallest) value its definition allows, so a + /// bound zero-extended from at most W bits is in range while an `int n` + /// against a uint8_t counter is not (`for (uint8_t i = 0; i < n; i++)` + /// never ends for n > 255). A runtime step is not provable. + /// When the proof fails, the loop may still be raised by assuming that it + /// terminates (terminationImpliesNoWrap; AssumeTermination). + bool counterStaysInRange(Operation *ext) { + assumedNoWrap = false; + uncounted = false; + if (counterProvablyInRange(ext)) + return true; + if (!terminationImpliesNoWrap(ext)) + return false; + assumedNoWrap = true; + // The bound's values as the test reads them, against the counter's. + unsigned w = intWidth(indVar.getType()); + auto [bMin, bMax] = valueRange(cmpIOp.getRhs(), boundUnsigned); + WideInt lo = viewMin(w, indVarUnsigned), hi = viewMax(w, indVarUnsigned); + uncounted = bMin < lo || bMax > hi; + return true; + } + + /// Whether the loop may be assumed to terminate and its termination + /// implies that its counter never wraps (see AssumeTermination): a counter + /// narrower than int, a runtime bound, a constant step of +-2^k with + /// 2^k <= 2^(W-1), a test that reads the counter with its own signedness + /// (not a sign-extended counter compared unsigned) and nothing in the loop + /// that makes running forever observable (mayDoObservableWork). + bool terminationImpliesNoWrap(Operation *ext) { + if (!AssumeTermination) + return false; + unsigned w = intWidth(indVar.getType()); + if (w == 0 || w >= kCIntWidth || intWidth(cmpIOp.getRhs().getType()) > 64) + return false; + if (ext && isa(ext) && boundUnsigned) + return false; + if (constantValue(cmpIOp.getRhs(), boundUnsigned)) + return false; + std::optional s = constantValue(step, /*asUnsigned=*/false); + if (!s || *s == 0) + return false; + WideInt mag = *s < 0 ? -*s : *s; + if ((mag & (mag - 1)) != 0 || mag > ((WideInt)1 << (w - 1))) + return false; + if (auto fn = loop->getParentOfType(); + fn && fn->hasAttr(polygeist::kVolatileAccessAttrName)) + return false; + SmallPtrSet visited; + return !mayDoObservableWork(loop.getOperation(), visited); + } + + bool counterProvablyInRange(Operation *ext) { + CmpIPredicate pred = cmpIOp.getPredicate(); + unsigned w = intWidth(indVar.getType()); + if (w >= kCIntWidth) + return true; + if (w == 0 || intWidth(cmpIOp.getRhs().getType()) > 64) + return false; + + WideInt lo = viewMin(w, indVarUnsigned); + WideInt hi = viewMax(w, indVarUnsigned); + Value init = loop.getInits()[indVar.getArgNumber()]; + std::optional start = constantValue(init, indVarUnsigned); + if (ext && isa(ext) && boundUnsigned) { + lo = 0; + if (start ? *start < 0 : valueRange(init, false).first < 0) + return false; + } + + std::optional s = constantValue(step, /*asUnsigned=*/false); + if (!s || *s == 0) + return false; + auto [bMin, bMax] = valueRange(cmpIOp.getRhs(), boundUnsigned); + if (*s > 0) { + // The largest value the test accepts. + WideInt last = (pred == CmpIPredicate::slt || pred == CmpIPredicate::ult) + ? bMax - 1 + : bMax; + if (start) { + if (*start > last) // the body never runs + return true; + last = *start + (last - *start) / *s * *s; + } + return last + *s <= hi; + } + WideInt d = -*s; + // The smallest value the test accepts. + WideInt first = (pred == CmpIPredicate::sgt || pred == CmpIPredicate::ugt) + ? bMin + 1 + : bMin; + if (start) { + if (*start < first) // the body never runs + return true; + first = *start - (*start - first) / d * d; + } + return first - d >= lo; + } + bool computeLegality(bool sizeCheck, Value lookThrough = nullptr) { step = nullptr; lb = nullptr; @@ -680,14 +1233,33 @@ struct WhileToForHelper { ub_addOne = false; ub_cloneMove = false; negativeStep = false; + indVarUnsigned = false; + boundUnsigned = isUnsignedPredicate(cmpIOp.getPredicate()); + lbIsBound = false; + ubIsBound = false; + assumedNoWrap = false; + uncounted = false; auto condOp = loop.getConditionOp(); indVar = dyn_cast(cmpIOp.getLhs()); Type extType = nullptr; - // todo handle ext - if (auto ext = cmpIOp.getLhs().getDefiningOp()) { - indVar = dyn_cast(ext.getIn()); - extType = ext.getType(); + Operation *ext = nullptr; + // A counter narrower than its bound is compared after a widening: + // `for (int8_t i ...; i < 64;)` compares extsi(i), `for (uint8_t i ...)` + // compares extui(i). Both extensions are monotone, so the bound test on + // the extended value is the same test on the counter while the counter + // does not wrap (counterStaysInRange). + if (auto extsi = cmpIOp.getLhs().getDefiningOp()) { + indVar = dyn_cast(extsi.getIn()); + extType = extsi.getType(); + ext = extsi; + } else if (auto extui = cmpIOp.getLhs().getDefiningOp()) { + indVar = dyn_cast(extui.getIn()); + extType = extui.getType(); + ext = extui; + indVarUnsigned = true; + } else if (boundUnsigned) { + indVarUnsigned = true; } // Condition is not the same as an induction variable { @@ -791,6 +1363,14 @@ struct WhileToForHelper { return false; } } + // Nor when the step is a block argument of the loop itself (or of a + // region nested in it): `m += m` doubles the counter, it does not step it + // by a constant amount. The scf.for built from it would read its own + // iteration argument as the step (invalid IR: "operand does not dominate + // this use", W8b repro r_step_iv.c, machsuite sort_merge). + if (auto arg = dyn_cast(step)) + if (loop->isAncestor(arg.getOwner()->getParentOp())) + return false; negativeStep = false; if (auto cop = step.getDefiningOp()) { @@ -815,23 +1395,27 @@ struct WhileToForHelper { case CmpIPredicate::slt: case CmpIPredicate::ult: { ub = cmpRhs; + ubIsBound = true; break; } case CmpIPredicate::ule: case CmpIPredicate::sle: { ub = cmpRhs; + ubIsBound = true; ub_addOne = true; break; } case CmpIPredicate::uge: case CmpIPredicate::sge: { lb = cmpRhs; + lbIsBound = true; break; } case CmpIPredicate::ugt: case CmpIPredicate::sgt: { lb = cmpRhs; + lbIsBound = true; lb_addOne = true; break; } @@ -847,19 +1431,16 @@ struct WhileToForHelper { if (!op || !canMoveOpOutsideWhile(op, loop) || (op->getNumResults() != 1)) return false; ub = cmpIOp.getRhs(); + ubIsBound = true; ub_cloneMove = true; } - return lb && ub; + if (!lb || !ub) + return false; + return counterStaysInRange(ext); } void prepareFor(PatternRewriter &rewriter) { - Value one; - if (lb_addOne) { - Value one = - rewriter.create(loop.getLoc(), 1, lb.getType()); - lb = rewriter.create(loop.getLoc(), lb, one); - } if (ub_cloneMove) { auto *op = ub.getDefiningOp(); assert(op); @@ -867,11 +1448,6 @@ struct WhileToForHelper { rewriter.replaceOp(op, newOp->getResults()); ub = newOp->getResult(0); } - if (ub_addOne) { - Value one = - rewriter.create(loop.getLoc(), 1, ub.getType()); - ub = rewriter.create(loop.getLoc(), ub, one); - } if (negativeStep) { if (auto cop = step.getDefiningOp()) { @@ -882,12 +1458,32 @@ struct WhileToForHelper { } } - ub = rewriter.create(loop.getLoc(), - IndexType::get(loop.getContext()), ub); - lb = rewriter.create(loop.getLoc(), - IndexType::get(loop.getContext()), lb); - step = rewriter.create( - loop.getLoc(), IndexType::get(loop.getContext()), step); + // The counter's own values (its start and step) are read with the + // counter's signedness, the comparison's bound with the predicate's + // (`ap_uint<8> i < ap_uint<8> len` compares ult in i8: len >= 128 is a + // large bound, not a negative one). The `+ 1` of an inclusive bound or a + // countdown's start is added in index, where it cannot wrap (a uint8_t + // countdown from 255 has ub 256, not 0). + auto toIndex = [&](Value v, bool asUnsigned) -> Value { + auto idxTy = IndexType::get(loop.getContext()); + if (v.getType().isa()) + return v; + if (asUnsigned) + return rewriter.create(loop.getLoc(), idxTy, v); + return rewriter.create(loop.getLoc(), idxTy, v); + }; + auto plusOne = [&](Value v) -> Value { + return rewriter.create( + loop.getLoc(), v, + rewriter.create(loop.getLoc(), 1)); + }; + ub = toIndex(ub, ubIsBound ? boundUnsigned : indVarUnsigned); + if (ub_addOne) + ub = plusOne(ub); + lb = toIndex(lb, lbIsBound ? boundUnsigned : indVarUnsigned); + if (lb_addOne) + lb = plusOne(lb); + step = toIndex(step, indVarUnsigned); } }; @@ -906,6 +1502,17 @@ struct MoveWhileToFor : public OpRewritePattern { } if (!helper.computeLegality(/*sizeCheck*/ true)) return failure(); + // Every value the condition passes to the body seeds an iter_arg of the + // for and is yielded from its body, so it has to exist outside the loop: + // a before-block argument (its init is used) or a value defined before + // the loop. A before-region op result (the extension a narrow counter is + // compared through, when the body shares it) would be erased with the + // while while still in use; MoveSideEffectFreeWhile recomputes such + // casts in the body first. + for (Value arg : condOp.getArgs()) + if (!isTopLevelArgValue(arg, &loop.getBefore()) && + !dominateWhile(arg, loop)) + return failure(); helper.prepareFor(rewriter); // input of the for goes the input of the scf::while plus the output taken @@ -915,9 +1522,14 @@ struct MoveWhileToFor : public OpRewritePattern { for (Value arg : condOp.getArgs()) { Type cst = nullptr; + bool castUnsigned = false; if (auto idx = arg.getDefiningOp()) { cst = idx.getType(); arg = idx.getIn(); + } else if (auto idx = arg.getDefiningOp()) { + cst = idx.getType(); + arg = idx.getIn(); + castUnsigned = true; } Value res; if (isTopLevelArgValue(arg, &loop.getBefore())) { @@ -927,13 +1539,24 @@ struct MoveWhileToFor : public OpRewritePattern { } else res = arg; if (cst) { - res = rewriter.create(res.getLoc(), cst, res); + if (castUnsigned) + res = rewriter.create(res.getLoc(), cst, res); + else + res = rewriter.create(res.getLoc(), cst, res); } forArgs.push_back(res); } auto forloop = rewriter.create(loop.getLoc(), helper.lb, helper.ub, helper.step, forArgs); + // Raised by assuming that the loop terminates (AssumeTermination): its + // counter casts are marked (ForOpInductionReplacement), and a bound that + // may lie beyond the counter's range makes it an uncounted loop. + if (helper.assumedNoWrap) + forloop->setAttr(kCounterNoWrapAttrName, + rewriter.getBoolAttr(helper.indVarUnsigned)); + if (helper.uncounted) + forloop->setAttr(kUncountedLoopAttrName, rewriter.getUnitAttr()); if (!forloop.getBody()->empty()) rewriter.eraseOp(forloop.getBody()->getTerminator()); @@ -1070,6 +1693,12 @@ struct MoveWhileAndDown : public OpRewritePattern { { IRMapping postMap; postMap.map(helper.indVar, trueInd); + // The counter may be compared through an extension (computeLegality + // looked through it): rebuild it on the new counter first. + if (helper.cmpIOp.getLhs() != helper.indVar) + if (Operation *ext = helper.cmpIOp.getLhs().getDefiningOp()) + postMap.map(ext->getResults(), + rewriter.clone(*ext, postMap)->getResults()); auto newCmp = cast(rewriter.clone(*helper.cmpIOp, postMap)); rewriter.create(condOp.getLoc(), newCmp, newBeforeYieldArgs); @@ -1340,19 +1969,44 @@ struct MoveWhileDown2 : public OpRewritePattern { // } loop ( ... i:) { // yield i:pair<2> // } + // + // The result need not sit at the block argument's position: the + // condition may forward other values in front of it, as for a + // rotated variable (`B = A; A = t;`), where the condition passes + // the old B, the old A and the if results. What the rewrite needs + // is that the after argument feeds nothing but the yield into + // %blockArg (it is replaced there by the then value and receives + // the old value afterwards), and that the then value is visible in + // the after region (defined in the then region, which moves there, + // or outside the loop). if (!std::get<0>(pair).use_empty()) { if (auto blockArg = dyn_cast(elseYielded)) if (blockArg.getOwner() == &op.getBefore().front()) { + Value afterArg = std::get<2>(pair); + bool thenValueVisible = + ifOp.getThenRegion().isAncestor( + thenYielded.getParentRegion()) || + !op->isAncestor(thenYielded.getParentRegion() + ->getParentOp()); if (afterYield.getResults()[blockArg.getArgNumber()] == - std::get<2>(pair) && - op.getResults()[blockArg.getArgNumber()] == - std::get<0>(pair)) { + afterArg && + afterArg.hasOneUse() && thenValueVisible) { prevResults.push_back(std::get<0>(pair)); condArgs.push_back(blockArg); afterYieldRewrites.emplace_back(blockArg.getArgNumber(), thenYielded); continue; } + // An exit-only value: the loop body never reads the after + // argument (the variable is carried through other + // positions, its then value is typically undef), so the + // result is the block argument at the failing check and the + // body needs no rewrite. + if (afterArg.use_empty()) { + prevResults.push_back(std::get<0>(pair)); + condArgs.push_back(blockArg); + continue; + } } return failure(); } @@ -1563,6 +2217,132 @@ struct WhileLogicalNegation : public OpRewritePattern { }; /// TODO move the addi down and repalce below with a subi +/// A while loop whose condition is a conjunction of two signed upper bounds +/// on its counter, `i < B1 && i + a < B2` (either conjunct may be `i`, +/// `i + a` or `a + i` against a value defined before the loop), tests the one +/// bound `i < min(B1, B2 - a)`: the loop is then counted and MoveWhileToFor +/// raises it. Vitis treats it so (VITIS_NOTES N153, kernels w9r21p_d1 / d3: +/// `for (u = 0; u < 32 && k + u < B; ++u)` is unrolled and its array +/// partitioned like the plain bound; class_ece8893 pranay_kamineny lab2). +/// The two tests agree while `B2 - a` does not overflow; the program never +/// computes that difference, so the pattern requires B2 to be a constant and +/// `a` a constant or the counter of an enclosing scf.for with constant +/// bounds, all within 2^30 in magnitude (then `i + a < B2` with `i` from 0 +/// cannot differ from `i < B2 - a` either). Only `slt` with the counter on +/// the left; the counter must be a before-block argument. +static llvm::cl::opt WhileConjunctiveBounds( + "while-conjunctive-bounds", llvm::cl::init(true), + llvm::cl::desc("Raise `while (i < B1 && i + a < B2)` loops as counted " + "loops of min(B1, B2 - a) trips (VITIS_NOTES N153)")); + +/// [lo, hi] of a constant or of the counter of an scf.for with constant +/// bounds (through integer casts), each within 2^30 in magnitude. +static bool boundedSmallValue(Value v, int64_t &lo, int64_t &hi, + unsigned depth = 0) { + constexpr int64_t kLimit = int64_t(1) << 30; + if (depth > 8) + return false; + APInt c; + if (matchPattern(v, m_ConstantInt(&c))) { + if (c.getSignificantBits() > 32) + return false; + lo = hi = c.getSExtValue(); + return lo > -kLimit && lo < kLimit; + } + if (Operation *def = v.getDefiningOp()) { + if (isa(def)) + return boundedSmallValue(def->getOperand(0), lo, hi, depth + 1); + return false; + } + auto arg = cast(v); + auto loop = dyn_cast(arg.getOwner()->getParentOp()); + if (!loop || arg != loop.getInductionVar()) + return false; + int64_t l, u, l2, u2; + if (!boundedSmallValue(loop.getLowerBound(), l, l2, depth + 1) || + !boundedSmallValue(loop.getUpperBound(), u, u2, depth + 1)) + return false; + lo = std::min(l, u); + hi = std::max(l, u); + return true; +} + +struct WhileConjunctiveBound : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(WhileOp op, + PatternRewriter &rewriter) const override { + if (!WhileConjunctiveBounds) + return failure(); + Block &before = op.getBefore().front(); + auto term = cast(before.getTerminator()); + auto conj = term.getCondition().getDefiningOp(); + if (!conj || conj->getBlock() != &before) + return failure(); + auto outside = [&](Value v) { + if (auto arg = dyn_cast(v)) + return !op->isAncestor(arg.getOwner()->getParentOp()); + return !op->isAncestor(v.getDefiningOp()); + }; + // `cmp` as `iv < bound`, the bound a value defined before the loop or + // `B - a`, built before the loop. + BlockArgument iv; + auto boundOf = [&](Value c, SmallVectorImpl> &out) { + auto cmp = c.getDefiningOp(); + if (!cmp || cmp.getPredicate() != CmpIPredicate::slt || + !outside(cmp.getRhs())) + return false; + Value lhs = cmp.getLhs(), offset; + if (auto add = lhs.getDefiningOp()) { + if (add->getBlock() != &before) + return false; + if (outside(add.getRhs())) { + lhs = add.getLhs(); + offset = add.getRhs(); + } else if (outside(add.getLhs())) { + lhs = add.getRhs(); + offset = add.getLhs(); + } else { + return false; + } + } + auto arg = dyn_cast(lhs); + if (!arg || arg.getOwner() != &before || (iv && arg != iv)) + return false; + iv = arg; + out.push_back({cmp.getRhs(), offset}); + return true; + }; + SmallVector, 2> bounds; + if (!boundOf(conj.getLhs(), bounds) || !boundOf(conj.getRhs(), bounds)) + return failure(); + if (iv.getType() != bounds[0].first.getType() || + iv.getType() != bounds[1].first.getType()) + return failure(); + // No overflow in `B - a` (see the comment above). + for (auto [b, a] : bounds) { + if (!a) + continue; + int64_t blo, bhi, alo, ahi; + if (!boundedSmallValue(b, blo, bhi) || blo != bhi || + !boundedSmallValue(a, alo, ahi)) + return failure(); + } + rewriter.setInsertionPoint(op); + SmallVector limits; + for (auto [b, a] : bounds) + limits.push_back(a ? rewriter.create(op.getLoc(), b, a) + .getResult() + : b); + Value limit = rewriter.create(op.getLoc(), limits[0], limits[1]); + rewriter.setInsertionPoint(conj); + Value test = + rewriter.create(conj.getLoc(), CmpIPredicate::slt, iv, limit); + rewriter.replaceOp(conj, test); + return success(); + } +}; + struct WhileCmpOffset : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; @@ -1977,17 +2757,30 @@ struct MoveSideEffectFreeWhile : public OpRewritePattern { bool changed = false; unsigned i = 0; for (auto arg : term.getArgs()) { - if (auto IC = arg.getDefiningOp()) { - if (arg.hasOneUse() && op.getResult(i).use_empty()) { - auto rep = op.getAfter().front().addArgument( - IC->getOperand(0).getType(), IC->getOperand(0).getLoc()); - IC->moveBefore(&op.getAfter().front(), op.getAfter().front().begin()); - conds.push_back(IC.getIn()); - IC.getInMutable().assign(rep); - op.getAfter().front().getArgument(i).replaceAllUsesWith( - IC->getResult(0)); - changed = true; + // A cast the condition passes to the body (an index cast of a counter, + // or the extension a narrow counter is compared through, when the body + // shares it) is recomputed in the body from the cast's input, which is + // passed instead. The before-region op moves when the condition was its + // only use and is cloned when the comparison still needs it there. + Operation *IC = arg.getDefiningOp(); + if (IC && isa(IC) && + op.getResult(i).use_empty() && + (arg.hasOneUse() || IC->getParentRegion() == &op.getBefore())) { + Block &after = op.getAfter().front(); + auto rep = after.addArgument(IC->getOperand(0).getType(), + IC->getOperand(0).getLoc()); + conds.push_back(IC->getOperand(0)); + Operation *bodyCast = IC; + if (arg.hasOneUse()) { + IC->moveBefore(&after, after.begin()); + } else { + OpBuilder::InsertionGuard guard(rewriter); + rewriter.setInsertionPointToStart(&after); + bodyCast = rewriter.clone(*IC); } + bodyCast->setOperand(0, rep); + after.getArgument(i).replaceAllUsesWith(bodyCast->getResult(0)); + changed = true; } i++; } @@ -2019,16 +2812,135 @@ struct SubToAdd : public OpRewritePattern { LogicalResult matchAndRewrite(SubIOp op, PatternRewriter &rewriter) const override { if (auto cop = op.getOperand(1).getDefiningOp()) { - rewriter.replaceOpWithNewOp( + // Negate in the constant's own width (APInt): going through the + // int64_t value() zero-extended -C into integers wider than 64 bits + // (x - 1 : i128 became x + (2^64 - 1)). Same constants as before for + // widths <= 64. + APInt c = cop.getValue().cast().getValue(); + // x - C and x + (-C) have the same exact result when -C does not + // overflow: a non-wrapping subtraction (polygeist.nsw) stays one. + bool nsw = op->hasAttr(kNoSignedWrapAttrName) && !c.isMinSignedValue(); + auto add = rewriter.replaceOpWithNewOp( op, op.getOperand(0), - rewriter.create(cop.getLoc(), -cop.value(), - cop.getType())); + rewriter.create( + cop.getLoc(), cop.getType(), + rewriter.getIntegerAttr(cop.getType(), -c))); + if (nsw) + add->setAttr(kNoSignedWrapAttrName, rewriter.getUnitAttr()); return success(); } return failure(); } }; +// The arith canonicalizer folds a chain of two add / sub with constant +// operands into one (`(x + 1) + 2` into `x + 3`, `3 - (x + 1)` into `2 - x`) +// and two mul by constants into one, through new ops without the +// polygeist.nsw mark of the originals (Passes.h). When both ops of a chain +// are marked, their exact results are in range, so the folded op, which +// computes the same value, does not wrap either. These patterns fold such a +// chain first (benefit 10: a DRR pattern's benefit is the number of ops it +// matches) into the form the arith patterns produce and keep +// the mark. The folded constant must fit its width (`x + 2^30 + 2^30` +// does not), or the folded op would compute a different value. + +/// A marked add / sub `op` with one constant operand, read as +/// `sign * x + k`: `x + c` and `c + x` are x + c, `x - c` is x + (-c), `c - x` +/// is -x + c. +struct AddSubConst { + Value x; + int sign; + APInt k; +}; + +static std::optional matchNoSignedWrapAddSubConst(Operation *op) { + if (!isa(op) || + !op->hasAttr(polygeist::kNoSignedWrapAttrName)) + return std::nullopt; + APInt c; + if (matchPattern(op->getOperand(1), m_ConstantInt(&c))) { + if (isa(op)) + return AddSubConst{op->getOperand(0), 1, c}; + if (c.isMinSignedValue()) + return std::nullopt; + return AddSubConst{op->getOperand(0), 1, -c}; + } + if (matchPattern(op->getOperand(0), m_ConstantInt(&c))) + return AddSubConst{op->getOperand(1), isa(op) ? 1 : -1, c}; + return std::nullopt; +} + +/// Folds the chain `op` = outer(inner(x)) of two marked add / sub with +/// constant operands into `x + k` or `k - x`, marked. +static LogicalResult foldNoSignedWrapAddSubChain(Operation *op, + PatternRewriter &rewriter) { + auto outer = matchNoSignedWrapAddSubConst(op); + if (!outer) + return failure(); + Operation *innerOp = outer->x.getDefiningOp(); + if (!innerOp) + return failure(); + auto inner = matchNoSignedWrapAddSubConst(innerOp); + if (!inner) + return failure(); + // outer->sign * (inner->sign * x + inner->k) + outer->k + if (outer->sign < 0 && inner->k.isMinSignedValue()) + return failure(); + bool overflow = false; + APInt k = + (outer->sign < 0 ? -inner->k : inner->k).sadd_ov(outer->k, overflow); + if (overflow) + return failure(); + Type t = op->getResult(0).getType(); + Value cst = rewriter.create(op->getLoc(), t, + rewriter.getIntegerAttr(t, k)); + Operation *folded = + outer->sign * inner->sign > 0 + ? rewriter.create(op->getLoc(), inner->x, cst).getOperation() + : rewriter.create(op->getLoc(), cst, inner->x).getOperation(); + folded->setAttr(polygeist::kNoSignedWrapAttrName, rewriter.getUnitAttr()); + rewriter.replaceOp(op, folded->getResults()); + return success(); +} + +template +struct NoSignedWrapAddSubChain : public OpRewritePattern { + NoSignedWrapAddSubChain(MLIRContext *ctx) + : OpRewritePattern(ctx, /*benefit=*/10) {} + LogicalResult matchAndRewrite(OpTy op, + PatternRewriter &rewriter) const override { + return foldNoSignedWrapAddSubChain(op, rewriter); + } +}; + +/// `(x * c0) * c1`, both marked, into `x * (c0 * c1)`, marked, when the +/// product fits. +struct NoSignedWrapMulChain : public OpRewritePattern { + NoSignedWrapMulChain(MLIRContext *ctx) + : OpRewritePattern(ctx, /*benefit=*/10) {} + LogicalResult matchAndRewrite(MulIOp op, + PatternRewriter &rewriter) const override { + APInt c0, c1; + if (!op->hasAttr(polygeist::kNoSignedWrapAttrName) || + !matchPattern(op.getRhs(), m_ConstantInt(&c1))) + return failure(); + auto inner = op.getLhs().getDefiningOp(); + if (!inner || !inner->hasAttr(polygeist::kNoSignedWrapAttrName) || + !matchPattern(inner.getRhs(), m_ConstantInt(&c0))) + return failure(); + bool overflow = false; + APInt k = c0.smul_ov(c1, overflow); + if (overflow) + return failure(); + Type t = op.getType(); + Value cst = rewriter.create( + op.getLoc(), t, rewriter.getIntegerAttr(t, k)); + auto folded = rewriter.replaceOpWithNewOp(op, inner.getLhs(), cst); + folded->setAttr(polygeist::kNoSignedWrapAttrName, rewriter.getUnitAttr()); + return success(); + } +}; + struct ReturnSq : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; LogicalResult matchAndRewrite(ReturnOp op, @@ -2228,7 +3140,7 @@ struct WhileShiftToInduction : public OpRewritePattern { void CanonicalizeFor::runOnOperation() { mlir::RewritePatternSet rpl(getOperation()->getContext()); rpl.add mlir::polygeist::createCanonicalizeForPass() { return std::make_unique(); } + +void mlir::polygeist::populateNoSignedWrapPatterns( + RewritePatternSet &patterns) { + patterns.add, NoSignedWrapAddSubChain, + NoSignedWrapMulChain>(patterns.getContext()); +} diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index f1d6a6ffa3ac..171853bb3d25 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -226,6 +226,22 @@ struct SubIndexOpLowering : public ConvertOpToLLVMPattern { strides.push_back(targetMemRef.stride(rewriter, loc, i)); } } else { + // A view of the same rank moves by whole rows: `p + 1` of a pointer to + // an int[8] (memref) is 8 elements on, not 1 (CIRCT W9 round + // 8 review defect 8: the differential check of a range-based for over + // the rows of a 2-D array, probe pq1.cpp). + size_t sz = 1; + for (size_t i = 1; i < sourceMemRefType.getShape().size(); i++) { + if (sourceMemRefType.getShape()[i] == ShapedType::kDynamic) + return failure(); + sz *= sourceMemRefType.getShape()[i]; + } + if (sz != 1) { + Value cop = rewriter.create( + loc, idxs[0].getType(), + rewriter.getIntegerAttr(idxs[0].getType(), sz)); + idxs[0] = rewriter.create(loc, idxs[0], cop); + } for (size_t i = 0; i < sourceMemRefType.getShape().size(); i++) { sizes.push_back(targetMemRef.size(rewriter, loc, i)); strides.push_back(targetMemRef.stride(rewriter, loc, i)); diff --git a/lib/polygeist/Passes/LoopRestructure.cpp b/lib/polygeist/Passes/LoopRestructure.cpp index c9cb3abc8243..61726eea18d4 100644 --- a/lib/polygeist/Passes/LoopRestructure.cpp +++ b/lib/polygeist/Passes/LoopRestructure.cpp @@ -422,8 +422,23 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) { combinedLocs.append(returnLocs); assert(combinedTypes.size() == combinedLocs.size()); - auto loop = builder.create( - header->front().getLoc(), combinedTypes, valsCallingLoop); + // Front ends may identify a source loop by a location with metadata on + // the loop's exit test (cgeist does this for HLS pragmas); keep such + // locations on the structured loop. + Location loopLoc = header->front().getLoc(); + { + SmallVector locs = {loopLoc}; + for (auto *B : exitingBlocks) { + Location termLoc = ((Block *)B)->getTerminator()->getLoc(); + if (auto fused = dyn_cast(termLoc)) + if (fused.getMetadata()) + locs.push_back(termLoc); + } + if (locs.size() > 1) + loopLoc = FusedLoc::get(builder.getContext(), locs); + } + auto loop = builder.create(loopLoc, combinedTypes, + valsCallingLoop); { SmallVector RetVals; for (size_t i = 0; i < returns.size(); ++i) { diff --git a/lib/polygeist/Passes/ParallelLICM.cpp b/lib/polygeist/Passes/ParallelLICM.cpp index 2fce2676954a..367f16b33789 100644 --- a/lib/polygeist/Passes/ParallelLICM.cpp +++ b/lib/polygeist/Passes/ParallelLICM.cpp @@ -24,10 +24,26 @@ using namespace polygeist; namespace { struct ParallelLICM : public ParallelLICMBase { + ParallelLICM() = default; + explicit ParallelLICM(bool keepLoops) : keepLoops(keepLoops) {} void runOnOperation() override; + + /// Do not hoist an op that is or contains a loop (cgeist + /// --hls-keep-invariant-loops): a loop-invariant inner loop stays in place. + bool keepLoops = false; }; } // namespace +/// Whether `op` must stay in its loop because it is or contains a loop and +/// loops are kept in place (`keepLoops`). +static bool keptInPlace(Operation *op, bool keepLoops) { + if (!keepLoops) + return false; + return op + ->walk([](LoopLikeOpInterface) { return WalkResult::interrupt(); }) + .wasInterrupted(); +} + static bool canBeParallelHoisted(Operation *op, Operation *scope, SmallPtrSetImpl &willBeMoved, bool includeAfter = false) { @@ -361,7 +377,8 @@ bool isSpeculatable(Operation *op) { } } // namespace mlir::polygeist -void moveParallelLoopInvariantCode(scf::ParallelOp looplike) { +void moveParallelLoopInvariantCode(scf::ParallelOp looplike, + bool keepLoops) { // We use two collections here as we need to preserve the order for insertion // and this is easiest. @@ -378,6 +395,7 @@ void moveParallelLoopInvariantCode(scf::ParallelOp looplike) { for (Block &block : region) for (Operation &op : block.without_terminator()) if ((!checkSpeculative || polygeist::isSpeculatable(&op)) && + !keptInPlace(&op, keepLoops) && canBeParallelHoisted(&op, looplike, willBeMovedSet)) { opsToMove.push_back(&op); willBeMovedSet.insert(&op); @@ -421,8 +439,14 @@ void moveParallelLoopInvariantCode(scf::ParallelOp looplike) { LLVM_DEBUG(looplike.print(llvm::dbgs() << "\n\nModified loop:\n")); } +// Used by ConvertParallelToGPU.cpp. +void moveParallelLoopInvariantCode(scf::ParallelOp looplike) { + moveParallelLoopInvariantCode(looplike, /*keepLoops=*/false); +} + // TODO affine parallel licm -void moveParallelLoopInvariantCode(affine::AffineParallelOp looplike) { +void moveParallelLoopInvariantCode(affine::AffineParallelOp looplike, + bool keepLoops) { // We use two collections here as we need to preserve the order for insertion // and this is easiest. @@ -438,6 +462,7 @@ void moveParallelLoopInvariantCode(affine::AffineParallelOp looplike) { for (Block &block : region) for (Operation &op : block.without_terminator()) if ((!checkSpeculative || polygeist::isSpeculatable(&op)) && + !keptInPlace(&op, keepLoops) && canBeParallelHoisted(&op, looplike, willBeMovedSet)) { opsToMove.push_back(&op); willBeMovedSet.insert(&op); @@ -532,7 +557,7 @@ void moveParallelLoopInvariantCode(affine::AffineParallelOp looplike) { LLVM_DEBUG(looplike.print(llvm::dbgs() << "\n\nModified loop:\n")); } -void moveSerialLoopInvariantCode(scf::ForOp looplike) { +void moveSerialLoopInvariantCode(scf::ForOp looplike, bool keepLoops) { // We use two collections here as we need to preserve the order for insertion // and this is easiest. @@ -548,6 +573,7 @@ void moveSerialLoopInvariantCode(scf::ForOp looplike) { for (Block &block : region) for (Operation &op : block.without_terminator()) if ((!checkSpeculative || polygeist::isSpeculatable(&op)) && + !keptInPlace(&op, keepLoops) && canBeParallelHoisted(&op, looplike, willBeMovedSet, /*checkAfter*/ true)) { opsToMove.push_back(&op); @@ -585,7 +611,8 @@ void moveSerialLoopInvariantCode(scf::ForOp looplike) { LLVM_DEBUG(looplike.print(llvm::dbgs() << "\n\nModified loop:\n")); } -void moveSerialLoopInvariantCode(affine::AffineForOp looplike) { +void moveSerialLoopInvariantCode(affine::AffineForOp looplike, + bool keepLoops) { // We use two collections here as we need to preserve the order for insertion // and this is easiest. @@ -601,6 +628,7 @@ void moveSerialLoopInvariantCode(affine::AffineForOp looplike) { for (Block &block : region) for (Operation &op : block.without_terminator()) { if ((!checkSpeculative || polygeist::isSpeculatable(&op)) && + !keptInPlace(&op, keepLoops) && canBeParallelHoisted(&op, looplike, willBeMovedSet, /*checkAfter*/ true)) { opsToMove.push_back(&op); @@ -697,17 +725,31 @@ void moveSerialLoopInvariantCode(affine::AffineForOp looplike) { void ParallelLICM::runOnOperation() { getOperation()->walk([&](LoopLikeOpInterface loopLike) { LLVM_DEBUG(loopLike.print(llvm::dbgs() << "\nOriginal loop:\n")); - moveLoopInvariantCode(loopLike); + if (keepLoops) + // mlir::moveLoopInvariantCode(LoopLikeOpInterface) (LLVM 18), except + // for ops that are or contain loops. + moveLoopInvariantCode( + loopLike.getLoopRegions(), + [&](Value value, Region *) { + return loopLike.isDefinedOutsideOfLoop(value); + }, + [&](Operation *op, Region *) { + return mlir::isMemoryEffectFree(op) && mlir::isSpeculatable(op) && + !keptInPlace(op, keepLoops); + }, + [&](Operation *op, Region *) { loopLike.moveOutOfLoop(op); }); + else + moveLoopInvariantCode(loopLike); if (auto par = dyn_cast((Operation *)loopLike)) { - moveParallelLoopInvariantCode(par); + moveParallelLoopInvariantCode(par, keepLoops); } else if (auto par = dyn_cast((Operation *)loopLike)) { - moveParallelLoopInvariantCode(par); + moveParallelLoopInvariantCode(par, keepLoops); } else if (auto par = dyn_cast((Operation *)loopLike)) { - moveSerialLoopInvariantCode(par); + moveSerialLoopInvariantCode(par, keepLoops); } else if (auto par = dyn_cast((Operation *)loopLike)) { - moveSerialLoopInvariantCode(par); + moveSerialLoopInvariantCode(par, keepLoops); } }); } @@ -715,3 +757,7 @@ void ParallelLICM::runOnOperation() { std::unique_ptr mlir::polygeist::createParallelLICMPass() { return std::make_unique(); } + +std::unique_ptr mlir::polygeist::createParallelLICMPass(bool keepLoops) { + return std::make_unique(keepLoops); +} diff --git a/lib/polygeist/Passes/PolygeistCanonicalize.cpp b/lib/polygeist/Passes/PolygeistCanonicalize.cpp index 1d12aaf2ad00..2749feb1d351 100644 --- a/lib/polygeist/Passes/PolygeistCanonicalize.cpp +++ b/lib/polygeist/Passes/PolygeistCanonicalize.cpp @@ -8,6 +8,7 @@ #include "PassDetails.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Async/IR/Async.h" #include "mlir/Dialect/DLTI/DLTI.h" @@ -34,6 +35,64 @@ using namespace mlir; using namespace polygeist; +namespace { +/// An array argument whose static shape differs from the parameter's only in +/// the first dimension (`f(x)` with `int x[3][8]` and `void f(int p[16][8])`) +/// reaches the callee through a memref.reinterpret_cast to the parameter's +/// shape (cgeist's castCallerMemRefArg). The two shapes have the same +/// row-major strides, so an access through the reinterpreted view addresses +/// the same element of the argument: once the call is inlined, the loads, +/// stores and subindex views of the view use the argument itself. +struct ArrayArgumentViewAccess + : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + static bool sameStridesAsSource(memref::ReinterpretCastOp op) { + auto src = dyn_cast(op.getSource().getType()); + MemRefType dst = op.getType(); + if (!src || !src.hasStaticShape() || !dst.hasStaticShape() || + !src.getLayout().isIdentity() || !dst.getLayout().isIdentity() || + src.getRank() != dst.getRank() || src.getRank() == 0 || + src.getElementType() != dst.getElementType() || + src.getMemorySpace() != dst.getMemorySpace()) + return false; + if (op.getStaticOffsets().size() != 1 || op.getStaticOffsets()[0] != 0) + return false; + return std::equal(std::next(src.getShape().begin()), src.getShape().end(), + std::next(dst.getShape().begin())); + } + + LogicalResult matchAndRewrite(memref::ReinterpretCastOp op, + PatternRewriter &rewriter) const override { + if (!sameStridesAsSource(op)) + return failure(); + Value src = op.getSource(); + bool changed = false; + for (OpOperand &use : llvm::make_early_inc_range(op->getUses())) { + Operation *user = use.getOwner(); + bool isAccessedMemref = + (isa( + user) && + use.getOperandNumber() == 0) || + (isa(user) && + use.getOperandNumber() == 1); + if (!isAccessedMemref) + continue; + rewriter.updateRootInPlace(user, [&] { use.set(src); }); + changed = true; + } + if (changed && op->use_empty()) + rewriter.eraseOp(op); + return success(changed); + } +}; +} // namespace + +void mlir::polygeist::populateArrayArgumentPatterns( + RewritePatternSet &patterns) { + patterns.add(patterns.getContext()); +} + namespace { struct PolygeistCanonicalizePass : public PolygeistCanonicalizeBase { @@ -67,6 +126,9 @@ struct PolygeistCanonicalizePass dialect->getCanonicalizationPatterns(owningPatterns); for (RegisteredOperationName op : context->getRegisteredOperations()) op.getCanonicalizationPatterns(owningPatterns, context); + // Folds of marked add / sub / mul chains that keep the mark (Passes.h). + polygeist::populateNoSignedWrapPatterns(owningPatterns); + polygeist::populateArrayArgumentPatterns(owningPatterns); patterns = std::make_shared( std::move(owningPatterns), disabledPatterns, enabledPatterns); diff --git a/lib/polygeist/Passes/RaiseToAffine.cpp b/lib/polygeist/Passes/RaiseToAffine.cpp index bcdb9fcef1dd..83b49be75862 100644 --- a/lib/polygeist/Passes/RaiseToAffine.cpp +++ b/lib/polygeist/Passes/RaiseToAffine.cpp @@ -26,6 +26,14 @@ struct RaiseSCFToAffine : public SCFRaiseToAffineBase { }; } // namespace +/// The upper bound `min(a, b)` of a counted loop (arith.minsi, also under an +/// index_cast) raises to an affine.for with a min bound (VITIS_NOTES N153: +/// `for (u = 0; u < 32 && k + u < B; ++u)`, WhileConjunctiveBound). +static llvm::cl::opt WhileConjunctiveMinBounds( + "raise-min-upper-bounds", llvm::cl::init(true), + llvm::cl::desc("Raise scf.for loops whose upper bound is an arith.minsi " + "to affine.for with a min bound (VITIS_NOTES N153)")); + struct ForOpRaising : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; @@ -91,6 +99,27 @@ struct ForOpRaising : public OpRewritePattern { if (isValidIndex(cur)) { ubs.push_back(cur); continue; + } else if (auto mn = cur.getDefiningOp(); + mn && WhileConjunctiveMinBounds) { + // UB min(a, b) on index (WhileConjunctiveBound's bound, + // VITIS_NOTES N153). + todo.push_back(mn.getLhs()); + todo.push_back(mn.getRhs()); + continue; + } else if (auto cast = cur.getDefiningOp(); + cast && WhileConjunctiveMinBounds) { + // index_cast(minsi(a, b)) = minsi(index_cast(a), index_cast(b)): + // index_cast sign-extends, which keeps the order. + if (auto mn = cast.getIn().getDefiningOp()) { + OpBuilder b(loop); + todo.push_back(b.create(cast.getLoc(), + b.getIndexType(), + mn.getLhs())); + todo.push_back(b.create(cast.getLoc(), + b.getIndexType(), + mn.getRhs())); + continue; + } } else if (auto selOp = cur.getDefiningOp()) { // UB only has min of operands if (auto cmp = selOp.getCondition().getDefiningOp()) { @@ -111,16 +140,54 @@ struct ForOpRaising : public OpRewritePattern { if (!loop.getStep().getDefiningOp()) { if (ubs.size() != 1 || lbs.size() != 1) return failure(); - ubs[0] = rewriter.create( - loop.getLoc(), - rewriter.create( - loop.getLoc(), - rewriter.create( - loop.getLoc(), loop.getStep(), - rewriter.create(loop.getLoc(), 1)), - rewriter.create(loop.getLoc(), loop.getUpperBound(), - loop.getLowerBound())), - loop.getStep()); + // The trip count is computed above every enclosing loop that does + // not define the bounds or the step, where it is a valid symbol like + // its operands: built next to the loop, inside an outer loop, the + // affine map composition below moves it there itself and loses track + // of the ops it moved (an assertion on a loop with a variable step + // `m += 1 << stage` inside a loop over k, hp_fft no_StagePipeline; + // CIRCT OPEN_ISSUES O76). + Operation *ip = loop; + auto definedIn = [](Value v, Operation *region) { + Operation *def = v.getDefiningOp(); + Region *r = def ? def->getParentRegion() + : v.cast().getParentRegion(); + return region->isAncestor(r->getParentOp()); + }; + while (Operation *parent = ip->getParentOp()) { + if (!isa( + parent) || + definedIn(loop.getStep(), parent) || + definedIn(loop.getUpperBound(), parent) || + definedIn(loop.getLowerBound(), parent)) + break; + ip = parent; + } + PatternRewriter::InsertionGuard tripGuard(rewriter); + rewriter.setInsertionPoint(ip); + // Hoisted above the guards and loops that protect the loop, the trip + // count also runs where the loop never would, so it must not trap: + // a zero step divides by one, and an empty range (ub <= lb) gives 0 + // instead of a huge unsigned quotient. Where the loop itself runs, + // the value is the plain (ub - lb + step - 1) / step (a step of 0 + // there is an endless C loop). `if (s > 0) for (i = 0; i < n; i += + // s)` inside another loop divided by zero (W9r7 review defect 1). + Location loc = loop.getLoc(); + Value zero = rewriter.create(loc, 0); + Value one = rewriter.create(loc, 1); + Value range = rewriter.create(loc, loop.getUpperBound(), + loop.getLowerBound()); + Value nonEmpty = + rewriter.create(loc, CmpIPredicate::sgt, range, zero); + Value roundedUp = rewriter.create( + loc, rewriter.create(loc, loop.getStep(), one), range); + Value numerator = + rewriter.create(loc, nonEmpty, roundedUp, zero); + Value stepIsZero = rewriter.create(loc, CmpIPredicate::eq, + loop.getStep(), zero); + Value divisor = + rewriter.create(loc, stepIsZero, one, loop.getStep()); + ubs[0] = rewriter.create(loc, numerator, divisor); lbs[0] = rewriter.create(loop.getLoc(), 0); rewrittenStep = true; } @@ -144,6 +211,9 @@ struct ForOpRaising : public OpRewritePattern { affine::AffineForOp affineLoop = rewriter.create( loop.getLoc(), lbs, lbMap, ubs, ubMap, getStep(loop.getStep()), loop.getInits()); + // The loop mark hls-est reads (Passes.h) moves to the affine loop. + if (Attribute mark = loop->getAttr(kUncountedLoopAttrName)) + affineLoop->setAttr(kUncountedLoopAttrName, mark); auto mergedYieldOp = cast(loop.getRegion().front().getTerminator()); diff --git a/patches/llvm-project/0001-xlx-bitwidth.patch b/patches/llvm-project/0001-xlx-bitwidth.patch new file mode 100644 index 000000000000..d944871bee04 --- /dev/null +++ b/patches/llvm-project/0001-xlx-bitwidth.patch @@ -0,0 +1,382 @@ +Squashed from the private llvm-project branch w11-real-headers (base 26eb4285b): + ac6056d62 [clang] Xilinx HLS bitwidth(N) attribute as _BitInt(N) (-fxlx-bitwidth), opt-in promotion (-fxlx-apint-promote) + 546cda75c [clang] -fxlx-bitwidth: own diagnostics for widths below 1 and above 8191; neutral template test (W11 review) +Apply with: git apply 0001-xlx-bitwidth.patch (in the llvm-project root). + +--- ac6056d62 [clang] Xilinx HLS bitwidth(N) attribute as _BitInt(N) (-fxlx-bitwidth), opt-in promotion (-fxlx-apint-promote) + +The Vitis HLS 2025.1 synthesis headers build ap_int / ap_fixed on +`int __attribute__((bitwidth(N))) V` (common/technology/autopilot/etc/ap_common.h:529-542); +upstream clang ignores the attribute, so every value became 32 bits. + +- Attr.td: XlxBitWidth, a GNU type attribute "bitwidth" with an expression argument + (ASTNode = 0, like vector_size). +- SemaType.cpp: HandleXlxBitWidthAttr builds _BitInt(N) / unsigned _BitInt(N) with the + signedness of the builtin integer base type, keeping qualifiers; a template-dependent N + gives DependentBitIntType (instantiation and deduction are upstream's). Signed width 1 + is accepted under the flag (ap_int<1>). Without -fxlx-bitwidth the attribute is + diagnosed and ignored exactly as before ("unknown attribute 'bitwidth' ignored"). +- SemaExpr.cpp UsualUnaryConversions: with -fxlx-apint-promote a _BitInt no wider than int + is promoted to int (unsigned int for an unsigned 32-bit one). +- LangOptions.def / Options.td: the two cc1 flags, off by default. + +Re-implemented (not copied) from hls-llvm-project (github.com/Xilinx/hls-llvm-project) +ee930469: clang/include/clang/Basic/Attr.td:554-559 (def BitWidth), +clang/lib/Sema/SemaType.cpp:2295 (BuildAPIntType) and :6867 (HandleBitWidthAttr), +clang/lib/Sema/SemaExpr.cpp:704 and clang/lib/AST/ASTContext.cpp:5553-5612 +(isPromotableIntegerOrAPIntType, getPromotedIntegerType); those are University of +Illinois/NCSA files with Xilinx additions. hls-llvm-project's APIntType / +DependentSizedAPIntType AST nodes are not ported: BitIntType covers them. + +Tests: clang/test/Sema/xlx-bitwidth.c, SemaCXX/xlx-bitwidth-template.cpp, +CodeGen/xlx-bitwidth.c. + +Co-Authored-By: Claude Opus 5.5 + +--- 546cda75c [clang] -fxlx-bitwidth: own diagnostics for widths below 1 and above 8191; neutral template test (W11 review) + +W11 review D4 and D5 (scratchpad w11/review.md): +- D4: under -fxlx-bitwidth every width from 1 up is valid for both signednesses, so + bitwidth(0) / bitwidth(-3) now report "bit width must be at least 1" instead of the + _BitInt message ("signed _BitInt must have a bit size of at least 2", or "greater + than 8388608" for a negative width). Widths above 8191, the ceiling of the + open-source Xilinx front end (hls-llvm-project ee930469 Type.h:1545 and :3131, + APIntType::isSizeTooLarge, used at SemaType.cpp:2320), get a warning; whether + Vitis 2025.1 has the same ceiling is unconfirmed. Custom diagnostic IDs keep the + private patch out of the diagnostic tables. Re-implemented from that behaviour, + not copied. +- D5: clang/test/SemaCXX/xlx-bitwidth-template.cpp no longer reproduces the shape of + the Vitis-installed ssdm_int partial specialisations (etc/ap_common.h:529-542, + the block the Apache-2.0 HLS_arbitrary_Precision_Types leaves out); it tests the + same behaviour (dependent width in fields, typedefs, parameters and locals; + deduction; constant evaluation) with neutral declarations written for the test. +- clang/test/Sema/xlx-bitwidth.c: the new diagnostics. + +Co-Authored-By: Claude Opus 5.5 + +diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td +index dd4d45171..d5998057b 100644 +--- a/clang/include/clang/Basic/Attr.td ++++ b/clang/include/clang/Basic/Attr.td +@@ -3013,6 +3013,19 @@ def Uuid : InheritableAttr { + let Documentation = [Undocumented]; + } + ++// Xilinx HLS arbitrary-precision integer attribute (the Vitis HLS headers' ++// ssdm_int). Re-implemented from hls-llvm-project ee930469 Attr.td:554-559 ++// (def BitWidth); here it is represented as BitIntType instead of a new ++// APIntType node, and is only honoured under -fxlx-bitwidth (otherwise it is ++// diagnosed and ignored exactly like an unknown attribute). ++def XlxBitWidth : TypeAttr { ++ let Spellings = [GNU<"bitwidth">]; ++ let Args = [ExprArgument<"BitWidth">]; ++ let Documentation = [Undocumented]; ++ // Represented as BitIntType instead. ++ let ASTNode = 0; ++} ++ + def VectorSize : TypeAttr { + let Spellings = [GCC<"vector_size">]; + let Args = [ExprArgument<"NumBytes">]; +diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def +index e18b5b80a..36b90adc0 100644 +--- a/clang/include/clang/Basic/LangOptions.def ++++ b/clang/include/clang/Basic/LangOptions.def +@@ -237,6 +237,9 @@ LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword") + LANGOPT(OpenCLPipes , 1, 0, "OpenCL pipes language constructs and built-ins") + LANGOPT(NativeHalfType , 1, 0, "Native half type support") + LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns") ++// Xilinx HLS front-end extensions (cgeist / hls-est, track W11). Off by default. ++LANGOPT(XlxBitWidth , 1, 0, "Xilinx HLS bitwidth(N) attribute as _BitInt(N)") ++LANGOPT(XlxAPIntPromote , 1, 0, "Xilinx HLS integer promotion of narrow _BitInt types") + LANGOPT(CUDA , 1, 0, "CUDA") + LANGOPT(HIP , 1, 0, "HIP") + LANGOPT(OpenMP , 32, 0, "OpenMP support and version of OpenMP (31, 40 or 45)") +diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td +index f8143651c..b4472e41b 100644 +--- a/clang/include/clang/Driver/Options.td ++++ b/clang/include/clang/Driver/Options.td +@@ -7418,6 +7418,14 @@ def fnative_half_arguments_and_returns : Flag<["-"], "fnative-half-arguments-and + HelpText<"Use the native __fp16 type for arguments and returns (and skip ABI-specific lowering)">, + MarshallingInfoFlag>, + ImpliedByAnyOf<[open_cl.KeyPath, render_script.KeyPath, hlsl.KeyPath]>; ++def fxlx_bitwidth : Flag<["-"], "fxlx-bitwidth">, ++ HelpText<"Treat the Xilinx HLS __attribute__((bitwidth(N))) on a builtin " ++ "integer type as _BitInt(N) (signed width 1 allowed)">, ++ MarshallingInfoFlag>; ++def fxlx_apint_promote : Flag<["-"], "fxlx-apint-promote">, ++ HelpText<"Apply the Xilinx HLS integer promotions to _BitInt types no wider " ++ "than int">, ++ MarshallingInfoFlag>; + def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">, + HelpText<"Set default calling convention">, + Values<"cdecl,fastcall,stdcall,vectorcall,regcall">, +diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp +index 92496b03e..f0a768441 100644 +--- a/clang/lib/Sema/SemaExpr.cpp ++++ b/clang/lib/Sema/SemaExpr.cpp +@@ -851,6 +851,24 @@ ExprResult Sema::UsualUnaryConversions(Expr *E) { + E = ImpCastExprToType(E, PTy, CK_IntegralCast).get(); + return E; + } ++ // Xilinx HLS (-fxlx-apint-promote): an arbitrary-precision integer no ++ // wider than int takes part in the integer promotions like a narrow ++ // builtin integer: it becomes int, or unsigned int for an unsigned one ++ // exactly as wide as int. Re-implemented from hls-llvm-project ee930469 ++ // SemaExpr.cpp:704 and ASTContext.cpp:5553 (isPromotableIntegerOrAPIntType) ++ // and :5575 (getPromotedIntegerType). ++ if (getLangOpts().XlxAPIntPromote) { ++ if (const auto *BIT = Ty->getAs()) { ++ uint64_t IntWidth = Context.getIntWidth(Context.IntTy); ++ if (BIT->getNumBits() <= IntWidth) { ++ QualType PT = (BIT->isUnsigned() && BIT->getNumBits() == IntWidth) ++ ? Context.UnsignedIntTy ++ : Context.IntTy; ++ E = ImpCastExprToType(E, PT, CK_IntegralCast).get(); ++ return E; ++ } ++ } ++ } + if (Context.isPromotableIntegerType(Ty)) { + QualType PT = Context.getPromotedIntegerType(Ty); + E = ImpCastExprToType(E, PT, CK_IntegralCast).get(); +diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp +index d13a5564e..a63bfa37a 100644 +--- a/clang/lib/Sema/SemaType.cpp ++++ b/clang/lib/Sema/SemaType.cpp +@@ -2361,8 +2361,25 @@ QualType Sema::BuildBitIntType(bool IsUnsigned, Expr *BitWidth, + if (ICE.isInvalid()) + return QualType(); + ++ // Xilinx HLS (-fxlx-bitwidth): every width from 1 up is valid, for both ++ // signednesses, so a width below 1 gets its own message instead of the ++ // _BitInt one (which says 2 for signed). The Xilinx front end rejects ++ // widths above 8191 (hls-llvm-project ee930469 Type.h:1545 and :3131, ++ // APIntType::isSizeTooLarge, used at SemaType.cpp:2320); whether Vitis ++ // 2025.1 has the same ceiling is unconfirmed, so that is a warning. ++ // Custom diagnostic IDs keep this private patch out of the diagnostic ++ // tables (no rebuild of every clang library that includes them). ++ if (getLangOpts().XlxBitWidth && (Bits.isNegative() || Bits.isZero())) { ++ Diag(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Error, ++ "bit width must be at least 1")); ++ return QualType(); ++ } ++ const uint64_t XlxMaxBitWidth = 8191; ++ + size_t NumBits = Bits.getZExtValue(); +- if (!IsUnsigned && NumBits < 2) { ++ // Xilinx HLS: ap_int<1> is a signed 1-bit integer. ++ bool AllowSigned1 = getLangOpts().XlxBitWidth && NumBits == 1; ++ if (!IsUnsigned && NumBits < 2 && !AllowSigned1) { + Diag(Loc, diag::err_bit_int_bad_size) << 0; + return QualType(); + } +@@ -2379,6 +2396,12 @@ QualType Sema::BuildBitIntType(bool IsUnsigned, Expr *BitWidth, + return QualType(); + } + ++ if (getLangOpts().XlxBitWidth && NumBits > XlxMaxBitWidth) ++ Diag(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Warning, ++ "bit width %0 exceeds %1, the largest " ++ "the Xilinx HLS front end accepts")) ++ << static_cast(NumBits) << XlxMaxBitWidth; ++ + return Context.getBitIntType(IsUnsigned, NumBits); + } + +@@ -8164,6 +8187,44 @@ void Sema::adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, + T = Context.getAdjustedType(T, Wrapped); + } + ++/// HandleXlxBitWidthAttr - the Xilinx HLS __attribute__((bitwidth(N))) on a ++/// builtin integer type (the Vitis HLS headers' ssdm_int, ap_common.h). ++/// Re-implemented from hls-llvm-project ee930469 SemaType.cpp:6867 ++/// (HandleBitWidthAttr) and :2295 (BuildAPIntType): the type becomes ++/// _BitInt(N) / unsigned _BitInt(N) with the signedness of the base type; a ++/// template-dependent N yields a DependentBitIntType. ++static void HandleXlxBitWidthAttr(QualType &CurType, ParsedAttr &Attr, ++ Sema &S) { ++ if (!S.getLangOpts().XlxBitWidth) { ++ // Same diagnostic as before the attribute was known. ++ S.Diag(Attr.getLoc(), diag::warn_unknown_attribute_ignored) ++ << Attr << Attr.getRange(); ++ Attr.setInvalid(); ++ return; ++ } ++ if (Attr.getNumArgs() != 1) { ++ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) ++ << Attr << 1; ++ Attr.setInvalid(); ++ return; ++ } ++ Qualifiers Quals = CurType.getQualifiers(); ++ QualType Base = CurType.getCanonicalType().getUnqualifiedType(); ++ if (!Base->isBuiltinType() || !Base->isIntegerType()) { ++ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type_str) ++ << Attr << Attr.isRegularKeywordAttribute() << "builtin integer types"; ++ Attr.setInvalid(); ++ return; ++ } ++ QualType T = S.BuildBitIntType(!Base->isSignedIntegerType(), ++ Attr.getArgAsExpr(0), Attr.getLoc()); ++ if (T.isNull()) { ++ Attr.setInvalid(); ++ return; ++ } ++ CurType = S.Context.getQualifiedType(T, Quals); ++} ++ + /// HandleVectorSizeAttribute - this attribute is only applicable to integral + /// and float scalars, although arrays, pointers, and function return values are + /// allowed in conjunction with this construct. Aggregates with this attribute +@@ -8700,6 +8761,11 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type, + distributeObjCPointerTypeAttr(state, attr, type); + attr.setUsedAsTypeAttr(); + break; ++ case ParsedAttr::AT_XlxBitWidth: ++ if (!attr.isInvalid()) ++ HandleXlxBitWidthAttr(type, attr, state.getSema()); ++ attr.setUsedAsTypeAttr(); ++ break; + case ParsedAttr::AT_VectorSize: + HandleVectorSizeAttr(type, attr, state.getSema()); + attr.setUsedAsTypeAttr(); +diff --git a/clang/test/CodeGen/xlx-bitwidth.c b/clang/test/CodeGen/xlx-bitwidth.c +new file mode 100755 +index 000000000..452c7656e +--- /dev/null ++++ b/clang/test/CodeGen/xlx-bitwidth.c +@@ -0,0 +1,17 @@ ++// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fxlx-bitwidth -emit-llvm -o - %s | FileCheck %s ++// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=OFF ++ ++typedef int __attribute__((bitwidth(17))) i17; ++typedef unsigned __attribute__((bitwidth(5))) u5; ++ ++// CHECK-LABEL: @add17( ++// CHECK: add nsw i17 ++// OFF-LABEL: @add17( ++// OFF: add nsw i32 ++i17 add17(i17 a, i17 b) { return a + b; } ++ ++// The usual arithmetic conversions of _BitInt: u5 + int is done in int. ++// CHECK-LABEL: @inc5( ++// CHECK: zext i5 %{{.*}} to i32 ++// CHECK: trunc i32 %{{.*}} to i5 ++u5 inc5(u5 a) { return a + 1; } +diff --git a/clang/test/Sema/xlx-bitwidth.c b/clang/test/Sema/xlx-bitwidth.c +new file mode 100755 +index 000000000..5c038b13b +--- /dev/null ++++ b/clang/test/Sema/xlx-bitwidth.c +@@ -0,0 +1,54 @@ ++// Xilinx HLS bitwidth(N) attribute (-fxlx-bitwidth): the type becomes _BitInt(N). ++// RUN: %clang_cc1 -fsyntax-only -fxlx-bitwidth -verify=on %s ++// RUN: %clang_cc1 -fsyntax-only -fxlx-bitwidth -fxlx-apint-promote -verify=on -DPROMOTE %s ++// RUN: %clang_cc1 -fsyntax-only -verify=off -DOFF %s ++ ++typedef int __attribute__((bitwidth(7))) i7; // off-warning {{unknown attribute 'bitwidth' ignored}} ++typedef unsigned __attribute__((bitwidth(12))) u12; // off-warning {{unknown attribute 'bitwidth' ignored}} ++ ++#ifdef OFF ++_Static_assert(__builtin_types_compatible_p(i7, int), ""); ++_Static_assert(__builtin_types_compatible_p(u12, unsigned), ""); ++#else ++_Static_assert(__builtin_types_compatible_p(i7, _BitInt(7)), ""); ++_Static_assert(__builtin_types_compatible_p(u12, unsigned _BitInt(12)), ""); ++ ++// Declarator position, as in the Vitis ssdm_int (ap_common.h). ++int x33 __attribute__((bitwidth(33))); ++_Static_assert(__builtin_types_compatible_p(__typeof__(x33), _BitInt(33)), ""); ++const unsigned cu5 __attribute__((bitwidth(5))) = 31; ++_Static_assert(__builtin_types_compatible_p(__typeof__(cu5), const unsigned _BitInt(5)), ""); ++ ++// Signed width 1 (ap_int<1>) is allowed under the flag. ++typedef int __attribute__((bitwidth(1))) i1; ++_Static_assert((i1)1 == -1, ""); ++ ++// Bad uses. ++float f __attribute__((bitwidth(3))); // on-error {{'bitwidth' attribute only applies to builtin integer types}} ++int w __attribute__((bitwidth(1, 2))); // on-error {{'bitwidth' attribute takes one argument}} ++int z __attribute__((bitwidth(0))); // on-error {{bit width must be at least 1}} ++unsigned uz __attribute__((bitwidth(0))); // on-error {{bit width must be at least 1}} ++int neg __attribute__((bitwidth(-3))); // on-error {{bit width must be at least 1}} ++// Vitis' AP_INT_MAX_W (x86-64 _BitInt has no smaller limit). ++int max __attribute__((bitwidth(4096))); ++int xmax __attribute__((bitwidth(8191))); ++// Above the open-source Xilinx front end's ceiling: accepted with a warning. ++int big __attribute__((bitwidth(9000))); // on-warning {{bit width 9000 exceeds 8191, the largest the Xilinx HLS front end accepts}} ++ ++i7 a; ++u12 b; ++unsigned __attribute__((bitwidth(32))) u32v; ++int __attribute__((bitwidth(33))) s33; ++#ifdef PROMOTE ++// Re-implemented Vitis promotion: no wider than int -> int (unsigned int for ++// an unsigned 32-bit one); wider types do not promote. ++_Static_assert(__builtin_types_compatible_p(__typeof__(a + a), int), ""); ++_Static_assert(__builtin_types_compatible_p(__typeof__(b << 1), int), ""); ++_Static_assert(__builtin_types_compatible_p(__typeof__(-u32v), unsigned int), ""); ++_Static_assert(__builtin_types_compatible_p(__typeof__(s33 + s33), _BitInt(33)), ""); ++_Static_assert(__builtin_types_compatible_p(__typeof__(~a), int), ""); ++#else ++_Static_assert(__builtin_types_compatible_p(__typeof__(a + a), _BitInt(7)), ""); ++_Static_assert(__builtin_types_compatible_p(__typeof__(b << 1), unsigned _BitInt(12)), ""); ++#endif ++#endif +diff --git a/clang/test/SemaCXX/xlx-bitwidth-template.cpp b/clang/test/SemaCXX/xlx-bitwidth-template.cpp +new file mode 100755 +index 000000000..d80b431a4 +--- /dev/null ++++ b/clang/test/SemaCXX/xlx-bitwidth-template.cpp +@@ -0,0 +1,50 @@ ++// Xilinx HLS bitwidth(N) with a template-dependent N. The declarations are ++// written for this test from the attribute's behaviour; none is taken from the ++// Vitis-installed headers. ++// RUN: %clang_cc1 -std=gnu++14 -fsyntax-only -fxlx-bitwidth -verify %s ++// expected-no-diagnostics ++ ++template struct SField { int v __attribute__((bitwidth(N))); }; ++template struct UField { unsigned v __attribute__((bitwidth(N))); }; ++template struct UTraits { ++ typedef unsigned __attribute__((bitwidth(N))) type; ++}; ++template struct STraits { ++ typedef int __attribute__((bitwidth(N))) type; ++}; ++ ++template struct same { static const bool value = false; }; ++template struct same { static const bool value = true; }; ++ ++static_assert(same::v), _BitInt(17)>::value, ""); ++static_assert(same::v), _BitInt(1)>::value, ""); ++static_assert(same::v), unsigned _BitInt(256)>::value, ""); ++static_assert(same::type, unsigned _BitInt(4096)>::value, ""); ++static_assert(same::type, _BitInt(5)>::value, ""); ++ ++// Deduction of N from the bit-precise type. ++template constexpr int width(_BitInt(N)) { return N; } ++template constexpr int uwidth(unsigned _BitInt(N)) { return N; } ++static_assert(width(SField<23>().v) == 23, ""); ++static_assert(uwidth(UField<70>().v) == 70, ""); ++ ++// A parameter with a dependent width, in constant evaluation: the argument ++// is converted to N bits. ++template constexpr long long narrow(int x __attribute__((bitwidth(N)))) { ++ return x; ++} ++static_assert(narrow<5>(31) == -1, ""); ++template ++constexpr unsigned long long unarrow(unsigned x __attribute__((bitwidth(N)))) { ++ return x; ++} ++static_assert(unarrow<9>(512) == 0, ""); ++ ++// A dependent-width local inside a function template. ++template constexpr unsigned long long mask(int lo, int hi) { ++ unsigned int m __attribute__((bitwidth(W))) = (unsigned _BitInt(W))-1; ++ m >>= (int)(W - (hi - lo + 1)); ++ return (unsigned long long)m; ++} ++static_assert(mask<12>(0, 3) == 0xF, ""); ++static_assert(mask<12>(2, 11) == 0x3FF, ""); diff --git a/patches/llvm-project/README.md b/patches/llvm-project/README.md new file mode 100644 index 000000000000..265a7e894b81 --- /dev/null +++ b/patches/llvm-project/README.md @@ -0,0 +1,45 @@ +# Patches to Polygeist's llvm-project + +Polygeist's `llvm-project/` is a checkout of upstream LLVM at +**`26eb4285b56edd8c897642078d91f16ff0fd3472`** (the revision in +`llvm-project/build/include/llvm/Support/VCSRevision.h`), detached, with its +git directory at `.git/modules/Polygeist/modules/llvm-project` of the HLS +repository (the `.git` file in `llvm-project/` points to a path that does not +exist, so use `GIT_DIR=/.git/modules/Polygeist/modules/llvm-project`). +The patches here are applied on top of it. The same change is committed there +as branch **`w11-xlx-bitwidth`** (`ac6056d62`, `546cda75c` on `26eb4285b`), +not checked out, so `llvm-project/build` is untouched; the private Release +build of that branch is `/home/peter/w11/llvm-build` (source +`/home/peter/w11/llvm-project`, the same commits), and the W11-integrate cgeist +(`/home/peter/w11/polygeist-build`) links against it. + +| Patch | What | Needed by | +|-------|------|-----------| +| `0001-xlx-bitwidth.patch` | clang: the Xilinx HLS `__attribute__((bitwidth(N)))` as `_BitInt(N)` under `-fxlx-bitwidth` (widths below 1 rejected with their own message, widths above 8191, the open-source Xilinx front end's ceiling, warned); the Vitis integer promotion of narrow `_BitInt` under `-fxlx-apint-promote`. Both cc1 flags are off by default; without them clang is unchanged. Squashed from the private branch `w11-real-headers` of `/home/peter/w11/llvm-project` (commits `ac6056d62`, `546cda75c`). | cgeist on the real Vitis HLS headers (track W11: `-Xclang -fxlx-bitwidth`, the hls-est harness's `--shim real`) | + +Apply and rebuild (Release is enough for cgeist; the patch touches `Attr.td`, +so most of clang rebuilds): + +```sh +cd && git apply /patches/llvm-project/0001-xlx-bitwidth.patch +ninja -C # then rebuild cgeist against it +``` + +Origin: re-implemented from hls-llvm-project (github.com/Xilinx/hls-llvm-project, +commit `ee930469`): `clang/include/clang/Basic/Attr.td:554-559`, +`clang/lib/Sema/SemaType.cpp:2295,2320,6867`, `clang/include/clang/AST/Type.h:1545,3131`, +`clang/lib/Sema/SemaExpr.cpp:704`, +`clang/lib/AST/ASTContext.cpp:5553-5612`. Those files are University of +Illinois/NCSA licensed; Xilinx's additions inside them carry only a +copyright line ("(C) Copyright 2016-2022 Xilinx, Inc."), no licence grant. +MEMOS decision #40 (hls-est tree) allows copying Xilinx's own Apache-2.0 files +(SemaXlxAttr.cpp, CGXlxAttr.cpp, ParseXlxPragma.cpp, CGFPGABuiltin.cpp, ...) +and says that Xilinx edits inside NCSA upstream files whose licence is not +stated are re-implemented, not copied; so this code was written anew from +their behaviour. + +The tests in the patch use declarations written for them from the attribute's +behaviour; none reproduces the Vitis-installed headers (the first version of +`SemaCXX/xlx-bitwidth-template.cpp`, in Polygeist commit `048ac028`, followed the +shape of the installed `etc/ap_common.h` `ssdm_int`; replaced in the W11 review +fixes). diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b48266d74d72..1efe66f7fdea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,3 +12,4 @@ add_lit_testsuite(check-polygeist-opt "Verify Polygeist passes perform correctly ) set_target_properties(check-polygeist-opt PROPERTIES FOLDER "Tests") +set_target_properties(check-cgeist PROPERTIES FOLDER "Tests") diff --git a/test/lit.cfg.py b/test/lit.cfg.py index 14be1508b64b..ef14577c8faf 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -63,6 +63,6 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) tool_dirs = [config.polygeist_tools_dir] -tools = ['polygeist-opt'] +tools = ['polygeist-opt', 'cgeist'] llvm_config.add_tool_substitutions(tools, tool_dirs) diff --git a/tools/cgeist/CMakeLists.txt b/tools/cgeist/CMakeLists.txt index fdcfad45f222..c3df49cdd3f6 100644 --- a/tools/cgeist/CMakeLists.txt +++ b/tools/cgeist/CMakeLists.txt @@ -1,136 +1,156 @@ set( LLVM_LINK_COMPONENTS - ${LLVM_TARGETS_TO_BUILD} - Analysis - CodeGen - Core - AggressiveInstCombine - InstCombine - Instrumentation - MC - IPO - MCParser - ObjCARCOpts - Option - ScalarOpts - Support - TransformUtils - Vectorize + ${LLVM_TARGETS_TO_BUILD} + Analysis + CodeGen + Core + AggressiveInstCombine + InstCombine + Instrumentation + MC + IPO + MCParser + ObjCARCOpts + Option + Passes + ScalarOpts + Support + TransformUtils + Vectorize ) +# The Xilinx HLS prelude (--xlx-prelude) is compiled into cgeist, so the binary +# needs no source tree at run time. +set(CGEIST_XLX_PRELUDE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/include/xlx/xlx_prelude.h") +file(READ "${CGEIST_XLX_PRELUDE_SRC}" CGEIST_XLX_PRELUDE) +configure_file(XlxPrelude.inc.in "${CMAKE_CURRENT_BINARY_DIR}/XlxPrelude.inc" @ONLY) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + "${CGEIST_XLX_PRELUDE_SRC}") + add_clang_executable(cgeist - driver.cc - Lib/CGStmt.cc - "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1_main.cpp" - "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1as_main.cpp" - "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1gen_reproducer_main.cpp" - Lib/pragmaHandler.cc - Lib/pragmaHandlerHLS.cc - Lib/HandleHLS.cc - Lib/AffineUtils.cc - Lib/ValueCategory.cc - Lib/utils.cc - Lib/IfScope.cc - Lib/TypeUtils.cc - Lib/CGCall.cc + driver.cc + Lib/CGStmt.cc + "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1_main.cpp" + "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1as_main.cpp" + "${LLVM_SOURCE_DIR}/../clang/tools/driver/cc1gen_reproducer_main.cpp" + Lib/pragmaHandler.cc + Lib/HLSPragma.cc + Lib/HLSAutoInline.cc + Lib/HLSPragmaMaterialize.cc + Lib/HLSPragmaParse.cc + Lib/HLSPragmaSema.cc + Lib/HLSPragmaSpec.cc + Lib/AffineUtils.cc + Lib/ValueCategory.cc + Lib/utils.cc + Lib/IfScope.cc + Lib/TypeUtils.cc + Lib/CGCall.cc + Lib/CGXlxBuiltin.cc + Lib/XlxDeadStore.cc + Lib/XlxLoopScalarPromote.cc + Lib/XlxMathCore.cc + Lib/XlxProxyScalarize.cc + Lib/XlxStringBits.cc ) if(POLYGEIST_ENABLE_CUDA) target_compile_definitions(cgeist - PRIVATE - POLYGEIST_ENABLE_CUDA=1 + PRIVATE + POLYGEIST_ENABLE_CUDA=1 ) add_dependencies(cgeist execution_engine_cuda_wrapper_binary_include) endif() if(POLYGEIST_ENABLE_ROCM) target_compile_definitions(cgeist - PRIVATE - POLYGEIST_ENABLE_ROCM=1 + PRIVATE + POLYGEIST_ENABLE_ROCM=1 ) add_dependencies(cgeist execution_engine_rocm_wrapper_binary_include) endif() install(TARGETS cgeist -EXPORT PolygeistTargets -RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR} -COMPONENT cgeist) + EXPORT PolygeistTargets + RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR} + COMPONENT cgeist) target_include_directories(cgeist PRIVATE - "${LLVM_SOURCE_DIR}/../clang/include" - "${CMAKE_BINARY_DIR}/tools/clang/include" + "${CMAKE_CURRENT_BINARY_DIR}" + "${LLVM_SOURCE_DIR}/../clang/include" + "${CMAKE_BINARY_DIR}/tools/clang/include" ) if(POLYGEIST_ENABLE_POLYMER) target_include_directories(cgeist PRIVATE - "${CMAKE_CURRENT_SOURCE_DIR}/../polymer/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../polymer/include" ) target_link_libraries(cgeist PRIVATE - PolymerTransforms + PolymerTransforms ) target_compile_definitions(cgeist - PRIVATE - POLYGEIST_ENABLE_POLYMER=1 + PRIVATE + POLYGEIST_ENABLE_POLYMER=1 ) endif() target_compile_definitions(cgeist PUBLIC -DLLVM_OBJ_ROOT="${LLVM_BINARY_DIR}") set(CGEIST_LIBS - MLIRPolygeist - MLIRPolygeistTransforms + MLIRPolygeist + MLIRPolygeistTransforms ) if(POLYGEIST_ENABLE_POLYMER) - list(APPEND CGEIST_LIBS - PolymerTransforms) + list(APPEND CGEIST_LIBS + PolymerTransforms) endif() list(APPEND CGEIST_LIBS - MLIRPolygeist + MLIRPolygeist - MLIRSupport - MLIRIR - MLIRAnalysis - MLIRLLVMDialect - MLIRNVVMDialect - MLIROpenMPDialect - MLIRGPUTransforms - MLIRTransforms - MLIRSCFToControlFlow - MLIRFuncToLLVM - MLIRFunctionInterfaces - MLIRAffineTransforms - MLIRAffineToStandard - MLIRMathToLLVM - MLIRTargetLLVMIRImport - MLIRSCFTransforms - MLIRPolygeistTransforms - MLIRLLVMToLLVMIRTranslation - MLIRSCFToOpenMP - MLIROpenMPToLLVM - MLIROpenMPToLLVMIRTranslation - MLIRGPUToNVVMTransforms - MLIRGPUToGPURuntimeTransforms - MLIRFuncAllExtensions - MLIRLLVMIRToLLVMTranslation - MLIRFromLLVMIRTranslationRegistration - MLIRAffineAnalysis - MLIRAnalysis - MLIRCastInterfaces - MLIRDialect - MLIROptLib - MLIRParser - MLIRPass - MLIRTransforms - MLIRTransformUtils - MLIRSupport - MLIRIR - MLIRCAPIRegisterEverything - MLIRBuiltinToLLVMIRTranslation + MLIRSupport + MLIRIR + MLIRAnalysis + MLIRLLVMDialect + MLIRNVVMDialect + MLIROpenMPDialect + MLIRGPUTransforms + MLIRTransforms + MLIRSCFToControlFlow + MLIRFuncToLLVM + MLIRFunctionInterfaces + MLIRAffineTransforms + MLIRAffineToStandard + MLIRMathToLLVM + MLIRTargetLLVMIRImport + MLIRSCFTransforms + MLIRPolygeistTransforms + MLIRLLVMToLLVMIRTranslation + MLIRSCFToOpenMP + MLIROpenMPToLLVM + MLIROpenMPToLLVMIRTranslation + MLIRGPUToNVVMTransforms + MLIRGPUToGPURuntimeTransforms + MLIRFuncAllExtensions + MLIRLLVMIRToLLVMTranslation + MLIRFromLLVMIRTranslationRegistration + MLIRAffineAnalysis + MLIRAnalysis + MLIRCastInterfaces + MLIRDialect + MLIROptLib + MLIRParser + MLIRPass + MLIRTransforms + MLIRTransformUtils + MLIRSupport + MLIRIR + MLIRCAPIRegisterEverything + MLIRBuiltinToLLVMIRTranslation - clangAST - clangBasic - clangCodeGen - clangDriver - clangFrontend - clangFrontendTool - clangLex - clangSerialization + clangAST + clangBasic + clangCodeGen + clangDriver + clangFrontend + clangFrontendTool + clangLex + clangSerialization ) target_link_libraries(cgeist PRIVATE ${CGEIST_LIBS}) diff --git a/tools/cgeist/Lib/CGCall.cc b/tools/cgeist/Lib/CGCall.cc index 9d8fa006d2cb..e1a3678d5e1e 100644 --- a/tools/cgeist/Lib/CGCall.cc +++ b/tools/cgeist/Lib/CGCall.cc @@ -6,8 +6,10 @@ // //===----------------------------------------------------------------------===// +#include "HLSPragma.h" #include "TypeUtils.h" #include "clang-mlir.h" +#include "XlxMathCore.h" #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/Math/IR/Math.h" @@ -22,6 +24,8 @@ using namespace mlir::arith; using namespace mlir::func; using namespace mlirclang; +extern llvm::cl::opt XlxPrelude; // driver.cc + extern llvm::cl::opt CStyleMemRef; /// Try to typecast the caller arg of type MemRef to fit the corresponding @@ -45,11 +49,102 @@ static mlir::Value castCallerMemRefArg(mlir::Value callerArg, srcShape[0] == ShapedType::kDynamic && std::equal(std::next(srcShape.begin()), srcShape.end(), std::next(dstShape.begin()))) { + // A static array seen through a cast to a dynamic first dimension + // (memref.get_global or memref.alloca, then memref.cast to ?xN) whose own + // first dimension differs from the parameter's: the chain of two + // casts folds into an invalid one, so with --hls-keep-misfit-inline-off + // (the call may stay) the static array is reinterpreted with the + // parameter's shape, as below (forgebench attn_breakdown: + // matmul_large(.., Q_weight_buffer[32][32], ..) with a [8][32] + // parameter; OPEN_ISSUES O167 in the hls-est tree). + mlir::Value staticSrc; + if (cgeist::hls::keepMisfitInlineOff()) + for (auto cast = callerArg.getDefiningOp(); + cast; cast = cast.getSource() + .getDefiningOp()) { + auto t = dyn_cast(cast.getSource().getType()); + if (t && t.hasStaticShape()) { + // Only a whole array (a global's memref.get_global, a local + // alloca, through casts that keep its type): a row view keeps + // its cast, as before. + mlir::Value whole = cast.getSource(); + while (auto same = whole.getDefiningOp()) { + if (same.getSource().getType() != whole.getType()) + break; + whole = same.getSource(); + } + if (whole.getDefiningOp() || + whole.getDefiningOp()) + staticSrc = whole; + break; + } + } + if (staticSrc) { + auto staticTy = cast(staticSrc.getType()); + if (dstTy.hasStaticShape() && + staticTy.getElementType() == dstTy.getElementType() && + staticTy.getRank() == dstTy.getRank() && + staticTy.getShape()[0] != dstShape[0] && + staticTy.getLayout().isIdentity() && + dstTy.getLayout().isIdentity()) { + b.setInsertionPointAfterValue(callerArg); + SmallVector strides(dstShape.size(), 1); + for (int k = static_cast(dstShape.size()) - 2; k >= 0; --k) + strides[k] = strides[k + 1] * dstShape[k + 1]; + return b.create( + callerArg.getLoc(), dstTy, staticSrc, /*offset*/ 0, + dstShape, strides); + } + } b.setInsertionPointAfterValue(callerArg); return b.create(callerArg.getLoc(), calleeArgType, callerArg); } + // A C array argument whose static shape differs from the parameter's + // (C ignores the first dimension of an array parameter, and a `T p[]` + // or `T *p` parameter takes any array): `g(x)` with `short x[4096]` and + // `void g(short a[])`, or `f(z)` with `short z[16]` and + // `void f(short a[4096])` (W8b, hls-doc/hlsfactory-v2.md class + // cgeist-invalid-mlir). A cast towards a dynamic shape is a valid + // memref.cast. Two static shapes that differ are not cast-compatible, + // and a chain of two casts through a dynamic shape is folded back into + // that invalid cast by memref.cast's folder, so the argument is + // reinterpreted with the parameter's own shape and row-major strides, + // which is how C addresses the parameter. Once the call is inlined, the + // accesses go back to the argument itself when only the first + // dimension differs (populateArrayArgumentPatterns). + // A pointer to an array, `(T (*)[8][8]) p`, is a memref of the array's + // own shape (memref<8x8xT>: cgeist's type for a pointer to an array is + // the pointee's), passed to a parameter `T a[4][8][8]` one rank higher + // with the same trailing shape. C addresses the parameter through the + // pointer, row-major from its first element, so the argument is + // re-typed through its address (class_ece8893_2023_spring GradCAM + // src_hls, W8b; it was an invalid func.call). + if (srcTy && srcShape.size() + 1 == dstShape.size() && + std::equal(srcShape.begin(), srcShape.end(), + std::next(dstShape.begin())) && + srcTy.getLayout().isIdentity() && dstTy.getLayout().isIdentity()) { + b.setInsertionPointAfterValue(callerArg); + mlir::Location loc = callerArg.getLoc(); + mlir::Value ptr = b.create( + loc, LLVM::LLVMPointerType::get(b.getI8Type()), callerArg); + return b.create(loc, dstTy, ptr); + } + if (srcTy && srcShape.size() == dstShape.size() && !srcShape.empty() && + srcTy.getLayout().isIdentity() && dstTy.getLayout().isIdentity()) { + b.setInsertionPointAfterValue(callerArg); + mlir::Location loc = callerArg.getLoc(); + if (mlir::memref::CastOp::areCastCompatible(srcTy, dstTy)) + return b.create(loc, dstTy, callerArg); + if (srcTy.hasStaticShape() && dstTy.hasStaticShape()) { + SmallVector strides(dstShape.size(), 1); + for (int k = static_cast(dstShape.size()) - 2; k >= 0; --k) + strides[k] = strides[k + 1] * dstShape[k + 1]; + return b.create( + loc, dstTy, callerArg, /*offset*/ 0, dstShape, strides); + } + } } } @@ -175,9 +270,23 @@ ValueCategory MLIRScanner::CallHelper( val); } if (auto prevTy = dyn_cast(val.getType())) { + // The argument is converted to the parameter's integer width + // explicitly (narrowing truncates; widening extends by the C + // signedness of the converted argument). + // (--scalar-wrapper-abi; with the option off, any mismatch is a + // trunci as before.) auto ipostTy = expectedType.cast(); - if (prevTy != ipostTy) + if (!ScalarWrapperABI) { + if (prevTy != ipostTy) + val = builder.create(loc, ipostTy, val); + } else if (prevTy.getWidth() > ipostTy.getWidth()) val = builder.create(loc, ipostTy, val); + else if (prevTy.getWidth() < ipostTy.getWidth()) { + if (aType->isUnsignedIntegerType() || prevTy.getWidth() == 1) + val = builder.create(loc, ipostTy, val); + else + val = builder.create(loc, ipostTy, val); + } } } } else { @@ -355,6 +464,47 @@ ValueCategory MLIRScanner::CallHelper( auto op = builder.create(loc, tocall, args); + // (--xlx-headers) A compound assignment (`/=`, `*=`, `+=`, `-=`, `++`, + // `--`) to an ap_fixed object: marked on the call, and by the inliner on + // the stores of its body (HLSPragma.cc). Vitis keeps two stores per bank for it when the + // array is partitioned and the bank index is not constant: the + // `if (!op) V = 0` at the head of the cross-format ap_fixed_base::operator= + // and the final store (CIRCT VITIS_NOTES N38 R-cmpd, kernels w9r_d1div / + // d2mul / d3add; a plain `A = w * A` replicates, w9r_d4asg). After cgeist's + // own store forwarding only the final store is left, so hls-est needs the + // mark to tell the two apart. + if (cgeist::hls::xlxHeaders()) + if (auto *oc = dyn_cast_or_null(expr)) { + clang::OverloadedOperatorKind k = oc->getOperator(); + if ((k == clang::OO_SlashEqual || k == clang::OO_StarEqual || + k == clang::OO_PlusEqual || k == clang::OO_MinusEqual || + // `++` / `--` go through operator+= / -= and the same + // cross-format operator= (Vitis: "store ... of constant 0", II 2; + // kernel w9r7rev_rc_inc, W9r7 review defect 5) + k == clang::OO_PlusPlus || k == clang::OO_MinusMinus) && + oc->getNumArgs() > 0) + if (const auto *rd = + oc->getArg(0)->getType()->getAsCXXRecordDecl()) + if (cgeist::hls::isApFixedClass(rd)) + op->setAttr("hls.ap_compound_assign", builder.getUnitAttr()); + } + + // (--xlx-headers) A call of an hls:: math function of hls_math.h is a core + // of the Vitis math library (XlxMathCore.h): marked on the call and on the + // callee, which is then never inlined. + if (auto *ce = dyn_cast_or_null(expr)) + if (auto core = cgeist::xlx::mathCoreOf(ce->getDirectCallee(), + Glob.CGM.getContext())) { + SmallVector fields = {builder.getNamedAttr( + "function", builder.getStringAttr(core->function))}; + if (!core->type.empty()) + fields.push_back( + builder.getNamedAttr("type", builder.getStringAttr(core->type))); + auto dict = builder.getDictionaryAttr(fields); + op->setAttr(cgeist::xlx::kMathCoreAttr, dict); + tocall->setAttr(cgeist::xlx::kMathCoreAttr, dict); + } + if (isArrayReturn) { // TODO remedy return if (retReference) @@ -584,6 +734,41 @@ MLIRScanner::EmitClangBuiltinCallExpr(clang::CallExpr *expr) { return make_pair(ValueCategory(), false); } +/// Whether `record` is std::ios_base or derives from it. +static bool derivesFromIosBase(const clang::CXXRecordDecl *record) { + if (!record || !record->hasDefinition()) + return false; + record = record->getDefinition(); + if (record->isInStdNamespace() && record->getIdentifier() && + record->getName() == "ios_base") + return true; + for (const clang::CXXBaseSpecifier &base : record->bases()) + if (derivesFromIosBase(base.getType()->getAsCXXRecordDecl())) + return true; + return false; +} + +/// Whether `type` (references removed) is a C++ standard stream: a class +/// that is or derives from std::ios_base (std::ostream, std::istream, their +/// file and string variants). +static bool isStdStreamType(clang::QualType type) { + return derivesFromIosBase( + type.getNonReferenceType().getCanonicalType()->getAsCXXRecordDecl()); +} + +/// Whether `call` is stream I/O whose value nothing needs: it returns +/// nothing or the stream itself, and its object or first argument is a +/// standard stream (`os << x`, `os.flush()`, `std::endl(os)`). +static bool isStreamIOCall(clang::CallExpr *call, clang::ASTContext &ctx) { + clang::QualType result = call->getCallReturnType(ctx); + if (!result->isVoidType() && !isStdStreamType(result)) + return false; + if (auto *member = dyn_cast(call)) + if (clang::Expr *object = member->getImplicitObjectArgument()) + return isStdStreamType(object->getType()); + return call->getNumArgs() > 0 && isStdStreamType(call->getArg(0)->getType()); +} + ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { auto loc = getMLIRLocation(expr->getExprLoc()); @@ -603,6 +788,62 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { } */ + // Console I/O through the C++ streams (`std::cout << x << std::endl;`, + // `std::cerr.flush()`) is no hardware: Vitis' reflow removes these calls + // (the Vitis 2025.1 run of class_ece8893_2023_spring YOLOv4-Tiny + // Maxpool_Layer: 29 ostream references in a.g.ld.5.gdce.ll, none in + // a.o.1.ll). cgeist used to emit them with the libstdc++ internals they + // call, whose `llvm.load` of a memref does not verify outside Polygeist. + // Only the arguments that have side effects are evaluated; a nested stream + // call among them is dropped the same way. + if (isStreamIOCall(expr, Glob.CGM.getContext())) { + auto evaluate = [&](clang::Expr *e) { + if (e && e->HasSideEffects(Glob.CGM.getContext())) + Visit(e); + }; + if (auto *member = dyn_cast(expr)) + evaluate(member->getImplicitObjectArgument()); + for (clang::Expr *arg : expr->arguments()) + evaluate(arg); + return ValueCategory(); + } + + // A builtin that clang evaluates to a constant of arithmetic type + // (`__builtin_inff()`, which 's INFINITY expands to, + // `__builtin_huge_val()`, `__builtin_nanf("")`): emit the constant. These + // builtins have no library definition, so a call to them could not be + // lowered or linked (W8b repro r_inff.c: `float m = -INFINITY;`). + if (expr->getBuiltinCallee() && expr->getType()->isArithmeticType() && + !expr->HasSideEffects(Glob.CGM.getContext())) { + clang::Expr::EvalResult res; + if (expr->EvaluateAsRValue(res, Glob.CGM.getContext()) && + !res.HasSideEffects) { + mlir::Type ty = getMLIRType(expr->getType()); + if (res.Val.isFloat()) + if (auto ft = dyn_cast(ty); + ft && &ft.getFloatSemantics() == &res.Val.getFloat().getSemantics()) + return ValueCategory( + builder.create(loc, res.Val.getFloat(), + ft), + /*isReference*/ false); + if (res.Val.isInt() && res.Val.getInt().getBitWidth() <= 64) + if (auto it = dyn_cast(ty)) + return ValueCategory( + builder.create( + loc, res.Val.getInt().getSExtValue(), it.getWidth()), + /*isReference*/ false); + } + } + + // Only callees named like the Xilinx HLS builtins (declared by the + // real-header prelude) are lowered here, and only under --xlx-prelude or + // --xlx-headers: without them such a call is emitted as before. + if (XlxPrelude || cgeist::hls::xlxHeaders()) { + auto xlx = EmitXlxBuiltin(expr); + if (xlx.second) + return xlx.first; + } + auto valEmitted = EmitGPUCallExpr(expr); if (valEmitted.second) return valEmitted.first; @@ -635,6 +876,22 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { } } } + // `x = y` on scalar wrappers with the trivial (defaulted) assignment: + // a load and a store, no call. + if (auto *oc = dyn_cast(expr)) { + if (oc->getOperator() == clang::OO_Equal && oc->getNumArgs() == 2) + if (auto *MD = dyn_cast_or_null(oc->getCalleeDecl())) + if (MD->isTrivial() && + (MD->isCopyAssignmentOperator() || + MD->isMoveAssignmentOperator()) && + Glob.getScalarWrapperField(MD->getParent())) { + ValueCategory lhs = Visit(oc->getArg(0)); + ValueCategory rhs = Visit(oc->getArg(1)); + assert(lhs.val && rhs.val && lhs.isReference); + lhs.store(loc, builder, rhs.getValue(loc, builder)); + return lhs; + } + } if (auto *oc = dyn_cast(expr)) { if (auto *lhs = dyn_cast(oc->getImplicitObjectArgument())) { expr->getCallee()->dump(); @@ -708,7 +965,12 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { if (auto *ic = dyn_cast(expr->getCallee())) if (auto *sr = dyn_cast(ic->getSubExpr())) { + // (--scalar-wrapper-abi: only for a floating first argument, so that + // hls::pow on an ap_fixed class stays a call; unchanged when off.) if (sr->getDecl()->getIdentifier() && + (!ScalarWrapperABI || + (expr->getNumArgs() == 2 && + expr->getArg(0)->getType()->isRealFloatingType())) && (sr->getDecl()->getName() == "__powf" || sr->getDecl()->getName() == "pow" || sr->getDecl()->getName() == "__nv_pow" || @@ -723,6 +985,25 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { for (auto *a : expr->arguments()) { args.push_back(Visit(a).getValue(loc, builder)); } + // A floating argument of another type than the result is converted + // to it first: libstdc++'s `std::pow(float, int)` is the promoted + // template whose parameters are (float, int) and whose result is + // double (C++11 [c.math]), computed as pow((double)x, (double)n). + // Without the conversion the op computed in float and claimed a + // double result (llvm.intr.powi(f32, i32) -> f64; CIRCT W9r14 + // review, kernel w9r14rv_pw_f32, OPEN_ISSUES O145). + auto toResultType = [&](mlir::Value v) -> mlir::Value { + auto from = v.getType().dyn_cast(); + auto to = mlirType.dyn_cast(); + if (!from || !to || from == to) + return v; + if (from.getWidth() < to.getWidth()) + return builder.create(loc, to, v); + return builder.create(loc, to, v); + }; + args[0] = toResultType(args[0]); + if (!args[1].getType().isa()) + args[1] = toResultType(args[1]); if (args[1].getType().isa()) return ValueCategory( builder.create(loc, mlirType, args[0], args[1]), @@ -750,7 +1031,13 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { sr->getDecl()->getName() == "fabs" || sr->getDecl()->getName() == "fabsf" || sr->getDecl()->getName() == "__builtin_fabs" || - sr->getDecl()->getName() == "__builtin_fabsf")) { + sr->getDecl()->getName() == "__builtin_fabsf") && + // Only the C library function on a number: an overload of the same + // name for a class (`fabs(ap_fixed)`, the Vitis hls_math + // overloads) is an ordinary call (W8b, flowgnn dgn and + // accelerators GP_selection: cast of a class value). + expr->getNumArgs() == 1 && + expr->getArg(0)->getType()->isArithmeticType()) { // isinf(x) --> fabs(x) == infinity // isfinite(x) --> fabs(x) != infinity // x != NaN via the ordered compare in either case. @@ -1939,7 +2226,28 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { return ValueCategory(); } - auto tocall = EmitDirectCallee(callee); + // (--xlx-headers) A member of hls::stream called on an object of a class + // derived from the member's class (hls::stream over + // hls::stream) is named as a member of the object's class. + const clang::CXXRecordDecl *xlxStreamObject = nullptr; + if (const auto *md = dyn_cast(callee); + md && Glob.isXlxStreamClass(md->getParent())) { + const clang::Expr *object = nullptr; + if (auto *mc = dyn_cast(expr)) + object = mc->getImplicitObjectArgument(); + else if (isa(expr) && expr->getNumArgs() > 0) + object = expr->getArg(0); + if (object) { + QualType t = object->IgnoreParenImpCasts()->getType(); + if (t->isPointerType()) + t = t->getPointeeType(); + xlxStreamObject = t->getAsCXXRecordDecl(); + } + } + auto tocall = xlxStreamObject + ? Glob.GetOrCreateMLIRFunction(callee, false, + xlxStreamObject) + : EmitDirectCallee(callee); SmallVector> args; QualType objType; diff --git a/tools/cgeist/Lib/CGStmt.cc b/tools/cgeist/Lib/CGStmt.cc index 6f27329d9f0a..77d3fec39f33 100644 --- a/tools/cgeist/Lib/CGStmt.cc +++ b/tools/cgeist/Lib/CGStmt.cc @@ -165,6 +165,7 @@ void MLIRScanner::buildAffineLoopImpl( loc, lb, builder.getSymbolIdentityMap(), ub, builder.getSymbolIdentityMap(), descr.getStep(), /*iterArgs=*/std::nullopt); + affineOp->setLoc(cgeist::hls::loopLocation(fors, loc)); auto ® = affineOp.getRegion(); @@ -211,6 +212,54 @@ void MLIRScanner::buildAffineLoop( buildAffineLoopImpl(fors, loc, lb, ub, descr); } +/// After a `break` a loop's condition is not evaluated: it may have side +/// effects (`do { if (..) break; } while (++i > 0);` must not increment i on +/// the break, `while (n--) { if (..) break; }` must not decrement n). The +/// condition is built inside `scf.if` on the no-break flag (else false), +/// between these two calls. Without a break the flag is the constant true and +/// the `scf.if` folds away. +static mlir::scf::IfOp beginNoBreakGuard(mlir::OpBuilder &builder, + mlir::Location loc, + mlir::Value noBreak) { + auto nb = builder.create(loc, noBreak, + std::vector()); + auto guard = builder.create( + loc, mlir::TypeRange{builder.getI1Type()}, nb, + /*withElseRegion=*/true); + builder.setInsertionPointToStart(&guard.getThenRegion().front()); + return guard; +} + +static mlir::Value endNoBreakGuard(mlir::OpBuilder &builder, + mlir::Location loc, mlir::scf::IfOp guard, + mlir::Value cond) { + builder.create(loc, cond); + builder.setInsertionPointToStart(&guard.getElseRegion().front()); + builder.create( + loc, mlir::ValueRange{builder.create( + loc, false, 1)}); + builder.setInsertionPointAfter(guard); + return guard.getResult(0); +} + +/// A while / do loop's condition is built while the loop is the innermost +/// one (`loops.back()`), so every statement-level guard in it (IfScope, e.g. +/// around a condition variable's declaration) reads this loop's keepRunning +/// flag. That flag is only set at the start of the body and cleared by a +/// `continue`, so the condition would read it uninitialised on the first test +/// (`while (int v = ..)` returned garbage) and false after a continue. Reset +/// it to the no-break flag before the condition: the condition runs exactly +/// when no break was taken. +static void storeKeepRunningForCondition(mlir::OpBuilder &builder, + mlir::Location loc, + const LoopContext &lctx) { + builder.create( + loc, + builder.create(loc, lctx.noBreak, + std::vector()), + lctx.keepRunning, std::vector()); +} + ValueCategory MLIRScanner::VisitForStmt(clang::ForStmt *fors) { IfScope scope(*this); @@ -247,6 +296,13 @@ ValueCategory MLIRScanner::VisitForStmt(clang::ForStmt *fors) { builder.setInsertionPointToStart(&condB); if (auto *s = fors->getCond()) { + mlir::scf::IfOp guard = beginNoBreakGuard(builder, loc, lctx.noBreak); + // `for (; int v = f();)`: the condition variable is initialised before + // each test, under the same no-break guard as the test (it may have + // side effects). It was never initialised before (the test read an + // undefined v). + if (auto *declStmt = fors->getConditionVariableDeclStmt()) + Visit(declStmt); auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); if (auto mt = dyn_cast(cond.getType())) { @@ -267,14 +323,14 @@ ValueCategory MLIRScanner::VisitForStmt(clang::ForStmt *fors) { loc, CmpIPredicate::ne, cond, builder.create(loc, 0, ty)); } - auto nb = builder.create( - loc, lctx.noBreak, std::vector()); - cond = builder.create(loc, cond, nb); - builder.create(loc, cond, &bodyB, &exitB); + cond = endNoBreakGuard(builder, loc, guard, cond); + builder.create( + cgeist::hls::loopLocation(fors, loc), cond, &bodyB, &exitB); } else { auto cond = builder.create( loc, lctx.noBreak, std::vector()); - builder.create(loc, cond, &bodyB, &exitB); + builder.create( + cgeist::hls::loopLocation(fors, loc), cond, &bodyB, &exitB); } builder.setInsertionPointToStart(&bodyB); @@ -340,6 +396,7 @@ ValueCategory MLIRScanner::VisitCXXForRangeStmt(clang::CXXForRangeStmt *fors) { builder.setInsertionPointToStart(&condB); if (auto *s = fors->getCond()) { + mlir::scf::IfOp guard = beginNoBreakGuard(builder, loc, lctx.noBreak); auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); if (auto LT = dyn_cast(cond.getType())) { @@ -353,14 +410,14 @@ ValueCategory MLIRScanner::VisitCXXForRangeStmt(clang::CXXForRangeStmt *fors) { loc, CmpIPredicate::ne, cond, builder.create(loc, 0, ty)); } - auto nb = builder.create(loc, lctx.noBreak, - std::vector()); - cond = builder.create(loc, cond, nb); - builder.create(loc, cond, &bodyB, &exitB); + cond = endNoBreakGuard(builder, loc, guard, cond); + builder.create( + cgeist::hls::loopLocation(fors, loc), cond, &bodyB, &exitB); } else { auto cond = builder.create( loc, lctx.noBreak, std::vector()); - builder.create(loc, cond, &bodyB, &exitB); + builder.create( + cgeist::hls::loopLocation(fors, loc), cond, &bodyB, &exitB); } builder.setInsertionPointToStart(&bodyB); @@ -738,8 +795,10 @@ ValueCategory MLIRScanner::VisitDoStmt(clang::DoStmt *fors) { builder.create(loc, &bodyB); builder.setInsertionPointToStart(&condB); + storeKeepRunningForCondition(builder, loc, loops.back()); if (auto *s = fors->getCond()) { + mlir::scf::IfOp guard = beginNoBreakGuard(builder, loc, loops.back().noBreak); auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); if (auto LT = dyn_cast(cond.getType())) { @@ -753,10 +812,9 @@ ValueCategory MLIRScanner::VisitDoStmt(clang::DoStmt *fors) { loc, CmpIPredicate::ne, cond, builder.create(loc, 0, ty)); } - auto nb = builder.create(loc, loops.back().noBreak, - std::vector()); - cond = builder.create(loc, cond, nb); - builder.create(loc, cond, &bodyB, &exitB); + cond = endNoBreakGuard(builder, loc, guard, cond); + builder.create( + cgeist::hls::loopLocation(fors, loc), cond, &bodyB, &exitB); } builder.setInsertionPointToStart(&bodyB); @@ -799,10 +857,14 @@ ValueCategory MLIRScanner::VisitWhileStmt(clang::WhileStmt *stmt) { builder.create(loc, &condB); builder.setInsertionPointToStart(&condB); + storeKeepRunningForCondition(builder, loc, loops.back()); - if (auto declStmt = stmt->getConditionVariableDeclStmt()) - Visit(declStmt); if (auto *s = stmt->getCond()) { + mlir::scf::IfOp guard = beginNoBreakGuard(builder, loc, loops.back().noBreak); + // `while (int v = f())`: the condition variable is initialised before + // each test, under the no-break guard (after a break neither runs). + if (auto declStmt = stmt->getConditionVariableDeclStmt()) + Visit(declStmt); auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); if (auto LT = dyn_cast(cond.getType())) { @@ -816,10 +878,9 @@ ValueCategory MLIRScanner::VisitWhileStmt(clang::WhileStmt *stmt) { loc, CmpIPredicate::ne, cond, builder.create(loc, 0, ty)); } - auto nb = builder.create(loc, loops.back().noBreak, - std::vector()); - cond = builder.create(loc, cond, nb); - builder.create(loc, cond, &bodyB, &exitB); + cond = endNoBreakGuard(builder, loc, guard, cond); + builder.create( + cgeist::hls::loopLocation(stmt, loc), cond, &bodyB, &exitB); } builder.setInsertionPointToStart(&bodyB); @@ -842,6 +903,9 @@ ValueCategory MLIRScanner::VisitWhileStmt(clang::WhileStmt *stmt) { ValueCategory MLIRScanner::VisitIfStmt(clang::IfStmt *stmt) { IfScope scope(*this); auto loc = getMLIRLocation(stmt->getIfLoc()); + // C++17 `if (init; cond)`: the init statement runs first (it was dropped). + if (auto *init = stmt->getInit()) + Visit(init); if (auto declStmt = stmt->getConditionVariableDeclStmt()) Visit(declStmt); auto cond = Visit(stmt->getCond()).getValue(loc, builder); @@ -888,6 +952,13 @@ ValueCategory MLIRScanner::VisitIfStmt(clang::IfStmt *stmt) { ValueCategory MLIRScanner::VisitSwitchStmt(clang::SwitchStmt *stmt) { IfScope scope(*this); + // `switch (init; int v = f())`: the init statement and the condition + // variable are evaluated before the condition (both were dropped, so the + // condition read an undefined v). + if (auto *init = stmt->getInit()) + Visit(init); + if (auto *declStmt = stmt->getConditionVariableDeclStmt()) + Visit(declStmt); auto cond = Visit(stmt->getCond()) .getValue(getMLIRLocation(stmt->getSwitchLoc()), builder); assert(cond != nullptr); @@ -1080,9 +1151,31 @@ ValueCategory MLIRScanner::VisitContinueStmt(clang::ContinueStmt *stmt) { return nullptr; } +/// A `goto` and the label it jumps to: cgeist's code for them is wrong +/// whatever their nesting (CIRCT OPEN_ISSUES O27: a forward `goto` out of an +/// if was dropped, held-out chstone dfadd / dfsin; a backward one made the +/// body run once; `goto skip; z = 7; skip:` at the top of a function still +/// ran `z = 7`, and the structured lowering after it fails on the +/// unreachable code once that is put in a block of its own). Reported as an +/// error rather than silently wrong code until a CFG lowering exists. +static bool reportStructuredGoto(MLIRScanner &scanner, mlir::Region *region, + mlir::func::FuncOp function, + clang::SourceLocation at, + clang::DiagnosticsEngine &diags, + llvm::StringRef what) { + diags.Report(at, diags.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "%0 is not supported by cgeist (its code would be " + "wrong)")) + << what; + return true; +} + ValueCategory MLIRScanner::VisitLabelStmt(clang::LabelStmt *stmt) { auto loc = getMLIRLocation(stmt->getIdentLoc()); auto *toadd = builder.getInsertionBlock()->getParent(); + // Only a label some `goto` jumps to (a label of a loop pragma, `L: for`, + // is fine): `goto` itself reports. Block *labelB; auto found = labels.find(stmt); if (found != labels.end()) { @@ -1100,6 +1193,10 @@ ValueCategory MLIRScanner::VisitLabelStmt(clang::LabelStmt *stmt) { ValueCategory MLIRScanner::VisitGotoStmt(clang::GotoStmt *stmt) { auto loc = getMLIRLocation(stmt->getGotoLoc()); + if (reportStructuredGoto(*this, builder.getInsertionBlock()->getParent(), + function, stmt->getGotoLoc(), Glob.CGM.getDiags(), + "'goto'")) + return nullptr; auto *labelstmt = stmt->getLabel()->getStmt(); Block *labelB; auto found = labels.find(labelstmt); @@ -1165,9 +1262,22 @@ ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) { auto postTy = returnVal.getType().cast().getElementType(); if (auto prevTy = dyn_cast(val.getType())) { + // Explicit width conversion of the returned integer (narrowing + // truncates; widening extends by the C signedness of the value). + // (--scalar-wrapper-abi; with the option off, any mismatch is a + // trunci as before.) auto ipostTy = postTy.cast(); - if (prevTy != ipostTy) { + if (!ScalarWrapperABI) { + if (prevTy != ipostTy) + val = builder.create(loc, ipostTy, val); + } else if (prevTy.getWidth() > ipostTy.getWidth()) val = builder.create(loc, ipostTy, val); + else if (prevTy.getWidth() < ipostTy.getWidth()) { + if (stmt->getRetValue()->getType()->isUnsignedIntegerType() || + prevTy.getWidth() == 1) + val = builder.create(loc, ipostTy, val); + else + val = builder.create(loc, ipostTy, val); } } else if (val.getType().isa() && postTy.isa()) diff --git a/tools/cgeist/Lib/CGXlxBuiltin.cc b/tools/cgeist/Lib/CGXlxBuiltin.cc new file mode 100644 index 000000000000..7b1639ef13fb --- /dev/null +++ b/tools/cgeist/Lib/CGXlxBuiltin.cc @@ -0,0 +1,519 @@ +// (C) Copyright 2016-2022 Xilinx, Inc. +// (C) Copyright 2023-2025 Advanced Micro Devices, Inc. +// All Rights Reserved. +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +//===----------------------------------------------------------------------===// +// +// cgeist lowering of the Xilinx HLS bit builtins that the Vitis HLS headers +// (common/technology/autopilot/etc/ap_common.h, autopilot_ssdm_bits.h, +// ap_int_base.h) call under __SYNTHESIS__. +// +// Origin: ported from hls-llvm-project (github.com/Xilinx/hls-llvm-project) +// commit ee930469, clang/lib/CodeGen/CGFPGABuiltin.cpp:1000-1677 +// (EmitBuiltinBitConcat, getRadix, EmitBuiltinBitFromString, +// EmitBuiltinBitSelect, EmitBuiltinBitSet, EmitBuiltinBitPartSelect, +// EmitBuiltinBitPartSet, EmitBuiltinBit{And,NAnd,Or,NOr,Xor,NXor}Reduce) and +// :1870-1905 (EmitBuiltinFPGACount{Leading,Trailing}Zero), under the Apache +// License 2.0 shown above. +// +// Changes from the original (Polygeist / cgeist, track W11, 2026-10): +// - Emits MLIR (arith / math) instead of LLVM IR; the bit reversal of a +// reversed range is expanded into shift / mask stages. +// - The operands' widths are recovered from the `(void*)&x` argument's +// pointee type in the clang AST instead of from the LLVM bitcast operand. +// - llvm.fpga.legacy.part.select / part.set are not emitted; their semantics +// are expanded into shift / mask / select ops. The expansion follows the +// constant folds of those intrinsics (hls-llvm-project ee930469, +// llvm/lib/Analysis/ConstantFolding.cpp:1368-1437, a University of +// Illinois/NCSA licensed file with Xilinx additions; re-implemented from +// its documented behaviour, not copied): bits [min(Lo,Hi), max(Lo,Hi)] are +// selected / replaced, and the field is bit-reversed when Lo > Hi. +// Lo or Hi outside the operand width is not folded by Vitis (its +// behaviour is unknown); here it gives the shift-and-mask result, which is +// unconfirmed. +// - The builtins are found by name; they are declared by cgeist's prelude +// (include/xlx/xlx_prelude.h) instead of Builtins.def. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "clang-mlir.h" +#include "mlir/Dialect/Arith/IR/Arith.h" +#include "mlir/Dialect/Math/IR/Math.h" +#include "clang/AST/Expr.h" +#include "llvm/ADT/APInt.h" +#include "llvm/Support/MathExtras.h" + +using namespace mlir; + +namespace { + +bool isXlxBuiltinName(llvm::StringRef name) { + return name.starts_with("__builtin_bit_") || name == "__fpga_ctlz" || + name == "__fpga_cttz" || name == "__fpga_shift_register_peek" || + name == "__fpga_shift_register_shift"; +} + +/// Port of getRadix (CGFPGABuiltin.cpp:1065): the radix of a decimal-radix +/// string with a 0 / 0x / 0b prefix; strips the prefix from `s`. 0: cannot +/// be processed. Unlike the original, `s` has no trailing NUL here (the +/// original's `length() - 1` counted it), and an empty digit string after a +/// prefix returns 0 instead of asserting. +uint32_t getRadix(std::string &s) { + std::string prefix = ""; + if (!s.empty() && (s[0] == '-' || s[0] == '+')) { + prefix += s[0]; + s = s.substr(1); + } + size_t len = s.length(); + if (len == 0) + return 0; + if (len == 1) { + if (s[0] <= '9' && s[0] >= '0') { + s = prefix + s; + return 10; + } + return 0; // only one char and it is not decimal + } + if (s[0] != '0') { + s = prefix + s; + return 10; + } + if (s[1] == 'x' || s[1] == 'X') { + if (len == 2) + return 0; // nothing follows the radix + s = prefix + s.substr(2); + return 16; + } + if (s[1] == 'b' || s[1] == 'B') { + if (len == 2) + return 0; + s = prefix + s.substr(2); + return 2; + } + s = prefix + s.substr(1); + return 8; +} + +} // namespace + +std::pair +MLIRScanner::EmitXlxBuiltin(clang::CallExpr *expr) { + const clang::FunctionDecl *FD = expr->getDirectCallee(); + if (!FD || !FD->getIdentifier() || isa(FD) || + !isXlxBuiltinName(FD->getName())) + return std::make_pair(ValueCategory(), false); + llvm::StringRef name = FD->getName(); + mlir::Location loc = getMLIRLocation(expr->getExprLoc()); + clang::DiagnosticsEngine &Diags = Glob.CGM.getDiags(); + auto done = [](ValueCategory v) { return std::make_pair(v, true); }; + + auto error = [&](const clang::Expr *at, llvm::StringRef msg) { + Diags.Report(at->getExprLoc(), + Diags.getCustomDiagID(clang::DiagnosticsEngine::Error, "%0")) + << msg; + }; + // Result of an int-returning builtin, or a placeholder after an error. + auto intResult = [&](mlir::Value bit) -> ValueCategory { + mlir::Type dest = getMLIRType(expr->getType()); + auto destTy = dest.dyn_cast(); + if (!destTy) + return ValueCategory(); + if (!bit) + return ValueCategory( + builder.create(loc, 0, destTy), false); + return ValueCategory(builder.create(loc, destTy, bit), + false); + }; + auto fail = [&](const clang::Expr *at, llvm::StringRef msg) { + error(at, msg); + return done(intResult(nullptr)); + }; + + auto constant = [&](mlir::IntegerType ty, const llvm::APInt &v) { + return builder + .create(loc, ty, builder.getIntegerAttr(ty, v)) + .getResult(); + }; + auto constantU = [&](mlir::IntegerType ty, uint64_t v) { + return constant(ty, llvm::APInt(64, v).zextOrTrunc(ty.getWidth())); + }; + // Zero-extend or truncate (CreateIntCast(..., /*isSigned=*/false)). + auto castTo = [&](mlir::Value v, mlir::IntegerType ty) -> mlir::Value { + unsigned from = v.getType().cast().getWidth(); + if (from == ty.getWidth()) + return v; + if (from < ty.getWidth()) + return builder.create(loc, ty, v); + return builder.create(loc, ty, v); + }; + + // The lvalue behind a `(void*)(&x)` argument (casts and parentheses + // stripped); the operand width is the width of its storage type, as with + // the original's pointer element type. + auto pointee = [&](clang::Expr *arg, ValueCategory &lv, + mlir::IntegerType &ty) -> bool { + auto *uo = dyn_cast(arg->IgnoreParenCasts()); + if (!uo || uo->getOpcode() != clang::UO_AddrOf) + return false; + ty = getMLIRType(uo->getSubExpr()->getType()) + .dyn_cast_or_null(); + if (!ty) + return false; + lv = Visit(uo->getSubExpr()); + return lv.val && lv.isReference; + }; + auto intArg = [&](clang::Expr *arg) -> mlir::Value { + mlir::Value v = Visit(arg).getValue(loc, builder); + if (!v || !v.getType().isa()) + return nullptr; + return castTo(v, builder.getI32Type()); + }; + + // A field [min(lo,hi), max(lo,hi)] of an iN value: the pieces shared by + // part_select and part_set. + struct Field { + mlir::Value reversed; ///< i1: lo > hi + mlir::Value low; ///< iN: min(lo, hi) + mlir::Value mask; ///< iN: n low ones, n = |hi - lo| + 1 + mlir::Value unusedHi; ///< iN: N - n + }; + auto field = [&](mlir::IntegerType ty, mlir::Value lo32, + mlir::Value hi32) -> Field { + Field F; + F.reversed = builder.create(loc, arith::CmpIPredicate::ugt, + lo32, hi32); + mlir::Value l = + builder.create(loc, F.reversed, hi32, lo32); + mlir::Value h = + builder.create(loc, F.reversed, lo32, hi32); + mlir::Value n32 = builder.create( + loc, builder.create(loc, h, l), + constantU(builder.getI32Type(), 1)); + F.low = castTo(l, ty); + F.unusedHi = builder.create( + loc, constantU(ty, ty.getWidth()), castTo(n32, ty)); + F.mask = builder.create( + loc, constant(ty, llvm::APInt::getAllOnes(ty.getWidth())), + F.unusedHi); + return F; + }; + // Bit-reverse the n low bits of v (bits above n are zero). Built from + // arith only (log2 swap stages at the next power-of-two width P), so that + // hls-est needs no new op and constant operands fold. + auto reverseLow = [&](mlir::Value v, const Field &F) -> mlir::Value { + auto ty = v.getType().cast(); + unsigned N = ty.getWidth(); + unsigned P = llvm::PowerOf2Ceil(N); + auto pty = builder.getIntegerType(P); + mlir::Value r = castTo(v, pty); + for (unsigned s = 1; s < P; s *= 2) { + // s ones, s zeros, repeated: 0x55.., 0x33.., 0x0F.., ... + llvm::APInt m(P, 0); + for (unsigned b = 0; b < P; ++b) + if ((b / s) % 2 == 0) + m.setBit(b); + mlir::Value mask = constant(pty, m); + mlir::Value sh = constantU(pty, s); + mlir::Value hi = builder.create( + loc, builder.create(loc, r, sh), mask); + mlir::Value lo = builder.create( + loc, builder.create(loc, r, mask), sh); + r = builder.create(loc, hi, lo); + } + // r holds the P-bit reversal; the n-bit field reversed is r >> (P - n). + mlir::Value amount = castTo(F.unusedHi, pty); + if (P != N) + amount = builder.create(loc, amount, + constantU(pty, P - N)); + r = builder.create(loc, r, amount); + return castTo(r, ty); + }; + auto partSelect = [&](mlir::Value val, mlir::Value lo32, + mlir::Value hi32) -> mlir::Value { + auto ty = val.getType().cast(); + Field F = field(ty, lo32, hi32); + mlir::Value fwd = builder.create( + loc, builder.create(loc, val, F.low), F.mask); + return builder.create(loc, F.reversed, + reverseLow(fwd, F), fwd); + }; + auto partSet = [&](mlir::Value val, mlir::Value rep, mlir::Value lo32, + mlir::Value hi32) -> mlir::Value { + auto ty = val.getType().cast(); + Field F = field(ty, lo32, hi32); + // Rep is cut or zero-extended to the field width (zextOrTrunc). + mlir::Value r = + builder.create(loc, castTo(rep, ty), F.mask); + r = builder.create(loc, F.reversed, reverseLow(r, F), r); + mlir::Value hole = builder.create( + loc, builder.create(loc, F.mask, F.low), + constant(ty, llvm::APInt::getAllOnes(ty.getWidth()))); + return builder.create( + loc, builder.create(loc, val, hole), + builder.create(loc, r, F.low)); + }; + + auto checkArgs = [&](unsigned n) { return expr->getNumArgs() == n; }; + std::string argError = "invalid arguments to '" + name.str() + "'"; + + // __builtin_bit_concat(R*, H*, L*): R = {H, L}. + if (name == "__builtin_bit_concat") { + ValueCategory R, H, L; + mlir::IntegerType RTy, HTy, LTy; + if (!checkArgs(3) || !pointee(expr->getArg(0), R, RTy) || + !pointee(expr->getArg(1), H, HTy) || + !pointee(expr->getArg(2), L, LTy)) + return fail(expr, "All three arguments to __builtin_bit_concat must be " + "int* typed"); + if (RTy.getWidth() != HTy.getWidth() + LTy.getWidth()) + return fail(expr->getArg(0), + "Invalid bit width for __builtin_bit_concat result"); + mlir::Value hi = castTo(H.getValue(loc, builder), RTy); + mlir::Value lo = castTo(L.getValue(loc, builder), RTy); + hi = builder.create(loc, hi, + constantU(RTy, LTy.getWidth())); + R.store(loc, builder, builder.create(loc, hi, lo)); + return done(ValueCategory()); + } + + // __builtin_bit_from_string(R*, "literal", radix): folded at compile time. + if (name == "__builtin_bit_from_string") { + ValueCategory R; + mlir::IntegerType RTy; + if (!checkArgs(3) || !pointee(expr->getArg(0), R, RTy)) + return fail(expr, "First argument to __builtin_bit_from_string must be " + "int* typed"); + auto *lit = + dyn_cast(expr->getArg(1)->IgnoreParenCasts()); + if (!lit || !lit->isOrdinary()) + return fail(expr->getArg(1), "Second argument to " + "__builtin_bit_from_string must be a " + "constant C string"); + clang::Expr::EvalResult radixEval; + if (!expr->getArg(2)->EvaluateAsInt(radixEval, Glob.CGM.getContext()) || + radixEval.Val.getInt().isZero()) + return fail(expr->getArg(2), "Third argument to " + "__builtin_bit_from_string must be a " + "constant int"); + uint64_t radix = radixEval.Val.getInt().getZExtValue(); + if (radix != 2 && radix != 8 && radix != 10 && radix != 16) + return fail(expr->getArg(2), "Third argument to " + "__builtin_bit_from_string must be 2, 8, " + "10 or 16"); + std::string str = lit->getString().str(); + if (radix == 10) + radix = getRadix(str); + if (radix == 0 || str.empty()) + return fail(expr->getArg(1), "Can not process radix for second " + "arguments of __builtin_bit_from_string"); + unsigned bits = RTy.getWidth(); + unsigned needed = llvm::APInt::getBitsNeeded(str, radix); + llvm::APInt v(needed, str, radix); + if (bits < needed) + v = v.trunc(bits); + else if (bits > needed) + v = str[0] == '-' ? v.sext(bits) : v.zext(bits); + R.store(loc, builder, constant(RTy, v)); + return done(ValueCategory()); + } + + // __builtin_bit_select(V*, bit): bit `bit` of V, zero-extended to int. + if (name == "__builtin_bit_select") { + ValueCategory V; + mlir::IntegerType VTy; + if (!checkArgs(2) || !pointee(expr->getArg(0), V, VTy)) + return fail(expr, "First argument to __builtin_bit_select must be int* " + "typed"); + mlir::Value bit = intArg(expr->getArg(1)); + if (!bit) + return fail(expr->getArg(1), "Second argument to __builtin_bit_select " + "must be an integer type"); + mlir::Value v = V.getValue(loc, builder); + mlir::Value sh = builder.create(loc, v, castTo(bit, VTy)); + return done(intResult( + builder.create(loc, builder.getI1Type(), sh))); + } + + // __builtin_bit_set(R*, V*, Rep*, bit) and + // __builtin_bit_part_set(R*, V*, Rep*, lo, hi): R = V with the field + // replaced by Rep. + if (name == "__builtin_bit_set" || name == "__builtin_bit_part_set") { + bool single = name == "__builtin_bit_set"; + ValueCategory R, V, Rep; + mlir::IntegerType RTy, VTy, RepTy; + if (!checkArgs(single ? 4 : 5) || !pointee(expr->getArg(0), R, RTy) || + !pointee(expr->getArg(1), V, VTy) || + !pointee(expr->getArg(2), Rep, RepTy)) + return fail(expr, argError + ": the first three must be int* typed"); + mlir::Value lo = intArg(expr->getArg(3)); + mlir::Value hi = single ? lo : intArg(expr->getArg(4)); + if (!lo || !hi) + return fail(expr, argError + ": the bit indices must be int typed"); + mlir::Value res = partSet(V.getValue(loc, builder), + Rep.getValue(loc, builder), lo, hi); + R.store(loc, builder, castTo(res, RTy)); + return done(ValueCategory()); + } + + // __builtin_bit_part_select(R*, V*, lo, hi): R = V[hi:lo] (reversed when + // lo > hi), zero-extended. + if (name == "__builtin_bit_part_select") { + ValueCategory R, V; + mlir::IntegerType RTy, VTy; + if (!checkArgs(4) || !pointee(expr->getArg(0), R, RTy) || + !pointee(expr->getArg(1), V, VTy)) + return fail(expr, argError + ": the first two must be int* typed"); + mlir::Value lo = intArg(expr->getArg(2)); + mlir::Value hi = intArg(expr->getArg(3)); + if (!lo || !hi) + return fail(expr, argError + ": the bit indices must be int typed"); + mlir::Value res = partSelect(V.getValue(loc, builder), lo, hi); + R.store(loc, builder, castTo(res, RTy)); + return done(ValueCategory()); + } + + // Reductions: __builtin_bit_{and,nand,or,nor,xor,nxor}_reduce(V*). + if (name.ends_with("_reduce")) { + llvm::StringRef op = name.drop_front(strlen("__builtin_bit_")) + .drop_back(strlen("_reduce")); + if (op != "and" && op != "nand" && op != "or" && op != "nor" && + op != "xor" && op != "nxor") + return fail(expr, "unsupported Xilinx HLS builtin '" + name.str() + "'"); + ValueCategory V; + mlir::IntegerType VTy; + if (!checkArgs(1) || !pointee(expr->getArg(0), V, VTy)) + return fail(expr, argError + ": the argument must be int* typed"); + mlir::Value v = V.getValue(loc, builder); + mlir::Value bit; + if (op == "and" || op == "nand") { + mlir::Value allOnes = + constant(VTy, llvm::APInt::getAllOnes(VTy.getWidth())); + bit = builder.create(loc, + op == "and" + ? arith::CmpIPredicate::eq + : arith::CmpIPredicate::ne, + v, allOnes); + } else if (op == "or" || op == "nor") { + bit = builder.create(loc, + op == "or" + ? arith::CmpIPredicate::ne + : arith::CmpIPredicate::eq, + v, constantU(VTy, 0)); + } else { + mlir::Value pop = builder.create(loc, v); + bit = builder.create(loc, builder.getI1Type(), pop); + if (op == "nxor") + bit = builder.create( + loc, bit, constantU(builder.getI1Type(), 1)); + } + return done(intResult(bit)); + } + + // __fpga_ctlz(x) / __fpga_cttz(x): count at the operand's own width, as an + // unsigned int (CGFPGABuiltin.cpp:1870-1905: an implicit conversion to int + // on the argument is looked through; zero gives the width). + if (name == "__fpga_ctlz" || name == "__fpga_cttz") { + if (!checkArgs(1)) + return fail(expr, argError); + clang::Expr *src = expr->getArg(0); + if (auto *ice = dyn_cast(src)) + if (const auto *BT = ice->getType()->getAs(); + BT && BT->getKind() == clang::BuiltinType::Int) + src = ice->getSubExpr(); + mlir::Value v = Visit(src).getValue(loc, builder); + if (!v || !v.getType().isa()) + return fail(expr, argError + ": the argument must be an integer"); + mlir::Value count = + name == "__fpga_ctlz" + ? builder.create(loc, v).getResult() + : builder.create(loc, v).getResult(); + count = castTo(count, builder.getI32Type()); + if (auto destTy = + getMLIRType(expr->getType()).dyn_cast()) + count = castTo(count, destTy); + return done(ValueCategory(count, false)); + } + + // ap_shift_reg (ap_shift_reg.h): `peek(Array, Addr)` reads Array[Addr]; + // `shift(DataIn, Array, Enable)` moves every element one place up + // (Array[i] = Array[i - 1]) and stores DataIn at 0 when Enable. The depth + // is the extent of the array the pointer argument is cast from (the + // header passes `(T *)Array` of `T Array[DEPTH]`). CIRCT OPEN_ISSUES O219 + // (Vitis_Libraries dsp 1-D FFT). + if (name == "__fpga_shift_register_peek" || + name == "__fpga_shift_register_shift") { + bool peek = name == "__fpga_shift_register_peek"; + if (expr->getNumArgs() != (peek ? 2u : 3u)) + return fail(expr, "wrong number of arguments to '" + name.str() + "'"); + clang::Expr *arrayArg = expr->getArg(peek ? 0 : 1); + ValueCategory ptr = Visit(arrayArg); + if (!ptr.val) + return fail(arrayArg, "cannot lower the shift register's array"); + if (peek) { + mlir::Value addr = Visit(expr->getArg(1)).getValue(loc, builder); + if (!addr || !addr.getType().isa()) + return fail(expr->getArg(1), "the address is not an integer"); + ValueCategory el = + CommonArrayLookup(loc, ptr, castToIndex(loc, addr, true), false); + return done(ValueCategory(el.getValue(loc, builder), false)); + } + const clang::ConstantArrayType *cat = + Glob.CGM.getContext().getAsConstantArrayType( + arrayArg->IgnoreParenCasts()->getType()); + if (!cat) + return fail(arrayArg, "the shift register is not a constant-size array"); + int64_t depth = cat->getSize().getSExtValue(); + mlir::Value in = Visit(expr->getArg(0)).getValue(loc, builder); + mlir::Value en = Visit(expr->getArg(2)).getValue(loc, builder); + if (!in || !en || !en.getType().isa()) + return fail(expr, "cannot lower the shift register's operands"); + auto enTy = en.getType().cast(); + mlir::Value cond = enTy.getWidth() == 1 + ? en + : builder.create( + loc, arith::CmpIPredicate::ne, en, + builder.create( + loc, 0, enTy)); + auto ifOp = builder.create(loc, cond, /*withElse=*/false); + mlir::OpBuilder::InsertionGuard guard(builder); + builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); + if (depth > 1) { + // for k in [0, depth - 1): i = depth - 1 - k; a[i] = a[i - 1] + auto c0 = builder.create(loc, 0); + auto c1 = builder.create(loc, 1); + auto last = builder.create(loc, depth - 1); + auto forOp = builder.create(loc, c0, last, c1); + builder.setInsertionPointToStart(forOp.getBody()); + mlir::Value i = builder.create( + loc, last, forOp.getInductionVar()); + mlir::Value prev = builder.create(loc, i, c1); + mlir::Value v = + CommonArrayLookup(loc, ptr, prev, false).getValue(loc, builder); + CommonArrayLookup(loc, ptr, i, false).store(loc, builder, v); + builder.setInsertionPointAfter(forOp); + } + CommonArrayLookup(loc, ptr, builder.create(loc, 0), + false) + .store(loc, builder, in); + return done(ValueCategory()); + } + + return fail(expr, "unsupported Xilinx HLS builtin '" + name.str() + "'"); +} diff --git a/tools/cgeist/Lib/HLSAutoInline.cc b/tools/cgeist/Lib/HLSAutoInline.cc new file mode 100644 index 000000000000..3ddcc1779371 --- /dev/null +++ b/tools/cgeist/Lib/HLSAutoInline.cc @@ -0,0 +1,1382 @@ +//===- HLSAutoInline.cc - Vitis automatic inlining decision ---------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// See HLSAutoInline.h for the rule and its evidence. +// +//===----------------------------------------------------------------------===// + +#include "HLSAutoInline.h" +#include "HLSPragma.h" + +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/ASTContext.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/SourceManager.h" +#include "clang/CodeGen/ModuleBuilder.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/MultiplexConsumer.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/Utils/StaticValueUtils.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/BuiltinOps.h" +#include "mlir/Interfaces/LoopLikeInterface.h" +#include "mlir/Pass/Pass.h" +#include "llvm/ADT/MapVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/ScalarEvolution.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Operator.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/IPO/AlwaysInliner.h" +#include "llvm/Transforms/Scalar/LoopPassManager.h" +#include "llvm/Transforms/Scalar/LoopRotation.h" +#include "llvm/Transforms/Scalar/LoopUnrollPass.h" +#include "llvm/Transforms/Utils/LCSSA.h" +#include "llvm/Transforms/Utils/LoopSimplify.h" +#include "llvm/Transforms/Utils/UnrollLoop.h" + +#include +#include +#include +#include +#include +#include + +using namespace cgeist::hls; + +static llvm::cl::opt HLSAutoInline( + "hls-auto-inline", llvm::cl::init(true), + llvm::cl::desc("With --hls-annotate: keep the calls Vitis does not inline " + "automatically (a callee without an inline pragma whose " + "size x calls exceeds the threshold, a dataflow process); " + "=false inlines them as cgeist did before (for " + "comparisons)")); + +static llvm::cl::opt HLSAutoInlineThreshold( + "hls-auto-inline-threshold", llvm::cl::init(100), + llvm::cl::desc("Largest size x calls Vitis inlines automatically (Vitis " + "2025.1: 100, VITIS_NOTES N18)")); + +static llvm::cl::opt HLSAutoInlineDataflow( + "hls-auto-inline-dataflow", llvm::cl::init(true), + llvm::cl::desc("Keep the calls at the top level of a function with " + "'#pragma HLS dataflow' and the calls to such a function, " + "whatever their size (Vitis keeps dataflow processes, " + "VITIS_NOTES N18)")); + +static llvm::cl::opt HLSAutoInlineRuntimeTripKept( + "hls-auto-inline-runtime-trip-kept", llvm::cl::init(true), + llvm::cl::desc("A loop marked for a complete unroll whose trip count is a " + "run-time value and whose maximum trip count exceeds " + "--hls-auto-inline-unroll-budget stays one loop in the " + "inline size count (VITIS_NOTES N161); off: it is " + "estimated at its maximum trip count")); + +static llvm::cl::opt HLSAutoInlineCallSiteConstantTrips( + "hls-auto-inline-callsite-constant-trips", llvm::cl::init(true), + llvm::cl::desc("Before measuring a function with a loop to unroll " + "completely whose trip count is a run-time value, replace " + "each integer parameter that every call passes as the " + "same constant by that constant, so the loop is counted " + "at the trip count the calls give it (Vitis unrolls it " + "inside the callee then: VITIS_NOTES N161 (b), kernel " + "w9r21rev_r9b_rtunroll_big); off: such a loop counts " + "once (N161)")); + +static llvm::cl::opt HLSAutoInlineUnrollBudget( + "hls-auto-inline-unroll-budget", llvm::cl::init(65536), + llvm::cl::desc("Designer knob: when the loops to unroll before measuring " + "would make a function larger than this many " + "instructions, its size and calls are estimated from the " + "trip counts instead of unrolling it (such a function is " + "kept by every caller; Vitis itself does not finish " + "unrolling e.g. lab2_hanchen)")); + +static llvm::cl::opt HLSAutoInlineRotatedSize( + "hls-auto-inline-rotated-size", llvm::cl::init(false), + llvm::cl::desc("Measure a function's size in loop-rotated form as Vitis' " + "step 2 counts it (VITIS_NOTES N131): after the proxy, " + "loop-rotate, instcombine, simplifycfg, dce; lifetime " + "markers do not count; plus one per loop with a variable " + "trip count and one per constant-trip loop after the " + "first among the loops at the top of the function or " + "directly in a variable-trip loop (the guard / exit " + "blocks LLVM 7's rotation keeps); an llvm.fmuladd counts " + "as the fmul + fadd Vitis' front end emits")); + +static llvm::cl::opt HLSAutoInlineCalleeUnroll( + "hls-auto-inline-callee-unroll", llvm::cl::init(true), + llvm::cl::desc("Before measuring, unroll the loops of every function " + "called (transitively) from a loop with a pipeline " + "pragma or from a pipelined function, as Vitis does " + "([HLS 214-291] 'implied by the pipeline pragma' for " + "callee loops, VITIS_NOTES N142: kernels w9r19p_iu_a / " + "iu_b / iu_d; an automatically pipelined loop does not, " + "iu_c); off: only the loops of the pipelined loop's own " + "function")); + +static llvm::cl::opt HLSAutoInlineReport( + "hls-auto-inline-report", llvm::cl::init(false), + llvm::cl::desc("Print every automatic inlining decision (caller, callee, " + "size, calls) to stderr")); + +static llvm::cl::opt HLSAutoInlineDump( + "hls-auto-inline-dump", llvm::cl::init(""), llvm::cl::Hidden, + llvm::cl::desc("Debugging: print the LLVM IR the size of every function " + "whose name contains this text is measured on (after the " + "simplification) to stderr")); + +namespace { + +/// A loop's start location as clang writes it into the loop metadata (the +/// `for` / `while` / `do` keyword). +struct LoopLoc { + std::string file; ///< basename of the presumed file name + unsigned line = 0, col = 0; + + bool matches(const llvm::DebugLoc &start) const { + return line == start.getLine() && col == start.getCol() && + file == llvm::sys::path::filename(start->getFilename()); + } +}; + +struct UnrollLoop : LoopLoc { + int64_t factor = 0; ///< 0 = complete, -1 = `unroll off` +}; + +/// One function of clang's IR after the size recipe. +struct FunctionSize { + int64_t size = 0; ///< instructions without sext / zext / trunc + bool returnsPointer = false; ///< pointer or reference return + bool alwaysInline = false; ///< `__attribute__((always_inline))` + bool estimated = false; ///< over the unroll budget: not unrolled + /// Direct calls to functions with a body, per callee, after the unroll. + std::map calls; +}; + +struct AutoInlineState { + std::vector unrollLoops; + std::vector pipelineLoops; + std::set pipelineFunctions; + /// The functions called, directly or through other functions, from a loop + /// with a pipeline pragma or from a pipelined function (N142): their loops + /// are unrolled before the size count like those of a pipelined function. + std::set reachedFromPipeline; + /// The always_inline functions; measure() inlines them into their callers + /// before it measures, while cgeist's MLIR still calls them. + std::set alwaysInline; + std::map functions; + bool measured = false; +}; + +AutoInlineState &state() { + static AutoInlineState s; + return s; +} + +//===----------------------------------------------------------------------===// +// Measuring clang's IR +//===----------------------------------------------------------------------===// + +/// The unroll factor of a loop: its own `#pragma HLS unroll`, else complete +/// when a pipelined loop encloses it or its function is pipelined (Vitis +/// unrolls those first: [HLS 214-291] "implied by the pipeline pragma", then +/// 214-186; w10rev rv_ai_pipe_inner, w10f_pipe_deep, w10f_fnpipe). nullopt: +/// not unrolled. +std::optional unrollFactor(llvm::Loop *L, bool functionPipelined) { + const AutoInlineState &st = state(); + llvm::DebugLoc start = L->getStartLoc(); + if (start) + for (const UnrollLoop &r : st.unrollLoops) + if (r.matches(start)) + return r.factor < 0 ? std::nullopt : std::optional(r.factor); + if (functionPipelined) + return 0; + for (llvm::Loop *p = L->getParentLoop(); p; p = p->getParentLoop()) + if (llvm::DebugLoc ps = p->getStartLoc()) + for (const LoopLoc &r : st.pipelineLoops) + if (r.matches(ps)) + return 0; + return std::nullopt; +} + +/// Gives the loops Vitis unrolls before the inline decision (unrollFactor) +/// LLVM's forced-unroll metadata. Returns whether any loop was marked. +bool markUnrollLoops(llvm::Function &F, llvm::LoopInfo &LI) { + const AutoInlineState &st = state(); + const bool functionPipelined = + st.pipelineFunctions.count(F.getName().str()) > 0 || + st.reachedFromPipeline.count(F.getName().str()) > 0; + if (st.unrollLoops.empty() && st.pipelineLoops.empty() && !functionPipelined) + return false; + bool any = false; + llvm::LLVMContext &ctx = F.getContext(); + for (llvm::Loop *L : LI.getLoopsInPreorder()) { + std::optional factor = unrollFactor(L, functionPipelined); + if (!factor) + continue; + llvm::SmallVector ops{nullptr}; + if (llvm::MDNode *old = L->getLoopID()) + for (unsigned i = 1; i < old->getNumOperands(); ++i) + ops.push_back(old->getOperand(i)); + if (*factor > 0) + ops.push_back(llvm::MDNode::get( + ctx, {llvm::MDString::get(ctx, "llvm.loop.unroll.count"), + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + llvm::Type::getInt32Ty(ctx), *factor))})); + else + ops.push_back(llvm::MDNode::get( + ctx, {llvm::MDString::get(ctx, "llvm.loop.unroll.full")})); + llvm::MDNode *id = llvm::MDNode::getDistinct(ctx, ops); + id->replaceOperandWith(0, id); + L->setLoopID(id); + any = true; + } + return any; +} + +/// How many copies of `L`'s body its unroll metadata asks for: the trip +/// count (else the maximum one, when the budget holds it) for a complete +/// unroll, the factor for a partial one, 1 otherwise. +/// +/// A loop whose trip count is a run-time value of its function (`for (i = 0; +/// i < length / 4; i++)` with `length` a parameter) is not unrolled before +/// the size count even when a pipeline pragma implies its complete unroll: +/// Vitis unrolls it only once inlining has made the trip constant +/// (VITIS_NOTES N161: class_ece8893 barry_walker lab2 +/// `accumulate_quarter_HLS`, `cmplx 002` 63 instructions in 4 blocks, then +/// `[HLS 214-186] Unrolling loop ... in function 'softmax_HLS' completely with +/// a factor of 25` after its `[HLS 214-178]` inlining). Its maximum trip +/// count (2^29 there) is no unroll LLVM performs either. +uint64_t unrollCopies(llvm::Loop *L, llvm::ScalarEvolution &SE, + uint64_t budget) { + llvm::MDNode *id = L->getLoopID(); + if (!id) + return 1; + if (llvm::GetUnrollMetadata(id, "llvm.loop.unroll.full")) { + if (unsigned n = SE.getSmallConstantTripCount(L)) + return n; + if (unsigned n = SE.getSmallConstantMaxTripCount(L)) + if (!HLSAutoInlineRuntimeTripKept || n <= budget) + return n; + return 1; + } + if (llvm::MDNode *count = llvm::GetUnrollMetadata(id, "llvm.loop.unroll.count")) + if (auto *c = llvm::mdconst::extract_or_null( + count->getOperand(1))) + return std::max(1, c->getZExtValue()); + return 1; +} + +/// Whether `F` has a loop that unrollFactor() unrolls completely and whose +/// trip count is not a constant. +static bool hasRuntimeTripCompleteUnroll(llvm::Function &F, llvm::LoopInfo &LI, + llvm::ScalarEvolution &SE) { + const AutoInlineState &st = state(); + const bool functionPipelined = + st.pipelineFunctions.count(F.getName().str()) > 0 || + st.reachedFromPipeline.count(F.getName().str()) > 0; + for (llvm::Loop *L : LI.getLoopsInPreorder()) { + std::optional factor = unrollFactor(L, functionPipelined); + if (factor && *factor == 0 && !SE.getSmallConstantTripCount(L)) + return true; + } + return false; +} + +/// Replaces each integer parameter of `F` that every call of `F` passes as +/// one and the same constant by that constant (interprocedural constant +/// propagation of the arguments). Returns whether anything was replaced. +/// Nothing happens when `F` has no call, or a use that is not the callee of +/// a direct call (an address taken). +/// +/// VITIS_NOTES N161 (b): Vitis propagates such a constant into the callee +/// before it unrolls and measures it: kernel w9r21rev_r9b_rtunroll_big +/// (`accq(row, wl, d, 64)`, the one call; `for (i = 0; i < length / 4; i++)` +/// under `#pragma HLS unroll`): `[HLS 214-186] Unrolling loop +/// 'VITIS_LOOP_5_1' ... in function 'accq' completely with a factor +/// of 16`, csynth_design_size.rpt accq 895 after the unroll, kept +/// (own module grp_accq_short_s). Calls that pass different constants +/// (barry_walker lab2: `accumulate_quarter_HLS(..., dk)` and `(..., N)`) or +/// a run-time value (w9r21rev_r9a_rtunroll) leave the parameter alone, and +/// Vitis inlines those callees before it unrolls the loop (N161). +static bool propagateCallSiteConstants(llvm::Function &F) { + llvm::SmallVector calls; + for (llvm::Use &use : F.uses()) { + auto *call = llvm::dyn_cast(use.getUser()); + if (!call || !call->isCallee(&use) || + call->arg_size() != F.arg_size()) + return false; + calls.push_back(call); + } + if (calls.empty()) + return false; + bool changed = false; + for (llvm::Argument &arg : F.args()) { + if (!arg.getType()->isIntegerTy() || arg.use_empty()) + continue; + auto *value = llvm::dyn_cast( + calls.front()->getArgOperand(arg.getArgNo())); + if (!value) + continue; + if (!llvm::all_of(calls, [&](llvm::CallBase *call) { + return call->getArgOperand(arg.getArgNo()) == value; + })) + continue; + arg.replaceAllUsesWith(value); + changed = true; + } + return changed; +} + +/// Whether a call of `callee` counts as a call of another design function. +/// A declaration counts too: with several translation units, the callee may +/// be defined in another one (Vitis links the units before it inlines, so +/// `top` in a.cpp calling `big` of b.cpp follows the size rule; before, such +/// a call was not counted and the inliner always inlined it: class_ece8893 +/// FLAT-acceleration's computeLogit / computeAttention, which Vitis keeps). +/// A callee no unit defines has no measured size and is left to the inliner +/// (MarkAutoInlinePass skips it); intrinsics never count. +static bool countsAsDesignCall(const llvm::Function *callee) { + return callee && !callee->isIntrinsic(); +} + +/// `F`'s size and calls as if its marked loops were unrolled: every block +/// counted once per copy of each enclosing marked loop (no simplification). +/// Counting stops (saturates) above `budget`. +FunctionSize estimateUnrolled(llvm::Function &F, llvm::LoopInfo &LI, + llvm::ScalarEvolution &SE, uint64_t budget) { + FunctionSize fs; + std::map copies; + auto copiesOf = [&](llvm::BasicBlock &BB) { + uint64_t m = 1; + for (llvm::Loop *L = LI.getLoopFor(&BB); L; L = L->getParentLoop()) { + auto it = copies.find(L); + if (it == copies.end()) + it = copies.emplace(L, unrollCopies(L, SE, budget)).first; + m = std::min(m * it->second, budget + 1); + } + return m; + }; + uint64_t size = 0; + for (llvm::BasicBlock &BB : F) { + uint64_t m = copiesOf(BB); + for (llvm::Instruction &I : BB) { + if (llvm::isa(I)) + continue; + size = std::min(size + m, budget + 1); + if (auto *call = llvm::dyn_cast(&I)) + if (llvm::Function *callee = call->getCalledFunction()) + if (countsAsDesignCall(callee)) + fs.calls[callee->getName().str()] += m; + } + } + fs.size = static_cast(size); + return fs; +} + +/// The integer a pointer operand of a Xilinx builtin points at: the +/// allocated / element / global type, or the type of a store into it just +/// before `at` or of a load from it, descending into the first member of a +/// struct or array (an ap_int's `V`). Null when no integer is found. +static llvm::IntegerType *builtinOperandType(llvm::Value *ptr, + llvm::Instruction *at) { + llvm::Value *p = ptr->stripPointerCasts(); + llvm::Type *t = nullptr; + if (auto *a = llvm::dyn_cast(p)) + t = a->getAllocatedType(); + else if (auto *g = llvm::dyn_cast(p)) + t = g->getResultElementType(); + else if (auto *gv = llvm::dyn_cast(p)) + t = gv->getValueType(); + if (!t) + for (llvm::Instruction *i = at->getPrevNode(); i && !t; + i = i->getPrevNode()) + if (auto *st = llvm::dyn_cast(i)) + if (st->getPointerOperand() == ptr) + t = st->getValueOperand()->getType(); + if (!t) + for (llvm::User *u : ptr->users()) + if (auto *ld = llvm::dyn_cast(u)) { + t = ld->getType(); + break; + } + while (t) { + if (auto *it = llvm::dyn_cast(t)) + return it; + if (auto *st = llvm::dyn_cast(t)) + t = st->getNumElements() ? st->getElementType(0) : nullptr; + else if (auto *at2 = llvm::dyn_cast(t)) + t = at2->getNumElements() ? at2->getElementType() : nullptr; + else + t = nullptr; + } + return nullptr; +} + +/// cgeist lowers the Xilinx HLS builtins of the real Vitis headers +/// (include/xlx/xlx_prelude.h: __builtin_bit_*, __fpga_fifo_pop / push) in +/// its MLIR codegen; the LLVM IR measured here sees them as calls of external +/// functions that take their operands through pointers, which keeps every +/// operand in a stack slot (SROA cannot promote an escaping alloca): an +/// alloca, a store and the call per use, where Vitis's front end emits a +/// load, one `llvm.fpga.*` intrinsic call (or, for a concatenation, a shl +/// and an or) and a store (hls-llvm-project CGFPGABuiltin.cpp, +/// EmitBuiltinBit*), which its simplification turns into one instruction. +/// GradCAM's `cam_core` measured 102 with the external calls (kept) and is +/// inlined by Vitis ([HLS 214-178]). Rewrite each such call the way Vitis's +/// front end emits it, with an opaque `readnone` function standing for the +/// intrinsic, so that the operands' slots promote and the count matches. +/// Calls whose operand types cannot be found are left as they are. +static void lowerXilinxBuiltinsForMeasure(llvm::Module &M) { + llvm::LLVMContext &ctx = M.getContext(); + auto opaque = [&](llvm::StringRef name, llvm::Type *ret, + llvm::ArrayRef args, bool pure) { + std::string full = ("__xlx_measure." + name).str(); + for (llvm::Type *a : args) + full += "." + std::to_string(a->isIntegerTy() + ? a->getIntegerBitWidth() + : 0u); + if (ret->isIntegerTy()) + full += ".r" + std::to_string(ret->getIntegerBitWidth()); + llvm::FunctionCallee fc = M.getOrInsertFunction( + full, llvm::FunctionType::get(ret, args, false)); + if (auto *f = llvm::dyn_cast(fc.getCallee())) { + f->addFnAttr(llvm::Attribute::NoUnwind); + if (pure) { + f->setDoesNotAccessMemory(); + f->addFnAttr(llvm::Attribute::WillReturn); + } + } + return fc; + }; + std::vector calls; + for (llvm::Function &F : M) + for (llvm::Instruction &I : llvm::instructions(F)) + if (auto *c = llvm::dyn_cast(&I)) + if (llvm::Function *callee = c->getCalledFunction()) + if (callee->isDeclaration() && + (callee->getName().starts_with("__builtin_bit_") || + callee->getName() == "__fpga_fifo_pop" || + callee->getName() == "__fpga_fifo_push")) + calls.push_back(c); + for (llvm::CallInst *c : calls) { + llvm::StringRef name = c->getCalledFunction()->getName(); + llvm::IRBuilder<> b(c); + unsigned n = c->arg_size(); + auto ty = [&](unsigned i) { return builtinOperandType(c->getArgOperand(i), c); }; + auto load = [&](unsigned i, llvm::IntegerType *t) { + return b.CreateLoad(t, c->getArgOperand(i)); + }; + llvm::Value *result = nullptr; // the call's own result, if any + bool done = false; + if ((name == "__builtin_bit_select" && n == 2) || + (name.ends_with("_reduce") && n == 1)) { + if (llvm::IntegerType *t = ty(0)) { + llvm::SmallVector args{load(0, t)}; + llvm::SmallVector types{t}; + if (n == 2) { + args.push_back(c->getArgOperand(1)); + types.push_back(c->getArgOperand(1)->getType()); + } + result = b.CreateCall( + opaque(name.drop_front(10), c->getType(), types, true), args); + done = true; + } + } else if (name == "__builtin_bit_concat" && n == 3) { + llvm::IntegerType *r = ty(0), *hi = ty(1), *lo = ty(2); + if (r && hi && lo) { + llvm::Value *h = b.CreateZExtOrTrunc(load(1, hi), r); + llvm::Value *l = b.CreateZExtOrTrunc(load(2, lo), r); + llvm::Value *v = b.CreateOr( + b.CreateShl(h, llvm::ConstantInt::get(r, lo->getBitWidth())), l); + b.CreateStore(v, c->getArgOperand(0)); + done = true; + } + } else if (name.starts_with("__builtin_bit_") && n >= 2 && + c->getType()->isVoidTy()) { + // set / part_select / part_set / from_string: result through arg 0, + // the other pointer operands loaded, the rest passed on. + if (llvm::IntegerType *r = ty(0)) { + llvm::SmallVector args; + llvm::SmallVector types; + bool ok = true; + for (unsigned i = 1; i < n && ok; ++i) { + llvm::Value *a = c->getArgOperand(i); + if (a->getType()->isPointerTy() && + name != "__builtin_bit_from_string") { + llvm::IntegerType *t = ty(i); + ok = t != nullptr; + if (ok) + a = load(i, t); + } + if (ok) { + args.push_back(a); + types.push_back(a->getType()); + } + } + if (ok) { + llvm::Value *v = + b.CreateCall(opaque(name.drop_front(10), r, types, true), args); + b.CreateStore(v, c->getArgOperand(0)); + done = true; + } + } + } else if (name == "__fpga_fifo_pop" && n == 2) { + if (llvm::IntegerType *t = ty(1)) { + llvm::Value *v = b.CreateCall( + opaque("fifo_pop", t, {c->getArgOperand(0)->getType()}, false), + {c->getArgOperand(0)}); + b.CreateStore(v, c->getArgOperand(1)); + done = true; + } + } else if (name == "__fpga_fifo_push" && n == 2) { + if (llvm::IntegerType *t = ty(1)) { + b.CreateCall(opaque("fifo_push", llvm::Type::getVoidTy(ctx), + {c->getArgOperand(0)->getType(), t}, false), + {c->getArgOperand(0), load(1, t)}); + done = true; + } + } + if (!done) + continue; + if (result) + c->replaceAllUsesWith(b.CreateZExtOrTrunc(result, c->getType())); + else if (!c->use_empty()) + c->replaceAllUsesWith(llvm::UndefValue::get(c->getType())); + c->eraseFromParent(); + } +} + +/// Whether `F` is a member of one of the ap_int / ap_fixed classes or their +/// bases and proxies (ap_int_base, ap_fixed_base, ap_bit_ref, af_range_ref, +/// ...): its mangled name is a nested name whose first component is such a +/// class (`_ZN13ap_fixed_baseILi16E...EC2Ed`, `_ZNK11ap_int_base...`). The +/// headers mark these AP_NODEBUG, so they carry no debug location to go by; +/// the demangled name would not do either (a free template function's +/// starts with its return type, `ap_fixed<16, 2> hls::sinpi<...>`). +static bool isApClassHeaderFunction(const llvm::Function &F) { + llvm::StringRef n = F.getName(); + if (!n.consume_front("_ZN")) + return false; + n.consume_front("K"); + unsigned len = 0; + if (n.consumeInteger(10, len) || len < 3 || n.size() < len) + return false; + llvm::StringRef cls = n.take_front(len); + return cls.starts_with("ap_") || cls.starts_with("af_"); +} + +/// Folds the stand-ins lowerXilinxBuiltinsForMeasure made whose operands +/// all became constants (after SROA and constant propagation), as LLVM's +/// constant folding of the `llvm.fpga.*` intrinsics does in Vitis's flow +/// (hls-llvm-project ConstantFolding.cpp): the double constructor of +/// ap_fixed_base selects the fields of a constant double's bits and folds +/// away. Returns whether anything was folded. +static bool foldConstantBuiltinStandIns(llvm::Function &F) { + std::vector> folds; + for (llvm::Instruction &I : llvm::instructions(F)) { + auto *c = llvm::dyn_cast(&I); + llvm::Function *callee = c ? c->getCalledFunction() : nullptr; + if (!callee || !callee->getName().starts_with("__xlx_measure.") || + !c->getType()->isIntegerTy()) + continue; + llvm::SmallVector a; + for (llvm::Value *v : c->args()) { + auto *ci = llvm::dyn_cast(v); + if (!ci) + break; + a.push_back(ci->getValue()); + } + if (a.size() != c->arg_size()) + continue; + llvm::StringRef kind = + callee->getName().drop_front(strlen("__xlx_measure.")).split('.').first; + unsigned rw = c->getType()->getIntegerBitWidth(); + auto pos = [](const llvm::APInt &v) { return v.getZExtValue(); }; + std::optional r; + if (kind == "bit_select" && a.size() == 2 && pos(a[1]) < a[0].getBitWidth()) { + r = llvm::APInt(rw, a[0][pos(a[1])] ? 1 : 0); + } else if (kind == "bit_part_select" && a.size() == 3) { + uint64_t lo = pos(a[1]), hi = pos(a[2]), w = a[0].getBitWidth(); + if (lo < w && hi < w) { + llvm::APInt out(rw, 0); + if (lo <= hi) { + for (uint64_t k = 0; k <= hi - lo && k < rw; ++k) + out.setBitVal(k, a[0][lo + k]); + } else { // reversed range + for (uint64_t k = 0; k <= lo - hi && k < rw; ++k) + out.setBitVal(k, a[0][lo - k]); + } + r = out; + } + } else if (kind == "bit_set" && a.size() == 3 && + pos(a[2]) < a[0].getBitWidth()) { + llvm::APInt out = a[0].zextOrTrunc(rw); + if (pos(a[2]) < rw) + out.setBitVal(pos(a[2]), a[1][0]); + r = out; + } else if (kind == "bit_part_set" && a.size() == 4) { + uint64_t lo = pos(a[2]), hi = pos(a[3]); + llvm::APInt out = a[0].zextOrTrunc(rw); + if (lo <= hi && hi < rw) { + for (uint64_t k = 0; k <= hi - lo; ++k) + out.setBitVal(lo + k, k < a[1].getBitWidth() && a[1][k]); + r = out; + } + } else if (kind.ends_with("_reduce") && a.size() == 1) { + bool v = false; + llvm::StringRef op = kind.drop_front(strlen("bit_")); + if (op == "and_reduce" || op == "nand_reduce") + v = a[0].isAllOnes(); + else if (op == "or_reduce" || op == "nor_reduce") + v = !a[0].isZero(); + else if (op == "xor_reduce" || op == "nxor_reduce") + v = a[0].popcount() % 2; + else + continue; + if (op.starts_with("n")) + v = !v; + r = llvm::APInt(rw, v ? 1 : 0); + } + if (r) + folds.push_back({c, *r}); + } + for (auto &[c, v] : folds) { + c->replaceAllUsesWith(llvm::ConstantInt::get(c->getType(), v)); + c->eraseFromParent(); + } + return !folds.empty(); +} + +/// Whether a loop with a pipeline pragma encloses `BB` (the innermost loop +/// itself or any loop around it). +static bool inPipelinedLoop(llvm::BasicBlock &BB, llvm::LoopInfo &LI) { + for (llvm::Loop *L = LI.getLoopFor(&BB); L; L = L->getParentLoop()) + if (llvm::DebugLoc start = L->getStartLoc()) + for (const LoopLoc &r : state().pipelineLoops) + if (r.matches(start)) + return true; + return false; +} + +/// Fills AutoInlineState::reachedFromPipeline (N142): Vitis applies the +/// pipeline pragma's implied complete unroll to the loops of every function +/// the pipelined loop (or pipelined function) calls, transitively, before it +/// counts sizes for the automatic inlining ([HLS 214-291] for the callee +/// loop; kernel w9r19p_iu_a: callee size 17 -> 96, kept; iu_d: through an +/// intermediate function; hlsyn aes `aes_subBytes_1` 17 -> 96). One body +/// serves every caller, so a function reached from one pipelined loop is +/// measured unrolled for all of them. Runs on the module after the +/// always_inline bodies are inlined (their calls are the caller's). +static void computeReachedFromPipeline(llvm::Module &M, + llvm::FunctionAnalysisManager &FAM) { + AutoInlineState &st = state(); + st.reachedFromPipeline.clear(); + if (!HLSAutoInlineCalleeUnroll || + (st.pipelineLoops.empty() && st.pipelineFunctions.empty())) + return; + std::vector work; + auto reach = [&](llvm::Function *callee) { + if (callee && !callee->isDeclaration() && !callee->isIntrinsic() && + st.reachedFromPipeline.insert(callee->getName().str()).second) + work.push_back(callee); + }; + for (llvm::Function &F : M) { + if (F.isDeclaration()) + continue; + const bool pipelined = st.pipelineFunctions.count(F.getName().str()) > 0; + llvm::LoopInfo *LI = nullptr; + if (!pipelined && !st.pipelineLoops.empty()) + LI = &FAM.getResult(F); + for (llvm::BasicBlock &BB : F) { + if (!pipelined && (!LI || !inPipelinedLoop(BB, *LI))) + continue; + for (llvm::Instruction &I : BB) + if (auto *call = llvm::dyn_cast(&I)) + reach(call->getCalledFunction()); + } + // Nothing cached from here may outlive the IR changes measure() makes + // outside a pass manager (foldConstantBuiltinStandIns). + FAM.invalidate(F, llvm::PreservedAnalyses::none()); + } + while (!work.empty()) { + llvm::Function *F = work.back(); + work.pop_back(); + for (llvm::Instruction &I : llvm::instructions(*F)) + if (auto *call = llvm::dyn_cast(&I)) + reach(call->getCalledFunction()); + } + if (HLSAutoInlineReport) + for (const std::string &name : st.reachedFromPipeline) + llvm::errs() << "hls-auto-inline: '" << name + << "' is called from a pipelined loop or function: its " + "loops are unrolled before measuring\n"; +} + +/// N18's size recipe on every function of `M`: the always_inline callees +/// inlined (clang -O0 runs the always-inliner, so N18's proxy measures every +/// function with them inlined); sroa; the pragma loops unrolled; early-cse, +/// instcombine, simplifycfg, dce; then the instructions without the integer +/// casts, and the direct calls per callee. +void measure(llvm::Module &M) { + llvm::PassBuilder PB; + llvm::LoopAnalysisManager LAM; + llvm::FunctionAnalysisManager FAM; + llvm::CGSCCAnalysisManager CGAM; + llvm::ModuleAnalysisManager MAM; + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + + auto parse = [&](llvm::StringRef text, llvm::FunctionPassManager &FPM) { + if (llvm::Error err = PB.parsePassPipeline(FPM, text)) { + llvm::errs() << "error: --hls-auto-inline: " << llvm::toString(std::move(err)) + << "\n"; + return false; + } + return true; + }; + // Vitis inlines every member of the ap_int / ap_fixed classes before it + // measures: none of them is ever a row of a design-size report + // (csynth_design_size.rpt, all td=off ground-truth runs), and the one the + // Vitis headers do not mark AP_INLINE (always_inline), the + // `ap_fixed_base(double)` constructor (etc/ap_fixed_base.h: "they're all + // AP_INLINE expect ap_fixed_base(double d)"), has no row and no [HLS + // 214-178] message either (GradCAM avg_pool: `const fm_t factor = + // (fm_t)(16.0 / 49)` in avg_pool_core, which Vitis inlines; measured with + // the constructor as a callee of its own, 106 and kept). + for (llvm::Function &F : M) + if (!F.isDeclaration() && + !F.hasFnAttribute(llvm::Attribute::AlwaysInline) && + isApClassHeaderFunction(F)) { + F.removeFnAttr(llvm::Attribute::NoInline); + F.removeFnAttr(llvm::Attribute::OptimizeNone); + F.addFnAttr(llvm::Attribute::AlwaysInline); + } + for (llvm::Function &F : M) + if (!F.isDeclaration() && F.hasFnAttribute(llvm::Attribute::AlwaysInline)) + state().alwaysInline.insert(F.getName().str()); + // As clang's -O0 pipeline: no lifetime markers for the inlined allocas. + llvm::ModulePassManager alwaysInline; + alwaysInline.addPass( + llvm::AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false)); + alwaysInline.run(M, MAM); + lowerXilinxBuiltinsForMeasure(M); + computeReachedFromPipeline(M, FAM); + + llvm::FunctionPassManager pre, post, rotated; + if (!parse("sroa", pre) || + !parse("early-cse,instcombine,simplifycfg,dce", post) || + (HLSAutoInlineRotatedSize && + !parse("loop(loop-rotate),instcombine,simplifycfg," + "dce", + rotated))) + return; + + // A complete unroll of large nests can take LLVM practically forever + // (lab2_hanchen: a 4 x 100 x 128 nest under a pipelined loop; Vitis's own + // run of it ends in its unroll step without a result). Such a function is + // far over the threshold whatever simplification follows, so its size and + // calls are estimated from the trip counts instead. + const uint64_t budget = HLSAutoInlineUnrollBudget; + std::map estimates; + // The callers' arguments must be SSA values (sroa) before a callee looks + // at them (propagateCallSiteConstants); sroa is function-local and the + // second run in the loop below finds nothing more to do. + if (HLSAutoInlineCallSiteConstantTrips) + for (llvm::Function &F : M) + if (!F.isDeclaration()) + pre.run(F, FAM); + for (llvm::Function &F : M) { + if (F.isDeclaration()) + continue; + pre.run(F, FAM); + if (HLSAutoInlineCallSiteConstantTrips) { + bool runtimeTrip = hasRuntimeTripCompleteUnroll( + F, FAM.getResult(F), + FAM.getResult(F)); + // The loop and SCEV results of this look must not reach the unroll + // below (it would see trip counts from before loop rotation). + FAM.invalidate(F, llvm::PreservedAnalyses::none()); + if (runtimeTrip && propagateCallSiteConstants(F)) { + post.run(F, FAM); + if (HLSAutoInlineReport) + llvm::errs() << "hls-auto-inline: '" << F.getName() + << "': parameters every call passes as one constant " + "are propagated before measuring\n"; + } + } + if (foldConstantBuiltinStandIns(F)) + post.run(F, FAM); + if (markUnrollLoops(F, FAM.getResult(F))) { + llvm::FunctionPassManager prepare; + prepare.addPass(llvm::LoopSimplifyPass()); + prepare.addPass(llvm::LCSSAPass()); + prepare.addPass(llvm::createFunctionToLoopPassAdaptor( + llvm::LoopRotatePass(), /*UseMemorySSA=*/false)); + prepare.run(F, FAM); + FunctionSize estimate = + estimateUnrolled(F, FAM.getResult(F), + FAM.getResult(F), + budget); + if (static_cast(estimate.size) > budget) { + if (HLSAutoInlineReport) + llvm::errs() << "hls-auto-inline: '" << F.getName() + << "' is not unrolled for measuring: over " + << budget << " instructions after the unroll; size " + << "and calls are estimated\n"; + estimate.estimated = true; + estimates[F.getName().str()] = std::move(estimate); + continue; + } + llvm::FunctionPassManager unroll; + unroll.addPass(llvm::LoopUnrollPass(llvm::LoopUnrollOptions( + /*OptLevel=*/2, /*OnlyWhenForced=*/true, /*ForgetSCEV=*/false))); + unroll.run(F, FAM); + } + post.run(F, FAM); + while (foldConstantBuiltinStandIns(F)) + post.run(F, FAM); + if (HLSAutoInlineRotatedSize) + rotated.run(F, FAM); + if (!HLSAutoInlineDump.empty() && + F.getName().contains(HLSAutoInlineDump)) + F.print(llvm::errs()); + } + + auto &functions = state().functions; + for (llvm::Function &F : M) { + if (F.isDeclaration()) + continue; + FunctionSize fs; + auto est = estimates.find(F.getName().str()); + if (est != estimates.end()) + fs = std::move(est->second); + fs.returnsPointer = F.getReturnType()->isPointerTy(); + fs.alwaysInline = F.hasFnAttribute(llvm::Attribute::AlwaysInline); + if (fs.estimated) { + functions[F.getName().str()] = std::move(fs); + continue; + } + if (HLSAutoInlineRotatedSize) { + // N131: LLVM 7's rotation keeps each guarded loop's preheader / exit + // block (one `br` each) and the block between two consecutive loops, + // which LLVM 18's CFG cleanup folds: one instruction per loop with a + // variable trip count, and per group of sibling loops one per + // constant-trip loop after the first (kernel w9r17p_tc_a; 145 of 150 + // plain-C functions exact). The sibling term counts only the loops at + // the top of the function and those directly in a variable-trip loop: + // constant-trip loops nested in a constant-trip loop add nothing + // (W9 round 17 review, kernels w9r17rev_rv_rot_nest51, w9r17fx_nest / + // nest2: 10 of 12 nested functions exact, every flat one unchanged; + // counting every constant loop of the function got 2 of 12, e.g. + // rv_rot_nest51 `blk` 56 for Vitis' 54, kept where Vitis inlines). + auto &LI = FAM.getResult(F); + auto &SE = FAM.getResult(F); + auto isConstantTrip = [&](llvm::Loop *L) { + return SE.getSmallConstantTripCount(L) > 0; + }; + auto siblingTerm = [&](llvm::ArrayRef siblings) { + int64_t constant = llvm::count_if(siblings, isConstantTrip); + return std::max(0, constant - 1); + }; + int64_t extra = siblingTerm(LI.getTopLevelLoops()); + for (llvm::Loop *L : LI.getLoopsInPreorder()) + if (!isConstantTrip(L)) + extra += 1 + siblingTerm(L->getSubLoops()); + fs.size += extra; + } + for (llvm::Instruction &I : llvm::instructions(F)) { + if (llvm::isa(I)) + continue; + if (HLSAutoInlineRotatedSize && I.isLifetimeStartOrEnd()) + continue; + // Integer casts are free in Vitis's count (N18: ai_gep_u16_e2_v2 116 + // with 16 index zext inlined, ai_gep_u16_e3_v2 118 kept). + if (llvm::isa(I)) + continue; + ++fs.size; + // Vitis' front end does not contract `a * b + c` (no llvm.fmuladd in + // any of the ground-truth runs' a.g.ld.5.gdce.ll), clang 18 does: an + // fmuladd counts as Vitis' fmul + fadd (spector_hls dct `DCT8_auto`: + // Vitis 56, kept; counted as one, 50 x 2 calls fell under the + // threshold; W9 round 17 review fixes). + if (HLSAutoInlineRotatedSize) + if (auto *intr = llvm::dyn_cast(&I)) + if (intr->getIntrinsicID() == llvm::Intrinsic::fmuladd) + ++fs.size; + if (auto *call = llvm::dyn_cast(&I)) + if (llvm::Function *callee = call->getCalledFunction()) + if (countsAsDesignCall(callee)) + ++fs.calls[callee->getName().str()]; + } + functions[F.getName().str()] = std::move(fs); + } + state().measured = true; +} + +/// What the CodeGenerator refers to. A base class of InlineSizeConsumer +/// placed before the multiplexer that owns the CodeGenerator, so that it is +/// built before and destroyed after it. +struct SizeResources { + llvm::LLVMContext context; + clang::CodeGenOptions codeGenOpts; + llvm::IntrusiveRefCntPtr diags; + clang::CodeGenerator *generator = nullptr; + + explicit SizeResources(clang::CompilerInstance &CI) + : codeGenOpts(CI.getCodeGenOpts()) { + // N18's proxy: clang -O0 -Xclang -disable-O0-optnone; locations only, so + // that the loop metadata carries the loops' start locations. + codeGenOpts.OptimizationLevel = 0; + codeGenOpts.DisableO0ImplyOptNone = true; + codeGenOpts.setDebugInfo(llvm::codegenoptions::LocTrackingOnly); + codeGenOpts.DebugColumnInfo = true; + // Its own diagnostics: whatever clang's codegen has to say must not + // change cgeist's result. + diags = new clang::DiagnosticsEngine( + new clang::DiagnosticIDs(), new clang::DiagnosticOptions(), + new clang::IgnoringDiagConsumer(), /*ShouldOwnClient=*/true); + } +}; + +/// clang's CodeGenerator for the translation unit; when the translation unit +/// ends, its module is measured (cgeist's own consumer comes first, so the +/// unroll pragmas are recorded by then). +class InlineSizeConsumer : private SizeResources, + public clang::MultiplexConsumer { +public: + InlineSizeConsumer(clang::CompilerInstance &CI, llvm::StringRef inFile) + : SizeResources(CI), MultiplexConsumer(makeGenerator(*this, CI, inFile)), + sourceDiags(CI.getDiagnostics()) {} + + // clang's CodeGenerator stops at the first error of its own diagnostics + // engine, which here is a private one; it must also stop at the first + // error in the source, or it generates code for an invalid AST and + // asserts (an `undeclared identifier` became a crash). cgeist fails on + // such a source anyway. + bool HandleTopLevelDecl(clang::DeclGroupRef D) override { + return sourceFailed() || MultiplexConsumer::HandleTopLevelDecl(D); + } + void HandleInlineFunctionDefinition(clang::FunctionDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::HandleInlineFunctionDefinition(D); + } + void HandleInterestingDecl(clang::DeclGroupRef D) override { + if (!sourceFailed()) + MultiplexConsumer::HandleInterestingDecl(D); + } + void HandleTagDeclDefinition(clang::TagDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::HandleTagDeclDefinition(D); + } + void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::HandleTagDeclRequiredDefinition(D); + } + void HandleCXXImplicitFunctionInstantiation(clang::FunctionDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(D); + } + void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(D); + } + void CompleteTentativeDefinition(clang::VarDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::CompleteTentativeDefinition(D); + } + void CompleteExternalDeclaration(clang::VarDecl *D) override { + if (!sourceFailed()) + MultiplexConsumer::CompleteExternalDeclaration(D); + } + void HandleVTable(clang::CXXRecordDecl *RD) override { + if (!sourceFailed()) + MultiplexConsumer::HandleVTable(RD); + } + + void HandleTranslationUnit(clang::ASTContext &C) override { + if (sourceFailed()) + return; + MultiplexConsumer::HandleTranslationUnit(C); + if (diags->hasErrorOccurred()) { + llvm::errs() << "warning: --hls-auto-inline: clang could not generate " + "LLVM IR for this translation unit; every call without " + "'inline off' is inlined\n"; + return; + } + std::unique_ptr M(generator->ReleaseModule()); + if (M) + measure(*M); + } + +private: + bool sourceFailed() const { return sourceDiags.hasErrorOccurred(); } + + clang::DiagnosticsEngine &sourceDiags; + + static std::vector> + makeGenerator(SizeResources &r, clang::CompilerInstance &CI, + llvm::StringRef inFile) { + std::unique_ptr gen(clang::CreateLLVMCodeGen( + *r.diags, inFile, &CI.getVirtualFileSystem(), CI.getHeaderSearchOpts(), + CI.getPreprocessorOpts(), r.codeGenOpts, r.context)); + r.generator = gen.get(); + std::vector> v; + v.push_back(std::move(gen)); + return v; + } +}; + +//===----------------------------------------------------------------------===// +// The decision +//===----------------------------------------------------------------------===// + +struct MarkAutoInlinePass + : public mlir::PassWrapper> { + MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(MarkAutoInlinePass) + llvm::StringRef getArgument() const final { return "hls-mark-auto-inline"; } + llvm::StringRef getDescription() const final { + return "Mark the calls Vitis does not inline automatically"; + } + void runOnOperation() final; +}; + +/// The trip count of `loop` when its `#pragma HLS unroll` is complete +/// (factor 0) and its bounds are constants: Vitis unrolls such a loop +/// ([HLS 214-186]) before it decides what to inline, so the calls in its body +/// are that many calls of the enclosing body. std::nullopt otherwise. +std::optional completeUnrollTrips(mlir::LoopLikeOpInterface loop) { + // The pragmas are not attributes of the loop yet when the decision runs; + // the loop is found by its source location (the `for` keyword, which + // recordUnrollLoop recorded and cgeist's loop location carries). + llvm::SmallVector locs; + loop->getLoc()->walk([&](mlir::Location l) { + if (auto flc = llvm::dyn_cast(l)) + locs.push_back(flc); + return mlir::WalkResult::advance(); + }); + bool complete = llvm::any_of(state().unrollLoops, [&](const UnrollLoop &r) { + return r.factor == 0 && + llvm::any_of(locs, [&](mlir::FileLineColLoc l) { + return l.getLine() == r.line && l.getColumn() == r.col && + llvm::sys::path::filename(l.getFilename().getValue()) == + r.file; + }); + }); + if (!complete) + return std::nullopt; + std::optional lb = loop.getSingleLowerBound(), + ub = loop.getSingleUpperBound(), + st = loop.getSingleStep(); + if (!lb || !ub || !st) + return std::nullopt; + std::optional l = mlir::getConstantIntValue(*lb), + u = mlir::getConstantIntValue(*ub), + s = mlir::getConstantIntValue(*st); + if (!l || !u || !s || *s <= 0) + return std::nullopt; + return *u > *l ? (*u - *l + *s - 1) / *s : 0; +} + +/// Whether a loop of `fn` encloses `op` once Vitis has unrolled the loops +/// with a complete unroll pragma and constant bounds (completeUnrollTrips; +/// such loops are gone when Vitis looks for dataflow processes: kernel +/// w9r6rev n48a, four calls of `stage` in a fully unrolled loop of a +/// dataflow region give the four processes stage, stage_1..3, 4 BRAM, with +/// size 22 x 4 calls below the threshold). `copies` (optional) receives +/// the number of copies the unrolled loops make of `op`. +bool isInsideLoop(mlir::Operation *op, mlir::func::FuncOp fn, + int64_t *copies = nullptr) { + int64_t k = 1; + for (mlir::Operation *p = op->getParentOp(); p && p != fn.getOperation(); + p = p->getParentOp()) + if (auto loop = llvm::dyn_cast(p)) { + std::optional trips = completeUnrollTrips(loop); + if (!trips) + return true; + k = std::min(k * *trips, int64_t(1) << 20); + } + if (copies) + *copies = k; + return false; +} + +/// Calls `fn(call, insideLoop)` for every call that ends up in `caller` once +/// cgeist has inlined the always_inline callees: the calls of `caller` +/// itself and, transitively, those in the bodies of the always_inline +/// functions it calls (measure() counted them in `caller`). `insideLoop`: +/// a loop of `caller` or of an always_inline body on the way encloses it +/// (a completely unrolled loop with constant bounds does not count, and the +/// third argument is the number of copies its unrolling makes, else 1). +void forEachEffectiveCall( + mlir::func::FuncOp caller, + const std::function &funcOf, + const std::function &fn) { + const std::set &alwaysInline = state().alwaysInline; + std::set onPath; + std::function walk = + [&](mlir::func::FuncOp f, bool outerInLoop) { + f.walk([&](mlir::func::CallOp call) { + int64_t copies = 1; + bool inLoop = outerInLoop || isInsideLoop(call, f, &copies); + fn(call, inLoop, inLoop ? 1 : copies); + std::string callee = call.getCallee().str(); + if (!alwaysInline.count(callee) || onPath.count(callee)) + return; + if (mlir::func::FuncOp body = funcOf(callee)) { + onPath.insert(callee); + walk(body, inLoop); + onPath.erase(callee); + } + }); + }; + if (caller) + walk(caller, false); +} + +llvm::StringRef displayName(mlir::func::FuncOp f, llvm::StringRef symbol) { + if (f) + if (auto n = f->getAttrOfType("hls.orig_name")) + return n.getValue(); + return symbol; +} + +void MarkAutoInlinePass::runOnOperation() { + AutoInlineState &st = state(); + if (!st.measured) + return; + mlir::ModuleOp module = getOperation(); + mlir::Builder b(module.getContext()); + + llvm::StringMap funcs; + module.walk([&](mlir::func::FuncOp f) { + if (!f.isExternal()) + funcs[f.getSymName()] = f; + }); + std::function funcOf = + [&](llvm::StringRef name) -> mlir::func::FuncOp { + auto it = funcs.find(name); + return it == funcs.end() ? mlir::func::FuncOp() : it->second; + }; + + /// Which calls of a (caller, callee) pair are kept. + enum class Which { All, OutsideLoops, InsideLoops }; + struct Kept { + std::string caller, callee; + int64_t calls, size; + Which which; + }; + std::vector kept; + std::map finalSize; + std::set visiting, done; + const int64_t threshold = HLSAutoInlineThreshold; + + // The calls of `callee` in `callerOp`, split by whether a loop of the + // caller encloses them. + auto countCalls = [&](mlir::func::FuncOp callerOp, llvm::StringRef callee, + int64_t &outside, int64_t &inside) { + outside = inside = 0; + forEachEffectiveCall(callerOp, funcOf, + [&](mlir::func::CallOp call, bool inLoop, + int64_t copies) { + if (call.getCallee() == callee) + (inLoop ? inside : outside) += copies; + }); + }; + + // Bottom-up over the call graph: a callee is decided in its own body + // (and its size grows by what it inlines) before its callers look at it. + std::function visit = [&](const std::string &c) { + if (done.count(c) || visiting.count(c)) + return; + auto it = st.functions.find(c); + if (it == st.functions.end()) + return; + visiting.insert(c); + for (auto &[callee, n] : it->second.calls) + visit(callee); + mlir::func::FuncOp callerOp = funcOf(c); + // An always_inline function the always-inliner kept (e.g. external + // linkage) is inlined into its callers anyway; their decisions cover its + // calls (forEachEffectiveCall), so it marks none itself. + const bool callerInlinesAway = it->second.alwaysInline; + const bool callerIsDataflow = + HLSAutoInlineDataflow && callerOp && callerOp->hasAttr("hls.dataflow"); + int64_t size = it->second.size; + for (const auto &entry : it->second.calls) { + const std::string &callee = entry.first; + const int64_t n = entry.second; + auto calleeInfo = st.functions.find(callee); + if (calleeInfo == st.functions.end() || !finalSize.count(callee)) + continue; // recursion (Vitis: an error, 214-139): leave to the inliner + mlir::func::FuncOp calleeOp = funcOf(callee); + int64_t calleeSize = finalSize[callee]; + auto report = [&](const char *decision, const char *reason, int64_t k) { + if (HLSAutoInlineReport) + llvm::errs() << "hls-auto-inline: caller '" + << displayName(callerOp, c) << "' callee '" + << displayName(calleeOp, callee) << "' size " + << calleeSize << " calls " << k << ": " << decision + << " (" << reason << ")\n"; + }; + auto inlineCalls = [&](const char *reason, int64_t k) { + size += k * (calleeSize - 2); + report("inlined", reason, k); + }; + auto keepCalls = [&](const char *reason, int64_t k, Which which) { + if (!callerInlinesAway) + kept.push_back({c, callee, k, calleeSize, which}); + report("kept", reason, k); + }; + if (calleeOp && calleeOp->hasAttr("hls.inline_off")) { + report("kept", "inline off", n); + continue; + } + if (calleeOp && calleeOp->hasAttr("hls.inline")) { + inlineCalls("inline pragma", n); + continue; + } + // always_inline: clang inlines it before Vitis's own inliner runs; the + // Vitis headers mark every ap_int / ap_fixed member and operator so + // under __SYNTHESIS__ (AP_INLINE, etc/ap_common.h), and none of them + // appears in a [HLS 214-178] line of the 208 corpus logs that use them. + // measure() has inlined them already; this catches the calls the + // always-inliner leaves (recursion). + if (calleeInfo->second.alwaysInline) { + inlineCalls("always_inline", n); + continue; + } + if (HLSAutoInlineDataflow && calleeOp && + calleeOp->hasAttr("hls.dataflow")) { + keepCalls("holds a dataflow region", n, Which::All); + continue; + } + // A call at the top level of a dataflow region is a process, kept + // whatever its size, also once a completely unrolled loop of the + // region has made it one (isInsideLoop); a call inside another loop of + // the region is not a process of its own and follows the size rule. + int64_t rest = n; + Which restWhich = Which::All; + if (callerIsDataflow) { + int64_t outside = 0, inside = 0; + countCalls(callerOp, callee, outside, inside); + if (outside > 0) { + keepCalls("dataflow process", outside, Which::OutsideLoops); + rest = inside > 0 ? std::max(n - outside, inside) : 0; + restWhich = Which::InsideLoops; + if (rest == 0) + continue; + } + } + if (calleeInfo->second.returnsPointer) + inlineCalls("returns a pointer", rest); + else if (calleeSize * rest > threshold) + keepCalls("size x calls > threshold", rest, restWhich); + else + inlineCalls("size x calls <= threshold", rest); + } + finalSize[c] = size; + visiting.erase(c); + done.insert(c); + }; + for (auto &[name, fs] : st.functions) + visit(name); + + // A kept call that sits in the body of an always_inline function is marked + // there, so it is kept in every caller of that function: a caller that + // would inline it is not modelled (keep wins; no corpus case known). + for (const Kept &k : kept) { + mlir::func::FuncOp callerOp = funcOf(k.caller), calleeOp = funcOf(k.callee); + if (!callerOp || !calleeOp) + continue; + bool marked = false; + forEachEffectiveCall(callerOp, funcOf, [&](mlir::func::CallOp call, + bool inLoop, int64_t) { + if (call.getCallee() != k.callee) + return; + if (k.which != Which::All && + inLoop != (k.which == Which::InsideLoops)) + return; + call->setAttr(kInlineAutoOffAttr, + b.getDictionaryAttr( + {b.getNamedAttr("calls", b.getI64IntegerAttr(k.calls)), + b.getNamedAttr("size", b.getI64IntegerAttr(k.size))})); + marked = true; + }); + if (marked) + calleeOp->setAttr(kInlineAutoOffAttr, + b.getDictionaryAttr({b.getNamedAttr( + "size", b.getI64IntegerAttr(k.size))})); + } +} + +} // namespace + +bool cgeist::hls::autoInlineEnabled() { + return HLSAutoInline && isEnabled() && !checkOnly(); +} + +static std::optional loopLoc(const clang::SourceManager &SM, + clang::SourceLocation loop) { + if (!autoInlineEnabled() || loop.isInvalid()) + return std::nullopt; + clang::PresumedLoc p = SM.getPresumedLoc(loop); + if (p.isInvalid()) + return std::nullopt; + return LoopLoc{llvm::sys::path::filename(p.getFilename()).str(), + p.getLine(), p.getColumn()}; +} + +void cgeist::hls::recordUnrollLoop(const clang::SourceManager &SM, + clang::SourceLocation loop, int64_t factor) { + if (std::optional l = loopLoc(SM, loop)) { + UnrollLoop r; + static_cast(r) = *l; + r.factor = factor; + state().unrollLoops.push_back(std::move(r)); + } +} + +void cgeist::hls::recordPipelineLoop(const clang::SourceManager &SM, + clang::SourceLocation loop) { + if (std::optional l = loopLoc(SM, loop)) + state().pipelineLoops.push_back(std::move(*l)); +} + +void cgeist::hls::recordPipelineFunction(llvm::StringRef symbol) { + if (autoInlineEnabled()) + state().pipelineFunctions.insert(symbol.str()); +} + +std::unique_ptr +cgeist::hls::createInlineSizeConsumer(clang::CompilerInstance &CI, + llvm::StringRef inFile) { + return std::make_unique(CI, inFile); +} + +std::unique_ptr cgeist::hls::createMarkAutoInlinePass() { + return std::make_unique(); +} diff --git a/tools/cgeist/Lib/HLSAutoInline.h b/tools/cgeist/Lib/HLSAutoInline.h new file mode 100644 index 000000000000..3de8dd4028e8 --- /dev/null +++ b/tools/cgeist/Lib/HLSAutoInline.h @@ -0,0 +1,108 @@ +//===- HLSAutoInline.h - Vitis automatic inlining decision ------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Vitis HLS 2025.1 inlines a callee without an inline pragma automatically +// ([HLS 214-178]) when it is small, and keeps it as its own module otherwise. +// The rule, pinned by kernels in the hls-est tree (VITIS_NOTES N18, MEMOS +// decision #34): +// +// * The call graph is visited bottom-up. For a caller C and a callee F +// without an inline pragma, all calls of F in C are inlined iff +// size(F) x calls(F in C) <= 100, +// and none of them otherwise. Calls are counted after the user's unroll +// pragmas and the complete unroll a pipeline pragma implies for every +// loop nested in the pipelined loop or function ([HLS 214-291]). +// * size(F) is F's instruction count after Vitis's simplification, without +// the integer casts (sext / zext / trunc), plus size(G) - 2 for every call +// of a G inlined into F before. +// * A callee that returns a pointer or a reference is always inlined; an +// `inline off` callee, a process of a dataflow region (a call at the top +// level of a `dataflow` function, also inside a loop of it that a +// complete unroll pragma with constant bounds removes; a call inside +// another loop of it follows the size rule) and a callee that holds a +// dataflow region are always kept; an `inline` (on) callee and an +// `always_inline` one (clang inlines it first; the Vitis headers mark +// every ap_int / ap_fixed member so) are always inlined, and the calls in +// an always_inline body count in the caller it is inlined into. +// * A dataflow pragma counts only directly in a function body or a `for` +// body; elsewhere Vitis ignores it ([HLS 207-5576]; HLSPragmaSema.cc). +// +// cgeist measures size(F) the way N18's proxy does (146 of 150 decisions of +// the N18 kernels): clang's own LLVM IR for the translation unit, at -O0 +// without optnone, the always_inline callees inlined (as clang -O0 does), +// with the loops above unrolled first, then `sroa, early-cse, instcombine, +// simplifycfg, dce`. A consumer +// next to cgeist's MLIR codegen builds that IR; a pass right before cgeist's +// inliner applies the rule and marks the calls Vitis keeps +// (`hls.inline_auto_off`, on the func.call and on the callee); cgeist's +// inliner interface does not inline them (HLSPragma.cc), and hls-est treats +// them like `inline off` calls. +// +//===----------------------------------------------------------------------===// + +#ifndef CGEIST_LIB_HLSAUTOINLINE_H +#define CGEIST_LIB_HLSAUTOINLINE_H + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace clang { +class ASTConsumer; +class CompilerInstance; +class SourceLocation; +class SourceManager; +} // namespace clang + +namespace mlir { +class Pass; +} // namespace mlir + +namespace cgeist { +namespace hls { + +/// `hls.inline_auto_off`: on a func.call, Vitis keeps this call (dictionary +/// {size, calls}); on a func.func, at least one of its calls is kept that way +/// (dictionary {size}). +constexpr llvm::StringLiteral kInlineAutoOffAttr = "hls.inline_auto_off"; + +/// Whether the automatic-inlining decision runs (--hls-annotate and +/// --hls-auto-inline, the default). +bool autoInlineEnabled(); + +/// A consumer that generates clang's LLVM IR for the translation unit next to +/// cgeist's own codegen and measures every function when the translation unit +/// ends. Add it after cgeist's consumer (it reads the unroll pragmas that +/// consumer's pragma sema records). +std::unique_ptr +createInlineSizeConsumer(clang::CompilerInstance &CI, llvm::StringRef inFile); + +/// Records a loop that carries `#pragma HLS unroll` (factor 0 = complete, +/// -1 = `unroll off`). +void recordUnrollLoop(const clang::SourceManager &SM, clang::SourceLocation loop, + int64_t factor); + +/// Records a loop that carries `#pragma HLS pipeline` (not `off`): Vitis +/// unrolls every loop nested in it completely before it sizes functions for +/// automatic inlining ([HLS 214-291], VITIS_NOTES N18). +void recordPipelineLoop(const clang::SourceManager &SM, + clang::SourceLocation loop); + +/// Records a function (its symbol) whose body carries `#pragma HLS pipeline`: +/// every loop in it is unrolled completely, as under a pipelined loop. +void recordPipelineFunction(llvm::StringRef symbol); + +/// The pass that applies the rule and marks the kept calls; add it right +/// before cgeist's inliner. +std::unique_ptr createMarkAutoInlinePass(); + +} // namespace hls +} // namespace cgeist + +#endif // CGEIST_LIB_HLSAUTOINLINE_H diff --git a/tools/cgeist/Lib/HLSPragma.cc b/tools/cgeist/Lib/HLSPragma.cc new file mode 100644 index 000000000000..9f5baa5cb9e6 --- /dev/null +++ b/tools/cgeist/Lib/HLSPragma.cc @@ -0,0 +1,1050 @@ +//===- HLSPragma.cc - Shared state and codegen hooks for #pragma HLS ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "HLSAutoInline.h" +#include "polygeist/Dialect.h" +#include "HLSPragmaInternal.h" + +#include "clang/AST/Decl.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Lex/Preprocessor.h" +#include "mlir/IR/Matchers.h" +#include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/BuiltinAttributes.h" +#include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/DialectRegistry.h" +#include "mlir/IR/Operation.h" +#include "mlir/IR/TypeUtilities.h" +#include "mlir/IR/SymbolTable.h" +#include "mlir/Interfaces/FunctionInterfaces.h" +#include "mlir/Pass/Pass.h" +#include "mlir/Transforms/InliningUtils.h" +#include "polygeist/Ops.h" +#include "polygeist/Passes/Passes.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/CommandLine.h" + +#include + +using namespace clang; +using namespace cgeist::hls; + +extern llvm::cl::opt HLSAnnotate; + +static llvm::cl::opt HLSPragmaCheckOnly( + "hls-pragma-check-only", llvm::cl::init(false), + llvm::cl::desc("With --hls-annotate: parse, place and validate the HLS " + "pragmas of every function body without generating code, " + "and report their targets (implies --hls-pragma-report)")); + +static llvm::cl::opt HLSPragmaReport( + "hls-pragma-report", llvm::cl::init(false), + llvm::cl::desc("With --hls-annotate: print, for every HLS pragma, the op(s) " + "it was attached to or why it was not applied")); + +//===----------------------------------------------------------------------===// +// State +//===----------------------------------------------------------------------===// + +State &State::get() { + static State state; + return state; +} + +void State::resetTranslationUnit() { + PP = nullptr; + pragmas.clear(); + analyzedFunctions.clear(); + loopTags.clear(); + storageTags.clear(); + assignTags.clear(); + globals.clear(); + globalOps.clear(); + checkedTU = false; +} + +TagRecord &State::newTag(TagClass cls) { + TagRecord &T = tags.emplace_back(); + T.id = tags.size() - 1; + T.cls = cls; + return T; +} + +mlir::Location State::tag(mlir::Location base, unsigned tagId) const { + mlir::MLIRContext *ctx = base.getContext(); + mlir::Builder b(ctx); + auto meta = b.getDictionaryAttr( + b.getNamedAttr(kTagKey, b.getI64IntegerAttr(tagId))); + return mlir::FusedLoc::get({base}, meta, ctx); +} + +// Custom diagnostics take their format string as the ID, so every distinct +// message text gets its own ID; arguments are streamed by the caller. +DiagnosticBuilder State::error(SourceLocation loc, llvm::StringRef fmt) { + DiagnosticsEngine &D = PP->getDiagnostics(); + return D.Report(loc, D.getDiagnosticIDs()->getCustomDiagID( + DiagnosticIDs::Error, fmt)); +} +DiagnosticBuilder State::warning(SourceLocation loc, llvm::StringRef fmt) { + DiagnosticsEngine &D = PP->getDiagnostics(); + return D.Report(loc, D.getDiagnosticIDs()->getCustomDiagID( + DiagnosticIDs::Warning, fmt)); +} +DiagnosticBuilder State::note(SourceLocation loc, llvm::StringRef fmt) { + DiagnosticsEngine &D = PP->getDiagnostics(); + return D.Report(loc, D.getDiagnosticIDs()->getCustomDiagID( + DiagnosticIDs::Note, fmt)); +} +DiagnosticBuilder State::remark(SourceLocation loc, llvm::StringRef fmt) { + DiagnosticsEngine &D = PP->getDiagnostics(); + return D.Report(loc, D.getDiagnosticIDs()->getCustomDiagID( + DiagnosticIDs::Remark, fmt)); +} + +std::string State::locString(SourceLocation loc) const { + if (!PP || loc.isInvalid()) + return ""; + PresumedLoc PL = PP->getSourceManager().getPresumedLoc( + PP->getSourceManager().getExpansionLoc(loc)); + if (PL.isInvalid()) + return ""; + return (llvm::Twine(PL.getFilename()) + ":" + llvm::Twine(PL.getLine()) + + ":" + llvm::Twine(PL.getColumn())) + .str(); +} + +//===----------------------------------------------------------------------===// +// Public interface +//===----------------------------------------------------------------------===// + +bool cgeist::hls::isEnabled() { return HLSAnnotate; } +bool cgeist::hls::checkOnly() { return HLSAnnotate && HLSPragmaCheckOnly; } +bool cgeist::hls::reportEnabled() { + return HLSAnnotate && (HLSPragmaReport || HLSPragmaCheckOnly); +} + +void cgeist::hls::beginTranslationUnit(Preprocessor &PP, + mlir::MLIRContext *ctx) { + State &S = State::get(); + S.resetTranslationUnit(); + S.PP = &PP; + S.mlirCtx = ctx; + registerPragmaHandler(PP); +} + +mlir::Location cgeist::hls::loopLocation(const Stmt *loop, + mlir::Location base) { + State &S = State::get(); + auto it = S.loopTags.find(loop); + if (it == S.loopTags.end()) + return base; + S.tags[it->second].tagged = true; + return S.tag(base, it->second); +} + +void cgeist::hls::onLocalStorage(const VarDecl *VD, mlir::Operation *storage) { + State &S = State::get(); + if (!VD || !storage) + return; + auto it = S.storageTags.find(VD); + if (it == S.storageTags.end()) + return; + S.tags[it->second].tagged = true; + storage->setLoc(S.tag(storage->getLoc(), it->second)); +} + +/// The depth D of an `hls::stream` object type (arrays of it +/// included), when D > 0. +static std::optional streamTemplateDepth(clang::QualType t) { + const clang::Type *base = t->getBaseElementTypeUnsafe(); + const auto *rd = base ? base->getAsCXXRecordDecl() : nullptr; + const auto *spec = + llvm::dyn_cast_or_null(rd); + if (!spec || + spec->getSpecializedTemplate()->getQualifiedNameAsString() != + "hls::stream") + return std::nullopt; + const clang::TemplateArgumentList &args = spec->getTemplateArgs(); + if (args.size() < 2 || args[1].getKind() != clang::TemplateArgument::Integral) + return std::nullopt; + int64_t d = args[1].getAsIntegral().getSExtValue(); + if (d <= 0) + return std::nullopt; + return d; +} + +void cgeist::hls::onGlobal(const VarDecl *VD, mlir::Operation *global) { + if (!isEnabled() || !VD || !global) + return; + State::get().globalOps[VD->getCanonicalDecl()] = global; + // A namespace-scope `hls::stream` is constructed by the + // translation unit's initialiser, which cgeist does not emit, so no call + // in the MLIR names its type; the depth is kept on the global + // (`hls.stream_depth`), which hls-est's FIFO model reads when no + // constructor call reaches the handle (CIRCT W9 round 6 review defect 5, + // kernel w9r6rev n49b: `static hls::stream gs;` used only + // through `hls::stream&` parameters is a 1024-deep FIFO, 2 BRAM). + // (A static local's constructor runs in its function, where hls-est + // sees it.) + if (std::optional depth = VD->isStaticLocal() + ? std::nullopt + : streamTemplateDepth(VD->getType())) + global->setAttr("hls.stream_depth", + mlir::IntegerAttr::get( + mlir::IntegerType::get(global->getContext(), 64), + *depth)); +} + +void cgeist::hls::onAssignedValue(const VarDecl *VD, mlir::Value value) { + State &S = State::get(); + if (!VD || !value) + return; + auto it = S.assignTags.find(VD); + if (it == S.assignTags.end()) + return; + // Search the expression computed for this assignment: `x = a * b + c` + // binds the multiplication of `op=mul`. The walk only follows pure + // arithmetic, so it stops at loads of other variables and never reaches + // operations of earlier statements. + auto isArith = [](mlir::Operation *op) { + llvm::StringRef d = op->getName().getDialectNamespace(); + return (d == "arith" || d == "math") && op->getNumResults() == 1; + }; + for (unsigned id : it->second) { + TagRecord &T = S.tags[id]; + auto matches = [&](mlir::Operation *op) { + if (!llvm::is_contained(T.opNames, op->getName().getStringRef().str())) + return false; + if (!T.floatWidth) + return true; + auto ft = llvm::dyn_cast( + mlir::getElementTypeOrSelf(op->getResult(0).getType())); + return ft && ft.getWidth() == T.floatWidth; + }; + llvm::SmallVector work; + llvm::SmallPtrSet seen; + if (mlir::Operation *root = value.getDefiningOp()) + work.push_back(root); + while (!work.empty()) { + mlir::Operation *op = work.pop_back_val(); + if (!seen.insert(op).second || !isArith(op) || seen.size() > 64) + continue; + if (matches(op)) { + op->setLoc(S.tag(op->getLoc(), id)); + T.tagged = true; + continue; // do not look inside a bound operation + } + for (mlir::Value operand : op->getOperands()) + if (mlir::Operation *def = operand.getDefiningOp()) + work.push_back(def); + } + } +} + +void cgeist::hls::endTranslationUnit() { + State &S = State::get(); + if (!isEnabled() || !S.PP) + return; + for (auto &[VD, G] : S.globals) { + auto it = S.globalOps.find(VD); + if (S.checkOnlyMode) { + for (int r : G.reports) + S.addOutcome(r, "global '" + G.name + "' (check-only)"); + continue; + } + if (it == S.globalOps.end()) { + S.warning(G.loc, "global '%0' is not used by any emitted function; " + "'%1' has no effect") + << G.name << G.pragmaName; + for (int r : G.reports) + S.addOutcome(r, "not applied: global '" + G.name + + "' is not used by any emitted function"); + continue; + } + mlir::Operation *op = it->second; + for (int r : G.reports) { + auto sym = op->getAttrOfType("sym_name"); + S.addOutcome(r, op->getName().getStringRef().str() + " @" + + (sym ? sym.getValue().str() : G.name)); + } + for (auto &[name, value] : G.attrs) { + mlir::Attribute merged = value; + auto oldArr = op->getAttrOfType(name); + auto newArr = llvm::dyn_cast(value); + if (oldArr && newArr) { + llvm::SmallVector all(oldArr.begin(), oldArr.end()); + all.append(newArr.begin(), newArr.end()); + merged = mlir::ArrayAttr::get(op->getContext(), all); + } + op->setAttr(name, merged); + } + } + // bind_op pragmas whose operation never showed up during codegen. + for (auto &[VD, ids] : S.assignTags) { + for (unsigned id : ids) { + TagRecord &T = S.tags[id]; + if (T.tagged) + continue; + T.materialized = true; // already reported + llvm::errs() << T.locString << ": warning: '" << T.pragmaName + << "': no matching operation is assigned to " << T.what + << "; the pragma has no effect\n"; + for (int r : T.reports) + S.addOutcome(r, "not applied: no matching operation is assigned to " + + T.what); + } + } + // Valid pragmas inside functions that were never emitted. + for (PragmaRecord &P : S.pragmas) + if (P.valid && !P.associated && !S.hasOutcome(P.report)) + S.addOutcome(P.report, + "not applied: the enclosing function is not emitted"); + S.PP = nullptr; +} + +//===----------------------------------------------------------------------===// +// Inlining +//===----------------------------------------------------------------------===// + +static llvm::cl::opt HLSIgnoreInlineOff( + "hls-ignore-inline-off", llvm::cl::init(false), + llvm::cl::desc("Let cgeist's inliner inline functions marked '#pragma HLS " + "inline off' too (the behaviour before the pragma was " + "honoured; for comparisons)")); + +static llvm::cl::opt HLSKeepMisfitInlineOff( + "hls-keep-misfit-inline-off", llvm::cl::init(false), + llvm::cl::desc("Keep a call of a function marked '#pragma HLS inline off' " + "also when an array argument's static shape differs from " + "the parameter's (the argument is reinterpreted to the " + "parameter type), as Vitis keeps the module whatever the " + "argument's size (VITIS_NOTES N123 / OPEN_ISSUES O156 in " + "the hls-est tree; off: such a call is inlined)")); + +bool cgeist::hls::keepMisfitInlineOff() { return HLSKeepMisfitInlineOff; } + +static llvm::cl::opt HLSInlineCarryPartition( + "hls-inline-carry-partition", llvm::cl::init(true), + llvm::cl::desc("When a call is inlined, carry the `array_partition` " + "pragmas of the callee's array parameters to the array the " + "argument names (an alloca, a global, or the caller's own " + "parameter), as Vitis partitions the root array whether " + "or not it inlines the callee; when the parameter's first " + "dimension is smaller than the root's, applied one " + "dimension deeper in the root and dropped past its rank " + "(Vitis HLS 214-248 / 214-253)")); + +/// The array a call argument names through casts: memref.cast and the +/// memref.reinterpret_cast that castCallerMemRefArg builds for an argument +/// whose static shape differs from the parameter's. +static mlir::Value partitionRootOf(mlir::Value v) { + for (unsigned guard = 0; guard < 16; ++guard) { + if (auto c = v.getDefiningOp()) { + v = c.getSource(); + continue; + } + if (auto r = v.getDefiningOp()) { + v = r.getSource(); + continue; + } + break; + } + return v; +} + +/// The callee parameter `paramTy`'s partition entries `entries` reach the +/// array `arg` names: appended to its alloca, its memref.global, or (the +/// caller's own parameter) its argument attributes with the first-dimension +/// extent of the parameter that carried the pragma (`rows`), compared with +/// the root array once one is reached (VITIS_NOTES N123 in the hls-est tree: +/// kernels w9r16p_pm_ctl / pm_mis / pm_big / pm_two / pm_two2; DGNN_Booster +/// convLSTM / EvolveGCN). An entry whose `rows` is smaller than the root's +/// first dimension applies one dimension deeper in the root; what falls past +/// the root's rank is dropped with Vitis' warning 214-253. +static void carryPartition(mlir::Operation *call, mlir::Value arg, + mlir::MemRefType paramTy, mlir::ArrayAttr entries, + mlir::StringRef calleeName); + +/// The entries of `entries` that name a member of the object (`member_path`, +/// set for a pragma on a data member inside a member function or for a +/// member path `s.buf`), appended unchanged to the object `arg` names: the +/// member's array is the same whatever the object parameter's shape (a +/// constructor's `this` is memref, the object memref<1 x +/// struct>). Returns the other entries. +static mlir::ArrayAttr carryMemberPartitions(mlir::Value arg, + mlir::ArrayAttr entries) { + mlir::MLIRContext *ctx = arg.getContext(); + llvm::SmallVector members, others; + for (mlir::Attribute a : entries) { + auto d = llvm::dyn_cast(a); + if (d && d.get("member_path")) + members.push_back(a); + else + others.push_back(a); + } + if (members.empty()) + return entries; + auto append = [&](mlir::ArrayAttr old) { + llvm::SmallVector all; + if (old) + all.append(old.begin(), old.end()); + for (mlir::Attribute a : members) + if (!llvm::is_contained(all, a)) + all.push_back(a); + return mlir::ArrayAttr::get(ctx, all); + }; + mlir::Value root = partitionRootOf(arg); + if (auto ba = llvm::dyn_cast(root)) { + auto fn = llvm::dyn_cast( + ba.getOwner()->getParentOp()); + if (fn && ba.getOwner() == &fn.getFunctionBody().front()) + fn.setArgAttr(ba.getArgNumber(), "hls.array_partition", + append(fn.getArgAttrOfType( + ba.getArgNumber(), "hls.array_partition"))); + } else { + mlir::Operation *holder = nullptr; + if (auto a = root.getDefiningOp()) + holder = a; + else if (auto a = root.getDefiningOp()) + holder = a; + else if (auto gg = root.getDefiningOp()) + holder = + mlir::SymbolTable::lookupNearestSymbolFrom(gg, gg.getNameAttr()); + if (holder) + holder->setAttr("hls.array_partition", + append(holder->getAttrOfType( + "hls.array_partition"))); + } + return mlir::ArrayAttr::get(ctx, others); +} + +static void carryPartition(mlir::Operation *call, mlir::Value arg, + mlir::MemRefType paramTy, mlir::ArrayAttr entries, + mlir::StringRef calleeName) { + mlir::MLIRContext *ctx = call->getContext(); + entries = carryMemberPartitions(arg, entries); + if (entries.empty()) + return; + mlir::Value root = partitionRootOf(arg); + auto rootTy = llvm::dyn_cast(root.getType()); + if (!rootTy || !rootTy.hasStaticShape() || !paramTy.hasStaticShape() || + rootTy.getRank() != paramTy.getRank() || rootTy.getRank() == 0) + return; + // The entries with the rows of the parameter that first carried them. + llvm::SmallVector withRows, kept; + for (mlir::Attribute a : entries) { + auto d = llvm::dyn_cast(a); + if (!d) + continue; + int64_t rows = paramTy.getDimSize(0); + if (auto r = d.getAs("rows")) + rows = r.getInt(); + llvm::SmallVector fields; + for (mlir::NamedAttribute f : d) + if (f.getName() != "rows") + fields.push_back(f); + mlir::DictionaryAttr plain = mlir::DictionaryAttr::get(ctx, fields); + fields.push_back(mlir::NamedAttribute( + mlir::StringAttr::get(ctx, "rows"), + mlir::IntegerAttr::get(mlir::IntegerType::get(ctx, 64), rows))); + withRows.push_back(mlir::DictionaryAttr::get(ctx, fields)); + // A parameter in between does not decide (kernels pm_two / pm_two2): + // the rows travel on to the root. + if (llvm::isa(root)) + continue; + if (rows < rootTy.getDimSize(0)) { + // A parameter with fewer rows than the root: Vitis applies the pragma + // one dimension deeper in the root (dimension d of the parameter to + // dimension d + 1; dim=0 to dimensions 2..rank) and ignores what falls + // past the root's rank (214-253). Kernels w9r16p_pm_mis (dim=2 + // complete, ignored), w9r16rv_pm_dim1 (dim=1 cyclic 2: "Cyclic + // partitioning with factor 2 on dimension 2"), w9r16fx_pm_d2cyc (dim=2 + // cyclic 2, ignored), w9r16fx_pm_d0 (dim=0 complete: "Complete + // partitioning on dimension 2" and 214-253), each with a [50][8] + // parameter on g[100][8]. + int64_t dim = 1; // the pragma default + if (auto di = d.getAs("dim")) + dim = di.getInt(); + int64_t rank = rootTy.getRank(); + llvm::SmallVector dims; + bool dropped = false; + if (dim == 0) { + for (int64_t q = 2; q <= rank; ++q) + dims.push_back(q); + dropped = true; // the parameter's last dimension falls past the rank + } else if (dim + 1 <= rank) { + dims.push_back(dim + 1); + } else { + dropped = true; + } + auto var = d.getAs("variable"); + if (dropped) + llvm::errs() << call->getLoc() + << ": warning: array_partition on parameter '" + << (var ? var.getValue() : "?") << "' of '" << calleeName + << "' ignored past dimension " << rank + << ": its first dimension (" << rows + << ") is smaller than that of the array it reaches (" + << rootTy.getDimSize(0) + << "), mismatched array size w.r.t. its call site " + "(Vitis HLS 214-253)\n"; + for (int64_t q : dims) { + llvm::SmallVector shifted; + for (mlir::NamedAttribute f : plain) + if (f.getName() != "dim") + shifted.push_back(f); + shifted.push_back(mlir::NamedAttribute( + mlir::StringAttr::get(ctx, "dim"), + mlir::IntegerAttr::get(mlir::IntegerType::get(ctx, 32), q))); + kept.push_back(mlir::DictionaryAttr::get(ctx, shifted)); + } + continue; + } + kept.push_back(plain); + } + auto append = [&](mlir::ArrayAttr old, + llvm::ArrayRef add) -> mlir::ArrayAttr { + llvm::SmallVector all; + if (old) + all.append(old.begin(), old.end()); + for (mlir::Attribute a : add) + if (!llvm::is_contained(all, a)) + all.push_back(a); + return mlir::ArrayAttr::get(ctx, all); + }; + if (auto ba = llvm::dyn_cast(root)) { + auto fn = llvm::dyn_cast( + ba.getOwner()->getParentOp()); + if (!fn || ba.getOwner() != &fn.getFunctionBody().front()) + return; + unsigned i = ba.getArgNumber(); + fn.setArgAttr(i, "hls.array_partition", + append(fn.getArgAttrOfType( + i, "hls.array_partition"), + withRows)); + return; + } + if (kept.empty()) + return; + mlir::Operation *holder = nullptr; + if (auto a = root.getDefiningOp()) + holder = a; + else if (auto a = root.getDefiningOp()) + holder = a; + else if (auto gg = root.getDefiningOp()) + holder = mlir::SymbolTable::lookupNearestSymbolFrom(gg, gg.getNameAttr()); + if (!holder) + return; + holder->setAttr("hls.array_partition", + append(holder->getAttrOfType( + "hls.array_partition"), + kept)); +} + +/// Whether an array partition is involved in the misfit argument `arg` of +/// `call` to `callable`: a partitioned parameter of the callee, a partition +/// on the array the argument names, or a partitioned parameter of another +/// callee that array is passed to (the partition is carried to it when that +/// call is inlined). hls-est cannot yet bank a partitioned array through the +/// reinterpreted view a kept call receives (OPEN_ISSUES O167 (a) in the +/// hls-est tree), so such a call is still inlined. +static bool misfitTouchesPartition(mlir::Operation *call, + mlir::Operation *callable, + mlir::Value arg) { + auto hasPartitionedParam = [](mlir::Operation *f) { + auto fn = llvm::dyn_cast_or_null(f); + if (!fn) + return false; + for (unsigned i = 0, e = fn.getNumArguments(); i < e; ++i) + if (fn.getArgAttr(i, "hls.array_partition")) + return true; + return false; + }; + if (hasPartitionedParam(callable)) + return true; + mlir::Value root = partitionRootOf(arg); + if (auto ba = llvm::dyn_cast(root)) { + auto fn = llvm::dyn_cast( + ba.getOwner()->getParentOp()); + if (fn && ba.getOwner() == &fn.getFunctionBody().front() && + fn.getArgAttr(ba.getArgNumber(), "hls.array_partition")) + return true; + } else if (mlir::Operation *def = root.getDefiningOp()) { + mlir::Operation *holder = def; + if (auto gg = llvm::dyn_cast(def)) + holder = mlir::SymbolTable::lookupNearestSymbolFrom(gg, gg.getNameAttr()); + if (holder && holder->hasAttr("hls.array_partition")) + return true; + } + // The array (or a view of it), passed down through any chain of calls, + // reaching a partitioned parameter: the partition is carried to it when + // that call is inlined (mult_op_module_mmv: BRAM_A2 reaches mmv_ij's + // partitioned parameter through gemm_ijk_with_mmv). + llvm::SmallVector work; + llvm::SmallPtrSet seen; + auto push = [&](mlir::Value v) { + if (seen.insert(v.getAsOpaquePointer()).second) + work.push_back(v); + }; + push(root); + if (auto gg = root.getDefiningOp()) + if (auto module = call->getParentOfType()) + module.walk([&](mlir::memref::GetGlobalOp other) { + if (other.getNameAttr() == gg.getNameAttr()) + push(other.getResult()); + }); + while (!work.empty()) { + mlir::Value v = work.pop_back_val(); + for (mlir::OpOperand &use : v.getUses()) { + mlir::Operation *user = use.getOwner(); + if (llvm::isa(user) || + user->getName().getStringRef() == "polygeist.subindex") { + if (user->getNumResults() == 1) + push(user->getResult(0)); + continue; + } + auto other = llvm::dyn_cast(user); + if (!other) + continue; + auto fn = llvm::dyn_cast_or_null( + other.resolveCallable()); + if (!fn || fn.isExternal()) + continue; + mlir::ValueRange args = other.getArgOperands(); + for (unsigned i = 0, e = std::min(args.size(), + fn.getNumArguments()); + i < e; ++i) { + if (args[i] != v) + continue; + if (fn.getArgAttr(i, "hls.array_partition")) + return true; + push(fn.getArgument(i)); + } + } + } + return false; +} + +namespace { +/// The func dialect's inliner interface: FuncInlinerInterface of +/// mlir/lib/Dialect/Func/Extensions/InlinerExtension.cpp (LLVM 18, same +/// licence as this file), except that a call to a function marked +/// `#pragma HLS inline off` is not legal to inline. +struct HLSFuncInlinerInterface : public mlir::DialectInlinerInterface { + explicit HLSFuncInlinerInterface(mlir::Dialect *dialect) + : DialectInlinerInterface(dialect) { + latest = this; + } + + /// The most recently created instance (cgeist creates one context). + static const HLSFuncInlinerInterface *latest; + + //===--------------------------------------------------------------------===// + // Analysis Hooks + //===--------------------------------------------------------------------===// + + /// Vitis keeps a function marked `#pragma HLS inline off` as its own module + /// (one instance per concurrent caller, VITIS_NOTES N14 in the hls-est + /// tree), so its calls stay calls. Every other call can be inlined. + /// + /// Exception: a call that is not valid IR on its own. cgeist casts an array + /// argument to the shape the parameter declares (--memref-fullrank), and C + /// ignores the first dimension of an array parameter, so `f(a)` with + /// `int a[32][32]` and `void f(int p[8][32])` gives a memref.cast from + /// memref<32x32xi32> to memref<8x32xi32>, which MLIR rejects. Inlining + /// folds such a cast away (the callee's accesses then use `a` directly); + /// a kept call would keep it. Such a call is inlined as before, with a + /// warning. + bool isLegalToInline(mlir::Operation *call, mlir::Operation *callable, + bool wouldBeCloned) const final { + if (!callable) + return true; + // An hls:: math library function kept as a core (XlxMathCore.h), except + // at a call whose arguments are all constants: Vitis evaluates such a + // call at compile time and builds no core (VITIS_NOTES N1a: hls::sqrt of + // a constant folds into the caller; N16: a constant call costs 0), so its + // body is inlined and folded here as well. + if (callable->hasAttr("hls.math_core")) + return llvm::all_of(call->getOperands(), [](mlir::Value v) { + return mlir::matchPattern(v, mlir::m_Constant()); + }); + // `inline off`, or a call Vitis would not inline automatically + // (hls.inline_auto_off, set by the pass before the inliner, + // HLSAutoInline.h). + bool pragmaOff = + !HLSIgnoreInlineOff && callable->hasAttr("hls.inline_off"); + bool autoOff = call->hasAttr(cgeist::hls::kInlineAutoOffAttr); + if (!pragmaOff && !autoOff) + return true; + for (auto [i, operand] : llvm::enumerate(call->getOperands())) { + // castCallerMemRefArg reinterprets an argument whose static shape + // differs from the parameter's (a valid op, since a chain of casts + // would fold back into an invalid one). + if (auto view = + operand.getDefiningOp()) { + if (pragmaOff && HLSKeepMisfitInlineOff && + !misfitTouchesPartition(call, callable, operand)) + return false; + auto name = callable->getAttrOfType("hls.orig_name"); + llvm::errs() << call->getLoc() << ": warning: '#pragma HLS inline off' " + << "of '" + << (name ? name.getValue() + : mlir::SymbolTable::getSymbolName(callable) + .getValue()) + << "' not honoured at this call: argument " << i << " (" + << view.getSource().getType() + << ") does not fit the parameter type " << view.getType() + << "; the call is inlined\n"; + return true; + } + for (auto cast = operand.getDefiningOp(); cast; + cast = cast.getSource().getDefiningOp()) { + if (mlir::memref::CastOp::areCastCompatible(cast.getSource().getType(), + cast.getType())) + continue; + if (!pragmaOff) + return true; // an automatic decision: inline it without a warning + auto name = callable->getAttrOfType("hls.orig_name"); + llvm::errs() << call->getLoc() << ": warning: '#pragma HLS inline off' " + << "of '" + << (name ? name.getValue() + : mlir::SymbolTable::getSymbolName(callable) + .getValue()) + << "' not honoured at this call: argument " << i << " (" + << cast.getSource().getType() + << ") does not fit the parameter type " << cast.getType() + << "; the call is inlined\n"; + return true; + } + } + return false; + } + + /// All operations can be inlined. + bool isLegalToInline(mlir::Operation *, mlir::Region *, bool, + mlir::IRMapping &) const final { + return true; + } + + /// All functions can be inlined. + bool isLegalToInline(mlir::Region *, mlir::Region *, bool, + mlir::IRMapping &) const final { + return true; + } + + //===--------------------------------------------------------------------===// + // Transformation Hooks + //===--------------------------------------------------------------------===// + + /// A callee marked polygeist.volatile_access (Passes.h) passes the mark to + /// the function it is inlined into: its volatile accesses are now in that + /// function's body, and CanonicalizeFor reads the mark per function. + /// + /// A call marked hls.ap_compound_assign (an ap_fixed `/=`, `*=`, `+=`, + /// `-=`, CGCall.cc) passes the mark to every store and every call of the + /// inlined body, so that the stores the compound assignment leaves carry + /// it whatever is inlined first. + void processInlinedCallBlocks( + mlir::Operation *call, + llvm::iterator_range blocks) const final { + // The stores are marked through their location (a tag materialized + // into the attribute at the end, HLSPragmaMaterialize.cc): the + // canonicalizations that fold the operator's views rebuild the stores + // and keep only the location. + if (call->hasAttr("hls.ap_compound_assign")) { + auto mark = mlir::UnitAttr::get(call->getContext()); + State &S = State::get(); + if (!S.compoundAssignTag) { + TagRecord &T = S.newTag(TagClass::Operation); + T.attrs.push_back({"hls.ap_compound_assign", mark}); + T.opNames = {"affine.store", "memref.store", "llvm.store"}; + T.pragmaName = "ap_fixed compound assignment"; + T.what = "store"; + S.compoundAssignTag = T.id; + } + unsigned id = *S.compoundAssignTag; + for (mlir::Block &b : blocks) + b.walk([&](mlir::Operation *op) { + if (llvm::isa(op)) + op->setAttr("hls.ap_compound_assign", mark); + else if (llvm::isa(op)) + op->setLoc(S.tag(op->getLoc(), id)); + }); + } + auto callOp = llvm::dyn_cast(call); + if (!callOp) + return; + mlir::Operation *callee = callOp.resolveCallable(); + // The callee's parameter partitions reach the caller's arrays (Vitis + // applies them whether or not it inlines the callee; N24 (f), N123). + if (HLSInlineCarryPartition && callee) + if (auto fn = llvm::dyn_cast(callee)) { + auto name = callee->getAttrOfType("hls.orig_name"); + llvm::StringRef calleeName = + name ? name.getValue() + : mlir::SymbolTable::getSymbolName(callee).getValue(); + mlir::ValueRange args = callOp.getArgOperands(); + for (unsigned i = 0, e = std::min(args.size(), + fn.getNumArguments()); + i < e; ++i) { + auto entries = + fn.getArgAttrOfType(i, "hls.array_partition"); + auto paramTy = + llvm::dyn_cast(fn.getArgumentTypes()[i]); + if (entries && paramTy) + carryPartition(call, args[i], paramTy, entries, calleeName); + } + } + if (!callee || !callee->hasAttr(mlir::polygeist::kVolatileAccessAttrName)) + return; + if (auto caller = call->getParentOfType()) + caller->setAttr(mlir::polygeist::kVolatileAccessAttrName, + mlir::UnitAttr::get(call->getContext())); + } + + /// Handle the given inlined terminator by replacing it with a new operation + /// as necessary. + void handleTerminator(mlir::Operation *op, mlir::Block *newDest) const final { + // Only return needs to be handled here. + auto returnOp = llvm::dyn_cast(op); + if (!returnOp) + return; + + // Replace the return with a branch to the dest. + mlir::OpBuilder builder(op); + builder.create(op->getLoc(), newDest, + returnOp.getOperands()); + op->erase(); + } + + /// Handle the given inlined terminator by replacing it with a new operation + /// as necessary. + void handleTerminator(mlir::Operation *op, + llvm::ArrayRef valuesToRepl) const final { + // Only return needs to be handled here. + auto returnOp = llvm::cast(op); + + // Replace the values directly with the return operands. + assert(returnOp.getNumOperands() == valuesToRepl.size()); + for (const auto &it : llvm::enumerate(returnOp.getOperands())) + valuesToRepl[it.index()].replaceAllUsesWith(it.value()); + } +}; +} // namespace + +const HLSFuncInlinerInterface *HLSFuncInlinerInterface::latest = nullptr; + +// The Vitis HLS headers' proxy objects (ap_range_ref, ap_bit_ref, +// ap_concat_ref, af_range_ref, af_bit_ref: a reference member plus indices, +// etc/ap_int_ref.h, ap_fixed_ref.h) are reached through +// polygeist.memref2pointer in their always_inline member functions. Without an +// inliner interface on the polygeist dialect those functions stay calls and +// the proxy stays a memref of an LLVM struct holding a memref, which is not +// valid MLIR once printed. With --xlx-headers the polygeist ops are legal to +// inline, so that the proxies can be scalarised in their callers +// (Lib/XlxProxyScalarize.cc, run by the driver under the same option). +// --xlx-headers also covers the other code-generation changes the real +// headers need (cgeist::hls::xlxHeaders() callers): struct field types +// compared as MLIR types, and namespace-qualified globals as memref globals. +static llvm::cl::opt HLSInlinePolygeistOps( + "xlx-headers", llvm::cl::init(false), + llvm::cl::desc("Code generation for the real Vitis HLS headers: inline " + "and scalarise their proxy objects (ap_range_ref, " + "ap_bit_ref, ap_concat_ref, ...), keep struct fields of " + "different MLIR types apart, and address " + "namespace-qualified globals as memref globals")); + +bool cgeist::hls::xlxHeaders() { return HLSInlinePolygeistOps; } + +bool cgeist::hls::isApFixedClass(const clang::CXXRecordDecl *rd) { + for (int depth = 0; rd && depth < 8; ++depth) { + rd = rd->getDefinition(); + if (!rd) + return false; + llvm::StringRef name = rd->getName(); + if (name == "ap_fixed" || name == "ap_ufixed" || name == "ap_fixed_base") + return true; + if (rd->getNumBases() != 1) + return false; + rd = rd->bases_begin()->getType()->getAsCXXRecordDecl(); + } + return false; +} + +namespace { +struct PolygeistOpsInlinerInterface : public mlir::DialectInlinerInterface { + using DialectInlinerInterface::DialectInlinerInterface; + bool isLegalToInline(mlir::Operation *, mlir::Region *, bool, + mlir::IRMapping &) const final { + return HLSInlinePolygeistOps; + } + bool isLegalToInline(mlir::Region *, mlir::Region *, bool, + mlir::IRMapping &) const final { + return HLSInlinePolygeistOps; + } +}; +} // namespace + +void cgeist::hls::registerInlinerExtension(mlir::DialectRegistry ®istry) { + registry.addExtension( + +[](mlir::MLIRContext *ctx, mlir::func::FuncDialect *dialect) { + dialect->addInterfaces(); + // The inliner extension relies on the ControlFlow dialect. + ctx->getOrLoadDialect(); + }); + registry.addExtension( + +[](mlir::MLIRContext *, mlir::polygeist::PolygeistDialect *dialect) { + dialect->addInterfaces(); + }); +} + +bool cgeist::hls::inlinerExtensionActive(mlir::MLIRContext *ctx) { + auto *dialect = ctx->getOrLoadDialect(); + const auto *iface = + dialect->getRegisteredInterface(); + return iface && iface == HLSFuncInlinerInterface::latest; +} + +//===----------------------------------------------------------------------===// +// AGGREGATE through callee parameters +//===----------------------------------------------------------------------===// + +static llvm::cl::opt HLSPropagateAggregate( + "hls-propagate-aggregate", llvm::cl::init(true), + llvm::cl::desc("With --hls-annotate: an AGGREGATE pragma on a function " + "parameter (or on `this` of a member function) also marks " + "the variable every call passes to it, as Vitis aggregates " + "the actual argument")); + +namespace { +constexpr llvm::StringLiteral kAggregateAttr = "hls.aggregate"; + +/// The value `view` is a view of whole elements of: memref.cast and +/// polygeist.subindex steps that keep the element type are followed (an +/// element `a[i]` of a struct array, the array decayed to a pointer). +/// A view of a member (a different element type) has no root: the pragma +/// then reaches only that member, which is not modelled. +mlir::Value elementViewRoot(mlir::Value view) { + auto elementType = [](mlir::Value v) -> mlir::Type { + auto t = llvm::dyn_cast(v.getType()); + return t ? t.getElementType() : mlir::Type(); + }; + mlir::Type elem = elementType(view); + if (!elem) + return {}; + while (mlir::Operation *def = view.getDefiningOp()) { + mlir::Value source; + if (auto cast = llvm::dyn_cast(def)) + source = cast.getSource(); + else if (auto sub = llvm::dyn_cast(def)) + source = sub.getSource(); + else + break; + if (elementType(source) != elem) + return {}; + view = source; + } + return view; +} + +/// The callee's entry, recorded on the actual with the name of the callee +/// it was passed to (`from`; the nearest one along a chain of calls). +mlir::Attribute propagatedEntry(mlir::Attribute entry, + mlir::func::FuncOp callee) { + auto dict = llvm::dyn_cast(entry); + if (!dict) + return entry; + mlir::NamedAttrList fields(dict); + fields.set("from", + mlir::StringAttr::get(dict.getContext(), callee.getSymName())); + return fields.getDictionary(dict.getContext()); +} +} // namespace + +void cgeist::hls::propagateAggregate(mlir::ModuleOp module) { + if (!isEnabled() || !HLSPropagateAggregate) + return; + llvm::StringMap> callsTo; + module.walk([&](mlir::func::CallOp call) { + callsTo[call.getCallee()].push_back(call); + }); + mlir::SymbolTable symbols(module); + + llvm::SmallVector> work; + module.walk([&](mlir::func::FuncOp fn) { + for (unsigned i = 0, e = fn.getNumArguments(); i < e; ++i) + if (fn.getArgAttr(i, kAggregateAttr)) + work.push_back({fn, i}); + }); + + while (!work.empty()) { + auto [callee, index] = work.pop_back_val(); + auto entries = callee.getArgAttrOfType(index, + kAggregateAttr); + if (!entries || entries.empty()) + continue; + mlir::Attribute entry = propagatedEntry(entries[0], callee); + auto mark = mlir::ArrayAttr::get(module.getContext(), {entry}); + for (mlir::func::CallOp call : callsTo.lookup(callee.getSymName())) { + if (index >= call.getNumOperands()) + continue; + mlir::Value root = elementViewRoot(call.getOperand(index)); + if (!root) + continue; + if (auto arg = llvm::dyn_cast(root)) { + auto caller = llvm::dyn_cast( + arg.getOwner()->getParentOp()); + if (!caller || arg.getOwner() != &caller.getBody().front() || + caller.getArgAttr(arg.getArgNumber(), kAggregateAttr)) + continue; + caller.setArgAttr(arg.getArgNumber(), kAggregateAttr, mark); + work.push_back({caller, arg.getArgNumber()}); + continue; + } + mlir::Operation *storage = root.getDefiningOp(); + if (auto get = llvm::dyn_cast(storage)) + storage = symbols.lookup(get.getName()); + if (!storage || + !llvm::isa(storage) || + storage->hasAttr(kAggregateAttr)) + continue; + storage->setAttr(kAggregateAttr, mark); + } + } +} + +namespace { +struct PropagateAggregatePass + : public mlir::PassWrapper> { + MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(PropagateAggregatePass) + llvm::StringRef getArgument() const final { + return "hls-propagate-aggregate"; + } + llvm::StringRef getDescription() const final { + return "Mark the actual arguments of parameters that carry an AGGREGATE " + "pragma"; + } + void runOnOperation() final { propagateAggregate(getOperation()); } +}; +} // namespace + +std::unique_ptr cgeist::hls::createPropagateAggregatePass() { + return std::make_unique(); +} diff --git a/tools/cgeist/Lib/HLSPragma.h b/tools/cgeist/Lib/HLSPragma.h new file mode 100644 index 000000000000..7fa2d80f4d73 --- /dev/null +++ b/tools/cgeist/Lib/HLSPragma.h @@ -0,0 +1,160 @@ +//===- HLSPragma.h - Vitis HLS pragma extraction ----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Public interface of the `#pragma HLS` extraction used by cgeist codegen and +// the driver. The design is documented in docs/hls-pragmas.md; in short: +// +// 1. Parsing (preprocessor): a catch-all pragma handler recognises the `HLS` +// namespace case-insensitively and turns each pragma into a typed record. +// 2. Association (AST): when a function body is about to be emitted, every +// pragma inside it is bound to its target (loop statement, function, +// parameter, local/global variable) by source location, validated, and +// turned into `hls.*` attributes. +// 3. Emission: attributes of functions and parameters are set directly. +// Loops, local variables and `bind_op` operations do not have a stable op +// at codegen time (loops are still a CFG), so the op is given a *tagged +// location* (a FusedLoc whose metadata names the target). Locations are +// carried along by every rewrite, clone and inline. +// 4. Materialization (after the pass pipeline): tags are turned into the +// final attributes on whichever op carries them, and removed from the +// locations. +// +//===----------------------------------------------------------------------===// + +#ifndef CGEIST_LIB_HLSPRAGMA_H +#define CGEIST_LIB_HLSPRAGMA_H + +#include "mlir/IR/Location.h" +#include "mlir/IR/Value.h" + +#include + +namespace clang { +class ASTContext; +class CXXRecordDecl; +class FunctionDecl; +class Preprocessor; +class Stmt; +class VarDecl; +} // namespace clang + +namespace mlir { +class DialectRegistry; +class Pass; +class MLIRContext; +class ModuleOp; +class Operation; +namespace func { +class FuncOp; +} // namespace func +} // namespace mlir + +namespace cgeist { +namespace hls { + +/// Whether `--hls-annotate` is on. +bool isEnabled(); + +/// Whether `--hls-pragma-check-only` is on: pragmas of every function body +/// are parsed, associated and validated, and no code is generated. +bool checkOnly(); + +//===-- Preprocessor stage -----------------------------------------------===// + +/// Registers the HLS pragma handler on `PP` and starts a new translation +/// unit. Always called; pragmas are only interpreted when isEnabled(). +void beginTranslationUnit(clang::Preprocessor &PP, mlir::MLIRContext *ctx); + +//===-- AST / codegen stage ----------------------------------------------===// + +/// Diagnoses pragmas that are not inside any function body. Called once +/// after the whole translation unit has been parsed. +void checkTranslationUnit(clang::ASTContext &astCtx); + +/// Check-only mode: associates and validates the pragmas of every function +/// definition in the translation unit (template instantiations included) +/// without generating code; outcomes go to the report. +void checkAllFunctions(clang::ASTContext &astCtx); + +/// Associates and validates all pragmas inside the body of `FD` and sets the +/// function-level and parameter-level attributes on `func`. `argOffset` is +/// the index of the first source parameter among the function's arguments +/// (1 for instance methods, which take `this` first). +void enterFunction(const clang::FunctionDecl *FD, mlir::func::FuncOp func, + unsigned argOffset); + +/// Returns `base`, tagged if `loop` is the target of any pragma. Used for +/// the op that evaluates the loop's exit condition (or the affine.for). +mlir::Location loopLocation(const clang::Stmt *loop, mlir::Location base); + +/// Called for the op that provides storage of a local variable (alloca). +void onLocalStorage(const clang::VarDecl *VD, mlir::Operation *storage); + +/// Called when a global (namespace-scope or static local) is created. +void onGlobal(const clang::VarDecl *VD, mlir::Operation *global); + +/// Called with the value assigned to `VD` (by `=`, `op=` or an initializer); +/// used by `bind_op`. +void onAssignedValue(const clang::VarDecl *VD, mlir::Value value); + +/// Finishes the translation unit: applies attributes to globals and reports +/// pragmas whose target never materialized during codegen. +void endTranslationUnit(); + +//===-- MLIR stage -------------------------------------------------------===// + +/// Turns location tags into `hls.*` attributes and strips the tags. When +/// `reportLost` is set, warns about tagged targets that no longer exist +/// (e.g. a fully unrolled loop or a variable promoted to registers). +void materialize(mlir::ModuleOp module, bool reportLost); + +/// An AGGREGATE pragma on a parameter (or on `this` of a member function) +/// reaches the variable a call passes to it, as in Vitis (VITIS_NOTES N37 +/// S2 (b), (c) in the hls-est tree): every call to a function with an +/// `hls.aggregate` argument marks the alloca, memref.global or caller +/// argument the actual is a whole-element view of, transitively, with the +/// callee's entry plus `from = `. A variable that already carries +/// `hls.aggregate` keeps its own. Off with --hls-propagate-aggregate=false. +void propagateAggregate(mlir::ModuleOp module); + +/// propagateAggregate() as a pass; add it before cgeist's inliner, which +/// removes the calls that carry the information. +std::unique_ptr createPropagateAggregatePass(); + +//===-- Inlining ---------------------------------------------------------===// + +/// Registers cgeist's inliner interface for the func dialect, in place of +/// mlir::func::registerInlinerExtension. It is MLIR's interface with one +/// rule added: a call to a function marked `#pragma HLS inline off` +/// (attribute `hls.inline_off`, set with --hls-annotate) is not inlined, so +/// the call stays a func.call as in Vitis, which keeps such a function as +/// its own module. --hls-ignore-inline-off restores the former behaviour +/// (every call is inlined). A dialect keeps the first interface registered +/// for it, so this must run before mlir::registerAllExtensions. +void registerInlinerExtension(mlir::DialectRegistry ®istry); + +/// Whether the func dialect of `ctx` uses the interface registered by +/// registerInlinerExtension() (loads the func dialect). +/// --xlx-headers (HLSPragma.cc). +bool xlxHeaders(); + +/// Whether `rd` is an ap_fixed / ap_ufixed / ap_fixed_base class of the +/// Vitis headers, or derives from one. +bool isApFixedClass(const clang::CXXRecordDecl *rd); + +bool inlinerExtensionActive(mlir::MLIRContext *ctx); + +/// --hls-keep-misfit-inline-off: an `inline off` call whose array argument +/// does not fit the parameter's first dimension is kept (the argument +/// reinterpreted to the parameter type). +bool keepMisfitInlineOff(); + +} // namespace hls +} // namespace cgeist + +#endif // CGEIST_LIB_HLSPRAGMA_H diff --git a/tools/cgeist/Lib/HLSPragmaInternal.h b/tools/cgeist/Lib/HLSPragmaInternal.h new file mode 100644 index 000000000000..040ea76cefed --- /dev/null +++ b/tools/cgeist/Lib/HLSPragmaInternal.h @@ -0,0 +1,273 @@ +//===- HLSPragmaInternal.h - HLS pragma data model --------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Data model shared by the parser (HLSPragmaParse.cc), the association and +// validation stage (HLSPragmaSema.cc) and materialization +// (HLSPragmaMaterialize.cc). Not part of the public interface. +// +//===----------------------------------------------------------------------===// + +#ifndef CGEIST_LIB_HLSPRAGMAINTERNAL_H +#define CGEIST_LIB_HLSPRAGMAINTERNAL_H + +#include "HLSPragma.h" + +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/SourceLocation.h" +#include "mlir/IR/Attributes.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" + +#include +#include +#include +#include + +namespace clang { +class SourceManager; +} // namespace clang + +namespace cgeist { +namespace hls { + +//===----------------------------------------------------------------------===// +// Pragma specifications +//===----------------------------------------------------------------------===// + +/// Where a pragma of a given kind attaches. +enum class Placement { + Loop, ///< innermost enclosing loop; error outside loops + LoopOrFunction, ///< innermost enclosing loop, else the function + Function, ///< enclosing function + Variable, ///< the storage named by the `variable` option + Port, ///< the parameter named by `port` (or `return`) +}; + +/// Value type of an option. +enum class OptType { + Flag, ///< boolean; bare `opt`, or `opt=true|false|1|0` + Int, ///< integer constant expression (macros, constexpr, enums) + Number, ///< integer or floating point literal + Enum, ///< one identifier out of a fixed, case-insensitive set + Variable, ///< C identifier, optionally a member path `a.b.c` + Name, ///< free-form name (e.g. `foo`, a bundle name) + NameList, ///< comma-separated names + IntList, ///< comma-separated integer constant expressions + IntOrEnum ///< integer constant expression, or one of an enum set +}; + +struct OptionSpec { + llvm::StringRef name; + OptType type; + std::vector values; ///< Enum/IntOrEnum values + bool required = false; + /// Enum values may be written bare (`#pragma HLS array_partition cyclic`). + bool positional = false; + std::optional min; + /// Key in the emitted dictionary (defaults to `name`). + llvm::StringRef attrKey; + /// Default emitted when the option is omitted. + enum class DefaultKind { None, Bool, Int, String } defaultKind = + DefaultKind::None; + bool defaultBool = false; + int64_t defaultInt = 0; + llvm::StringRef defaultString; + /// Emit enum values upper-case (`direction=raw` -> "RAW"). + bool upperCase = false; + + llvm::StringRef key() const { return attrKey.empty() ? name : attrKey; } + /// Spelling used in diagnostics (`II`, not `ii`). + llvm::StringRef displayName() const { + return key().equals_insensitive(name) ? key() : name; + } +}; + +enum class Multiplicity { + Single, ///< one per target + PerVariable, ///< one per (target, variable[, dim]) + Many, ///< any number; only exact duplicates are diagnosed +}; + +struct PragmaSpec { + llvm::StringRef name; ///< canonical lower-case name + Placement placement; + std::vector options; + bool hasOff = false; ///< supports `off` -> `hls._off` + Multiplicity multiplicity = Multiplicity::Single; + + const OptionSpec *findOption(llvm::StringRef lowerName) const; + /// Returns the option whose enum values contain `lowerValue` and that may + /// be written positionally. + const OptionSpec *findPositional(llvm::StringRef lowerValue) const; +}; + +/// All known pragmas. Lookup is by lower-case name. +const PragmaSpec *lookupPragmaSpec(llvm::StringRef lowerName); +llvm::ArrayRef allPragmaSpecs(); + +//===----------------------------------------------------------------------===// +// Parsed pragmas +//===----------------------------------------------------------------------===// + +/// One token of an option value, after macro expansion. +struct ValueToken { + enum Kind { Number, Identifier, String, Punct } kind; + std::string text; + clang::SourceLocation loc; +}; + +/// `this` or `*this` written as a pragma variable (Vitis header pragmas such +/// as `#pragma HLS aggregate variable=this`). +bool isThisReference(const std::vector &v); + +struct ParsedOption { + std::string name; ///< canonical lower-case option name + std::string spelling; + clang::SourceLocation loc; + const OptionSpec *spec = nullptr; + /// Positional enum value written without `name=`. + bool positional = false; + bool hasValue = false; + std::vector value; + + std::string valueText() const; +}; + +struct PragmaRecord { + unsigned id = 0; + const PragmaSpec *spec = nullptr; ///< null for unknown pragmas + std::string kindName; ///< lower-case pragma name as written + clang::SourceLocation loc; ///< location of `#pragma` / `_Pragma` + std::string text; ///< normalized text after `HLS` + std::string locString; ///< "file:line:col" for late diagnostics + std::vector options; + bool valid = true; ///< false after a syntax error + bool associated = false; ///< bound to a function that is emitted + int report = -1; ///< index into State::report + + bool isUnknown() const { return spec == nullptr; } + const ParsedOption *get(llvm::StringRef name) const; + bool isOff() const; +}; + +//===----------------------------------------------------------------------===// +// Location tags and per-process state +//===----------------------------------------------------------------------===// + +/// What kind of op a tag may be materialized on. +enum class TagClass { Loop, Storage, Operation }; + +/// One target that is identified through a location tag. +struct TagRecord { + unsigned id = 0; + TagClass cls = TagClass::Loop; + /// Attributes to add: name -> ArrayAttr of entries, or UnitAttr. + llvm::SmallVector, 2> attrs; + /// For TagClass::Operation: accepted op names (e.g. "arith.muli"). + llvm::SmallVector opNames; + /// For TagClass::Operation: required float width (0 = integer op / any). + unsigned floatWidth = 0; + std::string pragmaName; ///< for diagnostics + std::string what; ///< e.g. "loop", "variable 'buf'" + std::string locString; + std::string funcName; ///< symbol of the function containing the target + llvm::SmallVector reports; ///< State::report entries it serves + bool tagged = false; ///< some op received the tag during codegen + bool materialized = false; ///< some op received the attributes +}; + +/// Pending attributes for a global variable. +struct GlobalTarget { + llvm::SmallVector, 2> attrs; + std::string pragmaName; + std::string name; + clang::SourceLocation loc; + mlir::Operation *op = nullptr; + llvm::SmallVector reports; +}; + +/// What finally happened to one pragma (--hls-pragma-report). +struct ReportEntry { + std::string loc; + std::string pragma; ///< "#pragma HLS " + std::vector outcomes; +}; + +class State { +public: + static State &get(); + + // Per translation unit. + clang::Preprocessor *PP = nullptr; + mlir::MLIRContext *mlirCtx = nullptr; + std::vector pragmas; + /// Pragma ids already associated (prevents duplicate diagnostics when the + /// same body is visited twice). + llvm::DenseMap analyzedFunctions; + llvm::DenseMap loopTags; + llvm::DenseMap storageTags; + llvm::DenseMap> + assignTags; + llvm::DenseMap globals; + llvm::DenseMap globalOps; + /// Warnings for bind_op pragmas whose operation was never seen. + bool checkedTU = false; + /// True while running checkAllFunctions (no codegen, no materialization). + bool checkOnlyMode = false; + + // Persistent across translation units (consumed after the pipeline). + std::vector tags; + /// The tag that marks the stores of an inlined ap_fixed compound + /// assignment (hls.ap_compound_assign); created on first use. + std::optional compoundAssignTag; + std::vector report; + + /// Records an outcome for the pragma's report entry. + void addOutcome(int reportIndex, std::string outcome) { + if (reportIndex >= 0) + report[reportIndex].outcomes.push_back(std::move(outcome)); + } + bool hasOutcome(int reportIndex) const { + return reportIndex >= 0 && !report[reportIndex].outcomes.empty(); + } + + void resetTranslationUnit(); + + TagRecord &newTag(TagClass cls); + mlir::Location tag(mlir::Location base, unsigned tagId) const; + + // Diagnostics (valid during the translation unit only). + clang::DiagnosticBuilder error(clang::SourceLocation loc, + llvm::StringRef fmt); + clang::DiagnosticBuilder warning(clang::SourceLocation loc, + llvm::StringRef fmt); + clang::DiagnosticBuilder note(clang::SourceLocation loc, + llvm::StringRef fmt); + clang::DiagnosticBuilder remark(clang::SourceLocation loc, + llvm::StringRef fmt); + std::string locString(clang::SourceLocation loc) const; +}; + +/// Name of the location-tag metadata key. +constexpr llvm::StringLiteral kTagKey = "hls.tag"; + +/// Whether --hls-pragma-report is on. +bool reportEnabled(); + +/// Registers the catch-all pragma handler (HLSPragmaParse.cc). +void registerPragmaHandler(clang::Preprocessor &PP); + +/// `#pragma HLS ` as written in diagnostics. +std::string pragmaDisplayName(const PragmaRecord &P); + +} // namespace hls +} // namespace cgeist + +#endif // CGEIST_LIB_HLSPRAGMAINTERNAL_H diff --git a/tools/cgeist/Lib/HLSPragmaMaterialize.cc b/tools/cgeist/Lib/HLSPragmaMaterialize.cc new file mode 100644 index 000000000000..e137bb6761ea --- /dev/null +++ b/tools/cgeist/Lib/HLSPragmaMaterialize.cc @@ -0,0 +1,193 @@ +//===- HLSPragmaMaterialize.cc - Location tags to hls.* attributes --------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// After the pass pipeline, every op whose location carries an HLS tag gets +// the attributes recorded for that tag, provided the op is of the right kind +// (a loop for loop pragmas, an allocation for variable pragmas, a matching +// arithmetic op for bind_op). Tags are then removed from all locations so +// the printed IR (including debug info) is unaffected. +// +//===----------------------------------------------------------------------===// + +#include "HLSPragmaInternal.h" + +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/TypeUtilities.h" +#include "mlir/Interfaces/LoopLikeInterface.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/Support/raw_ostream.h" + +using namespace cgeist::hls; + +namespace { + +std::optional tagOf(mlir::FusedLoc loc) { + auto dict = llvm::dyn_cast_or_null(loc.getMetadata()); + if (!dict) + return std::nullopt; + if (auto id = dict.getAs(kTagKey)) + return id.getInt(); + return std::nullopt; +} + +void collectTags(mlir::Location loc, llvm::SetVector &ids) { + if (auto fused = llvm::dyn_cast(loc)) { + if (auto id = tagOf(fused)) + ids.insert(*id); + for (mlir::Location l : fused.getLocations()) + collectTags(l, ids); + } else if (auto call = llvm::dyn_cast(loc)) { + collectTags(call.getCallee(), ids); + } else if (auto nameLoc = llvm::dyn_cast(loc)) { + collectTags(nameLoc.getChildLoc(), ids); + } else if (auto opaque = llvm::dyn_cast(loc)) { + collectTags(opaque.getFallbackLocation(), ids); + } +} + +/// `loc` without HLS tags. +mlir::Location strip(mlir::Location loc) { + mlir::MLIRContext *ctx = loc.getContext(); + if (auto fused = llvm::dyn_cast(loc)) { + llvm::SmallVector inner; + for (mlir::Location l : fused.getLocations()) + inner.push_back(strip(l)); + mlir::Attribute meta = tagOf(fused) ? mlir::Attribute() : fused.getMetadata(); + if (inner.empty()) + return mlir::UnknownLoc::get(ctx); + return mlir::FusedLoc::get(inner, meta, ctx); + } + if (auto call = llvm::dyn_cast(loc)) + return mlir::CallSiteLoc::get(strip(call.getCallee()), + strip(call.getCaller())); + if (auto nameLoc = llvm::dyn_cast(loc)) + return mlir::NameLoc::get(nameLoc.getName(), strip(nameLoc.getChildLoc())); + return loc; +} + +bool accepts(const TagRecord &T, mlir::Operation *op) { + switch (T.cls) { + case TagClass::Loop: + return llvm::isa(op); + case TagClass::Storage: + return llvm::isa(op); + case TagClass::Operation: { + if (!llvm::is_contained(T.opNames, op->getName().getStringRef().str())) + return false; + if (!T.floatWidth) + return true; + auto ft = op->getNumResults() == 1 + ? llvm::dyn_cast(mlir::getElementTypeOrSelf( + op->getResult(0).getType())) + : mlir::FloatType(); + return ft && ft.getWidth() == T.floatWidth; + } + } + return false; +} + +void apply(const TagRecord &T, mlir::Operation *op) { + for (auto &[name, value] : T.attrs) { + auto oldArr = op->getAttrOfType(name); + auto newArr = llvm::dyn_cast(value); + if (oldArr && newArr) { + llvm::SmallVector all(oldArr.begin(), oldArr.end()); + for (mlir::Attribute a : newArr) + if (!llvm::is_contained(all, a)) + all.push_back(a); + op->setAttr(name, mlir::ArrayAttr::get(op->getContext(), all)); + } else { + op->setAttr(name, value); + } + } +} + +} // namespace + +void cgeist::hls::materialize(mlir::ModuleOp module, bool reportLost) { + State &S = State::get(); + + module->walk([&](mlir::Operation *op) { + llvm::SetVector ids; + collectTags(op->getLoc(), ids); + for (mlir::Region ®ion : op->getRegions()) + for (mlir::Block &block : region) + for (mlir::BlockArgument arg : block.getArguments()) + arg.setLoc(strip(arg.getLoc())); + if (ids.empty()) + return; + for (unsigned id : ids) { + if (id >= S.tags.size()) + continue; + TagRecord &T = S.tags[id]; + if (!accepts(T, op)) + continue; + apply(T, op); + T.materialized = true; + if (reportEnabled()) { + auto func = op->getParentOfType(); + std::string where = op->getName().getStringRef().str() + " (" + + T.what + ")" + + (func ? " in @" + func.getName().str() : ""); + for (int r : T.reports) + S.addOutcome(r, where); + } + } + op->setLoc(strip(op->getLoc())); + }); + + if (reportLost) { + for (TagRecord &T : S.tags) { + if (T.materialized || !T.tagged) + continue; + // A function that was not kept (e.g. inlined everywhere and removed) + // took the target with it; that is not a lost pragma. + if (!module.lookupSymbol(T.funcName)) { + for (int r : T.reports) + S.addOutcome(r, "not applied: @" + T.funcName + + " was removed (inlined into its callers or " + "unused), and so was the " + T.what); + continue; + } + T.materialized = true; // report once + for (int r : T.reports) + S.addOutcome(r, T.cls == TagClass::Operation + ? "not applied: the operation assigned to " + + T.what + " was folded away" + : "not applied: the " + T.what + + " was removed during optimization"); + llvm::errs() << T.locString << ": warning: '" << T.pragmaName << "': " + << (T.cls == TagClass::Loop + ? "the loop it applies to was removed during " + "optimization (e.g. fully unrolled or proven " + "dead)" + : T.cls == TagClass::Storage + ? T.what + " was promoted to registers or removed " + "during optimization" + : "the operation it binds was folded away during " + "optimization") + << "; the pragma has no effect\n"; + } + } + + if (reportEnabled()) { + for (ReportEntry &E : S.report) { + if (E.outcomes.empty()) + E.outcomes.push_back("not applied: the target was not emitted"); + for (const std::string &o : E.outcomes) + llvm::errs() << E.loc << ": remark: '" << E.pragma << "' -> " << o + << "\n"; + } + S.report.clear(); + } +} diff --git a/tools/cgeist/Lib/HLSPragmaParse.cc b/tools/cgeist/Lib/HLSPragmaParse.cc new file mode 100644 index 000000000000..0dea1fdb0a9c --- /dev/null +++ b/tools/cgeist/Lib/HLSPragmaParse.cc @@ -0,0 +1,518 @@ +//===- HLSPragmaParse.cc - Preprocessor stage of #pragma HLS --------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Turns `#pragma HLS ...` (any case, `_Pragma`, or produced by macros) into +// PragmaRecords. Only syntax and option types are checked here; placement, +// name resolution and cross-option semantics are HLSPragmaSema.cc's job. +// +//===----------------------------------------------------------------------===// + +#include "HLSPragmaInternal.h" + +#include "clang/Lex/LexDiagnostic.h" +#include "clang/Lex/Pragma.h" +#include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" + +#include + +using namespace clang; +using namespace cgeist::hls; +using llvm::StringRef; + +namespace { + +/// Tokens of the option list, grouped into "words". +struct RawToken { + Token tok; + std::string spelling; +}; + +bool isIdentifierLike(const Token &T) { + return T.getIdentifierInfo() != nullptr; +} + +bool isPunct(const RawToken &T, StringRef s) { + return !isIdentifierLike(T.tok) && T.tok.isNot(tok::numeric_constant) && + T.tok.isNot(tok::string_literal) && T.spelling == s; +} + +/// Tokens that glue the value to the token before/after them even across +/// whitespace (`ports=a, b`, `foo< int >`, `N * 2`). +bool joinsNext(const RawToken &T) { + return llvm::is_contained( + std::initializer_list{",", ".", "::", "<", "(", "+", "-", + "*", "/", "%", "<<", ">>", "->", "&", + "|", "^", "~"}, + T.spelling); +} +bool joinsPrevious(const RawToken &T) { + return llvm::is_contained( + std::initializer_list{",", ".", "::", ">", ")", "+", "-", + "*", "/", "%", "<<", ">>", "->", "&", + "|", "^"}, + T.spelling); +} + +} // namespace + +/// `this` or `*this` as a pragma variable. +bool cgeist::hls::isThisReference(const std::vector &v) { + return (v.size() == 1 && v[0].text == "this") || + (v.size() == 2 && v[0].text == "*" && v[1].text == "this"); +} + +namespace { + +ValueToken::Kind classify(const Token &T) { + if (T.is(tok::numeric_constant)) + return ValueToken::Number; + if (tok::isStringLiteral(T.getKind())) + return ValueToken::String; + if (isIdentifierLike(T)) + return ValueToken::Identifier; + return ValueToken::Punct; +} + +class PragmaParser { +public: + PragmaParser(Preprocessor &PP, PragmaRecord &P, std::vector toks) + : PP(PP), S(State::get()), P(P), toks(std::move(toks)) {} + + void parse(); + +private: + Preprocessor &PP; + State &S; + PragmaRecord &P; + std::vector toks; + size_t pos = 0; + + bool atEnd() const { return pos >= toks.size(); } + const RawToken &peek(size_t n = 0) const { return toks[pos + n]; } + + void fail() { P.valid = false; } + std::vector parseValue(); + void checkOption(ParsedOption &O); +}; + +void PragmaParser::parse() { + std::string display = pragmaDisplayName(P); + while (!atEnd()) { + const RawToken &nameTok = peek(); + if (!isIdentifierLike(nameTok.tok)) { + // Vitis 2025.1 warns ([HLS 207-5571] "unexpected pragma argument '2', + // expects identifier") and drops the pragma for any token that is not + // an option name (the open-source front end's parseIdentifierLoc, + // ParseXlxPragma.cpp, gives the same warning for every non-identifier + // token): hlsyn-vitis aes has `#pragma HLS pipeline` and `#pragma HLS + // unroll 2` on loop L4, which Vitis pipelines (module + // aes256_encrypt_ecb_Pipeline_L4), not unrolls; `#pragma HLS pipeline + // =2` warns the same way and the loop is only pipelined automatically + // ([HLS 214-376], Target II = NA; kernel w8bfix_peq, VITIS_NOTES N32). + // cgeist rejected the `=` form with an error. + S.warning(nameTok.tok.getLocation(), + "unexpected argument '%1' in '%0', expected an option name; " + "the pragma is ignored, as Vitis ignores it") + << display << nameTok.spelling; + fail(); + return; + } + ParsedOption O; + O.spelling = nameTok.spelling; + O.name = StringRef(nameTok.spelling).lower(); + O.loc = nameTok.tok.getLocation(); + ++pos; + if (!atEnd() && isPunct(peek(), "=")) { + ++pos; + O.hasValue = true; + if (atEnd()) { + S.error(O.loc, "expected a value after '%0=' in '%1'") + << O.spelling << display; + fail(); + break; + } + O.value = parseValue(); + } + checkOption(O); + P.options.push_back(std::move(O)); + } + + if (P.isUnknown() || !P.valid) + return; + for (const OptionSpec &spec : P.spec->options) { + if (spec.required && !P.get(spec.name)) { + S.error(P.loc, "'%0' requires option '%1'") + << display << spec.displayName(); + fail(); + } + } +} + +std::vector PragmaParser::parseValue() { + std::vector value; + int depth = 0; + auto take = [&]() { + const RawToken &T = toks[pos++]; + if (T.spelling == "(" || T.spelling == "<") + ++depth; + else if (T.spelling == ")" || T.spelling == ">") + --depth; + else if (T.spelling == ">>") + depth -= 2; + value.push_back({classify(T.tok), T.spelling, T.tok.getLocation()}); + }; + take(); // the first token always belongs to the value (`key= value`) + // Whitespace separates options, except inside brackets and around + // operators and separators. + while (!atEnd()) { + const RawToken &next = peek(); + const RawToken &last = toks[pos - 1]; + if (isPunct(next, "=")) + break; + bool glued = depth > 0 || !next.tok.hasLeadingSpace() || + joinsNext(last) || joinsPrevious(next); + if (!glued) + break; + take(); + } + return value; +} + +/// Evaluates a flag value (`true`, `false`, `1`, `0`); nullopt if invalid. +std::optional flagValue(const ParsedOption &O) { + if (!O.hasValue) + return true; + if (O.value.size() != 1) + return std::nullopt; + std::string v = StringRef(O.value[0].text).lower(); + if (v == "true" || v == "1" || v == "on" || v == "yes") + return true; + if (v == "false" || v == "0" || v == "off" || v == "no") + return false; + return std::nullopt; +} + +bool isIntegerExpressionToken(const ValueToken &T) { + if (T.kind == ValueToken::Number || T.kind == ValueToken::Identifier) + return true; + return llvm::is_contained( + std::initializer_list{"+", "-", "*", "/", "%", "(", ")", + "<<", ">>", "&", "|", "^", "~", "::", ","}, + T.text); +} + +/// Whether a numeric literal is an integer (decimal, octal, hex, binary). +bool isIntegerLiteral(StringRef text) { + text = text.rtrim("uUlLzZ"); + if (text.starts_with_insensitive("0x")) + return text.size() > 2 && llvm::all_of(text.drop_front(2), llvm::isHexDigit); + if (text.starts_with_insensitive("0b")) + return text.size() > 2 && + llvm::all_of(text.drop_front(2), [](char c) { return c == '0' || c == '1'; }); + return !text.empty() && llvm::all_of(text, llvm::isDigit); +} + +bool isIntegerOperand(const ValueToken &T) { + return isIntegerExpressionToken(T) && + (T.kind != ValueToken::Number || isIntegerLiteral(T.text)); +} + +void PragmaParser::checkOption(ParsedOption &O) { + std::string display = pragmaDisplayName(P); + if (P.isUnknown()) + return; // preserved verbatim, nothing to check + + if (O.name == "off" && P.spec->hasOff) + O.spec = P.spec->findOption("off"); + else + O.spec = P.spec->findOption(O.name); + + // Positional enum value, e.g. `array_partition cyclic`. + if (!O.spec && !O.hasValue) { + if (const OptionSpec *pos = P.spec->findPositional(O.name)) { + O.spec = pos; + O.positional = true; + O.hasValue = true; + O.value = {{ValueToken::Identifier, O.spelling, O.loc}}; + O.name = pos->name.str(); + } else if (P.spec->name == "dependence" && + (O.name == "true" || O.name == "false")) { + // Vivado spelling: `#pragma HLS dependence variable=a inter false`. + O.spec = P.spec->findOption("dependent"); + O.positional = true; + O.hasValue = true; + O.value = {{ValueToken::Identifier, O.name, O.loc}}; + O.name = "dependent"; + } + } + + if (!O.spec) { + // Vitis 2025.1 drops an INTERFACE pragma with an option it does not know + // as a whole ([HLS 207-5570] "unexpected pragma parameter"; the open + // front end's XlxPragmaArgParser::parse returns false): kernel + // w9r14p_mx_bw (`m_axi ... bus_bitwidth=512`) gets an ap_memory port + // and no adapter, and the pragma's other options are never checked + // (its max_read_burst_length=512 is not rejected, as it is without + // bus_bitwidth: w9r14p_mx_nobw, [HLS 214-326]); class_ece8893 + // max_beaulieu lab3 (VITIS_NOTES N108). Every pragma goes through the + // same parser in the open front end, and Vitis drops the others the + // same way (CIRCT W9r14 review kernels w9r14rv_mx_ap: array_partition + // with an unknown option, the array stays one memory, 6; w9r14rv_mx_bs: + // bind_storage impl=bram with an unknown option, 0; max_beaulieu's + // `unroll II=1`, 207-5570). + S.warning(O.loc, "unknown option '%0' in '%1'; the pragma is ignored, " + "as Vitis ignores it") + << O.spelling << display; + fail(); + return; + } + + // Duplicate options. + for (const ParsedOption &prev : P.options) { + if (prev.spec == O.spec) { + S.error(O.loc, "option '%0' is specified more than once in '%1'") + << O.spec->displayName() << display; + S.note(prev.loc, "previous occurrence is here"); + fail(); + return; + } + } + + const OptionSpec &spec = *O.spec; + auto badValue = [&](StringRef expected) { + S.error(O.value.empty() ? O.loc : O.value.front().loc, + "invalid value '%0' for option '%1' in '%2': expected %3") + << O.valueText() << spec.displayName() << display << expected; + fail(); + }; + + if (spec.type != OptType::Flag && !O.hasValue) { + S.error(O.loc, "option '%0' in '%1' requires a value") + << spec.displayName() << display; + fail(); + return; + } + + switch (spec.type) { + case OptType::Flag: + if (!flagValue(O)) + badValue("'true' or 'false'"); + return; + case OptType::Enum: + case OptType::IntOrEnum: { + if (O.value.size() == 1 && O.value[0].kind == ValueToken::Identifier) { + std::string lower = StringRef(O.value[0].text).lower(); + if (llvm::is_contained(spec.values, StringRef(lower))) + return; + if (spec.type == OptType::Enum) { + std::string list; + for (StringRef v : spec.values) + list += (list.empty() ? "" : ", ") + v.str(); + badValue("one of: " + list); + return; + } + } + if (spec.type == OptType::IntOrEnum && + llvm::all_of(O.value, isIntegerOperand)) + return; + std::string list; + for (StringRef v : spec.values) + list += (list.empty() ? "" : ", ") + v.str(); + badValue(spec.type == OptType::Enum ? "one of: " + list + : "an integer or one of: " + list); + return; + } + case OptType::Int: + if (!llvm::all_of(O.value, isIntegerOperand)) + badValue("an integer constant"); + return; + case OptType::Number: + if (!llvm::all_of(O.value, isIntegerExpressionToken)) + badValue("a number"); + return; + case OptType::Variable: { + // ['*'] 'this' + // | ident ('::' ident)* ( ('.' | '->') ident | '[' expr ']' )* + // `this` names the enclosing object (Vitis hls_vector.h:110, + // hls_stream_39.h:162); the qualified name is a namespace-scope variable + // (Vitis etc/hls_hotbm_apfixed.h:91), as accepted by hls-llvm-project + // ee930469 ParseXlxPragma.cpp (variable= is parsed as an expression). + // Both forms are accepted only under --xlx-headers, so that the output + // without it stays as before (`variable=this` is an error there). + bool xlx = cgeist::hls::xlxHeaders(); + if (xlx && isThisReference(O.value)) + return; + // `variable=&s`: Vitis 2025.1 drops the `&` with [HLS 207-5544] "extra + // token before variable expression is ignored" (kernel + // w9r22i_c6_addr_var; Vitis_Libraries vision xf_cvt_color_1.hpp + // `variable=&uvStream`). + if (O.value.size() > 1 && O.value[0].text == "&" && + O.value[1].kind == ValueToken::Identifier) { + S.warning(O.value[0].loc, "extra token before variable expression is " + "ignored in '%0', as Vitis ignores it") + << display; + O.value.erase(O.value.begin()); + } + const std::vector &v = O.value; + bool ok = !v.empty() && v[0].kind == ValueToken::Identifier; + size_t i = 1; + while (ok && xlx && i + 1 < v.size() && v[i].text == "::" && + v[i + 1].kind == ValueToken::Identifier) + i += 2; + while (ok && i < v.size()) { + if ((v[i].text == "." || v[i].text == "->") && i + 1 < v.size() && + v[i + 1].kind == ValueToken::Identifier) { + i += 2; + } else if (v[i].text == "[") { + size_t close = i + 1; + while (close < v.size() && v[close].text != "]") + ++close; + ok = close < v.size() && close > i + 1 && + std::all_of(v.begin() + i + 1, v.begin() + close, + isIntegerOperand); + i = close + 1; + } else { + ok = false; + } + } + if (!ok) + badValue("a variable name"); + return; + } + case OptType::Name: + return; + case OptType::NameList: + case OptType::IntList: { + bool expectItem = true; + for (const ValueToken &T : O.value) { + if (T.text == ",") { + if (expectItem) + return badValue("a comma-separated list"); + expectItem = true; + } else { + if (spec.type == OptType::IntList && !isIntegerOperand(T)) + return badValue("a comma-separated list of integers"); + expectItem = false; + } + } + if (expectItem) + badValue("a comma-separated list"); + return; + } + } +} + +/// Catch-all handler: registered without a name at the root namespace, so it +/// sees every pragma clang has no handler for. That is how `hls`, `Hls` etc. +/// are recognised (clang's namespace lookup is case-sensitive). +class HLSPragmaHandler : public PragmaHandler { +public: + HLSPragmaHandler() : PragmaHandler(StringRef()) {} + + void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, + Token &FirstTok) override { + if (!FirstTok.getIdentifierInfo() || + !FirstTok.getIdentifierInfo()->getName().equals_insensitive("hls")) { + // What clang does when no handler matches; the preprocessor discards + // the rest of the line. + PP.Diag(FirstTok, diag::warn_pragma_ignored); + return; + } + + // Lex (with macro expansion) up to the end of the pragma. + std::vector toks; + Token T; + PP.Lex(T); + while (T.isNot(tok::eod) && T.isNot(tok::eof)) { + toks.push_back({T, PP.getSpelling(T)}); + PP.Lex(T); + } + + State &S = State::get(); + if (!isEnabled()) + return; // consumed silently, as before --hls-annotate existed + + PragmaRecord P; + P.id = S.pragmas.size(); + P.loc = Introducer.Loc; + P.locString = S.locString(Introducer.Loc); + + // Normalized text, used for diagnostics and hls.unknown_pragmas. + for (size_t i = 0; i < toks.size(); ++i) { + if (i && toks[i].tok.hasLeadingSpace()) + P.text += ' '; + P.text += toks[i].spelling; + } + + P.report = S.report.size(); + S.report.push_back({P.locString, "#pragma HLS " + P.text, {}}); + + // An empty `#pragma HLS` is accepted silently by Vitis 2025.1 + // (xf_max_suppression.hpp:203; no message in the harris logs): ignored. + if (toks.empty()) { + S.addOutcome(P.report, "ignored: empty pragma (as Vitis)"); + return; + } + if (!isIdentifierLike(toks[0].tok)) { + S.error(toks.empty() ? FirstTok.getLocation() + : toks[0].tok.getLocation(), + "expected a pragma name after '#pragma HLS'"); + S.addOutcome(P.report, "rejected: invalid syntax"); + return; + } + P.kindName = StringRef(toks[0].spelling).lower(); + P.spec = lookupPragmaSpec(P.kindName); + if (P.isUnknown()) + S.warning(toks[0].tok.getLocation(), + "unknown HLS pragma '%0'; it is preserved in " + "'hls.unknown_pragmas'") + << toks[0].spelling; + + toks.erase(toks.begin()); + PragmaParser(PP, P, std::move(toks)).parse(); + if (!P.valid) + S.addOutcome(P.report, "rejected: invalid syntax"); + S.pragmas.push_back(std::move(P)); + } +}; + +} // namespace + +std::string ParsedOption::valueText() const { + std::string s; + for (const ValueToken &T : value) + s += T.text; + return s; +} + +const ParsedOption *PragmaRecord::get(StringRef name) const { + for (const ParsedOption &O : options) + if (O.spec && O.spec->name == name) + return &O; + return nullptr; +} + +bool PragmaRecord::isOff() const { + if (!spec || !spec->hasOff) + return false; + const ParsedOption *O = get("off"); + if (!O) + return false; + std::optional v = flagValue(*O); + return v && *v; +} + +std::string cgeist::hls::pragmaDisplayName(const PragmaRecord &P) { + return "#pragma HLS " + P.kindName; +} + +void cgeist::hls::registerPragmaHandler(Preprocessor &PP) { + PP.AddPragmaHandler(new HLSPragmaHandler()); +} diff --git a/tools/cgeist/Lib/HLSPragmaSema.cc b/tools/cgeist/Lib/HLSPragmaSema.cc new file mode 100644 index 000000000000..4f0affc13508 --- /dev/null +++ b/tools/cgeist/Lib/HLSPragmaSema.cc @@ -0,0 +1,2477 @@ +//===- HLSPragmaSema.cc - Association and validation of #pragma HLS -------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Binds each pragma inside a function body to its target by source location, +// resolves variable names and integer constants in the scope of the pragma, +// validates Vitis semantics, detects conflicts, and records the attributes +// to emit. See docs/hls-pragmas.md for the rules implemented here. +// +//===----------------------------------------------------------------------===// + +#include +#include "HLSAutoInline.h" +#include "HLSPragmaInternal.h" + +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtCXX.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Lex/Preprocessor.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/BuiltinAttributes.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/MapVector.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/CommandLine.h" + +#include + +#include + +using namespace clang; +using namespace cgeist::hls; +using llvm::StringRef; + +static llvm::cl::opt HLSRejectPartitionConflicts( + "hls-reject-partition-conflicts", llvm::cl::init(false), + llvm::cl::desc("Reject a second '#pragma HLS array_partition' on a " + "dimension an earlier one partitions, instead of merging " + "them the Vitis way (the larger factor; the behaviour " + "before W10; for comparisons)")); + +static llvm::cl::opt HLSTripOnePipelineUnroll( + "hls-trip-one-pipeline-unroll", llvm::cl::init(false), + llvm::cl::desc("A pipeline pragma on a loop whose trip count is 1 " + "completely unrolls the loops inside it, and the loop is " + "removed with its pragmas, as Vitis does (VITIS_NOTES " + "N40); off: the pragma is lost with the folded loop. Off " + "by default until hls-est schedules the stream loops of " + "the only corpus designs with this shape (OPEN_ISSUES " + "O57)")); + +/// The bind_storage dictionary a legacy RESOURCE pragma's memory core +/// names: `RAM_2P_BRAM` -> {type = "ram_2p", impl = "bram"}, `RAM_1P` -> +/// {type = "ram_1p"}, `FIFO_SRL` -> {type = "fifo", impl = "srl"}; the +/// `variable` and `latency` entries are kept. nullopt for an operator core +/// (`Mul_LUT`, `AddSub_DSP`), which stays an `hls.resource` attribute. +static std::optional +lowerResourceCore(mlir::DictionaryAttr entry, mlir::Builder &b) { + auto core = entry.getAs("core"); + if (!core) + return std::nullopt; + llvm::SmallVector parts; + llvm::StringRef(core.getValue()).split(parts, '_'); + std::string kind = parts.front().lower(); + std::string type, impl; + size_t next = 1; + if ((kind == "ram" || kind == "rom") && parts.size() >= 2) { + type = kind + "_" + parts[1].lower(); + next = 2; + } else if (kind == "fifo") { + type = "fifo"; + } else { + return std::nullopt; + } + if (next < parts.size()) { + impl = llvm::join(llvm::ArrayRef(parts).drop_front(next), "_"); + impl = llvm::StringRef(impl).lower(); + } + llvm::SmallVector fields; + if (!impl.empty()) + fields.push_back(b.getNamedAttr("impl", b.getStringAttr(impl))); + if (auto latency = entry.get("latency")) + fields.push_back(b.getNamedAttr("latency", latency)); + fields.push_back(b.getNamedAttr("type", b.getStringAttr(type))); + if (auto variable = entry.get("variable")) + fields.push_back(b.getNamedAttr("variable", variable)); + return b.getDictionaryAttr(fields); +} + +namespace { + +//===----------------------------------------------------------------------===// +// Source ranges +//===----------------------------------------------------------------------===// + +/// A half-open region (begin, end] of source positions. +struct Region { + SourceLocation begin; ///< exclusive + SourceLocation end; ///< inclusive +}; + +//===----------------------------------------------------------------------===// +// Targets +//===----------------------------------------------------------------------===// + +enum class TargetKind { Function, Param, Loop, Local, Global, Operation }; + +struct TargetKey { + TargetKind kind; + const void *ptr; + unsigned index; + bool operator<(const TargetKey &o) const { + return std::tie(kind, ptr, index) < std::tie(o.kind, o.ptr, o.index); + } +}; + +/// An entry already placed on a target, for conflict detection. +struct Placed { + const PragmaRecord *pragma; + std::string key; + std::string attrName; + mlir::Attribute value; + std::string variable; + int64_t dim = -1; ///< array_partition/array_reshape only +}; + +struct TargetBucket { + TargetKey key; + std::string what; + llvm::MapVector, + std::map> + arrays; + llvm::SmallVector units; + std::vector placed; + // TargetKind::Operation (bind_op) + llvm::SmallVector opNames; + unsigned floatWidth = 0; + const VarDecl *var = nullptr; + const PragmaRecord *firstPragma = nullptr; + llvm::SmallVector reports; +}; + +/// Result of resolving a `variable=` / `port=` name. +struct Resolved { + enum Kind { None, Local, Param, Global, Return } kind = None; + const VarDecl *vd = nullptr; + unsigned paramIndex = 0; + QualType type; ///< type of the full member path + std::string path; + /// For a path of members only (`r.data`, `s.in.buf`): the position of + /// each member in cgeist's struct type of its record (bases first, then + /// fields), outermost first; empty for a plain variable or a path with a + /// subscript. + llvm::SmallVector memberPositions; + bool hasSubscript = false; + /// The name is a data member of the object an instance member function + /// runs on (`m_Val` in a constructor = `this->m_Val`): the path starts at + /// the function's `this` argument. + bool viaThis = false; +}; + +/// The position path of field `F` in record `RD` as cgeist lays the record +/// out (bases first, then fields), searching the bases depth first; empty +/// when `F` is not a member of `RD`. +static llvm::SmallVector fieldPositionPath(const RecordDecl *RD, + const FieldDecl *F, + unsigned depth = 0) { + if (!RD || depth > 8) + return {}; + RD = RD->getDefinition(); + if (!RD) + return {}; + unsigned bases = 0; + if (const auto *CXRD = dyn_cast(RD)) + bases = CXRD->getNumBases(); + if (F->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) + return {static_cast(bases) + F->getFieldIndex()}; + if (const auto *CXRD = dyn_cast(RD)) { + int64_t k = 0; + for (const CXXBaseSpecifier &B : CXRD->bases()) { + if (const RecordDecl *BRD = B.getType()->getAsRecordDecl()) { + llvm::SmallVector rest = + fieldPositionPath(BRD, F, depth + 1); + if (!rest.empty()) { + rest.insert(rest.begin(), k); + return rest; + } + } + ++k; + } + } + return {}; +} + +/// Dimensions of an array-like type: extents (-1 when unknown). +llvm::SmallVector arrayShape(QualType t) { + llvm::SmallVector shape; + while (true) { + t = t.getNonReferenceType().getCanonicalType(); + if (const auto *CAT = dyn_cast(t.getTypePtr())) { + shape.push_back(CAT->getSize().getSExtValue()); + t = CAT->getElementType(); + } else if (const auto *AT = dyn_cast(t.getTypePtr())) { + shape.push_back(-1); + t = AT->getElementType(); + } else if (const auto *PT = dyn_cast(t.getTypePtr())) { + shape.push_back(-1); + t = PT->getPointeeType(); + } else { + return shape; + } + } +} + +/// The array a class holds as its only data member, through its only base +/// and nested such classes (hls::vector holds a std::array, which +/// holds a T[N]): its dimensions; empty when the class is not such a wrapper. +llvm::SmallVector wrappedArrayShape(QualType t) { + for (int depth = 0; depth < 8; ++depth) { + t = t.getNonReferenceType().getCanonicalType(); + const auto *rd = t->getAsCXXRecordDecl(); + if (!rd || !rd->hasDefinition()) + return {}; + rd = rd->getDefinition(); + const FieldDecl *only = nullptr; + unsigned fields = 0; + for (const FieldDecl *f : rd->fields()) { + only = f; + ++fields; + } + if (fields == 0 && rd->getNumBases() == 1) { + t = rd->bases_begin()->getType(); + continue; + } + if (fields != 1 || rd->getNumBases() != 0) + return {}; + QualType ft = only->getType(); + if (isa(ft.getCanonicalType().getTypePtr())) + return arrayShape(ft); + t = ft; + } + return {}; +} + +/// The dimensions an array_partition / array_reshape pragma on a variable of +/// type `t` addresses, as the variable's memref has them: the array's own; +/// for a class wrapping one array (an hls::vector, a std::array) the +/// variable's one-element dimension, then the wrapped array's (Vitis +/// partitions the vector's lanes: class_ece8893 nikhil_p lab3; CIRCT +/// OPEN_ISSUES O76). +llvm::SmallVector partitionShape(QualType t) { + llvm::SmallVector shape = arrayShape(t); + if (!shape.empty()) + return shape; + llvm::SmallVector wrapped = wrappedArrayShape(t); + if (wrapped.empty()) + return {}; + shape.push_back(1); + shape.append(wrapped.begin(), wrapped.end()); + return shape; +} + +/// Identifier of a declaration, or "" for unnamed / non-identifier names +/// (operators, structured bindings), where getName() would assert. +StringRef identName(const NamedDecl *ND) { + if (const IdentifierInfo *II = ND->getIdentifier()) + return II->getName(); + return ""; +} + +/// Maps a bind_op `op` value to MLIR op names and a float width. +void bindOpTarget(StringRef op, llvm::SmallVectorImpl &names, + unsigned &width) { + width = 0; + StringRef base = op; + if (op.size() > 1 && (op[0] == 'f' || op[0] == 'd' || op[0] == 'h')) { + width = op[0] == 'f' ? 32 : op[0] == 'd' ? 64 : 16; + base = op.drop_front(); + } + if (width == 0) { + if (base == "add") + names.push_back("arith.addi"); + else if (base == "sub") + names.push_back("arith.subi"); + else if (base == "mul") + names.push_back("arith.muli"); + return; + } + if (base == "add") + names.push_back("arith.addf"); + else if (base == "sub") + names.push_back("arith.subf"); + else if (base == "mul") + names.push_back("arith.mulf"); + else if (base == "div" || base == "recip") + names.push_back("arith.divf"); + else if (base == "sqrt") + names.push_back("math.sqrt"); + else if (base == "rsqrt") + names.push_back("math.rsqrt"); + else if (base == "exp") + names.push_back("math.exp"); + else if (base == "log") + names.push_back("math.log"); +} + +//===----------------------------------------------------------------------===// +// FunctionSema +//===----------------------------------------------------------------------===// + +class FunctionSema { +public: + FunctionSema(const FunctionDecl *FD, mlir::func::FuncOp func, + unsigned argOffset) + : FD(FD), func(func), argOffset(argOffset), AC(FD->getASTContext()), + SM(AC.getSourceManager()), S(State::get()), + b(func->getContext()) {} + + void run(); + +private: + const FunctionDecl *FD; + mlir::func::FuncOp func; + unsigned argOffset; + ASTContext &AC; + SourceManager &SM; + State &S; + mlir::Builder b; + + struct LoopInfo { + const Stmt *stmt; + Region region; + unsigned depth; + }; + struct DeclInfo { + const VarDecl *vd; + SourceRange scope; + }; + struct BlockInfo { + SourceRange range; + std::vector> children; // begin, isLoop + }; + std::vector loops; + std::vector decls; + std::vector blocks; + std::vector excluded; + std::vector usingDirectives; + std::map loopLabels; + llvm::DenseSet placedReports; + std::map buckets; + std::vector bucketOrder; + + // Source helpers. + bool before(SourceLocation a, SourceLocation b) const { + return SM.isBeforeInTranslationUnit(a, b); + } + bool inRegion(const Region &r, SourceLocation p) const { + return before(r.begin, p) && !before(r.end, p); + } + bool inRange(SourceRange r, SourceLocation p) const { + return !before(p, r.getBegin()) && !before(r.getEnd(), p); + } + bool rangeInside(SourceRange inner, SourceRange outer) const { + return !before(inner.getBegin(), outer.getBegin()) && + !before(outer.getEnd(), inner.getEnd()); + } + + void index(const Stmt *s, SourceRange scope, unsigned depth); + bool belongsHere(SourceLocation p) const; + const LoopInfo *innermostLoop(SourceLocation p) const; + bool loopFollows(SourceLocation p) const; + const BlockInfo *innermostBlock(SourceLocation p) const; + bool inFunctionOrForBody(SourceLocation p, const LoopInfo *loop) const; + + Resolved resolveVariable(const PragmaRecord &P, const ParsedOption &O, + bool allowReturn); + const VarDecl *lookupLocal(StringRef name, SourceLocation p) const; + const NamedDecl *lookupNonLocal(StringRef name) const; + std::optional lookupConstant(StringRef name, SourceLocation p); + std::optional callConstant(StringRef name, + llvm::ArrayRef args); + std::optional evalInt(const PragmaRecord &P, const ParsedOption &O); + + void process(PragmaRecord &P); + std::optional + buildEntry(const PragmaRecord &P, const Resolved &var, bool isOff, + int64_t &dimOut); + bool validate(const PragmaRecord &P, const Resolved &var, + llvm::SmallVectorImpl &fields); + void place(const PragmaRecord &P, TargetKey key, std::string what, + std::string attrName, mlir::Attribute value, std::string conflict, + std::string variable, int64_t dim); + void placePartition(const PragmaRecord &P, TargetKey key, std::string what, + std::string attrName, mlir::DictionaryAttr value, + std::string conflict, std::string variable, int64_t dim, + int64_t rank); + mlir::DictionaryAttr withDim(mlir::DictionaryAttr entry, int64_t dim); + TargetBucket &bucket(TargetKey key, std::string what); + void applyTripOnePipelines(); + void flush(); + + mlir::NamedAttribute named(StringRef k, mlir::Attribute v) { + return b.getNamedAttr(k, v); + } +}; + +void FunctionSema::index(const Stmt *s, SourceRange scope, unsigned depth) { + if (!s) + return; + if (const auto *L = dyn_cast(s)) { + excluded.push_back(L->getBody()->getSourceRange()); + return; + } + if (isa(s)) { + excluded.push_back(s->getSourceRange()); + return; + } + if (const auto *DS = dyn_cast(s)) { + for (const Decl *D : DS->decls()) { + if (const auto *VD = dyn_cast(D)) { + decls.push_back({VD, scope}); + if (VD->getInit()) + index(VD->getInit(), scope, depth); + } else if (const auto *UD = dyn_cast(D)) { + usingDirectives.push_back(UD); + } else if (const auto *RD = dyn_cast(D)) { + for (const CXXMethodDecl *M : RD->methods()) + if (M->hasBody()) + excluded.push_back(M->getBody()->getSourceRange()); + } + } + return; + } + + if (const auto *LS = dyn_cast(s)) + loopLabels[LS->getSubStmt()] = LS->getName(); + + // A branch of an if whose condition is a constant (a template argument: + // Vitis_Libraries vision `if (USE_URAM) { bind_storage ... impl=URAM } + // else { bind_storage ... impl=BRAM }`) is not emitted, so the pragmas in + // it are not either (clang's CodeGenFunction::EmitIfStmt skips a constant + // dead arm; Vitis applies only the live arm's pragmas). Its pragmas do not + // belong to this function. + if (const auto *IS = dyn_cast(s)) { + const Expr *cond = IS->getCond(); + bool value = false; + if (cond && !IS->getConditionVariable() && !IS->getInit() && + !cond->isValueDependent() && + cond->EvaluateAsBooleanCondition(value, AC)) { + if (const Stmt *dead = value ? IS->getElse() : IS->getThen()) + excluded.push_back(dead->getSourceRange()); + } + } + + const Stmt *body = nullptr; + SourceLocation regionBegin, regionEnd; + if (const auto *F = dyn_cast(s)) { + body = F->getBody(); + regionBegin = F->getRParenLoc(); + } else if (const auto *W = dyn_cast(s)) { + body = W->getBody(); + regionBegin = W->getRParenLoc(); + } else if (const auto *R = dyn_cast(s)) { + body = R->getBody(); + regionBegin = R->getRParenLoc(); + } else if (const auto *D = dyn_cast(s)) { + body = D->getBody(); + regionBegin = D->getDoLoc(); + regionEnd = D->getWhileLoc(); + } + if (body) { + if (regionEnd.isInvalid()) + regionEnd = body->getEndLoc(); + loops.push_back({s, {regionBegin, regionEnd}, depth + 1}); + ++depth; + } + + SourceRange childScope = scope; + if (isa(s)) + childScope = s->getSourceRange(); + + if (const auto *CS = dyn_cast(s)) { + BlockInfo info; + info.range = CS->getSourceRange(); + for (const Stmt *c : CS->body()) { + const Stmt *inner = c; + while (const auto *LS = dyn_cast(inner)) + inner = LS->getSubStmt(); + info.children.push_back( + {c->getBeginLoc(), + isa(inner)}); + } + blocks.push_back(std::move(info)); + } + + for (const Stmt *c : s->children()) + index(c, childScope, depth); +} + +bool FunctionSema::belongsHere(SourceLocation p) const { + const Stmt *body = FD->getBody(); + if (!body || !before(body->getBeginLoc(), p) || + !before(p, body->getEndLoc())) + return false; + for (SourceRange r : excluded) + if (inRange(r, p)) + return false; + return true; +} + +const FunctionSema::LoopInfo * +FunctionSema::innermostLoop(SourceLocation p) const { + const LoopInfo *best = nullptr; + for (const LoopInfo &L : loops) + if (inRegion(L.region, p) && (!best || L.depth > best->depth)) + best = &L; + return best; +} + +const FunctionSema::BlockInfo * +FunctionSema::innermostBlock(SourceLocation p) const { + const BlockInfo *inner = nullptr; + for (const BlockInfo &B : blocks) + if (inRange(B.range, p) && (!inner || rangeInside(B.range, inner->range))) + inner = &B; + return inner; +} + +bool FunctionSema::inFunctionOrForBody(SourceLocation p, + const LoopInfo *loop) const { + const BlockInfo *inner = innermostBlock(p); + if (!inner) + return false; + if (inner->range == FD->getBody()->getSourceRange()) + return true; + if (!loop) + return false; + const Stmt *body = nullptr; + if (const auto *F = dyn_cast(loop->stmt)) + body = F->getBody(); + else if (const auto *R = dyn_cast(loop->stmt)) + body = R->getBody(); + return body && isa(body) && + inner->range == body->getSourceRange(); +} + +bool FunctionSema::loopFollows(SourceLocation p) const { + const BlockInfo *inner = innermostBlock(p); + if (!inner) + return false; + for (auto &[loc, isLoop] : inner->children) + if (before(p, loc)) + return isLoop; + return false; +} + +//===----------------------------------------------------------------------===// +// Name and constant resolution +//===----------------------------------------------------------------------===// + +const VarDecl *FunctionSema::lookupLocal(StringRef name, + SourceLocation p) const { + const DeclInfo *visible = nullptr, *later = nullptr; + for (const DeclInfo &D : decls) { + if (identName(D.vd) != name || !inRange(D.scope, p)) + continue; + const DeclInfo *&slot = before(D.vd->getLocation(), p) ? visible : later; + if (!slot || rangeInside(D.scope, slot->scope)) + slot = &D; + } + // C scoping first; Vitis also accepts a pragma placed before the + // declaration it names, in the same or an enclosing scope. + if (visible) + return visible->vd; + return later ? later->vd : nullptr; +} + +const NamedDecl *FunctionSema::lookupNonLocal(StringRef qualified) const { + llvm::SmallVector parts; + qualified.split(parts, "::"); + std::function lookupIn = + [&](const DeclContext *DC, StringRef name) -> const NamedDecl * { + if (name.empty()) + return nullptr; + DeclarationName DN(&AC.Idents.get(name)); + for (NamedDecl *ND : DC->lookup(DN)) { + // `using Base::B;` in a class: the declaration it brings in. + if (auto *shadow = dyn_cast(ND)) + return shadow->getTargetDecl(); + if (auto *ud = dyn_cast(ND)) { + for (UsingShadowDecl *shadow : ud->shadows()) + return shadow->getTargetDecl(); + continue; + } + return ND; + } + // A member of a class is also found in its bases (a static constexpr + // member of a base class template: Vitis_Libraries vision + // `COLS_ADDRBOUND`), as C++ name lookup does. + if (const auto *RD = dyn_cast(DC)) + if (RD->hasDefinition()) + for (const CXXBaseSpecifier &B : RD->getDefinition()->bases()) + if (const auto *BRD = B.getType()->getAsCXXRecordDecl()) + if (const NamedDecl *ND = lookupIn(BRD, name)) + return ND; + return nullptr; + }; + + // First component: enclosing contexts, then using-directives (those in the + // function body and those of each enclosing context). + const NamedDecl *found = nullptr; + size_t next = 1; + if (parts.size() > 1 && parts.front().empty()) { // ::name + found = lookupIn(AC.getTranslationUnitDecl(), parts[1]); + next = 2; + } else { + for (const DeclContext *DC = FD->getDeclContext(); DC && !found; + DC = DC->getParent()) { + found = lookupIn(DC, parts.front()); + for (const UsingDirectiveDecl *UD : DC->using_directives()) + if (!found) + found = lookupIn(UD->getNominatedNamespace(), parts.front()); + } + for (const UsingDirectiveDecl *UD : usingDirectives) + if (!found) + found = lookupIn(UD->getNominatedNamespace(), parts.front()); + } + // A type template parameter of this instantiation (or of an enclosing + // class template specialization) names its argument's class: + // `#pragma HLS PIPELINE II = CholeskyTraits::INNER_II` with CholeskyTraits + // a template parameter (Vitis_Libraries solver cholesky.hpp, qrf.hpp). + auto templateTypeArgument = [&](StringRef name) -> const NamedDecl * { + auto fromList = [&](const TemplateParameterList *params, + const TemplateArgumentList &args) -> const NamedDecl * { + for (unsigned i = 0; i < params->size() && i < args.size(); ++i) + if (identName(params->getParam(i)) == name && + args[i].getKind() == TemplateArgument::Type) + if (const auto *RD = args[i].getAsType()->getAsCXXRecordDecl()) + return RD; + return nullptr; + }; + if (const FunctionTemplateDecl *T = FD->getPrimaryTemplate()) + if (const TemplateArgumentList *args = FD->getTemplateSpecializationArgs()) + if (const NamedDecl *ND = fromList(T->getTemplateParameters(), *args)) + return ND; + for (const DeclContext *DC = FD->getDeclContext(); DC; DC = DC->getParent()) + if (const auto *CTS = dyn_cast(DC)) + if (const NamedDecl *ND = fromList( + CTS->getSpecializedTemplate()->getTemplateParameters(), + CTS->getTemplateArgs())) + return ND; + return nullptr; + }; + if (!found && parts.size() > 1 && !parts.front().empty()) + found = templateTypeArgument(parts.front()); + // Remaining components: members of namespaces, classes and enums; a + // typedef of a class names the class. + for (; found && next < parts.size(); ++next) { + if (const auto *TD = dyn_cast(found)) + if (const auto *RD = TD->getUnderlyingType()->getAsCXXRecordDecl()) + found = RD; + const auto *DC = dyn_cast(found); + if (!DC) + return nullptr; + found = lookupIn(DC, parts[next]); + } + return found; +} + +std::optional FunctionSema::lookupConstant(StringRef name, + SourceLocation p) { + if (name == "true") + return 1; + if (name == "false") + return 0; + + // Template arguments of this instantiation (function or enclosing class). + auto fromTemplate = [&](const TemplateParameterList *params, + const TemplateArgumentList &args) + -> std::optional { + for (unsigned i = 0; i < params->size() && i < args.size(); ++i) + if (identName(params->getParam(i)) == name && + args[i].getKind() == TemplateArgument::Integral) + return args[i].getAsIntegral().getSExtValue(); + return std::nullopt; + }; + if (const FunctionTemplateDecl *T = FD->getPrimaryTemplate()) + if (const TemplateArgumentList *args = FD->getTemplateSpecializationArgs()) + if (auto v = fromTemplate(T->getTemplateParameters(), *args)) + return v; + for (const DeclContext *DC = FD->getDeclContext(); DC; DC = DC->getParent()) + if (const auto *CTS = dyn_cast(DC)) + if (auto v = fromTemplate( + CTS->getSpecializedTemplate()->getTemplateParameters(), + CTS->getTemplateArgs())) + return v; + + auto evalVar = [&](const VarDecl *VD) -> std::optional { + if (!VD->getType()->isIntegralOrEnumerationType()) + return std::nullopt; + if (!VD->isConstexpr() && !VD->getType().isConstQualified()) + return std::nullopt; + // A static data member of a class template specialization is + // instantiated with its initializer (in-class initializers of static + // constexpr members are instantiated with the class). + const Expr *init = VD->getAnyInitializer(); + if (!init) + return std::nullopt; + Expr::EvalResult result; + if (init->EvaluateAsInt(result, AC)) + return result.Val.getInt().getSExtValue(); + return std::nullopt; + }; + if (!name.contains("::")) + if (const VarDecl *VD = lookupLocal(name, p)) + return evalVar(VD); + if (const NamedDecl *ND = lookupNonLocal(name)) { + if (const auto *EC = dyn_cast(ND)) + return EC->getInitVal().getSExtValue(); + if (const auto *VD = dyn_cast(ND)) + return evalVar(VD); + } + // An enumerator of an unscoped enum declared in the function body: + // `enum { fifo_depth = burst_len * 2 }; #pragma HLS STREAM ... depth = + // fifo_depth` (Vitis_Libraries database scan_col_2.hpp). Looked up last, + // so a name the lookups above resolve keeps its meaning. + if (!name.contains("::")) + for (const Decl *D : FD->decls()) + if (const auto *ED = dyn_cast(D)) + if (!ED->isScoped()) + for (const EnumConstantDecl *EC : ED->enumerators()) + if (identName(EC) == name) + return EC->getInitVal().getSExtValue(); + return std::nullopt; +} + +/// Evaluates `name(args)` for a constexpr function (or an already +/// instantiated specialization of a constexpr function template) with +/// integral parameters, using clang's constant evaluator on a synthesized +/// call expression. +std::optional +FunctionSema::callConstant(StringRef name, llvm::ArrayRef args) { + llvm::SmallVector candidates; + auto consider = [&](const NamedDecl *ND) { + if (const auto *FD = dyn_cast(ND)) + candidates.push_back(FD); + else if (const auto *FTD = dyn_cast(ND)) + for (const FunctionDecl *Spec : FTD->specializations()) + candidates.push_back(Spec); + }; + llvm::SmallVector parts; + name.split(parts, "::"); + if (const NamedDecl *first = lookupNonLocal(name)) { + // All overloads in the context that declares the first match. + const DeclContext *DC = first->getDeclContext()->getRedeclContext(); + DeclarationName DN(&AC.Idents.get(parts.back())); + for (const NamedDecl *ND : DC->lookup(DN)) + consider(ND); + if (candidates.empty()) + consider(first); + } + for (const FunctionDecl *FD : candidates) { + FD = FD->getDefinition() ? FD->getDefinition() : FD; + if (!FD->isConstexpr() || FD->getNumParams() != args.size()) + continue; + llvm::SmallVector argExprs; + bool ok = true; + for (unsigned i = 0; i < args.size() && ok; ++i) { + QualType T = FD->getParamDecl(i)->getType().getCanonicalType(); + if (!T->isIntegerType() || T->isBooleanType()) { + ok = false; + break; + } + unsigned width = AC.getIntWidth(T); + argExprs.push_back(IntegerLiteral::Create( + AC, llvm::APInt(width, (uint64_t)args[i], T->isSignedIntegerType()), + T.getUnqualifiedType(), SourceLocation())); + } + if (!ok) + continue; + auto *fn = const_cast(FD); + auto *ref = DeclRefExpr::Create(AC, NestedNameSpecifierLoc(), + SourceLocation(), fn, false, + SourceLocation(), fn->getType(), VK_LValue); + auto *callee = ImplicitCastExpr::Create( + AC, AC.getPointerType(fn->getType()), CK_FunctionToPointerDecay, ref, + nullptr, VK_PRValue, FPOptionsOverride()); + auto *callExpr = CallExpr::Create( + AC, callee, argExprs, fn->getReturnType().getNonReferenceType(), + VK_PRValue, SourceLocation(), FPOptionsOverride()); + Expr::EvalResult result; + if (callExpr->EvaluateAsInt(result, AC)) + return result.Val.getInt().getSExtValue(); + } + return std::nullopt; +} + +/// Parses an integer literal as spelled (after macro expansion). +std::optional parseIntLiteral(StringRef text) { + text = text.rtrim("uUlLzZ"); + int64_t v; + if (text.size() > 1 && text[0] == '0' && llvm::isDigit(text[1])) { + if (!text.drop_front().getAsInteger(8, v)) + return v; + return std::nullopt; + } + if (!text.getAsInteger(0, v)) + return v; + return std::nullopt; +} + +/// Recursive-descent evaluator for integer constant expressions in options. +class IntExprEvaluator { +public: + using Lookup = llvm::function_ref(StringRef)>; + using Call = llvm::function_ref( + StringRef, llvm::ArrayRef)>; + IntExprEvaluator(const std::vector &toks, Lookup lookup, + Call call) + : toks(toks), lookup(lookup), call(call) {} + + std::optional evaluate() { + auto v = parseBinary(0); + if (!v || pos != toks.size()) + return std::nullopt; + return v; + } + std::string unresolved; + +private: + const std::vector &toks; + Lookup lookup; + Call call; + size_t pos = 0; + + static int precedence(StringRef op) { + return llvm::StringSwitch(op) + .Cases("*", "/", "%", 5) + .Cases("+", "-", 4) + .Cases("<<", ">>", 3) + .Case("&", 2) + .Case("^", 1) + .Case("|", 0) + .Default(-1); + } + + std::optional parsePrimary() { + if (pos >= toks.size()) + return std::nullopt; + const ValueToken &T = toks[pos++]; + if (T.text == "(") { + auto v = parseBinary(0); + if (!v || pos >= toks.size() || toks[pos].text != ")") + return std::nullopt; + ++pos; + return v; + } + if (T.text == "-" || T.text == "+" || T.text == "~") { + auto v = parsePrimary(); + if (!v) + return std::nullopt; + return T.text == "-" ? -*v : T.text == "~" ? ~*v : *v; + } + if (T.kind == ValueToken::Number) + return parseIntLiteral(T.text); + if (T.kind == ValueToken::Identifier || T.text == "::") { + // Qualified name: [::] ident (:: ident)* + std::string name = T.text; + while (pos + 1 < toks.size() && toks[pos].text == "::" && + toks[pos + 1].kind == ValueToken::Identifier) { + name += "::" + toks[pos + 1].text; + pos += 2; + } + if (T.text == "::" && pos < toks.size() && + toks[pos].kind == ValueToken::Identifier) + name += toks[pos++].text; + // A call to a constexpr function: name(args...) + if (pos < toks.size() && toks[pos].text == "(") { + ++pos; + llvm::SmallVector args; + while (pos < toks.size() && toks[pos].text != ")") { + auto a = parseBinary(0); + if (!a) + return std::nullopt; + args.push_back(*a); + if (pos < toks.size() && toks[pos].text == ",") + ++pos; + } + if (pos >= toks.size()) + return std::nullopt; + ++pos; // ')' + if (auto v = call(name, args)) + return v; + if (unresolved.empty()) + unresolved = name + "(...)"; + return std::nullopt; + } + if (auto v = lookup(name)) + return v; + if (unresolved.empty()) + unresolved = name; + return std::nullopt; + } + return std::nullopt; + } + + std::optional parseBinary(int minPrec) { + auto lhs = parsePrimary(); + while (lhs && pos < toks.size()) { + int prec = precedence(toks[pos].text); + if (prec < minPrec || prec < 0) + break; + StringRef op = toks[pos++].text; + auto rhs = parseBinary(prec + 1); + if (!rhs) + return std::nullopt; + if ((op == "/" || op == "%") && *rhs == 0) + return std::nullopt; + int64_t l = *lhs, r = *rhs; + lhs = llvm::StringSwitch(op) + .Case("*", l * r) + .Case("/", r ? l / r : 0) + .Case("%", r ? l % r : 0) + .Case("+", l + r) + .Case("-", l - r) + .Case("<<", l << r) + .Case(">>", l >> r) + .Case("&", l & r) + .Case("^", l ^ r) + .Case("|", l | r) + .Default(0); + } + return lhs; + } +}; + +std::optional FunctionSema::evalInt(const PragmaRecord &P, + const ParsedOption &O) { + // Named: the evaluator only keeps function_refs to them. + auto lookup = [&](StringRef name) { return lookupConstant(name, P.loc); }; + auto call = [&](StringRef name, llvm::ArrayRef args) { + return callConstant(name, args); + }; + IntExprEvaluator eval(O.value, lookup, call); + std::optional v = eval.evaluate(); + if (v) + return v; + if (!eval.unresolved.empty()) + S.error(O.value.front().loc, + "cannot resolve '%0' to an integer constant in '%1'") + << eval.unresolved << pragmaDisplayName(P); + else + S.error(O.value.front().loc, + "invalid integer expression '%0' for option '%1' in '%2'") + << O.valueText() << O.spec->displayName() << pragmaDisplayName(P); + return std::nullopt; +} + +Resolved FunctionSema::resolveVariable(const PragmaRecord &P, + const ParsedOption &O, + bool allowReturn) { + Resolved R; + std::string path = O.valueText(); + R.path = path; + std::string display = pragmaDisplayName(P); + bool xlx = cgeist::hls::xlxHeaders(); + // A qualified name `ns::var` (Vitis etc/hls_hotbm_apfixed.h:91) is looked + // up as a non-local name; the member path starts after it. + std::string qualified = O.value.front().text; + size_t pathStart = 1; + while (xlx && pathStart + 1 < O.value.size() && + O.value[pathStart].text == "::" && + O.value[pathStart + 1].kind == ValueToken::Identifier) { + qualified += "::" + O.value[pathStart + 1].text; + pathStart += 2; + } + bool isQualified = pathStart > 1; + StringRef base = qualified; + bool isPlainName = O.value.size() == 1; + + if (allowReturn && base == "return" && isPlainName) { + R.kind = Resolved::Return; + return R; + } + + // `variable=this` inside an instance member function names the object the + // function is called on, which is the function's first argument. Vitis's + // own hls_vector.h relies on it (`SYN_PRAGMA(HLS AGGREGATE variable=this)` + // in the member functions), so an hls::vector variable is aggregated once + // such a member is applied to it; only the aggregate pragmas take it. + // Under --xlx-headers `*this` is the same object. + bool namesThis = (base == "this" && isPlainName) || + (xlx && isThisReference(O.value)); + if (namesThis && P.spec && + (P.spec->name == "aggregate" || P.spec->name == "disaggregate")) { + const auto *MD = dyn_cast(FD); + if (MD && MD->isInstance() && argOffset == 1) { + R.kind = Resolved::Param; + R.paramIndex = 0; + R.type = MD->getThisType(); + return R; + } + } + // Any other `this` / `*this` (Vitis header pragmas, e.g. hls_stream_39.h:162) + // is not a variable of this function; the pragma is reported and dropped. + // Only under --xlx-headers (the parser rejects `*this` without it). + if (xlx && isThisReference(O.value)) { + S.warning(O.value.front().loc, + "'%0' in '%1' names the enclosing object; ignored") + << path << display; + return {}; + } + + if (isQualified) { + // Only the non-local lookup below can find a qualified name. + } else if (const VarDecl *VD = lookupLocal(base, P.loc)) { + R.vd = VD; + R.kind = VD->hasGlobalStorage() ? Resolved::Global : Resolved::Local; + R.type = VD->getType(); + } else { + unsigned i = 0; + for (const ParmVarDecl *PV : FD->parameters()) { + if (identName(PV) == base) { + R.kind = Resolved::Param; + R.vd = PV; + R.paramIndex = argOffset + i; + R.type = PV->getOriginalType(); + break; + } + ++i; + } + } + if (R.kind == Resolved::None) { + if (const NamedDecl *ND = lookupNonLocal(base)) { + if (const auto *VD = dyn_cast(ND); + VD && VD->hasGlobalStorage()) { + R.kind = Resolved::Global; + R.vd = VD->getCanonicalDecl(); + R.type = VD->getType(); + } else if (const auto *F = dyn_cast(ND)) { + // A data member named inside an instance member function (a + // constructor partitioning its member array: Vitis_Libraries blas + // `WindowRm::m_Val`, security aes `key_list`) is `this->member`: + // Vitis parses the variable as an expression of the function + // (hls-llvm-project Parser::ParseHLSVariableExpression), so the + // pragma applies to that member of the object the function runs on. + // An array_partition / array_reshape keeps the member path + // (member_path on the `this` argument, carried to the object at + // inline time); any other pragma on a member is reported and dropped + // (not modelled). + const auto *MD = dyn_cast(FD); + llvm::SmallVector positions; + if (MD && MD->isInstance() && argOffset == 1) + positions = fieldPositionPath(MD->getParent(), F); + bool partition = P.spec && (P.spec->name == "array_partition" || + P.spec->name == "array_reshape"); + if (!positions.empty() && partition) { + R.kind = Resolved::Param; + R.paramIndex = 0; + R.type = F->getType(); + R.memberPositions = positions; + R.viaThis = true; + } else if (!positions.empty()) { + S.warning(O.value.front().loc, + "'%0' in '%1' names a data member of the object; the " + "pragma is ignored (only array_partition and " + "array_reshape on members are modelled)") + << base << display; + return {}; + } else { + S.error(O.value.front().loc, + "'%0' in '%1' names a class member; only local variables, " + "parameters and globals can be annotated") + << base << display; + return {}; + } + } + } + } + if (R.kind == Resolved::None && !isQualified) { + // Declared only in a nested scope that does not contain the pragma + // (e.g. a buffer inside a loop, pragma at the top of the function). + // Vitis resolves such names within the function; accept a unique match. + llvm::SmallVector nested; + for (const DeclInfo &D : decls) + if (identName(D.vd) == base) + nested.push_back(D.vd); + if (nested.size() == 1) { + S.warning(O.value.front().loc, + "'%0' is declared in a nested scope that does not contain " + "'%1'; using that declaration") + << base << display; + R.vd = nested.front(); + R.kind = R.vd->hasGlobalStorage() ? Resolved::Global : Resolved::Local; + R.type = R.vd->getType(); + } else if (nested.size() > 1) { + S.error(O.value.front().loc, + "'%0' in '%1' is ambiguous: it is declared in several nested " + "scopes that do not contain the pragma") + << base << display; + return {}; + } + } + if (R.kind == Resolved::None) { + S.error(O.value.front().loc, "use of undeclared variable '%0' in '%1'") + << base << display; + return {}; + } + + // Member and element path: s.a[2]->b + const std::vector &v = O.value; + for (size_t i = pathStart; i < v.size();) { + QualType t = R.type.getNonReferenceType(); + if (v[i].text == "[") { + size_t close = i + 1; + while (close < v.size() && v[close].text != "]") + ++close; + std::vector index(v.begin() + i + 1, v.begin() + close); + auto lookup = [&](StringRef n) { return lookupConstant(n, P.loc); }; + auto call = [&](StringRef n, llvm::ArrayRef a) { + return callConstant(n, a); + }; + std::optional idx = + IntExprEvaluator(index, lookup, call).evaluate(); + if (const auto *CAT = AC.getAsConstantArrayType(t)) { + int64_t size = CAT->getSize().getSExtValue(); + if (idx && (*idx < 0 || *idx >= size)) { + S.error(v[i].loc, "index %0 is out of range for '%1' of size %2 " + "(in '%3')") + << *idx << t.getAsString() << size << display; + return {}; + } + R.type = CAT->getElementType(); + } else if (const auto *AT = AC.getAsArrayType(t)) { + R.type = AT->getElementType(); + } else if (const auto *PT = t->getAs()) { + R.type = PT->getPointeeType(); + } else { + S.error(v[i].loc, "subscripted value of type '%0' is not an array " + "(in '%1')") + << t.getAsString() << display; + return {}; + } + i = close + 1; + R.hasSubscript = true; + continue; + } + // '.' or '->' member + StringRef member = v[i + 1].text; + if (const auto *PT = t->getAs()) + t = PT->getPointeeType(); + const RecordDecl *RD = t->getAsRecordDecl(); + const FieldDecl *found = nullptr; + if (RD) + for (const FieldDecl *F : RD->fields()) + if (identName(F) == member) + found = F; + if (!found) { + S.error(v[i + 1].loc, "no member named '%0' in '%1' (in '%2')") + << member << t.getAsString() << display; + return {}; + } + R.type = found->getType(); + unsigned bases = 0; + if (const auto *CXRD = dyn_cast(RD)) + bases = CXRD->getNumBases(); + R.memberPositions.push_back(static_cast(bases) + + found->getFieldIndex()); + i += 2; + } + if (R.hasSubscript) + R.memberPositions.clear(); + return R; +} + +//===----------------------------------------------------------------------===// +// Entries +//===----------------------------------------------------------------------===// + +std::optional +FunctionSema::buildEntry(const PragmaRecord &P, const Resolved &var, + bool isOff, int64_t &dimOut) { + llvm::SmallVector fields; + bool ok = true; + const PragmaSpec &spec = *P.spec; + + for (const OptionSpec &os : spec.options) { + if (os.name == "off") + continue; + const ParsedOption *O = P.get(os.name); + // With `off`, only the naming options (and dim) are kept. + if (isOff && os.type != OptType::Variable && os.name != "dim") + continue; + mlir::Attribute value; + if (O) { + switch (os.type) { + case OptType::Flag: { + std::string v = O->hasValue ? StringRef(O->valueText()).lower() + : std::string("true"); + value = b.getBoolAttr(v == "true" || v == "1" || v == "on" || + v == "yes"); + break; + } + case OptType::Int: { + std::optional v = evalInt(P, *O); + if (!v) { + ok = false; + continue; + } + // An unroll factor below 1, written as a literal (`factor=0`, + // `factor=-1`) or as an expression that folds below 1 (hp_fft_hls + // `unroll factor=UF>>(STAGE-1)` with UF 1, STAGE 2): Vitis 2025.1 + // ignores the pragma with a warning ([HLS 207-5577] "Unroll pragma + // is ignored, because 'factor' is not positive integer", kernels + // w9r6_uf0 and w9r6rev uflit0, CIRCT OPEN_ISSUES O70 (b)) and + // decides on the loop automatically; so does cgeist. Other options + // below their minimum stay errors (an array_partition factor that + // folds to 0 fails in Vitis too, [HLS 200-1715], kernel w9r6rev apz). + if (os.min && *v < *os.min && spec.name == "unroll" && + os.name == "factor") { + S.warning(O->value.front().loc, + "option '%0' in '%1' is %2, below %3; the pragma " + "is ignored, as Vitis ignores it") + << os.displayName() << pragmaDisplayName(P) << *v << *os.min; + return std::nullopt; + } + if (os.min && *v < *os.min) { + S.error(O->value.front().loc, + "option '%0' in '%1' must be >= %2, got %3") + << os.displayName() << pragmaDisplayName(P) << *os.min << *v; + ok = false; + continue; + } + if (*v > INT32_MAX || *v < INT32_MIN) { + S.error(O->value.front().loc, + "option '%0' in '%1' is out of range: %2") + << os.displayName() << pragmaDisplayName(P) << *v; + ok = false; + continue; + } + value = b.getI32IntegerAttr(*v); + break; + } + case OptType::Number: { + StringRef text = O->valueText(); + bool isFloat = O->value.size() == 1 && + O->value[0].kind == ValueToken::Number && + !text.starts_with("0x") && + text.find_first_of(".eE") != StringRef::npos; + if (isFloat) { + double d = std::strtod(text.rtrim("fFlL").str().c_str(), nullptr); + if (!(d > 0)) { + S.error(O->value.front().loc, + "option '%0' in '%1' must be positive, got %2") + << os.displayName() << pragmaDisplayName(P) << text; + ok = false; + continue; + } + value = b.getF64FloatAttr(d); + } else { + std::optional v = evalInt(P, *O); + if (!v) { + ok = false; + continue; + } + if (*v <= 0 || *v > INT32_MAX) { + S.error(O->value.front().loc, + "option '%0' in '%1' must be positive, got %2") + << os.displayName() << pragmaDisplayName(P) << *v; + ok = false; + continue; + } + value = b.getI32IntegerAttr(*v); + } + break; + } + case OptType::Enum: + case OptType::IntOrEnum: { + std::string lower = StringRef(O->valueText()).lower(); + if (llvm::is_contained(os.values, StringRef(lower))) { + value = b.getStringAttr(os.upperCase ? StringRef(lower).upper() + : lower); + } else if (O->value.size() == 1 && + O->value[0].kind == ValueToken::Identifier && + !lookupConstant(O->value[0].text, P.loc)) { + // Neither an enumerator of the option nor a named constant. + std::string list; + for (StringRef v : os.values) + list += (list.empty() ? "" : ", ") + v.str(); + S.error(O->value.front().loc, + "invalid value '%0' for option '%1' in '%2': expected an " + "integer or one of: %3") + << O->valueText() << os.displayName() << pragmaDisplayName(P) + << list; + ok = false; + continue; + } else { + std::optional v = evalInt(P, *O); + if (!v) { + ok = false; + continue; + } + value = b.getI32IntegerAttr(*v); + } + break; + } + case OptType::Variable: + // A member of `this` reads as the member path `this.m_Val`, which + // hls-est's struct splitting places on the member's memory. + value = b.getStringAttr(var.viaThis ? "this." + O->valueText() + : O->valueText()); + break; + case OptType::Name: + value = b.getStringAttr(O->valueText()); + break; + case OptType::NameList: + case OptType::IntList: { + llvm::SmallVector items; + ParsedOption item = *O; + auto flushItem = [&]() { + if (os.type == OptType::NameList) { + items.push_back(b.getStringAttr(item.valueText())); + } else if (auto v = evalInt(P, item)) { + items.push_back(b.getI32IntegerAttr(*v)); + } else { + ok = false; + } + item.value.clear(); + }; + item.value.clear(); + for (const ValueToken &T : O->value) { + if (T.text == ",") + flushItem(); + else + item.value.push_back(T); + } + flushItem(); + value = b.getArrayAttr(items); + break; + } + } + } else { + switch (os.defaultKind) { + case OptionSpec::DefaultKind::None: + continue; + case OptionSpec::DefaultKind::Bool: + value = b.getBoolAttr(os.defaultBool); + break; + case OptionSpec::DefaultKind::Int: + value = b.getI32IntegerAttr(os.defaultInt); + break; + case OptionSpec::DefaultKind::String: + value = b.getStringAttr(os.defaultString); + break; + } + // A stream pragma without a depth: the consumer needs to know that + // the depth is the default, because Vitis's default depends on the + // variable: 2 for an hls::stream, the array's size for an array + // (CIRCT W9 round 8 review defect 4, kernel w9r8rev s1_nodepth.cpp: + // `#pragma HLS stream variable=buf` on int buf[1024] is + // fifo_w32_d1024). The depth key keeps the default 2. + if (spec.name == "stream" && os.name == "depth") + fields.push_back(named("depth_defaulted", b.getUnitAttr())); + } + fields.push_back(named(os.key(), value)); + } + if (!ok) + return std::nullopt; + // An array_partition on a member path: which member, by its position in + // the struct type, so that hls-est's struct splitting finds the member's + // memory in a struct with several array members (CIRCT OPEN_ISSUES O78; + // W9r7 review defect 10, kernel w9r7rev_mp_two). + if ((spec.name == "array_partition" || spec.name == "array_reshape") && + !var.memberPositions.empty()) { + llvm::SmallVector positions; + for (int64_t p : var.memberPositions) + positions.push_back(b.getI32IntegerAttr(static_cast(p))); + fields.push_back(named("member_path", b.getArrayAttr(positions))); + } + if (!isOff && !validate(P, var, fields)) + return std::nullopt; + if (isOff) { + for (const ParsedOption &O : P.options) + if (O.spec && O.spec->name != "off" && + O.spec->type != OptType::Variable && O.spec->name != "dim") { + S.warning(O.loc, "option '%0' is ignored because '%1' has 'off'") + << O.spec->displayName() << pragmaDisplayName(P); + break; + } + } + + mlir::DictionaryAttr dict = b.getDictionaryAttr(fields); + if (auto d = dict.getAs("dim")) + dimOut = d.getInt(); + return dict; +} + +/// Pragma-specific semantic checks. May adjust `fields`. +bool FunctionSema::validate(const PragmaRecord &P, const Resolved &var, + llvm::SmallVectorImpl &fields) { + StringRef name = P.spec->name; + std::string display = pragmaDisplayName(P); + auto get = [&](StringRef key) -> mlir::Attribute { + for (auto &f : fields) + if (f.getName() == key) + return f.getValue(); + return {}; + }; + auto getInt = [&](StringRef key) -> std::optional { + if (auto a = llvm::dyn_cast_or_null(get(key))) + return a.getInt(); + return std::nullopt; + }; + auto erase = [&](StringRef key) { + llvm::erase_if(fields, [&](auto &f) { return f.getName() == key; }); + }; + auto locOf = [&](StringRef opt) { + const ParsedOption *O = P.get(opt); + return O ? O->loc : P.loc; + }; + + if (name == "array_partition" || name == "array_reshape") { + llvm::SmallVector shape = arrayShape(var.type); + if (shape.empty() && !partitionShape(var.type).empty()) { + // A class wrapping an array (a single hls::vector, not an array of + // them): Vitis ignores the pragma ([HLS 214-253] "Ignored unsupported + // array_partition pragma on variable"; kernel w9r7fix_vp_local and + // class_ece8893 nikhil_p lab3 `col_ptr_B_local`; W9r7 review defect + // 8a), so it is dropped with a warning instead of rejected. + S.warning(locOf("variable"), + "'%0' on '%1' of class type '%2' is ignored (Vitis: " + "unsupported array_partition pragma)") + << display << var.path << var.type.getAsString(); + return false; + } + if (shape.empty()) { + // A scalar of class type (an ap_uint<64>): Vitis 2025.1 accepts the + // pragma without a message and nothing is partitioned (kernel + // w9r22i_c7_array_typedef; Vitis_Libraries blas transpMatB2.hpp + // `l_valIn`); a scalar of a builtin type stays an error. + if (var.type.getNonReferenceType()->isRecordType()) { + S.warning(locOf("variable"), + "'%0' on the scalar '%1' of type '%2' is ignored, as Vitis " + "ignores it") + << display << var.path << var.type.getAsString(); + return false; + } + S.error(locOf("variable"), + "'%0' requires an array or pointer, but '%1' has type '%2'") + << display << var.path << var.type.getAsString(); + return false; + } + StringRef kind = llvm::cast(get("kind")).getValue(); + std::optional factor = getInt("factor"); + if (kind == "complete" && factor) { + S.warning(locOf("factor"), + "'factor' is ignored for complete partitioning in '%0'") + << display; + erase("factor"); + factor.reset(); + } + if (kind != "complete" && !factor) { + S.error(P.loc, "'%0' with type=%1 requires option 'factor'") + << display << kind; + return false; + } + int64_t dim = *getInt("dim"); + if (dim > static_cast(shape.size())) { + // Vitis 2025.1 ignores an array_partition whose dim is deeper than the + // array, with a warning ([HLS 214-253], kernel w8b_pragma_k_dim_range: + // `dim=3` on `int A_local[8][8]` keeps one bank); the pragma is + // dropped here too. Unconfirmed for array_reshape, which stays an + // error. + if (name == "array_partition") { + S.warning(locOf("dim"), + "dim=%0 is out of range in '%1': '%2' has %3 dimension(s); " + "the pragma is ignored, as Vitis ignores it") + << dim << display << var.path + << static_cast(shape.size()); + return false; + } + S.error(locOf("dim"), + "dim=%0 is out of range in '%1': '%2' has %3 dimension(s)") + << dim << display << var.path << static_cast(shape.size()); + return false; + } + if (factor && dim > 0 && shape[dim - 1] > 0 && *factor > shape[dim - 1]) + S.warning(locOf("factor"), + "factor=%0 exceeds the size %1 of dimension %2 of '%3'") + << *factor << shape[dim - 1] << dim << var.path; + return true; + } + if (name == "loop_tripcount") { + // Without `max` Vitis 2025.1 accepts the pragma and ignores it (kernel + // w9r22i_c5_tripcount_nomax: no message, trip count '?' in the loop + // table; Vitis_Libraries data_compression huffman_treegen.hpp): it is + // dropped with a warning. + if (!getInt("max")) { + S.warning(P.loc, "'%0' without 'max' is ignored, as Vitis ignores it") + << display; + return false; + } + int64_t mn = *getInt("min"), mx = *getInt("max"); + if (mn > mx) { + S.error(locOf("min"), "min=%0 exceeds max=%1 in '%2'") + << mn << mx << display; + return false; + } + if (auto avg = getInt("avg")) { + if (*avg < mn || *avg > mx) { + S.error(locOf("avg"), "avg=%0 is not within [min, max] = [%1, %2] " + "in '%3'") + << *avg << mn << mx << display; + return false; + } + } else { + fields.push_back(named("avg", b.getI32IntegerAttr((mn + mx) / 2))); + } + return true; + } + if (name == "latency") { + auto mn = getInt("min"), mx = getInt("max"); + if (mn && mx && *mn > *mx) { + S.error(locOf("min"), "min=%0 exceeds max=%1 in '%2'") + << *mn << *mx << display; + return false; + } + return true; + } + if (name == "performance") { + if (!get("target_ti") && !get("target_tl")) { + S.error(P.loc, "'%0' requires 'target_ti' or 'target_tl'") << display; + return false; + } + return true; + } + if (name == "dependence") { + auto dep = llvm::cast(get("dependent")); + if (get("distance") && !dep.getValue()) + S.warning(locOf("distance"), + "'distance' has no effect with dependent=false in '%0'") + << display; + return true; + } + if (name == "alias") { + auto ports = llvm::cast(get("ports")); + if (ports.size() < 2) { + S.error(locOf("ports"), "'%0' requires at least two ports") << display; + return false; + } + for (mlir::Attribute a : ports) { + StringRef port = llvm::cast(a).getValue(); + if (llvm::none_of(FD->parameters(), [&](const ParmVarDecl *PV) { + return identName(PV) == port; + })) { + S.error(locOf("ports"), "'%0' in '%1' is not a function parameter") + << port << display; + return false; + } + } + bool hasDist = get("distance") != nullptr, hasOff = get("offset") != nullptr; + if (hasDist == hasOff) { + S.error(P.loc, "'%0' requires exactly one of 'distance' or 'offset'") + << display; + return false; + } + if (hasOff && + llvm::cast(get("offset")).size() != ports.size()) { + S.error(locOf("offset"), + "'%0' needs one offset per port (%1 ports, %2 offsets)") + << display << static_cast(ports.size()) + << static_cast( + llvm::cast(get("offset")).size()); + return false; + } + return true; + } + if (name == "interface") { + StringRef mode = llvm::cast(get("mode")).getValue(); + bool isCtrl = mode.starts_with("ap_ctrl_"); + if (isCtrl && var.kind != Resolved::Return) { + S.error(locOf("port"), "mode=%0 in '%1' requires port=return") + << mode << display; + return false; + } + if (var.kind == Resolved::Return && !isCtrl && mode != "s_axilite") { + S.error(locOf("port"), + "port=return in '%0' requires an ap_ctrl_* or s_axilite mode") + << display; + return false; + } + return true; + } + return true; +} + +TargetBucket &FunctionSema::bucket(TargetKey key, std::string what) { + auto [it, inserted] = buckets.try_emplace(key); + if (inserted) { + it->second.key = key; + it->second.what = std::move(what); + bucketOrder.push_back(key); + } + return it->second; +} + +void FunctionSema::place(const PragmaRecord &P, TargetKey key, + std::string what, std::string attrName, + mlir::Attribute value, std::string conflict, + std::string variable, int64_t dim) { + TargetBucket &B = bucket(key, what); + for (const Placed &prev : B.placed) { + bool overlaps = prev.key == conflict; + // Partitioning the same array: dim=0 (all) overlaps every dimension. + if (!overlaps && dim >= 0 && prev.dim >= 0 && prev.variable == variable && + prev.key.substr(0, prev.key.find('|')) == + conflict.substr(0, conflict.find('|'))) + overlaps = dim == 0 || prev.dim == 0 || dim == prev.dim; + if (!overlaps) + continue; + if (prev.attrName == attrName && prev.value == value) { + S.warning(P.loc, "duplicate '%0' on the same %1 is ignored") + << pragmaDisplayName(P) << B.what; + S.note(prev.pragma->loc, "previous pragma is here"); + S.addOutcome(P.report, "ignored: duplicate of the pragma at " + + prev.pragma->locString); + } else { + S.error(P.loc, "'%0' conflicts with an earlier pragma on the same %1") + << pragmaDisplayName(P) << B.what; + S.note(prev.pragma->loc, "previous pragma is here"); + S.addOutcome(P.report, "rejected: conflicts with the pragma at " + + prev.pragma->locString); + } + return; + } + B.placed.push_back({&P, conflict, attrName, value, variable, dim}); + if (!llvm::is_contained(B.reports, P.report)) // dim=0 split per dimension + B.reports.push_back(P.report); + placedReports.insert(P.report); + if (!B.firstPragma) + B.firstPragma = &P; + if (llvm::isa(value)) { + if (!llvm::is_contained(B.units, attrName)) + B.units.push_back(attrName); + } else { + B.arrays[attrName].push_back(value); + } +} + +mlir::DictionaryAttr FunctionSema::withDim(mlir::DictionaryAttr entry, + int64_t dim) { + llvm::SmallVector fields(entry.begin(), entry.end()); + for (mlir::NamedAttribute &f : fields) + if (f.getName() == "dim") + f = named("dim", b.getI32IntegerAttr(dim)); + return b.getDictionaryAttr(fields); +} + +namespace { +/// How Vitis combines two array_partition pragmas on the same array and +/// dimension (VITIS_NOTES N17 (c) and the W10 kernels +/// ~/hls-est-work/exp-src/w10conf/w10k_*.cpp, td=off, Vitis 2025.1): the same +/// type keeps the larger factor whatever the order (cyclic 2 / 4 and 4 / 2, +/// block 2 / 4: factor 4); `complete` wins over cyclic or block in either +/// order; cyclic against block is an error ([HLS 214-290] "Multiple +/// conflicting array_partition on dimension N"), even with equal factors. +enum class PartitionMerge { KeepEarlier, TakeLater, Conflict }; + +PartitionMerge mergePartition(mlir::DictionaryAttr earlier, + mlir::DictionaryAttr later) { + auto kindOf = [](mlir::DictionaryAttr e) { + auto k = e.getAs("kind"); + return k ? k.getValue() : StringRef(); + }; + auto factorOf = [](mlir::DictionaryAttr e) -> int64_t { + auto f = e.getAs("factor"); + return f ? f.getInt() : 0; + }; + StringRef k0 = kindOf(earlier), k1 = kindOf(later); + if (k0 == k1) { + if (k0 == "complete") + return PartitionMerge::KeepEarlier; + return factorOf(later) > factorOf(earlier) ? PartitionMerge::TakeLater + : PartitionMerge::KeepEarlier; + } + if (k0 == "complete") + return PartitionMerge::KeepEarlier; + if (k1 == "complete") + return PartitionMerge::TakeLater; + return PartitionMerge::Conflict; +} + +/// "cyclic factor=4" / "complete", for diagnostics. +std::string describePartition(mlir::DictionaryAttr e) { + std::string s; + if (auto k = e.getAs("kind")) + s = k.getValue().str(); + if (auto f = e.getAs("factor")) + s += " factor=" + std::to_string(f.getInt()); + return s; +} +} // namespace + +/// array_partition (not `off`): a pragma on a dimension that an earlier +/// pragma on the same array already partitions is merged the Vitis way +/// (mergePartition) instead of being rejected; the pragma that loses gets a +/// remark. `dim=0` stands for every dimension: when it meets a pragma on one +/// dimension it is split into one entry per dimension first (Vitis kernel +/// w10k_d0c2_d1c4: `cyclic factor=2 dim=0` then `cyclic factor=4 dim=1` on +/// int[64][32] gives factor 4 on dimension 1 and factor 2 on dimension 2). +/// Everything else (a duplicate, cyclic against block, `off`) goes through +/// place() as before. +void FunctionSema::placePartition(const PragmaRecord &P, TargetKey key, + std::string what, std::string attrName, + mlir::DictionaryAttr value, + std::string conflict, std::string variable, + int64_t dim, int64_t rank) { + TargetBucket &B = bucket(key, what); + std::string keyBase = conflict.substr(0, conflict.rfind("|dim=")); + auto keyFor = [&](int64_t d) { return keyBase + "|dim=" + std::to_string(d); }; + auto sameArray = [&](const Placed &p) { + return p.attrName == attrName && p.variable == variable && p.dim >= 0 && + p.key.substr(0, p.key.rfind("|dim=")) == keyBase; + }; + auto attrsOf = [&]() -> llvm::SmallVector & { + return B.arrays[attrName]; + }; + + if (rank > 1) { + // A dim=0 pragma against per-dimension entries: one entry per dimension. + if (dim == 0 && llvm::any_of(B.placed, [&](const Placed &p) { + return sameArray(p) && p.dim > 0; + })) { + for (int64_t d = 1; d <= rank; ++d) + placePartition(P, key, what, attrName, withDim(value, d), keyFor(d), + variable, d, rank); + return; + } + // A per-dimension pragma against an earlier dim=0 entry: split that one. + if (dim > 0) { + for (size_t i = 0; i < B.placed.size(); ++i) { + Placed prev = B.placed[i]; + if (!sameArray(prev) || prev.dim != 0) + continue; + auto prevValue = llvm::cast(prev.value); + llvm::SmallVector split; + llvm::SmallVector splitValues; + for (int64_t d = 1; d <= rank; ++d) { + Placed p = prev; + p.value = withDim(prevValue, d); + p.key = keyFor(d); + p.dim = d; + split.push_back(p); + splitValues.push_back(p.value); + } + B.placed.erase(B.placed.begin() + i); + B.placed.insert(B.placed.begin() + i, split.begin(), split.end()); + auto &vals = attrsOf(); + auto it = llvm::find(vals, prev.value); + if (it != vals.end()) { + size_t at = it - vals.begin(); + vals.erase(it); + vals.insert(vals.begin() + at, splitValues.begin(), + splitValues.end()); + } + break; + } + } + } + + // A one-dimensional array: dim=0 and dim=1 name the same dimension. + auto sameDim = [&](int64_t a, int64_t c) { + return a == c || (rank == 1 && (a == 0 || a == 1) && (c == 0 || c == 1)); + }; + for (Placed &prev : B.placed) { + if (!sameArray(prev) || !sameDim(prev.dim, dim) || prev.value == value) + continue; + auto prevValue = llvm::cast(prev.value); + PartitionMerge m = mergePartition(prevValue, value); + if (m == PartitionMerge::Conflict) + break; // place() reports it + std::string dimText = + dim == 0 ? "every dimension" : "dimension " + std::to_string(dim); + if (m == PartitionMerge::KeepEarlier) { + S.remark(P.loc, "'%0' (%1) on %2 of %3 is dropped: the earlier pragma " + "(%4) partitions it at least as finely, which Vitis " + "keeps") + << pragmaDisplayName(P) << describePartition(value) << dimText + << B.what << describePartition(prevValue); + S.note(prev.pragma->loc, "earlier pragma is here"); + S.addOutcome(P.report, "merged: dropped in favour of the pragma at " + + prev.pragma->locString + " (" + dimText + + ")"); + placedReports.insert(P.report); + return; + } + const PragmaRecord *dropped = prev.pragma; + S.remark(dropped->loc, "'%0' (%1) on %2 of %3 is dropped: the later pragma " + "(%4) partitions it more finely, which Vitis keeps") + << pragmaDisplayName(*dropped) << describePartition(prevValue) + << dimText << B.what << describePartition(value); + S.note(P.loc, "later pragma is here"); + S.addOutcome(dropped->report, "merged: dropped in favour of the pragma at " + + P.locString + " (" + dimText + ")"); + auto &vals = attrsOf(); + auto it = llvm::find(vals, prev.value); + if (it != vals.end()) + *it = value; + prev.pragma = &P; + prev.value = value; + if (!llvm::is_contained(B.reports, P.report)) + B.reports.push_back(P.report); + placedReports.insert(P.report); + // The dropped pragma's report keeps its "applied" outcome only if it + // still provides another dimension. + if (llvm::none_of(B.placed, + [&](const Placed &p) { return p.pragma == dropped; })) + llvm::erase_value(B.reports, dropped->report); + return; + } + place(P, key, what, attrName, value, conflict, variable, dim); +} + +void FunctionSema::process(PragmaRecord &P) { + std::string display = pragmaDisplayName(P); + const LoopInfo *loop = innermostLoop(P.loc); + TargetKey fnKey{TargetKind::Function, FD, 0}; + auto loopKey = [&] { return TargetKey{TargetKind::Loop, loop->stmt, 0}; }; + auto loopWhat = [&]() -> std::string { + auto it = loop ? loopLabels.find(loop->stmt) : loopLabels.end(); + return it == loopLabels.end() ? "loop" : "loop '" + it->second + "'"; + }; + + if (P.isUnknown()) { + mlir::Attribute text = b.getStringAttr(P.text); + std::string key = "unknown|" + P.text; // only exact repeats collide + if (loop) + place(P, loopKey(), loopWhat(), "hls.unknown_pragmas", text, key, "", + -1); + else + place(P, fnKey, "function", "hls.unknown_pragmas", text, key, "", -1); + return; + } + + const PragmaSpec &spec = *P.spec; + bool isOff = P.isOff(); + std::string baseName = "hls." + spec.name.str(); + std::string attrName = isOff ? baseName + "_off" : baseName; + + // Target. + Resolved var; + TargetKey key = fnKey; + std::string what = "function"; + switch (spec.placement) { + case Placement::Loop: + if (!loop) { + // Vitis 2025.1 ignores an `unroll` outside a loop body with a warning + // ([HLS 207-5589] "can only be applied inside loop body", kernel + // w8b_pragma_k_unroll_outside: the loop that follows is pipelined, not + // unrolled); the pragma is dropped here too. Unconfirmed for the other + // loop pragmas, which stay errors. + if (spec.name == "unroll") { + S.warning(P.loc, "'%0' can only be applied inside a loop body; it is " + "ignored, as Vitis ignores it") + << display; + return; + } + S.error(P.loc, "'%0' must be placed inside a loop body") << display; + if (loopFollows(P.loc)) + S.note(P.loc, "move it into the body of the loop that follows"); + return; + } + key = loopKey(); + what = loopWhat(); + break; + case Placement::LoopOrFunction: + // Vitis ignores a dataflow pragma anywhere else, e.g. in a nested `{ }` + // block or a `while` body ([HLS 207-5576] "Only 'for' loop or function + // body support the dataflow pragma"; w10rev rv_df_nested3, + // w10f_df_forblock, w10f_df_while), and inlines the calls by the size + // rule. + if (spec.name == "dataflow" && !inFunctionOrForBody(P.loc, loop)) { + S.warning(P.loc, "'%0' is ignored: only a 'for' loop body or a function " + "body supports the dataflow pragma (as Vitis, HLS " + "207-5576)") + << display; + S.addOutcome(P.report, "ignored: not directly in a 'for' loop body or " + "a function body"); + return; + } + if (loop) { + key = loopKey(); + what = loopWhat(); + } else if (spec.name == "pipeline" && loopFollows(P.loc)) { + // Pipelining a function fully unrolls its loops: when the pragma sits + // right before a loop that is rarely what was meant. + S.warning(P.loc, + "'%0' is outside the loop that follows it and applies to the " + "enclosing function; place it inside the loop body to apply " + "it to the loop") + << display; + } + break; + case Placement::Function: + break; + case Placement::Variable: + case Placement::Port: { + const ParsedOption *O = + P.get(spec.placement == Placement::Port ? "port" : "variable"); + var = resolveVariable(P, *O, spec.placement == Placement::Port); + if (var.kind == Resolved::None) + return; + what = var.kind == Resolved::Return ? "function" + : "variable '" + var.path + "'"; + if (spec.name == "bind_op") { + if (var.kind == Resolved::Global) { + S.error(O->loc, "'%0' requires a local variable or parameter") + << display; + return; + } + key = {TargetKind::Operation, var.vd, + static_cast(std::hash()( + P.get("op")->valueText()))}; + break; + } + if (spec.placement == Placement::Port && var.kind != Resolved::Return && + var.kind != Resolved::Param) { + // An interface on a local variable: Vitis 2025.1 reports [HLS 214-238] + // ("Unable to apply INTERFACE pragma options ...") and ignores it, the + // array stays a local memory (kernel w9r22i_c8_iface_nonparam; + // Vitis_Libraries vision xf_otsuthreshold.hpp `hist`). A global stays + // an error. + if (spec.name == "interface" && var.kind == Resolved::Local) { + S.warning(O->value.front().loc, + "'%0' in '%1' is not a function parameter; the pragma is " + "ignored, as Vitis ignores it") + << var.path << display; + return; + } + S.error(O->value.front().loc, "'%0' in '%1' is not a function parameter") + << var.path << display; + return; + } + if ((spec.name == "function_instantiate") && var.kind != Resolved::Param) { + S.error(O->value.front().loc, "'%0' in '%1' is not a function parameter") + << var.path << display; + return; + } + if (spec.name == "reset" && var.kind != Resolved::Global) { + S.error(O->value.front().loc, + "'%0' requires a static or global variable, but '%1' is not") + << display << var.path; + return; + } + switch (var.kind) { + case Resolved::Local: + key = {TargetKind::Local, var.vd, 0}; + break; + case Resolved::Param: + key = {TargetKind::Param, FD, var.paramIndex}; + break; + case Resolved::Global: + key = {TargetKind::Global, var.vd->getCanonicalDecl(), 0}; + break; + case Resolved::Return: + key = fnKey; + break; + case Resolved::None: + return; + } + break; + } + } + + // Loop pragmas may name a variable (dependence): it must resolve. + if (spec.placement != Placement::Variable && + spec.placement != Placement::Port) { + if (const ParsedOption *O = P.get("variable")) + if (resolveVariable(P, *O, false).kind == Resolved::None) + return; + } + + // `off` pragmas skip validate(); options that contradict `off` outright + // are errors rather than "ignored" warnings. + if (isOff && spec.name == "inline" && P.get("recursive")) { + S.error(P.loc, "'recursive' conflicts with 'off' in '%0'") << display; + return; + } + + int64_t dim = -1; + std::optional entry = buildEntry(P, var, isOff, dim); + if (!entry) + return; + + mlir::Attribute value = *entry; + // The legacy RESOURCE pragma on an array: its memory core is the + // bind_storage it names (Vitis 2025.1: `RESOURCE core=RAM_2P_BRAM` and + // `bind_storage type=ram_2p impl=bram` both give RAM_2P_BRAM_1R1W, kernels + // w9r13p_rs_res / rs_bind, CIRCT VITIS_NOTES N98). + std::string specName = spec.name.str(); + if (spec.name == "resource") + if (std::optional bind = + lowerResourceCore(*entry, b)) { + value = *bind; + attrName = "hls.bind_storage"; + specName = "bind_storage"; + } + bool variableLevel = spec.placement == Placement::Variable || + spec.placement == Placement::Port; + if (isOff && !variableLevel) + value = b.getUnitAttr(); + if (!(spec.name == "array_partition" || spec.name == "array_reshape")) + dim = -1; + + // Conflict key. + std::string conflict = specName; + std::string variable = var.path; + switch (spec.multiplicity) { + case Multiplicity::Single: + break; + case Multiplicity::PerVariable: + if (spec.name == "aggregate" || spec.name == "disaggregate") + conflict = "aggregate"; + conflict += "|" + variable; + if (spec.name == "bind_op") + conflict += "|" + P.get("op")->valueText(); + // A port may carry several interfaces of different modes (m_axi data + // plus an s_axilite offset register); only the same mode twice clashes. + if (spec.name == "interface") + conflict += "|" + StringRef(P.get("mode")->valueText()).lower(); + if (dim >= 0) + conflict += "|dim=" + std::to_string(dim); + break; + case Multiplicity::Many: { + std::string s; + llvm::raw_string_ostream os(s); + value.print(os); + conflict += "|" + os.str(); + break; + } + } + + // Two interface pragmas of one mode on one port: the later one decides, + // as in Vitis 2025.1 (kernels w8b_iface_k_two_maxi / k_two_maxi_bundle: + // both synthesize without a message, and the port uses the later + // pragma's bundle). The earlier entry is withdrawn before the later one + // is placed. + if (spec.name == "interface" && !isOff) { + TargetBucket &B = bucket(key, what); + for (auto it = B.placed.begin(); it != B.placed.end(); ++it) { + if (it->key != conflict || it->value == value) + continue; + S.warning(P.loc, "'%0' replaces the earlier pragma on the same %1; the " + "later one decides, as in Vitis") + << pragmaDisplayName(P) << B.what; + S.note(it->pragma->loc, "earlier pragma is here"); + S.addOutcome(it->pragma->report, + "replaced by the pragma at " + P.locString); + auto &vals = B.arrays[it->attrName]; + if (auto v = llvm::find(vals, it->value); v != vals.end()) + vals.erase(v); + B.placed.erase(it); + break; + } + } + if (spec.name == "array_partition" && !isOff && dim >= 0 && + !HLSRejectPartitionConflicts) + placePartition(P, key, what, attrName, + llvm::cast(value), conflict, variable, + dim, static_cast(partitionShape(var.type).size())); + else + place(P, key, what, attrName, value, conflict, variable, dim); + // Vitis sizes functions for automatic inlining after the user's unroll + // pragmas and the complete unroll a pipeline pragma implies (VITIS_NOTES + // N18); HLSAutoInline.cc unrolls these loops first. + if (placedReports.count(P.report)) { + if (spec.name == "unroll" && key.kind == TargetKind::Loop) { + int64_t factor = isOff ? -1 : 0; + if (auto d = llvm::dyn_cast(value)) + if (auto f = d.getAs("factor")) + factor = f.getInt(); + recordUnrollLoop(SM, static_cast(key.ptr)->getBeginLoc(), + factor); + } + if (spec.name == "pipeline" && !isOff) { + if (key.kind == TargetKind::Loop) + recordPipelineLoop(SM, + static_cast(key.ptr)->getBeginLoc()); + else if (key.kind == TargetKind::Function) + recordPipelineFunction(func.getName()); + } + } + if (key.kind == TargetKind::Operation) { + TargetBucket &B = buckets[key]; + B.var = var.vd; + B.opNames.clear(); + bindOpTarget(StringRef(P.get("op")->valueText()).lower(), B.opNames, + B.floatWidth); + } +} + +/// The trip count of `for (i = a; i < b; i++)`-shaped loops with constant +/// bounds (`<`, `<=`, `!=` with `++` / `+= 1`; `>`, `>=`, `!=` with `--` / +/// `-= 1`); nullopt for any other loop. +static std::optional constantTripCount(const Stmt *s, + ASTContext &AC) { + const auto *F = dyn_cast_or_null(s); + if (!F || !F->getInit() || !F->getCond() || !F->getInc()) + return std::nullopt; + auto constant = [&](const Expr *e) -> std::optional { + Expr::EvalResult r; + if (!e || e->isValueDependent() || !e->EvaluateAsInt(r, AC)) + return std::nullopt; + return r.Val.getInt().getSExtValue(); + }; + auto varOf = [](const Expr *e) -> const VarDecl * { + if (const auto *d = dyn_cast_or_null(e ? e->IgnoreParenImpCasts() + : nullptr)) + return dyn_cast(d->getDecl()); + return nullptr; + }; + // Init: `int i = a` or `i = a`. + const VarDecl *iv = nullptr; + std::optional start; + if (const auto *DS = dyn_cast(F->getInit())) { + if (!DS->isSingleDecl()) + return std::nullopt; + iv = dyn_cast(DS->getSingleDecl()); + start = iv ? constant(iv->getInit()) : std::nullopt; + } else if (const auto *BO = dyn_cast(F->getInit())) { + if (BO->getOpcode() != BO_Assign) + return std::nullopt; + iv = varOf(BO->getLHS()); + start = constant(BO->getRHS()); + } + if (!iv || !start || !iv->getType()->isIntegerType()) + return std::nullopt; + // Step: +1 or -1. + int step = 0; + const Expr *inc = F->getInc()->IgnoreParenImpCasts(); + if (const auto *U = dyn_cast(inc)) { + if (varOf(U->getSubExpr()) != iv) + return std::nullopt; + step = U->isIncrementOp() ? 1 : U->isDecrementOp() ? -1 : 0; + } else if (const auto *C = dyn_cast(inc)) { + std::optional by = constant(C->getRHS()); + if (varOf(C->getLHS()) != iv || !by || *by != 1) + return std::nullopt; + step = C->getOpcode() == BO_AddAssign ? 1 + : C->getOpcode() == BO_SubAssign ? -1 + : 0; + } + if (step == 0) + return std::nullopt; + // Condition: `i op b`. + const auto *cmp = dyn_cast(F->getCond()->IgnoreParenImpCasts()); + if (!cmp || varOf(cmp->getLHS()) != iv) + return std::nullopt; + std::optional end = constant(cmp->getRHS()); + if (!end) + return std::nullopt; + int64_t a = *start, b = *end; + switch (cmp->getOpcode()) { + case BO_LT: + return step > 0 ? std::max(0, b - a) : std::optional(); + case BO_LE: + return step > 0 ? std::max(0, b - a + 1) + : std::optional(); + case BO_GT: + return step < 0 ? std::max(0, a - b) : std::optional(); + case BO_GE: + return step < 0 ? std::max(0, a - b + 1) + : std::optional(); + case BO_NE: + if ((step > 0 && b >= a) || (step < 0 && a >= b)) + return step > 0 ? b - a : a - b; + return std::nullopt; + default: + return std::nullopt; + } +} + +/// A `pipeline` pragma on a loop whose trip count is 1 (VITIS_NOTES N40, +/// Vitis 2025.1 kernels w9p5_t1_flat / w9p5_t1_noflat, corpus stream_hls +/// MultiHeadSelfAttention1 opt5 node13): Vitis completely unrolls the loops +/// inside it, as any pipeline pragma does (`[HLS 214-291]`), then removes +/// the one-iteration loop together with its pipeline (and loop_flatten) +/// pragma, and its automatic pipelining decides on the enclosing nest +/// (`[HLS 214-376]`). The MLIR canonicalizer folds the one-iteration loop +/// before the pragma could be materialized, so the pragma's effect is moved +/// here: every loop nested in it gets a complete `unroll` (a partial unroll +/// pragma of its own is overridden to complete, `[HLS 214-291]`; an `unroll +/// off` is left alone), and the pipeline pragma is withdrawn. +void FunctionSema::applyTripOnePipelines() { + if (!HLSTripOnePipelineUnroll) + return; + static constexpr llvm::StringLiteral kPipeline = "hls.pipeline"; + static constexpr llvm::StringLiteral kUnroll = "hls.unroll"; + for (const LoopInfo &L : loops) { + auto it = buckets.find(TargetKey{TargetKind::Loop, L.stmt, 0}); + if (it == buckets.end() || !it->second.arrays.count(kPipeline.str())) + continue; + std::optional trips = constantTripCount(L.stmt, AC); + if (!trips || *trips != 1) + continue; + TargetBucket &B = it->second; + const PragmaRecord *P = nullptr; + for (const Placed &p : B.placed) + if (p.attrName == kPipeline) + P = p.pragma; + if (!P) + continue; + B.arrays.erase(kPipeline.str()); + llvm::erase_if(B.placed, + [&](const Placed &p) { return p.attrName == kPipeline; }); + if (llvm::none_of(B.placed, + [&](const Placed &p) { return p.pragma == P; })) + llvm::erase_value(B.reports, P->report); + if (B.firstPragma == P) // the loop's other pragmas (loop_flatten) remain + B.firstPragma = B.placed.empty() ? nullptr : B.placed.front().pragma; + S.warning(P->loc, "'%0' is on a loop with a trip count of 1: the loops " + "inside it are completely unrolled and the loop is " + "removed with its pragmas, as Vitis does") + << pragmaDisplayName(*P); + S.addOutcome(P->report, "applied as a complete unroll of the loops " + "inside the trip-count-1 loop, which is removed " + "(as Vitis)"); + mlir::Attribute complete = b.getDictionaryAttr( + {named("factor", b.getI32IntegerAttr(0)), + named("skip_exit_check", b.getBoolAttr(false))}); + for (const LoopInfo &I : loops) { + if (I.stmt == L.stmt || !inRegion(L.region, I.stmt->getBeginLoc())) + continue; + auto label = loopLabels.find(I.stmt); + TargetBucket &IB = + bucket(TargetKey{TargetKind::Loop, I.stmt, 0}, + label == loopLabels.end() ? "loop" + : "loop '" + label->second + "'"); + if (llvm::is_contained(IB.units, kUnroll.str() + "_off")) + continue; + // A partial `unroll factor=N` of its own is overridden: Vitis logs + // `[HLS 214-291] ... marked as complete unroll implied by the pipeline + // pragma` and unrolls it completely (kernel w9rv_t1_part, as for any + // pipeline pragma, VITIS_NOTES N43). + auto own = IB.arrays.find(kUnroll.str()); + if (own != IB.arrays.end()) { + own->second.clear(); + own->second.push_back(complete); + continue; + } + IB.arrays[kUnroll.str()].push_back(complete); + if (!IB.firstPragma) + IB.firstPragma = P; + } + } +} + +void FunctionSema::flush() { + std::string funcName = func.getName().str(); + for (const TargetKey &key : bucketOrder) { + TargetBucket &B = buckets[key]; + llvm::SmallVector, 2> attrs; + for (auto &[name, entries] : B.arrays) + attrs.push_back({name, b.getArrayAttr(entries)}); + for (const std::string &u : B.units) + attrs.push_back({u, b.getUnitAttr()}); + if (attrs.empty()) + continue; + + auto merge = [&](mlir::Attribute existing, mlir::Attribute add) { + auto oldArr = llvm::dyn_cast_or_null(existing); + auto newArr = llvm::dyn_cast(add); + if (!oldArr || !newArr) + return add; + llvm::SmallVector all(oldArr.begin(), oldArr.end()); + all.append(newArr.begin(), newArr.end()); + return static_cast(b.getArrayAttr(all)); + }; + + const PragmaRecord &first = *B.firstPragma; + switch (key.kind) { + case TargetKind::Function: + for (auto &[name, value] : attrs) + func->setAttr(name, merge(func->getAttr(name), value)); + for (int r : B.reports) + S.addOutcome(r, "func.func @" + funcName); + break; + case TargetKind::Param: + for (auto &[name, value] : attrs) + func.setArgAttr(key.index, name, + merge(func.getArgAttr(key.index, name), value)); + for (int r : B.reports) + S.addOutcome(r, "argument #" + std::to_string(key.index) + " (" + + B.what + ") of @" + funcName); + break; + case TargetKind::Global: { + GlobalTarget &G = + S.globals[static_cast(key.ptr)]; + G.name = identName(static_cast(key.ptr)).str(); + G.pragmaName = pragmaDisplayName(first); + G.loc = first.loc; + G.reports.append(B.reports.begin(), B.reports.end()); + for (auto &attr : attrs) { + bool found = false; + for (auto &existing : G.attrs) { + if (existing.first == attr.first) { + existing.second = merge(existing.second, attr.second); + found = true; + } + } + if (!found) + G.attrs.push_back(attr); + } + break; + } + case TargetKind::Loop: + case TargetKind::Local: + case TargetKind::Operation: { + TagClass cls = key.kind == TargetKind::Loop ? TagClass::Loop + : key.kind == TargetKind::Local ? TagClass::Storage + : TagClass::Operation; + TagRecord &T = S.newTag(cls); + T.attrs = attrs; + if (S.checkOnlyMode) { + // No code: report the AST-level target now. + std::string what = + key.kind == TargetKind::Operation + ? "operation assigned to variable '" + + identName(B.var).str() + "'" + : B.what; + for (int r : B.reports) + S.addOutcome(r, what + " in " + funcName + " (check-only)"); + T.tagged = T.materialized = true; + continue; + } + T.pragmaName = pragmaDisplayName(first); + T.what = B.what; + T.locString = first.locString; + T.funcName = funcName; + T.reports = B.reports; + if (key.kind == TargetKind::Loop) { + S.loopTags[static_cast(key.ptr)] = T.id; + } else if (key.kind == TargetKind::Local) { + S.storageTags[static_cast(key.ptr)] = T.id; + } else { + T.opNames.assign(B.opNames.begin(), B.opNames.end()); + T.floatWidth = B.floatWidth; + T.what = "variable '" + identName(B.var).str() + "'"; + S.assignTags[B.var].push_back(T.id); + } + break; + } + } + } +} + +void FunctionSema::run() { + const Stmt *body = FD->getBody(); + if (!body) + return; + index(body, body->getSourceRange(), 0); + for (PragmaRecord &P : S.pragmas) { + if (!P.valid || !belongsHere(P.loc)) + continue; + P.associated = true; + process(P); + if (!placedReports.count(P.report) && !S.hasOutcome(P.report)) + S.addOutcome(P.report, "rejected: see the diagnostic above"); + } + applyTripOnePipelines(); + flush(); +} + +//===----------------------------------------------------------------------===// +// Translation-unit checks +//===----------------------------------------------------------------------===// + +class BodyCollector : public RecursiveASTVisitor { +public: + std::vector bodies; + bool shouldVisitTemplateInstantiations() const { return true; } + bool VisitFunctionDecl(FunctionDecl *FD) { + if (FD->doesThisDeclarationHaveABody() && FD->getBody()) + bodies.push_back(FD->getBody()->getSourceRange()); + return true; + } +}; + +} // namespace + +void cgeist::hls::enterFunction(const FunctionDecl *FD, + mlir::func::FuncOp func, unsigned argOffset) { + State &S = State::get(); + if (!isEnabled() || !S.PP || S.analyzedFunctions.count(FD)) + return; + S.analyzedFunctions[FD] = true; + FunctionSema(FD, func, argOffset).run(); +} + +namespace { +class FunctionCollector : public RecursiveASTVisitor { +public: + std::vector functions; + bool shouldVisitTemplateInstantiations() const { return true; } + bool shouldVisitImplicitCode() const { return true; } + bool VisitFunctionDecl(FunctionDecl *FD) { + if (FD->doesThisDeclarationHaveABody() && FD->getBody() && + !FD->isDependentContext()) + functions.push_back(FD); + return true; + } +}; +} // namespace + +void cgeist::hls::checkAllFunctions(ASTContext &astCtx) { + State &S = State::get(); + if (!isEnabled() || !S.PP || !S.mlirCtx) + return; + S.checkOnlyMode = true; + FunctionCollector C; + C.TraverseDecl(astCtx.getTranslationUnitDecl()); + mlir::OpBuilder b(S.mlirCtx); + for (const FunctionDecl *FD : C.functions) { + const auto *MD = dyn_cast(FD); + unsigned offset = MD && MD->isInstance() ? 1 : 0; + llvm::SmallVector args(FD->getNumParams() + offset, + b.getI32Type()); + // A detached stand-in: it only receives the function-level attributes. + // Named as in diagnostics (qualified, with template arguments). + std::string name; + llvm::raw_string_ostream os(name); + FD->getNameForDiagnostic(os, astCtx.getPrintingPolicy(), + /*Qualified=*/true); + auto func = mlir::func::FuncOp::create(b.getUnknownLoc(), os.str(), + b.getFunctionType(args, {})); + enterFunction(FD, func, offset); + func->destroy(); + } +} + +void cgeist::hls::checkTranslationUnit(ASTContext &astCtx) { + State &S = State::get(); + if (!isEnabled() || S.checkedTU) + return; + S.checkedTU = true; + BodyCollector C; + C.TraverseDecl(astCtx.getTranslationUnitDecl()); + SourceManager &SM = astCtx.getSourceManager(); + for (PragmaRecord &P : S.pragmas) { + if (!P.valid) + continue; + bool inside = llvm::any_of(C.bodies, [&](SourceRange r) { + return SM.isBeforeInTranslationUnit(r.getBegin(), P.loc) && + SM.isBeforeInTranslationUnit(P.loc, r.getEnd()); + }); + if (!inside) { + S.error(P.loc, "'%0' must be placed inside a function body") + << pragmaDisplayName(P); + S.addOutcome(P.report, "rejected: outside a function body"); + } + } +} diff --git a/tools/cgeist/Lib/HLSPragmaSpec.cc b/tools/cgeist/Lib/HLSPragmaSpec.cc new file mode 100644 index 000000000000..b2d1fab8041a --- /dev/null +++ b/tools/cgeist/Lib/HLSPragmaSpec.cc @@ -0,0 +1,285 @@ +//===- HLSPragmaSpec.cc - Specifications of Vitis HLS pragmas -------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// The table of supported pragmas, their options, value types, defaults and +// placement. docs/hls-pragmas.md documents the same table; keep them in sync. +// +//===----------------------------------------------------------------------===// + +#include "HLSPragmaInternal.h" + +#include "llvm/ADT/STLExtras.h" + +using namespace cgeist::hls; +using llvm::StringLiteral; +using llvm::StringRef; + +namespace { + +/// Small builder so the table below stays readable. +struct Opt { + OptionSpec s; + Opt(StringLiteral name, OptType type) { s.name = name, s.type = type; } + Opt &values(std::initializer_list v) { + s.values.assign(v.begin(), v.end()); + return *this; + } + Opt &required() { return s.required = true, *this; } + Opt &positional() { return s.positional = true, *this; } + Opt &min(int64_t m) { return s.min = m, *this; } + Opt &key(StringLiteral k) { return s.attrKey = k, *this; } + Opt &upper() { return s.upperCase = true, *this; } + Opt &def(bool b) { + s.defaultKind = OptionSpec::DefaultKind::Bool; + s.defaultBool = b; + return *this; + } + Opt &def(int64_t i) { + s.defaultKind = OptionSpec::DefaultKind::Int; + s.defaultInt = i; + return *this; + } + Opt &def(StringLiteral str) { + s.defaultKind = OptionSpec::DefaultKind::String; + s.defaultString = str; + return *this; + } + operator OptionSpec() const { return s; } +}; + +Opt flag(StringLiteral n) { return Opt(n, OptType::Flag); } +Opt integer(StringLiteral n) { return Opt(n, OptType::Int); } +Opt number(StringLiteral n) { return Opt(n, OptType::Number); } +Opt enumOpt(StringLiteral n, std::initializer_list v) { + return Opt(n, OptType::Enum).values(v); +} +Opt variable() { return Opt("variable", OptType::Variable).required(); } +Opt name(StringLiteral n) { return Opt(n, OptType::Name); } + +PragmaSpec pragma(StringLiteral name, Placement placement, + std::vector options, bool hasOff = false, + Multiplicity m = Multiplicity::Single) { + PragmaSpec p; + p.name = name; + p.placement = placement; + p.options = std::move(options); + p.hasOff = hasOff; + p.multiplicity = m; + if (hasOff) + p.options.push_back(flag("off")); + return p; +} + +std::vector buildSpecs() { + using P = Placement; + using M = Multiplicity; + std::vector specs; + + // Partitioning options shared by array_partition and array_reshape. + auto partitionOptions = [](bool reshape) { + std::vector opts = { + variable(), + enumOpt("type", {"cyclic", "block", "complete"}) + .positional() + .def(StringLiteral("complete")) + .key("kind"), + integer("factor").min(1), + integer("dim").min(0).def(int64_t(1)), + }; + if (reshape) + opts.push_back(flag("object")); + return opts; + }; + + //===-- Loop pragmas ---------------------------------------------------===// + specs.push_back(pragma( + "pipeline", P::LoopOrFunction, + {integer("ii").min(1).key("II").def(int64_t(0)), flag("rewind").def(false), + enumOpt("style", {"stp", "flp", "frp"}).def(StringLiteral("stp")), + flag("enable_flush")}, + /*hasOff=*/true)); + specs.push_back(pragma("unroll", P::Loop, + {integer("factor").min(1).def(int64_t(0)), + flag("skip_exit_check").def(false)}, + /*hasOff=*/true)); + specs.push_back(pragma("loop_flatten", P::Loop, {}, /*hasOff=*/true)); + specs.push_back( + pragma("loop_merge", P::LoopOrFunction, {flag("force").def(false)})); + specs.push_back(pragma("loop_tripcount", P::Loop, + {integer("min").min(0).def(int64_t(0)), + integer("max").min(0), + integer("avg").min(0)})); + specs.push_back(pragma( + "dependence", P::LoopOrFunction, + {Opt("variable", OptType::Variable), + enumOpt("class", {"array", "pointer"}).positional(), + enumOpt("type", {"intra", "inter"}) + .positional() + .def(StringLiteral("inter")), + enumOpt("direction", {"raw", "war", "waw"}).positional().upper(), + integer("distance").min(1), + Opt("dependent", OptType::Flag).required()}, + false, M::Many)); + specs.push_back(pragma("dataflow", P::LoopOrFunction, + {flag("disable_start_propagation").def(false)})); + specs.push_back(pragma("latency", P::LoopOrFunction, + {integer("min").min(0), integer("max").min(0)})); + specs.push_back(pragma( + "performance", P::LoopOrFunction, + {number("target_ti"), number("target_tl"), + enumOpt("unit", {"cycle", "sec"}).def(StringLiteral("cycle"))})); + + //===-- Function pragmas -----------------------------------------------===// + specs.push_back(pragma("inline", P::Function, {flag("recursive").def(false)}, + /*hasOff=*/true)); + // `name` may be left out: the enclosing function is the top (Vitis 2025.1 + // accepts `#pragma HLS top`; dsp ssr_fft tests main.cpp:29). + specs.push_back(pragma("top", P::Function, {name("name")})); + specs.push_back(pragma("function_instantiate", P::Variable, {variable()}, + false, M::PerVariable)); + specs.push_back( + pragma("expression_balance", P::LoopOrFunction, {}, /*hasOff=*/true)); + specs.push_back(pragma( + "allocation", P::LoopOrFunction, + {Opt("instances", OptType::NameList).required(), + integer("limit").min(1).required(), + enumOpt("type", {"function", "operation"}) + .positional() + .def(StringLiteral("function"))}, + false, M::Many)); + specs.push_back(pragma("occurrence", P::LoopOrFunction, + {integer("cycle").min(1).required()})); + specs.push_back(pragma("protocol", P::LoopOrFunction, + {enumOpt("mode", {"fixed", "floating"}) + .positional() + .def(StringLiteral("floating"))})); + specs.push_back( + pragma("stable", P::Variable, {variable()}, false, M::PerVariable)); + specs.push_back(pragma("reset", P::Variable, {variable()}, /*hasOff=*/true, + M::PerVariable)); + + //===-- Variable / port pragmas ----------------------------------------===// + specs.push_back(pragma("array_partition", P::Variable, partitionOptions(false), + /*hasOff=*/true, M::PerVariable)); + specs.push_back(pragma("array_reshape", P::Variable, partitionOptions(true), + /*hasOff=*/true, M::PerVariable)); + specs.push_back(pragma( + "bind_storage", P::Variable, + {variable(), + // xpm_memory: Vitis 2025.1 accepts it (Vitis_Libraries solver + // potrf.hpp; kernel w9r22i_c3_xpm fails only on impl=uram for the + // part, [HLS 214-370]). + enumOpt("type", {"fifo", "ram_1p", "ram_1wnr", "ram_2p", "ram_s2p", + "ram_t2p", "rom_1p", "rom_2p", "rom_np", + "xpm_memory"}), + enumOpt("impl", {"auto", "bram", "bram_ecc", "lutram", "uram", + "uram_ecc", "srl", "memory"}), + integer("latency").min(-1)}, + false, M::PerVariable)); + // The legacy `RESOURCE variable=v core=C` (Vitis 2025.1 still accepts it): + // a memory core is lowered as the bind_storage it names (HLSPragmaSema.cc, + // lowerResourceCore). + specs.push_back(pragma("resource", P::Variable, + {variable(), name("core").required(), + integer("latency").min(-1), name("ports"), + name("metadata")}, + false, M::PerVariable)); + specs.push_back(pragma( + "bind_op", P::Variable, + {variable(), + enumOpt("op", {"add", "sub", "mul", "fadd", "fsub", "fmul", + "fdiv", "fexp", "flog", "fsqrt", "frsqrt", "frecip", + "dadd", "dsub", "dmul", "ddiv", "dexp", "dlog", + "dsqrt", "drsqrt", "drecip", "hadd", "hsub", "hmul", + "hdiv", "hsqrt"}) + .required(), + enumOpt("impl", {"auto", "dsp", "fabric", "meddsp", "fulldsp", "maxdsp", + "primitivedsp", "qadder", "vivado_dds"}), + integer("latency").min(-1)}, + false, M::PerVariable)); + specs.push_back(pragma( + "interface", P::Port, + {enumOpt("mode", {"ap_none", "ap_vld", "ap_ack", "ap_hs", "ap_ovld", + "ap_fifo", "ap_memory", "bram", "axis", "s_axilite", + "m_axi", "ap_ctrl_none", "ap_ctrl_hs", "ap_ctrl_chain", + "ap_stable"}) + .positional() + .required(), + Opt("port", OptType::Variable).required(), name("bundle"), + Opt("offset", OptType::IntOrEnum).values({"off", "direct", "slave"}), + integer("depth").min(1), integer("latency").min(0), + integer("max_widen_bitwidth").min(0), + integer("max_read_burst_length").min(1), + integer("max_write_burst_length").min(1), + integer("num_read_outstanding").min(1), + integer("num_write_outstanding").min(1), flag("register"), + enumOpt("register_mode", {"both", "forward", "reverse", "off"}), + enumOpt("storage_type", {"ram_1p", "ram_2p", "ram_s2p", "ram_t2p", + "ram_1wnr", "rom_1p", "rom_2p", "rom_np"}), + enumOpt("storage_impl", {"auto", "bram", "lutram", "uram"}), + name("clock"), name("name"), integer("channel").min(0), + integer("interrupt").min(0)}, + false, M::PerVariable)); + specs.push_back(pragma( + "stream", P::Variable, + {variable(), integer("depth").min(1).def(int64_t(2)), + enumOpt("type", {"fifo", "pipo", "shared", "unsync"}) + .def(StringLiteral("fifo"))}, + /*hasOff=*/true, M::PerVariable)); + // `aggregate variable=x bit` (the bare compact mode: the open front end's + // presentId("bit" | "byte" | "none" | "auto"), e.g. TAPA's vec.h). + specs.push_back(pragma("aggregate", P::Variable, + {variable(), enumOpt("compact", {"bit", "byte", "none", + "auto"}) + .def(StringLiteral("auto")) + .positional()}, + false, M::PerVariable)); + specs.push_back( + pragma("disaggregate", P::Variable, {variable()}, false, M::PerVariable)); + specs.push_back(pragma("alias", P::Function, + {Opt("ports", OptType::NameList).required(), + integer("distance"), Opt("offset", OptType::IntList)}, + false, M::Many)); + specs.push_back(pragma("cache", P::Port, + {Opt("port", OptType::Variable).required(), + integer("lines").min(1), integer("depth").min(1)}, + false, M::PerVariable)); + return specs; +} + +const std::vector &specTable() { + static const std::vector table = buildSpecs(); + return table; +} + +} // namespace + +const OptionSpec *PragmaSpec::findOption(StringRef lowerName) const { + for (const OptionSpec &o : options) + if (o.name == lowerName) + return &o; + return nullptr; +} + +const OptionSpec *PragmaSpec::findPositional(StringRef lowerValue) const { + for (const OptionSpec &o : options) + if (o.positional && llvm::is_contained(o.values, lowerValue)) + return &o; + return nullptr; +} + +const PragmaSpec *cgeist::hls::lookupPragmaSpec(StringRef lowerName) { + for (const PragmaSpec &p : specTable()) + if (p.name == lowerName) + return &p; + return nullptr; +} + +llvm::ArrayRef cgeist::hls::allPragmaSpecs() { + return specTable(); +} diff --git a/tools/cgeist/Lib/HandleHLS.cc b/tools/cgeist/Lib/HandleHLS.cc deleted file mode 100644 index a77ba7d0e1f2..000000000000 --- a/tools/cgeist/Lib/HandleHLS.cc +++ /dev/null @@ -1,541 +0,0 @@ -#include "clang/Frontend/ASTConsumers.h" -#include "clang/Frontend/MultiplexConsumer.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "mlir/IR/Builders.h" -#include "mlir/IR/BuiltinAttributes.h" -#include "mlir/IR/Location.h" -#include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/Affine/IR/AffineOps.h" -#include "mlir/Dialect/SCF/IR/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/StringExtras.h" // for SplitString -#include "pragmaHandlerHLS.h" -#include "HandleHLS.h" - -using mlir::memref::AllocaOp; -using namespace llvm; - -unsigned getSourceInfo(mlir::Location loc) { - // 1. Base Case: Standard File/Line/Column - if (auto fileLoc = llvm::dyn_cast(loc)) { - return fileLoc.getLine(); - } - if (auto fusedLoc = llvm::dyn_cast(loc)) { - auto locations = fusedLoc.getLocations(); - if(locations.size() > 0) { - return getSourceInfo(locations[0]); - } - return 0; - } - // 3. Recursive Case: CallSite Locations (If inlining has occurred) - if (auto callLoc = llvm::dyn_cast(loc)) { - return getSourceInfo(callLoc.getCaller()); - } - // 4. Case: Name Location (e.g., loc("myVar"(...) ) - if (auto nameLoc = llvm::dyn_cast(loc)) { - return getSourceInfo(nameLoc.getChildLoc()); - } - return 0; -} - -void ResolveScope(mlir::ModuleOp MlirModule, - std::vector &HLSMetadata) { - - struct ScopeInfo { - mlir::Operation *Op; - unsigned StartLine; - unsigned EndLine; - }; - - std::vector Scopes; - - // --- Phase 1: Collect all scope ops and their line ranges --- - MlirModule.walk([&](mlir::Operation *Op) { - - if (llvm::isa(Op)) { - llvm::outs() << "[scope] op=" << Op->getName().getStringRef(); - } - - if (mlir::isa(Op)) - return; - - // Only ops that define a new scope (have regions) - if (Op->getNumRegions() == 0) - return; - - - - unsigned StartLine = getSourceInfo(Op->getLoc()); - if (StartLine == 0) - return; - // End line = max line of any nested op in this scope - unsigned EndLine = StartLine; - Op->walk([&](mlir::Operation *Nested) { - if (Nested == Op) - return; - unsigned Line = getSourceInfo(Nested->getLoc()); - if (Line > EndLine) - EndLine = Line; - }); - Scopes.push_back({Op, StartLine, EndLine}); - llvm::outs() << "[scope] op=" << Op->getName().getStringRef() - << " start=" << StartLine << " end=" << EndLine << "\n"; - }); - - - // --- Phase 1.5: Widen each func.func's StartLine to cover the gap from - // the previous function's end. This lets pragmas that appear above the - // first emitted op (between '{' and the first statement) — and pragmas - // between functions — attach to the function that follows them. - // Other scope ops (loops) keep their original tight range, so the - // innermost-loop preference still works. - std::vector Funcs; - for (auto &S : Scopes) - if (llvm::isa(S.Op)) - Funcs.push_back(&S); - - llvm::sort(Funcs, [](ScopeInfo *a, ScopeInfo *b) { - return a->EndLine < b->EndLine; - }); - - unsigned PrevEnd = 0; - for (auto *F : Funcs) { - F->StartLine = PrevEnd + 1; - PrevEnd = F->EndLine; - } - - // --- Phase 2: Match each pragma to its innermost containing scope --- - for (HLSPragmaMetaData &Meta : HLSMetadata) { - mlir::Operation *InnermostOp = nullptr; - unsigned InnermostSpan = UINT_MAX; - - for (auto &Scope : Scopes) { - // Pragma must fall within the scope's line range - if (Meta.OffsetLoc < Scope.StartLine || Meta.OffsetLoc > Scope.EndLine) - continue; - - // Prefer the tightest (innermost) enclosing scope - unsigned Span = Scope.EndLine - Scope.StartLine; - // After --raise-scf-to-affine, loops are affine.for; before that, scf.for/while. - bool CurrIsLoop = llvm::isa(Scope.Op); - bool BestIsLoop = InnermostOp && - llvm::isa(InnermostOp); - - if (Span < InnermostSpan || (CurrIsLoop && !BestIsLoop && Span == InnermostSpan)) { - InnermostSpan = Span; - InnermostOp = Scope.Op; - } - } - - if (InnermostOp) { - Meta.Op = InnermostOp; - llvm::outs() << "[HLS] pragma '" << Meta.Name - << "' at line " << Meta.OffsetLoc - << " attached to '" << InnermostOp->getName().getStringRef() - << "' (scope span " << InnermostSpan << " lines)"; - - if (auto SymAttr = InnermostOp->getAttrOfType( - mlir::SymbolTable::getSymbolAttrName())) - - llvm::outs() << " ['" << SymAttr.getValue() << "']"; - llvm::outs() << "\n"; - } else { - Meta.Op = nullptr; - llvm::outs() << "[HLS] Warning: pragma '" << Meta.Name - << "' at line " << Meta.OffsetLoc - << " could not be resolved to any scope\n"; - } - } -} - -// Helper: parse a key=value arg list into a StringMap -void ParseArgs(ArrayRef Args, - llvm::StringMap &KV, - SmallVectorImpl &Flags) { - for (StringRef Arg : Args) { - if (Arg.contains('=')) { - auto [Key, Val] = Arg.split('='); - KV[Key] = Val; - } else { - Flags.push_back(Arg); // bare keywords like "complete", "rewind", "skip_exit_check" - } - } -} - -// Helper: find a memref.alloca by base variable name inside a scope op. -// memref.alloca has no name attribute; we recover the variable name from -// either (a) a NameLoc on the op's location, or (b) a "polygeist.varname" -// string attribute attached at scan time. Either source works; the second -// is the fallback if locations have been rewritten by passes. -AllocaOp FindAlloca(mlir::Operation *ScopeOp, StringRef BaseName) { - AllocaOp Found; - ScopeOp->walk([&](AllocaOp Alloca) { - // (a) try NameLoc on the alloca's location - if (auto NL = llvm::dyn_cast(Alloca.getLoc())) { - if (NL.getName().getValue() == BaseName) { - Found = Alloca; - return; - } - } - // (b) try a polygeist.varname attribute - if (auto NameAttr = - Alloca->getAttrOfType("polygeist.varname")) { - if (NameAttr.getValue() == BaseName) { - Found = Alloca; - return; - } - } - }); - return Found; -} - - -mlir::Operation *FindOpByName(mlir::Operation *ScopeOp, llvm::StringRef Name) { - mlir::Operation *Found = nullptr; - ScopeOp->walk([&](mlir::Operation *Op) { - if (auto names = Op->getAttrOfType("polygeist.ssa_names")) { - for (auto attr : names) { - if (auto sa = llvm::dyn_cast(attr)) { - if (sa.getValue() == Name) { - Found = Op; - return mlir::WalkResult::interrupt(); - } - } - } - } - return mlir::WalkResult::advance(); - }); - return Found; -} - -// Helper: append a DictionaryAttr entry to an ArrayAttr on an op -void AppendAttrEntry(mlir::Operation *Op, StringRef AttrName, - mlir::DictionaryAttr Entry) { - mlir::Builder B(Op->getContext()); - SmallVector Entries; - if (auto Existing = Op->getAttrOfType(AttrName)) - Entries.append(Existing.begin(), Existing.end()); - Entries.push_back(Entry); - Op->setAttr(AttrName, B.getArrayAttr(Entries)); -} - -// Helper: parse integer from StringRef, returns -1 on failure -int ParseInt(StringRef S) { - int Val = -1; - S.getAsInteger(10, Val); - return Val; -} - -// ── array_partition ──────────────────────────────────────────────────────── -void HandleArrayPartition(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - StringRef VarPath = KV.lookup("variable"); - if (VarPath.empty()) { - llvm::outs() << "[HLS] Warning: array_partition missing variable=\n"; - return; - } - - StringRef Base = VarPath.split('.').first; - AllocaOp AttachOp = FindAlloca(Meta.Op, Base); - if (!AttachOp) { - llvm::outs() << "[HLS] Warning: array_partition could not find alloca '" - << Base << "'\n"; - return; - } - - mlir::Builder B(AttachOp.getContext()); - SmallVector Fields; - Fields.push_back(B.getNamedAttr("variable", B.getStringAttr(VarPath))); - - // kind: explicit key or bare flag (complete/block/cyclic), default complete - StringRef Kind = KV.count("type") ? KV["type"] : StringRef("complete"); - for (StringRef F : Flags) - if (F == "complete" || F == "block" || F == "cyclic") { Kind = F; break; } - Fields.push_back(B.getNamedAttr("kind", B.getStringAttr(Kind))); - - if (KV.count("factor")) - Fields.push_back(B.getNamedAttr("factor", - B.getI32IntegerAttr(ParseInt(KV["factor"])))); - if (KV.count("dim")) - Fields.push_back(B.getNamedAttr("dim", - B.getI32IntegerAttr(ParseInt(KV["dim"])))); - - AppendAttrEntry(AttachOp, "hls.array_partition", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached array_partition {variable=" << VarPath - << ", kind=" << Kind << "} to '" << Base << "'\n"; -} - -// ── array_reshape ────────────────────────────────────────────────────────── -// Same args as array_partition; semantics differ (word-width widening vs split) -void HandleArrayReshape(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - StringRef VarPath = KV.lookup("variable"); - if (VarPath.empty()) { - llvm::outs() << "[HLS] Warning: array_reshape missing variable=\n"; - return; - } - - StringRef Base = VarPath.split('.').first; - AllocaOp AttachOp = FindAlloca(Meta.Op, Base); - if (!AttachOp) { - llvm::outs() << "[HLS] Warning: array_reshape could not find alloca '" - << Base << "'\n"; - return; - } - - mlir::Builder B(AttachOp.getContext()); - SmallVector Fields; - Fields.push_back(B.getNamedAttr("variable", B.getStringAttr(VarPath))); - - StringRef Kind = KV.count("type") ? KV["type"] : StringRef("complete"); - for (StringRef F : Flags) - if (F == "complete" || F == "block" || F == "cyclic") { Kind = F; break; } - Fields.push_back(B.getNamedAttr("kind", B.getStringAttr(Kind))); - - if (KV.count("factor")) - Fields.push_back(B.getNamedAttr("factor", - B.getI32IntegerAttr(ParseInt(KV["factor"])))); - if (KV.count("dim")) - Fields.push_back(B.getNamedAttr("dim", - B.getI32IntegerAttr(ParseInt(KV["dim"])))); - - AppendAttrEntry(AttachOp, "hls.array_reshape", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached array_reshape {variable=" << VarPath - << ", kind=" << Kind << "} to '" << Base << "'\n"; -} - -// ── bind_storage ─────────────────────────────────────────────────────────── -// #pragma HLS bind_storage variable= type= -// impl= latency= -void HandleBindStorage(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - StringRef VarPath = KV.lookup("variable"); - if (VarPath.empty()) { - llvm::outs() << "[HLS] Warning: bind_storage missing variable=\n"; - return; - } - - StringRef Base = VarPath.split('.').first; - AllocaOp AttachOp = FindAlloca(Meta.Op, Base); - if (!AttachOp) { - llvm::outs() << "[HLS] Warning: bind_storage could not find alloca '" - << Base << "'\n"; - return; - } - - mlir::Builder B(AttachOp.getContext()); - SmallVector Fields; - Fields.push_back(B.getNamedAttr("variable", B.getStringAttr(VarPath))); - - if (KV.count("type")) - Fields.push_back(B.getNamedAttr("type", B.getStringAttr(KV["type"]))); - if (KV.count("impl")) - Fields.push_back(B.getNamedAttr("impl", B.getStringAttr(KV["impl"]))); - if (KV.count("latency")) - Fields.push_back(B.getNamedAttr("latency", - B.getI32IntegerAttr(ParseInt(KV["latency"])))); - - AppendAttrEntry(AttachOp, "hls.bind_storage", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached bind_storage {variable=" << VarPath << "} to '" - << Base << "'\n"; -} - -// ── bind_op ──────────────────────────────────────────────────────────────── -// #pragma HLS bind_op variable= op= -// impl= latency= -void HandleBindOp(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - StringRef VarPath = KV.lookup("variable"); - if (VarPath.empty()) { - llvm::outs() << "[HLS] Warning: bind_op missing variable=\n"; - return; - } - - StringRef Base = VarPath.split('.').first; - mlir::Operation *AttachOp = FindOpByName(Meta.Op, Base); - - if (!AttachOp) { - llvm::outs() << "[HLS] Warning: bind_op could not find producer for '" - << Base << "'\n"; - return; - } - - // Optionally: filter by op type matching the pragma's op= field - if (KV.count("op")) { - StringRef Want = KV["op"]; - bool ok = false; - if (Want == "mul") - ok = llvm::isa(AttachOp); - else if (Want == "add") - ok = llvm::isa(AttachOp); - // ... etc - if (!ok) { - llvm::outs() << "[HLS] Warning: bind_op variable=" << Base - << " op=" << Want << " but producer is " - << AttachOp->getName().getStringRef() << "\n"; - return; - } - } - - mlir::Builder B(AttachOp->getContext()); - SmallVector Fields; - if (KV.count("op")) Fields.push_back(B.getNamedAttr("op", B.getStringAttr(KV["op"]))); - if (KV.count("impl")) Fields.push_back(B.getNamedAttr("impl", B.getStringAttr(KV["impl"]))); - if (KV.count("latency")) Fields.push_back(B.getNamedAttr("latency", B.getI32IntegerAttr(ParseInt(KV["latency"])))); - - AppendAttrEntry(AttachOp, "hls.bind_op", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached bind_op {variable=" << VarPath << "} to '" - << Base << "'\n"; -} - -// ── allocation ───────────────────────────────────────────────────────────── -// #pragma HLS allocation instances= limit= type= -// No variable — attaches to the enclosing function/scope op directly -void HandleAllocation(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - if (!KV.count("instances") || !KV.count("limit")) { - llvm::outs() << "[HLS] Warning: allocation missing instances= or limit=\n"; - return; - } - - mlir::Builder B(Meta.Op->getContext()); - SmallVector Fields; - Fields.push_back(B.getNamedAttr("instances", - B.getStringAttr(KV["instances"]))); - Fields.push_back(B.getNamedAttr("limit", - B.getI32IntegerAttr(ParseInt(KV["limit"])))); - - // type= defaults to "function" - StringRef AllocType = KV.count("type") ? KV["type"] : StringRef("function"); - Fields.push_back(B.getNamedAttr("type", B.getStringAttr(AllocType))); - - AppendAttrEntry(Meta.Op, "hls.allocation", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached allocation {instances=" << KV["instances"] - << ", limit=" << KV["limit"] << "} to scope op\n"; -} - -// ── unroll ───────────────────────────────────────────────────────────────── -// #pragma HLS unroll [factor=] [skip_exit_check] -// No variable — attaches to the enclosing loop/scope op -void HandleUnroll(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - mlir::Builder B(Meta.Op->getContext()); - SmallVector Fields; - - // factor= absent means full unroll - if (KV.count("factor")) - Fields.push_back(B.getNamedAttr("factor", - B.getI32IntegerAttr(ParseInt(KV["factor"])))); - else - Fields.push_back(B.getNamedAttr("factor", B.getI32IntegerAttr(0))); // 0 = full - - bool SkipExitCheck = llvm::is_contained(Flags, StringRef("skip_exit_check")); - Fields.push_back(B.getNamedAttr("skip_exit_check", - B.getBoolAttr(SkipExitCheck))); - - // Attach directly to the scope op (loop body) - AppendAttrEntry(Meta.Op, "hls.unroll", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached unroll {factor=" - << (KV.count("factor") ? KV["factor"] : StringRef("full")) - << ", skip_exit_check=" << SkipExitCheck << "} to scope op\n"; -} - -// ── pipeline ─────────────────────────────────────────────────────────────── -// #pragma HLS pipeline [II=] [rewind] [style=stp|flp|frp] -// No variable — attaches to the enclosing function/loop scope op -void HandlePipeline(HLSPragmaMetaData &Meta) { - SmallVector Args; - SplitString(Meta.Args, Args); - - llvm::StringMap KV; - SmallVector Flags; - ParseArgs(Args, KV, Flags); - - mlir::Builder B(Meta.Op->getContext()); - SmallVector Fields; - - // II=0 means "let tool decide minimum" - int II = KV.count("II") ? ParseInt(KV["II"]) : 0; - Fields.push_back(B.getNamedAttr("II", B.getI32IntegerAttr(II))); - - bool Rewind = llvm::is_contained(Flags, StringRef("rewind")); - Fields.push_back(B.getNamedAttr("rewind", B.getBoolAttr(Rewind))); - - // style: stp (stall), flp (flushable), frp (free-running), default stp - StringRef Style = KV.count("style") ? KV["style"] : StringRef("stp"); - Fields.push_back(B.getNamedAttr("style", B.getStringAttr(Style))); - - // Attach directly to the scope op (function or loop) - AppendAttrEntry(Meta.Op, "hls.pipeline", B.getDictionaryAttr(Fields)); - llvm::outs() << "[HLS] Attached pipeline {II=" << II - << ", rewind=" << Rewind << ", style=" << Style - << "} to scope op\n"; -} - - - -void AttachMetadata(std::vector &HLSMetadata) { - for (HLSPragmaMetaData &Meta : HLSMetadata) { - llvm::outs() << "Arguments: " << Meta.Args << "\n"; - if (!Meta.Op) { - llvm::outs() << "[HLS] Warning: pragma '" << Meta.Name - << "' has no resolved scope, skipping\n"; - continue; - } - if (Meta.Name == "array_partition") HandleArrayPartition(Meta); - else if (Meta.Name == "array_reshape") HandleArrayReshape(Meta); - else if (Meta.Name == "bind_storage") HandleBindStorage(Meta); - else if (Meta.Name == "bind_op") HandleBindOp(Meta); - else if (Meta.Name == "allocation") HandleAllocation(Meta); - else if (Meta.Name == "unroll") HandleUnroll(Meta); - else if (Meta.Name == "pipeline") HandlePipeline(Meta); - } -} - diff --git a/tools/cgeist/Lib/HandleHLS.h b/tools/cgeist/Lib/HandleHLS.h deleted file mode 100644 index 02f53a126473..000000000000 --- a/tools/cgeist/Lib/HandleHLS.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "clang/Frontend/ASTConsumers.h" -#include "clang/Frontend/MultiplexConsumer.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "mlir/IR/Builders.h" - -void ResolveScope(mlir::ModuleOp MlirModule, - std::vector &HLSMetadata); - -void AttachMetadata(std::vector &HLSMetadata); diff --git a/tools/cgeist/Lib/ValueCategory.cc b/tools/cgeist/Lib/ValueCategory.cc index 3817a64ee14f..b24711c2edd6 100644 --- a/tools/cgeist/Lib/ValueCategory.cc +++ b/tools/cgeist/Lib/ValueCategory.cc @@ -95,6 +95,17 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, toStore = builder.create(loc, MT, toStore); } } + // Assigning an array to a pointer variable (`p = out[1];` with + // `int out[16][32]` and a parameter `int p[16]`, a memref + // variable): the decayed row is a memref of static shape; cast it to the + // variable's type (W8b repro pa.c, forgebench mult_op_module_mm / + // mmv: `output = out[0];`). + if (auto dstMT = dyn_cast( + val.getType().cast().getElementType())) + if (auto srcMT = dyn_cast(toStore.getType())) + if (srcMT != dstMT && + mlir::memref::CastOp::areCastCompatible(srcMT, dstMT)) + toStore = builder.create(loc, dstMT, toStore); assert(toStore.getType() == val.getType().cast().getElementType() && "expect same type"); diff --git a/tools/cgeist/Lib/XlxDeadStore.cc b/tools/cgeist/Lib/XlxDeadStore.cc new file mode 100644 index 000000000000..8302f5c42dd9 --- /dev/null +++ b/tools/cgeist/Lib/XlxDeadStore.cc @@ -0,0 +1,176 @@ +//===- XlxDeadStore.cc - Overwritten stores of the Vitis HLS headers ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// --xlx-headers: delete a store that the next memory access in the same block +// overwrites, location for location, with nothing in between that touches +// memory. +// +// The Vitis HLS headers' conversions start with a guard store that the +// following code always overwrites, e.g. the ap_fixed_base conversion +// (etc/ap_fixed_base.h:691, equal_constexpr): +// +// if (!op) Base::V = 0; +// ... +// Base::V = op.V >> sh_amt; // unconditional +// +// After inlining, cgeist writes such a `Base::V` straight into the user's +// array element, so `out[0] += a * b` becomes +// +// scf.if %iszero { affine.store %c0, %out[0] } +// affine.store %v, %out[0] +// +// Vitis' LLVM pipeline removes the guarded store: in the Vitis run of +// forgebench/mult_op_module_dot the dot_product loop body of db/a.o.1.ll (the +// first reflow stage) has only the unconditional `store i16 %trunc.ln138.N, +// i16* %output` per unrolled iteration, no conditional store. Left in place +// it is an extra memory operation in hls-est's schedule (the same loop +// scheduled with and without it: 15 RAM_1WNR copies without, 1 with). +// +// What is deleted: an affine.store / memref.store, or an scf.if / affine.if +// without results and without an else branch whose then branch holds only +// memory-effect-free ops and stores to one location, when the next op after +// it in the block that has any memory effect is an unconditional store to the +// same location (the same memref value and the same indices: identical index +// operands, and for affine.store the identical map). Only memory-effect-free +// ops may lie in between, so no load can observe the deleted store. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "mlir/IR/BuiltinOps.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include + +using namespace mlir; + +namespace { + +/// The location a store writes: the memref, the index operands and, for an +/// affine.store, its map. +struct StoreLoc { + Value memref; + AffineMap map; // null for memref.store + SmallVector operands; + + bool operator==(const StoreLoc &o) const { + return memref == o.memref && map == o.map && operands == o.operands; + } +}; + +std::optional storeLoc(Operation *op) { + if (auto s = dyn_cast(op)) { + StoreLoc l{s.getMemRef(), s.getAffineMap(), {}}; + l.operands.append(s.getMapOperands().begin(), s.getMapOperands().end()); + return l; + } + if (auto s = dyn_cast(op)) { + StoreLoc l{s.getMemRef(), AffineMap(), {}}; + l.operands.append(s.getIndices().begin(), s.getIndices().end()); + return l; + } + return std::nullopt; +} + +/// The single location `op` may write when it is a store, or a guarded +/// (then-only, result-less) if whose then branch writes only that location +/// and has no other memory effect. std::nullopt otherwise. +std::optional deletableWrite(Operation *op) { + if (auto l = storeLoc(op)) + return l; + Block *then = nullptr; + if (auto i = dyn_cast(op)) { + if (i.getNumResults() || !i.getElseRegion().empty()) + return std::nullopt; + then = i.thenBlock(); + } else if (auto i = dyn_cast(op)) { + if (i.getNumResults() || i.hasElse()) + return std::nullopt; + then = i.getThenBlock(); + } else { + return std::nullopt; + } + std::optional loc; + for (Operation &inner : *then) { + if (auto l = storeLoc(&inner)) { + if (loc && !(*loc == *l)) + return std::nullopt; + // The memref and the index operands must be defined outside the if, so + // that the location means the same thing at the later store. + if (op->isAncestor(l->memref.getParentBlock()->getParentOp())) + return std::nullopt; + for (Value v : l->operands) + if (op->isAncestor(v.getParentBlock()->getParentOp())) + return std::nullopt; + loc = l; + continue; + } + if (!isMemoryEffectFree(&inner)) + return std::nullopt; + } + return loc; +} + +/// True when the next op after `op` in its block with a memory effect is a +/// store to `loc`. +bool overwrittenLater(Operation *op, const StoreLoc &loc) { + for (Operation *next = op->getNextNode(); next; next = next->getNextNode()) { + if (auto l = storeLoc(next)) + return *l == loc; + if (!isMemoryEffectFree(next)) + return false; + } + return false; +} + +} // namespace + +namespace cgeist { +void eraseOverwrittenStores(mlir::ModuleOp module) { + SmallVector dead; + module.walk([&](Operation *op) { + if (auto loc = deletableWrite(op)) + if (overwrittenLater(op, *loc)) + dead.push_back(op); + }); + // The walk is post-order: a store inside a guarded if comes before the if. + // Erase only the outermost dead ops (an op nested in another dead op goes + // with it). + llvm::SmallPtrSet deadSet(dead.begin(), dead.end()); + for (Operation *op : dead) { + bool nested = false; + for (Operation *p = op->getParentOp(); p && !nested; p = p->getParentOp()) + nested = deadSet.contains(p); + deadSet.erase(op); + if (nested) + continue; + // The guard's condition and the stored value may be dead now too. + llvm::SetVector defs; + op->walk([&](Operation *o) { + for (Value v : o->getOperands()) + if (Operation *d = v.getDefiningOp()) + if (!op->isAncestor(d)) + defs.insert(d); + }); + op->erase(); + while (!defs.empty()) { + Operation *d = defs.pop_back_val(); + if (!isOpTriviallyDead(d)) + continue; + for (Value v : d->getOperands()) + if (Operation *dd = v.getDefiningOp()) + defs.insert(dd); + d->erase(); + } + } +} +} // namespace cgeist diff --git a/tools/cgeist/Lib/XlxLoopScalarPromote.cc b/tools/cgeist/Lib/XlxLoopScalarPromote.cc new file mode 100644 index 000000000000..bea5c8a553b4 --- /dev/null +++ b/tools/cgeist/Lib/XlxLoopScalarPromote.cc @@ -0,0 +1,461 @@ +//===- XlxLoopScalarPromote.cc - Scalars carried by structured loops ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// A local scalar that a loop reads and updates (a loop counter) is promoted +// to an SSA value carried by the loops around its accesses. Polygeist's +// mem2reg forwards stores to loads within a block and through scf.if, but a +// value carried around an scf.while stays in its `memref` alloca: a loop +// counted by an `ap_uint<16>` (whose ++ / < are the Vitis header's inlined +// member functions) keeps its counter in memory, so --raise-scf-to-affine +// sees no induction variable and hls-est no counted loop (OPEN_ISSUES O101 +// in the hls-est tree: rosetta 3d-rendering OUTPUT_FB_ROW / COL, Dehazing +// debayer, which Vitis pipelines; with `int` counters both are counted +// loops). +// +// For every rank-0 alloca of an integer, index or float element whose uses +// are only loads and stores of it, each nested in scf.if / scf.while / +// scf.for / affine.for / affine.if regions of its function, the value is +// threaded through those regions in program order (structured SSA +// construction): a load takes the current value, a store sets it, an if gets +// a result carrying the value out of both arms, a loop gets an iteration +// argument (scf.while: one in the before region forwarded to the after +// region and yielded back). A load before any store reads an undefined value +// (llvm.mlir.undef), as the alloca did. A loop body (a while's condition) +// starts from an undefined value instead of its iteration argument only where +// the carried value is dead: no path from there (through the body, a +// zero-trip body, the next iteration or the code after the loop) reads it +// before writing it. Any other use or region op leaves the alloca as it is. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "mlir/IR/IntegerSet.h" +#include "mlir/IR/PatternMatch.h" +#include "mlir/Interfaces/LoopLikeInterface.h" +#include "mlir/Pass/Pass.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" + +using namespace mlir; + +namespace { + +/// The memref a load / store accesses, or null. +Value accessedMemref(Operation *op) { + if (auto l = dyn_cast(op)) + return l.getMemRef(); + if (auto s = dyn_cast(op)) + return s.getMemRef(); + if (auto l = dyn_cast(op)) + return l.getMemRef(); + if (auto s = dyn_cast(op)) + return s.getMemRef(); + return Value(); +} + +bool isLoad(Operation *op) { + return isa(op); +} + +/// A region op the promotion threads the value through. +bool isSupportedRegionOp(Operation *op) { + return isa(op); +} + +class Promoter { +public: + Promoter(memref::AllocaOp slot, IRRewriter &rewriter) + : slot(slot), rewriter(rewriter) {} + + /// Whether every use is a plain load / store of the scalar inside + /// supported region ops of the slot's function, and at least one use + /// lies in a loop (only those need this pass). + bool promotable() { + auto fn = slot->getParentOfType(); + if (!fn) + return false; + bool inLoop = false; + for (OpOperand &use : slot.getResult().getUses()) { + Operation *user = use.getOwner(); + if (accessedMemref(user) != slot.getResult()) + return false; // the address is stored, passed, viewed + if (auto s = dyn_cast(user); + s && s.getValueToStore() == slot.getResult()) + return false; + if (auto s = dyn_cast(user); + s && s.getValueToStore() == slot.getResult()) + return false; + for (Operation *p = user->getParentOp(); p != fn.getOperation(); + p = p->getParentOp()) { + if (!p || !isSupportedRegionOp(p)) + return false; + for (Region &r : p->getRegions()) + if (!r.empty() && !r.hasOneBlock()) + return false; + if (isa(p)) + inLoop = true; + } + } + return inLoop; + } + + void run() { + computeLiveness(); + Type t = slot.getType().getElementType(); + rewriter.setInsertionPointAfter(slot); + Value undef = rewriter.create(slot.getLoc(), t); + promoteBlock(*slot->getBlock(), undef); + for (Operation *op : dead) + rewriter.eraseOp(op); + rewriter.eraseOp(slot); + } + +private: + bool usesInside(Operation *op) { + bool found = false; + op->walk([&](Operation *inner) { + if (accessedMemref(inner) == slot.getResult()) { + found = true; + return WalkResult::interrupt(); + } + return WalkResult::advance(); + }); + return found; + } + + enum class First { None, Exposed, Defined }; + + /// Whether the operations [begin, end) may read the value before writing + /// it (a load first on some path: Exposed), surely write it first + /// (Defined), or neither (None: no read first, and some path leaves the + /// range without writing). + First firstAccess(Block::iterator begin, Block::iterator end) { + for (Operation &op : llvm::make_range(begin, end)) { + if (accessedMemref(&op) == slot.getResult()) + return isLoad(&op) ? First::Exposed : First::Defined; + if (op.getNumRegions() == 0 || !usesInside(&op)) + continue; + if (isa(op)) { + First t = op.getRegion(0).empty() ? First::None + : firstAccess(op.getRegion(0).front()); + First e = op.getRegion(1).empty() ? First::None + : firstAccess(op.getRegion(1).front()); + if (t == First::Exposed || e == First::Exposed) + return First::Exposed; + if (t == First::Defined && e == First::Defined) + return First::Defined; + continue; + } + if (auto w = dyn_cast(op)) { + First b = firstAccess(w.getBefore().front()); + if (b != First::None) + return b; // the condition runs at least once + if (firstAccess(w.getAfter().front()) == First::Exposed) + return First::Exposed; + continue; + } + // A loop body may run zero times: only a read in it counts. + for (Region &r : op.getRegions()) + if (!r.empty() && firstAccess(r.front()) == First::Exposed) + return First::Exposed; + } + return First::None; + } + + First firstAccess(Block &block) { + return firstAccess(block.begin(), block.end()); + } + + /// Whether the value held right after `op` may still be read: a path from + /// there reaches a load before a store. A path that leaves `op`'s block + /// continues where control goes next: after an if, at the next iteration + /// or the exit of a loop, into a while's body or out of it. The function's + /// end ends the scalar's life. + bool liveAfter(Operation *op) { + Block *block = op->getBlock(); + First rest = firstAccess(std::next(Block::iterator(op)), block->end()); + if (rest != First::None) + return rest == First::Exposed; + return liveAtEnd(block); + } + + /// Whether the value at the end of `block` may still be read. + bool liveAtEnd(Block *block) { + Operation *parent = block->getParentOp(); + if (isa(parent)) + return false; + if (isa(parent)) + return liveAfter(parent); + if (auto w = dyn_cast(parent)) { + if (block == &w.getBefore().front()) // the condition: body or exit + return liveAtStart(w.getAfter().front(), w) || liveAfter(w); + return liveAtWhileStart(w); // the body: back to the condition + } + // A loop body's end: the next iteration or the exit. + return liveAtStart(*block, parent) || liveAfter(parent); + } + + /// Whether the value at the start of `body` (of `loop`, a for loop or a + /// while's body) may be read. Going round the loop again adds no path + /// that the body itself does not already have. + bool liveAtStart(Block &body, Operation *loop) { + First f = firstAccess(body); + if (f != First::None) + return f == First::Exposed; + if (auto w = dyn_cast(loop)) // the body ends at the condition + return liveAtWhileStart(w); + return liveAfter(loop); // the exit + } + + /// Whether the value at the start of a while's condition may be read: the + /// condition reads it, or a path through the condition reaches the body + /// (which reads it first) or the exit (after which it is read). + bool liveAtWhileStart(scf::WhileOp w) { + First fb = firstAccess(w.getBefore().front()); + if (fb != First::None) + return fb == First::Exposed; + return firstAccess(w.getAfter().front()) == First::Exposed || + liveAfter(w); + } + + /// The value a loop body starts from: the iteration argument when the + /// value carried in may still be read (by the body before it writes, or, + /// on a path through the body that does not write it, after the loop), + /// else a fresh undefined value. A scalar each iteration writes before + /// reading (an accumulator reset in an outer loop's body) so carries no + /// recurrence around that loop, as LLVM's mem2reg builds no live phi for + /// it (hyungseok lab2: the sum of an inner product reset in the two loops + /// around it). Decided on the IR before any rewrite (`liveStart`). + Value bodyStart(Operation *loop, Block &body, Value arg) { + if (liveStart.lookup(loop)) + return arg; + OpBuilder::InsertionGuard g(rewriter); + rewriter.setInsertionPointToStart(&body); + return rewriter.create(slot.getLoc(), arg.getType()); + } + + /// Records, for every loop that holds an access, whether the value at the + /// start of its body (a while: of its condition) may be read. + void computeLiveness() { + slot->getParentOfType().walk([&](Operation *op) { + if (!usesInside(op)) + return; + if (auto w = dyn_cast(op)) + liveStart[op] = liveAtWhileStart(w); + else if (isa(op)) + liveStart[op] = liveAtStart(op->getRegion(0).front(), op); + }); + } + + /// Threads the value through `block` starting from `cur`; returns the value + /// at the block's end. + Value promoteBlock(Block &block, Value cur) { + SmallVector ops; + for (Operation &op : block) + ops.push_back(&op); + for (Operation *op : ops) { + if (accessedMemref(op) == slot.getResult()) { + if (isLoad(op)) + op->getResult(0).replaceAllUsesWith(cur); + else if (auto s = dyn_cast(op)) + cur = s.getValueToStore(); + else + cur = cast(op).getValueToStore(); + dead.push_back(op); + continue; + } + if (op->getNumRegions() == 0 || !usesInside(op)) + continue; + if (auto ifOp = dyn_cast(op)) + cur = promoteIf(ifOp, cur); + else if (auto ifOp = dyn_cast(op)) + cur = promoteAffineIf(ifOp, cur); + else if (auto w = dyn_cast(op)) + cur = promoteWhile(w, cur); + else if (auto loop = dyn_cast(op)) + cur = promoteLoop(loop, cur); + } + return cur; + } + + Value promoteIf(scf::IfOp ifOp, Value cur) { + Value thenV = promoteBlock(*ifOp.thenBlock(), cur); + Value elseV = ifOp.elseBlock() ? promoteBlock(*ifOp.elseBlock(), cur) : cur; + if (thenV == cur && elseV == cur) + return cur; + SmallVector types(ifOp.getResultTypes()); + types.push_back(cur.getType()); + rewriter.setInsertionPoint(ifOp); + auto newIf = rewriter.create(ifOp.getLoc(), types, + ifOp.getCondition(), + /*addThenBlock=*/false, + /*addElseBlock=*/false); + Operation *thenYield = ifOp.thenBlock()->getTerminator(); + thenYield->insertOperands(thenYield->getNumOperands(), thenV); + if (ifOp.elseBlock()) { + Operation *elseYield = ifOp.elseBlock()->getTerminator(); + elseYield->insertOperands(elseYield->getNumOperands(), elseV); + } + newIf.getThenRegion().takeBody(ifOp.getThenRegion()); + if (!ifOp.getElseRegion().empty()) { + newIf.getElseRegion().takeBody(ifOp.getElseRegion()); + } else { + Block *b = rewriter.createBlock(&newIf.getElseRegion()); + rewriter.setInsertionPointToEnd(b); + rewriter.create(ifOp.getLoc(), ValueRange{elseV}); + } + copyAttrs(ifOp, newIf); + for (auto [o, n] : llvm::zip(ifOp.getResults(), newIf.getResults())) + o.replaceAllUsesWith(n); + rewriter.eraseOp(ifOp); + return newIf.getResults().back(); + } + + Value promoteAffineIf(affine::AffineIfOp ifOp, Value cur) { + Value thenV = promoteBlock(*ifOp.getThenBlock(), cur); + Value elseV = + ifOp.hasElse() ? promoteBlock(*ifOp.getElseBlock(), cur) : cur; + if (thenV == cur && elseV == cur) + return cur; + SmallVector types(ifOp.getResultTypes()); + types.push_back(cur.getType()); + rewriter.setInsertionPoint(ifOp); + // An affine.if with results needs an else region; the builder's blocks + // are replaced by the old ones (or a block yielding the value). + auto newIf = rewriter.create( + ifOp.getLoc(), types, ifOp.getIntegerSet(), ifOp.getOperands(), + /*withElseRegion=*/true); + newIf.getThenRegion().getBlocks().clear(); + newIf.getElseRegion().getBlocks().clear(); + newIf.getThenRegion().takeBody(ifOp.getThenRegion()); + Operation *thenYield = newIf.getThenBlock()->getTerminator(); + thenYield->insertOperands(thenYield->getNumOperands(), thenV); + if (ifOp.hasElse()) { + newIf.getElseRegion().takeBody(ifOp.getElseRegion()); + Operation *elseYield = newIf.getElseBlock()->getTerminator(); + elseYield->insertOperands(elseYield->getNumOperands(), elseV); + } else { + Block *b = rewriter.createBlock(&newIf.getElseRegion()); + rewriter.setInsertionPointToEnd(b); + rewriter.create(ifOp.getLoc(), + ValueRange{elseV}); + } + copyAttrs(ifOp, newIf); + for (auto [o, n] : llvm::zip(ifOp.getResults(), newIf.getResults())) + o.replaceAllUsesWith(n); + rewriter.eraseOp(ifOp); + return newIf.getResults().back(); + } + + Value promoteWhile(scf::WhileOp w, Value cur) { + Type t = cur.getType(); + Location loc = w.getLoc(); + Block &before = w.getBefore().front(); + Block &after = w.getAfter().front(); + // The condition starts from the carried value when it may be read: by + // the condition or the body before they write it, or after the loop (the + // loop's result is the value the condition passes on when it exits). + BlockArgument bArg = before.addArgument(t, loc); + Value bStart = bArg; + if (!liveStart.lookup(w)) { + OpBuilder::InsertionGuard g(rewriter); + rewriter.setInsertionPointToStart(&before); + bStart = rewriter.create(loc, t); + } + Value bEnd = promoteBlock(before, bStart); + auto cond = cast(before.getTerminator()); + cond.getArgsMutable().append(bEnd); + BlockArgument aArg = after.addArgument(t, loc); + Value aEnd = promoteBlock(after, aArg); + auto yield = cast(after.getTerminator()); + yield.getResultsMutable().append(aEnd); + SmallVector inits(w.getInits()); + inits.push_back(cur); + SmallVector types(w.getResultTypes()); + types.push_back(t); + rewriter.setInsertionPoint(w); + auto nw = rewriter.create(loc, types, inits); + nw.getBefore().takeBody(w.getBefore()); + nw.getAfter().takeBody(w.getAfter()); + copyAttrs(w, nw); + for (auto [o, n] : llvm::zip(w.getResults(), nw.getResults())) + o.replaceAllUsesWith(n); + rewriter.eraseOp(w); + return nw.getResults().back(); + } + + Value promoteLoop(LoopLikeOpInterface loop, Value cur) { + Operation *original = loop.getOperation(); + FailureOr nl = loop.replaceWithAdditionalYields( + rewriter, ValueRange{cur}, /*replaceInitOperandUsesInLoop=*/false, + [&](OpBuilder &b, Location, ArrayRef args) { + // The builder stands at the body's yield; the body's operations + // may still be in the old loop's block (scf.for moves them into + // the new loop after this call), so thread the value through the + // block that holds the yield. + Block *body = b.getInsertionBlock(); + return SmallVector{ + promoteBlock(*body, bodyStart(original, *body, args.front()))}; + }); + if (failed(nl)) + return cur; // not reached: promotable() admits scf.for / affine.for + return (*nl)->getResults().back(); + } + + static void copyAttrs(Operation *from, Operation *to) { + for (NamedAttribute a : from->getDiscardableAttrs()) + to->setDiscardableAttr(a.getName(), a.getValue()); + } + + memref::AllocaOp slot; + IRRewriter &rewriter; + SmallVector dead; + llvm::DenseMap liveStart; +}; + +struct XlxLoopScalarPromotePass + : public PassWrapper> { + MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(XlxLoopScalarPromotePass) + StringRef getArgument() const override { + return "xlx-loop-scalar-promote"; + } + void getDependentDialects(DialectRegistry ®istry) const override { + registry.insert(); + } + void runOnOperation() override { + SmallVector candidates; + getOperation().walk([&](memref::AllocaOp a) { + MemRefType t = a.getType(); + if (t.getRank() == 0 && (t.getElementType().isIntOrIndexOrFloat())) + candidates.push_back(a); + }); + IRRewriter rewriter(&getContext()); + for (memref::AllocaOp a : candidates) { + Promoter p(a, rewriter); + if (!p.promotable()) + continue; + p.run(); + } + } +}; + +} // namespace + +namespace cgeist { +std::unique_ptr createXlxLoopScalarPromotePass() { + return std::make_unique(); +} +} // namespace cgeist diff --git a/tools/cgeist/Lib/XlxMathCore.cc b/tools/cgeist/Lib/XlxMathCore.cc new file mode 100644 index 000000000000..0ac42852d3a0 --- /dev/null +++ b/tools/cgeist/Lib/XlxMathCore.cc @@ -0,0 +1,138 @@ +//===- XlxMathCore.cc - hls:: math library calls as cores ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// See XlxMathCore.h. The function names are those hls-est's math-core model +// knows (MathCores.cpp coreFunctions); hls_math.h spells them also with an +// `f` suffix (hls::expf, hls::sqrtf) and a `half_` prefix (hls::half_exp). +// The fixed-point overloads are the ones the stand-in headers mark +// (shim/exactclass/hls_math.h HLSEST_M1 / HLSEST_M2); `abs` and the rounding +// functions are computed in plain logic there and are not cores. +// +//===----------------------------------------------------------------------===// + +#include "XlxMathCore.h" +#include "HLSPragma.h" + +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/Basic/SourceManager.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/Support/Path.h" + +using namespace clang; + +namespace cgeist { +namespace xlx { + +namespace { + +/// Cores of the float / double / half overloads (MathCores coreFunctions). +const llvm::StringSet<> &floatCores() { + static const llvm::StringSet<> s = { + "exp", "exp2", "exp10", "expm1", "log", "log2", "log10", + "log1p", "logb", "sqrt", "rsqrt", "cbrt", "recip", "sin", + "cos", "tan", "sinpi", "cospi", "asin", "acos", "atan", + "atan2", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh", + "pow", "erf", "erfc", "hypot", "fmod", "remainder"}; + return s; +} + +/// Cores of the fixed-point overloads (the stand-in headers' markers). +const llvm::StringSet<> &fixedCores() { + static const llvm::StringSet<> s = { + "sqrt", "exp", "exp2", "expm1", "log", "log2", "log10", "log1p", + "logb", "tanh", "sinh", "cosh", "atanh", "asinh", "acosh", "erf", + "erfc", "cbrt", "rsqrt", "tan", "sinpi", "cospi", "sin", "cos", + "atan", "asin", "acos", "atan2", "pow"}; + return s; +} + +/// W, I and signedness of an ap_fixed_base / ap_int_base class or a class +/// over one (ap_fixed, ap_uint). +bool apFormat(const CXXRecordDecl *rd, int64_t &w, int64_t &i, bool &s) { + for (unsigned guard = 0; rd && guard < 8; ++guard) { + if (auto *spec = dyn_cast(rd)) { + const TemplateArgumentList &a = spec->getTemplateArgs(); + auto num = [&](unsigned k, int64_t &v) { + if (k >= a.size() || a[k].getKind() != TemplateArgument::Integral) + return false; + v = a[k].getAsIntegral().getExtValue(); + return true; + }; + int64_t sv = 0; + if (spec->getName() == "ap_fixed_base" && a.size() == 6) + if (num(0, w) && num(1, i) && num(2, sv)) { + s = sv != 0; + return true; + } + if (spec->getName() == "ap_int_base" && a.size() == 2) + if (num(0, w) && num(1, sv)) { + i = w; + s = sv != 0; + return true; + } + } + if (rd->getNumBases() != 1) + return false; + rd = rd->bases_begin()->getType()->getAsCXXRecordDecl(); + } + return false; +} + +bool declaredInHlsMath(const FunctionDecl *fd, ASTContext &ctx) { + const FunctionDecl *pattern = fd->getTemplateInstantiationPattern(); + const FunctionDecl *d = pattern ? pattern : fd; + const SourceManager &sm = ctx.getSourceManager(); + SourceLocation loc = sm.getExpansionLoc(d->getLocation()); + if (loc.isInvalid()) + return false; + return llvm::sys::path::filename(sm.getFilename(loc)) == "hls_math.h"; +} + +} // namespace + +std::optional mathCoreOf(const FunctionDecl *fd, ASTContext &ctx) { + if (!cgeist::hls::xlxHeaders() || !fd || !fd->getIdentifier() || + fd->getNumParams() == 0 || isa(fd)) + return std::nullopt; + auto *ns = dyn_cast(fd->getDeclContext()->getRedeclContext()); + if (!ns || ns->getName() != "hls" || + !ns->getDeclContext()->getRedeclContext()->isTranslationUnit()) + return std::nullopt; + if (!declaredInHlsMath(fd, ctx)) + return std::nullopt; + + QualType arg = fd->getParamDecl(0)->getType().getNonReferenceType(); + arg = arg.getUnqualifiedType(); + llvm::StringRef name = fd->getName(); + if (const CXXRecordDecl *rd = arg->getAsCXXRecordDecl()) { + int64_t w = 0, i = 0; + bool s = true; + if (!fixedCores().contains(name) || !apFormat(rd, w, i, s)) + return std::nullopt; + return MathCore{name.str(), (s ? "ap_fixed<" : "ap_ufixed<") + + std::to_string(w) + "," + + std::to_string(i) + ">"}; + } + if (!arg->isRealFloatingType()) + return std::nullopt; + std::string fn = name.str(); + if (llvm::StringRef(fn).starts_with("half_")) + fn = fn.substr(5); + if (!floatCores().contains(fn) && fn.size() > 1 && fn.back() == 'f' && + floatCores().contains(llvm::StringRef(fn).drop_back())) + fn.pop_back(); + if (!floatCores().contains(fn)) + return std::nullopt; + return MathCore{fn, ""}; +} + +} // namespace xlx +} // namespace cgeist diff --git a/tools/cgeist/Lib/XlxMathCore.h b/tools/cgeist/Lib/XlxMathCore.h new file mode 100644 index 000000000000..3dfbbc9980c3 --- /dev/null +++ b/tools/cgeist/Lib/XlxMathCore.h @@ -0,0 +1,58 @@ +//===- XlxMathCore.h - hls:: math library calls as cores ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// --xlx-headers: a call of an hls:: math function of the real Vitis HLS +// hls_math.h (hls::exp, hls::tanh, hls::sqrt, ... of ap_fixed, float, double +// or half) is one core of the Vitis math library, whose BRAM hls-est prices +// per instance from its cost table (hls-est MathCores.cpp, VITIS_NOTES N16, +// tools/hls-est-validate/math_costs.json) - the model the stand-in headers +// feed through their __hlsest_math_ markers. cgeist marks such a call +// with `hls.math_core = {function = "", type = ""}` (type only for +// the fixed-point overloads: `ap_fixed` / `ap_ufixed` of the +// argument; the float / double / half type is the call's own operand type) +// and keeps the callee as a function of its own (`hls.math_core` on the +// func.func: never inlined), so that the library's code and tables are not +// mistaken for the design's while the MLIR still computes the headers' +// values. hls-est drops the body of such a callee. +// +//===----------------------------------------------------------------------===// + +#ifndef CGEIST_XLXMATHCORE_H +#define CGEIST_XLXMATHCORE_H + +#include "llvm/ADT/StringRef.h" +#include +#include + +namespace clang { +class ASTContext; +class FunctionDecl; +} // namespace clang + +namespace cgeist { +namespace xlx { + +/// The attribute on the call and on the kept callee. +constexpr llvm::StringLiteral kMathCoreAttr = "hls.math_core"; + +struct MathCore { + std::string function; // exp, tanh, sqrt, ... (MathCores' names) + std::string type; // ap_fixed / ap_ufixed, or empty +}; + +/// If `fd` (the direct callee of a call) is a math function of the Vitis +/// hls_math.h (declared in namespace hls in a file named hls_math.h), named +/// like a core of the math library: the core. None otherwise, and always +/// without --xlx-headers. +std::optional mathCoreOf(const clang::FunctionDecl *fd, + clang::ASTContext &ctx); + +} // namespace xlx +} // namespace cgeist + +#endif // CGEIST_XLXMATHCORE_H diff --git a/tools/cgeist/Lib/XlxProxyScalarize.cc b/tools/cgeist/Lib/XlxProxyScalarize.cc new file mode 100644 index 000000000000..47932eceadb5 --- /dev/null +++ b/tools/cgeist/Lib/XlxProxyScalarize.cc @@ -0,0 +1,669 @@ +//===- XlxProxyScalarize.cc - Scalarise ap_range_ref-like proxies ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// The Vitis HLS headers return proxy objects from x.range(h, l), x[i], (a, b) +// and friends: ap_range_ref / ap_bit_ref / ap_concat_ref / af_range_ref / +// af_bit_ref, structs of a reference to the ap value plus bit indices +// (etc/ap_int_ref.h:295, etc/ap_fixed_ref.h). cgeist gives such a struct a +// `memref<1x!llvm.struct<(memref, i32, i32)>>` alloca whose fields are +// written and read through polygeist.memref2pointer / llvm.getelementptr / +// llvm.store / llvm.load, plus whole-struct copies (affine.load/store of the +// element). A memref of a struct holding a memref is not valid MLIR once +// printed, and hls-est cannot read it. +// +// After the proxies' always_inline member functions are inlined +// (--hls-inline-polygeist-ops), a proxy is filled, copied and read in its +// caller, possibly inside the scf / affine regions the inlined bodies become. +// This pass forwards the stored field values to the loads in program order +// over the structured regions (through whole-struct copies and +// llvm.extractvalue) and deletes the proxy allocas: +// - a region of an op that runs it at most once (scf.if, affine.if, +// scf.execute_region, scf.index_switch) starts from the state before the +// op; any other region (loops) starts with the fields it stores unknown; +// - after an op, the fields stored inside its regions are unknown; +// - a region with more than one block is not analysed. +// The same applies to any other single-element struct alloca, in particular +// the headers' type-punning unions (doubleToRawBits: written as double, read +// as uint64): a field read as another integer / float type of the same width +// becomes an arith.bitcast of the stored value. +// A proxy that cannot be resolved this way (passed to a call, its address +// stored, a dynamic field index, a field read while unknown, a whole-struct +// value that escapes) is left as it is, together with every proxy whose +// value flows into it; the others are still scalarised. +// A proxy whose address is stored into a field of another proxy (the +// ap_range_ref / ap_bit_ref operands of an ap_concat_ref, which holds +// references to them, etc/ap_int_ref.h) is left in the first round; once the +// outer proxy is scalarised, its field loads are the inner proxy's address, +// so the pass repeats until a round scalarises nothing. +// Under --xlx-headers the driver then rejects any memref of a struct that +// still holds a memref (reportUnscalarisedProxies): printed, it is not valid +// MLIR, and hls-est cannot read it. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/Arith/IR/Arith.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "mlir/IR/IRMapping.h" +#include "mlir/Interfaces/ControlFlowInterfaces.h" +#include "mlir/Pass/Pass.h" +#include "polygeist/Ops.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SetVector.h" + +using namespace mlir; + +namespace { + +/// How one op touches a proxy alloca. +struct Access { + enum Kind { FieldStore, FieldLoad, WholeStore, WholeLoad } kind; + memref::AllocaOp alloca; + unsigned field = 0; +}; + +struct ProxyInfo { + memref::AllocaOp alloca; + LLVM::LLVMStructType type; + llvm::SmallVector erase; ///< accesses and address ops +}; + +/// The field's own type, or an integer / float of the same width: a union +/// read through another member (the headers' doubleToRawBits, a +/// `union { double d; uint64_t i; }` written as double and read as +/// integer) is that value's bit pattern. +bool sameBits(Type a, Type b) { + if (a == b) + return true; + return a.isIntOrFloat() && b.isIntOrFloat() && + a.getIntOrFloatBitWidth() == b.getIntOrFloatBitWidth(); +} + +/// The struct element type of a single-element memref alloca, or null. +LLVM::LLVMStructType proxyType(memref::AllocaOp alloca) { + MemRefType mt = alloca.getType(); + if (mt.getRank() > 1 || (mt.getRank() == 1 && mt.getDimSize(0) != 1)) + return nullptr; + auto st = mt.getElementType().dyn_cast(); + if (!st || st.isOpaque()) + return nullptr; + return st; +} + +class ProxyAnalysis { +public: + llvm::DenseMap accesses; + llvm::SmallVector proxies; + + /// Classify every use of the alloca; false if one is not understood. + bool add(memref::AllocaOp alloca) { + ProxyInfo P; + P.alloca = alloca; + P.type = proxyType(alloca); + if (!P.type) + return false; + llvm::DenseMap mine; + llvm::SmallVector worklist{alloca.getResult()}; + while (!worklist.empty()) { + Value v = worklist.pop_back_val(); + for (Operation *user : v.getUsers()) { + if (auto cast = dyn_cast(user)) { + worklist.push_back(cast.getResult()); + P.erase.push_back(cast); + continue; + } + if (auto m2p = dyn_cast(user)) { + P.erase.push_back(m2p); + if (!addPointer(P, m2p.getResult(), 0, mine)) + return false; + continue; + } + Access A{Access::WholeLoad, alloca, 0}; + if (isa(user)) { + A.kind = Access::WholeLoad; + } else if (auto st = dyn_cast(user)) { + if (st.getValueToStore() == v) + return false; // the proxy's address escapes into memory + A.kind = Access::WholeStore; + } else if (auto st = dyn_cast(user)) { + if (st.getValueToStore() == v) + return false; + A.kind = Access::WholeStore; + } else { + return false; // a call or anything else: not a local proxy + } + mine[user] = A; + P.erase.push_back(user); + } + } + if (mine.empty()) + return false; + for (auto &kv : mine) + accesses[kv.first] = kv.second; + proxies.push_back(P); + return true; + } + +private: + bool addPointer(ProxyInfo &P, Value ptr, unsigned field, + llvm::DenseMap &mine) { + for (Operation *user : ptr.getUsers()) { + if (auto gep = dyn_cast(user)) { + if (field != 0 || !gep.getDynamicIndices().empty()) + return false; + auto raw = gep.getRawConstantIndices(); + std::optional elem = gep.getElemType(); + if (raw.size() != 2 || raw[0] != 0 || !elem || *elem != P.type || + raw[1] < 0 || (size_t)raw[1] >= P.type.getBody().size()) + return false; + P.erase.push_back(gep); + if (!addPointer(P, gep.getResult(), raw[1], mine)) + return false; + continue; + } + Access A{Access::FieldLoad, P.alloca, field}; + Type fieldTy = P.type.getBody()[field]; + if (auto ld = dyn_cast(user)) { + if (!sameBits(ld.getType(), fieldTy)) + return false; + A.kind = Access::FieldLoad; + } else if (auto st = dyn_cast(user)) { + if (st.getValue() == ptr || !sameBits(st.getValue().getType(), fieldTy)) + return false; + A.kind = Access::FieldStore; + } else { + return false; + } + mine[user] = A; + P.erase.push_back(user); + } + return true; + } +}; + +/// Program-order forwarding of the proxies' field values over the function's +/// structured regions. Records the proxies it cannot resolve in `failed`. +class Forwarder { +public: + using Fields = llvm::SmallVector; + using State = llvm::DenseMap; // alloca -> fields + + Forwarder(ProxyAnalysis &PA) : PA(PA) {} + + ProxyAnalysis &PA; + llvm::DenseMap replace; + llvm::SmallVector extracts; + llvm::DenseSet failed; // allocas + /// Whole-struct loads: their field values and the proxy they came from. + llvm::DenseMap> structValues; + + void run(func::FuncOp func) { + State state; + walkRegion(func.getBody(), state); + // Every use of a whole-struct load must have been resolved. + for (auto &kv : structValues) + for (Operation *user : kv.first.getUsers()) + if (!PA.accesses.count(user) && !llvm::is_contained(extracts, user)) + failed.insert(kv.second.second); + } + +private: + unsigned numFields(memref::AllocaOp a) { + return a.getType() + .getElementType() + .cast() + .getBody() + .size(); + } + + Fields &fieldsOf(State &state, memref::AllocaOp a) { + Fields &cur = state[a]; + if (cur.empty()) + cur.assign(numFields(a), Value()); + return cur; + } + + /// Every proxy accessed inside `region` fails. + void failAccessesIn(Region ®ion) { + region.walk([&](Operation *op) { + auto it = PA.accesses.find(op); + if (it != PA.accesses.end()) + failed.insert(it->second.alloca); + }); + } + + /// Mark the fields stored anywhere inside `op`'s regions unknown. + void forgetStoresIn(Operation *op, State &state) { + for (Region ®ion : op->getRegions()) + region.walk([&](Operation *inner) { + auto it = PA.accesses.find(inner); + if (it == PA.accesses.end()) + return; + const Access &A = it->second; + if (A.kind == Access::FieldStore) + fieldsOf(state, A.alloca)[A.field] = Value(); + else if (A.kind == Access::WholeStore) + fieldsOf(state, A.alloca).assign(numFields(A.alloca), Value()); + }); + } + + static bool runsAtMostOnce(Operation *op) { + return isa(op); + } + + void walkRegion(Region ®ion, State &state) { + if (region.empty()) + return; + if (!region.hasOneBlock()) { + walkBlocks(region, state); + return; + } + walkBlock(region.front(), state); + } + + /// The fields two paths agree on (a field the paths disagree on, or that + /// one of them does not know, is unknown). + static State merge(const State &a, const State &b) { + State out; + for (auto &kv : a) { + auto it = b.find(kv.first); + if (it == b.end()) + continue; + Fields f(kv.second.size(), Value()); + for (size_t i = 0; i < f.size() && i < it->second.size(); ++i) + if (kv.second[i] == it->second[i]) + f[i] = kv.second[i]; + out[kv.first] = f; + } + return out; + } + + /// A region of several blocks (a `switch` is an scf.execute_region whose + /// blocks are its cases, CGStmt.cc VisitSwitchStmt): when every branch + /// goes to a later block (no cycle), the blocks are walked in order, each + /// starting from what its predecessors agree on; a proxy filled and read + /// in one case is resolved there. With a branch back to an earlier block + /// every block but the entry starts with the fields unknown. + void walkBlocks(Region ®ion, State &state) { + llvm::DenseMap order; + for (Block &b : region) + order[&b] = order.size(); + bool forward = true; + for (Block &b : region) + for (Block *succ : b.getSuccessors()) + forward &= order.lookup(succ) > order.lookup(&b); + llvm::DenseMap exitState; + for (Block &b : region) { + State in; + if (&b == ®ion.front()) { + in = state; + } else if (forward) { + bool first = true; + for (Block *pred : b.getPredecessors()) { + auto it = exitState.find(pred); + if (it == exitState.end()) { + in.clear(); + first = false; + break; + } + in = first ? it->second : merge(in, it->second); + first = false; + } + } + walkBlock(b, in); + exitState[&b] = std::move(in); + } + } + + void walkBlock(Block &block, State &state) { + for (Operation &op : block) { + if (op.getNumRegions() != 0) { + bool once = runsAtMostOnce(&op); + for (Region ®ion : op.getRegions()) { + State inner = state; + if (!once) + forgetStoresIn(&op, inner); + walkRegion(region, inner); + } + forgetStoresIn(&op, state); + continue; + } + visit(op, state); + } + } + + void visit(Operation &op, State &state) { + // llvm.extractvalue of a whole-struct load. + if (auto ex = dyn_cast(&op)) { + auto it = structValues.find(ex.getContainer()); + if (it == structValues.end()) + return; + const Fields &fs = it->second.first; + int64_t k = ex.getPosition().size() == 1 ? ex.getPosition()[0] : -1; + if (k < 0 || (size_t)k >= fs.size() || !fs[k] || + fs[k].getType() != ex.getType()) { + failed.insert(it->second.second); + return; + } + replace[ex.getResult()] = fs[k]; + extracts.push_back(ex); + return; + } + auto ai = PA.accesses.find(&op); + if (ai == PA.accesses.end()) + return; + const Access &A = ai->second; + Fields &cur = fieldsOf(state, A.alloca); + switch (A.kind) { + case Access::FieldStore: + cur[A.field] = cast(op).getValue(); + break; + case Access::FieldLoad: { + Value v = cur[A.field]; + if (!v) { + failed.insert(A.alloca); // read while unknown + break; + } + auto r = replace.find(v); + // Read the forwarded value before inserting: operator[] may grow the + // map and free the bucket `r` points into. + Value forwarded = r == replace.end() ? v : r->second; + replace[op.getResult(0)] = forwarded; + break; + } + case Access::WholeLoad: + structValues[op.getResult(0)] = {cur, A.alloca}; + break; + case Access::WholeStore: { + Value v = isa(op) + ? cast(op).getValueToStore() + : cast(op).getValueToStore(); + auto it = structValues.find(v); + if (it != structValues.end()) { + cur = it->second.first; + } else if (v.getDefiningOp()) { + cur.assign(cur.size(), Value()); + } else { + failed.insert(A.alloca); // a struct value from elsewhere + cur.assign(cur.size(), Value()); + } + break; + } + } + } +}; + +struct XlxProxyScalarizePass + : public PassWrapper> { + MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(XlxProxyScalarizePass) + StringRef getArgument() const final { return "xlx-proxy-scalarize"; } + StringRef getDescription() const final { + return "Scalarise the Vitis HLS headers' range / bit / concat proxies"; + } + + void runOnOperation() override { + func::FuncOp func = getOperation(); + splitProxyBlockArguments(func); + // Each round erases at least one alloca, so this terminates. + while (scalarizeOnce(func)) { + } + } + + /// A block that receives proxies as block arguments: the canonicalizer + /// merges the identical cases of a `switch` (`case 0: d.range(7, 0) = a; + /// break; default: d.range(7, 0) = b;`, vision xf_threshold.hpp) into one + /// block whose arguments are each case's proxy. The forwarding cannot see + /// a proxy through a block argument, so the block is copied once per + /// incoming edge with the edge's values in place of the arguments (the + /// blocks before the merge). Only blocks whose every predecessor is a + /// branch op of the same region are split; at most kMaxCopies copies. + static bool isProxyArgument(BlockArgument a); + + void splitProxyBlockArguments(func::FuncOp func) { + constexpr unsigned kMaxCopies = 64; + SmallVector work; + func.walk([&](Block *b) { + if (!b->isEntryBlock() && + llvm::any_of(b->getArguments(), isProxyArgument)) + work.push_back(b); + }); + for (Block *b : work) { + // The incoming edges: (terminator, successor index). + SmallVector> edges; + bool ok = true; + for (auto it = b->pred_begin(), e = b->pred_end(); it != e; ++it) { + Operation *term = (*it)->getTerminator(); + auto br = dyn_cast(term); + if (!br) { + ok = false; + break; + } + edges.push_back({term, it.getSuccessorIndex()}); + } + if (!ok || edges.empty() || edges.size() > kMaxCopies) + continue; + for (auto [term, idx] : edges) { + auto br = cast(term); + SuccessorOperands ops = br.getSuccessorOperands(idx); + if (ops.getProducedOperandCount() != 0 || + ops.size() != b->getNumArguments()) { + ok = false; + break; + } + } + // A value of the block used in another block would need a merge. + for (Operation &op : *b) + for (Value r : op.getResults()) + for (Operation *u : r.getUsers()) + if (b->findAncestorOpInBlock(*u) == nullptr) + ok = false; + if (!ok) + continue; + Region *region = b->getParent(); + for (auto [term, idx] : edges) { + auto br = cast(term); + SuccessorOperands ops = br.getSuccessorOperands(idx); + IRMapping map; + for (auto [arg, v] : llvm::zip(b->getArguments(), + ops.getForwardedOperands())) + map.map(arg, v); + Block *copy = new Block(); + region->getBlocks().insertAfter(Region::iterator(b), copy); + for (Operation &op : *b) + copy->push_back(op.clone(map)); + ops.erase(0, ops.size()); + term->setSuccessor(copy, idx); + } + // Every edge goes to a copy now. + b->dropAllDefinedValueUses(); + b->erase(); + } + } + + /// One round over the function's proxy allocas. True if at least one was + /// scalarised and erased. + bool scalarizeOnce(func::FuncOp func) { + llvm::SetVector candidates; + func.walk([&](memref::AllocaOp a) { + if (proxyType(a)) + candidates.insert(a); + }); + // Drop the proxies that cannot be resolved, and with them every proxy + // whose whole-struct value flows into one of them, until the rest + // resolves. + while (!candidates.empty()) { + ProxyAnalysis PA; + llvm::SmallVector rejected; + for (Operation *a : candidates) + if (!PA.add(cast(a))) + rejected.push_back(a); + if (!rejected.empty()) { + for (Operation *a : rejected) + candidates.remove(a); + continue; + } + Forwarder F(PA); + F.run(func); + if (!F.failed.empty()) { + for (Operation *a : F.failed) + candidates.remove(a); + continue; + } + return apply(PA, F); + } + return false; + } + + /// Rewrite the forwarded loads and erase the proxies. True if at least one + /// proxy alloca was erased. + bool apply(ProxyAnalysis &PA, Forwarder &F) { + // Resolve chains (a forwarded value that is itself replaced). + for (auto &kv : F.replace) { + Value v = kv.second; + for (auto it = F.replace.find(v); it != F.replace.end(); + it = F.replace.find(v)) + v = it->second; + if (v.getType() != kv.first.getType()) { + // A union member read as another type of the same width (sameBits). + Operation *at = kv.first.getDefiningOp(); + OpBuilder b(at); + v = b.create(at->getLoc(), kv.first.getType(), v); + } + kv.first.replaceAllUsesWith(v); + } + for (Operation *ex : F.extracts) + ex->erase(); + // Erase the accesses, then the address ops, then the allocas (users + // first: the erase lists are in use-before-def discovery order, so walk + // them until nothing is left). + llvm::SetVector dead; + for (ProxyInfo &P : PA.proxies) + for (Operation *op : P.erase) + dead.insert(op); + while (!dead.empty()) { + llvm::SmallVector ready; + for (Operation *op : dead) + if (op->use_empty()) + ready.push_back(op); + if (ready.empty()) + break; + for (Operation *op : ready) { + dead.remove(op); + op->erase(); + } + } + bool erased = false; + for (ProxyInfo &P : PA.proxies) + if (P.alloca->use_empty()) { + P.alloca->erase(); + erased = true; + } + return erased; + } +}; + +/// A memref whose element type is (or contains) an LLVM struct or array that +/// holds a memref: an unscalarised proxy. +bool holdsMemref(Type t) { + if (t.isa()) + return true; + if (auto st = t.dyn_cast()) + return !st.isOpaque() && llvm::any_of(st.getBody(), holdsMemref); + if (auto at = t.dyn_cast()) + return holdsMemref(at.getElementType()); + return false; +} + +bool isProxyMemref(Type t) { + auto mt = t.dyn_cast(); + if (!mt) + return false; + Type e = mt.getElementType(); + return e.isa() && holdsMemref(e); +} + +/// A block argument holding a proxy (a memref of a struct that holds a +/// memref, which only the headers' proxies are). +bool XlxProxyScalarizePass::isProxyArgument(BlockArgument a) { + return isProxyMemref(a.getType()); +} + +} // namespace + +namespace cgeist { +std::unique_ptr createXlxProxyScalarizePass() { + return std::make_unique(); +} +} // namespace cgeist + +namespace cgeist { +/// --xlx-headers: an error at every op that still defines or takes a memref of +/// a struct holding a memref (a proxy the pass could not scalarise, e.g. one +/// passed to a call). Such MLIR does not parse back ("invalid memref element +/// type"), so cgeist fails instead of printing it. +mlir::LogicalResult reportUnscalarisedProxies(mlir::ModuleOp module) { + bool found = false; + module.walk([&](Operation *op) { + bool bad = llvm::any_of(op->getResultTypes(), isProxyMemref); + for (Region ®ion : op->getRegions()) + for (Block &block : region) + bad |= llvm::any_of(block.getArgumentTypes(), isProxyMemref); + if (auto f = dyn_cast(op)) + bad |= llvm::any_of(f.getFunctionType().getInputs(), isProxyMemref) || + llvm::any_of(f.getFunctionType().getResults(), isProxyMemref); + if (auto g = dyn_cast(op)) + bad |= isProxyMemref(g.getType()); + if (!bad) + return; + found = true; + op->emitError("a Vitis HLS proxy object (ap_range_ref, ap_bit_ref, " + "ap_concat_ref, ...) could not be scalarised: a memref of a " + "struct holding a memref is not valid MLIR"); + }); + return mlir::failure(found); +} + +/// --xlx-headers: drop every linkonce_odr function (an inline function of the +/// headers) that nothing in the module references any more, as a C++ +/// compiler drops an unused inline function. Such a function can still hold +/// a proxy struct, which is only scalarised once inlined into a caller, and +/// whose type does not survive printing. +void dropUnusedLinkonceODR(mlir::ModuleOp module) { + bool changed = true; + while (changed) { + changed = false; + // Every symbol referenced anywhere in the module, collected in one walk + // (asking symbolKnownUseEmpty per function walks the module once per + // function: minutes on the fixed-point math headers). + llvm::DenseSet referenced; + auto uses = SymbolTable::getSymbolUses(&module.getBodyRegion()); + if (!uses) + return; // unknown symbol uses: keep everything + for (const SymbolTable::SymbolUse &use : *uses) + referenced.insert(use.getSymbolRef().getRootReference()); + llvm::SmallVector dead; + for (func::FuncOp f : module.getOps()) { + auto lnk = f->getAttrOfType("llvm.linkage"); + if (!lnk || lnk.getLinkage() != LLVM::Linkage::LinkonceODR) + continue; + if (!referenced.contains(f.getSymNameAttr())) + dead.push_back(f); + } + for (func::FuncOp f : dead) { + f.erase(); + changed = true; + } + } +} +} // namespace cgeist diff --git a/tools/cgeist/Lib/XlxStringBits.cc b/tools/cgeist/Lib/XlxStringBits.cc new file mode 100644 index 000000000000..8ddbf02bbf3f --- /dev/null +++ b/tools/cgeist/Lib/XlxStringBits.cc @@ -0,0 +1,667 @@ +//===- XlxStringBits.cc - Fold ap_int / ap_fixed string constructors ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Under __SYNTHESIS__ the Vitis HLS headers construct ap_int / ap_fixed values +// from C strings through +// +// typeof(Base::V) t; +// _ssdm_string2bits((void*)(&t), (const char*)(s), radix, I, S, Q, O, N, C99); +// Base::V = t; +// +// (etc/ap_fixed_base.h:458-471: I = _AP_I and the object's Q / O / N modes; +// etc/ap_int_base.h:398-410: I = _AP_W, AP_TRN, AP_WRAP, 0). The header notes +// that "_ssdm_string2bits only takes const string and const radix" and that +// "XFORM will do compile time processing of the string": the closed Vitis +// front end folds it. The fixed-point math headers rely on it for their +// lookup tables (etc/hls_exp_apfixed.h:225 `const static ap_ufixed<25,11> +// exp_x_msb_1_table[32] = {"0x1.0000p0", ...}` and others). Left as a call, +// every element is constructed at run time behind a static-init guard and +// cgeist spends minutes on a 256-entry table (W11 experiment: 493 s). +// +// This file evaluates such a construction at compile time. The value follows +// the Vitis C simulation of the same constructor (Vitis/include/etc/ +// ap_fixed_base.h:175-262 fromString, etc/ap_private.h:372-500 parseString; +// read, not copied): the string's number (sign; 0x / 0b / 0o prefix, else the +// given radix; a decimal `e` exponent, or a binary `p` exponent for the +// power-of-two radixes) converted to the target format with its quantisation +// and overflow modes (etc/ap_fixed_base.h:302-381 overflow_adjust / +// quantization_adjust). The C simulation rounds from a (W - I + 4)-bit +// fraction with a sticky bit; this evaluates the exact value, which can only +// differ for a decimal string within 2^-(W-I+4) of a rounding boundary +// (unconfirmed against Vitis: the XFORM fold is closed). +// +//===----------------------------------------------------------------------===// + +#include "XlxStringBits.h" + +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/DeclTemplate.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringSwitch.h" + +using namespace clang; +using llvm::APInt; + +namespace cgeist { +namespace xlx { + +namespace { + +/// A parsed number: (-1)^neg * mant * radix^-fracDigits * base^exp, with +/// base 10 for radix 10 and 2 otherwise (ap_private.h:372-500: a radix-10 +/// string shifts its decimal point by the `e` exponent, the others are +/// rewritten to binary and shift the binary point by the `p` exponent). +struct ParsedNumber { + bool neg = false; + unsigned radix = 10; + std::string digits; ///< mantissa digits without the point + int64_t fracDigits = 0; + int64_t exp = 0; +}; + +int digitValue(char c) { + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'z') + return c - 'a' + 10; + if (c >= 'A' && c <= 'Z') + return c - 'A' + 10; + return -1; +} + +std::optional parseExponent(llvm::StringRef s) { + if (s.empty()) + return std::nullopt; + bool neg = false; + if (s[0] == '+' || s[0] == '-') { + neg = s[0] == '-'; + s = s.drop_front(); + } + if (s.empty() || s.size() > 9) + return std::nullopt; + int64_t v = 0; + for (char c : s) { + if (c < '0' || c > '9') + return std::nullopt; + v = v * 10 + (c - '0'); + } + return neg ? -v : v; +} + +std::optional parseNumber(llvm::StringRef s, unsigned radix) { + // parseString trims spaces only. + while (!s.empty() && s.front() == ' ') + s = s.drop_front(); + while (!s.empty() && s.back() == ' ') + s = s.drop_back(); + if (s.empty()) + return std::nullopt; + ParsedNumber n; + if (s[0] == '-' || s[0] == '+') { + n.neg = s[0] == '-'; + s = s.drop_front(); + } + if (radix == 0) + radix = 10; + if (s.size() >= 2 && s[0] == '0') { + char p = s[1]; + if (p == 'x' || p == 'X') + radix = 16; + else if (p == 'b' || p == 'B') + radix = 2; + else if (p == 'o' || p == 'O') + radix = 8; + if (p == 'x' || p == 'X' || p == 'b' || p == 'B' || p == 'o' || p == 'O') + s = s.drop_front(2); + } + if (radix != 2 && radix != 8 && radix != 10 && radix != 16) + return std::nullopt; + n.radix = radix; + size_t expPos = radix == 10 ? s.find_first_of("eE") : s.find_first_of("pP"); + llvm::StringRef mant = s.substr(0, expPos); + if (expPos != llvm::StringRef::npos) { + auto e = parseExponent(s.substr(expPos + 1)); + if (!e) + return std::nullopt; + n.exp = *e; + } + bool point = false; + for (char c : mant) { + if (c == '.') { + if (point) + return std::nullopt; + point = true; + continue; + } + int d = digitValue(c); + if (d < 0 || d >= (int)radix) + return std::nullopt; + n.digits.push_back(c); + if (point) + n.fracDigits++; + } + if (n.digits.empty()) + return std::nullopt; + return n; +} + +/// floor(|value| * 2^F) and the two rounding bits of the discarded fraction +/// f: qb = (f >= 1/2), r = the bits below qb are not all zero (the +/// quantization_adjust inputs, ap_fixed_base.h:366-381). +struct Scaled { + APInt q; ///< unsigned magnitude + bool qb = false; + bool r = false; +}; + +constexpr unsigned kMaxBits = 1u << 16; + +std::optional scaleMagnitude(const ParsedNumber &n, int64_t F) { + unsigned bitsPerDigit = n.radix == 16 ? 4 : n.radix == 8 ? 3 : n.radix == 2 + ? 1 + : 4; + uint64_t mantBits = n.digits.size() * (uint64_t)bitsPerDigit + 2; + if (mantBits > kMaxBits) + return std::nullopt; + APInt mant(mantBits, 0); + for (char c : n.digits) { + mant *= APInt(mantBits, n.radix); + mant += APInt(mantBits, digitValue(c)); + } + Scaled out; + if (n.radix != 10) { + // value = mant * 2^(exp - bitsPerDigit * fracDigits); scaled by 2^F. + int64_t t = n.exp - (int64_t)bitsPerDigit * n.fracDigits + F; + if (t >= 0) { + if ((uint64_t)t + mantBits > kMaxBits) + return std::nullopt; + out.q = mant.zext(mantBits + t).shl(t); + return out; + } + uint64_t s = -t; + if (s > mantBits) { + // Every mantissa bit lies below the qb position. + out.q = APInt(mantBits, 0); + out.qb = false; + out.r = !mant.isZero(); + return out; + } + out.q = mant.lshr(s); + out.qb = mant[s - 1]; + out.r = s >= 2 && !mant.trunc(s - 1).isZero(); + return out; + } + // value = mant * 10^d, d = exp - fracDigits; scaled by 2^F. + int64_t d = n.exp - n.fracDigits; + uint64_t width = mantBits + (uint64_t)std::abs(F) + 4 * (uint64_t)std::abs(d) + 4; + if (width > kMaxBits) + return std::nullopt; + APInt num = mant.zext(width), den(width, 1); + if (F > 0) + num = num.shl(F); + else if (F < 0) + den = den.shl(-F); + APInt ten(width, 10); + for (int64_t i = 0; i < std::abs(d); ++i) { + if (d > 0) + num *= ten; + else + den *= ten; + } + APInt rem(width, 0); + APInt::udivrem(num, den, out.q, rem); + APInt twice = rem.shl(1); + out.qb = twice.uge(den); + out.r = out.qb ? twice.ugt(den) : !rem.isZero(); + return out; +} + +bool knownQ(llvm::StringRef q) { + return llvm::StringSwitch(q) + .Cases("AP_RND", "AP_RND_ZERO", "AP_RND_MIN_INF", "AP_RND_INF", true) + .Cases("AP_RND_CONV", "AP_TRN", "AP_TRN_ZERO", true) + .Default(false); +} + +bool knownO(llvm::StringRef o) { + return llvm::StringSwitch(o) + .Cases("AP_SAT", "AP_SAT_ZERO", "AP_SAT_SYM", "AP_WRAP", "AP_WRAP_SM", + true) + .Default(false); +} + +/// Set bits [lo, hi] of v to `ones`. +void setRange(APInt &v, unsigned lo, unsigned hi, bool ones) { + for (unsigned b = lo; b <= hi && b < v.getBitWidth(); ++b) { + if (ones) + v.setBit(b); + else + v.clearBit(b); + } +} + +} // namespace + +std::optional stringToFixedBits(llvm::StringRef str, unsigned radix, + const FixedFormat &fmt) { + if (fmt.W == 0 || fmt.W > kMaxBits || !knownQ(fmt.Q) || !knownO(fmt.O) || + fmt.N < 0 || fmt.N > (int64_t)fmt.W) + return std::nullopt; + auto n = parseNumber(str, radix); + if (!n) + return std::nullopt; + int64_t F = (int64_t)fmt.W - fmt.I; + if (std::abs(F) > (int64_t)kMaxBits) + return std::nullopt; + auto sc = scaleMagnitude(*n, F); + if (!sc) + return std::nullopt; + + // Signed floor of the value, and the rounding bits of its fraction. + unsigned width = std::max(sc->q.getBitWidth(), fmt.W) + 3; + APInt q = sc->q.zext(width); + bool qb = sc->qb, r = sc->r; + bool nonzero = !q.isZero() || qb || r; + bool isneg = n->neg && nonzero; + if (isneg) { + bool frac = qb || r; + q.negate(); + if (frac) { + q -= 1; + // fraction 1 - f: >= 1/2 iff f <= 1/2; the bits below are nonzero + // unless 1 - f is exactly 1/2. + bool nqb = !(qb && r); + bool nr = nqb ? !qb : true; + qb = nqb; + r = nr; + } + } + + // Quantisation (quantization_adjust): add qb under the mode's condition. + bool inc = false; + if (fmt.Q == "AP_RND") + inc = qb; + else if (fmt.Q == "AP_RND_ZERO") + inc = qb && (isneg || r); + else if (fmt.Q == "AP_RND_MIN_INF") + inc = qb && r; + else if (fmt.Q == "AP_RND_INF") + inc = qb && (!isneg || r); + else if (fmt.Q == "AP_RND_CONV") + inc = qb && (q[0] || r); + else if (fmt.Q == "AP_TRN_ZERO") + inc = isneg && (qb || r); + if (inc) + q += 1; + + // Overflow (overflow_adjust): the target's range for the W-bit pattern. + unsigned W = fmt.W; + APInt maxV = fmt.S ? APInt::getSignedMaxValue(W).sext(width) + : APInt::getMaxValue(W).zext(width); + APInt minV = fmt.S ? APInt::getSignedMinValue(W).sext(width) + : APInt(width, 0); + bool overflow = q.sgt(maxV); + bool underflow = q.slt(minV); + APInt v = q.trunc(W); + if (!overflow && !underflow) + return v; + bool sign = isneg; // neg_src + if (fmt.O == "AP_WRAP") { + if (fmt.N == 0) + return v; + if (fmt.S) { + setRange(v, W - 1, W - 1, sign); + if (fmt.N > 1) + setRange(v, W - fmt.N, W - 2, !sign); + } else { + setRange(v, W - fmt.N, W - 1, true); + } + return v; + } + if (fmt.O == "AP_SAT_ZERO") + return APInt(W, 0); + if (fmt.O == "AP_WRAP_SM" && fmt.S) { + bool Ro = v[W - 1]; + bool lD = q[W]; // the last deleted bit + if (fmt.N == 0) { + if (lD != Ro) { + v.flipAllBits(); + setRange(v, W - 1, W - 1, lD); + } + } else { + if (fmt.N == 1 && sign != Ro) { + v.flipAllBits(); + } else if (fmt.N > 1) { + bool lNo = v[W - fmt.N]; + if (lNo == sign) + v.flipAllBits(); + setRange(v, W - fmt.N, W - 2, !sign); + } + setRange(v, W - 1, W - 1, sign); + } + return v; + } + // AP_SAT, AP_SAT_SYM (and AP_WRAP_SM of an unsigned type). + if (fmt.S) { + if (overflow) + return APInt::getSignedMaxValue(W); + APInt m = APInt::getSignedMinValue(W); + if (fmt.O == "AP_SAT_SYM") + m.setBit(0); + return m; + } + return overflow ? APInt::getMaxValue(W) : APInt(W, 0); +} + +namespace { + +/// Looks through temporaries, elidable copies and no-op / constructor +/// conversions to the constructor call that makes the value. +const CXXConstructExpr *stripToConstruct(const Expr *E) { + for (unsigned guard = 0; E && guard < 32; ++guard) { + E = E->IgnoreParens(); + if (auto *X = dyn_cast(E)) { + E = X->getSubExpr(); + continue; + } + if (auto *X = dyn_cast(E)) { + E = X->getSubExpr(); + continue; + } + if (auto *X = dyn_cast(E)) { + E = X->getSubExpr(); + continue; + } + if (auto *X = dyn_cast(E)) { + if (X->getCastKind() == CK_NoOp || + X->getCastKind() == CK_ConstructorConversion) { + E = X->getSubExpr(); + continue; + } + return nullptr; + } + if (auto *CE = dyn_cast(E)) { + const CXXConstructorDecl *C = CE->getConstructor(); + if (CE->getNumArgs() == 1 && + (CE->isElidable() || + ((C->isCopyConstructor() || C->isMoveConstructor()) && + C->isTrivial()))) { + E = CE->getArg(0); + continue; + } + return CE; + } + return nullptr; + } + return nullptr; +} + +/// An argument of a call inside the constructor `fn` (called with `args`): +/// a reference to one of fn's parameters becomes the caller's argument. +const Expr *mapArg(const Expr *e, const FunctionDecl *fn, + llvm::ArrayRef args) { + if (auto *DRE = dyn_cast(e->IgnoreParenCasts())) + if (auto *P = dyn_cast(DRE->getDecl())) + if (auto *Owner = dyn_cast(P->getDeclContext())) + if (Owner->getCanonicalDecl() == fn->getCanonicalDecl()) { + unsigned i = P->getFunctionScopeIndex(); + return i < args.size() ? args[i] : nullptr; + } + return e; +} + +std::optional evalInt(const Expr *e, ASTContext &Ctx) { + if (!e || e->isValueDependent()) + return std::nullopt; + Expr::EvalResult R; + if (!e->EvaluateAsInt(R, Ctx)) + return std::nullopt; + return R.Val.getInt().getExtValue(); +} + +/// The enumerator name of an ap_q_mode / ap_o_mode argument. +std::optional enumName(const Expr *e, ASTContext &Ctx) { + if (!e) + return std::nullopt; + auto v = evalInt(e, Ctx); + if (!v) + return std::nullopt; + const Expr *x = e->IgnoreParenImpCasts(); + const EnumType *ET = x->getType()->getAs(); + if (!ET) + if (auto *S = dyn_cast(x)) + ET = S->getReplacement()->IgnoreParenImpCasts()->getType() + ->getAs(); + if (!ET) + return std::nullopt; + for (const EnumConstantDecl *EC : ET->getDecl()->enumerators()) + if (EC->getInitVal().getExtValue() == *v) + return EC->getName(); + return std::nullopt; +} + +const CallExpr *findCall(const Stmt *S, llvm::StringRef name) { + if (!S) + return nullptr; + if (auto *CE = dyn_cast(S)) + if (const FunctionDecl *FD = CE->getDirectCallee()) + if (FD->getIdentifier() && FD->getName() == name) + return CE; + for (const Stmt *C : S->children()) + if (const CallExpr *R = findCall(C, name)) + return R; + return nullptr; +} + +std::optional foldCtor(const CXXConstructorDecl *ctor, + llvm::ArrayRef args, + ASTContext &Ctx, unsigned depth) { + if (!ctor || depth > 4) + return std::nullopt; + const FunctionDecl *defFn = nullptr; + if (!ctor->hasBody(defFn) || !defFn) + return std::nullopt; + auto *def = dyn_cast(defFn); + if (!def) + return std::nullopt; + + // ap_fixed(const char* s) : Base(s) {} - follow the base / delegating + // initialiser that receives the string. + for (const CXXCtorInitializer *init : def->inits()) { + if (!init->isBaseInitializer() && !init->isDelegatingInitializer()) + continue; + const CXXConstructExpr *inner = stripToConstruct(init->getInit()); + if (!inner) + continue; + llvm::SmallVector innerArgs; + bool passesString = false; + for (const Expr *a : inner->arguments()) { + const Expr *m = mapArg(a, def, args); + if (!m) + return std::nullopt; + if (m != a) + passesString |= isa(m->IgnoreParenImpCasts()); + innerArgs.push_back(m); + } + if (passesString) + return foldCtor(inner->getConstructor(), innerArgs, Ctx, depth + 1); + } + + const CallExpr *call = findCall(def->getBody(), "_ssdm_string2bits"); + if (!call || call->getNumArgs() < 8) + return std::nullopt; + // Destination: (void*)(&t) with t an integer of the object's width. + auto *addr = dyn_cast(call->getArg(0)->IgnoreParenCasts()); + if (!addr || addr->getOpcode() != UO_AddrOf) + return std::nullopt; + QualType dstTy = addr->getSubExpr()->getType(); + if (!dstTy->isIntegerType() || dstTy->isBooleanType()) + return std::nullopt; + unsigned W = Ctx.getIntWidth(dstTy); + + const Expr *strArg = mapArg(call->getArg(1), def, args); + if (!strArg) + return std::nullopt; + auto *lit = dyn_cast(strArg->IgnoreParenCasts()); + if (!lit || !lit->isOrdinary()) + return std::nullopt; + auto radix = evalInt(mapArg(call->getArg(2), def, args), Ctx); + auto I = evalInt(mapArg(call->getArg(3), def, args), Ctx); + auto S = evalInt(mapArg(call->getArg(4), def, args), Ctx); + auto Q = enumName(mapArg(call->getArg(5), def, args), Ctx); + auto O = enumName(mapArg(call->getArg(6), def, args), Ctx); + auto N = evalInt(mapArg(call->getArg(7), def, args), Ctx); + if (!radix || !I || !S || !Q || !O || !N || *radix < 0) + return std::nullopt; + FixedFormat fmt; + fmt.W = W; + fmt.I = *I; + fmt.S = *S != 0; + fmt.Q = *Q; + fmt.O = *O; + fmt.N = *N; + return stringToFixedBits(lit->getString(), (unsigned)*radix, fmt); +} + +/// The enumerator name of an enum-typed integral template argument. +std::optional enumArgName(const TemplateArgument &a) { + if (a.getKind() != TemplateArgument::Integral) + return std::nullopt; + const EnumType *ET = a.getIntegralType()->getAs(); + if (!ET) + return std::nullopt; + for (const EnumConstantDecl *EC : ET->getDecl()->enumerators()) + if (llvm::APSInt::isSameValue(EC->getInitVal(), a.getAsIntegral())) + return EC->getName(); + return std::nullopt; +} + +std::optional intArg(const TemplateArgument &a) { + if (a.getKind() != TemplateArgument::Integral) + return std::nullopt; + return a.getAsIntegral().getExtValue(); +} + +/// The format of an ap_int_base / ap_fixed_base class or of a class derived +/// from one through single bases (ap_uint, ap_fixed). +/// `fixed` says which of the two it is. +std::optional apFormat(const CXXRecordDecl *RD, bool &fixed) { + for (unsigned guard = 0; RD && guard < 8; ++guard) { + if (auto *spec = dyn_cast(RD)) { + const TemplateArgumentList &args = spec->getTemplateArgs(); + if (spec->getName() == "ap_int_base" && args.size() == 2) { + auto W = intArg(args[0]), S = intArg(args[1]); + if (!W || !S || *W <= 0) + return std::nullopt; + FixedFormat f; + f.W = (unsigned)*W; + f.I = *W; + f.S = *S != 0; + fixed = false; + return f; + } + if (spec->getName() == "ap_fixed_base" && args.size() == 6) { + auto W = intArg(args[0]), I = intArg(args[1]), S = intArg(args[2]), + N = intArg(args[5]); + auto Q = enumArgName(args[3]), O = enumArgName(args[4]); + if (!W || !I || !S || !N || !Q || !O || *W <= 0) + return std::nullopt; + FixedFormat f; + f.W = (unsigned)*W; + f.I = *I; + f.S = *S != 0; + f.Q = *Q; + f.O = *O; + f.N = *N; + fixed = true; + return f; + } + } + if (RD->getNumBases() != 1) + return std::nullopt; + RD = RD->bases_begin()->getType()->getAsCXXRecordDecl(); + } + return std::nullopt; +} + +} // namespace + +std::optional foldDefaultConstruct(const Expr *E, ASTContext &Ctx) { + const CXXConstructExpr *CE = stripToConstruct(E); + if (!CE || CE->getNumArgs() != 0 || + !CE->getConstructor()->isDefaultConstructor()) + return std::nullopt; + bool fixed = false; + auto fmt = apFormat(CE->getConstructor()->getParent(), fixed); + if (!fmt) + return std::nullopt; + return APInt(fmt->W, 0); +} + +std::optional foldNumericConstruct(const Expr *E, ASTContext &Ctx) { + const CXXConstructExpr *CE = stripToConstruct(E); + if (!CE || CE->getNumArgs() != 1) + return std::nullopt; + const Expr *arg = CE->getArg(0); + QualType argTy = arg->IgnoreParenImpCasts()->getType(); + if (arg->isValueDependent() || + !(argTy->isIntegerType() || argTy->isRealFloatingType())) + return std::nullopt; + bool fixed = false; + auto fmt = apFormat(CE->getConstructor()->getParent(), fixed); + // N saturation bits and AP_WRAP_SM are rare in tables and not checked + // against the numeric constructors: leave them to the caller's fallback. + if (!fmt || fmt->N != 0 || fmt->O == "AP_WRAP_SM") + return std::nullopt; + // The constant at the argument's own type (before the implicit conversion + // to the constructor's parameter type, which the headers' overloads avoid + // by having one constructor per C type). + const Expr *value = arg->IgnoreParenImpCasts(); + Expr::EvalResult R; + if (!value->EvaluateAsRValue(R, Ctx) || R.HasSideEffects) + return std::nullopt; + // The exact value as a string in the form stringToFixedBits reads: decimal + // for an integer, the exact hexadecimal significand and binary exponent + // for a floating-point value. + llvm::SmallString<64> text; + if (R.Val.isInt()) { + R.Val.getInt().toString(text, 10); + } else if (R.Val.isFloat() && fixed) { + const llvm::APFloat &f = R.Val.getFloat(); + if (!f.isFinite()) + return std::nullopt; + if (f.isZero()) + return APInt(fmt->W, 0); + char buf[128]; + unsigned n = f.convertToHexString(buf, 0, /*UpperCase*/ false, + llvm::APFloat::rmNearestTiesToEven); + text.assign(buf, buf + n); + } else { + return std::nullopt; + } + return stringToFixedBits(text, 10, *fmt); +} + +std::optional foldStringConstruct(const Expr *E, ASTContext &Ctx) { + const CXXConstructExpr *CE = stripToConstruct(E); + if (!CE || CE->getNumArgs() == 0) + return std::nullopt; + if (!isa(CE->getArg(0)->IgnoreParenImpCasts())) + return std::nullopt; + llvm::SmallVector args(CE->arguments()); + return foldCtor(CE->getConstructor(), args, Ctx, 0); +} + +} // namespace xlx +} // namespace cgeist diff --git a/tools/cgeist/Lib/XlxStringBits.h b/tools/cgeist/Lib/XlxStringBits.h new file mode 100644 index 000000000000..b27ac4343c25 --- /dev/null +++ b/tools/cgeist/Lib/XlxStringBits.h @@ -0,0 +1,84 @@ +//===- XlxStringBits.h - Fold ap_int / ap_fixed string constructors -------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// --xlx-headers: compile-time values of the Vitis HLS headers' string +// constructors (`ap_ufixed<25,11> t[] = {"0x1.a614p0", ...}`, the lookup +// tables of the fixed-point math functions). Under __SYNTHESIS__ these call +// `_ssdm_string2bits(&t, s, radix, I, S, Q, O, N, C99)` +// (etc/ap_fixed_base.h:458-471, etc/ap_int_base.h:398-410), which the +// closed Vitis front end evaluates at compile time ("XFORM will do compile +// time processing of the string"). See XlxStringBits.cc. +// +//===----------------------------------------------------------------------===// + +#ifndef CGEIST_XLXSTRINGBITS_H +#define CGEIST_XLXSTRINGBITS_H + +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/StringRef.h" +#include + +namespace clang { +class ASTContext; +class Expr; +} // namespace clang + +namespace cgeist { +namespace xlx { + +/// The target format of _ssdm_string2bits: W bits, I integer bits, signed or +/// not, and the quantisation / overflow modes by their enumerator names +/// (AP_TRN, AP_RND_CONV, ..., AP_WRAP, AP_SAT_SYM, ...), N saturation bits. +struct FixedFormat { + unsigned W = 0; + int64_t I = 0; + bool S = false; + llvm::StringRef Q = "AP_TRN"; + llvm::StringRef O = "AP_WRAP"; + int64_t N = 0; +}; + +/// The W-bit pattern of the string `str` (a C-simulation style number: +/// optional sign, 0x / 0b / 0o prefix, digits with an optional point, a +/// decimal `e` or binary `p` exponent) in the format `fmt`, read in radix +/// `radix` when there is no prefix (0 or 10: decimal). None when the string is +/// not a number of that form or the format is not supported. +std::optional stringToFixedBits(llvm::StringRef str, + unsigned radix, + const FixedFormat &fmt); + +/// If `E` constructs (through temporaries, elidable copies and casts) a +/// scalar-wrapper object with a constructor that passes its string argument +/// to _ssdm_string2bits, and that argument is a string literal: the object's +/// bit pattern. None otherwise. +std::optional foldStringConstruct(const clang::Expr *E, + clang::ASTContext &Ctx); + +/// An ap_int / ap_uint / ap_fixed / ap_ufixed default construction (a +/// CXXConstructExpr without arguments of one of those classes): its value in +/// static storage, 0 at the type's width (the object is zero-initialised +/// before the constructor runs, and the headers' default constructors set +/// nothing). None otherwise. +std::optional foldDefaultConstruct(const clang::Expr *E, + clang::ASTContext &Ctx); + +/// If `E` constructs (through temporaries, elidable copies and casts) an +/// ap_int / ap_uint / ap_fixed / ap_ufixed object (a class over +/// ap_int_base or ap_fixed_base) from one integer, +/// bool or (for the fixed-point classes) floating-point constant: the object's +/// bit pattern, the constant's exact value quantised and wrapped / saturated +/// by the class's modes as the headers' numeric constructors do +/// (etc/ap_fixed_base.h:547-640 for double, the integer constructors through +/// ap_int_base). None otherwise, and for N > 0 or AP_WRAP_SM. +std::optional foldNumericConstruct(const clang::Expr *E, + clang::ASTContext &Ctx); + +} // namespace xlx +} // namespace cgeist + +#endif // CGEIST_XLXSTRINGBITS_H diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index bf63bba663f7..fd1fbad91bca 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -7,8 +7,10 @@ //===----------------------------------------------------------------------===// #include "clang-mlir.h" +#include "polygeist/Passes/Passes.h" #include "../ArgumentList.h" #include "TypeUtils.h" +#include "XlxStringBits.h" #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/SCF/IR/SCF.h" @@ -16,6 +18,8 @@ #include "utils.h" #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" +#include "clang/AST/Mangle.h" +#include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" @@ -57,12 +61,21 @@ static cl::opt static cl::opt memRefABI("memref-abi", cl::init(true), cl::desc("Use memrefs when possible")); -cl::opt PrefixABI("prefix-abi", cl::init(""), - cl::desc("Prefix for emitted symbols")); +static cl::opt HLSDynamicGlobalInit( + "hls-dynamic-global-init", cl::init(true), + cl::desc("Emit a global whose initializer is not a constant (C++ dynamic " + "initialization, `static const T s = 1.0 / sqrt(128.0)`) as a " + "function __hls_global_init. marked hls.global_init that " + "computes and stores it, instead of leaving the global " + "uninitialized (check_semantics runs these before the top; " + "hls-est does not reach them)")); cl::opt HLSAnnotate("hls-annotate", cl::init(false), cl::desc("annotate hls pragmas")); +cl::opt PrefixABI("prefix-abi", cl::init(""), + cl::desc("Prefix for emitted symbols")); + cl::opt CStyleMemRef("c-style-memref", cl::init(true), cl::desc("Use c style memrefs when possible")); @@ -70,6 +83,18 @@ static cl::opt CombinedStructABI("struct-abi", cl::init(true), cl::desc("Use literal LLVM ABI for structs")); +// Opt-in (default off): with the option off, every code path below behaves +// exactly as before the option existed. +cl::opt ScalarWrapperABI( + "scalar-wrapper-abi", cl::init(false), + cl::desc("Lower a class whose only data member (through any chain of " + "single-base classes) is one scalar to that scalar: ap_fixed / " + "ap_int style wrappers become iN / fN values, references and " + "memref elements (also enables the constant evaluation of const " + "initialisers, explicit integer argument / return width " + "conversion, per-dimension construction of N-D class arrays and " + "__builtin_bit_cast that such wrappers need)")); + ValueCategory MLIRScanner::createComplexFloat(mlir::Location loc, mlir::Value real, mlir::Value imag, @@ -122,6 +147,18 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, val); } } + if (auto mt = dyn_cast(val.getType()); + mt && mt.getRank() == 1 && mt.getElementType().isa()) { + // A temporary of createComplexFloat (memref<2xT>): the parts are its + // elements 0 and 1. + auto mt1 = mlir::MemRefType::get({ShapedType::kDynamic}, + mt.getElementType(), + MemRefLayoutAttrInterface(), + mt.getMemorySpace()); + return ValueCategory(builder.create( + loc, mt1, val, getConstantIndex(fnum)), + /*isReference*/ true); + } if (auto mt = dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); assert(shape.size() == 2); @@ -174,7 +211,9 @@ mlir::Value MLIRScanner::getComplexPart(mlir::Location loc, mlir::Value complex, } auto ref = getComplexPartRef(loc, complex, fnum).val; if (auto mt = dyn_cast(ref.getType())) { - return builder.create(loc, ref); + // A memref view of the part: element 0 (a load without indices is + // invalid on it and asserted in SimplifySubIndexUsers). + return ValueCategory(ref, /*isReference*/ true).getValue(loc, builder); } else if (auto PT = dyn_cast(ref.getType())) { return builder.create(loc, ref); } else { @@ -208,6 +247,541 @@ bool isLLVMStructABI(const RecordDecl *RD, llvm::StructType *ST) { return false; } +bool MLIRASTConsumer::isXlxStreamMember(const clang::FunctionDecl *FD) const { + const auto *md = dyn_cast_or_null(FD); + return md && isXlxStreamClass(md->getParent()); +} + +bool MLIRASTConsumer::isXlxStreamClass(const clang::RecordDecl *RD) const { + if (!cgeist::hls::xlxHeaders() || !RD) + return false; + auto *spec = dyn_cast(RD); + if (!spec || spec->getName() != "stream") + return false; + auto *ns = dyn_cast( + spec->getDeclContext()->getRedeclContext()); + return ns && ns->getName() == "hls" && + ns->getDeclContext()->getRedeclContext()->isTranslationUnit(); +} + +std::optional +MLIRASTConsumer::packedStreamBits(clang::QualType T) { + T = T.getCanonicalType(); + if (T->isBooleanType()) + return 1; + if (const auto *AT = CGM.getContext().getAsConstantArrayType(T)) { + std::optional e = packedStreamBits(AT->getElementType()); + if (!e) + return std::nullopt; + return *e * static_cast(AT->getSize().getZExtValue()); + } + // A scalar (also an ap_int / ap_fixed class cgeist lowers to one iW). + auto scalarBits = [&](mlir::Type mt) -> std::optional { + if (mt.isIntOrFloat()) + return mt.getIntOrFloatBitWidth(); + return std::nullopt; + }; + const auto *RD = T->getAsRecordDecl(); + if (!RD) { + if (T->isPointerType() || T->isReferenceType()) + return std::nullopt; + return scalarBits(getMLIRType(T)); + } + if (getScalarWrapperField(RD)) + if (std::optional b = scalarBits(getMLIRType(T))) + return b; + RD = RD->getDefinition(); + if (!RD || RD->isUnion() || RD->isInvalidDecl() || RD->isDependentType()) + return std::nullopt; + int64_t sum = 0; + if (const auto *CXRD = dyn_cast(RD)) { + if (CXRD->isPolymorphic() || CXRD->getNumVBases() != 0) + return std::nullopt; + for (const clang::CXXBaseSpecifier &B : CXRD->bases()) { + std::optional b = packedStreamBits(B.getType()); + if (!b) + return std::nullopt; + sum += *b; + } + } + for (const clang::FieldDecl *F : RD->fields()) { + if (F->isBitField()) + return std::nullopt; + std::optional b = packedStreamBits(F->getType()); + if (!b) + return std::nullopt; + sum += *b; + } + return sum; +} + +const clang::FieldDecl * +MLIRASTConsumer::getScalarWrapperField(const clang::RecordDecl *RD) { + if (!ScalarWrapperABI || !RD) + return nullptr; + RD = RD->getDefinition(); + if (!RD) + return nullptr; + auto it = scalarWrapperCache.find(RD); + if (it != scalarWrapperCache.end()) + return it->second; + scalarWrapperCache[RD] = nullptr; // recursion guard + const clang::FieldDecl *result = nullptr; + // (--xlx-headers) An hls::stream is one i32 handle (getMLIRType) whatever + // its element type: the payload member `V` (hls::stream, also through + // the base of hls::stream) stands for it, so that the base / derived + // conversions of the object are the identity. Only the stream's own + // members, which cgeist never emits, name `V`. + if (isXlxStreamClass(RD)) { + auto *CXRD = dyn_cast(RD); + if (CXRD && CXRD->getNumBases() == 1 && RD->field_empty()) { + if (auto *BRT = + CXRD->bases_begin()->getType()->getAs()) + result = getScalarWrapperField(BRT->getDecl()); + } else if (!RD->field_empty()) { + result = *RD->field_begin(); + } + scalarWrapperCache[RD] = result; + return result; + } + do { + if (RD->isUnion() || RD->isInvalidDecl() || RD->isDependentType() || + RD->hasAttr() || RD->hasAttr()) + break; + auto *CXRD = dyn_cast(RD); + if (CXRD && (CXRD->isLambda() || CXRD->isPolymorphic() || + CXRD->getNumVBases() != 0 || CXRD->getNumBases() > 1)) + break; + const clang::FieldDecl *field = nullptr; + unsigned nfields = 0; + for (auto *f : RD->fields()) { + field = f; + nfields++; + } + if (CXRD && CXRD->getNumBases() == 1) { + // Chain: a class without members of its own over a wrapper base + // (ap_fixed over ap_fixed_base, ap_uint over ap_int_base). + if (nfields != 0) + break; + auto *BRT = CXRD->bases_begin()->getType()->getAs(); + if (BRT) + result = getScalarWrapperField(BRT->getDecl()); + break; + } + if (nfields != 1 || field->isBitField()) + break; + clang::QualType FT = field->getType(); + if (FT->isReferenceType()) + break; + const clang::Type *T = FT->getUnqualifiedDesugaredType(); + if (isa(T) || isa(T) || + (T->isBuiltinType() && + (T->isIntegerType() || T->isRealFloatingType()))) + result = field; + } while (false); + if (result) { + // The record must have exactly the scalar's object representation: an + // explicitly aligned member (`alignas(16) int v`) or anything else that + // adds padding or alignment keeps the record an aggregate, so that + // sizeof / alignof and the memory layout stay those of the record. + clang::ASTContext &Ctx = CGM.getContext(); + clang::QualType RecTy = Ctx.getRecordType(RD); + clang::QualType ScalarTy = result->getType(); + if (Ctx.getTypeSize(RecTy) != Ctx.getTypeSize(ScalarTy) || + Ctx.getTypeAlign(RecTy) != Ctx.getTypeAlign(ScalarTy)) + result = nullptr; + } + scalarWrapperCache[RD] = result; + return result; +} + +/// The reference `value` to a scalar-wrapper object, as the reference type +/// `nt` of a base or derived class of the same wrapper chain: the same +/// scalar, so only the memref shape / pointer type may need a cast. +static mlir::Value castScalarWrapperRef(mlir::OpBuilder &builder, + mlir::Location loc, mlir::Value value, + mlir::Type nt) { + if (value.getType() == nt) + return value; + auto smt = dyn_cast(value.getType()); + auto dmt = dyn_cast(nt); + if (smt && dmt && smt.getElementType() == dmt.getElementType() && + smt.getRank() == dmt.getRank() && + smt.getMemorySpace() == dmt.getMemorySpace()) + return builder.create(loc, dmt, value); + auto spt = dyn_cast(value.getType()); + auto dpt = dyn_cast(nt); + if (spt && dpt) + return builder.create(loc, dpt, value); + return value; +} + +/// Flattens the constant-evaluated initialiser `V` into attributes of the +/// scalar type `elemTy`, in memory order (array elements, then for a record +/// its bases and fields; a scalar wrapper contributes its one member). +static bool apValueToElements(const clang::APValue &V, mlir::Type elemTy, + SmallVectorImpl &out) { + switch (V.getKind()) { + case clang::APValue::Int: { + auto it = dyn_cast(elemTy); + if (!it) + return false; + llvm::APSInt v = V.getInt(); + APInt r = v.isUnsigned() ? v.zextOrTrunc(it.getWidth()) + : v.sextOrTrunc(it.getWidth()); + out.push_back(mlir::IntegerAttr::get(it, r)); + return true; + } + case clang::APValue::Float: { + auto ft = dyn_cast(elemTy); + if (!ft) + return false; + llvm::APFloat f = V.getFloat(); + bool lossy = false; + f.convert(ft.getFloatSemantics(), llvm::APFloat::rmNearestTiesToEven, + &lossy); + out.push_back(mlir::FloatAttr::get(ft, f)); + return true; + } + case clang::APValue::Array: { + for (unsigned i = 0, e = V.getArrayInitializedElts(); i < e; i++) + if (!apValueToElements(V.getArrayInitializedElt(i), elemTy, out)) + return false; + if (V.hasArrayFiller()) + for (unsigned i = V.getArrayInitializedElts(), e = V.getArraySize(); + i < e; i++) + if (!apValueToElements(V.getArrayFiller(), elemTy, out)) + return false; + return true; + } + case clang::APValue::Struct: { + for (unsigned i = 0, e = V.getStructNumBases(); i < e; i++) + if (!apValueToElements(V.getStructBase(i), elemTy, out)) + return false; + for (unsigned i = 0, e = V.getStructNumFields(); i < e; i++) + if (!apValueToElements(V.getStructField(i), elemTy, out)) + return false; + return true; + } + default: + return false; + } +} + +mlir::DenseElementsAttr +MLIRASTConsumer::evaluateConstantInitializer(const clang::VarDecl *VD, + mlir::MemRefType mr) { + if (!ScalarWrapperABI || !VD || !mr.hasStaticShape()) + return nullptr; + const VarDecl *InitVD = nullptr; + const Expr *AnyInit = VD->getAnyInitializer(InitVD); + if (!AnyInit || !InitVD) + return nullptr; + clang::APValue *cv = InitVD->evaluateValue(); + if (!cv) + return nullptr; + SmallVector elts; + if (!apValueToElements(*cv, mr.getElementType(), elts) || + (int64_t)elts.size() != mr.getNumElements()) + return nullptr; + return DenseElementsAttr::get( + RankedTensorType::get(mr.getShape(), mr.getElementType()), elts); +} + +mlir::DenseElementsAttr +MLIRASTConsumer::evaluateXlxStringInitializer(const clang::Expr *init, + clang::QualType type, + mlir::MemRefType mr) { + if (!ScalarWrapperABI || !cgeist::hls::xlxHeaders() || !init || + !mr.hasStaticShape()) + return nullptr; + auto it = mr.getElementType().dyn_cast(); + if (!it) + return nullptr; + clang::ASTContext &Ctx = CGM.getContext(); + SmallVector elts; + bool anyFolded = false; + std::function walk = + [&](const clang::Expr *e, clang::QualType T) -> bool { + if (!e) + return false; + e = e->IgnoreParens(); + if (auto *EWC = dyn_cast(e)) + e = EWC->getSubExpr()->IgnoreParens(); + if (auto *IL = dyn_cast(e)) { + if (const auto *AT = Ctx.getAsConstantArrayType(T)) { + uint64_t n = AT->getSize().getZExtValue(); + for (uint64_t i = 0; i < n; ++i) { + const clang::Expr *el = i < IL->getNumInits() ? IL->getInit(i) + : IL->getArrayFiller(); + if (!walk(el, AT->getElementType())) + return false; + } + return true; + } + return IL->getNumInits() == 1 && walk(IL->getInit(0), T); + } + // A default-constructed ap object, or an array of them (`ap_fixed<16,5> + // buf[N];`, the filler of `buf[N] = {0}`): zero in static storage (the + // headers' default constructors are `= default` and set nothing, but + // are not constexpr with the Xilinx bitwidth types, so clang's constant + // evaluation gives up). + if (const auto *AT = Ctx.getAsConstantArrayType(T)) { + if (auto *CE = dyn_cast(e); + CE && CE->getNumArgs() == 0 && + CE->getConstructor()->isDefaultConstructor()) { + uint64_t n = AT->getSize().getZExtValue(); + clang::QualType ET = AT->getElementType(); + while (const auto *inner = Ctx.getAsConstantArrayType(ET)) { + n *= inner->getSize().getZExtValue(); + ET = inner->getElementType(); + } + // The construction of every element (the element's own default + // constructor). + auto zero = cgeist::xlx::foldDefaultConstruct(e, Ctx); + if (!zero || zero->getBitWidth() != it.getWidth()) + return false; + for (uint64_t i = 0; i < n; ++i) + elts.push_back(*zero); + anyFolded = true; + return true; + } + } + if (auto v = cgeist::xlx::foldDefaultConstruct(e, Ctx)) { + if (v->getBitWidth() != it.getWidth()) + return false; + elts.push_back(*v); + anyFolded = true; + return true; + } + if (auto v = cgeist::xlx::foldStringConstruct(e, Ctx)) { + if (v->getBitWidth() != it.getWidth()) + return false; + elts.push_back(*v); + anyFolded = true; + return true; + } + // An ap type constructed from a number: the real headers' constructors + // are not constexpr, so clang has no constant for it (OPEN_ISSUES O63); + // the Vitis front end folds the constructor (its global initialiser). + if (auto v = cgeist::xlx::foldNumericConstruct(e, Ctx)) { + if (v->getBitWidth() != it.getWidth()) + return false; + elts.push_back(*v); + anyFolded = true; + return true; + } + if (T->isIntegerType()) { + clang::Expr::EvalResult R; + if (!e->isValueDependent() && e->EvaluateAsInt(R, Ctx)) { + llvm::APSInt v = R.Val.getInt(); + elts.push_back(v.isUnsigned() ? v.zextOrTrunc(it.getWidth()) + : v.sextOrTrunc(it.getWidth())); + return true; + } + } + return false; + }; + if (!walk(init, type) || !anyFolded || + (int64_t)elts.size() != mr.getNumElements()) + return nullptr; + return DenseElementsAttr::get( + RankedTensorType::get(mr.getShape(), mr.getElementType()), elts); +} + +/// The scalars of an (LLVM-typed) memref element `t`, all zero, in memory +/// order: a scalar, the elements of an array, the members of a struct. +static bool zeroScalars(mlir::Type t, SmallVectorImpl &out) { + if (auto it = dyn_cast(t)) { + out.push_back(mlir::IntegerAttr::get(it, 0)); + return true; + } + if (auto ft = dyn_cast(t)) { + out.push_back(mlir::FloatAttr::get(ft, 0.0)); + return true; + } + if (auto at = dyn_cast(t)) { + for (unsigned i = 0, n = at.getNumElements(); i < n; ++i) + if (!zeroScalars(at.getElementType(), out)) + return false; + return true; + } + if (auto st = dyn_cast(t)) { + for (mlir::Type m : st.getBody()) + if (!zeroScalars(m, out)) + return false; + return true; + } + return false; +} + +/// The constant-evaluated value `V` of an object whose memref element type +/// is `t` (an llvm.struct / llvm.array of scalars, or a scalar, which a +/// scalar wrapper class stands for under --scalar-wrapper-abi), flattened +/// into scalar attributes in memory order. +static bool apValueToTyped(const clang::APValue &V, mlir::Type t, + SmallVectorImpl &out) { + if (isa(t)) { + const clang::APValue *v = &V; + for (unsigned guard = 0; v->isStruct() && guard < 8; ++guard) { + if (v->getStructNumFields() == 1 && v->getStructNumBases() == 0) + v = &v->getStructField(0); + else if (v->getStructNumBases() == 1 && v->getStructNumFields() == 0) + v = &v->getStructBase(0); + else + return false; + } + if (!v->isInt() && !v->isFloat()) + return false; + return apValueToElements(*v, t, out); + } + if (auto at = dyn_cast(t)) { + if (!V.isArray() || V.getArraySize() != at.getNumElements()) + return false; + for (unsigned i = 0, n = at.getNumElements(); i < n; ++i) { + const clang::APValue &e = i < V.getArrayInitializedElts() + ? V.getArrayInitializedElt(i) + : V.getArrayFiller(); + if (!apValueToTyped(e, at.getElementType(), out)) + return false; + } + return true; + } + if (auto st = dyn_cast(t)) { + if (!V.isStruct() || V.getStructNumBases() != 0 || + V.getStructNumFields() != st.getBody().size()) + return false; + for (auto [i, m] : llvm::enumerate(st.getBody())) + if (!apValueToTyped(V.getStructField(i), m, out)) + return false; + return true; + } + return false; +} + +/// The initialiser `e` of an object of type `T` whose memref element type +/// is `t`, flattened like apValueToTyped, for the initialisers clang cannot +/// evaluate (--xlx-headers: ap members constructed from numbers or strings, +/// default-constructed ap members). `folded` is set when a leaf needed one +/// of those folds. +static bool initExprToTyped(const clang::Expr *e, clang::QualType T, + mlir::Type t, clang::ASTContext &Ctx, + SmallVectorImpl &out, + bool &folded) { + if (!e || isa(e->IgnoreParens())) + return zeroScalars(t, out); + e = e->IgnoreParens(); + if (auto *EWC = dyn_cast(e)) + e = EWC->getSubExpr()->IgnoreParens(); + auto *IL = dyn_cast(e); + if (auto it = dyn_cast(t)) { + std::optional v = cgeist::xlx::foldNumericConstruct(e, Ctx); + if (!v) + v = cgeist::xlx::foldStringConstruct(e, Ctx); + if (!v) + v = cgeist::xlx::foldDefaultConstruct(e, Ctx); + if (v) { + if (v->getBitWidth() != it.getWidth()) + return false; + out.push_back(mlir::IntegerAttr::get(it, *v)); + folded = true; + return true; + } + if (IL && IL->getNumInits() == 1) + return initExprToTyped(IL->getInit(0), T, t, Ctx, out, folded); + clang::Expr::EvalResult R; + if (T->isIntegerType() && !e->isValueDependent() && + e->EvaluateAsInt(R, Ctx)) { + llvm::APSInt v = R.Val.getInt(); + out.push_back(mlir::IntegerAttr::get( + it, v.isUnsigned() ? v.zextOrTrunc(it.getWidth()) + : v.sextOrTrunc(it.getWidth()))); + return true; + } + return false; + } + if (auto ft = dyn_cast(t)) { + if (IL && IL->getNumInits() == 1) + return initExprToTyped(IL->getInit(0), T, t, Ctx, out, folded); + llvm::APFloat f(0.0); + if (!T->isRealFloatingType() || e->isValueDependent() || + !e->EvaluateAsFloat(f, Ctx)) + return false; + bool lossy = false; + f.convert(ft.getFloatSemantics(), llvm::APFloat::rmNearestTiesToEven, + &lossy); + out.push_back(mlir::FloatAttr::get(ft, f)); + return true; + } + if (auto at = dyn_cast(t)) { + const auto *CAT = Ctx.getAsConstantArrayType(T); + if (!CAT || CAT->getSize().getZExtValue() != at.getNumElements() || !IL) + return false; + for (unsigned i = 0, n = at.getNumElements(); i < n; ++i) { + const clang::Expr *el = + i < IL->getNumInits() ? IL->getInit(i) : IL->getArrayFiller(); + if (!initExprToTyped(el, CAT->getElementType(), at.getElementType(), + Ctx, out, folded)) + return false; + } + return true; + } + if (auto st = dyn_cast(t)) { + const auto *RD = T->getAsCXXRecordDecl(); + if (!RD || !IL || RD->getNumBases() != 0 || RD->isUnion()) + return false; + SmallVector fields(RD->fields()); + if (fields.size() != st.getBody().size() || + llvm::any_of(fields, + [](const clang::FieldDecl *f) { return f->isBitField(); })) + return false; + for (auto [i, f] : llvm::enumerate(fields)) { + const clang::Expr *fi = i < IL->getNumInits() ? IL->getInit(i) : nullptr; + if (!initExprToTyped(fi, f->getType(), st.getBody()[i], Ctx, out, + folded)) + return false; + } + return true; + } + return false; +} + +mlir::ArrayAttr +MLIRASTConsumer::evaluateStructInitializer(const clang::VarDecl *VD, + const clang::Expr *init, + mlir::MemRefType mr) { + if (!ScalarWrapperABI || !VD || !mr.hasStaticShape() || + !isa(mr.getElementType())) + return nullptr; + // The whole variable as nested arrays of the element struct. + mlir::Type whole = mr.getElementType(); + for (int64_t d : llvm::reverse(mr.getShape())) + whole = mlir::LLVM::LLVMArrayType::get(whole, d); + clang::ASTContext &Ctx = CGM.getContext(); + // A scalar (not an array) variable: memref<1 x struct>. + bool scalarVar = !Ctx.getAsConstantArrayType(VD->getType()); + SmallVector flat; + const VarDecl *InitVD = nullptr; + if (VD->getAnyInitializer(InitVD) && InitVD) { + if (clang::APValue *cv = InitVD->evaluateValue()) { + bool ok = scalarVar + ? apValueToTyped(*cv, mr.getElementType(), flat) + : apValueToTyped(*cv, whole, flat); + if (ok) + return mlir::ArrayAttr::get(mr.getContext(), flat); + flat.clear(); + } + } + bool folded = false; + bool ok = scalarVar ? initExprToTyped(init, VD->getType(), + mr.getElementType(), Ctx, flat, folded) + : initExprToTyped(init, VD->getType(), whole, Ctx, flat, + folded); + if (!ok) + return nullptr; + return mlir::ArrayAttr::get(mr.getContext(), flat); +} + mlir::Attribute wrapIntegerMemorySpace(unsigned memorySpace, MLIRContext *ctx) { if (memorySpace == 0) return nullptr; @@ -221,8 +795,47 @@ MLIRScanner::MLIRScanner(MLIRASTConsumer &Glob, : Glob(Glob), module(module), builder(module->getContext()), ThisCapture(nullptr), LTInfo(LTInfo) {} +namespace { +/// Finds an access to a volatile-qualified object in a function body: a +/// glvalue expression of volatile-qualified type (reads, writes, compound +/// assignments, ++ / --, and conservatively also `&v` and unevaluated +/// operands). cgeist does not represent volatile on memref accesses, so the +/// function is marked instead (polygeist.volatile_access, Passes.h). +class VolatileAccessFinder + : public clang::RecursiveASTVisitor { +public: + bool found = false; + bool VisitExpr(clang::Expr *e) { + // Some expressions carry no type (e.g. a pack or an unresolved + // placeholder in an uninstantiated context); they access nothing. + clang::QualType t = e->getType(); + if (!t.isNull() && e->isGLValue() && t.isVolatileQualified()) { + found = true; + return false; + } + return true; + } +}; +} // namespace + +/// Whether the body of `fd` (with a constructor's member initialisers) +/// accesses a volatile-qualified object (VolatileAccessFinder). +static bool accessesVolatile(const FunctionDecl *fd) { + VolatileAccessFinder finder; + if (auto *ctor = dyn_cast(fd)) + for (auto *init : ctor->inits()) + if (init->getInit() && !finder.found) + finder.TraverseStmt(init->getInit()); + if (Stmt *body = fd->getBody(); body && !finder.found) + finder.TraverseStmt(body); + return finder.found; +} + void MLIRScanner::init(mlir::func::FuncOp function, const FunctionDecl *fd) { this->function = function; + if (accessesVolatile(fd)) + function->setAttr(mlir::polygeist::kVolatileAccessAttrName, + mlir::UnitAttr::get(function->getContext())); this->EmittingFunctionDecl = fd; if (ShowAST) { @@ -232,6 +845,12 @@ void MLIRScanner::init(mlir::func::FuncOp function, const FunctionDecl *fd) { setEntryAndAllocBlock(function.addEntryBlock()); + { + auto *MD = dyn_cast(fd); + cgeist::hls::enterFunction(fd, function, + /*argOffset=*/MD && MD->isInstance() ? 1 : 0); + } + unsigned i = 0; if (auto CM = dyn_cast(fd)) { if (CM->getParent()->isLambda()) { @@ -292,7 +911,7 @@ void MLIRScanner::init(mlir::func::FuncOp function, const FunctionDecl *fd) { builder.create(loc); return; } - + if (auto CC = dyn_cast(fd)) { const CXXRecordDecl *ClassDecl = CC->getParent(); for (auto expr : CC->inits()) { @@ -577,8 +1196,6 @@ mlir::Value MLIRScanner::createAllocOp(mlir::Type t, VarDecl *name, assert(alloc); // NamedAttribute attrs[] = {NamedAttribute("name", name)}; if (name) { - // if (name->getName() == "i") - // llvm_unreachable(" not i"); if (params.find(name) != params.end()) { name->dump(); } @@ -586,17 +1203,32 @@ mlir::Value MLIRScanner::createAllocOp(mlir::Type t, VarDecl *name, params[name] = ValueCategory(alloc, /*isReference*/ true); // Tag the underlying memref.alloca / llvm.alloca with the C variable name - // so HLS pragma resolution can find it later by name. + // (consumed by hls-est) and hand it to the HLS pragma machinery. mlir::Operation *defining = alloc.getDefiningOp(); while (auto castOp = - llvm::dyn_cast_or_null(defining)) { + llvm::dyn_cast_or_null(defining)) defining = castOp.getSource().getDefiningOp(); - } - if (HLSAnnotate && defining && (llvm::isa(defining) || - llvm::isa(defining))) { + if (HLSAnnotate && defining && + (llvm::isa(defining) || + llvm::isa(defining))) { defining->setAttr( "polygeist.varname", - mlir::StringAttr::get(builder.getContext(), name->getName())); + mlir::StringAttr::get(builder.getContext(), name->getNameAsString())); + + // Preserve genuine on-chip buffers (multi-element arrays) as hardware + // memory resources: this attr blocks store-to-load forwarding and + // dead-alloca elimination in the Polygeist canonicalizer, so the buffer + // survives for BRAM estimation. Scalars are deliberately left alone: + // they must still mem2reg to SSA, so we do NOT tag them. + if (auto memrefAlloca = + llvm::dyn_cast(defining)) { + auto mt = llvm::cast(memrefAlloca.getType()); + bool isBuffer = mt.hasStaticShape() && mt.getNumElements() > 1; + if (isBuffer) + defining->setAttr("hls.preserve", + mlir::UnitAttr::get(builder.getContext())); + } + cgeist::hls::onLocalStorage(name, defining); } } return alloc; @@ -661,10 +1293,12 @@ ValueCategory MLIRScanner::VisitConstantExpr(clang::ConstantExpr *expr) { auto sv = Visit(expr->getSubExpr()); if (auto ty = dyn_cast(getMLIRType(expr->getType()))) { if (expr->hasAPValueResult()) { - return ValueCategory(builder.create( - getMLIRLocation(expr->getExprLoc()), - expr->getResultAsAPSInt().getExtValue(), ty), - /*isReference*/ false); + return ValueCategory( + builder.create( + getMLIRLocation(expr->getExprLoc()), ty, + mlir::IntegerAttr::get( + ty, expr->getResultAsAPSInt().extOrTrunc(ty.getWidth()))), + /*isReference*/ false); } } assert(sv.val); @@ -679,6 +1313,14 @@ ValueCategory MLIRScanner::VisitTypeTraitExpr(clang::TypeTraitExpr *expr) { /*isReference*/ false); } +ValueCategory +MLIRScanner::VisitCXXNullPtrLiteralExpr(clang::CXXNullPtrLiteralExpr *expr) { + return ValueCategory( + builder.create(getMLIRLocation(expr->getExprLoc()), + getMLIRType(expr->getType())), + /*isReference*/ false); +} + ValueCategory MLIRScanner::VisitGNUNullExpr(clang::GNUNullExpr *expr) { auto ty = getMLIRType(expr->getType()).cast(); return ValueCategory(builder.create( @@ -688,9 +1330,14 @@ ValueCategory MLIRScanner::VisitGNUNullExpr(clang::GNUNullExpr *expr) { ValueCategory MLIRScanner::VisitIntegerLiteral(clang::IntegerLiteral *expr) { auto ty = getMLIRType(expr->getType()).cast(); + // The literal's APInt has the width of its type; build the attribute from + // it directly, so a value that does not fit in 64 bits (a _BitInt literal) + // is kept as it is. return ValueCategory( - builder.create(getMLIRLocation(expr->getExprLoc()), - expr->getValue().getSExtValue(), ty), + builder.create( + getMLIRLocation(expr->getExprLoc()), ty, + mlir::IntegerAttr::get(ty, + expr->getValue().zextOrTrunc(ty.getWidth()))), /*isReference*/ false); } @@ -784,6 +1431,102 @@ MLIRScanner::VisitImplicitValueInitExpr(clang::ImplicitValueInitExpr *decl) { llvm_unreachable("bad"); } +/// Whether clang's constant value `v` is all zeros (integers 0, floats +0.0, +/// arrays and structs of such). +static bool isZeroValue(const clang::APValue &v) { + switch (v.getKind()) { + case clang::APValue::Int: + return v.getInt().isZero(); + case clang::APValue::Float: + return v.getFloat().isPosZero(); + case clang::APValue::Array: + for (unsigned i = 0, e = v.getArrayInitializedElts(); i < e; ++i) + if (!isZeroValue(v.getArrayInitializedElt(i))) + return false; + return !v.hasArrayFiller() || isZeroValue(v.getArrayFiller()); + case clang::APValue::Struct: + for (unsigned i = 0, e = v.getStructNumBases(); i < e; ++i) + if (!isZeroValue(v.getStructBase(i))) + return false; + for (unsigned i = 0, e = v.getStructNumFields(); i < e; ++i) + if (!isZeroValue(v.getStructField(i))) + return false; + return true; + default: + return false; + } +} + +/// Whether the braced initialiser `e` sets every scalar to zero (`= {0}`, +/// `= {}`), as clang's constant evaluation shows. +static bool isZeroInitializer(clang::Expr *e, clang::ASTContext &ctx) { + if (isa(e)) + return true; + clang::Expr::EvalResult res; + return !e->isValueDependent() && e->EvaluateAsRValue(res, ctx) && + !res.HasSideEffects && isZeroValue(res.Val); +} + +/// Stores zero into every scalar of the aggregate `toInit` refers to, for an +/// aggregate member or element that a braced initialiser leaves without a +/// value (`window w = {};` with `struct window { unsigned char win[4][4]; }`, +/// clang's ImplicitValueInitExpr of the member's array type, W8b repro +/// r_local_struct_zero.cpp). `toInit` is a memref of scalars (a view whose +/// dynamic leading dimension selects one element, or the whole array) or an +/// LLVM pointer to an aggregate. Returns false when it is neither; else sets +/// `dense` to the splat zero of the scalars written into a memref (null for +/// an LLVM pointer), which a global's initial value is built from. +static bool zeroFillAggregate(mlir::OpBuilder &builder, mlir::Location loc, + mlir::Value toInit, + mlir::DenseElementsAttr &dense) { + dense = mlir::DenseElementsAttr(); + if (auto mt = dyn_cast(toInit.getType())) { + mlir::Type et = mt.getElementType(); + if (!et.isa() || mt.getRank() == 0) + return false; + for (auto [d, n] : llvm::enumerate(mt.getShape())) + if (n == ShapedType::kDynamic && d != 0) + return false; + mlir::TypedAttr zero = builder.getZeroAttr(et).cast(); + mlir::Value zeroV = builder.create(loc, zero); + auto c0 = builder.create(loc, 0); + auto c1 = builder.create(loc, 1); + // A dynamic leading dimension is a view of one element: index 0 only. + SmallVector idx; + int64_t count = 1; + mlir::OpBuilder::InsertionGuard guard(builder); + for (int64_t n : mt.getShape()) { + if (n == ShapedType::kDynamic) { + idx.push_back(c0); + continue; + } + count *= n; + auto ub = builder.create(loc, n); + auto loop = builder.create(loc, c0, ub, c1); + builder.setInsertionPointToStart(loop.getBody()); + idx.push_back(loop.getInductionVar()); + } + builder.create(loc, zeroV, toInit, idx); + // A view of one element contributes `count` scalars to its parent's + // value; the whole array (static leading dimension) gets its own shape, + // as a global's initial value needs. + std::vector shape({count}); + if (mt.getShape()[0] != ShapedType::kDynamic) + shape.assign(mt.getShape().begin(), mt.getShape().end()); + dense = SplatElementsAttr::get(RankedTensorType::get(shape, et), zero); + return true; + } + if (auto pt = dyn_cast(toInit.getType())) { + mlir::Type et = pt.getElementType(); + if (!et || !et.isa()) + return false; + builder.create(loc, builder.create(loc, et), + toInit); + return true; + } + return false; +} + /// Construct corresponding MLIR operations to initialize the given value by a /// provided InitListExpr. mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, @@ -808,7 +1551,33 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, [&](Expr *expr, mlir::Value toInit, bool inner) -> mlir::DenseElementsAttr { Location loc = toInit.getLoc(); + // A member that a braced initialiser leaves out takes its default member + // initialiser (`struct S { int n = 4; float w[2]; }; S s = {};`, C++11). + // It is the initialiser's own expression, evaluated here; visiting the + // CXXDefaultInitExpr itself needs a `this` the aggregate does not have + // (W8b, class_ece8893_2023_spring FocusedACO: assertion `ThisVal.val`). + if (auto *defaultInit = dyn_cast(expr)) + expr = defaultInit->getExpr(); + // A braced initialiser of a scalar (`bool r{false}`, the default member + // initialiser a braced aggregate initialiser leaves to a member) is its + // one element: `struct P { int x{0}; bool r{false}; }; P p = {a};` hit + // "unknown inner type" below with the member's scalar pointer + // (OPEN_ISSUES O152, FocusedACO three-opt `Segment seg[3] = {...}`). + if (auto *scalarList = dyn_cast(expr); + scalarList && scalarList->getType()->isScalarType() && + scalarList->getNumInits() == 1 && !scalarList->hasArrayFiller()) + return helper(scalarList->getInit(0), toInit, inner); if (InitListExpr *initListExpr = dyn_cast(expr)) { + // An all-zero braced initialiser of an array of scalars (`fm_t + // buf[64][112][112] = {0};`) is one zero-filling loop nest, not one + // store per element: element by element, a large array took cgeist + // longer than 10 minutes (W8b: YOLOv4-Tiny, DSC_Acceleration). + if (isa(toInit.getType()) && + isZeroInitializer(initListExpr, Glob.CGM.getContext())) { + mlir::DenseElementsAttr dense; + if (zeroFillAggregate(builder, loc, toInit, dense)) + return dense; + } if (inner) { if (auto mt = dyn_cast(toInit.getType())) { @@ -855,6 +1624,20 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, if (auto mt = dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); + // --scalar-wrapper-abi keeps a struct of one scalar member as that + // scalar (memref for `struct V { int x; }`): its braced + // initialiser `V{a.x + b.x}` initialises the scalar itself (before, + // assert(0) below; OPEN_ISSUES O91, reproducer c_initlist.cpp). + if (shape.empty() && !initListExpr->hasArrayFiller() && + initListExpr->getNumInits() == 1 && + mt.getElementType().isIntOrIndexOrFloat()) { + mlir::Value v = + Visit(initListExpr->getInit(0)).getValue(loc, builder); + if (v.getType() == mt.getElementType()) { + builder.create(loc, v, toInit, ValueRange()); + return mlir::DenseElementsAttr(); + } + } if (shape.size() == 0) { auto ET = mt.getElementType(); if (ET.isa() || @@ -928,8 +1711,32 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, } return mlir::DenseElementsAttr(); } else { + // (--xlx-headers) An element constructed from a string literal is a + // constant (XlxStringBits.cc); no constructor call or temporary. + if (cgeist::hls::xlxHeaders() && ScalarWrapperABI) + if (auto mt = dyn_cast(toInit.getType())) + if (auto et = dyn_cast(mt.getElementType())) + if (auto v = cgeist::xlx::foldStringConstruct( + expr, Glob.CGM.getContext()); + v && v->getBitWidth() == et.getWidth()) { + mlir::Attribute attr = builder.getIntegerAttr(et, *v); + ValueCategory(toInit, /*isReference*/ true) + .store(loc, builder, + builder.create( + loc, et, attr.cast())); + return DenseElementsAttr::get( + RankedTensorType::get(std::vector({1}), et), + llvm::ArrayRef(attr)); + } bool isArray = false; Glob.getMLIRType(expr->getType(), &isArray); + if (isa(expr) && + (isArray || expr->getType()->isArrayType() || + expr->getType()->isRecordType())) { + mlir::DenseElementsAttr dense; + if (zeroFillAggregate(builder, loc, toInit, dense)) + return dense; + } ValueCategory sub = Visit(expr); ValueCategory(toInit, /*isReference*/ true) .store(loc, builder, sub, isArray); @@ -953,6 +1760,20 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, return helper(expr, toInit, inner); } +/// The initialiser of `decl`, with an ExprWithCleanups around a braced +/// initialiser removed: `fm_t buf[2][2][2] = {0}` with a class element type +/// wraps its InitListExpr in one (the element constructors bind temporaries), +/// which the init-list paths below would not see; visited as an expression it +/// became a rank-3 temporary that the array store cannot copy (W8b repro +/// r_init3d.cpp). The temporaries are trivially destructible scalars here. +static clang::Expr *initSkippingCleanups(const clang::VarDecl *decl) { + auto *init = const_cast(decl->getInit()); + if (auto *ewc = dyn_cast_or_null(init)) + if (isa(ewc->getSubExpr())) + return ewc->getSubExpr(); + return init; +} + ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { decl = decl->getCanonicalDecl(); auto varLoc = getMLIRLocation(decl->getBeginLoc()); @@ -974,8 +1795,37 @@ ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { Glob.CGM.getContext().getLValueReferenceType(decl->getType())); } - if (auto init = decl->getInit()) { - if (!isa(init) && !isa(init)) { + // (--scalar-wrapper-abi) A static local with constant initialisation + // (C++ [basic.start.static], e.g. `static const ap_uint<12> lt[4] = + // {...}`) is initialised before the program runs: its global gets clang's + // evaluated value as dense initial value and nothing is emitted at run + // time (no initialiser code, no guard flag). + // (--xlx-headers) The same for an initialiser of string constructions + // (`const static ap_ufixed<25,11> tbl[32] = {"0x1.0000p0", ...}` in the + // Vitis math headers), which the Vitis front end folds at compile time + // (XlxStringBits.cc). + bool staticConstInit = false; + if (ScalarWrapperABI && decl->isStaticLocal() && memtype == 0 && + decl->getInit() && + (decl->hasConstantInitialization() || cgeist::hls::xlxHeaders()) && + !Glob.getMLIRType( + Glob.CGM.getContext().getPointerType(decl->getType())) + .isa()) { + auto gv = Glob.GetOrCreateGlobal( + decl, (function.getName() + "@static@").str(), /*tryInit*/ false); + auto gmt = gv.first.getType().cast(); + if (auto dense = decl->hasConstantInitialization() + ? Glob.evaluateConstantInitializer(decl, gmt) + : Glob.evaluateXlxStringInitializer( + decl->getInit(), decl->getType(), gmt)) { + gv.first.setInitialValueAttr(dense); + staticConstInit = true; + } + } + + if (auto init = initSkippingCleanups(decl)) { + if (!staticConstInit && !isa(init) && + !isa(init)) { auto visit = Visit(init); if (!visit.val) { decl->dump(); @@ -996,6 +1846,8 @@ ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { init->dump(); llvm_unreachable("?"); } + if (HLSAnnotate) + cgeist::hls::onAssignedValue(decl, inite.val); subType = inite.val.getType(); } } @@ -1021,6 +1873,7 @@ ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { } mlir::Value op; + mlir::Value staticInitTarget; // --scalar-wrapper-abi, see below Block *block = nullptr; Block::iterator iter; @@ -1039,6 +1892,13 @@ ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { decl, (function.getName() + "@static@").str(), /*tryInit*/ false); op = abuilder.create(varLoc, gv.first.getType(), gv.first.getName()); + // (--scalar-wrapper-abi) A run-time initialiser value of array type, + // or an init list, is stored through the global's static shape: the + // dynamic-shape view below does not match an array value, and an init + // list with an array filler needs the static size. (A constructor + // call keeps the dynamic-shape view as its `this`.) + if (ScalarWrapperABI && decl->getInit()) + staticInitTarget = op; auto mt = gv.first.getType().cast(); auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; @@ -1049,6 +1909,8 @@ ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { op); } params[decl] = ValueCategory(op, /*isReference*/ true); + if (staticConstInit) + return ValueCategory(op, /*isReference*/ true); if (decl->getInit()) { auto mr = MemRefType::get({1}, builder.getI1Type()); bool inits[1] = {true}; @@ -1083,11 +1945,13 @@ ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) { op = createAllocOp(subType, decl, memtype, isArray, LLVMABI); if (inite.val) { - ValueCategory(op, /*isReference*/ true) + ValueCategory(staticInitTarget && isArray ? staticInitTarget : op, + /*isReference*/ true) .store(varLoc, builder, inite, isArray); - } else if (auto init = decl->getInit()) { + } else if (auto init = initSkippingCleanups(decl)) { if (isa(init)) { - InitializeValueByInitListExpr(op, init); + InitializeValueByInitListExpr(staticInitTarget ? staticInitTarget : op, + init); } else if (auto CE = dyn_cast(init)) { VisitConstructCommon(CE, decl, memtype, op); } else @@ -1508,12 +2372,80 @@ mlir::Value add(MLIRScanner &sc, mlir::OpBuilder &builder, mlir::Location loc, return builder.create(loc, lhs, rhs); } -mlir::Value MLIRScanner::castToIndex(mlir::Location loc, mlir::Value val) { +/// Whether the sign-dependent ops emitted for a value of clang type `qt` +/// (extsi/extui, shrsi/shrui, divsi/divui, cmpi s*/u*, sitofp/uitofp, +/// index_cast/index_castui, ...) are signed. Decided on the canonical type, +/// so a typedef or alias template (uint32_t, size_t, ap_uint) and an +/// unsigned _BitInt are seen through; bool and an enum with an unsigned +/// underlying type count as unsigned, as in clang. Non-integer types default +/// to signed. +static bool isSignedIntegerQualType(clang::QualType qt) { + return !qt->isUnsignedIntegerType(); +} + +/// The type of the operand `e` of an arithmetic operator as written, before +/// the integer promotions and the usual arithmetic conversions. +static clang::QualType operandTypeAsWritten(const clang::Expr *e) { + return e->IgnoreParenImpCasts()->getType(); +} + +/// Marks `v` polygeist.nsw (Passes.h) when it is an arith.addi / subi / muli +/// that cgeist built in the width of `compQT` for a C integer +, -, * (or +/// unary minus, `rhsQT` null) computed in `compQT` on operands written with +/// types `lhsQT` / `rhsQT`, and that operation is undefined when its exact +/// result does not fit: `compQT` is a signed integer type at least as wide as +/// int (C11 6.5p5, C++ [expr.pre]p4) and the program is not compiled with +/// -fwrapv. Unsigned arithmetic, which wraps, is not marked, nor is arithmetic +/// on an operand promoted from a type narrower than int (char, short, bool, +/// an enum, a narrow _BitInt), nor an op built in a narrower type than +/// `compQT` (the `+=` / `-=` of a narrow LHS). AffineCFG raises a marked op to +/// an affine expression without proving that it keeps the value. Returns `v`. +static mlir::Value markNoSignedWrap(clang::CodeGen::CodeGenModule &CGM, + mlir::Value v, clang::QualType compQT, + clang::QualType lhsQT, + clang::QualType rhsQT = clang::QualType()) { + mlir::Operation *op = v.getDefiningOp(); + if (!isa_and_nonnull(op)) + return v; + clang::ASTContext &ctx = CGM.getContext(); + if (CGM.getLangOpts().isSignedOverflowDefined() || + !compQT->isSignedIntegerType()) + return v; + unsigned intWidth = ctx.getIntWidth(ctx.IntTy); + unsigned compWidth = ctx.getIntWidth(compQT); + auto it = dyn_cast(v.getType()); + if (compWidth < intWidth || !it || it.getWidth() != compWidth) + return v; + auto promotedFromNarrow = [&](clang::QualType t) { + if (t.isNull()) + return false; + if (!t->isIntegerType() || t->isEnumeralType()) + return true; + return ctx.isPromotableIntegerType(t) || ctx.getIntWidth(t) < intWidth; + }; + if (promotedFromNarrow(lhsQT) || promotedFromNarrow(rhsQT)) + return v; + op->setAttr(mlir::polygeist::kNoSignedWrapAttrName, + mlir::UnitAttr::get(op->getContext())); + return v; +} + +mlir::Value MLIRScanner::castToIndex(mlir::Location loc, mlir::Value val, + bool isUnsigned) { assert(val && "Expect non-null value"); - if (auto op = val.getDefiningOp()) - return getConstantIndex(op.value()); + if (auto op = val.getDefiningOp()) { + // A constant index is extended to the index width as its C type says + // (`ap_uint<8> j = 200` is 200, not -56), when it fits. + APInt v = op.getValue().cast().getValue(); + if (isUnsigned ? v.getActiveBits() < 64 : v.getSignificantBits() <= 64) + return getConstantIndex(isUnsigned ? (int64_t)v.getZExtValue() + : v.getSExtValue()); + } + if (isUnsigned) + return builder.create( + loc, mlir::IndexType::get(val.getContext()), val); return builder.create( loc, mlir::IndexType::get(val.getContext()), val); } @@ -1581,7 +2513,32 @@ ValueCategory MLIRScanner::VisitConstructCommon(clang::CXXConstructExpr *cons, op = createAllocOp(subType, name, memtype, isArray, LLVMABI); auto decl = cons->getConstructor(); - if (cons->requiresZeroInitialization()) { + const clang::FieldDecl *wrapperField = Glob.getScalarWrapperField( + Glob.CGM.getContext().getBaseElementType(cons->getType())->getAsRecordDecl()); + // (--xlx-headers) A scalar wrapper constructed from a string literal + // (`ap_fixed<16,5> c = "1.5"`): the value _ssdm_string2bits would give, + // folded at compile time as by the Vitis front end (XlxStringBits.cc). + if (cgeist::hls::xlxHeaders() && wrapperField && + !Glob.CGM.getContext().getAsArrayType(cons->getType())) + if (auto mt = dyn_cast(op.getType())) + if (auto et = dyn_cast(mt.getElementType())) + if (auto v = cgeist::xlx::foldStringConstruct( + cons, Glob.CGM.getContext()); + v && v->getBitWidth() == et.getWidth()) { + ValueCategory(op, /*isReference*/ true) + .store(loc, builder, + builder.create( + loc, et, builder.getIntegerAttr(et, *v))); + return ValueCategory(op, /*isReference*/ true); + } + if (cons->requiresZeroInitialization() && wrapperField && + op.getType().isa()) { + // Scalar wrapper(s): plain zero stores instead of a memset through a + // pointer (which the HLS analyses cannot read), one per object + // constructed here (not per element of the memref `op` refers into: + // `this` of a base or member subobject is memref). + storeZeroToWrapperObjects(loc, op, cons->getType(), count); + } else if (cons->requiresZeroInitialization()) { mlir::Value val = op; if (val.getType().isa()) { val = builder.create( @@ -1607,32 +2564,75 @@ ValueCategory MLIRScanner::VisitConstructCommon(clang::CXXConstructExpr *cons, if (decl->isTrivial() && decl->isDefaultConstructor()) return ValueCategory(op, /*isReference*/ true); + // A trivial copy / move of a scalar wrapper is a load and a store. + if (wrapperField && decl->isTrivial() && + (decl->isCopyConstructor() || decl->isMoveConstructor()) && + cons->getNumArgs() == 1 && + !Glob.CGM.getContext().getAsArrayType(cons->getType())) { + ValueCategory src = Visit(cons->getArg(0)); + assert(src.val && "copy constructor source"); + ValueCategory(op, /*isReference*/ true) + .store(loc, builder, src.getValue(loc, builder)); + return ValueCategory(op, /*isReference*/ true); + } + mlir::Block::iterator oldpoint; mlir::Block *oldblock; ValueCategory endobj(op, /*isReference*/ true); ValueCategory obj(op, /*isReference*/ true); QualType innerType = cons->getType(); - if (auto arrayType = Glob.CGM.getContext().getAsArrayType(cons->getType())) { - innerType = arrayType->getElementType(); - mlir::Value size; - if (count) - size = count; - else { - auto CAT = cast(arrayType); - size = getConstantIndex(CAT->getSize().getLimitedValue()); - } - auto forOp = builder.create(loc, getConstantIndex(0), size, - getConstantIndex(1)); + if (!ScalarWrapperABI) { + // Unchanged lowering (option off): one loop over the outermost dimension. + if (auto arrayType = + Glob.CGM.getContext().getAsArrayType(cons->getType())) { + innerType = arrayType->getElementType(); + mlir::Value size; + if (count) + size = count; + else { + auto CAT = cast(arrayType); + size = getConstantIndex(CAT->getSize().getLimitedValue()); + } + auto forOp = builder.create(loc, getConstantIndex(0), size, + getConstantIndex(1)); + oldpoint = builder.getInsertionPoint(); + oldblock = builder.getInsertionBlock(); + + builder.setInsertionPointToStart(&forOp.getRegion().getBlocks().front()); + assert(obj.isReference); + obj = CommonArrayToPointer(loc, obj); + obj = CommonArrayLookup(loc, obj, forOp.getInductionVar(), + /*isImplicitRef*/ false, /*removeIndex*/ false); + assert(obj.isReference); + } + } else if (Glob.CGM.getContext().getAsArrayType(cons->getType())) { + // One loop per array dimension, so that the constructor's `this` is the + // element reference (a constant array of class objects `T a[N][M]` was + // only looped over its outermost dimension before). oldpoint = builder.getInsertionPoint(); oldblock = builder.getInsertionBlock(); - - builder.setInsertionPointToStart(&forOp.getRegion().getBlocks().front()); - assert(obj.isReference); - obj = CommonArrayToPointer(loc, obj); - obj = CommonArrayLookup(loc, obj, forOp.getInductionVar(), - /*isImplicitRef*/ false, /*removeIndex*/ false); - assert(obj.isReference); + bool outermost = true; + while (auto *AT = Glob.CGM.getContext().getAsArrayType(innerType)) { + innerType = AT->getElementType(); + mlir::Value size; + if (outermost && count) + size = count; + else { + auto CAT = cast(AT); + size = getConstantIndex(CAT->getSize().getLimitedValue()); + } + auto forOp = builder.create(loc, getConstantIndex(0), size, + getConstantIndex(1)); + builder.setInsertionPointToStart(&forOp.getRegion().getBlocks().front()); + assert(obj.isReference); + bool last = !Glob.CGM.getContext().getAsArrayType(innerType); + obj = CommonArrayToPointer(loc, obj); + obj = CommonArrayLookup(loc, obj, forOp.getInductionVar(), + /*isImplicitRef*/ false, /*removeIndex*/ !last); + assert(obj.isReference); + outermost = false; + } } auto tocall = Glob.GetOrCreateMLIRFunction(cons->getConstructor()); @@ -1650,6 +2650,78 @@ ValueCategory MLIRScanner::VisitConstructCommon(clang::CXXConstructExpr *cons, return endobj; } +void MLIRScanner::storeZeroToWrapperObjects(mlir::Location loc, + mlir::Value op, clang::QualType T, + mlir::Value count) { + auto &Ctx = Glob.CGM.getContext(); + OpBuilder::InsertionGuard guard(builder); + // One loop per array dimension of the constructed type (the outermost one + // runs `count` times for `new T[n]()`), as for the constructor calls, so + // the store goes to exactly the objects being value-initialised. + ValueCategory obj(op, /*isReference*/ true); + bool outermost = true; + while (auto *AT = Ctx.getAsArrayType(T)) { + T = AT->getElementType(); + mlir::Value size; + if (outermost && count) + size = count; + else + size = getConstantIndex( + cast(AT)->getSize().getLimitedValue()); + auto forOp = builder.create(loc, getConstantIndex(0), size, + getConstantIndex(1)); + builder.setInsertionPointToStart(forOp.getBody()); + bool last = !Ctx.getAsArrayType(T); + obj = CommonArrayToPointer(loc, obj); + obj = CommonArrayLookup(loc, obj, forOp.getInductionVar(), + /*isImplicitRef*/ false, /*removeIndex*/ !last); + outermost = false; + } + mlir::Type et = getMLIRType(T); // the wrapper's scalar + mlir::Value zero; + if (auto it = dyn_cast(et)) + zero = builder.create(loc, 0, it); + else if (auto ft = dyn_cast(et)) + zero = builder.create( + loc, APFloat::getZero(ft.getFloatSemantics()), ft); + else + llvm_unreachable("zero store of a non-scalar wrapper"); + obj.store(loc, builder, zero); +} + +mlir::Value MLIRScanner::tryEmitConstVarValue(mlir::Location loc, + const VarDecl *VD, + clang::QualType resultType) { + if (!ScalarWrapperABI || !VD || isa(VD)) + return nullptr; + clang::QualType VT = VD->getType(); + if (!VT.isConstQualified() || VT.isVolatileQualified()) + return nullptr; + const VarDecl *InitVD = nullptr; + const Expr *Init = VD->getAnyInitializer(InitVD); + if (!Init || !InitVD) + return nullptr; + // Only an initialiser clang evaluated as a constant expression (static + // members, globals, constexpr; a non-constant `const` local stays a load). + if (!InitVD->hasConstantInitialization() && + !InitVD->isUsableInConstantExpressions(Glob.CGM.getContext())) + return nullptr; + clang::APValue *val = InitVD->evaluateValue(); + if (!val) + return nullptr; + mlir::Type ty = getMLIRType(resultType); + if (!ty.isa()) + return nullptr; + SmallVector elts; + if (!apValueToElements(*val, ty, elts) || elts.size() != 1) + return nullptr; + if (auto ia = dyn_cast(elts[0])) + return builder.create(loc, ty, ia); + if (auto fa = dyn_cast(elts[0])) + return builder.create(loc, ty, fa); + return nullptr; +} + ValueCategory MLIRScanner::CommonArrayToPointer(mlir::Location loc, ValueCategory scalar) { assert(scalar.val); @@ -1752,7 +2824,8 @@ MLIRScanner::VisitArraySubscriptExpr(clang::ArraySubscriptExpr *expr) { auto rhs = Visit(expr->getRHS()).getValue(loc, builder); // Check the RHS has been successfully emitted assert(rhs); - auto idx = castToIndex(getMLIRLocation(expr->getRBracketLoc()), rhs); + auto idx = castToIndex(getMLIRLocation(expr->getRBracketLoc()), rhs, + !isSignedIntegerQualType(expr->getRHS()->getType())); if (isa( expr->getLHS()->getType()->getUnqualifiedDesugaredType())) { assert(moo.isReference); @@ -1809,9 +2882,18 @@ const clang::FunctionDecl *MLIRScanner::EmitCallee(const Expr *E) { std::pair MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) { auto loc = getMLIRLocation(expr->getExprLoc()); + // The name-based lowering below is for the C math library; an overload + // of the same name on another type (hls::exp on an ap_fixed class) + // stays a call (--scalar-wrapper-abi; unchanged when the option is off). + bool floatArgs = true; + if (ScalarWrapperABI) { + floatArgs = expr->getNumArgs() > 0; + for (auto *a : expr->arguments()) + floatArgs &= a->getType()->isRealFloatingType(); + } if (auto ic = dyn_cast(expr->getCallee())) { if (auto sr = dyn_cast(ic->getSubExpr())) { - if (sr->getDecl()->getIdentifier() && + if (floatArgs && sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "__log2f") { std::vector args; for (auto a : expr->arguments()) { @@ -1822,7 +2904,7 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) { /*isReference*/ false), true); } - if (sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "log") { + if (floatArgs && sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "log") { std::vector args; for (auto a : expr->arguments()) { args.push_back(Visit(a).getValue(loc, builder)); @@ -1832,7 +2914,7 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) { /*isReference*/ false), true); } - if (sr->getDecl()->getIdentifier() && + if (floatArgs && sr->getDecl()->getIdentifier() && (sr->getDecl()->getName() == "ceil")) { std::vector args; for (auto a : expr->arguments()) { @@ -1843,7 +2925,7 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) { /*isReference*/ false), true); } - if (sr->getDecl()->getIdentifier() && + if (floatArgs && sr->getDecl()->getIdentifier() && (sr->getDecl()->getName() == "expf" || sr->getDecl()->getName() == "exp")) { std::vector args; @@ -1855,7 +2937,7 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) { /*isReference*/ false), true); } - if (sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "sin") { + if (floatArgs && sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "sin") { std::vector args; for (auto a : expr->arguments()) { args.push_back(Visit(a).getValue(loc, builder)); @@ -1866,7 +2948,7 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) { true); } - if (sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "cos") { + if (floatArgs && sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "cos") { std::vector args; for (auto a : expr->arguments()) { args.push_back(Visit(a).getValue(loc, builder)); @@ -2119,7 +3201,7 @@ MLIRScanner::EmitGPUCallExpr(clang::CallExpr *expr) { return make_pair(ValueCategory(), false); } -mlir::Value MLIRScanner::getConstantIndex(int x) { +mlir::Value MLIRScanner::getConstantIndex(int64_t x) { if (constants.find(x) != constants.end()) { return constants[x]; } @@ -2196,8 +3278,11 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { val.dump(); } auto ty = val.getType().cast(); - auto c1 = builder.create( - loc, APInt::getAllOnes(ty.getWidth()).getSExtValue(), ty); + // The mask is built from the full-width APInt: ConstantIntOp(int64_t, iN) + // zero-extends the 64-bit -1, so wider integers (ap_int, W > 64) + // would only have their low 64 bits inverted. + auto c1 = builder.create( + loc, builder.getIntegerAttr(ty, APInt::getAllOnes(ty.getWidth()))); return ValueCategory(builder.create(loc, val, c1), /*isReference*/ false); } @@ -2247,10 +3332,13 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { /*isReference*/ false); } return ValueCategory( - builder.create(loc, - builder.create( - loc, 0, ty.cast()), - val), + markNoSignedWrap( + Glob.CGM, + builder.create(loc, + builder.create( + loc, 0, ty.cast()), + val), + U->getType(), operandTypeAsWritten(U->getSubExpr())), /*isReference*/ false); } } @@ -2295,9 +3383,13 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { llvm::errs() << " ty: " << ty << "prev: " << prev << "\n"; } assert(prev.getType() == ty); - next = builder.create( - loc, prev, - builder.create(loc, 1, ty.cast())); + // ++x is x += 1 (C11 6.5.3.1): x's type, unless x is promoted. + next = markNoSignedWrap( + Glob.CGM, + builder.create(loc, prev, + builder.create( + loc, 1, ty.cast())), + U->getSubExpr()->getType(), U->getSubExpr()->getType()); } sub.store(loc, builder, next); @@ -2337,11 +3429,20 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { llvm::errs() << ty << " - " << prev << "\n"; U->dump(); } - next = builder.create( - loc, prev, - builder.create(loc, 1, ty.cast())); + next = markNoSignedWrap( + Glob.CGM, + builder.create(loc, prev, + builder.create( + loc, 1, ty.cast())), + U->getSubExpr()->getType(), U->getSubExpr()->getType()); } sub.store(loc, builder, next); + // In C++ `--i` is an lvalue, as `++i` (returned as `sub` above): a use + // such as `for (i = 8; --i;)` reads it through an lvalue-to-rvalue cast, + // which asserted on the value returned before (hlsyn-vitis aes, W8b). + if (U->getOpcode() == clang::UnaryOperator::Opcode::UO_PreDec && + U->isLValue()) + return sub; return ValueCategory( (U->getOpcode() == clang::UnaryOperator::Opcode::UO_PostDec) ? prev : next, @@ -2576,19 +3677,38 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) { } } +/// Reports the value assigned to a plain variable to `#pragma HLS bind_op`. +/// The variable an assignment writes: `x`, `x[i][j]`, `x.f`. +static const VarDecl *assignedVariable(clang::Expr *lhs) { + lhs = lhs->IgnoreParenCasts(); + while (true) { + if (auto *ASE = dyn_cast(lhs)) + lhs = ASE->getBase()->IgnoreParenCasts(); + else if (auto *ME = dyn_cast(lhs)) + lhs = ME->getBase()->IgnoreParenCasts(); + else + break; + } + if (auto DRE = dyn_cast(lhs)) + return dyn_cast(DRE->getDecl()); + return nullptr; +} + +/// Reports the value assigned to a variable to `#pragma HLS bind_op`. +static void notifyHLSAssign(clang::BinaryOperator *BO, mlir::Value value) { + if (!HLSAnnotate) + return; + if (const VarDecl *VD = assignedVariable(BO->getLHS())) + cgeist::hls::onAssignedValue(VD, value); +} + ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { auto loc = getMLIRLocation(BO->getExprLoc()); auto fixInteger = [&](mlir::Value res, bool forceUnsigned = false) { auto prevTy = res.getType().cast(); auto postTy = getMLIRType(BO->getType()).cast(); - bool signedType = true; - if (auto bit = dyn_cast(&*BO->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(BO->getType()); if (forceUnsigned) signedType = false; if (postTy != prevTy) { @@ -2708,13 +3828,254 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { assert(rhs.val); } // TODO note assumptions made here about unsigned / unordered - bool signedType = true; - if (auto bit = dyn_cast(&*BO->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; + bool signedType = isSignedIntegerQualType(BO->getType()); + + // Scalar `lhs op= rhs` (an integer or floating LHS, every compound + // assignment): clang evaluates it in the computation type + // (CompoundAssignOperator::getComputationLHSType(), e.g. `int` for an + // `unsigned char` LHS, `double` for `int += 1.5` and for `float += double`, + // the LHS type itself for a _BitInt), then converts the result back to the + // LHS type. Both operands are brought to the computation type, + // `mkInt(l, r, isSigned)` / `mkFloat(l, r)` build the op there, and the + // result is truncated/extended (or converted back from a floating + // computation type, or rounded to a narrower floating LHS) to the LHS + // element type before the store; a bool LHS stores the result tested + // against zero. + auto emitScalarCompound = + [&](llvm::function_ref mkInt, + llvm::function_ref mkFloat) + -> ValueCategory { + assert(lhs.isReference); + auto *CAO = cast(BO); + clang::QualType compQT = CAO->getComputationLHSType(); + clang::QualType lhsQT = BO->getLHS()->getType(); + mlir::Type compTy = getMLIRType(compQT); + bool compSigned = isSignedIntegerQualType(compQT); + bool lhsSigned = isSignedIntegerQualType(lhsQT); + mlir::Value prev = lhs.getValue(loc, builder); + mlir::Value rhsV = rhs.getValue(loc, builder); + mlir::Type lhsTy = prev.getType(); + // Convert the C value `v`, of signedness `vSigned`, to scalar type `to`, + // whose C signedness is `toSigned` (it only decides fptosi vs fptoui: a + // floating computation stored to an unsigned LHS is fptoui in C). + auto convert = [&](mlir::Value v, mlir::Type to, bool vSigned, + bool toSigned) -> mlir::Value { + mlir::Type from = v.getType(); + if (from == to) + return v; + if (auto fi = dyn_cast(from)) { + if (auto ti = dyn_cast(to)) { + if (fi.getWidth() > ti.getWidth()) + return builder.create(loc, to, v); + if (vSigned) + return builder.create(loc, to, v); + return builder.create(loc, to, v); + } + if (isa(to)) { + if (vSigned) + return builder.create(loc, to, v); + return builder.create(loc, to, v); + } + } else if (auto ff = dyn_cast(from)) { + if (auto tf = dyn_cast(to)) { + if (ff.getWidth() < tf.getWidth()) + return builder.create(loc, to, v); + if (ff.getWidth() > tf.getWidth()) + return builder.create(loc, to, v); + } else if (isa(to)) { + if (toSigned) + return builder.create(loc, to, v); + return builder.create(loc, to, v); + } + } + BO->dump(); + llvm::errs() << " from: " << v << " to: " << to << "\n"; + llvm_unreachable("unsupported compound assignment conversion"); + }; + rhsV = convert(rhsV, compTy, + isSignedIntegerQualType(BO->getRHS()->getType()), + compSigned); + // `+` and `-` take the low bits of their result from the low bits of + // their operands alone: with an integer computation type wider than an + // integer (non-bool) LHS, `+=` / `-=` are built in the LHS type on the + // RHS truncated to it, the same value as computing in the computation + // type and truncating. A narrow counter's `i += 2` / `i -= 2` thus stays + // an iN add of the counter, the update CanonicalizeFor raises to a for + // loop. The iN op wraps modulo 2^N like the C assignment; AffineCFG + // raises it to an affine expression only when it provably does not wrap. + // The other compound assignments compute in the computation type. + switch (BO->getOpcode()) { + case clang::BinaryOperator::Opcode::BO_AddAssign: + case clang::BinaryOperator::Opcode::BO_SubAssign: + if (isa(compTy) && isa(lhsTy) && + !lhsQT->isBooleanType() && + lhsTy.getIntOrFloatBitWidth() < compTy.getIntOrFloatBitWidth()) { + mlir::Value narrowRhs = + builder.create(loc, lhsTy, rhsV); + mlir::Value result = mkInt(prev, narrowRhs, compSigned); + notifyHLSAssign(BO, result); + lhs.store(loc, builder, result); + return lhs; + } + break; + default: + break; + } + prev = convert(prev, compTy, lhsSigned, compSigned); + mlir::Value result; + if (isa(compTy)) { + assert(mkFloat && "compound assignment has no floating-point form"); + result = mkFloat(prev, rhsV); + } else { + result = markNoSignedWrap(Glob.CGM, mkInt(prev, rhsV, compSigned), + compQT, lhsQT, + operandTypeAsWritten(BO->getRHS())); + } + if (lhsQT->isBooleanType()) { + // `b op= x` stores `(bool)(b op x)`: the result is tested against zero + // (as CK_IntegralToBoolean / CK_FloatingToBoolean do), not truncated. + if (auto ft = dyn_cast(compTy)) { + auto zero = builder.create( + loc, APFloat::getZero(ft.getFloatSemantics()), ft); + result = builder.create(loc, CmpFPredicate::UNE, result, + zero); + } else { + result = builder.create( + loc, CmpIPredicate::ne, result, + builder.create(loc, 0, compTy)); + } + if (lhsTy.getIntOrFloatBitWidth() > 1) + result = builder.create(loc, lhsTy, result); + } else { + result = convert(result, lhsTy, compSigned, lhsSigned); + } + notifyHLSAssign(BO, result); + lhs.store(loc, builder, result); + return lhs; + }; + + // Floating complex `+ - * /` and their compound assignments, built the + // way Vitis's front end does for its FPGA targets (hls-llvm-project + // clang/lib/CodeGen/CGExprComplex.cpp EmitBinAdd / EmitBinSub / + // EmitBinMul / EmitBinDiv under IsFPGAArch, Apache-2.0 WITH + // LLVM-exception): a real operand contributes no imaginary part (C11 + // Annex G.5.1), the product is (ac - bd) + i(ad + bc) with no NaN + // recovery libcall, and the quotient by a complex is ((ac + bd) + i(bc - + // ad)) / (cc + dd) with no __divsc3. The type test looks through typedefs: + // libstdc++'s std::complex keeps its value as `_ComplexT _M_value` + // and its operators are `_M_value op= __z.__rep()`, whose type is the + // typedef, which the opcode cases below test with isa and + // missed (CIRCT W9 round 6 review, defect 2: `a[i] = a[i] + a[j]` and + // `a[i] = a[i] * a[j]` asserted 'must have shape 1'). + if (const auto *cty = BO->getType()->getAs()) { + clang::BinaryOperator::Opcode op = BO->getOpcode(); + bool assign = BO->isCompoundAssignmentOp(); + if (assign) + op = clang::BinaryOperator::getOpForCompoundAssignment(op); + bool arith = op == clang::BO_Add || op == clang::BO_Sub || + op == clang::BO_Mul || op == clang::BO_Div; + // `+` and `+=` of two complex operands on a type written as `_Complex` + // itself already work in the opcode cases below (the `+=` case also + // tells the HLS pragma layer about the assignment); they keep that path + // so that the MLIR of code that compiled before is unchanged. + if (op == clang::BO_Add && isa(BO->getType()) && + BO->getLHS()->getType()->isAnyComplexType() && + BO->getRHS()->getType()->isAnyComplexType()) + arith = false; + clang::QualType compElt = cty->getElementType(); + if (assign) + if (const auto *cc = cast(BO) + ->getComputationResultType() + ->getAs()) + compElt = cc->getElementType(); + auto compTy = dyn_cast(getMLIRType(compElt)); + auto lhsElt = dyn_cast(getMLIRType(cty->getElementType())); + if (arith && compTy && lhsElt) { + auto toFloat = [&](mlir::Value v, mlir::FloatType t) -> mlir::Value { + if (!v || v.getType() == t) + return v; + auto ft = cast(v.getType()); + if (ft.getWidth() < t.getWidth()) + return builder.create(loc, t, v); + return builder.create(loc, t, v); + }; + // (real, imaginary) of an operand; the imaginary part of a real one + // is null. + auto parts = [&](ValueCategory v, clang::QualType t) + -> std::pair { + if (t->isAnyComplexType()) + return {toFloat(getComplexPart(loc, v.val, 0), compTy), + toFloat(getComplexPart(loc, v.val, 1), compTy)}; + mlir::Value r = v.getValue(loc, builder); + if (auto it = dyn_cast(r.getType())) + r = t->isUnsignedIntegerType() + ? builder.create(loc, compTy, r).getResult() + : builder.create(loc, compTy, r) + .getResult(); + return {toFloat(r, compTy), mlir::Value()}; + }; + auto [a, b] = parts(lhs, BO->getLHS()->getType()); + auto [c, d] = parts(rhs, BO->getRHS()->getType()); + auto add = [&](mlir::Value x, mlir::Value y) -> mlir::Value { + return builder.create(loc, x, y); + }; + auto sub = [&](mlir::Value x, mlir::Value y) -> mlir::Value { + return builder.create(loc, x, y); + }; + auto mul = [&](mlir::Value x, mlir::Value y) -> mlir::Value { + return builder.create(loc, x, y); + }; + auto div = [&](mlir::Value x, mlir::Value y) -> mlir::Value { + return builder.create(loc, x, y); + }; + mlir::Value re, im; + switch (op) { + case clang::BO_Add: + re = add(a, c); + im = b && d ? add(b, d) : (b ? b : d); + break; + case clang::BO_Sub: + re = sub(a, c); + im = b && d ? sub(b, d) + : (b ? b : builder.create(loc, d)); + break; + case clang::BO_Mul: + if (b && d) { + re = sub(mul(a, c), mul(b, d)); + im = add(mul(a, d), mul(b, c)); + } else { + re = mul(a, c); + im = b ? mul(b, c) : mul(a, d); + } + break; + default: // BO_Div + if (d) { + if (!b) + b = builder.create( + loc, APFloat::getZero(compTy.getFloatSemantics()), compTy); + mlir::Value den = add(mul(c, c), mul(d, d)); + re = div(add(mul(a, c), mul(b, d)), den); + im = div(sub(mul(b, c), mul(a, d)), den); + } else { + re = div(a, c); + im = div(b, c); + } + break; + } + if (!im) // both operands real: not a complex expression + im = builder.create( + loc, APFloat::getZero(compTy.getFloatSemantics()), compTy); + re = toFloat(re, lhsElt); + im = toFloat(im, lhsElt); + if (!assign) + return createComplexFloat(loc, re, im, BO->getType()); + assert(lhs.isReference); + getComplexPartRef(loc, lhs.val, 0).store(loc, builder, re); + getComplexPartRef(loc, lhs.val, 1).store(loc, builder, im); + return lhs; + } } + switch (BO->getOpcode()) { case clang::BinaryOperator::Opcode::BO_Shr: { auto lhsv = lhs.getValue(loc, builder); @@ -2781,13 +4142,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { case clang::BinaryOperator::Opcode::BO_LE: case clang::BinaryOperator::Opcode::BO_EQ: case clang::BinaryOperator::Opcode::BO_NE: { - signedType = true; - if (auto bit = dyn_cast(&*BO->getLHS()->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + signedType = isSignedIntegerQualType(BO->getLHS()->getType()); CmpFPredicate FPred; CmpIPredicate IPred; LLVM::ICmpPredicate LPred; @@ -2857,7 +4212,11 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { /*isReference*/ false); } else { return ValueCategory( - builder.create(loc, lhs_v, rhs.getValue(loc, builder)), + markNoSignedWrap(Glob.CGM, + builder.create( + loc, lhs_v, rhs.getValue(loc, builder)), + BO->getType(), operandTypeAsWritten(BO->getLHS()), + operandTypeAsWritten(BO->getRHS())), /*isReference*/ false); } } @@ -2900,14 +4259,14 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } } case clang::BinaryOperator::Opcode::BO_Add: { - auto emitSubindex = [&](auto mr, auto ptradd) { + auto emitSubindex = [&](auto mr, auto ptradd, bool ptraddUnsigned) { auto mt = mr.getType().template dyn_cast(); auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), MemRefLayoutAttrInterface(), mt.getMemorySpace()); - ptradd = castToIndex(loc, ptradd); + ptradd = castToIndex(loc, ptradd, ptraddUnsigned); return ValueCategory( builder.create(loc, mt0, mr, ptradd), /*isReference*/ false); @@ -2928,9 +4287,11 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { return ValueCategory(builder.create(loc, lhs_v, rhs_v), /*isReference*/ false); } else if (lhs_v.getType().isa()) { - return emitSubindex(lhs_v, rhs_v); + return emitSubindex(lhs_v, rhs_v, + !isSignedIntegerQualType(BO->getRHS()->getType())); } else if (rhs_v.getType().isa()) { - return emitSubindex(rhs_v, lhs_v); + return emitSubindex(rhs_v, lhs_v, + !isSignedIntegerQualType(BO->getLHS()->getType())); } else if (auto pt = dyn_cast(lhs_v.getType())) { return ValueCategory( @@ -2940,14 +4301,24 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } else { if (auto lhs_c = lhs_v.getDefiningOp()) { if (auto rhs_c = rhs_v.getDefiningOp()) { - return ValueCategory( - builder.create( - loc, lhs_c.value() + rhs_c.value(), lhs_c.getType()), - false); + if (lhs_c.getType() == rhs_c.getType()) { + // Fold in the constants' own width (wraps like the C type; works + // past 64 bits). + APInt sum = lhs_c.getValue().cast().getValue() + + rhs_c.getValue().cast().getValue(); + return ValueCategory( + builder.create( + loc, lhs_c.getType(), + mlir::IntegerAttr::get(lhs_c.getType(), sum)), + false); + } } } - return ValueCategory(builder.create(loc, lhs_v, rhs_v), - /*isReference*/ false); + return ValueCategory( + markNoSignedWrap(Glob.CGM, builder.create(loc, lhs_v, rhs_v), + BO->getType(), operandTypeAsWritten(BO->getLHS()), + operandTypeAsWritten(BO->getRHS())), + /*isReference*/ false); } } case clang::BinaryOperator::Opcode::BO_Sub: { @@ -3001,12 +4372,47 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { mlir::TypeAttr::get(pt.getElementType())))); return ValueCategory(val, /*isReference*/ false); } else { - return ValueCategory(builder.create(loc, lhs_v, rhs_v), - /*isReference*/ false); + return ValueCategory( + markNoSignedWrap(Glob.CGM, builder.create(loc, lhs_v, rhs_v), + BO->getType(), operandTypeAsWritten(BO->getLHS()), + operandTypeAsWritten(BO->getRHS())), + /*isReference*/ false); } } case clang::BinaryOperator::Opcode::BO_Assign: { assert(lhs.isReference); + // C struct assignment `a[i] = b[j]` of a struct whose members share one + // type (CombinedStructABI: `struct { double x, y, z; }` is a row of + // memref): both sides are references to such a row, and the + // assignment copies the members one by one. Reading the row as one + // value (below) asserts on a rank-2 reference (W8b repros + // r_struct_assign*.c: `out[i] = p`, `out[1][i] = pos[2][i]`). A + // `_Complex` value is such a row too (memref): the implicit + // copy assignment of std::complex (`_M_value = __z._M_value`) + // asserted the same way (CIRCT OPEN_ISSUES O70 (a), hp_fft_hls + // `d[i] = std::complex(a[i], b[i])`). + // A floating `_Complex` assignment copies the real and the imaginary + // part, whatever form the right side has (a row of an array, a + // temporary from createComplexFloat, a struct value): both parts are + // read before either is written. + if (const auto *cty = BO->getType()->getAs()) + if (cty->getElementType()->isRealFloatingType()) { + mlir::Value re = getComplexPart(loc, rhs.val, 0); + mlir::Value im = getComplexPart(loc, rhs.val, 1); + getComplexPartRef(loc, lhs.val, 0).store(loc, builder, re); + getComplexPartRef(loc, lhs.val, 1).store(loc, builder, im); + return lhs; + } + if (rhs.isReference && + (BO->getType()->isRecordType() || BO->getType()->isAnyComplexType())) + if (auto rmt = dyn_cast(rhs.val.getType())) + if (auto lmt = dyn_cast(lhs.val.getType())) + if (rmt.getRank() == 2 && lmt.getRank() == 2 && + rmt.getElementType() == lmt.getElementType() && + !rmt.isDynamicDim(1) && rmt.getDimSize(1) == lmt.getDimSize(1)) { + lhs.store(loc, builder, rhs, /*isArray*/ true); + return lhs; + } mlir::Value tostore = rhs.getValue(loc, builder); mlir::Type subType; if (auto PT = dyn_cast(lhs.val.getType())) @@ -3016,13 +4422,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { if (tostore.getType() != subType) { if (auto prevTy = dyn_cast(tostore.getType())) { if (auto postTy = dyn_cast(subType)) { - bool signedType = true; - if (auto bit = dyn_cast(&*BO->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(BO->getType()); if (prevTy.getWidth() < postTy.getWidth()) { if (signedType) { @@ -3036,20 +4436,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } } } - if (HLSAnnotate) { - if (auto DRE = dyn_cast(BO->getLHS()->IgnoreParenCasts())) { - if (auto VD = dyn_cast(DRE->getDecl())) { - if (auto *defOp = tostore.getDefiningOp()) { - SmallVector existing; - if (auto arr = defOp->getAttrOfType("polygeist.ssa_names")) - existing.append(arr.begin(), arr.end()); - existing.push_back(builder.getStringAttr(VD->getName())); - defOp->setAttr("polygeist.ssa_names", - builder.getArrayAttr(existing)); - } - } - } - } + notifyHLSAssign(BO, tostore); lhs.store(loc, builder, tostore); return lhs; } @@ -3071,41 +4458,27 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { loc, getComplexPart(loc, prev, 1), getComplexPart(loc, rhsV, 1)); result = createComplexFloat(loc, real, imag, BO->getType()) .getValue(loc, builder); - lhs.store(loc, builder, result); + notifyHLSAssign(BO, result); + lhs.store(loc, builder, result); return lhs; } auto prev = lhs.getValue(loc, builder); - if (auto postTy = dyn_cast(prev.getType())) { - mlir::Value rhsV = rhs.getValue(loc, builder); - auto prevTy = rhsV.getType().cast(); - if (prevTy == postTy) { - } else if (prevTy.getWidth() < postTy.getWidth()) { - rhsV = builder.create(loc, postTy, rhsV); - } else { - rhsV = builder.create(loc, postTy, rhsV); - } - assert(rhsV.getType() == prev.getType()); - result = builder.create(loc, prev, rhsV); - } else if (auto pt = - dyn_cast(prev.getType())) { + // An integer or floating LHS (bool, char, _BitInt, float, ...) goes + // through the computation type like every other compound assignment: + // `int += 1.5` is sitofp / addf / fptosi, `bool += 1` stores + // (b + 1) != 0, `float += double` adds in double and rounds the sum. + if (prev.getType().isa()) + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + [&](mlir::Value l, mlir::Value r) -> mlir::Value { + return builder.create(loc, l, r); + }); + if (auto pt = dyn_cast(prev.getType())) { result = builder.create( loc, pt, prev, std::vector({rhs.getValue(loc, builder)})); - } else if (auto postTy = dyn_cast(prev.getType())) { - mlir::Value rhsV = rhs.getValue(loc, builder); - auto prevTy = rhsV.getType().cast(); - if (prevTy == postTy) { - } else if (prevTy.getWidth() < postTy.getWidth()) { - if (signedType) { - rhsV = builder.create(loc, postTy, rhsV); - } else { - rhsV = builder.create(loc, postTy, rhsV); - } - } else { - rhsV = builder.create(loc, postTy, rhsV); - } - assert(rhsV.getType() == prev.getType()); - result = builder.create(loc, prev, rhsV); } else if (auto postTy = dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto shape = std::vector(postTy.getShape()); @@ -3114,11 +4487,13 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { MemRefLayoutAttrInterface(), postTy.getMemorySpace()); auto ptradd = rhsV; - ptradd = castToIndex(loc, ptradd); + ptradd = castToIndex(loc, ptradd, + !isSignedIntegerQualType(BO->getRHS()->getType())); result = builder.create(loc, postTy, prev, ptradd); } else { assert(false && "Unsupported add assign type"); } + notifyHLSAssign(BO, result); lhs.store(loc, builder, result); return lhs; } @@ -3128,29 +4503,18 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } assert(lhs.isReference); auto prev = lhs.getValue(loc, builder); + if (prev.getType().isa()) + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + [&](mlir::Value l, mlir::Value r) -> mlir::Value { + return builder.create(loc, l, r); + }); - mlir::Value result; - if (prev.getType().isa()) { - auto right = rhs.getValue(loc, builder); - if (right.getType() != prev.getType()) { - auto prevTy = right.getType().cast(); - auto postTy = getMLIRType(BO->getType()).cast(); - - if (prevTy.getWidth() < postTy.getWidth()) { - right = builder.create(loc, postTy, right); - } else { - right = builder.create(loc, postTy, right); - } - } - if (right.getType() != prev.getType()) { - BO->dump(); - llvm::errs() << " p:" << prev << " r:" << right << "\n"; - } - assert(right.getType() == prev.getType()); - result = builder.create(loc, prev, right); - } else { - result = builder.create(loc, prev, rhs.getValue(loc, builder)); - } + mlir::Value result = + builder.create(loc, prev, rhs.getValue(loc, builder)); + notifyHLSAssign(BO, result); lhs.store(loc, builder, result); return lhs; } @@ -3160,29 +4524,18 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } assert(lhs.isReference); auto prev = lhs.getValue(loc, builder); + if (prev.getType().isa()) + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + [&](mlir::Value l, mlir::Value r) -> mlir::Value { + return builder.create(loc, l, r); + }); - mlir::Value result; - if (prev.getType().isa()) { - auto right = rhs.getValue(loc, builder); - if (right.getType() != prev.getType()) { - auto prevTy = right.getType().cast(); - auto postTy = getMLIRType(BO->getType()).cast(); - - if (prevTy.getWidth() < postTy.getWidth()) { - right = builder.create(loc, postTy, right); - } else { - right = builder.create(loc, postTy, right); - } - } - if (right.getType() != prev.getType()) { - BO->dump(); - llvm::errs() << " p:" << prev << " r:" << right << "\n"; - } - assert(right.getType() == prev.getType()); - result = builder.create(loc, prev, right); - } else { - result = builder.create(loc, prev, rhs.getValue(loc, builder)); - } + mlir::Value result = + builder.create(loc, prev, rhs.getValue(loc, builder)); + notifyHLSAssign(BO, result); lhs.store(loc, builder, result); return lhs; } @@ -3192,104 +4545,75 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } assert(lhs.isReference); auto prev = lhs.getValue(loc, builder); + if (prev.getType().isa()) + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool isSigned) -> mlir::Value { + if (isSigned) + return builder.create(loc, l, r); + return builder.create(loc, l, r); + }, + [&](mlir::Value l, mlir::Value r) -> mlir::Value { + return builder.create(loc, l, r); + }); mlir::Value result; - if (prev.getType().isa()) { - mlir::Value val = rhs.getValue(loc, builder); - auto prevTy = val.getType().cast(); - auto postTy = prev.getType().cast(); - - if (prevTy.getWidth() < postTy.getWidth()) { - val = builder.create(loc, postTy, val); - } else if (prevTy.getWidth() > postTy.getWidth()) { - val = builder.create(loc, postTy, val); - } - result = builder.create(loc, prev, val); - } else { - if (signedType) - result = builder.create(loc, prev, - rhs.getValue(loc, builder)); - else - result = builder.create(loc, prev, - rhs.getValue(loc, builder)); - } - lhs.store(loc, builder, result); - return lhs; - } - case clang::BinaryOperator::Opcode::BO_ShrAssign: { - assert(lhs.isReference); - auto lhsv = lhs.getValue(loc, builder); - auto rhsv = rhs.getValue(loc, builder); - - mlir::Value result; - - auto prevTy = rhsv.getType().cast(); - auto postTy = lhsv.getType().cast(); - if (prevTy.getWidth() < postTy.getWidth()) - rhsv = builder.create(loc, postTy, rhsv); - if (prevTy.getWidth() > postTy.getWidth()) - rhsv = builder.create(loc, postTy, rhsv); - assert(lhsv.getType() == rhsv.getType()); - if (signedType) - result = builder.create(loc, lhsv, rhsv); + result = + builder.create(loc, prev, rhs.getValue(loc, builder)); else - result = builder.create(loc, lhsv, rhsv); + result = + builder.create(loc, prev, rhs.getValue(loc, builder)); + notifyHLSAssign(BO, result); lhs.store(loc, builder, result); return lhs; } + case clang::BinaryOperator::Opcode::BO_ShrAssign: { + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool isSigned) -> mlir::Value { + if (isSigned) + return builder.create(loc, l, r); + return builder.create(loc, l, r); + }, + nullptr); + } case clang::BinaryOperator::Opcode::BO_ShlAssign: { - assert(lhs.isReference); - auto prev = lhs.getValue(loc, builder); - - mlir::Value result = - builder.create(loc, prev, rhs.getValue(loc, builder)); - lhs.store(loc, builder, result); - return lhs; + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + nullptr); } case clang::BinaryOperator::Opcode::BO_RemAssign: { - assert(lhs.isReference); - auto prev = lhs.getValue(loc, builder); - - mlir::Value result; - - if (prev.getType().isa()) { - result = builder.create(loc, prev, rhs.getValue(loc, builder)); - } else { - if (signedType) - result = builder.create(loc, prev, rhs.getValue(loc, builder)); - else - result = builder.create(loc, prev, rhs.getValue(loc, builder)); - } - lhs.store(loc, builder, result); - return lhs; + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool isSigned) -> mlir::Value { + if (isSigned) + return builder.create(loc, l, r); + return builder.create(loc, l, r); + }, + [&](mlir::Value l, mlir::Value r) -> mlir::Value { + return builder.create(loc, l, r); + }); } case clang::BinaryOperator::Opcode::BO_AndAssign: { - assert(lhs.isReference); - auto prev = lhs.getValue(loc, builder); - - mlir::Value result = - builder.create(loc, prev, rhs.getValue(loc, builder)); - lhs.store(loc, builder, result); - return lhs; + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + nullptr); } case clang::BinaryOperator::Opcode::BO_OrAssign: { - assert(lhs.isReference); - auto prev = lhs.getValue(loc, builder); - - mlir::Value result = - builder.create(loc, prev, rhs.getValue(loc, builder)); - lhs.store(loc, builder, result); - return lhs; + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + nullptr); } case clang::BinaryOperator::Opcode::BO_XorAssign: { - assert(lhs.isReference); - auto prev = lhs.getValue(loc, builder); - - mlir::Value result = - builder.create(loc, prev, rhs.getValue(loc, builder)); - lhs.store(loc, builder, result); - return lhs; + return emitScalarCompound( + [&](mlir::Value l, mlir::Value r, bool) -> mlir::Value { + return builder.create(loc, l, r); + }, + nullptr); } default: { @@ -3315,6 +4639,13 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, assert(FD && "Attempting to lookup field of nullptr"); auto rd = FD->getParent(); + // The member of a scalar wrapper is the object itself. + if (Glob.getScalarWrapperField(rd) == FD) { + if (isLValue) + val = ValueCategory(val, /*isReference*/ true).getValue(loc, builder); + return ValueCategory(val, /*isReference*/ true); + } + auto ST = cast(getLLVMType(CT)); size_t fnum = 0; @@ -3356,6 +4687,23 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, return ValueCategory(sub1, /*isReference*/ true); } auto ET = mt.getElementType(); + if (shape.size() == 1 && + !ET.isa()) { + // A struct whose members share one type is a memref of that type with + // the members as its (only) dimension (CombinedStructABI): a reference + // to one `struct { unsigned long a, b; }` is memref<2xi64>. Member + // `fnum` is the view starting at element fnum, as the rank > 1 case + // above builds after selecting the row (W8b repro r_bfs.c, machsuite + // bfs_bulk: `nodes[n].edge_begin` with `node_t nodes[N]`). + shape[0] = ShapedType::kDynamic; + auto mt1 = mlir::MemRefType::get(shape, ET, MemRefLayoutAttrInterface(), + mt.getMemorySpace()); + mlir::Value sub = builder.create( + loc, mt1, val, getConstantIndex(fnum)); + if (isLValue) + sub = ValueCategory(sub, /*isReference*/ true).getValue(loc, builder); + return ValueCategory(sub, /*isReference*/ true); + } assert(ET.isa() || ET.isa()); val = builder.create( @@ -3473,7 +4821,10 @@ ValueCategory MLIRScanner::VisitDeclRefExpr(DeclRefExpr *E) { if (Glob.getMLIRType(Glob.CGM.getContext().getPointerType(E->getType())) .isa() || name == "stderr" || name == "stdout" || name == "stdin" || - (E->hasQualifier())) { + // A qualified name (`ns::table[i]`, the Vitis math headers' tables) + // is an ordinary global with --xlx-headers; otherwise it keeps the + // LLVM-global path, which cannot index a memref-typed global. + (E->hasQualifier() && !cgeist::hls::xlxHeaders())) { return ValueCategory(builder.create( loc, Glob.GetOrCreateLLVMGlobal(VD)), /*isReference*/ true); @@ -3561,6 +4912,17 @@ ValueCategory MLIRScanner::VisitCXXNoexceptExpr(CXXNoexceptExpr *expr) { ValueCategory MLIRScanner::VisitMemberExpr(MemberExpr *ME) { auto loc = getMLIRLocation(ME->getExprLoc()); + // A static data member named through an object (`obj.N`, Vitis_Libraries + // solver svd.hpp `traits.OFF_DIAG_II`): the member is the variable itself; + // the object expression is not evaluated for a value (it has no side + // effects in the cases met). It used to assert in cast. + if (auto *VD = dyn_cast(ME->getMemberDecl())) { + auto *ref = DeclRefExpr::Create( + Glob.CGM.getContext(), NestedNameSpecifierLoc(), SourceLocation(), VD, + /*RefersToEnclosingVariableOrCapture=*/false, ME->getExprLoc(), + VD->getType(), VK_LValue); + return Visit(ref); + } auto memberName = ME->getMemberDecl()->getName(); if (auto sr2 = dyn_cast(ME->getBase())) { if (auto sr = dyn_cast(sr2->getSourceExpr())) { @@ -3609,6 +4971,13 @@ mlir::Value MLIRScanner::GetAddressOfDerivedClass( CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End) { const ASTContext &Context = Glob.CGM.getContext(); + // Within a scalar-wrapper chain every class is the same scalar. + if (Glob.getScalarWrapperField(DerivedClass)) + return castScalarWrapperRef( + builder, loc, value, + getMLIRType(Context.getLValueReferenceType( + QualType(DerivedClass->getTypeForDecl(), 0)))); + SmallVector ToBase = {DerivedClass}; SmallVector Bases; for (auto I = Start; I != End; I++) { @@ -3625,6 +4994,16 @@ mlir::Value MLIRScanner::GetAddressOfDerivedClass( const auto *BaseDecl = cast(Base->getType()->castAs()->getDecl()); const auto *RD = ToBase[i - 1]; + // A step from a scalar-wrapper base to a wrapper derived class (the + // wrapper part of a path that ends in a class that is not one) is the + // identity: both are the same scalar. + if (Glob.getScalarWrapperField(RD)) { + value = castScalarWrapperRef( + builder, loc, value, + getMLIRType(Context.getLValueReferenceType( + QualType(RD->getTypeForDecl(), 0)))); + continue; + } // Get the layout. const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); assert(!Base->isVirtual() && "Should not see virtual bases here!"); @@ -3697,6 +5076,15 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( for (auto tup : llvm::zip(BaseTypes, BaseVirtuals)) { + // Within a scalar-wrapper chain every class is the same scalar: from the + // first wrapper on the path (the derived class itself, or a wrapper base + // of a class that is not one) the rest of the path is the identity. + if (Glob.getScalarWrapperField(RD)) + return castScalarWrapperRef( + builder, loc, value, + getMLIRType(Glob.CGM.getContext().getPointerType( + QualType(BaseTypes.back(), 0)))); + auto BaseType = std::get<0>(tup); const auto *BaseDecl = @@ -3851,7 +5239,8 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { mlir::Value val = GetAddressOfBaseClass(loc, se.val, Derived, BaseTypes, BaseVirtual); if (E->getCastKind() != clang::CastKind::CK_UncheckedDerivedToBase && - !isa(E->IgnoreParens())) { + !isa(E->IgnoreParens()) && + !Glob.getScalarWrapperField(Derived)) { mlir::Value ptr = val; if (auto MT = dyn_cast(ptr.getType())) ptr = builder.create( @@ -4109,6 +5498,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { case clang::CastKind::CK_LValueToRValue: { if (auto dr = dyn_cast(E->getSubExpr())) { if (auto VD = dyn_cast(dr->getDecl()->getCanonicalDecl())) { + // A const variable with a constant initialiser reads as that + // constant (clang's own constant evaluation): static const members + // such as `static const int F = W - I`, const globals, constexpr + // scalar wrappers. + if (mlir::Value c = tryEmitConstVarValue(loc, VD, E->getType())) + return ValueCategory(c, /*isReference*/ false); if (NOUR_Constant == dr->isNonOdrUse()) { auto VarD = cast(VD); if (!VarD->getInit()) { @@ -4149,16 +5544,34 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { assert(prev.isReference); return ValueCategory(lres, /*isReference*/ false); } + case clang::CastKind::CK_LValueToRValueBitCast: { + // __builtin_bit_cast(To, lvalue): the object representation reread as + // `To`. Between scalars of one width that is an arith.bitcast. + // (--scalar-wrapper-abi only; unhandled as before when the option is off.) + if (!ScalarWrapperABI) { + if (EmittingFunctionDecl) + EmittingFunctionDecl->dump(); + E->dump(); + llvm_unreachable("unhandled cast"); + } + auto se = Visit(E->getSubExpr()); + assert(se.val && "bit_cast operand"); + mlir::Value v = se.getValue(loc, builder); + mlir::Type to = getMLIRType(E->getType()); + if (v.getType() == to) + return ValueCategory(v, /*isReference*/ false); + if (v.getType().isIntOrFloat() && to.isIntOrFloat() && + v.getType().getIntOrFloatBitWidth() == to.getIntOrFloatBitWidth()) + return ValueCategory(builder.create(loc, to, v), + /*isReference*/ false); + E->dump(); + llvm::errs() << "from: " << v.getType() << " to: " << to << "\n"; + llvm_unreachable("unsupported __builtin_bit_cast"); + } case clang::CastKind::CK_IntegralToFloating: { auto scalar = Visit(E->getSubExpr()).getValue(loc, builder); auto ty = getMLIRType(E->getType()).cast(); - bool signedType = true; - if (auto bit = dyn_cast(&*E->getSubExpr()->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(E->getSubExpr()->getType()); if (signedType) return ValueCategory( builder.create(loc, ty, scalar), @@ -4171,13 +5584,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { case clang::CastKind::CK_FloatingToIntegral: { auto scalar = Visit(E->getSubExpr()).getValue(loc, builder); auto ty = getMLIRType(E->getType()).cast(); - bool signedType = true; - if (auto bit = dyn_cast(&*E->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(E->getType()); if (signedType) return ValueCategory( builder.create(loc, ty, scalar), @@ -4206,13 +5613,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { llvm::errs() << " scalar: " << scalar << "\n"; } auto prevTy = scalar.getType().cast(); - bool signedType = true; - if (auto bit = dyn_cast(&*E->getSubExpr()->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(E->getSubExpr()->getType()); if (prevTy == postTy) return ValueCategory(scalar, /*isReference*/ false); @@ -4278,6 +5679,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { loc, postTy, mlir::FloatAttr::get(postTy, Val)), false); } + if (prevTy.getWidth() == postTy.getWidth()) { + // f16 <-> bf16: neither extf nor truncf applies; go through f32. + scalar = builder.create(loc, builder.getF32Type(), scalar); + return ValueCategory(builder.create(loc, postTy, scalar), + /*isReference*/ false); + } if (prevTy.getWidth() < postTy.getWidth()) { return ValueCategory(builder.create(loc, postTy, scalar), /*isReference*/ false); @@ -4321,7 +5728,52 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { return createComplexFloat(loc, real, imag, E->getType()); } case clang::CastKind::CK_ArrayToPointerDecay: { - return CommonArrayToPointer(loc, Visit(E->getSubExpr())); + ValueCategory array = Visit(E->getSubExpr()); + // An array lvalue reached through a pointer to an array (`*__begin` of a + // range-based for over `int (&)[4][8]`, bound to `auto &row`) is that + // pointer, a memref one rank above the array (memref for an + // int[8]); the array is the pointer's row 0. Decaying the pointer itself + // kept the extra rank, and a later `*p` asserted in getValue (CIRCT W9 + // round 8 review defect 8, reproducer rf2.cpp: a nested range-for over + // the rows of a 2-D array reference). + if (auto mt = array.val ? dyn_cast(array.val.getType()) + : MemRefType()) { + // The array's own extents; the memref must be exactly one leading + // (pointer) dimension above them. + // The pointer's dimension is dynamic, and the array's elements are + // scalars of the memref's element type: an array of structs + // (PE pes[3][3] as memref<3x3x3xi32>, the struct's fields the last + // dimension) is not a pointer to an array, whatever its sizes. + llvm::SmallVector extents; + bool constant = true; + clang::QualType elem = E->getSubExpr()->getType(); + while (const clang::ArrayType *AT = elem->getAsArrayTypeUnsafe()) { + auto *CAT = dyn_cast(AT); + if (!CAT) { + constant = false; + break; + } + extents.push_back(CAT->getSize().getSExtValue()); + elem = AT->getElementType(); + } + bool scalarElems = constant && (elem->isBuiltinType() || + elem->isEnumeralType()) && + getMLIRType(elem) == mt.getElementType(); + if (array.isReference && scalarElems && !extents.empty() && + mt.getRank() == static_cast(extents.size()) + 1 && + ShapedType::isDynamic(mt.getShape()[0]) && + mt.getShape().drop_front() == llvm::ArrayRef(extents) && + mt.getLayout().isIdentity()) { + auto row = mlir::MemRefType::get(mt.getShape().drop_front(), + mt.getElementType(), + MemRefLayoutAttrInterface(), + mt.getMemorySpace()); + array = ValueCategory(builder.create( + loc, row, array.val, getConstantIndex(0)), + /*isReference*/ true); + } + } + return CommonArrayToPointer(loc, array); #if 0 auto mt = scalar.val.getType().cast(); @@ -4396,13 +5848,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { loc, CmpIPredicate::ne, res, builder.create(loc, 0, prevTy)); auto postTy = getMLIRType(E->getType()).cast(); - bool signedType = true; - if (auto bit = dyn_cast(&*E->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(E->getType()); if (postTy.getWidth() > 1) { if (signedType) { res = builder.create(loc, postTy, res); @@ -4416,13 +5862,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto res = Visit(E->getSubExpr()).getValue(loc, builder); auto prevTy = res.getType().cast(); auto postTy = getMLIRType(E->getType()).cast(); - bool signedType = true; - if (auto bit = dyn_cast(&*E->getType())) { - if (bit->isUnsignedInteger()) - signedType = false; - if (bit->isSignedInteger()) - signedType = true; - } + bool signedType = isSignedIntegerQualType(E->getType()); auto Zero = builder.create( loc, APFloat::getZero(prevTy.getFloatSemantics()), prevTy); res = builder.create(loc, CmpFPredicate::UNE, res, Zero); @@ -4870,6 +6310,7 @@ MLIRASTConsumer::GetOrCreateLLVMGlobal(const ValueDecl *FD, SymbolTable::setSymbolVisibility(glob, mlir::SymbolTable::Visibility::Private); } + cgeist::hls::onGlobal(VD, glob); return llvmGlobals[name] = glob; } @@ -4880,8 +6321,22 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, name = (PrefixABI + name); + // A global an earlier translation unit created: this unit's declaration + // must reach the HLS pragmas that name it (an ARRAY_PARTITION in a unit + // that only declares the global `extern`, CIRCT OPEN_ISSUES O75, flowgnn + // gin), and when the earlier unit only declared it and this one defines + // it, the global gets this unit's definition (and initializer). + mlir::memref::GlobalOp pendingDefinition; if (globals.find(name) != globals.end()) { - return globals[name]; + auto entry = globals[name]; + const auto *VD0 = dyn_cast(FD); + if (!VD0) + return entry; + cgeist::hls::onGlobal(VD0->getCanonicalDecl(), entry.first); + const VarDecl *def = VD0->getDefinition(); + if (!def || entry.first.getInitialValue()) + return entry; + pendingDefinition = entry.first; } bool isArray = false; @@ -4897,6 +6352,10 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, mr = mlir::MemRefType::get(shape, mr.getElementType(), MemRefLayoutAttrInterface(), wrapIntegerMemorySpace(memspace, mr.getContext())); + // A definition whose type differs from the earlier declaration's (an + // `extern T a[];` of unknown size): the uses already have that type. + if (pendingDefinition && pendingDefinition.getType() != mr) + return globals[name]; mlir::SymbolTable::Visibility lnk; mlir::Attribute initial_value; @@ -4908,15 +6367,25 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, if (!VD) FD->dump(); VD = VD->getCanonicalDecl(); - - if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { + // The declaration that defines the global in this unit, when there is one: + // the canonical (first) declaration is an `extern` one when a header + // declares the global before the unit defines it, and its definition and + // initializer must not be lost (`extern int W[4]; int W[4] = {...};` gave a + // bare declaration; W9r7 review defect 2). + const VarDecl *DefVD = VD->getDefinition(); + if (!DefVD) + DefVD = VD->getActingDefinition(); + if (!DefVD) + DefVD = VD; + + if (DefVD->isThisDeclarationADefinition() == VarDecl::Definition) { initial_value = builder.getUnitAttr(); - } else if (VD->isThisDeclarationADefinition() == + } else if (DefVD->isThisDeclarationADefinition() == VarDecl::TentativeDefinition) { initial_value = builder.getUnitAttr(); } - switch (CGM.getLLVMLinkageVarDefinition(VD)) { + switch (CGM.getLLVMLinkageVarDefinition(DefVD)) { case llvm::GlobalValue::LinkageTypes::InternalLinkage: lnk = mlir::SymbolTable::Visibility::Private; break; @@ -4952,11 +6421,17 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, break; } - auto globalOp = builder.create( - module->getLoc(), builder.getStringAttr(name), - /*sym_visibility*/ mlir::StringAttr(), mlir::TypeAttr::get(mr), - initial_value, mlir::UnitAttr(), /*alignment*/ nullptr); - SymbolTable::setSymbolVisibility(globalOp, lnk); + mlir::memref::GlobalOp globalOp = pendingDefinition; + if (globalOp) { + if (initial_value) + globalOp.setInitialValueAttr(initial_value); + } else { + globalOp = builder.create( + module->getLoc(), builder.getStringAttr(name), + /*sym_visibility*/ mlir::StringAttr(), mlir::TypeAttr::get(mr), + initial_value, mlir::UnitAttr(), /*alignment*/ nullptr); + SymbolTable::setSymbolVisibility(globalOp, lnk); + } // TODO we should probably set the mem spaces here? But I am not sure that // works well with our one-module representation because the host-side "stubs" @@ -4969,9 +6444,10 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, } globals[name] = std::make_pair(globalOp, isArray); + cgeist::hls::onGlobal(VD, globalOp); if (tryInit) - if (auto init = VD->getInit()) { + if (auto init = initSkippingCleanups(DefVD)) { MLIRScanner ms(*this, module, LTInfo); mlir::Block *B = new Block(); ms.setEntryAndAllocBlock(B); @@ -4980,7 +6456,22 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, auto op = builder.create(module->getLoc(), mr); bool initialized = false; - if (isa(init)) { + // clang's constant evaluation first (--scalar-wrapper-abi): it folds + // `static const int F = W - I`, scalar-wrapper globals with constexpr + // constructors and their arrays (`const ap_fixed tbl[4] = {...}` + // becomes a dense initial value), which the expression visitor below + // cannot. + if (auto dense = evaluateConstantInitializer(VD, mr)) { + initial_value = dense; + initialized = true; + } else if (auto dense = + evaluateXlxStringInitializer(init, VD->getType(), mr)) { + // --xlx-headers: a table of string constructions. + initial_value = dense; + initialized = true; + } + if (initialized) { + } else if (isa(init)) { if (auto A = ms.InitializeValueByInitListExpr( op, const_cast(init))) { initialized = true; @@ -4999,10 +6490,24 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, } } - if (!initialized) { - FD->dump(); - init->dump(); - llvm::errs() << " warning not initializing global: " << name << "\n"; + // An array of structs (or a struct): memref.global cannot hold a + // value of llvm.struct elements, so the constant goes into + // `hls.struct_initial_value`, one attribute per scalar in memory order + // (elements, then members depth-first), which hls-est's + // --split-struct-memrefs turns into the initial values of the + // per-member memories. + mlir::ArrayAttr structInit; + if (!initialized && + (structInit = evaluateStructInitializer(VD, init, mr))) { + globalOp->setAttr("hls.struct_initial_value", structInit); + } else if (!initialized) { + if (!(HLSDynamicGlobalInit && + emitDynamicInitializer(DefVD, init, globalOp, isArray))) { + FD->dump(); + init->dump(); + llvm::errs() << " warning not initializing global: " << name + << "\n"; + } } else { globalOp.setInitialValueAttr(initial_value); } @@ -5012,6 +6517,58 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix, return globals[name]; } +bool MLIRASTConsumer::emitDynamicInitializer(const VarDecl *VD, + const Expr *init, + mlir::memref::GlobalOp global, + bool isArray) { + using namespace mlir; + // An initializer list of non-constant elements and a reference are left + // to the warning: only one value is computed and stored here. + if (isArray || isa(init) || VD->getType()->isReferenceType()) + return false; + MemRefType mt = global.getType(); + if (mt.getRank() < 1) + return false; + std::string fname = ("__hls_global_init." + global.getSymName()).str(); + if (module->lookupSymbol(fname)) + return true; + Location loc = getMLIRLocation(VD->getLocation()); + OpBuilder mb(module->getContext()); + mb.setInsertionPointToEnd(module->getBody()); + auto fn = mb.create(loc, fname, mb.getFunctionType({}, {})); + // The declaration's position orders the initializers as C++ does within a + // translation unit (check_semantics runs them in that order). + fn->setAttr("hls.global_init", + mb.getI64IntegerAttr(static_cast( + VD->getLocation().getRawEncoding()))); + Block *entry = fn.addEntryBlock(); + MLIRScanner ms(*this, module, LTInfo); + ms.setEntryAndAllocBlock(entry); + OpBuilder &b = ms.getBuilder(); + ValueCategory vc = ms.Visit(const_cast(init)); + // A reference is loaded only when it names one element (a class object + // of an array type, or an array, is not one value). + auto refTy = vc.val && vc.isReference ? dyn_cast(vc.val.getType()) + : MemRefType(); + bool oneElement = refTy && refTy.getRank() == 1 && + (refTy.getShape()[0] == 1 || refTy.isDynamicDim(0)); + mlir::Value v = !vc.val ? mlir::Value() + : !vc.isReference ? vc.val + : oneElement && refTy.getElementType() == mt.getElementType() + ? vc.getValue(loc, b) + : mlir::Value(); + if (!v || v.getType() != mt.getElementType()) { + fn.erase(); + return false; + } + auto gv = b.create(loc, mt, global.getName()); + mlir::Value zero = b.create(loc, 0); + llvm::SmallVector idx(mt.getRank(), zero); + b.create(loc, v, gv, idx); + b.create(loc); + return true; +} + mlir::Value MLIRASTConsumer::GetOrCreateGlobalLLVMString( mlir::Location loc, mlir::OpBuilder &builder, StringRef value) { using namespace mlir; @@ -5034,8 +6591,9 @@ mlir::Value MLIRASTConsumer::GetOrCreateGlobalLLVMString( } mlir::func::FuncOp -MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, - bool getDeviceStub) { +MLIRASTConsumer::GetOrCreateMLIRFunction( + const FunctionDecl *FD, bool getDeviceStub, + const clang::CXXRecordDecl *xlxStreamObject) { assert(FD->getTemplatedKind() != FunctionDecl::TemplatedKind::TK_FunctionTemplate); assert( @@ -5052,12 +6610,51 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, else name = CGM.getMangledName(FD).str(); + // (--xlx-headers) A member of hls::stream is never emitted: every call is + // an external call, as with the stand-in headers. A member inherited from + // hls::stream and called on an hls::stream object is named as + // a member of the object's class, so that the name carries D (the + // stand-in's hls::stream declares every member itself). + const auto *streamMember = dyn_cast(FD); + bool xlxStream = streamMember && isXlxStreamClass(streamMember->getParent()); + if (xlxStream && xlxStreamObject && + xlxStreamObject != streamMember->getParent() && + isXlxStreamClass(xlxStreamObject)) { + // The class's part of the mangled name: the RTTI name of the class is + // `_ZTI` + its nested name (`N3hls6streamIiLi0EEE`), which the member's + // name (`_ZN3hls6streamIiLi0EE4readEv`, `_ZNK...`) contains without the + // closing `E`. Substitution indices are the same for both classes (the + // depth literal is no substitution candidate). + auto classPart = [&](const clang::CXXRecordDecl *rd) { + std::string rtti; + llvm::raw_string_ostream os(rtti); + std::unique_ptr mc( + CGM.getContext().createMangleContext()); + mc->mangleCXXRTTI(CGM.getContext().getRecordType(rd), os); + os.flush(); + StringRef r(rtti); + if (!r.consume_front("_ZTIN") || !r.consume_back("E")) + return std::string(); + return r.str(); + }; + std::string from = classPart(streamMember->getParent()); + std::string to = classPart(xlxStreamObject); + StringRef n(name); + for (StringRef head : {"_ZN", "_ZNK"}) + if (!from.empty() && !to.empty() && n.starts_with((head + from).str())) { + name = (head + to + n.drop_front(head.size() + from.size())).str(); + break; + } + } + name = (PrefixABI + name); assert(name != "free"); + + llvm::GlobalValue::LinkageTypes LV; - if (!FD->hasBody()) + if (!FD->hasBody() || xlxStream) LV = llvm::GlobalValue::LinkageTypes::ExternalLinkage; else if (auto CC = dyn_cast(FD)) LV = CGM.getFunctionLinkage(GlobalDecl(CC, CXXCtorType::Ctor_Complete)); @@ -5104,13 +6701,13 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, } const FunctionDecl *Def = nullptr; - if (!FD->isDefined(Def, /*checkforfriend*/ true)) + if (xlxStream || !FD->isDefined(Def, /*checkforfriend*/ true)) Def = FD; if (functions.find(name) != functions.end()) { auto function = functions[name]; - if (Def->isThisDeclarationADefinition()) { + if (!xlxStream && Def->isThisDeclarationADefinition()) { if (LV == llvm::GlobalValue::InternalLinkage || LV == llvm::GlobalValue::PrivateLinkage || !Def->isDefined() || Def->hasAttr() || Def->hasAttr()) { @@ -5212,18 +6809,34 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, mlir::OpBuilder builder(module->getContext()); auto funcType = builder.getFunctionType(types, rettypes); + + mlir::func::FuncOp function = mlir::func::FuncOp(mlir::func::FuncOp::create( getMLIRLocation(FD->getLocation()), name, funcType)); - - if ((FD->hasAttr() || FD->hasAttr()) && - !FD->hasAttr()) { - function->setAttr("polygeist.device_only_func", - StringAttr::get(builder.getContext(), "1")); - } - + + if (HLSAnnotate) + function->setAttr("hls.orig_name", + StringAttr::get(builder.getContext(), FD->getNameAsString())); + // (--xlx-headers) A member of hls::stream: the bits Vitis packs T + // into, which the IR type cannot tell (`bool` is an i8 there; Vitis packs + // a struct of a float and a bool into 33 bits, VITIS_NOTES N58, kernels + // w9r7_sb_*). hls-est's FIFO model reads it. + if (HLSAnnotate && xlxStream) { + const auto *spec = dyn_cast( + streamMember->getParent()); + if (spec && spec->getTemplateArgs().size() >= 1 && + spec->getTemplateArgs()[0].getKind() == clang::TemplateArgument::Type) + if (std::optional bits = + packedStreamBits(spec->getTemplateArgs()[0].getAsType())) + if (*bits > 0) + function->setAttr("hls.stream_element_bits", + builder.getI64IntegerAttr(*bits)); + } + if (LV == llvm::GlobalValue::InternalLinkage || LV == llvm::GlobalValue::PrivateLinkage || !FD->isDefined() || - FD->hasAttr() || FD->hasAttr()) { + xlxStream || FD->hasAttr() || + FD->hasAttr()) { SymbolTable::setSymbolVisibility(function, SymbolTable::Visibility::Private); } else { @@ -5237,7 +6850,7 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, functions[name] = function; module->push_back(function); - if (Def->isThisDeclarationADefinition()) { + if (!xlxStream && Def->isThisDeclarationADefinition()) { assert(Def->getTemplatedKind() != FunctionDecl::TemplatedKind::TK_FunctionTemplate); assert(Def->getTemplatedKind() != @@ -5251,10 +6864,48 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, return function; } +namespace { +/// Finds an expression clang's error recovery left in a function body (a +/// RecoveryExpr, or any expression built on one: a use of an undeclared +/// name, a call that matched no overload). +class ErrorExprFinder : public clang::RecursiveASTVisitor { +public: + bool found = false; + bool VisitExpr(clang::Expr *e) { + if (e->containsErrors()) { + found = true; + return false; + } + return true; + } +}; +} // namespace + +/// A function clang's semantic analysis rejected: an invalid declaration (an +/// unknown parameter type) or a body with error-recovery expressions. Its +/// errors are already reported and cgeist exits with a failure; emitting it +/// asserted in the emitter (ValueCategory::getValue). Clang's own CodeGen +/// emits nothing for a translation unit with errors; cgeist still emits the +/// valid functions, whose HLS pragma diagnostics are reported during +/// emission. +static bool hasSemanticErrors(const FunctionDecl *fd) { + if (fd->isInvalidDecl()) + return true; + const FunctionDecl *def = nullptr; + if (!fd->hasBody(def) || !def->getBody()) + return false; + ErrorExprFinder finder; + finder.TraverseStmt(def->getBody()); + return finder.found; +} + void MLIRASTConsumer::run() { while (functionsToEmit.size()) { const FunctionDecl *FD = functionsToEmit.front(); functionsToEmit.pop_front(); + if (astContext.getDiagnostics().hasErrorOccurred() && + hasSemanticErrors(FD)) + continue; assert(FD->getTemplatedKind() != FunctionDecl::TK_FunctionTemplate); assert(FD->getTemplatedKind() != FunctionDecl::TemplatedKind:: @@ -5277,6 +6928,19 @@ void MLIRASTConsumer::run() { } } + +/// Whether `--function=` names `fd` by its source name (`top`, or the +/// qualified `ns::top`) rather than its mangled one: the HLS top of a C++ +/// design is given by its source name, as Vitis' `set_top` takes it. Every +/// overload of that name is emitted. +static bool isRequestedBySourceName(const FunctionDecl *fd, + const std::set &requested) { + if (!fd->getIdentifier()) + return false; + return requested.count(fd->getName().str()) || + requested.count(fd->getQualifiedNameAsString()); +} + void MLIRASTConsumer::HandleDeclContext(DeclContext *DC) { for (auto D : DC->decls()) { @@ -5307,6 +6971,13 @@ void MLIRASTConsumer::HandleDeclContext(DeclContext *DC) { if (fd->isTemplated()) { continue; } + // (--xlx-headers) A member of hls::stream is never emitted, also when an + // earlier translation unit's external call put its name in emitIfFound + // and this unit holds its definition (CIRCT OPEN_ISSUES O193: flowgnn/dgn, + // `operator<<` / `write` of hls::stream> got + // their synthesis bodies, __fpga_fifo_push, in a three-unit compile). + if (isXlxStreamMember(fd)) + continue; bool externLinkage = true; /* @@ -5342,7 +7013,7 @@ void MLIRASTConsumer::HandleDeclContext(DeclContext *DC) { if ((emitIfFound.count("*") && name != "fpclassify" && !fd->isStatic() && externLinkage) || - emitIfFound.count(name)) { + emitIfFound.count(name) || isRequestedBySourceName(fd, emitIfFound)) { functionsToEmit.push_back(fd); } else { } @@ -5382,6 +7053,13 @@ bool MLIRASTConsumer::HandleTopLevelDecl(DeclGroupRef dg) { if (fd->isTemplated()) { continue; } + // (--xlx-headers) A member of hls::stream is never emitted, also when an + // earlier translation unit's external call put its name in emitIfFound + // and this unit holds its definition (CIRCT OPEN_ISSUES O193: flowgnn/dgn, + // `operator<<` / `write` of hls::stream> got + // their synthesis bodies, __fpga_fifo_push, in a three-unit compile). + if (isXlxStreamMember(fd)) + continue; bool externLinkage = true; /* @@ -5417,7 +7095,7 @@ bool MLIRASTConsumer::HandleTopLevelDecl(DeclGroupRef dg) { if ((emitIfFound.count("*") && name != "fpclassify" && !fd->isStatic() && externLinkage) || - emitIfFound.count(name)) { + emitIfFound.count(name) || isRequestedBySourceName(fd, emitIfFound)) { functionsToEmit.push_back(fd); } else { } @@ -5428,7 +7106,82 @@ bool MLIRASTConsumer::HandleTopLevelDecl(DeclGroupRef dg) { // Wait until Sema has instantiated all the relevant code // before running codegen on the selected functions. -void MLIRASTConsumer::HandleTranslationUnit(ASTContext &C) { run(); } +// Set by parseMLIR: the module is built from more than one translation unit. +static bool gSeveralTranslationUnits = false; +// The mark of a global emitUnusedDefinitions created; eraseUnusedDefinitions +// removes it, and the global when nothing uses it. +static constexpr llvm::StringLiteral kUnusedDefinitionAttr = + "cgeist.unused_definition"; + +void MLIRASTConsumer::HandleTranslationUnit(ASTContext &C) { + cgeist::hls::checkTranslationUnit(C); + if (cgeist::hls::checkOnly()) + cgeist::hls::checkAllFunctions(C); // no code generation + else { + run(); + if (gSeveralTranslationUnits) + emitUnusedDefinitions(C.getTranslationUnitDecl()); + } + cgeist::hls::endTranslationUnit(); +} + +void MLIRASTConsumer::emitUnusedDefinitions(clang::DeclContext *DC) { + for (clang::Decl *D : DC->decls()) { + if (isa(D)) { + emitUnusedDefinitions(cast(D)); + continue; + } + auto *V = dyn_cast(D); + // Only a definition another unit can name: external linkage, at file or + // namespace scope, of a concrete type. + if (!V || V->isThisDeclarationADefinition() == VarDecl::DeclarationOnly || + !V->isFileVarDecl() || !V->hasExternalFormalLinkage() || + V->isTemplated() || V->getType()->isDependentType() || + V->getType()->isReferenceType() || V->isInvalidDecl()) + continue; + std::string name = PrefixABI + CGM.getMangledName(V).str(); + auto found = globals.find(name); + if (found != globals.end()) { + // An earlier unit's declaration: this definition completes it. + if (!found->second.first.getInitialValue()) + GetOrCreateGlobal(V, /*prefix=*/""); + continue; + } + // A new global: only memories of integers and floats with a constant (or + // no) initializer, the tables and weights a design keeps in another + // file; objects with constructors (streams, std::complex) stay out. + const clang::Type *base = V->getType()->getBaseElementTypeUnsafe(); + if (const auto *RT = base->getAs()) + if (isXlxStreamClass(RT->getDecl())) + continue; + if (const Expr *init = V->getInit()) + if (!init->isConstantInitializer(CGM.getContext(), false)) + continue; + auto mr = getMLIRType(CGM.getContext().getLValueReferenceType(V->getType())) + .dyn_cast(); + if (!mr || !mr.getElementType().isIntOrFloat()) + continue; + auto created = GetOrCreateGlobal(V, /*prefix=*/""); + if (created.first) + created.first->setAttr(kUnusedDefinitionAttr, + mlir::UnitAttr::get(module->getContext())); + } +} + +// After the last translation unit: the definitions emitUnusedDefinitions +// created that no unit used go away again, so that only the globals a +// function names are in the module, as with one unit. +static void eraseUnusedDefinitions(mlir::ModuleOp module) { + for (auto g : llvm::make_early_inc_range( + module.getBody()->getOps())) { + if (!g->hasAttr(kUnusedDefinitionAttr)) + continue; + g->removeAttr(kUnusedDefinitionAttr); + if (mlir::SymbolTable::symbolKnownUseEmpty(g, module)) + g.erase(); + } +} mlir::Location MLIRASTConsumer::getMLIRLocation(clang::SourceLocation loc) { auto spellingLoc = SM.getSpellingLoc(loc); @@ -5448,7 +7201,11 @@ static void getConstantArrayShapeAndElemType(const clang::QualType &ty, clang::QualType curTy = ty; while (curTy->isConstantArrayType()) { - auto cstArrTy = cast(curTy); + // Through type sugar: the deduced `auto &&__range` of a range-based for + // over an `int (&)[8]` parameter is an array type behind an AutoType + // (before, cast asserted; OPEN_ISSUES O91, + // reproducer c_rangefor.cpp). + auto cstArrTy = cast(curTy->getAsArrayTypeUnsafe()); shape.push_back(cstArrTy->getSize().getSExtValue()); curTy = cstArrTy->getElementType(); } @@ -5541,7 +7298,20 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, clang::QualType elemTy; getConstantArrayShapeAndElemType(origTy, shape, elemTy); - return mlir::MemRefType::get(shape, getMLIRType(elemTy)); + // A struct whose members share one type is itself a memref + // (CombinedStructABI: `struct { unsigned long a, b; }` is + // memref<2xi64>); the array of them adds its dimensions in front, + // as the non-full-rank path below does (memref), instead + // of a memref of memrefs (W8b repro r_bfs.c, machsuite bfs_bulk / + // bfs_queue: `node_t nodes[N]` became memref>). + mlir::Type elemMLIR = getMLIRType(elemTy); + if (auto inner = dyn_cast(elemMLIR)) { + if (inner.hasStaticShape() && inner.getLayout().isIdentity()) { + shape.append(inner.getShape().begin(), inner.getShape().end()); + return mlir::MemRefType::get(shape, inner.getElementType()); + } + } + return mlir::MemRefType::get(shape, elemMLIR); } } @@ -5576,6 +7346,14 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, RT->dump(); } assert(!RT->getDecl()->isInvalidDecl()); + // (--xlx-headers) An hls::stream is an i32 handle, the stand-in + // headers' `int` member. + if (isXlxStreamClass(RT->getDecl())) + return mlir::IntegerType::get(module->getContext(), 32); + // A scalar wrapper is its member (ap_fixed<16,5> -> i16). implicitRef + // stays false: the value is a scalar, not an aggregate. + if (const clang::FieldDecl *WF = getScalarWrapperField(RT->getDecl())) + return getMLIRType(WF->getType(), /*implicitRef*/ nullptr, allowMerge); if (typeCache.find(RT) != typeCache.end()) return typeCache[RT]; llvm::Type *LT = CGM.getTypes().ConvertType(qt); @@ -5645,6 +7423,13 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, return typeCache[RT]; } + // With opaque LLVM pointers every pointer or reference field has the same + // LLVM type, so `notAllSame` cannot tell `A &a; B &b;` apart (the Vitis + // headers' ap_concat_ref): compare the MLIR field types as well. Only + // with --xlx-headers, which leaves other inputs unchanged. + if (cgeist::hls::xlxHeaders()) + for (mlir::Type t : types) + notAllSame |= t != types[0]; if (!memRefABI || notAllSame || !allowMerge || innerLLVM) { auto retTy = mlir::LLVM::LLVMStructType::getLiteral(module->getContext(), types); @@ -5834,6 +7619,17 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, return mlir::MemRefType::get({outer}, subType); } + if (auto BIT = dyn_cast(t)) { + // _BitInt(N) / unsigned _BitInt(N): a signless iN like the other ints. + mlir::OpBuilder builder(module->getContext()); + return builder.getIntegerType(BIT->getNumBits()); + } + + // std::nullptr_t (a parameter or temporary of type decltype(nullptr)): a + // null pointer, as clang's CodeGen gives it (an i8* in LLVM IR). + if (t->isNullPtrType()) + return LLVM::LLVMPointerType::get( + mlir::IntegerType::get(module->getContext(), 8)); if (t->isBuiltinType() || isa(t)) { if (t->isBooleanType()) { OpBuilder builder(module->getContext()); @@ -5850,6 +7646,10 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, if (T->isDoubleTy()) { return builder.getF64Type(); } + if (T->isHalfTy()) // _Float16 (and __fp16 storage) + return builder.getF16Type(); + if (T->isBFloatTy()) // __bf16 + return builder.getBF16Type(); if (T->isX86_FP80Ty()) return builder.getF80Type(); if (T->isFP128Ty()) @@ -5873,7 +7673,9 @@ llvm::Type *MLIRASTConsumer::getLLVMType(clang::QualType t) { #include "llvm/TargetParser/Host.h" +#include "HLSAutoInline.h" #include "clang/Frontend/FrontendAction.h" +#include "clang/Frontend/MultiplexConsumer.h" class MLIRAction : public clang::ASTFrontendAction { public: std::set emitIfFound; @@ -5890,10 +7692,19 @@ class MLIRAction : public clang::ASTFrontendAction { } std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override { - return std::unique_ptr(new MLIRASTConsumer( + std::unique_ptr consumer(new MLIRASTConsumer( emitIfFound, done, llvmStringGlobals, globals, functions, llvmGlobals, llvmFunctions, CI.getPreprocessor(), CI.getASTContext(), module, CI.getSourceManager(), CI.getCodeGenOpts())); + if (!cgeist::hls::autoInlineEnabled()) + return consumer; + // Vitis's automatic inlining needs clang's own LLVM IR for the sizes + // (HLSAutoInline.h); cgeist's consumer first, so that its pragma sema + // has recorded the unroll pragmas when the sizes are measured. + std::vector> consumers; + consumers.push_back(std::move(consumer)); + consumers.push_back(cgeist::hls::createInlineSizeConsumer(CI, InFile)); + return std::make_unique(std::move(consumers)); } }; @@ -5950,6 +7761,7 @@ mlir::Value MLIRScanner::getTypeAlign(mlir::Location loc, clang::QualType t) { } #include "clang/Frontend/TextDiagnosticBuffer.h" +#include "XlxPrelude.inc" static bool parseMLIR(const char *Argv0, std::vector filenames, std::string fn, std::vector includeDirs, @@ -6030,6 +7842,10 @@ static bool parseMLIR(const char *Argv0, std::vector filenames, Argv.push_back("-include"); Argv.emplace_back(Include); } + for (const auto &Arg : XclangArgs) { + Argv.push_back("-Xclang"); + Argv.emplace_back(Arg); + } Argv.push_back("-emit-ast"); @@ -6040,6 +7856,7 @@ static bool parseMLIR(const char *Argv0, std::vector filenames, return false; MLIRAction Act(fn, module); + gSeveralTranslationUnits = Jobs.size() > 1; for (auto &job : Jobs) { std::unique_ptr Clang(new CompilerInstance()); @@ -6053,6 +7870,18 @@ static bool parseMLIR(const char *Argv0, std::vector filenames, Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(), *args, Diags); Clang->getInvocation().getFrontendOpts().DisableFree = false; + if (XlxPrelude) { + // A virtual file (absolute, so that the include lookup finds it), + // included after every -include file. + static const char *const kXlxPreludeName = + "/cgeist-builtin-include/xlx/xlx_prelude.h"; + PreprocessorOptions &PPOpts = Clang->getPreprocessorOpts(); + PPOpts.Includes.push_back(kXlxPreludeName); + PPOpts.addRemappedFile( + kXlxPreludeName, + llvm::MemoryBuffer::getMemBuffer(kXlxPreludeText, kXlxPreludeName) + .release()); + } void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath; // Infer the builtin include path if unspecified. @@ -6176,5 +8005,6 @@ static bool parseMLIR(const char *Argv0, std::vector filenames, return false; } } + eraseUnusedDefinitions(module.get()); return true; } diff --git a/tools/cgeist/Lib/clang-mlir.h b/tools/cgeist/Lib/clang-mlir.h index ccc4029ef60a..c991995b74dc 100644 --- a/tools/cgeist/Lib/clang-mlir.h +++ b/tools/cgeist/Lib/clang-mlir.h @@ -26,8 +26,7 @@ #include "mlir/Target/LLVMIR/TypeToLLVM.h" #include "polygeist/Ops.h" #include "pragmaHandler.h" -#include "pragmaHandlerHLS.h" -#include "HandleHLS.h" +#include "HLSPragma.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/StmtVisitor.h" #include "clang/Lex/HeaderSearch.h" @@ -48,6 +47,9 @@ extern llvm::cl::opt PrefixABI; extern llvm::cl::opt HLSAnnotate; +// --scalar-wrapper-abi (default off), defined in clang-mlir.cc. +extern llvm::cl::opt ScalarWrapperABI; + struct LoopContext { mlir::Value keepRunning; mlir::Value noBreak; @@ -97,10 +99,11 @@ struct MLIRASTConsumer : public ASTConsumer { PP.getPreprocessorOpts(), codegenops, llvmMod, PP.getDiagnostics()), error(false), typeTranslator(*module->getContext()), reverseTypeTranslator(lcontext) { + addPragmaScopHandlers(PP, scopLocList); addPragmaEndScopHandlers(PP, scopLocList); addPragmaLowerToHandlers(PP, LTInfo); - addPragmaHLSHandlers(PP); + cgeist::hls::beginTranslationUnit(PP, module->getContext()); } ~MLIRASTConsumer() {} @@ -110,8 +113,28 @@ struct MLIRASTConsumer : public ASTConsumer { mlir::OpBuilder(module->getContext()).getI8Type()); } - mlir::func::FuncOp GetOrCreateMLIRFunction(const FunctionDecl *FD, - bool getDeviceStub = false); + /// `xlxStreamObject` (--xlx-headers): the static class of the object a + /// member of hls::stream is called on, when that is a class derived from + /// the member's own class (hls::stream over hls::stream); the + /// external function is then named as a member of that class. + mlir::func::FuncOp + GetOrCreateMLIRFunction(const FunctionDecl *FD, bool getDeviceStub = false, + const clang::CXXRecordDecl *xlxStreamObject = nullptr); + + /// --xlx-headers: whether `RD` is a specialisation of the Vitis HLS class + /// template hls::stream (hls_stream_39.h, ap_axi_sdata.h). Such an object + /// is an i32 handle and its members are external functions, as with the + /// stand-in headers (shim/exactclass hls_stream.h), whose IR form hls-est's + /// FIFO model reads (StreamFifos.cpp, VITIS_NOTES N31). + bool isXlxStreamClass(const clang::RecordDecl *RD) const; + /// A member function of an hls::stream class (isXlxStreamClass): never + /// emitted, every call stays an external call. + bool isXlxStreamMember(const clang::FunctionDecl *FD) const; + /// The bits Vitis packs a value of `T` into on a stream (VITIS_NOTES N58): + /// a struct is the sum of its members' (bases first, no padding), `bool` + /// is 1 bit, an array n x its element, anything else the width of the + /// MLIR type cgeist gives it. None for a type with no such width. + std::optional packedStreamBits(clang::QualType T); mlir::LLVM::LLVMFuncOp GetOrCreateLLVMFunction(const FunctionDecl *FD); mlir::LLVM::LLVMFuncOp GetOrCreateFreeFunction(); @@ -131,17 +154,66 @@ struct MLIRASTConsumer : public ASTConsumer { GetOrCreateGlobal(const ValueDecl *VD, std::string prefix, bool tryInit = true); + /// A global whose initializer is not a constant cgeist can evaluate: a + /// function `__hls_global_init.` that computes it and stores it + /// (C++'s dynamic initialization, which runs before main), marked + /// `hls.global_init` with the declaration's source position. False when + /// the initializer cannot be emitted that way. + bool emitDynamicInitializer(const clang::VarDecl *VD, const clang::Expr *init, + mlir::memref::GlobalOp global, bool isArray); + std::deque functionsToEmit; void run(); void HandleTranslationUnit(clang::ASTContext &Context) override; + // Several translation units: the global definitions of this unit that no + // emitted function used, so that a unit that only declares them (`extern`) + // still gets their storage and initializer (CIRCT OPEN_ISSUES O75; W9r7 + // review defect 2). Unused ones are removed after the last unit + // (eraseUnusedDefinitions). + void emitUnusedDefinitions(clang::DeclContext *DC); + bool HandleTopLevelDecl(DeclGroupRef dg) override; void HandleDeclContext(DeclContext *DC); std::map typeCache; + + /// Scalar wrappers (--scalar-wrapper-abi): a record whose only data member, + /// through any chain of single-base classes without members of their own, + /// is one scalar (integer, _BitInt, enum, floating). Such a record is + /// lowered to that scalar: ap_fixed<16,5> is an i16, `this` / references + /// are memref, arrays memref<...xi16>. Returns the member, or null + /// when the record is not a wrapper. Memoised. + llvm::DenseMap + scalarWrapperCache; + const clang::FieldDecl *getScalarWrapperField(const clang::RecordDecl *RD); + + /// --scalar-wrapper-abi: the initial value of the variable `VD` of memref + /// type `mr` as clang's constant evaluation of its initialiser (scalars, + /// arrays, scalar wrappers and their arrays), or null when it is not a + /// compile-time constant of that shape (or the option is off). + mlir::DenseElementsAttr evaluateConstantInitializer(const clang::VarDecl *VD, + mlir::MemRefType mr); + /// --xlx-headers (with --scalar-wrapper-abi): the initialiser `init` of an + /// object of type `type` as the dense value of `mr`, when its leaves are + /// scalar wrappers constructed from string literals (folded as by the Vitis + /// front end, XlxStringBits.cc), ap types constructed from a numeric + /// constant (foldNumericConstruct) or integer constants, and at least one + /// is not a plain integer constant; null otherwise or when the options are + /// off. + mlir::DenseElementsAttr evaluateXlxStringInitializer(const clang::Expr *init, + clang::QualType type, + mlir::MemRefType mr); + /// --scalar-wrapper-abi: the initial value of the global `VD` whose + /// memref `mr` has llvm.struct elements, as one attribute per scalar in + /// memory order (clang's constant evaluation, or the --xlx-headers folds of + /// ap constructions); null when it is not such a constant. + mlir::ArrayAttr evaluateStructInitializer(const clang::VarDecl *VD, + const clang::Expr *init, + mlir::MemRefType mr); mlir::Type getMLIRType(clang::QualType t, bool *implicitRef = nullptr, bool allowMerge = true); @@ -189,6 +261,20 @@ class MLIRScanner : public StmtVisitor { mlir::Value getTypeSize(mlir::Location loc, clang::QualType t); mlir::Value getTypeAlign(mlir::Location loc, clang::QualType t); + /// The constant a load of the const variable `VD` yields (clang's + /// constant evaluation of its initialiser), as an arith.constant of the + /// MLIR type of `resultType`, or null when it is not a compile-time + /// constant scalar. + mlir::Value tryEmitConstVarValue(mlir::Location loc, const VarDecl *VD, + clang::QualType resultType); + + /// Value-initialisation of scalar-wrapper objects of type `T` at the + /// reference `op` (--scalar-wrapper-abi): one zero store per object, a + /// loop per array dimension of `T` (the outermost runs `count` times + /// when given, as for `new T[n]()`). + void storeZeroToWrapperObjects(mlir::Location loc, mlir::Value op, + clang::QualType T, mlir::Value count); + mlir::Value createAllocOp(mlir::Type t, VarDecl *name, uint64_t memspace, bool isArray, bool LLVMABI); @@ -196,9 +282,10 @@ class MLIRScanner : public StmtVisitor { mlir::func::FuncOp EmitDirectCallee(const FunctionDecl *FD); - std::map constants; + std::map constants; - mlir::Value castToIndex(mlir::Location loc, mlir::Value val); + mlir::Value castToIndex(mlir::Location loc, mlir::Value val, + bool isUnsigned = false); mlir::Value getLLVM(Expr *E, bool isRef = false); @@ -244,7 +331,7 @@ class MLIRScanner : public StmtVisitor { mlir::OpBuilder &getBuilder(); - mlir::Value getConstantIndex(int x); + mlir::Value getConstantIndex(int64_t x); ValueCategory createComplexFloat(mlir::Location loc, mlir::Value real, mlir::Value imag, clang::QualType cty); @@ -265,6 +352,7 @@ class MLIRScanner : public StmtVisitor { ValueCategory VisitTypeTraitExpr(clang::TypeTraitExpr *expr); ValueCategory VisitGNUNullExpr(clang::GNUNullExpr *expr); + ValueCategory VisitCXXNullPtrLiteralExpr(clang::CXXNullPtrLiteralExpr *expr); ValueCategory VisitIntegerLiteral(clang::IntegerLiteral *expr); ValueCategory VisitCharacterLiteral(clang::CharacterLiteral *expr); @@ -318,6 +406,9 @@ class MLIRScanner : public StmtVisitor { std::pair EmitBuiltinOps(clang::CallExpr *expr); + /// The Xilinx HLS bit builtins of the Vitis headers (CGXlxBuiltin.cc). + std::pair EmitXlxBuiltin(clang::CallExpr *expr); + ValueCategory VisitCXXScalarValueInitExpr(clang::CXXScalarValueInitExpr *expr); diff --git a/tools/cgeist/Lib/pragmaHandlerHLS.cc b/tools/cgeist/Lib/pragmaHandlerHLS.cc deleted file mode 100644 index f7cd1f624906..000000000000 --- a/tools/cgeist/Lib/pragmaHandlerHLS.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "pragmaHandlerHLS.h" -#include "clang/Frontend/ASTConsumers.h" -#include "clang/Frontend/MultiplexConsumer.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "mlir/IR/Builders.h" - -using namespace clang; - -std::vector g_HLSMetadata; - -PragmaHLSHandler::PragmaHLSHandler(std::vector &Metadata) - : PragmaHandler("HLS"), HLSMetaData(Metadata) {} - -void PragmaHLSHandler::HandlePragma(Preprocessor &PP, - PragmaIntroducer Introducer, - Token &PragmaTok) { - SourceManager &SM = PP.getSourceManager(); - Token Tok{}; - PP.Lex(Tok); - - if (Tok.isNot(tok::identifier)) return; - HLSPragmaMetaData P; - P.Name = StringRef(PP.getSpelling(Tok)).lower(); - P.Loc = Tok.getLocation(); - P.OffsetLoc = SM.getSpellingLineNumber(P.Loc); // ← add this line - PP.Lex(Tok); - - if (Tok.is(tok::eod)) { - HLSMetaData.push_back(P); - return; - } - - SourceLocation Start = Tok.getLocation(); - SourceLocation End = Start; - while (PP.Lex(Tok), Tok.isNot(tok::eod)) - End = Tok.getEndLoc(); - - // Extract raw text from source - bool Invalid = false; - const char *StartPtr = SM.getCharacterData(Start, &Invalid); - const char *EndPtr = SM.getCharacterData(End, &Invalid); - - if (!Invalid && StartPtr && EndPtr && EndPtr > StartPtr) { - StringRef RawPragma(StartPtr, EndPtr - StartPtr); - P.Args = RawPragma.str(); - } - llvm::outs() << "[HLS] pragma name: " << P.Name << " pragma args: " - << P.Args << "\n"; - HLSMetaData.push_back(P); -} - -void addPragmaHLSHandlers(Preprocessor &PP) { - PP.AddPragmaHandler(new PragmaHLSHandler(g_HLSMetadata)); -} \ No newline at end of file diff --git a/tools/cgeist/Lib/pragmaHandlerHLS.h b/tools/cgeist/Lib/pragmaHandlerHLS.h deleted file mode 100644 index 6f979e213da2..000000000000 --- a/tools/cgeist/Lib/pragmaHandlerHLS.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef MLIR_TOOLS_MLIRCLANG_LIB_PRAGMAHANDLERHLS_H -#define MLIR_TOOLS_MLIRCLANG_LIB_PRAGMAHANDLERHLS_H - -#include "clang/Frontend/FrontendAction.h" -#include "clang/Lex/Pragma.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/AST/RecursiveASTVisitor.h" -#include "mlir/IR/Operation.h" -#include -#include - -enum HLSPragmaType { - ArrayPartition, - ArrayReshape, - BindStorage, - BindOp, - Allocation, - Unroll, - Pipeline - }; - -/// Holds metadata parsed from #pragma HLS -struct HLSPragmaMetaData { - std::string Name; // e.g., "pipeline" - std::string Args; // e.g., "II=1" - clang::SourceLocation Loc; - mlir::Operation *Op = nullptr; - unsigned OffsetLoc = 0; -}; - -/// Handles the transition from Preprocessor (#pragma) to AST metadata -class PragmaHLSHandler : public clang::PragmaHandler { -public: - PragmaHLSHandler(std::vector &Metadata); - - void HandlePragma(clang::Preprocessor &PP, - clang::PragmaIntroducer Introducer, - clang::Token &PragmaTok) override; -private: - std::vector &HLSMetaData; -}; - -void addPragmaHLSHandlers(clang::Preprocessor &PP); - -// Global storage for HLS pragma metadata collected during parse. -// Populated by PragmaHLSHandler::HandlePragma, consumed in driver.cc -// after the MLIR pass pipeline runs. -extern std::vector g_HLSMetadata; - - -#endif \ No newline at end of file diff --git a/tools/cgeist/Lib/utils.h b/tools/cgeist/Lib/utils.h index e8af3dc420ce..f80132c0b65e 100644 --- a/tools/cgeist/Lib/utils.h +++ b/tools/cgeist/Lib/utils.h @@ -12,8 +12,6 @@ #include "mlir/IR/Builders.h" #include "llvm/ADT/ArrayRef.h" -inline bool g_HLSpragmaAnnotate = false; - namespace mlir { class Operation; namespace func { diff --git a/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp b/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp index 94b0c5dedd52..db14c69985d3 100644 --- a/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp +++ b/tools/cgeist/Test/HLS/AccessMemberArrayPartition.cpp @@ -1,43 +1,43 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - -struct C { - int A[8]; - int B[4]; -}; - -struct S { - int A[8]; - int B[4]; - C c; -}; - -int top(int input1[8], int input2[4]) { - S s; -#pragma HLS array_partition variable=s.A complete -#pragma HLS array_partition variable=s.c.A complete -#pragma HLS array_partition variable=s.B block factor=2 - for (int i = 0; i < 8; i++) { - s.A[i] = input1[i]; - s.c.A[i] = 2 * input1[i]; - } - for (int i = 0; i < 4; i++) { - s.B[i] = input2[i]; - s.c.B[i] = 2 * input2[i]; - } - - for (int i = 0; i < 8; i++) { - s.A[i] = s.A[i] + 1; - s.c.A[i] = s.c.A[i] + 1; - } - int sum = 0; - for (int i = 0; i < 8; i++) { - sum += s.A[i]; - sum += s.c.A[i]; - } - - return sum; - -} - -// CHECK: %alloca = memref.alloca() {hls.array_partition = [{kind = "complete", variable = "s.A"}, {kind = "complete", variable = "s.c.A"}, {factor = 2 : i32, kind = "block", variable = "s.B"}], polygeist.varname = "s"} - +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank | FileCheck %s + +struct C { + int A[8]; + int B[4]; +}; + +struct S { + int A[8]; + int B[4]; + C c; +}; + +int top(int input1[8], int input2[4]) { + S s; +#pragma HLS array_partition variable=s.A complete +#pragma HLS array_partition variable=s.c.A complete +#pragma HLS array_partition variable=s.B block factor=2 + for (int i = 0; i < 8; i++) { + s.A[i] = input1[i]; + s.c.A[i] = 2 * input1[i]; + } + for (int i = 0; i < 4; i++) { + s.B[i] = input2[i]; + s.c.B[i] = 2 * input2[i]; + } + + for (int i = 0; i < 8; i++) { + s.A[i] = s.A[i] + 1; + s.c.A[i] = s.c.A[i] + 1; + } + int sum = 0; + for (int i = 0; i < 8; i++) { + sum += s.A[i]; + sum += s.c.A[i]; + } + + return sum; + +} + +// CHECK: %alloca = memref.alloca() {hls.array_partition = [{dim = 1 : i32, kind = "complete", member_path = [0 : i32], variable = "s.A"}, {dim = 1 : i32, kind = "complete", member_path = [2 : i32, 0 : i32], variable = "s.c.A"}, {dim = 1 : i32, factor = 2 : i32, kind = "block", member_path = [1 : i32], variable = "s.B"}], polygeist.varname = "s"} + diff --git a/tools/cgeist/Test/HLS/Allocation.cpp b/tools/cgeist/Test/HLS/Allocation.cpp index 7bea626fad52..d81ca9bd196c 100644 --- a/tools/cgeist/Test/HLS/Allocation.cpp +++ b/tools/cgeist/Test/HLS/Allocation.cpp @@ -1,23 +1,23 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - -template -DT foo(DT a, DT b) { - return a + b; -} - -// ------------------------------------------------------------ -// Top-level function that calls foo and foo -// ------------------------------------------------------------ -void top(int *out_int, float *out_float, int a, int b, float x, float y) { - -#pragma HLS ALLOCATION function instances=foo limit=1 -#pragma HLS ALLOCATION function instances=foo limit=1 - - int r1 = foo(a, b); - float r2 = foo(x, y); - - *out_int = r1; - *out_float = r2; -} - -// CHECK: hls.allocation = [{instances = "foo", limit = 1 : i32, type = "function"}, {instances = "foo", limit = 1 : i32, type = "function"} \ No newline at end of file +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +template +DT foo(DT a, DT b) { + return a + b; +} + +// ------------------------------------------------------------ +// Top-level function that calls foo and foo +// ------------------------------------------------------------ +void top(int *out_int, float *out_float, int a, int b, float x, float y) { + +#pragma HLS ALLOCATION function instances=foo limit=1 +#pragma HLS ALLOCATION function instances=foo limit=1 + + int r1 = foo(a, b); + float r2 = foo(x, y); + + *out_int = r1; + *out_float = r2; +} + +// CHECK: hls.allocation = [{instances = ["foo"], limit = 1 : i32, type = "function"}, {instances = ["foo"], limit = 1 : i32, type = "function"}] \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/BasicArrayPartition.cpp b/tools/cgeist/Test/HLS/BasicArrayPartition.cpp index b2d2c446da37..6c15f7b38947 100644 --- a/tools/cgeist/Test/HLS/BasicArrayPartition.cpp +++ b/tools/cgeist/Test/HLS/BasicArrayPartition.cpp @@ -1,12 +1,12 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - -void basic_array_partition() { - int arr[8]; -#pragma HLS array_partition variable=arr complete - // Simple computation to test parallel access - for(int i = 0; i < 8; i++) { - arr[i] += 1; - } -} - -// CHECK: %alloca = memref.alloca() {hls.array_partition = [{kind = "complete", variable = "arr"}], polygeist.varname = "arr"} \ No newline at end of file +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +void basic_array_partition() { + int arr[8]; +#pragma HLS array_partition variable=arr complete + // Simple computation to test parallel access + for(int i = 0; i < 8; i++) { + arr[i] += 1; + } +} + +// CHECK: %alloca = memref.alloca() {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "arr"}], hls.preserve, polygeist.varname = "arr"} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/BindOp.cpp b/tools/cgeist/Test/HLS/BindOp.cpp index ac47fc746e35..0a9a49c2715d 100644 --- a/tools/cgeist/Test/HLS/BindOp.cpp +++ b/tools/cgeist/Test/HLS/BindOp.cpp @@ -1,11 +1,13 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - -int foo (int a, int b) { - int c, d; -#pragma HLS BIND_OP variable=c op=mul impl=fabric latency=2 - c = a*b; - d = a*c; - return d; -} - -// CHECK: {hls.bind_op = [{impl = "fabric", latency = 2 : i32, op = "mul"}], polygeist.ssa_names = ["c"]} \ No newline at end of file +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +int foo (int a, int b) { + int c, d; +#pragma HLS BIND_OP variable=c op=mul impl=fabric latency=2 + c = a*b; + d = a*c; + return d; +} + +// The pragma binds the multiplication assigned to c (not the one assigned to d). +// CHECK: %[[C:.*]] = arith.muli %arg0, %arg1 {hls.bind_op = [{impl = "fabric", latency = 2 : i32, op = "mul", variable = "c"}]} : i32 +// CHECK-NEXT: arith.muli %arg0, %[[C]] : i32 \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/BindStorage.cpp b/tools/cgeist/Test/HLS/BindStorage.cpp index bcec9b5b1bfe..5b807d751da3 100644 --- a/tools/cgeist/Test/HLS/BindStorage.cpp +++ b/tools/cgeist/Test/HLS/BindStorage.cpp @@ -1,23 +1,23 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - -void mac_top(int input[64], int &result) { -#pragma HLS bind_storage variable=weights type=ram_1p impl=bram -#pragma HLS bind_storage variable=bias type=ram_1p impl=lutram -#pragma HLS bind_storage variable=output type=ram_2p impl=uram latency=3 - int weights[64]; - int bias[16]; - int output[16]; - - for (int i = 0; i < 16; i++) { - output[i] = bias[i]; - for (int j = 0; j < 4; j++) - output[i] += input[i*4+j] * weights[i*4+j]; - } - for (int i = 0; i < 64; i++) { - result += output[i]; - } -} - -// CHECK: %alloca = memref.alloca() {hls.bind_storage = [{impl = "uram", latency = 3 : i32, type = "ram_2p", variable = "output"}], polygeist.varname = "output"} : memref<16xi32> -// CHECK: %alloca_0 = memref.alloca() {hls.bind_storage = [{impl = "lutram", type = "ram_1p", variable = "bias"}], polygeist.varname = "bias"} : memref<16xi32> -// CHECK: %alloca_1 = memref.alloca() {hls.bind_storage = [{impl = "bram", type = "ram_1p", variable = "weights"}], polygeist.varname = "weights"} : memref<64xi32> +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +void mac_top(int input[64], int &result) { +#pragma HLS bind_storage variable=weights type=ram_1p impl=bram +#pragma HLS bind_storage variable=bias type=ram_1p impl=lutram +#pragma HLS bind_storage variable=output type=ram_2p impl=uram latency=3 + int weights[64]; + int bias[16]; + int output[16]; + + for (int i = 0; i < 16; i++) { + output[i] = bias[i]; + for (int j = 0; j < 4; j++) + output[i] += input[i*4+j] * weights[i*4+j]; + } + for (int i = 0; i < 64; i++) { + result += output[i]; + } +} + +// CHECK: %alloca = memref.alloca() {hls.bind_storage = [{impl = "uram", latency = 3 : i32, type = "ram_2p", variable = "output"}], hls.preserve, polygeist.varname = "output"} : memref<16xi32> +// CHECK: %alloca_0 = memref.alloca() {hls.bind_storage = [{impl = "lutram", type = "ram_1p", variable = "bias"}], hls.preserve, polygeist.varname = "bias"} : memref<16xi32> +// CHECK: %alloca_1 = memref.alloca() {hls.bind_storage = [{impl = "bram", type = "ram_1p", variable = "weights"}], hls.preserve, polygeist.varname = "weights"} : memref<64xi32> diff --git a/tools/cgeist/Test/HLS/HLSAllocation.cpp b/tools/cgeist/Test/HLS/HLSAllocation.cpp new file mode 100644 index 000000000000..35799f444e82 --- /dev/null +++ b/tools/cgeist/Test/HLS/HLSAllocation.cpp @@ -0,0 +1,305 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +typedef ap_fixed<16, 5> data_t; + +#define C 64 +#define H 28 +#define W 28 + +data_t FM_buffer_1[C][H][W]; +data_t FM_buffer_2[C][H][W]; +data_t FM_buffer_3[C][H][W]; +data_t FM_buffer_4[C][H][W]; + + +void load_feature_map(data_t input_dram[C][H][W], data_t input_buffer[C][H][W]) +{ + #pragma HLS inline off + for (int c = 0; c < C; c++) + { + for (int h = 0; h < H; h++) + { + for (int w = 0; w < W; w++) + { + input_buffer[c][h][w] = input_dram[c][h][w]; + } + } + } +} + +void store_feature_map(data_t output_buffer[C][H][W], data_t output_dram[C][H][W]) +{ + #pragma HLS inline off + for (int c = 0; c < C; c++) + { + for (int h = 0; h < H; h++) + { + for (int w = 0; w < W; w++) + { + output_dram[c][h][w] = output_buffer[c][h][w]; + } + } + } +} + +void compute_exp(data_t input[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + output[i][j][k] = hls::exp(input[i][j][k]); + } + } + } + +} + +void negative(data_t input[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + output[i][j][k] = -input[i][j][k]; + } + } + } +} + +void compute_div(data_t input_1[C][H][W], data_t input_2[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + output[i][j][k] = input_1[i][j][k]/input_2[i][j][k]; + } + } + } +} + +void compute_add(data_t input_1[C][H][W], data_t input_2[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + output[i][j][k] = input_1[i][j][k] + input_2[i][j][k]; + } + } + } +} + +void compute_mul(data_t input_1[C][H][W], data_t input_2[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + output[i][j][k] = input_1[i][j][k] * input_2[i][j][k]; + } + } + } +} + +void set_value(data_t bram[C][H][W], data_t value) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + bram[i][j][k] = value; + } + } + } +} + + +void select(data_t input_1[C][H][W], data_t input_2[C][H][W], data_t output[C][H][W], data_t threshold) +{ + #pragma HLS inline off + for (int i = 0; i < C; i++) + { + for (int j = 0; j < H; j++) + { + for (int k = 0; k < W; k++) + { + if (input_1[i][j][k] >= threshold) { + output[i][j][k] = input_1[i][j][k]; + } else { + output[i][j][k] = input_2[i][j][k]; + } + } + } + } +} + +void sigmoid (data_t input[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + load_feature_map(input, FM_buffer_1); + negative(FM_buffer_1, FM_buffer_2); + compute_exp(FM_buffer_2, FM_buffer_1); + set_value(FM_buffer_3, (data_t) 1); + compute_add(FM_buffer_3, FM_buffer_1, FM_buffer_2); + compute_div(FM_buffer_3, FM_buffer_2, FM_buffer_1); + store_feature_map(FM_buffer_1, output); +} + +void tanh (data_t input[C][H][W], data_t output[C][H][W]) +{ + #pragma HLS inline off + load_feature_map(input, FM_buffer_1); + compute_exp(FM_buffer_1, FM_buffer_2); //exp(x) + negative(FM_buffer_1, FM_buffer_3); + compute_exp(FM_buffer_3, FM_buffer_1); //exp(-x) + compute_add(FM_buffer_2, FM_buffer_1, FM_buffer_3); + negative(FM_buffer_1, FM_buffer_4); + compute_add(FM_buffer_2, FM_buffer_4, FM_buffer_1); + compute_div(FM_buffer_1, FM_buffer_3, FM_buffer_2); + store_feature_map(FM_buffer_2, output); +} + +void elu(data_t input[C][H][W], data_t output[C][H][W], data_t alpha) +{ + #pragma HLS inline off + load_feature_map(input, FM_buffer_1); + compute_exp(FM_buffer_1, FM_buffer_2); + set_value(FM_buffer_3, (data_t) -1); + compute_add(FM_buffer_2, FM_buffer_3, FM_buffer_4); + set_value(FM_buffer_3, alpha); + compute_mul(FM_buffer_3, FM_buffer_4, FM_buffer_2); + select(FM_buffer_1, FM_buffer_2, FM_buffer_3, (data_t) 0); + store_feature_map(FM_buffer_3, output); +} + + + + +void top( + data_t input_sigmoid[C][H][W], + data_t output_sigmoid[C][H][W], + data_t input_tanh[C][H][W], + data_t output_tanh[C][H][W], + data_t input_elu[C][H][W], + data_t output_elu[C][H][W] +) +{ + #pragma HLS interface m_axi port=input_sigmoid offset=slave bundle=mem1 + #pragma HLS interface m_axi port=output_sigmoid offset=slave bundle=mem2 + + #pragma HLS interface m_axi port=input_tanh offset=slave bundle=mem1 + #pragma HLS interface m_axi port=output_tanh offset=slave bundle=mem2 + + #pragma HLS interface m_axi port=input_elu offset=slave bundle=mem1 + #pragma HLS interface m_axi port=output_elu offset=slave bundle=mem2 + + + #pragma HLS allocation function instances= load_feature_map limit=1 + #pragma HLS allocation function instances= store_feature_map limit=1 + #pragma HLS allocation function instances= compute_exp limit=1 + #pragma HLS allocation function instances= negative limit=1 + #pragma HLS allocation function instances= compute_div limit=1 + #pragma HLS allocation function instances= compute_add limit=1 + #pragma HLS allocation function instances= compute_mul limit=1 + #pragma HLS allocation function instances= set_value limit=1 + #pragma HLS allocation function instances= select limit=1 + + //sigmoid + load_feature_map(input_sigmoid, FM_buffer_1); + negative(FM_buffer_1, FM_buffer_2); + compute_exp(FM_buffer_2, FM_buffer_1); + set_value(FM_buffer_3, (data_t) 1); + compute_add(FM_buffer_3, FM_buffer_1, FM_buffer_2); + compute_div(FM_buffer_3, FM_buffer_2, FM_buffer_1); + store_feature_map(FM_buffer_1, output_sigmoid); + + //tanh + load_feature_map(input_tanh, FM_buffer_1); + compute_exp(FM_buffer_1, FM_buffer_2); //exp(x) + negative(FM_buffer_1, FM_buffer_3); + compute_exp(FM_buffer_3, FM_buffer_1); //exp(-x) + compute_add(FM_buffer_2, FM_buffer_1, FM_buffer_3); + negative(FM_buffer_1, FM_buffer_4); + compute_add(FM_buffer_2, FM_buffer_4, FM_buffer_1); + compute_div(FM_buffer_1, FM_buffer_3, FM_buffer_2); + store_feature_map(FM_buffer_2, output_tanh); + + //elu + load_feature_map(input_elu, FM_buffer_1); + compute_exp(FM_buffer_1, FM_buffer_2); + set_value(FM_buffer_3, (data_t) -1); + compute_add(FM_buffer_2, FM_buffer_3, FM_buffer_4); + set_value(FM_buffer_3, (data_t) 0.5); + compute_mul(FM_buffer_3, FM_buffer_4, FM_buffer_2); + select(FM_buffer_1, FM_buffer_2, FM_buffer_3, (data_t) 0); + store_feature_map(FM_buffer_3, output_elu); + // sigmoid(input_sigmoid, output_sigmoid); + // tanh(input_tanh, output_tanh); + // elu(input_elu, output_elu, (data_t) 0.5); +} + + +// Vitis ap_fixed/hls_math code: the pragmas are checked without code +// generation. (With the earlier stand-in headers cgeist could not generate +// code for hls::exp on ap_fixed, math.exp got the struct operand; with the +// exactclass headers and --scalar-wrapper-abi it does.) +// RUN: cgeist %s --function='*' -S --hls-annotate --hls-pragma-check-only %stdinclude %vitis_include --scalar-wrapper-abi -o /dev/null 2>&1 | FileCheck %s --check-prefix=HLS +// HLS-NOT: error +// HLS: HLSAllocation.cpp:27:5: remark: '#pragma HLS inline off' -> func.func @load_feature_map +// HLS: HLSAllocation.cpp:42:5: remark: '#pragma HLS inline off' -> func.func @store_feature_map +// HLS: HLSAllocation.cpp:57:5: remark: '#pragma HLS inline off' -> func.func @compute_exp +// HLS: HLSAllocation.cpp:73:5: remark: '#pragma HLS inline off' -> func.func @negative +// HLS: HLSAllocation.cpp:88:5: remark: '#pragma HLS inline off' -> func.func @compute_div +// HLS: HLSAllocation.cpp:103:5: remark: '#pragma HLS inline off' -> func.func @compute_add +// HLS: HLSAllocation.cpp:118:5: remark: '#pragma HLS inline off' -> func.func @compute_mul +// HLS: HLSAllocation.cpp:133:5: remark: '#pragma HLS inline off' -> func.func @set_value +// HLS: HLSAllocation.cpp:149:5: remark: '#pragma HLS inline off' -> func.func @select +// HLS: HLSAllocation.cpp:168:5: remark: '#pragma HLS inline off' -> func.func @sigmoid +// HLS: HLSAllocation.cpp:180:5: remark: '#pragma HLS inline off' -> func.func @tanh +// HLS: HLSAllocation.cpp:194:5: remark: '#pragma HLS inline off' -> func.func @elu +// HLS: HLSAllocation.cpp:217:5: remark: '#pragma HLS interface m_axi port=input_sigmoid offset=slave bundle=mem1' -> argument #0 (variable 'input_sigmoid') of @top +// HLS: HLSAllocation.cpp:218:5: remark: '#pragma HLS interface m_axi port=output_sigmoid offset=slave bundle=mem2' -> argument #1 (variable 'output_sigmoid') of @top +// HLS: HLSAllocation.cpp:220:5: remark: '#pragma HLS interface m_axi port=input_tanh offset=slave bundle=mem1' -> argument #2 (variable 'input_tanh') of @top +// HLS: HLSAllocation.cpp:221:5: remark: '#pragma HLS interface m_axi port=output_tanh offset=slave bundle=mem2' -> argument #3 (variable 'output_tanh') of @top +// HLS: HLSAllocation.cpp:223:5: remark: '#pragma HLS interface m_axi port=input_elu offset=slave bundle=mem1' -> argument #4 (variable 'input_elu') of @top +// HLS: HLSAllocation.cpp:224:5: remark: '#pragma HLS interface m_axi port=output_elu offset=slave bundle=mem2' -> argument #5 (variable 'output_elu') of @top +// HLS: HLSAllocation.cpp:227:5: remark: '#pragma HLS allocation function instances= load_feature_map limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:228:5: remark: '#pragma HLS allocation function instances= store_feature_map limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:229:5: remark: '#pragma HLS allocation function instances= compute_exp limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:230:5: remark: '#pragma HLS allocation function instances= negative limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:231:5: remark: '#pragma HLS allocation function instances= compute_div limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:232:5: remark: '#pragma HLS allocation function instances= compute_add limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:233:5: remark: '#pragma HLS allocation function instances= compute_mul limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:234:5: remark: '#pragma HLS allocation function instances= set_value limit=1' -> func.func @top +// HLS: HLSAllocation.cpp:235:5: remark: '#pragma HLS allocation function instances= select limit=1' -> func.func @top +// HLS-NOT: remark: diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/README.md b/tools/cgeist/Test/HLS/Inputs/vitis/README.md new file mode 100644 index 000000000000..e9f10ffc2b67 --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/README.md @@ -0,0 +1,38 @@ +# Vitis HLS header stand-ins for the cgeist lit tests (`%vitis_include`) + +These headers are a copy of the hls-est harness's `exactclass` shim: +`tools/hls-est-validate/shim/exactclass/` in the CIRCT tree (`~/circt`, branch +`hls-est-vitis-match`, files as of commit c4249e886, 2026-10-13, which added +the math-core markers to `hls_math.h` and `-DHLSEST_MATH_MARKERS` to +`cgeist_flags`). Edit the shim there and copy the headers here again; do not +edit them here. The shim's own README in that directory says what is modelled +bit-exactly (checked against the Vitis 2025.1 headers by `check_shim.py` and +`check_shim_cgeist.py`) and what is not. + +`ap_int`, `ap_uint`, `ap_fixed<...>` and `ap_ufixed<...>` are classes +whose only data member is the raw `_BitInt(W)` / `unsigned _BitInt(W)`, as in +the real headers in `__SYNTHESIS__` mode, and every operation is the integer +arithmetic of the Vitis headers. cgeist lowers such a single-scalar class to +its scalar only with the opt-in `--scalar-wrapper-abi`, so every RUN line that +uses `%vitis_include` also passes `--scalar-wrapper-abi`: an `ap_fixed<16,5>` +is then an `i16` in the MLIR, an array of them a `memref<...xi16>`. +Without the flag these classes are LLVM structs. + +`cgeist_flags` is the shim's file of extra cgeist flags (`--scalar-wrapper-abi`, +`-DHLSEST_MATH_MARKERS`), copied too: the hls-est harness reads it when +`run_hlsest.py --shim polygeist` selects this directory, and the HLSFactory +tests (`hlsfactory/lit.local.cfg`, `%vitis_shim_flags`) read it to build the +harness's command. The other lit tests pass `--scalar-wrapper-abi` themselves +and do not define the macro, so `hls_math.h` calls the libm builtins there. + +Not provided (compile errors, not silent differences): assignable range / bit +selects and concatenations (`x.range(7, 0) = v`), string constructors, and the +Vitis headers outside `ap_int.h`, `ap_fixed.h`, `ap_axi_sdata.h`, `ap_cint.h`, +`hls_half.h`, `hls_math.h`, `hls_stream.h` and `hls_vector.h`. `hls::stream` +operations are declared, not defined (calls to external functions). The +HLSFactory designs these gaps stop are listed in `hlsfactory/SUMMARY.md`. + +These headers replaced the earlier minimal stand-ins (a 64-bit integer behind +every `ap_[u]int` and a `double` behind every `ap_fixed`) on 2026-10-11 +(MEMOS decision #10 of the hls-est project; MEMOS decision #9 keeps +`--scalar-wrapper-abi` opt-in). diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/ap_axi_sdata.h b/tools/cgeist/Test/HLS/Inputs/vitis/ap_axi_sdata.h new file mode 100644 index 000000000000..803b418a4ce1 --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/ap_axi_sdata.h @@ -0,0 +1,38 @@ +// Minimal stand-in for the Vitis HLS ap_axi_sdata.h, for cgeist tests only. +#ifndef CGEIST_TEST_AP_AXI_SDATA_H +#define CGEIST_TEST_AP_AXI_SDATA_H + +#ifdef __cplusplus +#include "ap_int.h" + +template struct ap_axis { + ap_int data; + ap_uint<(D + 7) / 8> keep; + ap_uint<(D + 7) / 8> strb; + ap_uint user; + ap_uint<1> last; + ap_uint id; + ap_uint dest; +}; +template struct ap_axiu { + ap_uint data; + ap_uint<(D + 7) / 8> keep; + ap_uint<(D + 7) / 8> strb; + ap_uint user; + ap_uint<1> last; + ap_uint id; + ap_uint dest; +}; +namespace hls { +template struct axis { + T data; + ap_uint<(sizeof(T) + 0)> keep; + ap_uint<(sizeof(T) + 0)> strb; + ap_uint user; + ap_uint<1> last; + ap_uint id; + ap_uint dest; +}; +} // namespace hls +#endif // __cplusplus +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/ap_cint.h b/tools/cgeist/Test/HLS/Inputs/vitis/ap_cint.h new file mode 100644 index 000000000000..b61adfadb57c --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/ap_cint.h @@ -0,0 +1,26 @@ +// Minimal stand-in for the Vivado HLS ap_cint.h (C arbitrary-precision +// types), for cgeist tests only: each intN / uintN is the smallest builtin +// integer type that holds N bits. +#ifndef CGEIST_TEST_AP_CINT_H +#define CGEIST_TEST_AP_CINT_H +#define CGEIST_AP_CINT(N, T) \ + typedef signed T int##N; \ + typedef unsigned T uint##N; +CGEIST_AP_CINT(1, char) CGEIST_AP_CINT(2, char) CGEIST_AP_CINT(3, char) +CGEIST_AP_CINT(4, char) CGEIST_AP_CINT(5, char) CGEIST_AP_CINT(6, char) +CGEIST_AP_CINT(7, char) CGEIST_AP_CINT(9, short) CGEIST_AP_CINT(10, short) +CGEIST_AP_CINT(11, short) CGEIST_AP_CINT(12, short) CGEIST_AP_CINT(13, short) +CGEIST_AP_CINT(14, short) CGEIST_AP_CINT(15, short) CGEIST_AP_CINT(17, int) +CGEIST_AP_CINT(18, int) CGEIST_AP_CINT(19, int) CGEIST_AP_CINT(20, int) +CGEIST_AP_CINT(24, int) CGEIST_AP_CINT(31, int) CGEIST_AP_CINT(33, long long) +CGEIST_AP_CINT(48, long long) CGEIST_AP_CINT(63, long long) +#undef CGEIST_AP_CINT +typedef signed char int8; +typedef unsigned char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned uint32; +typedef long long int64; +typedef unsigned long long uint64; +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/ap_fixed.h b/tools/cgeist/Test/HLS/Inputs/vitis/ap_fixed.h new file mode 100644 index 000000000000..bf5734d58a20 --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/ap_fixed.h @@ -0,0 +1,520 @@ +// hls-est "exactclass" stand-in for the Vitis HLS ap_fixed.h. +// +// ap_fixed / ap_ufixed<...> derive from ap_fixed_base +// whose ONLY data member is the raw `_BitInt(W)` / `unsigned _BitInt(W)` V +// holding value * 2^(W-I). cgeist (--scalar-wrapper-abi) lowers the class to +// that scalar, so arrays of ap_fixed<16,5> are memref<...xi16> in the MLIR and +// every operation is the integer arithmetic below. +// +// Semantics follow etc/ap_fixed_base.h of Vitis 2025.1 (validated bit for bit +// against the real headers by tools/hls-est-validate/check_shim.py): +// * result types of + - * / & | ^ per ap_fixed_base::RType, computed +// exactly; `a OP= b` and `T x = expr` convert back with the target's +// quantization (AP_TRN floor, AP_RND half-up, AP_RND_ZERO, AP_RND_MIN_INF, +// AP_RND_INF, AP_RND_CONV, AP_TRN_ZERO) and overflow mode (AP_WRAP modular, +// AP_SAT clamp, AP_SAT_ZERO, AP_SAT_SYM). N (saturation bits) and +// AP_WRAP_SM are not implemented (treated as AP_WRAP / N = 0); +// * int -> fixed: value << F then wrap/saturate; double -> fixed: the IEEE +// mantissa is shifted exactly (floor for AP_TRN), then wrap/saturate; +// * a / b: truncation toward zero of (a.V << max(F2,0)) / b.V, exact (the +// synthesis path; the C simulation path divides in fewer bits, so +// min / -1 LSB wraps there - VITIS_NOTES N11 - and traps on a zero +// divisor; Vitis synthesis treats the quotient as undef - hls-est's +// --vitis-fold models that); +// * comparisons are exact (operands aligned to the larger F); +// * Vitis has no ap_fixed OP double: such expressions are computed in +// double through `operator double()`, as here; `(int)x` and to_int() +// both truncate toward zero (to_int() through to_ap_int_base(), the +// integer part, as in Vitis). +#ifndef HLSEST_EXACTCLASS_AP_FIXED_H +#define HLSEST_EXACTCLASS_AP_FIXED_H +#ifdef __cplusplus +#include "ap_int.h" +// Vitis marks every ap_int / ap_fixed member and operator AP_INLINE, i.e. +// `inline __attribute__((always_inline))` under __SYNTHESIS__ +// (etc/ap_common.h): clang inlines them before Vitis's own inliner, which +// never lists them ([HLS 214-178]). cgeist's automatic-inlining rule +// (--hls-auto-inline, VITIS_NOTES N18) reads the same attribute. +#ifdef __clang__ +#pragma clang attribute push(__attribute__((always_inline)), apply_to = function) +#endif + +template struct _ap_fixed_factory { typedef ap_fixed type; }; +template struct _ap_fixed_factory { typedef ap_ufixed type; }; + +template +struct ap_fixed_base { + static_assert(W > 0, "ap_fixed_base bitwidth must be positive"); + typedef typename ap_detail::bits::type raw_t; + static const int width = W; + static const int iwidth = I; + static const ap_q_mode qmode = Q; + static const ap_o_mode omode = O; + static const int F = W - I; // fractional bits (may be negative or > W) + + raw_t V; // the only data member (uninitialised by default, like Vitis) + + /// The value of V (sign-extends the bit of a signed 1-bit type). + typedef typename ap_detail::bits::vtype val_t; + constexpr val_t rval() const { return ap_detail::bits::val(V); } + + /// Result types of the binary operators (ap_fixed_base.h RType). + template struct RType { + enum { + F2 = W2 - I2, + mult_w = W + W2, + mult_i = I + I2, + mult_s = S || S2, + plus_w = ap_detail::max(I + (S2 && !S), I2 + (S && !S2)) + 1 + ap_detail::max(F, F2), + plus_i = ap_detail::max(I + (S2 && !S), I2 + (S && !S2)) + 1, + plus_s = S || S2, + minus_w = ap_detail::max(I + (S2 && !S), I2 + (S && !S2)) + 1 + ap_detail::max(F, F2), + minus_i = ap_detail::max(I + (S2 && !S), I2 + (S && !S2)) + 1, + minus_s = true, + div_w = S2 + W + ap_detail::max(F2, 0), + div_i = S2 + I + F2, + div_s = S || S2, + logic_w = ap_detail::max(I + (S2 && !S), I2 + (S && !S2)) + ap_detail::max(F, F2), + logic_i = ap_detail::max(I + (S2 && !S), I2 + (S && !S2)), + logic_s = S || S2 + }; + typedef ap_fixed_base lhs; + typedef ap_fixed_base rhs; + typedef ap_fixed_base mult_base; + typedef ap_fixed_base plus_base; + typedef ap_fixed_base minus_base; + typedef ap_fixed_base logic_base; + typedef ap_fixed_base div_base; + typedef ap_fixed_base arg1_base; + typedef typename _ap_fixed_factory::type mult; + typedef typename _ap_fixed_factory::type plus; + typedef typename _ap_fixed_factory::type minus; + typedef typename _ap_fixed_factory::type logic; + typedef typename _ap_fixed_factory::type div; + typedef typename _ap_fixed_factory::type arg1; + }; + + // ---- the conversion core ------------------------------------------------- + // from_raw: a value given as the W2-bit raw integer v2 with F2 fractional + // bits becomes this type's raw: align to F (quantizing with Q when bits are + // dropped), then apply the overflow mode O. The exact value is kept in a + // signed type wide enough for the shift, so AP_SAT is an exact clamp. + template + static constexpr raw_t from_raw(typename ap_detail::bits::vtype v2, int F2) { + const int CW = W2 + W + 3; + typedef ap_detail::sbits wide; + wide v = (wide)v2; + wide q = 0; + bool big = false; // |value| >= 2^W after the shift: out of range unless 0 + if (F2 > F) { + int sh = F2 - F; + bool qb = false, r = false, s = v < 0; + if (sh >= CW) { + q = s ? (wide)-1 : (wide)0; + qb = s; + r = v != 0; + } else { + q = v >> sh; + qb = ((v >> (sh - 1)) & 1) != 0; + r = sh > 1 ? ((v & (((wide)1 << (sh - 1)) - 1)) != 0) : false; + } + bool add = false; + if (Q == AP_TRN) add = false; + else if (Q == AP_RND) add = qb; + else if (Q == AP_RND_ZERO) add = qb && (s || r); + else if (Q == AP_RND_MIN_INF) add = qb && r; + else if (Q == AP_RND_INF) add = qb && (!s || r); + else if (Q == AP_RND_CONV) add = qb && (((q & 1) != 0) || r); + else /* AP_TRN_ZERO */ add = s && (qb || r); + q += add; + } else if (F2 < F) { + int sh = F - F2; + if (v == 0) q = 0; + else if (sh >= W + 1) { big = true; q = v < 0 ? (wide)-1 : (wide)1; } + else q = v << sh; + } else { + q = v; + } + if (O == AP_WRAP) return big ? (raw_t)0 : (raw_t)q; + const wide mn = (wide)ap_detail::smin(), mx = (wide)ap_detail::smax(); + bool over = (big && q > 0) || q > mx; + bool under = (big && q < 0) || q < mn; + if (!over && !under) return (raw_t)q; + if (O == AP_SAT) return over ? (raw_t)mx : (raw_t)mn; + if (O == AP_SAT_ZERO) return (raw_t)0; + if (O == AP_SAT_SYM) return over ? (raw_t)mx : (S ? (raw_t)(-mx) : (raw_t)0); + return big ? (raw_t)0 : (raw_t)q; // AP_WRAP_SM: not modelled, plain wrap + } + template + static constexpr raw_t from(const ap_fixed_base &o) { return from_raw(o.rval(), W2 - I2); } + // double -> fixed: the IEEE mantissa (negated if negative) has 52 - exp + // fractional bits; NaN/inf are not special-cased (Vitis warns and goes on). + static constexpr raw_t from_double(double d) { + unsigned long long b = __builtin_bit_cast(unsigned long long, d); + bool neg = (b >> 63) != 0; + int e = (int)((b >> 52) & 0x7ff); + unsigned long long m = b & ((1ull << 52) - 1); + if (e == 0 && m == 0) return (raw_t)0; + m |= 1ull << 52; + ap_detail::sbits<55> man = (ap_detail::sbits<55>)m; + if (neg) man = -man; + return from_raw<55, true>(man, 52 - (e - 1023)); + } + + // ---- constructors -------------------------------------------------------- + ap_fixed_base() = default; + ap_fixed_base(const ap_fixed_base &) = default; + ap_fixed_base &operator=(const ap_fixed_base &) = default; + template + constexpr ap_fixed_base(const ap_fixed_base &o) : V(from(o)) {} + template + constexpr ap_fixed_base(const ap_int_base &o) : V(from_raw(o.rval(), 0)) {} + template ::type> + constexpr ap_fixed_base(T v) + : V(from_raw::W, ap_detail::ctype::S>( + (typename ap_detail::bits::W, ap_detail::ctype::S>::vtype)v, 0)) {} + constexpr ap_fixed_base(double d) : V(from_double(d)) {} + constexpr ap_fixed_base(float d) : V(from_double((double)d)) {} + constexpr ap_fixed_base(_Float16 d) : V(from_double((double)d)) {} + + template + constexpr ap_fixed_base &operator=(const ap_fixed_base &o) { V = from(o); return *this; } + template + constexpr ap_fixed_base &operator=(const ap_int_base &o) { V = from_raw(o.rval(), 0); return *this; } + template ::type> + constexpr ap_fixed_base &operator=(T v) { V = ap_fixed_base(v).V; return *this; } + constexpr ap_fixed_base &operator=(double d) { V = from_double(d); return *this; } + constexpr ap_fixed_base &operator=(float d) { V = from_double((double)d); return *this; } + + // ---- conversions --------------------------------------------------------- + constexpr double to_double() const { return (double)rval() * ap_detail::pow2<-F>::v; } + constexpr operator double() const { return to_double(); } + // The other implicit conversions Vitis provides (ap_fixed_base.h:1184-1217): + // the integer ones truncate toward zero through to_int() and friends. With + // them, `x * 0.5` is ambiguous - as with the real headers. + constexpr operator float() const { return to_float(); } + constexpr operator _Float16() const { return to_half(); } + constexpr operator bool() const { return V != 0; } + constexpr operator char() const { return (char)to_int(); } + constexpr operator signed char() const { return (signed char)to_int(); } + constexpr operator unsigned char() const { return (unsigned char)to_uint(); } + constexpr operator short() const { return (short)to_int(); } + constexpr operator unsigned short() const { return (unsigned short)to_uint(); } + constexpr operator int() const { return to_int(); } + constexpr operator unsigned() const { return to_uint(); } + constexpr operator long() const { return (long)to_int64(); } + constexpr operator unsigned long() const { return (unsigned long)to_uint64(); } + constexpr operator long long() const { return to_int64(); } + constexpr operator unsigned long long() const { return to_uint64(); } + constexpr float to_float() const { return (float)to_double(); } + constexpr _Float16 to_half() const { return (_Float16)to_float(); } + // integer part, as Vitis to_ap_int_base(): truncated toward zero (see ipart()). + constexpr ap_int_base to_ap_int_base() const { + ap_int_base r; + r.V = (typename ap_int_base::raw_t)ipart(); + return r; + } + constexpr ap_int to_ap_int() const { return ap_int(to_ap_int_base()); } + constexpr char to_char() const { return (char)ipart(); } + constexpr short to_short() const { return (short)ipart(); } + constexpr int to_int() const { return (int)ipart(); } + constexpr unsigned to_uint() const { return (unsigned)ipart(); } + constexpr long to_long() const { return (long)ipart(); } + constexpr unsigned long to_ulong() const { return (unsigned long)ipart(); } + constexpr ap_slong to_int64() const { return (ap_slong)ipart(); } + constexpr ap_ulong to_uint64() const { return (ap_ulong)ipart(); } + + constexpr int length() const { return W; } + constexpr int wl() const { return W; } + constexpr int iwl() const { return I; } + constexpr bool is_zero() const { return V == 0; } + constexpr bool is_neg() const { return S && rval() < 0; } + constexpr bool sign() const { return S && rval() < 0; } + + // ---- bit and slice selects on the raw bits (value-returning) ------------- + constexpr bool operator[](int i) const { return (((ap_detail::ubits)V >> i) & 1) != 0; } + constexpr bool bit(int i) const { return (*this)[i]; } + constexpr bool get_bit(int i) const { return (*this)[i]; } + constexpr void set_bit(int i, bool b) { + ap_detail::ubits m = (ap_detail::ubits)1 << i; + V = (raw_t)(b ? ((ap_detail::ubits)V | m) : ((ap_detail::ubits)V & (ap_detail::ubits)~m)); + } + constexpr void set(int i) { set_bit(i, true); } + constexpr void set(int i, bool b) { set_bit(i, b); } + constexpr void clear(int i) { set_bit(i, false); } + constexpr const ap_int_base range(int hi, int lo) const { + ap_int_base r; + r.V = (ap_detail::ubits)V; + return r.range(hi, lo); + } + constexpr const ap_int_base range() const { ap_int_base r; r.V = (ap_detail::ubits)V; return r; } + constexpr const ap_int_base operator()(int hi, int lo) const { return range(hi, lo); } + constexpr const ap_int_base range(int hi, int lo) { return ((const ap_fixed_base *)this)->range(hi, lo); } + constexpr const ap_int_base operator()(int hi, int lo) { return range(hi, lo); } + + // ---- unary --------------------------------------------------------------- + constexpr typename _ap_fixed_factory::type operator-() const { + ap_fixed_base r; + r.V = (typename ap_fixed_base::raw_t)(-(ap_detail::sbits)rval()); + return typename _ap_fixed_factory::type(r); + } + constexpr typename _ap_fixed_factory::type operator+() const { return typename _ap_fixed_factory::type(*this); } + constexpr bool operator!() const { return V == 0; } + constexpr ap_fixed_base operator~() const { + ap_fixed_base r; + r.V = (raw_t)~V; + return r; + } + constexpr ap_fixed_base &operator++() { return *this += 1; } + constexpr ap_fixed_base &operator--() { return *this -= 1; } + constexpr const ap_fixed_base operator++(int) { ap_fixed_base t(*this); ++*this; return t; } + constexpr const ap_fixed_base operator--(int) { ap_fixed_base t(*this); --*this; return t; } + + // ---- shifts on the raw bits, width W kept -------------------------------- + constexpr ap_fixed_base operator<<(unsigned sh) const { + ap_fixed_base r; + r.V = sh < (unsigned)W ? (raw_t)((ap_detail::ubits)V << sh) : (raw_t)0; + return r; + } + constexpr ap_fixed_base operator>>(unsigned sh) const { + ap_fixed_base r; + if (sh < (unsigned)W) r.V = (raw_t)(rval() >> sh); + else r.V = (S && rval() < 0) ? (raw_t)-1 : (raw_t)0; + return r; + } + constexpr ap_fixed_base operator<<(int sh) const { return sh < 0 ? operator>>((unsigned)-sh) : operator<<((unsigned)sh); } + constexpr ap_fixed_base operator>>(int sh) const { return sh < 0 ? operator<<((unsigned)-sh) : operator>>((unsigned)sh); } + template + constexpr ap_fixed_base operator<<(const ap_int_base &o) const { return operator<<((int)o.to_int64()); } + template + constexpr ap_fixed_base operator>>(const ap_int_base &o) const { return operator>>((int)o.to_int64()); } + template constexpr ap_fixed_base &operator<<=(const T &sh) { *this = operator<<(sh); return *this; } + template constexpr ap_fixed_base &operator>>=(const T &sh) { *this = operator>>(sh); return *this; } + + // ---- binary arithmetic with another fixed-point value ------------------- + template + constexpr typename RType::mult operator*(const ap_fixed_base &o) const { + typename RType::mult_base r; + typedef typename RType::mult_base::raw_t mr; + r.V = (mr)((mr)rval() * (mr)o.rval()); // W + W2 bits hold the product exactly + return typename RType::mult(r); + } + template + constexpr typename RType::div operator/(const ap_fixed_base &o) const { + typedef typename RType::div_base R; + const int F2 = W2 - I2; + typedef ap_detail::sbits wide; + R r; + r.V = (typename R::raw_t)(((wide)rval() << ap_detail::max(F2, 0)) / (wide)o.rval()); // truncation toward zero + return typename RType::div(r); + } + template + constexpr typename RType::plus operator+(const ap_fixed_base &o) const { + typedef typename RType::plus_base R; + const int F2 = W2 - I2, F3 = ap_detail::max(F, F2); + typedef ap_detail::sbits wide; + R r; + r.V = (typename R::raw_t)(((wide)rval() << (F3 - F)) + ((wide)o.rval() << (F3 - F2))); + return typename RType::plus(r); + } + template + constexpr typename RType::minus operator-(const ap_fixed_base &o) const { + typedef typename RType::minus_base R; + const int F2 = W2 - I2, F3 = ap_detail::max(F, F2); + typedef ap_detail::sbits wide; + R r; + r.V = (typename R::raw_t)(((wide)rval() << (F3 - F)) - ((wide)o.rval() << (F3 - F2))); + return typename RType::minus(r); + } + // Bitwise: both operands converted to the logic type first (Vitis OP_BIN_AF). +#define HLSEST_AF_LOGIC(SYM) \ + template \ + constexpr typename RType::logic operator SYM( \ + const ap_fixed_base &o) const { \ + typedef typename RType::logic_base R; \ + R l(*this), rr(o), r; \ + r.V = (typename R::raw_t)(l.V SYM rr.V); \ + return typename RType::logic(r); \ + } + HLSEST_AF_LOGIC(&) + HLSEST_AF_LOGIC(|) + HLSEST_AF_LOGIC(^) +#undef HLSEST_AF_LOGIC + + // ---- comparisons: operands aligned to the larger F (the narrower-F side + // widened, as Vitis OP_CMP_AF), then compared as bitwidth integers with + // the C conversion rule of ap_detail::cmp_lt -------------------------------- + template + constexpr bool lt_(const ap_fixed_base &o) const { + const int F2 = W2 - I2; + const int WL = F >= F2 ? W : ap_detail::max(W + F2 - F + 1, 1); + const int WR = F > F2 ? ap_detail::max(W2 + F - F2, 1) : W2; + const int F3 = ap_detail::max(F, F2); + const int MW = ap_detail::max(WL, WR) + 1; + typedef ap_detail::sbits sw; + return ap_detail::cmp_lt((sw)((sw)rval() << (F3 - F)), (sw)((sw)o.rval() << (F3 - F2))); + } + template + constexpr bool eq_(const ap_fixed_base &o) const { + const int F2 = W2 - I2; + const int WL = F >= F2 ? W : ap_detail::max(W + F2 - F + 1, 1); + const int WR = F > F2 ? ap_detail::max(W2 + F - F2, 1) : W2; + const int F3 = ap_detail::max(F, F2); + const int MW = ap_detail::max(WL, WR) + 1; + typedef ap_detail::sbits sw; + return ap_detail::cmp_eq((sw)((sw)rval() << (F3 - F)), (sw)((sw)o.rval() << (F3 - F2))); + } +#define HLSEST_AF_CMP(SYM, EXPR) \ + template \ + constexpr bool operator SYM(const ap_fixed_base &o) const { \ + return EXPR; \ + } \ + constexpr bool operator SYM(double d) const { return to_double() SYM d; } + HLSEST_AF_CMP(<, lt_(o)) + HLSEST_AF_CMP(>, o.lt_(*this)) + HLSEST_AF_CMP(<=, !o.lt_(*this)) + HLSEST_AF_CMP(>=, !lt_(o)) + HLSEST_AF_CMP(==, eq_(o)) + HLSEST_AF_CMP(!=, !eq_(o)) +#undef HLSEST_AF_CMP + + // ---- compound assignment: the binary operator, then this type's + // quantization / overflow (Vitis OP_ASSIGN_AF) ----------------------------- + template constexpr ap_fixed_base &operator*=(const T &o) { *this = (*this) * o; return *this; } + template constexpr ap_fixed_base &operator/=(const T &o) { *this = (*this) / o; return *this; } + template constexpr ap_fixed_base &operator+=(const T &o) { *this = (*this) + o; return *this; } + template constexpr ap_fixed_base &operator-=(const T &o) { *this = (*this) - o; return *this; } + template constexpr ap_fixed_base &operator&=(const T &o) { *this = (*this) & o; return *this; } + template constexpr ap_fixed_base &operator|=(const T &o) { *this = (*this) | o; return *this; } + template constexpr ap_fixed_base &operator^=(const T &o) { *this = (*this) ^ o; return *this; } + +private: + // The integer part as Vitis to_ap_int_base(): the I bits above F (floor), + // then +1 for a negative value with non-zero fraction bits, i.e. truncation + // toward zero like a C double -> int conversion. + constexpr ap_detail::sbits ipart() const { + typedef ap_detail::sbits wide; + const int shr = F >= 0 ? (F < W + 2 ? F : 0) : 0, shl = F < 0 ? -F : 0; + if (I <= 0) return (S && rval() < 0) ? (wide)-1 : (wide)0; // 1-bit field: 0, or 0 + 1 wrapped + wide r = (F >= 0 && F >= W + 2) ? (wide)((S && rval() < 0) ? -1 : 0) : (wide)(((wide)rval() >> shr) << shl); + if (S && rval() < 0 && F > 0) { + bool frac = F >= W ? (V != 0) : (((ap_detail::ubits)V & (ap_detail::ubits)((((ap_detail::ubits)1) << F) - 1)) != 0); + if (frac) r += 1; + } + return r; + } +}; + +// ---- ap_int_base from ap_fixed_base (declared in ap_int.h) ----------------- +template +template +constexpr ap_int_base::ap_int_base(const ap_fixed_base &o) + : V((raw_t)o.to_ap_int_base().rval()) {} + +// ---- mixed operators: C integer -> ap_fixed_base, +// ap_int_base -> ap_fixed_base (Vitis AF_BIN_OP_WITH_INT / +// AF_BIN_OP_WITH_AP_INT). There is deliberately no operator with double: +// those go through operator double(), as with the Vitis headers. ------------- +#define HLSEST_AF_MIX(SYM, RTY) \ + template \ + constexpr typename ap_fixed_base::template RType::W, \ + ap_detail::ctype::W, \ + ap_detail::ctype::S>::RTY \ + operator SYM(const ap_fixed_base &a, T b) { \ + return a SYM ap_fixed_base::W, ap_detail::ctype::W, ap_detail::ctype::S>(b); \ + } \ + template \ + constexpr typename ap_fixed_base::template RType::W, \ + ap_detail::ctype::W, \ + ap_detail::ctype::S>::RTY \ + operator SYM(T a, const ap_fixed_base &b) { \ + return ap_fixed_base::W, ap_detail::ctype::W, ap_detail::ctype::S>(a) SYM b; \ + } \ + template \ + constexpr typename ap_fixed_base::template RType::RTY operator SYM( \ + const ap_fixed_base &a, const ap_int_base &b) { \ + return a SYM ap_fixed_base(b); \ + } \ + template \ + constexpr typename ap_fixed_base::template RType::RTY operator SYM( \ + const ap_int_base &a, const ap_fixed_base &b) { \ + return ap_fixed_base(a) SYM b; \ + } +HLSEST_AF_MIX(+, plus) +HLSEST_AF_MIX(-, minus) +HLSEST_AF_MIX(*, mult) +HLSEST_AF_MIX(/, div) +HLSEST_AF_MIX(&, logic) +HLSEST_AF_MIX(|, logic) +HLSEST_AF_MIX(^, logic) +#undef HLSEST_AF_MIX +#define HLSEST_AF_MIXREL(SYM) \ + template ::type> \ + constexpr bool operator SYM(const ap_fixed_base &a, T b) { \ + return a SYM ap_fixed_base::W, ap_detail::ctype::W, ap_detail::ctype::S>(b); \ + } \ + template ::type> \ + constexpr bool operator SYM(T a, const ap_fixed_base &b) { \ + return ap_fixed_base::W, ap_detail::ctype::W, ap_detail::ctype::S>(a) SYM b; \ + } \ + template \ + constexpr bool operator SYM(const ap_fixed_base &a, const ap_int_base &b) { \ + return a SYM ap_fixed_base(b); \ + } \ + template \ + constexpr bool operator SYM(const ap_int_base &a, const ap_fixed_base &b) { \ + return ap_fixed_base(a) SYM b; \ + } \ + template \ + constexpr bool operator SYM(double a, const ap_fixed_base &b) { \ + return a SYM b.to_double(); \ + } +HLSEST_AF_MIXREL(<) +HLSEST_AF_MIXREL(>) +HLSEST_AF_MIXREL(<=) +HLSEST_AF_MIXREL(>=) +HLSEST_AF_MIXREL(==) +HLSEST_AF_MIXREL(!=) +#undef HLSEST_AF_MIXREL + +// Concatenation of the raw bits with an ap_int or another ap_fixed. +template +constexpr const ap_uint operator,(const ap_fixed_base &a, const ap_int_base &b) { + return (a.range(), b); +} +template +constexpr const ap_uint operator,(const ap_int_base &a, const ap_fixed_base &b) { + return (a, b.range()); +} +template +constexpr const ap_uint operator,(const ap_fixed_base &a, const ap_fixed_base &b) { + return (a.range(), b.range()); +} + +template +struct ap_fixed : ap_fixed_base { + typedef ap_fixed_base Base; + ap_fixed() = default; + ap_fixed(const ap_fixed &) = default; + ap_fixed &operator=(const ap_fixed &) = default; + template constexpr ap_fixed(const T &v) : Base(v) {} + template constexpr ap_fixed &operator=(const T &v) { this->V = ap_fixed(v).V; return *this; } +}; +template +struct ap_ufixed : ap_fixed_base { + typedef ap_fixed_base Base; + ap_ufixed() = default; + ap_ufixed(const ap_ufixed &) = default; + ap_ufixed &operator=(const ap_ufixed &) = default; + template constexpr ap_ufixed(const T &v) : Base(v) {} + template constexpr ap_ufixed &operator=(const T &v) { this->V = ap_ufixed(v).V; return *this; } +}; + +#ifdef __clang__ +#pragma clang attribute pop +#endif + +#endif // __cplusplus +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/ap_int.h b/tools/cgeist/Test/HLS/Inputs/vitis/ap_int.h new file mode 100644 index 000000000000..f55e3b2b4a47 --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/ap_int.h @@ -0,0 +1,527 @@ +// hls-est "exactclass" stand-in for the Vitis HLS ap_int.h. +// +// ap_int / ap_uint are classes whose ONLY data member is a +// `_BitInt(W)` / `unsigned _BitInt(W)` (ap_int_base::V), exactly like +// the Vitis headers in __SYNTHESIS__ mode (`int __attribute__((bitwidth(W)))`). +// cgeist (Polygeist branch hls-est-vitis-match, --scalar-wrapper-abi) lowers a +// single-scalar-member class to that scalar, so every ap_int value, array +// element, reference and `this` is a plain `iW` in the MLIR. +// +// Semantics follow etc/ap_int_base.h of Vitis 2025.1: +// * result widths of + - * / % & | ^ per ap_int_base::RType (the wider +// Vitis result type), computed exactly; assigning back truncates (wrap); +// * shifts keep the width of the left operand (bits shifted out are lost); +// * conversion from float truncates toward zero, then wraps to W bits; +// conversion from double does the same except that, as in Vitis' +// ap_int_base(double), the shifted mantissa of a value with +// 1 <= |d| < 2^52 passes through a 25-bit signed integer +// (ap_int_base): ap_int<32>(1073741824.0) is 0, +// ap_uint<40>(4294967295.0) is 0xFFFFFFFFFF (g++ and csynth agree); +// * the implicit conversion to a built-in integer is the 64-bit one Vitis +// provides (`operator RetType()`): long long / unsigned long long; +// * range() / operator() / operator[] / bit() / (a, b) are VALUE-returning +// (const): `x.range(7, 0) = v` does not compile (Vitis uses reference +// proxies there; see tools/hls-est-validate/OPEN_ISSUES.md). +// clang rejects a signed _BitInt(1), so the signed 1-bit types (ap_int<1>, +// ap_fixed<1,I>) keep their bit in an `unsigned _BitInt(1)` (an i1 in the +// MLIR, as wide as in Vitis) and every value read goes through rval(), which +// sign-extends it (1 reads as -1). Known deviation: string constructors are +// not provided. +#ifndef HLSEST_EXACTCLASS_AP_INT_H +#define HLSEST_EXACTCLASS_AP_INT_H +#ifdef __cplusplus +// Vitis marks every ap_int / ap_fixed member and operator AP_INLINE, i.e. +// `inline __attribute__((always_inline))` under __SYNTHESIS__ +// (etc/ap_common.h): clang inlines them before Vitis's own inliner, which +// never lists them ([HLS 214-178]). cgeist's automatic-inlining rule +// (--hls-auto-inline, VITIS_NOTES N18) reads the same attribute. +#ifdef __clang__ +#pragma clang attribute push(__attribute__((always_inline)), apply_to = function) +#endif + +enum ap_q_mode { AP_RND, AP_RND_ZERO, AP_RND_MIN_INF, AP_RND_INF, AP_RND_CONV, AP_TRN, AP_TRN_ZERO }; +enum ap_o_mode { AP_SAT, AP_SAT_ZERO, AP_SAT_SYM, AP_WRAP, AP_WRAP_SM }; + +typedef long long ap_slong; +typedef unsigned long long ap_ulong; + +namespace ap_detail { +constexpr int max(int a, int b) { return a > b ? a : b; } +constexpr int min(int a, int b) { return a < b ? a : b; } + +// bits::type is the raw STORAGE type of an N-bit value (the one data +// member V); bits::vtype the type of its value and val() the read. +// A signed _BitInt needs >= 2 bits, so a signed 1-bit value is stored in an +// unsigned _BitInt(1) and read as -bit (0 or -1). +template struct bits { + typedef _BitInt((N < 2 ? 2 : N)) type; + typedef type vtype; + static constexpr vtype val(type v) { return v; } +}; +template <> struct bits<1, true> { + typedef unsigned _BitInt(1) type; + typedef _BitInt(2) vtype; + static constexpr vtype val(type v) { return -(vtype)v; } +}; +template struct bits { + typedef unsigned _BitInt((N < 1 ? 1 : N)) type; + typedef type vtype; + static constexpr vtype val(type v) { return v; } +}; +// Computation types (any width; >= 2 bits signed, >= 1 bit unsigned). +template using sbits = _BitInt((N < 2 ? 2 : N)); +template using ubits = unsigned _BitInt((N < 1 ? 1 : N)); + +// Width and signedness Vitis assigns to each C integer type in mixed +// expressions (ap_int_base.h ALL_OP_BIN_WITH_INT, ap_fixed_base.h +// ALL_AF_OP_WITH_INT). The primary template is empty so that +// `typename ctype::...` is a substitution failure for any other T. +template struct ctype {}; +template <> struct ctype { static constexpr int W = 1; static constexpr bool S = false; typedef bool type; }; +template <> struct ctype { static constexpr int W = 8; static constexpr bool S = ((char)-1 < 0); typedef char type; }; +template <> struct ctype { static constexpr int W = 8; static constexpr bool S = true; typedef signed char type; }; +template <> struct ctype { static constexpr int W = 8; static constexpr bool S = false; typedef unsigned char type; }; +template <> struct ctype { static constexpr int W = 16; static constexpr bool S = true; typedef short type; }; +template <> struct ctype { static constexpr int W = 16; static constexpr bool S = false; typedef unsigned short type; }; +template <> struct ctype { static constexpr int W = 32; static constexpr bool S = true; typedef int type; }; +template <> struct ctype { static constexpr int W = 32; static constexpr bool S = false; typedef unsigned type; }; +template <> struct ctype { static constexpr int W = 64; static constexpr bool S = true; typedef long type; }; +template <> struct ctype { static constexpr int W = 64; static constexpr bool S = false; typedef unsigned long type; }; +template <> struct ctype { static constexpr int W = 64; static constexpr bool S = true; typedef long long type; }; +template <> struct ctype { static constexpr int W = 64; static constexpr bool S = false; typedef unsigned long long type; }; + +// 2^E as a double, computed at compile time (a static constexpr member, so +// the frontend folds it to a constant; __builtin_ldexp would be a libc call). +constexpr double pow2_eval(int e) { + double r = 1.0; + for (int i = 0; i < (e < 0 ? -e : e); i++) r = e < 0 ? r * 0.5 : r * 2.0; + return r; +} +template struct pow2 { static constexpr double v = pow2_eval(E); }; +template struct rettype { typedef long long type; }; +template <> struct rettype { typedef unsigned long long type; }; + +// Conversion of a double holding an exactly converted FLOAT to a W-bit +// integer, as ap_int_base(float): decode the IEEE mantissa, shift it by the +// exponent (bits shifted out of W are lost), then negate in W bits, i.e. +// truncation toward zero, then wrap. NaN/inf: Vitis warns and proceeds with +// the raw bits; we do the same. +template +constexpr typename bits::type float_to_int(double d) { + typedef typename bits::type raw_t; + typedef ubits<(W > 64 ? W : 64)> uw; + unsigned long long b = __builtin_bit_cast(unsigned long long, d); + bool neg = (b >> 63) != 0; + int e = (int)((b >> 52) & 0x7ff); + unsigned long long m = b & ((1ull << 52) - 1); + if (e == 0 && m == 0) return (raw_t)0; + m |= 1ull << 52; + int exp = e - 1023; + uw mag = 0; + if (exp < 52) { + int sh = 52 - exp; + mag = sh < 54 ? (uw)(m >> sh) : (uw)0; + } else { + int sh = exp - 52; + mag = sh < W ? (uw)((uw)m << sh) : (uw)0; + } + ubits r = (ubits)mag; + return (raw_t)(neg ? (ubits)-r : r); +} +// ap_int_base(double) (etc/ap_int_base.h, Vitis 2025.1): as float_to_int, +// except that for 0 < 52 - exp < 54 (|d| < 2^52) the shifted mantissa is +// stored in an ap_int_base, a 25-bit SIGNED integer, +// before it is assigned (sign-extended) to the W-bit result. A value with +// 2^24 <= |d| < 2^52 therefore keeps only its low 25 bits, read as signed: +// ap_int<32>(1073741824.0) is 0, ap_int<32>(16777219.0) is -16777213, +// ap_uint<40>(4294967295.0) is 0xFFFFFFFFFF. Confirmed with g++ against the +// real headers and with csynth (a.o.3.ll stores the same constants). +template +constexpr typename bits::type double_to_int(double d) { + typedef typename bits::type raw_t; + unsigned long long b = __builtin_bit_cast(unsigned long long, d); + int e = (int)((b >> 52) & 0x7ff); + int sh = 52 - (e - 1023); + if (((b << 1) >> 1) == 0 || sh <= 0 || sh >= 54) return float_to_int(d); + bool neg = (b >> 63) != 0; + unsigned long long m = (b & ((1ull << 52) - 1)) | (1ull << 52); + unsigned long long t = (m >> sh) & 0x1ffffffull; // ap_int_base<25, true> + long long v = (t & 0x1000000ull) ? (long long)t - 0x2000000ll : (long long)t; + ubits r = (ubits)(sbits<(W > 64 ? W : 64)>)v; // sign-extend, then wrap + return (raw_t)(neg ? (ubits)-r : r); +} + +template constexpr sbits smin() { return S ? (sbits)(-((sbits)1 << (W - 1))) : (sbits)0; } +template constexpr sbits smax() { return S ? (sbits)(((sbits)1 << (W - 1)) - 1) : (sbits)(((sbits)1 << W) - 1); } +} // namespace ap_detail + +namespace ap_detail { +// Vitis compares two bitwidth integers with the C usual arithmetic +// conversions (etc/ap_private.h operator<): both narrower than int -> signed; +// same signedness -> that; mixed -> unsigned when the unsigned operand is at +// least as wide as the signed one, else signed. Operands arrive extended to +// MW bits by their own signedness. +template +constexpr bool cmp_lt(sbits l, sbits r) { + const bool sgn = (S1 == S2) ? S1 : ((W1 < 32 && W2 < 32) ? true : (S1 ? !(W2 >= W1) : !(W1 >= W2))); + return sgn ? (l < r) : ((ubits)l < (ubits)r); +} +template +constexpr bool cmp_eq(sbits l, sbits r) { return l == r; } +} // namespace ap_detail + +template struct ap_fixed_base; +template struct ap_fixed; +template struct ap_ufixed; +template struct ap_int; +template struct ap_uint; + +template struct _ap_int_factory { typedef ap_int type; }; +template struct _ap_int_factory { typedef ap_uint type; }; + +template struct ap_int_base { + static_assert(W > 0, "ap_int_base bitwidth must be positive"); + typedef typename ap_detail::bits::type raw_t; + static const int width = W; + static const bool sign = S; + + raw_t V; // the only data member (uninitialised by default, like Vitis) + + /// The value of V (sign-extends the bit of a signed 1-bit type). + typedef typename ap_detail::bits::vtype val_t; + constexpr val_t rval() const { return ap_detail::bits::val(V); } + + /// Result types of the binary operators (ap_int_base.h RType). + template struct RType { + enum { + mult_w = W + W2, + mult_s = S || S2, + plus_w = ap_detail::max(W + (S2 && !S), W2 + (S && !S2)) + 1, + plus_s = S || S2, + minus_w = ap_detail::max(W + (S2 && !S), W2 + (S && !S2)) + 1, + minus_s = true, + div_w = W + S2, + div_s = S || S2, + mod_w = ap_detail::min(W, W2 + (!S2 && S)), + mod_s = S, + logic_w = ap_detail::max(W + (S2 && !S), W2 + (S && !S2)), + logic_s = S || S2 + }; + typedef ap_int_base mult_base; + typedef ap_int_base plus_base; + typedef ap_int_base minus_base; + typedef ap_int_base logic_base; + typedef ap_int_base div_base; + typedef ap_int_base mod_base; + typedef ap_int_base arg1_base; + typedef typename _ap_int_factory::type mult; + typedef typename _ap_int_factory::type plus; + typedef typename _ap_int_factory::type minus; + typedef typename _ap_int_factory::type logic; + typedef typename _ap_int_factory::type div; + typedef typename _ap_int_factory::type mod; + typedef typename _ap_int_factory::type arg1; + typedef bool reduce; + }; + + // ---- constructors (all trivial or constexpr) ---------------------------- + ap_int_base() = default; + ap_int_base(const ap_int_base &) = default; + ap_int_base &operator=(const ap_int_base &) = default; + // from another width: sign/zero-extend by the SOURCE signedness, then wrap. + template + constexpr ap_int_base(const ap_int_base &o) : V((raw_t)o.rval()) {} + template ::type> + constexpr ap_int_base(T v) : V((raw_t)v) {} + constexpr ap_int_base(double d) : V(ap_detail::double_to_int(d)) {} + constexpr ap_int_base(float d) : V(ap_detail::float_to_int((double)d)) {} + // from a fixed-point value: its integer part (truncated toward zero, as + // Vitis to_ap_int_base()); defined in ap_fixed.h. + template + constexpr ap_int_base(const ap_fixed_base &o); + + template + constexpr ap_int_base &operator=(const ap_int_base &o) { V = (raw_t)o.rval(); return *this; } + template ::type> + constexpr ap_int_base &operator=(T v) { V = (raw_t)v; return *this; } + + // ---- conversions --------------------------------------------------------- + // Vitis: `operator RetType()` with RetType the 64-bit C integer of the + // same signedness (relied on for array subscripts and mixed arithmetic). + constexpr operator typename ap_detail::rettype::type() const { + return (typename ap_detail::rettype::type)rval(); + } + constexpr bool to_bool() const { return V != 0; } + constexpr char to_char() const { return (char)rval(); } + constexpr signed char to_schar() const { return (signed char)rval(); } + constexpr unsigned char to_uchar() const { return (unsigned char)rval(); } + constexpr short to_short() const { return (short)rval(); } + constexpr unsigned short to_ushort() const { return (unsigned short)rval(); } + constexpr int to_int() const { return (int)rval(); } + constexpr unsigned to_uint() const { return (unsigned)rval(); } + constexpr long to_long() const { return (long)rval(); } + constexpr unsigned long to_ulong() const { return (unsigned long)rval(); } + constexpr ap_slong to_int64() const { return (ap_slong)rval(); } + constexpr ap_ulong to_uint64() const { return (ap_ulong)rval(); } + constexpr float to_float() const { return (float)rval(); } + constexpr double to_double() const { return (double)rval(); } + constexpr _Float16 to_half() const { return (_Float16)(float)rval(); } + + constexpr int length() const { return W; } + constexpr bool iszero() const { return V == 0; } + constexpr bool is_zero() const { return V == 0; } + constexpr bool sign_bit() const { return ((ap_detail::ubits)V >> (W - 1)) & 1; } + + // ---- bit and slice selects (value-returning) ---------------------------- + constexpr bool operator[](int i) const { return (((ap_detail::ubits)V >> i) & 1) != 0; } + constexpr bool bit(int i) const { return (*this)[i]; } + constexpr bool get_bit(int i) const { return (*this)[i]; } + constexpr bool test(int i) const { return (*this)[i]; } + constexpr void set_bit(int i, bool b) { + ap_detail::ubits m = (ap_detail::ubits)1 << i; + V = (raw_t)(b ? ((ap_detail::ubits)V | m) : ((ap_detail::ubits)V & (ap_detail::ubits)~m)); + } + constexpr void set(int i) { set_bit(i, true); } + constexpr void set(int i, bool b) { set_bit(i, b); } + constexpr void clear(int i) { set_bit(i, false); } + constexpr void invert(int i) { set_bit(i, !(*this)[i]); } + // bits [hi:lo], zero-extended to W bits (what an ap_range_ref converts to). + constexpr const ap_int_base range(int hi, int lo) const { + ap_int_base r; + int h = hi, l = lo; + if (h < l) { h = lo; l = hi; } + int n = h - l + 1; + ap_detail::ubits v = (ap_detail::ubits)V >> l; + if (n < W) v &= (ap_detail::ubits)((((ap_detail::ubits)1) << n) - 1); + if (hi < lo) { // reversed select + ap_detail::ubits o = 0; + for (int k = 0; k < n; k++) o |= (ap_detail::ubits)(((v >> k) & 1)) << (n - 1 - k); + v = o; + } + r.V = v; + return r; + } + constexpr const ap_int_base range() const { ap_int_base r; r.V = (ap_detail::ubits)V; return r; } + constexpr const ap_int_base operator()(int hi, int lo) const { return range(hi, lo); } + constexpr const ap_int_base range(int hi, int lo) { return ((const ap_int_base *)this)->range(hi, lo); } + constexpr const ap_int_base operator()(int hi, int lo) { return range(hi, lo); } + + constexpr bool and_reduce() const { return (ap_detail::ubits)V == (ap_detail::ubits)~(ap_detail::ubits)0; } + constexpr bool nand_reduce() const { return !and_reduce(); } + constexpr bool or_reduce() const { return V != 0; } + constexpr bool nor_reduce() const { return V == 0; } + constexpr bool xor_reduce() const { + bool p = false; + for (int i = 0; i < W; i++) p ^= (*this)[i]; + return p; + } + constexpr bool xnor_reduce() const { return !xor_reduce(); } + constexpr void reverse() { + ap_detail::ubits o = 0, v = (ap_detail::ubits)V; + for (int k = 0; k < W; k++) o |= (ap_detail::ubits)((v >> k) & 1) << (W - 1 - k); + V = (raw_t)o; + } + constexpr int countLeadingZeros() const { + int n = 0; + for (int i = W - 1; i >= 0 && !(*this)[i]; i--) n++; + return n; + } + + // ---- unary --------------------------------------------------------------- + constexpr typename RType<1, false>::minus operator-() const { + typename RType<1, false>::minus_base r; + r.V = (typename RType<1, false>::minus_base::raw_t)(-(ap_detail::sbits)rval()); + return typename RType<1, false>::minus(r); + } + constexpr typename RType::arg1 operator+() const { return typename RType::arg1(*this); } + constexpr typename RType::arg1 operator~() const { + ap_int_base r; + r.V = (raw_t)~V; + return typename RType::arg1(r); + } + constexpr bool operator!() const { return V == 0; } + + constexpr ap_int_base &operator++() { V = (raw_t)((ap_detail::sbits)rval() + 1); return *this; } + constexpr ap_int_base &operator--() { V = (raw_t)((ap_detail::sbits)rval() - 1); return *this; } + constexpr const ap_int_base operator++(int) { ap_int_base t(*this); ++*this; return t; } + constexpr const ap_int_base operator--(int) { ap_int_base t(*this); --*this; return t; } + + // ---- shifts: the result keeps W bits ------------------------------------ + constexpr typename RType::arg1 operator<<(unsigned sh) const { + ap_int_base r; + r.V = sh < (unsigned)W ? (raw_t)((ap_detail::ubits)V << sh) : (raw_t)0; + return typename RType::arg1(r); + } + constexpr typename RType::arg1 operator>>(unsigned sh) const { + ap_int_base r; + if (sh < (unsigned)W) r.V = (raw_t)(rval() >> sh); + else r.V = (S && rval() < 0) ? (raw_t)-1 : (raw_t)0; + return typename RType::arg1(r); + } + constexpr typename RType::arg1 operator<<(int sh) const { return sh < 0 ? operator>>((unsigned)-sh) : operator<<((unsigned)sh); } + constexpr typename RType::arg1 operator>>(int sh) const { return sh < 0 ? operator<<((unsigned)-sh) : operator>>((unsigned)sh); } + template + constexpr typename RType::arg1 operator<<(const ap_int_base &o) const { return operator<<((int)o.to_int64()); } + template + constexpr typename RType::arg1 operator>>(const ap_int_base &o) const { return operator>>((int)o.to_int64()); } + template constexpr ap_int_base &operator<<=(const T &sh) { *this = operator<<(sh); return *this; } + template constexpr ap_int_base &operator>>=(const T &sh) { *this = operator>>(sh); return *this; } + + // ---- compound assignment (the binary operator, then wrap) --------------- + template constexpr ap_int_base &operator+=(const T &o) { *this = (*this + o); return *this; } + template constexpr ap_int_base &operator-=(const T &o) { *this = (*this - o); return *this; } + template constexpr ap_int_base &operator*=(const T &o) { *this = (*this * o); return *this; } + template constexpr ap_int_base &operator/=(const T &o) { *this = (*this / o); return *this; } + template constexpr ap_int_base &operator%=(const T &o) { *this = (*this % o); return *this; } + template constexpr ap_int_base &operator&=(const T &o) { *this = (*this & o); return *this; } + template constexpr ap_int_base &operator|=(const T &o) { *this = (*this | o); return *this; } + template constexpr ap_int_base &operator^=(const T &o) { *this = (*this ^ o); return *this; } +}; + +// ---- binary operators on two ap_int_base: exact in a wide type, then the +// Vitis result width (ap_int_base.h OP_BIN_AP / OP_BIN_AP2) -------------------- +namespace ap_detail { +template struct wide2 { typedef sbits type; }; +} +#define HLSEST_AP_INT_BIN(SYM, RTY) \ + template \ + constexpr typename ap_int_base::template RType::RTY operator SYM( \ + const ap_int_base &a, const ap_int_base &b) { \ + typedef typename ap_detail::wide2::type wide; \ + typename ap_int_base::template RType::RTY##_base r; \ + r.V = (typename ap_int_base::template RType::RTY##_base::raw_t)( \ + (wide)a.rval() SYM(wide) b.rval()); \ + return typename ap_int_base::template RType::RTY(r); \ + } +HLSEST_AP_INT_BIN(+, plus) +HLSEST_AP_INT_BIN(-, minus) +HLSEST_AP_INT_BIN(*, mult) +HLSEST_AP_INT_BIN(&, logic) +HLSEST_AP_INT_BIN(|, logic) +HLSEST_AP_INT_BIN(^, logic) +#undef HLSEST_AP_INT_BIN +// Division and modulo (etc/ap_private.h operator/ and operator%): both +// operands are extended by their own signedness to the common type of +// MAX(W1,W2) + (S1||S2) bits whose signedness is that of the wider operand +// (signed if either is, at equal widths); quotient and remainder are signed +// when that common type is. +// A negative value in an unsigned common type is therefore its bit pattern +// (ap_uint<16>(17272) / ap_int<8>(-1) is 0). A zero divisor is undefined +// (Vitis: `undef`; the IR carries `divsi x, 0`). +template +constexpr typename ap_int_base::template RType::div operator/( + const ap_int_base &a, const ap_int_base &b) { + typedef typename ap_int_base::template RType::div_base R; + const int MW = ap_detail::max(W1, W2) + (S1 || S2); + const bool CS = W1 > W2 ? S1 : (W2 > W1 ? S2 : (S1 || S2)); + typedef ap_detail::sbits sw; + typedef ap_detail::ubits uw; + sw l = (sw)a.rval(), r = (sw)b.rval(); + R res; + if (CS) res.V = (typename R::raw_t)(l / r); + else res.V = (typename R::raw_t)((uw)l / (uw)r); + return typename ap_int_base::template RType::div(res); +} +template +constexpr typename ap_int_base::template RType::mod operator%( + const ap_int_base &a, const ap_int_base &b) { + typedef typename ap_int_base::template RType::mod_base R; + const int MW = ap_detail::max(W1, W2) + (S1 || S2); + const bool CS = W1 > W2 ? S1 : (W2 > W1 ? S2 : (S1 || S2)); + typedef ap_detail::sbits sw; + typedef ap_detail::ubits uw; + sw l = (sw)a.rval(), r = (sw)b.rval(); + R res; + if (CS) res.V = (typename R::raw_t)(l % r); + else res.V = (typename R::raw_t)((uw)l % (uw)r); + return typename ap_int_base::template RType::mod(res); +} +#define HLSEST_AP_INT_REL(SYM, EXPR) \ + template \ + constexpr bool operator SYM(const ap_int_base &a, const ap_int_base &b) { \ + const int MW = ap_detail::max(W1, W2) + 1; \ + ap_detail::sbits l = (ap_detail::sbits)a.rval(), r = (ap_detail::sbits)b.rval(); \ + return EXPR; \ + } +HLSEST_AP_INT_REL(<, (ap_detail::cmp_lt(l, r))) +HLSEST_AP_INT_REL(>, (ap_detail::cmp_lt(r, l))) +HLSEST_AP_INT_REL(<=, (!ap_detail::cmp_lt(r, l))) +HLSEST_AP_INT_REL(>=, (!ap_detail::cmp_lt(l, r))) +HLSEST_AP_INT_REL(==, (ap_detail::cmp_eq(l, r))) +HLSEST_AP_INT_REL(!=, (!ap_detail::cmp_eq(l, r))) +#undef HLSEST_AP_INT_REL + +// ---- mixed with C integers: the C value becomes ap_int_base +// (ap_int_base.h ALL_OP_BIN_WITH_INT / ALL_OP_REL_WITH_INT). ------------------ +#define HLSEST_AP_INT_MIX(SYM, RTY) \ + template \ + constexpr typename ap_int_base::template RType::W, \ + ap_detail::ctype::S>::RTY \ + operator SYM(const ap_int_base &a, T b) { \ + return a SYM ap_int_base::W, ap_detail::ctype::S>(b); \ + } \ + template \ + constexpr typename ap_int_base::template RType::W, \ + ap_detail::ctype::S>::RTY \ + operator SYM(T a, const ap_int_base &b) { \ + return ap_int_base::W, ap_detail::ctype::S>(a) SYM b; \ + } +HLSEST_AP_INT_MIX(+, plus) +HLSEST_AP_INT_MIX(-, minus) +HLSEST_AP_INT_MIX(*, mult) +HLSEST_AP_INT_MIX(/, div) +HLSEST_AP_INT_MIX(%, mod) +HLSEST_AP_INT_MIX(&, logic) +HLSEST_AP_INT_MIX(|, logic) +HLSEST_AP_INT_MIX(^, logic) +#undef HLSEST_AP_INT_MIX +#define HLSEST_AP_INT_MIXREL(SYM) \ + template ::type> \ + constexpr bool operator SYM(const ap_int_base &a, T b) { \ + return a SYM ap_int_base::W, ap_detail::ctype::S>(b); \ + } \ + template ::type> \ + constexpr bool operator SYM(T a, const ap_int_base &b) { \ + return ap_int_base::W, ap_detail::ctype::S>(a) SYM b; \ + } +HLSEST_AP_INT_MIXREL(<) +HLSEST_AP_INT_MIXREL(>) +HLSEST_AP_INT_MIXREL(<=) +HLSEST_AP_INT_MIXREL(>=) +HLSEST_AP_INT_MIXREL(==) +HLSEST_AP_INT_MIXREL(!=) +#undef HLSEST_AP_INT_MIXREL + +// Concatenation (a, b): the W1+W2 raw bits, unsigned. +template +constexpr const ap_uint operator,(const ap_int_base &a, const ap_int_base &b) { + ap_int_base r; + r.V = ((ap_detail::ubits)(ap_detail::ubits)a.V << W2) | (ap_detail::ubits)(ap_detail::ubits)b.V; + return ap_uint(r); +} + +template struct ap_int : ap_int_base { + typedef ap_int_base Base; + ap_int() = default; + ap_int(const ap_int &) = default; + ap_int &operator=(const ap_int &) = default; + template constexpr ap_int(const T &v) : Base(v) {} + template constexpr ap_int &operator=(const T &v) { this->V = ap_int(v).V; return *this; } +}; +template struct ap_uint : ap_int_base { + typedef ap_int_base Base; + ap_uint() = default; + ap_uint(const ap_uint &) = default; + ap_uint &operator=(const ap_uint &) = default; + template constexpr ap_uint(const T &v) : Base(v) {} + template constexpr ap_uint &operator=(const T &v) { this->V = ap_uint(v).V; return *this; } +}; + +#ifdef __clang__ +#pragma clang attribute pop +#endif + +#include "ap_fixed.h" + +#endif // __cplusplus +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/cgeist_flags b/tools/cgeist/Test/HLS/Inputs/vitis/cgeist_flags new file mode 100644 index 000000000000..0e1caa2a521b --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/cgeist_flags @@ -0,0 +1,5 @@ +--scalar-wrapper-abi +# Math-core markers in hls_math.h: the fixed-point math functions call +# __hlsest_math_(args..., W, I, S) instead of the libm builtin, so that +# hls-est (--bram-analysis math-costs=) sees the ap_fixed type of each call. +-DHLSEST_MATH_MARKERS diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/hls_half.h b/tools/cgeist/Test/HLS/Inputs/vitis/hls_half.h new file mode 100644 index 000000000000..987a8f70c6a4 --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/hls_half.h @@ -0,0 +1,6 @@ +// hls-est "exactclass" stand-in for the Vitis HLS hls_half.h: half is the +// 16-bit IEEE binary16 type (cgeist lowers _Float16 to f16). +#ifndef HLSEST_EXACTCLASS_HLS_HALF_H +#define HLSEST_EXACTCLASS_HLS_HALF_H +typedef _Float16 half; +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/hls_math.h b/tools/cgeist/Test/HLS/Inputs/vitis/hls_math.h new file mode 100644 index 000000000000..b7da02734beb --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/hls_math.h @@ -0,0 +1,418 @@ +// hls-est "exactclass" stand-in for the Vitis HLS hls_math.h, over the +// _BitInt-backed ap_fixed / ap_int classes of ap_fixed.h and over the native +// float / double / half types. +// +// Bit-exactness vs Vitis 2025.1 (tools/hls-est-validate/VITIS_NOTES.md): +// sqrt exact: etc/hls_sqrt_apfixed.h returns 0 for a negative input and the +// root rounded half-up to F fractional bits (checked exhaustively for +// ap_fixed<16,5> by check_shim.py). +// exp etc/hls_exp_apfixed.h is a 3-table approximation that SATURATES to +// the type's maximum (it never wraps). It is "All Rights Reserved" in +// the Vitis install and not part of the Apache-2.0 +// HLS_arbitrary_Precision_Types repository, so it is not ported: this +// shim returns floor(exp(x)*2^F) with the same saturation, which +// differs from the tables by one LSB, in either direction, on ~1% of +// the inputs (909 of 38 447 ap_fixed<16,5> inputs; check_shim.py). +// log, tanh, sin, cos, atan, pow, rsqrt and the rest are evaluated in +// double and truncated (floor) to the Vitis result type; Vitis uses +// CORDIC / table algorithms there, so a last-bit difference is +// possible ("unconfirmed" in VITIS_NOTES.md). recip is 1/x with the +// exact fixed-point division. pow of two ap_fixed values of one type +// is evaluated in double too (Vitis 2025.1 synthesizes a fixed-point +// pow core, pow_16_5_s for ap_fixed<16,5>; its last bits are not +// checked here). Before this overload the call was ambiguous between +// the float, double and half overloads and did not compile. +// Math-core markers (for hls-est --bram-analysis math-costs=, the cost table +// tools/hls-est-validate/math_costs.json): with +// -DHLSEST_MATH_MARKERS (this directory's cgeist_flags) the builtin call at the +// heart of every fixed-point function below (__builtin_exp, __builtin_sqrt, +// ...) becomes a call of the extern "C" declaration +// __hlsest_math_(args..., W, I, S) of the ARGUMENT's ap_fixed_base +// parameters, so hls-est can price the Vitis core of hls:: on +// ap_fixed (S = 0: ap_ufixed). It replaces a call that is already opaque +// (cgeist emits these builtins as calls of the libm functions; sqrt is a +// math.sqrt next to the opaque floor of raw_sat), returns the builtin's value +// and is never constant-evaluated (none of these builtins is constexpr in +// clang 18), so the IR is the same up to the callee's name and its three +// constant operands. Functions computed in integer arithmetic (recip, abs, +// fabs, floor, ceil, trunc, fmin, fmax, fdim, copysign) have no such call and +// no marker; round / rint keep __builtin_round / __builtin_rint (hls-est does +// not price rounding). Without the macro (host compilers: check_shim.py, and +// check_semantics.py's native builds, which drop it) the builtins are called +// directly, as before; check_semantics.py links the MLIR's markers to stubs +// that call the builtin. +#ifndef HLSEST_EXACTCLASS_HLS_MATH_H +#define HLSEST_EXACTCLASS_HLS_MATH_H +#include +#ifdef __cplusplus +#include "ap_fixed.h" +#include "hls_half.h" + +#ifdef HLSEST_MATH_MARKERS +extern "C" { +#define HLSEST_MDECL1(N) double __hlsest_math_##N(double, int, int, int); +#define HLSEST_MDECL2(N) double __hlsest_math_##N(double, double, int, int, int); +HLSEST_MDECL1(sqrt) HLSEST_MDECL1(exp) HLSEST_MDECL1(exp2) HLSEST_MDECL1(expm1) +HLSEST_MDECL1(log) HLSEST_MDECL1(log2) HLSEST_MDECL1(log10) HLSEST_MDECL1(log1p) +HLSEST_MDECL1(logb) HLSEST_MDECL1(tanh) HLSEST_MDECL1(sinh) HLSEST_MDECL1(cosh) +HLSEST_MDECL1(atanh) HLSEST_MDECL1(asinh) HLSEST_MDECL1(acosh) HLSEST_MDECL1(erf) +HLSEST_MDECL1(erfc) HLSEST_MDECL1(cbrt) HLSEST_MDECL1(rsqrt) HLSEST_MDECL1(tan) +HLSEST_MDECL1(sinpi) HLSEST_MDECL1(cospi) HLSEST_MDECL1(sin) HLSEST_MDECL1(cos) +HLSEST_MDECL1(atan) HLSEST_MDECL1(asin) HLSEST_MDECL1(acos) +HLSEST_MDECL2(atan2) HLSEST_MDECL2(pow) +#undef HLSEST_MDECL1 +#undef HLSEST_MDECL2 +} +// N: the hls:: function, B: the builtin it stands for (the value returned); +// W, I, S: the template parameters of the enclosing fixed-point overload. +#define HLSEST_M1(N, B, X) __hlsest_math_##N((X), W, I, (int)S) +#define HLSEST_M2(N, B, X, Y) __hlsest_math_##N((X), (Y), W, I, (int)S) +#else +#define HLSEST_M1(N, B, X) B(X) +#define HLSEST_M2(N, B, X, Y) B((X), (Y)) +#endif + +namespace hls { +namespace detail { +// floor(rawv) clamped to the raw range of ap_fixed_base (the +// fixed-point library functions saturate rather than wrap). +template +constexpr typename ap_detail::bits::type raw_sat(double rawv) { + typedef typename ap_detail::bits::type raw_t; + double s = __builtin_floor(rawv); + double mx = (double)(ap_detail::sbits)ap_detail::smax(); + double mn = (double)(ap_detail::sbits)ap_detail::smin(); + if (!(s == s)) return (raw_t)0; // NaN + if (s >= mx) return (raw_t)ap_detail::smax(); + if (s <= mn) return (raw_t)ap_detail::smin(); + return (raw_t)(ap_detail::sbits)s; +} +// floor(d * 2^F) as that raw. +template +constexpr typename ap_detail::bits::type raw_from_double_sat(double d) { + return raw_sat(d * ap_detail::pow2::v); +} +template +constexpr ap_fixed_base fixed_from_double_sat(double d) { + ap_fixed_base r; + r.V = raw_from_double_sat(d); + return r; +} +} // namespace detail + +// ---- native types ----------------------------------------------------------- +#define HLSEST_NATIVE1(NAME, F, D) \ + inline float NAME(float x) { return F(x); } \ + inline double NAME(double x) { return D(x); } \ + inline half NAME(half x) { return (half)F((float)x); } +HLSEST_NATIVE1(sqrt, __builtin_sqrtf, __builtin_sqrt) +HLSEST_NATIVE1(exp, __builtin_expf, __builtin_exp) +HLSEST_NATIVE1(exp2, __builtin_exp2f, __builtin_exp2) +HLSEST_NATIVE1(expm1, __builtin_expm1f, __builtin_expm1) +HLSEST_NATIVE1(log, __builtin_logf, __builtin_log) +HLSEST_NATIVE1(log2, __builtin_log2f, __builtin_log2) +HLSEST_NATIVE1(log10, __builtin_log10f, __builtin_log10) +HLSEST_NATIVE1(log1p, __builtin_log1pf, __builtin_log1p) +HLSEST_NATIVE1(sin, __builtin_sinf, __builtin_sin) +HLSEST_NATIVE1(cos, __builtin_cosf, __builtin_cos) +HLSEST_NATIVE1(tan, __builtin_tanf, __builtin_tan) +HLSEST_NATIVE1(asin, __builtin_asinf, __builtin_asin) +HLSEST_NATIVE1(acos, __builtin_acosf, __builtin_acos) +HLSEST_NATIVE1(atan, __builtin_atanf, __builtin_atan) +HLSEST_NATIVE1(sinh, __builtin_sinhf, __builtin_sinh) +HLSEST_NATIVE1(cosh, __builtin_coshf, __builtin_cosh) +HLSEST_NATIVE1(tanh, __builtin_tanhf, __builtin_tanh) +HLSEST_NATIVE1(asinh, __builtin_asinhf, __builtin_asinh) +HLSEST_NATIVE1(acosh, __builtin_acoshf, __builtin_acosh) +HLSEST_NATIVE1(atanh, __builtin_atanhf, __builtin_atanh) +HLSEST_NATIVE1(erf, __builtin_erff, __builtin_erf) +HLSEST_NATIVE1(erfc, __builtin_erfcf, __builtin_erfc) +HLSEST_NATIVE1(fabs, __builtin_fabsf, __builtin_fabs) +HLSEST_NATIVE1(abs, __builtin_fabsf, __builtin_fabs) +HLSEST_NATIVE1(floor, __builtin_floorf, __builtin_floor) +HLSEST_NATIVE1(ceil, __builtin_ceilf, __builtin_ceil) +HLSEST_NATIVE1(trunc, __builtin_truncf, __builtin_trunc) +HLSEST_NATIVE1(round, __builtin_roundf, __builtin_round) +HLSEST_NATIVE1(rint, __builtin_rintf, __builtin_rint) +HLSEST_NATIVE1(nearbyint, __builtin_nearbyintf, __builtin_nearbyint) +HLSEST_NATIVE1(cbrt, __builtin_cbrtf, __builtin_cbrt) +HLSEST_NATIVE1(logb, __builtin_logbf, __builtin_logb) +#undef HLSEST_NATIVE1 +inline float rsqrt(float x) { return 1.0f / __builtin_sqrtf(x); } +inline double rsqrt(double x) { return 1.0 / __builtin_sqrt(x); } +inline half rsqrt(half x) { return (half)(1.0f / __builtin_sqrtf((float)x)); } +inline float recip(float x) { return 1.0f / x; } +inline double recip(double x) { return 1.0 / x; } +inline half recip(half x) { return (half)(1.0f / (float)x); } +inline float pow(float x, float y) { return __builtin_powf(x, y); } +inline double pow(double x, double y) { return __builtin_pow(x, y); } +inline half pow(half x, half y) { return (half)__builtin_powf((float)x, (float)y); } +inline float atan2(float y, float x) { return __builtin_atan2f(y, x); } +inline double atan2(double y, double x) { return __builtin_atan2(y, x); } +inline float hypot(float x, float y) { return __builtin_hypotf(x, y); } +inline double hypot(double x, double y) { return __builtin_hypot(x, y); } +inline float fmod(float x, float y) { return __builtin_fmodf(x, y); } +inline double fmod(double x, double y) { return __builtin_fmod(x, y); } +inline float fmax(float a, float b) { return a > b ? a : b; } +inline double fmax(double a, double b) { return a > b ? a : b; } +inline float fmin(float a, float b) { return a < b ? a : b; } +inline double fmin(double a, double b) { return a < b ? a : b; } +inline float copysign(float x, float y) { return __builtin_copysignf(x, y); } +inline double copysign(double x, double y) { return __builtin_copysign(x, y); } +inline float nextafter(float x, float y) { return __builtin_nextafterf(x, y); } +inline double nextafter(double x, double y) { return __builtin_nextafter(x, y); } +inline bool signbit(float x) { return __builtin_signbit(x); } +inline bool signbit(double x) { return __builtin_signbit(x); } +inline bool isnan(float x) { return x != x; } +inline bool isnan(double x) { return x != x; } +inline bool isinf(float x) { return __builtin_isinf(x); } +inline bool isinf(double x) { return __builtin_isinf(x); } +inline bool isfinite(float x) { return __builtin_isfinite(x); } +inline bool isfinite(double x) { return __builtin_isfinite(x); } +inline float expf(float x) { return __builtin_expf(x); } +inline float logf(float x) { return __builtin_logf(x); } +inline float sqrtf(float x) { return __builtin_sqrtf(x); } +inline float powf(float x, float y) { return __builtin_powf(x, y); } +inline float fabsf(float x) { return __builtin_fabsf(x); } +inline float sinf(float x) { return __builtin_sinf(x); } +inline float cosf(float x) { return __builtin_cosf(x); } +inline float tanhf(float x) { return __builtin_tanhf(x); } +inline float floorf(float x) { return __builtin_floorf(x); } +inline float ceilf(float x) { return __builtin_ceilf(x); } +inline float roundf(float x) { return __builtin_roundf(x); } +inline float fmaxf(float a, float b) { return a > b ? a : b; } +inline float fminf(float a, float b) { return a < b ? a : b; } +template T max(T a, T b) { return a > b ? a : b; } +template T min(T a, T b) { return a < b ? a : b; } + +// ---- fixed point: core on ap_fixed_base, then the derived overloads ---------- +#define HLSEST_FB template +#define HLSEST_FBT ap_fixed_base + +// sqrt (etc/hls_sqrt_apfixed.h): round-half-up of the exact root. The generic +// branch returns 0 for a negative input (and for I <= 0 when the bits above +// position W+I-2 are set); the small lookup-table branches (F == 0 && I <= 13, +// F <= 4 && I <= 5) drop the sign bit first and take the root of the +// remaining W-1 bits as an unsigned value. +HLSEST_FB constexpr ap_fixed_base sqrt(const HLSEST_FBT &x) { + ap_fixed_base r; + const int F = W - I; + const bool table = (F == 0 && I <= 13) || (F <= 4 && I <= 5); + double xv = x.to_double(); + if (S && x.rval() < 0) { + if (!table) { r.V = 0; return r; } + xv = (double)((ap_detail::ubits)x.V & (ap_detail::ubits)((((ap_detail::ubits)1) << (W - 1)) - 1)) * ap_detail::pow2<-(W - I)>::v; + } else if (!table && I <= 0) { + const int lsbx = (-I + 2 <= W) ? (W + I - 2) : 0; + if (((ap_detail::ubits)x.V >> lsbx) != 0) { r.V = 0; return r; } + } + double s = HLSEST_M1(sqrt, __builtin_sqrt, xv); + r.V = detail::raw_sat(s * ap_detail::pow2::v + 0.5); + return r; +} +// exp: floor(exp(x)*2^F), saturating to the maximum (never wraps). +HLSEST_FB constexpr ap_fixed_base exp(const HLSEST_FBT &x) { + if (I > 33 || W - I > 32) { ap_fixed_base z; z.V = 0; return z; } + return detail::fixed_from_double_sat(HLSEST_M1(exp, __builtin_exp, x.to_double())); +} +#define HLSEST_FIXED_VIA_DOUBLE(NAME, EXPR) \ + HLSEST_FB constexpr ap_fixed_base NAME(const HLSEST_FBT &x) { \ + double d = x.to_double(); \ + (void)d; \ + return detail::fixed_from_double_sat(EXPR); \ + } +HLSEST_FIXED_VIA_DOUBLE(log, d > 0 ? HLSEST_M1(log, __builtin_log, d) : 0.0) +HLSEST_FIXED_VIA_DOUBLE(log2, d > 0 ? HLSEST_M1(log2, __builtin_log2, d) : 0.0) +HLSEST_FIXED_VIA_DOUBLE(log10, d > 0 ? HLSEST_M1(log10, __builtin_log10, d) : 0.0) +HLSEST_FIXED_VIA_DOUBLE(logb, d > 0 ? HLSEST_M1(logb, __builtin_logb, d) : 0.0) +HLSEST_FIXED_VIA_DOUBLE(exp2, HLSEST_M1(exp2, __builtin_exp2, d)) +HLSEST_FIXED_VIA_DOUBLE(expm1, HLSEST_M1(expm1, __builtin_expm1, d)) +HLSEST_FIXED_VIA_DOUBLE(log1p, HLSEST_M1(log1p, __builtin_log1p, d)) +HLSEST_FIXED_VIA_DOUBLE(tanh, HLSEST_M1(tanh, __builtin_tanh, d)) +HLSEST_FIXED_VIA_DOUBLE(sinh, HLSEST_M1(sinh, __builtin_sinh, d)) +HLSEST_FIXED_VIA_DOUBLE(cosh, HLSEST_M1(cosh, __builtin_cosh, d)) +HLSEST_FIXED_VIA_DOUBLE(atanh, HLSEST_M1(atanh, __builtin_atanh, d)) +HLSEST_FIXED_VIA_DOUBLE(asinh, HLSEST_M1(asinh, __builtin_asinh, d)) +HLSEST_FIXED_VIA_DOUBLE(acosh, HLSEST_M1(acosh, __builtin_acosh, d)) +HLSEST_FIXED_VIA_DOUBLE(erf, HLSEST_M1(erf, __builtin_erf, d)) +HLSEST_FIXED_VIA_DOUBLE(erfc, HLSEST_M1(erfc, __builtin_erfc, d)) +HLSEST_FIXED_VIA_DOUBLE(cbrt, HLSEST_M1(cbrt, __builtin_cbrt, d)) +HLSEST_FIXED_VIA_DOUBLE(rsqrt, d > 0 ? 1.0 / HLSEST_M1(rsqrt, __builtin_sqrt, d) : 0.0) +HLSEST_FIXED_VIA_DOUBLE(tan, HLSEST_M1(tan, __builtin_tan, d)) +HLSEST_FIXED_VIA_DOUBLE(sinpi, HLSEST_M1(sinpi, __builtin_sin, d * 3.14159265358979323846)) +HLSEST_FIXED_VIA_DOUBLE(cospi, HLSEST_M1(cospi, __builtin_cos, d * 3.14159265358979323846)) +#undef HLSEST_FIXED_VIA_DOUBLE +// sin / cos return ap_fixed, atan ap_fixed, asin / acos +// ap_fixed (hls_math.h signatures). +HLSEST_FB constexpr ap_fixed_base sin(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(HLSEST_M1(sin, __builtin_sin, x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base cos(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(HLSEST_M1(cos, __builtin_cos, x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base atan(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(HLSEST_M1(atan, __builtin_atan, x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base asin(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(HLSEST_M1(asin, __builtin_asin, x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base acos(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(HLSEST_M1(acos, __builtin_acos, x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base atan2(const HLSEST_FBT &y, const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(HLSEST_M2(atan2, __builtin_atan2, y.to_double(), x.to_double())); +} +// pow: evaluated in double like log (Vitis has a fixed-point pow core, +// pow_W_I_s; last-bit agreement not checked). +HLSEST_FB constexpr ap_fixed_base pow(const HLSEST_FBT &x, const HLSEST_FBT &y) { + return detail::fixed_from_double_sat(HLSEST_M2(pow, __builtin_pow, x.to_double(), y.to_double())); +} +// recip: 1 / x with the exact fixed-point division (truncation). +HLSEST_FB constexpr ap_fixed_base recip(const HLSEST_FBT &x) { + ap_fixed_base r; + if (x.V == 0) { r.V = 0; return r; } + r = ap_fixed_base<2, 2, true>(1) / x; + return r; +} +// Rounding to integers, exact on the raw bits. +HLSEST_FB constexpr ap_fixed_base floor(const HLSEST_FBT &x) { + ap_fixed_base r; + const int F = W - I; + if (F <= 0) { r.V = x.V; return r; } // no fractional bits + if (F >= W) { r.V = 0; return r; } // |x| < 1: floor is 0 or an unrepresentable -1 (wraps to 0) + r.V = (typename HLSEST_FBT::raw_t)((ap_detail::ubits)x.V & + (ap_detail::ubits)~(ap_detail::ubits)((((ap_detail::ubits)1) << F) - 1)); + return r; +} +HLSEST_FB constexpr ap_fixed_base ceil(const HLSEST_FBT &x) { + ap_fixed_base r = floor(x); + if (r.V != x.V) r += 1; + return r; +} +HLSEST_FB constexpr ap_fixed_base trunc(const HLSEST_FBT &x) { + ap_fixed_base r = floor(x); + if (S && x.rval() < 0 && r.V != x.V) r += 1; + return r; +} +HLSEST_FB constexpr ap_fixed_base round(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(__builtin_round(x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base rint(const HLSEST_FBT &x) { + return detail::fixed_from_double_sat(__builtin_rint(x.to_double())); +} +HLSEST_FB constexpr ap_fixed_base fabs(const HLSEST_FBT &x) { + ap_fixed_base r; + r.V = (S && x.rval() < 0) ? (typename HLSEST_FBT::raw_t)(-x.rval()) : x.V; + return r; +} +HLSEST_FB constexpr ap_fixed_base abs(const HLSEST_FBT &x) { return fabs(x); } +HLSEST_FB constexpr ap_fixed_base fmax(const HLSEST_FBT &a, const HLSEST_FBT &b) { return a > b ? a : b; } +HLSEST_FB constexpr ap_fixed_base fmin(const HLSEST_FBT &a, const HLSEST_FBT &b) { return a < b ? a : b; } +HLSEST_FB constexpr ap_fixed_base fdim(const HLSEST_FBT &a, const HLSEST_FBT &b) { + ap_fixed_base r; + if (a > b) r = a - b; else r.V = 0; + return r; +} +HLSEST_FB constexpr ap_fixed_base copysign(const HLSEST_FBT &a, const HLSEST_FBT &b) { + ap_fixed_base r = fabs(a); + if (S && b.rval() < 0) r.V = (typename HLSEST_FBT::raw_t)(-r.rval()); + return r; +} +HLSEST_FB constexpr bool signbit(const HLSEST_FBT &x) { return S && x.rval() < 0; } +HLSEST_FB constexpr bool isnan(const HLSEST_FBT &) { return false; } +HLSEST_FB constexpr bool isinf(const HLSEST_FBT &) { return false; } +HLSEST_FB constexpr bool isfinite(const HLSEST_FBT &) { return true; } + +// Derived-type overloads: same result type as the argument (Vitis returns +// ap_fixed / ap_ufixed); the base overload above is picked for the +// intermediate ap_fixed_base results of arithmetic. +#define HLSEST_FIXED_DERIVED(NAME) \ + template \ + constexpr ap_fixed NAME(const ap_fixed &x) { \ + return ap_fixed(NAME((const ap_fixed_base &)x)); \ + } \ + template \ + constexpr ap_ufixed NAME(const ap_ufixed &x) { \ + return ap_ufixed(NAME((const ap_fixed_base &)x)); \ + } \ + template constexpr ap_int NAME(const ap_int &x) { \ + return ap_int(NAME(ap_fixed_base(x))); \ + } \ + template constexpr ap_uint NAME(const ap_uint &x) { \ + return ap_uint(NAME(ap_fixed_base(x))); \ + } +HLSEST_FIXED_DERIVED(sqrt) +HLSEST_FIXED_DERIVED(exp) +HLSEST_FIXED_DERIVED(exp2) +HLSEST_FIXED_DERIVED(expm1) +HLSEST_FIXED_DERIVED(log) +HLSEST_FIXED_DERIVED(log2) +HLSEST_FIXED_DERIVED(log10) +HLSEST_FIXED_DERIVED(log1p) +HLSEST_FIXED_DERIVED(logb) +HLSEST_FIXED_DERIVED(tanh) +HLSEST_FIXED_DERIVED(sinh) +HLSEST_FIXED_DERIVED(cosh) +HLSEST_FIXED_DERIVED(atanh) +HLSEST_FIXED_DERIVED(asinh) +HLSEST_FIXED_DERIVED(acosh) +HLSEST_FIXED_DERIVED(erf) +HLSEST_FIXED_DERIVED(erfc) +HLSEST_FIXED_DERIVED(cbrt) +HLSEST_FIXED_DERIVED(rsqrt) +HLSEST_FIXED_DERIVED(recip) +HLSEST_FIXED_DERIVED(tan) +HLSEST_FIXED_DERIVED(floor) +HLSEST_FIXED_DERIVED(ceil) +HLSEST_FIXED_DERIVED(trunc) +HLSEST_FIXED_DERIVED(round) +HLSEST_FIXED_DERIVED(rint) +HLSEST_FIXED_DERIVED(fabs) +HLSEST_FIXED_DERIVED(abs) +HLSEST_FIXED_DERIVED(sinpi) +HLSEST_FIXED_DERIVED(cospi) +#undef HLSEST_FIXED_DERIVED +#define HLSEST_FIXED_DERIVED2(NAME) \ + template \ + constexpr ap_fixed NAME(const ap_fixed &a, \ + const ap_fixed &b) { \ + return ap_fixed(NAME((const ap_fixed_base &)a, \ + (const ap_fixed_base &)b)); \ + } \ + template \ + constexpr ap_ufixed NAME(const ap_ufixed &a, \ + const ap_ufixed &b) { \ + return ap_ufixed(NAME((const ap_fixed_base &)a, \ + (const ap_fixed_base &)b)); \ + } +HLSEST_FIXED_DERIVED2(fmax) +HLSEST_FIXED_DERIVED2(fmin) +HLSEST_FIXED_DERIVED2(fdim) +HLSEST_FIXED_DERIVED2(copysign) +HLSEST_FIXED_DERIVED2(pow) +#undef HLSEST_FIXED_DERIVED2 +template +constexpr ap_fixed sin(const ap_fixed &x) { return ap_fixed(sin((const ap_fixed_base &)x)); } +template +constexpr ap_fixed cos(const ap_fixed &x) { return ap_fixed(cos((const ap_fixed_base &)x)); } +template +constexpr ap_fixed atan(const ap_fixed &x) { return ap_fixed(atan((const ap_fixed_base &)x)); } +template +constexpr ap_fixed asin(const ap_fixed &x) { return ap_fixed(asin((const ap_fixed_base &)x)); } +template +constexpr ap_fixed acos(const ap_fixed &x) { return ap_fixed(acos((const ap_fixed_base &)x)); } +template +constexpr ap_fixed atan2(const ap_fixed &y, const ap_fixed &x) { + return ap_fixed(atan2((const ap_fixed_base &)y, (const ap_fixed_base &)x)); +} +template +constexpr ap_ufixed sin(const ap_ufixed &x) { return ap_ufixed(sin((const ap_fixed_base &)x)); } +template +constexpr ap_ufixed cos(const ap_ufixed &x) { return ap_ufixed(cos((const ap_fixed_base &)x)); } +#undef HLSEST_FB +#undef HLSEST_FBT +} // namespace hls +#undef HLSEST_M1 +#undef HLSEST_M2 +#endif // __cplusplus +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/hls_stream.h b/tools/cgeist/Test/HLS/Inputs/vitis/hls_stream.h new file mode 100644 index 000000000000..dc6f4771c24e --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/hls_stream.h @@ -0,0 +1,31 @@ +// Minimal stand-in for the Vitis HLS hls_stream.h, for cgeist tests only. +// Stream operations are declared, not defined: cgeist emits them as calls to +// external functions, which is all pragma extraction needs. +#ifndef CGEIST_TEST_HLS_STREAM_H +#define CGEIST_TEST_HLS_STREAM_H + +#ifdef __cplusplus +namespace hls { + +template class stream { +public: + stream(); + stream(const char *name); + T read(); + void read(T &v); + bool read_nb(T &v); + void write(const T &v); + bool write_nb(const T &v); + bool empty() const; + bool full() const; + int size() const; + void operator>>(T &v); + void operator<<(const T &v); + +private: + int handle; +}; + +} // namespace hls +#endif // __cplusplus +#endif diff --git a/tools/cgeist/Test/HLS/Inputs/vitis/hls_vector.h b/tools/cgeist/Test/HLS/Inputs/vitis/hls_vector.h new file mode 100644 index 000000000000..5a82896c8126 --- /dev/null +++ b/tools/cgeist/Test/HLS/Inputs/vitis/hls_vector.h @@ -0,0 +1,44 @@ +// Minimal stand-in for the Vitis HLS hls_vector.h, for cgeist tests only. +#ifndef CGEIST_TEST_HLS_VECTOR_H +#define CGEIST_TEST_HLS_VECTOR_H + +#ifdef __cplusplus +#include + +namespace hls { +template class vector { +public: + T data[N]; + T &operator[](size_t i) { return data[i]; } + const T &operator[](size_t i) const { return data[i]; } + vector &operator+=(const vector &o) { + for (size_t i = 0; i < N; ++i) + data[i] += o.data[i]; + return *this; + } + vector &operator-=(const vector &o) { + for (size_t i = 0; i < N; ++i) + data[i] -= o.data[i]; + return *this; + } + vector &operator*=(const vector &o) { + for (size_t i = 0; i < N; ++i) + data[i] *= o.data[i]; + return *this; + } +}; +template +vector operator+(vector a, const vector &b) { + return a += b; +} +template +vector operator-(vector a, const vector &b) { + return a -= b; +} +template +vector operator*(vector a, const vector &b) { + return a *= b; +} +} // namespace hls +#endif // __cplusplus +#endif diff --git a/tools/cgeist/Test/HLS/Pipeline.cpp b/tools/cgeist/Test/HLS/Pipeline.cpp index c7d2e99619c2..d374a0cc7d80 100644 --- a/tools/cgeist/Test/HLS/Pipeline.cpp +++ b/tools/cgeist/Test/HLS/Pipeline.cpp @@ -1,12 +1,15 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - - -void my_kernel(int j) { - j = 0; - for(int i = 0; i < 10; ++i) { - #pragma HLS pipeline II=1 - j += 1; - } -} - -// CHECK: hls.pipeline = [{II = 1 : i32, rewind = false, style = "stp"}] \ No newline at end of file +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank 2>&1 | FileCheck %s + +// The loop must have an observable effect: with `j` a by-value parameter the +// loop was dead and is (correctly) removed, leaving nothing to annotate. +void my_kernel(int *j) { + *j = 0; + for(int i = 0; i < 10; ++i) { + #pragma HLS pipeline II=1 + j[i] += 1; + } +} + +// CHECK-NOT: warning +// CHECK: affine.for +// CHECK: } {hls.pipeline = [{II = 1 : i32, rewind = false, style = "stp"}]} diff --git a/tools/cgeist/Test/HLS/Unroll.cpp b/tools/cgeist/Test/HLS/Unroll.cpp index 785ec1138e57..30d50af314d8 100644 --- a/tools/cgeist/Test/HLS/Unroll.cpp +++ b/tools/cgeist/Test/HLS/Unroll.cpp @@ -1,13 +1,13 @@ -//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s - -void fir_filter(int x[16], int h[8], int y[16]) { - for (int i = 0; i < 16; i++) { -#pragma HLS unroll - int acc = 0; - for (int j = 0; j < 8; j++) - acc += x[i-j] * h[j]; - y[i] = acc; - } -} - +//RUN: cgeist %s --function="*" -S --hls-annotate --raise-scf-to-affine --memref-fullrank| FileCheck %s + +void fir_filter(int x[16], int h[8], int y[16]) { + for (int i = 0; i < 16; i++) { +#pragma HLS unroll + int acc = 0; + for (int j = 0; j < 8; j++) + acc += x[i-j] * h[j]; + y[i] = acc; + } +} + // CHECK: {hls.unroll = [{factor = 0 : i32, skip_exit_check = false}]} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/aggregate/aggregate.c b/tools/cgeist/Test/HLS/aggregate/aggregate.c new file mode 100644 index 000000000000..17d751c2106f --- /dev/null +++ b/tools/cgeist/Test/HLS/aggregate/aggregate.c @@ -0,0 +1,69 @@ +// #pragma HLS aggregate / disaggregate: hls.aggregate = [{variable, compact}] +// (compact defaults to "auto") and hls.disaggregate = [{variable}] on the +// storage of a struct variable, parameter or global. The two conflict on +// the same variable. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +struct Pixel { + unsigned char r, g, b, a; +}; +struct Pair { + int x[4]; + int y[4]; +}; + +// CHECK-LABEL: func.func @params( +// CHECK-SAME: {hls.aggregate = [{compact = "bit", variable = "in"}]} +// CHECK-SAME: {hls.aggregate = [{compact = "auto", variable = "out"}]} +void params(struct Pixel in[16], struct Pixel out[16]) { +#pragma HLS aggregate variable=in compact=bit +#pragma HLS AGGREGATE variable=out + // (Field-wise: cgeist cannot yet copy whole struct array elements.) + for (int i = 0; i < 16; ++i) { + out[i].r = in[i].r; + out[i].g = in[i].g; + out[i].b = in[i].b; + out[i].a = in[i].a; + } +} + +// CHECK-LABEL: func.func @locals( +// CHECK-DAG: hls.aggregate = [{compact = "byte", variable = "p"}] +// CHECK-DAG: hls.disaggregate = [{variable = "q"}] +int locals(int *a) { + struct Pair p, q; +#pragma HLS aggregate variable=p compact=byte +#pragma HLS disaggregate variable=q + for (int i = 0; i < 4; ++i) { + p.x[i] = a[i]; + p.y[i] = a[i + 4]; + q.x[i] = a[i] * 2; + q.y[i] = a[i] * 3; + } + int s = 0; + for (int i = 0; i < 4; ++i) + s += p.x[3 - i] * q.y[i] + p.y[i] * q.x[3 - i]; + return s; +} + +// cgeist's inliner does not inline functions with struct-typed locals, so +// `locals` stays a call at every -O level; its attributes stay on its own +// allocas (checked above). +// CHECK-LABEL: func.func @top( +// CHECK: call @locals +int top(int *a) { return locals(a); } + +#ifdef ERRORS +void errors(struct Pixel *px) { +#pragma HLS aggregate variable=px +// ERR-DAG: aggregate.c:[[@LINE+1]]:1: error: '#pragma HLS disaggregate' conflicts with an earlier pragma on the same variable 'px' +#pragma HLS disaggregate variable=px +// ERR-DAG: aggregate.c:[[@LINE+1]]:43: error: invalid value 'nibble' for option 'compact' in '#pragma HLS aggregate' +#pragma HLS aggregate variable=px compact=nibble + px[0].r = 1; +} +#endif diff --git a/tools/cgeist/Test/HLS/aggregate/propagate.cpp b/tools/cgeist/Test/HLS/aggregate/propagate.cpp new file mode 100644 index 000000000000..08a495e544ff --- /dev/null +++ b/tools/cgeist/Test/HLS/aggregate/propagate.cpp @@ -0,0 +1,81 @@ +// An AGGREGATE pragma reaches the variable a call passes to the annotated +// parameter (Vitis 2025.1: [HLS 214-241] "Aggregating bram variable" names +// the caller's variable, kernels w9s_b and w9v_s_inl of the hls-est notes, +// VITIS_NOTES N37 S2 (b)), also through a chain of calls and when the callee +// is inlined. `variable=this` inside a member function names the object it is +// called on (Vitis's hls_vector.h runs `SYN_PRAGMA(HLS AGGREGATE +// variable=this)` in its members, N37 S2 (c)). The variable gets +// hls.aggregate with `from` = the callee the actual was passed to. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine --memref-fullrank 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine --memref-fullrank -DINLINED 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine --memref-fullrank --hls-propagate-aggregate=false 2>&1 | FileCheck %s --check-prefix=OFF + +// CHECK-NOT: error + +template struct vec { + T d[N]; + T &operator[](int i) { +#pragma HLS aggregate variable=this + return d[i]; + } + void clear() { + for (int i = 0; i < N; ++i) + d[i] = 0; + } +}; +struct plain { + short d[8]; +}; + +#ifdef INLINED +#define KEEP +#else +#define KEEP _Pragma("HLS inline off") +#endif + +static void fill(plain p[64], const short *in) { + KEEP +#pragma HLS aggregate variable=p + for (int i = 0; i < 64 * 8; i++) + p[i >> 3].d[i & 7] = in[i]; +} +static void relay(plain q[64], const short *in) { + KEEP + fill(q, in); +} + +// CHECK: memref.global @gv {{.*}}hls.aggregate = [{compact = "auto", from = "{{.*}}vec{{.*}}", variable = "this"}] +// OFF: memref.global @gv : memref<32x!llvm.struct<(array<8 x i16>)>> = uninitialized{{$}} +vec gv[32]; + +// CHECK-LABEL: func.func @top( +// CHECK-DAG: hls.aggregate = [{compact = "auto", from = "{{.*}}relay{{.*}}", variable = "p"}], hls.preserve, polygeist.varname = "pa" +// CHECK-DAG: hls.aggregate = [{compact = "auto", from = "{{.*}}vec{{.*}}", variable = "this"}], hls.preserve, polygeist.varname = "va" +// CHECK-DAG: memref.alloca() {hls.preserve, polygeist.varname = "vc"} +// CHECK-DAG: memref.alloca() {hls.preserve, polygeist.varname = "pb"} +// OFF-LABEL: func.func @top( +// OFF-NOT: hls.aggregate +// OFF: return +extern "C" void top(const short in[512], short out[4], int k) { + vec va[64]; // operator[] applied: aggregated through `this` + vec vc[64]; // only clear(): not aggregated + plain pa[64]; // reaches fill's parameter through relay + plain pb[64]; // no pragma + for (int i = 0; i < 64 * 8; i++) + va[i >> 3][i & 7] = in[i]; + for (int i = 0; i < 64; i++) + vc[i].clear(); + for (int i = 0; i < 32 * 8; i++) + gv[i >> 3][i & 7] = in[i]; + relay(pa, in); + for (int i = 0; i < 64 * 8; i++) + pb[i >> 3].d[i & 7] = in[i]; + int s = 0; + for (int i = 0; i < 512; i++) { + int j = (i * k) & 511; + s += va[j >> 3][j & 7] + vc[j >> 3].d[j & 7] + pa[j >> 3].d[j & 7] + + pb[j >> 3].d[j & 7] + gv[(j >> 3) & 31][j & 7]; + } + out[0] = s; +} diff --git a/tools/cgeist/Test/HLS/alias/alias.c b/tools/cgeist/Test/HLS/alias/alias.c new file mode 100644 index 000000000000..d843a59de3d4 --- /dev/null +++ b/tools/cgeist/Test/HLS/alias/alias.c @@ -0,0 +1,43 @@ +// #pragma HLS alias: hls.alias = [{ports, distance | offset}] on the function. +// ports must be at least two parameters; exactly one of distance/offset, +// with one offset per port. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +// CHECK-LABEL: func.func @distance( +// CHECK-SAME: hls.alias = [{distance = 1024 : i32, ports = ["a", "b", "c"]}] +void distance(int *a, int *b, int *c) { +#pragma HLS alias ports=a,b,c distance=1024 + for (int i = 0; i < 16; ++i) + c[i] = a[i] + b[i]; +} + +// CHECK-LABEL: func.func @offsets( +// CHECK-SAME: hls.alias = [{offset = [0 : i32, 256 : i32], ports = ["x", "y"]}] +#define OFF 256 +void offsets(int *x, int *y) { +#pragma HLS ALIAS ports=x, y offset=0, OFF + for (int i = 0; i < 16; ++i) + y[i] = x[i]; +} + +#ifdef ERRORS +void errors(int *a, int *b) { + int local[4]; +// ERR-DAG: alias.c:[[@LINE+1]]:19: error: '#pragma HLS alias' requires at least two ports +#pragma HLS alias ports=a distance=4 +// ERR-DAG: alias.c:[[@LINE+1]]:1: error: '#pragma HLS alias' requires exactly one of 'distance' or 'offset' +#pragma HLS alias ports=a,b +// ERR-DAG: alias.c:[[@LINE+1]]:1: error: '#pragma HLS alias' requires exactly one of 'distance' or 'offset' +#pragma HLS alias ports=a,b distance=4 offset=0,4 +// ERR-DAG: alias.c:[[@LINE+1]]:29: error: '#pragma HLS alias' needs one offset per port (2 ports, 3 offsets) +#pragma HLS alias ports=a,b offset=0,4,8 +// ERR-DAG: alias.c:[[@LINE+1]]:19: error: 'local' in '#pragma HLS alias' is not a function parameter +#pragma HLS alias ports=a,local distance=4 + local[0] = 1; + a[0] = b[0] + local[0]; +} +#endif diff --git a/tools/cgeist/Test/HLS/allocation/allocation.cpp b/tools/cgeist/Test/HLS/allocation/allocation.cpp new file mode 100644 index 000000000000..b4ef4522d4a4 --- /dev/null +++ b/tools/cgeist/Test/HLS/allocation/allocation.cpp @@ -0,0 +1,48 @@ +// #pragma HLS allocation: hls.allocation = [{instances, limit, type}] on the +// enclosing function (or loop); instances is a list of names; type is +// "function" (default) or "operation", also accepted positionally. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +template T mac(T a, T b, T c) { return a * b + c; } +int sub(int a, int b) { return a - b; } + +// Several allocation pragmas accumulate in source order. +// CHECK-LABEL: func.func @_Z3topPiS_( +// CHECK-SAME: hls.allocation = [{instances = ["mac"], limit = 1 : i32, type = "function"}, {instances = ["mul"], limit = 2 : i32, type = "operation"}, {instances = ["sub", "mac"], limit = 3 : i32, type = "function"}, {instances = ["add"], limit = 4 : i32, type = "operation"}] +void top(int *a, int *b) { +#pragma HLS ALLOCATION function instances=mac limit=1 +#pragma HLS allocation operation instances=mul limit=2 +#pragma HLS allocation instances=sub, mac limit=3 type=function +#pragma HLS allocation type=operation instances=add limit=4 + for (int i = 0; i < 8; ++i) + b[i] = mac(a[i], a[i], sub(b[i], 1)); +} + +// Loop region. +// CHECK-LABEL: func.func @_Z4loopPi( +// CHECK: } {hls.allocation = [{instances = ["mul"], limit = 1 : i32, type = "operation"}]} +void loop(int *a) { + for (int i = 0; i < 8; ++i) { +#pragma HLS allocation operation instances=mul limit=1 + a[i] = a[i] * a[i] * 3; + } +} + +#ifdef ERRORS +void errors(int *a) { +// ERR-DAG: allocation.cpp:[[@LINE+1]]:1: error: '#pragma HLS allocation' requires option 'limit' +#pragma HLS allocation function instances=sub +// ERR-DAG: allocation.cpp:[[@LINE+1]]:1: error: '#pragma HLS allocation' requires option 'instances' +#pragma HLS allocation function limit=1 +// ERR-DAG: allocation.cpp:[[@LINE+1]]:53: error: option 'limit' in '#pragma HLS allocation' must be >= 1, got 0 +#pragma HLS allocation function instances=sub limit=0 +#pragma HLS allocation function instances=sub limit=2 +// ERR-DAG: allocation.cpp:[[@LINE+1]]:1: warning: duplicate '#pragma HLS allocation' on the same function is ignored +#pragma HLS allocation function instances=sub limit=2 + a[0] = sub(a[0], 1); +} +#endif diff --git a/tools/cgeist/Test/HLS/array_partition/errors.c b/tools/cgeist/Test/HLS/array_partition/errors.c new file mode 100644 index 000000000000..62e49361861d --- /dev/null +++ b/tools/cgeist/Test/HLS/array_partition/errors.c @@ -0,0 +1,58 @@ +// Semantic errors and warnings for array_partition. Each produces a specific +// diagnostic and a clean exit. +// RUN: not cgeist %s --function='*' -S --hls-annotate -o /dev/null 2>&1 | FileCheck %s + +int scalar_global; + +void f(int *a, int n) { + int buf[16]; + int m[4][8]; + int scalar = 0; +// CHECK-DAG: errors.c:[[@LINE+1]]:1: error: '#pragma HLS array_partition' with type=cyclic requires option 'factor' +#pragma HLS array_partition variable=buf cyclic +// CHECK-DAG: errors.c:[[@LINE+1]]:1: error: '#pragma HLS array_partition' with type=block requires option 'factor' +#pragma HLS array_partition variable=buf type=block +// Ignored with a warning, as Vitis 2025.1 ignores it ([HLS 214-253]). +// CHECK-DAG: errors.c:[[@LINE+1]]:40: warning: dim=3 is out of range in '#pragma HLS array_partition': 'm' has 2 dimension(s); the pragma is ignored, as Vitis ignores it +#pragma HLS array_partition variable=m dim=3 complete +// CHECK-DAG: errors.c:[[@LINE+1]]:29: error: '#pragma HLS array_partition' requires an array or pointer, but 'scalar' has type 'int' +#pragma HLS array_partition variable=scalar complete +// CHECK-DAG: errors.c:[[@LINE+1]]:29: error: '#pragma HLS array_partition' requires an array or pointer, but 'n' has type 'int' +#pragma HLS array_partition variable=n complete +// CHECK-DAG: errors.c:[[@LINE+1]]:29: error: '#pragma HLS array_partition' requires an array or pointer, but 'scalar_global' has type 'int' +#pragma HLS array_partition variable=scalar_global complete +// CHECK-DAG: errors.c:[[@LINE+1]]:38: error: use of undeclared variable 'nope' in '#pragma HLS array_partition' +#pragma HLS array_partition variable=nope complete +// CHECK-DAG: errors.c:[[@LINE+1]]:42: error: no member named 'x' in 'int[16]' (in '#pragma HLS array_partition') +#pragma HLS array_partition variable=buf.x complete +// CHECK-DAG: errors.c:[[@LINE+1]]:55: warning: 'factor' is ignored for complete partitioning in '#pragma HLS array_partition' +#pragma HLS array_partition variable=m complete dim=1 factor=2 +// CHECK-DAG: errors.c:[[@LINE+1]]:47: warning: factor=32 exceeds the size 8 of dimension 2 of 'm' +#pragma HLS array_partition variable=m cyclic factor=32 dim=2 + for (int i = 0; i < 16; ++i) + buf[i] = a[i] + m[i % 4][i % 8] + scalar + n + scalar_global; + a[0] = buf[3]; +} + +// Two pragmas on one dimension (dim=0 covers every dimension): cyclic against +// block and `off` against a partition are errors, an identical repeat is a +// warning; the others are merged the Vitis way (W10, +// regressions/array-partition-merge.c): here `complete dim=0` replaces the +// cyclic partition of dimension 1, with a remark at the dropped pragma. +void conflicts(int *a) { + int buf[4][4]; +// CHECK-DAG: errors.c:[[@LINE+1]]:1: remark: '#pragma HLS array_partition' (cyclic factor=2) on dimension 1 of variable 'buf' is dropped: the later pragma (complete) partitions it more finely, which Vitis keeps +#pragma HLS array_partition variable=buf cyclic factor=2 dim=1 +// CHECK-DAG: errors.c:[[@LINE+1]]:1: error: '#pragma HLS array_partition' conflicts with an earlier pragma on the same variable 'buf' +#pragma HLS array_partition variable=buf block factor=2 dim=1 +// CHECK-DAG: errors.c:[[@LINE+1]]:1: warning: duplicate '#pragma HLS array_partition' on the same variable 'buf' is ignored +#pragma HLS array_partition variable=buf type=cyclic factor=2 dim=1 +#pragma HLS array_partition variable=buf complete dim=0 +// CHECK-DAG: errors.c:[[@LINE+1]]:1: error: '#pragma HLS array_partition' conflicts with an earlier pragma on the same variable 'buf' +#pragma HLS array_partition variable=buf off + for (int i = 0; i < 16; ++i) + buf[i / 4][i % 4] = a[i]; + a[0] = buf[1][2]; +} + +// CHECK-NOT: Stack dump diff --git a/tools/cgeist/Test/HLS/array_partition/inline-carry-partition.cpp b/tools/cgeist/Test/HLS/array_partition/inline-carry-partition.cpp new file mode 100644 index 000000000000..afaeff0918ea --- /dev/null +++ b/tools/cgeist/Test/HLS/array_partition/inline-carry-partition.cpp @@ -0,0 +1,131 @@ +// A callee parameter's array_partition reaches the root array of the +// argument when cgeist inlines the call (also a misfit `inline off` call, +// whose argument's first dimension differs from the parameter's), unless the +// parameter's first dimension is smaller than the root's: then Vitis applies +// it one dimension deeper in the root (parameter dimension d to root +// dimension d + 1, dim=0 to dimensions 2..rank) and ignores what falls past +// the root's rank (HLS 214-253). The parameters in between do not decide; a caller's own +// parameter carries the entry with the first dimension of the parameter that +// had the pragma (`rows`) until a root is reached. VITIS_NOTES N123 in the +// hls-est tree, kernels w9r16p_pm_mis (2 BRAM), pm_big (8), pm_two2 (8), +// w9r16i_pm_kept (2); W9r16 review fixes: w9r16rv_pm_dim1 (dim=1 cyclic 2: +// Vitis "Cyclic partitioning with factor 2 on dimension 2", 4 BRAM), +// w9r16fx_pm_d2cyc (dim=2 cyclic 2: ignored, 2) and w9r16fx_pm_d0 (dim=0 +// complete: "Complete partitioning on dimension 2" and 214-253, 8). +// RUN: cgeist %s %resourcedir --function='*' -S --hls-annotate --raise-scf-to-affine --memref-fullrank -o - 2>/dev/null | FileCheck %s +// RUN: cgeist %s %resourcedir --function='*' -S --hls-annotate --raise-scf-to-affine --memref-fullrank -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN +// RUN: cgeist %s %resourcedir --function='*' -S --hls-annotate --raise-scf-to-affine --memref-fullrank --hls-inline-carry-partition=false -o - 2>/dev/null | FileCheck %s --check-prefix=OFF +// RUN: cgeist %s %resourcedir --function='*' -S --hls-annotate --raise-scf-to-affine --memref-fullrank --hls-keep-misfit-inline-off -o - 2>/dev/null | FileCheck %s --check-prefix=KEEP + +// CHECK-DAG: memref.global @g_big : memref<100x8xi32> = uninitialized {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "a"}]} +// CHECK-DAG: memref.global @g_kept : memref<100x8xi32> = uninitialized{{ *$}} +// CHECK-DAG: memref.global @g_mis : memref<100x8xi32> = uninitialized{{ *$}} +// CHECK-DAG: memref.global @g_dim1 : memref<100x8xi32> = uninitialized {hls.array_partition = [{dim = 2 : i32, factor = 2 : i32, kind = "cyclic", variable = "a"}]} +// CHECK-DAG: memref.global @g_d2c : memref<100x8xi32> = uninitialized{{ *$}} +// CHECK-DAG: memref.global @g_d0 : memref<100x8xi32> = uninitialized {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "a"}]} +// CHECK-DAG: memref.global @g_two : memref<100x8xi32> = uninitialized {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "a"}]} +// CHECK-LABEL: func.func @_Z6w_keptPA8_iPii( +// CHECK-SAME: hls.array_partition = [{dim = 2 : i32, kind = "complete", rows = 50 : i64, variable = "a"}] +// WARN-DAG: warning: array_partition on parameter 'a' of 'f_mis' ignored past dimension 2: its first dimension (50) is smaller than that of the array it reaches (100) +// WARN-DAG: warning: array_partition on parameter 'a' of 'f_d2c' ignored past dimension 2 +// WARN-DAG: warning: array_partition on parameter 'a' of 'f_d0' ignored past dimension 2 +// WARN-NOT: array_partition on parameter 'a' of 'f_dim1' +// OFF-NOT: memref.global {{.*}}hls.array_partition +// OFF-NOT: rows = +// --hls-keep-misfit-inline-off (off by default) keeps a misfit call whose +// argument is reinterpreted to the parameter type, but not when a partition +// is involved (the callee's parameter here: hls-est cannot yet bank through +// the reinterpreted view, OPEN_ISSUES O167 (a) in the hls-est tree), so f_two +// is still inlined and its partition carried; the calls without a partition +// are kept (keep-misfit-global.cpp): +// KEEP-LABEL: func.func @_Z5w_twoPA8_iPii( +// KEEP-NOT: call @_Z5f_twoPA8_iPii( +// KEEP: return + +int g_mis[100][8], g_big[100][8], g_two[100][8], g_kept[100][8]; +int g_dim1[100][8], g_d2c[100][8], g_d0[100][8]; + +void f_mis(int a[50][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=2 complete + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[i][j]; +} +void top_mis(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_mis[i / 8][i % 8] = in[i]; + f_mis(g_mis, out, n); +} + +void f_big(int a[200][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=2 complete + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[i][j]; +} +void top_big(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_big[i / 8][i % 8] = in[i]; + f_big(g_big, out, n); +} + +void f_two(int a[100][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=2 complete + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[i][j]; +} +void w_two(int a[200][8], int out[8], int n) { +#pragma HLS inline off + f_two(a, out, n); +} +void top_two(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_two[i / 8][i % 8] = in[i]; + w_two(g_two, out, n); +} + +void f_kept(int a[50][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=2 complete + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[i][j]; +} +void w_kept(int a[100][8], int out[8], int n) { +#pragma HLS inline off + f_kept(a, out, n); +} +void top_kept(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_kept[i / 8][i % 8] = in[i]; + w_kept(g_kept, out, n); +} + +void f_dim1(int a[50][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=1 cyclic factor=2 + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[2 * i][j] + a[2 * i + 1][j]; +} +void top_dim1(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_dim1[i / 8][i % 8] = in[i]; + f_dim1(g_dim1, out, n); +} + +void f_d2c(int a[50][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=2 cyclic factor=2 + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[i][j]; +} +void top_d2c(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_d2c[i / 8][i % 8] = in[i]; + f_d2c(g_d2c, out, n); +} + +void f_d0(int a[50][8], int out[8], int n) { +#pragma HLS inline off +#pragma HLS array_partition variable=a dim=0 complete + for (int i = 0; i < n; i++) + for (int j = 0; j < 8; j++) out[j] += a[i][j]; +} +void top_d0(int in[800], int out[8], int n) { + for (int i = 0; i < 800; i++) g_d0[i / 8][i % 8] = in[i]; + f_d0(g_d0, out, n); +} diff --git a/tools/cgeist/Test/HLS/array_partition/lowering.c b/tools/cgeist/Test/HLS/array_partition/lowering.c new file mode 100644 index 000000000000..a15fcc2d629d --- /dev/null +++ b/tools/cgeist/Test/HLS/array_partition/lowering.c @@ -0,0 +1,43 @@ +// hls.array_partition survives every pipeline configuration; when a callee +// is inlined, its local arrays are cloned into the caller with their +// attributes, and a caller's array passed to a callee keeps its own. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s --check-prefixes=CHECK,NOINLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O1 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O2 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 --raise-scf-to-affine 2>&1 | FileCheck %s --check-prefixes=CHECK,NOINLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine --memref-fullrank 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: cgeist %s --function='*' -S --hls-annotate --raise-scf-to-affine -o - \ +// RUN: | polygeist-opt --canonicalize --cse --affine-loop-unroll="unroll-factor=2" \ +// RUN: | FileCheck %s --check-prefixes=CHECK,INLINE + +// CHECK-NOT: warning + +// CHECK-LABEL: func.func @filter( +// CHECK: memref.alloca() {hls.array_partition = [{dim = 1 : i32, factor = 4 : i32, kind = "cyclic", variable = "taps"}], hls.preserve, polygeist.varname = "taps"} : memref<16xi32> +void filter(int *x, int *y) { + int taps[16]; +#pragma HLS array_partition variable=taps cyclic factor=4 + for (int i = 0; i < 16; ++i) + taps[i] = x[i] * 3; + for (int i = 0; i < 16; ++i) { + int acc = 0; + for (int j = 0; j < 16; ++j) + acc += taps[j] * x[i + j]; + y[i] = acc; + } +} + +// CHECK-LABEL: func.func @top( +// CHECK: memref.alloca() {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "tmp"}], hls.preserve, polygeist.varname = "tmp"} : memref<32xi32> +// INLINE: memref.alloca() {hls.array_partition = [{dim = 1 : i32, factor = 4 : i32, kind = "cyclic", variable = "taps"}], hls.preserve, polygeist.varname = "taps"} : memref<16xi32> +// NOINLINE: call @filter +// INLINE-NOT: call @filter +void top(int *x, int *y) { + int tmp[32]; +#pragma HLS array_partition variable=tmp complete + for (int i = 0; i < 32; ++i) + tmp[i] = x[i] + 1; + filter(tmp, y); +} diff --git a/tools/cgeist/Test/HLS/array_partition/options.c b/tools/cgeist/Test/HLS/array_partition/options.c new file mode 100644 index 000000000000..992f7d49b300 --- /dev/null +++ b/tools/cgeist/Test/HLS/array_partition/options.c @@ -0,0 +1,107 @@ +// #pragma HLS array_partition: hls.array_partition = [{variable, kind, factor?, +// dim}] on the storage of the variable. kind defaults to "complete" and dim +// to 1; factor is omitted for complete partitioning. `off` gives +// hls.array_partition_off = [{variable, dim}]. +// RUN: cgeist %s --function='*' -S --hls-annotate 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate --raise-scf-to-affine 2>&1 | FileCheck %s + +// CHECK-NOT: warning +// CHECK-NOT: error + +#define USE(buf, n) \ + for (int i = 0; i < (n); ++i) \ + buf[i] = a[i]; \ + for (int i = 0; i < (n); ++i) \ + a[(n) - 1 - i] = buf[i]; + +// CHECK-LABEL: func.func @defaults( +// CHECK: memref.alloca() {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} +void defaults(int *a) { + int buf[16]; +#pragma HLS array_partition variable=buf + USE(buf, 16) +} + +// CHECK-LABEL: func.func @complete( +// CHECK: {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "buf"}] +void complete(int *a) { + int buf[16]; +#pragma HLS array_partition variable=buf type=complete + USE(buf, 16) +} + +// CHECK-LABEL: func.func @cyclic( +// CHECK: {hls.array_partition = [{dim = 1 : i32, factor = 4 : i32, kind = "cyclic", variable = "buf"}] +void cyclic(int *a) { + int buf[16]; +#pragma HLS array_partition variable=buf type=cyclic factor=4 + USE(buf, 16) +} + +// CHECK-LABEL: func.func @block( +// CHECK: {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "block", variable = "buf"}] +void block(int *a) { + int buf[16]; +#pragma HLS array_partition variable=buf type=block factor=2 + USE(buf, 16) +} + +// Positional type (older Vivado spelling). +// CHECK-LABEL: func.func @positional( +// CHECK: {hls.array_partition = [{dim = 1 : i32, factor = 8 : i32, kind = "cyclic", variable = "buf"}] +void positional(int *a) { + int buf[16]; +#pragma HLS ARRAY_PARTITION variable=buf cyclic factor=8 + USE(buf, 16) +} + +// CHECK-LABEL: func.func @dim_explicit( +// CHECK: {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "buf"}] +void dim_explicit(int *a) { + int buf[4][4]; +#pragma HLS array_partition variable=buf complete dim=2 + for (int i = 0; i < 16; ++i) + buf[i / 4][i % 4] = a[i]; + for (int i = 0; i < 16; ++i) + a[i] = buf[i % 4][i / 4]; +} + +// dim=0 partitions every dimension. +// CHECK-LABEL: func.func @dim_zero( +// CHECK: {hls.array_partition = [{dim = 0 : i32, factor = 2 : i32, kind = "cyclic", variable = "buf"}] +void dim_zero(int *a) { + int buf[4][4]; +#pragma HLS array_partition variable=buf cyclic factor=2 dim=0 + for (int i = 0; i < 16; ++i) + buf[i / 4][i % 4] = a[i]; + for (int i = 0; i < 16; ++i) + a[i] = buf[i % 4][i / 4]; +} + +// All options together, in any order. +// CHECK-LABEL: func.func @all( +// CHECK: {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "block", variable = "buf"}] +void all(int *a) { + int buf[16]; +#pragma HLS array_partition dim=1 factor=2 type=block variable=buf + USE(buf, 16) +} + +// CHECK-LABEL: func.func @off( +// CHECK: {hls.array_partition_off = [{dim = 1 : i32, variable = "buf"}], hls.preserve, polygeist.varname = "buf"} +void off(int *a) { + int buf[16]; +#pragma HLS array_partition variable=buf off + USE(buf, 16) +} + +// CHECK-LABEL: func.func @off_dim( +// CHECK: {hls.array_partition_off = [{dim = 2 : i32, variable = "buf"}] +void off_dim(int *a) { + int buf[4][4]; +#pragma HLS array_partition variable=buf dim=2 off=true + for (int i = 0; i < 16; ++i) + buf[i / 4][i % 4] = a[i]; + for (int i = 0; i < 16; ++i) + a[i] = buf[i % 4][i / 4]; +} diff --git a/tools/cgeist/Test/HLS/array_partition/variables.c b/tools/cgeist/Test/HLS/array_partition/variables.c new file mode 100644 index 000000000000..adb614ae8a43 --- /dev/null +++ b/tools/cgeist/Test/HLS/array_partition/variables.c @@ -0,0 +1,131 @@ +// Variable resolution for array_partition: local arrays (1-D, multi-D, in +// inner scopes), array and pointer parameters (argument attributes), +// globals and static locals (memref.global), shadowing, pragmas placed +// before the declaration, and several pragmas on one array. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 --raise-scf-to-affine 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 --raise-scf-to-affine --memref-fullrank 2>&1 | FileCheck %s --check-prefix=FULLRANK + +// CHECK-NOT: warning +// CHECK-NOT: error + +int gbuf[32][4]; +int gunused[8]; + +// Globals are annotated on their memref.global. +// CHECK-DAG: memref.global @gbuf : memref<32x4xi32> = uninitialized {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "gbuf"}, {dim = 1 : i32, factor = 4 : i32, kind = "cyclic", variable = "gbuf"}]} +// CHECK-DAG: memref.global "private" @"statics@static@st" : memref<8xi32> = uninitialized {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "block", variable = "st"}]} + +// CHECK-LABEL: func.func @multi_dim( +// CHECK: memref.alloca() {hls.array_partition = [{dim = 3 : i32, kind = "complete", variable = "buf"}, {dim = 1 : i32, factor = 2 : i32, kind = "cyclic", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} : memref<4x4x2xi32> +void multi_dim(int *a) { + int buf[4][4][2]; +#pragma HLS array_partition variable=buf complete dim=3 +#pragma HLS array_partition variable=buf cyclic factor=2 dim=1 + for (int i = 0; i < 32; ++i) + buf[i / 8][(i / 2) % 4][i % 2] = a[i]; + for (int i = 0; i < 32; ++i) + a[i] = buf[i % 4][(i / 4) % 4][i / 16]; +} + +// Array and pointer parameters: argument attributes. +// CHECK-LABEL: func.func @params( +// CHECK-SAME: %arg0: memref {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "m"}]} +// CHECK-SAME: %arg1: memref {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "cyclic", variable = "p"}]} +// CHECK-SAME: %arg2: memref {hls.array_partition = [{dim = 1 : i32, factor = 4 : i32, kind = "block", variable = "v"}]} +// CHECK-SAME: %arg3: i32) +// FULLRANK-LABEL: func.func @params( +// FULLRANK-SAME: {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "m"}]} +void params(int m[8][4], int *p, int v[16], int n) { +#pragma HLS array_partition variable=m complete dim=2 +#pragma HLS array_partition variable=p cyclic factor=2 +#pragma HLS array_partition variable=v block factor=4 + for (int i = 0; i < 8; ++i) + for (int j = 0; j < 4; ++j) + m[i][j] = p[i + j] + v[i] + n; +} + +// Globals and static locals, named from inside the function. +// CHECK-LABEL: func.func @statics( +void statics(int *a) { + static int st[8]; +#pragma HLS array_partition variable=st block factor=2 +#pragma HLS array_partition variable=gbuf complete dim=2 +#pragma HLS array_partition variable=gbuf cyclic factor=4 dim=1 + for (int i = 0; i < 8; ++i) { + st[i] += a[i]; + gbuf[i][i % 4] += st[i]; + } +} + +// Pragma before the declaration (accepted, as Vitis does). +// CHECK-LABEL: func.func @before_declaration( +// CHECK: {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "cyclic", variable = "late"}], hls.preserve, polygeist.varname = "late"} +void before_declaration(int *a) { +#pragma HLS array_partition variable=late cyclic factor=2 + int late[8]; + for (int i = 0; i < 8; ++i) + late[i] = a[i]; + for (int i = 0; i < 8; ++i) + a[7 - i] = late[i]; +} + +// Shadowing: the pragma names the variable visible at its location. +// CHECK-LABEL: func.func @shadowing( +// CHECK-DAG: {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} : memref<4xi32> +// CHECK-DAG: {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "cyclic", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} : memref<16xi32> +void shadowing(int *a) { + int buf[16]; +#pragma HLS array_partition variable=buf cyclic factor=2 + for (int i = 0; i < 16; ++i) + buf[i] = a[i]; + { + int buf[4]; +#pragma HLS array_partition variable=buf complete + for (int i = 0; i < 4; ++i) + buf[i] = a[i]; + for (int i = 0; i < 4; ++i) + a[i] = buf[3 - i]; + } + for (int i = 0; i < 16; ++i) + a[i] += buf[15 - i]; +} + +// A local array declared inside a loop body: the alloca is hoisted out of +// the loop and keeps the attribute; the pragma inside the loop names it. +// CHECK-LABEL: func.func @in_loop_body( +// CHECK: memref.alloca() {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "row"}], hls.preserve, polygeist.varname = "row"} : memref<4xi32> +void in_loop_body(int *a) { + for (int i = 0; i < 8; ++i) { + int row[4]; +#pragma HLS array_partition variable=row complete + for (int j = 0; j < 4; ++j) + row[j] = a[i * 4 + j]; + for (int j = 0; j < 4; ++j) + a[i * 4 + j] = row[3 - j]; + } +} + +// Struct members: the pragma annotates the struct's storage and records +// the member path. +struct Pair { + int x[8]; + int y[8]; +}; +// CHECK-LABEL: func.func @members( +// A member path records the member's position in the struct (member_path), +// for hls-est's struct splitting (CIRCT OPEN_ISSUES O78). +// CHECK: {hls.array_partition = [{dim = 1 : i32, kind = "complete", member_path = [0 : i32], variable = "s.x"}, {dim = 1 : i32, factor = 2 : i32, kind = "cyclic", member_path = [1 : i32], variable = "s.y"}] +int members(int *a) { + struct Pair s; +#pragma HLS array_partition variable=s.x complete +#pragma HLS array_partition variable=s.y cyclic factor=2 + for (int i = 0; i < 8; ++i) { + s.x[i] = a[i]; + s.y[i] = a[i + 8]; + } + int r = 0; + for (int i = 0; i < 8; ++i) + r += s.x[i] * s.y[7 - i]; + return r; +} diff --git a/tools/cgeist/Test/HLS/array_reshape/array_reshape.c b/tools/cgeist/Test/HLS/array_reshape/array_reshape.c new file mode 100644 index 000000000000..c135663dd829 --- /dev/null +++ b/tools/cgeist/Test/HLS/array_reshape/array_reshape.c @@ -0,0 +1,67 @@ +// #pragma HLS array_reshape: same options and shape as array_partition, under +// hls.array_reshape, plus the `object` flag; `off` gives +// hls.array_reshape_off. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s --check-prefixes=CHECK,NOINLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +int gtab[64]; + +// CHECK-DAG: memref.global @gtab : memref<64xi32> = uninitialized {hls.array_reshape = [{dim = 1 : i32, factor = 4 : i32, kind = "block", variable = "gtab"}]} + +// CHECK-LABEL: func.func @local( +// CHECK: memref.alloca() {hls.array_reshape = [{dim = 1 : i32, kind = "complete", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} : memref<8xi32> +void local(int *a) { + int buf[8]; +#pragma HLS array_reshape variable=buf + for (int i = 0; i < 8; ++i) + buf[i] = a[i]; + for (int i = 0; i < 8; ++i) + a[i] = buf[7 - i]; +} + +// CHECK-LABEL: func.func @multi( +// CHECK: memref.alloca() {hls.array_partition = [{dim = 1 : i32, kind = "complete", variable = "m"}], hls.array_reshape = [{dim = 2 : i32, factor = 2 : i32, kind = "cyclic", object = true, variable = "m"}], hls.preserve, polygeist.varname = "m"} : memref<4x8xi32> +void multi(int *a) { + int m[4][8]; +#pragma HLS ARRAY_RESHAPE variable=m cyclic factor=2 dim=2 object +#pragma HLS array_partition variable=m complete dim=1 + for (int i = 0; i < 32; ++i) + m[i / 8][i % 8] = a[i]; + for (int i = 0; i < 32; ++i) + a[i] = m[i % 4][i / 4]; +} + +// CHECK-LABEL: func.func @params( +// CHECK-SAME: %arg0: memref {hls.array_reshape = [{dim = 0 : i32, kind = "complete", variable = "p"}]} +// CHECK-SAME: %arg1: memref {hls.array_reshape_off = [{dim = 1 : i32, variable = "q"}]} +void params(int p[4][8], int *q) { +#pragma HLS array_reshape variable=p complete dim=0 +#pragma HLS array_reshape variable=q off +#pragma HLS array_reshape variable=gtab block factor=4 + for (int i = 0; i < 32; ++i) + q[i] = p[i / 8][i % 8] + gtab[i]; +} + +// CHECK-LABEL: func.func @top( +// INLINE: memref.alloca() {hls.array_reshape = [{dim = 1 : i32, kind = "complete", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} : memref<8xi32> +// NOINLINE: call @local +void top(int *a) { local(a); } + +#ifdef ERRORS +void errors(int *a) { + int buf[8]; + int x; +// ERR-DAG: array_reshape.c:[[@LINE+1]]:1: error: '#pragma HLS array_reshape' with type=cyclic requires option 'factor' +#pragma HLS array_reshape variable=buf cyclic +// ERR-DAG: array_reshape.c:[[@LINE+1]]:27: error: '#pragma HLS array_reshape' requires an array or pointer, but 'x' has type 'int' +#pragma HLS array_reshape variable=x complete +// ERR-DAG: array_reshape.c:[[@LINE+1]]:40: error: dim=2 is out of range in '#pragma HLS array_reshape': 'buf' has 1 dimension(s) +#pragma HLS array_reshape variable=buf dim=2 + x = 0; + buf[0] = x; + a[0] = buf[0]; +} +#endif diff --git a/tools/cgeist/Test/HLS/bind_op/bind_op.c b/tools/cgeist/Test/HLS/bind_op/bind_op.c new file mode 100644 index 000000000000..a4d2856a8350 --- /dev/null +++ b/tools/cgeist/Test/HLS/bind_op/bind_op.c @@ -0,0 +1,79 @@ +// #pragma HLS bind_op: hls.bind_op = [{variable, op, impl?, latency?}] on +// each operation of kind `op` whose result is assigned to the variable (by +// its initializer, `=` or a compound assignment). f*/d*/h* ops match float +// operations of 32/64/16 bits. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s --check-prefixes=CHECK,NOINLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +double sqrt(double); + +// CHECK-LABEL: func.func @kinds( +// CHECK-DAG: arith.muli %arg0, %arg1 {hls.bind_op = [{impl = "dsp", latency = 3 : i32, op = "mul", variable = "c"}]} : i32 +// CHECK-DAG: arith.addi %arg0, %{{.*}} {hls.bind_op = [{impl = "fabric", op = "add", variable = "s"}]} : i32 +// CHECK-DAG: arith.addi %{{.*}}, %arg1 {hls.bind_op = [{impl = "fabric", op = "add", variable = "s"}]} : i32 +// CHECK-DAG: arith.subi %arg0, %arg1 {hls.bind_op = [{op = "sub", variable = "d"}]} : i32 +// CHECK-DAG: arith.mulf %arg2, %arg3 {hls.bind_op = [{impl = "maxdsp", op = "fmul", variable = "f"}]} : f32 +// CHECK-DAG: arith.divf %arg2, %arg3 {hls.bind_op = [{impl = "fabric", latency = 8 : i32, op = "fdiv", variable = "g"}]} : f32 +// CHECK-DAG: math.sqrt %arg4 {hls.bind_op = [{impl = "fabric", op = "dsqrt", variable = "q"}]} : f64 +// CHECK-DAG: arith.addf %arg4, %arg4 {hls.bind_op = [{impl = "fulldsp", op = "dadd", variable = "r"}]} : f64 +int kinds(int a, int b, float x, float y, double z) { + int c = a * b; +#pragma HLS bind_op variable=c op=mul impl=dsp latency=3 + int s; +#pragma HLS BIND_OP variable=s op=ADD impl=fabric + s = a + c; + s += b; + int d = a - b; +#pragma HLS bind_op variable=d op=sub + float f = x * y; +#pragma HLS bind_op variable=f op=fmul impl=maxdsp + float g = x / y; +#pragma HLS bind_op variable=g op=fdiv impl=fabric latency=8 + double q = sqrt(z); +#pragma HLS bind_op variable=q op=dsqrt impl=fabric + double r = z + z; +#pragma HLS bind_op variable=r op=dadd impl=fulldsp + return s + d + (int)f + (int)g + (int)q + (int)r; +} + +// In a loop, the operation assigned in every iteration is annotated. +// CHECK-LABEL: func.func @in_loop( +// CHECK: arith.muli {{.*}} {hls.bind_op = [{impl = "dsp", op = "mul", variable = "prod"}]} : i32 +void in_loop(int *a, int *b, int *c) { + for (int i = 0; i < 16; ++i) { + int prod; +#pragma HLS bind_op variable=prod op=mul impl=dsp + prod = a[i] * b[i]; + c[i] = prod; + } +} + +// After inlining, the cloned operation keeps the attribute. +// CHECK-LABEL: func.func @top( +// NOINLINE: call @in_loop +// INLINE: arith.muli {{.*}} {hls.bind_op = [{impl = "dsp", op = "mul", variable = "prod"}]} : i32 +void top(int *a, int *b, int *c) { in_loop(a, b, c); } + +#ifdef ERRORS +int g_acc; +int errors(int a, int b, float x) { + int m = a + b; +// ERR-DAG: bind_op.c:[[@LINE+1]]:1: warning: '#pragma HLS bind_op': no matching operation is assigned to variable 'm'; the pragma has no effect +#pragma HLS bind_op variable=m op=mul impl=dsp + float f = x * x; +// A double op on a float variable does not match either. +// ERR-DAG: bind_op.c:[[@LINE+1]]:1: warning: '#pragma HLS bind_op': no matching operation is assigned to variable 'f'; the pragma has no effect +#pragma HLS bind_op variable=f op=dmul +// ERR-DAG: bind_op.c:[[@LINE+1]]:1: error: '#pragma HLS bind_op' requires option 'op' +#pragma HLS bind_op variable=m impl=dsp +// ERR-DAG: bind_op.c:[[@LINE+1]]:35: error: invalid value 'fma' for option 'op' in '#pragma HLS bind_op' +#pragma HLS bind_op variable=m op=fma +// ERR-DAG: bind_op.c:[[@LINE+1]]:21: error: '#pragma HLS bind_op' requires a local variable or parameter +#pragma HLS bind_op variable=g_acc op=add + g_acc = m; + return m + (int)f; +} +#endif diff --git a/tools/cgeist/Test/HLS/bind_storage/bind_storage.c b/tools/cgeist/Test/HLS/bind_storage/bind_storage.c new file mode 100644 index 000000000000..93e8e2179d47 --- /dev/null +++ b/tools/cgeist/Test/HLS/bind_storage/bind_storage.c @@ -0,0 +1,70 @@ +// #pragma HLS bind_storage: hls.bind_storage = [{variable, type, impl?, +// latency?}] on the variable's storage. type is required. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s --check-prefixes=CHECK,NOINLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine --memref-fullrank 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +int grom[256]; + +// CHECK-DAG: memref.global @grom : memref<256xi32> = uninitialized {hls.bind_storage = [{impl = "bram", type = "rom_2p", variable = "grom"}]} + +// Each type/impl combination, and latency. +// CHECK-LABEL: func.func @kinds( +// CHECK-DAG: {hls.bind_storage = [{type = "ram_1p", variable = "a1"}], hls.preserve, polygeist.varname = "a1"} +// CHECK-DAG: {hls.bind_storage = [{impl = "lutram", type = "ram_2p", variable = "a2"}], hls.preserve, polygeist.varname = "a2"} +// CHECK-DAG: {hls.bind_storage = [{impl = "uram", latency = 3 : i32, type = "ram_t2p", variable = "a3"}], hls.preserve, polygeist.varname = "a3"} +// CHECK-DAG: {hls.bind_storage = [{impl = "srl", type = "fifo", variable = "a4"}], hls.preserve, polygeist.varname = "a4"} +// CHECK-DAG: {hls.bind_storage = [{impl = "bram_ecc", type = "ram_s2p", variable = "a5"}], hls.preserve, polygeist.varname = "a5"} +int kinds(int *in) { + int a1[16], a2[16], a3[16], a4[16], a5[16]; +#pragma HLS bind_storage variable=a1 type=ram_1p +#pragma HLS bind_storage variable=a2 type=ram_2p impl=lutram +#pragma HLS BIND_STORAGE variable=a3 type=RAM_T2P impl=URAM latency=3 +#pragma HLS bind_storage variable=a4 type=fifo impl=srl +#pragma HLS bind_storage variable=a5 type=ram_s2p impl=bram_ecc + for (int i = 0; i < 16; ++i) { + a1[i] = in[i]; + a2[i] = a1[i] + 1; + a3[i] = a2[i] + 1; + a4[i] = a3[i] + 1; + a5[i] = a4[i] + 1; + } + int s = 0; + for (int i = 0; i < 16; ++i) + s += a1[15 - i] + a2[i] + a3[i] + a4[i] + a5[15 - i]; + return s; +} + +// Parameters and globals. +// CHECK-LABEL: func.func @ports( +// CHECK-SAME: %arg0: memref<{{[?0-9]+}}xi32> {hls.bind_storage = [{impl = "bram", type = "ram_1p", variable = "coef"}]} +int ports(int coef[64], int i) { +#pragma HLS bind_storage variable=coef type=ram_1p impl=bram +#pragma HLS bind_storage variable=grom type=rom_2p impl=bram + return coef[i] + grom[i]; +} + +// CHECK-LABEL: func.func @top( +// INLINE-DAG: {hls.bind_storage = [{type = "ram_1p", variable = "a1"}], hls.preserve, polygeist.varname = "a1"} +// NOINLINE: call @kinds +int top(int *in) { return kinds(in); } + +#ifdef ERRORS +void errors(int *a) { + int buf[8]; +// ERR-DAG: bind_storage.c:[[@LINE+1]]:44: error: invalid value 'ram_3p' for option 'type' in '#pragma HLS bind_storage': expected one of: fifo, ram_1p, ram_1wnr, ram_2p, ram_s2p, ram_t2p, rom_1p, rom_2p, rom_np +#pragma HLS bind_storage variable=buf type=ram_3p +// ERR-DAG: bind_storage.c:[[@LINE+1]]:56: error: invalid value 'dsp' for option 'impl' in '#pragma HLS bind_storage': expected one of: auto, bram, bram_ecc, lutram, uram, uram_ecc, srl, memory +#pragma HLS bind_storage variable=buf type=ram_1p impl=dsp +#pragma HLS bind_storage variable=buf type=ram_1p +// ERR-DAG: bind_storage.c:[[@LINE+1]]:1: error: '#pragma HLS bind_storage' conflicts with an earlier pragma on the same variable 'buf' +#pragma HLS bind_storage variable=buf type=ram_2p +// ERR-DAG: bind_storage.c:[[@LINE+1]]:35: error: use of undeclared variable 'missing' in '#pragma HLS bind_storage' +#pragma HLS bind_storage variable=missing type=ram_1p + buf[0] = 1; + a[0] = buf[0]; +} +#endif diff --git a/tools/cgeist/Test/HLS/bind_storage/resource_core.c b/tools/cgeist/Test/HLS/bind_storage/resource_core.c new file mode 100644 index 000000000000..b61626158fbf --- /dev/null +++ b/tools/cgeist/Test/HLS/bind_storage/resource_core.c @@ -0,0 +1,40 @@ +// The legacy `#pragma HLS RESOURCE variable=v core=C` (still accepted by +// Vitis 2025.1): a memory core is the bind_storage it names, so the array +// gets hls.bind_storage = [{type, impl?, latency?, variable}]. Vitis 2025.1 +// td=off, kernels w9r13p_rs_res / rs_bind (CIRCT VITIS_NOTES N98): `RESOURCE +// core=RAM_2P_BRAM` and `bind_storage type=ram_2p impl=bram` on a 16 x 16-bit +// array both give RAM_2P_BRAM_1R1W, 1 BRAM. An operator core (Mul_LUT, +// AddSub_DSP) names no storage and stays an hls.resource attribute. +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine --memref-fullrank 2>&1 | FileCheck %s + +// CHECK-NOT: warning + +int g[64]; +// CHECK-DAG: memref.global @g : memref<64xi32> = uninitialized {hls.bind_storage = [{impl = "lutram", type = "ram_1p", variable = "g"}]} + +// CHECK-LABEL: func.func @cores( +// CHECK-DAG: {hls.bind_storage = [{impl = "bram", type = "ram_2p", variable = "a1"}], hls.preserve, polygeist.varname = "a1"} +// CHECK-DAG: {hls.bind_storage = [{type = "ram_1p", variable = "a2"}], hls.preserve, polygeist.varname = "a2"} +// CHECK-DAG: {hls.bind_storage = [{impl = "lutram", latency = 2 : i32, type = "ram_t2p", variable = "a3"}], hls.preserve, polygeist.varname = "a3"} +// CHECK-DAG: {hls.bind_storage = [{impl = "srl", type = "fifo", variable = "a4"}], hls.preserve, polygeist.varname = "a4"} +// CHECK-DAG: {hls.preserve, hls.resource = [{core = "Mul_LUT", variable = "a5"}], polygeist.varname = "a5"} +int cores(int *in) { + int a1[16], a2[16], a3[16], a4[16], a5[16]; +#pragma HLS RESOURCE variable=g core=RAM_1P_LUTRAM +#pragma HLS RESOURCE variable=a1 core=RAM_2P_BRAM +#pragma HLS resource variable=a2 core=RAM_1P +#pragma HLS RESOURCE variable=a3 core=RAM_T2P_LUTRAM latency=2 +#pragma HLS RESOURCE variable=a4 core=FIFO_SRL +#pragma HLS RESOURCE variable=a5 core=Mul_LUT + for (int i = 0; i < 16; ++i) { + a1[i] = in[i] + g[i]; + a2[i] = a1[i] + 1; + a3[i] = a2[i] + 1; + a4[i] = a3[i] + 1; + a5[i] = a4[i] + 1; + } + int s = 0; + for (int i = 0; i < 16; ++i) + s += a1[15 - i] + a2[i] + a3[i] + a4[i] + a5[15 - i]; + return s; +} diff --git a/tools/cgeist/Test/HLS/cache/cache.c b/tools/cgeist/Test/HLS/cache/cache.c new file mode 100644 index 000000000000..591b393c515d --- /dev/null +++ b/tools/cgeist/Test/HLS/cache/cache.c @@ -0,0 +1,30 @@ +// #pragma HLS cache: hls.cache = [{port, lines?, depth?}] as an argument +// attribute on the named (m_axi) parameter. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +// CHECK-LABEL: func.func @cached( +// CHECK-SAME: %arg0: memref<{{.*}}> {hls.cache = [{depth = 64 : i32, lines = 4 : i32, port = "in"}], hls.interface = [{bundle = "gmem", mode = "m_axi", port = "in"}]} +// CHECK-SAME: %arg1: memref<{{.*}}> {hls.cache = [{port = "out"}]} +void cached(int *in, int *out) { +#pragma HLS interface m_axi port=in bundle=gmem +#pragma HLS cache port=in lines=4 depth=64 +#pragma HLS CACHE port=out + for (int i = 0; i < 64; ++i) + out[i] = in[i] + in[63 - i]; +} + +#ifdef ERRORS +void errors(int *p) { + int local[4]; +// ERR-DAG: cache.c:[[@LINE+1]]:24: error: 'local' in '#pragma HLS cache' is not a function parameter +#pragma HLS cache port=local lines=1 +// ERR-DAG: cache.c:[[@LINE+1]]:32: error: option 'lines' in '#pragma HLS cache' must be >= 1, got 0 +#pragma HLS cache port=p lines=0 + local[0] = 0; + p[0] = local[0]; +} +#endif diff --git a/tools/cgeist/Test/HLS/consumer/contract-shape.c b/tools/cgeist/Test/HLS/consumer/contract-shape.c new file mode 100644 index 000000000000..4a5154f07b77 --- /dev/null +++ b/tools/cgeist/Test/HLS/consumer/contract-shape.c @@ -0,0 +1,50 @@ +// The exact attribute shapes hls-est (~/circt, lib/Dialect/Resource) reads. +// This test runs without hls-est; the hls-est-*.c tests exercise the same +// attributes through the tool itself. +// +// - hls.array_partition: ArrayAttr of {kind: "cyclic"|"block"|"complete", +// factor: i32 (cyclic/block only), dim: i32 (always present, 1-based, +// 0 = all), variable: string}, on memref.alloca / memref.global or as a +// func.func argument attribute (MemoryInterface.cpp parsePartitionSpec, +// MemoryDS.cpp getPartitionSpecs, InferVitisSplitArray.cpp). +// - hls.pipeline: ArrayAttr of {II: i32, ...} on affine.for; II > 0 is a +// user target, 0 means "not specified" (InferVitisSplitArray.cpp). +// - hls.pipeline_off: unit attribute on affine.for. +// - polygeist.varname: string on the defining op of a memref. +// - hls.preserve: unit attribute on multi-element local arrays (read by the +// Polygeist canonicalizer). +// RUN: cgeist %s --function='*' -S --hls-annotate --raise-scf-to-affine 2>&1 | FileCheck %s --strict-whitespace + +// CHECK-NOT: warning + +float G[64]; + +// CHECK: memref.global @G : memref<64xf32> = uninitialized {hls.array_partition = [{dim = 1 : i32, factor = 4 : i32, kind = "block", variable = "G"}]} + +// CHECK-LABEL: func.func @shapes( +// CHECK-SAME: %arg0: memref {hls.array_partition = [{dim = 2 : i32, kind = "complete", variable = "a"}]} +// CHECK: %[[BUF:.*]] = memref.alloca() {hls.array_partition = [{dim = 1 : i32, factor = 2 : i32, kind = "cyclic", variable = "buf"}], hls.preserve, polygeist.varname = "buf"} : memref<64xf32> +// CHECK: affine.for +// CHECK: {{^}} } {hls.pipeline = [{II = 1 : i32, rewind = false, style = "stp"}]} +// CHECK: affine.for +// CHECK: {{^}} } {hls.pipeline = [{II = 0 : i32, rewind = false, style = "stp"}]} +// CHECK: affine.for +// CHECK: {{^}} } {hls.pipeline_off} +void shapes(float a[8][16], float *x, float *y) { + float buf[64]; +#pragma HLS array_partition variable=a complete dim=2 +#pragma HLS array_partition variable=buf cyclic factor=2 +#pragma HLS array_partition variable=G block factor=4 + for (int i = 0; i < 64; ++i) { +#pragma HLS pipeline II=1 + buf[i] = x[i] + G[i]; + } + for (int i = 0; i < 32; ++i) { +#pragma HLS pipeline + y[i] = buf[2 * i] + buf[2 * i + 1]; + } + for (int i = 0; i < 8; ++i) { +#pragma HLS pipeline off + y[i] += a[i][i]; + } +} diff --git a/tools/cgeist/Test/HLS/consumer/hls-est-banking.c b/tools/cgeist/Test/HLS/consumer/hls-est-banking.c new file mode 100644 index 000000000000..d046a1e56fff --- /dev/null +++ b/tools/cgeist/Test/HLS/consumer/hls-est-banking.c @@ -0,0 +1,37 @@ +// hls.array_partition drives hls-est's memory banking and BRAM accounting. +// REQUIRES: hls-est +// RUN: cgeist %s --function=kernel -S --hls-annotate --raise-scf-to-affine -o %t.mlir +// RUN: sed -i 's/^module attributes {.*} {$/module {/' %t.mlir +// RUN: %hls-est %t.mlir --allow-unregistered-dialect --memory-banking-bram | FileCheck %s --check-prefix=BANK +// RUN: cgeist %s --function=kernel -S --hls-annotate --raise-scf-to-affine -DNO_PRAGMA -o %t.none.mlir +// RUN: sed -i 's/^module attributes {.*} {$/module {/' %t.none.mlir +// RUN: %hls-est %t.none.mlir --allow-unregistered-dialect --memory-banking-bram | FileCheck %s --check-prefix=NOBANK +// RUN: %hls-est %t.mlir --allow-unregistered-dialect --affine-loop-normalize --memory-banking-bram --convert-affine-to-loopschedule --bram-analysis | FileCheck %s --check-prefix=BRAM + +// cyclic factor=4 on a 1024-element buffer: four banks of 256. +// BANK-LABEL: func.func @kernel( +// BANK-COUNT-4: memref.alloca() {{.*}}hls.bank_of = "buf"{{.*}} : memref<256xf32> +// BANK-NOT: memref<1024xf32> + +// Without the pragma the buffer stays whole. +// NOBANK-LABEL: func.func @kernel( +// NOBANK: memref.alloca() {{.*}}polygeist.varname = "buf"{{.*}} : memref<1024xf32> +// NOBANK-NOT: memref<256xf32> + +// BRAM-COUNT-4: memref.alloca @ loc( +// BRAM: Total BRAM: + +void kernel(float A[64][1024], float *x, float *y) { + float buf[1024]; +#ifndef NO_PRAGMA +#pragma HLS array_partition variable=buf cyclic factor=4 +#endif + for (int i = 0; i < 1024; ++i) + buf[i] = x[i]; + for (int i = 0; i < 64; ++i) { + float s = 0; + for (int j = 0; j < 1024; ++j) + s += A[i][j] * buf[j]; + y[i] = s; + } +} diff --git a/tools/cgeist/Test/HLS/consumer/hls-est-pipeline.c b/tools/cgeist/Test/HLS/consumer/hls-est-pipeline.c new file mode 100644 index 000000000000..fca46646f1ae --- /dev/null +++ b/tools/cgeist/Test/HLS/consumer/hls-est-pipeline.c @@ -0,0 +1,62 @@ +// hls.pipeline (II), hls.pipeline_off and polygeist.varname as consumed by +// hls-est's infer-vitis-split-array; a user hls.array_partition overrides +// inference. +// REQUIRES: hls-est +// RUN: cgeist %s --function='*' -S --hls-annotate --raise-scf-to-affine -o %t.mlir +// RUN: sed -i 's/^module attributes {.*} {$/module {/' %t.mlir +// RUN: %hls-est %t.mlir --allow-unregistered-dialect "--infer-vitis-split-array=td=auto emit-remarks=true" -o /dev/null 2>&1 | FileCheck %s +// RUN: %hls-est %t.mlir --allow-unregistered-dialect "--infer-vitis-split-array=td=auto emit-remarks=true auto-pipeline=true" -o /dev/null 2>&1 | FileCheck %s --check-prefix=AUTO + +// Two reads of `buf` per iteration at the user's II=1: split by 2, reported +// under the C name carried by polygeist.varname. +// CHECK-DAG: remark: Inferring pragma 'array_partition type=cyclic factor=2 dim=1' for array 'user_ii' due to pipeline pragma + +// II=2 leaves room for both reads: nothing to infer for `relaxed`. +// CHECK-NOT: for array 'relaxed' +// A user partition stands: nothing inferred for `given`. +// CHECK-NOT: for array 'given' +// pipeline off: never treated as pipelined, even with auto-pipeline. +// CHECK-NOT: for array 'unpiped' +// AUTO-NOT: for array 'unpiped' +// AUTO-NOT: for array 'relaxed' + +void user_ii_kernel(float *x, float *y) { + float user_ii[64]; + for (int i = 0; i < 64; ++i) + user_ii[i] = x[i]; + for (int i = 0; i < 32; ++i) { +#pragma HLS pipeline II=1 + y[i] = user_ii[2 * i] + user_ii[2 * i + 1]; + } +} + +void relaxed_kernel(float *x, float *y) { + float relaxed[64]; + for (int i = 0; i < 64; ++i) + relaxed[i] = x[i]; + for (int i = 0; i < 32; ++i) { +#pragma HLS pipeline II=2 + y[i] = relaxed[2 * i] + relaxed[2 * i + 1]; + } +} + +void given_kernel(float *x, float *y) { + float given[64]; +#pragma HLS array_partition variable=given block factor=2 + for (int i = 0; i < 64; ++i) + given[i] = x[i]; + for (int i = 0; i < 32; ++i) { +#pragma HLS pipeline II=1 + y[i] = given[2 * i] + given[2 * i + 1]; + } +} + +void unpiped_kernel(float *x, float *y) { + float unpiped[64]; + for (int i = 0; i < 64; ++i) + unpiped[i] = x[i]; + for (int i = 0; i < 32; ++i) { +#pragma HLS pipeline off + y[i] = unpiped[2 * i] + unpiped[2 * i + 1]; + } +} diff --git a/tools/cgeist/Test/HLS/dataflow/dataflow.c b/tools/cgeist/Test/HLS/dataflow/dataflow.c new file mode 100644 index 000000000000..94f1fe65ea6e --- /dev/null +++ b/tools/cgeist/Test/HLS/dataflow/dataflow.c @@ -0,0 +1,58 @@ +// #pragma HLS dataflow: hls.dataflow = [{disable_start_propagation}] on the +// function (outside loops) or on the enclosing loop. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s --strict-whitespace +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --strict-whitespace +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +static void produce(int *a, int *b) { + for (int i = 0; i < 16; ++i) + b[i] = a[i] + 1; +} +static void consume(int *b, int *c) { + for (int i = 0; i < 16; ++i) + c[i] = 2 * b[i]; +} + +// CHECK-LABEL: func.func @function_dataflow( +// CHECK-SAME: hls.dataflow = [{disable_start_propagation = false}] +void function_dataflow(int *a, int *c) { +#pragma HLS dataflow + int b[16]; + produce(a, b); + consume(b, c); +} + +// CHECK-LABEL: func.func @function_dataflow_nsp( +// CHECK-SAME: hls.dataflow = [{disable_start_propagation = true}] +void function_dataflow_nsp(int *a, int *c) { + int b[16]; + produce(a, b); +#pragma HLS DATAFLOW disable_start_propagation + consume(b, c); +} + +// CHECK-LABEL: func.func @loop_dataflow( +// CHECK: {{^}} } {hls.dataflow = [{disable_start_propagation = false}]} +void loop_dataflow(int a[4][16], int c[4][16]) { + for (int k = 0; k < 4; ++k) { +#pragma HLS dataflow + int b[16]; + for (int i = 0; i < 16; ++i) + b[i] = a[k][i] + 1; + for (int i = 0; i < 16; ++i) + c[k][i] = 2 * b[i]; + } +} + +#ifdef ERRORS +void errors(int *a, int *c) { +#pragma HLS dataflow +// ERR: dataflow.c:[[@LINE+1]]:1: warning: duplicate '#pragma HLS dataflow' on the same function is ignored +#pragma HLS dataflow +// ERR: dataflow.c:[[@LINE+1]]:1: error: '#pragma HLS dataflow' conflicts with an earlier pragma on the same function +#pragma HLS dataflow disable_start_propagation + c[0] = a[0]; +} +#endif diff --git a/tools/cgeist/Test/HLS/dependence/dependence.c b/tools/cgeist/Test/HLS/dependence/dependence.c new file mode 100644 index 000000000000..42bb2ed0ccfe --- /dev/null +++ b/tools/cgeist/Test/HLS/dependence/dependence.c @@ -0,0 +1,81 @@ +// #pragma HLS dependence: hls.dependence = [{variable?, class?, type, +// direction?, distance?, dependent}] on the enclosing loop (or function). +// `dependent` is required; type defaults to "inter"; direction is upper-case. +// Vivado's positional spelling (`inter RAW false`) is accepted. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s --strict-whitespace +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --strict-whitespace --check-prefixes=CHECK,INLINE +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +// CHECK-LABEL: func.func @minimal( +// CHECK: {{^}} } {hls.dependence = [{dependent = false, type = "inter"}]} +void minimal(int *a) { + for (int i = 1; i < 64; ++i) { +#pragma HLS dependence dependent=false + a[i] = a[i - 1] + 1; + } +} + +// CHECK-LABEL: func.func @all_options( +// CHECK: {{^}} } {hls.dependence = [{class = "array", dependent = true, direction = "RAW", distance = 2 : i32, type = "inter", variable = "buf"}]} +void all_options(int *a) { + int buf[64]; + for (int i = 0; i < 64; ++i) + buf[i] = a[i]; + for (int i = 2; i < 64; ++i) { +#pragma HLS dependence variable=buf class=array type=inter direction=raw distance=2 dependent=true + buf[i] = buf[i - 2] + 1; + } + for (int i = 0; i < 64; ++i) + a[i] = buf[i]; +} + +// Several dependence pragmas on one loop accumulate. +// CHECK-LABEL: func.func @positional( +// CHECK: {{^}} } {hls.dependence = [{class = "pointer", dependent = false, direction = "WAR", type = "intra", variable = "a"}, {dependent = true, type = "inter", variable = "b"}]} +void positional(int *a, int *b) { + for (int i = 1; i < 64; ++i) { +#pragma HLS DEPENDENCE variable=a pointer intra WAR false +#pragma HLS dependence variable=b inter true + a[i] = a[i - 1] + b[i]; + b[i] = a[i]; + } +} + +// CHECK-LABEL: func.func @function_level( +// CHECK-SAME: hls.dependence = [{dependent = false, type = "inter", variable = "a"}] +void function_level(int *a) { +#pragma HLS dependence variable=a dependent=false + for (int i = 1; i < 64; ++i) + a[i] = a[i - 1] + 1; +} + +// CHECK-LABEL: func.func @top( +// INLINE: } {hls.dependence = [{dependent = false, type = "inter"}]} +void top(int *a) { minimal(a); } + +#ifdef ERRORS +void errors(int *a) { + for (int i = 1; i < 64; ++i) { +// ERR-DAG: dependence.c:[[@LINE+1]]:1: error: '#pragma HLS dependence' requires option 'dependent' +#pragma HLS dependence variable=a type=inter + a[i] = a[i - 1]; + } + for (int i = 1; i < 64; ++i) { +// ERR-DAG: dependence.c:[[@LINE+1]]:33: error: use of undeclared variable 'nope' in '#pragma HLS dependence' +#pragma HLS dependence variable=nope dependent=false + a[i] = a[i - 1]; + } + for (int i = 1; i < 64; ++i) { +// ERR-DAG: dependence.c:[[@LINE+1]]:51: warning: 'distance' has no effect with dependent=false in '#pragma HLS dependence' +#pragma HLS dependence variable=a dependent=false distance=4 + a[i] = a[i - 1]; + } + for (int i = 1; i < 64; ++i) { +// ERR-DAG: dependence.c:[[@LINE+1]]:45: error: invalid value 'rar' for option 'direction' in '#pragma HLS dependence': expected one of: raw, war, waw +#pragma HLS dependence variable=a direction=rar dependent=true + a[i] = a[i - 1]; + } +} +#endif diff --git a/tools/cgeist/Test/HLS/expression_balance/expression_balance.c b/tools/cgeist/Test/HLS/expression_balance/expression_balance.c new file mode 100644 index 000000000000..17738f1b84d0 --- /dev/null +++ b/tools/cgeist/Test/HLS/expression_balance/expression_balance.c @@ -0,0 +1,43 @@ +// #pragma HLS expression_balance: hls.expression_balance = [{}] on the +// enclosing loop or function; `off` gives hls.expression_balance_off. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O3 --raise-scf-to-affine 2>&1 | FileCheck %s --check-prefixes=CHECK,INLINE +// RUN: not cgeist %s --function='*' -S --hls-annotate -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +// CHECK-LABEL: func.func @function_on( +// CHECK-SAME: hls.expression_balance = [{}] +int function_on(int *a) { +#pragma HLS expression_balance + return a[0] + a[1] + a[2] + a[3]; +} + +// CHECK-LABEL: func.func @function_off( +// CHECK-SAME: hls.expression_balance_off +float function_off(float *a) { +#pragma HLS EXPRESSION_BALANCE off + return a[0] + a[1] + a[2] + a[3]; +} + +// CHECK-LABEL: func.func @loop_off( +// CHECK: } {hls.expression_balance_off} +void loop_off(float *a, float *b) { + for (int i = 0; i < 8; ++i) { +#pragma HLS expression_balance off + b[i] = a[i] + a[i + 1] + a[i + 2]; + } +} + +// CHECK-LABEL: func.func @top( +// INLINE: } {hls.expression_balance_off} +void top(float *a, float *b) { loop_off(a, b); } + +#ifdef ERRORS +int errors(int *a) { +#pragma HLS expression_balance +// ERR: expression_balance.c:[[@LINE+1]]:1: error: '#pragma HLS expression_balance' conflicts with an earlier pragma on the same function +#pragma HLS expression_balance off + return a[0]; +} +#endif diff --git a/tools/cgeist/Test/HLS/function_instantiate/function_instantiate.c b/tools/cgeist/Test/HLS/function_instantiate/function_instantiate.c new file mode 100644 index 000000000000..a7ce91221ef0 --- /dev/null +++ b/tools/cgeist/Test/HLS/function_instantiate/function_instantiate.c @@ -0,0 +1,33 @@ +// #pragma HLS function_instantiate: argument attribute +// hls.function_instantiate = [{variable}] on the named parameter. +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 2>&1 | FileCheck %s +// RUN: cgeist %s --function='*' -S --hls-annotate -O0 --raise-scf-to-affine 2>&1 | FileCheck %s +// RUN: not cgeist %s --function='*' -S --hls-annotate -O0 -DERRORS -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK-NOT: warning + +// CHECK-LABEL: func.func @scale( +// CHECK-SAME: %arg0: memref, %arg1: i32 {hls.function_instantiate = [{variable = "mode"}]}, %arg2: i32 {hls.function_instantiate = [{variable = "shift"}]}) +void scale(int *a, int mode, int shift) { +#pragma HLS function_instantiate variable=mode +#pragma HLS FUNCTION_INSTANTIATE variable=shift + for (int i = 0; i < 8; ++i) + a[i] = mode ? a[i] << shift : a[i]; +} + +#ifdef ERRORS +int g; +void errors(int *a, int m) { + int local = 0; +// ERR: function_instantiate.c:[[@LINE+1]]:43: error: 'local' in '#pragma HLS function_instantiate' is not a function parameter +#pragma HLS function_instantiate variable=local +// ERR: function_instantiate.c:[[@LINE+1]]:43: error: 'g' in '#pragma HLS function_instantiate' is not a function parameter +#pragma HLS function_instantiate variable=g +// ERR: function_instantiate.c:[[@LINE+1]]:43: error: use of undeclared variable 'q' in '#pragma HLS function_instantiate' +#pragma HLS function_instantiate variable=q +#pragma HLS function_instantiate variable=m +// ERR: function_instantiate.c:[[@LINE+1]]:1: warning: duplicate '#pragma HLS function_instantiate' on the same variable 'm' is ignored +#pragma HLS function_instantiate variable=m + a[0] = local + m; +} +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt1/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt1/src/Autoencoder.cpp new file mode 100644 index 000000000000..acb2c8e6a8b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt1/src/Autoencoder.cpp @@ -0,0 +1,562 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[32][784] +) { // L7 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L8 + loop1: for (int v3 = 0; v3 < 784; v3++) { // L9 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L10 + v1[v2][v3] = v4; // L11 + } + } + return ; // L14 +} + +void node1( + hls::stream &v5, + float v6[784], + hls::stream &v7, + float v8 +) { // L16 + loop2: for (int v9 = 0; v9 < 32; v9++) { // L17 + loop3: for (int v10 = 0; v10 < 784; v10++) { // L18 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v5.read(); // L19 + float v12 = v6[v10]; // L20 + float v13 = v11 + v12; // L21 + float v14 = -(v13); // L22 + float v15 = exp(v14); // L23 + float v16 = v15 + v8; // L24 + float v17 = v8 / v16; // L25 + v7.write(v17); // L26 + } + } + return ; // L29 +} + +void node2( + hls::stream &v18, + hls::stream &v19, + hls::stream &v20, + float v21 +) { // L31 + float v22[32][784]; // L32 + float v23[256][784]; // L33 + float v24[32][256]; // L34 + loop4: for (int v25 = 0; v25 < 32; v25++) { // L35 + loop5: for (int v26 = 0; v26 < 784; v26++) { // L36 + loop6: for (int v27 = 0; v27 < 256; v27++) { // L37 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v26 == 0) { // L38 + float v28 = v18.read(); // L39 + v24[v25][v27] = v28; // L40 + } + float v29 = v24[v25][v27]; // L42 + if (v25 == 0) { // L43 + float v30 = v19.read(); // L44 + v23[v27][v26] = v30; // L45 + } + float v31 = v23[v27][v26]; // L47 + if (v27 == 0) { // L48 + v22[v25][v26] = v21; // L49 + } + float v32 = v22[v25][v26]; // L51 + float v33 = v29 * v31; // L52 + float v34 = v32 + v33; // L53 + v22[v25][v26] = v34; // L54 + if ((v27 - 255) == 0) { // L55 + float v35 = v22[v25][v26]; // L56 + v20.write(v35); // L57 + } + } + } + } + return ; // L62 +} + +void node3( + float v36[784][256], + hls::stream &v37 +) { // L64 + loop7: for (int v38 = 0; v38 < 784; v38++) { // L65 + loop8: for (int v39 = 0; v39 < 256; v39++) { // L66 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v38][v39]; // L67 + v37.write(v40); // L68 + } + } + return ; // L71 +} + +void node4( + hls::stream &v41, + float v42[256], + hls::stream &v43, + float v44 +) { // L73 + loop9: for (int v45 = 0; v45 < 32; v45++) { // L74 + loop10: for (int v46 = 0; v46 < 256; v46++) { // L75 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v47 = v41.read(); // L76 + float v48 = v42[v46]; // L77 + float v49 = v47 + v48; // L78 + bool v50 = v49 > v44; // L79 + float v51 = v50 ? (float)v49 : (float)v44; // L80 + v43.write(v51); // L81 + } + } + return ; // L84 +} + +void node5( + hls::stream &v52, + hls::stream &v53, + hls::stream &v54, + float v55 +) { // L86 + float v56[32][256]; // L87 + float v57[128][256]; // L88 + float v58[32][128]; // L89 + loop11: for (int v59 = 0; v59 < 32; v59++) { // L90 + loop12: for (int v60 = 0; v60 < 256; v60++) { // L91 + loop13: for (int v61 = 0; v61 < 128; v61++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { // L93 + float v62 = v53.read(); // L94 + v58[v59][v61] = v62; // L95 + } + float v63 = v58[v59][v61]; // L97 + if (v59 == 0) { // L98 + float v64 = v52.read(); // L99 + v57[v61][v60] = v64; // L100 + } + float v65 = v57[v61][v60]; // L102 + if (v61 == 0) { // L103 + v56[v59][v60] = v55; // L104 + } + float v66 = v56[v59][v60]; // L106 + float v67 = v63 * v65; // L107 + float v68 = v66 + v67; // L108 + v56[v59][v60] = v68; // L109 + if ((v61 - 127) == 0) { // L110 + float v69 = v56[v59][v60]; // L111 + v54.write(v69); // L112 + } + } + } + } + return ; // L117 +} + +void node6( + float v70[256][128], + hls::stream &v71 +) { // L119 + loop14: for (int v72 = 0; v72 < 256; v72++) { // L120 + loop15: for (int v73 = 0; v73 < 128; v73++) { // L121 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[v72][v73]; // L122 + v71.write(v74); // L123 + } + } + return ; // L126 +} + +void node7( + hls::stream &v75, + float v76[128], + hls::stream &v77, + float v78 +) { // L128 + loop16: for (int v79 = 0; v79 < 32; v79++) { // L129 + loop17: for (int v80 = 0; v80 < 128; v80++) { // L130 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v81 = v75.read(); // L131 + float v82 = v76[v80]; // L132 + float v83 = v81 + v82; // L133 + bool v84 = v83 > v78; // L134 + float v85 = v84 ? (float)v83 : (float)v78; // L135 + v77.write(v85); // L136 + } + } + return ; // L139 +} + +void node8( + hls::stream &v86, + hls::stream &v87, + hls::stream &v88, + float v89 +) { // L141 + float v90[32][128]; // L142 + float v91[64][128]; // L143 + float v92[32][64]; // L144 + loop18: for (int v93 = 0; v93 < 32; v93++) { // L145 + loop19: for (int v94 = 0; v94 < 128; v94++) { // L146 + loop20: for (int v95 = 0; v95 < 64; v95++) { // L147 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v94 == 0) { // L148 + float v96 = v87.read(); // L149 + v92[v93][v95] = v96; // L150 + } + float v97 = v92[v93][v95]; // L152 + if (v93 == 0) { // L153 + float v98 = v86.read(); // L154 + v91[v95][v94] = v98; // L155 + } + float v99 = v91[v95][v94]; // L157 + if (v95 == 0) { // L158 + v90[v93][v94] = v89; // L159 + } + float v100 = v90[v93][v94]; // L161 + float v101 = v97 * v99; // L162 + float v102 = v100 + v101; // L163 + v90[v93][v94] = v102; // L164 + if ((v95 - 63) == 0) { // L165 + float v103 = v90[v93][v94]; // L166 + v88.write(v103); // L167 + } + } + } + } + return ; // L172 +} + +void node9( + float v104[128][64], + hls::stream &v105 +) { // L174 + loop21: for (int v106 = 0; v106 < 128; v106++) { // L175 + loop22: for (int v107 = 0; v107 < 64; v107++) { // L176 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v108 = v104[v106][v107]; // L177 + v105.write(v108); // L178 + } + } + return ; // L181 +} + +void node10( + hls::stream &v109, + float v110[64], + hls::stream &v111 +) { // L183 + loop23: for (int v112 = 0; v112 < 32; v112++) { // L184 + loop24: for (int v113 = 0; v113 < 64; v113++) { // L185 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v109.read(); // L186 + float v115 = v110[v113]; // L187 + float v116 = v114 + v115; // L188 + v111.write(v116); // L189 + } + } + return ; // L192 +} + +void node11( + hls::stream &v117, + hls::stream &v118, + hls::stream &v119, + float v120 +) { // L194 + float v121[32][64]; // L195 + float v122[128][64]; // L196 + float v123[32][128]; // L197 + loop25: for (int v124 = 0; v124 < 32; v124++) { // L198 + loop26: for (int v125 = 0; v125 < 64; v125++) { // L199 + loop27: for (int v126 = 0; v126 < 128; v126++) { // L200 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v125 == 0) { // L201 + float v127 = v117.read(); // L202 + v123[v124][v126] = v127; // L203 + } + float v128 = v123[v124][v126]; // L205 + if (v124 == 0) { // L206 + float v129 = v118.read(); // L207 + v122[v126][v125] = v129; // L208 + } + float v130 = v122[v126][v125]; // L210 + if (v126 == 0) { // L211 + v121[v124][v125] = v120; // L212 + } + float v131 = v121[v124][v125]; // L214 + float v132 = v128 * v130; // L215 + float v133 = v131 + v132; // L216 + v121[v124][v125] = v133; // L217 + if ((v126 - 127) == 0) { // L218 + float v134 = v121[v124][v125]; // L219 + v119.write(v134); // L220 + } + } + } + } + return ; // L225 +} + +void node12( + float v135[64][128], + hls::stream &v136 +) { // L227 + loop28: for (int v137 = 0; v137 < 64; v137++) { // L228 + loop29: for (int v138 = 0; v138 < 128; v138++) { // L229 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v139 = v135[v137][v138]; // L230 + v136.write(v139); // L231 + } + } + return ; // L234 +} + +void node13( + hls::stream &v140, + float v141[128], + hls::stream &v142, + float v143 +) { // L236 + loop30: for (int v144 = 0; v144 < 32; v144++) { // L237 + loop31: for (int v145 = 0; v145 < 128; v145++) { // L238 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v146 = v140.read(); // L239 + float v147 = v141[v145]; // L240 + float v148 = v146 + v147; // L241 + bool v149 = v148 > v143; // L242 + float v150 = v149 ? (float)v148 : (float)v143; // L243 + v142.write(v150); // L244 + } + } + return ; // L247 +} + +void node14( + hls::stream &v151, + hls::stream &v152, + hls::stream &v153, + float v154 +) { // L249 + float v155[32][128]; // L250 + float v156[256][128]; // L251 + float v157[32][256]; // L252 + loop32: for (int v158 = 0; v158 < 32; v158++) { // L253 + loop33: for (int v159 = 0; v159 < 128; v159++) { // L254 + loop34: for (int v160 = 0; v160 < 256; v160++) { // L255 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v159 == 0) { // L256 + float v161 = v151.read(); // L257 + v157[v158][v160] = v161; // L258 + } + float v162 = v157[v158][v160]; // L260 + if (v158 == 0) { // L261 + float v163 = v152.read(); // L262 + v156[v160][v159] = v163; // L263 + } + float v164 = v156[v160][v159]; // L265 + if (v160 == 0) { // L266 + v155[v158][v159] = v154; // L267 + } + float v165 = v155[v158][v159]; // L269 + float v166 = v162 * v164; // L270 + float v167 = v165 + v166; // L271 + v155[v158][v159] = v167; // L272 + if ((v160 - 255) == 0) { // L273 + float v168 = v155[v158][v159]; // L274 + v153.write(v168); // L275 + } + } + } + } + return ; // L280 +} + +void node15( + float v169[128][256], + hls::stream &v170 +) { // L282 + loop35: for (int v171 = 0; v171 < 128; v171++) { // L283 + loop36: for (int v172 = 0; v172 < 256; v172++) { // L284 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v173 = v169[v171][v172]; // L285 + v170.write(v173); // L286 + } + } + return ; // L289 +} + +void node16( + hls::stream &v174, + float v175[256], + hls::stream &v176, + float v177 +) { // L291 + loop37: for (int v178 = 0; v178 < 32; v178++) { // L292 + loop38: for (int v179 = 0; v179 < 256; v179++) { // L293 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v180 = v174.read(); // L294 + float v181 = v175[v179]; // L295 + float v182 = v180 + v181; // L296 + bool v183 = v182 > v177; // L297 + float v184 = v183 ? (float)v182 : (float)v177; // L298 + v176.write(v184); // L299 + } + } + return ; // L302 +} + +void node17( + float v185[32][784], + hls::stream &v186, + hls::stream &v187, + float v188 +) { // L304 + float v189[32][256]; // L305 + float v190[784][256]; // L306 + loop39: for (int v191 = 0; v191 < 32; v191++) { // L307 + loop40: for (int v192 = 0; v192 < 256; v192++) { // L308 + loop41: for (int v193 = 0; v193 < 784; v193++) { // L309 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v185[v191][v193]; // L310 + if (v191 == 0) { // L311 + float v195 = v186.read(); // L312 + v190[v193][v192] = v195; // L313 + } + float v196 = v190[v193][v192]; // L315 + if (v193 == 0) { // L316 + v189[v191][v192] = v188; // L317 + } + float v197 = v189[v191][v192]; // L319 + float v198 = v194 * v196; // L320 + float v199 = v197 + v198; // L321 + v189[v191][v192] = v199; // L322 + if ((v193 - 783) == 0) { // L323 + float v200 = v189[v191][v192]; // L324 + v187.write(v200); // L325 + } + } + } + } + return ; // L330 +} + +void node18( + float v201[256][784], + hls::stream &v202 +) { // L332 + loop42: for (int v203 = 0; v203 < 256; v203++) { // L333 + loop43: for (int v204 = 0; v204 < 784; v204++) { // L334 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v205 = v201[v203][v204]; // L335 + v202.write(v205); // L336 + } + } + return ; // L339 +} + +void forward( + float v206[32][784], + float v207[256], + float v208[256][784], + float v209[128], + float v210[128][256], + float v211[64], + float v212[64][128], + float v213[128], + float v214[128][64], + float v215[256], + float v216[256][128], + float v217[784], + float v218[784][256], + float v219[32][784] +) { // L341 + #pragma HLS DATAFLOW + hls::stream v220("fifo_0"); + #pragma HLS STREAM variable=v220 depth=25088 // L344 + hls::stream v221("fifo_1"); + #pragma HLS STREAM variable=v221 depth=25088 // L345 + hls::stream v222("fifo_2"); + #pragma HLS STREAM variable=v222 depth=200704 // L346 + hls::stream v223("fifo_3"); + #pragma HLS STREAM variable=v223 depth=8192 // L347 + hls::stream v224("fifo_4"); + #pragma HLS STREAM variable=v224 depth=8192 // L348 + hls::stream v225("fifo_5"); + #pragma HLS STREAM variable=v225 depth=32768 // L349 + hls::stream v226("fifo_6"); + #pragma HLS STREAM variable=v226 depth=4096 // L350 + hls::stream v227("fifo_7"); + #pragma HLS STREAM variable=v227 depth=4096 // L351 + hls::stream v228("fifo_8"); + #pragma HLS STREAM variable=v228 depth=8192 // L352 + hls::stream v229("fifo_9"); + #pragma HLS STREAM variable=v229 depth=2048 // L353 + hls::stream v230("fifo_10"); + #pragma HLS STREAM variable=v230 depth=2048 // L354 + hls::stream v231("fifo_11"); + #pragma HLS STREAM variable=v231 depth=8192 // L355 + hls::stream v232("fifo_12"); + #pragma HLS STREAM variable=v232 depth=4096 // L356 + hls::stream v233("fifo_13"); + #pragma HLS STREAM variable=v233 depth=4096 // L357 + hls::stream v234("fifo_14"); + #pragma HLS STREAM variable=v234 depth=32768 // L358 + hls::stream v235("fifo_15"); + #pragma HLS STREAM variable=v235 depth=8192 // L359 + hls::stream v236("fifo_16"); + #pragma HLS STREAM variable=v236 depth=8192 // L360 + hls::stream v237("fifo_17"); + #pragma HLS STREAM variable=v237 depth=200704 // L361 + node18(v208, v237); // L362 + node17(v206, v237, v236, 0.000000); // L363 + node16(v236, v207, v235, 0.000000); // L364 + node15(v210, v234); // L365 + node14(v235, v234, v233, 0.000000); // L366 + node13(v233, v209, v232, 0.000000); // L367 + node12(v212, v231); // L368 + node11(v232, v231, v230, 0.000000); // L369 + node10(v230, v211, v229); // L370 + node9(v214, v228); // L371 + node8(v228, v229, v227, 0.000000); // L372 + node7(v227, v213, v226, 0.000000); // L373 + node6(v216, v225); // L374 + node5(v225, v226, v224, 0.000000); // L375 + node4(v224, v215, v223, 0.000000); // L376 + node3(v218, v222); // L377 + node2(v223, v222, v221, 0.000000); // L378 + node1(v221, v217, v220, 1.000000); // L379 + node0(v220, v219); // L380 + return ; // L381 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt2/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt2/src/Autoencoder.cpp new file mode 100644 index 000000000000..b0753b5fc629 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt2/src/Autoencoder.cpp @@ -0,0 +1,558 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[32][784] +) { // L7 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L8 + loop1: for (int v3 = 0; v3 < 784; v3++) { // L9 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L10 + v1[v2][v3] = v4; // L11 + } + } + return ; // L14 +} + +void node1( + hls::stream &v5, + float v6[784], + hls::stream &v7, + float v8 +) { // L16 + loop2: for (int v9 = 0; v9 < 32; v9++) { // L17 + loop3: for (int v10 = 0; v10 < 784; v10++) { // L18 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v5.read(); // L19 + float v12 = v6[v10]; // L20 + float v13 = v11 + v12; // L21 + float v14 = -(v13); // L22 + float v15 = exp(v14); // L23 + float v16 = v15 + v8; // L24 + float v17 = v8 / v16; // L25 + v7.write(v17); // L26 + } + } + return ; // L29 +} + +void node2( + float v18[256][784], + hls::stream &v19, + hls::stream &v20, + float v21 +) { // L31 + float v22[32][784]; // L32 + float v23[256][784]; // L33 + float v24[32][256]; // L34 + loop4: for (int v25 = 0; v25 < 32; v25++) { // L35 + loop5: for (int v26 = 0; v26 < 256; v26++) { // L36 + loop6: for (int v27 = 0; v27 < 784; v27++) { // L37 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v27 == 0) { // L38 + float v28 = v19.read(); // L39 + v24[v25][v26] = v28; // L40 + } + float v29 = v24[v25][v26]; // L42 + if (v25 == 0) { // L43 + float v30 = v18[v26][v27]; // L44 + v23[v26][v27] = v30; // L45 + } + float v31 = v23[v26][v27]; // L47 + if (v26 == 0) { // L48 + v22[v25][v27] = v21; // L49 + } + float v32 = v22[v25][v27]; // L51 + float v33 = v29 * v31; // L52 + float v34 = v32 + v33; // L53 + v22[v25][v27] = v34; // L54 + if ((v26 - 255) == 0) { // L55 + float v35 = v22[v25][v27]; // L56 + v20.write(v35); // L57 + } + } + } + } + return ; // L62 +} + +void node3( + float v36[784][256], + float v37[256][784] +) { // L64 + loop7: for (int v38 = 0; v38 < 784; v38++) { // L65 + loop8: for (int v39 = 0; v39 < 256; v39++) { // L66 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v38][v39]; // L67 + v37[v39][v38] = v40; // L68 + } + } + return ; // L71 +} + +void node4( + hls::stream &v41, + float v42[256], + hls::stream &v43, + float v44 +) { // L73 + loop9: for (int v45 = 0; v45 < 32; v45++) { // L74 + loop10: for (int v46 = 0; v46 < 256; v46++) { // L75 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v47 = v41.read(); // L76 + float v48 = v42[v46]; // L77 + float v49 = v47 + v48; // L78 + bool v50 = v49 > v44; // L79 + float v51 = v50 ? (float)v49 : (float)v44; // L80 + v43.write(v51); // L81 + } + } + return ; // L84 +} + +void node5( + float v52[128][256], + hls::stream &v53, + hls::stream &v54, + float v55 +) { // L86 + float v56[32][256]; // L87 + float v57[128][256]; // L88 + float v58[32][128]; // L89 + loop11: for (int v59 = 0; v59 < 32; v59++) { // L90 + loop12: for (int v60 = 0; v60 < 256; v60++) { // L91 + loop13: for (int v61 = 0; v61 < 128; v61++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { // L93 + float v62 = v53.read(); // L94 + v58[v59][v61] = v62; // L95 + } + float v63 = v58[v59][v61]; // L97 + if (v59 == 0) { // L98 + float v64 = v52[v61][v60]; // L99 + v57[v61][v60] = v64; // L100 + } + float v65 = v57[v61][v60]; // L102 + if (v61 == 0) { // L103 + v56[v59][v60] = v55; // L104 + } + float v66 = v56[v59][v60]; // L106 + float v67 = v63 * v65; // L107 + float v68 = v66 + v67; // L108 + v56[v59][v60] = v68; // L109 + if ((v61 - 127) == 0) { // L110 + float v69 = v56[v59][v60]; // L111 + v54.write(v69); // L112 + } + } + } + } + return ; // L117 +} + +void node6( + float v70[256][128], + float v71[128][256] +) { // L119 + loop14: for (int v72 = 0; v72 < 128; v72++) { // L120 + loop15: for (int v73 = 0; v73 < 256; v73++) { // L121 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[v73][v72]; // L122 + v71[v72][v73] = v74; // L123 + } + } + return ; // L126 +} + +void node7( + hls::stream &v75, + float v76[128], + hls::stream &v77, + float v78 +) { // L128 + loop16: for (int v79 = 0; v79 < 32; v79++) { // L129 + loop17: for (int v80 = 0; v80 < 128; v80++) { // L130 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v81 = v75.read(); // L131 + float v82 = v76[v80]; // L132 + float v83 = v81 + v82; // L133 + bool v84 = v83 > v78; // L134 + float v85 = v84 ? (float)v83 : (float)v78; // L135 + v77.write(v85); // L136 + } + } + return ; // L139 +} + +void node8( + float v86[64][128], + hls::stream &v87, + hls::stream &v88, + float v89 +) { // L141 + float v90[32][128]; // L142 + float v91[64][128]; // L143 + float v92[32][64]; // L144 + loop18: for (int v93 = 0; v93 < 32; v93++) { // L145 + loop19: for (int v94 = 0; v94 < 128; v94++) { // L146 + loop20: for (int v95 = 0; v95 < 64; v95++) { // L147 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v94 == 0) { // L148 + float v96 = v87.read(); // L149 + v92[v93][v95] = v96; // L150 + } + float v97 = v92[v93][v95]; // L152 + if (v93 == 0) { // L153 + float v98 = v86[v95][v94]; // L154 + v91[v95][v94] = v98; // L155 + } + float v99 = v91[v95][v94]; // L157 + if (v95 == 0) { // L158 + v90[v93][v94] = v89; // L159 + } + float v100 = v90[v93][v94]; // L161 + float v101 = v97 * v99; // L162 + float v102 = v100 + v101; // L163 + v90[v93][v94] = v102; // L164 + if ((v95 - 63) == 0) { // L165 + float v103 = v90[v93][v94]; // L166 + v88.write(v103); // L167 + } + } + } + } + return ; // L172 +} + +void node9( + float v104[128][64], + float v105[64][128] +) { // L174 + loop21: for (int v106 = 0; v106 < 64; v106++) { // L175 + loop22: for (int v107 = 0; v107 < 128; v107++) { // L176 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v108 = v104[v107][v106]; // L177 + v105[v106][v107] = v108; // L178 + } + } + return ; // L181 +} + +void node10( + hls::stream &v109, + float v110[64], + hls::stream &v111 +) { // L183 + loop23: for (int v112 = 0; v112 < 32; v112++) { // L184 + loop24: for (int v113 = 0; v113 < 64; v113++) { // L185 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v109.read(); // L186 + float v115 = v110[v113]; // L187 + float v116 = v114 + v115; // L188 + v111.write(v116); // L189 + } + } + return ; // L192 +} + +void node11( + hls::stream &v117, + float v118[128][64], + hls::stream &v119, + float v120 +) { // L194 + float v121[32][64]; // L195 + float v122[128][64]; // L196 + float v123[32][128]; // L197 + loop25: for (int v124 = 0; v124 < 32; v124++) { // L198 + loop26: for (int v125 = 0; v125 < 64; v125++) { // L199 + loop27: for (int v126 = 0; v126 < 128; v126++) { // L200 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v125 == 0) { // L201 + float v127 = v117.read(); // L202 + v123[v124][v126] = v127; // L203 + } + float v128 = v123[v124][v126]; // L205 + if (v124 == 0) { // L206 + float v129 = v118[v126][v125]; // L207 + v122[v126][v125] = v129; // L208 + } + float v130 = v122[v126][v125]; // L210 + if (v126 == 0) { // L211 + v121[v124][v125] = v120; // L212 + } + float v131 = v121[v124][v125]; // L214 + float v132 = v128 * v130; // L215 + float v133 = v131 + v132; // L216 + v121[v124][v125] = v133; // L217 + if ((v126 - 127) == 0) { // L218 + float v134 = v121[v124][v125]; // L219 + v119.write(v134); // L220 + } + } + } + } + return ; // L225 +} + +void node12( + float v135[64][128], + float v136[128][64] +) { // L227 + loop28: for (int v137 = 0; v137 < 128; v137++) { // L228 + loop29: for (int v138 = 0; v138 < 64; v138++) { // L229 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v139 = v135[v138][v137]; // L230 + v136[v137][v138] = v139; // L231 + } + } + return ; // L234 +} + +void node13( + hls::stream &v140, + float v141[128], + hls::stream &v142, + float v143 +) { // L236 + loop30: for (int v144 = 0; v144 < 32; v144++) { // L237 + loop31: for (int v145 = 0; v145 < 128; v145++) { // L238 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v146 = v140.read(); // L239 + float v147 = v141[v145]; // L240 + float v148 = v146 + v147; // L241 + bool v149 = v148 > v143; // L242 + float v150 = v149 ? (float)v148 : (float)v143; // L243 + v142.write(v150); // L244 + } + } + return ; // L247 +} + +void node14( + hls::stream &v151, + hls::stream &v152, + hls::stream &v153, + float v154 +) { // L249 + float v155[32][128]; // L250 + float v156[256][128]; // L251 + float v157[32][256]; // L252 + loop32: for (int v158 = 0; v158 < 32; v158++) { // L253 + loop33: for (int v159 = 0; v159 < 256; v159++) { // L254 + loop34: for (int v160 = 0; v160 < 128; v160++) { // L255 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v160 == 0) { // L256 + float v161 = v152.read(); // L257 + v157[v158][v159] = v161; // L258 + } + float v162 = v157[v158][v159]; // L260 + if (v158 == 0) { // L261 + float v163 = v151.read(); // L262 + v156[v159][v160] = v163; // L263 + } + float v164 = v156[v159][v160]; // L265 + if (v159 == 0) { // L266 + v155[v158][v160] = v154; // L267 + } + float v165 = v155[v158][v160]; // L269 + float v166 = v162 * v164; // L270 + float v167 = v165 + v166; // L271 + v155[v158][v160] = v167; // L272 + if ((v159 - 255) == 0) { // L273 + float v168 = v155[v158][v160]; // L274 + v153.write(v168); // L275 + } + } + } + } + return ; // L280 +} + +void node15( + float v169[128][256], + hls::stream &v170 +) { // L282 + loop35: for (int v171 = 0; v171 < 256; v171++) { // L283 + loop36: for (int v172 = 0; v172 < 128; v172++) { // L284 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v173 = v169[v172][v171]; // L285 + v170.write(v173); // L286 + } + } + return ; // L289 +} + +void node16( + hls::stream &v174, + float v175[256], + hls::stream &v176, + float v177 +) { // L291 + loop37: for (int v178 = 0; v178 < 32; v178++) { // L292 + loop38: for (int v179 = 0; v179 < 256; v179++) { // L293 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v180 = v174.read(); // L294 + float v181 = v175[v179]; // L295 + float v182 = v180 + v181; // L296 + bool v183 = v182 > v177; // L297 + float v184 = v183 ? (float)v182 : (float)v177; // L298 + v176.write(v184); // L299 + } + } + return ; // L302 +} + +void node17( + float v185[32][784], + hls::stream &v186, + hls::stream &v187, + float v188 +) { // L304 + float v189[32][256]; // L305 + float v190[784][256]; // L306 + loop39: for (int v191 = 0; v191 < 32; v191++) { // L307 + loop40: for (int v192 = 0; v192 < 784; v192++) { // L308 + loop41: for (int v193 = 0; v193 < 256; v193++) { // L309 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v185[v191][v192]; // L310 + if (v191 == 0) { // L311 + float v195 = v186.read(); // L312 + v190[v192][v193] = v195; // L313 + } + float v196 = v190[v192][v193]; // L315 + if (v192 == 0) { // L316 + v189[v191][v193] = v188; // L317 + } + float v197 = v189[v191][v193]; // L319 + float v198 = v194 * v196; // L320 + float v199 = v197 + v198; // L321 + v189[v191][v193] = v199; // L322 + if ((v192 - 783) == 0) { // L323 + float v200 = v189[v191][v193]; // L324 + v187.write(v200); // L325 + } + } + } + } + return ; // L330 +} + +void node18( + float v201[256][784], + hls::stream &v202 +) { // L332 + loop42: for (int v203 = 0; v203 < 784; v203++) { // L333 + loop43: for (int v204 = 0; v204 < 256; v204++) { // L334 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v205 = v201[v204][v203]; // L335 + v202.write(v205); // L336 + } + } + return ; // L339 +} + +void forward( + float v206[32][784], + float v207[256], + float v208[256][784], + float v209[128], + float v210[128][256], + float v211[64], + float v212[64][128], + float v213[128], + float v214[128][64], + float v215[256], + float v216[256][128], + float v217[784], + float v218[784][256], + float v219[32][784] +) { // L341 + #pragma HLS DATAFLOW + hls::stream v220("fifo_0"); + #pragma HLS STREAM variable=v220 depth=25088 // L344 + hls::stream v221("fifo_1"); + #pragma HLS STREAM variable=v221 depth=25088 // L345 + float v222[256][784]; // L346 + hls::stream v223("fifo_2"); + #pragma HLS STREAM variable=v223 depth=8192 // L347 + hls::stream v224("fifo_3"); + #pragma HLS STREAM variable=v224 depth=8192 // L348 + float v225[128][256]; // L349 + hls::stream v226("fifo_4"); + #pragma HLS STREAM variable=v226 depth=4096 // L350 + hls::stream v227("fifo_5"); + #pragma HLS STREAM variable=v227 depth=4096 // L351 + float v228[64][128]; // L352 + hls::stream v229("fifo_6"); + #pragma HLS STREAM variable=v229 depth=2048 // L353 + hls::stream v230("fifo_7"); + #pragma HLS STREAM variable=v230 depth=2048 // L354 + float v231[128][64]; // L355 + hls::stream v232("fifo_8"); + #pragma HLS STREAM variable=v232 depth=4096 // L356 + hls::stream v233("fifo_9"); + #pragma HLS STREAM variable=v233 depth=4096 // L357 + hls::stream v234("fifo_10"); + #pragma HLS STREAM variable=v234 depth=32768 // L358 + hls::stream v235("fifo_11"); + #pragma HLS STREAM variable=v235 depth=8192 // L359 + hls::stream v236("fifo_12"); + #pragma HLS STREAM variable=v236 depth=8192 // L360 + hls::stream v237("fifo_13"); + #pragma HLS STREAM variable=v237 depth=200704 // L361 + node18(v208, v237); // L362 + node17(v206, v237, v236, 0.000000); // L363 + node16(v236, v207, v235, 0.000000); // L364 + node15(v210, v234); // L365 + node14(v234, v235, v233, 0.000000); // L366 + node13(v233, v209, v232, 0.000000); // L367 + node12(v212, v231); // L368 + node11(v232, v231, v230, 0.000000); // L369 + node10(v230, v211, v229); // L370 + node9(v214, v228); // L371 + node8(v228, v229, v227, 0.000000); // L372 + node7(v227, v213, v226, 0.000000); // L373 + node6(v216, v225); // L374 + node5(v225, v226, v224, 0.000000); // L375 + node4(v224, v215, v223, 0.000000); // L376 + node3(v218, v222); // L377 + node2(v222, v223, v221, 0.000000); // L378 + node1(v221, v217, v220, 1.000000); // L379 + node0(v220, v219); // L380 + return ; // L381 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt3/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt3/src/Autoencoder.cpp new file mode 100644 index 000000000000..059f95354110 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt3/src/Autoencoder.cpp @@ -0,0 +1,650 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][49], + float v1[32][784] +) { // L15 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L16 + loop1: for (int v3 = 0; v3 < 16; v3++) { // L17 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L18 + loop3: for (int v5 = 0; v5 < 49; v5++) { // L19 + float v6 = v0[v4][v5].read(); // L20 + v1[(v2 + v4)][(v5 + (v3 * 49))] = v6; // L21 + } + } + } + } + return ; // L26 +} + +void node1( + hls::stream v7[1][49], + float v8[784], + hls::stream v9[1][49], + float v10 +) { // L28 + loop4: for (int v11 = 0; v11 < 32; v11++) { // L29 + loop5: for (int v12 = 0; v12 < 16; v12++) { // L30 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 1; v13++) { // L31 + loop7: for (int v14 = 0; v14 < 49; v14++) { // L32 + float v15 = v7[v13][v14].read(); // L33 + float v16 = v8[(v14 + (v12 * 49))]; // L34 + float v17 = v15 + v16; // L35 + float v18 = -(v17); // L36 + float v19 = exp(v18); // L37 + float v20 = v19 + v10; // L38 + float v21 = v10 / v20; // L39 + v9[v13][v14].write(v21); // L40 + } + } + } + } + return ; // L45 +} + +void node2( + hls::stream v22[1][4], + hls::stream v23[4][49], + hls::stream v24[1][49], + float v25 +) { // L47 + float v26[32][784]; // L48 + float v27[256][784]; // L49 + float v28[32][256]; // L50 + loop8: for (int v29 = 0; v29 < 32; v29++) { // L51 + loop9: for (int v30 = 0; v30 < 16; v30++) { // L52 + loop10: for (int v31 = 0; v31 < 64; v31++) { // L53 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v32 = 0; v32 < 1; v32++) { // L54 + loop12: for (int v33 = 0; v33 < 49; v33++) { // L55 + loop13: for (int v34 = 0; v34 < 4; v34++) { // L56 + if ((v33 + (v30 * 49)) == 0) { // L57 + float v35 = v22[v32][v34].read(); // L58 + v28[(v29 + v32)][(v34 + (v31 * 4))] = v35; // L59 + } + float v36 = v28[(v29 + v32)][(v34 + (v31 * 4))]; // L61 + if ((v29 + v32) == 0) { // L62 + float v37 = v23[v34][v33].read(); // L63 + v27[(v34 + (v31 * 4))][(v33 + (v30 * 49))] = v37; // L64 + } + float v38 = v27[(v34 + (v31 * 4))][(v33 + (v30 * 49))]; // L66 + if ((v34 + (v31 * 4)) == 0) { // L67 + v26[(v29 + v32)][(v33 + (v30 * 49))] = v25; // L68 + } + float v39 = v26[(v29 + v32)][(v33 + (v30 * 49))]; // L70 + float v40 = v36 * v38; // L71 + float v41 = v39 + v40; // L72 + v26[(v29 + v32)][(v33 + (v30 * 49))] = v41; // L73 + if (((v34 + (v31 * 4)) - 255) == 0) { // L74 + float v42 = v26[(v29 + v32)][(v33 + (v30 * 49))]; // L75 + v24[v32][v33].write(v42); // L76 + } + } + } + } + } + } + } + return ; // L84 +} + +void node3( + float v43[784][256], + hls::stream v44[4][49] +) { // L86 + loop14: for (int v45 = 0; v45 < 16; v45++) { // L87 + loop15: for (int v46 = 0; v46 < 64; v46++) { // L88 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v47 = 0; v47 < 49; v47++) { // L89 + loop17: for (int v48 = 0; v48 < 4; v48++) { // L90 + float v49 = v43[(v47 + (v45 * 49))][(v48 + (v46 * 4))]; // L91 + v44[v48][v47].write(v49); // L92 + } + } + } + } + return ; // L97 +} + +void node4( + hls::stream v50[1][4], + float v51[256], + hls::stream v52[1][4], + float v53 +) { // L99 + loop18: for (int v54 = 0; v54 < 32; v54++) { // L100 + loop19: for (int v55 = 0; v55 < 64; v55++) { // L101 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v56 = 0; v56 < 1; v56++) { // L102 + loop21: for (int v57 = 0; v57 < 4; v57++) { // L103 + float v58 = v50[v56][v57].read(); // L104 + float v59 = v51[(v57 + (v55 * 4))]; // L105 + float v60 = v58 + v59; // L106 + bool v61 = v60 > v53; // L107 + float v62 = v61 ? (float)v60 : (float)v53; // L108 + v52[v56][v57].write(v62); // L109 + } + } + } + } + return ; // L114 +} + +void node5( + hls::stream v63[1][8], + hls::stream v64[8][4], + hls::stream v65[1][4], + float v66 +) { // L116 + float v67[32][256]; // L117 + float v68[128][256]; // L118 + float v69[32][128]; // L119 + loop22: for (int v70 = 0; v70 < 32; v70++) { // L120 + loop23: for (int v71 = 0; v71 < 64; v71++) { // L121 + loop24: for (int v72 = 0; v72 < 16; v72++) { // L122 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 1; v73++) { // L123 + loop26: for (int v74 = 0; v74 < 4; v74++) { // L124 + loop27: for (int v75 = 0; v75 < 8; v75++) { // L125 + if ((v74 + (v71 * 4)) == 0) { // L126 + float v76 = v63[v73][v75].read(); // L127 + v69[(v70 + v73)][(v75 + (v72 * 8))] = v76; // L128 + } + float v77 = v69[(v70 + v73)][(v75 + (v72 * 8))]; // L130 + if ((v70 + v73) == 0) { // L131 + float v78 = v64[v75][v74].read(); // L132 + v68[(v75 + (v72 * 8))][(v74 + (v71 * 4))] = v78; // L133 + } + float v79 = v68[(v75 + (v72 * 8))][(v74 + (v71 * 4))]; // L135 + if ((v75 + (v72 * 8)) == 0) { // L136 + v67[(v70 + v73)][(v74 + (v71 * 4))] = v66; // L137 + } + float v80 = v67[(v70 + v73)][(v74 + (v71 * 4))]; // L139 + float v81 = v77 * v79; // L140 + float v82 = v80 + v81; // L141 + v67[(v70 + v73)][(v74 + (v71 * 4))] = v82; // L142 + if (((v75 + (v72 * 8)) - 127) == 0) { // L143 + float v83 = v67[(v70 + v73)][(v74 + (v71 * 4))]; // L144 + v65[v73][v74].write(v83); // L145 + } + } + } + } + } + } + } + return ; // L153 +} + +void node6( + float v84[256][128], + hls::stream v85[8][4] +) { // L155 + loop28: for (int v86 = 0; v86 < 64; v86++) { // L156 + loop29: for (int v87 = 0; v87 < 16; v87++) { // L157 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v88 = 0; v88 < 4; v88++) { // L158 + loop31: for (int v89 = 0; v89 < 8; v89++) { // L159 + float v90 = v84[(v88 + (v86 * 4))][(v89 + (v87 * 8))]; // L160 + v85[v89][v88].write(v90); // L161 + } + } + } + } + return ; // L166 +} + +void node7( + hls::stream v91[1][8], + float v92[128], + hls::stream v93[1][8], + float v94 +) { // L168 + loop32: for (int v95 = 0; v95 < 32; v95++) { // L169 + loop33: for (int v96 = 0; v96 < 16; v96++) { // L170 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v97 = 0; v97 < 1; v97++) { // L171 + loop35: for (int v98 = 0; v98 < 8; v98++) { // L172 + float v99 = v91[v97][v98].read(); // L173 + float v100 = v92[(v98 + (v96 * 8))]; // L174 + float v101 = v99 + v100; // L175 + bool v102 = v101 > v94; // L176 + float v103 = v102 ? (float)v101 : (float)v94; // L177 + v93[v97][v98].write(v103); // L178 + } + } + } + } + return ; // L183 +} + +void node8( + hls::stream v104[2][8], + hls::stream v105[1][2], + hls::stream v106[1][8], + float v107 +) { // L185 + float v108[32][128]; // L186 + float v109[64][128]; // L187 + float v110[32][64]; // L188 + loop36: for (int v111 = 0; v111 < 32; v111++) { // L189 + loop37: for (int v112 = 0; v112 < 16; v112++) { // L190 + loop38: for (int v113 = 0; v113 < 32; v113++) { // L191 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v114 = 0; v114 < 1; v114++) { // L192 + loop40: for (int v115 = 0; v115 < 8; v115++) { // L193 + loop41: for (int v116 = 0; v116 < 2; v116++) { // L194 + if ((v115 + (v112 * 8)) == 0) { // L195 + float v117 = v105[v114][v116].read(); // L196 + v110[(v111 + v114)][(v116 + (v113 * 2))] = v117; // L197 + } + float v118 = v110[(v111 + v114)][(v116 + (v113 * 2))]; // L199 + if ((v111 + v114) == 0) { // L200 + float v119 = v104[v116][v115].read(); // L201 + v109[(v116 + (v113 * 2))][(v115 + (v112 * 8))] = v119; // L202 + } + float v120 = v109[(v116 + (v113 * 2))][(v115 + (v112 * 8))]; // L204 + if ((v116 + (v113 * 2)) == 0) { // L205 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v107; // L206 + } + float v121 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L208 + float v122 = v118 * v120; // L209 + float v123 = v121 + v122; // L210 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v123; // L211 + if (((v116 + (v113 * 2)) - 63) == 0) { // L212 + float v124 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L213 + v106[v114][v115].write(v124); // L214 + } + } + } + } + } + } + } + return ; // L222 +} + +void node9( + float v125[128][64], + hls::stream v126[2][8] +) { // L224 + loop42: for (int v127 = 0; v127 < 16; v127++) { // L225 + loop43: for (int v128 = 0; v128 < 32; v128++) { // L226 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v129 = 0; v129 < 8; v129++) { // L227 + loop45: for (int v130 = 0; v130 < 2; v130++) { // L228 + float v131 = v125[(v129 + (v127 * 8))][(v130 + (v128 * 2))]; // L229 + v126[v130][v129].write(v131); // L230 + } + } + } + } + return ; // L235 +} + +void node10( + hls::stream v132[1][2], + float v133[64], + hls::stream v134[1][2] +) { // L237 + loop46: for (int v135 = 0; v135 < 32; v135++) { // L238 + loop47: for (int v136 = 0; v136 < 32; v136++) { // L239 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v137 = 0; v137 < 1; v137++) { // L240 + loop49: for (int v138 = 0; v138 < 2; v138++) { // L241 + float v139 = v132[v137][v138].read(); // L242 + float v140 = v133[(v138 + (v136 * 2))]; // L243 + float v141 = v139 + v140; // L244 + v134[v137][v138].write(v141); // L245 + } + } + } + } + return ; // L250 +} + +void node11( + hls::stream v142[1][4], + hls::stream v143[4][2], + hls::stream v144[1][2], + float v145 +) { // L252 + float v146[32][64]; // L253 + float v147[128][64]; // L254 + float v148[32][128]; // L255 + loop50: for (int v149 = 0; v149 < 32; v149++) { // L256 + loop51: for (int v150 = 0; v150 < 32; v150++) { // L257 + loop52: for (int v151 = 0; v151 < 32; v151++) { // L258 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v152 = 0; v152 < 1; v152++) { // L259 + loop54: for (int v153 = 0; v153 < 2; v153++) { // L260 + loop55: for (int v154 = 0; v154 < 4; v154++) { // L261 + if ((v153 + (v150 * 2)) == 0) { // L262 + float v155 = v142[v152][v154].read(); // L263 + v148[(v149 + v152)][(v154 + (v151 * 4))] = v155; // L264 + } + float v156 = v148[(v149 + v152)][(v154 + (v151 * 4))]; // L266 + if ((v149 + v152) == 0) { // L267 + float v157 = v143[v154][v153].read(); // L268 + v147[(v154 + (v151 * 4))][(v153 + (v150 * 2))] = v157; // L269 + } + float v158 = v147[(v154 + (v151 * 4))][(v153 + (v150 * 2))]; // L271 + if ((v154 + (v151 * 4)) == 0) { // L272 + v146[(v149 + v152)][(v153 + (v150 * 2))] = v145; // L273 + } + float v159 = v146[(v149 + v152)][(v153 + (v150 * 2))]; // L275 + float v160 = v156 * v158; // L276 + float v161 = v159 + v160; // L277 + v146[(v149 + v152)][(v153 + (v150 * 2))] = v161; // L278 + if (((v154 + (v151 * 4)) - 127) == 0) { // L279 + float v162 = v146[(v149 + v152)][(v153 + (v150 * 2))]; // L280 + v144[v152][v153].write(v162); // L281 + } + } + } + } + } + } + } + return ; // L289 +} + +void node12( + float v163[64][128], + hls::stream v164[4][2] +) { // L291 + loop56: for (int v165 = 0; v165 < 32; v165++) { // L292 + loop57: for (int v166 = 0; v166 < 32; v166++) { // L293 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop58: for (int v167 = 0; v167 < 2; v167++) { // L294 + loop59: for (int v168 = 0; v168 < 4; v168++) { // L295 + float v169 = v163[(v167 + (v165 * 2))][(v168 + (v166 * 4))]; // L296 + v164[v168][v167].write(v169); // L297 + } + } + } + } + return ; // L302 +} + +void node13( + hls::stream v170[1][4], + float v171[128], + hls::stream v172[1][4], + float v173 +) { // L304 + loop60: for (int v174 = 0; v174 < 32; v174++) { // L305 + loop61: for (int v175 = 0; v175 < 32; v175++) { // L306 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v176 = 0; v176 < 1; v176++) { // L307 + loop63: for (int v177 = 0; v177 < 4; v177++) { // L308 + float v178 = v170[v176][v177].read(); // L309 + float v179 = v171[(v177 + (v175 * 4))]; // L310 + float v180 = v178 + v179; // L311 + bool v181 = v180 > v173; // L312 + float v182 = v181 ? (float)v180 : (float)v173; // L313 + v172[v176][v177].write(v182); // L314 + } + } + } + } + return ; // L319 +} + +void node14( + hls::stream v183[8][4], + hls::stream v184[1][8], + hls::stream v185[1][4], + float v186 +) { // L321 + float v187[32][128]; // L322 + float v188[256][128]; // L323 + float v189[32][256]; // L324 + loop64: for (int v190 = 0; v190 < 32; v190++) { // L325 + loop65: for (int v191 = 0; v191 < 32; v191++) { // L326 + loop66: for (int v192 = 0; v192 < 32; v192++) { // L327 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop67: for (int v193 = 0; v193 < 1; v193++) { // L328 + loop68: for (int v194 = 0; v194 < 4; v194++) { // L329 + loop69: for (int v195 = 0; v195 < 8; v195++) { // L330 + if ((v194 + (v191 * 4)) == 0) { // L331 + float v196 = v184[v193][v195].read(); // L332 + v189[(v190 + v193)][(v195 + (v192 * 8))] = v196; // L333 + } + float v197 = v189[(v190 + v193)][(v195 + (v192 * 8))]; // L335 + if ((v190 + v193) == 0) { // L336 + float v198 = v183[v195][v194].read(); // L337 + v188[(v195 + (v192 * 8))][(v194 + (v191 * 4))] = v198; // L338 + } + float v199 = v188[(v195 + (v192 * 8))][(v194 + (v191 * 4))]; // L340 + if ((v195 + (v192 * 8)) == 0) { // L341 + v187[(v190 + v193)][(v194 + (v191 * 4))] = v186; // L342 + } + float v200 = v187[(v190 + v193)][(v194 + (v191 * 4))]; // L344 + float v201 = v197 * v199; // L345 + float v202 = v200 + v201; // L346 + v187[(v190 + v193)][(v194 + (v191 * 4))] = v202; // L347 + if (((v195 + (v192 * 8)) - 255) == 0) { // L348 + float v203 = v187[(v190 + v193)][(v194 + (v191 * 4))]; // L349 + v185[v193][v194].write(v203); // L350 + } + } + } + } + } + } + } + return ; // L358 +} + +void node15( + float v204[128][256], + hls::stream v205[8][4] +) { // L360 + loop70: for (int v206 = 0; v206 < 32; v206++) { // L361 + loop71: for (int v207 = 0; v207 < 32; v207++) { // L362 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop72: for (int v208 = 0; v208 < 4; v208++) { // L363 + loop73: for (int v209 = 0; v209 < 8; v209++) { // L364 + float v210 = v204[(v208 + (v206 * 4))][(v209 + (v207 * 8))]; // L365 + v205[v209][v208].write(v210); // L366 + } + } + } + } + return ; // L371 +} + +void node16( + hls::stream v211[1][8], + float v212[256], + hls::stream v213[1][8], + float v214 +) { // L373 + loop74: for (int v215 = 0; v215 < 32; v215++) { // L374 + loop75: for (int v216 = 0; v216 < 32; v216++) { // L375 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v217 = 0; v217 < 1; v217++) { // L376 + loop77: for (int v218 = 0; v218 < 8; v218++) { // L377 + float v219 = v211[v217][v218].read(); // L378 + float v220 = v212[(v218 + (v216 * 8))]; // L379 + float v221 = v219 + v220; // L380 + bool v222 = v221 > v214; // L381 + float v223 = v222 ? (float)v221 : (float)v214; // L382 + v213[v217][v218].write(v223); // L383 + } + } + } + } + return ; // L388 +} + +void node17( + float v224[32][784], + hls::stream v225[28][8], + hls::stream v226[1][8], + float v227 +) { // L390 + float v228[32][256]; // L391 + float v229[784][256]; // L392 + loop78: for (int v230 = 0; v230 < 32; v230++) { // L393 + loop79: for (int v231 = 0; v231 < 32; v231++) { // L394 + loop80: for (int v232 = 0; v232 < 28; v232++) { // L395 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v233 = 0; v233 < 1; v233++) { // L396 + loop82: for (int v234 = 0; v234 < 8; v234++) { // L397 + loop83: for (int v235 = 0; v235 < 28; v235++) { // L398 + float v236 = v224[(v230 + v233)][(v235 + (v232 * 28))]; // L399 + if ((v230 + v233) == 0) { // L400 + float v237 = v225[v235][v234].read(); // L401 + v229[(v235 + (v232 * 28))][(v234 + (v231 * 8))] = v237; // L402 + } + float v238 = v229[(v235 + (v232 * 28))][(v234 + (v231 * 8))]; // L404 + if ((v235 + (v232 * 28)) == 0) { // L405 + v228[(v230 + v233)][(v234 + (v231 * 8))] = v227; // L406 + } + float v239 = v228[(v230 + v233)][(v234 + (v231 * 8))]; // L408 + float v240 = v236 * v238; // L409 + float v241 = v239 + v240; // L410 + v228[(v230 + v233)][(v234 + (v231 * 8))] = v241; // L411 + if (((v235 + (v232 * 28)) - 783) == 0) { // L412 + float v242 = v228[(v230 + v233)][(v234 + (v231 * 8))]; // L413 + v226[v233][v234].write(v242); // L414 + } + } + } + } + } + } + } + return ; // L422 +} + +void node18( + float v243[256][784], + hls::stream v244[28][8] +) { // L424 + loop84: for (int v245 = 0; v245 < 32; v245++) { // L425 + loop85: for (int v246 = 0; v246 < 28; v246++) { // L426 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v247 = 0; v247 < 8; v247++) { // L427 + loop87: for (int v248 = 0; v248 < 28; v248++) { // L428 + float v249 = v243[(v247 + (v245 * 8))][(v248 + (v246 * 28))]; // L429 + v244[v248][v247].write(v249); // L430 + } + } + } + } + return ; // L435 +} + +void forward( + float v250[32][784], + float v251[256], + float v252[256][784], + float v253[128], + float v254[128][256], + float v255[64], + float v256[64][128], + float v257[128], + float v258[128][64], + float v259[256], + float v260[256][128], + float v261[784], + float v262[784][256], + float v263[32][784] +) { // L437 + #pragma HLS DATAFLOW + hls::stream v264[1][49]; + #pragma HLS STREAM variable=v264 depth=512 // L440 + hls::stream v265[1][49]; + #pragma HLS STREAM variable=v265 depth=512 // L441 + hls::stream v266[4][49]; + #pragma HLS STREAM variable=v266 depth=1024 // L442 + hls::stream v267[1][4]; + #pragma HLS STREAM variable=v267 depth=2048 // L443 + hls::stream v268[1][4]; + #pragma HLS STREAM variable=v268 depth=2048 // L444 + hls::stream v269[8][4]; + #pragma HLS STREAM variable=v269 depth=1024 // L445 + hls::stream v270[1][8]; + #pragma HLS STREAM variable=v270 depth=512 // L446 + hls::stream v271[1][8]; + #pragma HLS STREAM variable=v271 depth=512 // L447 + hls::stream v272[2][8]; + #pragma HLS STREAM variable=v272 depth=512 // L448 + hls::stream v273[1][2]; + #pragma HLS STREAM variable=v273 depth=1024 // L449 + hls::stream v274[1][2]; + #pragma HLS STREAM variable=v274 depth=1024 // L450 + hls::stream v275[4][2]; + #pragma HLS STREAM variable=v275 depth=1024 // L451 + hls::stream v276[1][4]; + #pragma HLS STREAM variable=v276 depth=1024 // L452 + hls::stream v277[1][4]; + #pragma HLS STREAM variable=v277 depth=1024 // L453 + hls::stream v278[8][4]; + #pragma HLS STREAM variable=v278 depth=1024 // L454 + hls::stream v279[1][8]; + #pragma HLS STREAM variable=v279 depth=1024 // L455 + hls::stream v280[1][8]; + #pragma HLS STREAM variable=v280 depth=1024 // L456 + hls::stream v281[28][8]; + #pragma HLS STREAM variable=v281 depth=896 // L457 + node18(v252, v281); // L458 + node17(v250, v281, v280, 0.000000); // L459 + node16(v280, v251, v279, 0.000000); // L460 + node15(v254, v278); // L461 + node14(v278, v279, v277, 0.000000); // L462 + node13(v277, v253, v276, 0.000000); // L463 + node12(v256, v275); // L464 + node11(v276, v275, v274, 0.000000); // L465 + node10(v274, v255, v273); // L466 + node9(v258, v272); // L467 + node8(v272, v273, v271, 0.000000); // L468 + node7(v271, v257, v270, 0.000000); // L469 + node6(v260, v269); // L470 + node5(v270, v269, v268, 0.000000); // L471 + node4(v268, v259, v267, 0.000000); // L472 + node3(v262, v266); // L473 + node2(v267, v266, v265, 0.000000); // L474 + node1(v265, v261, v264, 1.000000); // L475 + node0(v264, v263); // L476 + return ; // L477 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt4/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt4/src/Autoencoder.cpp new file mode 100644 index 000000000000..6c24c5d09cf1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt4/src/Autoencoder.cpp @@ -0,0 +1,646 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][8], + float v1[32][784] +) { // L12 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L13 + loop1: for (int v3 = 0; v3 < 98; v3++) { // L14 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L15 + loop3: for (int v5 = 0; v5 < 8; v5++) { // L16 + float v6 = v0[v4][v5].read(); // L17 + v1[(v2 + v4)][(v5 + (v3 * 8))] = v6; // L18 + } + } + } + } + return ; // L23 +} + +void node1( + hls::stream v7[1][8], + float v8[784], + hls::stream v9[1][8], + float v10 +) { // L25 + loop4: for (int v11 = 0; v11 < 32; v11++) { // L26 + loop5: for (int v12 = 0; v12 < 98; v12++) { // L27 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 1; v13++) { // L28 + loop7: for (int v14 = 0; v14 < 8; v14++) { // L29 + float v15 = v7[v13][v14].read(); // L30 + float v16 = v8[(v14 + (v12 * 8))]; // L31 + float v17 = v15 + v16; // L32 + float v18 = -(v17); // L33 + float v19 = exp(v18); // L34 + float v20 = v19 + v10; // L35 + float v21 = v10 / v20; // L36 + v9[v13][v14].write(v21); // L37 + } + } + } + } + return ; // L42 +} + +void node2( + hls::stream v22[1][16], + float v23[256][784], + hls::stream v24[1][8], + float v25 +) { // L44 + float v26[32][784]; // L45 + float v27[256][784]; // L46 + float v28[32][256]; // L47 + loop8: for (int v29 = 0; v29 < 32; v29++) { // L48 + loop9: for (int v30 = 0; v30 < 16; v30++) { // L49 + loop10: for (int v31 = 0; v31 < 98; v31++) { // L50 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v32 = 0; v32 < 1; v32++) { // L51 + loop12: for (int v33 = 0; v33 < 16; v33++) { // L52 + loop13: for (int v34 = 0; v34 < 8; v34++) { // L53 + if ((v34 + (v31 * 8)) == 0) { // L54 + float v35 = v22[v32][v33].read(); // L55 + v28[(v29 + v32)][(v33 + (v30 * 16))] = v35; // L56 + } + float v36 = v28[(v29 + v32)][(v33 + (v30 * 16))]; // L58 + if ((v29 + v32) == 0) { // L59 + float v37 = v23[(v33 + (v30 * 16))][(v34 + (v31 * 8))]; // L60 + v27[(v33 + (v30 * 16))][(v34 + (v31 * 8))] = v37; // L61 + } + float v38 = v27[(v33 + (v30 * 16))][(v34 + (v31 * 8))]; // L63 + if ((v33 + (v30 * 16)) == 0) { // L64 + v26[(v29 + v32)][(v34 + (v31 * 8))] = v25; // L65 + } + float v39 = v26[(v29 + v32)][(v34 + (v31 * 8))]; // L67 + float v40 = v36 * v38; // L68 + float v41 = v39 + v40; // L69 + v26[(v29 + v32)][(v34 + (v31 * 8))] = v41; // L70 + if (((v33 + (v30 * 16)) - 255) == 0) { // L71 + float v42 = v26[(v29 + v32)][(v34 + (v31 * 8))]; // L72 + v24[v32][v34].write(v42); // L73 + } + } + } + } + } + } + } + return ; // L81 +} + +void node3( + float v43[784][256], + float v44[256][784] +) { // L83 + loop14: for (int v45 = 0; v45 < 98; v45++) { // L84 + loop15: for (int v46 = 0; v46 < 16; v46++) { // L85 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v47 = 0; v47 < 8; v47++) { // L86 + loop17: for (int v48 = 0; v48 < 16; v48++) { // L87 + float v49 = v43[(v47 + (v45 * 8))][(v48 + (v46 * 16))]; // L88 + v44[(v48 + (v46 * 16))][(v47 + (v45 * 8))] = v49; // L89 + } + } + } + } + return ; // L94 +} + +void node4( + hls::stream v50[1][16], + float v51[256], + hls::stream v52[1][16], + float v53 +) { // L96 + loop18: for (int v54 = 0; v54 < 32; v54++) { // L97 + loop19: for (int v55 = 0; v55 < 16; v55++) { // L98 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v56 = 0; v56 < 1; v56++) { // L99 + loop21: for (int v57 = 0; v57 < 16; v57++) { // L100 + float v58 = v50[v56][v57].read(); // L101 + float v59 = v51[(v57 + (v55 * 16))]; // L102 + float v60 = v58 + v59; // L103 + bool v61 = v60 > v53; // L104 + float v62 = v61 ? (float)v60 : (float)v53; // L105 + v52[v56][v57].write(v62); // L106 + } + } + } + } + return ; // L111 +} + +void node5( + hls::stream v63[1][8], + float v64[128][256], + hls::stream v65[1][16], + float v66 +) { // L113 + float v67[32][256]; // L114 + float v68[128][256]; // L115 + float v69[32][128]; // L116 + loop22: for (int v70 = 0; v70 < 32; v70++) { // L117 + loop23: for (int v71 = 0; v71 < 16; v71++) { // L118 + loop24: for (int v72 = 0; v72 < 16; v72++) { // L119 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 1; v73++) { // L120 + loop26: for (int v74 = 0; v74 < 16; v74++) { // L121 + loop27: for (int v75 = 0; v75 < 8; v75++) { // L122 + if ((v74 + (v71 * 16)) == 0) { // L123 + float v76 = v63[v73][v75].read(); // L124 + v69[(v70 + v73)][(v75 + (v72 * 8))] = v76; // L125 + } + float v77 = v69[(v70 + v73)][(v75 + (v72 * 8))]; // L127 + if ((v70 + v73) == 0) { // L128 + float v78 = v64[(v75 + (v72 * 8))][(v74 + (v71 * 16))]; // L129 + v68[(v75 + (v72 * 8))][(v74 + (v71 * 16))] = v78; // L130 + } + float v79 = v68[(v75 + (v72 * 8))][(v74 + (v71 * 16))]; // L132 + if ((v75 + (v72 * 8)) == 0) { // L133 + v67[(v70 + v73)][(v74 + (v71 * 16))] = v66; // L134 + } + float v80 = v67[(v70 + v73)][(v74 + (v71 * 16))]; // L136 + float v81 = v77 * v79; // L137 + float v82 = v80 + v81; // L138 + v67[(v70 + v73)][(v74 + (v71 * 16))] = v82; // L139 + if (((v75 + (v72 * 8)) - 127) == 0) { // L140 + float v83 = v67[(v70 + v73)][(v74 + (v71 * 16))]; // L141 + v65[v73][v74].write(v83); // L142 + } + } + } + } + } + } + } + return ; // L150 +} + +void node6( + float v84[256][128], + float v85[128][256] +) { // L152 + loop28: for (int v86 = 0; v86 < 16; v86++) { // L153 + loop29: for (int v87 = 0; v87 < 16; v87++) { // L154 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v88 = 0; v88 < 8; v88++) { // L155 + loop31: for (int v89 = 0; v89 < 16; v89++) { // L156 + float v90 = v84[(v89 + (v87 * 16))][(v88 + (v86 * 8))]; // L157 + v85[(v88 + (v86 * 8))][(v89 + (v87 * 16))] = v90; // L158 + } + } + } + } + return ; // L163 +} + +void node7( + hls::stream v91[1][8], + float v92[128], + hls::stream v93[1][8], + float v94 +) { // L165 + loop32: for (int v95 = 0; v95 < 32; v95++) { // L166 + loop33: for (int v96 = 0; v96 < 16; v96++) { // L167 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v97 = 0; v97 < 1; v97++) { // L168 + loop35: for (int v98 = 0; v98 < 8; v98++) { // L169 + float v99 = v91[v97][v98].read(); // L170 + float v100 = v92[(v98 + (v96 * 8))]; // L171 + float v101 = v99 + v100; // L172 + bool v102 = v101 > v94; // L173 + float v103 = v102 ? (float)v101 : (float)v94; // L174 + v93[v97][v98].write(v103); // L175 + } + } + } + } + return ; // L180 +} + +void node8( + hls::stream v104[1][4], + float v105[64][128], + hls::stream v106[1][8], + float v107 +) { // L182 + float v108[32][128]; // L183 + float v109[64][128]; // L184 + float v110[32][64]; // L185 + loop36: for (int v111 = 0; v111 < 32; v111++) { // L186 + loop37: for (int v112 = 0; v112 < 16; v112++) { // L187 + loop38: for (int v113 = 0; v113 < 16; v113++) { // L188 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v114 = 0; v114 < 1; v114++) { // L189 + loop40: for (int v115 = 0; v115 < 8; v115++) { // L190 + loop41: for (int v116 = 0; v116 < 4; v116++) { // L191 + if ((v115 + (v112 * 8)) == 0) { // L192 + float v117 = v104[v114][v116].read(); // L193 + v110[(v111 + v114)][(v116 + (v113 * 4))] = v117; // L194 + } + float v118 = v110[(v111 + v114)][(v116 + (v113 * 4))]; // L196 + if ((v111 + v114) == 0) { // L197 + float v119 = v105[(v116 + (v113 * 4))][(v115 + (v112 * 8))]; // L198 + v109[(v116 + (v113 * 4))][(v115 + (v112 * 8))] = v119; // L199 + } + float v120 = v109[(v116 + (v113 * 4))][(v115 + (v112 * 8))]; // L201 + if ((v116 + (v113 * 4)) == 0) { // L202 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v107; // L203 + } + float v121 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L205 + float v122 = v118 * v120; // L206 + float v123 = v121 + v122; // L207 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v123; // L208 + if (((v116 + (v113 * 4)) - 63) == 0) { // L209 + float v124 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L210 + v106[v114][v115].write(v124); // L211 + } + } + } + } + } + } + } + return ; // L219 +} + +void node9( + float v125[128][64], + float v126[64][128] +) { // L221 + loop42: for (int v127 = 0; v127 < 16; v127++) { // L222 + loop43: for (int v128 = 0; v128 < 16; v128++) { // L223 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v129 = 0; v129 < 4; v129++) { // L224 + loop45: for (int v130 = 0; v130 < 8; v130++) { // L225 + float v131 = v125[(v130 + (v128 * 8))][(v129 + (v127 * 4))]; // L226 + v126[(v129 + (v127 * 4))][(v130 + (v128 * 8))] = v131; // L227 + } + } + } + } + return ; // L232 +} + +void node10( + hls::stream v132[1][4], + float v133[64], + hls::stream v134[1][4] +) { // L234 + loop46: for (int v135 = 0; v135 < 32; v135++) { // L235 + loop47: for (int v136 = 0; v136 < 16; v136++) { // L236 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v137 = 0; v137 < 1; v137++) { // L237 + loop49: for (int v138 = 0; v138 < 4; v138++) { // L238 + float v139 = v132[v137][v138].read(); // L239 + float v140 = v133[(v138 + (v136 * 4))]; // L240 + float v141 = v139 + v140; // L241 + v134[v137][v138].write(v141); // L242 + } + } + } + } + return ; // L247 +} + +void node11( + hls::stream v142[1][8], + float v143[128][64], + hls::stream v144[1][4], + float v145 +) { // L249 + float v146[32][64]; // L250 + float v147[128][64]; // L251 + float v148[32][128]; // L252 + loop50: for (int v149 = 0; v149 < 32; v149++) { // L253 + loop51: for (int v150 = 0; v150 < 16; v150++) { // L254 + loop52: for (int v151 = 0; v151 < 16; v151++) { // L255 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v152 = 0; v152 < 1; v152++) { // L256 + loop54: for (int v153 = 0; v153 < 4; v153++) { // L257 + loop55: for (int v154 = 0; v154 < 8; v154++) { // L258 + if ((v153 + (v150 * 4)) == 0) { // L259 + float v155 = v142[v152][v154].read(); // L260 + v148[(v149 + v152)][(v154 + (v151 * 8))] = v155; // L261 + } + float v156 = v148[(v149 + v152)][(v154 + (v151 * 8))]; // L263 + if ((v149 + v152) == 0) { // L264 + float v157 = v143[(v154 + (v151 * 8))][(v153 + (v150 * 4))]; // L265 + v147[(v154 + (v151 * 8))][(v153 + (v150 * 4))] = v157; // L266 + } + float v158 = v147[(v154 + (v151 * 8))][(v153 + (v150 * 4))]; // L268 + if ((v154 + (v151 * 8)) == 0) { // L269 + v146[(v149 + v152)][(v153 + (v150 * 4))] = v145; // L270 + } + float v159 = v146[(v149 + v152)][(v153 + (v150 * 4))]; // L272 + float v160 = v156 * v158; // L273 + float v161 = v159 + v160; // L274 + v146[(v149 + v152)][(v153 + (v150 * 4))] = v161; // L275 + if (((v154 + (v151 * 8)) - 127) == 0) { // L276 + float v162 = v146[(v149 + v152)][(v153 + (v150 * 4))]; // L277 + v144[v152][v153].write(v162); // L278 + } + } + } + } + } + } + } + return ; // L286 +} + +void node12( + float v163[64][128], + float v164[128][64] +) { // L288 + loop56: for (int v165 = 0; v165 < 16; v165++) { // L289 + loop57: for (int v166 = 0; v166 < 16; v166++) { // L290 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop58: for (int v167 = 0; v167 < 8; v167++) { // L291 + loop59: for (int v168 = 0; v168 < 4; v168++) { // L292 + float v169 = v163[(v168 + (v166 * 4))][(v167 + (v165 * 8))]; // L293 + v164[(v167 + (v165 * 8))][(v168 + (v166 * 4))] = v169; // L294 + } + } + } + } + return ; // L299 +} + +void node13( + hls::stream v170[1][8], + float v171[128], + hls::stream v172[1][8], + float v173 +) { // L301 + loop60: for (int v174 = 0; v174 < 32; v174++) { // L302 + loop61: for (int v175 = 0; v175 < 16; v175++) { // L303 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v176 = 0; v176 < 1; v176++) { // L304 + loop63: for (int v177 = 0; v177 < 8; v177++) { // L305 + float v178 = v170[v176][v177].read(); // L306 + float v179 = v171[(v177 + (v175 * 8))]; // L307 + float v180 = v178 + v179; // L308 + bool v181 = v180 > v173; // L309 + float v182 = v181 ? (float)v180 : (float)v173; // L310 + v172[v176][v177].write(v182); // L311 + } + } + } + } + return ; // L316 +} + +void node14( + hls::stream v183[1][8], + hls::stream v184[8][8], + hls::stream v185[1][8], + float v186 +) { // L318 + float v187[32][128]; // L319 + float v188[256][128]; // L320 + float v189[32][256]; // L321 + loop64: for (int v190 = 0; v190 < 32; v190++) { // L322 + loop65: for (int v191 = 0; v191 < 32; v191++) { // L323 + loop66: for (int v192 = 0; v192 < 16; v192++) { // L324 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop67: for (int v193 = 0; v193 < 1; v193++) { // L325 + loop68: for (int v194 = 0; v194 < 8; v194++) { // L326 + loop69: for (int v195 = 0; v195 < 8; v195++) { // L327 + if ((v195 + (v192 * 8)) == 0) { // L328 + float v196 = v183[v193][v194].read(); // L329 + v189[(v190 + v193)][(v194 + (v191 * 8))] = v196; // L330 + } + float v197 = v189[(v190 + v193)][(v194 + (v191 * 8))]; // L332 + if ((v190 + v193) == 0) { // L333 + float v198 = v184[v194][v195].read(); // L334 + v188[(v194 + (v191 * 8))][(v195 + (v192 * 8))] = v198; // L335 + } + float v199 = v188[(v194 + (v191 * 8))][(v195 + (v192 * 8))]; // L337 + if ((v194 + (v191 * 8)) == 0) { // L338 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v186; // L339 + } + float v200 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L341 + float v201 = v197 * v199; // L342 + float v202 = v200 + v201; // L343 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v202; // L344 + if (((v194 + (v191 * 8)) - 255) == 0) { // L345 + float v203 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L346 + v185[v193][v195].write(v203); // L347 + } + } + } + } + } + } + } + return ; // L355 +} + +void node15( + float v204[128][256], + hls::stream v205[8][8] +) { // L357 + loop70: for (int v206 = 0; v206 < 32; v206++) { // L358 + loop71: for (int v207 = 0; v207 < 16; v207++) { // L359 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop72: for (int v208 = 0; v208 < 8; v208++) { // L360 + loop73: for (int v209 = 0; v209 < 8; v209++) { // L361 + float v210 = v204[(v209 + (v207 * 8))][(v208 + (v206 * 8))]; // L362 + v205[v208][v209].write(v210); // L363 + } + } + } + } + return ; // L368 +} + +void node16( + hls::stream v211[1][8], + float v212[256], + hls::stream v213[1][8], + float v214 +) { // L370 + loop74: for (int v215 = 0; v215 < 32; v215++) { // L371 + loop75: for (int v216 = 0; v216 < 32; v216++) { // L372 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v217 = 0; v217 < 1; v217++) { // L373 + loop77: for (int v218 = 0; v218 < 8; v218++) { // L374 + float v219 = v211[v217][v218].read(); // L375 + float v220 = v212[(v218 + (v216 * 8))]; // L376 + float v221 = v219 + v220; // L377 + bool v222 = v221 > v214; // L378 + float v223 = v222 ? (float)v221 : (float)v214; // L379 + v213[v217][v218].write(v223); // L380 + } + } + } + } + return ; // L385 +} + +void node17( + hls::stream v224[16][8], + float v225[32][784], + hls::stream v226[1][8], + float v227 +) { // L387 + float v228[32][256]; // L388 + float v229[784][256]; // L389 + loop78: for (int v230 = 0; v230 < 32; v230++) { // L390 + loop79: for (int v231 = 0; v231 < 49; v231++) { // L391 + loop80: for (int v232 = 0; v232 < 32; v232++) { // L392 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v233 = 0; v233 < 1; v233++) { // L393 + loop82: for (int v234 = 0; v234 < 16; v234++) { // L394 + loop83: for (int v235 = 0; v235 < 8; v235++) { // L395 + float v236 = v225[(v230 + v233)][(v234 + (v231 * 16))]; // L396 + if ((v230 + v233) == 0) { // L397 + float v237 = v224[v234][v235].read(); // L398 + v229[(v234 + (v231 * 16))][(v235 + (v232 * 8))] = v237; // L399 + } + float v238 = v229[(v234 + (v231 * 16))][(v235 + (v232 * 8))]; // L401 + if ((v234 + (v231 * 16)) == 0) { // L402 + v228[(v230 + v233)][(v235 + (v232 * 8))] = v227; // L403 + } + float v239 = v228[(v230 + v233)][(v235 + (v232 * 8))]; // L405 + float v240 = v236 * v238; // L406 + float v241 = v239 + v240; // L407 + v228[(v230 + v233)][(v235 + (v232 * 8))] = v241; // L408 + if (((v234 + (v231 * 16)) - 783) == 0) { // L409 + float v242 = v228[(v230 + v233)][(v235 + (v232 * 8))]; // L410 + v226[v233][v235].write(v242); // L411 + } + } + } + } + } + } + } + return ; // L419 +} + +void node18( + float v243[256][784], + hls::stream v244[16][8] +) { // L421 + loop84: for (int v245 = 0; v245 < 49; v245++) { // L422 + loop85: for (int v246 = 0; v246 < 32; v246++) { // L423 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v247 = 0; v247 < 16; v247++) { // L424 + loop87: for (int v248 = 0; v248 < 8; v248++) { // L425 + float v249 = v243[(v248 + (v246 * 8))][(v247 + (v245 * 16))]; // L426 + v244[v247][v248].write(v249); // L427 + } + } + } + } + return ; // L432 +} + +void forward( + float v250[32][784], + float v251[256], + float v252[256][784], + float v253[128], + float v254[128][256], + float v255[64], + float v256[64][128], + float v257[128], + float v258[128][64], + float v259[256], + float v260[256][128], + float v261[784], + float v262[784][256], + float v263[32][784] +) { // L434 + #pragma HLS DATAFLOW + hls::stream v264[1][8]; + #pragma HLS STREAM variable=v264 depth=3136 // L437 + hls::stream v265[1][8]; + #pragma HLS STREAM variable=v265 depth=3136 // L438 + float v266[256][784]; // L439 + hls::stream v267[1][16]; + #pragma HLS STREAM variable=v267 depth=512 // L440 + hls::stream v268[1][16]; + #pragma HLS STREAM variable=v268 depth=512 // L441 + float v269[128][256]; // L442 + hls::stream v270[1][8]; + #pragma HLS STREAM variable=v270 depth=512 // L443 + hls::stream v271[1][8]; + #pragma HLS STREAM variable=v271 depth=512 // L444 + float v272[64][128]; // L445 + hls::stream v273[1][4]; + #pragma HLS STREAM variable=v273 depth=512 // L446 + hls::stream v274[1][4]; + #pragma HLS STREAM variable=v274 depth=512 // L447 + float v275[128][64]; // L448 + hls::stream v276[1][8]; + #pragma HLS STREAM variable=v276 depth=512 // L449 + hls::stream v277[1][8]; + #pragma HLS STREAM variable=v277 depth=512 // L450 + hls::stream v278[8][8]; + #pragma HLS STREAM variable=v278 depth=512 // L451 + hls::stream v279[1][8]; + #pragma HLS STREAM variable=v279 depth=1024 // L452 + hls::stream v280[1][8]; + #pragma HLS STREAM variable=v280 depth=1024 // L453 + hls::stream v281[16][8]; + #pragma HLS STREAM variable=v281 depth=1568 // L454 + node18(v252, v281); // L455 + node17(v281, v250, v280, 0.000000); // L456 + node16(v280, v251, v279, 0.000000); // L457 + node15(v254, v278); // L458 + node14(v279, v278, v277, 0.000000); // L459 + node13(v277, v253, v276, 0.000000); // L460 + node12(v256, v275); // L461 + node11(v276, v275, v274, 0.000000); // L462 + node10(v274, v255, v273); // L463 + node9(v258, v272); // L464 + node8(v273, v272, v271, 0.000000); // L465 + node7(v271, v257, v270, 0.000000); // L466 + node6(v260, v269); // L467 + node5(v270, v269, v268, 0.000000); // L468 + node4(v268, v259, v267, 0.000000); // L469 + node3(v262, v266); // L470 + node2(v267, v266, v265, 0.000000); // L471 + node1(v265, v261, v264, 1.000000); // L472 + node0(v264, v263); // L473 + return ; // L474 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt5/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt5/src/Autoencoder.cpp new file mode 100644 index 000000000000..b61ee43fc768 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/Autoencoder__opt5/src/Autoencoder.cpp @@ -0,0 +1,738 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][28], + float v1[32][784] +) { // L34 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=28 + + loop0: for (int v2 = 0; v2 < 32; v2++) { // L35 + loop1: for (int v3 = 0; v3 < 28; v3++) { // L36 + #pragma HLS pipeline II=1 + loop2: for (int v4 = 0; v4 < 1; v4++) { // L37 + loop3: for (int v5 = 0; v5 < 28; v5++) { // L38 + float v6 = v0[v4][v5].read(); // L39 + v1[(v2 + v4)][(v5 + (v3 * 28))] = v6; // L40 + } + } + } + } + return ; // L45 +} + +void node1( + hls::stream v7[1][28], + float v8[784], + hls::stream v9[1][28], + float v10 +) { // L47 + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=28 + + loop4: for (int v11 = 0; v11 < 32; v11++) { // L48 + loop5: for (int v12 = 0; v12 < 28; v12++) { // L49 + #pragma HLS pipeline II=1 + loop6: for (int v13 = 0; v13 < 1; v13++) { // L50 + loop7: for (int v14 = 0; v14 < 28; v14++) { // L51 + float v15 = v7[v13][v14].read(); // L52 + float v16 = v8[(v14 + (v12 * 28))]; // L53 + float v17 = v15 + v16; // L54 + float v18 = -(v17); // L55 + float v19 = exp(v18); // L56 + float v20 = v19 + v10; // L57 + float v21 = v10 / v20; // L58 + v9[v13][v14].write(v21); // L59 + } + } + } + } + return ; // L64 +} + +void node2( + hls::stream v22[1][8], + float v23[256][784], + hls::stream v24[1][28], + float v25 +) { // L66 + float v26[32][784]; // L67 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=28 + + float v27[256][784]; // L68 + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=28 + + float v28[32][256]; // L69 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=8 + + loop8: for (int v29 = 0; v29 < 32; v29++) { // L70 + loop9: for (int v30 = 0; v30 < 32; v30++) { // L71 + loop10: for (int v31 = 0; v31 < 28; v31++) { // L72 + #pragma HLS pipeline II=1 + loop11: for (int v32 = 0; v32 < 1; v32++) { // L73 + loop12: for (int v33 = 0; v33 < 8; v33++) { // L74 + loop13: for (int v34 = 0; v34 < 28; v34++) { // L75 + if ((v34 + (v31 * 28)) == 0) { // L76 + float v35 = v22[v32][v33].read(); // L77 + v28[(v29 + v32)][(v33 + (v30 * 8))] = v35; // L78 + } + float v36 = v28[(v29 + v32)][(v33 + (v30 * 8))]; // L80 + if ((v29 + v32) == 0) { // L81 + float v37 = v23[(v33 + (v30 * 8))][(v34 + (v31 * 28))]; // L82 + v27[(v33 + (v30 * 8))][(v34 + (v31 * 28))] = v37; // L83 + } + float v38 = v27[(v33 + (v30 * 8))][(v34 + (v31 * 28))]; // L85 + if ((v33 + (v30 * 8)) == 0) { // L86 + v26[(v29 + v32)][(v34 + (v31 * 28))] = v25; // L87 + } + float v39 = v26[(v29 + v32)][(v34 + (v31 * 28))]; // L89 + float v40 = v36 * v38; // L90 + float v41 = v39 + v40; // L91 + v26[(v29 + v32)][(v34 + (v31 * 28))] = v41; // L92 + if (((v33 + (v30 * 8)) - 255) == 0) { // L93 + float v42 = v26[(v29 + v32)][(v34 + (v31 * 28))]; // L94 + v24[v32][v34].write(v42); // L95 + } + } + } + } + } + } + } + return ; // L103 +} + +void node3( + float v43[784][256], + float v44[256][784] +) { // L105 + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=28 + #pragma HLS array_partition variable=v43 cyclic dim=2 factor=8 + + loop14: for (int v45 = 0; v45 < 28; v45++) { // L106 + loop15: for (int v46 = 0; v46 < 32; v46++) { // L107 + #pragma HLS pipeline II=1 + loop16: for (int v47 = 0; v47 < 28; v47++) { // L108 + loop17: for (int v48 = 0; v48 < 8; v48++) { // L109 + float v49 = v43[(v47 + (v45 * 28))][(v48 + (v46 * 8))]; // L110 + v44[(v48 + (v46 * 8))][(v47 + (v45 * 28))] = v49; // L111 + } + } + } + } + return ; // L116 +} + +void node4( + hls::stream v50[1][8], + float v51[256], + hls::stream v52[1][8], + float v53 +) { // L118 + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=8 + + loop18: for (int v54 = 0; v54 < 32; v54++) { // L119 + loop19: for (int v55 = 0; v55 < 32; v55++) { // L120 + #pragma HLS pipeline II=1 + loop20: for (int v56 = 0; v56 < 1; v56++) { // L121 + loop21: for (int v57 = 0; v57 < 8; v57++) { // L122 + float v58 = v50[v56][v57].read(); // L123 + float v59 = v51[(v57 + (v55 * 8))]; // L124 + float v60 = v58 + v59; // L125 + bool v61 = v60 > v53; // L126 + float v62 = v61 ? (float)v60 : (float)v53; // L127 + v52[v56][v57].write(v62); // L128 + } + } + } + } + return ; // L133 +} + +void node5( + hls::stream v63[1][4], + hls::stream v64[4][8], + hls::stream v65[1][8], + float v66 +) { // L135 + float v67[32][256]; // L136 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=8 + + float v68[128][256]; // L137 + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=8 + + float v69[32][128]; // L138 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 32; v70++) { // L139 + loop23: for (int v71 = 0; v71 < 32; v71++) { // L140 + loop24: for (int v72 = 0; v72 < 32; v72++) { // L141 + #pragma HLS pipeline II=1 + loop25: for (int v73 = 0; v73 < 1; v73++) { // L142 + loop26: for (int v74 = 0; v74 < 4; v74++) { // L143 + loop27: for (int v75 = 0; v75 < 8; v75++) { // L144 + if ((v75 + (v72 * 8)) == 0) { // L145 + float v76 = v63[v73][v74].read(); // L146 + v69[(v70 + v73)][(v74 + (v71 * 4))] = v76; // L147 + } + float v77 = v69[(v70 + v73)][(v74 + (v71 * 4))]; // L149 + if ((v70 + v73) == 0) { // L150 + float v78 = v64[v74][v75].read(); // L151 + v68[(v74 + (v71 * 4))][(v75 + (v72 * 8))] = v78; // L152 + } + float v79 = v68[(v74 + (v71 * 4))][(v75 + (v72 * 8))]; // L154 + if ((v74 + (v71 * 4)) == 0) { // L155 + v67[(v70 + v73)][(v75 + (v72 * 8))] = v66; // L156 + } + float v80 = v67[(v70 + v73)][(v75 + (v72 * 8))]; // L158 + float v81 = v77 * v79; // L159 + float v82 = v80 + v81; // L160 + v67[(v70 + v73)][(v75 + (v72 * 8))] = v82; // L161 + if (((v74 + (v71 * 4)) - 127) == 0) { // L162 + float v83 = v67[(v70 + v73)][(v75 + (v72 * 8))]; // L163 + v65[v73][v75].write(v83); // L164 + } + } + } + } + } + } + } + return ; // L172 +} + +void node6( + float v84[256][128], + hls::stream v85[4][8] +) { // L174 + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + loop28: for (int v86 = 0; v86 < 32; v86++) { // L175 + loop29: for (int v87 = 0; v87 < 32; v87++) { // L176 + #pragma HLS pipeline II=1 + loop30: for (int v88 = 0; v88 < 4; v88++) { // L177 + loop31: for (int v89 = 0; v89 < 8; v89++) { // L178 + float v90 = v84[(v89 + (v87 * 8))][(v88 + (v86 * 4))]; // L179 + v85[v88][v89].write(v90); // L180 + } + } + } + } + return ; // L185 +} + +void node7( + hls::stream v91[1][4], + float v92[128], + hls::stream v93[1][4], + float v94 +) { // L187 + #pragma HLS array_partition variable=v92 cyclic dim=1 factor=4 + + loop32: for (int v95 = 0; v95 < 32; v95++) { // L188 + loop33: for (int v96 = 0; v96 < 32; v96++) { // L189 + #pragma HLS pipeline II=1 + loop34: for (int v97 = 0; v97 < 1; v97++) { // L190 + loop35: for (int v98 = 0; v98 < 4; v98++) { // L191 + float v99 = v91[v97][v98].read(); // L192 + float v100 = v92[(v98 + (v96 * 4))]; // L193 + float v101 = v99 + v100; // L194 + bool v102 = v101 > v94; // L195 + float v103 = v102 ? (float)v101 : (float)v94; // L196 + v93[v97][v98].write(v103); // L197 + } + } + } + } + return ; // L202 +} + +void node8( + hls::stream v104[1][2], + hls::stream v105[2][4], + hls::stream v106[1][4], + float v107 +) { // L204 + float v108[32][128]; // L205 + #pragma HLS array_partition variable=v108 cyclic dim=2 factor=4 + + float v109[64][128]; // L206 + #pragma HLS array_partition variable=v109 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v109 cyclic dim=2 factor=4 + + float v110[32][64]; // L207 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=2 + + loop36: for (int v111 = 0; v111 < 32; v111++) { // L208 + loop37: for (int v112 = 0; v112 < 32; v112++) { // L209 + loop38: for (int v113 = 0; v113 < 32; v113++) { // L210 + #pragma HLS pipeline II=1 + loop39: for (int v114 = 0; v114 < 1; v114++) { // L211 + loop40: for (int v115 = 0; v115 < 2; v115++) { // L212 + loop41: for (int v116 = 0; v116 < 4; v116++) { // L213 + if ((v116 + (v113 * 4)) == 0) { // L214 + float v117 = v104[v114][v115].read(); // L215 + v110[(v111 + v114)][(v115 + (v112 * 2))] = v117; // L216 + } + float v118 = v110[(v111 + v114)][(v115 + (v112 * 2))]; // L218 + if ((v111 + v114) == 0) { // L219 + float v119 = v105[v115][v116].read(); // L220 + v109[(v115 + (v112 * 2))][(v116 + (v113 * 4))] = v119; // L221 + } + float v120 = v109[(v115 + (v112 * 2))][(v116 + (v113 * 4))]; // L223 + if ((v115 + (v112 * 2)) == 0) { // L224 + v108[(v111 + v114)][(v116 + (v113 * 4))] = v107; // L225 + } + float v121 = v108[(v111 + v114)][(v116 + (v113 * 4))]; // L227 + float v122 = v118 * v120; // L228 + float v123 = v121 + v122; // L229 + v108[(v111 + v114)][(v116 + (v113 * 4))] = v123; // L230 + if (((v115 + (v112 * 2)) - 63) == 0) { // L231 + float v124 = v108[(v111 + v114)][(v116 + (v113 * 4))]; // L232 + v106[v114][v116].write(v124); // L233 + } + } + } + } + } + } + } + return ; // L241 +} + +void node9( + float v125[128][64], + hls::stream v126[2][4] +) { // L243 + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=2 + + loop42: for (int v127 = 0; v127 < 32; v127++) { // L244 + loop43: for (int v128 = 0; v128 < 32; v128++) { // L245 + #pragma HLS pipeline II=1 + loop44: for (int v129 = 0; v129 < 2; v129++) { // L246 + loop45: for (int v130 = 0; v130 < 4; v130++) { // L247 + float v131 = v125[(v130 + (v128 * 4))][(v129 + (v127 * 2))]; // L248 + v126[v129][v130].write(v131); // L249 + } + } + } + } + return ; // L254 +} + +void node10( + hls::stream v132[1][2], + float v133[64], + hls::stream v134[1][2] +) { // L256 + #pragma HLS array_partition variable=v133 cyclic dim=1 factor=2 + + loop46: for (int v135 = 0; v135 < 32; v135++) { // L257 + loop47: for (int v136 = 0; v136 < 32; v136++) { // L258 + #pragma HLS pipeline II=1 + loop48: for (int v137 = 0; v137 < 1; v137++) { // L259 + loop49: for (int v138 = 0; v138 < 2; v138++) { // L260 + float v139 = v132[v137][v138].read(); // L261 + float v140 = v133[(v138 + (v136 * 2))]; // L262 + float v141 = v139 + v140; // L263 + v134[v137][v138].write(v141); // L264 + } + } + } + } + return ; // L269 +} + +void node11( + hls::stream v142[8][2], + hls::stream v143[1][8], + hls::stream v144[1][2], + float v145 +) { // L271 + float v146[32][64]; // L272 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=2 + + float v147[128][64]; // L273 + #pragma HLS array_partition variable=v147 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v147 cyclic dim=2 factor=2 + + float v148[32][128]; // L274 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=8 + + loop50: for (int v149 = 0; v149 < 32; v149++) { // L275 + loop51: for (int v150 = 0; v150 < 16; v150++) { // L276 + loop52: for (int v151 = 0; v151 < 32; v151++) { // L277 + #pragma HLS pipeline II=1 + loop53: for (int v152 = 0; v152 < 1; v152++) { // L278 + loop54: for (int v153 = 0; v153 < 8; v153++) { // L279 + loop55: for (int v154 = 0; v154 < 2; v154++) { // L280 + if ((v154 + (v151 * 2)) == 0) { // L281 + float v155 = v143[v152][v153].read(); // L282 + v148[(v149 + v152)][(v153 + (v150 * 8))] = v155; // L283 + } + float v156 = v148[(v149 + v152)][(v153 + (v150 * 8))]; // L285 + if ((v149 + v152) == 0) { // L286 + float v157 = v142[v153][v154].read(); // L287 + v147[(v153 + (v150 * 8))][(v154 + (v151 * 2))] = v157; // L288 + } + float v158 = v147[(v153 + (v150 * 8))][(v154 + (v151 * 2))]; // L290 + if ((v153 + (v150 * 8)) == 0) { // L291 + v146[(v149 + v152)][(v154 + (v151 * 2))] = v145; // L292 + } + float v159 = v146[(v149 + v152)][(v154 + (v151 * 2))]; // L294 + float v160 = v156 * v158; // L295 + float v161 = v159 + v160; // L296 + v146[(v149 + v152)][(v154 + (v151 * 2))] = v161; // L297 + if (((v153 + (v150 * 8)) - 127) == 0) { // L298 + float v162 = v146[(v149 + v152)][(v154 + (v151 * 2))]; // L299 + v144[v152][v154].write(v162); // L300 + } + } + } + } + } + } + } + return ; // L308 +} + +void node12( + float v163[64][128], + hls::stream v164[8][2] +) { // L310 + #pragma HLS array_partition variable=v163 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v163 cyclic dim=2 factor=8 + + loop56: for (int v165 = 0; v165 < 16; v165++) { // L311 + loop57: for (int v166 = 0; v166 < 32; v166++) { // L312 + #pragma HLS pipeline II=1 + loop58: for (int v167 = 0; v167 < 8; v167++) { // L313 + loop59: for (int v168 = 0; v168 < 2; v168++) { // L314 + float v169 = v163[(v168 + (v166 * 2))][(v167 + (v165 * 8))]; // L315 + v164[v167][v168].write(v169); // L316 + } + } + } + } + return ; // L321 +} + +void node13( + hls::stream v170[1][8], + float v171[128], + hls::stream v172[1][8], + float v173 +) { // L323 + #pragma HLS array_partition variable=v171 cyclic dim=1 factor=8 + + loop60: for (int v174 = 0; v174 < 32; v174++) { // L324 + loop61: for (int v175 = 0; v175 < 16; v175++) { // L325 + #pragma HLS pipeline II=1 + loop62: for (int v176 = 0; v176 < 1; v176++) { // L326 + loop63: for (int v177 = 0; v177 < 8; v177++) { // L327 + float v178 = v170[v176][v177].read(); // L328 + float v179 = v171[(v177 + (v175 * 8))]; // L329 + float v180 = v178 + v179; // L330 + bool v181 = v180 > v173; // L331 + float v182 = v181 ? (float)v180 : (float)v173; // L332 + v172[v176][v177].write(v182); // L333 + } + } + } + } + return ; // L338 +} + +void node14( + hls::stream v183[1][4], + hls::stream v184[4][8], + hls::stream v185[1][8], + float v186 +) { // L340 + float v187[32][128]; // L341 + #pragma HLS array_partition variable=v187 cyclic dim=2 factor=8 + + float v188[256][128]; // L342 + #pragma HLS array_partition variable=v188 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v188 cyclic dim=2 factor=8 + + float v189[32][256]; // L343 + #pragma HLS array_partition variable=v189 cyclic dim=2 factor=4 + + loop64: for (int v190 = 0; v190 < 32; v190++) { // L344 + loop65: for (int v191 = 0; v191 < 64; v191++) { // L345 + loop66: for (int v192 = 0; v192 < 16; v192++) { // L346 + #pragma HLS pipeline II=1 + loop67: for (int v193 = 0; v193 < 1; v193++) { // L347 + loop68: for (int v194 = 0; v194 < 4; v194++) { // L348 + loop69: for (int v195 = 0; v195 < 8; v195++) { // L349 + if ((v195 + (v192 * 8)) == 0) { // L350 + float v196 = v183[v193][v194].read(); // L351 + v189[(v190 + v193)][(v194 + (v191 * 4))] = v196; // L352 + } + float v197 = v189[(v190 + v193)][(v194 + (v191 * 4))]; // L354 + if ((v190 + v193) == 0) { // L355 + float v198 = v184[v194][v195].read(); // L356 + v188[(v194 + (v191 * 4))][(v195 + (v192 * 8))] = v198; // L357 + } + float v199 = v188[(v194 + (v191 * 4))][(v195 + (v192 * 8))]; // L359 + if ((v194 + (v191 * 4)) == 0) { // L360 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v186; // L361 + } + float v200 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L363 + float v201 = v197 * v199; // L364 + float v202 = v200 + v201; // L365 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v202; // L366 + if (((v194 + (v191 * 4)) - 255) == 0) { // L367 + float v203 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L368 + v185[v193][v195].write(v203); // L369 + } + } + } + } + } + } + } + return ; // L377 +} + +void node15( + float v204[128][256], + hls::stream v205[4][8] +) { // L379 + #pragma HLS array_partition variable=v204 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v204 cyclic dim=2 factor=4 + + loop70: for (int v206 = 0; v206 < 64; v206++) { // L380 + loop71: for (int v207 = 0; v207 < 16; v207++) { // L381 + #pragma HLS pipeline II=1 + loop72: for (int v208 = 0; v208 < 4; v208++) { // L382 + loop73: for (int v209 = 0; v209 < 8; v209++) { // L383 + float v210 = v204[(v209 + (v207 * 8))][(v208 + (v206 * 4))]; // L384 + v205[v208][v209].write(v210); // L385 + } + } + } + } + return ; // L390 +} + +void node16( + hls::stream v211[1][4], + float v212[256], + hls::stream v213[1][4], + float v214 +) { // L392 + #pragma HLS array_partition variable=v212 cyclic dim=1 factor=4 + + loop74: for (int v215 = 0; v215 < 32; v215++) { // L393 + loop75: for (int v216 = 0; v216 < 64; v216++) { // L394 + #pragma HLS pipeline II=1 + loop76: for (int v217 = 0; v217 < 1; v217++) { // L395 + loop77: for (int v218 = 0; v218 < 4; v218++) { // L396 + float v219 = v211[v217][v218].read(); // L397 + float v220 = v212[(v218 + (v216 * 4))]; // L398 + float v221 = v219 + v220; // L399 + bool v222 = v221 > v214; // L400 + float v223 = v222 ? (float)v221 : (float)v214; // L401 + v213[v217][v218].write(v223); // L402 + } + } + } + } + return ; // L407 +} + +void node17( + hls::stream v224[49][4], + float v225[32][784], + hls::stream v226[1][4], + float v227 +) { // L409 + #pragma HLS array_partition variable=v225 cyclic dim=2 factor=49 + + float v228[32][256]; // L410 + #pragma HLS array_partition variable=v228 cyclic dim=2 factor=4 + + float v229[784][256]; // L411 + #pragma HLS array_partition variable=v229 cyclic dim=1 factor=49 + #pragma HLS array_partition variable=v229 cyclic dim=2 factor=4 + + loop78: for (int v230 = 0; v230 < 32; v230++) { // L412 + loop79: for (int v231 = 0; v231 < 16; v231++) { // L413 + loop80: for (int v232 = 0; v232 < 64; v232++) { // L414 + #pragma HLS pipeline II=1 + loop81: for (int v233 = 0; v233 < 1; v233++) { // L415 + loop82: for (int v234 = 0; v234 < 49; v234++) { // L416 + loop83: for (int v235 = 0; v235 < 4; v235++) { // L417 + float v236 = v225[(v230 + v233)][(v234 + (v231 * 49))]; // L418 + if ((v230 + v233) == 0) { // L419 + float v237 = v224[v234][v235].read(); // L420 + v229[(v234 + (v231 * 49))][(v235 + (v232 * 4))] = v237; // L421 + } + float v238 = v229[(v234 + (v231 * 49))][(v235 + (v232 * 4))]; // L423 + if ((v234 + (v231 * 49)) == 0) { // L424 + v228[(v230 + v233)][(v235 + (v232 * 4))] = v227; // L425 + } + float v239 = v228[(v230 + v233)][(v235 + (v232 * 4))]; // L427 + float v240 = v236 * v238; // L428 + float v241 = v239 + v240; // L429 + v228[(v230 + v233)][(v235 + (v232 * 4))] = v241; // L430 + if (((v234 + (v231 * 49)) - 783) == 0) { // L431 + float v242 = v228[(v230 + v233)][(v235 + (v232 * 4))]; // L432 + v226[v233][v235].write(v242); // L433 + } + } + } + } + } + } + } + return ; // L441 +} + +void node18( + float v243[256][784], + hls::stream v244[49][4] +) { // L443 + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v243 cyclic dim=2 factor=49 + + loop84: for (int v245 = 0; v245 < 16; v245++) { // L444 + loop85: for (int v246 = 0; v246 < 64; v246++) { // L445 + #pragma HLS pipeline II=1 + loop86: for (int v247 = 0; v247 < 49; v247++) { // L446 + loop87: for (int v248 = 0; v248 < 4; v248++) { // L447 + float v249 = v243[(v248 + (v246 * 4))][(v247 + (v245 * 49))]; // L448 + v244[v247][v248].write(v249); // L449 + } + } + } + } + return ; // L454 +} + +void forward( + float v250[32][784], + float v251[256], + float v252[256][784], + float v253[128], + float v254[128][256], + float v255[64], + float v256[64][128], + float v257[128], + float v258[128][64], + float v259[256], + float v260[256][128], + float v261[784], + float v262[784][256], + float v263[32][784] +) { // L456 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v250 cyclic dim=2 factor=49 + + #pragma HLS array_partition variable=v251 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=49 + + #pragma HLS array_partition variable=v253 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v254 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v254 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v255 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v259 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v260 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v260 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v261 cyclic dim=1 factor=28 + + #pragma HLS array_partition variable=v262 cyclic dim=1 factor=28 + #pragma HLS array_partition variable=v262 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v263 cyclic dim=2 factor=28 + + hls::stream v264[1][28]; + #pragma HLS STREAM variable=v264 depth=896 // L459 + hls::stream v265[1][28]; + #pragma HLS STREAM variable=v265 depth=896 // L460 + float v266[256][784]; // L461 + hls::stream v267[1][8]; + #pragma HLS STREAM variable=v267 depth=1024 // L462 + hls::stream v268[1][8]; + #pragma HLS STREAM variable=v268 depth=1024 // L463 + hls::stream v269[4][8]; + #pragma HLS STREAM variable=v269 depth=1024 // L464 + hls::stream v270[1][4]; + #pragma HLS STREAM variable=v270 depth=1024 // L465 + hls::stream v271[1][4]; + #pragma HLS STREAM variable=v271 depth=1024 // L466 + hls::stream v272[2][4]; + #pragma HLS STREAM variable=v272 depth=1024 // L467 + hls::stream v273[1][2]; + #pragma HLS STREAM variable=v273 depth=1024 // L468 + hls::stream v274[1][2]; + #pragma HLS STREAM variable=v274 depth=1024 // L469 + hls::stream v275[8][2]; + #pragma HLS STREAM variable=v275 depth=512 // L470 + hls::stream v276[1][8]; + #pragma HLS STREAM variable=v276 depth=512 // L471 + hls::stream v277[1][8]; + #pragma HLS STREAM variable=v277 depth=512 // L472 + hls::stream v278[4][8]; + #pragma HLS STREAM variable=v278 depth=1024 // L473 + hls::stream v279[1][4]; + #pragma HLS STREAM variable=v279 depth=2048 // L474 + hls::stream v280[1][4]; + #pragma HLS STREAM variable=v280 depth=2048 // L475 + hls::stream v281[49][4]; + #pragma HLS STREAM variable=v281 depth=1024 // L476 + node18(v252, v281); // L477 + node17(v281, v250, v280, 0.000000); // L478 + node16(v280, v251, v279, 0.000000); // L479 + node15(v254, v278); // L480 + node14(v279, v278, v277, 0.000000); // L481 + node13(v277, v253, v276, 0.000000); // L482 + node12(v256, v275); // L483 + node11(v275, v276, v274, 0.000000); // L484 + node10(v274, v255, v273); // L485 + node9(v258, v272); // L486 + node8(v273, v272, v271, 0.000000); // L487 + node7(v271, v257, v270, 0.000000); // L488 + node6(v260, v269); // L489 + node5(v270, v269, v268, 0.000000); // L490 + node4(v268, v259, v267, 0.000000); // L491 + node3(v262, v266); // L492 + node2(v267, v266, v265, 0.000000); // L493 + node1(v265, v261, v264, 1.000000); // L494 + node0(v264, v263); // L495 + return ; // L496 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..19dc1c101858 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,134 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { + #pragma HLS DATAFLOW + float v4[8][114][114]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 114; v6++) { + loop2: for (int v7 = 0; v7 < 114; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + v4[v5][v6][v7] = 0.000000; + } + } + } + loop3: for (int v8 = 0; v8 < 8; v8++) { + loop4: for (int v9 = 0; v9 < 112; v9++) { + loop5: for (int v10 = 0; v10 < 112; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v0[0][v8][v9][v10]; + v4[v8][(v9 + 1)][(v10 + 1)] = v11; + } + } + } + float v12[8][112][112]; + hls::stream v13("fifo_0"); + #pragma HLS STREAM variable=v13 depth=100352 + float v14[8][112][112]; + loop6: for (int v15 = 0; v15 < 112; v15++) { + loop7: for (int v16 = 0; v16 < 112; v16++) { + loop8: for (int v17 = 0; v17 < 8; v17++) { + loop9: for (int v18 = 0; v18 < 3; v18++) { + loop10: for (int v19 = 0; v19 < 3; v19++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v20 = v4[v17][(v15 + v18)][(v16 + v19)]; + float v21 = v2[v17][v18][v19]; + if (v18 == 0 && v19 == 0) { + v12[v17][v15][v16] = 0.000000; + } + float v22 = v12[v17][v15][v16]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v12[v17][v15][v16] = v24; + if ((v18 - 2) == 0 && (v19 - 2) == 0) { + float v25 = v12[v17][v15][v16]; + v13.write(v25); + } + } + } + } + } + } + float v26[8][112][112]; + hls::stream v27("fifo_1"); + #pragma HLS STREAM variable=v27 depth=100352 + loop11: for (int v28 = 0; v28 < 8; v28++) { + loop12: for (int v29 = 0; v29 < 112; v29++) { + loop13: for (int v30 = 0; v30 < 112; v30++) { + loop14: for (int v31 = 0; v31 < 8; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v28 == 0) { + float v32 = v13.read(); + v14[v31][v29][v30] = v32; + } + float v33 = v14[v31][v29][v30]; + float v34 = v1[v28][v31][0][0]; + if (v31 == 0) { + v26[v28][v29][v30] = 0.000000; + } + float v35 = v26[v28][v29][v30]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[v28][v29][v30] = v37; + if ((v31 - 7) == 0) { + float v38 = v26[v28][v29][v30]; + v27.write(v38); + } + } + } + } + } + hls::stream v39("fifo_2"); + #pragma HLS STREAM variable=v39 depth=100352 + loop15: for (int v40 = 0; v40 < 8; v40++) { + loop16: for (int v41 = 0; v41 < 112; v41++) { + loop17: for (int v42 = 0; v42 < 112; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v43 = v27.read(); + float v44 = 0.000010; + float v45 = v44 + 1.000000; + float v46 = 1.0 / sqrt(v45); + float v47 = v43 * v46; + float v48 = v47 + 0.000000; + bool v49 = v48 > 0.000000; + float v50 = v49 ? (float)v48 : (float)0.000000; + v39.write(v50); + } + } + } + loop18: for (int v51 = 0; v51 < 8; v51++) { + loop19: for (int v52 = 0; v52 < 112; v52++) { + loop20: for (int v53 = 0; v53 < 112; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v54 = v39.read(); + v3[0][v51][v52][v53] = v54; + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..c2c68b8366f0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,189 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][8][112][112] +) { // L8 + loop0: for (int v2 = 0; v2 < 112; v2++) { // L9 + loop1: for (int v3 = 0; v3 < 112; v3++) { // L10 + loop2: for (int v4 = 0; v4 < 8; v4++) { // L11 + #pragma HLS pipeline II=1 + float v5 = v0.read(); // L12 + v1[0][v4][v3][v2] = v5; // L13 + } + } + } + return ; // L17 +} + +void node1( + hls::stream &v6, + hls::stream &v7, + double v8, + float v9, + float v10 +) { // L19 + loop3: for (int v11 = 0; v11 < 112; v11++) { // L20 + loop4: for (int v12 = 0; v12 < 112; v12++) { // L21 + loop5: for (int v13 = 0; v13 < 8; v13++) { // L22 + #pragma HLS pipeline II=1 + float v14 = v6.read(); // L23 + float v15 = v8; // L24 + float v16 = v15 + v9; // L25 + float v17 = 1.0 / sqrt(v16); // L26 + float v18 = v14 * v17; // L27 + float v19 = v18 + v10; // L28 + bool v20 = v19 > v10; // L29 + float v21 = v20 ? (float)v19 : (float)v10; // L30 + v7.write(v21); // L31 + } + } + } + return ; // L35 +} + +void node2( + hls::stream &v22, + float v23[8][8][1][1], + hls::stream &v24, + float v25 +) { // L37 + float v26[8]; // L38 + float v27; // L39 + loop6: for (int v28 = 0; v28 < 112; v28++) { // L40 + loop7: for (int v29 = 0; v29 < 112; v29++) { // L41 + loop8: for (int v30 = 0; v30 < 8; v30++) { // L42 + loop9: for (int v31 = 0; v31 < 8; v31++) { // L43 + #pragma HLS pipeline II=1 + if (v31 == 0) { // L44 + float v32 = v22.read(); // L45 + v27 = v32; // L46 + } + float v33 = v27; // L48 + float v34 = v23[v31][v30][0][0]; // L49 + if (v30 == 0) { // L50 + v26[v31] = v25; // L51 + } + float v35 = v26[v31]; // L53 + float v36 = v33 * v34; // L54 + float v37 = v35 + v36; // L55 + v26[v31] = v37; // L56 + if ((v30 - 7) == 0) { // L57 + float v38 = v26[v31]; // L58 + v24.write(v38); // L59 + } + } + } + } + } + return ; // L65 +} + +void node3( + float v39[8][3][3], + hls::stream &v40, + hls::stream &v41, + float v42 +) { // L67 + float v43[8]; // L68 + float v44[8][114][114]; // L69 + loop10: for (int v45 = 0; v45 < 114; v45++) { // L70 + loop11: for (int v46 = 0; v46 < 114; v46++) { // L71 + loop12: for (int v47 = 0; v47 < 3; v47++) { // L72 + loop13: for (int v48 = 0; v48 < 3; v48++) { // L73 + loop14: for (int v49 = 0; v49 < 8; v49++) { // L74 + #pragma HLS pipeline II=1 + if (v48 == 0 && v47 == 0) { // L75 + float v50 = v40.read(); // L76 + v44[v49][v46][v45] = v50; // L77 + } + if ((v46 - 2) >= 0 && (v45 - 2) >= 0) { // L79 + float v51 = v44[v49][((v48 + v46) - 2)][((v47 + v45) - 2)]; // L80 + float v52 = v39[v49][v48][v47]; // L81 + if (v48 == 0 && v47 == 0) { // L82 + v43[v49] = v42; // L83 + } + float v53 = v43[v49]; // L85 + float v54 = v51 * v52; // L86 + float v55 = v53 + v54; // L87 + v43[v49] = v55; // L88 + if ((v48 - 2) == 0 && (v47 - 2) == 0) { // L89 + float v56 = v43[v49]; // L90 + v41.write(v56); // L91 + } + } + } + } + } + } + } + return ; // L99 +} + +void node4( + float v57[1][8][112][112], + hls::stream &v58, + float v59 +) { // L101 + float v60[8][114][114]; // L102 + loop15: for (int v61 = 0; v61 < 114; v61++) { // L103 + loop16: for (int v62 = 0; v62 < 114; v62++) { // L104 + loop17: for (int v63 = 0; v63 < 8; v63++) { // L105 + #pragma HLS pipeline II=1 + v60[v63][v62][v61] = v59; // L106 + } + } + } + loop18: for (int v64 = 0; v64 < 114; v64++) { // L110 + loop19: for (int v65 = 0; v65 < 114; v65++) { // L111 + loop20: for (int v66 = 0; v66 < 8; v66++) { // L112 + #pragma HLS pipeline II=1 + if ((v65 - 1) >= 0 && (v64 - 1) >= 0 && ((-v65) + 112) >= 0 && ((-v64) + 112) >= 0) { // L113 + float v67 = v57[0][v66][(v65 - 1)][(v64 - 1)]; // L114 + v60[v66][v65][v64] = v67; // L115 + } + float v68 = v60[v66][v65][v64]; // L117 + v58.write(v68); // L118 + } + } + } + return ; // L122 +} + +void forward( + float v69[1][8][112][112], + float v70[8][8][1][1], + float v71[8][3][3], + float v72[1][8][112][112] +) { // L124 + #pragma HLS DATAFLOW + hls::stream v73("fifo_0"); + #pragma HLS STREAM variable=v73 depth=100352 // L128 + hls::stream v74("fifo_1"); + #pragma HLS STREAM variable=v74 depth=100352 // L129 + hls::stream v75("fifo_2"); + #pragma HLS STREAM variable=v75 depth=100352 // L130 + hls::stream v76("fifo_3"); + #pragma HLS STREAM variable=v76 depth=103968 // L131 + node4(v69, v76, 0.000000); // L132 + node3(v71, v76, v75, 0.000000); // L133 + node2(v75, v70, v74, 0.000000); // L134 + node1(v74, v73, 0.000010, 1.000000, 0.000000); // L135 + node0(v73, v72); // L136 + return ; // L137 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..1d82348ce6a2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,181 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { // L9 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=14 + + float v4[8][114][114]; // L13 + loop0: for (int v5 = 0; v5 < 8; v5++) { // L14 + loop1: for (int v6 = 0; v6 < 57; v6++) { // L15 + loop2: for (int v7 = 0; v7 < 114; v7++) { // L16 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 1; v8++) { // L17 + loop4: for (int v9 = 0; v9 < 2; v9++) { // L18 + loop5: for (int v10 = 0; v10 < 1; v10++) { // L19 + v4[(v5 + v8)][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; // L20 + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { // L27 + loop7: for (int v12 = 0; v12 < 56; v12++) { // L28 + loop8: for (int v13 = 0; v13 < 112; v13++) { // L29 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 1; v14++) { // L30 + loop10: for (int v15 = 0; v15 < 2; v15++) { // L31 + loop11: for (int v16 = 0; v16 < 1; v16++) { // L32 + float v17 = v0[0][(v11 + v14)][(v15 + (v12 * 2))][(v13 + v16)]; // L33 + v4[(v11 + v14)][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; // L34 + } + } + } + } + } + } + float v18[8][112][112]; // L41 + hls::stream v19[1][2][14]; + #pragma HLS STREAM variable=v19 depth=3584 // L42 + float v20[8][112][112]; // L43 + loop12: for (int v21 = 0; v21 < 56; v21++) { // L44 + loop13: for (int v22 = 0; v22 < 8; v22++) { // L45 + loop14: for (int v23 = 0; v23 < 8; v23++) { // L46 + loop15: for (int v24 = 0; v24 < 3; v24++) { // L47 + loop16: for (int v25 = 0; v25 < 3; v25++) { // L48 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v26 = 0; v26 < 2; v26++) { // L49 + loop18: for (int v27 = 0; v27 < 14; v27++) { // L50 + loop19: for (int v28 = 0; v28 < 1; v28++) { // L51 + loop20: for (int v29 = 0; v29 < 1; v29++) { // L52 + loop21: for (int v30 = 0; v30 < 1; v30++) { // L53 + float v31 = v4[(v23 + v28)][(((v26 + (v21 * 2)) + v24) + v29)][(((v27 + (v22 * 14)) + v25) + v30)]; // L54 + float v32 = v2[(v23 + v28)][(v24 + v29)][(v25 + v30)]; // L55 + if ((v24 + v29) == 0 && (v25 + v30) == 0) { // L56 + v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = 0.000000; // L57 + } + float v33 = v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; // L59 + float v34 = v31 * v32; // L60 + float v35 = v33 + v34; // L61 + v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = v35; // L62 + if (((v24 + v29) - 2) == 0 && ((v25 + v30) - 2) == 0) { // L63 + float v36 = v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; // L64 + v19[v28][v26][v27].write(v36); // L65 + } + } + } + } + } + } + } + } + } + } + } + float v37[8][112][112]; // L77 + hls::stream v38[1][2][14]; + #pragma HLS STREAM variable=v38 depth=3584 // L78 + loop22: for (int v39 = 0; v39 < 8; v39++) { // L79 + loop23: for (int v40 = 0; v40 < 56; v40++) { // L80 + loop24: for (int v41 = 0; v41 < 8; v41++) { // L81 + loop25: for (int v42 = 0; v42 < 8; v42++) { // L82 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v43 = 0; v43 < 1; v43++) { // L83 + loop27: for (int v44 = 0; v44 < 2; v44++) { // L84 + loop28: for (int v45 = 0; v45 < 14; v45++) { // L85 + loop29: for (int v46 = 0; v46 < 1; v46++) { // L86 + if ((v39 + v43) == 0) { // L87 + float v47 = v19[v46][v44][v45].read(); // L88 + v20[(v42 + v46)][(v44 + (v40 * 2))][(v45 + (v41 * 14))] = v47; // L89 + } + float v48 = v20[(v42 + v46)][(v44 + (v40 * 2))][(v45 + (v41 * 14))]; // L91 + float v49 = v1[(v39 + v43)][(v42 + v46)][0][0]; // L92 + if ((v42 + v46) == 0) { // L93 + v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))] = 0.000000; // L94 + } + float v50 = v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))]; // L96 + float v51 = v48 * v49; // L97 + float v52 = v50 + v51; // L98 + v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))] = v52; // L99 + if (((v42 + v46) - 7) == 0) { // L100 + float v53 = v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))]; // L101 + v38[v43][v44][v45].write(v53); // L102 + } + } + } + } + } + } + } + } + } + hls::stream v54[1][2][14]; + #pragma HLS STREAM variable=v54 depth=3584 // L112 + loop30: for (int v55 = 0; v55 < 8; v55++) { // L113 + loop31: for (int v56 = 0; v56 < 56; v56++) { // L114 + loop32: for (int v57 = 0; v57 < 8; v57++) { // L115 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v58 = 0; v58 < 1; v58++) { // L116 + loop34: for (int v59 = 0; v59 < 2; v59++) { // L117 + loop35: for (int v60 = 0; v60 < 14; v60++) { // L118 + float v61 = v38[v58][v59][v60].read(); // L119 + float v62 = 0.000010; // L120 + float v63 = v62 + 1.000000; // L121 + float v64 = 1.0 / sqrt(v63); // L122 + float v65 = v61 * v64; // L123 + float v66 = v65 + 0.000000; // L124 + bool v67 = v66 > 0.000000; // L125 + float v68 = v67 ? (float)v66 : (float)0.000000; // L126 + v54[v58][v59][v60].write(v68); // L127 + } + } + } + } + } + } + loop36: for (int v69 = 0; v69 < 8; v69++) { // L134 + loop37: for (int v70 = 0; v70 < 56; v70++) { // L135 + loop38: for (int v71 = 0; v71 < 8; v71++) { // L136 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v72 = 0; v72 < 1; v72++) { // L137 + loop40: for (int v73 = 0; v73 < 2; v73++) { // L138 + loop41: for (int v74 = 0; v74 < 14; v74++) { // L139 + float v75 = v54[v72][v73][v74].read(); // L140 + v3[0][(v69 + v72)][(v73 + (v70 * 2))][(v74 + (v71 * 14))] = v75; // L141 + } + } + } + } + } + } + return ; // L148 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..51a45b21d296 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,181 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=14 + + float v4[8][114][114]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 57; v6++) { + loop2: for (int v7 = 0; v7 < 114; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 1; v8++) { + loop4: for (int v9 = 0; v9 < 2; v9++) { + loop5: for (int v10 = 0; v10 < 1; v10++) { + v4[(v5 + v8)][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 56; v12++) { + loop8: for (int v13 = 0; v13 < 112; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 1; v14++) { + loop10: for (int v15 = 0; v15 < 2; v15++) { + loop11: for (int v16 = 0; v16 < 1; v16++) { + float v17 = v0[0][(v11 + v14)][(v15 + (v12 * 2))][(v13 + v16)]; + v4[(v11 + v14)][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; + } + } + } + } + } + } + float v18[8][112][112]; + hls::stream v19[1][2][14]; + #pragma HLS STREAM variable=v19 depth=3584 + float v20[8][112][112]; + loop12: for (int v21 = 0; v21 < 56; v21++) { + loop13: for (int v22 = 0; v22 < 8; v22++) { + loop14: for (int v23 = 0; v23 < 3; v23++) { + loop15: for (int v24 = 0; v24 < 3; v24++) { + loop16: for (int v25 = 0; v25 < 8; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v26 = 0; v26 < 2; v26++) { + loop18: for (int v27 = 0; v27 < 14; v27++) { + loop19: for (int v28 = 0; v28 < 1; v28++) { + loop20: for (int v29 = 0; v29 < 1; v29++) { + loop21: for (int v30 = 0; v30 < 1; v30++) { + float v31 = v4[(v25 + v30)][(((v26 + (v21 * 2)) + v23) + v28)][(((v27 + (v22 * 14)) + v24) + v29)]; + float v32 = v2[(v25 + v30)][(v23 + v28)][(v24 + v29)]; + if ((v23 + v28) == 0 && (v24 + v29) == 0) { + v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = 0.000000; + } + float v33 = v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = v35; + if (((v23 + v28) - 2) == 0 && ((v24 + v29) - 2) == 0) { + float v36 = v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; + v19[v30][v26][v27].write(v36); + } + } + } + } + } + } + } + } + } + } + } + float v37[8][112][112]; + hls::stream v38[1][2][14]; + #pragma HLS STREAM variable=v38 depth=3584 + loop22: for (int v39 = 0; v39 < 56; v39++) { + loop23: for (int v40 = 0; v40 < 8; v40++) { + loop24: for (int v41 = 0; v41 < 8; v41++) { + loop25: for (int v42 = 0; v42 < 8; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v43 = 0; v43 < 2; v43++) { + loop27: for (int v44 = 0; v44 < 14; v44++) { + loop28: for (int v45 = 0; v45 < 1; v45++) { + loop29: for (int v46 = 0; v46 < 1; v46++) { + if ((v42 + v46) == 0) { + float v47 = v19[v45][v43][v44].read(); + v20[(v41 + v45)][(v43 + (v39 * 2))][(v44 + (v40 * 14))] = v47; + } + float v48 = v20[(v41 + v45)][(v43 + (v39 * 2))][(v44 + (v40 * 14))]; + float v49 = v1[(v42 + v46)][(v41 + v45)][0][0]; + if ((v41 + v45) == 0) { + v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))] = 0.000000; + } + float v50 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))]; + float v51 = v48 * v49; + float v52 = v50 + v51; + v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))] = v52; + if (((v41 + v45) - 7) == 0) { + float v53 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))]; + v38[v46][v43][v44].write(v53); + } + } + } + } + } + } + } + } + } + hls::stream v54[1][2][14]; + #pragma HLS STREAM variable=v54 depth=3584 + loop30: for (int v55 = 0; v55 < 56; v55++) { + loop31: for (int v56 = 0; v56 < 8; v56++) { + loop32: for (int v57 = 0; v57 < 8; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v58 = 0; v58 < 2; v58++) { + loop34: for (int v59 = 0; v59 < 14; v59++) { + loop35: for (int v60 = 0; v60 < 1; v60++) { + float v61 = v38[v60][v58][v59].read(); + float v62 = 0.000010; + float v63 = v62 + 1.000000; + float v64 = 1.0 / sqrt(v63); + float v65 = v61 * v64; + float v66 = v65 + 0.000000; + bool v67 = v66 > 0.000000; + float v68 = v67 ? (float)v66 : (float)0.000000; + v54[v60][v58][v59].write(v68); + } + } + } + } + } + } + loop36: for (int v69 = 0; v69 < 56; v69++) { + loop37: for (int v70 = 0; v70 < 8; v70++) { + loop38: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v72 = 0; v72 < 2; v72++) { + loop40: for (int v73 = 0; v73 < 14; v73++) { + loop41: for (int v74 = 0; v74 < 1; v74++) { + float v75 = v54[v74][v72][v73].read(); + v3[0][(v71 + v74)][(v72 + (v69 * 2))][(v73 + (v70 * 14))] = v75; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..be65bca88fda --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,181 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=14 + + float v4[8][114][114]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 57; v6++) { + loop2: for (int v7 = 0; v7 < 114; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 1; v8++) { + loop4: for (int v9 = 0; v9 < 2; v9++) { + loop5: for (int v10 = 0; v10 < 1; v10++) { + v4[(v5 + v8)][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 56; v12++) { + loop8: for (int v13 = 0; v13 < 112; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 1; v14++) { + loop10: for (int v15 = 0; v15 < 2; v15++) { + loop11: for (int v16 = 0; v16 < 1; v16++) { + float v17 = v0[0][(v11 + v14)][(v15 + (v12 * 2))][(v13 + v16)]; + v4[(v11 + v14)][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; + } + } + } + } + } + } + float v18[8][112][112]; + hls::stream v19[1][2][14]; + #pragma HLS STREAM variable=v19 depth=3584 + float v20[8][112][112]; + loop12: for (int v21 = 0; v21 < 56; v21++) { + loop13: for (int v22 = 0; v22 < 8; v22++) { + loop14: for (int v23 = 0; v23 < 3; v23++) { + loop15: for (int v24 = 0; v24 < 3; v24++) { + loop16: for (int v25 = 0; v25 < 8; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v26 = 0; v26 < 2; v26++) { + loop18: for (int v27 = 0; v27 < 1; v27++) { + loop19: for (int v28 = 0; v28 < 1; v28++) { + loop20: for (int v29 = 0; v29 < 1; v29++) { + loop21: for (int v30 = 0; v30 < 14; v30++) { + float v31 = v4[(v22 + v27)][(((v26 + (v21 * 2)) + v23) + v28)][(((v30 + (v25 * 14)) + v24) + v29)]; + float v32 = v2[(v22 + v27)][(v23 + v28)][(v24 + v29)]; + if ((v23 + v28) == 0 && (v24 + v29) == 0) { + v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))] = 0.000000; + } + float v33 = v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))] = v35; + if (((v23 + v28) - 2) == 0 && ((v24 + v29) - 2) == 0) { + float v36 = v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))]; + v19[v27][v26][v30].write(v36); + } + } + } + } + } + } + } + } + } + } + } + float v37[8][112][112]; + hls::stream v38[1][2][14]; + #pragma HLS STREAM variable=v38 depth=3584 + loop22: for (int v39 = 0; v39 < 56; v39++) { + loop23: for (int v40 = 0; v40 < 8; v40++) { + loop24: for (int v41 = 0; v41 < 8; v41++) { + loop25: for (int v42 = 0; v42 < 8; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v43 = 0; v43 < 2; v43++) { + loop27: for (int v44 = 0; v44 < 1; v44++) { + loop28: for (int v45 = 0; v45 < 14; v45++) { + loop29: for (int v46 = 0; v46 < 1; v46++) { + if ((v42 + v46) == 0) { + float v47 = v19[v44][v43][v45].read(); + v20[(v40 + v44)][(v43 + (v39 * 2))][(v45 + (v41 * 14))] = v47; + } + float v48 = v20[(v40 + v44)][(v43 + (v39 * 2))][(v45 + (v41 * 14))]; + float v49 = v1[(v42 + v46)][(v40 + v44)][0][0]; + if ((v40 + v44) == 0) { + v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))] = 0.000000; + } + float v50 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))]; + float v51 = v48 * v49; + float v52 = v50 + v51; + v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))] = v52; + if (((v40 + v44) - 7) == 0) { + float v53 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))]; + v38[v46][v43][v45].write(v53); + } + } + } + } + } + } + } + } + } + hls::stream v54[1][2][14]; + #pragma HLS STREAM variable=v54 depth=3584 + loop30: for (int v55 = 0; v55 < 56; v55++) { + loop31: for (int v56 = 0; v56 < 8; v56++) { + loop32: for (int v57 = 0; v57 < 8; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v58 = 0; v58 < 2; v58++) { + loop34: for (int v59 = 0; v59 < 14; v59++) { + loop35: for (int v60 = 0; v60 < 1; v60++) { + float v61 = v38[v60][v58][v59].read(); + float v62 = 0.000010; + float v63 = v62 + 1.000000; + float v64 = 1.0 / sqrt(v63); + float v65 = v61 * v64; + float v66 = v65 + 0.000000; + bool v67 = v66 > 0.000000; + float v68 = v67 ? (float)v66 : (float)0.000000; + v54[v60][v58][v59].write(v68); + } + } + } + } + } + } + loop36: for (int v69 = 0; v69 < 56; v69++) { + loop37: for (int v70 = 0; v70 < 8; v70++) { + loop38: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v72 = 0; v72 < 2; v72++) { + loop40: for (int v73 = 0; v73 < 14; v73++) { + loop41: for (int v74 = 0; v74 < 1; v74++) { + float v75 = v54[v74][v72][v73].read(); + v3[0][(v71 + v74)][(v72 + (v69 * 2))][(v73 + (v70 * 14))] = v75; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt1/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt1/src/FeedForward.cpp new file mode 100644 index 000000000000..b25856f045e0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt1/src/FeedForward.cpp @@ -0,0 +1,229 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][512][128] +) { + loop0: for (int v2 = 0; v2 < 512; v2++) { + loop1: for (int v3 = 0; v3 < 128; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 512; v8++) { + loop3: for (int v9 = 0; v9 < 128; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v9]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + hls::stream &v13, + float v14[256][128], + hls::stream &v15, + float v16 +) { + float v17[512][128]; + float v18[256][128]; + float v19[512][256]; + loop4: for (int v20 = 0; v20 < 512; v20++) { + loop5: for (int v21 = 0; v21 < 128; v21++) { + loop6: for (int v22 = 0; v22 < 256; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v21 == 0) { + float v23 = v13.read(); + v19[v20][v22] = v23; + } + float v24 = v19[v20][v22]; + if (v20 == 0) { + float v25 = v14[v22][v21]; + v18[v22][v21] = v25; + } + float v26 = v18[v22][v21]; + if (v22 == 0) { + v17[v20][v21] = v16; + } + float v27 = v17[v20][v21]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v20][v21] = v29; + if ((v22 - 255) == 0) { + float v30 = v17[v20][v21]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][256], + float v32[256][128] +) { + loop7: for (int v33 = 0; v33 < 256; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32[v33][v34] = v35; + } + } + return ; +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38, + float v39 +) { + loop9: for (int v40 = 0; v40 < 512; v40++) { + loop10: for (int v41 = 0; v41 < 256; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v36.read(); + float v43 = v37[v41]; + float v44 = v42 + v43; + bool v45 = v44 > v39; + float v46 = v45 ? (float)v44 : (float)v39; + v38.write(v46); + } + } + return ; +} + +void node5( + hls::stream &v47, + float v48[128][256], + hls::stream &v49, + float v50 +) { + float v51[512][256]; + float v52[128][256]; + float v53[512][128]; + loop11: for (int v54 = 0; v54 < 512; v54++) { + loop12: for (int v55 = 0; v55 < 256; v55++) { + loop13: for (int v56 = 0; v56 < 128; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v55 == 0) { + float v57 = v47.read(); + v53[v54][v56] = v57; + } + float v58 = v53[v54][v56]; + if (v54 == 0) { + float v59 = v48[v56][v55]; + v52[v56][v55] = v59; + } + float v60 = v52[v56][v55]; + if (v56 == 0) { + v51[v54][v55] = v50; + } + float v61 = v51[v54][v55]; + float v62 = v58 * v60; + float v63 = v61 + v62; + v51[v54][v55] = v63; + if ((v56 - 127) == 0) { + float v64 = v51[v54][v55]; + v49.write(v64); + } + } + } + } + return ; +} + +void node6( + float v65[256][128], + float v66[128][256] +) { + loop14: for (int v67 = 0; v67 < 128; v67++) { + loop15: for (int v68 = 0; v68 < 256; v68++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v69 = v65[v68][v67]; + v66[v67][v68] = v69; + } + } + return ; +} + +void node7( + float v70[1][512][128], + hls::stream &v71 +) { + loop16: for (int v72 = 0; v72 < 512; v72++) { + loop17: for (int v73 = 0; v73 < 128; v73++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[0][v72][v73]; + v71.write(v74); + } + } + return ; +} + +void forward( + float v75[1][512][128], + float v76[256], + float v77[256][128], + float v78[128], + float v79[128][256], + float v80[1][512][128] +) { + #pragma HLS DATAFLOW + hls::stream v81("fifo_0"); + #pragma HLS STREAM variable=v81 depth=65536 + hls::stream v82("fifo_1"); + #pragma HLS STREAM variable=v82 depth=65536 + float v83[256][128]; + hls::stream v84("fifo_2"); + #pragma HLS STREAM variable=v84 depth=131072 + hls::stream v85("fifo_3"); + #pragma HLS STREAM variable=v85 depth=131072 + float v86[128][256]; + hls::stream v87("fifo_4"); + #pragma HLS STREAM variable=v87 depth=65536 + node7(v75, v87); + node6(v77, v86); + node5(v87, v86, v85, 0.000000); + node4(v85, v76, v84, 0.000000); + node3(v79, v83); + node2(v84, v83, v82, 0.000000); + node1(v82, v78, v81); + node0(v81, v80); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt2/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt2/src/FeedForward.cpp new file mode 100644 index 000000000000..9240141cfa48 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt2/src/FeedForward.cpp @@ -0,0 +1,231 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][512][128] +) { + loop0: for (int v2 = 0; v2 < 512; v2++) { + loop1: for (int v3 = 0; v3 < 128; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 512; v8++) { + loop3: for (int v9 = 0; v9 < 128; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v9]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + hls::stream &v13, + hls::stream &v14, + hls::stream &v15, + float v16 +) { + float v17[512][128]; + float v18[256][128]; + float v19[512][256]; + loop4: for (int v20 = 0; v20 < 512; v20++) { + loop5: for (int v21 = 0; v21 < 256; v21++) { + loop6: for (int v22 = 0; v22 < 128; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v22 == 0) { + float v23 = v13.read(); + v19[v20][v21] = v23; + } + float v24 = v19[v20][v21]; + if (v20 == 0) { + float v25 = v14.read(); + v18[v21][v22] = v25; + } + float v26 = v18[v21][v22]; + if (v21 == 0) { + v17[v20][v22] = v16; + } + float v27 = v17[v20][v22]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v20][v22] = v29; + if ((v21 - 255) == 0) { + float v30 = v17[v20][v22]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][256], + hls::stream &v32 +) { + loop7: for (int v33 = 0; v33 < 256; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32.write(v35); + } + } + return ; +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38, + float v39 +) { + loop9: for (int v40 = 0; v40 < 512; v40++) { + loop10: for (int v41 = 0; v41 < 256; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v36.read(); + float v43 = v37[v41]; + float v44 = v42 + v43; + bool v45 = v44 > v39; + float v46 = v45 ? (float)v44 : (float)v39; + v38.write(v46); + } + } + return ; +} + +void node5( + hls::stream &v47, + hls::stream &v48, + hls::stream &v49, + float v50 +) { + float v51[512][256]; + float v52[128][256]; + float v53[512][128]; + loop11: for (int v54 = 0; v54 < 512; v54++) { + loop12: for (int v55 = 0; v55 < 128; v55++) { + loop13: for (int v56 = 0; v56 < 256; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v56 == 0) { + float v57 = v47.read(); + v53[v54][v55] = v57; + } + float v58 = v53[v54][v55]; + if (v54 == 0) { + float v59 = v48.read(); + v52[v55][v56] = v59; + } + float v60 = v52[v55][v56]; + if (v55 == 0) { + v51[v54][v56] = v50; + } + float v61 = v51[v54][v56]; + float v62 = v58 * v60; + float v63 = v61 + v62; + v51[v54][v56] = v63; + if ((v55 - 127) == 0) { + float v64 = v51[v54][v56]; + v49.write(v64); + } + } + } + } + return ; +} + +void node6( + float v65[256][128], + hls::stream &v66 +) { + loop14: for (int v67 = 0; v67 < 128; v67++) { + loop15: for (int v68 = 0; v68 < 256; v68++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v69 = v65[v68][v67]; + v66.write(v69); + } + } + return ; +} + +void node7( + float v70[1][512][128], + hls::stream &v71 +) { + loop16: for (int v72 = 0; v72 < 512; v72++) { + loop17: for (int v73 = 0; v73 < 128; v73++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[0][v72][v73]; + v71.write(v74); + } + } + return ; +} + +void forward( + float v75[1][512][128], + float v76[256], + float v77[256][128], + float v78[128], + float v79[128][256], + float v80[1][512][128] +) { + #pragma HLS DATAFLOW + hls::stream v81("fifo_0"); + #pragma HLS STREAM variable=v81 depth=65536 + hls::stream v82("fifo_1"); + #pragma HLS STREAM variable=v82 depth=65536 + hls::stream v83("fifo_2"); + #pragma HLS STREAM variable=v83 depth=32768 + hls::stream v84("fifo_3"); + #pragma HLS STREAM variable=v84 depth=131072 + hls::stream v85("fifo_4"); + #pragma HLS STREAM variable=v85 depth=131072 + hls::stream v86("fifo_5"); + #pragma HLS STREAM variable=v86 depth=32768 + hls::stream v87("fifo_6"); + #pragma HLS STREAM variable=v87 depth=65536 + node7(v75, v87); + node6(v77, v86); + node5(v87, v86, v85, 0.000000); + node4(v85, v76, v84, 0.000000); + node3(v79, v83); + node2(v84, v83, v82, 0.000000); + node1(v82, v78, v81); + node0(v81, v80); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt3/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt3/src/FeedForward.cpp new file mode 100644 index 000000000000..cd9bf2ad109e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt3/src/FeedForward.cpp @@ -0,0 +1,333 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][8], + float v1[1][512][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 256; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 2))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][8], + float v8[128], + hls::stream v9[2][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 256; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 2; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + float v17[256][128], + hls::stream v18[2][16], + hls::stream v19[2][8], + float v20 +) { + #pragma HLS array_partition variable=v17 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v17 cyclic dim=2 factor=8 + + float v21[512][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[256][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[512][256]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=16 + + loop8: for (int v24 = 0; v24 < 256; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 2; v27++) { + loop12: for (int v28 = 0; v28 < 8; v28++) { + loop13: for (int v29 = 0; v29 < 16; v29++) { + if ((v28 + (v25 * 8)) == 0) { + float v30 = v18[v27][v29].read(); + v23[(v27 + (v24 * 2))][(v29 + (v26 * 16))] = v30; + } + float v31 = v23[(v27 + (v24 * 2))][(v29 + (v26 * 16))]; + if ((v27 + (v24 * 2)) == 0) { + float v32 = v17[(v29 + (v26 * 16))][(v28 + (v25 * 8))]; + v22[(v29 + (v26 * 16))][(v28 + (v25 * 8))] = v32; + } + float v33 = v22[(v29 + (v26 * 16))][(v28 + (v25 * 8))]; + if ((v29 + (v26 * 16)) == 0) { + v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))] = v36; + if (((v29 + (v26 * 16)) - 255) == 0) { + float v37 = v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))]; + v19[v27][v28].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][256], + float v39[256][128] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=8 + + loop14: for (int v40 = 0; v40 < 16; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 16; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 16))]; + v39[(v42 + (v40 * 16))][(v43 + (v41 * 8))] = v44; + } + } + } + } + return ; +} + +void node4( + hls::stream v45[2][16], + float v46[256], + hls::stream v47[2][16], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=16 + + loop18: for (int v49 = 0; v49 < 256; v49++) { + loop19: for (int v50 = 0; v50 < 16; v50++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v51 = 0; v51 < 2; v51++) { + loop21: for (int v52 = 0; v52 < 16; v52++) { + float v53 = v45[v51][v52].read(); + float v54 = v46[(v52 + (v50 * 16))]; + float v55 = v53 + v54; + bool v56 = v55 > v48; + float v57 = v56 ? (float)v55 : (float)v48; + v47[v51][v52].write(v57); + } + } + } + } + return ; +} + +void node5( + float v58[128][256], + hls::stream v59[2][8], + hls::stream v60[2][16], + float v61 +) { + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=16 + + float v62[512][256]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=16 + + float v63[128][256]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=16 + + float v64[512][128]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop22: for (int v65 = 0; v65 < 256; v65++) { + loop23: for (int v66 = 0; v66 < 16; v66++) { + loop24: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v68 = 0; v68 < 2; v68++) { + loop26: for (int v69 = 0; v69 < 16; v69++) { + loop27: for (int v70 = 0; v70 < 8; v70++) { + if ((v69 + (v66 * 16)) == 0) { + float v71 = v59[v68][v70].read(); + v64[(v68 + (v65 * 2))][(v70 + (v67 * 8))] = v71; + } + float v72 = v64[(v68 + (v65 * 2))][(v70 + (v67 * 8))]; + if ((v68 + (v65 * 2)) == 0) { + float v73 = v58[(v70 + (v67 * 8))][(v69 + (v66 * 16))]; + v63[(v70 + (v67 * 8))][(v69 + (v66 * 16))] = v73; + } + float v74 = v63[(v70 + (v67 * 8))][(v69 + (v66 * 16))]; + if ((v70 + (v67 * 8)) == 0) { + v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))] = v61; + } + float v75 = v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))] = v77; + if (((v70 + (v67 * 8)) - 127) == 0) { + float v78 = v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))]; + v60[v68][v69].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v79[256][128], + float v80[128][256] +) { + #pragma HLS array_partition variable=v79 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v80 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v80 cyclic dim=2 factor=16 + + loop28: for (int v81 = 0; v81 < 16; v81++) { + loop29: for (int v82 = 0; v82 < 16; v82++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v83 = 0; v83 < 8; v83++) { + loop31: for (int v84 = 0; v84 < 16; v84++) { + float v85 = v79[(v84 + (v82 * 16))][(v83 + (v81 * 8))]; + v80[(v83 + (v81 * 8))][(v84 + (v82 * 16))] = v85; + } + } + } + } + return ; +} + +void node7( + float v86[1][512][128], + hls::stream v87[2][8] +) { + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v86 cyclic dim=3 factor=8 + + loop32: for (int v88 = 0; v88 < 256; v88++) { + loop33: for (int v89 = 0; v89 < 16; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 2; v90++) { + loop35: for (int v91 = 0; v91 < 8; v91++) { + float v92 = v86[0][(v90 + (v88 * 2))][(v91 + (v89 * 8))]; + v87[v90][v91].write(v92); + } + } + } + } + return ; +} + +void forward( + float v93[1][512][128], + float v94[256], + float v95[256][128], + float v96[128], + float v97[128][256], + float v98[1][512][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v93 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v94 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v95 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v95 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v97 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v98 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v98 cyclic dim=3 factor=8 + + hls::stream v99[2][8]; + #pragma HLS STREAM variable=v99 depth=4096 + hls::stream v100[2][8]; + #pragma HLS STREAM variable=v100 depth=4096 + float v101[256][128]; + #pragma HLS array_partition variable=v101 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v101 cyclic dim=2 factor=8 + + hls::stream v102[2][16]; + #pragma HLS STREAM variable=v102 depth=4096 + hls::stream v103[2][16]; + #pragma HLS STREAM variable=v103 depth=4096 + float v104[128][256]; + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=16 + + hls::stream v105[2][8]; + #pragma HLS STREAM variable=v105 depth=4096 + node7(v93, v105); + node6(v95, v104); + node5(v104, v105, v103, 0.000000); + node4(v103, v94, v102, 0.000000); + node3(v97, v101); + node2(v101, v102, v100, 0.000000); + node1(v100, v96, v99); + node0(v99, v98); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt4/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt4/src/FeedForward.cpp new file mode 100644 index 000000000000..649f30f37f9c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt4/src/FeedForward.cpp @@ -0,0 +1,317 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][8], + float v1[1][512][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 256; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 2))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][8], + float v8[128], + hls::stream v9[2][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 256; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 2; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[16][8], + hls::stream v18[2][16], + hls::stream v19[2][8], + float v20 +) { + float v21[512][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[256][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[512][256]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=16 + + loop8: for (int v24 = 0; v24 < 256; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 2; v27++) { + loop12: for (int v28 = 0; v28 < 16; v28++) { + loop13: for (int v29 = 0; v29 < 8; v29++) { + if ((v29 + (v26 * 8)) == 0) { + float v30 = v18[v27][v28].read(); + v23[(v27 + (v24 * 2))][(v28 + (v25 * 16))] = v30; + } + float v31 = v23[(v27 + (v24 * 2))][(v28 + (v25 * 16))]; + if ((v27 + (v24 * 2)) == 0) { + float v32 = v17[v28][v29].read(); + v22[(v28 + (v25 * 16))][(v29 + (v26 * 8))] = v32; + } + float v33 = v22[(v28 + (v25 * 16))][(v29 + (v26 * 8))]; + if ((v28 + (v25 * 16)) == 0) { + v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))] = v36; + if (((v28 + (v25 * 16)) - 255) == 0) { + float v37 = v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))]; + v19[v27][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][256], + hls::stream v39[16][8] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=16 + + loop14: for (int v40 = 0; v40 < 16; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 16; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 16))]; + v39[v42][v43].write(v44); + } + } + } + } + return ; +} + +void node4( + hls::stream v45[2][16], + float v46[256], + hls::stream v47[2][16], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=16 + + loop18: for (int v49 = 0; v49 < 256; v49++) { + loop19: for (int v50 = 0; v50 < 16; v50++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v51 = 0; v51 < 2; v51++) { + loop21: for (int v52 = 0; v52 < 16; v52++) { + float v53 = v45[v51][v52].read(); + float v54 = v46[(v52 + (v50 * 16))]; + float v55 = v53 + v54; + bool v56 = v55 > v48; + float v57 = v56 ? (float)v55 : (float)v48; + v47[v51][v52].write(v57); + } + } + } + } + return ; +} + +void node5( + hls::stream v58[8][16], + hls::stream v59[2][8], + hls::stream v60[2][16], + float v61 +) { + float v62[512][256]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=16 + + float v63[128][256]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=16 + + float v64[512][128]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop22: for (int v65 = 0; v65 < 256; v65++) { + loop23: for (int v66 = 0; v66 < 16; v66++) { + loop24: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v68 = 0; v68 < 2; v68++) { + loop26: for (int v69 = 0; v69 < 8; v69++) { + loop27: for (int v70 = 0; v70 < 16; v70++) { + if ((v70 + (v67 * 16)) == 0) { + float v71 = v59[v68][v69].read(); + v64[(v68 + (v65 * 2))][(v69 + (v66 * 8))] = v71; + } + float v72 = v64[(v68 + (v65 * 2))][(v69 + (v66 * 8))]; + if ((v68 + (v65 * 2)) == 0) { + float v73 = v58[v69][v70].read(); + v63[(v69 + (v66 * 8))][(v70 + (v67 * 16))] = v73; + } + float v74 = v63[(v69 + (v66 * 8))][(v70 + (v67 * 16))]; + if ((v69 + (v66 * 8)) == 0) { + v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))] = v61; + } + float v75 = v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))] = v77; + if (((v69 + (v66 * 8)) - 127) == 0) { + float v78 = v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))]; + v60[v68][v70].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v79[256][128], + hls::stream v80[8][16] +) { + #pragma HLS array_partition variable=v79 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=8 + + loop28: for (int v81 = 0; v81 < 16; v81++) { + loop29: for (int v82 = 0; v82 < 16; v82++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v83 = 0; v83 < 8; v83++) { + loop31: for (int v84 = 0; v84 < 16; v84++) { + float v85 = v79[(v84 + (v82 * 16))][(v83 + (v81 * 8))]; + v80[v83][v84].write(v85); + } + } + } + } + return ; +} + +void node7( + float v86[1][512][128], + hls::stream v87[2][8] +) { + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v86 cyclic dim=3 factor=8 + + loop32: for (int v88 = 0; v88 < 256; v88++) { + loop33: for (int v89 = 0; v89 < 16; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 2; v90++) { + loop35: for (int v91 = 0; v91 < 8; v91++) { + float v92 = v86[0][(v90 + (v88 * 2))][(v91 + (v89 * 8))]; + v87[v90][v91].write(v92); + } + } + } + } + return ; +} + +void forward( + float v93[1][512][128], + float v94[256], + float v95[256][128], + float v96[128], + float v97[128][256], + float v98[1][512][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v93 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v94 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v95 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v95 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v97 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v98 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v98 cyclic dim=3 factor=8 + + hls::stream v99[2][8]; + #pragma HLS STREAM variable=v99 depth=4096 + hls::stream v100[2][8]; + #pragma HLS STREAM variable=v100 depth=4096 + hls::stream v101[16][8]; + #pragma HLS STREAM variable=v101 depth=256 + hls::stream v102[2][16]; + #pragma HLS STREAM variable=v102 depth=4096 + hls::stream v103[2][16]; + #pragma HLS STREAM variable=v103 depth=4096 + hls::stream v104[8][16]; + #pragma HLS STREAM variable=v104 depth=256 + hls::stream v105[2][8]; + #pragma HLS STREAM variable=v105 depth=4096 + node7(v93, v105); + node6(v95, v104); + node5(v104, v105, v103, 0.000000); + node4(v103, v94, v102, 0.000000); + node3(v97, v101); + node2(v101, v102, v100, 0.000000); + node1(v100, v96, v99); + node0(v99, v98); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt5/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt5/src/FeedForward.cpp new file mode 100644 index 000000000000..a3d637e285b4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/FeedForward__opt5/src/FeedForward.cpp @@ -0,0 +1,305 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[32][8], + float v1[1][512][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 32; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 32))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[32][8], + float v8[128], + hls::stream v9[32][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 16; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 32; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[1][8], + hls::stream v18[32][1], + hls::stream v19[32][8], + float v20 +) { + float v21[512][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[256][128]; + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[512][256]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=32 + + loop8: for (int v24 = 0; v24 < 256; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 1; v27++) { + loop12: for (int v28 = 0; v28 < 32; v28++) { + loop13: for (int v29 = 0; v29 < 8; v29++) { + if ((v29 + (v26 * 8)) == 0) { + float v30 = v18[v28][v27].read(); + v23[(v28 + (v25 * 32))][(v24 + v27)] = v30; + } + float v31 = v23[(v28 + (v25 * 32))][(v24 + v27)]; + if ((v28 + (v25 * 32)) == 0) { + float v32 = v17[v27][v29].read(); + v22[(v24 + v27)][(v29 + (v26 * 8))] = v32; + } + float v33 = v22[(v24 + v27)][(v29 + (v26 * 8))]; + if ((v24 + v27) == 0) { + v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))] = v20; + } + float v34 = v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))] = v36; + if (((v24 + v27) - 255) == 0) { + float v37 = v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))]; + v19[v28][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][256], + hls::stream v39[1][8] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + + loop14: for (int v40 = 0; v40 < 256; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 1; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v40 + v42)]; + v39[v42][v43].write(v44); + } + } + } + } + return ; +} + +void node4( + hls::stream v45[32][1], + float v46[256], + hls::stream v47[32][1], + float v48 +) { + loop18: for (int v49 = 0; v49 < 256; v49++) { + loop19: for (int v50 = 0; v50 < 16; v50++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v51 = 0; v51 < 1; v51++) { + loop21: for (int v52 = 0; v52 < 32; v52++) { + float v53 = v45[v52][v51].read(); + float v54 = v46[(v49 + v51)]; + float v55 = v53 + v54; + bool v56 = v55 > v48; + float v57 = v56 ? (float)v55 : (float)v48; + v47[v52][v51].write(v57); + } + } + } + } + return ; +} + +void node5( + hls::stream v58[32][8], + hls::stream v59[8][1], + hls::stream v60[32][1], + float v61 +) { + float v62[512][256]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=32 + + float v63[128][256]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + + float v64[512][128]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop22: for (int v65 = 0; v65 < 256; v65++) { + loop23: for (int v66 = 0; v66 < 16; v66++) { + loop24: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v68 = 0; v68 < 1; v68++) { + loop26: for (int v69 = 0; v69 < 8; v69++) { + loop27: for (int v70 = 0; v70 < 32; v70++) { + if ((v65 + v68) == 0) { + float v71 = v58[v70][v69].read(); + v64[(v70 + (v67 * 32))][(v69 + (v66 * 8))] = v71; + } + float v72 = v64[(v70 + (v67 * 32))][(v69 + (v66 * 8))]; + if ((v70 + (v67 * 32)) == 0) { + float v73 = v59[v69][v68].read(); + v63[(v69 + (v66 * 8))][(v65 + v68)] = v73; + } + float v74 = v63[(v69 + (v66 * 8))][(v65 + v68)]; + if ((v69 + (v66 * 8)) == 0) { + v62[(v70 + (v67 * 32))][(v65 + v68)] = v61; + } + float v75 = v62[(v70 + (v67 * 32))][(v65 + v68)]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v70 + (v67 * 32))][(v65 + v68)] = v77; + if (((v69 + (v66 * 8)) - 127) == 0) { + float v78 = v62[(v70 + (v67 * 32))][(v65 + v68)]; + v60[v70][v68].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v79[256][128], + hls::stream v80[8][1] +) { + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=8 + + loop28: for (int v81 = 0; v81 < 256; v81++) { + loop29: for (int v82 = 0; v82 < 16; v82++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v83 = 0; v83 < 1; v83++) { + loop31: for (int v84 = 0; v84 < 8; v84++) { + float v85 = v79[(v81 + v83)][(v84 + (v82 * 8))]; + v80[v84][v83].write(v85); + } + } + } + } + return ; +} + +void node7( + float v86[1][512][128], + hls::stream v87[32][8] +) { + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v86 cyclic dim=3 factor=8 + + loop32: for (int v88 = 0; v88 < 16; v88++) { + loop33: for (int v89 = 0; v89 < 16; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 8; v90++) { + loop35: for (int v91 = 0; v91 < 32; v91++) { + float v92 = v86[0][(v91 + (v89 * 32))][(v90 + (v88 * 8))]; + v87[v91][v90].write(v92); + } + } + } + } + return ; +} + +void forward( + float v93[1][512][128], + float v94[256], + float v95[256][128], + float v96[128], + float v97[128][256], + float v98[1][512][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v93 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v95 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v98 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v98 cyclic dim=3 factor=8 + + hls::stream v99[32][8]; + #pragma HLS STREAM variable=v99 depth=256 + hls::stream v100[32][8]; + #pragma HLS STREAM variable=v100 depth=256 + hls::stream v101[1][8]; + #pragma HLS STREAM variable=v101 depth=4096 + hls::stream v102[32][1]; + #pragma HLS STREAM variable=v102 depth=4096 + hls::stream v103[32][1]; + #pragma HLS STREAM variable=v103 depth=4096 + hls::stream v104[8][1]; + #pragma HLS STREAM variable=v104 depth=4096 + hls::stream v105[32][8]; + #pragma HLS STREAM variable=v105 depth=256 + node7(v93, v105); + node6(v95, v104); + node5(v105, v104, v103, 0.000000); + node4(v103, v94, v102, 0.000000); + node3(v97, v101); + node2(v101, v102, v100, 0.000000); + node1(v100, v96, v99); + node0(v99, v98); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..73146c87489f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,734 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][64][128] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 128; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 64; v8++) { + loop3: for (int v9 = 0; v9 < 128; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v9]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + float v13[128][128], + hls::stream &v14, + hls::stream &v15, + float v16 +) { + float v17[64][128]; + float v18[128][128]; + float v19[64][128]; + loop4: for (int v20 = 0; v20 < 64; v20++) { + loop5: for (int v21 = 0; v21 < 128; v21++) { + loop6: for (int v22 = 0; v22 < 128; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v21 == 0) { + float v23 = v14.read(); + v19[v20][v22] = v23; + } + float v24 = v19[v20][v22]; + if (v20 == 0) { + float v25 = v13[v22][v21]; + v18[v22][v21] = v25; + } + float v26 = v18[v22][v21]; + if (v22 == 0) { + v17[v20][v21] = v16; + } + float v27 = v17[v20][v21]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v20][v21] = v29; + if ((v22 - 127) == 0) { + float v30 = v17[v20][v21]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][128], + float v32[128][128] +) { + loop7: for (int v33 = 0; v33 < 128; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32[v33][v34] = v35; + } + } + return ; +} + +void node4( + float v36[64][8][16], + hls::stream &v37 +) { + loop9: for (int v38 = 0; v38 < 64; v38++) { + loop10: for (int v39 = 0; v39 < 128; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v38][(v39 / 16)][(v39 % 16)]; + v37.write(v40); + } + } + return ; +} + +void node5( + float v41[8][64][16], + float v42[64][8][16] +) { + loop11: for (int v43 = 0; v43 < 8; v43++) { + loop12: for (int v44 = 0; v44 < 64; v44++) { + loop13: for (int v45 = 0; v45 < 16; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v46 = v41[v43][v44][v45]; + v42[v44][v43][v45] = v46; + } + } + } + return ; +} + +void node6( + float v47[8][64][16], + hls::stream &v48, + float v49[8][64][16], + float v50 +) { + float v51[8][64][16]; + float v52[8][64][16]; + float v53[8][64][64]; + loop14: for (int v54 = 0; v54 < 8; v54++) { + loop15: for (int v55 = 0; v55 < 64; v55++) { + loop16: for (int v56 = 0; v56 < 16; v56++) { + loop17: for (int v57 = 0; v57 < 64; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v56 == 0) { + float v58 = v48.read(); + v53[v54][v55][v57] = v58; + } + float v59 = v53[v54][v55][v57]; + if (v55 == 0) { + float v60 = v47[v54][v57][v56]; + v52[v54][v57][v56] = v60; + } + float v61 = v52[v54][v57][v56]; + if (v57 == 0) { + v51[v54][v55][v56] = v50; + } + float v62 = v51[v54][v55][v56]; + float v63 = v59 * v61; + float v64 = v62 + v63; + v51[v54][v55][v56] = v64; + if ((v57 - 63) == 0) { + float v65 = v51[v54][v55][v56]; + v49[v54][v55][v56] = v65; + } + } + } + } + } + return ; +} + +void node7( + float v66[64][128], + float v67[8][64][16] +) { + loop18: for (int v68 = 0; v68 < 8; v68++) { + loop19: for (int v69 = 0; v69 < 64; v69++) { + loop20: for (int v70 = 0; v70 < 16; v70++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v71 = v66[v69][((v68 * 16) + v70)]; + v67[v68][v69][v70] = v71; + } + } + } + return ; +} + +void node8( + hls::stream &v72, + hls::stream &v73, + hls::stream &v74 +) { + float v75[8][64]; + loop21: for (int v76 = 0; v76 < 8; v76++) { + loop22: for (int v77 = 0; v77 < 64; v77++) { + loop23: for (int v78 = 0; v78 < 64; v78++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v79 = v72.read(); + if (v78 == 0) { + float v80 = v73.read(); + v75[v76][v77] = v80; + } + float v81 = v75[v76][v77]; + float v82 = v79 / v81; + v74.write(v82); + } + } + } + return ; +} + +void node9( + hls::stream &v83, + hls::stream &v84, + float v85 +) { + float v86[8][64]; + loop24: for (int v87 = 0; v87 < 8; v87++) { + loop25: for (int v88 = 0; v88 < 64; v88++) { + loop26: for (int v89 = 0; v89 < 64; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v90 = v83.read(); + if (v89 == 0) { + v86[v87][v88] = v85; + } + float v91 = v86[v87][v88]; + float v92 = v90 + v91; + v86[v87][v88] = v92; + if ((v89 - 63) == 0) { + float v93 = v86[v87][v88]; + v84.write(v93); + } + } + } + } + return ; +} + +void node10( + hls::stream &v94, + hls::stream &v95, + hls::stream &v96, + hls::stream &v97 +) { + float v98[8][64]; + loop27: for (int v99 = 0; v99 < 8; v99++) { + loop28: for (int v100 = 0; v100 < 64; v100++) { + loop29: for (int v101 = 0; v101 < 64; v101++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v102 = v94.read(); + if (v101 == 0) { + float v103 = v95.read(); + v98[v99][v100] = v103; + } + float v104 = v98[v99][v100]; + float v105 = v102 - v104; + float v106 = exp(v105); + v96.write(v106); + v97.write(v106); + } + } + } + return ; +} + +void node11( + hls::stream &v107, + hls::stream &v108, + float v109 +) { + float v110[8][64]; + loop30: for (int v111 = 0; v111 < 8; v111++) { + loop31: for (int v112 = 0; v112 < 64; v112++) { + loop32: for (int v113 = 0; v113 < 64; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v107.read(); + if (v113 == 0) { + v110[v111][v112] = v109; + } + float v115 = v110[v111][v112]; + float v116 = fmax(v114, v115); + v110[v111][v112] = v116; + if ((v113 - 63) == 0) { + float v117 = v110[v111][v112]; + v108.write(v117); + } + } + } + } + return ; +} + +void node12( + hls::stream &v118, + hls::stream &v119, + hls::stream &v120, + float v121 +) { + loop33: for (int v122 = 0; v122 < 8; v122++) { + loop34: for (int v123 = 0; v123 < 64; v123++) { + loop35: for (int v124 = 0; v124 < 64; v124++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v125 = v118.read(); + float v126 = v125 / v121; + v119.write(v126); + v120.write(v126); + } + } + } + return ; +} + +void node13( + hls::stream &v127, + float v128[8][16][64], + hls::stream &v129, + float v130 +) { + float v131[8][64][64]; + float v132[8][16][64]; + float v133[8][64][16]; + loop36: for (int v134 = 0; v134 < 8; v134++) { + loop37: for (int v135 = 0; v135 < 64; v135++) { + loop38: for (int v136 = 0; v136 < 64; v136++) { + loop39: for (int v137 = 0; v137 < 16; v137++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v136 == 0) { + float v138 = v127.read(); + v133[v134][v135][v137] = v138; + } + float v139 = v133[v134][v135][v137]; + if (v135 == 0) { + float v140 = v128[v134][v137][v136]; + v132[v134][v137][v136] = v140; + } + float v141 = v132[v134][v137][v136]; + if (v137 == 0) { + v131[v134][v135][v136] = v130; + } + float v142 = v131[v134][v135][v136]; + float v143 = v139 * v141; + float v144 = v142 + v143; + v131[v134][v135][v136] = v144; + if ((v137 - 15) == 0) { + float v145 = v131[v134][v135][v136]; + v129.write(v145); + } + } + } + } + } + return ; +} + +void node14( + float v146[64][128], + float v147[8][16][64] +) { + loop40: for (int v148 = 0; v148 < 8; v148++) { + loop41: for (int v149 = 0; v149 < 16; v149++) { + loop42: for (int v150 = 0; v150 < 64; v150++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v151 = v146[v150][((v148 * 16) + v149)]; + v147[v148][v149][v150] = v151; + } + } + } + return ; +} + +void node15( + float v152[64][128], + hls::stream &v153 +) { + loop43: for (int v154 = 0; v154 < 8; v154++) { + loop44: for (int v155 = 0; v155 < 64; v155++) { + loop45: for (int v156 = 0; v156 < 16; v156++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v157 = v152[v155][((v154 * 16) + v156)]; + v153.write(v157); + } + } + } + return ; +} + +void node16( + hls::stream &v158, + float v159[128], + float v160[64][128] +) { + loop46: for (int v161 = 0; v161 < 64; v161++) { + loop47: for (int v162 = 0; v162 < 128; v162++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v163 = v158.read(); + float v164 = v159[v162]; + float v165 = v163 + v164; + v160[v161][v162] = v165; + } + } + return ; +} + +void node17( + hls::stream &v166, + float v167[128][128], + hls::stream &v168, + float v169 +) { + float v170[64][128]; + float v171[128][128]; + float v172[64][128]; + loop48: for (int v173 = 0; v173 < 64; v173++) { + loop49: for (int v174 = 0; v174 < 128; v174++) { + loop50: for (int v175 = 0; v175 < 128; v175++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v174 == 0) { + float v176 = v166.read(); + v172[v173][v175] = v176; + } + float v177 = v172[v173][v175]; + if (v173 == 0) { + float v178 = v167[v175][v174]; + v171[v175][v174] = v178; + } + float v179 = v171[v175][v174]; + if (v175 == 0) { + v170[v173][v174] = v169; + } + float v180 = v170[v173][v174]; + float v181 = v177 * v179; + float v182 = v180 + v181; + v170[v173][v174] = v182; + if ((v175 - 127) == 0) { + float v183 = v170[v173][v174]; + v168.write(v183); + } + } + } + } + return ; +} + +void node18( + float v184[128][128], + float v185[128][128] +) { + loop51: for (int v186 = 0; v186 < 128; v186++) { + loop52: for (int v187 = 0; v187 < 128; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v188 = v184[v187][v186]; + v185[v186][v187] = v188; + } + } + return ; +} + +void node19( + hls::stream &v189, + float v190[128], + float v191[64][128] +) { + loop53: for (int v192 = 0; v192 < 64; v192++) { + loop54: for (int v193 = 0; v193 < 128; v193++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v189.read(); + float v195 = v190[v193]; + float v196 = v194 + v195; + v191[v192][v193] = v196; + } + } + return ; +} + +void node20( + float v197[128][128], + hls::stream &v198, + hls::stream &v199, + float v200 +) { + float v201[64][128]; + float v202[128][128]; + float v203[64][128]; + loop55: for (int v204 = 0; v204 < 64; v204++) { + loop56: for (int v205 = 0; v205 < 128; v205++) { + loop57: for (int v206 = 0; v206 < 128; v206++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v205 == 0) { + float v207 = v198.read(); + v203[v204][v206] = v207; + } + float v208 = v203[v204][v206]; + if (v204 == 0) { + float v209 = v197[v206][v205]; + v202[v206][v205] = v209; + } + float v210 = v202[v206][v205]; + if (v206 == 0) { + v201[v204][v205] = v200; + } + float v211 = v201[v204][v205]; + float v212 = v208 * v210; + float v213 = v211 + v212; + v201[v204][v205] = v213; + if ((v206 - 127) == 0) { + float v214 = v201[v204][v205]; + v199.write(v214); + } + } + } + } + return ; +} + +void node21( + float v215[128][128], + float v216[128][128] +) { + loop58: for (int v217 = 0; v217 < 128; v217++) { + loop59: for (int v218 = 0; v218 < 128; v218++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v219 = v215[v218][v217]; + v216[v217][v218] = v219; + } + } + return ; +} + +void node22( + hls::stream &v220, + float v221[128], + float v222[64][128] +) { + loop60: for (int v223 = 0; v223 < 64; v223++) { + loop61: for (int v224 = 0; v224 < 128; v224++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v225 = v220.read(); + float v226 = v221[v224]; + float v227 = v225 + v226; + v222[v223][v224] = v227; + } + } + return ; +} + +void node23( + hls::stream &v228, + float v229[128][128], + hls::stream &v230, + float v231 +) { + float v232[64][128]; + float v233[128][128]; + float v234[64][128]; + loop62: for (int v235 = 0; v235 < 64; v235++) { + loop63: for (int v236 = 0; v236 < 128; v236++) { + loop64: for (int v237 = 0; v237 < 128; v237++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v236 == 0) { + float v238 = v228.read(); + v234[v235][v237] = v238; + } + float v239 = v234[v235][v237]; + if (v235 == 0) { + float v240 = v229[v237][v236]; + v233[v237][v236] = v240; + } + float v241 = v233[v237][v236]; + if (v237 == 0) { + v232[v235][v236] = v231; + } + float v242 = v232[v235][v236]; + float v243 = v239 * v241; + float v244 = v242 + v243; + v232[v235][v236] = v244; + if ((v237 - 127) == 0) { + float v245 = v232[v235][v236]; + v230.write(v245); + } + } + } + } + return ; +} + +void node24( + float v246[128][128], + float v247[128][128] +) { + loop65: for (int v248 = 0; v248 < 128; v248++) { + loop66: for (int v249 = 0; v249 < 128; v249++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v250 = v246[v249][v248]; + v247[v248][v249] = v250; + } + } + return ; +} + +void node25( + float v251[1][64][128], + hls::stream &v252, + hls::stream &v253, + hls::stream &v254 +) { + loop67: for (int v255 = 0; v255 < 64; v255++) { + loop68: for (int v256 = 0; v256 < 128; v256++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v257 = v251[0][v255][v256]; + v252.write(v257); + v253.write(v257); + v254.write(v257); + } + } + return ; +} + +void forward( + float v258[1][64][128], + float v259[128], + float v260[128][128], + float v261[128], + float v262[128][128], + float v263[128], + float v264[128][128], + float v265[128], + float v266[128][128], + float v267[1][64][128] +) { + #pragma HLS DATAFLOW + hls::stream v268("fifo_0"); + #pragma HLS STREAM variable=v268 depth=8192 + hls::stream v269("fifo_1"); + #pragma HLS STREAM variable=v269 depth=8192 + float v270[128][128]; + hls::stream v271("fifo_2"); + #pragma HLS STREAM variable=v271 depth=8192 + float v272[64][8][16]; + float v273[8][64][16]; + float v274[8][64][16]; + hls::stream v275("fifo_3"); + #pragma HLS STREAM variable=v275 depth=32768 + hls::stream v276("fifo_4"); + #pragma HLS STREAM variable=v276 depth=512 + hls::stream v277("fifo_5"); + #pragma HLS STREAM variable=v277 depth=32768 + hls::stream v278("fifo_6"); + #pragma HLS STREAM variable=v278 depth=32768 + hls::stream v279("fifo_7"); + #pragma HLS STREAM variable=v279 depth=512 + hls::stream v280("fifo_8"); + #pragma HLS STREAM variable=v280 depth=32768 + hls::stream v281("fifo_9"); + #pragma HLS STREAM variable=v281 depth=32768 + hls::stream v282("fifo_10"); + #pragma HLS STREAM variable=v282 depth=32768 + float v283[8][16][64]; + hls::stream v284("fifo_11"); + #pragma HLS STREAM variable=v284 depth=8192 + float v285[64][128]; + hls::stream v286("fifo_12"); + #pragma HLS STREAM variable=v286 depth=8192 + float v287[128][128]; + float v288[64][128]; + hls::stream v289("fifo_13"); + #pragma HLS STREAM variable=v289 depth=8192 + float v290[128][128]; + float v291[64][128]; + hls::stream v292("fifo_14"); + #pragma HLS STREAM variable=v292 depth=8192 + float v293[128][128]; + hls::stream v294("fifo_15"); + #pragma HLS STREAM variable=v294 depth=8192 + hls::stream v295("fifo_16"); + #pragma HLS STREAM variable=v295 depth=8192 + hls::stream v296("fifo_17"); + #pragma HLS STREAM variable=v296 depth=8192 + node25(v258, v296, v295, v294); + node24(v260, v293); + node23(v294, v293, v292, 0.000000); + node22(v292, v259, v291); + node21(v262, v290); + node20(v290, v295, v289, 0.000000); + node19(v289, v261, v288); + node18(v264, v287); + node17(v296, v287, v286, 0.000000); + node16(v286, v263, v285); + node15(v291, v284); + node14(v288, v283); + node13(v284, v283, v282, 0.000000); + node12(v282, v281, v280, 4.000000); + node11(v281, v279, -INFINITY); + node10(v280, v279, v278, v277); + node9(v278, v276, 0.000000); + node8(v277, v276, v275); + node7(v285, v274); + node6(v274, v275, v273, 0.000000); + node5(v273, v272); + node4(v272, v271); + node3(v266, v270); + node2(v270, v271, v269, 0.000000); + node1(v269, v265, v268); + node0(v268, v267); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..f4dcc94569a6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,738 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][64][128] +) { + loop0: for (int v2 = 0; v2 < 128; v2++) { + loop1: for (int v3 = 0; v3 < 64; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v3][v2] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 128; v8++) { + loop3: for (int v9 = 0; v9 < 64; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v8]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + hls::stream &v13, + float v14[128][128], + hls::stream &v15, + float v16 +) { + float v17[64][128]; + float v18[128][128]; + float v19[64][128]; + loop4: for (int v20 = 0; v20 < 128; v20++) { + loop5: for (int v21 = 0; v21 < 128; v21++) { + loop6: for (int v22 = 0; v22 < 64; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v20 == 0) { + float v23 = v13.read(); + v19[v22][v21] = v23; + } + float v24 = v19[v22][v21]; + if (v22 == 0) { + float v25 = v14[v21][v20]; + v18[v21][v20] = v25; + } + float v26 = v18[v21][v20]; + if (v21 == 0) { + v17[v22][v20] = v16; + } + float v27 = v17[v22][v20]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v22][v20] = v29; + if ((v21 - 127) == 0) { + float v30 = v17[v22][v20]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][128], + float v32[128][128] +) { + loop7: for (int v33 = 0; v33 < 128; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32[v33][v34] = v35; + } + } + return ; +} + +void node4( + float v36[64][8][16], + hls::stream &v37 +) { + loop9: for (int v38 = 0; v38 < 128; v38++) { + loop10: for (int v39 = 0; v39 < 64; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v39][(v38 / 16)][(v38 % 16)]; + v37.write(v40); + } + } + return ; +} + +void node5( + float v41[8][64][16], + float v42[64][8][16] +) { + loop11: for (int v43 = 0; v43 < 8; v43++) { + loop12: for (int v44 = 0; v44 < 64; v44++) { + loop13: for (int v45 = 0; v45 < 16; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v46 = v41[v43][v44][v45]; + v42[v44][v43][v45] = v46; + } + } + } + return ; +} + +void node6( + hls::stream &v47, + float v48[8][64][16], + float v49[8][64][16], + float v50 +) { + float v51[8][64][16]; + float v52[8][64][16]; + float v53[8][64][64]; + loop14: for (int v54 = 0; v54 < 8; v54++) { + loop15: for (int v55 = 0; v55 < 64; v55++) { + loop16: for (int v56 = 0; v56 < 64; v56++) { + loop17: for (int v57 = 0; v57 < 16; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v57 == 0) { + float v58 = v47.read(); + v53[v54][v55][v56] = v58; + } + float v59 = v53[v54][v55][v56]; + if (v55 == 0) { + float v60 = v48[v54][v56][v57]; + v52[v54][v56][v57] = v60; + } + float v61 = v52[v54][v56][v57]; + if (v56 == 0) { + v51[v54][v55][v57] = v50; + } + float v62 = v51[v54][v55][v57]; + float v63 = v59 * v61; + float v64 = v62 + v63; + v51[v54][v55][v57] = v64; + if ((v56 - 63) == 0) { + float v65 = v51[v54][v55][v57]; + v49[v54][v55][v57] = v65; + } + } + } + } + } + return ; +} + +void node7( + float v66[64][128], + float v67[8][64][16] +) { + loop18: for (int v68 = 0; v68 < 8; v68++) { + loop19: for (int v69 = 0; v69 < 16; v69++) { + loop20: for (int v70 = 0; v70 < 64; v70++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v71 = v66[v70][((v68 * 16) + v69)]; + v67[v68][v70][v69] = v71; + } + } + } + return ; +} + +void node8( + hls::stream &v72, + hls::stream &v73, + hls::stream &v74 +) { + float v75[8][64]; + loop21: for (int v76 = 0; v76 < 8; v76++) { + loop22: for (int v77 = 0; v77 < 64; v77++) { + loop23: for (int v78 = 0; v78 < 64; v78++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v79 = v72.read(); + if (v78 == 0) { + float v80 = v73.read(); + v75[v76][v77] = v80; + } + float v81 = v75[v76][v77]; + float v82 = v79 / v81; + v74.write(v82); + } + } + } + return ; +} + +void node9( + hls::stream &v83, + hls::stream &v84, + float v85 +) { + float v86[8][64]; + loop24: for (int v87 = 0; v87 < 8; v87++) { + loop25: for (int v88 = 0; v88 < 64; v88++) { + loop26: for (int v89 = 0; v89 < 64; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v90 = v83.read(); + if (v89 == 0) { + v86[v87][v88] = v85; + } + float v91 = v86[v87][v88]; + float v92 = v90 + v91; + v86[v87][v88] = v92; + if ((v89 - 63) == 0) { + float v93 = v86[v87][v88]; + v84.write(v93); + } + } + } + } + return ; +} + +void node10( + hls::stream &v94, + hls::stream &v95, + hls::stream &v96, + hls::stream &v97 +) { + float v98[8][64]; + loop27: for (int v99 = 0; v99 < 8; v99++) { + loop28: for (int v100 = 0; v100 < 64; v100++) { + loop29: for (int v101 = 0; v101 < 64; v101++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v102 = v94.read(); + if (v101 == 0) { + float v103 = v95.read(); + v98[v99][v100] = v103; + } + float v104 = v98[v99][v100]; + float v105 = v102 - v104; + float v106 = exp(v105); + v96.write(v106); + v97.write(v106); + } + } + } + return ; +} + +void node11( + hls::stream &v107, + hls::stream &v108, + float v109 +) { + float v110[8][64]; + loop30: for (int v111 = 0; v111 < 8; v111++) { + loop31: for (int v112 = 0; v112 < 64; v112++) { + loop32: for (int v113 = 0; v113 < 64; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v107.read(); + if (v113 == 0) { + v110[v111][v112] = v109; + } + float v115 = v110[v111][v112]; + float v116 = fmax(v114, v115); + v110[v111][v112] = v116; + if ((v113 - 63) == 0) { + float v117 = v110[v111][v112]; + v108.write(v117); + } + } + } + } + return ; +} + +void node12( + hls::stream &v118, + hls::stream &v119, + hls::stream &v120, + float v121 +) { + loop33: for (int v122 = 0; v122 < 8; v122++) { + loop34: for (int v123 = 0; v123 < 64; v123++) { + loop35: for (int v124 = 0; v124 < 64; v124++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v125 = v118.read(); + float v126 = v125 / v121; + v119.write(v126); + v120.write(v126); + } + } + } + return ; +} + +void node13( + hls::stream &v127, + hls::stream &v128, + hls::stream &v129, + float v130 +) { + float v131[8][64][64]; + float v132[8][16][64]; + float v133[8][64][16]; + loop36: for (int v134 = 0; v134 < 8; v134++) { + loop37: for (int v135 = 0; v135 < 16; v135++) { + loop38: for (int v136 = 0; v136 < 64; v136++) { + loop39: for (int v137 = 0; v137 < 64; v137++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v137 == 0) { + float v138 = v128.read(); + v133[v134][v136][v135] = v138; + } + float v139 = v133[v134][v136][v135]; + if (v136 == 0) { + float v140 = v127.read(); + v132[v134][v135][v137] = v140; + } + float v141 = v132[v134][v135][v137]; + if (v135 == 0) { + v131[v134][v136][v137] = v130; + } + float v142 = v131[v134][v136][v137]; + float v143 = v139 * v141; + float v144 = v142 + v143; + v131[v134][v136][v137] = v144; + if ((v135 - 15) == 0) { + float v145 = v131[v134][v136][v137]; + v129.write(v145); + } + } + } + } + } + return ; +} + +void node14( + float v146[64][128], + hls::stream &v147 +) { + loop40: for (int v148 = 0; v148 < 8; v148++) { + loop41: for (int v149 = 0; v149 < 16; v149++) { + loop42: for (int v150 = 0; v150 < 64; v150++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v151 = v146[v150][((v148 * 16) + v149)]; + v147.write(v151); + } + } + } + return ; +} + +void node15( + float v152[64][128], + hls::stream &v153 +) { + loop43: for (int v154 = 0; v154 < 8; v154++) { + loop44: for (int v155 = 0; v155 < 16; v155++) { + loop45: for (int v156 = 0; v156 < 64; v156++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v157 = v152[v156][((v154 * 16) + v155)]; + v153.write(v157); + } + } + } + return ; +} + +void node16( + hls::stream &v158, + float v159[128], + float v160[64][128] +) { + loop46: for (int v161 = 0; v161 < 64; v161++) { + loop47: for (int v162 = 0; v162 < 128; v162++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v163 = v158.read(); + float v164 = v159[v162]; + float v165 = v163 + v164; + v160[v161][v162] = v165; + } + } + return ; +} + +void node17( + hls::stream &v166, + hls::stream &v167, + hls::stream &v168, + float v169 +) { + float v170[64][128]; + float v171[128][128]; + float v172[64][128]; + loop48: for (int v173 = 0; v173 < 64; v173++) { + loop49: for (int v174 = 0; v174 < 128; v174++) { + loop50: for (int v175 = 0; v175 < 128; v175++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v175 == 0) { + float v176 = v167.read(); + v172[v173][v174] = v176; + } + float v177 = v172[v173][v174]; + if (v173 == 0) { + float v178 = v166.read(); + v171[v174][v175] = v178; + } + float v179 = v171[v174][v175]; + if (v174 == 0) { + v170[v173][v175] = v169; + } + float v180 = v170[v173][v175]; + float v181 = v177 * v179; + float v182 = v180 + v181; + v170[v173][v175] = v182; + if ((v174 - 127) == 0) { + float v183 = v170[v173][v175]; + v168.write(v183); + } + } + } + } + return ; +} + +void node18( + float v184[128][128], + hls::stream &v185 +) { + loop51: for (int v186 = 0; v186 < 128; v186++) { + loop52: for (int v187 = 0; v187 < 128; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v188 = v184[v187][v186]; + v185.write(v188); + } + } + return ; +} + +void node19( + hls::stream &v189, + float v190[128], + float v191[64][128] +) { + loop53: for (int v192 = 0; v192 < 64; v192++) { + loop54: for (int v193 = 0; v193 < 128; v193++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v189.read(); + float v195 = v190[v193]; + float v196 = v194 + v195; + v191[v192][v193] = v196; + } + } + return ; +} + +void node20( + hls::stream &v197, + hls::stream &v198, + hls::stream &v199, + float v200 +) { + float v201[64][128]; + float v202[128][128]; + float v203[64][128]; + loop55: for (int v204 = 0; v204 < 64; v204++) { + loop56: for (int v205 = 0; v205 < 128; v205++) { + loop57: for (int v206 = 0; v206 < 128; v206++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v206 == 0) { + float v207 = v197.read(); + v203[v204][v205] = v207; + } + float v208 = v203[v204][v205]; + if (v204 == 0) { + float v209 = v198.read(); + v202[v205][v206] = v209; + } + float v210 = v202[v205][v206]; + if (v205 == 0) { + v201[v204][v206] = v200; + } + float v211 = v201[v204][v206]; + float v212 = v208 * v210; + float v213 = v211 + v212; + v201[v204][v206] = v213; + if ((v205 - 127) == 0) { + float v214 = v201[v204][v206]; + v199.write(v214); + } + } + } + } + return ; +} + +void node21( + float v215[128][128], + hls::stream &v216 +) { + loop58: for (int v217 = 0; v217 < 128; v217++) { + loop59: for (int v218 = 0; v218 < 128; v218++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v219 = v215[v218][v217]; + v216.write(v219); + } + } + return ; +} + +void node22( + hls::stream &v220, + float v221[128], + float v222[64][128] +) { + loop60: for (int v223 = 0; v223 < 64; v223++) { + loop61: for (int v224 = 0; v224 < 128; v224++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v225 = v220.read(); + float v226 = v221[v224]; + float v227 = v225 + v226; + v222[v223][v224] = v227; + } + } + return ; +} + +void node23( + hls::stream &v228, + hls::stream &v229, + hls::stream &v230, + float v231 +) { + float v232[64][128]; + float v233[128][128]; + float v234[64][128]; + loop62: for (int v235 = 0; v235 < 64; v235++) { + loop63: for (int v236 = 0; v236 < 128; v236++) { + loop64: for (int v237 = 0; v237 < 128; v237++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v237 == 0) { + float v238 = v229.read(); + v234[v235][v236] = v238; + } + float v239 = v234[v235][v236]; + if (v235 == 0) { + float v240 = v228.read(); + v233[v236][v237] = v240; + } + float v241 = v233[v236][v237]; + if (v236 == 0) { + v232[v235][v237] = v231; + } + float v242 = v232[v235][v237]; + float v243 = v239 * v241; + float v244 = v242 + v243; + v232[v235][v237] = v244; + if ((v236 - 127) == 0) { + float v245 = v232[v235][v237]; + v230.write(v245); + } + } + } + } + return ; +} + +void node24( + float v246[128][128], + hls::stream &v247 +) { + loop65: for (int v248 = 0; v248 < 128; v248++) { + loop66: for (int v249 = 0; v249 < 128; v249++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v250 = v246[v249][v248]; + v247.write(v250); + } + } + return ; +} + +void node25( + float v251[1][64][128], + hls::stream &v252, + hls::stream &v253, + hls::stream &v254 +) { + loop67: for (int v255 = 0; v255 < 64; v255++) { + loop68: for (int v256 = 0; v256 < 128; v256++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v257 = v251[0][v255][v256]; + v252.write(v257); + v253.write(v257); + v254.write(v257); + } + } + return ; +} + +void forward( + float v258[1][64][128], + float v259[128], + float v260[128][128], + float v261[128], + float v262[128][128], + float v263[128], + float v264[128][128], + float v265[128], + float v266[128][128], + float v267[1][64][128] +) { + #pragma HLS DATAFLOW + hls::stream v268("fifo_0"); + #pragma HLS STREAM variable=v268 depth=8192 + hls::stream v269("fifo_1"); + #pragma HLS STREAM variable=v269 depth=8192 + float v270[128][128]; + hls::stream v271("fifo_2"); + #pragma HLS STREAM variable=v271 depth=8192 + float v272[64][8][16]; + float v273[8][64][16]; + float v274[8][64][16]; + hls::stream v275("fifo_3"); + #pragma HLS STREAM variable=v275 depth=32768 + hls::stream v276("fifo_4"); + #pragma HLS STREAM variable=v276 depth=512 + hls::stream v277("fifo_5"); + #pragma HLS STREAM variable=v277 depth=32768 + hls::stream v278("fifo_6"); + #pragma HLS STREAM variable=v278 depth=32768 + hls::stream v279("fifo_7"); + #pragma HLS STREAM variable=v279 depth=512 + hls::stream v280("fifo_8"); + #pragma HLS STREAM variable=v280 depth=32768 + hls::stream v281("fifo_9"); + #pragma HLS STREAM variable=v281 depth=32768 + hls::stream v282("fifo_10"); + #pragma HLS STREAM variable=v282 depth=32768 + hls::stream v283("fifo_11"); + #pragma HLS STREAM variable=v283 depth=8192 + hls::stream v284("fifo_12"); + #pragma HLS STREAM variable=v284 depth=8192 + float v285[64][128]; + hls::stream v286("fifo_13"); + #pragma HLS STREAM variable=v286 depth=8192 + hls::stream v287("fifo_14"); + #pragma HLS STREAM variable=v287 depth=16384 + float v288[64][128]; + hls::stream v289("fifo_15"); + #pragma HLS STREAM variable=v289 depth=8192 + hls::stream v290("fifo_16"); + #pragma HLS STREAM variable=v290 depth=16384 + float v291[64][128]; + hls::stream v292("fifo_17"); + #pragma HLS STREAM variable=v292 depth=8192 + hls::stream v293("fifo_18"); + #pragma HLS STREAM variable=v293 depth=16384 + hls::stream v294("fifo_19"); + #pragma HLS STREAM variable=v294 depth=8192 + hls::stream v295("fifo_20"); + #pragma HLS STREAM variable=v295 depth=8192 + hls::stream v296("fifo_21"); + #pragma HLS STREAM variable=v296 depth=8192 + node25(v258, v296, v295, v294); + node24(v260, v293); + node23(v293, v294, v292, 0.000000); + node22(v292, v259, v291); + node21(v262, v290); + node20(v295, v290, v289, 0.000000); + node19(v289, v261, v288); + node18(v264, v287); + node17(v287, v296, v286, 0.000000); + node16(v286, v263, v285); + node15(v291, v284); + node14(v288, v283); + node13(v283, v284, v282, 0.000000); + node12(v282, v281, v280, 4.000000); + node11(v281, v279, -INFINITY); + node10(v280, v279, v278, v277); + node9(v278, v276, 0.000000); + node8(v277, v276, v275); + node7(v285, v274); + node6(v275, v274, v273, 0.000000); + node5(v273, v272); + node4(v272, v271); + node3(v266, v270); + node2(v271, v270, v269, 0.000000); + node1(v269, v265, v268); + node0(v268, v267); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..71ca54aa4df7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,1107 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[8][8], + float v1[1][64][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 8; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 8; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 8))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[8][8], + float v8[128], + hls::stream v9[8][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 8; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 8; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[8][2], + float v18[128][128], + hls::stream v19[8][8], + float v20 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=8 + + float v21[64][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[128][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[64][128]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=2 + + loop8: for (int v24 = 0; v24 < 8; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 64; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 8; v27++) { + loop12: for (int v28 = 0; v28 < 8; v28++) { + loop13: for (int v29 = 0; v29 < 2; v29++) { + if ((v28 + (v25 * 8)) == 0) { + float v30 = v17[v27][v29].read(); + v23[(v27 + (v24 * 8))][(v29 + (v26 * 2))] = v30; + } + float v31 = v23[(v27 + (v24 * 8))][(v29 + (v26 * 2))]; + if ((v27 + (v24 * 8)) == 0) { + float v32 = v18[(v29 + (v26 * 2))][(v28 + (v25 * 8))]; + v22[(v29 + (v26 * 2))][(v28 + (v25 * 8))] = v32; + } + float v33 = v22[(v29 + (v26 * 2))][(v28 + (v25 * 8))]; + if ((v29 + (v26 * 2)) == 0) { + v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))] = v36; + if (((v29 + (v26 * 2)) - 127) == 0) { + float v37 = v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))]; + v19[v27][v28].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][128], + float v39[128][128] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=8 + + loop14: for (int v40 = 0; v40 < 64; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 2; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 2))]; + v39[(v42 + (v40 * 2))][(v43 + (v41 * 8))] = v44; + } + } + } + } + return ; +} + +void node4( + float v45[64][8][16], + hls::stream v46[8][2] +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=3 factor=2 + + loop18: for (int v47 = 0; v47 < 8; v47++) { + loop19: for (int v48 = 0; v48 < 64; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v49 = 0; v49 < 8; v49++) { + loop21: for (int v50 = 0; v50 < 2; v50++) { + float v51 = v45[(v49 + (v47 * 8))][(v48 / 8)][((v50 + (v48 * 2)) % 16)]; + v46[v49][v50].write(v51); + } + } + } + } + return ; +} + +void node5( + float v52[8][64][16], + float v53[64][8][16] +) { + #pragma HLS array_partition variable=v52 complete dim=1 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=3 factor=2 + + loop22: for (int v54 = 0; v54 < 4; v54++) { + loop23: for (int v55 = 0; v55 < 8; v55++) { + loop24: for (int v56 = 0; v56 < 8; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v57 = 0; v57 < 2; v57++) { + loop26: for (int v58 = 0; v58 < 8; v58++) { + loop27: for (int v59 = 0; v59 < 2; v59++) { + float v60 = v52[(v57 + (v54 * 2))][(v58 + (v55 * 8))][(v59 + (v56 * 2))]; + v53[(v58 + (v55 * 8))][(v57 + (v54 * 2))][(v59 + (v56 * 2))] = v60; + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v61[8][2][2], + float v62[8][64][16], + float v63[8][64][16], + float v64 +) { + #pragma HLS array_partition variable=v62 complete dim=1 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v63 complete dim=1 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=3 factor=2 + + float v65[8][64][16]; + #pragma HLS array_partition variable=v65 complete dim=1 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v65 cyclic dim=3 factor=2 + + float v66[8][64][16]; + #pragma HLS array_partition variable=v66 complete dim=1 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v66 cyclic dim=3 factor=2 + + float v67[8][64][64]; + #pragma HLS array_partition variable=v67 complete dim=1 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=3 factor=2 + + loop28: for (int v68 = 0; v68 < 1; v68++) { + loop29: for (int v69 = 0; v69 < 32; v69++) { + loop30: for (int v70 = 0; v70 < 8; v70++) { + loop31: for (int v71 = 0; v71 < 32; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop32: for (int v72 = 0; v72 < 8; v72++) { + loop33: for (int v73 = 0; v73 < 2; v73++) { + loop34: for (int v74 = 0; v74 < 2; v74++) { + loop35: for (int v75 = 0; v75 < 2; v75++) { + if ((v74 + (v70 * 2)) == 0) { + float v76 = v61[v72][v73][v75].read(); + v67[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))] = v76; + } + float v77 = v67[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))]; + if ((v73 + (v69 * 2)) == 0) { + float v78 = v62[(v72 + (v68 * 8))][(v75 + (v71 * 2))][(v74 + (v70 * 2))]; + v66[(v72 + (v68 * 8))][(v75 + (v71 * 2))][(v74 + (v70 * 2))] = v78; + } + float v79 = v66[(v72 + (v68 * 8))][(v75 + (v71 * 2))][(v74 + (v70 * 2))]; + if ((v75 + (v71 * 2)) == 0) { + v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))] = v64; + } + float v80 = v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))]; + float v81 = v77 * v79; + float v82 = v80 + v81; + v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))] = v82; + if (((v75 + (v71 * 2)) - 63) == 0) { + float v83 = v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))]; + v63[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))] = v83; + } + } + } + } + } + } + } + } + } + return ; +} + +void node7( + float v84[64][128], + float v85[8][64][16] +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v85 complete dim=1 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=3 factor=2 + + loop36: for (int v86 = 0; v86 < 1; v86++) { + loop37: for (int v87 = 0; v87 < 32; v87++) { + loop38: for (int v88 = 0; v88 < 8; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v89 = 0; v89 < 8; v89++) { + loop40: for (int v90 = 0; v90 < 2; v90++) { + loop41: for (int v91 = 0; v91 < 2; v91++) { + float v92 = v84[(v90 + (v87 * 2))][((((v89 * 16) + (v86 * 128)) + v91) + (v88 * 2))]; + v85[(v89 + (v86 * 8))][(v90 + (v87 * 2))][(v91 + (v88 * 2))] = v92; + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v93[8][2][2], + hls::stream v94[8][2], + hls::stream v95[8][2][2] +) { + float v96[8][64]; + #pragma HLS array_partition variable=v96 complete dim=1 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=2 + + loop42: for (int v97 = 0; v97 < 1; v97++) { + loop43: for (int v98 = 0; v98 < 32; v98++) { + loop44: for (int v99 = 0; v99 < 32; v99++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop45: for (int v100 = 0; v100 < 8; v100++) { + loop46: for (int v101 = 0; v101 < 2; v101++) { + loop47: for (int v102 = 0; v102 < 2; v102++) { + float v103 = v93[v100][v101][v102].read(); + if ((v102 + (v99 * 2)) == 0) { + float v104 = v94[v100][v101].read(); + v96[(v100 + (v97 * 8))][(v101 + (v98 * 2))] = v104; + } + float v105 = v96[(v100 + (v97 * 8))][(v101 + (v98 * 2))]; + float v106 = v103 / v105; + v95[v100][v101][v102].write(v106); + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v107[8][2][2], + hls::stream v108[8][2], + float v109 +) { + float v110[8][64]; + #pragma HLS array_partition variable=v110 complete dim=1 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=2 + + loop48: for (int v111 = 0; v111 < 1; v111++) { + loop49: for (int v112 = 0; v112 < 32; v112++) { + loop50: for (int v113 = 0; v113 < 32; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v114 = 0; v114 < 8; v114++) { + loop52: for (int v115 = 0; v115 < 2; v115++) { + loop53: for (int v116 = 0; v116 < 2; v116++) { + float v117 = v107[v114][v115][v116].read(); + if ((v116 + (v113 * 2)) == 0) { + v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))] = v109; + } + float v118 = v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))]; + float v119 = v117 + v118; + v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))] = v119; + if (((v116 + (v113 * 2)) - 63) == 0) { + float v120 = v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))]; + v108[v114][v115].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v121[8][2][2], + hls::stream v122[8][2], + hls::stream v123[8][2][2], + hls::stream v124[8][2][2] +) { + float v125[8][64]; + #pragma HLS array_partition variable=v125 complete dim=1 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=2 + + loop54: for (int v126 = 0; v126 < 1; v126++) { + loop55: for (int v127 = 0; v127 < 32; v127++) { + loop56: for (int v128 = 0; v128 < 32; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v129 = 0; v129 < 8; v129++) { + loop58: for (int v130 = 0; v130 < 2; v130++) { + loop59: for (int v131 = 0; v131 < 2; v131++) { + float v132 = v121[v129][v130][v131].read(); + if ((v131 + (v128 * 2)) == 0) { + float v133 = v122[v129][v130].read(); + v125[(v129 + (v126 * 8))][(v130 + (v127 * 2))] = v133; + } + float v134 = v125[(v129 + (v126 * 8))][(v130 + (v127 * 2))]; + float v135 = v132 - v134; + float v136 = exp(v135); + v123[v129][v130][v131].write(v136); + v124[v129][v130][v131].write(v136); + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v137[8][2][2], + hls::stream v138[8][2], + float v139 +) { + float v140[8][64]; + #pragma HLS array_partition variable=v140 complete dim=1 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=2 + + loop60: for (int v141 = 0; v141 < 1; v141++) { + loop61: for (int v142 = 0; v142 < 32; v142++) { + loop62: for (int v143 = 0; v143 < 32; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v144 = 0; v144 < 8; v144++) { + loop64: for (int v145 = 0; v145 < 2; v145++) { + loop65: for (int v146 = 0; v146 < 2; v146++) { + float v147 = v137[v144][v145][v146].read(); + if ((v146 + (v143 * 2)) == 0) { + v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))] = v139; + } + float v148 = v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))]; + float v149 = fmax(v147, v148); + v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))] = v149; + if (((v146 + (v143 * 2)) - 63) == 0) { + float v150 = v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))]; + v138[v144][v145].write(v150); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v151[8][2][2], + hls::stream v152[8][2][2], + hls::stream v153[8][2][2], + float v154 +) { + loop66: for (int v155 = 0; v155 < 1; v155++) { + loop67: for (int v156 = 0; v156 < 32; v156++) { + loop68: for (int v157 = 0; v157 < 32; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop69: for (int v158 = 0; v158 < 8; v158++) { + loop70: for (int v159 = 0; v159 < 2; v159++) { + loop71: for (int v160 = 0; v160 < 2; v160++) { + float v161 = v151[v158][v159][v160].read(); + float v162 = v161 / v154; + v152[v158][v159][v160].write(v162); + v153[v158][v159][v160].write(v162); + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v163[8][2][2], + float v164[8][16][64], + hls::stream v165[8][2][2], + float v166 +) { + #pragma HLS array_partition variable=v164 complete dim=1 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v164 cyclic dim=3 factor=2 + + float v167[8][64][64]; + #pragma HLS array_partition variable=v167 complete dim=1 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v167 cyclic dim=3 factor=2 + + float v168[8][16][64]; + #pragma HLS array_partition variable=v168 complete dim=1 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=3 factor=2 + + float v169[8][64][16]; + #pragma HLS array_partition variable=v169 complete dim=1 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=3 factor=2 + + loop72: for (int v170 = 0; v170 < 1; v170++) { + loop73: for (int v171 = 0; v171 < 32; v171++) { + loop74: for (int v172 = 0; v172 < 32; v172++) { + loop75: for (int v173 = 0; v173 < 8; v173++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v174 = 0; v174 < 8; v174++) { + loop77: for (int v175 = 0; v175 < 2; v175++) { + loop78: for (int v176 = 0; v176 < 2; v176++) { + loop79: for (int v177 = 0; v177 < 2; v177++) { + if ((v176 + (v172 * 2)) == 0) { + float v178 = v163[v174][v175][v177].read(); + v169[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v177 + (v173 * 2))] = v178; + } + float v179 = v169[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v177 + (v173 * 2))]; + if ((v175 + (v171 * 2)) == 0) { + float v180 = v164[(v174 + (v170 * 8))][(v177 + (v173 * 2))][(v176 + (v172 * 2))]; + v168[(v174 + (v170 * 8))][(v177 + (v173 * 2))][(v176 + (v172 * 2))] = v180; + } + float v181 = v168[(v174 + (v170 * 8))][(v177 + (v173 * 2))][(v176 + (v172 * 2))]; + if ((v177 + (v173 * 2)) == 0) { + v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))] = v166; + } + float v182 = v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))]; + float v183 = v179 * v181; + float v184 = v182 + v183; + v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))] = v184; + if (((v177 + (v173 * 2)) - 15) == 0) { + float v185 = v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))]; + v165[v174][v175][v176].write(v185); + } + } + } + } + } + } + } + } + } + return ; +} + +void node14( + float v186[64][128], + float v187[8][16][64] +) { + #pragma HLS array_partition variable=v186 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v186 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v187 complete dim=1 + #pragma HLS array_partition variable=v187 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v187 cyclic dim=3 factor=2 + + loop80: for (int v188 = 0; v188 < 1; v188++) { + loop81: for (int v189 = 0; v189 < 8; v189++) { + loop82: for (int v190 = 0; v190 < 32; v190++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v191 = 0; v191 < 8; v191++) { + loop84: for (int v192 = 0; v192 < 2; v192++) { + loop85: for (int v193 = 0; v193 < 2; v193++) { + float v194 = v186[(v193 + (v190 * 2))][((((v191 * 16) + (v188 * 128)) + v192) + (v189 * 2))]; + v187[(v191 + (v188 * 8))][(v192 + (v189 * 2))][(v193 + (v190 * 2))] = v194; + } + } + } + } + } + } + return ; +} + +void node15( + float v195[64][128], + hls::stream v196[8][2][2] +) { + #pragma HLS array_partition variable=v195 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v195 cyclic dim=2 factor=8 + + loop86: for (int v197 = 0; v197 < 1; v197++) { + loop87: for (int v198 = 0; v198 < 32; v198++) { + loop88: for (int v199 = 0; v199 < 8; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v200 = 0; v200 < 8; v200++) { + loop90: for (int v201 = 0; v201 < 2; v201++) { + loop91: for (int v202 = 0; v202 < 2; v202++) { + float v203 = v195[(v201 + (v198 * 2))][((((v200 * 16) + (v197 * 128)) + v202) + (v199 * 2))]; + v196[v200][v201][v202].write(v203); + } + } + } + } + } + } + return ; +} + +void node16( + hls::stream v204[2][8], + float v205[128], + float v206[64][128] +) { + #pragma HLS array_partition variable=v205 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=8 + + loop92: for (int v207 = 0; v207 < 32; v207++) { + loop93: for (int v208 = 0; v208 < 16; v208++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop94: for (int v209 = 0; v209 < 2; v209++) { + loop95: for (int v210 = 0; v210 < 8; v210++) { + float v211 = v204[v209][v210].read(); + float v212 = v205[(v210 + (v208 * 8))]; + float v213 = v211 + v212; + v206[(v209 + (v207 * 2))][(v210 + (v208 * 8))] = v213; + } + } + } + } + return ; +} + +void node17( + hls::stream v214[2][4], + float v215[128][128], + hls::stream v216[2][8], + float v217 +) { + #pragma HLS array_partition variable=v215 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v215 cyclic dim=2 factor=8 + + float v218[64][128]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=8 + + float v219[128][128]; + #pragma HLS array_partition variable=v219 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v219 cyclic dim=2 factor=8 + + float v220[64][128]; + #pragma HLS array_partition variable=v220 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v220 cyclic dim=2 factor=4 + + loop96: for (int v221 = 0; v221 < 32; v221++) { + loop97: for (int v222 = 0; v222 < 16; v222++) { + loop98: for (int v223 = 0; v223 < 32; v223++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop99: for (int v224 = 0; v224 < 2; v224++) { + loop100: for (int v225 = 0; v225 < 8; v225++) { + loop101: for (int v226 = 0; v226 < 4; v226++) { + if ((v225 + (v222 * 8)) == 0) { + float v227 = v214[v224][v226].read(); + v220[(v224 + (v221 * 2))][(v226 + (v223 * 4))] = v227; + } + float v228 = v220[(v224 + (v221 * 2))][(v226 + (v223 * 4))]; + if ((v224 + (v221 * 2)) == 0) { + float v229 = v215[(v226 + (v223 * 4))][(v225 + (v222 * 8))]; + v219[(v226 + (v223 * 4))][(v225 + (v222 * 8))] = v229; + } + float v230 = v219[(v226 + (v223 * 4))][(v225 + (v222 * 8))]; + if ((v226 + (v223 * 4)) == 0) { + v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))] = v217; + } + float v231 = v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))]; + float v232 = v228 * v230; + float v233 = v231 + v232; + v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))] = v233; + if (((v226 + (v223 * 4)) - 127) == 0) { + float v234 = v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))]; + v216[v224][v225].write(v234); + } + } + } + } + } + } + } + return ; +} + +void node18( + float v235[128][128], + float v236[128][128] +) { + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v236 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v236 cyclic dim=2 factor=8 + + loop102: for (int v237 = 0; v237 < 32; v237++) { + loop103: for (int v238 = 0; v238 < 16; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop104: for (int v239 = 0; v239 < 4; v239++) { + loop105: for (int v240 = 0; v240 < 8; v240++) { + float v241 = v235[(v240 + (v238 * 8))][(v239 + (v237 * 4))]; + v236[(v239 + (v237 * 4))][(v240 + (v238 * 8))] = v241; + } + } + } + } + return ; +} + +void node19( + hls::stream v242[2][8], + float v243[128], + float v244[64][128] +) { + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=8 + + loop106: for (int v245 = 0; v245 < 32; v245++) { + loop107: for (int v246 = 0; v246 < 16; v246++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop108: for (int v247 = 0; v247 < 2; v247++) { + loop109: for (int v248 = 0; v248 < 8; v248++) { + float v249 = v242[v247][v248].read(); + float v250 = v243[(v248 + (v246 * 8))]; + float v251 = v249 + v250; + v244[(v247 + (v245 * 2))][(v248 + (v246 * 8))] = v251; + } + } + } + } + return ; +} + +void node20( + float v252[128][128], + hls::stream v253[2][4], + hls::stream v254[2][8], + float v255 +) { + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=8 + + float v256[64][128]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=8 + + float v257[128][128]; + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v257 cyclic dim=2 factor=8 + + float v258[64][128]; + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=4 + + loop110: for (int v259 = 0; v259 < 32; v259++) { + loop111: for (int v260 = 0; v260 < 16; v260++) { + loop112: for (int v261 = 0; v261 < 32; v261++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop113: for (int v262 = 0; v262 < 2; v262++) { + loop114: for (int v263 = 0; v263 < 8; v263++) { + loop115: for (int v264 = 0; v264 < 4; v264++) { + if ((v263 + (v260 * 8)) == 0) { + float v265 = v253[v262][v264].read(); + v258[(v262 + (v259 * 2))][(v264 + (v261 * 4))] = v265; + } + float v266 = v258[(v262 + (v259 * 2))][(v264 + (v261 * 4))]; + if ((v262 + (v259 * 2)) == 0) { + float v267 = v252[(v264 + (v261 * 4))][(v263 + (v260 * 8))]; + v257[(v264 + (v261 * 4))][(v263 + (v260 * 8))] = v267; + } + float v268 = v257[(v264 + (v261 * 4))][(v263 + (v260 * 8))]; + if ((v264 + (v261 * 4)) == 0) { + v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))] = v255; + } + float v269 = v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))]; + float v270 = v266 * v268; + float v271 = v269 + v270; + v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))] = v271; + if (((v264 + (v261 * 4)) - 127) == 0) { + float v272 = v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))]; + v254[v262][v263].write(v272); + } + } + } + } + } + } + } + return ; +} + +void node21( + float v273[128][128], + float v274[128][128] +) { + #pragma HLS array_partition variable=v273 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v273 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v274 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v274 cyclic dim=2 factor=8 + + loop116: for (int v275 = 0; v275 < 32; v275++) { + loop117: for (int v276 = 0; v276 < 16; v276++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop118: for (int v277 = 0; v277 < 4; v277++) { + loop119: for (int v278 = 0; v278 < 8; v278++) { + float v279 = v273[(v278 + (v276 * 8))][(v277 + (v275 * 4))]; + v274[(v277 + (v275 * 4))][(v278 + (v276 * 8))] = v279; + } + } + } + } + return ; +} + +void node22( + hls::stream v280[2][8], + float v281[128], + float v282[64][128] +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=8 + + loop120: for (int v283 = 0; v283 < 32; v283++) { + loop121: for (int v284 = 0; v284 < 16; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop122: for (int v285 = 0; v285 < 2; v285++) { + loop123: for (int v286 = 0; v286 < 8; v286++) { + float v287 = v280[v285][v286].read(); + float v288 = v281[(v286 + (v284 * 8))]; + float v289 = v287 + v288; + v282[(v285 + (v283 * 2))][(v286 + (v284 * 8))] = v289; + } + } + } + } + return ; +} + +void node23( + float v290[128][128], + hls::stream v291[2][4], + hls::stream v292[2][8], + float v293 +) { + #pragma HLS array_partition variable=v290 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v290 cyclic dim=2 factor=8 + + float v294[64][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=8 + + float v295[128][128]; + #pragma HLS array_partition variable=v295 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v295 cyclic dim=2 factor=8 + + float v296[64][128]; + #pragma HLS array_partition variable=v296 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v296 cyclic dim=2 factor=4 + + loop124: for (int v297 = 0; v297 < 32; v297++) { + loop125: for (int v298 = 0; v298 < 16; v298++) { + loop126: for (int v299 = 0; v299 < 32; v299++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop127: for (int v300 = 0; v300 < 2; v300++) { + loop128: for (int v301 = 0; v301 < 8; v301++) { + loop129: for (int v302 = 0; v302 < 4; v302++) { + if ((v301 + (v298 * 8)) == 0) { + float v303 = v291[v300][v302].read(); + v296[(v300 + (v297 * 2))][(v302 + (v299 * 4))] = v303; + } + float v304 = v296[(v300 + (v297 * 2))][(v302 + (v299 * 4))]; + if ((v300 + (v297 * 2)) == 0) { + float v305 = v290[(v302 + (v299 * 4))][(v301 + (v298 * 8))]; + v295[(v302 + (v299 * 4))][(v301 + (v298 * 8))] = v305; + } + float v306 = v295[(v302 + (v299 * 4))][(v301 + (v298 * 8))]; + if ((v302 + (v299 * 4)) == 0) { + v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))] = v293; + } + float v307 = v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))]; + float v308 = v304 * v306; + float v309 = v307 + v308; + v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))] = v309; + if (((v302 + (v299 * 4)) - 127) == 0) { + float v310 = v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))]; + v292[v300][v301].write(v310); + } + } + } + } + } + } + } + return ; +} + +void node24( + float v311[128][128], + float v312[128][128] +) { + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v312 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v312 cyclic dim=2 factor=8 + + loop130: for (int v313 = 0; v313 < 32; v313++) { + loop131: for (int v314 = 0; v314 < 16; v314++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop132: for (int v315 = 0; v315 < 4; v315++) { + loop133: for (int v316 = 0; v316 < 8; v316++) { + float v317 = v311[(v316 + (v314 * 8))][(v315 + (v313 * 4))]; + v312[(v315 + (v313 * 4))][(v316 + (v314 * 8))] = v317; + } + } + } + } + return ; +} + +void node25( + float v318[1][64][128], + hls::stream v319[2][4], + hls::stream v320[2][4], + hls::stream v321[2][4] +) { + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v318 cyclic dim=3 factor=4 + + loop134: for (int v322 = 0; v322 < 32; v322++) { + loop135: for (int v323 = 0; v323 < 32; v323++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v324 = 0; v324 < 2; v324++) { + loop137: for (int v325 = 0; v325 < 4; v325++) { + float v326 = v318[0][(v324 + (v322 * 2))][(v325 + (v323 * 4))]; + v319[v324][v325].write(v326); + v320[v324][v325].write(v326); + v321[v324][v325].write(v326); + } + } + } + } + return ; +} + +void forward( + float v327[1][64][128], + float v328[128], + float v329[128][128], + float v330[128], + float v331[128][128], + float v332[128], + float v333[128][128], + float v334[128], + float v335[128][128], + float v336[1][64][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v327 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v327 cyclic dim=3 factor=4 + + #pragma HLS array_partition variable=v328 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v329 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v329 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v330 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v331 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v331 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v332 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v333 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v333 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v334 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v335 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v335 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v336 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v336 cyclic dim=3 factor=8 + + hls::stream v337[8][8]; + #pragma HLS STREAM variable=v337 depth=128 + hls::stream v338[8][8]; + #pragma HLS STREAM variable=v338 depth=128 + float v339[128][128]; + #pragma HLS array_partition variable=v339 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v339 cyclic dim=2 factor=8 + + hls::stream v340[8][2]; + #pragma HLS STREAM variable=v340 depth=512 + float v341[64][8][16]; + #pragma HLS array_partition variable=v341 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v341 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=3 factor=2 + + float v342[8][64][16]; + #pragma HLS array_partition variable=v342 complete dim=1 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=3 factor=2 + + float v343[8][64][16]; + #pragma HLS array_partition variable=v343 complete dim=1 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=3 factor=2 + + hls::stream v344[8][2][2]; + #pragma HLS STREAM variable=v344 depth=1024 + hls::stream v345[8][2]; + #pragma HLS STREAM variable=v345 depth=32 + hls::stream v346[8][2][2]; + #pragma HLS STREAM variable=v346 depth=1024 + hls::stream v347[8][2][2]; + #pragma HLS STREAM variable=v347 depth=1024 + hls::stream v348[8][2]; + #pragma HLS STREAM variable=v348 depth=32 + hls::stream v349[8][2][2]; + #pragma HLS STREAM variable=v349 depth=1024 + hls::stream v350[8][2][2]; + #pragma HLS STREAM variable=v350 depth=1024 + hls::stream v351[8][2][2]; + #pragma HLS STREAM variable=v351 depth=1024 + float v352[8][16][64]; + #pragma HLS array_partition variable=v352 complete dim=1 + #pragma HLS array_partition variable=v352 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v352 cyclic dim=3 factor=2 + + hls::stream v353[8][2][2]; + #pragma HLS STREAM variable=v353 depth=256 + float v354[64][128]; + #pragma HLS array_partition variable=v354 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v354 cyclic dim=2 factor=8 + + hls::stream v355[2][8]; + #pragma HLS STREAM variable=v355 depth=512 + float v356[128][128]; + #pragma HLS array_partition variable=v356 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v356 cyclic dim=2 factor=8 + + float v357[64][128]; + #pragma HLS array_partition variable=v357 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v357 cyclic dim=2 factor=8 + + hls::stream v358[2][8]; + #pragma HLS STREAM variable=v358 depth=512 + float v359[128][128]; + #pragma HLS array_partition variable=v359 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v359 cyclic dim=2 factor=8 + + float v360[64][128]; + #pragma HLS array_partition variable=v360 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v360 cyclic dim=2 factor=8 + + hls::stream v361[2][8]; + #pragma HLS STREAM variable=v361 depth=512 + float v362[128][128]; + #pragma HLS array_partition variable=v362 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v362 cyclic dim=2 factor=8 + + hls::stream v363[2][4]; + #pragma HLS STREAM variable=v363 depth=1024 + hls::stream v364[2][4]; + #pragma HLS STREAM variable=v364 depth=1024 + hls::stream v365[2][4]; + #pragma HLS STREAM variable=v365 depth=1024 + node25(v327, v365, v364, v363); + node24(v329, v362); + node23(v362, v363, v361, 0.000000); + node22(v361, v328, v360); + node21(v331, v359); + node20(v359, v364, v358, 0.000000); + node19(v358, v330, v357); + node18(v333, v356); + node17(v365, v356, v355, 0.000000); + node16(v355, v332, v354); + node15(v360, v353); + node14(v357, v352); + node13(v353, v352, v351, 0.000000); + node12(v351, v350, v349, 4.000000); + node11(v350, v348, -INFINITY); + node10(v349, v348, v347, v346); + node9(v347, v345, 0.000000); + node8(v346, v345, v344); + node7(v354, v343); + node6(v344, v343, v342, 0.000000); + node5(v342, v341); + node4(v341, v340); + node3(v335, v339); + node2(v340, v339, v338, 0.000000); + node1(v338, v334, v337); + node0(v337, v336); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..76d359640c8d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,1064 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][32], + float v1[1][64][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=32 + + loop0: for (int v2 = 0; v2 < 4; v2++) { + loop1: for (int v3 = 0; v3 < 32; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 32; v4++) { + loop3: for (int v5 = 0; v5 < 2; v5++) { + float v6 = v0[v5][v4].read(); + v1[0][(v5 + (v3 * 2))][(v4 + (v2 * 32))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][32], + float v8[128], + hls::stream v9[2][32] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=32 + + loop4: for (int v10 = 0; v10 < 4; v10++) { + loop5: for (int v11 = 0; v11 < 32; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 32; v12++) { + loop7: for (int v13 = 0; v13 < 2; v13++) { + float v14 = v7[v13][v12].read(); + float v15 = v8[(v12 + (v10 * 32))]; + float v16 = v14 + v15; + v9[v13][v12].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[2][32], + hls::stream v18[2][2], + hls::stream v19[2][32], + float v20 +) { + float v21[64][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=32 + + float v22[128][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=32 + + float v23[64][128]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=2 + + loop8: for (int v24 = 0; v24 < 4; v24++) { + loop9: for (int v25 = 0; v25 < 64; v25++) { + loop10: for (int v26 = 0; v26 < 32; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 32; v27++) { + loop12: for (int v28 = 0; v28 < 2; v28++) { + loop13: for (int v29 = 0; v29 < 2; v29++) { + if ((v27 + (v24 * 32)) == 0) { + float v30 = v18[v29][v28].read(); + v23[(v29 + (v26 * 2))][(v28 + (v25 * 2))] = v30; + } + float v31 = v23[(v29 + (v26 * 2))][(v28 + (v25 * 2))]; + if ((v29 + (v26 * 2)) == 0) { + float v32 = v17[v28][v27].read(); + v22[(v28 + (v25 * 2))][(v27 + (v24 * 32))] = v32; + } + float v33 = v22[(v28 + (v25 * 2))][(v27 + (v24 * 32))]; + if ((v28 + (v25 * 2)) == 0) { + v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))] = v20; + } + float v34 = v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))] = v36; + if (((v28 + (v25 * 2)) - 127) == 0) { + float v37 = v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))]; + v19[v29][v27].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][128], + hls::stream v39[2][32] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=2 + + loop14: for (int v40 = 0; v40 < 4; v40++) { + loop15: for (int v41 = 0; v41 < 64; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 32; v42++) { + loop17: for (int v43 = 0; v43 < 2; v43++) { + float v44 = v38[(v42 + (v40 * 32))][(v43 + (v41 * 2))]; + v39[v43][v42].write(v44); + } + } + } + } + return ; +} + +void node4( + float v45[64][8][16], + hls::stream v46[2][2] +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=3 factor=4 + + loop18: for (int v47 = 0; v47 < 64; v47++) { + loop19: for (int v48 = 0; v48 < 32; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v49 = 0; v49 < 2; v49++) { + loop21: for (int v50 = 0; v50 < 2; v50++) { + float v51 = v45[(v50 + (v48 * 2))][(v47 / 8)][((v49 + (v47 * 2)) % 16)]; + v46[v50][v49].write(v51); + } + } + } + } + return ; +} + +void node5( + float v52[8][64][16], + float v53[64][8][16] +) { + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v52 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=3 factor=4 + + loop22: for (int v54 = 0; v54 < 4; v54++) { + loop23: for (int v55 = 0; v55 < 32; v55++) { + loop24: for (int v56 = 0; v56 < 4; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v57 = 0; v57 < 2; v57++) { + loop26: for (int v58 = 0; v58 < 2; v58++) { + loop27: for (int v59 = 0; v59 < 4; v59++) { + float v60 = v52[(v57 + (v54 * 2))][(v58 + (v55 * 2))][(v59 + (v56 * 4))]; + v53[(v58 + (v55 * 2))][(v57 + (v54 * 2))][(v59 + (v56 * 4))] = v60; + } + } + } + } + } + } + return ; +} + +void node6( + float v61[8][64][16], + hls::stream v62[2][4][4], + float v63[8][64][16], + float v64 +) { + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v61 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v63 cyclic dim=3 factor=2 + + float v65[8][64][16]; + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v65 cyclic dim=3 factor=2 + + float v66[8][64][16]; + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v66 cyclic dim=3 factor=2 + + float v67[8][64][64]; + #pragma HLS array_partition variable=v67 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v67 cyclic dim=3 factor=4 + + loop28: for (int v68 = 0; v68 < 4; v68++) { + loop29: for (int v69 = 0; v69 < 16; v69++) { + loop30: for (int v70 = 0; v70 < 16; v70++) { + loop31: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop32: for (int v72 = 0; v72 < 2; v72++) { + loop33: for (int v73 = 0; v73 < 4; v73++) { + loop34: for (int v74 = 0; v74 < 4; v74++) { + loop35: for (int v75 = 0; v75 < 2; v75++) { + if ((v75 + (v71 * 2)) == 0) { + float v76 = v62[v72][v74][v73].read(); + v67[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v73 + (v69 * 4))] = v76; + } + float v77 = v67[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v73 + (v69 * 4))]; + if ((v74 + (v70 * 4)) == 0) { + float v78 = v61[(v72 + (v68 * 2))][(v73 + (v69 * 4))][(v75 + (v71 * 2))]; + v66[(v72 + (v68 * 2))][(v73 + (v69 * 4))][(v75 + (v71 * 2))] = v78; + } + float v79 = v66[(v72 + (v68 * 2))][(v73 + (v69 * 4))][(v75 + (v71 * 2))]; + if ((v73 + (v69 * 4)) == 0) { + v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))] = v64; + } + float v80 = v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))]; + float v81 = v77 * v79; + float v82 = v80 + v81; + v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))] = v82; + if (((v73 + (v69 * 4)) - 63) == 0) { + float v83 = v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))]; + v63[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))] = v83; + } + } + } + } + } + } + } + } + } + return ; +} + +void node7( + float v84[64][128], + float v85[8][64][16] +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v85 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v85 cyclic dim=3 factor=2 + + loop36: for (int v86 = 0; v86 < 4; v86++) { + loop37: for (int v87 = 0; v87 < 8; v87++) { + loop38: for (int v88 = 0; v88 < 16; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v89 = 0; v89 < 2; v89++) { + loop40: for (int v90 = 0; v90 < 2; v90++) { + loop41: for (int v91 = 0; v91 < 4; v91++) { + float v92 = v84[(v91 + (v88 * 4))][((((v89 * 16) + (v86 * 32)) + v90) + (v87 * 2))]; + v85[(v89 + (v86 * 2))][(v91 + (v88 * 4))][(v90 + (v87 * 2))] = v92; + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v93[2][4][4], + hls::stream v94[2][4], + hls::stream v95[2][4][4] +) { + float v96[8][64]; + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=4 + + loop42: for (int v97 = 0; v97 < 4; v97++) { + loop43: for (int v98 = 0; v98 < 16; v98++) { + loop44: for (int v99 = 0; v99 < 16; v99++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop45: for (int v100 = 0; v100 < 2; v100++) { + loop46: for (int v101 = 0; v101 < 4; v101++) { + loop47: for (int v102 = 0; v102 < 4; v102++) { + float v103 = v93[v100][v102][v101].read(); + if ((v101 + (v98 * 4)) == 0) { + float v104 = v94[v100][v102].read(); + v96[(v100 + (v97 * 2))][(v102 + (v99 * 4))] = v104; + } + float v105 = v96[(v100 + (v97 * 2))][(v102 + (v99 * 4))]; + float v106 = v103 / v105; + v95[v100][v102][v101].write(v106); + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v107[2][4][4], + hls::stream v108[2][4], + float v109 +) { + float v110[8][64]; + #pragma HLS array_partition variable=v110 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=4 + + loop48: for (int v111 = 0; v111 < 4; v111++) { + loop49: for (int v112 = 0; v112 < 16; v112++) { + loop50: for (int v113 = 0; v113 < 16; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v114 = 0; v114 < 2; v114++) { + loop52: for (int v115 = 0; v115 < 4; v115++) { + loop53: for (int v116 = 0; v116 < 4; v116++) { + float v117 = v107[v114][v116][v115].read(); + if ((v115 + (v112 * 4)) == 0) { + v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))] = v109; + } + float v118 = v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))]; + float v119 = v117 + v118; + v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))] = v119; + if (((v115 + (v112 * 4)) - 63) == 0) { + float v120 = v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))]; + v108[v114][v116].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v121[2][4][4], + hls::stream v122[2][4], + hls::stream v123[2][4][4], + hls::stream v124[2][4][4] +) { + float v125[8][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop54: for (int v126 = 0; v126 < 4; v126++) { + loop55: for (int v127 = 0; v127 < 16; v127++) { + loop56: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v129 = 0; v129 < 2; v129++) { + loop58: for (int v130 = 0; v130 < 4; v130++) { + loop59: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[v129][v131][v130].read(); + if ((v130 + (v127 * 4)) == 0) { + float v133 = v122[v129][v131].read(); + v125[(v129 + (v126 * 2))][(v131 + (v128 * 4))] = v133; + } + float v134 = v125[(v129 + (v126 * 2))][(v131 + (v128 * 4))]; + float v135 = v132 - v134; + float v136 = exp(v135); + v123[v129][v131][v130].write(v136); + v124[v129][v131][v130].write(v136); + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v137[2][4][4], + hls::stream v138[2][4], + float v139 +) { + float v140[8][64]; + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + loop60: for (int v141 = 0; v141 < 4; v141++) { + loop61: for (int v142 = 0; v142 < 16; v142++) { + loop62: for (int v143 = 0; v143 < 16; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v144 = 0; v144 < 2; v144++) { + loop64: for (int v145 = 0; v145 < 4; v145++) { + loop65: for (int v146 = 0; v146 < 4; v146++) { + float v147 = v137[v144][v146][v145].read(); + if ((v145 + (v142 * 4)) == 0) { + v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))] = v139; + } + float v148 = v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))]; + float v149 = fmax(v147, v148); + v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))] = v149; + if (((v145 + (v142 * 4)) - 63) == 0) { + float v150 = v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))]; + v138[v144][v146].write(v150); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v151[2][4][4], + hls::stream v152[2][4][4], + hls::stream v153[2][4][4], + float v154 +) { + loop66: for (int v155 = 0; v155 < 4; v155++) { + loop67: for (int v156 = 0; v156 < 16; v156++) { + loop68: for (int v157 = 0; v157 < 16; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop69: for (int v158 = 0; v158 < 2; v158++) { + loop70: for (int v159 = 0; v159 < 4; v159++) { + loop71: for (int v160 = 0; v160 < 4; v160++) { + float v161 = v151[v158][v160][v159].read(); + float v162 = v161 / v154; + v152[v158][v160][v159].write(v162); + v153[v158][v160][v159].write(v162); + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v163[2][4][2], + hls::stream v164[2][2][4], + hls::stream v165[2][4][4], + float v166 +) { + float v167[8][64][64]; + #pragma HLS array_partition variable=v167 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v167 cyclic dim=3 factor=4 + + float v168[8][16][64]; + #pragma HLS array_partition variable=v168 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=3 factor=4 + + float v169[8][64][16]; + #pragma HLS array_partition variable=v169 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v169 cyclic dim=3 factor=2 + + loop72: for (int v170 = 0; v170 < 4; v170++) { + loop73: for (int v171 = 0; v171 < 8; v171++) { + loop74: for (int v172 = 0; v172 < 16; v172++) { + loop75: for (int v173 = 0; v173 < 16; v173++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v174 = 0; v174 < 2; v174++) { + loop77: for (int v175 = 0; v175 < 2; v175++) { + loop78: for (int v176 = 0; v176 < 4; v176++) { + loop79: for (int v177 = 0; v177 < 4; v177++) { + if ((v176 + (v172 * 4)) == 0) { + float v178 = v163[v174][v177][v175].read(); + v169[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v175 + (v171 * 2))] = v178; + } + float v179 = v169[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v175 + (v171 * 2))]; + if ((v177 + (v173 * 4)) == 0) { + float v180 = v164[v174][v175][v176].read(); + v168[(v174 + (v170 * 2))][(v175 + (v171 * 2))][(v176 + (v172 * 4))] = v180; + } + float v181 = v168[(v174 + (v170 * 2))][(v175 + (v171 * 2))][(v176 + (v172 * 4))]; + if ((v175 + (v171 * 2)) == 0) { + v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))] = v166; + } + float v182 = v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))]; + float v183 = v179 * v181; + float v184 = v182 + v183; + v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))] = v184; + if (((v175 + (v171 * 2)) - 15) == 0) { + float v185 = v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))]; + v165[v174][v177][v176].write(v185); + } + } + } + } + } + } + } + } + } + return ; +} + +void node14( + float v186[64][128], + hls::stream v187[2][2][4] +) { + #pragma HLS array_partition variable=v186 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v186 cyclic dim=2 factor=2 + + loop80: for (int v188 = 0; v188 < 4; v188++) { + loop81: for (int v189 = 0; v189 < 8; v189++) { + loop82: for (int v190 = 0; v190 < 16; v190++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v191 = 0; v191 < 2; v191++) { + loop84: for (int v192 = 0; v192 < 2; v192++) { + loop85: for (int v193 = 0; v193 < 4; v193++) { + float v194 = v186[(v193 + (v190 * 4))][((((v191 * 16) + (v188 * 32)) + v192) + (v189 * 2))]; + v187[v191][v192][v193].write(v194); + } + } + } + } + } + } + return ; +} + +void node15( + float v195[64][128], + hls::stream v196[2][4][2] +) { + #pragma HLS array_partition variable=v195 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v195 cyclic dim=2 factor=2 + + loop86: for (int v197 = 0; v197 < 4; v197++) { + loop87: for (int v198 = 0; v198 < 8; v198++) { + loop88: for (int v199 = 0; v199 < 16; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v200 = 0; v200 < 2; v200++) { + loop90: for (int v201 = 0; v201 < 2; v201++) { + loop91: for (int v202 = 0; v202 < 4; v202++) { + float v203 = v195[(v202 + (v199 * 4))][((((v200 * 16) + (v197 * 32)) + v201) + (v198 * 2))]; + v196[v200][v202][v201].write(v203); + } + } + } + } + } + } + return ; +} + +void node16( + hls::stream v204[4][2], + float v205[128], + float v206[64][128] +) { + #pragma HLS array_partition variable=v205 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=2 + + loop92: for (int v207 = 0; v207 < 16; v207++) { + loop93: for (int v208 = 0; v208 < 64; v208++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop94: for (int v209 = 0; v209 < 4; v209++) { + loop95: for (int v210 = 0; v210 < 2; v210++) { + float v211 = v204[v209][v210].read(); + float v212 = v205[(v210 + (v208 * 2))]; + float v213 = v211 + v212; + v206[(v209 + (v207 * 4))][(v210 + (v208 * 2))] = v213; + } + } + } + } + return ; +} + +void node17( + hls::stream v214[8][2], + hls::stream v215[4][8], + hls::stream v216[4][2], + float v217 +) { + float v218[64][128]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=2 + + float v219[128][128]; + #pragma HLS array_partition variable=v219 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v219 cyclic dim=2 factor=2 + + float v220[64][128]; + #pragma HLS array_partition variable=v220 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v220 cyclic dim=2 factor=8 + + loop96: for (int v221 = 0; v221 < 16; v221++) { + loop97: for (int v222 = 0; v222 < 16; v222++) { + loop98: for (int v223 = 0; v223 < 64; v223++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop99: for (int v224 = 0; v224 < 4; v224++) { + loop100: for (int v225 = 0; v225 < 8; v225++) { + loop101: for (int v226 = 0; v226 < 2; v226++) { + if ((v226 + (v223 * 2)) == 0) { + float v227 = v215[v224][v225].read(); + v220[(v224 + (v221 * 4))][(v225 + (v222 * 8))] = v227; + } + float v228 = v220[(v224 + (v221 * 4))][(v225 + (v222 * 8))]; + if ((v224 + (v221 * 4)) == 0) { + float v229 = v214[v225][v226].read(); + v219[(v225 + (v222 * 8))][(v226 + (v223 * 2))] = v229; + } + float v230 = v219[(v225 + (v222 * 8))][(v226 + (v223 * 2))]; + if ((v225 + (v222 * 8)) == 0) { + v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))] = v217; + } + float v231 = v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))]; + float v232 = v228 * v230; + float v233 = v231 + v232; + v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))] = v233; + if (((v225 + (v222 * 8)) - 127) == 0) { + float v234 = v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))]; + v216[v224][v226].write(v234); + } + } + } + } + } + } + } + return ; +} + +void node18( + float v235[128][128], + hls::stream v236[8][2] +) { + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=8 + + loop102: for (int v237 = 0; v237 < 16; v237++) { + loop103: for (int v238 = 0; v238 < 64; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop104: for (int v239 = 0; v239 < 8; v239++) { + loop105: for (int v240 = 0; v240 < 2; v240++) { + float v241 = v235[(v240 + (v238 * 2))][(v239 + (v237 * 8))]; + v236[v239][v240].write(v241); + } + } + } + } + return ; +} + +void node19( + hls::stream v242[4][2], + float v243[128], + float v244[64][128] +) { + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=2 + + loop106: for (int v245 = 0; v245 < 16; v245++) { + loop107: for (int v246 = 0; v246 < 64; v246++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop108: for (int v247 = 0; v247 < 4; v247++) { + loop109: for (int v248 = 0; v248 < 2; v248++) { + float v249 = v242[v247][v248].read(); + float v250 = v243[(v248 + (v246 * 2))]; + float v251 = v249 + v250; + v244[(v247 + (v245 * 4))][(v248 + (v246 * 2))] = v251; + } + } + } + } + return ; +} + +void node20( + hls::stream v252[8][2], + hls::stream v253[4][8], + hls::stream v254[4][2], + float v255 +) { + float v256[64][128]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=2 + + float v257[128][128]; + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v257 cyclic dim=2 factor=2 + + float v258[64][128]; + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=8 + + loop110: for (int v259 = 0; v259 < 16; v259++) { + loop111: for (int v260 = 0; v260 < 16; v260++) { + loop112: for (int v261 = 0; v261 < 64; v261++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop113: for (int v262 = 0; v262 < 4; v262++) { + loop114: for (int v263 = 0; v263 < 8; v263++) { + loop115: for (int v264 = 0; v264 < 2; v264++) { + if ((v264 + (v261 * 2)) == 0) { + float v265 = v253[v262][v263].read(); + v258[(v262 + (v259 * 4))][(v263 + (v260 * 8))] = v265; + } + float v266 = v258[(v262 + (v259 * 4))][(v263 + (v260 * 8))]; + if ((v262 + (v259 * 4)) == 0) { + float v267 = v252[v263][v264].read(); + v257[(v263 + (v260 * 8))][(v264 + (v261 * 2))] = v267; + } + float v268 = v257[(v263 + (v260 * 8))][(v264 + (v261 * 2))]; + if ((v263 + (v260 * 8)) == 0) { + v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))] = v255; + } + float v269 = v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))]; + float v270 = v266 * v268; + float v271 = v269 + v270; + v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))] = v271; + if (((v263 + (v260 * 8)) - 127) == 0) { + float v272 = v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))]; + v254[v262][v264].write(v272); + } + } + } + } + } + } + } + return ; +} + +void node21( + float v273[128][128], + hls::stream v274[8][2] +) { + #pragma HLS array_partition variable=v273 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v273 cyclic dim=2 factor=8 + + loop116: for (int v275 = 0; v275 < 16; v275++) { + loop117: for (int v276 = 0; v276 < 64; v276++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop118: for (int v277 = 0; v277 < 8; v277++) { + loop119: for (int v278 = 0; v278 < 2; v278++) { + float v279 = v273[(v278 + (v276 * 2))][(v277 + (v275 * 8))]; + v274[v277][v278].write(v279); + } + } + } + } + return ; +} + +void node22( + hls::stream v280[4][2], + float v281[128], + float v282[64][128] +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=2 + + loop120: for (int v283 = 0; v283 < 16; v283++) { + loop121: for (int v284 = 0; v284 < 64; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop122: for (int v285 = 0; v285 < 4; v285++) { + loop123: for (int v286 = 0; v286 < 2; v286++) { + float v287 = v280[v285][v286].read(); + float v288 = v281[(v286 + (v284 * 2))]; + float v289 = v287 + v288; + v282[(v285 + (v283 * 4))][(v286 + (v284 * 2))] = v289; + } + } + } + } + return ; +} + +void node23( + hls::stream v290[8][2], + hls::stream v291[4][8], + hls::stream v292[4][2], + float v293 +) { + float v294[64][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=2 + + float v295[128][128]; + #pragma HLS array_partition variable=v295 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v295 cyclic dim=2 factor=2 + + float v296[64][128]; + #pragma HLS array_partition variable=v296 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v296 cyclic dim=2 factor=8 + + loop124: for (int v297 = 0; v297 < 16; v297++) { + loop125: for (int v298 = 0; v298 < 16; v298++) { + loop126: for (int v299 = 0; v299 < 64; v299++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop127: for (int v300 = 0; v300 < 4; v300++) { + loop128: for (int v301 = 0; v301 < 8; v301++) { + loop129: for (int v302 = 0; v302 < 2; v302++) { + if ((v302 + (v299 * 2)) == 0) { + float v303 = v291[v300][v301].read(); + v296[(v300 + (v297 * 4))][(v301 + (v298 * 8))] = v303; + } + float v304 = v296[(v300 + (v297 * 4))][(v301 + (v298 * 8))]; + if ((v300 + (v297 * 4)) == 0) { + float v305 = v290[v301][v302].read(); + v295[(v301 + (v298 * 8))][(v302 + (v299 * 2))] = v305; + } + float v306 = v295[(v301 + (v298 * 8))][(v302 + (v299 * 2))]; + if ((v301 + (v298 * 8)) == 0) { + v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))] = v293; + } + float v307 = v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))]; + float v308 = v304 * v306; + float v309 = v307 + v308; + v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))] = v309; + if (((v301 + (v298 * 8)) - 127) == 0) { + float v310 = v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))]; + v292[v300][v302].write(v310); + } + } + } + } + } + } + } + return ; +} + +void node24( + float v311[128][128], + hls::stream v312[8][2] +) { + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=8 + + loop130: for (int v313 = 0; v313 < 16; v313++) { + loop131: for (int v314 = 0; v314 < 64; v314++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop132: for (int v315 = 0; v315 < 8; v315++) { + loop133: for (int v316 = 0; v316 < 2; v316++) { + float v317 = v311[(v316 + (v314 * 2))][(v315 + (v313 * 8))]; + v312[v315][v316].write(v317); + } + } + } + } + return ; +} + +void node25( + float v318[1][64][128], + hls::stream v319[4][8], + hls::stream v320[4][8], + hls::stream v321[4][8] +) { + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v318 cyclic dim=3 factor=8 + + loop134: for (int v322 = 0; v322 < 16; v322++) { + loop135: for (int v323 = 0; v323 < 16; v323++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v324 = 0; v324 < 4; v324++) { + loop137: for (int v325 = 0; v325 < 8; v325++) { + float v326 = v318[0][(v324 + (v322 * 4))][(v325 + (v323 * 8))]; + v319[v324][v325].write(v326); + v320[v324][v325].write(v326); + v321[v324][v325].write(v326); + } + } + } + } + return ; +} + +void forward( + float v327[1][64][128], + float v328[128], + float v329[128][128], + float v330[128], + float v331[128][128], + float v332[128], + float v333[128][128], + float v334[128], + float v335[128][128], + float v336[1][64][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v327 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v327 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v328 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v329 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v329 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v330 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v331 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v331 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v332 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v333 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v333 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v334 cyclic dim=1 factor=32 + + #pragma HLS array_partition variable=v335 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v335 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v336 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v336 cyclic dim=3 factor=32 + + hls::stream v337[2][32]; + #pragma HLS STREAM variable=v337 depth=128 + hls::stream v338[2][32]; + #pragma HLS STREAM variable=v338 depth=128 + hls::stream v339[2][32]; + #pragma HLS STREAM variable=v339 depth=256 + hls::stream v340[2][2]; + #pragma HLS STREAM variable=v340 depth=2048 + float v341[64][8][16]; + #pragma HLS array_partition variable=v341 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=3 factor=4 + + float v342[8][64][16]; + #pragma HLS array_partition variable=v342 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v342 cyclic dim=3 factor=2 + + float v343[8][64][16]; + #pragma HLS array_partition variable=v343 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v343 cyclic dim=3 factor=2 + + hls::stream v344[2][4][4]; + #pragma HLS STREAM variable=v344 depth=1024 + hls::stream v345[2][4]; + #pragma HLS STREAM variable=v345 depth=64 + hls::stream v346[2][4][4]; + #pragma HLS STREAM variable=v346 depth=1024 + hls::stream v347[2][4][4]; + #pragma HLS STREAM variable=v347 depth=1024 + hls::stream v348[2][4]; + #pragma HLS STREAM variable=v348 depth=64 + hls::stream v349[2][4][4]; + #pragma HLS STREAM variable=v349 depth=1024 + hls::stream v350[2][4][4]; + #pragma HLS STREAM variable=v350 depth=1024 + hls::stream v351[2][4][4]; + #pragma HLS STREAM variable=v351 depth=1024 + hls::stream v352[2][2][4]; + #pragma HLS STREAM variable=v352 depth=512 + hls::stream v353[2][4][2]; + #pragma HLS STREAM variable=v353 depth=512 + float v354[64][128]; + #pragma HLS array_partition variable=v354 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v354 cyclic dim=2 factor=2 + + hls::stream v355[4][2]; + #pragma HLS STREAM variable=v355 depth=1024 + hls::stream v356[8][2]; + #pragma HLS STREAM variable=v356 depth=1024 + float v357[64][128]; + #pragma HLS array_partition variable=v357 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v357 cyclic dim=2 factor=2 + + hls::stream v358[4][2]; + #pragma HLS STREAM variable=v358 depth=1024 + hls::stream v359[8][2]; + #pragma HLS STREAM variable=v359 depth=1024 + float v360[64][128]; + #pragma HLS array_partition variable=v360 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v360 cyclic dim=2 factor=2 + + hls::stream v361[4][2]; + #pragma HLS STREAM variable=v361 depth=1024 + hls::stream v362[8][2]; + #pragma HLS STREAM variable=v362 depth=1024 + hls::stream v363[4][8]; + #pragma HLS STREAM variable=v363 depth=256 + hls::stream v364[4][8]; + #pragma HLS STREAM variable=v364 depth=256 + hls::stream v365[4][8]; + #pragma HLS STREAM variable=v365 depth=256 + node25(v327, v365, v364, v363); + node24(v329, v362); + node23(v362, v363, v361, 0.000000); + node22(v361, v328, v360); + node21(v331, v359); + node20(v359, v364, v358, 0.000000); + node19(v358, v330, v357); + node18(v333, v356); + node17(v356, v365, v355, 0.000000); + node16(v355, v332, v354); + node15(v360, v353); + node14(v357, v352); + node13(v353, v352, v351, 0.000000); + node12(v351, v350, v349, 4.000000); + node11(v350, v348, -INFINITY); + node10(v349, v348, v347, v346); + node9(v347, v345, 0.000000); + node8(v346, v345, v344); + node7(v354, v343); + node6(v343, v344, v342, 0.000000); + node5(v342, v341); + node4(v341, v340); + node3(v335, v339); + node2(v339, v340, v338, 0.000000); + node1(v338, v334, v337); + node0(v337, v336); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..068e4e9f9ef8 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,1086 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[8][8], + float v1[1][64][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 8; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 8; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 8))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[8][8], + float v8[128], + hls::stream v9[8][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 8; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 8; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[2][8], + hls::stream v18[8][2], + hls::stream v19[8][8], + float v20 +) { + float v21[64][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[128][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[64][128]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=2 + + loop8: for (int v24 = 0; v24 < 8; v24++) { + loop9: for (int v25 = 0; v25 < 64; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 8; v27++) { + loop12: for (int v28 = 0; v28 < 2; v28++) { + loop13: for (int v29 = 0; v29 < 8; v29++) { + if ((v29 + (v26 * 8)) == 0) { + float v30 = v18[v27][v28].read(); + v23[(v27 + (v24 * 8))][(v28 + (v25 * 2))] = v30; + } + float v31 = v23[(v27 + (v24 * 8))][(v28 + (v25 * 2))]; + if ((v27 + (v24 * 8)) == 0) { + float v32 = v17[v28][v29].read(); + v22[(v28 + (v25 * 2))][(v29 + (v26 * 8))] = v32; + } + float v33 = v22[(v28 + (v25 * 2))][(v29 + (v26 * 8))]; + if ((v28 + (v25 * 2)) == 0) { + v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))] = v36; + if (((v28 + (v25 * 2)) - 127) == 0) { + float v37 = v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))]; + v19[v27][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][128], + hls::stream v39[2][8] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=2 + + loop14: for (int v40 = 0; v40 < 64; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 2; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 2))]; + v39[v42][v43].write(v44); + } + } + } + } + return ; +} + +void node4( + float v45[64][8][16], + hls::stream v46[8][2] +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=3 factor=2 + + loop18: for (int v47 = 0; v47 < 8; v47++) { + loop19: for (int v48 = 0; v48 < 64; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v49 = 0; v49 < 8; v49++) { + loop21: for (int v50 = 0; v50 < 2; v50++) { + float v51 = v45[(v49 + (v47 * 8))][(v48 / 8)][((v50 + (v48 * 2)) % 16)]; + v46[v49][v50].write(v51); + } + } + } + } + return ; +} + +void node5( + float v52[8][64][16], + float v53[64][8][16] +) { + #pragma HLS array_partition variable=v52 complete dim=1 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=3 factor=2 + + loop22: for (int v54 = 0; v54 < 8; v54++) { + loop23: for (int v55 = 0; v55 < 4; v55++) { + loop24: for (int v56 = 0; v56 < 8; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v57 = 0; v57 < 8; v57++) { + loop26: for (int v58 = 0; v58 < 2; v58++) { + loop27: for (int v59 = 0; v59 < 2; v59++) { + float v60 = v52[(v58 + (v55 * 2))][(v57 + (v54 * 8))][(v59 + (v56 * 2))]; + v53[(v57 + (v54 * 8))][(v58 + (v55 * 2))][(v59 + (v56 * 2))] = v60; + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v61[8][2][2], + float v62[8][64][16], + float v63[8][64][16], + float v64 +) { + #pragma HLS array_partition variable=v62 complete dim=1 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v63 complete dim=1 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=3 factor=2 + + float v65[8][64][16]; + #pragma HLS array_partition variable=v65 complete dim=1 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v65 cyclic dim=3 factor=2 + + float v66[8][64][16]; + #pragma HLS array_partition variable=v66 complete dim=1 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v66 cyclic dim=3 factor=2 + + float v67[8][64][64]; + #pragma HLS array_partition variable=v67 complete dim=1 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=3 factor=2 + + loop28: for (int v68 = 0; v68 < 32; v68++) { + loop29: for (int v69 = 0; v69 < 32; v69++) { + loop30: for (int v70 = 0; v70 < 1; v70++) { + loop31: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop32: for (int v72 = 0; v72 < 2; v72++) { + loop33: for (int v73 = 0; v73 < 2; v73++) { + loop34: for (int v74 = 0; v74 < 8; v74++) { + loop35: for (int v75 = 0; v75 < 2; v75++) { + if ((v75 + (v71 * 2)) == 0) { + float v76 = v61[v74][v72][v73].read(); + v67[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v73 + (v69 * 2))] = v76; + } + float v77 = v67[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v73 + (v69 * 2))]; + if ((v72 + (v68 * 2)) == 0) { + float v78 = v62[(v74 + (v70 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))]; + v66[(v74 + (v70 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))] = v78; + } + float v79 = v66[(v74 + (v70 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))]; + if ((v73 + (v69 * 2)) == 0) { + v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))] = v64; + } + float v80 = v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))]; + float v81 = v77 * v79; + float v82 = v80 + v81; + v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))] = v82; + if (((v73 + (v69 * 2)) - 63) == 0) { + float v83 = v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))]; + v63[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))] = v83; + } + } + } + } + } + } + } + } + } + return ; +} + +void node7( + float v84[64][128], + float v85[8][64][16] +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v85 complete dim=1 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=3 factor=2 + + loop36: for (int v86 = 0; v86 < 8; v86++) { + loop37: for (int v87 = 0; v87 < 1; v87++) { + loop38: for (int v88 = 0; v88 < 32; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v89 = 0; v89 < 2; v89++) { + loop40: for (int v90 = 0; v90 < 8; v90++) { + loop41: for (int v91 = 0; v91 < 2; v91++) { + float v92 = v84[(v91 + (v88 * 2))][((((v90 * 16) + (v87 * 128)) + v89) + (v86 * 2))]; + v85[(v90 + (v87 * 8))][(v91 + (v88 * 2))][(v89 + (v86 * 2))] = v92; + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v93[8][2][2], + hls::stream v94[8][2], + hls::stream v95[8][2][2] +) { + float v96[8][64]; + #pragma HLS array_partition variable=v96 complete dim=1 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=2 + + loop42: for (int v97 = 0; v97 < 32; v97++) { + loop43: for (int v98 = 0; v98 < 32; v98++) { + loop44: for (int v99 = 0; v99 < 1; v99++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop45: for (int v100 = 0; v100 < 2; v100++) { + loop46: for (int v101 = 0; v101 < 2; v101++) { + loop47: for (int v102 = 0; v102 < 8; v102++) { + float v103 = v93[v102][v100][v101].read(); + if ((v101 + (v98 * 2)) == 0) { + float v104 = v94[v102][v100].read(); + v96[(v102 + (v99 * 8))][(v100 + (v97 * 2))] = v104; + } + float v105 = v96[(v102 + (v99 * 8))][(v100 + (v97 * 2))]; + float v106 = v103 / v105; + v95[v102][v100][v101].write(v106); + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v107[8][2][2], + hls::stream v108[8][2], + float v109 +) { + float v110[8][64]; + #pragma HLS array_partition variable=v110 complete dim=1 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=2 + + loop48: for (int v111 = 0; v111 < 32; v111++) { + loop49: for (int v112 = 0; v112 < 32; v112++) { + loop50: for (int v113 = 0; v113 < 1; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v114 = 0; v114 < 2; v114++) { + loop52: for (int v115 = 0; v115 < 2; v115++) { + loop53: for (int v116 = 0; v116 < 8; v116++) { + float v117 = v107[v116][v114][v115].read(); + if ((v115 + (v112 * 2)) == 0) { + v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))] = v109; + } + float v118 = v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))]; + float v119 = v117 + v118; + v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))] = v119; + if (((v115 + (v112 * 2)) - 63) == 0) { + float v120 = v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))]; + v108[v116][v114].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v121[8][2][2], + hls::stream v122[8][2], + hls::stream v123[8][2][2], + hls::stream v124[8][2][2] +) { + float v125[8][64]; + #pragma HLS array_partition variable=v125 complete dim=1 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=2 + + loop54: for (int v126 = 0; v126 < 32; v126++) { + loop55: for (int v127 = 0; v127 < 32; v127++) { + loop56: for (int v128 = 0; v128 < 1; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v129 = 0; v129 < 2; v129++) { + loop58: for (int v130 = 0; v130 < 2; v130++) { + loop59: for (int v131 = 0; v131 < 8; v131++) { + float v132 = v121[v131][v129][v130].read(); + if ((v130 + (v127 * 2)) == 0) { + float v133 = v122[v131][v129].read(); + v125[(v131 + (v128 * 8))][(v129 + (v126 * 2))] = v133; + } + float v134 = v125[(v131 + (v128 * 8))][(v129 + (v126 * 2))]; + float v135 = v132 - v134; + float v136 = exp(v135); + v123[v131][v129][v130].write(v136); + v124[v131][v129][v130].write(v136); + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v137[8][2][2], + hls::stream v138[8][2], + float v139 +) { + float v140[8][64]; + #pragma HLS array_partition variable=v140 complete dim=1 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=2 + + loop60: for (int v141 = 0; v141 < 32; v141++) { + loop61: for (int v142 = 0; v142 < 32; v142++) { + loop62: for (int v143 = 0; v143 < 1; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v144 = 0; v144 < 2; v144++) { + loop64: for (int v145 = 0; v145 < 2; v145++) { + loop65: for (int v146 = 0; v146 < 8; v146++) { + float v147 = v137[v146][v144][v145].read(); + if ((v145 + (v142 * 2)) == 0) { + v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))] = v139; + } + float v148 = v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))]; + float v149 = fmax(v147, v148); + v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))] = v149; + if (((v145 + (v142 * 2)) - 63) == 0) { + float v150 = v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))]; + v138[v146][v144].write(v150); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v151[8][2][2], + hls::stream v152[8][2][2], + hls::stream v153[8][2][2], + float v154 +) { + loop66: for (int v155 = 0; v155 < 32; v155++) { + loop67: for (int v156 = 0; v156 < 32; v156++) { + loop68: for (int v157 = 0; v157 < 1; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop69: for (int v158 = 0; v158 < 2; v158++) { + loop70: for (int v159 = 0; v159 < 2; v159++) { + loop71: for (int v160 = 0; v160 < 8; v160++) { + float v161 = v151[v160][v158][v159].read(); + float v162 = v161 / v154; + v152[v160][v158][v159].write(v162); + v153[v160][v158][v159].write(v162); + } + } + } + } + } + } + return ; +} + +void node13( + float v163[8][16][64], + float v164[8][64][16], + hls::stream v165[8][2][2], + float v166 +) { + #pragma HLS array_partition variable=v163 complete dim=1 + #pragma HLS array_partition variable=v163 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v163 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v164 complete dim=1 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v164 cyclic dim=3 factor=2 + + float v167[8][64][64]; + #pragma HLS array_partition variable=v167 complete dim=1 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v167 cyclic dim=3 factor=2 + + float v168[8][16][64]; + #pragma HLS array_partition variable=v168 complete dim=1 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=3 factor=2 + + float v169[8][64][16]; + #pragma HLS array_partition variable=v169 complete dim=1 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=3 factor=2 + + loop72: for (int v170 = 0; v170 < 32; v170++) { + loop73: for (int v171 = 0; v171 < 32; v171++) { + loop74: for (int v172 = 0; v172 < 8; v172++) { + loop75: for (int v173 = 0; v173 < 1; v173++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v174 = 0; v174 < 2; v174++) { + loop77: for (int v175 = 0; v175 < 2; v175++) { + loop78: for (int v176 = 0; v176 < 2; v176++) { + loop79: for (int v177 = 0; v177 < 8; v177++) { + if ((v175 + (v171 * 2)) == 0) { + float v178 = v164[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v176 + (v172 * 2))]; + v169[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v176 + (v172 * 2))] = v178; + } + float v179 = v169[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v176 + (v172 * 2))]; + if ((v174 + (v170 * 2)) == 0) { + float v180 = v163[(v177 + (v173 * 8))][(v176 + (v172 * 2))][(v175 + (v171 * 2))]; + v168[(v177 + (v173 * 8))][(v176 + (v172 * 2))][(v175 + (v171 * 2))] = v180; + } + float v181 = v168[(v177 + (v173 * 8))][(v176 + (v172 * 2))][(v175 + (v171 * 2))]; + if ((v176 + (v172 * 2)) == 0) { + v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))] = v166; + } + float v182 = v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))]; + float v183 = v179 * v181; + float v184 = v182 + v183; + v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))] = v184; + if (((v176 + (v172 * 2)) - 15) == 0) { + float v185 = v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))]; + v165[v177][v174][v175].write(v185); + } + } + } + } + } + } + } + } + } + return ; +} + +void node14( + float v186[64][128], + float v187[8][16][64] +) { + #pragma HLS array_partition variable=v186 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v186 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v187 complete dim=1 + #pragma HLS array_partition variable=v187 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v187 cyclic dim=3 factor=2 + + loop80: for (int v188 = 0; v188 < 8; v188++) { + loop81: for (int v189 = 0; v189 < 1; v189++) { + loop82: for (int v190 = 0; v190 < 32; v190++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v191 = 0; v191 < 2; v191++) { + loop84: for (int v192 = 0; v192 < 8; v192++) { + loop85: for (int v193 = 0; v193 < 2; v193++) { + float v194 = v186[(v193 + (v190 * 2))][((((v192 * 16) + (v189 * 128)) + v191) + (v188 * 2))]; + v187[(v192 + (v189 * 8))][(v191 + (v188 * 2))][(v193 + (v190 * 2))] = v194; + } + } + } + } + } + } + return ; +} + +void node15( + float v195[64][128], + float v196[8][64][16] +) { + #pragma HLS array_partition variable=v195 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v195 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v196 complete dim=1 + #pragma HLS array_partition variable=v196 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v196 cyclic dim=3 factor=2 + + loop86: for (int v197 = 0; v197 < 32; v197++) { + loop87: for (int v198 = 0; v198 < 1; v198++) { + loop88: for (int v199 = 0; v199 < 8; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v200 = 0; v200 < 2; v200++) { + loop90: for (int v201 = 0; v201 < 8; v201++) { + loop91: for (int v202 = 0; v202 < 2; v202++) { + float v203 = v195[(v200 + (v197 * 2))][((((v201 * 16) + (v198 * 128)) + v202) + (v199 * 2))]; + v196[(v201 + (v198 * 8))][(v200 + (v197 * 2))][(v202 + (v199 * 2))] = v203; + } + } + } + } + } + } + return ; +} + +void node16( + hls::stream v204[2][8], + float v205[128], + float v206[64][128] +) { + #pragma HLS array_partition variable=v205 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=8 + + loop92: for (int v207 = 0; v207 < 32; v207++) { + loop93: for (int v208 = 0; v208 < 16; v208++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop94: for (int v209 = 0; v209 < 2; v209++) { + loop95: for (int v210 = 0; v210 < 8; v210++) { + float v211 = v204[v209][v210].read(); + float v212 = v205[(v210 + (v208 * 8))]; + float v213 = v211 + v212; + v206[(v209 + (v207 * 2))][(v210 + (v208 * 8))] = v213; + } + } + } + } + return ; +} + +void node17( + hls::stream v214[4][8], + hls::stream v215[2][4], + hls::stream v216[2][8], + float v217 +) { + float v218[64][128]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=8 + + float v219[128][128]; + #pragma HLS array_partition variable=v219 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v219 cyclic dim=2 factor=8 + + float v220[64][128]; + #pragma HLS array_partition variable=v220 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v220 cyclic dim=2 factor=4 + + loop96: for (int v221 = 0; v221 < 32; v221++) { + loop97: for (int v222 = 0; v222 < 32; v222++) { + loop98: for (int v223 = 0; v223 < 16; v223++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop99: for (int v224 = 0; v224 < 4; v224++) { + loop100: for (int v225 = 0; v225 < 2; v225++) { + loop101: for (int v226 = 0; v226 < 8; v226++) { + if ((v226 + (v223 * 8)) == 0) { + float v227 = v215[v225][v224].read(); + v220[(v225 + (v222 * 2))][(v224 + (v221 * 4))] = v227; + } + float v228 = v220[(v225 + (v222 * 2))][(v224 + (v221 * 4))]; + if ((v225 + (v222 * 2)) == 0) { + float v229 = v214[v224][v226].read(); + v219[(v224 + (v221 * 4))][(v226 + (v223 * 8))] = v229; + } + float v230 = v219[(v224 + (v221 * 4))][(v226 + (v223 * 8))]; + if ((v224 + (v221 * 4)) == 0) { + v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))] = v217; + } + float v231 = v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))]; + float v232 = v228 * v230; + float v233 = v231 + v232; + v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))] = v233; + if (((v224 + (v221 * 4)) - 127) == 0) { + float v234 = v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))]; + v216[v225][v226].write(v234); + } + } + } + } + } + } + } + return ; +} + +void node18( + float v235[128][128], + hls::stream v236[4][8] +) { + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=4 + + loop102: for (int v237 = 0; v237 < 32; v237++) { + loop103: for (int v238 = 0; v238 < 16; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop104: for (int v239 = 0; v239 < 4; v239++) { + loop105: for (int v240 = 0; v240 < 8; v240++) { + float v241 = v235[(v240 + (v238 * 8))][(v239 + (v237 * 4))]; + v236[v239][v240].write(v241); + } + } + } + } + return ; +} + +void node19( + hls::stream v242[2][8], + float v243[128], + float v244[64][128] +) { + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=8 + + loop106: for (int v245 = 0; v245 < 32; v245++) { + loop107: for (int v246 = 0; v246 < 16; v246++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop108: for (int v247 = 0; v247 < 2; v247++) { + loop109: for (int v248 = 0; v248 < 8; v248++) { + float v249 = v242[v247][v248].read(); + float v250 = v243[(v248 + (v246 * 8))]; + float v251 = v249 + v250; + v244[(v247 + (v245 * 2))][(v248 + (v246 * 8))] = v251; + } + } + } + } + return ; +} + +void node20( + hls::stream v252[4][8], + hls::stream v253[2][4], + hls::stream v254[2][8], + float v255 +) { + float v256[64][128]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=8 + + float v257[128][128]; + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v257 cyclic dim=2 factor=8 + + float v258[64][128]; + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=4 + + loop110: for (int v259 = 0; v259 < 32; v259++) { + loop111: for (int v260 = 0; v260 < 32; v260++) { + loop112: for (int v261 = 0; v261 < 16; v261++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop113: for (int v262 = 0; v262 < 4; v262++) { + loop114: for (int v263 = 0; v263 < 2; v263++) { + loop115: for (int v264 = 0; v264 < 8; v264++) { + if ((v264 + (v261 * 8)) == 0) { + float v265 = v253[v263][v262].read(); + v258[(v263 + (v260 * 2))][(v262 + (v259 * 4))] = v265; + } + float v266 = v258[(v263 + (v260 * 2))][(v262 + (v259 * 4))]; + if ((v263 + (v260 * 2)) == 0) { + float v267 = v252[v262][v264].read(); + v257[(v262 + (v259 * 4))][(v264 + (v261 * 8))] = v267; + } + float v268 = v257[(v262 + (v259 * 4))][(v264 + (v261 * 8))]; + if ((v262 + (v259 * 4)) == 0) { + v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))] = v255; + } + float v269 = v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))]; + float v270 = v266 * v268; + float v271 = v269 + v270; + v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))] = v271; + if (((v262 + (v259 * 4)) - 127) == 0) { + float v272 = v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))]; + v254[v263][v264].write(v272); + } + } + } + } + } + } + } + return ; +} + +void node21( + float v273[128][128], + hls::stream v274[4][8] +) { + #pragma HLS array_partition variable=v273 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v273 cyclic dim=2 factor=4 + + loop116: for (int v275 = 0; v275 < 32; v275++) { + loop117: for (int v276 = 0; v276 < 16; v276++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop118: for (int v277 = 0; v277 < 4; v277++) { + loop119: for (int v278 = 0; v278 < 8; v278++) { + float v279 = v273[(v278 + (v276 * 8))][(v277 + (v275 * 4))]; + v274[v277][v278].write(v279); + } + } + } + } + return ; +} + +void node22( + hls::stream v280[2][8], + float v281[128], + float v282[64][128] +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=8 + + loop120: for (int v283 = 0; v283 < 16; v283++) { + loop121: for (int v284 = 0; v284 < 32; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop122: for (int v285 = 0; v285 < 8; v285++) { + loop123: for (int v286 = 0; v286 < 2; v286++) { + float v287 = v280[v286][v285].read(); + float v288 = v281[(v285 + (v283 * 8))]; + float v289 = v287 + v288; + v282[(v286 + (v284 * 2))][(v285 + (v283 * 8))] = v289; + } + } + } + } + return ; +} + +void node23( + hls::stream v290[2][4], + hls::stream v291[4][8], + hls::stream v292[2][8], + float v293 +) { + float v294[64][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=8 + + float v295[128][128]; + #pragma HLS array_partition variable=v295 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v295 cyclic dim=2 factor=8 + + float v296[64][128]; + #pragma HLS array_partition variable=v296 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v296 cyclic dim=2 factor=4 + + loop124: for (int v297 = 0; v297 < 32; v297++) { + loop125: for (int v298 = 0; v298 < 16; v298++) { + loop126: for (int v299 = 0; v299 < 32; v299++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop127: for (int v300 = 0; v300 < 4; v300++) { + loop128: for (int v301 = 0; v301 < 8; v301++) { + loop129: for (int v302 = 0; v302 < 2; v302++) { + if ((v301 + (v298 * 8)) == 0) { + float v303 = v290[v302][v300].read(); + v296[(v302 + (v299 * 2))][(v300 + (v297 * 4))] = v303; + } + float v304 = v296[(v302 + (v299 * 2))][(v300 + (v297 * 4))]; + if ((v302 + (v299 * 2)) == 0) { + float v305 = v291[v300][v301].read(); + v295[(v300 + (v297 * 4))][(v301 + (v298 * 8))] = v305; + } + float v306 = v295[(v300 + (v297 * 4))][(v301 + (v298 * 8))]; + if ((v300 + (v297 * 4)) == 0) { + v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))] = v293; + } + float v307 = v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))]; + float v308 = v304 * v306; + float v309 = v307 + v308; + v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))] = v309; + if (((v300 + (v297 * 4)) - 127) == 0) { + float v310 = v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))]; + v292[v302][v301].write(v310); + } + } + } + } + } + } + } + return ; +} + +void node24( + float v311[128][128], + hls::stream v312[4][8] +) { + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + loop130: for (int v313 = 0; v313 < 32; v313++) { + loop131: for (int v314 = 0; v314 < 16; v314++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop132: for (int v315 = 0; v315 < 4; v315++) { + loop133: for (int v316 = 0; v316 < 8; v316++) { + float v317 = v311[(v316 + (v314 * 8))][(v315 + (v313 * 4))]; + v312[v315][v316].write(v317); + } + } + } + } + return ; +} + +void node25( + float v318[1][64][128], + hls::stream v319[2][4], + hls::stream v320[2][4], + hls::stream v321[2][4] +) { + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v318 cyclic dim=3 factor=4 + + loop134: for (int v322 = 0; v322 < 32; v322++) { + loop135: for (int v323 = 0; v323 < 32; v323++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v324 = 0; v324 < 4; v324++) { + loop137: for (int v325 = 0; v325 < 2; v325++) { + float v326 = v318[0][(v325 + (v323 * 2))][(v324 + (v322 * 4))]; + v319[v325][v324].write(v326); + v320[v325][v324].write(v326); + v321[v325][v324].write(v326); + } + } + } + } + return ; +} + +void forward( + float v327[1][64][128], + float v328[128], + float v329[128][128], + float v330[128], + float v331[128][128], + float v332[128], + float v333[128][128], + float v334[128], + float v335[128][128], + float v336[1][64][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v327 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v327 cyclic dim=3 factor=4 + + #pragma HLS array_partition variable=v328 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v329 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v329 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v330 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v331 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v331 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v332 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v333 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v333 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v334 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v335 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v335 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v336 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v336 cyclic dim=3 factor=8 + + hls::stream v337[8][8]; + #pragma HLS STREAM variable=v337 depth=128 + hls::stream v338[8][8]; + #pragma HLS STREAM variable=v338 depth=128 + hls::stream v339[2][8]; + #pragma HLS STREAM variable=v339 depth=1024 + hls::stream v340[8][2]; + #pragma HLS STREAM variable=v340 depth=512 + float v341[64][8][16]; + #pragma HLS array_partition variable=v341 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v341 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=3 factor=2 + + float v342[8][64][16]; + #pragma HLS array_partition variable=v342 complete dim=1 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=3 factor=2 + + float v343[8][64][16]; + #pragma HLS array_partition variable=v343 complete dim=1 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=3 factor=2 + + hls::stream v344[8][2][2]; + #pragma HLS STREAM variable=v344 depth=1024 + hls::stream v345[8][2]; + #pragma HLS STREAM variable=v345 depth=32 + hls::stream v346[8][2][2]; + #pragma HLS STREAM variable=v346 depth=1024 + hls::stream v347[8][2][2]; + #pragma HLS STREAM variable=v347 depth=1024 + hls::stream v348[8][2]; + #pragma HLS STREAM variable=v348 depth=32 + hls::stream v349[8][2][2]; + #pragma HLS STREAM variable=v349 depth=1024 + hls::stream v350[8][2][2]; + #pragma HLS STREAM variable=v350 depth=1024 + hls::stream v351[8][2][2]; + #pragma HLS STREAM variable=v351 depth=1024 + float v352[8][16][64]; + #pragma HLS array_partition variable=v352 complete dim=1 + #pragma HLS array_partition variable=v352 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v352 cyclic dim=3 factor=2 + + float v353[8][64][16]; + #pragma HLS array_partition variable=v353 complete dim=1 + #pragma HLS array_partition variable=v353 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v353 cyclic dim=3 factor=2 + + float v354[64][128]; + #pragma HLS array_partition variable=v354 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v354 cyclic dim=2 factor=8 + + hls::stream v355[2][8]; + #pragma HLS STREAM variable=v355 depth=512 + hls::stream v356[4][8]; + #pragma HLS STREAM variable=v356 depth=512 + float v357[64][128]; + #pragma HLS array_partition variable=v357 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v357 cyclic dim=2 factor=8 + + hls::stream v358[2][8]; + #pragma HLS STREAM variable=v358 depth=512 + hls::stream v359[4][8]; + #pragma HLS STREAM variable=v359 depth=512 + float v360[64][128]; + #pragma HLS array_partition variable=v360 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v360 cyclic dim=2 factor=8 + + hls::stream v361[2][8]; + #pragma HLS STREAM variable=v361 depth=512 + hls::stream v362[4][8]; + #pragma HLS STREAM variable=v362 depth=512 + hls::stream v363[2][4]; + #pragma HLS STREAM variable=v363 depth=1024 + hls::stream v364[2][4]; + #pragma HLS STREAM variable=v364 depth=1024 + hls::stream v365[2][4]; + #pragma HLS STREAM variable=v365 depth=1024 + node25(v327, v365, v364, v363); + node24(v329, v362); + node23(v363, v362, v361, 0.000000); + node22(v361, v328, v360); + node21(v331, v359); + node20(v359, v364, v358, 0.000000); + node19(v358, v330, v357); + node18(v333, v356); + node17(v356, v365, v355, 0.000000); + node16(v355, v332, v354); + node15(v360, v353); + node14(v357, v352); + node13(v352, v353, v351, 0.000000); + node12(v351, v350, v349, 4.000000); + node11(v350, v348, -INFINITY); + node10(v349, v348, v347, v346); + node9(v347, v345, 0.000000); + node8(v346, v345, v344); + node7(v354, v343); + node6(v344, v343, v342, 0.000000); + node5(v342, v341); + node4(v341, v340); + node3(v335, v339); + node2(v339, v340, v338, 0.000000); + node1(v338, v334, v337); + node0(v337, v336); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt1/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt1/src/ResMLP.cpp new file mode 100644 index 000000000000..a4f4c79fabf7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt1/src/ResMLP.cpp @@ -0,0 +1,406 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[8][10] +) { // L6 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L7 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L8 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L9 + v1[v2][v3] = v4; // L10 + } + } + return ; // L13 +} + +void node1( + hls::stream &v5, + float v6[10], + hls::stream &v7 +) { // L15 + loop2: for (int v8 = 0; v8 < 8; v8++) { // L16 + loop3: for (int v9 = 0; v9 < 10; v9++) { // L17 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); // L18 + float v11 = v6[v9]; // L19 + float v12 = v10 + v11; // L20 + v7.write(v12); // L21 + } + } + return ; // L24 +} + +void node2( + hls::stream &v13, + hls::stream &v14, + hls::stream &v15, + float v16 +) { // L26 + float v17[8][10]; // L27 + float v18[256][10]; // L28 + float v19[8][256]; // L29 + loop4: for (int v20 = 0; v20 < 8; v20++) { // L30 + loop5: for (int v21 = 0; v21 < 10; v21++) { // L31 + loop6: for (int v22 = 0; v22 < 256; v22++) { // L32 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v21 == 0) { // L33 + float v23 = v14.read(); // L34 + v19[v20][v22] = v23; // L35 + } + float v24 = v19[v20][v22]; // L37 + if (v20 == 0) { // L38 + float v25 = v13.read(); // L39 + v18[v22][v21] = v25; // L40 + } + float v26 = v18[v22][v21]; // L42 + if (v22 == 0) { // L43 + v17[v20][v21] = v16; // L44 + } + float v27 = v17[v20][v21]; // L46 + float v28 = v24 * v26; // L47 + float v29 = v27 + v28; // L48 + v17[v20][v21] = v29; // L49 + if ((v22 - 255) == 0) { // L50 + float v30 = v17[v20][v21]; // L51 + v15.write(v30); // L52 + } + } + } + } + return ; // L57 +} + +void node3( + float v31[10][256], + hls::stream &v32 +) { // L59 + loop7: for (int v33 = 0; v33 < 10; v33++) { // L60 + loop8: for (int v34 = 0; v34 < 256; v34++) { // L61 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v33][v34]; // L62 + v32.write(v35); // L63 + } + } + return ; // L66 +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38 +) { // L68 + loop9: for (int v39 = 0; v39 < 8; v39++) { // L69 + loop10: for (int v40 = 0; v40 < 256; v40++) { // L70 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v41 = v36.read(); // L71 + float v42 = v37[v40]; // L72 + float v43 = v41 + v42; // L73 + v38.write(v43); // L74 + } + } + return ; // L77 +} + +void node5( + hls::stream &v44, + hls::stream &v45, + hls::stream &v46, + float v47 +) { // L79 + float v48[8][256]; // L80 + float v49[512][256]; // L81 + float v50[8][512]; // L82 + loop11: for (int v51 = 0; v51 < 8; v51++) { // L83 + loop12: for (int v52 = 0; v52 < 256; v52++) { // L84 + loop13: for (int v53 = 0; v53 < 512; v53++) { // L85 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v52 == 0) { // L86 + float v54 = v44.read(); // L87 + v50[v51][v53] = v54; // L88 + } + float v55 = v50[v51][v53]; // L90 + if (v51 == 0) { // L91 + float v56 = v45.read(); // L92 + v49[v53][v52] = v56; // L93 + } + float v57 = v49[v53][v52]; // L95 + if (v53 == 0) { // L96 + v48[v51][v52] = v47; // L97 + } + float v58 = v48[v51][v52]; // L99 + float v59 = v55 * v57; // L100 + float v60 = v58 + v59; // L101 + v48[v51][v52] = v60; // L102 + if ((v53 - 511) == 0) { // L103 + float v61 = v48[v51][v52]; // L104 + v46.write(v61); // L105 + } + } + } + } + return ; // L110 +} + +void node6( + float v62[256][512], + hls::stream &v63 +) { // L112 + loop14: for (int v64 = 0; v64 < 256; v64++) { // L113 + loop15: for (int v65 = 0; v65 < 512; v65++) { // L114 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v66 = v62[v64][v65]; // L115 + v63.write(v66); // L116 + } + } + return ; // L119 +} + +void node7( + hls::stream &v67, + float v68[512], + hls::stream &v69, + hls::stream &v70, + float v71 +) { // L121 + loop16: for (int v72 = 0; v72 < 8; v72++) { // L122 + loop17: for (int v73 = 0; v73 < 512; v73++) { // L123 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v67.read(); // L124 + float v75 = v68[v73]; // L125 + float v76 = v69.read(); // L126 + float v77 = v74 + v75; // L127 + float v78 = v77 + v76; // L128 + bool v79 = v78 > v71; // L129 + float v80 = v79 ? (float)v78 : (float)v71; // L130 + v70.write(v80); // L131 + } + } + return ; // L134 +} + +void node8( + hls::stream &v81, + hls::stream &v82, + hls::stream &v83, + float v84 +) { // L136 + float v85[8][512]; // L137 + float v86[512][512]; // L138 + float v87[8][512]; // L139 + loop18: for (int v88 = 0; v88 < 8; v88++) { // L140 + loop19: for (int v89 = 0; v89 < 512; v89++) { // L141 + loop20: for (int v90 = 0; v90 < 512; v90++) { // L142 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v89 == 0) { // L143 + float v91 = v82.read(); // L144 + v87[v88][v90] = v91; // L145 + } + float v92 = v87[v88][v90]; // L147 + if (v88 == 0) { // L148 + float v93 = v81.read(); // L149 + v86[v90][v89] = v93; // L150 + } + float v94 = v86[v90][v89]; // L152 + if (v90 == 0) { // L153 + v85[v88][v89] = v84; // L154 + } + float v95 = v85[v88][v89]; // L156 + float v96 = v92 * v94; // L157 + float v97 = v95 + v96; // L158 + v85[v88][v89] = v97; // L159 + if ((v90 - 511) == 0) { // L160 + float v98 = v85[v88][v89]; // L161 + v83.write(v98); // L162 + } + } + } + } + return ; // L167 +} + +void node9( + float v99[512][512], + hls::stream &v100 +) { // L169 + loop21: for (int v101 = 0; v101 < 512; v101++) { // L170 + loop22: for (int v102 = 0; v102 < 512; v102++) { // L171 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v103 = v99[v101][v102]; // L172 + v100.write(v103); // L173 + } + } + return ; // L176 +} + +void node10( + hls::stream &v104, + hls::stream &v105, + float v106 +) { // L178 + loop23: for (int v107 = 0; v107 < 8; v107++) { // L179 + loop24: for (int v108 = 0; v108 < 512; v108++) { // L180 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v104.read(); // L181 + bool v110 = v109 > v106; // L182 + float v111 = v110 ? (float)v109 : (float)v106; // L183 + v105.write(v111); // L184 + } + } + return ; // L187 +} + +void node11( + hls::stream &v112, + float v113[512], + hls::stream &v114, + hls::stream &v115 +) { // L189 + loop25: for (int v116 = 0; v116 < 8; v116++) { // L190 + loop26: for (int v117 = 0; v117 < 512; v117++) { // L191 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v118 = v112.read(); // L192 + float v119 = v113[v117]; // L193 + float v120 = v118 + v119; // L194 + v114.write(v120); // L195 + v115.write(v120); // L196 + } + } + return ; // L199 +} + +void node12( + float v121[8][1024], + hls::stream &v122, + hls::stream &v123, + float v124 +) { // L201 + float v125[8][512]; // L202 + float v126[1024][512]; // L203 + loop27: for (int v127 = 0; v127 < 8; v127++) { // L204 + loop28: for (int v128 = 0; v128 < 512; v128++) { // L205 + loop29: for (int v129 = 0; v129 < 1024; v129++) { // L206 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v130 = v121[v127][v129]; // L207 + if (v127 == 0) { // L208 + float v131 = v122.read(); // L209 + v126[v129][v128] = v131; // L210 + } + float v132 = v126[v129][v128]; // L212 + if (v129 == 0) { // L213 + v125[v127][v128] = v124; // L214 + } + float v133 = v125[v127][v128]; // L216 + float v134 = v130 * v132; // L217 + float v135 = v133 + v134; // L218 + v125[v127][v128] = v135; // L219 + if ((v129 - 1023) == 0) { // L220 + float v136 = v125[v127][v128]; // L221 + v123.write(v136); // L222 + } + } + } + } + return ; // L227 +} + +void node13( + float v137[512][1024], + hls::stream &v138 +) { // L229 + loop30: for (int v139 = 0; v139 < 512; v139++) { // L230 + loop31: for (int v140 = 0; v140 < 1024; v140++) { // L231 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v141 = v137[v139][v140]; // L232 + v138.write(v141); // L233 + } + } + return ; // L236 +} + +void forward( + float v142[8][1024], + float v143[512], + float v144[512][1024], + float v145[512], + float v146[512][512], + float v147[256], + float v148[256][512], + float v149[10], + float v150[10][256], + float v151[8][10] +) { // L238 + #pragma HLS DATAFLOW + hls::stream v152("fifo_0"); + #pragma HLS STREAM variable=v152 depth=80 // L240 + hls::stream v153("fifo_1"); + #pragma HLS STREAM variable=v153 depth=80 // L241 + hls::stream v154("fifo_2"); + #pragma HLS STREAM variable=v154 depth=2560 // L242 + hls::stream v155("fifo_3"); + #pragma HLS STREAM variable=v155 depth=2048 // L243 + hls::stream v156("fifo_4"); + #pragma HLS STREAM variable=v156 depth=2048 // L244 + hls::stream v157("fifo_5"); + #pragma HLS STREAM variable=v157 depth=131072 // L245 + hls::stream v158("fifo_6"); + #pragma HLS STREAM variable=v158 depth=4096 // L246 + hls::stream v159("fifo_7"); + #pragma HLS STREAM variable=v159 depth=4096 // L247 + hls::stream v160("fifo_8"); + #pragma HLS STREAM variable=v160 depth=262144 // L248 + hls::stream v161("fifo_9"); + #pragma HLS STREAM variable=v161 depth=4096 // L249 + hls::stream v162("fifo_10"); + #pragma HLS STREAM variable=v162 depth=4096 // L250 + hls::stream v163("fifo_11"); + #pragma HLS STREAM variable=v163 depth=4096 // L251 + hls::stream v164("fifo_12"); + #pragma HLS STREAM variable=v164 depth=4096 // L252 + hls::stream v165("fifo_13"); + #pragma HLS STREAM variable=v165 depth=524288 // L253 + node13(v144, v165); // L254 + node12(v142, v165, v164, 0.000000); // L255 + node11(v164, v143, v163, v162); // L256 + node10(v163, v161, 0.000000); // L257 + node9(v146, v160); // L258 + node8(v160, v161, v159, 0.000000); // L259 + node7(v159, v145, v162, v158, 0.000000); // L260 + node6(v148, v157); // L261 + node5(v158, v157, v156, 0.000000); // L262 + node4(v156, v147, v155); // L263 + node3(v150, v154); // L264 + node2(v154, v155, v153, 0.000000); // L265 + node1(v153, v149, v152); // L266 + node0(v152, v151); // L267 + return ; // L268 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt2/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt2/src/ResMLP.cpp new file mode 100644 index 000000000000..e1c7100dcfce --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt2/src/ResMLP.cpp @@ -0,0 +1,405 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[8][10] +) { // L6 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L7 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L8 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L9 + v1[v2][v3] = v4; // L10 + } + } + return ; // L13 +} + +void node1( + hls::stream &v5, + float v6[10], + hls::stream &v7 +) { // L15 + loop2: for (int v8 = 0; v8 < 8; v8++) { // L16 + loop3: for (int v9 = 0; v9 < 10; v9++) { // L17 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); // L18 + float v11 = v6[v9]; // L19 + float v12 = v10 + v11; // L20 + v7.write(v12); // L21 + } + } + return ; // L24 +} + +void node2( + hls::stream &v13, + float v14[256][10], + hls::stream &v15, + float v16 +) { // L26 + float v17[8][10]; // L27 + float v18[256][10]; // L28 + float v19[8][256]; // L29 + loop4: for (int v20 = 0; v20 < 8; v20++) { // L30 + loop5: for (int v21 = 0; v21 < 256; v21++) { // L31 + loop6: for (int v22 = 0; v22 < 10; v22++) { // L32 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v22 == 0) { // L33 + float v23 = v13.read(); // L34 + v19[v20][v21] = v23; // L35 + } + float v24 = v19[v20][v21]; // L37 + if (v20 == 0) { // L38 + float v25 = v14[v21][v22]; // L39 + v18[v21][v22] = v25; // L40 + } + float v26 = v18[v21][v22]; // L42 + if (v21 == 0) { // L43 + v17[v20][v22] = v16; // L44 + } + float v27 = v17[v20][v22]; // L46 + float v28 = v24 * v26; // L47 + float v29 = v27 + v28; // L48 + v17[v20][v22] = v29; // L49 + if ((v21 - 255) == 0) { // L50 + float v30 = v17[v20][v22]; // L51 + v15.write(v30); // L52 + } + } + } + } + return ; // L57 +} + +void node3( + float v31[10][256], + float v32[256][10] +) { // L59 + loop7: for (int v33 = 0; v33 < 10; v33++) { // L60 + loop8: for (int v34 = 0; v34 < 256; v34++) { // L61 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v33][v34]; // L62 + v32[v34][v33] = v35; // L63 + } + } + return ; // L66 +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38 +) { // L68 + loop9: for (int v39 = 0; v39 < 8; v39++) { // L69 + loop10: for (int v40 = 0; v40 < 256; v40++) { // L70 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v41 = v36.read(); // L71 + float v42 = v37[v40]; // L72 + float v43 = v41 + v42; // L73 + v38.write(v43); // L74 + } + } + return ; // L77 +} + +void node5( + hls::stream &v44, + hls::stream &v45, + hls::stream &v46, + float v47 +) { // L79 + float v48[8][256]; // L80 + float v49[512][256]; // L81 + float v50[8][512]; // L82 + loop11: for (int v51 = 0; v51 < 8; v51++) { // L83 + loop12: for (int v52 = 0; v52 < 512; v52++) { // L84 + loop13: for (int v53 = 0; v53 < 256; v53++) { // L85 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v53 == 0) { // L86 + float v54 = v45.read(); // L87 + v50[v51][v52] = v54; // L88 + } + float v55 = v50[v51][v52]; // L90 + if (v51 == 0) { // L91 + float v56 = v44.read(); // L92 + v49[v52][v53] = v56; // L93 + } + float v57 = v49[v52][v53]; // L95 + if (v52 == 0) { // L96 + v48[v51][v53] = v47; // L97 + } + float v58 = v48[v51][v53]; // L99 + float v59 = v55 * v57; // L100 + float v60 = v58 + v59; // L101 + v48[v51][v53] = v60; // L102 + if ((v52 - 511) == 0) { // L103 + float v61 = v48[v51][v53]; // L104 + v46.write(v61); // L105 + } + } + } + } + return ; // L110 +} + +void node6( + float v62[256][512], + hls::stream &v63 +) { // L112 + loop14: for (int v64 = 0; v64 < 512; v64++) { // L113 + loop15: for (int v65 = 0; v65 < 256; v65++) { // L114 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v66 = v62[v65][v64]; // L115 + v63.write(v66); // L116 + } + } + return ; // L119 +} + +void node7( + hls::stream &v67, + float v68[512], + hls::stream &v69, + hls::stream &v70, + float v71 +) { // L121 + loop16: for (int v72 = 0; v72 < 8; v72++) { // L122 + loop17: for (int v73 = 0; v73 < 512; v73++) { // L123 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v67.read(); // L124 + float v75 = v68[v73]; // L125 + float v76 = v69.read(); // L126 + float v77 = v74 + v75; // L127 + float v78 = v77 + v76; // L128 + bool v79 = v78 > v71; // L129 + float v80 = v79 ? (float)v78 : (float)v71; // L130 + v70.write(v80); // L131 + } + } + return ; // L134 +} + +void node8( + hls::stream &v81, + hls::stream &v82, + hls::stream &v83, + float v84 +) { // L136 + float v85[8][512]; // L137 + float v86[512][512]; // L138 + float v87[8][512]; // L139 + loop18: for (int v88 = 0; v88 < 8; v88++) { // L140 + loop19: for (int v89 = 0; v89 < 512; v89++) { // L141 + loop20: for (int v90 = 0; v90 < 512; v90++) { // L142 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v90 == 0) { // L143 + float v91 = v81.read(); // L144 + v87[v88][v89] = v91; // L145 + } + float v92 = v87[v88][v89]; // L147 + if (v88 == 0) { // L148 + float v93 = v82.read(); // L149 + v86[v89][v90] = v93; // L150 + } + float v94 = v86[v89][v90]; // L152 + if (v89 == 0) { // L153 + v85[v88][v90] = v84; // L154 + } + float v95 = v85[v88][v90]; // L156 + float v96 = v92 * v94; // L157 + float v97 = v95 + v96; // L158 + v85[v88][v90] = v97; // L159 + if ((v89 - 511) == 0) { // L160 + float v98 = v85[v88][v90]; // L161 + v83.write(v98); // L162 + } + } + } + } + return ; // L167 +} + +void node9( + float v99[512][512], + hls::stream &v100 +) { // L169 + loop21: for (int v101 = 0; v101 < 512; v101++) { // L170 + loop22: for (int v102 = 0; v102 < 512; v102++) { // L171 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v103 = v99[v102][v101]; // L172 + v100.write(v103); // L173 + } + } + return ; // L176 +} + +void node10( + hls::stream &v104, + hls::stream &v105, + float v106 +) { // L178 + loop23: for (int v107 = 0; v107 < 8; v107++) { // L179 + loop24: for (int v108 = 0; v108 < 512; v108++) { // L180 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v104.read(); // L181 + bool v110 = v109 > v106; // L182 + float v111 = v110 ? (float)v109 : (float)v106; // L183 + v105.write(v111); // L184 + } + } + return ; // L187 +} + +void node11( + hls::stream &v112, + float v113[512], + hls::stream &v114, + hls::stream &v115 +) { // L189 + loop25: for (int v116 = 0; v116 < 8; v116++) { // L190 + loop26: for (int v117 = 0; v117 < 512; v117++) { // L191 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v118 = v112.read(); // L192 + float v119 = v113[v117]; // L193 + float v120 = v118 + v119; // L194 + v114.write(v120); // L195 + v115.write(v120); // L196 + } + } + return ; // L199 +} + +void node12( + float v121[8][1024], + hls::stream &v122, + hls::stream &v123, + float v124 +) { // L201 + float v125[8][512]; // L202 + float v126[1024][512]; // L203 + loop27: for (int v127 = 0; v127 < 8; v127++) { // L204 + loop28: for (int v128 = 0; v128 < 1024; v128++) { // L205 + loop29: for (int v129 = 0; v129 < 512; v129++) { // L206 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v130 = v121[v127][v128]; // L207 + if (v127 == 0) { // L208 + float v131 = v122.read(); // L209 + v126[v128][v129] = v131; // L210 + } + float v132 = v126[v128][v129]; // L212 + if (v128 == 0) { // L213 + v125[v127][v129] = v124; // L214 + } + float v133 = v125[v127][v129]; // L216 + float v134 = v130 * v132; // L217 + float v135 = v133 + v134; // L218 + v125[v127][v129] = v135; // L219 + if ((v128 - 1023) == 0) { // L220 + float v136 = v125[v127][v129]; // L221 + v123.write(v136); // L222 + } + } + } + } + return ; // L227 +} + +void node13( + float v137[512][1024], + hls::stream &v138 +) { // L229 + loop30: for (int v139 = 0; v139 < 1024; v139++) { // L230 + loop31: for (int v140 = 0; v140 < 512; v140++) { // L231 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v141 = v137[v140][v139]; // L232 + v138.write(v141); // L233 + } + } + return ; // L236 +} + +void forward( + float v142[8][1024], + float v143[512], + float v144[512][1024], + float v145[512], + float v146[512][512], + float v147[256], + float v148[256][512], + float v149[10], + float v150[10][256], + float v151[8][10] +) { // L238 + #pragma HLS DATAFLOW + hls::stream v152("fifo_0"); + #pragma HLS STREAM variable=v152 depth=80 // L240 + hls::stream v153("fifo_1"); + #pragma HLS STREAM variable=v153 depth=80 // L241 + float v154[256][10]; // L242 + hls::stream v155("fifo_2"); + #pragma HLS STREAM variable=v155 depth=2048 // L243 + hls::stream v156("fifo_3"); + #pragma HLS STREAM variable=v156 depth=2048 // L244 + hls::stream v157("fifo_4"); + #pragma HLS STREAM variable=v157 depth=131072 // L245 + hls::stream v158("fifo_5"); + #pragma HLS STREAM variable=v158 depth=4096 // L246 + hls::stream v159("fifo_6"); + #pragma HLS STREAM variable=v159 depth=4096 // L247 + hls::stream v160("fifo_7"); + #pragma HLS STREAM variable=v160 depth=262144 // L248 + hls::stream v161("fifo_8"); + #pragma HLS STREAM variable=v161 depth=4096 // L249 + hls::stream v162("fifo_9"); + #pragma HLS STREAM variable=v162 depth=4096 // L250 + hls::stream v163("fifo_10"); + #pragma HLS STREAM variable=v163 depth=4096 // L251 + hls::stream v164("fifo_11"); + #pragma HLS STREAM variable=v164 depth=4096 // L252 + hls::stream v165("fifo_12"); + #pragma HLS STREAM variable=v165 depth=524288 // L253 + node13(v144, v165); // L254 + node12(v142, v165, v164, 0.000000); // L255 + node11(v164, v143, v163, v162); // L256 + node10(v163, v161, 0.000000); // L257 + node9(v146, v160); // L258 + node8(v161, v160, v159, 0.000000); // L259 + node7(v159, v145, v162, v158, 0.000000); // L260 + node6(v148, v157); // L261 + node5(v157, v158, v156, 0.000000); // L262 + node4(v156, v147, v155); // L263 + node3(v150, v154); // L264 + node2(v155, v154, v153, 0.000000); // L265 + node1(v153, v149, v152); // L266 + node0(v152, v151); // L267 + return ; // L268 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt3/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt3/src/ResMLP.cpp new file mode 100644 index 000000000000..79e23ca3d036 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt3/src/ResMLP.cpp @@ -0,0 +1,470 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[8][10] +) { // L10 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L11 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L12 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L13 + loop3: for (int v5 = 0; v5 < 1; v5++) { // L14 + float v6 = v0[v4][v5].read(); // L15 + v1[(v2 + v4)][(v3 + v5)] = v6; // L16 + } + } + } + } + return ; // L21 +} + +void node1( + hls::stream v7[1][1], + float v8[10], + hls::stream v9[1][1] +) { // L23 + loop4: for (int v10 = 0; v10 < 8; v10++) { // L24 + loop5: for (int v11 = 0; v11 < 10; v11++) { // L25 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 1; v12++) { // L26 + loop7: for (int v13 = 0; v13 < 1; v13++) { // L27 + float v14 = v7[v12][v13].read(); // L28 + float v15 = v8[(v11 + v13)]; // L29 + float v16 = v14 + v15; // L30 + v9[v12][v13].write(v16); // L31 + } + } + } + } + return ; // L36 +} + +void node2( + hls::stream v17[16][1], + hls::stream v18[1][16], + hls::stream v19[1][1], + float v20 +) { // L38 + float v21[8][10]; // L39 + float v22[256][10]; // L40 + float v23[8][256]; // L41 + loop8: for (int v24 = 0; v24 < 8; v24++) { // L42 + loop9: for (int v25 = 0; v25 < 10; v25++) { // L43 + loop10: for (int v26 = 0; v26 < 16; v26++) { // L44 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 1; v27++) { // L45 + loop12: for (int v28 = 0; v28 < 1; v28++) { // L46 + loop13: for (int v29 = 0; v29 < 16; v29++) { // L47 + if ((v25 + v28) == 0) { // L48 + float v30 = v18[v27][v29].read(); // L49 + v23[(v24 + v27)][(v29 + (v26 * 16))] = v30; // L50 + } + float v31 = v23[(v24 + v27)][(v29 + (v26 * 16))]; // L52 + if ((v24 + v27) == 0) { // L53 + float v32 = v17[v29][v28].read(); // L54 + v22[(v29 + (v26 * 16))][(v25 + v28)] = v32; // L55 + } + float v33 = v22[(v29 + (v26 * 16))][(v25 + v28)]; // L57 + if ((v29 + (v26 * 16)) == 0) { // L58 + v21[(v24 + v27)][(v25 + v28)] = v20; // L59 + } + float v34 = v21[(v24 + v27)][(v25 + v28)]; // L61 + float v35 = v31 * v33; // L62 + float v36 = v34 + v35; // L63 + v21[(v24 + v27)][(v25 + v28)] = v36; // L64 + if (((v29 + (v26 * 16)) - 255) == 0) { // L65 + float v37 = v21[(v24 + v27)][(v25 + v28)]; // L66 + v19[v27][v28].write(v37); // L67 + } + } + } + } + } + } + } + return ; // L75 +} + +void node3( + float v38[10][256], + hls::stream v39[16][1] +) { // L77 + loop14: for (int v40 = 0; v40 < 10; v40++) { // L78 + loop15: for (int v41 = 0; v41 < 16; v41++) { // L79 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 1; v42++) { // L80 + loop17: for (int v43 = 0; v43 < 16; v43++) { // L81 + float v44 = v38[(v40 + v42)][(v43 + (v41 * 16))]; // L82 + v39[v43][v42].write(v44); // L83 + } + } + } + } + return ; // L88 +} + +void node4( + hls::stream v45[1][16], + float v46[256], + hls::stream v47[1][16] +) { // L90 + loop18: for (int v48 = 0; v48 < 8; v48++) { // L91 + loop19: for (int v49 = 0; v49 < 16; v49++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v50 = 0; v50 < 1; v50++) { // L93 + loop21: for (int v51 = 0; v51 < 16; v51++) { // L94 + float v52 = v45[v50][v51].read(); // L95 + float v53 = v46[(v51 + (v49 * 16))]; // L96 + float v54 = v52 + v53; // L97 + v47[v50][v51].write(v54); // L98 + } + } + } + } + return ; // L103 +} + +void node5( + hls::stream v55[1][8], + hls::stream v56[8][16], + hls::stream v57[1][16], + float v58 +) { // L105 + float v59[8][256]; // L106 + float v60[512][256]; // L107 + float v61[8][512]; // L108 + loop22: for (int v62 = 0; v62 < 8; v62++) { // L109 + loop23: for (int v63 = 0; v63 < 16; v63++) { // L110 + loop24: for (int v64 = 0; v64 < 64; v64++) { // L111 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v65 = 0; v65 < 1; v65++) { // L112 + loop26: for (int v66 = 0; v66 < 16; v66++) { // L113 + loop27: for (int v67 = 0; v67 < 8; v67++) { // L114 + if ((v66 + (v63 * 16)) == 0) { // L115 + float v68 = v55[v65][v67].read(); // L116 + v61[(v62 + v65)][(v67 + (v64 * 8))] = v68; // L117 + } + float v69 = v61[(v62 + v65)][(v67 + (v64 * 8))]; // L119 + if ((v62 + v65) == 0) { // L120 + float v70 = v56[v67][v66].read(); // L121 + v60[(v67 + (v64 * 8))][(v66 + (v63 * 16))] = v70; // L122 + } + float v71 = v60[(v67 + (v64 * 8))][(v66 + (v63 * 16))]; // L124 + if ((v67 + (v64 * 8)) == 0) { // L125 + v59[(v62 + v65)][(v66 + (v63 * 16))] = v58; // L126 + } + float v72 = v59[(v62 + v65)][(v66 + (v63 * 16))]; // L128 + float v73 = v69 * v71; // L129 + float v74 = v72 + v73; // L130 + v59[(v62 + v65)][(v66 + (v63 * 16))] = v74; // L131 + if (((v67 + (v64 * 8)) - 511) == 0) { // L132 + float v75 = v59[(v62 + v65)][(v66 + (v63 * 16))]; // L133 + v57[v65][v66].write(v75); // L134 + } + } + } + } + } + } + } + return ; // L142 +} + +void node6( + float v76[256][512], + hls::stream v77[8][16] +) { // L144 + loop28: for (int v78 = 0; v78 < 16; v78++) { // L145 + loop29: for (int v79 = 0; v79 < 64; v79++) { // L146 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v80 = 0; v80 < 16; v80++) { // L147 + loop31: for (int v81 = 0; v81 < 8; v81++) { // L148 + float v82 = v76[(v80 + (v78 * 16))][(v81 + (v79 * 8))]; // L149 + v77[v81][v80].write(v82); // L150 + } + } + } + } + return ; // L155 +} + +void node7( + hls::stream v83[1][8], + float v84[512], + hls::stream v85[1][8], + hls::stream v86[1][8], + float v87 +) { // L157 + loop32: for (int v88 = 0; v88 < 8; v88++) { // L158 + loop33: for (int v89 = 0; v89 < 64; v89++) { // L159 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 1; v90++) { // L160 + loop35: for (int v91 = 0; v91 < 8; v91++) { // L161 + float v92 = v83[v90][v91].read(); // L162 + float v93 = v84[(v91 + (v89 * 8))]; // L163 + float v94 = v85[v90][v91].read(); // L164 + float v95 = v92 + v93; // L165 + float v96 = v95 + v94; // L166 + bool v97 = v96 > v87; // L167 + float v98 = v97 ? (float)v96 : (float)v87; // L168 + v86[v90][v91].write(v98); // L169 + } + } + } + } + return ; // L174 +} + +void node8( + hls::stream v99[8][8], + hls::stream v100[1][8], + hls::stream v101[1][8], + float v102 +) { // L176 + float v103[8][512]; // L177 + float v104[512][512]; // L178 + float v105[8][512]; // L179 + loop36: for (int v106 = 0; v106 < 8; v106++) { // L180 + loop37: for (int v107 = 0; v107 < 64; v107++) { // L181 + loop38: for (int v108 = 0; v108 < 64; v108++) { // L182 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v109 = 0; v109 < 1; v109++) { // L183 + loop40: for (int v110 = 0; v110 < 8; v110++) { // L184 + loop41: for (int v111 = 0; v111 < 8; v111++) { // L185 + if ((v110 + (v107 * 8)) == 0) { // L186 + float v112 = v100[v109][v111].read(); // L187 + v105[(v106 + v109)][(v111 + (v108 * 8))] = v112; // L188 + } + float v113 = v105[(v106 + v109)][(v111 + (v108 * 8))]; // L190 + if ((v106 + v109) == 0) { // L191 + float v114 = v99[v111][v110].read(); // L192 + v104[(v111 + (v108 * 8))][(v110 + (v107 * 8))] = v114; // L193 + } + float v115 = v104[(v111 + (v108 * 8))][(v110 + (v107 * 8))]; // L195 + if ((v111 + (v108 * 8)) == 0) { // L196 + v103[(v106 + v109)][(v110 + (v107 * 8))] = v102; // L197 + } + float v116 = v103[(v106 + v109)][(v110 + (v107 * 8))]; // L199 + float v117 = v113 * v115; // L200 + float v118 = v116 + v117; // L201 + v103[(v106 + v109)][(v110 + (v107 * 8))] = v118; // L202 + if (((v111 + (v108 * 8)) - 511) == 0) { // L203 + float v119 = v103[(v106 + v109)][(v110 + (v107 * 8))]; // L204 + v101[v109][v110].write(v119); // L205 + } + } + } + } + } + } + } + return ; // L213 +} + +void node9( + float v120[512][512], + hls::stream v121[8][8] +) { // L215 + loop42: for (int v122 = 0; v122 < 64; v122++) { // L216 + loop43: for (int v123 = 0; v123 < 64; v123++) { // L217 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v124 = 0; v124 < 8; v124++) { // L218 + loop45: for (int v125 = 0; v125 < 8; v125++) { // L219 + float v126 = v120[(v124 + (v122 * 8))][(v125 + (v123 * 8))]; // L220 + v121[v125][v124].write(v126); // L221 + } + } + } + } + return ; // L226 +} + +void node10( + hls::stream v127[1][8], + hls::stream v128[1][8], + float v129 +) { // L228 + loop46: for (int v130 = 0; v130 < 8; v130++) { // L229 + loop47: for (int v131 = 0; v131 < 64; v131++) { // L230 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v132 = 0; v132 < 1; v132++) { // L231 + loop49: for (int v133 = 0; v133 < 8; v133++) { // L232 + float v134 = v127[v132][v133].read(); // L233 + bool v135 = v134 > v129; // L234 + float v136 = v135 ? (float)v134 : (float)v129; // L235 + v128[v132][v133].write(v136); // L236 + } + } + } + } + return ; // L241 +} + +void node11( + hls::stream v137[1][8], + float v138[512], + hls::stream v139[1][8], + hls::stream v140[1][8] +) { // L243 + loop50: for (int v141 = 0; v141 < 8; v141++) { // L244 + loop51: for (int v142 = 0; v142 < 64; v142++) { // L245 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop52: for (int v143 = 0; v143 < 1; v143++) { // L246 + loop53: for (int v144 = 0; v144 < 8; v144++) { // L247 + float v145 = v137[v143][v144].read(); // L248 + float v146 = v138[(v144 + (v142 * 8))]; // L249 + float v147 = v145 + v146; // L250 + v139[v143][v144].write(v147); // L251 + v140[v143][v144].write(v147); // L252 + } + } + } + } + return ; // L257 +} + +void node12( + float v148[8][1024], + hls::stream v149[32][8], + hls::stream v150[1][8], + float v151 +) { // L259 + float v152[8][512]; // L260 + float v153[1024][512]; // L261 + loop54: for (int v154 = 0; v154 < 8; v154++) { // L262 + loop55: for (int v155 = 0; v155 < 64; v155++) { // L263 + loop56: for (int v156 = 0; v156 < 32; v156++) { // L264 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v157 = 0; v157 < 1; v157++) { // L265 + loop58: for (int v158 = 0; v158 < 8; v158++) { // L266 + loop59: for (int v159 = 0; v159 < 32; v159++) { // L267 + float v160 = v148[(v154 + v157)][(v159 + (v156 * 32))]; // L268 + if ((v154 + v157) == 0) { // L269 + float v161 = v149[v159][v158].read(); // L270 + v153[(v159 + (v156 * 32))][(v158 + (v155 * 8))] = v161; // L271 + } + float v162 = v153[(v159 + (v156 * 32))][(v158 + (v155 * 8))]; // L273 + if ((v159 + (v156 * 32)) == 0) { // L274 + v152[(v154 + v157)][(v158 + (v155 * 8))] = v151; // L275 + } + float v163 = v152[(v154 + v157)][(v158 + (v155 * 8))]; // L277 + float v164 = v160 * v162; // L278 + float v165 = v163 + v164; // L279 + v152[(v154 + v157)][(v158 + (v155 * 8))] = v165; // L280 + if (((v159 + (v156 * 32)) - 1023) == 0) { // L281 + float v166 = v152[(v154 + v157)][(v158 + (v155 * 8))]; // L282 + v150[v157][v158].write(v166); // L283 + } + } + } + } + } + } + } + return ; // L291 +} + +void node13( + float v167[512][1024], + hls::stream v168[32][8] +) { // L293 + loop60: for (int v169 = 0; v169 < 64; v169++) { // L294 + loop61: for (int v170 = 0; v170 < 32; v170++) { // L295 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v171 = 0; v171 < 8; v171++) { // L296 + loop63: for (int v172 = 0; v172 < 32; v172++) { // L297 + float v173 = v167[(v171 + (v169 * 8))][(v172 + (v170 * 32))]; // L298 + v168[v172][v171].write(v173); // L299 + } + } + } + } + return ; // L304 +} + +void forward( + float v174[8][1024], + float v175[512], + float v176[512][1024], + float v177[512], + float v178[512][512], + float v179[256], + float v180[256][512], + float v181[10], + float v182[10][256], + float v183[8][10] +) { // L306 + #pragma HLS DATAFLOW + hls::stream v184[1][1]; + #pragma HLS STREAM variable=v184 depth=80 // L308 + hls::stream v185[1][1]; + #pragma HLS STREAM variable=v185 depth=80 // L309 + hls::stream v186[16][1]; + #pragma HLS STREAM variable=v186 depth=160 // L310 + hls::stream v187[1][16]; + #pragma HLS STREAM variable=v187 depth=128 // L311 + hls::stream v188[1][16]; + #pragma HLS STREAM variable=v188 depth=128 // L312 + hls::stream v189[8][16]; + #pragma HLS STREAM variable=v189 depth=1024 // L313 + hls::stream v190[1][8]; + #pragma HLS STREAM variable=v190 depth=512 // L314 + hls::stream v191[1][8]; + #pragma HLS STREAM variable=v191 depth=512 // L315 + hls::stream v192[8][8]; + #pragma HLS STREAM variable=v192 depth=4096 // L316 + hls::stream v193[1][8]; + #pragma HLS STREAM variable=v193 depth=512 // L317 + hls::stream v194[1][8]; + #pragma HLS STREAM variable=v194 depth=512 // L318 + hls::stream v195[1][8]; + #pragma HLS STREAM variable=v195 depth=512 // L319 + hls::stream v196[1][8]; + #pragma HLS STREAM variable=v196 depth=512 // L320 + hls::stream v197[32][8]; + #pragma HLS STREAM variable=v197 depth=2048 // L321 + node13(v176, v197); // L322 + node12(v174, v197, v196, 0.000000); // L323 + node11(v196, v175, v195, v194); // L324 + node10(v195, v193, 0.000000); // L325 + node9(v178, v192); // L326 + node8(v192, v193, v191, 0.000000); // L327 + node7(v191, v177, v194, v190, 0.000000); // L328 + node6(v180, v189); // L329 + node5(v190, v189, v188, 0.000000); // L330 + node4(v188, v179, v187); // L331 + node3(v182, v186); // L332 + node2(v186, v187, v185, 0.000000); // L333 + node1(v185, v181, v184); // L334 + node0(v184, v183); // L335 + return ; // L336 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt4/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt4/src/ResMLP.cpp new file mode 100644 index 000000000000..1443cb07415b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt4/src/ResMLP.cpp @@ -0,0 +1,469 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[8][10] +) { // L10 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L11 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L12 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L13 + loop3: for (int v5 = 0; v5 < 1; v5++) { // L14 + float v6 = v0[v4][v5].read(); // L15 + v1[(v2 + v4)][(v3 + v5)] = v6; // L16 + } + } + } + } + return ; // L21 +} + +void node1( + hls::stream v7[1][1], + float v8[10], + hls::stream v9[1][1] +) { // L23 + loop4: for (int v10 = 0; v10 < 8; v10++) { // L24 + loop5: for (int v11 = 0; v11 < 10; v11++) { // L25 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 1; v12++) { // L26 + loop7: for (int v13 = 0; v13 < 1; v13++) { // L27 + float v14 = v7[v12][v13].read(); // L28 + float v15 = v8[(v11 + v13)]; // L29 + float v16 = v14 + v15; // L30 + v9[v12][v13].write(v16); // L31 + } + } + } + } + return ; // L36 +} + +void node2( + hls::stream v17[1][4], + float v18[256][10], + hls::stream v19[1][1], + float v20 +) { // L38 + float v21[8][10]; // L39 + float v22[256][10]; // L40 + float v23[8][256]; // L41 + loop8: for (int v24 = 0; v24 < 8; v24++) { // L42 + loop9: for (int v25 = 0; v25 < 64; v25++) { // L43 + loop10: for (int v26 = 0; v26 < 10; v26++) { // L44 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 1; v27++) { // L45 + loop12: for (int v28 = 0; v28 < 4; v28++) { // L46 + loop13: for (int v29 = 0; v29 < 1; v29++) { // L47 + if ((v26 + v29) == 0) { // L48 + float v30 = v17[v27][v28].read(); // L49 + v23[(v24 + v27)][(v28 + (v25 * 4))] = v30; // L50 + } + float v31 = v23[(v24 + v27)][(v28 + (v25 * 4))]; // L52 + if ((v24 + v27) == 0) { // L53 + float v32 = v18[(v28 + (v25 * 4))][(v26 + v29)]; // L54 + v22[(v28 + (v25 * 4))][(v26 + v29)] = v32; // L55 + } + float v33 = v22[(v28 + (v25 * 4))][(v26 + v29)]; // L57 + if ((v28 + (v25 * 4)) == 0) { // L58 + v21[(v24 + v27)][(v26 + v29)] = v20; // L59 + } + float v34 = v21[(v24 + v27)][(v26 + v29)]; // L61 + float v35 = v31 * v33; // L62 + float v36 = v34 + v35; // L63 + v21[(v24 + v27)][(v26 + v29)] = v36; // L64 + if (((v28 + (v25 * 4)) - 255) == 0) { // L65 + float v37 = v21[(v24 + v27)][(v26 + v29)]; // L66 + v19[v27][v29].write(v37); // L67 + } + } + } + } + } + } + } + return ; // L75 +} + +void node3( + float v38[10][256], + float v39[256][10] +) { // L77 + loop14: for (int v40 = 0; v40 < 10; v40++) { // L78 + loop15: for (int v41 = 0; v41 < 64; v41++) { // L79 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 1; v42++) { // L80 + loop17: for (int v43 = 0; v43 < 4; v43++) { // L81 + float v44 = v38[(v40 + v42)][(v43 + (v41 * 4))]; // L82 + v39[(v43 + (v41 * 4))][(v40 + v42)] = v44; // L83 + } + } + } + } + return ; // L88 +} + +void node4( + hls::stream v45[1][4], + float v46[256], + hls::stream v47[1][4] +) { // L90 + loop18: for (int v48 = 0; v48 < 8; v48++) { // L91 + loop19: for (int v49 = 0; v49 < 64; v49++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v50 = 0; v50 < 1; v50++) { // L93 + loop21: for (int v51 = 0; v51 < 4; v51++) { // L94 + float v52 = v45[v50][v51].read(); // L95 + float v53 = v46[(v51 + (v49 * 4))]; // L96 + float v54 = v52 + v53; // L97 + v47[v50][v51].write(v54); // L98 + } + } + } + } + return ; // L103 +} + +void node5( + hls::stream v55[16][4], + hls::stream v56[1][16], + hls::stream v57[1][4], + float v58 +) { // L105 + float v59[8][256]; // L106 + float v60[512][256]; // L107 + float v61[8][512]; // L108 + loop22: for (int v62 = 0; v62 < 8; v62++) { // L109 + loop23: for (int v63 = 0; v63 < 32; v63++) { // L110 + loop24: for (int v64 = 0; v64 < 64; v64++) { // L111 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v65 = 0; v65 < 1; v65++) { // L112 + loop26: for (int v66 = 0; v66 < 16; v66++) { // L113 + loop27: for (int v67 = 0; v67 < 4; v67++) { // L114 + if ((v67 + (v64 * 4)) == 0) { // L115 + float v68 = v56[v65][v66].read(); // L116 + v61[(v62 + v65)][(v66 + (v63 * 16))] = v68; // L117 + } + float v69 = v61[(v62 + v65)][(v66 + (v63 * 16))]; // L119 + if ((v62 + v65) == 0) { // L120 + float v70 = v55[v66][v67].read(); // L121 + v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))] = v70; // L122 + } + float v71 = v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))]; // L124 + if ((v66 + (v63 * 16)) == 0) { // L125 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v58; // L126 + } + float v72 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L128 + float v73 = v69 * v71; // L129 + float v74 = v72 + v73; // L130 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v74; // L131 + if (((v66 + (v63 * 16)) - 511) == 0) { // L132 + float v75 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L133 + v57[v65][v67].write(v75); // L134 + } + } + } + } + } + } + } + return ; // L142 +} + +void node6( + float v76[256][512], + hls::stream v77[16][4] +) { // L144 + loop28: for (int v78 = 0; v78 < 32; v78++) { // L145 + loop29: for (int v79 = 0; v79 < 64; v79++) { // L146 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v80 = 0; v80 < 16; v80++) { // L147 + loop31: for (int v81 = 0; v81 < 4; v81++) { // L148 + float v82 = v76[(v81 + (v79 * 4))][(v80 + (v78 * 16))]; // L149 + v77[v80][v81].write(v82); // L150 + } + } + } + } + return ; // L155 +} + +void node7( + hls::stream v83[1][16], + float v84[512], + hls::stream v85[1][16], + hls::stream v86[1][16], + float v87 +) { // L157 + loop32: for (int v88 = 0; v88 < 8; v88++) { // L158 + loop33: for (int v89 = 0; v89 < 32; v89++) { // L159 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 1; v90++) { // L160 + loop35: for (int v91 = 0; v91 < 16; v91++) { // L161 + float v92 = v83[v90][v91].read(); // L162 + float v93 = v84[(v91 + (v89 * 16))]; // L163 + float v94 = v85[v90][v91].read(); // L164 + float v95 = v92 + v93; // L165 + float v96 = v95 + v94; // L166 + bool v97 = v96 > v87; // L167 + float v98 = v97 ? (float)v96 : (float)v87; // L168 + v86[v90][v91].write(v98); // L169 + } + } + } + } + return ; // L174 +} + +void node8( + hls::stream v99[1][16], + hls::stream v100[16][16], + hls::stream v101[1][16], + float v102 +) { // L176 + float v103[8][512]; // L177 + float v104[512][512]; // L178 + float v105[8][512]; // L179 + loop36: for (int v106 = 0; v106 < 8; v106++) { // L180 + loop37: for (int v107 = 0; v107 < 32; v107++) { // L181 + loop38: for (int v108 = 0; v108 < 32; v108++) { // L182 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v109 = 0; v109 < 1; v109++) { // L183 + loop40: for (int v110 = 0; v110 < 16; v110++) { // L184 + loop41: for (int v111 = 0; v111 < 16; v111++) { // L185 + if ((v111 + (v108 * 16)) == 0) { // L186 + float v112 = v99[v109][v110].read(); // L187 + v105[(v106 + v109)][(v110 + (v107 * 16))] = v112; // L188 + } + float v113 = v105[(v106 + v109)][(v110 + (v107 * 16))]; // L190 + if ((v106 + v109) == 0) { // L191 + float v114 = v100[v110][v111].read(); // L192 + v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))] = v114; // L193 + } + float v115 = v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))]; // L195 + if ((v110 + (v107 * 16)) == 0) { // L196 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v102; // L197 + } + float v116 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L199 + float v117 = v113 * v115; // L200 + float v118 = v116 + v117; // L201 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v118; // L202 + if (((v110 + (v107 * 16)) - 511) == 0) { // L203 + float v119 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L204 + v101[v109][v111].write(v119); // L205 + } + } + } + } + } + } + } + return ; // L213 +} + +void node9( + float v120[512][512], + hls::stream v121[16][16] +) { // L215 + loop42: for (int v122 = 0; v122 < 32; v122++) { // L216 + loop43: for (int v123 = 0; v123 < 32; v123++) { // L217 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v124 = 0; v124 < 16; v124++) { // L218 + loop45: for (int v125 = 0; v125 < 16; v125++) { // L219 + float v126 = v120[(v125 + (v123 * 16))][(v124 + (v122 * 16))]; // L220 + v121[v124][v125].write(v126); // L221 + } + } + } + } + return ; // L226 +} + +void node10( + hls::stream v127[1][16], + hls::stream v128[1][16], + float v129 +) { // L228 + loop46: for (int v130 = 0; v130 < 8; v130++) { // L229 + loop47: for (int v131 = 0; v131 < 32; v131++) { // L230 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v132 = 0; v132 < 1; v132++) { // L231 + loop49: for (int v133 = 0; v133 < 16; v133++) { // L232 + float v134 = v127[v132][v133].read(); // L233 + bool v135 = v134 > v129; // L234 + float v136 = v135 ? (float)v134 : (float)v129; // L235 + v128[v132][v133].write(v136); // L236 + } + } + } + } + return ; // L241 +} + +void node11( + hls::stream v137[1][16], + float v138[512], + hls::stream v139[1][16], + hls::stream v140[1][16] +) { // L243 + loop50: for (int v141 = 0; v141 < 8; v141++) { // L244 + loop51: for (int v142 = 0; v142 < 32; v142++) { // L245 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop52: for (int v143 = 0; v143 < 1; v143++) { // L246 + loop53: for (int v144 = 0; v144 < 16; v144++) { // L247 + float v145 = v137[v143][v144].read(); // L248 + float v146 = v138[(v144 + (v142 * 16))]; // L249 + float v147 = v145 + v146; // L250 + v139[v143][v144].write(v147); // L251 + v140[v143][v144].write(v147); // L252 + } + } + } + } + return ; // L257 +} + +void node12( + hls::stream v148[8][16], + float v149[8][1024], + hls::stream v150[1][16], + float v151 +) { // L259 + float v152[8][512]; // L260 + float v153[1024][512]; // L261 + loop54: for (int v154 = 0; v154 < 8; v154++) { // L262 + loop55: for (int v155 = 0; v155 < 128; v155++) { // L263 + loop56: for (int v156 = 0; v156 < 32; v156++) { // L264 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v157 = 0; v157 < 1; v157++) { // L265 + loop58: for (int v158 = 0; v158 < 8; v158++) { // L266 + loop59: for (int v159 = 0; v159 < 16; v159++) { // L267 + float v160 = v149[(v154 + v157)][(v158 + (v155 * 8))]; // L268 + if ((v154 + v157) == 0) { // L269 + float v161 = v148[v158][v159].read(); // L270 + v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))] = v161; // L271 + } + float v162 = v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))]; // L273 + if ((v158 + (v155 * 8)) == 0) { // L274 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v151; // L275 + } + float v163 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L277 + float v164 = v160 * v162; // L278 + float v165 = v163 + v164; // L279 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v165; // L280 + if (((v158 + (v155 * 8)) - 1023) == 0) { // L281 + float v166 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L282 + v150[v157][v159].write(v166); // L283 + } + } + } + } + } + } + } + return ; // L291 +} + +void node13( + float v167[512][1024], + hls::stream v168[8][16] +) { // L293 + loop60: for (int v169 = 0; v169 < 128; v169++) { // L294 + loop61: for (int v170 = 0; v170 < 32; v170++) { // L295 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v171 = 0; v171 < 8; v171++) { // L296 + loop63: for (int v172 = 0; v172 < 16; v172++) { // L297 + float v173 = v167[(v172 + (v170 * 16))][(v171 + (v169 * 8))]; // L298 + v168[v171][v172].write(v173); // L299 + } + } + } + } + return ; // L304 +} + +void forward( + float v174[8][1024], + float v175[512], + float v176[512][1024], + float v177[512], + float v178[512][512], + float v179[256], + float v180[256][512], + float v181[10], + float v182[10][256], + float v183[8][10] +) { // L306 + #pragma HLS DATAFLOW + hls::stream v184[1][1]; + #pragma HLS STREAM variable=v184 depth=80 // L308 + hls::stream v185[1][1]; + #pragma HLS STREAM variable=v185 depth=80 // L309 + float v186[256][10]; // L310 + hls::stream v187[1][4]; + #pragma HLS STREAM variable=v187 depth=512 // L311 + hls::stream v188[1][4]; + #pragma HLS STREAM variable=v188 depth=512 // L312 + hls::stream v189[16][4]; + #pragma HLS STREAM variable=v189 depth=2048 // L313 + hls::stream v190[1][16]; + #pragma HLS STREAM variable=v190 depth=256 // L314 + hls::stream v191[1][16]; + #pragma HLS STREAM variable=v191 depth=256 // L315 + hls::stream v192[16][16]; + #pragma HLS STREAM variable=v192 depth=1024 // L316 + hls::stream v193[1][16]; + #pragma HLS STREAM variable=v193 depth=256 // L317 + hls::stream v194[1][16]; + #pragma HLS STREAM variable=v194 depth=256 // L318 + hls::stream v195[1][16]; + #pragma HLS STREAM variable=v195 depth=256 // L319 + hls::stream v196[1][16]; + #pragma HLS STREAM variable=v196 depth=256 // L320 + hls::stream v197[8][16]; + #pragma HLS STREAM variable=v197 depth=4096 // L321 + node13(v176, v197); // L322 + node12(v197, v174, v196, 0.000000); // L323 + node11(v196, v175, v195, v194); // L324 + node10(v195, v193, 0.000000); // L325 + node9(v178, v192); // L326 + node8(v193, v192, v191, 0.000000); // L327 + node7(v191, v177, v194, v190, 0.000000); // L328 + node6(v180, v189); // L329 + node5(v189, v190, v188, 0.000000); // L330 + node4(v188, v179, v187); // L331 + node3(v182, v186); // L332 + node2(v187, v186, v185, 0.000000); // L333 + node1(v185, v181, v184); // L334 + node0(v184, v183); // L335 + return ; // L336 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt5/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt5/src/ResMLP.cpp new file mode 100644 index 000000000000..3c59e22674b8 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResMLP__opt5/src/ResMLP.cpp @@ -0,0 +1,517 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[8][10] +) { // L23 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L24 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L25 + #pragma HLS pipeline II=1 + loop2: for (int v4 = 0; v4 < 1; v4++) { // L26 + loop3: for (int v5 = 0; v5 < 1; v5++) { // L27 + float v6 = v0[v4][v5].read(); // L28 + v1[(v2 + v4)][(v3 + v5)] = v6; // L29 + } + } + } + } + return ; // L34 +} + +void node1( + hls::stream v7[1][1], + float v8[10], + hls::stream v9[1][1] +) { // L36 + loop4: for (int v10 = 0; v10 < 8; v10++) { // L37 + loop5: for (int v11 = 0; v11 < 10; v11++) { // L38 + #pragma HLS pipeline II=1 + loop6: for (int v12 = 0; v12 < 1; v12++) { // L39 + loop7: for (int v13 = 0; v13 < 1; v13++) { // L40 + float v14 = v7[v12][v13].read(); // L41 + float v15 = v8[(v11 + v13)]; // L42 + float v16 = v14 + v15; // L43 + v9[v12][v13].write(v16); // L44 + } + } + } + } + return ; // L49 +} + +void node2( + hls::stream v17[1][4], + hls::stream v18[4][1], + hls::stream v19[1][1], + float v20 +) { // L51 + float v21[8][10]; // L52 + float v22[256][10]; // L53 + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + + float v23[8][256]; // L54 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=4 + + loop8: for (int v24 = 0; v24 < 8; v24++) { // L55 + loop9: for (int v25 = 0; v25 < 64; v25++) { // L56 + loop10: for (int v26 = 0; v26 < 10; v26++) { // L57 + #pragma HLS pipeline II=1 + loop11: for (int v27 = 0; v27 < 1; v27++) { // L58 + loop12: for (int v28 = 0; v28 < 4; v28++) { // L59 + loop13: for (int v29 = 0; v29 < 1; v29++) { // L60 + if ((v26 + v29) == 0) { // L61 + float v30 = v17[v27][v28].read(); // L62 + v23[(v24 + v27)][(v28 + (v25 * 4))] = v30; // L63 + } + float v31 = v23[(v24 + v27)][(v28 + (v25 * 4))]; // L65 + if ((v24 + v27) == 0) { // L66 + float v32 = v18[v28][v29].read(); // L67 + v22[(v28 + (v25 * 4))][(v26 + v29)] = v32; // L68 + } + float v33 = v22[(v28 + (v25 * 4))][(v26 + v29)]; // L70 + if ((v28 + (v25 * 4)) == 0) { // L71 + v21[(v24 + v27)][(v26 + v29)] = v20; // L72 + } + float v34 = v21[(v24 + v27)][(v26 + v29)]; // L74 + float v35 = v31 * v33; // L75 + float v36 = v34 + v35; // L76 + v21[(v24 + v27)][(v26 + v29)] = v36; // L77 + if (((v28 + (v25 * 4)) - 255) == 0) { // L78 + float v37 = v21[(v24 + v27)][(v26 + v29)]; // L79 + v19[v27][v29].write(v37); // L80 + } + } + } + } + } + } + } + return ; // L88 +} + +void node3( + float v38[10][256], + hls::stream v39[4][1] +) { // L90 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=4 + + loop14: for (int v40 = 0; v40 < 64; v40++) { // L91 + loop15: for (int v41 = 0; v41 < 10; v41++) { // L92 + #pragma HLS pipeline II=1 + loop16: for (int v42 = 0; v42 < 4; v42++) { // L93 + loop17: for (int v43 = 0; v43 < 1; v43++) { // L94 + float v44 = v38[(v41 + v43)][(v42 + (v40 * 4))]; // L95 + v39[v42][v43].write(v44); // L96 + } + } + } + } + return ; // L101 +} + +void node4( + hls::stream v45[1][4], + float v46[256], + hls::stream v47[1][4] +) { // L103 + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=4 + + loop18: for (int v48 = 0; v48 < 8; v48++) { // L104 + loop19: for (int v49 = 0; v49 < 64; v49++) { // L105 + #pragma HLS pipeline II=1 + loop20: for (int v50 = 0; v50 < 1; v50++) { // L106 + loop21: for (int v51 = 0; v51 < 4; v51++) { // L107 + float v52 = v45[v50][v51].read(); // L108 + float v53 = v46[(v51 + (v49 * 4))]; // L109 + float v54 = v52 + v53; // L110 + v47[v50][v51].write(v54); // L111 + } + } + } + } + return ; // L116 +} + +void node5( + hls::stream v55[16][4], + hls::stream v56[1][16], + hls::stream v57[1][4], + float v58 +) { // L118 + float v59[8][256]; // L119 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=4 + + float v60[512][256]; // L120 + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=4 + + float v61[8][512]; // L121 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=16 + + loop22: for (int v62 = 0; v62 < 8; v62++) { // L122 + loop23: for (int v63 = 0; v63 < 32; v63++) { // L123 + loop24: for (int v64 = 0; v64 < 64; v64++) { // L124 + #pragma HLS pipeline II=1 + loop25: for (int v65 = 0; v65 < 1; v65++) { // L125 + loop26: for (int v66 = 0; v66 < 16; v66++) { // L126 + loop27: for (int v67 = 0; v67 < 4; v67++) { // L127 + if ((v67 + (v64 * 4)) == 0) { // L128 + float v68 = v56[v65][v66].read(); // L129 + v61[(v62 + v65)][(v66 + (v63 * 16))] = v68; // L130 + } + float v69 = v61[(v62 + v65)][(v66 + (v63 * 16))]; // L132 + if ((v62 + v65) == 0) { // L133 + float v70 = v55[v66][v67].read(); // L134 + v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))] = v70; // L135 + } + float v71 = v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))]; // L137 + if ((v66 + (v63 * 16)) == 0) { // L138 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v58; // L139 + } + float v72 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L141 + float v73 = v69 * v71; // L142 + float v74 = v72 + v73; // L143 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v74; // L144 + if (((v66 + (v63 * 16)) - 511) == 0) { // L145 + float v75 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L146 + v57[v65][v67].write(v75); // L147 + } + } + } + } + } + } + } + return ; // L155 +} + +void node6( + float v76[256][512], + hls::stream v77[16][4] +) { // L157 + #pragma HLS array_partition variable=v76 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v76 cyclic dim=2 factor=16 + + loop28: for (int v78 = 0; v78 < 32; v78++) { // L158 + loop29: for (int v79 = 0; v79 < 64; v79++) { // L159 + #pragma HLS pipeline II=1 + loop30: for (int v80 = 0; v80 < 16; v80++) { // L160 + loop31: for (int v81 = 0; v81 < 4; v81++) { // L161 + float v82 = v76[(v81 + (v79 * 4))][(v80 + (v78 * 16))]; // L162 + v77[v80][v81].write(v82); // L163 + } + } + } + } + return ; // L168 +} + +void node7( + hls::stream v83[1][16], + float v84[512], + hls::stream v85[1][16], + hls::stream v86[1][16], + float v87 +) { // L170 + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=16 + + loop32: for (int v88 = 0; v88 < 8; v88++) { // L171 + loop33: for (int v89 = 0; v89 < 32; v89++) { // L172 + #pragma HLS pipeline II=1 + loop34: for (int v90 = 0; v90 < 1; v90++) { // L173 + loop35: for (int v91 = 0; v91 < 16; v91++) { // L174 + float v92 = v83[v90][v91].read(); // L175 + float v93 = v84[(v91 + (v89 * 16))]; // L176 + float v94 = v85[v90][v91].read(); // L177 + float v95 = v92 + v93; // L178 + float v96 = v95 + v94; // L179 + bool v97 = v96 > v87; // L180 + float v98 = v97 ? (float)v96 : (float)v87; // L181 + v86[v90][v91].write(v98); // L182 + } + } + } + } + return ; // L187 +} + +void node8( + hls::stream v99[16][16], + hls::stream v100[1][16], + hls::stream v101[1][16], + float v102 +) { // L189 + float v103[8][512]; // L190 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=16 + + float v104[512][512]; // L191 + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=16 + + float v105[8][512]; // L192 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=16 + + loop36: for (int v106 = 0; v106 < 8; v106++) { // L193 + loop37: for (int v107 = 0; v107 < 32; v107++) { // L194 + loop38: for (int v108 = 0; v108 < 32; v108++) { // L195 + #pragma HLS pipeline II=1 + loop39: for (int v109 = 0; v109 < 1; v109++) { // L196 + loop40: for (int v110 = 0; v110 < 16; v110++) { // L197 + loop41: for (int v111 = 0; v111 < 16; v111++) { // L198 + if ((v111 + (v108 * 16)) == 0) { // L199 + float v112 = v100[v109][v110].read(); // L200 + v105[(v106 + v109)][(v110 + (v107 * 16))] = v112; // L201 + } + float v113 = v105[(v106 + v109)][(v110 + (v107 * 16))]; // L203 + if ((v106 + v109) == 0) { // L204 + float v114 = v99[v110][v111].read(); // L205 + v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))] = v114; // L206 + } + float v115 = v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))]; // L208 + if ((v110 + (v107 * 16)) == 0) { // L209 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v102; // L210 + } + float v116 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L212 + float v117 = v113 * v115; // L213 + float v118 = v116 + v117; // L214 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v118; // L215 + if (((v110 + (v107 * 16)) - 511) == 0) { // L216 + float v119 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L217 + v101[v109][v111].write(v119); // L218 + } + } + } + } + } + } + } + return ; // L226 +} + +void node9( + float v120[512][512], + hls::stream v121[16][16] +) { // L228 + #pragma HLS array_partition variable=v120 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v120 cyclic dim=2 factor=16 + + loop42: for (int v122 = 0; v122 < 32; v122++) { // L229 + loop43: for (int v123 = 0; v123 < 32; v123++) { // L230 + #pragma HLS pipeline II=1 + loop44: for (int v124 = 0; v124 < 16; v124++) { // L231 + loop45: for (int v125 = 0; v125 < 16; v125++) { // L232 + float v126 = v120[(v125 + (v123 * 16))][(v124 + (v122 * 16))]; // L233 + v121[v124][v125].write(v126); // L234 + } + } + } + } + return ; // L239 +} + +void node10( + hls::stream v127[1][16], + hls::stream v128[1][16], + float v129 +) { // L241 + loop46: for (int v130 = 0; v130 < 8; v130++) { // L242 + loop47: for (int v131 = 0; v131 < 32; v131++) { // L243 + #pragma HLS pipeline II=1 + loop48: for (int v132 = 0; v132 < 1; v132++) { // L244 + loop49: for (int v133 = 0; v133 < 16; v133++) { // L245 + float v134 = v127[v132][v133].read(); // L246 + bool v135 = v134 > v129; // L247 + float v136 = v135 ? (float)v134 : (float)v129; // L248 + v128[v132][v133].write(v136); // L249 + } + } + } + } + return ; // L254 +} + +void node11( + hls::stream v137[1][16], + float v138[512], + hls::stream v139[1][16], + hls::stream v140[1][16] +) { // L256 + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=16 + + loop50: for (int v141 = 0; v141 < 8; v141++) { // L257 + loop51: for (int v142 = 0; v142 < 32; v142++) { // L258 + #pragma HLS pipeline II=1 + loop52: for (int v143 = 0; v143 < 1; v143++) { // L259 + loop53: for (int v144 = 0; v144 < 16; v144++) { // L260 + float v145 = v137[v143][v144].read(); // L261 + float v146 = v138[(v144 + (v142 * 16))]; // L262 + float v147 = v145 + v146; // L263 + v139[v143][v144].write(v147); // L264 + v140[v143][v144].write(v147); // L265 + } + } + } + } + return ; // L270 +} + +void node12( + float v148[8][1024], + hls::stream v149[8][16], + hls::stream v150[1][16], + float v151 +) { // L272 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=8 + + float v152[8][512]; // L273 + #pragma HLS array_partition variable=v152 cyclic dim=2 factor=16 + + float v153[1024][512]; // L274 + #pragma HLS array_partition variable=v153 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v153 cyclic dim=2 factor=16 + + loop54: for (int v154 = 0; v154 < 8; v154++) { // L275 + loop55: for (int v155 = 0; v155 < 128; v155++) { // L276 + loop56: for (int v156 = 0; v156 < 32; v156++) { // L277 + #pragma HLS pipeline II=1 + loop57: for (int v157 = 0; v157 < 1; v157++) { // L278 + loop58: for (int v158 = 0; v158 < 8; v158++) { // L279 + loop59: for (int v159 = 0; v159 < 16; v159++) { // L280 + float v160 = v148[(v154 + v157)][(v158 + (v155 * 8))]; // L281 + if ((v154 + v157) == 0) { // L282 + float v161 = v149[v158][v159].read(); // L283 + v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))] = v161; // L284 + } + float v162 = v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))]; // L286 + if ((v158 + (v155 * 8)) == 0) { // L287 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v151; // L288 + } + float v163 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L290 + float v164 = v160 * v162; // L291 + float v165 = v163 + v164; // L292 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v165; // L293 + if (((v158 + (v155 * 8)) - 1023) == 0) { // L294 + float v166 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L295 + v150[v157][v159].write(v166); // L296 + } + } + } + } + } + } + } + return ; // L304 +} + +void node13( + float v167[512][1024], + hls::stream v168[8][16] +) { // L306 + #pragma HLS array_partition variable=v167 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=8 + + loop60: for (int v169 = 0; v169 < 128; v169++) { // L307 + loop61: for (int v170 = 0; v170 < 32; v170++) { // L308 + #pragma HLS pipeline II=1 + loop62: for (int v171 = 0; v171 < 8; v171++) { // L309 + loop63: for (int v172 = 0; v172 < 16; v172++) { // L310 + float v173 = v167[(v172 + (v170 * 16))][(v171 + (v169 * 8))]; // L311 + v168[v171][v172].write(v173); // L312 + } + } + } + } + return ; // L317 +} + +void forward( + float v174[8][1024], + float v175[512], + float v176[512][1024], + float v177[512], + float v178[512][512], + float v179[256], + float v180[256][512], + float v181[10], + float v182[10][256], + float v183[8][10] +) { // L319 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v174 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v175 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v176 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v176 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v177 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v178 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v178 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v179 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v180 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v180 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v182 cyclic dim=2 factor=4 + + hls::stream v184[1][1]; + #pragma HLS STREAM variable=v184 depth=80 // L321 + hls::stream v185[1][1]; + #pragma HLS STREAM variable=v185 depth=80 // L322 + hls::stream v186[4][1]; + #pragma HLS STREAM variable=v186 depth=640 // L323 + hls::stream v187[1][4]; + #pragma HLS STREAM variable=v187 depth=512 // L324 + hls::stream v188[1][4]; + #pragma HLS STREAM variable=v188 depth=512 // L325 + hls::stream v189[16][4]; + #pragma HLS STREAM variable=v189 depth=2048 // L326 + hls::stream v190[1][16]; + #pragma HLS STREAM variable=v190 depth=256 // L327 + hls::stream v191[1][16]; + #pragma HLS STREAM variable=v191 depth=256 // L328 + hls::stream v192[16][16]; + #pragma HLS STREAM variable=v192 depth=1024 // L329 + hls::stream v193[1][16]; + #pragma HLS STREAM variable=v193 depth=256 // L330 + hls::stream v194[1][16]; + #pragma HLS STREAM variable=v194 depth=256 // L331 + hls::stream v195[1][16]; + #pragma HLS STREAM variable=v195 depth=256 // L332 + hls::stream v196[1][16]; + #pragma HLS STREAM variable=v196 depth=256 // L333 + hls::stream v197[8][16]; + #pragma HLS STREAM variable=v197 depth=4096 // L334 + node13(v176, v197); // L335 + node12(v174, v197, v196, 0.000000); // L336 + node11(v196, v175, v195, v194); // L337 + node10(v195, v193, 0.000000); // L338 + node9(v178, v192); // L339 + node8(v192, v193, v191, 0.000000); // L340 + node7(v191, v177, v194, v190, 0.000000); // L341 + node6(v180, v189); // L342 + node5(v189, v190, v188, 0.000000); // L343 + node4(v188, v179, v187); // L344 + node3(v182, v186); // L345 + node2(v187, v186, v185, 0.000000); // L346 + node1(v185, v181, v184); // L347 + node0(v184, v183); // L348 + return ; // L349 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt1/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt1/src/ResidualBlock.cpp new file mode 100644 index 000000000000..862e72ceb690 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt1/src/ResidualBlock.cpp @@ -0,0 +1,176 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { + #pragma HLS DATAFLOW + float v4[16][58][58]; + loop0: for (int v5 = 0; v5 < 16; v5++) { + loop1: for (int v6 = 0; v6 < 58; v6++) { + loop2: for (int v7 = 0; v7 < 58; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + v4[v5][v6][v7] = 0.000000; + } + } + } + loop3: for (int v8 = 0; v8 < 16; v8++) { + loop4: for (int v9 = 0; v9 < 56; v9++) { + loop5: for (int v10 = 0; v10 < 56; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v0[0][v8][v9][v10]; + v4[v8][(v9 + 1)][(v10 + 1)] = v11; + } + } + } + float v12[16][56][56]; + hls::stream v13("fifo_0"); + #pragma HLS STREAM variable=v13 depth=50176 + loop6: for (int v14 = 0; v14 < 16; v14++) { + loop7: for (int v15 = 0; v15 < 56; v15++) { + loop8: for (int v16 = 0; v16 < 56; v16++) { + loop9: for (int v17 = 0; v17 < 16; v17++) { + loop10: for (int v18 = 0; v18 < 3; v18++) { + loop11: for (int v19 = 0; v19 < 3; v19++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v20 = v4[v17][(v15 + v18)][(v16 + v19)]; + float v21 = v1[v14][v17][v18][v19]; + if (v17 == 0 && v18 == 0 && v19 == 0) { + v12[v14][v15][v16] = 0.000000; + } + float v22 = v12[v14][v15][v16]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v12[v14][v15][v16] = v24; + if ((v17 - 15) == 0 && (v18 - 2) == 0 && (v19 - 2) == 0) { + float v25 = v12[v14][v15][v16]; + v13.write(v25); + } + } + } + } + } + } + } + hls::stream v26("fifo_1"); + #pragma HLS STREAM variable=v26 depth=50176 + loop12: for (int v27 = 0; v27 < 16; v27++) { + loop13: for (int v28 = 0; v28 < 56; v28++) { + loop14: for (int v29 = 0; v29 < 56; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v30 = v13.read(); + float v31 = 0.000010; + float v32 = v31 + 1.000000; + float v33 = 1.0 / sqrt(v32); + float v34 = v30 * v33; + float v35 = v34 + 0.000000; + bool v36 = v35 > 0.000000; + float v37 = v36 ? (float)v35 : (float)0.000000; + v26.write(v37); + } + } + } + float v38[16][58][58]; + loop15: for (int v39 = 0; v39 < 16; v39++) { + loop16: for (int v40 = 0; v40 < 58; v40++) { + loop17: for (int v41 = 0; v41 < 58; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + v38[v39][v40][v41] = 0.000000; + } + } + } + loop18: for (int v42 = 0; v42 < 16; v42++) { + loop19: for (int v43 = 0; v43 < 56; v43++) { + loop20: for (int v44 = 0; v44 < 56; v44++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v45 = v26.read(); + v38[v42][(v43 + 1)][(v44 + 1)] = v45; + } + } + } + float v46[16][56][56]; + hls::stream v47("fifo_2"); + #pragma HLS STREAM variable=v47 depth=50176 + loop21: for (int v48 = 0; v48 < 16; v48++) { + loop22: for (int v49 = 0; v49 < 56; v49++) { + loop23: for (int v50 = 0; v50 < 56; v50++) { + loop24: for (int v51 = 0; v51 < 16; v51++) { + loop25: for (int v52 = 0; v52 < 3; v52++) { + loop26: for (int v53 = 0; v53 < 3; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v54 = v38[v51][(v49 + v52)][(v50 + v53)]; + float v55 = v2[v48][v51][v52][v53]; + if (v51 == 0 && v52 == 0 && v53 == 0) { + v46[v48][v49][v50] = 0.000000; + } + float v56 = v46[v48][v49][v50]; + float v57 = v54 * v55; + float v58 = v56 + v57; + v46[v48][v49][v50] = v58; + if ((v51 - 15) == 0 && (v52 - 2) == 0 && (v53 - 2) == 0) { + float v59 = v46[v48][v49][v50]; + v47.write(v59); + } + } + } + } + } + } + } + hls::stream v60("fifo_3"); + #pragma HLS STREAM variable=v60 depth=50176 + loop27: for (int v61 = 0; v61 < 16; v61++) { + loop28: for (int v62 = 0; v62 < 56; v62++) { + loop29: for (int v63 = 0; v63 < 56; v63++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v64 = v47.read(); + float v65 = v0[0][v61][v62][v63]; + float v66 = 0.000010; + float v67 = v66 + 1.000000; + float v68 = 1.0 / sqrt(v67); + float v69 = v64 * v68; + float v70 = v69 + 0.000000; + float v71 = v70 + v65; + bool v72 = v71 > 0.000000; + float v73 = v72 ? (float)v71 : (float)0.000000; + v60.write(v73); + } + } + } + loop30: for (int v74 = 0; v74 < 16; v74++) { + loop31: for (int v75 = 0; v75 < 56; v75++) { + loop32: for (int v76 = 0; v76 < 56; v76++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v77 = v60.read(); + v3[0][v74][v75][v76] = v77; + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt2/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt2/src/ResidualBlock.cpp new file mode 100644 index 000000000000..8b00eab7d1b6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt2/src/ResidualBlock.cpp @@ -0,0 +1,262 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][16][56][56] +) { // L6 + loop0: for (int v2 = 0; v2 < 56; v2++) { // L7 + loop1: for (int v3 = 0; v3 < 56; v3++) { // L8 + loop2: for (int v4 = 0; v4 < 16; v4++) { // L9 + #pragma HLS pipeline II=1 + float v5 = v0.read(); // L10 + v1[0][v4][v2][v3] = v5; // L11 + } + } + } + return ; // L15 +} + +void node1( + float v6[1][16][56][56], + hls::stream &v7, + hls::stream &v8, + double v9, + float v10, + float v11 +) { // L17 + loop3: for (int v12 = 0; v12 < 56; v12++) { // L18 + loop4: for (int v13 = 0; v13 < 56; v13++) { // L19 + loop5: for (int v14 = 0; v14 < 16; v14++) { // L20 + #pragma HLS pipeline II=1 + float v15 = v7.read(); // L21 + float v16 = v6[0][v14][v12][v13]; // L22 + float v17 = v9; // L23 + float v18 = v17 + v11; // L24 + float v19 = 1.0 / sqrt(v18); // L25 + float v20 = v15 * v19; // L26 + float v21 = v20 + v10; // L27 + float v22 = v21 + v16; // L28 + bool v23 = v22 > v10; // L29 + float v24 = v23 ? (float)v22 : (float)v10; // L30 + v8.write(v24); // L31 + } + } + } + return ; // L35 +} + +void node2( + hls::stream &v25, + float v26[16][16][3][3], + hls::stream &v27, + float v28 +) { // L37 + float v29[16]; // L38 + float v30[16][58][58]; // L39 + loop6: for (int v31 = 0; v31 < 58; v31++) { // L40 + loop7: for (int v32 = 0; v32 < 58; v32++) { // L41 + loop8: for (int v33 = 0; v33 < 16; v33++) { // L42 + loop9: for (int v34 = 0; v34 < 3; v34++) { // L43 + loop10: for (int v35 = 0; v35 < 3; v35++) { // L44 + loop11: for (int v36 = 0; v36 < 16; v36++) { // L45 + #pragma HLS pipeline II=1 + if (v36 == 0 && v34 == 0 && v35 == 0) { // L46 + float v37 = v25.read(); // L47 + v30[v33][v31][v32] = v37; // L48 + } + if ((v31 - 2) >= 0 && (v32 - 2) >= 0) { // L50 + float v38 = v30[v33][((v34 + v31) - 2)][((v35 + v32) - 2)]; // L51 + float v39 = v26[v36][v33][v34][v35]; // L52 + if (v33 == 0 && v34 == 0 && v35 == 0) { // L53 + v29[v36] = v28; // L54 + } + float v40 = v29[v36]; // L56 + float v41 = v38 * v39; // L57 + float v42 = v40 + v41; // L58 + v29[v36] = v42; // L59 + if ((v33 - 15) == 0 && (v34 - 2) == 0 && (v35 - 2) == 0) { // L60 + float v43 = v29[v36]; // L61 + v27.write(v43); // L62 + } + } + } + } + } + } + } + } + return ; // L71 +} + +void node3( + hls::stream &v44, + hls::stream &v45, + float v46 +) { // L73 + float v47[16][58][58]; // L74 + loop12: for (int v48 = 0; v48 < 58; v48++) { // L75 + loop13: for (int v49 = 0; v49 < 58; v49++) { // L76 + loop14: for (int v50 = 0; v50 < 16; v50++) { // L77 + #pragma HLS pipeline II=1 + v47[v50][v48][v49] = v46; // L78 + } + } + } + loop15: for (int v51 = 0; v51 < 58; v51++) { // L82 + loop16: for (int v52 = 0; v52 < 58; v52++) { // L83 + loop17: for (int v53 = 0; v53 < 16; v53++) { // L84 + #pragma HLS pipeline II=1 + if ((v51 - 1) >= 0 && (v52 - 1) >= 0 && ((-v51) + 56) >= 0 && ((-v52) + 56) >= 0) { // L85 + float v54 = v44.read(); // L86 + v47[v53][v51][v52] = v54; // L87 + } + float v55 = v47[v53][v51][v52]; // L89 + v45.write(v55); // L90 + } + } + } + return ; // L94 +} + +void node4( + hls::stream &v56, + hls::stream &v57, + double v58, + float v59, + float v60 +) { // L96 + loop18: for (int v61 = 0; v61 < 56; v61++) { // L97 + loop19: for (int v62 = 0; v62 < 56; v62++) { // L98 + loop20: for (int v63 = 0; v63 < 16; v63++) { // L99 + #pragma HLS pipeline II=1 + float v64 = v56.read(); // L100 + float v65 = v58; // L101 + float v66 = v65 + v59; // L102 + float v67 = 1.0 / sqrt(v66); // L103 + float v68 = v64 * v67; // L104 + float v69 = v68 + v60; // L105 + bool v70 = v69 > v60; // L106 + float v71 = v70 ? (float)v69 : (float)v60; // L107 + v57.write(v71); // L108 + } + } + } + return ; // L112 +} + +void node5( + float v72[16][16][3][3], + hls::stream &v73, + hls::stream &v74, + float v75 +) { // L114 + float v76[16]; // L115 + float v77[16][58][58]; // L116 + loop21: for (int v78 = 0; v78 < 58; v78++) { // L117 + loop22: for (int v79 = 0; v79 < 58; v79++) { // L118 + loop23: for (int v80 = 0; v80 < 3; v80++) { // L119 + loop24: for (int v81 = 0; v81 < 3; v81++) { // L120 + loop25: for (int v82 = 0; v82 < 16; v82++) { // L121 + loop26: for (int v83 = 0; v83 < 16; v83++) { // L122 + #pragma HLS pipeline II=1 + if (v83 == 0 && v80 == 0 && v81 == 0) { // L123 + float v84 = v73.read(); // L124 + v77[v82][v78][v79] = v84; // L125 + } + if ((v78 - 2) >= 0 && (v79 - 2) >= 0) { // L127 + float v85 = v77[v82][((v80 + v78) - 2)][((v81 + v79) - 2)]; // L128 + float v86 = v72[v83][v82][v80][v81]; // L129 + if (v82 == 0 && v80 == 0 && v81 == 0) { // L130 + v76[v83] = v75; // L131 + } + float v87 = v76[v83]; // L133 + float v88 = v85 * v86; // L134 + float v89 = v87 + v88; // L135 + v76[v83] = v89; // L136 + if ((v82 - 15) == 0 && (v80 - 2) == 0 && (v81 - 2) == 0) { // L137 + float v90 = v76[v83]; // L138 + v74.write(v90); // L139 + } + } + } + } + } + } + } + } + return ; // L148 +} + +void node6( + float v91[1][16][56][56], + hls::stream &v92, + float v93 +) { // L150 + float v94[16][58][58]; // L151 + loop27: for (int v95 = 0; v95 < 58; v95++) { // L152 + loop28: for (int v96 = 0; v96 < 58; v96++) { // L153 + loop29: for (int v97 = 0; v97 < 16; v97++) { // L154 + #pragma HLS pipeline II=1 + v94[v97][v95][v96] = v93; // L155 + } + } + } + loop30: for (int v98 = 0; v98 < 58; v98++) { // L159 + loop31: for (int v99 = 0; v99 < 58; v99++) { // L160 + loop32: for (int v100 = 0; v100 < 16; v100++) { // L161 + #pragma HLS pipeline II=1 + if ((v98 - 1) >= 0 && (v99 - 1) >= 0 && ((-v98) + 56) >= 0 && ((-v99) + 56) >= 0) { // L162 + float v101 = v91[0][v100][(v98 - 1)][(v99 - 1)]; // L163 + v94[v100][v98][v99] = v101; // L164 + } + float v102 = v94[v100][v98][v99]; // L166 + v92.write(v102); // L167 + } + } + } + return ; // L171 +} + +void forward( + float v103[1][16][56][56], + float v104[16][16][3][3], + float v105[16][16][3][3], + float v106[1][16][56][56] +) { // L173 + #pragma HLS DATAFLOW + hls::stream v107("fifo_0"); + #pragma HLS STREAM variable=v107 depth=50176 // L177 + hls::stream v108("fifo_1"); + #pragma HLS STREAM variable=v108 depth=50176 // L178 + hls::stream v109("fifo_2"); + #pragma HLS STREAM variable=v109 depth=53824 // L179 + hls::stream v110("fifo_3"); + #pragma HLS STREAM variable=v110 depth=50176 // L180 + hls::stream v111("fifo_4"); + #pragma HLS STREAM variable=v111 depth=50176 // L181 + hls::stream v112("fifo_5"); + #pragma HLS STREAM variable=v112 depth=53824 // L182 + node6(v103, v112, 0.000000); // L183 + node5(v104, v112, v111, 0.000000); // L184 + node4(v111, v110, 0.000010, 1.000000, 0.000000); // L185 + node3(v110, v109, 0.000000); // L186 + node2(v109, v105, v108, 0.000000); // L187 + node1(v103, v108, v107, 0.000010, 0.000000, 1.000000); // L188 + node0(v107, v106); // L189 + return ; // L190 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt3/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt3/src/ResidualBlock.cpp new file mode 100644 index 000000000000..1f61448e2b24 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt3/src/ResidualBlock.cpp @@ -0,0 +1,249 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { // L7 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=7 + + float v4[16][58][58]; // L11 + loop0: for (int v5 = 0; v5 < 8; v5++) { // L12 + loop1: for (int v6 = 0; v6 < 29; v6++) { // L13 + loop2: for (int v7 = 0; v7 < 58; v7++) { // L14 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 2; v8++) { // L15 + loop4: for (int v9 = 0; v9 < 2; v9++) { // L16 + loop5: for (int v10 = 0; v10 < 1; v10++) { // L17 + v4[(v8 + (v5 * 2))][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; // L18 + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { // L25 + loop7: for (int v12 = 0; v12 < 28; v12++) { // L26 + loop8: for (int v13 = 0; v13 < 56; v13++) { // L27 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 2; v14++) { // L28 + loop10: for (int v15 = 0; v15 < 2; v15++) { // L29 + loop11: for (int v16 = 0; v16 < 1; v16++) { // L30 + float v17 = v0[0][(v14 + (v11 * 2))][(v15 + (v12 * 2))][(v13 + v16)]; // L31 + v4[(v14 + (v11 * 2))][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; // L32 + } + } + } + } + } + } + float v18[16][56][56]; // L39 + hls::stream v19[2][2][1]; + #pragma HLS STREAM variable=v19 depth=12544 // L40 + loop12: for (int v20 = 0; v20 < 8; v20++) { // L41 + loop13: for (int v21 = 0; v21 < 28; v21++) { // L42 + loop14: for (int v22 = 0; v22 < 56; v22++) { // L43 + loop15: for (int v23 = 0; v23 < 8; v23++) { // L44 + loop16: for (int v24 = 0; v24 < 3; v24++) { // L45 + loop17: for (int v25 = 0; v25 < 3; v25++) { // L46 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop18: for (int v26 = 0; v26 < 2; v26++) { // L47 + loop19: for (int v27 = 0; v27 < 2; v27++) { // L48 + loop20: for (int v28 = 0; v28 < 1; v28++) { // L49 + loop21: for (int v29 = 0; v29 < 2; v29++) { // L50 + loop22: for (int v30 = 0; v30 < 1; v30++) { // L51 + loop23: for (int v31 = 0; v31 < 1; v31++) { // L52 + float v32 = v4[(v29 + (v23 * 2))][(((v27 + (v21 * 2)) + v24) + v30)][(((v22 + v28) + v25) + v31)]; // L53 + float v33 = v1[(v26 + (v20 * 2))][(v29 + (v23 * 2))][(v24 + v30)][(v25 + v31)]; // L54 + if ((v29 + (v23 * 2)) == 0 && (v24 + v30) == 0 && (v25 + v31) == 0) { // L55 + v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)] = 0.000000; // L56 + } + float v34 = v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)]; // L58 + float v35 = v32 * v33; // L59 + float v36 = v34 + v35; // L60 + v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)] = v36; // L61 + if (((v29 + (v23 * 2)) - 15) == 0 && ((v24 + v30) - 2) == 0 && ((v25 + v31) - 2) == 0) { // L62 + float v37 = v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)]; // L63 + v19[v26][v27][v28].write(v37); // L64 + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v38[2][2][1]; + #pragma HLS STREAM variable=v38 depth=12544 // L78 + loop24: for (int v39 = 0; v39 < 8; v39++) { // L79 + loop25: for (int v40 = 0; v40 < 28; v40++) { // L80 + loop26: for (int v41 = 0; v41 < 56; v41++) { // L81 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop27: for (int v42 = 0; v42 < 2; v42++) { // L82 + loop28: for (int v43 = 0; v43 < 2; v43++) { // L83 + loop29: for (int v44 = 0; v44 < 1; v44++) { // L84 + float v45 = v19[v42][v43][v44].read(); // L85 + float v46 = 0.000010; // L86 + float v47 = v46 + 1.000000; // L87 + float v48 = 1.0 / sqrt(v47); // L88 + float v49 = v45 * v48; // L89 + float v50 = v49 + 0.000000; // L90 + bool v51 = v50 > 0.000000; // L91 + float v52 = v51 ? (float)v50 : (float)0.000000; // L92 + v38[v42][v43][v44].write(v52); // L93 + } + } + } + } + } + } + float v53[16][58][58]; // L100 + loop30: for (int v54 = 0; v54 < 8; v54++) { // L101 + loop31: for (int v55 = 0; v55 < 29; v55++) { // L102 + loop32: for (int v56 = 0; v56 < 58; v56++) { // L103 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v57 = 0; v57 < 2; v57++) { // L104 + loop34: for (int v58 = 0; v58 < 2; v58++) { // L105 + loop35: for (int v59 = 0; v59 < 1; v59++) { // L106 + v53[(v57 + (v54 * 2))][(v58 + (v55 * 2))][(v56 + v59)] = 0.000000; // L107 + } + } + } + } + } + } + loop36: for (int v60 = 0; v60 < 8; v60++) { // L114 + loop37: for (int v61 = 0; v61 < 28; v61++) { // L115 + loop38: for (int v62 = 0; v62 < 56; v62++) { // L116 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v63 = 0; v63 < 2; v63++) { // L117 + loop40: for (int v64 = 0; v64 < 2; v64++) { // L118 + loop41: for (int v65 = 0; v65 < 1; v65++) { // L119 + float v66 = v38[v63][v64][v65].read(); // L120 + v53[(v63 + (v60 * 2))][((v64 + (v61 * 2)) + 1)][((v62 + v65) + 1)] = v66; // L121 + } + } + } + } + } + } + float v67[16][56][56]; // L128 + hls::stream v68[2][2][7]; + #pragma HLS STREAM variable=v68 depth=1792 // L129 + loop42: for (int v69 = 0; v69 < 8; v69++) { // L130 + loop43: for (int v70 = 0; v70 < 28; v70++) { // L131 + loop44: for (int v71 = 0; v71 < 8; v71++) { // L132 + loop45: for (int v72 = 0; v72 < 8; v72++) { // L133 + loop46: for (int v73 = 0; v73 < 3; v73++) { // L134 + loop47: for (int v74 = 0; v74 < 3; v74++) { // L135 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v75 = 0; v75 < 2; v75++) { // L136 + loop49: for (int v76 = 0; v76 < 2; v76++) { // L137 + loop50: for (int v77 = 0; v77 < 7; v77++) { // L138 + loop51: for (int v78 = 0; v78 < 2; v78++) { // L139 + loop52: for (int v79 = 0; v79 < 1; v79++) { // L140 + loop53: for (int v80 = 0; v80 < 1; v80++) { // L141 + float v81 = v53[(v78 + (v72 * 2))][(((v76 + (v70 * 2)) + v73) + v79)][(((v77 + (v71 * 7)) + v74) + v80)]; // L142 + float v82 = v2[(v75 + (v69 * 2))][(v78 + (v72 * 2))][(v73 + v79)][(v74 + v80)]; // L143 + if ((v78 + (v72 * 2)) == 0 && (v73 + v79) == 0 && (v74 + v80) == 0) { // L144 + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))] = 0.000000; // L145 + } + float v83 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))]; // L147 + float v84 = v81 * v82; // L148 + float v85 = v83 + v84; // L149 + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))] = v85; // L150 + if (((v78 + (v72 * 2)) - 15) == 0 && ((v73 + v79) - 2) == 0 && ((v74 + v80) - 2) == 0) { // L151 + float v86 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))]; // L152 + v68[v75][v76][v77].write(v86); // L153 + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v87[2][2][7]; + #pragma HLS STREAM variable=v87 depth=1792 // L167 + loop54: for (int v88 = 0; v88 < 8; v88++) { // L168 + loop55: for (int v89 = 0; v89 < 28; v89++) { // L169 + loop56: for (int v90 = 0; v90 < 8; v90++) { // L170 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v91 = 0; v91 < 2; v91++) { // L171 + loop58: for (int v92 = 0; v92 < 2; v92++) { // L172 + loop59: for (int v93 = 0; v93 < 7; v93++) { // L173 + float v94 = v68[v91][v92][v93].read(); // L174 + float v95 = v0[0][(v91 + (v88 * 2))][(v92 + (v89 * 2))][(v93 + (v90 * 7))]; // L175 + float v96 = 0.000010; // L176 + float v97 = v96 + 1.000000; // L177 + float v98 = 1.0 / sqrt(v97); // L178 + float v99 = v94 * v98; // L179 + float v100 = v99 + 0.000000; // L180 + float v101 = v100 + v95; // L181 + bool v102 = v101 > 0.000000; // L182 + float v103 = v102 ? (float)v101 : (float)0.000000; // L183 + v87[v91][v92][v93].write(v103); // L184 + } + } + } + } + } + } + loop60: for (int v104 = 0; v104 < 8; v104++) { // L191 + loop61: for (int v105 = 0; v105 < 28; v105++) { // L192 + loop62: for (int v106 = 0; v106 < 8; v106++) { // L193 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v107 = 0; v107 < 2; v107++) { // L194 + loop64: for (int v108 = 0; v108 < 2; v108++) { // L195 + loop65: for (int v109 = 0; v109 < 7; v109++) { // L196 + float v110 = v87[v107][v108][v109].read(); // L197 + v3[0][(v107 + (v104 * 2))][(v108 + (v105 * 2))][(v109 + (v106 * 7))] = v110; // L198 + } + } + } + } + } + } + return ; // L205 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt4/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt4/src/ResidualBlock.cpp new file mode 100644 index 000000000000..b7d0817fa8ca --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt4/src/ResidualBlock.cpp @@ -0,0 +1,249 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=7 + + float v4[16][58][58]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 58; v6++) { + loop2: for (int v7 = 0; v7 < 29; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 2; v8++) { + loop4: for (int v9 = 0; v9 < 1; v9++) { + loop5: for (int v10 = 0; v10 < 2; v10++) { + v4[(v8 + (v5 * 2))][(v10 + (v7 * 2))][(v6 + v9)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 56; v12++) { + loop8: for (int v13 = 0; v13 < 28; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 2; v14++) { + loop10: for (int v15 = 0; v15 < 1; v15++) { + loop11: for (int v16 = 0; v16 < 2; v16++) { + float v17 = v0[0][(v14 + (v11 * 2))][(v16 + (v13 * 2))][(v12 + v15)]; + v4[(v14 + (v11 * 2))][((v16 + (v13 * 2)) + 1)][((v12 + v15) + 1)] = v17; + } + } + } + } + } + } + float v18[16][56][56]; + hls::stream v19[2][2][1]; + #pragma HLS STREAM variable=v19 depth=12544 + loop12: for (int v20 = 0; v20 < 8; v20++) { + loop13: for (int v21 = 0; v21 < 8; v21++) { + loop14: for (int v22 = 0; v22 < 28; v22++) { + loop15: for (int v23 = 0; v23 < 3; v23++) { + loop16: for (int v24 = 0; v24 < 3; v24++) { + loop17: for (int v25 = 0; v25 < 56; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop18: for (int v26 = 0; v26 < 2; v26++) { + loop19: for (int v27 = 0; v27 < 2; v27++) { + loop20: for (int v28 = 0; v28 < 2; v28++) { + loop21: for (int v29 = 0; v29 < 1; v29++) { + loop22: for (int v30 = 0; v30 < 1; v30++) { + loop23: for (int v31 = 0; v31 < 1; v31++) { + float v32 = v4[(v27 + (v21 * 2))][(((v28 + (v22 * 2)) + v23) + v29)][(((v25 + v31) + v24) + v30)]; + float v33 = v1[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v23 + v29)][(v24 + v30)]; + if ((v27 + (v21 * 2)) == 0 && (v23 + v29) == 0 && (v24 + v30) == 0) { + v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)] = 0.000000; + } + float v34 = v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)]; + float v35 = v32 * v33; + float v36 = v34 + v35; + v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)] = v36; + if (((v27 + (v21 * 2)) - 15) == 0 && ((v23 + v29) - 2) == 0 && ((v24 + v30) - 2) == 0) { + float v37 = v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)]; + v19[v26][v28][v31].write(v37); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v38[2][2][1]; + #pragma HLS STREAM variable=v38 depth=12544 + loop24: for (int v39 = 0; v39 < 8; v39++) { + loop25: for (int v40 = 0; v40 < 28; v40++) { + loop26: for (int v41 = 0; v41 < 56; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop27: for (int v42 = 0; v42 < 2; v42++) { + loop28: for (int v43 = 0; v43 < 2; v43++) { + loop29: for (int v44 = 0; v44 < 1; v44++) { + float v45 = v19[v42][v43][v44].read(); + float v46 = 0.000010; + float v47 = v46 + 1.000000; + float v48 = 1.0 / sqrt(v47); + float v49 = v45 * v48; + float v50 = v49 + 0.000000; + bool v51 = v50 > 0.000000; + float v52 = v51 ? (float)v50 : (float)0.000000; + v38[v42][v43][v44].write(v52); + } + } + } + } + } + } + float v53[16][58][58]; + loop30: for (int v54 = 0; v54 < 8; v54++) { + loop31: for (int v55 = 0; v55 < 58; v55++) { + loop32: for (int v56 = 0; v56 < 29; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v57 = 0; v57 < 2; v57++) { + loop34: for (int v58 = 0; v58 < 1; v58++) { + loop35: for (int v59 = 0; v59 < 2; v59++) { + v53[(v57 + (v54 * 2))][(v59 + (v56 * 2))][(v55 + v58)] = 0.000000; + } + } + } + } + } + } + loop36: for (int v60 = 0; v60 < 8; v60++) { + loop37: for (int v61 = 0; v61 < 28; v61++) { + loop38: for (int v62 = 0; v62 < 56; v62++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v63 = 0; v63 < 2; v63++) { + loop40: for (int v64 = 0; v64 < 2; v64++) { + loop41: for (int v65 = 0; v65 < 1; v65++) { + float v66 = v38[v63][v64][v65].read(); + v53[(v63 + (v60 * 2))][((v64 + (v61 * 2)) + 1)][((v62 + v65) + 1)] = v66; + } + } + } + } + } + } + float v67[16][56][56]; + hls::stream v68[2][2][7]; + #pragma HLS STREAM variable=v68 depth=1792 + loop42: for (int v69 = 0; v69 < 8; v69++) { + loop43: for (int v70 = 0; v70 < 28; v70++) { + loop44: for (int v71 = 0; v71 < 8; v71++) { + loop45: for (int v72 = 0; v72 < 3; v72++) { + loop46: for (int v73 = 0; v73 < 3; v73++) { + loop47: for (int v74 = 0; v74 < 8; v74++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v75 = 0; v75 < 2; v75++) { + loop49: for (int v76 = 0; v76 < 2; v76++) { + loop50: for (int v77 = 0; v77 < 2; v77++) { + loop51: for (int v78 = 0; v78 < 1; v78++) { + loop52: for (int v79 = 0; v79 < 1; v79++) { + loop53: for (int v80 = 0; v80 < 7; v80++) { + float v81 = v53[(v77 + (v71 * 2))][(((v76 + (v70 * 2)) + v72) + v78)][(((v80 + (v74 * 7)) + v73) + v79)]; + float v82 = v2[(v75 + (v69 * 2))][(v77 + (v71 * 2))][(v72 + v78)][(v73 + v79)]; + if ((v77 + (v71 * 2)) == 0 && (v72 + v78) == 0 && (v73 + v79) == 0) { + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))] = 0.000000; + } + float v83 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))] = v85; + if (((v77 + (v71 * 2)) - 15) == 0 && ((v72 + v78) - 2) == 0 && ((v73 + v79) - 2) == 0) { + float v86 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))]; + v68[v75][v76][v80].write(v86); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v87[2][2][7]; + #pragma HLS STREAM variable=v87 depth=1792 + loop54: for (int v88 = 0; v88 < 8; v88++) { + loop55: for (int v89 = 0; v89 < 28; v89++) { + loop56: for (int v90 = 0; v90 < 8; v90++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v91 = 0; v91 < 2; v91++) { + loop58: for (int v92 = 0; v92 < 2; v92++) { + loop59: for (int v93 = 0; v93 < 7; v93++) { + float v94 = v68[v91][v92][v93].read(); + float v95 = v0[0][(v91 + (v88 * 2))][(v92 + (v89 * 2))][(v93 + (v90 * 7))]; + float v96 = 0.000010; + float v97 = v96 + 1.000000; + float v98 = 1.0 / sqrt(v97); + float v99 = v94 * v98; + float v100 = v99 + 0.000000; + float v101 = v100 + v95; + bool v102 = v101 > 0.000000; + float v103 = v102 ? (float)v101 : (float)0.000000; + v87[v91][v92][v93].write(v103); + } + } + } + } + } + } + loop60: for (int v104 = 0; v104 < 8; v104++) { + loop61: for (int v105 = 0; v105 < 28; v105++) { + loop62: for (int v106 = 0; v106 < 8; v106++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v107 = 0; v107 < 2; v107++) { + loop64: for (int v108 = 0; v108 < 2; v108++) { + loop65: for (int v109 = 0; v109 < 7; v109++) { + float v110 = v87[v107][v108][v109].read(); + v3[0][(v107 + (v104 * 2))][(v108 + (v105 * 2))][(v109 + (v106 * 7))] = v110; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt5/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt5/src/ResidualBlock.cpp new file mode 100644 index 000000000000..9fea4e30213a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/ResidualBlock__opt5/src/ResidualBlock.cpp @@ -0,0 +1,249 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=7 + + float v4[16][58][58]; + loop0: for (int v5 = 0; v5 < 29; v5++) { + loop1: for (int v6 = 0; v6 < 8; v6++) { + loop2: for (int v7 = 0; v7 < 58; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 2; v8++) { + loop4: for (int v9 = 0; v9 < 2; v9++) { + loop5: for (int v10 = 0; v10 < 1; v10++) { + v4[(v9 + (v6 * 2))][(v8 + (v5 * 2))][(v7 + v10)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 28; v12++) { + loop8: for (int v13 = 0; v13 < 56; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 2; v14++) { + loop10: for (int v15 = 0; v15 < 2; v15++) { + loop11: for (int v16 = 0; v16 < 1; v16++) { + float v17 = v0[0][(v14 + (v11 * 2))][(v15 + (v12 * 2))][(v13 + v16)]; + v4[(v14 + (v11 * 2))][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; + } + } + } + } + } + } + float v18[16][56][56]; + hls::stream v19[2][2][1]; + #pragma HLS STREAM variable=v19 depth=12544 + loop12: for (int v20 = 0; v20 < 56; v20++) { + loop13: for (int v21 = 0; v21 < 8; v21++) { + loop14: for (int v22 = 0; v22 < 3; v22++) { + loop15: for (int v23 = 0; v23 < 3; v23++) { + loop16: for (int v24 = 0; v24 < 28; v24++) { + loop17: for (int v25 = 0; v25 < 8; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop18: for (int v26 = 0; v26 < 1; v26++) { + loop19: for (int v27 = 0; v27 < 2; v27++) { + loop20: for (int v28 = 0; v28 < 1; v28++) { + loop21: for (int v29 = 0; v29 < 1; v29++) { + loop22: for (int v30 = 0; v30 < 2; v30++) { + loop23: for (int v31 = 0; v31 < 2; v31++) { + float v32 = v4[(v27 + (v21 * 2))][(((v30 + (v24 * 2)) + v23) + v29)][(((v20 + v26) + v22) + v28)]; + float v33 = v1[(v31 + (v25 * 2))][(v27 + (v21 * 2))][(v23 + v29)][(v22 + v28)]; + if ((v27 + (v21 * 2)) == 0 && (v23 + v29) == 0 && (v22 + v28) == 0) { + v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)] = 0.000000; + } + float v34 = v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)]; + float v35 = v32 * v33; + float v36 = v34 + v35; + v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)] = v36; + if (((v27 + (v21 * 2)) - 15) == 0 && ((v23 + v29) - 2) == 0 && ((v22 + v28) - 2) == 0) { + float v37 = v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)]; + v19[v31][v30][v26].write(v37); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v38[2][2][1]; + #pragma HLS STREAM variable=v38 depth=12544 + loop24: for (int v39 = 0; v39 < 56; v39++) { + loop25: for (int v40 = 0; v40 < 28; v40++) { + loop26: for (int v41 = 0; v41 < 8; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop27: for (int v42 = 0; v42 < 1; v42++) { + loop28: for (int v43 = 0; v43 < 2; v43++) { + loop29: for (int v44 = 0; v44 < 2; v44++) { + float v45 = v19[v44][v43][v42].read(); + float v46 = 0.000010; + float v47 = v46 + 1.000000; + float v48 = 1.0 / sqrt(v47); + float v49 = v45 * v48; + float v50 = v49 + 0.000000; + bool v51 = v50 > 0.000000; + float v52 = v51 ? (float)v50 : (float)0.000000; + v38[v44][v43][v42].write(v52); + } + } + } + } + } + } + float v53[16][58][58]; + loop30: for (int v54 = 0; v54 < 8; v54++) { + loop31: for (int v55 = 0; v55 < 29; v55++) { + loop32: for (int v56 = 0; v56 < 58; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v57 = 0; v57 < 2; v57++) { + loop34: for (int v58 = 0; v58 < 2; v58++) { + loop35: for (int v59 = 0; v59 < 1; v59++) { + v53[(v57 + (v54 * 2))][(v58 + (v55 * 2))][(v56 + v59)] = 0.000000; + } + } + } + } + } + } + loop36: for (int v60 = 0; v60 < 56; v60++) { + loop37: for (int v61 = 0; v61 < 28; v61++) { + loop38: for (int v62 = 0; v62 < 8; v62++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v63 = 0; v63 < 1; v63++) { + loop40: for (int v64 = 0; v64 < 2; v64++) { + loop41: for (int v65 = 0; v65 < 2; v65++) { + float v66 = v38[v65][v64][v63].read(); + v53[(v65 + (v62 * 2))][((v64 + (v61 * 2)) + 1)][((v60 + v63) + 1)] = v66; + } + } + } + } + } + } + float v67[16][56][56]; + hls::stream v68[2][2][7]; + #pragma HLS STREAM variable=v68 depth=1792 + loop42: for (int v69 = 0; v69 < 8; v69++) { + loop43: for (int v70 = 0; v70 < 3; v70++) { + loop44: for (int v71 = 0; v71 < 28; v71++) { + loop45: for (int v72 = 0; v72 < 3; v72++) { + loop46: for (int v73 = 0; v73 < 8; v73++) { + loop47: for (int v74 = 0; v74 < 8; v74++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v75 = 0; v75 < 2; v75++) { + loop49: for (int v76 = 0; v76 < 1; v76++) { + loop50: for (int v77 = 0; v77 < 2; v77++) { + loop51: for (int v78 = 0; v78 < 1; v78++) { + loop52: for (int v79 = 0; v79 < 2; v79++) { + loop53: for (int v80 = 0; v80 < 7; v80++) { + float v81 = v53[(v75 + (v69 * 2))][(((v77 + (v71 * 2)) + v72) + v78)][(((v80 + (v74 * 7)) + v70) + v76)]; + float v82 = v2[(v79 + (v73 * 2))][(v75 + (v69 * 2))][(v72 + v78)][(v70 + v76)]; + if ((v75 + (v69 * 2)) == 0 && (v72 + v78) == 0 && (v70 + v76) == 0) { + v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))] = 0.000000; + } + float v83 = v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))] = v85; + if (((v75 + (v69 * 2)) - 15) == 0 && ((v72 + v78) - 2) == 0 && ((v70 + v76) - 2) == 0) { + float v86 = v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))]; + v68[v79][v77][v80].write(v86); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v87[2][2][7]; + #pragma HLS STREAM variable=v87 depth=1792 + loop54: for (int v88 = 0; v88 < 28; v88++) { + loop55: for (int v89 = 0; v89 < 8; v89++) { + loop56: for (int v90 = 0; v90 < 8; v90++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v91 = 0; v91 < 2; v91++) { + loop58: for (int v92 = 0; v92 < 2; v92++) { + loop59: for (int v93 = 0; v93 < 7; v93++) { + float v94 = v68[v92][v91][v93].read(); + float v95 = v0[0][(v92 + (v89 * 2))][(v91 + (v88 * 2))][(v93 + (v90 * 7))]; + float v96 = 0.000010; + float v97 = v96 + 1.000000; + float v98 = 1.0 / sqrt(v97); + float v99 = v94 * v98; + float v100 = v99 + 0.000000; + float v101 = v100 + v95; + bool v102 = v101 > 0.000000; + float v103 = v102 ? (float)v101 : (float)0.000000; + v87[v92][v91][v93].write(v103); + } + } + } + } + } + } + loop60: for (int v104 = 0; v104 < 28; v104++) { + loop61: for (int v105 = 0; v105 < 8; v105++) { + loop62: for (int v106 = 0; v106 < 8; v106++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v107 = 0; v107 < 2; v107++) { + loop64: for (int v108 = 0; v108 < 2; v108++) { + loop65: for (int v109 = 0; v109 < 7; v109++) { + float v110 = v87[v108][v107][v109].read(); + v3[0][(v108 + (v105 * 2))][(v107 + (v104 * 2))][(v109 + (v106 * 7))] = v110; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt1/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt1/src/Autoencoder.cpp new file mode 100644 index 000000000000..acb2c8e6a8b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt1/src/Autoencoder.cpp @@ -0,0 +1,562 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[32][784] +) { // L7 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L8 + loop1: for (int v3 = 0; v3 < 784; v3++) { // L9 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L10 + v1[v2][v3] = v4; // L11 + } + } + return ; // L14 +} + +void node1( + hls::stream &v5, + float v6[784], + hls::stream &v7, + float v8 +) { // L16 + loop2: for (int v9 = 0; v9 < 32; v9++) { // L17 + loop3: for (int v10 = 0; v10 < 784; v10++) { // L18 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v5.read(); // L19 + float v12 = v6[v10]; // L20 + float v13 = v11 + v12; // L21 + float v14 = -(v13); // L22 + float v15 = exp(v14); // L23 + float v16 = v15 + v8; // L24 + float v17 = v8 / v16; // L25 + v7.write(v17); // L26 + } + } + return ; // L29 +} + +void node2( + hls::stream &v18, + hls::stream &v19, + hls::stream &v20, + float v21 +) { // L31 + float v22[32][784]; // L32 + float v23[256][784]; // L33 + float v24[32][256]; // L34 + loop4: for (int v25 = 0; v25 < 32; v25++) { // L35 + loop5: for (int v26 = 0; v26 < 784; v26++) { // L36 + loop6: for (int v27 = 0; v27 < 256; v27++) { // L37 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v26 == 0) { // L38 + float v28 = v18.read(); // L39 + v24[v25][v27] = v28; // L40 + } + float v29 = v24[v25][v27]; // L42 + if (v25 == 0) { // L43 + float v30 = v19.read(); // L44 + v23[v27][v26] = v30; // L45 + } + float v31 = v23[v27][v26]; // L47 + if (v27 == 0) { // L48 + v22[v25][v26] = v21; // L49 + } + float v32 = v22[v25][v26]; // L51 + float v33 = v29 * v31; // L52 + float v34 = v32 + v33; // L53 + v22[v25][v26] = v34; // L54 + if ((v27 - 255) == 0) { // L55 + float v35 = v22[v25][v26]; // L56 + v20.write(v35); // L57 + } + } + } + } + return ; // L62 +} + +void node3( + float v36[784][256], + hls::stream &v37 +) { // L64 + loop7: for (int v38 = 0; v38 < 784; v38++) { // L65 + loop8: for (int v39 = 0; v39 < 256; v39++) { // L66 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v38][v39]; // L67 + v37.write(v40); // L68 + } + } + return ; // L71 +} + +void node4( + hls::stream &v41, + float v42[256], + hls::stream &v43, + float v44 +) { // L73 + loop9: for (int v45 = 0; v45 < 32; v45++) { // L74 + loop10: for (int v46 = 0; v46 < 256; v46++) { // L75 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v47 = v41.read(); // L76 + float v48 = v42[v46]; // L77 + float v49 = v47 + v48; // L78 + bool v50 = v49 > v44; // L79 + float v51 = v50 ? (float)v49 : (float)v44; // L80 + v43.write(v51); // L81 + } + } + return ; // L84 +} + +void node5( + hls::stream &v52, + hls::stream &v53, + hls::stream &v54, + float v55 +) { // L86 + float v56[32][256]; // L87 + float v57[128][256]; // L88 + float v58[32][128]; // L89 + loop11: for (int v59 = 0; v59 < 32; v59++) { // L90 + loop12: for (int v60 = 0; v60 < 256; v60++) { // L91 + loop13: for (int v61 = 0; v61 < 128; v61++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { // L93 + float v62 = v53.read(); // L94 + v58[v59][v61] = v62; // L95 + } + float v63 = v58[v59][v61]; // L97 + if (v59 == 0) { // L98 + float v64 = v52.read(); // L99 + v57[v61][v60] = v64; // L100 + } + float v65 = v57[v61][v60]; // L102 + if (v61 == 0) { // L103 + v56[v59][v60] = v55; // L104 + } + float v66 = v56[v59][v60]; // L106 + float v67 = v63 * v65; // L107 + float v68 = v66 + v67; // L108 + v56[v59][v60] = v68; // L109 + if ((v61 - 127) == 0) { // L110 + float v69 = v56[v59][v60]; // L111 + v54.write(v69); // L112 + } + } + } + } + return ; // L117 +} + +void node6( + float v70[256][128], + hls::stream &v71 +) { // L119 + loop14: for (int v72 = 0; v72 < 256; v72++) { // L120 + loop15: for (int v73 = 0; v73 < 128; v73++) { // L121 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[v72][v73]; // L122 + v71.write(v74); // L123 + } + } + return ; // L126 +} + +void node7( + hls::stream &v75, + float v76[128], + hls::stream &v77, + float v78 +) { // L128 + loop16: for (int v79 = 0; v79 < 32; v79++) { // L129 + loop17: for (int v80 = 0; v80 < 128; v80++) { // L130 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v81 = v75.read(); // L131 + float v82 = v76[v80]; // L132 + float v83 = v81 + v82; // L133 + bool v84 = v83 > v78; // L134 + float v85 = v84 ? (float)v83 : (float)v78; // L135 + v77.write(v85); // L136 + } + } + return ; // L139 +} + +void node8( + hls::stream &v86, + hls::stream &v87, + hls::stream &v88, + float v89 +) { // L141 + float v90[32][128]; // L142 + float v91[64][128]; // L143 + float v92[32][64]; // L144 + loop18: for (int v93 = 0; v93 < 32; v93++) { // L145 + loop19: for (int v94 = 0; v94 < 128; v94++) { // L146 + loop20: for (int v95 = 0; v95 < 64; v95++) { // L147 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v94 == 0) { // L148 + float v96 = v87.read(); // L149 + v92[v93][v95] = v96; // L150 + } + float v97 = v92[v93][v95]; // L152 + if (v93 == 0) { // L153 + float v98 = v86.read(); // L154 + v91[v95][v94] = v98; // L155 + } + float v99 = v91[v95][v94]; // L157 + if (v95 == 0) { // L158 + v90[v93][v94] = v89; // L159 + } + float v100 = v90[v93][v94]; // L161 + float v101 = v97 * v99; // L162 + float v102 = v100 + v101; // L163 + v90[v93][v94] = v102; // L164 + if ((v95 - 63) == 0) { // L165 + float v103 = v90[v93][v94]; // L166 + v88.write(v103); // L167 + } + } + } + } + return ; // L172 +} + +void node9( + float v104[128][64], + hls::stream &v105 +) { // L174 + loop21: for (int v106 = 0; v106 < 128; v106++) { // L175 + loop22: for (int v107 = 0; v107 < 64; v107++) { // L176 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v108 = v104[v106][v107]; // L177 + v105.write(v108); // L178 + } + } + return ; // L181 +} + +void node10( + hls::stream &v109, + float v110[64], + hls::stream &v111 +) { // L183 + loop23: for (int v112 = 0; v112 < 32; v112++) { // L184 + loop24: for (int v113 = 0; v113 < 64; v113++) { // L185 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v109.read(); // L186 + float v115 = v110[v113]; // L187 + float v116 = v114 + v115; // L188 + v111.write(v116); // L189 + } + } + return ; // L192 +} + +void node11( + hls::stream &v117, + hls::stream &v118, + hls::stream &v119, + float v120 +) { // L194 + float v121[32][64]; // L195 + float v122[128][64]; // L196 + float v123[32][128]; // L197 + loop25: for (int v124 = 0; v124 < 32; v124++) { // L198 + loop26: for (int v125 = 0; v125 < 64; v125++) { // L199 + loop27: for (int v126 = 0; v126 < 128; v126++) { // L200 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v125 == 0) { // L201 + float v127 = v117.read(); // L202 + v123[v124][v126] = v127; // L203 + } + float v128 = v123[v124][v126]; // L205 + if (v124 == 0) { // L206 + float v129 = v118.read(); // L207 + v122[v126][v125] = v129; // L208 + } + float v130 = v122[v126][v125]; // L210 + if (v126 == 0) { // L211 + v121[v124][v125] = v120; // L212 + } + float v131 = v121[v124][v125]; // L214 + float v132 = v128 * v130; // L215 + float v133 = v131 + v132; // L216 + v121[v124][v125] = v133; // L217 + if ((v126 - 127) == 0) { // L218 + float v134 = v121[v124][v125]; // L219 + v119.write(v134); // L220 + } + } + } + } + return ; // L225 +} + +void node12( + float v135[64][128], + hls::stream &v136 +) { // L227 + loop28: for (int v137 = 0; v137 < 64; v137++) { // L228 + loop29: for (int v138 = 0; v138 < 128; v138++) { // L229 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v139 = v135[v137][v138]; // L230 + v136.write(v139); // L231 + } + } + return ; // L234 +} + +void node13( + hls::stream &v140, + float v141[128], + hls::stream &v142, + float v143 +) { // L236 + loop30: for (int v144 = 0; v144 < 32; v144++) { // L237 + loop31: for (int v145 = 0; v145 < 128; v145++) { // L238 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v146 = v140.read(); // L239 + float v147 = v141[v145]; // L240 + float v148 = v146 + v147; // L241 + bool v149 = v148 > v143; // L242 + float v150 = v149 ? (float)v148 : (float)v143; // L243 + v142.write(v150); // L244 + } + } + return ; // L247 +} + +void node14( + hls::stream &v151, + hls::stream &v152, + hls::stream &v153, + float v154 +) { // L249 + float v155[32][128]; // L250 + float v156[256][128]; // L251 + float v157[32][256]; // L252 + loop32: for (int v158 = 0; v158 < 32; v158++) { // L253 + loop33: for (int v159 = 0; v159 < 128; v159++) { // L254 + loop34: for (int v160 = 0; v160 < 256; v160++) { // L255 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v159 == 0) { // L256 + float v161 = v151.read(); // L257 + v157[v158][v160] = v161; // L258 + } + float v162 = v157[v158][v160]; // L260 + if (v158 == 0) { // L261 + float v163 = v152.read(); // L262 + v156[v160][v159] = v163; // L263 + } + float v164 = v156[v160][v159]; // L265 + if (v160 == 0) { // L266 + v155[v158][v159] = v154; // L267 + } + float v165 = v155[v158][v159]; // L269 + float v166 = v162 * v164; // L270 + float v167 = v165 + v166; // L271 + v155[v158][v159] = v167; // L272 + if ((v160 - 255) == 0) { // L273 + float v168 = v155[v158][v159]; // L274 + v153.write(v168); // L275 + } + } + } + } + return ; // L280 +} + +void node15( + float v169[128][256], + hls::stream &v170 +) { // L282 + loop35: for (int v171 = 0; v171 < 128; v171++) { // L283 + loop36: for (int v172 = 0; v172 < 256; v172++) { // L284 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v173 = v169[v171][v172]; // L285 + v170.write(v173); // L286 + } + } + return ; // L289 +} + +void node16( + hls::stream &v174, + float v175[256], + hls::stream &v176, + float v177 +) { // L291 + loop37: for (int v178 = 0; v178 < 32; v178++) { // L292 + loop38: for (int v179 = 0; v179 < 256; v179++) { // L293 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v180 = v174.read(); // L294 + float v181 = v175[v179]; // L295 + float v182 = v180 + v181; // L296 + bool v183 = v182 > v177; // L297 + float v184 = v183 ? (float)v182 : (float)v177; // L298 + v176.write(v184); // L299 + } + } + return ; // L302 +} + +void node17( + float v185[32][784], + hls::stream &v186, + hls::stream &v187, + float v188 +) { // L304 + float v189[32][256]; // L305 + float v190[784][256]; // L306 + loop39: for (int v191 = 0; v191 < 32; v191++) { // L307 + loop40: for (int v192 = 0; v192 < 256; v192++) { // L308 + loop41: for (int v193 = 0; v193 < 784; v193++) { // L309 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v185[v191][v193]; // L310 + if (v191 == 0) { // L311 + float v195 = v186.read(); // L312 + v190[v193][v192] = v195; // L313 + } + float v196 = v190[v193][v192]; // L315 + if (v193 == 0) { // L316 + v189[v191][v192] = v188; // L317 + } + float v197 = v189[v191][v192]; // L319 + float v198 = v194 * v196; // L320 + float v199 = v197 + v198; // L321 + v189[v191][v192] = v199; // L322 + if ((v193 - 783) == 0) { // L323 + float v200 = v189[v191][v192]; // L324 + v187.write(v200); // L325 + } + } + } + } + return ; // L330 +} + +void node18( + float v201[256][784], + hls::stream &v202 +) { // L332 + loop42: for (int v203 = 0; v203 < 256; v203++) { // L333 + loop43: for (int v204 = 0; v204 < 784; v204++) { // L334 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v205 = v201[v203][v204]; // L335 + v202.write(v205); // L336 + } + } + return ; // L339 +} + +void forward( + float v206[32][784], + float v207[256], + float v208[256][784], + float v209[128], + float v210[128][256], + float v211[64], + float v212[64][128], + float v213[128], + float v214[128][64], + float v215[256], + float v216[256][128], + float v217[784], + float v218[784][256], + float v219[32][784] +) { // L341 + #pragma HLS DATAFLOW + hls::stream v220("fifo_0"); + #pragma HLS STREAM variable=v220 depth=25088 // L344 + hls::stream v221("fifo_1"); + #pragma HLS STREAM variable=v221 depth=25088 // L345 + hls::stream v222("fifo_2"); + #pragma HLS STREAM variable=v222 depth=200704 // L346 + hls::stream v223("fifo_3"); + #pragma HLS STREAM variable=v223 depth=8192 // L347 + hls::stream v224("fifo_4"); + #pragma HLS STREAM variable=v224 depth=8192 // L348 + hls::stream v225("fifo_5"); + #pragma HLS STREAM variable=v225 depth=32768 // L349 + hls::stream v226("fifo_6"); + #pragma HLS STREAM variable=v226 depth=4096 // L350 + hls::stream v227("fifo_7"); + #pragma HLS STREAM variable=v227 depth=4096 // L351 + hls::stream v228("fifo_8"); + #pragma HLS STREAM variable=v228 depth=8192 // L352 + hls::stream v229("fifo_9"); + #pragma HLS STREAM variable=v229 depth=2048 // L353 + hls::stream v230("fifo_10"); + #pragma HLS STREAM variable=v230 depth=2048 // L354 + hls::stream v231("fifo_11"); + #pragma HLS STREAM variable=v231 depth=8192 // L355 + hls::stream v232("fifo_12"); + #pragma HLS STREAM variable=v232 depth=4096 // L356 + hls::stream v233("fifo_13"); + #pragma HLS STREAM variable=v233 depth=4096 // L357 + hls::stream v234("fifo_14"); + #pragma HLS STREAM variable=v234 depth=32768 // L358 + hls::stream v235("fifo_15"); + #pragma HLS STREAM variable=v235 depth=8192 // L359 + hls::stream v236("fifo_16"); + #pragma HLS STREAM variable=v236 depth=8192 // L360 + hls::stream v237("fifo_17"); + #pragma HLS STREAM variable=v237 depth=200704 // L361 + node18(v208, v237); // L362 + node17(v206, v237, v236, 0.000000); // L363 + node16(v236, v207, v235, 0.000000); // L364 + node15(v210, v234); // L365 + node14(v235, v234, v233, 0.000000); // L366 + node13(v233, v209, v232, 0.000000); // L367 + node12(v212, v231); // L368 + node11(v232, v231, v230, 0.000000); // L369 + node10(v230, v211, v229); // L370 + node9(v214, v228); // L371 + node8(v228, v229, v227, 0.000000); // L372 + node7(v227, v213, v226, 0.000000); // L373 + node6(v216, v225); // L374 + node5(v225, v226, v224, 0.000000); // L375 + node4(v224, v215, v223, 0.000000); // L376 + node3(v218, v222); // L377 + node2(v223, v222, v221, 0.000000); // L378 + node1(v221, v217, v220, 1.000000); // L379 + node0(v220, v219); // L380 + return ; // L381 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt2/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt2/src/Autoencoder.cpp new file mode 100644 index 000000000000..b0753b5fc629 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt2/src/Autoencoder.cpp @@ -0,0 +1,558 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[32][784] +) { // L7 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L8 + loop1: for (int v3 = 0; v3 < 784; v3++) { // L9 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L10 + v1[v2][v3] = v4; // L11 + } + } + return ; // L14 +} + +void node1( + hls::stream &v5, + float v6[784], + hls::stream &v7, + float v8 +) { // L16 + loop2: for (int v9 = 0; v9 < 32; v9++) { // L17 + loop3: for (int v10 = 0; v10 < 784; v10++) { // L18 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v5.read(); // L19 + float v12 = v6[v10]; // L20 + float v13 = v11 + v12; // L21 + float v14 = -(v13); // L22 + float v15 = exp(v14); // L23 + float v16 = v15 + v8; // L24 + float v17 = v8 / v16; // L25 + v7.write(v17); // L26 + } + } + return ; // L29 +} + +void node2( + float v18[256][784], + hls::stream &v19, + hls::stream &v20, + float v21 +) { // L31 + float v22[32][784]; // L32 + float v23[256][784]; // L33 + float v24[32][256]; // L34 + loop4: for (int v25 = 0; v25 < 32; v25++) { // L35 + loop5: for (int v26 = 0; v26 < 256; v26++) { // L36 + loop6: for (int v27 = 0; v27 < 784; v27++) { // L37 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v27 == 0) { // L38 + float v28 = v19.read(); // L39 + v24[v25][v26] = v28; // L40 + } + float v29 = v24[v25][v26]; // L42 + if (v25 == 0) { // L43 + float v30 = v18[v26][v27]; // L44 + v23[v26][v27] = v30; // L45 + } + float v31 = v23[v26][v27]; // L47 + if (v26 == 0) { // L48 + v22[v25][v27] = v21; // L49 + } + float v32 = v22[v25][v27]; // L51 + float v33 = v29 * v31; // L52 + float v34 = v32 + v33; // L53 + v22[v25][v27] = v34; // L54 + if ((v26 - 255) == 0) { // L55 + float v35 = v22[v25][v27]; // L56 + v20.write(v35); // L57 + } + } + } + } + return ; // L62 +} + +void node3( + float v36[784][256], + float v37[256][784] +) { // L64 + loop7: for (int v38 = 0; v38 < 784; v38++) { // L65 + loop8: for (int v39 = 0; v39 < 256; v39++) { // L66 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v38][v39]; // L67 + v37[v39][v38] = v40; // L68 + } + } + return ; // L71 +} + +void node4( + hls::stream &v41, + float v42[256], + hls::stream &v43, + float v44 +) { // L73 + loop9: for (int v45 = 0; v45 < 32; v45++) { // L74 + loop10: for (int v46 = 0; v46 < 256; v46++) { // L75 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v47 = v41.read(); // L76 + float v48 = v42[v46]; // L77 + float v49 = v47 + v48; // L78 + bool v50 = v49 > v44; // L79 + float v51 = v50 ? (float)v49 : (float)v44; // L80 + v43.write(v51); // L81 + } + } + return ; // L84 +} + +void node5( + float v52[128][256], + hls::stream &v53, + hls::stream &v54, + float v55 +) { // L86 + float v56[32][256]; // L87 + float v57[128][256]; // L88 + float v58[32][128]; // L89 + loop11: for (int v59 = 0; v59 < 32; v59++) { // L90 + loop12: for (int v60 = 0; v60 < 256; v60++) { // L91 + loop13: for (int v61 = 0; v61 < 128; v61++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { // L93 + float v62 = v53.read(); // L94 + v58[v59][v61] = v62; // L95 + } + float v63 = v58[v59][v61]; // L97 + if (v59 == 0) { // L98 + float v64 = v52[v61][v60]; // L99 + v57[v61][v60] = v64; // L100 + } + float v65 = v57[v61][v60]; // L102 + if (v61 == 0) { // L103 + v56[v59][v60] = v55; // L104 + } + float v66 = v56[v59][v60]; // L106 + float v67 = v63 * v65; // L107 + float v68 = v66 + v67; // L108 + v56[v59][v60] = v68; // L109 + if ((v61 - 127) == 0) { // L110 + float v69 = v56[v59][v60]; // L111 + v54.write(v69); // L112 + } + } + } + } + return ; // L117 +} + +void node6( + float v70[256][128], + float v71[128][256] +) { // L119 + loop14: for (int v72 = 0; v72 < 128; v72++) { // L120 + loop15: for (int v73 = 0; v73 < 256; v73++) { // L121 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[v73][v72]; // L122 + v71[v72][v73] = v74; // L123 + } + } + return ; // L126 +} + +void node7( + hls::stream &v75, + float v76[128], + hls::stream &v77, + float v78 +) { // L128 + loop16: for (int v79 = 0; v79 < 32; v79++) { // L129 + loop17: for (int v80 = 0; v80 < 128; v80++) { // L130 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v81 = v75.read(); // L131 + float v82 = v76[v80]; // L132 + float v83 = v81 + v82; // L133 + bool v84 = v83 > v78; // L134 + float v85 = v84 ? (float)v83 : (float)v78; // L135 + v77.write(v85); // L136 + } + } + return ; // L139 +} + +void node8( + float v86[64][128], + hls::stream &v87, + hls::stream &v88, + float v89 +) { // L141 + float v90[32][128]; // L142 + float v91[64][128]; // L143 + float v92[32][64]; // L144 + loop18: for (int v93 = 0; v93 < 32; v93++) { // L145 + loop19: for (int v94 = 0; v94 < 128; v94++) { // L146 + loop20: for (int v95 = 0; v95 < 64; v95++) { // L147 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v94 == 0) { // L148 + float v96 = v87.read(); // L149 + v92[v93][v95] = v96; // L150 + } + float v97 = v92[v93][v95]; // L152 + if (v93 == 0) { // L153 + float v98 = v86[v95][v94]; // L154 + v91[v95][v94] = v98; // L155 + } + float v99 = v91[v95][v94]; // L157 + if (v95 == 0) { // L158 + v90[v93][v94] = v89; // L159 + } + float v100 = v90[v93][v94]; // L161 + float v101 = v97 * v99; // L162 + float v102 = v100 + v101; // L163 + v90[v93][v94] = v102; // L164 + if ((v95 - 63) == 0) { // L165 + float v103 = v90[v93][v94]; // L166 + v88.write(v103); // L167 + } + } + } + } + return ; // L172 +} + +void node9( + float v104[128][64], + float v105[64][128] +) { // L174 + loop21: for (int v106 = 0; v106 < 64; v106++) { // L175 + loop22: for (int v107 = 0; v107 < 128; v107++) { // L176 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v108 = v104[v107][v106]; // L177 + v105[v106][v107] = v108; // L178 + } + } + return ; // L181 +} + +void node10( + hls::stream &v109, + float v110[64], + hls::stream &v111 +) { // L183 + loop23: for (int v112 = 0; v112 < 32; v112++) { // L184 + loop24: for (int v113 = 0; v113 < 64; v113++) { // L185 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v109.read(); // L186 + float v115 = v110[v113]; // L187 + float v116 = v114 + v115; // L188 + v111.write(v116); // L189 + } + } + return ; // L192 +} + +void node11( + hls::stream &v117, + float v118[128][64], + hls::stream &v119, + float v120 +) { // L194 + float v121[32][64]; // L195 + float v122[128][64]; // L196 + float v123[32][128]; // L197 + loop25: for (int v124 = 0; v124 < 32; v124++) { // L198 + loop26: for (int v125 = 0; v125 < 64; v125++) { // L199 + loop27: for (int v126 = 0; v126 < 128; v126++) { // L200 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v125 == 0) { // L201 + float v127 = v117.read(); // L202 + v123[v124][v126] = v127; // L203 + } + float v128 = v123[v124][v126]; // L205 + if (v124 == 0) { // L206 + float v129 = v118[v126][v125]; // L207 + v122[v126][v125] = v129; // L208 + } + float v130 = v122[v126][v125]; // L210 + if (v126 == 0) { // L211 + v121[v124][v125] = v120; // L212 + } + float v131 = v121[v124][v125]; // L214 + float v132 = v128 * v130; // L215 + float v133 = v131 + v132; // L216 + v121[v124][v125] = v133; // L217 + if ((v126 - 127) == 0) { // L218 + float v134 = v121[v124][v125]; // L219 + v119.write(v134); // L220 + } + } + } + } + return ; // L225 +} + +void node12( + float v135[64][128], + float v136[128][64] +) { // L227 + loop28: for (int v137 = 0; v137 < 128; v137++) { // L228 + loop29: for (int v138 = 0; v138 < 64; v138++) { // L229 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v139 = v135[v138][v137]; // L230 + v136[v137][v138] = v139; // L231 + } + } + return ; // L234 +} + +void node13( + hls::stream &v140, + float v141[128], + hls::stream &v142, + float v143 +) { // L236 + loop30: for (int v144 = 0; v144 < 32; v144++) { // L237 + loop31: for (int v145 = 0; v145 < 128; v145++) { // L238 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v146 = v140.read(); // L239 + float v147 = v141[v145]; // L240 + float v148 = v146 + v147; // L241 + bool v149 = v148 > v143; // L242 + float v150 = v149 ? (float)v148 : (float)v143; // L243 + v142.write(v150); // L244 + } + } + return ; // L247 +} + +void node14( + hls::stream &v151, + hls::stream &v152, + hls::stream &v153, + float v154 +) { // L249 + float v155[32][128]; // L250 + float v156[256][128]; // L251 + float v157[32][256]; // L252 + loop32: for (int v158 = 0; v158 < 32; v158++) { // L253 + loop33: for (int v159 = 0; v159 < 256; v159++) { // L254 + loop34: for (int v160 = 0; v160 < 128; v160++) { // L255 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v160 == 0) { // L256 + float v161 = v152.read(); // L257 + v157[v158][v159] = v161; // L258 + } + float v162 = v157[v158][v159]; // L260 + if (v158 == 0) { // L261 + float v163 = v151.read(); // L262 + v156[v159][v160] = v163; // L263 + } + float v164 = v156[v159][v160]; // L265 + if (v159 == 0) { // L266 + v155[v158][v160] = v154; // L267 + } + float v165 = v155[v158][v160]; // L269 + float v166 = v162 * v164; // L270 + float v167 = v165 + v166; // L271 + v155[v158][v160] = v167; // L272 + if ((v159 - 255) == 0) { // L273 + float v168 = v155[v158][v160]; // L274 + v153.write(v168); // L275 + } + } + } + } + return ; // L280 +} + +void node15( + float v169[128][256], + hls::stream &v170 +) { // L282 + loop35: for (int v171 = 0; v171 < 256; v171++) { // L283 + loop36: for (int v172 = 0; v172 < 128; v172++) { // L284 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v173 = v169[v172][v171]; // L285 + v170.write(v173); // L286 + } + } + return ; // L289 +} + +void node16( + hls::stream &v174, + float v175[256], + hls::stream &v176, + float v177 +) { // L291 + loop37: for (int v178 = 0; v178 < 32; v178++) { // L292 + loop38: for (int v179 = 0; v179 < 256; v179++) { // L293 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v180 = v174.read(); // L294 + float v181 = v175[v179]; // L295 + float v182 = v180 + v181; // L296 + bool v183 = v182 > v177; // L297 + float v184 = v183 ? (float)v182 : (float)v177; // L298 + v176.write(v184); // L299 + } + } + return ; // L302 +} + +void node17( + float v185[32][784], + hls::stream &v186, + hls::stream &v187, + float v188 +) { // L304 + float v189[32][256]; // L305 + float v190[784][256]; // L306 + loop39: for (int v191 = 0; v191 < 32; v191++) { // L307 + loop40: for (int v192 = 0; v192 < 784; v192++) { // L308 + loop41: for (int v193 = 0; v193 < 256; v193++) { // L309 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v185[v191][v192]; // L310 + if (v191 == 0) { // L311 + float v195 = v186.read(); // L312 + v190[v192][v193] = v195; // L313 + } + float v196 = v190[v192][v193]; // L315 + if (v192 == 0) { // L316 + v189[v191][v193] = v188; // L317 + } + float v197 = v189[v191][v193]; // L319 + float v198 = v194 * v196; // L320 + float v199 = v197 + v198; // L321 + v189[v191][v193] = v199; // L322 + if ((v192 - 783) == 0) { // L323 + float v200 = v189[v191][v193]; // L324 + v187.write(v200); // L325 + } + } + } + } + return ; // L330 +} + +void node18( + float v201[256][784], + hls::stream &v202 +) { // L332 + loop42: for (int v203 = 0; v203 < 784; v203++) { // L333 + loop43: for (int v204 = 0; v204 < 256; v204++) { // L334 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v205 = v201[v204][v203]; // L335 + v202.write(v205); // L336 + } + } + return ; // L339 +} + +void forward( + float v206[32][784], + float v207[256], + float v208[256][784], + float v209[128], + float v210[128][256], + float v211[64], + float v212[64][128], + float v213[128], + float v214[128][64], + float v215[256], + float v216[256][128], + float v217[784], + float v218[784][256], + float v219[32][784] +) { // L341 + #pragma HLS DATAFLOW + hls::stream v220("fifo_0"); + #pragma HLS STREAM variable=v220 depth=25088 // L344 + hls::stream v221("fifo_1"); + #pragma HLS STREAM variable=v221 depth=25088 // L345 + float v222[256][784]; // L346 + hls::stream v223("fifo_2"); + #pragma HLS STREAM variable=v223 depth=8192 // L347 + hls::stream v224("fifo_3"); + #pragma HLS STREAM variable=v224 depth=8192 // L348 + float v225[128][256]; // L349 + hls::stream v226("fifo_4"); + #pragma HLS STREAM variable=v226 depth=4096 // L350 + hls::stream v227("fifo_5"); + #pragma HLS STREAM variable=v227 depth=4096 // L351 + float v228[64][128]; // L352 + hls::stream v229("fifo_6"); + #pragma HLS STREAM variable=v229 depth=2048 // L353 + hls::stream v230("fifo_7"); + #pragma HLS STREAM variable=v230 depth=2048 // L354 + float v231[128][64]; // L355 + hls::stream v232("fifo_8"); + #pragma HLS STREAM variable=v232 depth=4096 // L356 + hls::stream v233("fifo_9"); + #pragma HLS STREAM variable=v233 depth=4096 // L357 + hls::stream v234("fifo_10"); + #pragma HLS STREAM variable=v234 depth=32768 // L358 + hls::stream v235("fifo_11"); + #pragma HLS STREAM variable=v235 depth=8192 // L359 + hls::stream v236("fifo_12"); + #pragma HLS STREAM variable=v236 depth=8192 // L360 + hls::stream v237("fifo_13"); + #pragma HLS STREAM variable=v237 depth=200704 // L361 + node18(v208, v237); // L362 + node17(v206, v237, v236, 0.000000); // L363 + node16(v236, v207, v235, 0.000000); // L364 + node15(v210, v234); // L365 + node14(v234, v235, v233, 0.000000); // L366 + node13(v233, v209, v232, 0.000000); // L367 + node12(v212, v231); // L368 + node11(v232, v231, v230, 0.000000); // L369 + node10(v230, v211, v229); // L370 + node9(v214, v228); // L371 + node8(v228, v229, v227, 0.000000); // L372 + node7(v227, v213, v226, 0.000000); // L373 + node6(v216, v225); // L374 + node5(v225, v226, v224, 0.000000); // L375 + node4(v224, v215, v223, 0.000000); // L376 + node3(v218, v222); // L377 + node2(v222, v223, v221, 0.000000); // L378 + node1(v221, v217, v220, 1.000000); // L379 + node0(v220, v219); // L380 + return ; // L381 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt3/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt3/src/Autoencoder.cpp new file mode 100644 index 000000000000..059f95354110 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt3/src/Autoencoder.cpp @@ -0,0 +1,650 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][49], + float v1[32][784] +) { // L15 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L16 + loop1: for (int v3 = 0; v3 < 16; v3++) { // L17 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L18 + loop3: for (int v5 = 0; v5 < 49; v5++) { // L19 + float v6 = v0[v4][v5].read(); // L20 + v1[(v2 + v4)][(v5 + (v3 * 49))] = v6; // L21 + } + } + } + } + return ; // L26 +} + +void node1( + hls::stream v7[1][49], + float v8[784], + hls::stream v9[1][49], + float v10 +) { // L28 + loop4: for (int v11 = 0; v11 < 32; v11++) { // L29 + loop5: for (int v12 = 0; v12 < 16; v12++) { // L30 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 1; v13++) { // L31 + loop7: for (int v14 = 0; v14 < 49; v14++) { // L32 + float v15 = v7[v13][v14].read(); // L33 + float v16 = v8[(v14 + (v12 * 49))]; // L34 + float v17 = v15 + v16; // L35 + float v18 = -(v17); // L36 + float v19 = exp(v18); // L37 + float v20 = v19 + v10; // L38 + float v21 = v10 / v20; // L39 + v9[v13][v14].write(v21); // L40 + } + } + } + } + return ; // L45 +} + +void node2( + hls::stream v22[1][4], + hls::stream v23[4][49], + hls::stream v24[1][49], + float v25 +) { // L47 + float v26[32][784]; // L48 + float v27[256][784]; // L49 + float v28[32][256]; // L50 + loop8: for (int v29 = 0; v29 < 32; v29++) { // L51 + loop9: for (int v30 = 0; v30 < 16; v30++) { // L52 + loop10: for (int v31 = 0; v31 < 64; v31++) { // L53 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v32 = 0; v32 < 1; v32++) { // L54 + loop12: for (int v33 = 0; v33 < 49; v33++) { // L55 + loop13: for (int v34 = 0; v34 < 4; v34++) { // L56 + if ((v33 + (v30 * 49)) == 0) { // L57 + float v35 = v22[v32][v34].read(); // L58 + v28[(v29 + v32)][(v34 + (v31 * 4))] = v35; // L59 + } + float v36 = v28[(v29 + v32)][(v34 + (v31 * 4))]; // L61 + if ((v29 + v32) == 0) { // L62 + float v37 = v23[v34][v33].read(); // L63 + v27[(v34 + (v31 * 4))][(v33 + (v30 * 49))] = v37; // L64 + } + float v38 = v27[(v34 + (v31 * 4))][(v33 + (v30 * 49))]; // L66 + if ((v34 + (v31 * 4)) == 0) { // L67 + v26[(v29 + v32)][(v33 + (v30 * 49))] = v25; // L68 + } + float v39 = v26[(v29 + v32)][(v33 + (v30 * 49))]; // L70 + float v40 = v36 * v38; // L71 + float v41 = v39 + v40; // L72 + v26[(v29 + v32)][(v33 + (v30 * 49))] = v41; // L73 + if (((v34 + (v31 * 4)) - 255) == 0) { // L74 + float v42 = v26[(v29 + v32)][(v33 + (v30 * 49))]; // L75 + v24[v32][v33].write(v42); // L76 + } + } + } + } + } + } + } + return ; // L84 +} + +void node3( + float v43[784][256], + hls::stream v44[4][49] +) { // L86 + loop14: for (int v45 = 0; v45 < 16; v45++) { // L87 + loop15: for (int v46 = 0; v46 < 64; v46++) { // L88 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v47 = 0; v47 < 49; v47++) { // L89 + loop17: for (int v48 = 0; v48 < 4; v48++) { // L90 + float v49 = v43[(v47 + (v45 * 49))][(v48 + (v46 * 4))]; // L91 + v44[v48][v47].write(v49); // L92 + } + } + } + } + return ; // L97 +} + +void node4( + hls::stream v50[1][4], + float v51[256], + hls::stream v52[1][4], + float v53 +) { // L99 + loop18: for (int v54 = 0; v54 < 32; v54++) { // L100 + loop19: for (int v55 = 0; v55 < 64; v55++) { // L101 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v56 = 0; v56 < 1; v56++) { // L102 + loop21: for (int v57 = 0; v57 < 4; v57++) { // L103 + float v58 = v50[v56][v57].read(); // L104 + float v59 = v51[(v57 + (v55 * 4))]; // L105 + float v60 = v58 + v59; // L106 + bool v61 = v60 > v53; // L107 + float v62 = v61 ? (float)v60 : (float)v53; // L108 + v52[v56][v57].write(v62); // L109 + } + } + } + } + return ; // L114 +} + +void node5( + hls::stream v63[1][8], + hls::stream v64[8][4], + hls::stream v65[1][4], + float v66 +) { // L116 + float v67[32][256]; // L117 + float v68[128][256]; // L118 + float v69[32][128]; // L119 + loop22: for (int v70 = 0; v70 < 32; v70++) { // L120 + loop23: for (int v71 = 0; v71 < 64; v71++) { // L121 + loop24: for (int v72 = 0; v72 < 16; v72++) { // L122 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 1; v73++) { // L123 + loop26: for (int v74 = 0; v74 < 4; v74++) { // L124 + loop27: for (int v75 = 0; v75 < 8; v75++) { // L125 + if ((v74 + (v71 * 4)) == 0) { // L126 + float v76 = v63[v73][v75].read(); // L127 + v69[(v70 + v73)][(v75 + (v72 * 8))] = v76; // L128 + } + float v77 = v69[(v70 + v73)][(v75 + (v72 * 8))]; // L130 + if ((v70 + v73) == 0) { // L131 + float v78 = v64[v75][v74].read(); // L132 + v68[(v75 + (v72 * 8))][(v74 + (v71 * 4))] = v78; // L133 + } + float v79 = v68[(v75 + (v72 * 8))][(v74 + (v71 * 4))]; // L135 + if ((v75 + (v72 * 8)) == 0) { // L136 + v67[(v70 + v73)][(v74 + (v71 * 4))] = v66; // L137 + } + float v80 = v67[(v70 + v73)][(v74 + (v71 * 4))]; // L139 + float v81 = v77 * v79; // L140 + float v82 = v80 + v81; // L141 + v67[(v70 + v73)][(v74 + (v71 * 4))] = v82; // L142 + if (((v75 + (v72 * 8)) - 127) == 0) { // L143 + float v83 = v67[(v70 + v73)][(v74 + (v71 * 4))]; // L144 + v65[v73][v74].write(v83); // L145 + } + } + } + } + } + } + } + return ; // L153 +} + +void node6( + float v84[256][128], + hls::stream v85[8][4] +) { // L155 + loop28: for (int v86 = 0; v86 < 64; v86++) { // L156 + loop29: for (int v87 = 0; v87 < 16; v87++) { // L157 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v88 = 0; v88 < 4; v88++) { // L158 + loop31: for (int v89 = 0; v89 < 8; v89++) { // L159 + float v90 = v84[(v88 + (v86 * 4))][(v89 + (v87 * 8))]; // L160 + v85[v89][v88].write(v90); // L161 + } + } + } + } + return ; // L166 +} + +void node7( + hls::stream v91[1][8], + float v92[128], + hls::stream v93[1][8], + float v94 +) { // L168 + loop32: for (int v95 = 0; v95 < 32; v95++) { // L169 + loop33: for (int v96 = 0; v96 < 16; v96++) { // L170 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v97 = 0; v97 < 1; v97++) { // L171 + loop35: for (int v98 = 0; v98 < 8; v98++) { // L172 + float v99 = v91[v97][v98].read(); // L173 + float v100 = v92[(v98 + (v96 * 8))]; // L174 + float v101 = v99 + v100; // L175 + bool v102 = v101 > v94; // L176 + float v103 = v102 ? (float)v101 : (float)v94; // L177 + v93[v97][v98].write(v103); // L178 + } + } + } + } + return ; // L183 +} + +void node8( + hls::stream v104[2][8], + hls::stream v105[1][2], + hls::stream v106[1][8], + float v107 +) { // L185 + float v108[32][128]; // L186 + float v109[64][128]; // L187 + float v110[32][64]; // L188 + loop36: for (int v111 = 0; v111 < 32; v111++) { // L189 + loop37: for (int v112 = 0; v112 < 16; v112++) { // L190 + loop38: for (int v113 = 0; v113 < 32; v113++) { // L191 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v114 = 0; v114 < 1; v114++) { // L192 + loop40: for (int v115 = 0; v115 < 8; v115++) { // L193 + loop41: for (int v116 = 0; v116 < 2; v116++) { // L194 + if ((v115 + (v112 * 8)) == 0) { // L195 + float v117 = v105[v114][v116].read(); // L196 + v110[(v111 + v114)][(v116 + (v113 * 2))] = v117; // L197 + } + float v118 = v110[(v111 + v114)][(v116 + (v113 * 2))]; // L199 + if ((v111 + v114) == 0) { // L200 + float v119 = v104[v116][v115].read(); // L201 + v109[(v116 + (v113 * 2))][(v115 + (v112 * 8))] = v119; // L202 + } + float v120 = v109[(v116 + (v113 * 2))][(v115 + (v112 * 8))]; // L204 + if ((v116 + (v113 * 2)) == 0) { // L205 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v107; // L206 + } + float v121 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L208 + float v122 = v118 * v120; // L209 + float v123 = v121 + v122; // L210 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v123; // L211 + if (((v116 + (v113 * 2)) - 63) == 0) { // L212 + float v124 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L213 + v106[v114][v115].write(v124); // L214 + } + } + } + } + } + } + } + return ; // L222 +} + +void node9( + float v125[128][64], + hls::stream v126[2][8] +) { // L224 + loop42: for (int v127 = 0; v127 < 16; v127++) { // L225 + loop43: for (int v128 = 0; v128 < 32; v128++) { // L226 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v129 = 0; v129 < 8; v129++) { // L227 + loop45: for (int v130 = 0; v130 < 2; v130++) { // L228 + float v131 = v125[(v129 + (v127 * 8))][(v130 + (v128 * 2))]; // L229 + v126[v130][v129].write(v131); // L230 + } + } + } + } + return ; // L235 +} + +void node10( + hls::stream v132[1][2], + float v133[64], + hls::stream v134[1][2] +) { // L237 + loop46: for (int v135 = 0; v135 < 32; v135++) { // L238 + loop47: for (int v136 = 0; v136 < 32; v136++) { // L239 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v137 = 0; v137 < 1; v137++) { // L240 + loop49: for (int v138 = 0; v138 < 2; v138++) { // L241 + float v139 = v132[v137][v138].read(); // L242 + float v140 = v133[(v138 + (v136 * 2))]; // L243 + float v141 = v139 + v140; // L244 + v134[v137][v138].write(v141); // L245 + } + } + } + } + return ; // L250 +} + +void node11( + hls::stream v142[1][4], + hls::stream v143[4][2], + hls::stream v144[1][2], + float v145 +) { // L252 + float v146[32][64]; // L253 + float v147[128][64]; // L254 + float v148[32][128]; // L255 + loop50: for (int v149 = 0; v149 < 32; v149++) { // L256 + loop51: for (int v150 = 0; v150 < 32; v150++) { // L257 + loop52: for (int v151 = 0; v151 < 32; v151++) { // L258 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v152 = 0; v152 < 1; v152++) { // L259 + loop54: for (int v153 = 0; v153 < 2; v153++) { // L260 + loop55: for (int v154 = 0; v154 < 4; v154++) { // L261 + if ((v153 + (v150 * 2)) == 0) { // L262 + float v155 = v142[v152][v154].read(); // L263 + v148[(v149 + v152)][(v154 + (v151 * 4))] = v155; // L264 + } + float v156 = v148[(v149 + v152)][(v154 + (v151 * 4))]; // L266 + if ((v149 + v152) == 0) { // L267 + float v157 = v143[v154][v153].read(); // L268 + v147[(v154 + (v151 * 4))][(v153 + (v150 * 2))] = v157; // L269 + } + float v158 = v147[(v154 + (v151 * 4))][(v153 + (v150 * 2))]; // L271 + if ((v154 + (v151 * 4)) == 0) { // L272 + v146[(v149 + v152)][(v153 + (v150 * 2))] = v145; // L273 + } + float v159 = v146[(v149 + v152)][(v153 + (v150 * 2))]; // L275 + float v160 = v156 * v158; // L276 + float v161 = v159 + v160; // L277 + v146[(v149 + v152)][(v153 + (v150 * 2))] = v161; // L278 + if (((v154 + (v151 * 4)) - 127) == 0) { // L279 + float v162 = v146[(v149 + v152)][(v153 + (v150 * 2))]; // L280 + v144[v152][v153].write(v162); // L281 + } + } + } + } + } + } + } + return ; // L289 +} + +void node12( + float v163[64][128], + hls::stream v164[4][2] +) { // L291 + loop56: for (int v165 = 0; v165 < 32; v165++) { // L292 + loop57: for (int v166 = 0; v166 < 32; v166++) { // L293 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop58: for (int v167 = 0; v167 < 2; v167++) { // L294 + loop59: for (int v168 = 0; v168 < 4; v168++) { // L295 + float v169 = v163[(v167 + (v165 * 2))][(v168 + (v166 * 4))]; // L296 + v164[v168][v167].write(v169); // L297 + } + } + } + } + return ; // L302 +} + +void node13( + hls::stream v170[1][4], + float v171[128], + hls::stream v172[1][4], + float v173 +) { // L304 + loop60: for (int v174 = 0; v174 < 32; v174++) { // L305 + loop61: for (int v175 = 0; v175 < 32; v175++) { // L306 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v176 = 0; v176 < 1; v176++) { // L307 + loop63: for (int v177 = 0; v177 < 4; v177++) { // L308 + float v178 = v170[v176][v177].read(); // L309 + float v179 = v171[(v177 + (v175 * 4))]; // L310 + float v180 = v178 + v179; // L311 + bool v181 = v180 > v173; // L312 + float v182 = v181 ? (float)v180 : (float)v173; // L313 + v172[v176][v177].write(v182); // L314 + } + } + } + } + return ; // L319 +} + +void node14( + hls::stream v183[8][4], + hls::stream v184[1][8], + hls::stream v185[1][4], + float v186 +) { // L321 + float v187[32][128]; // L322 + float v188[256][128]; // L323 + float v189[32][256]; // L324 + loop64: for (int v190 = 0; v190 < 32; v190++) { // L325 + loop65: for (int v191 = 0; v191 < 32; v191++) { // L326 + loop66: for (int v192 = 0; v192 < 32; v192++) { // L327 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop67: for (int v193 = 0; v193 < 1; v193++) { // L328 + loop68: for (int v194 = 0; v194 < 4; v194++) { // L329 + loop69: for (int v195 = 0; v195 < 8; v195++) { // L330 + if ((v194 + (v191 * 4)) == 0) { // L331 + float v196 = v184[v193][v195].read(); // L332 + v189[(v190 + v193)][(v195 + (v192 * 8))] = v196; // L333 + } + float v197 = v189[(v190 + v193)][(v195 + (v192 * 8))]; // L335 + if ((v190 + v193) == 0) { // L336 + float v198 = v183[v195][v194].read(); // L337 + v188[(v195 + (v192 * 8))][(v194 + (v191 * 4))] = v198; // L338 + } + float v199 = v188[(v195 + (v192 * 8))][(v194 + (v191 * 4))]; // L340 + if ((v195 + (v192 * 8)) == 0) { // L341 + v187[(v190 + v193)][(v194 + (v191 * 4))] = v186; // L342 + } + float v200 = v187[(v190 + v193)][(v194 + (v191 * 4))]; // L344 + float v201 = v197 * v199; // L345 + float v202 = v200 + v201; // L346 + v187[(v190 + v193)][(v194 + (v191 * 4))] = v202; // L347 + if (((v195 + (v192 * 8)) - 255) == 0) { // L348 + float v203 = v187[(v190 + v193)][(v194 + (v191 * 4))]; // L349 + v185[v193][v194].write(v203); // L350 + } + } + } + } + } + } + } + return ; // L358 +} + +void node15( + float v204[128][256], + hls::stream v205[8][4] +) { // L360 + loop70: for (int v206 = 0; v206 < 32; v206++) { // L361 + loop71: for (int v207 = 0; v207 < 32; v207++) { // L362 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop72: for (int v208 = 0; v208 < 4; v208++) { // L363 + loop73: for (int v209 = 0; v209 < 8; v209++) { // L364 + float v210 = v204[(v208 + (v206 * 4))][(v209 + (v207 * 8))]; // L365 + v205[v209][v208].write(v210); // L366 + } + } + } + } + return ; // L371 +} + +void node16( + hls::stream v211[1][8], + float v212[256], + hls::stream v213[1][8], + float v214 +) { // L373 + loop74: for (int v215 = 0; v215 < 32; v215++) { // L374 + loop75: for (int v216 = 0; v216 < 32; v216++) { // L375 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v217 = 0; v217 < 1; v217++) { // L376 + loop77: for (int v218 = 0; v218 < 8; v218++) { // L377 + float v219 = v211[v217][v218].read(); // L378 + float v220 = v212[(v218 + (v216 * 8))]; // L379 + float v221 = v219 + v220; // L380 + bool v222 = v221 > v214; // L381 + float v223 = v222 ? (float)v221 : (float)v214; // L382 + v213[v217][v218].write(v223); // L383 + } + } + } + } + return ; // L388 +} + +void node17( + float v224[32][784], + hls::stream v225[28][8], + hls::stream v226[1][8], + float v227 +) { // L390 + float v228[32][256]; // L391 + float v229[784][256]; // L392 + loop78: for (int v230 = 0; v230 < 32; v230++) { // L393 + loop79: for (int v231 = 0; v231 < 32; v231++) { // L394 + loop80: for (int v232 = 0; v232 < 28; v232++) { // L395 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v233 = 0; v233 < 1; v233++) { // L396 + loop82: for (int v234 = 0; v234 < 8; v234++) { // L397 + loop83: for (int v235 = 0; v235 < 28; v235++) { // L398 + float v236 = v224[(v230 + v233)][(v235 + (v232 * 28))]; // L399 + if ((v230 + v233) == 0) { // L400 + float v237 = v225[v235][v234].read(); // L401 + v229[(v235 + (v232 * 28))][(v234 + (v231 * 8))] = v237; // L402 + } + float v238 = v229[(v235 + (v232 * 28))][(v234 + (v231 * 8))]; // L404 + if ((v235 + (v232 * 28)) == 0) { // L405 + v228[(v230 + v233)][(v234 + (v231 * 8))] = v227; // L406 + } + float v239 = v228[(v230 + v233)][(v234 + (v231 * 8))]; // L408 + float v240 = v236 * v238; // L409 + float v241 = v239 + v240; // L410 + v228[(v230 + v233)][(v234 + (v231 * 8))] = v241; // L411 + if (((v235 + (v232 * 28)) - 783) == 0) { // L412 + float v242 = v228[(v230 + v233)][(v234 + (v231 * 8))]; // L413 + v226[v233][v234].write(v242); // L414 + } + } + } + } + } + } + } + return ; // L422 +} + +void node18( + float v243[256][784], + hls::stream v244[28][8] +) { // L424 + loop84: for (int v245 = 0; v245 < 32; v245++) { // L425 + loop85: for (int v246 = 0; v246 < 28; v246++) { // L426 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v247 = 0; v247 < 8; v247++) { // L427 + loop87: for (int v248 = 0; v248 < 28; v248++) { // L428 + float v249 = v243[(v247 + (v245 * 8))][(v248 + (v246 * 28))]; // L429 + v244[v248][v247].write(v249); // L430 + } + } + } + } + return ; // L435 +} + +void forward( + float v250[32][784], + float v251[256], + float v252[256][784], + float v253[128], + float v254[128][256], + float v255[64], + float v256[64][128], + float v257[128], + float v258[128][64], + float v259[256], + float v260[256][128], + float v261[784], + float v262[784][256], + float v263[32][784] +) { // L437 + #pragma HLS DATAFLOW + hls::stream v264[1][49]; + #pragma HLS STREAM variable=v264 depth=512 // L440 + hls::stream v265[1][49]; + #pragma HLS STREAM variable=v265 depth=512 // L441 + hls::stream v266[4][49]; + #pragma HLS STREAM variable=v266 depth=1024 // L442 + hls::stream v267[1][4]; + #pragma HLS STREAM variable=v267 depth=2048 // L443 + hls::stream v268[1][4]; + #pragma HLS STREAM variable=v268 depth=2048 // L444 + hls::stream v269[8][4]; + #pragma HLS STREAM variable=v269 depth=1024 // L445 + hls::stream v270[1][8]; + #pragma HLS STREAM variable=v270 depth=512 // L446 + hls::stream v271[1][8]; + #pragma HLS STREAM variable=v271 depth=512 // L447 + hls::stream v272[2][8]; + #pragma HLS STREAM variable=v272 depth=512 // L448 + hls::stream v273[1][2]; + #pragma HLS STREAM variable=v273 depth=1024 // L449 + hls::stream v274[1][2]; + #pragma HLS STREAM variable=v274 depth=1024 // L450 + hls::stream v275[4][2]; + #pragma HLS STREAM variable=v275 depth=1024 // L451 + hls::stream v276[1][4]; + #pragma HLS STREAM variable=v276 depth=1024 // L452 + hls::stream v277[1][4]; + #pragma HLS STREAM variable=v277 depth=1024 // L453 + hls::stream v278[8][4]; + #pragma HLS STREAM variable=v278 depth=1024 // L454 + hls::stream v279[1][8]; + #pragma HLS STREAM variable=v279 depth=1024 // L455 + hls::stream v280[1][8]; + #pragma HLS STREAM variable=v280 depth=1024 // L456 + hls::stream v281[28][8]; + #pragma HLS STREAM variable=v281 depth=896 // L457 + node18(v252, v281); // L458 + node17(v250, v281, v280, 0.000000); // L459 + node16(v280, v251, v279, 0.000000); // L460 + node15(v254, v278); // L461 + node14(v278, v279, v277, 0.000000); // L462 + node13(v277, v253, v276, 0.000000); // L463 + node12(v256, v275); // L464 + node11(v276, v275, v274, 0.000000); // L465 + node10(v274, v255, v273); // L466 + node9(v258, v272); // L467 + node8(v272, v273, v271, 0.000000); // L468 + node7(v271, v257, v270, 0.000000); // L469 + node6(v260, v269); // L470 + node5(v270, v269, v268, 0.000000); // L471 + node4(v268, v259, v267, 0.000000); // L472 + node3(v262, v266); // L473 + node2(v267, v266, v265, 0.000000); // L474 + node1(v265, v261, v264, 1.000000); // L475 + node0(v264, v263); // L476 + return ; // L477 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt4/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt4/src/Autoencoder.cpp new file mode 100644 index 000000000000..6c24c5d09cf1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt4/src/Autoencoder.cpp @@ -0,0 +1,646 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][8], + float v1[32][784] +) { // L12 + loop0: for (int v2 = 0; v2 < 32; v2++) { // L13 + loop1: for (int v3 = 0; v3 < 98; v3++) { // L14 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L15 + loop3: for (int v5 = 0; v5 < 8; v5++) { // L16 + float v6 = v0[v4][v5].read(); // L17 + v1[(v2 + v4)][(v5 + (v3 * 8))] = v6; // L18 + } + } + } + } + return ; // L23 +} + +void node1( + hls::stream v7[1][8], + float v8[784], + hls::stream v9[1][8], + float v10 +) { // L25 + loop4: for (int v11 = 0; v11 < 32; v11++) { // L26 + loop5: for (int v12 = 0; v12 < 98; v12++) { // L27 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 1; v13++) { // L28 + loop7: for (int v14 = 0; v14 < 8; v14++) { // L29 + float v15 = v7[v13][v14].read(); // L30 + float v16 = v8[(v14 + (v12 * 8))]; // L31 + float v17 = v15 + v16; // L32 + float v18 = -(v17); // L33 + float v19 = exp(v18); // L34 + float v20 = v19 + v10; // L35 + float v21 = v10 / v20; // L36 + v9[v13][v14].write(v21); // L37 + } + } + } + } + return ; // L42 +} + +void node2( + hls::stream v22[1][16], + float v23[256][784], + hls::stream v24[1][8], + float v25 +) { // L44 + float v26[32][784]; // L45 + float v27[256][784]; // L46 + float v28[32][256]; // L47 + loop8: for (int v29 = 0; v29 < 32; v29++) { // L48 + loop9: for (int v30 = 0; v30 < 16; v30++) { // L49 + loop10: for (int v31 = 0; v31 < 98; v31++) { // L50 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v32 = 0; v32 < 1; v32++) { // L51 + loop12: for (int v33 = 0; v33 < 16; v33++) { // L52 + loop13: for (int v34 = 0; v34 < 8; v34++) { // L53 + if ((v34 + (v31 * 8)) == 0) { // L54 + float v35 = v22[v32][v33].read(); // L55 + v28[(v29 + v32)][(v33 + (v30 * 16))] = v35; // L56 + } + float v36 = v28[(v29 + v32)][(v33 + (v30 * 16))]; // L58 + if ((v29 + v32) == 0) { // L59 + float v37 = v23[(v33 + (v30 * 16))][(v34 + (v31 * 8))]; // L60 + v27[(v33 + (v30 * 16))][(v34 + (v31 * 8))] = v37; // L61 + } + float v38 = v27[(v33 + (v30 * 16))][(v34 + (v31 * 8))]; // L63 + if ((v33 + (v30 * 16)) == 0) { // L64 + v26[(v29 + v32)][(v34 + (v31 * 8))] = v25; // L65 + } + float v39 = v26[(v29 + v32)][(v34 + (v31 * 8))]; // L67 + float v40 = v36 * v38; // L68 + float v41 = v39 + v40; // L69 + v26[(v29 + v32)][(v34 + (v31 * 8))] = v41; // L70 + if (((v33 + (v30 * 16)) - 255) == 0) { // L71 + float v42 = v26[(v29 + v32)][(v34 + (v31 * 8))]; // L72 + v24[v32][v34].write(v42); // L73 + } + } + } + } + } + } + } + return ; // L81 +} + +void node3( + float v43[784][256], + float v44[256][784] +) { // L83 + loop14: for (int v45 = 0; v45 < 98; v45++) { // L84 + loop15: for (int v46 = 0; v46 < 16; v46++) { // L85 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v47 = 0; v47 < 8; v47++) { // L86 + loop17: for (int v48 = 0; v48 < 16; v48++) { // L87 + float v49 = v43[(v47 + (v45 * 8))][(v48 + (v46 * 16))]; // L88 + v44[(v48 + (v46 * 16))][(v47 + (v45 * 8))] = v49; // L89 + } + } + } + } + return ; // L94 +} + +void node4( + hls::stream v50[1][16], + float v51[256], + hls::stream v52[1][16], + float v53 +) { // L96 + loop18: for (int v54 = 0; v54 < 32; v54++) { // L97 + loop19: for (int v55 = 0; v55 < 16; v55++) { // L98 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v56 = 0; v56 < 1; v56++) { // L99 + loop21: for (int v57 = 0; v57 < 16; v57++) { // L100 + float v58 = v50[v56][v57].read(); // L101 + float v59 = v51[(v57 + (v55 * 16))]; // L102 + float v60 = v58 + v59; // L103 + bool v61 = v60 > v53; // L104 + float v62 = v61 ? (float)v60 : (float)v53; // L105 + v52[v56][v57].write(v62); // L106 + } + } + } + } + return ; // L111 +} + +void node5( + hls::stream v63[1][8], + float v64[128][256], + hls::stream v65[1][16], + float v66 +) { // L113 + float v67[32][256]; // L114 + float v68[128][256]; // L115 + float v69[32][128]; // L116 + loop22: for (int v70 = 0; v70 < 32; v70++) { // L117 + loop23: for (int v71 = 0; v71 < 16; v71++) { // L118 + loop24: for (int v72 = 0; v72 < 16; v72++) { // L119 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 1; v73++) { // L120 + loop26: for (int v74 = 0; v74 < 16; v74++) { // L121 + loop27: for (int v75 = 0; v75 < 8; v75++) { // L122 + if ((v74 + (v71 * 16)) == 0) { // L123 + float v76 = v63[v73][v75].read(); // L124 + v69[(v70 + v73)][(v75 + (v72 * 8))] = v76; // L125 + } + float v77 = v69[(v70 + v73)][(v75 + (v72 * 8))]; // L127 + if ((v70 + v73) == 0) { // L128 + float v78 = v64[(v75 + (v72 * 8))][(v74 + (v71 * 16))]; // L129 + v68[(v75 + (v72 * 8))][(v74 + (v71 * 16))] = v78; // L130 + } + float v79 = v68[(v75 + (v72 * 8))][(v74 + (v71 * 16))]; // L132 + if ((v75 + (v72 * 8)) == 0) { // L133 + v67[(v70 + v73)][(v74 + (v71 * 16))] = v66; // L134 + } + float v80 = v67[(v70 + v73)][(v74 + (v71 * 16))]; // L136 + float v81 = v77 * v79; // L137 + float v82 = v80 + v81; // L138 + v67[(v70 + v73)][(v74 + (v71 * 16))] = v82; // L139 + if (((v75 + (v72 * 8)) - 127) == 0) { // L140 + float v83 = v67[(v70 + v73)][(v74 + (v71 * 16))]; // L141 + v65[v73][v74].write(v83); // L142 + } + } + } + } + } + } + } + return ; // L150 +} + +void node6( + float v84[256][128], + float v85[128][256] +) { // L152 + loop28: for (int v86 = 0; v86 < 16; v86++) { // L153 + loop29: for (int v87 = 0; v87 < 16; v87++) { // L154 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v88 = 0; v88 < 8; v88++) { // L155 + loop31: for (int v89 = 0; v89 < 16; v89++) { // L156 + float v90 = v84[(v89 + (v87 * 16))][(v88 + (v86 * 8))]; // L157 + v85[(v88 + (v86 * 8))][(v89 + (v87 * 16))] = v90; // L158 + } + } + } + } + return ; // L163 +} + +void node7( + hls::stream v91[1][8], + float v92[128], + hls::stream v93[1][8], + float v94 +) { // L165 + loop32: for (int v95 = 0; v95 < 32; v95++) { // L166 + loop33: for (int v96 = 0; v96 < 16; v96++) { // L167 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v97 = 0; v97 < 1; v97++) { // L168 + loop35: for (int v98 = 0; v98 < 8; v98++) { // L169 + float v99 = v91[v97][v98].read(); // L170 + float v100 = v92[(v98 + (v96 * 8))]; // L171 + float v101 = v99 + v100; // L172 + bool v102 = v101 > v94; // L173 + float v103 = v102 ? (float)v101 : (float)v94; // L174 + v93[v97][v98].write(v103); // L175 + } + } + } + } + return ; // L180 +} + +void node8( + hls::stream v104[1][4], + float v105[64][128], + hls::stream v106[1][8], + float v107 +) { // L182 + float v108[32][128]; // L183 + float v109[64][128]; // L184 + float v110[32][64]; // L185 + loop36: for (int v111 = 0; v111 < 32; v111++) { // L186 + loop37: for (int v112 = 0; v112 < 16; v112++) { // L187 + loop38: for (int v113 = 0; v113 < 16; v113++) { // L188 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v114 = 0; v114 < 1; v114++) { // L189 + loop40: for (int v115 = 0; v115 < 8; v115++) { // L190 + loop41: for (int v116 = 0; v116 < 4; v116++) { // L191 + if ((v115 + (v112 * 8)) == 0) { // L192 + float v117 = v104[v114][v116].read(); // L193 + v110[(v111 + v114)][(v116 + (v113 * 4))] = v117; // L194 + } + float v118 = v110[(v111 + v114)][(v116 + (v113 * 4))]; // L196 + if ((v111 + v114) == 0) { // L197 + float v119 = v105[(v116 + (v113 * 4))][(v115 + (v112 * 8))]; // L198 + v109[(v116 + (v113 * 4))][(v115 + (v112 * 8))] = v119; // L199 + } + float v120 = v109[(v116 + (v113 * 4))][(v115 + (v112 * 8))]; // L201 + if ((v116 + (v113 * 4)) == 0) { // L202 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v107; // L203 + } + float v121 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L205 + float v122 = v118 * v120; // L206 + float v123 = v121 + v122; // L207 + v108[(v111 + v114)][(v115 + (v112 * 8))] = v123; // L208 + if (((v116 + (v113 * 4)) - 63) == 0) { // L209 + float v124 = v108[(v111 + v114)][(v115 + (v112 * 8))]; // L210 + v106[v114][v115].write(v124); // L211 + } + } + } + } + } + } + } + return ; // L219 +} + +void node9( + float v125[128][64], + float v126[64][128] +) { // L221 + loop42: for (int v127 = 0; v127 < 16; v127++) { // L222 + loop43: for (int v128 = 0; v128 < 16; v128++) { // L223 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v129 = 0; v129 < 4; v129++) { // L224 + loop45: for (int v130 = 0; v130 < 8; v130++) { // L225 + float v131 = v125[(v130 + (v128 * 8))][(v129 + (v127 * 4))]; // L226 + v126[(v129 + (v127 * 4))][(v130 + (v128 * 8))] = v131; // L227 + } + } + } + } + return ; // L232 +} + +void node10( + hls::stream v132[1][4], + float v133[64], + hls::stream v134[1][4] +) { // L234 + loop46: for (int v135 = 0; v135 < 32; v135++) { // L235 + loop47: for (int v136 = 0; v136 < 16; v136++) { // L236 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v137 = 0; v137 < 1; v137++) { // L237 + loop49: for (int v138 = 0; v138 < 4; v138++) { // L238 + float v139 = v132[v137][v138].read(); // L239 + float v140 = v133[(v138 + (v136 * 4))]; // L240 + float v141 = v139 + v140; // L241 + v134[v137][v138].write(v141); // L242 + } + } + } + } + return ; // L247 +} + +void node11( + hls::stream v142[1][8], + float v143[128][64], + hls::stream v144[1][4], + float v145 +) { // L249 + float v146[32][64]; // L250 + float v147[128][64]; // L251 + float v148[32][128]; // L252 + loop50: for (int v149 = 0; v149 < 32; v149++) { // L253 + loop51: for (int v150 = 0; v150 < 16; v150++) { // L254 + loop52: for (int v151 = 0; v151 < 16; v151++) { // L255 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v152 = 0; v152 < 1; v152++) { // L256 + loop54: for (int v153 = 0; v153 < 4; v153++) { // L257 + loop55: for (int v154 = 0; v154 < 8; v154++) { // L258 + if ((v153 + (v150 * 4)) == 0) { // L259 + float v155 = v142[v152][v154].read(); // L260 + v148[(v149 + v152)][(v154 + (v151 * 8))] = v155; // L261 + } + float v156 = v148[(v149 + v152)][(v154 + (v151 * 8))]; // L263 + if ((v149 + v152) == 0) { // L264 + float v157 = v143[(v154 + (v151 * 8))][(v153 + (v150 * 4))]; // L265 + v147[(v154 + (v151 * 8))][(v153 + (v150 * 4))] = v157; // L266 + } + float v158 = v147[(v154 + (v151 * 8))][(v153 + (v150 * 4))]; // L268 + if ((v154 + (v151 * 8)) == 0) { // L269 + v146[(v149 + v152)][(v153 + (v150 * 4))] = v145; // L270 + } + float v159 = v146[(v149 + v152)][(v153 + (v150 * 4))]; // L272 + float v160 = v156 * v158; // L273 + float v161 = v159 + v160; // L274 + v146[(v149 + v152)][(v153 + (v150 * 4))] = v161; // L275 + if (((v154 + (v151 * 8)) - 127) == 0) { // L276 + float v162 = v146[(v149 + v152)][(v153 + (v150 * 4))]; // L277 + v144[v152][v153].write(v162); // L278 + } + } + } + } + } + } + } + return ; // L286 +} + +void node12( + float v163[64][128], + float v164[128][64] +) { // L288 + loop56: for (int v165 = 0; v165 < 16; v165++) { // L289 + loop57: for (int v166 = 0; v166 < 16; v166++) { // L290 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop58: for (int v167 = 0; v167 < 8; v167++) { // L291 + loop59: for (int v168 = 0; v168 < 4; v168++) { // L292 + float v169 = v163[(v168 + (v166 * 4))][(v167 + (v165 * 8))]; // L293 + v164[(v167 + (v165 * 8))][(v168 + (v166 * 4))] = v169; // L294 + } + } + } + } + return ; // L299 +} + +void node13( + hls::stream v170[1][8], + float v171[128], + hls::stream v172[1][8], + float v173 +) { // L301 + loop60: for (int v174 = 0; v174 < 32; v174++) { // L302 + loop61: for (int v175 = 0; v175 < 16; v175++) { // L303 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v176 = 0; v176 < 1; v176++) { // L304 + loop63: for (int v177 = 0; v177 < 8; v177++) { // L305 + float v178 = v170[v176][v177].read(); // L306 + float v179 = v171[(v177 + (v175 * 8))]; // L307 + float v180 = v178 + v179; // L308 + bool v181 = v180 > v173; // L309 + float v182 = v181 ? (float)v180 : (float)v173; // L310 + v172[v176][v177].write(v182); // L311 + } + } + } + } + return ; // L316 +} + +void node14( + hls::stream v183[1][8], + hls::stream v184[8][8], + hls::stream v185[1][8], + float v186 +) { // L318 + float v187[32][128]; // L319 + float v188[256][128]; // L320 + float v189[32][256]; // L321 + loop64: for (int v190 = 0; v190 < 32; v190++) { // L322 + loop65: for (int v191 = 0; v191 < 32; v191++) { // L323 + loop66: for (int v192 = 0; v192 < 16; v192++) { // L324 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop67: for (int v193 = 0; v193 < 1; v193++) { // L325 + loop68: for (int v194 = 0; v194 < 8; v194++) { // L326 + loop69: for (int v195 = 0; v195 < 8; v195++) { // L327 + if ((v195 + (v192 * 8)) == 0) { // L328 + float v196 = v183[v193][v194].read(); // L329 + v189[(v190 + v193)][(v194 + (v191 * 8))] = v196; // L330 + } + float v197 = v189[(v190 + v193)][(v194 + (v191 * 8))]; // L332 + if ((v190 + v193) == 0) { // L333 + float v198 = v184[v194][v195].read(); // L334 + v188[(v194 + (v191 * 8))][(v195 + (v192 * 8))] = v198; // L335 + } + float v199 = v188[(v194 + (v191 * 8))][(v195 + (v192 * 8))]; // L337 + if ((v194 + (v191 * 8)) == 0) { // L338 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v186; // L339 + } + float v200 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L341 + float v201 = v197 * v199; // L342 + float v202 = v200 + v201; // L343 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v202; // L344 + if (((v194 + (v191 * 8)) - 255) == 0) { // L345 + float v203 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L346 + v185[v193][v195].write(v203); // L347 + } + } + } + } + } + } + } + return ; // L355 +} + +void node15( + float v204[128][256], + hls::stream v205[8][8] +) { // L357 + loop70: for (int v206 = 0; v206 < 32; v206++) { // L358 + loop71: for (int v207 = 0; v207 < 16; v207++) { // L359 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop72: for (int v208 = 0; v208 < 8; v208++) { // L360 + loop73: for (int v209 = 0; v209 < 8; v209++) { // L361 + float v210 = v204[(v209 + (v207 * 8))][(v208 + (v206 * 8))]; // L362 + v205[v208][v209].write(v210); // L363 + } + } + } + } + return ; // L368 +} + +void node16( + hls::stream v211[1][8], + float v212[256], + hls::stream v213[1][8], + float v214 +) { // L370 + loop74: for (int v215 = 0; v215 < 32; v215++) { // L371 + loop75: for (int v216 = 0; v216 < 32; v216++) { // L372 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v217 = 0; v217 < 1; v217++) { // L373 + loop77: for (int v218 = 0; v218 < 8; v218++) { // L374 + float v219 = v211[v217][v218].read(); // L375 + float v220 = v212[(v218 + (v216 * 8))]; // L376 + float v221 = v219 + v220; // L377 + bool v222 = v221 > v214; // L378 + float v223 = v222 ? (float)v221 : (float)v214; // L379 + v213[v217][v218].write(v223); // L380 + } + } + } + } + return ; // L385 +} + +void node17( + hls::stream v224[16][8], + float v225[32][784], + hls::stream v226[1][8], + float v227 +) { // L387 + float v228[32][256]; // L388 + float v229[784][256]; // L389 + loop78: for (int v230 = 0; v230 < 32; v230++) { // L390 + loop79: for (int v231 = 0; v231 < 49; v231++) { // L391 + loop80: for (int v232 = 0; v232 < 32; v232++) { // L392 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v233 = 0; v233 < 1; v233++) { // L393 + loop82: for (int v234 = 0; v234 < 16; v234++) { // L394 + loop83: for (int v235 = 0; v235 < 8; v235++) { // L395 + float v236 = v225[(v230 + v233)][(v234 + (v231 * 16))]; // L396 + if ((v230 + v233) == 0) { // L397 + float v237 = v224[v234][v235].read(); // L398 + v229[(v234 + (v231 * 16))][(v235 + (v232 * 8))] = v237; // L399 + } + float v238 = v229[(v234 + (v231 * 16))][(v235 + (v232 * 8))]; // L401 + if ((v234 + (v231 * 16)) == 0) { // L402 + v228[(v230 + v233)][(v235 + (v232 * 8))] = v227; // L403 + } + float v239 = v228[(v230 + v233)][(v235 + (v232 * 8))]; // L405 + float v240 = v236 * v238; // L406 + float v241 = v239 + v240; // L407 + v228[(v230 + v233)][(v235 + (v232 * 8))] = v241; // L408 + if (((v234 + (v231 * 16)) - 783) == 0) { // L409 + float v242 = v228[(v230 + v233)][(v235 + (v232 * 8))]; // L410 + v226[v233][v235].write(v242); // L411 + } + } + } + } + } + } + } + return ; // L419 +} + +void node18( + float v243[256][784], + hls::stream v244[16][8] +) { // L421 + loop84: for (int v245 = 0; v245 < 49; v245++) { // L422 + loop85: for (int v246 = 0; v246 < 32; v246++) { // L423 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v247 = 0; v247 < 16; v247++) { // L424 + loop87: for (int v248 = 0; v248 < 8; v248++) { // L425 + float v249 = v243[(v248 + (v246 * 8))][(v247 + (v245 * 16))]; // L426 + v244[v247][v248].write(v249); // L427 + } + } + } + } + return ; // L432 +} + +void forward( + float v250[32][784], + float v251[256], + float v252[256][784], + float v253[128], + float v254[128][256], + float v255[64], + float v256[64][128], + float v257[128], + float v258[128][64], + float v259[256], + float v260[256][128], + float v261[784], + float v262[784][256], + float v263[32][784] +) { // L434 + #pragma HLS DATAFLOW + hls::stream v264[1][8]; + #pragma HLS STREAM variable=v264 depth=3136 // L437 + hls::stream v265[1][8]; + #pragma HLS STREAM variable=v265 depth=3136 // L438 + float v266[256][784]; // L439 + hls::stream v267[1][16]; + #pragma HLS STREAM variable=v267 depth=512 // L440 + hls::stream v268[1][16]; + #pragma HLS STREAM variable=v268 depth=512 // L441 + float v269[128][256]; // L442 + hls::stream v270[1][8]; + #pragma HLS STREAM variable=v270 depth=512 // L443 + hls::stream v271[1][8]; + #pragma HLS STREAM variable=v271 depth=512 // L444 + float v272[64][128]; // L445 + hls::stream v273[1][4]; + #pragma HLS STREAM variable=v273 depth=512 // L446 + hls::stream v274[1][4]; + #pragma HLS STREAM variable=v274 depth=512 // L447 + float v275[128][64]; // L448 + hls::stream v276[1][8]; + #pragma HLS STREAM variable=v276 depth=512 // L449 + hls::stream v277[1][8]; + #pragma HLS STREAM variable=v277 depth=512 // L450 + hls::stream v278[8][8]; + #pragma HLS STREAM variable=v278 depth=512 // L451 + hls::stream v279[1][8]; + #pragma HLS STREAM variable=v279 depth=1024 // L452 + hls::stream v280[1][8]; + #pragma HLS STREAM variable=v280 depth=1024 // L453 + hls::stream v281[16][8]; + #pragma HLS STREAM variable=v281 depth=1568 // L454 + node18(v252, v281); // L455 + node17(v281, v250, v280, 0.000000); // L456 + node16(v280, v251, v279, 0.000000); // L457 + node15(v254, v278); // L458 + node14(v279, v278, v277, 0.000000); // L459 + node13(v277, v253, v276, 0.000000); // L460 + node12(v256, v275); // L461 + node11(v276, v275, v274, 0.000000); // L462 + node10(v274, v255, v273); // L463 + node9(v258, v272); // L464 + node8(v273, v272, v271, 0.000000); // L465 + node7(v271, v257, v270, 0.000000); // L466 + node6(v260, v269); // L467 + node5(v270, v269, v268, 0.000000); // L468 + node4(v268, v259, v267, 0.000000); // L469 + node3(v262, v266); // L470 + node2(v267, v266, v265, 0.000000); // L471 + node1(v265, v261, v264, 1.000000); // L472 + node0(v264, v263); // L473 + return ; // L474 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt5/src/Autoencoder.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt5/src/Autoencoder.cpp new file mode 100644 index 000000000000..b61ee43fc768 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/Autoencoder__opt5/src/Autoencoder.cpp @@ -0,0 +1,738 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][28], + float v1[32][784] +) { // L34 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=28 + + loop0: for (int v2 = 0; v2 < 32; v2++) { // L35 + loop1: for (int v3 = 0; v3 < 28; v3++) { // L36 + #pragma HLS pipeline II=1 + loop2: for (int v4 = 0; v4 < 1; v4++) { // L37 + loop3: for (int v5 = 0; v5 < 28; v5++) { // L38 + float v6 = v0[v4][v5].read(); // L39 + v1[(v2 + v4)][(v5 + (v3 * 28))] = v6; // L40 + } + } + } + } + return ; // L45 +} + +void node1( + hls::stream v7[1][28], + float v8[784], + hls::stream v9[1][28], + float v10 +) { // L47 + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=28 + + loop4: for (int v11 = 0; v11 < 32; v11++) { // L48 + loop5: for (int v12 = 0; v12 < 28; v12++) { // L49 + #pragma HLS pipeline II=1 + loop6: for (int v13 = 0; v13 < 1; v13++) { // L50 + loop7: for (int v14 = 0; v14 < 28; v14++) { // L51 + float v15 = v7[v13][v14].read(); // L52 + float v16 = v8[(v14 + (v12 * 28))]; // L53 + float v17 = v15 + v16; // L54 + float v18 = -(v17); // L55 + float v19 = exp(v18); // L56 + float v20 = v19 + v10; // L57 + float v21 = v10 / v20; // L58 + v9[v13][v14].write(v21); // L59 + } + } + } + } + return ; // L64 +} + +void node2( + hls::stream v22[1][8], + float v23[256][784], + hls::stream v24[1][28], + float v25 +) { // L66 + float v26[32][784]; // L67 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=28 + + float v27[256][784]; // L68 + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=28 + + float v28[32][256]; // L69 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=8 + + loop8: for (int v29 = 0; v29 < 32; v29++) { // L70 + loop9: for (int v30 = 0; v30 < 32; v30++) { // L71 + loop10: for (int v31 = 0; v31 < 28; v31++) { // L72 + #pragma HLS pipeline II=1 + loop11: for (int v32 = 0; v32 < 1; v32++) { // L73 + loop12: for (int v33 = 0; v33 < 8; v33++) { // L74 + loop13: for (int v34 = 0; v34 < 28; v34++) { // L75 + if ((v34 + (v31 * 28)) == 0) { // L76 + float v35 = v22[v32][v33].read(); // L77 + v28[(v29 + v32)][(v33 + (v30 * 8))] = v35; // L78 + } + float v36 = v28[(v29 + v32)][(v33 + (v30 * 8))]; // L80 + if ((v29 + v32) == 0) { // L81 + float v37 = v23[(v33 + (v30 * 8))][(v34 + (v31 * 28))]; // L82 + v27[(v33 + (v30 * 8))][(v34 + (v31 * 28))] = v37; // L83 + } + float v38 = v27[(v33 + (v30 * 8))][(v34 + (v31 * 28))]; // L85 + if ((v33 + (v30 * 8)) == 0) { // L86 + v26[(v29 + v32)][(v34 + (v31 * 28))] = v25; // L87 + } + float v39 = v26[(v29 + v32)][(v34 + (v31 * 28))]; // L89 + float v40 = v36 * v38; // L90 + float v41 = v39 + v40; // L91 + v26[(v29 + v32)][(v34 + (v31 * 28))] = v41; // L92 + if (((v33 + (v30 * 8)) - 255) == 0) { // L93 + float v42 = v26[(v29 + v32)][(v34 + (v31 * 28))]; // L94 + v24[v32][v34].write(v42); // L95 + } + } + } + } + } + } + } + return ; // L103 +} + +void node3( + float v43[784][256], + float v44[256][784] +) { // L105 + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=28 + #pragma HLS array_partition variable=v43 cyclic dim=2 factor=8 + + loop14: for (int v45 = 0; v45 < 28; v45++) { // L106 + loop15: for (int v46 = 0; v46 < 32; v46++) { // L107 + #pragma HLS pipeline II=1 + loop16: for (int v47 = 0; v47 < 28; v47++) { // L108 + loop17: for (int v48 = 0; v48 < 8; v48++) { // L109 + float v49 = v43[(v47 + (v45 * 28))][(v48 + (v46 * 8))]; // L110 + v44[(v48 + (v46 * 8))][(v47 + (v45 * 28))] = v49; // L111 + } + } + } + } + return ; // L116 +} + +void node4( + hls::stream v50[1][8], + float v51[256], + hls::stream v52[1][8], + float v53 +) { // L118 + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=8 + + loop18: for (int v54 = 0; v54 < 32; v54++) { // L119 + loop19: for (int v55 = 0; v55 < 32; v55++) { // L120 + #pragma HLS pipeline II=1 + loop20: for (int v56 = 0; v56 < 1; v56++) { // L121 + loop21: for (int v57 = 0; v57 < 8; v57++) { // L122 + float v58 = v50[v56][v57].read(); // L123 + float v59 = v51[(v57 + (v55 * 8))]; // L124 + float v60 = v58 + v59; // L125 + bool v61 = v60 > v53; // L126 + float v62 = v61 ? (float)v60 : (float)v53; // L127 + v52[v56][v57].write(v62); // L128 + } + } + } + } + return ; // L133 +} + +void node5( + hls::stream v63[1][4], + hls::stream v64[4][8], + hls::stream v65[1][8], + float v66 +) { // L135 + float v67[32][256]; // L136 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=8 + + float v68[128][256]; // L137 + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=8 + + float v69[32][128]; // L138 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 32; v70++) { // L139 + loop23: for (int v71 = 0; v71 < 32; v71++) { // L140 + loop24: for (int v72 = 0; v72 < 32; v72++) { // L141 + #pragma HLS pipeline II=1 + loop25: for (int v73 = 0; v73 < 1; v73++) { // L142 + loop26: for (int v74 = 0; v74 < 4; v74++) { // L143 + loop27: for (int v75 = 0; v75 < 8; v75++) { // L144 + if ((v75 + (v72 * 8)) == 0) { // L145 + float v76 = v63[v73][v74].read(); // L146 + v69[(v70 + v73)][(v74 + (v71 * 4))] = v76; // L147 + } + float v77 = v69[(v70 + v73)][(v74 + (v71 * 4))]; // L149 + if ((v70 + v73) == 0) { // L150 + float v78 = v64[v74][v75].read(); // L151 + v68[(v74 + (v71 * 4))][(v75 + (v72 * 8))] = v78; // L152 + } + float v79 = v68[(v74 + (v71 * 4))][(v75 + (v72 * 8))]; // L154 + if ((v74 + (v71 * 4)) == 0) { // L155 + v67[(v70 + v73)][(v75 + (v72 * 8))] = v66; // L156 + } + float v80 = v67[(v70 + v73)][(v75 + (v72 * 8))]; // L158 + float v81 = v77 * v79; // L159 + float v82 = v80 + v81; // L160 + v67[(v70 + v73)][(v75 + (v72 * 8))] = v82; // L161 + if (((v74 + (v71 * 4)) - 127) == 0) { // L162 + float v83 = v67[(v70 + v73)][(v75 + (v72 * 8))]; // L163 + v65[v73][v75].write(v83); // L164 + } + } + } + } + } + } + } + return ; // L172 +} + +void node6( + float v84[256][128], + hls::stream v85[4][8] +) { // L174 + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + loop28: for (int v86 = 0; v86 < 32; v86++) { // L175 + loop29: for (int v87 = 0; v87 < 32; v87++) { // L176 + #pragma HLS pipeline II=1 + loop30: for (int v88 = 0; v88 < 4; v88++) { // L177 + loop31: for (int v89 = 0; v89 < 8; v89++) { // L178 + float v90 = v84[(v89 + (v87 * 8))][(v88 + (v86 * 4))]; // L179 + v85[v88][v89].write(v90); // L180 + } + } + } + } + return ; // L185 +} + +void node7( + hls::stream v91[1][4], + float v92[128], + hls::stream v93[1][4], + float v94 +) { // L187 + #pragma HLS array_partition variable=v92 cyclic dim=1 factor=4 + + loop32: for (int v95 = 0; v95 < 32; v95++) { // L188 + loop33: for (int v96 = 0; v96 < 32; v96++) { // L189 + #pragma HLS pipeline II=1 + loop34: for (int v97 = 0; v97 < 1; v97++) { // L190 + loop35: for (int v98 = 0; v98 < 4; v98++) { // L191 + float v99 = v91[v97][v98].read(); // L192 + float v100 = v92[(v98 + (v96 * 4))]; // L193 + float v101 = v99 + v100; // L194 + bool v102 = v101 > v94; // L195 + float v103 = v102 ? (float)v101 : (float)v94; // L196 + v93[v97][v98].write(v103); // L197 + } + } + } + } + return ; // L202 +} + +void node8( + hls::stream v104[1][2], + hls::stream v105[2][4], + hls::stream v106[1][4], + float v107 +) { // L204 + float v108[32][128]; // L205 + #pragma HLS array_partition variable=v108 cyclic dim=2 factor=4 + + float v109[64][128]; // L206 + #pragma HLS array_partition variable=v109 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v109 cyclic dim=2 factor=4 + + float v110[32][64]; // L207 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=2 + + loop36: for (int v111 = 0; v111 < 32; v111++) { // L208 + loop37: for (int v112 = 0; v112 < 32; v112++) { // L209 + loop38: for (int v113 = 0; v113 < 32; v113++) { // L210 + #pragma HLS pipeline II=1 + loop39: for (int v114 = 0; v114 < 1; v114++) { // L211 + loop40: for (int v115 = 0; v115 < 2; v115++) { // L212 + loop41: for (int v116 = 0; v116 < 4; v116++) { // L213 + if ((v116 + (v113 * 4)) == 0) { // L214 + float v117 = v104[v114][v115].read(); // L215 + v110[(v111 + v114)][(v115 + (v112 * 2))] = v117; // L216 + } + float v118 = v110[(v111 + v114)][(v115 + (v112 * 2))]; // L218 + if ((v111 + v114) == 0) { // L219 + float v119 = v105[v115][v116].read(); // L220 + v109[(v115 + (v112 * 2))][(v116 + (v113 * 4))] = v119; // L221 + } + float v120 = v109[(v115 + (v112 * 2))][(v116 + (v113 * 4))]; // L223 + if ((v115 + (v112 * 2)) == 0) { // L224 + v108[(v111 + v114)][(v116 + (v113 * 4))] = v107; // L225 + } + float v121 = v108[(v111 + v114)][(v116 + (v113 * 4))]; // L227 + float v122 = v118 * v120; // L228 + float v123 = v121 + v122; // L229 + v108[(v111 + v114)][(v116 + (v113 * 4))] = v123; // L230 + if (((v115 + (v112 * 2)) - 63) == 0) { // L231 + float v124 = v108[(v111 + v114)][(v116 + (v113 * 4))]; // L232 + v106[v114][v116].write(v124); // L233 + } + } + } + } + } + } + } + return ; // L241 +} + +void node9( + float v125[128][64], + hls::stream v126[2][4] +) { // L243 + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=2 + + loop42: for (int v127 = 0; v127 < 32; v127++) { // L244 + loop43: for (int v128 = 0; v128 < 32; v128++) { // L245 + #pragma HLS pipeline II=1 + loop44: for (int v129 = 0; v129 < 2; v129++) { // L246 + loop45: for (int v130 = 0; v130 < 4; v130++) { // L247 + float v131 = v125[(v130 + (v128 * 4))][(v129 + (v127 * 2))]; // L248 + v126[v129][v130].write(v131); // L249 + } + } + } + } + return ; // L254 +} + +void node10( + hls::stream v132[1][2], + float v133[64], + hls::stream v134[1][2] +) { // L256 + #pragma HLS array_partition variable=v133 cyclic dim=1 factor=2 + + loop46: for (int v135 = 0; v135 < 32; v135++) { // L257 + loop47: for (int v136 = 0; v136 < 32; v136++) { // L258 + #pragma HLS pipeline II=1 + loop48: for (int v137 = 0; v137 < 1; v137++) { // L259 + loop49: for (int v138 = 0; v138 < 2; v138++) { // L260 + float v139 = v132[v137][v138].read(); // L261 + float v140 = v133[(v138 + (v136 * 2))]; // L262 + float v141 = v139 + v140; // L263 + v134[v137][v138].write(v141); // L264 + } + } + } + } + return ; // L269 +} + +void node11( + hls::stream v142[8][2], + hls::stream v143[1][8], + hls::stream v144[1][2], + float v145 +) { // L271 + float v146[32][64]; // L272 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=2 + + float v147[128][64]; // L273 + #pragma HLS array_partition variable=v147 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v147 cyclic dim=2 factor=2 + + float v148[32][128]; // L274 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=8 + + loop50: for (int v149 = 0; v149 < 32; v149++) { // L275 + loop51: for (int v150 = 0; v150 < 16; v150++) { // L276 + loop52: for (int v151 = 0; v151 < 32; v151++) { // L277 + #pragma HLS pipeline II=1 + loop53: for (int v152 = 0; v152 < 1; v152++) { // L278 + loop54: for (int v153 = 0; v153 < 8; v153++) { // L279 + loop55: for (int v154 = 0; v154 < 2; v154++) { // L280 + if ((v154 + (v151 * 2)) == 0) { // L281 + float v155 = v143[v152][v153].read(); // L282 + v148[(v149 + v152)][(v153 + (v150 * 8))] = v155; // L283 + } + float v156 = v148[(v149 + v152)][(v153 + (v150 * 8))]; // L285 + if ((v149 + v152) == 0) { // L286 + float v157 = v142[v153][v154].read(); // L287 + v147[(v153 + (v150 * 8))][(v154 + (v151 * 2))] = v157; // L288 + } + float v158 = v147[(v153 + (v150 * 8))][(v154 + (v151 * 2))]; // L290 + if ((v153 + (v150 * 8)) == 0) { // L291 + v146[(v149 + v152)][(v154 + (v151 * 2))] = v145; // L292 + } + float v159 = v146[(v149 + v152)][(v154 + (v151 * 2))]; // L294 + float v160 = v156 * v158; // L295 + float v161 = v159 + v160; // L296 + v146[(v149 + v152)][(v154 + (v151 * 2))] = v161; // L297 + if (((v153 + (v150 * 8)) - 127) == 0) { // L298 + float v162 = v146[(v149 + v152)][(v154 + (v151 * 2))]; // L299 + v144[v152][v154].write(v162); // L300 + } + } + } + } + } + } + } + return ; // L308 +} + +void node12( + float v163[64][128], + hls::stream v164[8][2] +) { // L310 + #pragma HLS array_partition variable=v163 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v163 cyclic dim=2 factor=8 + + loop56: for (int v165 = 0; v165 < 16; v165++) { // L311 + loop57: for (int v166 = 0; v166 < 32; v166++) { // L312 + #pragma HLS pipeline II=1 + loop58: for (int v167 = 0; v167 < 8; v167++) { // L313 + loop59: for (int v168 = 0; v168 < 2; v168++) { // L314 + float v169 = v163[(v168 + (v166 * 2))][(v167 + (v165 * 8))]; // L315 + v164[v167][v168].write(v169); // L316 + } + } + } + } + return ; // L321 +} + +void node13( + hls::stream v170[1][8], + float v171[128], + hls::stream v172[1][8], + float v173 +) { // L323 + #pragma HLS array_partition variable=v171 cyclic dim=1 factor=8 + + loop60: for (int v174 = 0; v174 < 32; v174++) { // L324 + loop61: for (int v175 = 0; v175 < 16; v175++) { // L325 + #pragma HLS pipeline II=1 + loop62: for (int v176 = 0; v176 < 1; v176++) { // L326 + loop63: for (int v177 = 0; v177 < 8; v177++) { // L327 + float v178 = v170[v176][v177].read(); // L328 + float v179 = v171[(v177 + (v175 * 8))]; // L329 + float v180 = v178 + v179; // L330 + bool v181 = v180 > v173; // L331 + float v182 = v181 ? (float)v180 : (float)v173; // L332 + v172[v176][v177].write(v182); // L333 + } + } + } + } + return ; // L338 +} + +void node14( + hls::stream v183[1][4], + hls::stream v184[4][8], + hls::stream v185[1][8], + float v186 +) { // L340 + float v187[32][128]; // L341 + #pragma HLS array_partition variable=v187 cyclic dim=2 factor=8 + + float v188[256][128]; // L342 + #pragma HLS array_partition variable=v188 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v188 cyclic dim=2 factor=8 + + float v189[32][256]; // L343 + #pragma HLS array_partition variable=v189 cyclic dim=2 factor=4 + + loop64: for (int v190 = 0; v190 < 32; v190++) { // L344 + loop65: for (int v191 = 0; v191 < 64; v191++) { // L345 + loop66: for (int v192 = 0; v192 < 16; v192++) { // L346 + #pragma HLS pipeline II=1 + loop67: for (int v193 = 0; v193 < 1; v193++) { // L347 + loop68: for (int v194 = 0; v194 < 4; v194++) { // L348 + loop69: for (int v195 = 0; v195 < 8; v195++) { // L349 + if ((v195 + (v192 * 8)) == 0) { // L350 + float v196 = v183[v193][v194].read(); // L351 + v189[(v190 + v193)][(v194 + (v191 * 4))] = v196; // L352 + } + float v197 = v189[(v190 + v193)][(v194 + (v191 * 4))]; // L354 + if ((v190 + v193) == 0) { // L355 + float v198 = v184[v194][v195].read(); // L356 + v188[(v194 + (v191 * 4))][(v195 + (v192 * 8))] = v198; // L357 + } + float v199 = v188[(v194 + (v191 * 4))][(v195 + (v192 * 8))]; // L359 + if ((v194 + (v191 * 4)) == 0) { // L360 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v186; // L361 + } + float v200 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L363 + float v201 = v197 * v199; // L364 + float v202 = v200 + v201; // L365 + v187[(v190 + v193)][(v195 + (v192 * 8))] = v202; // L366 + if (((v194 + (v191 * 4)) - 255) == 0) { // L367 + float v203 = v187[(v190 + v193)][(v195 + (v192 * 8))]; // L368 + v185[v193][v195].write(v203); // L369 + } + } + } + } + } + } + } + return ; // L377 +} + +void node15( + float v204[128][256], + hls::stream v205[4][8] +) { // L379 + #pragma HLS array_partition variable=v204 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v204 cyclic dim=2 factor=4 + + loop70: for (int v206 = 0; v206 < 64; v206++) { // L380 + loop71: for (int v207 = 0; v207 < 16; v207++) { // L381 + #pragma HLS pipeline II=1 + loop72: for (int v208 = 0; v208 < 4; v208++) { // L382 + loop73: for (int v209 = 0; v209 < 8; v209++) { // L383 + float v210 = v204[(v209 + (v207 * 8))][(v208 + (v206 * 4))]; // L384 + v205[v208][v209].write(v210); // L385 + } + } + } + } + return ; // L390 +} + +void node16( + hls::stream v211[1][4], + float v212[256], + hls::stream v213[1][4], + float v214 +) { // L392 + #pragma HLS array_partition variable=v212 cyclic dim=1 factor=4 + + loop74: for (int v215 = 0; v215 < 32; v215++) { // L393 + loop75: for (int v216 = 0; v216 < 64; v216++) { // L394 + #pragma HLS pipeline II=1 + loop76: for (int v217 = 0; v217 < 1; v217++) { // L395 + loop77: for (int v218 = 0; v218 < 4; v218++) { // L396 + float v219 = v211[v217][v218].read(); // L397 + float v220 = v212[(v218 + (v216 * 4))]; // L398 + float v221 = v219 + v220; // L399 + bool v222 = v221 > v214; // L400 + float v223 = v222 ? (float)v221 : (float)v214; // L401 + v213[v217][v218].write(v223); // L402 + } + } + } + } + return ; // L407 +} + +void node17( + hls::stream v224[49][4], + float v225[32][784], + hls::stream v226[1][4], + float v227 +) { // L409 + #pragma HLS array_partition variable=v225 cyclic dim=2 factor=49 + + float v228[32][256]; // L410 + #pragma HLS array_partition variable=v228 cyclic dim=2 factor=4 + + float v229[784][256]; // L411 + #pragma HLS array_partition variable=v229 cyclic dim=1 factor=49 + #pragma HLS array_partition variable=v229 cyclic dim=2 factor=4 + + loop78: for (int v230 = 0; v230 < 32; v230++) { // L412 + loop79: for (int v231 = 0; v231 < 16; v231++) { // L413 + loop80: for (int v232 = 0; v232 < 64; v232++) { // L414 + #pragma HLS pipeline II=1 + loop81: for (int v233 = 0; v233 < 1; v233++) { // L415 + loop82: for (int v234 = 0; v234 < 49; v234++) { // L416 + loop83: for (int v235 = 0; v235 < 4; v235++) { // L417 + float v236 = v225[(v230 + v233)][(v234 + (v231 * 49))]; // L418 + if ((v230 + v233) == 0) { // L419 + float v237 = v224[v234][v235].read(); // L420 + v229[(v234 + (v231 * 49))][(v235 + (v232 * 4))] = v237; // L421 + } + float v238 = v229[(v234 + (v231 * 49))][(v235 + (v232 * 4))]; // L423 + if ((v234 + (v231 * 49)) == 0) { // L424 + v228[(v230 + v233)][(v235 + (v232 * 4))] = v227; // L425 + } + float v239 = v228[(v230 + v233)][(v235 + (v232 * 4))]; // L427 + float v240 = v236 * v238; // L428 + float v241 = v239 + v240; // L429 + v228[(v230 + v233)][(v235 + (v232 * 4))] = v241; // L430 + if (((v234 + (v231 * 49)) - 783) == 0) { // L431 + float v242 = v228[(v230 + v233)][(v235 + (v232 * 4))]; // L432 + v226[v233][v235].write(v242); // L433 + } + } + } + } + } + } + } + return ; // L441 +} + +void node18( + float v243[256][784], + hls::stream v244[49][4] +) { // L443 + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v243 cyclic dim=2 factor=49 + + loop84: for (int v245 = 0; v245 < 16; v245++) { // L444 + loop85: for (int v246 = 0; v246 < 64; v246++) { // L445 + #pragma HLS pipeline II=1 + loop86: for (int v247 = 0; v247 < 49; v247++) { // L446 + loop87: for (int v248 = 0; v248 < 4; v248++) { // L447 + float v249 = v243[(v248 + (v246 * 4))][(v247 + (v245 * 49))]; // L448 + v244[v247][v248].write(v249); // L449 + } + } + } + } + return ; // L454 +} + +void forward( + float v250[32][784], + float v251[256], + float v252[256][784], + float v253[128], + float v254[128][256], + float v255[64], + float v256[64][128], + float v257[128], + float v258[128][64], + float v259[256], + float v260[256][128], + float v261[784], + float v262[784][256], + float v263[32][784] +) { // L456 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v250 cyclic dim=2 factor=49 + + #pragma HLS array_partition variable=v251 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=49 + + #pragma HLS array_partition variable=v253 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v254 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v254 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v255 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v259 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v260 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v260 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v261 cyclic dim=1 factor=28 + + #pragma HLS array_partition variable=v262 cyclic dim=1 factor=28 + #pragma HLS array_partition variable=v262 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v263 cyclic dim=2 factor=28 + + hls::stream v264[1][28]; + #pragma HLS STREAM variable=v264 depth=896 // L459 + hls::stream v265[1][28]; + #pragma HLS STREAM variable=v265 depth=896 // L460 + float v266[256][784]; // L461 + hls::stream v267[1][8]; + #pragma HLS STREAM variable=v267 depth=1024 // L462 + hls::stream v268[1][8]; + #pragma HLS STREAM variable=v268 depth=1024 // L463 + hls::stream v269[4][8]; + #pragma HLS STREAM variable=v269 depth=1024 // L464 + hls::stream v270[1][4]; + #pragma HLS STREAM variable=v270 depth=1024 // L465 + hls::stream v271[1][4]; + #pragma HLS STREAM variable=v271 depth=1024 // L466 + hls::stream v272[2][4]; + #pragma HLS STREAM variable=v272 depth=1024 // L467 + hls::stream v273[1][2]; + #pragma HLS STREAM variable=v273 depth=1024 // L468 + hls::stream v274[1][2]; + #pragma HLS STREAM variable=v274 depth=1024 // L469 + hls::stream v275[8][2]; + #pragma HLS STREAM variable=v275 depth=512 // L470 + hls::stream v276[1][8]; + #pragma HLS STREAM variable=v276 depth=512 // L471 + hls::stream v277[1][8]; + #pragma HLS STREAM variable=v277 depth=512 // L472 + hls::stream v278[4][8]; + #pragma HLS STREAM variable=v278 depth=1024 // L473 + hls::stream v279[1][4]; + #pragma HLS STREAM variable=v279 depth=2048 // L474 + hls::stream v280[1][4]; + #pragma HLS STREAM variable=v280 depth=2048 // L475 + hls::stream v281[49][4]; + #pragma HLS STREAM variable=v281 depth=1024 // L476 + node18(v252, v281); // L477 + node17(v281, v250, v280, 0.000000); // L478 + node16(v280, v251, v279, 0.000000); // L479 + node15(v254, v278); // L480 + node14(v279, v278, v277, 0.000000); // L481 + node13(v277, v253, v276, 0.000000); // L482 + node12(v256, v275); // L483 + node11(v275, v276, v274, 0.000000); // L484 + node10(v274, v255, v273); // L485 + node9(v258, v272); // L486 + node8(v273, v272, v271, 0.000000); // L487 + node7(v271, v257, v270, 0.000000); // L488 + node6(v260, v269); // L489 + node5(v270, v269, v268, 0.000000); // L490 + node4(v268, v259, v267, 0.000000); // L491 + node3(v262, v266); // L492 + node2(v267, v266, v265, 0.000000); // L493 + node1(v265, v261, v264, 1.000000); // L494 + node0(v264, v263); // L495 + return ; // L496 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..19dc1c101858 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt1/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,134 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { + #pragma HLS DATAFLOW + float v4[8][114][114]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 114; v6++) { + loop2: for (int v7 = 0; v7 < 114; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + v4[v5][v6][v7] = 0.000000; + } + } + } + loop3: for (int v8 = 0; v8 < 8; v8++) { + loop4: for (int v9 = 0; v9 < 112; v9++) { + loop5: for (int v10 = 0; v10 < 112; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v0[0][v8][v9][v10]; + v4[v8][(v9 + 1)][(v10 + 1)] = v11; + } + } + } + float v12[8][112][112]; + hls::stream v13("fifo_0"); + #pragma HLS STREAM variable=v13 depth=100352 + float v14[8][112][112]; + loop6: for (int v15 = 0; v15 < 112; v15++) { + loop7: for (int v16 = 0; v16 < 112; v16++) { + loop8: for (int v17 = 0; v17 < 8; v17++) { + loop9: for (int v18 = 0; v18 < 3; v18++) { + loop10: for (int v19 = 0; v19 < 3; v19++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v20 = v4[v17][(v15 + v18)][(v16 + v19)]; + float v21 = v2[v17][v18][v19]; + if (v18 == 0 && v19 == 0) { + v12[v17][v15][v16] = 0.000000; + } + float v22 = v12[v17][v15][v16]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v12[v17][v15][v16] = v24; + if ((v18 - 2) == 0 && (v19 - 2) == 0) { + float v25 = v12[v17][v15][v16]; + v13.write(v25); + } + } + } + } + } + } + float v26[8][112][112]; + hls::stream v27("fifo_1"); + #pragma HLS STREAM variable=v27 depth=100352 + loop11: for (int v28 = 0; v28 < 8; v28++) { + loop12: for (int v29 = 0; v29 < 112; v29++) { + loop13: for (int v30 = 0; v30 < 112; v30++) { + loop14: for (int v31 = 0; v31 < 8; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v28 == 0) { + float v32 = v13.read(); + v14[v31][v29][v30] = v32; + } + float v33 = v14[v31][v29][v30]; + float v34 = v1[v28][v31][0][0]; + if (v31 == 0) { + v26[v28][v29][v30] = 0.000000; + } + float v35 = v26[v28][v29][v30]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[v28][v29][v30] = v37; + if ((v31 - 7) == 0) { + float v38 = v26[v28][v29][v30]; + v27.write(v38); + } + } + } + } + } + hls::stream v39("fifo_2"); + #pragma HLS STREAM variable=v39 depth=100352 + loop15: for (int v40 = 0; v40 < 8; v40++) { + loop16: for (int v41 = 0; v41 < 112; v41++) { + loop17: for (int v42 = 0; v42 < 112; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v43 = v27.read(); + float v44 = 0.000010; + float v45 = v44 + 1.000000; + float v46 = 1.0 / sqrt(v45); + float v47 = v43 * v46; + float v48 = v47 + 0.000000; + bool v49 = v48 > 0.000000; + float v50 = v49 ? (float)v48 : (float)0.000000; + v39.write(v50); + } + } + } + loop18: for (int v51 = 0; v51 < 8; v51++) { + loop19: for (int v52 = 0; v52 < 112; v52++) { + loop20: for (int v53 = 0; v53 < 112; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v54 = v39.read(); + v3[0][v51][v52][v53] = v54; + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..c2c68b8366f0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt2/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,189 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][8][112][112] +) { // L8 + loop0: for (int v2 = 0; v2 < 112; v2++) { // L9 + loop1: for (int v3 = 0; v3 < 112; v3++) { // L10 + loop2: for (int v4 = 0; v4 < 8; v4++) { // L11 + #pragma HLS pipeline II=1 + float v5 = v0.read(); // L12 + v1[0][v4][v3][v2] = v5; // L13 + } + } + } + return ; // L17 +} + +void node1( + hls::stream &v6, + hls::stream &v7, + double v8, + float v9, + float v10 +) { // L19 + loop3: for (int v11 = 0; v11 < 112; v11++) { // L20 + loop4: for (int v12 = 0; v12 < 112; v12++) { // L21 + loop5: for (int v13 = 0; v13 < 8; v13++) { // L22 + #pragma HLS pipeline II=1 + float v14 = v6.read(); // L23 + float v15 = v8; // L24 + float v16 = v15 + v9; // L25 + float v17 = 1.0 / sqrt(v16); // L26 + float v18 = v14 * v17; // L27 + float v19 = v18 + v10; // L28 + bool v20 = v19 > v10; // L29 + float v21 = v20 ? (float)v19 : (float)v10; // L30 + v7.write(v21); // L31 + } + } + } + return ; // L35 +} + +void node2( + hls::stream &v22, + float v23[8][8][1][1], + hls::stream &v24, + float v25 +) { // L37 + float v26[8]; // L38 + float v27; // L39 + loop6: for (int v28 = 0; v28 < 112; v28++) { // L40 + loop7: for (int v29 = 0; v29 < 112; v29++) { // L41 + loop8: for (int v30 = 0; v30 < 8; v30++) { // L42 + loop9: for (int v31 = 0; v31 < 8; v31++) { // L43 + #pragma HLS pipeline II=1 + if (v31 == 0) { // L44 + float v32 = v22.read(); // L45 + v27 = v32; // L46 + } + float v33 = v27; // L48 + float v34 = v23[v31][v30][0][0]; // L49 + if (v30 == 0) { // L50 + v26[v31] = v25; // L51 + } + float v35 = v26[v31]; // L53 + float v36 = v33 * v34; // L54 + float v37 = v35 + v36; // L55 + v26[v31] = v37; // L56 + if ((v30 - 7) == 0) { // L57 + float v38 = v26[v31]; // L58 + v24.write(v38); // L59 + } + } + } + } + } + return ; // L65 +} + +void node3( + float v39[8][3][3], + hls::stream &v40, + hls::stream &v41, + float v42 +) { // L67 + float v43[8]; // L68 + float v44[8][114][114]; // L69 + loop10: for (int v45 = 0; v45 < 114; v45++) { // L70 + loop11: for (int v46 = 0; v46 < 114; v46++) { // L71 + loop12: for (int v47 = 0; v47 < 3; v47++) { // L72 + loop13: for (int v48 = 0; v48 < 3; v48++) { // L73 + loop14: for (int v49 = 0; v49 < 8; v49++) { // L74 + #pragma HLS pipeline II=1 + if (v48 == 0 && v47 == 0) { // L75 + float v50 = v40.read(); // L76 + v44[v49][v46][v45] = v50; // L77 + } + if ((v46 - 2) >= 0 && (v45 - 2) >= 0) { // L79 + float v51 = v44[v49][((v48 + v46) - 2)][((v47 + v45) - 2)]; // L80 + float v52 = v39[v49][v48][v47]; // L81 + if (v48 == 0 && v47 == 0) { // L82 + v43[v49] = v42; // L83 + } + float v53 = v43[v49]; // L85 + float v54 = v51 * v52; // L86 + float v55 = v53 + v54; // L87 + v43[v49] = v55; // L88 + if ((v48 - 2) == 0 && (v47 - 2) == 0) { // L89 + float v56 = v43[v49]; // L90 + v41.write(v56); // L91 + } + } + } + } + } + } + } + return ; // L99 +} + +void node4( + float v57[1][8][112][112], + hls::stream &v58, + float v59 +) { // L101 + float v60[8][114][114]; // L102 + loop15: for (int v61 = 0; v61 < 114; v61++) { // L103 + loop16: for (int v62 = 0; v62 < 114; v62++) { // L104 + loop17: for (int v63 = 0; v63 < 8; v63++) { // L105 + #pragma HLS pipeline II=1 + v60[v63][v62][v61] = v59; // L106 + } + } + } + loop18: for (int v64 = 0; v64 < 114; v64++) { // L110 + loop19: for (int v65 = 0; v65 < 114; v65++) { // L111 + loop20: for (int v66 = 0; v66 < 8; v66++) { // L112 + #pragma HLS pipeline II=1 + if ((v65 - 1) >= 0 && (v64 - 1) >= 0 && ((-v65) + 112) >= 0 && ((-v64) + 112) >= 0) { // L113 + float v67 = v57[0][v66][(v65 - 1)][(v64 - 1)]; // L114 + v60[v66][v65][v64] = v67; // L115 + } + float v68 = v60[v66][v65][v64]; // L117 + v58.write(v68); // L118 + } + } + } + return ; // L122 +} + +void forward( + float v69[1][8][112][112], + float v70[8][8][1][1], + float v71[8][3][3], + float v72[1][8][112][112] +) { // L124 + #pragma HLS DATAFLOW + hls::stream v73("fifo_0"); + #pragma HLS STREAM variable=v73 depth=100352 // L128 + hls::stream v74("fifo_1"); + #pragma HLS STREAM variable=v74 depth=100352 // L129 + hls::stream v75("fifo_2"); + #pragma HLS STREAM variable=v75 depth=100352 // L130 + hls::stream v76("fifo_3"); + #pragma HLS STREAM variable=v76 depth=103968 // L131 + node4(v69, v76, 0.000000); // L132 + node3(v71, v76, v75, 0.000000); // L133 + node2(v75, v70, v74, 0.000000); // L134 + node1(v74, v73, 0.000010, 1.000000, 0.000000); // L135 + node0(v73, v72); // L136 + return ; // L137 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..1d82348ce6a2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt3/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,181 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { // L9 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=14 + + float v4[8][114][114]; // L13 + loop0: for (int v5 = 0; v5 < 8; v5++) { // L14 + loop1: for (int v6 = 0; v6 < 57; v6++) { // L15 + loop2: for (int v7 = 0; v7 < 114; v7++) { // L16 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 1; v8++) { // L17 + loop4: for (int v9 = 0; v9 < 2; v9++) { // L18 + loop5: for (int v10 = 0; v10 < 1; v10++) { // L19 + v4[(v5 + v8)][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; // L20 + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { // L27 + loop7: for (int v12 = 0; v12 < 56; v12++) { // L28 + loop8: for (int v13 = 0; v13 < 112; v13++) { // L29 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 1; v14++) { // L30 + loop10: for (int v15 = 0; v15 < 2; v15++) { // L31 + loop11: for (int v16 = 0; v16 < 1; v16++) { // L32 + float v17 = v0[0][(v11 + v14)][(v15 + (v12 * 2))][(v13 + v16)]; // L33 + v4[(v11 + v14)][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; // L34 + } + } + } + } + } + } + float v18[8][112][112]; // L41 + hls::stream v19[1][2][14]; + #pragma HLS STREAM variable=v19 depth=3584 // L42 + float v20[8][112][112]; // L43 + loop12: for (int v21 = 0; v21 < 56; v21++) { // L44 + loop13: for (int v22 = 0; v22 < 8; v22++) { // L45 + loop14: for (int v23 = 0; v23 < 8; v23++) { // L46 + loop15: for (int v24 = 0; v24 < 3; v24++) { // L47 + loop16: for (int v25 = 0; v25 < 3; v25++) { // L48 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v26 = 0; v26 < 2; v26++) { // L49 + loop18: for (int v27 = 0; v27 < 14; v27++) { // L50 + loop19: for (int v28 = 0; v28 < 1; v28++) { // L51 + loop20: for (int v29 = 0; v29 < 1; v29++) { // L52 + loop21: for (int v30 = 0; v30 < 1; v30++) { // L53 + float v31 = v4[(v23 + v28)][(((v26 + (v21 * 2)) + v24) + v29)][(((v27 + (v22 * 14)) + v25) + v30)]; // L54 + float v32 = v2[(v23 + v28)][(v24 + v29)][(v25 + v30)]; // L55 + if ((v24 + v29) == 0 && (v25 + v30) == 0) { // L56 + v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = 0.000000; // L57 + } + float v33 = v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; // L59 + float v34 = v31 * v32; // L60 + float v35 = v33 + v34; // L61 + v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = v35; // L62 + if (((v24 + v29) - 2) == 0 && ((v25 + v30) - 2) == 0) { // L63 + float v36 = v18[(v23 + v28)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; // L64 + v19[v28][v26][v27].write(v36); // L65 + } + } + } + } + } + } + } + } + } + } + } + float v37[8][112][112]; // L77 + hls::stream v38[1][2][14]; + #pragma HLS STREAM variable=v38 depth=3584 // L78 + loop22: for (int v39 = 0; v39 < 8; v39++) { // L79 + loop23: for (int v40 = 0; v40 < 56; v40++) { // L80 + loop24: for (int v41 = 0; v41 < 8; v41++) { // L81 + loop25: for (int v42 = 0; v42 < 8; v42++) { // L82 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v43 = 0; v43 < 1; v43++) { // L83 + loop27: for (int v44 = 0; v44 < 2; v44++) { // L84 + loop28: for (int v45 = 0; v45 < 14; v45++) { // L85 + loop29: for (int v46 = 0; v46 < 1; v46++) { // L86 + if ((v39 + v43) == 0) { // L87 + float v47 = v19[v46][v44][v45].read(); // L88 + v20[(v42 + v46)][(v44 + (v40 * 2))][(v45 + (v41 * 14))] = v47; // L89 + } + float v48 = v20[(v42 + v46)][(v44 + (v40 * 2))][(v45 + (v41 * 14))]; // L91 + float v49 = v1[(v39 + v43)][(v42 + v46)][0][0]; // L92 + if ((v42 + v46) == 0) { // L93 + v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))] = 0.000000; // L94 + } + float v50 = v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))]; // L96 + float v51 = v48 * v49; // L97 + float v52 = v50 + v51; // L98 + v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))] = v52; // L99 + if (((v42 + v46) - 7) == 0) { // L100 + float v53 = v37[(v39 + v43)][(v44 + (v40 * 2))][(v45 + (v41 * 14))]; // L101 + v38[v43][v44][v45].write(v53); // L102 + } + } + } + } + } + } + } + } + } + hls::stream v54[1][2][14]; + #pragma HLS STREAM variable=v54 depth=3584 // L112 + loop30: for (int v55 = 0; v55 < 8; v55++) { // L113 + loop31: for (int v56 = 0; v56 < 56; v56++) { // L114 + loop32: for (int v57 = 0; v57 < 8; v57++) { // L115 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v58 = 0; v58 < 1; v58++) { // L116 + loop34: for (int v59 = 0; v59 < 2; v59++) { // L117 + loop35: for (int v60 = 0; v60 < 14; v60++) { // L118 + float v61 = v38[v58][v59][v60].read(); // L119 + float v62 = 0.000010; // L120 + float v63 = v62 + 1.000000; // L121 + float v64 = 1.0 / sqrt(v63); // L122 + float v65 = v61 * v64; // L123 + float v66 = v65 + 0.000000; // L124 + bool v67 = v66 > 0.000000; // L125 + float v68 = v67 ? (float)v66 : (float)0.000000; // L126 + v54[v58][v59][v60].write(v68); // L127 + } + } + } + } + } + } + loop36: for (int v69 = 0; v69 < 8; v69++) { // L134 + loop37: for (int v70 = 0; v70 < 56; v70++) { // L135 + loop38: for (int v71 = 0; v71 < 8; v71++) { // L136 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v72 = 0; v72 < 1; v72++) { // L137 + loop40: for (int v73 = 0; v73 < 2; v73++) { // L138 + loop41: for (int v74 = 0; v74 < 14; v74++) { // L139 + float v75 = v54[v72][v73][v74].read(); // L140 + v3[0][(v69 + v72)][(v73 + (v70 * 2))][(v74 + (v71 * 14))] = v75; // L141 + } + } + } + } + } + } + return ; // L148 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..51a45b21d296 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt4/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,181 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=14 + + float v4[8][114][114]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 57; v6++) { + loop2: for (int v7 = 0; v7 < 114; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 1; v8++) { + loop4: for (int v9 = 0; v9 < 2; v9++) { + loop5: for (int v10 = 0; v10 < 1; v10++) { + v4[(v5 + v8)][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 56; v12++) { + loop8: for (int v13 = 0; v13 < 112; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 1; v14++) { + loop10: for (int v15 = 0; v15 < 2; v15++) { + loop11: for (int v16 = 0; v16 < 1; v16++) { + float v17 = v0[0][(v11 + v14)][(v15 + (v12 * 2))][(v13 + v16)]; + v4[(v11 + v14)][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; + } + } + } + } + } + } + float v18[8][112][112]; + hls::stream v19[1][2][14]; + #pragma HLS STREAM variable=v19 depth=3584 + float v20[8][112][112]; + loop12: for (int v21 = 0; v21 < 56; v21++) { + loop13: for (int v22 = 0; v22 < 8; v22++) { + loop14: for (int v23 = 0; v23 < 3; v23++) { + loop15: for (int v24 = 0; v24 < 3; v24++) { + loop16: for (int v25 = 0; v25 < 8; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v26 = 0; v26 < 2; v26++) { + loop18: for (int v27 = 0; v27 < 14; v27++) { + loop19: for (int v28 = 0; v28 < 1; v28++) { + loop20: for (int v29 = 0; v29 < 1; v29++) { + loop21: for (int v30 = 0; v30 < 1; v30++) { + float v31 = v4[(v25 + v30)][(((v26 + (v21 * 2)) + v23) + v28)][(((v27 + (v22 * 14)) + v24) + v29)]; + float v32 = v2[(v25 + v30)][(v23 + v28)][(v24 + v29)]; + if ((v23 + v28) == 0 && (v24 + v29) == 0) { + v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = 0.000000; + } + float v33 = v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))] = v35; + if (((v23 + v28) - 2) == 0 && ((v24 + v29) - 2) == 0) { + float v36 = v18[(v25 + v30)][(v26 + (v21 * 2))][(v27 + (v22 * 14))]; + v19[v30][v26][v27].write(v36); + } + } + } + } + } + } + } + } + } + } + } + float v37[8][112][112]; + hls::stream v38[1][2][14]; + #pragma HLS STREAM variable=v38 depth=3584 + loop22: for (int v39 = 0; v39 < 56; v39++) { + loop23: for (int v40 = 0; v40 < 8; v40++) { + loop24: for (int v41 = 0; v41 < 8; v41++) { + loop25: for (int v42 = 0; v42 < 8; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v43 = 0; v43 < 2; v43++) { + loop27: for (int v44 = 0; v44 < 14; v44++) { + loop28: for (int v45 = 0; v45 < 1; v45++) { + loop29: for (int v46 = 0; v46 < 1; v46++) { + if ((v42 + v46) == 0) { + float v47 = v19[v45][v43][v44].read(); + v20[(v41 + v45)][(v43 + (v39 * 2))][(v44 + (v40 * 14))] = v47; + } + float v48 = v20[(v41 + v45)][(v43 + (v39 * 2))][(v44 + (v40 * 14))]; + float v49 = v1[(v42 + v46)][(v41 + v45)][0][0]; + if ((v41 + v45) == 0) { + v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))] = 0.000000; + } + float v50 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))]; + float v51 = v48 * v49; + float v52 = v50 + v51; + v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))] = v52; + if (((v41 + v45) - 7) == 0) { + float v53 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v44 + (v40 * 14))]; + v38[v46][v43][v44].write(v53); + } + } + } + } + } + } + } + } + } + hls::stream v54[1][2][14]; + #pragma HLS STREAM variable=v54 depth=3584 + loop30: for (int v55 = 0; v55 < 56; v55++) { + loop31: for (int v56 = 0; v56 < 8; v56++) { + loop32: for (int v57 = 0; v57 < 8; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v58 = 0; v58 < 2; v58++) { + loop34: for (int v59 = 0; v59 < 14; v59++) { + loop35: for (int v60 = 0; v60 < 1; v60++) { + float v61 = v38[v60][v58][v59].read(); + float v62 = 0.000010; + float v63 = v62 + 1.000000; + float v64 = 1.0 / sqrt(v63); + float v65 = v61 * v64; + float v66 = v65 + 0.000000; + bool v67 = v66 > 0.000000; + float v68 = v67 ? (float)v66 : (float)0.000000; + v54[v60][v58][v59].write(v68); + } + } + } + } + } + } + loop36: for (int v69 = 0; v69 < 56; v69++) { + loop37: for (int v70 = 0; v70 < 8; v70++) { + loop38: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v72 = 0; v72 < 2; v72++) { + loop40: for (int v73 = 0; v73 < 14; v73++) { + loop41: for (int v74 = 0; v74 < 1; v74++) { + float v75 = v54[v74][v72][v73].read(); + v3[0][(v71 + v74)][(v72 + (v69 * 2))][(v73 + (v70 * 14))] = v75; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp new file mode 100644 index 000000000000..be65bca88fda --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/DepthwiseSeparableConvBlock__opt5/src/DepthwiseSeparableConvBlock.cpp @@ -0,0 +1,181 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][8][112][112], + float v1[8][8][1][1], + float v2[8][3][3], + float v3[1][8][112][112] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=14 + + float v4[8][114][114]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 57; v6++) { + loop2: for (int v7 = 0; v7 < 114; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 1; v8++) { + loop4: for (int v9 = 0; v9 < 2; v9++) { + loop5: for (int v10 = 0; v10 < 1; v10++) { + v4[(v5 + v8)][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 56; v12++) { + loop8: for (int v13 = 0; v13 < 112; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 1; v14++) { + loop10: for (int v15 = 0; v15 < 2; v15++) { + loop11: for (int v16 = 0; v16 < 1; v16++) { + float v17 = v0[0][(v11 + v14)][(v15 + (v12 * 2))][(v13 + v16)]; + v4[(v11 + v14)][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; + } + } + } + } + } + } + float v18[8][112][112]; + hls::stream v19[1][2][14]; + #pragma HLS STREAM variable=v19 depth=3584 + float v20[8][112][112]; + loop12: for (int v21 = 0; v21 < 56; v21++) { + loop13: for (int v22 = 0; v22 < 8; v22++) { + loop14: for (int v23 = 0; v23 < 3; v23++) { + loop15: for (int v24 = 0; v24 < 3; v24++) { + loop16: for (int v25 = 0; v25 < 8; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v26 = 0; v26 < 2; v26++) { + loop18: for (int v27 = 0; v27 < 1; v27++) { + loop19: for (int v28 = 0; v28 < 1; v28++) { + loop20: for (int v29 = 0; v29 < 1; v29++) { + loop21: for (int v30 = 0; v30 < 14; v30++) { + float v31 = v4[(v22 + v27)][(((v26 + (v21 * 2)) + v23) + v28)][(((v30 + (v25 * 14)) + v24) + v29)]; + float v32 = v2[(v22 + v27)][(v23 + v28)][(v24 + v29)]; + if ((v23 + v28) == 0 && (v24 + v29) == 0) { + v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))] = 0.000000; + } + float v33 = v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))] = v35; + if (((v23 + v28) - 2) == 0 && ((v24 + v29) - 2) == 0) { + float v36 = v18[(v22 + v27)][(v26 + (v21 * 2))][(v30 + (v25 * 14))]; + v19[v27][v26][v30].write(v36); + } + } + } + } + } + } + } + } + } + } + } + float v37[8][112][112]; + hls::stream v38[1][2][14]; + #pragma HLS STREAM variable=v38 depth=3584 + loop22: for (int v39 = 0; v39 < 56; v39++) { + loop23: for (int v40 = 0; v40 < 8; v40++) { + loop24: for (int v41 = 0; v41 < 8; v41++) { + loop25: for (int v42 = 0; v42 < 8; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v43 = 0; v43 < 2; v43++) { + loop27: for (int v44 = 0; v44 < 1; v44++) { + loop28: for (int v45 = 0; v45 < 14; v45++) { + loop29: for (int v46 = 0; v46 < 1; v46++) { + if ((v42 + v46) == 0) { + float v47 = v19[v44][v43][v45].read(); + v20[(v40 + v44)][(v43 + (v39 * 2))][(v45 + (v41 * 14))] = v47; + } + float v48 = v20[(v40 + v44)][(v43 + (v39 * 2))][(v45 + (v41 * 14))]; + float v49 = v1[(v42 + v46)][(v40 + v44)][0][0]; + if ((v40 + v44) == 0) { + v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))] = 0.000000; + } + float v50 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))]; + float v51 = v48 * v49; + float v52 = v50 + v51; + v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))] = v52; + if (((v40 + v44) - 7) == 0) { + float v53 = v37[(v42 + v46)][(v43 + (v39 * 2))][(v45 + (v41 * 14))]; + v38[v46][v43][v45].write(v53); + } + } + } + } + } + } + } + } + } + hls::stream v54[1][2][14]; + #pragma HLS STREAM variable=v54 depth=3584 + loop30: for (int v55 = 0; v55 < 56; v55++) { + loop31: for (int v56 = 0; v56 < 8; v56++) { + loop32: for (int v57 = 0; v57 < 8; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v58 = 0; v58 < 2; v58++) { + loop34: for (int v59 = 0; v59 < 14; v59++) { + loop35: for (int v60 = 0; v60 < 1; v60++) { + float v61 = v38[v60][v58][v59].read(); + float v62 = 0.000010; + float v63 = v62 + 1.000000; + float v64 = 1.0 / sqrt(v63); + float v65 = v61 * v64; + float v66 = v65 + 0.000000; + bool v67 = v66 > 0.000000; + float v68 = v67 ? (float)v66 : (float)0.000000; + v54[v60][v58][v59].write(v68); + } + } + } + } + } + } + loop36: for (int v69 = 0; v69 < 56; v69++) { + loop37: for (int v70 = 0; v70 < 8; v70++) { + loop38: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v72 = 0; v72 < 2; v72++) { + loop40: for (int v73 = 0; v73 < 14; v73++) { + loop41: for (int v74 = 0; v74 < 1; v74++) { + float v75 = v54[v74][v72][v73].read(); + v3[0][(v71 + v74)][(v72 + (v69 * 2))][(v73 + (v70 * 14))] = v75; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt1/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt1/src/FeedForward.cpp new file mode 100644 index 000000000000..b25856f045e0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt1/src/FeedForward.cpp @@ -0,0 +1,229 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][512][128] +) { + loop0: for (int v2 = 0; v2 < 512; v2++) { + loop1: for (int v3 = 0; v3 < 128; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 512; v8++) { + loop3: for (int v9 = 0; v9 < 128; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v9]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + hls::stream &v13, + float v14[256][128], + hls::stream &v15, + float v16 +) { + float v17[512][128]; + float v18[256][128]; + float v19[512][256]; + loop4: for (int v20 = 0; v20 < 512; v20++) { + loop5: for (int v21 = 0; v21 < 128; v21++) { + loop6: for (int v22 = 0; v22 < 256; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v21 == 0) { + float v23 = v13.read(); + v19[v20][v22] = v23; + } + float v24 = v19[v20][v22]; + if (v20 == 0) { + float v25 = v14[v22][v21]; + v18[v22][v21] = v25; + } + float v26 = v18[v22][v21]; + if (v22 == 0) { + v17[v20][v21] = v16; + } + float v27 = v17[v20][v21]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v20][v21] = v29; + if ((v22 - 255) == 0) { + float v30 = v17[v20][v21]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][256], + float v32[256][128] +) { + loop7: for (int v33 = 0; v33 < 256; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32[v33][v34] = v35; + } + } + return ; +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38, + float v39 +) { + loop9: for (int v40 = 0; v40 < 512; v40++) { + loop10: for (int v41 = 0; v41 < 256; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v36.read(); + float v43 = v37[v41]; + float v44 = v42 + v43; + bool v45 = v44 > v39; + float v46 = v45 ? (float)v44 : (float)v39; + v38.write(v46); + } + } + return ; +} + +void node5( + hls::stream &v47, + float v48[128][256], + hls::stream &v49, + float v50 +) { + float v51[512][256]; + float v52[128][256]; + float v53[512][128]; + loop11: for (int v54 = 0; v54 < 512; v54++) { + loop12: for (int v55 = 0; v55 < 256; v55++) { + loop13: for (int v56 = 0; v56 < 128; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v55 == 0) { + float v57 = v47.read(); + v53[v54][v56] = v57; + } + float v58 = v53[v54][v56]; + if (v54 == 0) { + float v59 = v48[v56][v55]; + v52[v56][v55] = v59; + } + float v60 = v52[v56][v55]; + if (v56 == 0) { + v51[v54][v55] = v50; + } + float v61 = v51[v54][v55]; + float v62 = v58 * v60; + float v63 = v61 + v62; + v51[v54][v55] = v63; + if ((v56 - 127) == 0) { + float v64 = v51[v54][v55]; + v49.write(v64); + } + } + } + } + return ; +} + +void node6( + float v65[256][128], + float v66[128][256] +) { + loop14: for (int v67 = 0; v67 < 128; v67++) { + loop15: for (int v68 = 0; v68 < 256; v68++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v69 = v65[v68][v67]; + v66[v67][v68] = v69; + } + } + return ; +} + +void node7( + float v70[1][512][128], + hls::stream &v71 +) { + loop16: for (int v72 = 0; v72 < 512; v72++) { + loop17: for (int v73 = 0; v73 < 128; v73++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[0][v72][v73]; + v71.write(v74); + } + } + return ; +} + +void forward( + float v75[1][512][128], + float v76[256], + float v77[256][128], + float v78[128], + float v79[128][256], + float v80[1][512][128] +) { + #pragma HLS DATAFLOW + hls::stream v81("fifo_0"); + #pragma HLS STREAM variable=v81 depth=65536 + hls::stream v82("fifo_1"); + #pragma HLS STREAM variable=v82 depth=65536 + float v83[256][128]; + hls::stream v84("fifo_2"); + #pragma HLS STREAM variable=v84 depth=131072 + hls::stream v85("fifo_3"); + #pragma HLS STREAM variable=v85 depth=131072 + float v86[128][256]; + hls::stream v87("fifo_4"); + #pragma HLS STREAM variable=v87 depth=65536 + node7(v75, v87); + node6(v77, v86); + node5(v87, v86, v85, 0.000000); + node4(v85, v76, v84, 0.000000); + node3(v79, v83); + node2(v84, v83, v82, 0.000000); + node1(v82, v78, v81); + node0(v81, v80); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt2/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt2/src/FeedForward.cpp new file mode 100644 index 000000000000..9240141cfa48 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt2/src/FeedForward.cpp @@ -0,0 +1,231 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][512][128] +) { + loop0: for (int v2 = 0; v2 < 512; v2++) { + loop1: for (int v3 = 0; v3 < 128; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 512; v8++) { + loop3: for (int v9 = 0; v9 < 128; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v9]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + hls::stream &v13, + hls::stream &v14, + hls::stream &v15, + float v16 +) { + float v17[512][128]; + float v18[256][128]; + float v19[512][256]; + loop4: for (int v20 = 0; v20 < 512; v20++) { + loop5: for (int v21 = 0; v21 < 256; v21++) { + loop6: for (int v22 = 0; v22 < 128; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v22 == 0) { + float v23 = v13.read(); + v19[v20][v21] = v23; + } + float v24 = v19[v20][v21]; + if (v20 == 0) { + float v25 = v14.read(); + v18[v21][v22] = v25; + } + float v26 = v18[v21][v22]; + if (v21 == 0) { + v17[v20][v22] = v16; + } + float v27 = v17[v20][v22]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v20][v22] = v29; + if ((v21 - 255) == 0) { + float v30 = v17[v20][v22]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][256], + hls::stream &v32 +) { + loop7: for (int v33 = 0; v33 < 256; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32.write(v35); + } + } + return ; +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38, + float v39 +) { + loop9: for (int v40 = 0; v40 < 512; v40++) { + loop10: for (int v41 = 0; v41 < 256; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v36.read(); + float v43 = v37[v41]; + float v44 = v42 + v43; + bool v45 = v44 > v39; + float v46 = v45 ? (float)v44 : (float)v39; + v38.write(v46); + } + } + return ; +} + +void node5( + hls::stream &v47, + hls::stream &v48, + hls::stream &v49, + float v50 +) { + float v51[512][256]; + float v52[128][256]; + float v53[512][128]; + loop11: for (int v54 = 0; v54 < 512; v54++) { + loop12: for (int v55 = 0; v55 < 128; v55++) { + loop13: for (int v56 = 0; v56 < 256; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v56 == 0) { + float v57 = v47.read(); + v53[v54][v55] = v57; + } + float v58 = v53[v54][v55]; + if (v54 == 0) { + float v59 = v48.read(); + v52[v55][v56] = v59; + } + float v60 = v52[v55][v56]; + if (v55 == 0) { + v51[v54][v56] = v50; + } + float v61 = v51[v54][v56]; + float v62 = v58 * v60; + float v63 = v61 + v62; + v51[v54][v56] = v63; + if ((v55 - 127) == 0) { + float v64 = v51[v54][v56]; + v49.write(v64); + } + } + } + } + return ; +} + +void node6( + float v65[256][128], + hls::stream &v66 +) { + loop14: for (int v67 = 0; v67 < 128; v67++) { + loop15: for (int v68 = 0; v68 < 256; v68++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v69 = v65[v68][v67]; + v66.write(v69); + } + } + return ; +} + +void node7( + float v70[1][512][128], + hls::stream &v71 +) { + loop16: for (int v72 = 0; v72 < 512; v72++) { + loop17: for (int v73 = 0; v73 < 128; v73++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v70[0][v72][v73]; + v71.write(v74); + } + } + return ; +} + +void forward( + float v75[1][512][128], + float v76[256], + float v77[256][128], + float v78[128], + float v79[128][256], + float v80[1][512][128] +) { + #pragma HLS DATAFLOW + hls::stream v81("fifo_0"); + #pragma HLS STREAM variable=v81 depth=65536 + hls::stream v82("fifo_1"); + #pragma HLS STREAM variable=v82 depth=65536 + hls::stream v83("fifo_2"); + #pragma HLS STREAM variable=v83 depth=32768 + hls::stream v84("fifo_3"); + #pragma HLS STREAM variable=v84 depth=131072 + hls::stream v85("fifo_4"); + #pragma HLS STREAM variable=v85 depth=131072 + hls::stream v86("fifo_5"); + #pragma HLS STREAM variable=v86 depth=32768 + hls::stream v87("fifo_6"); + #pragma HLS STREAM variable=v87 depth=65536 + node7(v75, v87); + node6(v77, v86); + node5(v87, v86, v85, 0.000000); + node4(v85, v76, v84, 0.000000); + node3(v79, v83); + node2(v84, v83, v82, 0.000000); + node1(v82, v78, v81); + node0(v81, v80); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt3/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt3/src/FeedForward.cpp new file mode 100644 index 000000000000..cd9bf2ad109e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt3/src/FeedForward.cpp @@ -0,0 +1,333 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][8], + float v1[1][512][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 256; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 2))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][8], + float v8[128], + hls::stream v9[2][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 256; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 2; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + float v17[256][128], + hls::stream v18[2][16], + hls::stream v19[2][8], + float v20 +) { + #pragma HLS array_partition variable=v17 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v17 cyclic dim=2 factor=8 + + float v21[512][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[256][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[512][256]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=16 + + loop8: for (int v24 = 0; v24 < 256; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 2; v27++) { + loop12: for (int v28 = 0; v28 < 8; v28++) { + loop13: for (int v29 = 0; v29 < 16; v29++) { + if ((v28 + (v25 * 8)) == 0) { + float v30 = v18[v27][v29].read(); + v23[(v27 + (v24 * 2))][(v29 + (v26 * 16))] = v30; + } + float v31 = v23[(v27 + (v24 * 2))][(v29 + (v26 * 16))]; + if ((v27 + (v24 * 2)) == 0) { + float v32 = v17[(v29 + (v26 * 16))][(v28 + (v25 * 8))]; + v22[(v29 + (v26 * 16))][(v28 + (v25 * 8))] = v32; + } + float v33 = v22[(v29 + (v26 * 16))][(v28 + (v25 * 8))]; + if ((v29 + (v26 * 16)) == 0) { + v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))] = v36; + if (((v29 + (v26 * 16)) - 255) == 0) { + float v37 = v21[(v27 + (v24 * 2))][(v28 + (v25 * 8))]; + v19[v27][v28].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][256], + float v39[256][128] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=8 + + loop14: for (int v40 = 0; v40 < 16; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 16; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 16))]; + v39[(v42 + (v40 * 16))][(v43 + (v41 * 8))] = v44; + } + } + } + } + return ; +} + +void node4( + hls::stream v45[2][16], + float v46[256], + hls::stream v47[2][16], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=16 + + loop18: for (int v49 = 0; v49 < 256; v49++) { + loop19: for (int v50 = 0; v50 < 16; v50++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v51 = 0; v51 < 2; v51++) { + loop21: for (int v52 = 0; v52 < 16; v52++) { + float v53 = v45[v51][v52].read(); + float v54 = v46[(v52 + (v50 * 16))]; + float v55 = v53 + v54; + bool v56 = v55 > v48; + float v57 = v56 ? (float)v55 : (float)v48; + v47[v51][v52].write(v57); + } + } + } + } + return ; +} + +void node5( + float v58[128][256], + hls::stream v59[2][8], + hls::stream v60[2][16], + float v61 +) { + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=16 + + float v62[512][256]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=16 + + float v63[128][256]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=16 + + float v64[512][128]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop22: for (int v65 = 0; v65 < 256; v65++) { + loop23: for (int v66 = 0; v66 < 16; v66++) { + loop24: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v68 = 0; v68 < 2; v68++) { + loop26: for (int v69 = 0; v69 < 16; v69++) { + loop27: for (int v70 = 0; v70 < 8; v70++) { + if ((v69 + (v66 * 16)) == 0) { + float v71 = v59[v68][v70].read(); + v64[(v68 + (v65 * 2))][(v70 + (v67 * 8))] = v71; + } + float v72 = v64[(v68 + (v65 * 2))][(v70 + (v67 * 8))]; + if ((v68 + (v65 * 2)) == 0) { + float v73 = v58[(v70 + (v67 * 8))][(v69 + (v66 * 16))]; + v63[(v70 + (v67 * 8))][(v69 + (v66 * 16))] = v73; + } + float v74 = v63[(v70 + (v67 * 8))][(v69 + (v66 * 16))]; + if ((v70 + (v67 * 8)) == 0) { + v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))] = v61; + } + float v75 = v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))] = v77; + if (((v70 + (v67 * 8)) - 127) == 0) { + float v78 = v62[(v68 + (v65 * 2))][(v69 + (v66 * 16))]; + v60[v68][v69].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v79[256][128], + float v80[128][256] +) { + #pragma HLS array_partition variable=v79 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v80 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v80 cyclic dim=2 factor=16 + + loop28: for (int v81 = 0; v81 < 16; v81++) { + loop29: for (int v82 = 0; v82 < 16; v82++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v83 = 0; v83 < 8; v83++) { + loop31: for (int v84 = 0; v84 < 16; v84++) { + float v85 = v79[(v84 + (v82 * 16))][(v83 + (v81 * 8))]; + v80[(v83 + (v81 * 8))][(v84 + (v82 * 16))] = v85; + } + } + } + } + return ; +} + +void node7( + float v86[1][512][128], + hls::stream v87[2][8] +) { + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v86 cyclic dim=3 factor=8 + + loop32: for (int v88 = 0; v88 < 256; v88++) { + loop33: for (int v89 = 0; v89 < 16; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 2; v90++) { + loop35: for (int v91 = 0; v91 < 8; v91++) { + float v92 = v86[0][(v90 + (v88 * 2))][(v91 + (v89 * 8))]; + v87[v90][v91].write(v92); + } + } + } + } + return ; +} + +void forward( + float v93[1][512][128], + float v94[256], + float v95[256][128], + float v96[128], + float v97[128][256], + float v98[1][512][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v93 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v94 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v95 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v95 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v97 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v98 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v98 cyclic dim=3 factor=8 + + hls::stream v99[2][8]; + #pragma HLS STREAM variable=v99 depth=4096 + hls::stream v100[2][8]; + #pragma HLS STREAM variable=v100 depth=4096 + float v101[256][128]; + #pragma HLS array_partition variable=v101 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v101 cyclic dim=2 factor=8 + + hls::stream v102[2][16]; + #pragma HLS STREAM variable=v102 depth=4096 + hls::stream v103[2][16]; + #pragma HLS STREAM variable=v103 depth=4096 + float v104[128][256]; + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=16 + + hls::stream v105[2][8]; + #pragma HLS STREAM variable=v105 depth=4096 + node7(v93, v105); + node6(v95, v104); + node5(v104, v105, v103, 0.000000); + node4(v103, v94, v102, 0.000000); + node3(v97, v101); + node2(v101, v102, v100, 0.000000); + node1(v100, v96, v99); + node0(v99, v98); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt4/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt4/src/FeedForward.cpp new file mode 100644 index 000000000000..649f30f37f9c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt4/src/FeedForward.cpp @@ -0,0 +1,317 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][8], + float v1[1][512][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 256; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 2))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][8], + float v8[128], + hls::stream v9[2][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 256; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 2; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[16][8], + hls::stream v18[2][16], + hls::stream v19[2][8], + float v20 +) { + float v21[512][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[256][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[512][256]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=16 + + loop8: for (int v24 = 0; v24 < 256; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 2; v27++) { + loop12: for (int v28 = 0; v28 < 16; v28++) { + loop13: for (int v29 = 0; v29 < 8; v29++) { + if ((v29 + (v26 * 8)) == 0) { + float v30 = v18[v27][v28].read(); + v23[(v27 + (v24 * 2))][(v28 + (v25 * 16))] = v30; + } + float v31 = v23[(v27 + (v24 * 2))][(v28 + (v25 * 16))]; + if ((v27 + (v24 * 2)) == 0) { + float v32 = v17[v28][v29].read(); + v22[(v28 + (v25 * 16))][(v29 + (v26 * 8))] = v32; + } + float v33 = v22[(v28 + (v25 * 16))][(v29 + (v26 * 8))]; + if ((v28 + (v25 * 16)) == 0) { + v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))] = v36; + if (((v28 + (v25 * 16)) - 255) == 0) { + float v37 = v21[(v27 + (v24 * 2))][(v29 + (v26 * 8))]; + v19[v27][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][256], + hls::stream v39[16][8] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=16 + + loop14: for (int v40 = 0; v40 < 16; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 16; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 16))]; + v39[v42][v43].write(v44); + } + } + } + } + return ; +} + +void node4( + hls::stream v45[2][16], + float v46[256], + hls::stream v47[2][16], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=16 + + loop18: for (int v49 = 0; v49 < 256; v49++) { + loop19: for (int v50 = 0; v50 < 16; v50++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v51 = 0; v51 < 2; v51++) { + loop21: for (int v52 = 0; v52 < 16; v52++) { + float v53 = v45[v51][v52].read(); + float v54 = v46[(v52 + (v50 * 16))]; + float v55 = v53 + v54; + bool v56 = v55 > v48; + float v57 = v56 ? (float)v55 : (float)v48; + v47[v51][v52].write(v57); + } + } + } + } + return ; +} + +void node5( + hls::stream v58[8][16], + hls::stream v59[2][8], + hls::stream v60[2][16], + float v61 +) { + float v62[512][256]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=16 + + float v63[128][256]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=16 + + float v64[512][128]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop22: for (int v65 = 0; v65 < 256; v65++) { + loop23: for (int v66 = 0; v66 < 16; v66++) { + loop24: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v68 = 0; v68 < 2; v68++) { + loop26: for (int v69 = 0; v69 < 8; v69++) { + loop27: for (int v70 = 0; v70 < 16; v70++) { + if ((v70 + (v67 * 16)) == 0) { + float v71 = v59[v68][v69].read(); + v64[(v68 + (v65 * 2))][(v69 + (v66 * 8))] = v71; + } + float v72 = v64[(v68 + (v65 * 2))][(v69 + (v66 * 8))]; + if ((v68 + (v65 * 2)) == 0) { + float v73 = v58[v69][v70].read(); + v63[(v69 + (v66 * 8))][(v70 + (v67 * 16))] = v73; + } + float v74 = v63[(v69 + (v66 * 8))][(v70 + (v67 * 16))]; + if ((v69 + (v66 * 8)) == 0) { + v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))] = v61; + } + float v75 = v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))] = v77; + if (((v69 + (v66 * 8)) - 127) == 0) { + float v78 = v62[(v68 + (v65 * 2))][(v70 + (v67 * 16))]; + v60[v68][v70].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v79[256][128], + hls::stream v80[8][16] +) { + #pragma HLS array_partition variable=v79 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=8 + + loop28: for (int v81 = 0; v81 < 16; v81++) { + loop29: for (int v82 = 0; v82 < 16; v82++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v83 = 0; v83 < 8; v83++) { + loop31: for (int v84 = 0; v84 < 16; v84++) { + float v85 = v79[(v84 + (v82 * 16))][(v83 + (v81 * 8))]; + v80[v83][v84].write(v85); + } + } + } + } + return ; +} + +void node7( + float v86[1][512][128], + hls::stream v87[2][8] +) { + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v86 cyclic dim=3 factor=8 + + loop32: for (int v88 = 0; v88 < 256; v88++) { + loop33: for (int v89 = 0; v89 < 16; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 2; v90++) { + loop35: for (int v91 = 0; v91 < 8; v91++) { + float v92 = v86[0][(v90 + (v88 * 2))][(v91 + (v89 * 8))]; + v87[v90][v91].write(v92); + } + } + } + } + return ; +} + +void forward( + float v93[1][512][128], + float v94[256], + float v95[256][128], + float v96[128], + float v97[128][256], + float v98[1][512][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v93 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v94 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v95 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v95 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v97 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v98 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v98 cyclic dim=3 factor=8 + + hls::stream v99[2][8]; + #pragma HLS STREAM variable=v99 depth=4096 + hls::stream v100[2][8]; + #pragma HLS STREAM variable=v100 depth=4096 + hls::stream v101[16][8]; + #pragma HLS STREAM variable=v101 depth=256 + hls::stream v102[2][16]; + #pragma HLS STREAM variable=v102 depth=4096 + hls::stream v103[2][16]; + #pragma HLS STREAM variable=v103 depth=4096 + hls::stream v104[8][16]; + #pragma HLS STREAM variable=v104 depth=256 + hls::stream v105[2][8]; + #pragma HLS STREAM variable=v105 depth=4096 + node7(v93, v105); + node6(v95, v104); + node5(v104, v105, v103, 0.000000); + node4(v103, v94, v102, 0.000000); + node3(v97, v101); + node2(v101, v102, v100, 0.000000); + node1(v100, v96, v99); + node0(v99, v98); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt5/src/FeedForward.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt5/src/FeedForward.cpp new file mode 100644 index 000000000000..a3d637e285b4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/FeedForward__opt5/src/FeedForward.cpp @@ -0,0 +1,305 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[32][8], + float v1[1][512][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 32; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 32))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[32][8], + float v8[128], + hls::stream v9[32][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 16; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 32; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[1][8], + hls::stream v18[32][1], + hls::stream v19[32][8], + float v20 +) { + float v21[512][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[256][128]; + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[512][256]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=32 + + loop8: for (int v24 = 0; v24 < 256; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 1; v27++) { + loop12: for (int v28 = 0; v28 < 32; v28++) { + loop13: for (int v29 = 0; v29 < 8; v29++) { + if ((v29 + (v26 * 8)) == 0) { + float v30 = v18[v28][v27].read(); + v23[(v28 + (v25 * 32))][(v24 + v27)] = v30; + } + float v31 = v23[(v28 + (v25 * 32))][(v24 + v27)]; + if ((v28 + (v25 * 32)) == 0) { + float v32 = v17[v27][v29].read(); + v22[(v24 + v27)][(v29 + (v26 * 8))] = v32; + } + float v33 = v22[(v24 + v27)][(v29 + (v26 * 8))]; + if ((v24 + v27) == 0) { + v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))] = v20; + } + float v34 = v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))] = v36; + if (((v24 + v27) - 255) == 0) { + float v37 = v21[(v28 + (v25 * 32))][(v29 + (v26 * 8))]; + v19[v28][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][256], + hls::stream v39[1][8] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + + loop14: for (int v40 = 0; v40 < 256; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 1; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v40 + v42)]; + v39[v42][v43].write(v44); + } + } + } + } + return ; +} + +void node4( + hls::stream v45[32][1], + float v46[256], + hls::stream v47[32][1], + float v48 +) { + loop18: for (int v49 = 0; v49 < 256; v49++) { + loop19: for (int v50 = 0; v50 < 16; v50++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v51 = 0; v51 < 1; v51++) { + loop21: for (int v52 = 0; v52 < 32; v52++) { + float v53 = v45[v52][v51].read(); + float v54 = v46[(v49 + v51)]; + float v55 = v53 + v54; + bool v56 = v55 > v48; + float v57 = v56 ? (float)v55 : (float)v48; + v47[v52][v51].write(v57); + } + } + } + } + return ; +} + +void node5( + hls::stream v58[32][8], + hls::stream v59[8][1], + hls::stream v60[32][1], + float v61 +) { + float v62[512][256]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=32 + + float v63[128][256]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + + float v64[512][128]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop22: for (int v65 = 0; v65 < 256; v65++) { + loop23: for (int v66 = 0; v66 < 16; v66++) { + loop24: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v68 = 0; v68 < 1; v68++) { + loop26: for (int v69 = 0; v69 < 8; v69++) { + loop27: for (int v70 = 0; v70 < 32; v70++) { + if ((v65 + v68) == 0) { + float v71 = v58[v70][v69].read(); + v64[(v70 + (v67 * 32))][(v69 + (v66 * 8))] = v71; + } + float v72 = v64[(v70 + (v67 * 32))][(v69 + (v66 * 8))]; + if ((v70 + (v67 * 32)) == 0) { + float v73 = v59[v69][v68].read(); + v63[(v69 + (v66 * 8))][(v65 + v68)] = v73; + } + float v74 = v63[(v69 + (v66 * 8))][(v65 + v68)]; + if ((v69 + (v66 * 8)) == 0) { + v62[(v70 + (v67 * 32))][(v65 + v68)] = v61; + } + float v75 = v62[(v70 + (v67 * 32))][(v65 + v68)]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v70 + (v67 * 32))][(v65 + v68)] = v77; + if (((v69 + (v66 * 8)) - 127) == 0) { + float v78 = v62[(v70 + (v67 * 32))][(v65 + v68)]; + v60[v70][v68].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v79[256][128], + hls::stream v80[8][1] +) { + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=8 + + loop28: for (int v81 = 0; v81 < 256; v81++) { + loop29: for (int v82 = 0; v82 < 16; v82++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v83 = 0; v83 < 1; v83++) { + loop31: for (int v84 = 0; v84 < 8; v84++) { + float v85 = v79[(v81 + v83)][(v84 + (v82 * 8))]; + v80[v84][v83].write(v85); + } + } + } + } + return ; +} + +void node7( + float v86[1][512][128], + hls::stream v87[32][8] +) { + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v86 cyclic dim=3 factor=8 + + loop32: for (int v88 = 0; v88 < 16; v88++) { + loop33: for (int v89 = 0; v89 < 16; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 8; v90++) { + loop35: for (int v91 = 0; v91 < 32; v91++) { + float v92 = v86[0][(v91 + (v89 * 32))][(v90 + (v88 * 8))]; + v87[v91][v90].write(v92); + } + } + } + } + return ; +} + +void forward( + float v93[1][512][128], + float v94[256], + float v95[256][128], + float v96[128], + float v97[128][256], + float v98[1][512][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v93 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v95 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v98 cyclic dim=2 factor=32 + #pragma HLS array_partition variable=v98 cyclic dim=3 factor=8 + + hls::stream v99[32][8]; + #pragma HLS STREAM variable=v99 depth=256 + hls::stream v100[32][8]; + #pragma HLS STREAM variable=v100 depth=256 + hls::stream v101[1][8]; + #pragma HLS STREAM variable=v101 depth=4096 + hls::stream v102[32][1]; + #pragma HLS STREAM variable=v102 depth=4096 + hls::stream v103[32][1]; + #pragma HLS STREAM variable=v103 depth=4096 + hls::stream v104[8][1]; + #pragma HLS STREAM variable=v104 depth=4096 + hls::stream v105[32][8]; + #pragma HLS STREAM variable=v105 depth=256 + node7(v93, v105); + node6(v95, v104); + node5(v105, v104, v103, 0.000000); + node4(v103, v94, v102, 0.000000); + node3(v97, v101); + node2(v101, v102, v100, 0.000000); + node1(v100, v96, v99); + node0(v99, v98); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..73146c87489f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt1/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,734 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][64][128] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 128; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 64; v8++) { + loop3: for (int v9 = 0; v9 < 128; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v9]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + float v13[128][128], + hls::stream &v14, + hls::stream &v15, + float v16 +) { + float v17[64][128]; + float v18[128][128]; + float v19[64][128]; + loop4: for (int v20 = 0; v20 < 64; v20++) { + loop5: for (int v21 = 0; v21 < 128; v21++) { + loop6: for (int v22 = 0; v22 < 128; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v21 == 0) { + float v23 = v14.read(); + v19[v20][v22] = v23; + } + float v24 = v19[v20][v22]; + if (v20 == 0) { + float v25 = v13[v22][v21]; + v18[v22][v21] = v25; + } + float v26 = v18[v22][v21]; + if (v22 == 0) { + v17[v20][v21] = v16; + } + float v27 = v17[v20][v21]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v20][v21] = v29; + if ((v22 - 127) == 0) { + float v30 = v17[v20][v21]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][128], + float v32[128][128] +) { + loop7: for (int v33 = 0; v33 < 128; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32[v33][v34] = v35; + } + } + return ; +} + +void node4( + float v36[64][8][16], + hls::stream &v37 +) { + loop9: for (int v38 = 0; v38 < 64; v38++) { + loop10: for (int v39 = 0; v39 < 128; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v38][(v39 / 16)][(v39 % 16)]; + v37.write(v40); + } + } + return ; +} + +void node5( + float v41[8][64][16], + float v42[64][8][16] +) { + loop11: for (int v43 = 0; v43 < 8; v43++) { + loop12: for (int v44 = 0; v44 < 64; v44++) { + loop13: for (int v45 = 0; v45 < 16; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v46 = v41[v43][v44][v45]; + v42[v44][v43][v45] = v46; + } + } + } + return ; +} + +void node6( + float v47[8][64][16], + hls::stream &v48, + float v49[8][64][16], + float v50 +) { + float v51[8][64][16]; + float v52[8][64][16]; + float v53[8][64][64]; + loop14: for (int v54 = 0; v54 < 8; v54++) { + loop15: for (int v55 = 0; v55 < 64; v55++) { + loop16: for (int v56 = 0; v56 < 16; v56++) { + loop17: for (int v57 = 0; v57 < 64; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v56 == 0) { + float v58 = v48.read(); + v53[v54][v55][v57] = v58; + } + float v59 = v53[v54][v55][v57]; + if (v55 == 0) { + float v60 = v47[v54][v57][v56]; + v52[v54][v57][v56] = v60; + } + float v61 = v52[v54][v57][v56]; + if (v57 == 0) { + v51[v54][v55][v56] = v50; + } + float v62 = v51[v54][v55][v56]; + float v63 = v59 * v61; + float v64 = v62 + v63; + v51[v54][v55][v56] = v64; + if ((v57 - 63) == 0) { + float v65 = v51[v54][v55][v56]; + v49[v54][v55][v56] = v65; + } + } + } + } + } + return ; +} + +void node7( + float v66[64][128], + float v67[8][64][16] +) { + loop18: for (int v68 = 0; v68 < 8; v68++) { + loop19: for (int v69 = 0; v69 < 64; v69++) { + loop20: for (int v70 = 0; v70 < 16; v70++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v71 = v66[v69][((v68 * 16) + v70)]; + v67[v68][v69][v70] = v71; + } + } + } + return ; +} + +void node8( + hls::stream &v72, + hls::stream &v73, + hls::stream &v74 +) { + float v75[8][64]; + loop21: for (int v76 = 0; v76 < 8; v76++) { + loop22: for (int v77 = 0; v77 < 64; v77++) { + loop23: for (int v78 = 0; v78 < 64; v78++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v79 = v72.read(); + if (v78 == 0) { + float v80 = v73.read(); + v75[v76][v77] = v80; + } + float v81 = v75[v76][v77]; + float v82 = v79 / v81; + v74.write(v82); + } + } + } + return ; +} + +void node9( + hls::stream &v83, + hls::stream &v84, + float v85 +) { + float v86[8][64]; + loop24: for (int v87 = 0; v87 < 8; v87++) { + loop25: for (int v88 = 0; v88 < 64; v88++) { + loop26: for (int v89 = 0; v89 < 64; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v90 = v83.read(); + if (v89 == 0) { + v86[v87][v88] = v85; + } + float v91 = v86[v87][v88]; + float v92 = v90 + v91; + v86[v87][v88] = v92; + if ((v89 - 63) == 0) { + float v93 = v86[v87][v88]; + v84.write(v93); + } + } + } + } + return ; +} + +void node10( + hls::stream &v94, + hls::stream &v95, + hls::stream &v96, + hls::stream &v97 +) { + float v98[8][64]; + loop27: for (int v99 = 0; v99 < 8; v99++) { + loop28: for (int v100 = 0; v100 < 64; v100++) { + loop29: for (int v101 = 0; v101 < 64; v101++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v102 = v94.read(); + if (v101 == 0) { + float v103 = v95.read(); + v98[v99][v100] = v103; + } + float v104 = v98[v99][v100]; + float v105 = v102 - v104; + float v106 = exp(v105); + v96.write(v106); + v97.write(v106); + } + } + } + return ; +} + +void node11( + hls::stream &v107, + hls::stream &v108, + float v109 +) { + float v110[8][64]; + loop30: for (int v111 = 0; v111 < 8; v111++) { + loop31: for (int v112 = 0; v112 < 64; v112++) { + loop32: for (int v113 = 0; v113 < 64; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v107.read(); + if (v113 == 0) { + v110[v111][v112] = v109; + } + float v115 = v110[v111][v112]; + float v116 = fmax(v114, v115); + v110[v111][v112] = v116; + if ((v113 - 63) == 0) { + float v117 = v110[v111][v112]; + v108.write(v117); + } + } + } + } + return ; +} + +void node12( + hls::stream &v118, + hls::stream &v119, + hls::stream &v120, + float v121 +) { + loop33: for (int v122 = 0; v122 < 8; v122++) { + loop34: for (int v123 = 0; v123 < 64; v123++) { + loop35: for (int v124 = 0; v124 < 64; v124++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v125 = v118.read(); + float v126 = v125 / v121; + v119.write(v126); + v120.write(v126); + } + } + } + return ; +} + +void node13( + hls::stream &v127, + float v128[8][16][64], + hls::stream &v129, + float v130 +) { + float v131[8][64][64]; + float v132[8][16][64]; + float v133[8][64][16]; + loop36: for (int v134 = 0; v134 < 8; v134++) { + loop37: for (int v135 = 0; v135 < 64; v135++) { + loop38: for (int v136 = 0; v136 < 64; v136++) { + loop39: for (int v137 = 0; v137 < 16; v137++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v136 == 0) { + float v138 = v127.read(); + v133[v134][v135][v137] = v138; + } + float v139 = v133[v134][v135][v137]; + if (v135 == 0) { + float v140 = v128[v134][v137][v136]; + v132[v134][v137][v136] = v140; + } + float v141 = v132[v134][v137][v136]; + if (v137 == 0) { + v131[v134][v135][v136] = v130; + } + float v142 = v131[v134][v135][v136]; + float v143 = v139 * v141; + float v144 = v142 + v143; + v131[v134][v135][v136] = v144; + if ((v137 - 15) == 0) { + float v145 = v131[v134][v135][v136]; + v129.write(v145); + } + } + } + } + } + return ; +} + +void node14( + float v146[64][128], + float v147[8][16][64] +) { + loop40: for (int v148 = 0; v148 < 8; v148++) { + loop41: for (int v149 = 0; v149 < 16; v149++) { + loop42: for (int v150 = 0; v150 < 64; v150++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v151 = v146[v150][((v148 * 16) + v149)]; + v147[v148][v149][v150] = v151; + } + } + } + return ; +} + +void node15( + float v152[64][128], + hls::stream &v153 +) { + loop43: for (int v154 = 0; v154 < 8; v154++) { + loop44: for (int v155 = 0; v155 < 64; v155++) { + loop45: for (int v156 = 0; v156 < 16; v156++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v157 = v152[v155][((v154 * 16) + v156)]; + v153.write(v157); + } + } + } + return ; +} + +void node16( + hls::stream &v158, + float v159[128], + float v160[64][128] +) { + loop46: for (int v161 = 0; v161 < 64; v161++) { + loop47: for (int v162 = 0; v162 < 128; v162++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v163 = v158.read(); + float v164 = v159[v162]; + float v165 = v163 + v164; + v160[v161][v162] = v165; + } + } + return ; +} + +void node17( + hls::stream &v166, + float v167[128][128], + hls::stream &v168, + float v169 +) { + float v170[64][128]; + float v171[128][128]; + float v172[64][128]; + loop48: for (int v173 = 0; v173 < 64; v173++) { + loop49: for (int v174 = 0; v174 < 128; v174++) { + loop50: for (int v175 = 0; v175 < 128; v175++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v174 == 0) { + float v176 = v166.read(); + v172[v173][v175] = v176; + } + float v177 = v172[v173][v175]; + if (v173 == 0) { + float v178 = v167[v175][v174]; + v171[v175][v174] = v178; + } + float v179 = v171[v175][v174]; + if (v175 == 0) { + v170[v173][v174] = v169; + } + float v180 = v170[v173][v174]; + float v181 = v177 * v179; + float v182 = v180 + v181; + v170[v173][v174] = v182; + if ((v175 - 127) == 0) { + float v183 = v170[v173][v174]; + v168.write(v183); + } + } + } + } + return ; +} + +void node18( + float v184[128][128], + float v185[128][128] +) { + loop51: for (int v186 = 0; v186 < 128; v186++) { + loop52: for (int v187 = 0; v187 < 128; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v188 = v184[v187][v186]; + v185[v186][v187] = v188; + } + } + return ; +} + +void node19( + hls::stream &v189, + float v190[128], + float v191[64][128] +) { + loop53: for (int v192 = 0; v192 < 64; v192++) { + loop54: for (int v193 = 0; v193 < 128; v193++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v189.read(); + float v195 = v190[v193]; + float v196 = v194 + v195; + v191[v192][v193] = v196; + } + } + return ; +} + +void node20( + float v197[128][128], + hls::stream &v198, + hls::stream &v199, + float v200 +) { + float v201[64][128]; + float v202[128][128]; + float v203[64][128]; + loop55: for (int v204 = 0; v204 < 64; v204++) { + loop56: for (int v205 = 0; v205 < 128; v205++) { + loop57: for (int v206 = 0; v206 < 128; v206++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v205 == 0) { + float v207 = v198.read(); + v203[v204][v206] = v207; + } + float v208 = v203[v204][v206]; + if (v204 == 0) { + float v209 = v197[v206][v205]; + v202[v206][v205] = v209; + } + float v210 = v202[v206][v205]; + if (v206 == 0) { + v201[v204][v205] = v200; + } + float v211 = v201[v204][v205]; + float v212 = v208 * v210; + float v213 = v211 + v212; + v201[v204][v205] = v213; + if ((v206 - 127) == 0) { + float v214 = v201[v204][v205]; + v199.write(v214); + } + } + } + } + return ; +} + +void node21( + float v215[128][128], + float v216[128][128] +) { + loop58: for (int v217 = 0; v217 < 128; v217++) { + loop59: for (int v218 = 0; v218 < 128; v218++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v219 = v215[v218][v217]; + v216[v217][v218] = v219; + } + } + return ; +} + +void node22( + hls::stream &v220, + float v221[128], + float v222[64][128] +) { + loop60: for (int v223 = 0; v223 < 64; v223++) { + loop61: for (int v224 = 0; v224 < 128; v224++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v225 = v220.read(); + float v226 = v221[v224]; + float v227 = v225 + v226; + v222[v223][v224] = v227; + } + } + return ; +} + +void node23( + hls::stream &v228, + float v229[128][128], + hls::stream &v230, + float v231 +) { + float v232[64][128]; + float v233[128][128]; + float v234[64][128]; + loop62: for (int v235 = 0; v235 < 64; v235++) { + loop63: for (int v236 = 0; v236 < 128; v236++) { + loop64: for (int v237 = 0; v237 < 128; v237++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v236 == 0) { + float v238 = v228.read(); + v234[v235][v237] = v238; + } + float v239 = v234[v235][v237]; + if (v235 == 0) { + float v240 = v229[v237][v236]; + v233[v237][v236] = v240; + } + float v241 = v233[v237][v236]; + if (v237 == 0) { + v232[v235][v236] = v231; + } + float v242 = v232[v235][v236]; + float v243 = v239 * v241; + float v244 = v242 + v243; + v232[v235][v236] = v244; + if ((v237 - 127) == 0) { + float v245 = v232[v235][v236]; + v230.write(v245); + } + } + } + } + return ; +} + +void node24( + float v246[128][128], + float v247[128][128] +) { + loop65: for (int v248 = 0; v248 < 128; v248++) { + loop66: for (int v249 = 0; v249 < 128; v249++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v250 = v246[v249][v248]; + v247[v248][v249] = v250; + } + } + return ; +} + +void node25( + float v251[1][64][128], + hls::stream &v252, + hls::stream &v253, + hls::stream &v254 +) { + loop67: for (int v255 = 0; v255 < 64; v255++) { + loop68: for (int v256 = 0; v256 < 128; v256++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v257 = v251[0][v255][v256]; + v252.write(v257); + v253.write(v257); + v254.write(v257); + } + } + return ; +} + +void forward( + float v258[1][64][128], + float v259[128], + float v260[128][128], + float v261[128], + float v262[128][128], + float v263[128], + float v264[128][128], + float v265[128], + float v266[128][128], + float v267[1][64][128] +) { + #pragma HLS DATAFLOW + hls::stream v268("fifo_0"); + #pragma HLS STREAM variable=v268 depth=8192 + hls::stream v269("fifo_1"); + #pragma HLS STREAM variable=v269 depth=8192 + float v270[128][128]; + hls::stream v271("fifo_2"); + #pragma HLS STREAM variable=v271 depth=8192 + float v272[64][8][16]; + float v273[8][64][16]; + float v274[8][64][16]; + hls::stream v275("fifo_3"); + #pragma HLS STREAM variable=v275 depth=32768 + hls::stream v276("fifo_4"); + #pragma HLS STREAM variable=v276 depth=512 + hls::stream v277("fifo_5"); + #pragma HLS STREAM variable=v277 depth=32768 + hls::stream v278("fifo_6"); + #pragma HLS STREAM variable=v278 depth=32768 + hls::stream v279("fifo_7"); + #pragma HLS STREAM variable=v279 depth=512 + hls::stream v280("fifo_8"); + #pragma HLS STREAM variable=v280 depth=32768 + hls::stream v281("fifo_9"); + #pragma HLS STREAM variable=v281 depth=32768 + hls::stream v282("fifo_10"); + #pragma HLS STREAM variable=v282 depth=32768 + float v283[8][16][64]; + hls::stream v284("fifo_11"); + #pragma HLS STREAM variable=v284 depth=8192 + float v285[64][128]; + hls::stream v286("fifo_12"); + #pragma HLS STREAM variable=v286 depth=8192 + float v287[128][128]; + float v288[64][128]; + hls::stream v289("fifo_13"); + #pragma HLS STREAM variable=v289 depth=8192 + float v290[128][128]; + float v291[64][128]; + hls::stream v292("fifo_14"); + #pragma HLS STREAM variable=v292 depth=8192 + float v293[128][128]; + hls::stream v294("fifo_15"); + #pragma HLS STREAM variable=v294 depth=8192 + hls::stream v295("fifo_16"); + #pragma HLS STREAM variable=v295 depth=8192 + hls::stream v296("fifo_17"); + #pragma HLS STREAM variable=v296 depth=8192 + node25(v258, v296, v295, v294); + node24(v260, v293); + node23(v294, v293, v292, 0.000000); + node22(v292, v259, v291); + node21(v262, v290); + node20(v290, v295, v289, 0.000000); + node19(v289, v261, v288); + node18(v264, v287); + node17(v296, v287, v286, 0.000000); + node16(v286, v263, v285); + node15(v291, v284); + node14(v288, v283); + node13(v284, v283, v282, 0.000000); + node12(v282, v281, v280, 4.000000); + node11(v281, v279, -INFINITY); + node10(v280, v279, v278, v277); + node9(v278, v276, 0.000000); + node8(v277, v276, v275); + node7(v285, v274); + node6(v274, v275, v273, 0.000000); + node5(v273, v272); + node4(v272, v271); + node3(v266, v270); + node2(v270, v271, v269, 0.000000); + node1(v269, v265, v268); + node0(v268, v267); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..f4dcc94569a6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt2/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,738 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][64][128] +) { + loop0: for (int v2 = 0; v2 < 128; v2++) { + loop1: for (int v3 = 0; v3 < 64; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[0][v3][v2] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[128], + hls::stream &v7 +) { + loop2: for (int v8 = 0; v8 < 128; v8++) { + loop3: for (int v9 = 0; v9 < 64; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); + float v11 = v6[v8]; + float v12 = v10 + v11; + v7.write(v12); + } + } + return ; +} + +void node2( + hls::stream &v13, + float v14[128][128], + hls::stream &v15, + float v16 +) { + float v17[64][128]; + float v18[128][128]; + float v19[64][128]; + loop4: for (int v20 = 0; v20 < 128; v20++) { + loop5: for (int v21 = 0; v21 < 128; v21++) { + loop6: for (int v22 = 0; v22 < 64; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v20 == 0) { + float v23 = v13.read(); + v19[v22][v21] = v23; + } + float v24 = v19[v22][v21]; + if (v22 == 0) { + float v25 = v14[v21][v20]; + v18[v21][v20] = v25; + } + float v26 = v18[v21][v20]; + if (v21 == 0) { + v17[v22][v20] = v16; + } + float v27 = v17[v22][v20]; + float v28 = v24 * v26; + float v29 = v27 + v28; + v17[v22][v20] = v29; + if ((v21 - 127) == 0) { + float v30 = v17[v22][v20]; + v15.write(v30); + } + } + } + } + return ; +} + +void node3( + float v31[128][128], + float v32[128][128] +) { + loop7: for (int v33 = 0; v33 < 128; v33++) { + loop8: for (int v34 = 0; v34 < 128; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v34][v33]; + v32[v33][v34] = v35; + } + } + return ; +} + +void node4( + float v36[64][8][16], + hls::stream &v37 +) { + loop9: for (int v38 = 0; v38 < 128; v38++) { + loop10: for (int v39 = 0; v39 < 64; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v40 = v36[v39][(v38 / 16)][(v38 % 16)]; + v37.write(v40); + } + } + return ; +} + +void node5( + float v41[8][64][16], + float v42[64][8][16] +) { + loop11: for (int v43 = 0; v43 < 8; v43++) { + loop12: for (int v44 = 0; v44 < 64; v44++) { + loop13: for (int v45 = 0; v45 < 16; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v46 = v41[v43][v44][v45]; + v42[v44][v43][v45] = v46; + } + } + } + return ; +} + +void node6( + hls::stream &v47, + float v48[8][64][16], + float v49[8][64][16], + float v50 +) { + float v51[8][64][16]; + float v52[8][64][16]; + float v53[8][64][64]; + loop14: for (int v54 = 0; v54 < 8; v54++) { + loop15: for (int v55 = 0; v55 < 64; v55++) { + loop16: for (int v56 = 0; v56 < 64; v56++) { + loop17: for (int v57 = 0; v57 < 16; v57++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v57 == 0) { + float v58 = v47.read(); + v53[v54][v55][v56] = v58; + } + float v59 = v53[v54][v55][v56]; + if (v55 == 0) { + float v60 = v48[v54][v56][v57]; + v52[v54][v56][v57] = v60; + } + float v61 = v52[v54][v56][v57]; + if (v56 == 0) { + v51[v54][v55][v57] = v50; + } + float v62 = v51[v54][v55][v57]; + float v63 = v59 * v61; + float v64 = v62 + v63; + v51[v54][v55][v57] = v64; + if ((v56 - 63) == 0) { + float v65 = v51[v54][v55][v57]; + v49[v54][v55][v57] = v65; + } + } + } + } + } + return ; +} + +void node7( + float v66[64][128], + float v67[8][64][16] +) { + loop18: for (int v68 = 0; v68 < 8; v68++) { + loop19: for (int v69 = 0; v69 < 16; v69++) { + loop20: for (int v70 = 0; v70 < 64; v70++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v71 = v66[v70][((v68 * 16) + v69)]; + v67[v68][v70][v69] = v71; + } + } + } + return ; +} + +void node8( + hls::stream &v72, + hls::stream &v73, + hls::stream &v74 +) { + float v75[8][64]; + loop21: for (int v76 = 0; v76 < 8; v76++) { + loop22: for (int v77 = 0; v77 < 64; v77++) { + loop23: for (int v78 = 0; v78 < 64; v78++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v79 = v72.read(); + if (v78 == 0) { + float v80 = v73.read(); + v75[v76][v77] = v80; + } + float v81 = v75[v76][v77]; + float v82 = v79 / v81; + v74.write(v82); + } + } + } + return ; +} + +void node9( + hls::stream &v83, + hls::stream &v84, + float v85 +) { + float v86[8][64]; + loop24: for (int v87 = 0; v87 < 8; v87++) { + loop25: for (int v88 = 0; v88 < 64; v88++) { + loop26: for (int v89 = 0; v89 < 64; v89++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v90 = v83.read(); + if (v89 == 0) { + v86[v87][v88] = v85; + } + float v91 = v86[v87][v88]; + float v92 = v90 + v91; + v86[v87][v88] = v92; + if ((v89 - 63) == 0) { + float v93 = v86[v87][v88]; + v84.write(v93); + } + } + } + } + return ; +} + +void node10( + hls::stream &v94, + hls::stream &v95, + hls::stream &v96, + hls::stream &v97 +) { + float v98[8][64]; + loop27: for (int v99 = 0; v99 < 8; v99++) { + loop28: for (int v100 = 0; v100 < 64; v100++) { + loop29: for (int v101 = 0; v101 < 64; v101++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v102 = v94.read(); + if (v101 == 0) { + float v103 = v95.read(); + v98[v99][v100] = v103; + } + float v104 = v98[v99][v100]; + float v105 = v102 - v104; + float v106 = exp(v105); + v96.write(v106); + v97.write(v106); + } + } + } + return ; +} + +void node11( + hls::stream &v107, + hls::stream &v108, + float v109 +) { + float v110[8][64]; + loop30: for (int v111 = 0; v111 < 8; v111++) { + loop31: for (int v112 = 0; v112 < 64; v112++) { + loop32: for (int v113 = 0; v113 < 64; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v114 = v107.read(); + if (v113 == 0) { + v110[v111][v112] = v109; + } + float v115 = v110[v111][v112]; + float v116 = fmax(v114, v115); + v110[v111][v112] = v116; + if ((v113 - 63) == 0) { + float v117 = v110[v111][v112]; + v108.write(v117); + } + } + } + } + return ; +} + +void node12( + hls::stream &v118, + hls::stream &v119, + hls::stream &v120, + float v121 +) { + loop33: for (int v122 = 0; v122 < 8; v122++) { + loop34: for (int v123 = 0; v123 < 64; v123++) { + loop35: for (int v124 = 0; v124 < 64; v124++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v125 = v118.read(); + float v126 = v125 / v121; + v119.write(v126); + v120.write(v126); + } + } + } + return ; +} + +void node13( + hls::stream &v127, + hls::stream &v128, + hls::stream &v129, + float v130 +) { + float v131[8][64][64]; + float v132[8][16][64]; + float v133[8][64][16]; + loop36: for (int v134 = 0; v134 < 8; v134++) { + loop37: for (int v135 = 0; v135 < 16; v135++) { + loop38: for (int v136 = 0; v136 < 64; v136++) { + loop39: for (int v137 = 0; v137 < 64; v137++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v137 == 0) { + float v138 = v128.read(); + v133[v134][v136][v135] = v138; + } + float v139 = v133[v134][v136][v135]; + if (v136 == 0) { + float v140 = v127.read(); + v132[v134][v135][v137] = v140; + } + float v141 = v132[v134][v135][v137]; + if (v135 == 0) { + v131[v134][v136][v137] = v130; + } + float v142 = v131[v134][v136][v137]; + float v143 = v139 * v141; + float v144 = v142 + v143; + v131[v134][v136][v137] = v144; + if ((v135 - 15) == 0) { + float v145 = v131[v134][v136][v137]; + v129.write(v145); + } + } + } + } + } + return ; +} + +void node14( + float v146[64][128], + hls::stream &v147 +) { + loop40: for (int v148 = 0; v148 < 8; v148++) { + loop41: for (int v149 = 0; v149 < 16; v149++) { + loop42: for (int v150 = 0; v150 < 64; v150++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v151 = v146[v150][((v148 * 16) + v149)]; + v147.write(v151); + } + } + } + return ; +} + +void node15( + float v152[64][128], + hls::stream &v153 +) { + loop43: for (int v154 = 0; v154 < 8; v154++) { + loop44: for (int v155 = 0; v155 < 16; v155++) { + loop45: for (int v156 = 0; v156 < 64; v156++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v157 = v152[v156][((v154 * 16) + v155)]; + v153.write(v157); + } + } + } + return ; +} + +void node16( + hls::stream &v158, + float v159[128], + float v160[64][128] +) { + loop46: for (int v161 = 0; v161 < 64; v161++) { + loop47: for (int v162 = 0; v162 < 128; v162++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v163 = v158.read(); + float v164 = v159[v162]; + float v165 = v163 + v164; + v160[v161][v162] = v165; + } + } + return ; +} + +void node17( + hls::stream &v166, + hls::stream &v167, + hls::stream &v168, + float v169 +) { + float v170[64][128]; + float v171[128][128]; + float v172[64][128]; + loop48: for (int v173 = 0; v173 < 64; v173++) { + loop49: for (int v174 = 0; v174 < 128; v174++) { + loop50: for (int v175 = 0; v175 < 128; v175++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v175 == 0) { + float v176 = v167.read(); + v172[v173][v174] = v176; + } + float v177 = v172[v173][v174]; + if (v173 == 0) { + float v178 = v166.read(); + v171[v174][v175] = v178; + } + float v179 = v171[v174][v175]; + if (v174 == 0) { + v170[v173][v175] = v169; + } + float v180 = v170[v173][v175]; + float v181 = v177 * v179; + float v182 = v180 + v181; + v170[v173][v175] = v182; + if ((v174 - 127) == 0) { + float v183 = v170[v173][v175]; + v168.write(v183); + } + } + } + } + return ; +} + +void node18( + float v184[128][128], + hls::stream &v185 +) { + loop51: for (int v186 = 0; v186 < 128; v186++) { + loop52: for (int v187 = 0; v187 < 128; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v188 = v184[v187][v186]; + v185.write(v188); + } + } + return ; +} + +void node19( + hls::stream &v189, + float v190[128], + float v191[64][128] +) { + loop53: for (int v192 = 0; v192 < 64; v192++) { + loop54: for (int v193 = 0; v193 < 128; v193++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v194 = v189.read(); + float v195 = v190[v193]; + float v196 = v194 + v195; + v191[v192][v193] = v196; + } + } + return ; +} + +void node20( + hls::stream &v197, + hls::stream &v198, + hls::stream &v199, + float v200 +) { + float v201[64][128]; + float v202[128][128]; + float v203[64][128]; + loop55: for (int v204 = 0; v204 < 64; v204++) { + loop56: for (int v205 = 0; v205 < 128; v205++) { + loop57: for (int v206 = 0; v206 < 128; v206++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v206 == 0) { + float v207 = v197.read(); + v203[v204][v205] = v207; + } + float v208 = v203[v204][v205]; + if (v204 == 0) { + float v209 = v198.read(); + v202[v205][v206] = v209; + } + float v210 = v202[v205][v206]; + if (v205 == 0) { + v201[v204][v206] = v200; + } + float v211 = v201[v204][v206]; + float v212 = v208 * v210; + float v213 = v211 + v212; + v201[v204][v206] = v213; + if ((v205 - 127) == 0) { + float v214 = v201[v204][v206]; + v199.write(v214); + } + } + } + } + return ; +} + +void node21( + float v215[128][128], + hls::stream &v216 +) { + loop58: for (int v217 = 0; v217 < 128; v217++) { + loop59: for (int v218 = 0; v218 < 128; v218++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v219 = v215[v218][v217]; + v216.write(v219); + } + } + return ; +} + +void node22( + hls::stream &v220, + float v221[128], + float v222[64][128] +) { + loop60: for (int v223 = 0; v223 < 64; v223++) { + loop61: for (int v224 = 0; v224 < 128; v224++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v225 = v220.read(); + float v226 = v221[v224]; + float v227 = v225 + v226; + v222[v223][v224] = v227; + } + } + return ; +} + +void node23( + hls::stream &v228, + hls::stream &v229, + hls::stream &v230, + float v231 +) { + float v232[64][128]; + float v233[128][128]; + float v234[64][128]; + loop62: for (int v235 = 0; v235 < 64; v235++) { + loop63: for (int v236 = 0; v236 < 128; v236++) { + loop64: for (int v237 = 0; v237 < 128; v237++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v237 == 0) { + float v238 = v229.read(); + v234[v235][v236] = v238; + } + float v239 = v234[v235][v236]; + if (v235 == 0) { + float v240 = v228.read(); + v233[v236][v237] = v240; + } + float v241 = v233[v236][v237]; + if (v236 == 0) { + v232[v235][v237] = v231; + } + float v242 = v232[v235][v237]; + float v243 = v239 * v241; + float v244 = v242 + v243; + v232[v235][v237] = v244; + if ((v236 - 127) == 0) { + float v245 = v232[v235][v237]; + v230.write(v245); + } + } + } + } + return ; +} + +void node24( + float v246[128][128], + hls::stream &v247 +) { + loop65: for (int v248 = 0; v248 < 128; v248++) { + loop66: for (int v249 = 0; v249 < 128; v249++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v250 = v246[v249][v248]; + v247.write(v250); + } + } + return ; +} + +void node25( + float v251[1][64][128], + hls::stream &v252, + hls::stream &v253, + hls::stream &v254 +) { + loop67: for (int v255 = 0; v255 < 64; v255++) { + loop68: for (int v256 = 0; v256 < 128; v256++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v257 = v251[0][v255][v256]; + v252.write(v257); + v253.write(v257); + v254.write(v257); + } + } + return ; +} + +void forward( + float v258[1][64][128], + float v259[128], + float v260[128][128], + float v261[128], + float v262[128][128], + float v263[128], + float v264[128][128], + float v265[128], + float v266[128][128], + float v267[1][64][128] +) { + #pragma HLS DATAFLOW + hls::stream v268("fifo_0"); + #pragma HLS STREAM variable=v268 depth=8192 + hls::stream v269("fifo_1"); + #pragma HLS STREAM variable=v269 depth=8192 + float v270[128][128]; + hls::stream v271("fifo_2"); + #pragma HLS STREAM variable=v271 depth=8192 + float v272[64][8][16]; + float v273[8][64][16]; + float v274[8][64][16]; + hls::stream v275("fifo_3"); + #pragma HLS STREAM variable=v275 depth=32768 + hls::stream v276("fifo_4"); + #pragma HLS STREAM variable=v276 depth=512 + hls::stream v277("fifo_5"); + #pragma HLS STREAM variable=v277 depth=32768 + hls::stream v278("fifo_6"); + #pragma HLS STREAM variable=v278 depth=32768 + hls::stream v279("fifo_7"); + #pragma HLS STREAM variable=v279 depth=512 + hls::stream v280("fifo_8"); + #pragma HLS STREAM variable=v280 depth=32768 + hls::stream v281("fifo_9"); + #pragma HLS STREAM variable=v281 depth=32768 + hls::stream v282("fifo_10"); + #pragma HLS STREAM variable=v282 depth=32768 + hls::stream v283("fifo_11"); + #pragma HLS STREAM variable=v283 depth=8192 + hls::stream v284("fifo_12"); + #pragma HLS STREAM variable=v284 depth=8192 + float v285[64][128]; + hls::stream v286("fifo_13"); + #pragma HLS STREAM variable=v286 depth=8192 + hls::stream v287("fifo_14"); + #pragma HLS STREAM variable=v287 depth=16384 + float v288[64][128]; + hls::stream v289("fifo_15"); + #pragma HLS STREAM variable=v289 depth=8192 + hls::stream v290("fifo_16"); + #pragma HLS STREAM variable=v290 depth=16384 + float v291[64][128]; + hls::stream v292("fifo_17"); + #pragma HLS STREAM variable=v292 depth=8192 + hls::stream v293("fifo_18"); + #pragma HLS STREAM variable=v293 depth=16384 + hls::stream v294("fifo_19"); + #pragma HLS STREAM variable=v294 depth=8192 + hls::stream v295("fifo_20"); + #pragma HLS STREAM variable=v295 depth=8192 + hls::stream v296("fifo_21"); + #pragma HLS STREAM variable=v296 depth=8192 + node25(v258, v296, v295, v294); + node24(v260, v293); + node23(v293, v294, v292, 0.000000); + node22(v292, v259, v291); + node21(v262, v290); + node20(v295, v290, v289, 0.000000); + node19(v289, v261, v288); + node18(v264, v287); + node17(v287, v296, v286, 0.000000); + node16(v286, v263, v285); + node15(v291, v284); + node14(v288, v283); + node13(v283, v284, v282, 0.000000); + node12(v282, v281, v280, 4.000000); + node11(v281, v279, -INFINITY); + node10(v280, v279, v278, v277); + node9(v278, v276, 0.000000); + node8(v277, v276, v275); + node7(v285, v274); + node6(v275, v274, v273, 0.000000); + node5(v273, v272); + node4(v272, v271); + node3(v266, v270); + node2(v271, v270, v269, 0.000000); + node1(v269, v265, v268); + node0(v268, v267); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..71ca54aa4df7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt3/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,1107 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[8][8], + float v1[1][64][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 8; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 8; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 8))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[8][8], + float v8[128], + hls::stream v9[8][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 8; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 8; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[8][2], + float v18[128][128], + hls::stream v19[8][8], + float v20 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=8 + + float v21[64][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[128][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[64][128]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=2 + + loop8: for (int v24 = 0; v24 < 8; v24++) { + loop9: for (int v25 = 0; v25 < 16; v25++) { + loop10: for (int v26 = 0; v26 < 64; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 8; v27++) { + loop12: for (int v28 = 0; v28 < 8; v28++) { + loop13: for (int v29 = 0; v29 < 2; v29++) { + if ((v28 + (v25 * 8)) == 0) { + float v30 = v17[v27][v29].read(); + v23[(v27 + (v24 * 8))][(v29 + (v26 * 2))] = v30; + } + float v31 = v23[(v27 + (v24 * 8))][(v29 + (v26 * 2))]; + if ((v27 + (v24 * 8)) == 0) { + float v32 = v18[(v29 + (v26 * 2))][(v28 + (v25 * 8))]; + v22[(v29 + (v26 * 2))][(v28 + (v25 * 8))] = v32; + } + float v33 = v22[(v29 + (v26 * 2))][(v28 + (v25 * 8))]; + if ((v29 + (v26 * 2)) == 0) { + v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))] = v36; + if (((v29 + (v26 * 2)) - 127) == 0) { + float v37 = v21[(v27 + (v24 * 8))][(v28 + (v25 * 8))]; + v19[v27][v28].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][128], + float v39[128][128] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=8 + + loop14: for (int v40 = 0; v40 < 64; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 2; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 2))]; + v39[(v42 + (v40 * 2))][(v43 + (v41 * 8))] = v44; + } + } + } + } + return ; +} + +void node4( + float v45[64][8][16], + hls::stream v46[8][2] +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=3 factor=2 + + loop18: for (int v47 = 0; v47 < 8; v47++) { + loop19: for (int v48 = 0; v48 < 64; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v49 = 0; v49 < 8; v49++) { + loop21: for (int v50 = 0; v50 < 2; v50++) { + float v51 = v45[(v49 + (v47 * 8))][(v48 / 8)][((v50 + (v48 * 2)) % 16)]; + v46[v49][v50].write(v51); + } + } + } + } + return ; +} + +void node5( + float v52[8][64][16], + float v53[64][8][16] +) { + #pragma HLS array_partition variable=v52 complete dim=1 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=3 factor=2 + + loop22: for (int v54 = 0; v54 < 4; v54++) { + loop23: for (int v55 = 0; v55 < 8; v55++) { + loop24: for (int v56 = 0; v56 < 8; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v57 = 0; v57 < 2; v57++) { + loop26: for (int v58 = 0; v58 < 8; v58++) { + loop27: for (int v59 = 0; v59 < 2; v59++) { + float v60 = v52[(v57 + (v54 * 2))][(v58 + (v55 * 8))][(v59 + (v56 * 2))]; + v53[(v58 + (v55 * 8))][(v57 + (v54 * 2))][(v59 + (v56 * 2))] = v60; + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v61[8][2][2], + float v62[8][64][16], + float v63[8][64][16], + float v64 +) { + #pragma HLS array_partition variable=v62 complete dim=1 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v63 complete dim=1 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=3 factor=2 + + float v65[8][64][16]; + #pragma HLS array_partition variable=v65 complete dim=1 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v65 cyclic dim=3 factor=2 + + float v66[8][64][16]; + #pragma HLS array_partition variable=v66 complete dim=1 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v66 cyclic dim=3 factor=2 + + float v67[8][64][64]; + #pragma HLS array_partition variable=v67 complete dim=1 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=3 factor=2 + + loop28: for (int v68 = 0; v68 < 1; v68++) { + loop29: for (int v69 = 0; v69 < 32; v69++) { + loop30: for (int v70 = 0; v70 < 8; v70++) { + loop31: for (int v71 = 0; v71 < 32; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop32: for (int v72 = 0; v72 < 8; v72++) { + loop33: for (int v73 = 0; v73 < 2; v73++) { + loop34: for (int v74 = 0; v74 < 2; v74++) { + loop35: for (int v75 = 0; v75 < 2; v75++) { + if ((v74 + (v70 * 2)) == 0) { + float v76 = v61[v72][v73][v75].read(); + v67[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))] = v76; + } + float v77 = v67[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))]; + if ((v73 + (v69 * 2)) == 0) { + float v78 = v62[(v72 + (v68 * 8))][(v75 + (v71 * 2))][(v74 + (v70 * 2))]; + v66[(v72 + (v68 * 8))][(v75 + (v71 * 2))][(v74 + (v70 * 2))] = v78; + } + float v79 = v66[(v72 + (v68 * 8))][(v75 + (v71 * 2))][(v74 + (v70 * 2))]; + if ((v75 + (v71 * 2)) == 0) { + v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))] = v64; + } + float v80 = v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))]; + float v81 = v77 * v79; + float v82 = v80 + v81; + v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))] = v82; + if (((v75 + (v71 * 2)) - 63) == 0) { + float v83 = v65[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))]; + v63[(v72 + (v68 * 8))][(v73 + (v69 * 2))][(v74 + (v70 * 2))] = v83; + } + } + } + } + } + } + } + } + } + return ; +} + +void node7( + float v84[64][128], + float v85[8][64][16] +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v85 complete dim=1 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=3 factor=2 + + loop36: for (int v86 = 0; v86 < 1; v86++) { + loop37: for (int v87 = 0; v87 < 32; v87++) { + loop38: for (int v88 = 0; v88 < 8; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v89 = 0; v89 < 8; v89++) { + loop40: for (int v90 = 0; v90 < 2; v90++) { + loop41: for (int v91 = 0; v91 < 2; v91++) { + float v92 = v84[(v90 + (v87 * 2))][((((v89 * 16) + (v86 * 128)) + v91) + (v88 * 2))]; + v85[(v89 + (v86 * 8))][(v90 + (v87 * 2))][(v91 + (v88 * 2))] = v92; + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v93[8][2][2], + hls::stream v94[8][2], + hls::stream v95[8][2][2] +) { + float v96[8][64]; + #pragma HLS array_partition variable=v96 complete dim=1 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=2 + + loop42: for (int v97 = 0; v97 < 1; v97++) { + loop43: for (int v98 = 0; v98 < 32; v98++) { + loop44: for (int v99 = 0; v99 < 32; v99++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop45: for (int v100 = 0; v100 < 8; v100++) { + loop46: for (int v101 = 0; v101 < 2; v101++) { + loop47: for (int v102 = 0; v102 < 2; v102++) { + float v103 = v93[v100][v101][v102].read(); + if ((v102 + (v99 * 2)) == 0) { + float v104 = v94[v100][v101].read(); + v96[(v100 + (v97 * 8))][(v101 + (v98 * 2))] = v104; + } + float v105 = v96[(v100 + (v97 * 8))][(v101 + (v98 * 2))]; + float v106 = v103 / v105; + v95[v100][v101][v102].write(v106); + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v107[8][2][2], + hls::stream v108[8][2], + float v109 +) { + float v110[8][64]; + #pragma HLS array_partition variable=v110 complete dim=1 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=2 + + loop48: for (int v111 = 0; v111 < 1; v111++) { + loop49: for (int v112 = 0; v112 < 32; v112++) { + loop50: for (int v113 = 0; v113 < 32; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v114 = 0; v114 < 8; v114++) { + loop52: for (int v115 = 0; v115 < 2; v115++) { + loop53: for (int v116 = 0; v116 < 2; v116++) { + float v117 = v107[v114][v115][v116].read(); + if ((v116 + (v113 * 2)) == 0) { + v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))] = v109; + } + float v118 = v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))]; + float v119 = v117 + v118; + v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))] = v119; + if (((v116 + (v113 * 2)) - 63) == 0) { + float v120 = v110[(v114 + (v111 * 8))][(v115 + (v112 * 2))]; + v108[v114][v115].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v121[8][2][2], + hls::stream v122[8][2], + hls::stream v123[8][2][2], + hls::stream v124[8][2][2] +) { + float v125[8][64]; + #pragma HLS array_partition variable=v125 complete dim=1 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=2 + + loop54: for (int v126 = 0; v126 < 1; v126++) { + loop55: for (int v127 = 0; v127 < 32; v127++) { + loop56: for (int v128 = 0; v128 < 32; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v129 = 0; v129 < 8; v129++) { + loop58: for (int v130 = 0; v130 < 2; v130++) { + loop59: for (int v131 = 0; v131 < 2; v131++) { + float v132 = v121[v129][v130][v131].read(); + if ((v131 + (v128 * 2)) == 0) { + float v133 = v122[v129][v130].read(); + v125[(v129 + (v126 * 8))][(v130 + (v127 * 2))] = v133; + } + float v134 = v125[(v129 + (v126 * 8))][(v130 + (v127 * 2))]; + float v135 = v132 - v134; + float v136 = exp(v135); + v123[v129][v130][v131].write(v136); + v124[v129][v130][v131].write(v136); + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v137[8][2][2], + hls::stream v138[8][2], + float v139 +) { + float v140[8][64]; + #pragma HLS array_partition variable=v140 complete dim=1 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=2 + + loop60: for (int v141 = 0; v141 < 1; v141++) { + loop61: for (int v142 = 0; v142 < 32; v142++) { + loop62: for (int v143 = 0; v143 < 32; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v144 = 0; v144 < 8; v144++) { + loop64: for (int v145 = 0; v145 < 2; v145++) { + loop65: for (int v146 = 0; v146 < 2; v146++) { + float v147 = v137[v144][v145][v146].read(); + if ((v146 + (v143 * 2)) == 0) { + v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))] = v139; + } + float v148 = v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))]; + float v149 = fmax(v147, v148); + v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))] = v149; + if (((v146 + (v143 * 2)) - 63) == 0) { + float v150 = v140[(v144 + (v141 * 8))][(v145 + (v142 * 2))]; + v138[v144][v145].write(v150); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v151[8][2][2], + hls::stream v152[8][2][2], + hls::stream v153[8][2][2], + float v154 +) { + loop66: for (int v155 = 0; v155 < 1; v155++) { + loop67: for (int v156 = 0; v156 < 32; v156++) { + loop68: for (int v157 = 0; v157 < 32; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop69: for (int v158 = 0; v158 < 8; v158++) { + loop70: for (int v159 = 0; v159 < 2; v159++) { + loop71: for (int v160 = 0; v160 < 2; v160++) { + float v161 = v151[v158][v159][v160].read(); + float v162 = v161 / v154; + v152[v158][v159][v160].write(v162); + v153[v158][v159][v160].write(v162); + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v163[8][2][2], + float v164[8][16][64], + hls::stream v165[8][2][2], + float v166 +) { + #pragma HLS array_partition variable=v164 complete dim=1 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v164 cyclic dim=3 factor=2 + + float v167[8][64][64]; + #pragma HLS array_partition variable=v167 complete dim=1 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v167 cyclic dim=3 factor=2 + + float v168[8][16][64]; + #pragma HLS array_partition variable=v168 complete dim=1 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=3 factor=2 + + float v169[8][64][16]; + #pragma HLS array_partition variable=v169 complete dim=1 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=3 factor=2 + + loop72: for (int v170 = 0; v170 < 1; v170++) { + loop73: for (int v171 = 0; v171 < 32; v171++) { + loop74: for (int v172 = 0; v172 < 32; v172++) { + loop75: for (int v173 = 0; v173 < 8; v173++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v174 = 0; v174 < 8; v174++) { + loop77: for (int v175 = 0; v175 < 2; v175++) { + loop78: for (int v176 = 0; v176 < 2; v176++) { + loop79: for (int v177 = 0; v177 < 2; v177++) { + if ((v176 + (v172 * 2)) == 0) { + float v178 = v163[v174][v175][v177].read(); + v169[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v177 + (v173 * 2))] = v178; + } + float v179 = v169[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v177 + (v173 * 2))]; + if ((v175 + (v171 * 2)) == 0) { + float v180 = v164[(v174 + (v170 * 8))][(v177 + (v173 * 2))][(v176 + (v172 * 2))]; + v168[(v174 + (v170 * 8))][(v177 + (v173 * 2))][(v176 + (v172 * 2))] = v180; + } + float v181 = v168[(v174 + (v170 * 8))][(v177 + (v173 * 2))][(v176 + (v172 * 2))]; + if ((v177 + (v173 * 2)) == 0) { + v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))] = v166; + } + float v182 = v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))]; + float v183 = v179 * v181; + float v184 = v182 + v183; + v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))] = v184; + if (((v177 + (v173 * 2)) - 15) == 0) { + float v185 = v167[(v174 + (v170 * 8))][(v175 + (v171 * 2))][(v176 + (v172 * 2))]; + v165[v174][v175][v176].write(v185); + } + } + } + } + } + } + } + } + } + return ; +} + +void node14( + float v186[64][128], + float v187[8][16][64] +) { + #pragma HLS array_partition variable=v186 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v186 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v187 complete dim=1 + #pragma HLS array_partition variable=v187 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v187 cyclic dim=3 factor=2 + + loop80: for (int v188 = 0; v188 < 1; v188++) { + loop81: for (int v189 = 0; v189 < 8; v189++) { + loop82: for (int v190 = 0; v190 < 32; v190++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v191 = 0; v191 < 8; v191++) { + loop84: for (int v192 = 0; v192 < 2; v192++) { + loop85: for (int v193 = 0; v193 < 2; v193++) { + float v194 = v186[(v193 + (v190 * 2))][((((v191 * 16) + (v188 * 128)) + v192) + (v189 * 2))]; + v187[(v191 + (v188 * 8))][(v192 + (v189 * 2))][(v193 + (v190 * 2))] = v194; + } + } + } + } + } + } + return ; +} + +void node15( + float v195[64][128], + hls::stream v196[8][2][2] +) { + #pragma HLS array_partition variable=v195 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v195 cyclic dim=2 factor=8 + + loop86: for (int v197 = 0; v197 < 1; v197++) { + loop87: for (int v198 = 0; v198 < 32; v198++) { + loop88: for (int v199 = 0; v199 < 8; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v200 = 0; v200 < 8; v200++) { + loop90: for (int v201 = 0; v201 < 2; v201++) { + loop91: for (int v202 = 0; v202 < 2; v202++) { + float v203 = v195[(v201 + (v198 * 2))][((((v200 * 16) + (v197 * 128)) + v202) + (v199 * 2))]; + v196[v200][v201][v202].write(v203); + } + } + } + } + } + } + return ; +} + +void node16( + hls::stream v204[2][8], + float v205[128], + float v206[64][128] +) { + #pragma HLS array_partition variable=v205 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=8 + + loop92: for (int v207 = 0; v207 < 32; v207++) { + loop93: for (int v208 = 0; v208 < 16; v208++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop94: for (int v209 = 0; v209 < 2; v209++) { + loop95: for (int v210 = 0; v210 < 8; v210++) { + float v211 = v204[v209][v210].read(); + float v212 = v205[(v210 + (v208 * 8))]; + float v213 = v211 + v212; + v206[(v209 + (v207 * 2))][(v210 + (v208 * 8))] = v213; + } + } + } + } + return ; +} + +void node17( + hls::stream v214[2][4], + float v215[128][128], + hls::stream v216[2][8], + float v217 +) { + #pragma HLS array_partition variable=v215 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v215 cyclic dim=2 factor=8 + + float v218[64][128]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=8 + + float v219[128][128]; + #pragma HLS array_partition variable=v219 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v219 cyclic dim=2 factor=8 + + float v220[64][128]; + #pragma HLS array_partition variable=v220 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v220 cyclic dim=2 factor=4 + + loop96: for (int v221 = 0; v221 < 32; v221++) { + loop97: for (int v222 = 0; v222 < 16; v222++) { + loop98: for (int v223 = 0; v223 < 32; v223++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop99: for (int v224 = 0; v224 < 2; v224++) { + loop100: for (int v225 = 0; v225 < 8; v225++) { + loop101: for (int v226 = 0; v226 < 4; v226++) { + if ((v225 + (v222 * 8)) == 0) { + float v227 = v214[v224][v226].read(); + v220[(v224 + (v221 * 2))][(v226 + (v223 * 4))] = v227; + } + float v228 = v220[(v224 + (v221 * 2))][(v226 + (v223 * 4))]; + if ((v224 + (v221 * 2)) == 0) { + float v229 = v215[(v226 + (v223 * 4))][(v225 + (v222 * 8))]; + v219[(v226 + (v223 * 4))][(v225 + (v222 * 8))] = v229; + } + float v230 = v219[(v226 + (v223 * 4))][(v225 + (v222 * 8))]; + if ((v226 + (v223 * 4)) == 0) { + v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))] = v217; + } + float v231 = v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))]; + float v232 = v228 * v230; + float v233 = v231 + v232; + v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))] = v233; + if (((v226 + (v223 * 4)) - 127) == 0) { + float v234 = v218[(v224 + (v221 * 2))][(v225 + (v222 * 8))]; + v216[v224][v225].write(v234); + } + } + } + } + } + } + } + return ; +} + +void node18( + float v235[128][128], + float v236[128][128] +) { + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v236 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v236 cyclic dim=2 factor=8 + + loop102: for (int v237 = 0; v237 < 32; v237++) { + loop103: for (int v238 = 0; v238 < 16; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop104: for (int v239 = 0; v239 < 4; v239++) { + loop105: for (int v240 = 0; v240 < 8; v240++) { + float v241 = v235[(v240 + (v238 * 8))][(v239 + (v237 * 4))]; + v236[(v239 + (v237 * 4))][(v240 + (v238 * 8))] = v241; + } + } + } + } + return ; +} + +void node19( + hls::stream v242[2][8], + float v243[128], + float v244[64][128] +) { + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=8 + + loop106: for (int v245 = 0; v245 < 32; v245++) { + loop107: for (int v246 = 0; v246 < 16; v246++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop108: for (int v247 = 0; v247 < 2; v247++) { + loop109: for (int v248 = 0; v248 < 8; v248++) { + float v249 = v242[v247][v248].read(); + float v250 = v243[(v248 + (v246 * 8))]; + float v251 = v249 + v250; + v244[(v247 + (v245 * 2))][(v248 + (v246 * 8))] = v251; + } + } + } + } + return ; +} + +void node20( + float v252[128][128], + hls::stream v253[2][4], + hls::stream v254[2][8], + float v255 +) { + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=8 + + float v256[64][128]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=8 + + float v257[128][128]; + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v257 cyclic dim=2 factor=8 + + float v258[64][128]; + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=4 + + loop110: for (int v259 = 0; v259 < 32; v259++) { + loop111: for (int v260 = 0; v260 < 16; v260++) { + loop112: for (int v261 = 0; v261 < 32; v261++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop113: for (int v262 = 0; v262 < 2; v262++) { + loop114: for (int v263 = 0; v263 < 8; v263++) { + loop115: for (int v264 = 0; v264 < 4; v264++) { + if ((v263 + (v260 * 8)) == 0) { + float v265 = v253[v262][v264].read(); + v258[(v262 + (v259 * 2))][(v264 + (v261 * 4))] = v265; + } + float v266 = v258[(v262 + (v259 * 2))][(v264 + (v261 * 4))]; + if ((v262 + (v259 * 2)) == 0) { + float v267 = v252[(v264 + (v261 * 4))][(v263 + (v260 * 8))]; + v257[(v264 + (v261 * 4))][(v263 + (v260 * 8))] = v267; + } + float v268 = v257[(v264 + (v261 * 4))][(v263 + (v260 * 8))]; + if ((v264 + (v261 * 4)) == 0) { + v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))] = v255; + } + float v269 = v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))]; + float v270 = v266 * v268; + float v271 = v269 + v270; + v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))] = v271; + if (((v264 + (v261 * 4)) - 127) == 0) { + float v272 = v256[(v262 + (v259 * 2))][(v263 + (v260 * 8))]; + v254[v262][v263].write(v272); + } + } + } + } + } + } + } + return ; +} + +void node21( + float v273[128][128], + float v274[128][128] +) { + #pragma HLS array_partition variable=v273 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v273 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v274 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v274 cyclic dim=2 factor=8 + + loop116: for (int v275 = 0; v275 < 32; v275++) { + loop117: for (int v276 = 0; v276 < 16; v276++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop118: for (int v277 = 0; v277 < 4; v277++) { + loop119: for (int v278 = 0; v278 < 8; v278++) { + float v279 = v273[(v278 + (v276 * 8))][(v277 + (v275 * 4))]; + v274[(v277 + (v275 * 4))][(v278 + (v276 * 8))] = v279; + } + } + } + } + return ; +} + +void node22( + hls::stream v280[2][8], + float v281[128], + float v282[64][128] +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=8 + + loop120: for (int v283 = 0; v283 < 32; v283++) { + loop121: for (int v284 = 0; v284 < 16; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop122: for (int v285 = 0; v285 < 2; v285++) { + loop123: for (int v286 = 0; v286 < 8; v286++) { + float v287 = v280[v285][v286].read(); + float v288 = v281[(v286 + (v284 * 8))]; + float v289 = v287 + v288; + v282[(v285 + (v283 * 2))][(v286 + (v284 * 8))] = v289; + } + } + } + } + return ; +} + +void node23( + float v290[128][128], + hls::stream v291[2][4], + hls::stream v292[2][8], + float v293 +) { + #pragma HLS array_partition variable=v290 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v290 cyclic dim=2 factor=8 + + float v294[64][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=8 + + float v295[128][128]; + #pragma HLS array_partition variable=v295 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v295 cyclic dim=2 factor=8 + + float v296[64][128]; + #pragma HLS array_partition variable=v296 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v296 cyclic dim=2 factor=4 + + loop124: for (int v297 = 0; v297 < 32; v297++) { + loop125: for (int v298 = 0; v298 < 16; v298++) { + loop126: for (int v299 = 0; v299 < 32; v299++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop127: for (int v300 = 0; v300 < 2; v300++) { + loop128: for (int v301 = 0; v301 < 8; v301++) { + loop129: for (int v302 = 0; v302 < 4; v302++) { + if ((v301 + (v298 * 8)) == 0) { + float v303 = v291[v300][v302].read(); + v296[(v300 + (v297 * 2))][(v302 + (v299 * 4))] = v303; + } + float v304 = v296[(v300 + (v297 * 2))][(v302 + (v299 * 4))]; + if ((v300 + (v297 * 2)) == 0) { + float v305 = v290[(v302 + (v299 * 4))][(v301 + (v298 * 8))]; + v295[(v302 + (v299 * 4))][(v301 + (v298 * 8))] = v305; + } + float v306 = v295[(v302 + (v299 * 4))][(v301 + (v298 * 8))]; + if ((v302 + (v299 * 4)) == 0) { + v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))] = v293; + } + float v307 = v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))]; + float v308 = v304 * v306; + float v309 = v307 + v308; + v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))] = v309; + if (((v302 + (v299 * 4)) - 127) == 0) { + float v310 = v294[(v300 + (v297 * 2))][(v301 + (v298 * 8))]; + v292[v300][v301].write(v310); + } + } + } + } + } + } + } + return ; +} + +void node24( + float v311[128][128], + float v312[128][128] +) { + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v312 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v312 cyclic dim=2 factor=8 + + loop130: for (int v313 = 0; v313 < 32; v313++) { + loop131: for (int v314 = 0; v314 < 16; v314++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop132: for (int v315 = 0; v315 < 4; v315++) { + loop133: for (int v316 = 0; v316 < 8; v316++) { + float v317 = v311[(v316 + (v314 * 8))][(v315 + (v313 * 4))]; + v312[(v315 + (v313 * 4))][(v316 + (v314 * 8))] = v317; + } + } + } + } + return ; +} + +void node25( + float v318[1][64][128], + hls::stream v319[2][4], + hls::stream v320[2][4], + hls::stream v321[2][4] +) { + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v318 cyclic dim=3 factor=4 + + loop134: for (int v322 = 0; v322 < 32; v322++) { + loop135: for (int v323 = 0; v323 < 32; v323++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v324 = 0; v324 < 2; v324++) { + loop137: for (int v325 = 0; v325 < 4; v325++) { + float v326 = v318[0][(v324 + (v322 * 2))][(v325 + (v323 * 4))]; + v319[v324][v325].write(v326); + v320[v324][v325].write(v326); + v321[v324][v325].write(v326); + } + } + } + } + return ; +} + +void forward( + float v327[1][64][128], + float v328[128], + float v329[128][128], + float v330[128], + float v331[128][128], + float v332[128], + float v333[128][128], + float v334[128], + float v335[128][128], + float v336[1][64][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v327 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v327 cyclic dim=3 factor=4 + + #pragma HLS array_partition variable=v328 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v329 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v329 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v330 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v331 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v331 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v332 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v333 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v333 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v334 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v335 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v335 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v336 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v336 cyclic dim=3 factor=8 + + hls::stream v337[8][8]; + #pragma HLS STREAM variable=v337 depth=128 + hls::stream v338[8][8]; + #pragma HLS STREAM variable=v338 depth=128 + float v339[128][128]; + #pragma HLS array_partition variable=v339 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v339 cyclic dim=2 factor=8 + + hls::stream v340[8][2]; + #pragma HLS STREAM variable=v340 depth=512 + float v341[64][8][16]; + #pragma HLS array_partition variable=v341 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v341 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=3 factor=2 + + float v342[8][64][16]; + #pragma HLS array_partition variable=v342 complete dim=1 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=3 factor=2 + + float v343[8][64][16]; + #pragma HLS array_partition variable=v343 complete dim=1 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=3 factor=2 + + hls::stream v344[8][2][2]; + #pragma HLS STREAM variable=v344 depth=1024 + hls::stream v345[8][2]; + #pragma HLS STREAM variable=v345 depth=32 + hls::stream v346[8][2][2]; + #pragma HLS STREAM variable=v346 depth=1024 + hls::stream v347[8][2][2]; + #pragma HLS STREAM variable=v347 depth=1024 + hls::stream v348[8][2]; + #pragma HLS STREAM variable=v348 depth=32 + hls::stream v349[8][2][2]; + #pragma HLS STREAM variable=v349 depth=1024 + hls::stream v350[8][2][2]; + #pragma HLS STREAM variable=v350 depth=1024 + hls::stream v351[8][2][2]; + #pragma HLS STREAM variable=v351 depth=1024 + float v352[8][16][64]; + #pragma HLS array_partition variable=v352 complete dim=1 + #pragma HLS array_partition variable=v352 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v352 cyclic dim=3 factor=2 + + hls::stream v353[8][2][2]; + #pragma HLS STREAM variable=v353 depth=256 + float v354[64][128]; + #pragma HLS array_partition variable=v354 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v354 cyclic dim=2 factor=8 + + hls::stream v355[2][8]; + #pragma HLS STREAM variable=v355 depth=512 + float v356[128][128]; + #pragma HLS array_partition variable=v356 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v356 cyclic dim=2 factor=8 + + float v357[64][128]; + #pragma HLS array_partition variable=v357 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v357 cyclic dim=2 factor=8 + + hls::stream v358[2][8]; + #pragma HLS STREAM variable=v358 depth=512 + float v359[128][128]; + #pragma HLS array_partition variable=v359 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v359 cyclic dim=2 factor=8 + + float v360[64][128]; + #pragma HLS array_partition variable=v360 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v360 cyclic dim=2 factor=8 + + hls::stream v361[2][8]; + #pragma HLS STREAM variable=v361 depth=512 + float v362[128][128]; + #pragma HLS array_partition variable=v362 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v362 cyclic dim=2 factor=8 + + hls::stream v363[2][4]; + #pragma HLS STREAM variable=v363 depth=1024 + hls::stream v364[2][4]; + #pragma HLS STREAM variable=v364 depth=1024 + hls::stream v365[2][4]; + #pragma HLS STREAM variable=v365 depth=1024 + node25(v327, v365, v364, v363); + node24(v329, v362); + node23(v362, v363, v361, 0.000000); + node22(v361, v328, v360); + node21(v331, v359); + node20(v359, v364, v358, 0.000000); + node19(v358, v330, v357); + node18(v333, v356); + node17(v365, v356, v355, 0.000000); + node16(v355, v332, v354); + node15(v360, v353); + node14(v357, v352); + node13(v353, v352, v351, 0.000000); + node12(v351, v350, v349, 4.000000); + node11(v350, v348, -INFINITY); + node10(v349, v348, v347, v346); + node9(v347, v345, 0.000000); + node8(v346, v345, v344); + node7(v354, v343); + node6(v344, v343, v342, 0.000000); + node5(v342, v341); + node4(v341, v340); + node3(v335, v339); + node2(v340, v339, v338, 0.000000); + node1(v338, v334, v337); + node0(v337, v336); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..76d359640c8d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt4/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,1064 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][32], + float v1[1][64][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=32 + + loop0: for (int v2 = 0; v2 < 4; v2++) { + loop1: for (int v3 = 0; v3 < 32; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 32; v4++) { + loop3: for (int v5 = 0; v5 < 2; v5++) { + float v6 = v0[v5][v4].read(); + v1[0][(v5 + (v3 * 2))][(v4 + (v2 * 32))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][32], + float v8[128], + hls::stream v9[2][32] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=32 + + loop4: for (int v10 = 0; v10 < 4; v10++) { + loop5: for (int v11 = 0; v11 < 32; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 32; v12++) { + loop7: for (int v13 = 0; v13 < 2; v13++) { + float v14 = v7[v13][v12].read(); + float v15 = v8[(v12 + (v10 * 32))]; + float v16 = v14 + v15; + v9[v13][v12].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[2][32], + hls::stream v18[2][2], + hls::stream v19[2][32], + float v20 +) { + float v21[64][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=32 + + float v22[128][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=32 + + float v23[64][128]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=2 + + loop8: for (int v24 = 0; v24 < 4; v24++) { + loop9: for (int v25 = 0; v25 < 64; v25++) { + loop10: for (int v26 = 0; v26 < 32; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 32; v27++) { + loop12: for (int v28 = 0; v28 < 2; v28++) { + loop13: for (int v29 = 0; v29 < 2; v29++) { + if ((v27 + (v24 * 32)) == 0) { + float v30 = v18[v29][v28].read(); + v23[(v29 + (v26 * 2))][(v28 + (v25 * 2))] = v30; + } + float v31 = v23[(v29 + (v26 * 2))][(v28 + (v25 * 2))]; + if ((v29 + (v26 * 2)) == 0) { + float v32 = v17[v28][v27].read(); + v22[(v28 + (v25 * 2))][(v27 + (v24 * 32))] = v32; + } + float v33 = v22[(v28 + (v25 * 2))][(v27 + (v24 * 32))]; + if ((v28 + (v25 * 2)) == 0) { + v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))] = v20; + } + float v34 = v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))] = v36; + if (((v28 + (v25 * 2)) - 127) == 0) { + float v37 = v21[(v29 + (v26 * 2))][(v27 + (v24 * 32))]; + v19[v29][v27].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][128], + hls::stream v39[2][32] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=2 + + loop14: for (int v40 = 0; v40 < 4; v40++) { + loop15: for (int v41 = 0; v41 < 64; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 32; v42++) { + loop17: for (int v43 = 0; v43 < 2; v43++) { + float v44 = v38[(v42 + (v40 * 32))][(v43 + (v41 * 2))]; + v39[v43][v42].write(v44); + } + } + } + } + return ; +} + +void node4( + float v45[64][8][16], + hls::stream v46[2][2] +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=3 factor=4 + + loop18: for (int v47 = 0; v47 < 64; v47++) { + loop19: for (int v48 = 0; v48 < 32; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v49 = 0; v49 < 2; v49++) { + loop21: for (int v50 = 0; v50 < 2; v50++) { + float v51 = v45[(v50 + (v48 * 2))][(v47 / 8)][((v49 + (v47 * 2)) % 16)]; + v46[v50][v49].write(v51); + } + } + } + } + return ; +} + +void node5( + float v52[8][64][16], + float v53[64][8][16] +) { + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v52 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=3 factor=4 + + loop22: for (int v54 = 0; v54 < 4; v54++) { + loop23: for (int v55 = 0; v55 < 32; v55++) { + loop24: for (int v56 = 0; v56 < 4; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v57 = 0; v57 < 2; v57++) { + loop26: for (int v58 = 0; v58 < 2; v58++) { + loop27: for (int v59 = 0; v59 < 4; v59++) { + float v60 = v52[(v57 + (v54 * 2))][(v58 + (v55 * 2))][(v59 + (v56 * 4))]; + v53[(v58 + (v55 * 2))][(v57 + (v54 * 2))][(v59 + (v56 * 4))] = v60; + } + } + } + } + } + } + return ; +} + +void node6( + float v61[8][64][16], + hls::stream v62[2][4][4], + float v63[8][64][16], + float v64 +) { + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v61 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v63 cyclic dim=3 factor=2 + + float v65[8][64][16]; + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v65 cyclic dim=3 factor=2 + + float v66[8][64][16]; + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v66 cyclic dim=3 factor=2 + + float v67[8][64][64]; + #pragma HLS array_partition variable=v67 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v67 cyclic dim=3 factor=4 + + loop28: for (int v68 = 0; v68 < 4; v68++) { + loop29: for (int v69 = 0; v69 < 16; v69++) { + loop30: for (int v70 = 0; v70 < 16; v70++) { + loop31: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop32: for (int v72 = 0; v72 < 2; v72++) { + loop33: for (int v73 = 0; v73 < 4; v73++) { + loop34: for (int v74 = 0; v74 < 4; v74++) { + loop35: for (int v75 = 0; v75 < 2; v75++) { + if ((v75 + (v71 * 2)) == 0) { + float v76 = v62[v72][v74][v73].read(); + v67[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v73 + (v69 * 4))] = v76; + } + float v77 = v67[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v73 + (v69 * 4))]; + if ((v74 + (v70 * 4)) == 0) { + float v78 = v61[(v72 + (v68 * 2))][(v73 + (v69 * 4))][(v75 + (v71 * 2))]; + v66[(v72 + (v68 * 2))][(v73 + (v69 * 4))][(v75 + (v71 * 2))] = v78; + } + float v79 = v66[(v72 + (v68 * 2))][(v73 + (v69 * 4))][(v75 + (v71 * 2))]; + if ((v73 + (v69 * 4)) == 0) { + v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))] = v64; + } + float v80 = v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))]; + float v81 = v77 * v79; + float v82 = v80 + v81; + v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))] = v82; + if (((v73 + (v69 * 4)) - 63) == 0) { + float v83 = v65[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))]; + v63[(v72 + (v68 * 2))][(v74 + (v70 * 4))][(v75 + (v71 * 2))] = v83; + } + } + } + } + } + } + } + } + } + return ; +} + +void node7( + float v84[64][128], + float v85[8][64][16] +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v85 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v85 cyclic dim=3 factor=2 + + loop36: for (int v86 = 0; v86 < 4; v86++) { + loop37: for (int v87 = 0; v87 < 8; v87++) { + loop38: for (int v88 = 0; v88 < 16; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v89 = 0; v89 < 2; v89++) { + loop40: for (int v90 = 0; v90 < 2; v90++) { + loop41: for (int v91 = 0; v91 < 4; v91++) { + float v92 = v84[(v91 + (v88 * 4))][((((v89 * 16) + (v86 * 32)) + v90) + (v87 * 2))]; + v85[(v89 + (v86 * 2))][(v91 + (v88 * 4))][(v90 + (v87 * 2))] = v92; + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v93[2][4][4], + hls::stream v94[2][4], + hls::stream v95[2][4][4] +) { + float v96[8][64]; + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=4 + + loop42: for (int v97 = 0; v97 < 4; v97++) { + loop43: for (int v98 = 0; v98 < 16; v98++) { + loop44: for (int v99 = 0; v99 < 16; v99++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop45: for (int v100 = 0; v100 < 2; v100++) { + loop46: for (int v101 = 0; v101 < 4; v101++) { + loop47: for (int v102 = 0; v102 < 4; v102++) { + float v103 = v93[v100][v102][v101].read(); + if ((v101 + (v98 * 4)) == 0) { + float v104 = v94[v100][v102].read(); + v96[(v100 + (v97 * 2))][(v102 + (v99 * 4))] = v104; + } + float v105 = v96[(v100 + (v97 * 2))][(v102 + (v99 * 4))]; + float v106 = v103 / v105; + v95[v100][v102][v101].write(v106); + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v107[2][4][4], + hls::stream v108[2][4], + float v109 +) { + float v110[8][64]; + #pragma HLS array_partition variable=v110 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=4 + + loop48: for (int v111 = 0; v111 < 4; v111++) { + loop49: for (int v112 = 0; v112 < 16; v112++) { + loop50: for (int v113 = 0; v113 < 16; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v114 = 0; v114 < 2; v114++) { + loop52: for (int v115 = 0; v115 < 4; v115++) { + loop53: for (int v116 = 0; v116 < 4; v116++) { + float v117 = v107[v114][v116][v115].read(); + if ((v115 + (v112 * 4)) == 0) { + v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))] = v109; + } + float v118 = v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))]; + float v119 = v117 + v118; + v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))] = v119; + if (((v115 + (v112 * 4)) - 63) == 0) { + float v120 = v110[(v114 + (v111 * 2))][(v116 + (v113 * 4))]; + v108[v114][v116].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v121[2][4][4], + hls::stream v122[2][4], + hls::stream v123[2][4][4], + hls::stream v124[2][4][4] +) { + float v125[8][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop54: for (int v126 = 0; v126 < 4; v126++) { + loop55: for (int v127 = 0; v127 < 16; v127++) { + loop56: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v129 = 0; v129 < 2; v129++) { + loop58: for (int v130 = 0; v130 < 4; v130++) { + loop59: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[v129][v131][v130].read(); + if ((v130 + (v127 * 4)) == 0) { + float v133 = v122[v129][v131].read(); + v125[(v129 + (v126 * 2))][(v131 + (v128 * 4))] = v133; + } + float v134 = v125[(v129 + (v126 * 2))][(v131 + (v128 * 4))]; + float v135 = v132 - v134; + float v136 = exp(v135); + v123[v129][v131][v130].write(v136); + v124[v129][v131][v130].write(v136); + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v137[2][4][4], + hls::stream v138[2][4], + float v139 +) { + float v140[8][64]; + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + loop60: for (int v141 = 0; v141 < 4; v141++) { + loop61: for (int v142 = 0; v142 < 16; v142++) { + loop62: for (int v143 = 0; v143 < 16; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v144 = 0; v144 < 2; v144++) { + loop64: for (int v145 = 0; v145 < 4; v145++) { + loop65: for (int v146 = 0; v146 < 4; v146++) { + float v147 = v137[v144][v146][v145].read(); + if ((v145 + (v142 * 4)) == 0) { + v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))] = v139; + } + float v148 = v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))]; + float v149 = fmax(v147, v148); + v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))] = v149; + if (((v145 + (v142 * 4)) - 63) == 0) { + float v150 = v140[(v144 + (v141 * 2))][(v146 + (v143 * 4))]; + v138[v144][v146].write(v150); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v151[2][4][4], + hls::stream v152[2][4][4], + hls::stream v153[2][4][4], + float v154 +) { + loop66: for (int v155 = 0; v155 < 4; v155++) { + loop67: for (int v156 = 0; v156 < 16; v156++) { + loop68: for (int v157 = 0; v157 < 16; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop69: for (int v158 = 0; v158 < 2; v158++) { + loop70: for (int v159 = 0; v159 < 4; v159++) { + loop71: for (int v160 = 0; v160 < 4; v160++) { + float v161 = v151[v158][v160][v159].read(); + float v162 = v161 / v154; + v152[v158][v160][v159].write(v162); + v153[v158][v160][v159].write(v162); + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v163[2][4][2], + hls::stream v164[2][2][4], + hls::stream v165[2][4][4], + float v166 +) { + float v167[8][64][64]; + #pragma HLS array_partition variable=v167 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v167 cyclic dim=3 factor=4 + + float v168[8][16][64]; + #pragma HLS array_partition variable=v168 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=3 factor=4 + + float v169[8][64][16]; + #pragma HLS array_partition variable=v169 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v169 cyclic dim=3 factor=2 + + loop72: for (int v170 = 0; v170 < 4; v170++) { + loop73: for (int v171 = 0; v171 < 8; v171++) { + loop74: for (int v172 = 0; v172 < 16; v172++) { + loop75: for (int v173 = 0; v173 < 16; v173++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v174 = 0; v174 < 2; v174++) { + loop77: for (int v175 = 0; v175 < 2; v175++) { + loop78: for (int v176 = 0; v176 < 4; v176++) { + loop79: for (int v177 = 0; v177 < 4; v177++) { + if ((v176 + (v172 * 4)) == 0) { + float v178 = v163[v174][v177][v175].read(); + v169[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v175 + (v171 * 2))] = v178; + } + float v179 = v169[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v175 + (v171 * 2))]; + if ((v177 + (v173 * 4)) == 0) { + float v180 = v164[v174][v175][v176].read(); + v168[(v174 + (v170 * 2))][(v175 + (v171 * 2))][(v176 + (v172 * 4))] = v180; + } + float v181 = v168[(v174 + (v170 * 2))][(v175 + (v171 * 2))][(v176 + (v172 * 4))]; + if ((v175 + (v171 * 2)) == 0) { + v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))] = v166; + } + float v182 = v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))]; + float v183 = v179 * v181; + float v184 = v182 + v183; + v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))] = v184; + if (((v175 + (v171 * 2)) - 15) == 0) { + float v185 = v167[(v174 + (v170 * 2))][(v177 + (v173 * 4))][(v176 + (v172 * 4))]; + v165[v174][v177][v176].write(v185); + } + } + } + } + } + } + } + } + } + return ; +} + +void node14( + float v186[64][128], + hls::stream v187[2][2][4] +) { + #pragma HLS array_partition variable=v186 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v186 cyclic dim=2 factor=2 + + loop80: for (int v188 = 0; v188 < 4; v188++) { + loop81: for (int v189 = 0; v189 < 8; v189++) { + loop82: for (int v190 = 0; v190 < 16; v190++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v191 = 0; v191 < 2; v191++) { + loop84: for (int v192 = 0; v192 < 2; v192++) { + loop85: for (int v193 = 0; v193 < 4; v193++) { + float v194 = v186[(v193 + (v190 * 4))][((((v191 * 16) + (v188 * 32)) + v192) + (v189 * 2))]; + v187[v191][v192][v193].write(v194); + } + } + } + } + } + } + return ; +} + +void node15( + float v195[64][128], + hls::stream v196[2][4][2] +) { + #pragma HLS array_partition variable=v195 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v195 cyclic dim=2 factor=2 + + loop86: for (int v197 = 0; v197 < 4; v197++) { + loop87: for (int v198 = 0; v198 < 8; v198++) { + loop88: for (int v199 = 0; v199 < 16; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v200 = 0; v200 < 2; v200++) { + loop90: for (int v201 = 0; v201 < 2; v201++) { + loop91: for (int v202 = 0; v202 < 4; v202++) { + float v203 = v195[(v202 + (v199 * 4))][((((v200 * 16) + (v197 * 32)) + v201) + (v198 * 2))]; + v196[v200][v202][v201].write(v203); + } + } + } + } + } + } + return ; +} + +void node16( + hls::stream v204[4][2], + float v205[128], + float v206[64][128] +) { + #pragma HLS array_partition variable=v205 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=2 + + loop92: for (int v207 = 0; v207 < 16; v207++) { + loop93: for (int v208 = 0; v208 < 64; v208++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop94: for (int v209 = 0; v209 < 4; v209++) { + loop95: for (int v210 = 0; v210 < 2; v210++) { + float v211 = v204[v209][v210].read(); + float v212 = v205[(v210 + (v208 * 2))]; + float v213 = v211 + v212; + v206[(v209 + (v207 * 4))][(v210 + (v208 * 2))] = v213; + } + } + } + } + return ; +} + +void node17( + hls::stream v214[8][2], + hls::stream v215[4][8], + hls::stream v216[4][2], + float v217 +) { + float v218[64][128]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=2 + + float v219[128][128]; + #pragma HLS array_partition variable=v219 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v219 cyclic dim=2 factor=2 + + float v220[64][128]; + #pragma HLS array_partition variable=v220 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v220 cyclic dim=2 factor=8 + + loop96: for (int v221 = 0; v221 < 16; v221++) { + loop97: for (int v222 = 0; v222 < 16; v222++) { + loop98: for (int v223 = 0; v223 < 64; v223++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop99: for (int v224 = 0; v224 < 4; v224++) { + loop100: for (int v225 = 0; v225 < 8; v225++) { + loop101: for (int v226 = 0; v226 < 2; v226++) { + if ((v226 + (v223 * 2)) == 0) { + float v227 = v215[v224][v225].read(); + v220[(v224 + (v221 * 4))][(v225 + (v222 * 8))] = v227; + } + float v228 = v220[(v224 + (v221 * 4))][(v225 + (v222 * 8))]; + if ((v224 + (v221 * 4)) == 0) { + float v229 = v214[v225][v226].read(); + v219[(v225 + (v222 * 8))][(v226 + (v223 * 2))] = v229; + } + float v230 = v219[(v225 + (v222 * 8))][(v226 + (v223 * 2))]; + if ((v225 + (v222 * 8)) == 0) { + v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))] = v217; + } + float v231 = v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))]; + float v232 = v228 * v230; + float v233 = v231 + v232; + v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))] = v233; + if (((v225 + (v222 * 8)) - 127) == 0) { + float v234 = v218[(v224 + (v221 * 4))][(v226 + (v223 * 2))]; + v216[v224][v226].write(v234); + } + } + } + } + } + } + } + return ; +} + +void node18( + float v235[128][128], + hls::stream v236[8][2] +) { + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=8 + + loop102: for (int v237 = 0; v237 < 16; v237++) { + loop103: for (int v238 = 0; v238 < 64; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop104: for (int v239 = 0; v239 < 8; v239++) { + loop105: for (int v240 = 0; v240 < 2; v240++) { + float v241 = v235[(v240 + (v238 * 2))][(v239 + (v237 * 8))]; + v236[v239][v240].write(v241); + } + } + } + } + return ; +} + +void node19( + hls::stream v242[4][2], + float v243[128], + float v244[64][128] +) { + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=2 + + loop106: for (int v245 = 0; v245 < 16; v245++) { + loop107: for (int v246 = 0; v246 < 64; v246++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop108: for (int v247 = 0; v247 < 4; v247++) { + loop109: for (int v248 = 0; v248 < 2; v248++) { + float v249 = v242[v247][v248].read(); + float v250 = v243[(v248 + (v246 * 2))]; + float v251 = v249 + v250; + v244[(v247 + (v245 * 4))][(v248 + (v246 * 2))] = v251; + } + } + } + } + return ; +} + +void node20( + hls::stream v252[8][2], + hls::stream v253[4][8], + hls::stream v254[4][2], + float v255 +) { + float v256[64][128]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=2 + + float v257[128][128]; + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v257 cyclic dim=2 factor=2 + + float v258[64][128]; + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=8 + + loop110: for (int v259 = 0; v259 < 16; v259++) { + loop111: for (int v260 = 0; v260 < 16; v260++) { + loop112: for (int v261 = 0; v261 < 64; v261++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop113: for (int v262 = 0; v262 < 4; v262++) { + loop114: for (int v263 = 0; v263 < 8; v263++) { + loop115: for (int v264 = 0; v264 < 2; v264++) { + if ((v264 + (v261 * 2)) == 0) { + float v265 = v253[v262][v263].read(); + v258[(v262 + (v259 * 4))][(v263 + (v260 * 8))] = v265; + } + float v266 = v258[(v262 + (v259 * 4))][(v263 + (v260 * 8))]; + if ((v262 + (v259 * 4)) == 0) { + float v267 = v252[v263][v264].read(); + v257[(v263 + (v260 * 8))][(v264 + (v261 * 2))] = v267; + } + float v268 = v257[(v263 + (v260 * 8))][(v264 + (v261 * 2))]; + if ((v263 + (v260 * 8)) == 0) { + v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))] = v255; + } + float v269 = v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))]; + float v270 = v266 * v268; + float v271 = v269 + v270; + v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))] = v271; + if (((v263 + (v260 * 8)) - 127) == 0) { + float v272 = v256[(v262 + (v259 * 4))][(v264 + (v261 * 2))]; + v254[v262][v264].write(v272); + } + } + } + } + } + } + } + return ; +} + +void node21( + float v273[128][128], + hls::stream v274[8][2] +) { + #pragma HLS array_partition variable=v273 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v273 cyclic dim=2 factor=8 + + loop116: for (int v275 = 0; v275 < 16; v275++) { + loop117: for (int v276 = 0; v276 < 64; v276++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop118: for (int v277 = 0; v277 < 8; v277++) { + loop119: for (int v278 = 0; v278 < 2; v278++) { + float v279 = v273[(v278 + (v276 * 2))][(v277 + (v275 * 8))]; + v274[v277][v278].write(v279); + } + } + } + } + return ; +} + +void node22( + hls::stream v280[4][2], + float v281[128], + float v282[64][128] +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=2 + + loop120: for (int v283 = 0; v283 < 16; v283++) { + loop121: for (int v284 = 0; v284 < 64; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop122: for (int v285 = 0; v285 < 4; v285++) { + loop123: for (int v286 = 0; v286 < 2; v286++) { + float v287 = v280[v285][v286].read(); + float v288 = v281[(v286 + (v284 * 2))]; + float v289 = v287 + v288; + v282[(v285 + (v283 * 4))][(v286 + (v284 * 2))] = v289; + } + } + } + } + return ; +} + +void node23( + hls::stream v290[8][2], + hls::stream v291[4][8], + hls::stream v292[4][2], + float v293 +) { + float v294[64][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=2 + + float v295[128][128]; + #pragma HLS array_partition variable=v295 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v295 cyclic dim=2 factor=2 + + float v296[64][128]; + #pragma HLS array_partition variable=v296 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v296 cyclic dim=2 factor=8 + + loop124: for (int v297 = 0; v297 < 16; v297++) { + loop125: for (int v298 = 0; v298 < 16; v298++) { + loop126: for (int v299 = 0; v299 < 64; v299++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop127: for (int v300 = 0; v300 < 4; v300++) { + loop128: for (int v301 = 0; v301 < 8; v301++) { + loop129: for (int v302 = 0; v302 < 2; v302++) { + if ((v302 + (v299 * 2)) == 0) { + float v303 = v291[v300][v301].read(); + v296[(v300 + (v297 * 4))][(v301 + (v298 * 8))] = v303; + } + float v304 = v296[(v300 + (v297 * 4))][(v301 + (v298 * 8))]; + if ((v300 + (v297 * 4)) == 0) { + float v305 = v290[v301][v302].read(); + v295[(v301 + (v298 * 8))][(v302 + (v299 * 2))] = v305; + } + float v306 = v295[(v301 + (v298 * 8))][(v302 + (v299 * 2))]; + if ((v301 + (v298 * 8)) == 0) { + v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))] = v293; + } + float v307 = v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))]; + float v308 = v304 * v306; + float v309 = v307 + v308; + v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))] = v309; + if (((v301 + (v298 * 8)) - 127) == 0) { + float v310 = v294[(v300 + (v297 * 4))][(v302 + (v299 * 2))]; + v292[v300][v302].write(v310); + } + } + } + } + } + } + } + return ; +} + +void node24( + float v311[128][128], + hls::stream v312[8][2] +) { + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=8 + + loop130: for (int v313 = 0; v313 < 16; v313++) { + loop131: for (int v314 = 0; v314 < 64; v314++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop132: for (int v315 = 0; v315 < 8; v315++) { + loop133: for (int v316 = 0; v316 < 2; v316++) { + float v317 = v311[(v316 + (v314 * 2))][(v315 + (v313 * 8))]; + v312[v315][v316].write(v317); + } + } + } + } + return ; +} + +void node25( + float v318[1][64][128], + hls::stream v319[4][8], + hls::stream v320[4][8], + hls::stream v321[4][8] +) { + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v318 cyclic dim=3 factor=8 + + loop134: for (int v322 = 0; v322 < 16; v322++) { + loop135: for (int v323 = 0; v323 < 16; v323++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v324 = 0; v324 < 4; v324++) { + loop137: for (int v325 = 0; v325 < 8; v325++) { + float v326 = v318[0][(v324 + (v322 * 4))][(v325 + (v323 * 8))]; + v319[v324][v325].write(v326); + v320[v324][v325].write(v326); + v321[v324][v325].write(v326); + } + } + } + } + return ; +} + +void forward( + float v327[1][64][128], + float v328[128], + float v329[128][128], + float v330[128], + float v331[128][128], + float v332[128], + float v333[128][128], + float v334[128], + float v335[128][128], + float v336[1][64][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v327 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v327 cyclic dim=3 factor=8 + + #pragma HLS array_partition variable=v328 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v329 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v329 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v330 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v331 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v331 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v332 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v333 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v333 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v334 cyclic dim=1 factor=32 + + #pragma HLS array_partition variable=v335 cyclic dim=1 factor=32 + #pragma HLS array_partition variable=v335 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v336 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v336 cyclic dim=3 factor=32 + + hls::stream v337[2][32]; + #pragma HLS STREAM variable=v337 depth=128 + hls::stream v338[2][32]; + #pragma HLS STREAM variable=v338 depth=128 + hls::stream v339[2][32]; + #pragma HLS STREAM variable=v339 depth=256 + hls::stream v340[2][2]; + #pragma HLS STREAM variable=v340 depth=2048 + float v341[64][8][16]; + #pragma HLS array_partition variable=v341 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=3 factor=4 + + float v342[8][64][16]; + #pragma HLS array_partition variable=v342 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v342 cyclic dim=3 factor=2 + + float v343[8][64][16]; + #pragma HLS array_partition variable=v343 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=4 + #pragma HLS array_partition variable=v343 cyclic dim=3 factor=2 + + hls::stream v344[2][4][4]; + #pragma HLS STREAM variable=v344 depth=1024 + hls::stream v345[2][4]; + #pragma HLS STREAM variable=v345 depth=64 + hls::stream v346[2][4][4]; + #pragma HLS STREAM variable=v346 depth=1024 + hls::stream v347[2][4][4]; + #pragma HLS STREAM variable=v347 depth=1024 + hls::stream v348[2][4]; + #pragma HLS STREAM variable=v348 depth=64 + hls::stream v349[2][4][4]; + #pragma HLS STREAM variable=v349 depth=1024 + hls::stream v350[2][4][4]; + #pragma HLS STREAM variable=v350 depth=1024 + hls::stream v351[2][4][4]; + #pragma HLS STREAM variable=v351 depth=1024 + hls::stream v352[2][2][4]; + #pragma HLS STREAM variable=v352 depth=512 + hls::stream v353[2][4][2]; + #pragma HLS STREAM variable=v353 depth=512 + float v354[64][128]; + #pragma HLS array_partition variable=v354 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v354 cyclic dim=2 factor=2 + + hls::stream v355[4][2]; + #pragma HLS STREAM variable=v355 depth=1024 + hls::stream v356[8][2]; + #pragma HLS STREAM variable=v356 depth=1024 + float v357[64][128]; + #pragma HLS array_partition variable=v357 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v357 cyclic dim=2 factor=2 + + hls::stream v358[4][2]; + #pragma HLS STREAM variable=v358 depth=1024 + hls::stream v359[8][2]; + #pragma HLS STREAM variable=v359 depth=1024 + float v360[64][128]; + #pragma HLS array_partition variable=v360 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v360 cyclic dim=2 factor=2 + + hls::stream v361[4][2]; + #pragma HLS STREAM variable=v361 depth=1024 + hls::stream v362[8][2]; + #pragma HLS STREAM variable=v362 depth=1024 + hls::stream v363[4][8]; + #pragma HLS STREAM variable=v363 depth=256 + hls::stream v364[4][8]; + #pragma HLS STREAM variable=v364 depth=256 + hls::stream v365[4][8]; + #pragma HLS STREAM variable=v365 depth=256 + node25(v327, v365, v364, v363); + node24(v329, v362); + node23(v362, v363, v361, 0.000000); + node22(v361, v328, v360); + node21(v331, v359); + node20(v359, v364, v358, 0.000000); + node19(v358, v330, v357); + node18(v333, v356); + node17(v356, v365, v355, 0.000000); + node16(v355, v332, v354); + node15(v360, v353); + node14(v357, v352); + node13(v353, v352, v351, 0.000000); + node12(v351, v350, v349, 4.000000); + node11(v350, v348, -INFINITY); + node10(v349, v348, v347, v346); + node9(v347, v345, 0.000000); + node8(v346, v345, v344); + node7(v354, v343); + node6(v343, v344, v342, 0.000000); + node5(v342, v341); + node4(v341, v340); + node3(v335, v339); + node2(v339, v340, v338, 0.000000); + node1(v338, v334, v337); + node0(v337, v336); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp new file mode 100644 index 000000000000..068e4e9f9ef8 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/MultiHeadSelfAttention1__opt5/src/MultiHeadSelfAttention1.cpp @@ -0,0 +1,1086 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[8][8], + float v1[1][64][128] +) { + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v1 cyclic dim=3 factor=8 + + loop0: for (int v2 = 0; v2 < 8; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 8; v4++) { + loop3: for (int v5 = 0; v5 < 8; v5++) { + float v6 = v0[v4][v5].read(); + v1[0][(v4 + (v2 * 8))][(v5 + (v3 * 8))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[8][8], + float v8[128], + hls::stream v9[8][8] +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=8 + + loop4: for (int v10 = 0; v10 < 8; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 8; v12++) { + loop7: for (int v13 = 0; v13 < 8; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v8[(v13 + (v11 * 8))]; + float v16 = v14 + v15; + v9[v12][v13].write(v16); + } + } + } + } + return ; +} + +void node2( + hls::stream v17[2][8], + hls::stream v18[8][2], + hls::stream v19[8][8], + float v20 +) { + float v21[64][128]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=8 + + float v22[128][128]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=8 + + float v23[64][128]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=2 + + loop8: for (int v24 = 0; v24 < 8; v24++) { + loop9: for (int v25 = 0; v25 < 64; v25++) { + loop10: for (int v26 = 0; v26 < 16; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 8; v27++) { + loop12: for (int v28 = 0; v28 < 2; v28++) { + loop13: for (int v29 = 0; v29 < 8; v29++) { + if ((v29 + (v26 * 8)) == 0) { + float v30 = v18[v27][v28].read(); + v23[(v27 + (v24 * 8))][(v28 + (v25 * 2))] = v30; + } + float v31 = v23[(v27 + (v24 * 8))][(v28 + (v25 * 2))]; + if ((v27 + (v24 * 8)) == 0) { + float v32 = v17[v28][v29].read(); + v22[(v28 + (v25 * 2))][(v29 + (v26 * 8))] = v32; + } + float v33 = v22[(v28 + (v25 * 2))][(v29 + (v26 * 8))]; + if ((v28 + (v25 * 2)) == 0) { + v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))] = v20; + } + float v34 = v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))]; + float v35 = v31 * v33; + float v36 = v34 + v35; + v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))] = v36; + if (((v28 + (v25 * 2)) - 127) == 0) { + float v37 = v21[(v27 + (v24 * 8))][(v29 + (v26 * 8))]; + v19[v27][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v38[128][128], + hls::stream v39[2][8] +) { + #pragma HLS array_partition variable=v38 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=2 + + loop14: for (int v40 = 0; v40 < 64; v40++) { + loop15: for (int v41 = 0; v41 < 16; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 2; v42++) { + loop17: for (int v43 = 0; v43 < 8; v43++) { + float v44 = v38[(v43 + (v41 * 8))][(v42 + (v40 * 2))]; + v39[v42][v43].write(v44); + } + } + } + } + return ; +} + +void node4( + float v45[64][8][16], + hls::stream v46[8][2] +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=3 factor=2 + + loop18: for (int v47 = 0; v47 < 8; v47++) { + loop19: for (int v48 = 0; v48 < 64; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v49 = 0; v49 < 8; v49++) { + loop21: for (int v50 = 0; v50 < 2; v50++) { + float v51 = v45[(v49 + (v47 * 8))][(v48 / 8)][((v50 + (v48 * 2)) % 16)]; + v46[v49][v50].write(v51); + } + } + } + } + return ; +} + +void node5( + float v52[8][64][16], + float v53[64][8][16] +) { + #pragma HLS array_partition variable=v52 complete dim=1 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=3 factor=2 + + loop22: for (int v54 = 0; v54 < 8; v54++) { + loop23: for (int v55 = 0; v55 < 4; v55++) { + loop24: for (int v56 = 0; v56 < 8; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v57 = 0; v57 < 8; v57++) { + loop26: for (int v58 = 0; v58 < 2; v58++) { + loop27: for (int v59 = 0; v59 < 2; v59++) { + float v60 = v52[(v58 + (v55 * 2))][(v57 + (v54 * 8))][(v59 + (v56 * 2))]; + v53[(v57 + (v54 * 8))][(v58 + (v55 * 2))][(v59 + (v56 * 2))] = v60; + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v61[8][2][2], + float v62[8][64][16], + float v63[8][64][16], + float v64 +) { + #pragma HLS array_partition variable=v62 complete dim=1 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v63 complete dim=1 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=3 factor=2 + + float v65[8][64][16]; + #pragma HLS array_partition variable=v65 complete dim=1 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v65 cyclic dim=3 factor=2 + + float v66[8][64][16]; + #pragma HLS array_partition variable=v66 complete dim=1 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v66 cyclic dim=3 factor=2 + + float v67[8][64][64]; + #pragma HLS array_partition variable=v67 complete dim=1 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=3 factor=2 + + loop28: for (int v68 = 0; v68 < 32; v68++) { + loop29: for (int v69 = 0; v69 < 32; v69++) { + loop30: for (int v70 = 0; v70 < 1; v70++) { + loop31: for (int v71 = 0; v71 < 8; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop32: for (int v72 = 0; v72 < 2; v72++) { + loop33: for (int v73 = 0; v73 < 2; v73++) { + loop34: for (int v74 = 0; v74 < 8; v74++) { + loop35: for (int v75 = 0; v75 < 2; v75++) { + if ((v75 + (v71 * 2)) == 0) { + float v76 = v61[v74][v72][v73].read(); + v67[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v73 + (v69 * 2))] = v76; + } + float v77 = v67[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v73 + (v69 * 2))]; + if ((v72 + (v68 * 2)) == 0) { + float v78 = v62[(v74 + (v70 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))]; + v66[(v74 + (v70 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))] = v78; + } + float v79 = v66[(v74 + (v70 * 8))][(v73 + (v69 * 2))][(v75 + (v71 * 2))]; + if ((v73 + (v69 * 2)) == 0) { + v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))] = v64; + } + float v80 = v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))]; + float v81 = v77 * v79; + float v82 = v80 + v81; + v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))] = v82; + if (((v73 + (v69 * 2)) - 63) == 0) { + float v83 = v65[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))]; + v63[(v74 + (v70 * 8))][(v72 + (v68 * 2))][(v75 + (v71 * 2))] = v83; + } + } + } + } + } + } + } + } + } + return ; +} + +void node7( + float v84[64][128], + float v85[8][64][16] +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v85 complete dim=1 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=3 factor=2 + + loop36: for (int v86 = 0; v86 < 8; v86++) { + loop37: for (int v87 = 0; v87 < 1; v87++) { + loop38: for (int v88 = 0; v88 < 32; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v89 = 0; v89 < 2; v89++) { + loop40: for (int v90 = 0; v90 < 8; v90++) { + loop41: for (int v91 = 0; v91 < 2; v91++) { + float v92 = v84[(v91 + (v88 * 2))][((((v90 * 16) + (v87 * 128)) + v89) + (v86 * 2))]; + v85[(v90 + (v87 * 8))][(v91 + (v88 * 2))][(v89 + (v86 * 2))] = v92; + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v93[8][2][2], + hls::stream v94[8][2], + hls::stream v95[8][2][2] +) { + float v96[8][64]; + #pragma HLS array_partition variable=v96 complete dim=1 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=2 + + loop42: for (int v97 = 0; v97 < 32; v97++) { + loop43: for (int v98 = 0; v98 < 32; v98++) { + loop44: for (int v99 = 0; v99 < 1; v99++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop45: for (int v100 = 0; v100 < 2; v100++) { + loop46: for (int v101 = 0; v101 < 2; v101++) { + loop47: for (int v102 = 0; v102 < 8; v102++) { + float v103 = v93[v102][v100][v101].read(); + if ((v101 + (v98 * 2)) == 0) { + float v104 = v94[v102][v100].read(); + v96[(v102 + (v99 * 8))][(v100 + (v97 * 2))] = v104; + } + float v105 = v96[(v102 + (v99 * 8))][(v100 + (v97 * 2))]; + float v106 = v103 / v105; + v95[v102][v100][v101].write(v106); + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v107[8][2][2], + hls::stream v108[8][2], + float v109 +) { + float v110[8][64]; + #pragma HLS array_partition variable=v110 complete dim=1 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=2 + + loop48: for (int v111 = 0; v111 < 32; v111++) { + loop49: for (int v112 = 0; v112 < 32; v112++) { + loop50: for (int v113 = 0; v113 < 1; v113++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v114 = 0; v114 < 2; v114++) { + loop52: for (int v115 = 0; v115 < 2; v115++) { + loop53: for (int v116 = 0; v116 < 8; v116++) { + float v117 = v107[v116][v114][v115].read(); + if ((v115 + (v112 * 2)) == 0) { + v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))] = v109; + } + float v118 = v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))]; + float v119 = v117 + v118; + v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))] = v119; + if (((v115 + (v112 * 2)) - 63) == 0) { + float v120 = v110[(v116 + (v113 * 8))][(v114 + (v111 * 2))]; + v108[v116][v114].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v121[8][2][2], + hls::stream v122[8][2], + hls::stream v123[8][2][2], + hls::stream v124[8][2][2] +) { + float v125[8][64]; + #pragma HLS array_partition variable=v125 complete dim=1 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=2 + + loop54: for (int v126 = 0; v126 < 32; v126++) { + loop55: for (int v127 = 0; v127 < 32; v127++) { + loop56: for (int v128 = 0; v128 < 1; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v129 = 0; v129 < 2; v129++) { + loop58: for (int v130 = 0; v130 < 2; v130++) { + loop59: for (int v131 = 0; v131 < 8; v131++) { + float v132 = v121[v131][v129][v130].read(); + if ((v130 + (v127 * 2)) == 0) { + float v133 = v122[v131][v129].read(); + v125[(v131 + (v128 * 8))][(v129 + (v126 * 2))] = v133; + } + float v134 = v125[(v131 + (v128 * 8))][(v129 + (v126 * 2))]; + float v135 = v132 - v134; + float v136 = exp(v135); + v123[v131][v129][v130].write(v136); + v124[v131][v129][v130].write(v136); + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v137[8][2][2], + hls::stream v138[8][2], + float v139 +) { + float v140[8][64]; + #pragma HLS array_partition variable=v140 complete dim=1 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=2 + + loop60: for (int v141 = 0; v141 < 32; v141++) { + loop61: for (int v142 = 0; v142 < 32; v142++) { + loop62: for (int v143 = 0; v143 < 1; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v144 = 0; v144 < 2; v144++) { + loop64: for (int v145 = 0; v145 < 2; v145++) { + loop65: for (int v146 = 0; v146 < 8; v146++) { + float v147 = v137[v146][v144][v145].read(); + if ((v145 + (v142 * 2)) == 0) { + v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))] = v139; + } + float v148 = v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))]; + float v149 = fmax(v147, v148); + v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))] = v149; + if (((v145 + (v142 * 2)) - 63) == 0) { + float v150 = v140[(v146 + (v143 * 8))][(v144 + (v141 * 2))]; + v138[v146][v144].write(v150); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v151[8][2][2], + hls::stream v152[8][2][2], + hls::stream v153[8][2][2], + float v154 +) { + loop66: for (int v155 = 0; v155 < 32; v155++) { + loop67: for (int v156 = 0; v156 < 32; v156++) { + loop68: for (int v157 = 0; v157 < 1; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop69: for (int v158 = 0; v158 < 2; v158++) { + loop70: for (int v159 = 0; v159 < 2; v159++) { + loop71: for (int v160 = 0; v160 < 8; v160++) { + float v161 = v151[v160][v158][v159].read(); + float v162 = v161 / v154; + v152[v160][v158][v159].write(v162); + v153[v160][v158][v159].write(v162); + } + } + } + } + } + } + return ; +} + +void node13( + float v163[8][16][64], + float v164[8][64][16], + hls::stream v165[8][2][2], + float v166 +) { + #pragma HLS array_partition variable=v163 complete dim=1 + #pragma HLS array_partition variable=v163 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v163 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v164 complete dim=1 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v164 cyclic dim=3 factor=2 + + float v167[8][64][64]; + #pragma HLS array_partition variable=v167 complete dim=1 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v167 cyclic dim=3 factor=2 + + float v168[8][16][64]; + #pragma HLS array_partition variable=v168 complete dim=1 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=3 factor=2 + + float v169[8][64][16]; + #pragma HLS array_partition variable=v169 complete dim=1 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=3 factor=2 + + loop72: for (int v170 = 0; v170 < 32; v170++) { + loop73: for (int v171 = 0; v171 < 32; v171++) { + loop74: for (int v172 = 0; v172 < 8; v172++) { + loop75: for (int v173 = 0; v173 < 1; v173++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v174 = 0; v174 < 2; v174++) { + loop77: for (int v175 = 0; v175 < 2; v175++) { + loop78: for (int v176 = 0; v176 < 2; v176++) { + loop79: for (int v177 = 0; v177 < 8; v177++) { + if ((v175 + (v171 * 2)) == 0) { + float v178 = v164[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v176 + (v172 * 2))]; + v169[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v176 + (v172 * 2))] = v178; + } + float v179 = v169[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v176 + (v172 * 2))]; + if ((v174 + (v170 * 2)) == 0) { + float v180 = v163[(v177 + (v173 * 8))][(v176 + (v172 * 2))][(v175 + (v171 * 2))]; + v168[(v177 + (v173 * 8))][(v176 + (v172 * 2))][(v175 + (v171 * 2))] = v180; + } + float v181 = v168[(v177 + (v173 * 8))][(v176 + (v172 * 2))][(v175 + (v171 * 2))]; + if ((v176 + (v172 * 2)) == 0) { + v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))] = v166; + } + float v182 = v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))]; + float v183 = v179 * v181; + float v184 = v182 + v183; + v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))] = v184; + if (((v176 + (v172 * 2)) - 15) == 0) { + float v185 = v167[(v177 + (v173 * 8))][(v174 + (v170 * 2))][(v175 + (v171 * 2))]; + v165[v177][v174][v175].write(v185); + } + } + } + } + } + } + } + } + } + return ; +} + +void node14( + float v186[64][128], + float v187[8][16][64] +) { + #pragma HLS array_partition variable=v186 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v186 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v187 complete dim=1 + #pragma HLS array_partition variable=v187 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v187 cyclic dim=3 factor=2 + + loop80: for (int v188 = 0; v188 < 8; v188++) { + loop81: for (int v189 = 0; v189 < 1; v189++) { + loop82: for (int v190 = 0; v190 < 32; v190++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v191 = 0; v191 < 2; v191++) { + loop84: for (int v192 = 0; v192 < 8; v192++) { + loop85: for (int v193 = 0; v193 < 2; v193++) { + float v194 = v186[(v193 + (v190 * 2))][((((v192 * 16) + (v189 * 128)) + v191) + (v188 * 2))]; + v187[(v192 + (v189 * 8))][(v191 + (v188 * 2))][(v193 + (v190 * 2))] = v194; + } + } + } + } + } + } + return ; +} + +void node15( + float v195[64][128], + float v196[8][64][16] +) { + #pragma HLS array_partition variable=v195 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v195 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v196 complete dim=1 + #pragma HLS array_partition variable=v196 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v196 cyclic dim=3 factor=2 + + loop86: for (int v197 = 0; v197 < 32; v197++) { + loop87: for (int v198 = 0; v198 < 1; v198++) { + loop88: for (int v199 = 0; v199 < 8; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v200 = 0; v200 < 2; v200++) { + loop90: for (int v201 = 0; v201 < 8; v201++) { + loop91: for (int v202 = 0; v202 < 2; v202++) { + float v203 = v195[(v200 + (v197 * 2))][((((v201 * 16) + (v198 * 128)) + v202) + (v199 * 2))]; + v196[(v201 + (v198 * 8))][(v200 + (v197 * 2))][(v202 + (v199 * 2))] = v203; + } + } + } + } + } + } + return ; +} + +void node16( + hls::stream v204[2][8], + float v205[128], + float v206[64][128] +) { + #pragma HLS array_partition variable=v205 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=8 + + loop92: for (int v207 = 0; v207 < 32; v207++) { + loop93: for (int v208 = 0; v208 < 16; v208++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop94: for (int v209 = 0; v209 < 2; v209++) { + loop95: for (int v210 = 0; v210 < 8; v210++) { + float v211 = v204[v209][v210].read(); + float v212 = v205[(v210 + (v208 * 8))]; + float v213 = v211 + v212; + v206[(v209 + (v207 * 2))][(v210 + (v208 * 8))] = v213; + } + } + } + } + return ; +} + +void node17( + hls::stream v214[4][8], + hls::stream v215[2][4], + hls::stream v216[2][8], + float v217 +) { + float v218[64][128]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=8 + + float v219[128][128]; + #pragma HLS array_partition variable=v219 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v219 cyclic dim=2 factor=8 + + float v220[64][128]; + #pragma HLS array_partition variable=v220 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v220 cyclic dim=2 factor=4 + + loop96: for (int v221 = 0; v221 < 32; v221++) { + loop97: for (int v222 = 0; v222 < 32; v222++) { + loop98: for (int v223 = 0; v223 < 16; v223++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop99: for (int v224 = 0; v224 < 4; v224++) { + loop100: for (int v225 = 0; v225 < 2; v225++) { + loop101: for (int v226 = 0; v226 < 8; v226++) { + if ((v226 + (v223 * 8)) == 0) { + float v227 = v215[v225][v224].read(); + v220[(v225 + (v222 * 2))][(v224 + (v221 * 4))] = v227; + } + float v228 = v220[(v225 + (v222 * 2))][(v224 + (v221 * 4))]; + if ((v225 + (v222 * 2)) == 0) { + float v229 = v214[v224][v226].read(); + v219[(v224 + (v221 * 4))][(v226 + (v223 * 8))] = v229; + } + float v230 = v219[(v224 + (v221 * 4))][(v226 + (v223 * 8))]; + if ((v224 + (v221 * 4)) == 0) { + v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))] = v217; + } + float v231 = v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))]; + float v232 = v228 * v230; + float v233 = v231 + v232; + v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))] = v233; + if (((v224 + (v221 * 4)) - 127) == 0) { + float v234 = v218[(v225 + (v222 * 2))][(v226 + (v223 * 8))]; + v216[v225][v226].write(v234); + } + } + } + } + } + } + } + return ; +} + +void node18( + float v235[128][128], + hls::stream v236[4][8] +) { + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=4 + + loop102: for (int v237 = 0; v237 < 32; v237++) { + loop103: for (int v238 = 0; v238 < 16; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop104: for (int v239 = 0; v239 < 4; v239++) { + loop105: for (int v240 = 0; v240 < 8; v240++) { + float v241 = v235[(v240 + (v238 * 8))][(v239 + (v237 * 4))]; + v236[v239][v240].write(v241); + } + } + } + } + return ; +} + +void node19( + hls::stream v242[2][8], + float v243[128], + float v244[64][128] +) { + #pragma HLS array_partition variable=v243 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=8 + + loop106: for (int v245 = 0; v245 < 32; v245++) { + loop107: for (int v246 = 0; v246 < 16; v246++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop108: for (int v247 = 0; v247 < 2; v247++) { + loop109: for (int v248 = 0; v248 < 8; v248++) { + float v249 = v242[v247][v248].read(); + float v250 = v243[(v248 + (v246 * 8))]; + float v251 = v249 + v250; + v244[(v247 + (v245 * 2))][(v248 + (v246 * 8))] = v251; + } + } + } + } + return ; +} + +void node20( + hls::stream v252[4][8], + hls::stream v253[2][4], + hls::stream v254[2][8], + float v255 +) { + float v256[64][128]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=8 + + float v257[128][128]; + #pragma HLS array_partition variable=v257 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v257 cyclic dim=2 factor=8 + + float v258[64][128]; + #pragma HLS array_partition variable=v258 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v258 cyclic dim=2 factor=4 + + loop110: for (int v259 = 0; v259 < 32; v259++) { + loop111: for (int v260 = 0; v260 < 32; v260++) { + loop112: for (int v261 = 0; v261 < 16; v261++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop113: for (int v262 = 0; v262 < 4; v262++) { + loop114: for (int v263 = 0; v263 < 2; v263++) { + loop115: for (int v264 = 0; v264 < 8; v264++) { + if ((v264 + (v261 * 8)) == 0) { + float v265 = v253[v263][v262].read(); + v258[(v263 + (v260 * 2))][(v262 + (v259 * 4))] = v265; + } + float v266 = v258[(v263 + (v260 * 2))][(v262 + (v259 * 4))]; + if ((v263 + (v260 * 2)) == 0) { + float v267 = v252[v262][v264].read(); + v257[(v262 + (v259 * 4))][(v264 + (v261 * 8))] = v267; + } + float v268 = v257[(v262 + (v259 * 4))][(v264 + (v261 * 8))]; + if ((v262 + (v259 * 4)) == 0) { + v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))] = v255; + } + float v269 = v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))]; + float v270 = v266 * v268; + float v271 = v269 + v270; + v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))] = v271; + if (((v262 + (v259 * 4)) - 127) == 0) { + float v272 = v256[(v263 + (v260 * 2))][(v264 + (v261 * 8))]; + v254[v263][v264].write(v272); + } + } + } + } + } + } + } + return ; +} + +void node21( + float v273[128][128], + hls::stream v274[4][8] +) { + #pragma HLS array_partition variable=v273 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v273 cyclic dim=2 factor=4 + + loop116: for (int v275 = 0; v275 < 32; v275++) { + loop117: for (int v276 = 0; v276 < 16; v276++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop118: for (int v277 = 0; v277 < 4; v277++) { + loop119: for (int v278 = 0; v278 < 8; v278++) { + float v279 = v273[(v278 + (v276 * 8))][(v277 + (v275 * 4))]; + v274[v277][v278].write(v279); + } + } + } + } + return ; +} + +void node22( + hls::stream v280[2][8], + float v281[128], + float v282[64][128] +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=8 + + loop120: for (int v283 = 0; v283 < 16; v283++) { + loop121: for (int v284 = 0; v284 < 32; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop122: for (int v285 = 0; v285 < 8; v285++) { + loop123: for (int v286 = 0; v286 < 2; v286++) { + float v287 = v280[v286][v285].read(); + float v288 = v281[(v285 + (v283 * 8))]; + float v289 = v287 + v288; + v282[(v286 + (v284 * 2))][(v285 + (v283 * 8))] = v289; + } + } + } + } + return ; +} + +void node23( + hls::stream v290[2][4], + hls::stream v291[4][8], + hls::stream v292[2][8], + float v293 +) { + float v294[64][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=8 + + float v295[128][128]; + #pragma HLS array_partition variable=v295 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v295 cyclic dim=2 factor=8 + + float v296[64][128]; + #pragma HLS array_partition variable=v296 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v296 cyclic dim=2 factor=4 + + loop124: for (int v297 = 0; v297 < 32; v297++) { + loop125: for (int v298 = 0; v298 < 16; v298++) { + loop126: for (int v299 = 0; v299 < 32; v299++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop127: for (int v300 = 0; v300 < 4; v300++) { + loop128: for (int v301 = 0; v301 < 8; v301++) { + loop129: for (int v302 = 0; v302 < 2; v302++) { + if ((v301 + (v298 * 8)) == 0) { + float v303 = v290[v302][v300].read(); + v296[(v302 + (v299 * 2))][(v300 + (v297 * 4))] = v303; + } + float v304 = v296[(v302 + (v299 * 2))][(v300 + (v297 * 4))]; + if ((v302 + (v299 * 2)) == 0) { + float v305 = v291[v300][v301].read(); + v295[(v300 + (v297 * 4))][(v301 + (v298 * 8))] = v305; + } + float v306 = v295[(v300 + (v297 * 4))][(v301 + (v298 * 8))]; + if ((v300 + (v297 * 4)) == 0) { + v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))] = v293; + } + float v307 = v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))]; + float v308 = v304 * v306; + float v309 = v307 + v308; + v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))] = v309; + if (((v300 + (v297 * 4)) - 127) == 0) { + float v310 = v294[(v302 + (v299 * 2))][(v301 + (v298 * 8))]; + v292[v302][v301].write(v310); + } + } + } + } + } + } + } + return ; +} + +void node24( + float v311[128][128], + hls::stream v312[4][8] +) { + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + loop130: for (int v313 = 0; v313 < 32; v313++) { + loop131: for (int v314 = 0; v314 < 16; v314++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop132: for (int v315 = 0; v315 < 4; v315++) { + loop133: for (int v316 = 0; v316 < 8; v316++) { + float v317 = v311[(v316 + (v314 * 8))][(v315 + (v313 * 4))]; + v312[v315][v316].write(v317); + } + } + } + } + return ; +} + +void node25( + float v318[1][64][128], + hls::stream v319[2][4], + hls::stream v320[2][4], + hls::stream v321[2][4] +) { + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v318 cyclic dim=3 factor=4 + + loop134: for (int v322 = 0; v322 < 32; v322++) { + loop135: for (int v323 = 0; v323 < 32; v323++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v324 = 0; v324 < 4; v324++) { + loop137: for (int v325 = 0; v325 < 2; v325++) { + float v326 = v318[0][(v325 + (v323 * 2))][(v324 + (v322 * 4))]; + v319[v325][v324].write(v326); + v320[v325][v324].write(v326); + v321[v325][v324].write(v326); + } + } + } + } + return ; +} + +void forward( + float v327[1][64][128], + float v328[128], + float v329[128][128], + float v330[128], + float v331[128][128], + float v332[128], + float v333[128][128], + float v334[128], + float v335[128][128], + float v336[1][64][128] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v327 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v327 cyclic dim=3 factor=4 + + #pragma HLS array_partition variable=v328 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v329 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v329 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v330 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v331 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v331 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v332 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v333 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v333 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v334 cyclic dim=1 factor=8 + + #pragma HLS array_partition variable=v335 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v335 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v336 cyclic dim=2 factor=8 + #pragma HLS array_partition variable=v336 cyclic dim=3 factor=8 + + hls::stream v337[8][8]; + #pragma HLS STREAM variable=v337 depth=128 + hls::stream v338[8][8]; + #pragma HLS STREAM variable=v338 depth=128 + hls::stream v339[2][8]; + #pragma HLS STREAM variable=v339 depth=1024 + hls::stream v340[8][2]; + #pragma HLS STREAM variable=v340 depth=512 + float v341[64][8][16]; + #pragma HLS array_partition variable=v341 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v341 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v341 cyclic dim=3 factor=2 + + float v342[8][64][16]; + #pragma HLS array_partition variable=v342 complete dim=1 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=3 factor=2 + + float v343[8][64][16]; + #pragma HLS array_partition variable=v343 complete dim=1 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=3 factor=2 + + hls::stream v344[8][2][2]; + #pragma HLS STREAM variable=v344 depth=1024 + hls::stream v345[8][2]; + #pragma HLS STREAM variable=v345 depth=32 + hls::stream v346[8][2][2]; + #pragma HLS STREAM variable=v346 depth=1024 + hls::stream v347[8][2][2]; + #pragma HLS STREAM variable=v347 depth=1024 + hls::stream v348[8][2]; + #pragma HLS STREAM variable=v348 depth=32 + hls::stream v349[8][2][2]; + #pragma HLS STREAM variable=v349 depth=1024 + hls::stream v350[8][2][2]; + #pragma HLS STREAM variable=v350 depth=1024 + hls::stream v351[8][2][2]; + #pragma HLS STREAM variable=v351 depth=1024 + float v352[8][16][64]; + #pragma HLS array_partition variable=v352 complete dim=1 + #pragma HLS array_partition variable=v352 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v352 cyclic dim=3 factor=2 + + float v353[8][64][16]; + #pragma HLS array_partition variable=v353 complete dim=1 + #pragma HLS array_partition variable=v353 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v353 cyclic dim=3 factor=2 + + float v354[64][128]; + #pragma HLS array_partition variable=v354 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v354 cyclic dim=2 factor=8 + + hls::stream v355[2][8]; + #pragma HLS STREAM variable=v355 depth=512 + hls::stream v356[4][8]; + #pragma HLS STREAM variable=v356 depth=512 + float v357[64][128]; + #pragma HLS array_partition variable=v357 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v357 cyclic dim=2 factor=8 + + hls::stream v358[2][8]; + #pragma HLS STREAM variable=v358 depth=512 + hls::stream v359[4][8]; + #pragma HLS STREAM variable=v359 depth=512 + float v360[64][128]; + #pragma HLS array_partition variable=v360 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v360 cyclic dim=2 factor=8 + + hls::stream v361[2][8]; + #pragma HLS STREAM variable=v361 depth=512 + hls::stream v362[4][8]; + #pragma HLS STREAM variable=v362 depth=512 + hls::stream v363[2][4]; + #pragma HLS STREAM variable=v363 depth=1024 + hls::stream v364[2][4]; + #pragma HLS STREAM variable=v364 depth=1024 + hls::stream v365[2][4]; + #pragma HLS STREAM variable=v365 depth=1024 + node25(v327, v365, v364, v363); + node24(v329, v362); + node23(v363, v362, v361, 0.000000); + node22(v361, v328, v360); + node21(v331, v359); + node20(v359, v364, v358, 0.000000); + node19(v358, v330, v357); + node18(v333, v356); + node17(v356, v365, v355, 0.000000); + node16(v355, v332, v354); + node15(v360, v353); + node14(v357, v352); + node13(v352, v353, v351, 0.000000); + node12(v351, v350, v349, 4.000000); + node11(v350, v348, -INFINITY); + node10(v349, v348, v347, v346); + node9(v347, v345, 0.000000); + node8(v346, v345, v344); + node7(v354, v343); + node6(v344, v343, v342, 0.000000); + node5(v342, v341); + node4(v341, v340); + node3(v335, v339); + node2(v339, v340, v338, 0.000000); + node1(v338, v334, v337); + node0(v337, v336); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt1/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt1/src/ResMLP.cpp new file mode 100644 index 000000000000..a4f4c79fabf7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt1/src/ResMLP.cpp @@ -0,0 +1,406 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[8][10] +) { // L6 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L7 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L8 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L9 + v1[v2][v3] = v4; // L10 + } + } + return ; // L13 +} + +void node1( + hls::stream &v5, + float v6[10], + hls::stream &v7 +) { // L15 + loop2: for (int v8 = 0; v8 < 8; v8++) { // L16 + loop3: for (int v9 = 0; v9 < 10; v9++) { // L17 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); // L18 + float v11 = v6[v9]; // L19 + float v12 = v10 + v11; // L20 + v7.write(v12); // L21 + } + } + return ; // L24 +} + +void node2( + hls::stream &v13, + hls::stream &v14, + hls::stream &v15, + float v16 +) { // L26 + float v17[8][10]; // L27 + float v18[256][10]; // L28 + float v19[8][256]; // L29 + loop4: for (int v20 = 0; v20 < 8; v20++) { // L30 + loop5: for (int v21 = 0; v21 < 10; v21++) { // L31 + loop6: for (int v22 = 0; v22 < 256; v22++) { // L32 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v21 == 0) { // L33 + float v23 = v14.read(); // L34 + v19[v20][v22] = v23; // L35 + } + float v24 = v19[v20][v22]; // L37 + if (v20 == 0) { // L38 + float v25 = v13.read(); // L39 + v18[v22][v21] = v25; // L40 + } + float v26 = v18[v22][v21]; // L42 + if (v22 == 0) { // L43 + v17[v20][v21] = v16; // L44 + } + float v27 = v17[v20][v21]; // L46 + float v28 = v24 * v26; // L47 + float v29 = v27 + v28; // L48 + v17[v20][v21] = v29; // L49 + if ((v22 - 255) == 0) { // L50 + float v30 = v17[v20][v21]; // L51 + v15.write(v30); // L52 + } + } + } + } + return ; // L57 +} + +void node3( + float v31[10][256], + hls::stream &v32 +) { // L59 + loop7: for (int v33 = 0; v33 < 10; v33++) { // L60 + loop8: for (int v34 = 0; v34 < 256; v34++) { // L61 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v33][v34]; // L62 + v32.write(v35); // L63 + } + } + return ; // L66 +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38 +) { // L68 + loop9: for (int v39 = 0; v39 < 8; v39++) { // L69 + loop10: for (int v40 = 0; v40 < 256; v40++) { // L70 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v41 = v36.read(); // L71 + float v42 = v37[v40]; // L72 + float v43 = v41 + v42; // L73 + v38.write(v43); // L74 + } + } + return ; // L77 +} + +void node5( + hls::stream &v44, + hls::stream &v45, + hls::stream &v46, + float v47 +) { // L79 + float v48[8][256]; // L80 + float v49[512][256]; // L81 + float v50[8][512]; // L82 + loop11: for (int v51 = 0; v51 < 8; v51++) { // L83 + loop12: for (int v52 = 0; v52 < 256; v52++) { // L84 + loop13: for (int v53 = 0; v53 < 512; v53++) { // L85 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v52 == 0) { // L86 + float v54 = v44.read(); // L87 + v50[v51][v53] = v54; // L88 + } + float v55 = v50[v51][v53]; // L90 + if (v51 == 0) { // L91 + float v56 = v45.read(); // L92 + v49[v53][v52] = v56; // L93 + } + float v57 = v49[v53][v52]; // L95 + if (v53 == 0) { // L96 + v48[v51][v52] = v47; // L97 + } + float v58 = v48[v51][v52]; // L99 + float v59 = v55 * v57; // L100 + float v60 = v58 + v59; // L101 + v48[v51][v52] = v60; // L102 + if ((v53 - 511) == 0) { // L103 + float v61 = v48[v51][v52]; // L104 + v46.write(v61); // L105 + } + } + } + } + return ; // L110 +} + +void node6( + float v62[256][512], + hls::stream &v63 +) { // L112 + loop14: for (int v64 = 0; v64 < 256; v64++) { // L113 + loop15: for (int v65 = 0; v65 < 512; v65++) { // L114 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v66 = v62[v64][v65]; // L115 + v63.write(v66); // L116 + } + } + return ; // L119 +} + +void node7( + hls::stream &v67, + float v68[512], + hls::stream &v69, + hls::stream &v70, + float v71 +) { // L121 + loop16: for (int v72 = 0; v72 < 8; v72++) { // L122 + loop17: for (int v73 = 0; v73 < 512; v73++) { // L123 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v67.read(); // L124 + float v75 = v68[v73]; // L125 + float v76 = v69.read(); // L126 + float v77 = v74 + v75; // L127 + float v78 = v77 + v76; // L128 + bool v79 = v78 > v71; // L129 + float v80 = v79 ? (float)v78 : (float)v71; // L130 + v70.write(v80); // L131 + } + } + return ; // L134 +} + +void node8( + hls::stream &v81, + hls::stream &v82, + hls::stream &v83, + float v84 +) { // L136 + float v85[8][512]; // L137 + float v86[512][512]; // L138 + float v87[8][512]; // L139 + loop18: for (int v88 = 0; v88 < 8; v88++) { // L140 + loop19: for (int v89 = 0; v89 < 512; v89++) { // L141 + loop20: for (int v90 = 0; v90 < 512; v90++) { // L142 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v89 == 0) { // L143 + float v91 = v82.read(); // L144 + v87[v88][v90] = v91; // L145 + } + float v92 = v87[v88][v90]; // L147 + if (v88 == 0) { // L148 + float v93 = v81.read(); // L149 + v86[v90][v89] = v93; // L150 + } + float v94 = v86[v90][v89]; // L152 + if (v90 == 0) { // L153 + v85[v88][v89] = v84; // L154 + } + float v95 = v85[v88][v89]; // L156 + float v96 = v92 * v94; // L157 + float v97 = v95 + v96; // L158 + v85[v88][v89] = v97; // L159 + if ((v90 - 511) == 0) { // L160 + float v98 = v85[v88][v89]; // L161 + v83.write(v98); // L162 + } + } + } + } + return ; // L167 +} + +void node9( + float v99[512][512], + hls::stream &v100 +) { // L169 + loop21: for (int v101 = 0; v101 < 512; v101++) { // L170 + loop22: for (int v102 = 0; v102 < 512; v102++) { // L171 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v103 = v99[v101][v102]; // L172 + v100.write(v103); // L173 + } + } + return ; // L176 +} + +void node10( + hls::stream &v104, + hls::stream &v105, + float v106 +) { // L178 + loop23: for (int v107 = 0; v107 < 8; v107++) { // L179 + loop24: for (int v108 = 0; v108 < 512; v108++) { // L180 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v104.read(); // L181 + bool v110 = v109 > v106; // L182 + float v111 = v110 ? (float)v109 : (float)v106; // L183 + v105.write(v111); // L184 + } + } + return ; // L187 +} + +void node11( + hls::stream &v112, + float v113[512], + hls::stream &v114, + hls::stream &v115 +) { // L189 + loop25: for (int v116 = 0; v116 < 8; v116++) { // L190 + loop26: for (int v117 = 0; v117 < 512; v117++) { // L191 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v118 = v112.read(); // L192 + float v119 = v113[v117]; // L193 + float v120 = v118 + v119; // L194 + v114.write(v120); // L195 + v115.write(v120); // L196 + } + } + return ; // L199 +} + +void node12( + float v121[8][1024], + hls::stream &v122, + hls::stream &v123, + float v124 +) { // L201 + float v125[8][512]; // L202 + float v126[1024][512]; // L203 + loop27: for (int v127 = 0; v127 < 8; v127++) { // L204 + loop28: for (int v128 = 0; v128 < 512; v128++) { // L205 + loop29: for (int v129 = 0; v129 < 1024; v129++) { // L206 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v130 = v121[v127][v129]; // L207 + if (v127 == 0) { // L208 + float v131 = v122.read(); // L209 + v126[v129][v128] = v131; // L210 + } + float v132 = v126[v129][v128]; // L212 + if (v129 == 0) { // L213 + v125[v127][v128] = v124; // L214 + } + float v133 = v125[v127][v128]; // L216 + float v134 = v130 * v132; // L217 + float v135 = v133 + v134; // L218 + v125[v127][v128] = v135; // L219 + if ((v129 - 1023) == 0) { // L220 + float v136 = v125[v127][v128]; // L221 + v123.write(v136); // L222 + } + } + } + } + return ; // L227 +} + +void node13( + float v137[512][1024], + hls::stream &v138 +) { // L229 + loop30: for (int v139 = 0; v139 < 512; v139++) { // L230 + loop31: for (int v140 = 0; v140 < 1024; v140++) { // L231 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v141 = v137[v139][v140]; // L232 + v138.write(v141); // L233 + } + } + return ; // L236 +} + +void forward( + float v142[8][1024], + float v143[512], + float v144[512][1024], + float v145[512], + float v146[512][512], + float v147[256], + float v148[256][512], + float v149[10], + float v150[10][256], + float v151[8][10] +) { // L238 + #pragma HLS DATAFLOW + hls::stream v152("fifo_0"); + #pragma HLS STREAM variable=v152 depth=80 // L240 + hls::stream v153("fifo_1"); + #pragma HLS STREAM variable=v153 depth=80 // L241 + hls::stream v154("fifo_2"); + #pragma HLS STREAM variable=v154 depth=2560 // L242 + hls::stream v155("fifo_3"); + #pragma HLS STREAM variable=v155 depth=2048 // L243 + hls::stream v156("fifo_4"); + #pragma HLS STREAM variable=v156 depth=2048 // L244 + hls::stream v157("fifo_5"); + #pragma HLS STREAM variable=v157 depth=131072 // L245 + hls::stream v158("fifo_6"); + #pragma HLS STREAM variable=v158 depth=4096 // L246 + hls::stream v159("fifo_7"); + #pragma HLS STREAM variable=v159 depth=4096 // L247 + hls::stream v160("fifo_8"); + #pragma HLS STREAM variable=v160 depth=262144 // L248 + hls::stream v161("fifo_9"); + #pragma HLS STREAM variable=v161 depth=4096 // L249 + hls::stream v162("fifo_10"); + #pragma HLS STREAM variable=v162 depth=4096 // L250 + hls::stream v163("fifo_11"); + #pragma HLS STREAM variable=v163 depth=4096 // L251 + hls::stream v164("fifo_12"); + #pragma HLS STREAM variable=v164 depth=4096 // L252 + hls::stream v165("fifo_13"); + #pragma HLS STREAM variable=v165 depth=524288 // L253 + node13(v144, v165); // L254 + node12(v142, v165, v164, 0.000000); // L255 + node11(v164, v143, v163, v162); // L256 + node10(v163, v161, 0.000000); // L257 + node9(v146, v160); // L258 + node8(v160, v161, v159, 0.000000); // L259 + node7(v159, v145, v162, v158, 0.000000); // L260 + node6(v148, v157); // L261 + node5(v158, v157, v156, 0.000000); // L262 + node4(v156, v147, v155); // L263 + node3(v150, v154); // L264 + node2(v154, v155, v153, 0.000000); // L265 + node1(v153, v149, v152); // L266 + node0(v152, v151); // L267 + return ; // L268 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt2/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt2/src/ResMLP.cpp new file mode 100644 index 000000000000..e1c7100dcfce --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt2/src/ResMLP.cpp @@ -0,0 +1,405 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[8][10] +) { // L6 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L7 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L8 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); // L9 + v1[v2][v3] = v4; // L10 + } + } + return ; // L13 +} + +void node1( + hls::stream &v5, + float v6[10], + hls::stream &v7 +) { // L15 + loop2: for (int v8 = 0; v8 < 8; v8++) { // L16 + loop3: for (int v9 = 0; v9 < 10; v9++) { // L17 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v5.read(); // L18 + float v11 = v6[v9]; // L19 + float v12 = v10 + v11; // L20 + v7.write(v12); // L21 + } + } + return ; // L24 +} + +void node2( + hls::stream &v13, + float v14[256][10], + hls::stream &v15, + float v16 +) { // L26 + float v17[8][10]; // L27 + float v18[256][10]; // L28 + float v19[8][256]; // L29 + loop4: for (int v20 = 0; v20 < 8; v20++) { // L30 + loop5: for (int v21 = 0; v21 < 256; v21++) { // L31 + loop6: for (int v22 = 0; v22 < 10; v22++) { // L32 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v22 == 0) { // L33 + float v23 = v13.read(); // L34 + v19[v20][v21] = v23; // L35 + } + float v24 = v19[v20][v21]; // L37 + if (v20 == 0) { // L38 + float v25 = v14[v21][v22]; // L39 + v18[v21][v22] = v25; // L40 + } + float v26 = v18[v21][v22]; // L42 + if (v21 == 0) { // L43 + v17[v20][v22] = v16; // L44 + } + float v27 = v17[v20][v22]; // L46 + float v28 = v24 * v26; // L47 + float v29 = v27 + v28; // L48 + v17[v20][v22] = v29; // L49 + if ((v21 - 255) == 0) { // L50 + float v30 = v17[v20][v22]; // L51 + v15.write(v30); // L52 + } + } + } + } + return ; // L57 +} + +void node3( + float v31[10][256], + float v32[256][10] +) { // L59 + loop7: for (int v33 = 0; v33 < 10; v33++) { // L60 + loop8: for (int v34 = 0; v34 < 256; v34++) { // L61 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v35 = v31[v33][v34]; // L62 + v32[v34][v33] = v35; // L63 + } + } + return ; // L66 +} + +void node4( + hls::stream &v36, + float v37[256], + hls::stream &v38 +) { // L68 + loop9: for (int v39 = 0; v39 < 8; v39++) { // L69 + loop10: for (int v40 = 0; v40 < 256; v40++) { // L70 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v41 = v36.read(); // L71 + float v42 = v37[v40]; // L72 + float v43 = v41 + v42; // L73 + v38.write(v43); // L74 + } + } + return ; // L77 +} + +void node5( + hls::stream &v44, + hls::stream &v45, + hls::stream &v46, + float v47 +) { // L79 + float v48[8][256]; // L80 + float v49[512][256]; // L81 + float v50[8][512]; // L82 + loop11: for (int v51 = 0; v51 < 8; v51++) { // L83 + loop12: for (int v52 = 0; v52 < 512; v52++) { // L84 + loop13: for (int v53 = 0; v53 < 256; v53++) { // L85 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v53 == 0) { // L86 + float v54 = v45.read(); // L87 + v50[v51][v52] = v54; // L88 + } + float v55 = v50[v51][v52]; // L90 + if (v51 == 0) { // L91 + float v56 = v44.read(); // L92 + v49[v52][v53] = v56; // L93 + } + float v57 = v49[v52][v53]; // L95 + if (v52 == 0) { // L96 + v48[v51][v53] = v47; // L97 + } + float v58 = v48[v51][v53]; // L99 + float v59 = v55 * v57; // L100 + float v60 = v58 + v59; // L101 + v48[v51][v53] = v60; // L102 + if ((v52 - 511) == 0) { // L103 + float v61 = v48[v51][v53]; // L104 + v46.write(v61); // L105 + } + } + } + } + return ; // L110 +} + +void node6( + float v62[256][512], + hls::stream &v63 +) { // L112 + loop14: for (int v64 = 0; v64 < 512; v64++) { // L113 + loop15: for (int v65 = 0; v65 < 256; v65++) { // L114 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v66 = v62[v65][v64]; // L115 + v63.write(v66); // L116 + } + } + return ; // L119 +} + +void node7( + hls::stream &v67, + float v68[512], + hls::stream &v69, + hls::stream &v70, + float v71 +) { // L121 + loop16: for (int v72 = 0; v72 < 8; v72++) { // L122 + loop17: for (int v73 = 0; v73 < 512; v73++) { // L123 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v74 = v67.read(); // L124 + float v75 = v68[v73]; // L125 + float v76 = v69.read(); // L126 + float v77 = v74 + v75; // L127 + float v78 = v77 + v76; // L128 + bool v79 = v78 > v71; // L129 + float v80 = v79 ? (float)v78 : (float)v71; // L130 + v70.write(v80); // L131 + } + } + return ; // L134 +} + +void node8( + hls::stream &v81, + hls::stream &v82, + hls::stream &v83, + float v84 +) { // L136 + float v85[8][512]; // L137 + float v86[512][512]; // L138 + float v87[8][512]; // L139 + loop18: for (int v88 = 0; v88 < 8; v88++) { // L140 + loop19: for (int v89 = 0; v89 < 512; v89++) { // L141 + loop20: for (int v90 = 0; v90 < 512; v90++) { // L142 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v90 == 0) { // L143 + float v91 = v81.read(); // L144 + v87[v88][v89] = v91; // L145 + } + float v92 = v87[v88][v89]; // L147 + if (v88 == 0) { // L148 + float v93 = v82.read(); // L149 + v86[v89][v90] = v93; // L150 + } + float v94 = v86[v89][v90]; // L152 + if (v89 == 0) { // L153 + v85[v88][v90] = v84; // L154 + } + float v95 = v85[v88][v90]; // L156 + float v96 = v92 * v94; // L157 + float v97 = v95 + v96; // L158 + v85[v88][v90] = v97; // L159 + if ((v89 - 511) == 0) { // L160 + float v98 = v85[v88][v90]; // L161 + v83.write(v98); // L162 + } + } + } + } + return ; // L167 +} + +void node9( + float v99[512][512], + hls::stream &v100 +) { // L169 + loop21: for (int v101 = 0; v101 < 512; v101++) { // L170 + loop22: for (int v102 = 0; v102 < 512; v102++) { // L171 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v103 = v99[v102][v101]; // L172 + v100.write(v103); // L173 + } + } + return ; // L176 +} + +void node10( + hls::stream &v104, + hls::stream &v105, + float v106 +) { // L178 + loop23: for (int v107 = 0; v107 < 8; v107++) { // L179 + loop24: for (int v108 = 0; v108 < 512; v108++) { // L180 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v104.read(); // L181 + bool v110 = v109 > v106; // L182 + float v111 = v110 ? (float)v109 : (float)v106; // L183 + v105.write(v111); // L184 + } + } + return ; // L187 +} + +void node11( + hls::stream &v112, + float v113[512], + hls::stream &v114, + hls::stream &v115 +) { // L189 + loop25: for (int v116 = 0; v116 < 8; v116++) { // L190 + loop26: for (int v117 = 0; v117 < 512; v117++) { // L191 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v118 = v112.read(); // L192 + float v119 = v113[v117]; // L193 + float v120 = v118 + v119; // L194 + v114.write(v120); // L195 + v115.write(v120); // L196 + } + } + return ; // L199 +} + +void node12( + float v121[8][1024], + hls::stream &v122, + hls::stream &v123, + float v124 +) { // L201 + float v125[8][512]; // L202 + float v126[1024][512]; // L203 + loop27: for (int v127 = 0; v127 < 8; v127++) { // L204 + loop28: for (int v128 = 0; v128 < 1024; v128++) { // L205 + loop29: for (int v129 = 0; v129 < 512; v129++) { // L206 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v130 = v121[v127][v128]; // L207 + if (v127 == 0) { // L208 + float v131 = v122.read(); // L209 + v126[v128][v129] = v131; // L210 + } + float v132 = v126[v128][v129]; // L212 + if (v128 == 0) { // L213 + v125[v127][v129] = v124; // L214 + } + float v133 = v125[v127][v129]; // L216 + float v134 = v130 * v132; // L217 + float v135 = v133 + v134; // L218 + v125[v127][v129] = v135; // L219 + if ((v128 - 1023) == 0) { // L220 + float v136 = v125[v127][v129]; // L221 + v123.write(v136); // L222 + } + } + } + } + return ; // L227 +} + +void node13( + float v137[512][1024], + hls::stream &v138 +) { // L229 + loop30: for (int v139 = 0; v139 < 1024; v139++) { // L230 + loop31: for (int v140 = 0; v140 < 512; v140++) { // L231 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v141 = v137[v140][v139]; // L232 + v138.write(v141); // L233 + } + } + return ; // L236 +} + +void forward( + float v142[8][1024], + float v143[512], + float v144[512][1024], + float v145[512], + float v146[512][512], + float v147[256], + float v148[256][512], + float v149[10], + float v150[10][256], + float v151[8][10] +) { // L238 + #pragma HLS DATAFLOW + hls::stream v152("fifo_0"); + #pragma HLS STREAM variable=v152 depth=80 // L240 + hls::stream v153("fifo_1"); + #pragma HLS STREAM variable=v153 depth=80 // L241 + float v154[256][10]; // L242 + hls::stream v155("fifo_2"); + #pragma HLS STREAM variable=v155 depth=2048 // L243 + hls::stream v156("fifo_3"); + #pragma HLS STREAM variable=v156 depth=2048 // L244 + hls::stream v157("fifo_4"); + #pragma HLS STREAM variable=v157 depth=131072 // L245 + hls::stream v158("fifo_5"); + #pragma HLS STREAM variable=v158 depth=4096 // L246 + hls::stream v159("fifo_6"); + #pragma HLS STREAM variable=v159 depth=4096 // L247 + hls::stream v160("fifo_7"); + #pragma HLS STREAM variable=v160 depth=262144 // L248 + hls::stream v161("fifo_8"); + #pragma HLS STREAM variable=v161 depth=4096 // L249 + hls::stream v162("fifo_9"); + #pragma HLS STREAM variable=v162 depth=4096 // L250 + hls::stream v163("fifo_10"); + #pragma HLS STREAM variable=v163 depth=4096 // L251 + hls::stream v164("fifo_11"); + #pragma HLS STREAM variable=v164 depth=4096 // L252 + hls::stream v165("fifo_12"); + #pragma HLS STREAM variable=v165 depth=524288 // L253 + node13(v144, v165); // L254 + node12(v142, v165, v164, 0.000000); // L255 + node11(v164, v143, v163, v162); // L256 + node10(v163, v161, 0.000000); // L257 + node9(v146, v160); // L258 + node8(v161, v160, v159, 0.000000); // L259 + node7(v159, v145, v162, v158, 0.000000); // L260 + node6(v148, v157); // L261 + node5(v157, v158, v156, 0.000000); // L262 + node4(v156, v147, v155); // L263 + node3(v150, v154); // L264 + node2(v155, v154, v153, 0.000000); // L265 + node1(v153, v149, v152); // L266 + node0(v152, v151); // L267 + return ; // L268 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt3/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt3/src/ResMLP.cpp new file mode 100644 index 000000000000..79e23ca3d036 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt3/src/ResMLP.cpp @@ -0,0 +1,470 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[8][10] +) { // L10 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L11 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L12 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L13 + loop3: for (int v5 = 0; v5 < 1; v5++) { // L14 + float v6 = v0[v4][v5].read(); // L15 + v1[(v2 + v4)][(v3 + v5)] = v6; // L16 + } + } + } + } + return ; // L21 +} + +void node1( + hls::stream v7[1][1], + float v8[10], + hls::stream v9[1][1] +) { // L23 + loop4: for (int v10 = 0; v10 < 8; v10++) { // L24 + loop5: for (int v11 = 0; v11 < 10; v11++) { // L25 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 1; v12++) { // L26 + loop7: for (int v13 = 0; v13 < 1; v13++) { // L27 + float v14 = v7[v12][v13].read(); // L28 + float v15 = v8[(v11 + v13)]; // L29 + float v16 = v14 + v15; // L30 + v9[v12][v13].write(v16); // L31 + } + } + } + } + return ; // L36 +} + +void node2( + hls::stream v17[16][1], + hls::stream v18[1][16], + hls::stream v19[1][1], + float v20 +) { // L38 + float v21[8][10]; // L39 + float v22[256][10]; // L40 + float v23[8][256]; // L41 + loop8: for (int v24 = 0; v24 < 8; v24++) { // L42 + loop9: for (int v25 = 0; v25 < 10; v25++) { // L43 + loop10: for (int v26 = 0; v26 < 16; v26++) { // L44 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 1; v27++) { // L45 + loop12: for (int v28 = 0; v28 < 1; v28++) { // L46 + loop13: for (int v29 = 0; v29 < 16; v29++) { // L47 + if ((v25 + v28) == 0) { // L48 + float v30 = v18[v27][v29].read(); // L49 + v23[(v24 + v27)][(v29 + (v26 * 16))] = v30; // L50 + } + float v31 = v23[(v24 + v27)][(v29 + (v26 * 16))]; // L52 + if ((v24 + v27) == 0) { // L53 + float v32 = v17[v29][v28].read(); // L54 + v22[(v29 + (v26 * 16))][(v25 + v28)] = v32; // L55 + } + float v33 = v22[(v29 + (v26 * 16))][(v25 + v28)]; // L57 + if ((v29 + (v26 * 16)) == 0) { // L58 + v21[(v24 + v27)][(v25 + v28)] = v20; // L59 + } + float v34 = v21[(v24 + v27)][(v25 + v28)]; // L61 + float v35 = v31 * v33; // L62 + float v36 = v34 + v35; // L63 + v21[(v24 + v27)][(v25 + v28)] = v36; // L64 + if (((v29 + (v26 * 16)) - 255) == 0) { // L65 + float v37 = v21[(v24 + v27)][(v25 + v28)]; // L66 + v19[v27][v28].write(v37); // L67 + } + } + } + } + } + } + } + return ; // L75 +} + +void node3( + float v38[10][256], + hls::stream v39[16][1] +) { // L77 + loop14: for (int v40 = 0; v40 < 10; v40++) { // L78 + loop15: for (int v41 = 0; v41 < 16; v41++) { // L79 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 1; v42++) { // L80 + loop17: for (int v43 = 0; v43 < 16; v43++) { // L81 + float v44 = v38[(v40 + v42)][(v43 + (v41 * 16))]; // L82 + v39[v43][v42].write(v44); // L83 + } + } + } + } + return ; // L88 +} + +void node4( + hls::stream v45[1][16], + float v46[256], + hls::stream v47[1][16] +) { // L90 + loop18: for (int v48 = 0; v48 < 8; v48++) { // L91 + loop19: for (int v49 = 0; v49 < 16; v49++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v50 = 0; v50 < 1; v50++) { // L93 + loop21: for (int v51 = 0; v51 < 16; v51++) { // L94 + float v52 = v45[v50][v51].read(); // L95 + float v53 = v46[(v51 + (v49 * 16))]; // L96 + float v54 = v52 + v53; // L97 + v47[v50][v51].write(v54); // L98 + } + } + } + } + return ; // L103 +} + +void node5( + hls::stream v55[1][8], + hls::stream v56[8][16], + hls::stream v57[1][16], + float v58 +) { // L105 + float v59[8][256]; // L106 + float v60[512][256]; // L107 + float v61[8][512]; // L108 + loop22: for (int v62 = 0; v62 < 8; v62++) { // L109 + loop23: for (int v63 = 0; v63 < 16; v63++) { // L110 + loop24: for (int v64 = 0; v64 < 64; v64++) { // L111 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v65 = 0; v65 < 1; v65++) { // L112 + loop26: for (int v66 = 0; v66 < 16; v66++) { // L113 + loop27: for (int v67 = 0; v67 < 8; v67++) { // L114 + if ((v66 + (v63 * 16)) == 0) { // L115 + float v68 = v55[v65][v67].read(); // L116 + v61[(v62 + v65)][(v67 + (v64 * 8))] = v68; // L117 + } + float v69 = v61[(v62 + v65)][(v67 + (v64 * 8))]; // L119 + if ((v62 + v65) == 0) { // L120 + float v70 = v56[v67][v66].read(); // L121 + v60[(v67 + (v64 * 8))][(v66 + (v63 * 16))] = v70; // L122 + } + float v71 = v60[(v67 + (v64 * 8))][(v66 + (v63 * 16))]; // L124 + if ((v67 + (v64 * 8)) == 0) { // L125 + v59[(v62 + v65)][(v66 + (v63 * 16))] = v58; // L126 + } + float v72 = v59[(v62 + v65)][(v66 + (v63 * 16))]; // L128 + float v73 = v69 * v71; // L129 + float v74 = v72 + v73; // L130 + v59[(v62 + v65)][(v66 + (v63 * 16))] = v74; // L131 + if (((v67 + (v64 * 8)) - 511) == 0) { // L132 + float v75 = v59[(v62 + v65)][(v66 + (v63 * 16))]; // L133 + v57[v65][v66].write(v75); // L134 + } + } + } + } + } + } + } + return ; // L142 +} + +void node6( + float v76[256][512], + hls::stream v77[8][16] +) { // L144 + loop28: for (int v78 = 0; v78 < 16; v78++) { // L145 + loop29: for (int v79 = 0; v79 < 64; v79++) { // L146 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v80 = 0; v80 < 16; v80++) { // L147 + loop31: for (int v81 = 0; v81 < 8; v81++) { // L148 + float v82 = v76[(v80 + (v78 * 16))][(v81 + (v79 * 8))]; // L149 + v77[v81][v80].write(v82); // L150 + } + } + } + } + return ; // L155 +} + +void node7( + hls::stream v83[1][8], + float v84[512], + hls::stream v85[1][8], + hls::stream v86[1][8], + float v87 +) { // L157 + loop32: for (int v88 = 0; v88 < 8; v88++) { // L158 + loop33: for (int v89 = 0; v89 < 64; v89++) { // L159 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 1; v90++) { // L160 + loop35: for (int v91 = 0; v91 < 8; v91++) { // L161 + float v92 = v83[v90][v91].read(); // L162 + float v93 = v84[(v91 + (v89 * 8))]; // L163 + float v94 = v85[v90][v91].read(); // L164 + float v95 = v92 + v93; // L165 + float v96 = v95 + v94; // L166 + bool v97 = v96 > v87; // L167 + float v98 = v97 ? (float)v96 : (float)v87; // L168 + v86[v90][v91].write(v98); // L169 + } + } + } + } + return ; // L174 +} + +void node8( + hls::stream v99[8][8], + hls::stream v100[1][8], + hls::stream v101[1][8], + float v102 +) { // L176 + float v103[8][512]; // L177 + float v104[512][512]; // L178 + float v105[8][512]; // L179 + loop36: for (int v106 = 0; v106 < 8; v106++) { // L180 + loop37: for (int v107 = 0; v107 < 64; v107++) { // L181 + loop38: for (int v108 = 0; v108 < 64; v108++) { // L182 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v109 = 0; v109 < 1; v109++) { // L183 + loop40: for (int v110 = 0; v110 < 8; v110++) { // L184 + loop41: for (int v111 = 0; v111 < 8; v111++) { // L185 + if ((v110 + (v107 * 8)) == 0) { // L186 + float v112 = v100[v109][v111].read(); // L187 + v105[(v106 + v109)][(v111 + (v108 * 8))] = v112; // L188 + } + float v113 = v105[(v106 + v109)][(v111 + (v108 * 8))]; // L190 + if ((v106 + v109) == 0) { // L191 + float v114 = v99[v111][v110].read(); // L192 + v104[(v111 + (v108 * 8))][(v110 + (v107 * 8))] = v114; // L193 + } + float v115 = v104[(v111 + (v108 * 8))][(v110 + (v107 * 8))]; // L195 + if ((v111 + (v108 * 8)) == 0) { // L196 + v103[(v106 + v109)][(v110 + (v107 * 8))] = v102; // L197 + } + float v116 = v103[(v106 + v109)][(v110 + (v107 * 8))]; // L199 + float v117 = v113 * v115; // L200 + float v118 = v116 + v117; // L201 + v103[(v106 + v109)][(v110 + (v107 * 8))] = v118; // L202 + if (((v111 + (v108 * 8)) - 511) == 0) { // L203 + float v119 = v103[(v106 + v109)][(v110 + (v107 * 8))]; // L204 + v101[v109][v110].write(v119); // L205 + } + } + } + } + } + } + } + return ; // L213 +} + +void node9( + float v120[512][512], + hls::stream v121[8][8] +) { // L215 + loop42: for (int v122 = 0; v122 < 64; v122++) { // L216 + loop43: for (int v123 = 0; v123 < 64; v123++) { // L217 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v124 = 0; v124 < 8; v124++) { // L218 + loop45: for (int v125 = 0; v125 < 8; v125++) { // L219 + float v126 = v120[(v124 + (v122 * 8))][(v125 + (v123 * 8))]; // L220 + v121[v125][v124].write(v126); // L221 + } + } + } + } + return ; // L226 +} + +void node10( + hls::stream v127[1][8], + hls::stream v128[1][8], + float v129 +) { // L228 + loop46: for (int v130 = 0; v130 < 8; v130++) { // L229 + loop47: for (int v131 = 0; v131 < 64; v131++) { // L230 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v132 = 0; v132 < 1; v132++) { // L231 + loop49: for (int v133 = 0; v133 < 8; v133++) { // L232 + float v134 = v127[v132][v133].read(); // L233 + bool v135 = v134 > v129; // L234 + float v136 = v135 ? (float)v134 : (float)v129; // L235 + v128[v132][v133].write(v136); // L236 + } + } + } + } + return ; // L241 +} + +void node11( + hls::stream v137[1][8], + float v138[512], + hls::stream v139[1][8], + hls::stream v140[1][8] +) { // L243 + loop50: for (int v141 = 0; v141 < 8; v141++) { // L244 + loop51: for (int v142 = 0; v142 < 64; v142++) { // L245 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop52: for (int v143 = 0; v143 < 1; v143++) { // L246 + loop53: for (int v144 = 0; v144 < 8; v144++) { // L247 + float v145 = v137[v143][v144].read(); // L248 + float v146 = v138[(v144 + (v142 * 8))]; // L249 + float v147 = v145 + v146; // L250 + v139[v143][v144].write(v147); // L251 + v140[v143][v144].write(v147); // L252 + } + } + } + } + return ; // L257 +} + +void node12( + float v148[8][1024], + hls::stream v149[32][8], + hls::stream v150[1][8], + float v151 +) { // L259 + float v152[8][512]; // L260 + float v153[1024][512]; // L261 + loop54: for (int v154 = 0; v154 < 8; v154++) { // L262 + loop55: for (int v155 = 0; v155 < 64; v155++) { // L263 + loop56: for (int v156 = 0; v156 < 32; v156++) { // L264 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v157 = 0; v157 < 1; v157++) { // L265 + loop58: for (int v158 = 0; v158 < 8; v158++) { // L266 + loop59: for (int v159 = 0; v159 < 32; v159++) { // L267 + float v160 = v148[(v154 + v157)][(v159 + (v156 * 32))]; // L268 + if ((v154 + v157) == 0) { // L269 + float v161 = v149[v159][v158].read(); // L270 + v153[(v159 + (v156 * 32))][(v158 + (v155 * 8))] = v161; // L271 + } + float v162 = v153[(v159 + (v156 * 32))][(v158 + (v155 * 8))]; // L273 + if ((v159 + (v156 * 32)) == 0) { // L274 + v152[(v154 + v157)][(v158 + (v155 * 8))] = v151; // L275 + } + float v163 = v152[(v154 + v157)][(v158 + (v155 * 8))]; // L277 + float v164 = v160 * v162; // L278 + float v165 = v163 + v164; // L279 + v152[(v154 + v157)][(v158 + (v155 * 8))] = v165; // L280 + if (((v159 + (v156 * 32)) - 1023) == 0) { // L281 + float v166 = v152[(v154 + v157)][(v158 + (v155 * 8))]; // L282 + v150[v157][v158].write(v166); // L283 + } + } + } + } + } + } + } + return ; // L291 +} + +void node13( + float v167[512][1024], + hls::stream v168[32][8] +) { // L293 + loop60: for (int v169 = 0; v169 < 64; v169++) { // L294 + loop61: for (int v170 = 0; v170 < 32; v170++) { // L295 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v171 = 0; v171 < 8; v171++) { // L296 + loop63: for (int v172 = 0; v172 < 32; v172++) { // L297 + float v173 = v167[(v171 + (v169 * 8))][(v172 + (v170 * 32))]; // L298 + v168[v172][v171].write(v173); // L299 + } + } + } + } + return ; // L304 +} + +void forward( + float v174[8][1024], + float v175[512], + float v176[512][1024], + float v177[512], + float v178[512][512], + float v179[256], + float v180[256][512], + float v181[10], + float v182[10][256], + float v183[8][10] +) { // L306 + #pragma HLS DATAFLOW + hls::stream v184[1][1]; + #pragma HLS STREAM variable=v184 depth=80 // L308 + hls::stream v185[1][1]; + #pragma HLS STREAM variable=v185 depth=80 // L309 + hls::stream v186[16][1]; + #pragma HLS STREAM variable=v186 depth=160 // L310 + hls::stream v187[1][16]; + #pragma HLS STREAM variable=v187 depth=128 // L311 + hls::stream v188[1][16]; + #pragma HLS STREAM variable=v188 depth=128 // L312 + hls::stream v189[8][16]; + #pragma HLS STREAM variable=v189 depth=1024 // L313 + hls::stream v190[1][8]; + #pragma HLS STREAM variable=v190 depth=512 // L314 + hls::stream v191[1][8]; + #pragma HLS STREAM variable=v191 depth=512 // L315 + hls::stream v192[8][8]; + #pragma HLS STREAM variable=v192 depth=4096 // L316 + hls::stream v193[1][8]; + #pragma HLS STREAM variable=v193 depth=512 // L317 + hls::stream v194[1][8]; + #pragma HLS STREAM variable=v194 depth=512 // L318 + hls::stream v195[1][8]; + #pragma HLS STREAM variable=v195 depth=512 // L319 + hls::stream v196[1][8]; + #pragma HLS STREAM variable=v196 depth=512 // L320 + hls::stream v197[32][8]; + #pragma HLS STREAM variable=v197 depth=2048 // L321 + node13(v176, v197); // L322 + node12(v174, v197, v196, 0.000000); // L323 + node11(v196, v175, v195, v194); // L324 + node10(v195, v193, 0.000000); // L325 + node9(v178, v192); // L326 + node8(v192, v193, v191, 0.000000); // L327 + node7(v191, v177, v194, v190, 0.000000); // L328 + node6(v180, v189); // L329 + node5(v190, v189, v188, 0.000000); // L330 + node4(v188, v179, v187); // L331 + node3(v182, v186); // L332 + node2(v186, v187, v185, 0.000000); // L333 + node1(v185, v181, v184); // L334 + node0(v184, v183); // L335 + return ; // L336 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt4/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt4/src/ResMLP.cpp new file mode 100644 index 000000000000..1443cb07415b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt4/src/ResMLP.cpp @@ -0,0 +1,469 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[8][10] +) { // L10 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L11 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L12 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { // L13 + loop3: for (int v5 = 0; v5 < 1; v5++) { // L14 + float v6 = v0[v4][v5].read(); // L15 + v1[(v2 + v4)][(v3 + v5)] = v6; // L16 + } + } + } + } + return ; // L21 +} + +void node1( + hls::stream v7[1][1], + float v8[10], + hls::stream v9[1][1] +) { // L23 + loop4: for (int v10 = 0; v10 < 8; v10++) { // L24 + loop5: for (int v11 = 0; v11 < 10; v11++) { // L25 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 1; v12++) { // L26 + loop7: for (int v13 = 0; v13 < 1; v13++) { // L27 + float v14 = v7[v12][v13].read(); // L28 + float v15 = v8[(v11 + v13)]; // L29 + float v16 = v14 + v15; // L30 + v9[v12][v13].write(v16); // L31 + } + } + } + } + return ; // L36 +} + +void node2( + hls::stream v17[1][4], + float v18[256][10], + hls::stream v19[1][1], + float v20 +) { // L38 + float v21[8][10]; // L39 + float v22[256][10]; // L40 + float v23[8][256]; // L41 + loop8: for (int v24 = 0; v24 < 8; v24++) { // L42 + loop9: for (int v25 = 0; v25 < 64; v25++) { // L43 + loop10: for (int v26 = 0; v26 < 10; v26++) { // L44 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v27 = 0; v27 < 1; v27++) { // L45 + loop12: for (int v28 = 0; v28 < 4; v28++) { // L46 + loop13: for (int v29 = 0; v29 < 1; v29++) { // L47 + if ((v26 + v29) == 0) { // L48 + float v30 = v17[v27][v28].read(); // L49 + v23[(v24 + v27)][(v28 + (v25 * 4))] = v30; // L50 + } + float v31 = v23[(v24 + v27)][(v28 + (v25 * 4))]; // L52 + if ((v24 + v27) == 0) { // L53 + float v32 = v18[(v28 + (v25 * 4))][(v26 + v29)]; // L54 + v22[(v28 + (v25 * 4))][(v26 + v29)] = v32; // L55 + } + float v33 = v22[(v28 + (v25 * 4))][(v26 + v29)]; // L57 + if ((v28 + (v25 * 4)) == 0) { // L58 + v21[(v24 + v27)][(v26 + v29)] = v20; // L59 + } + float v34 = v21[(v24 + v27)][(v26 + v29)]; // L61 + float v35 = v31 * v33; // L62 + float v36 = v34 + v35; // L63 + v21[(v24 + v27)][(v26 + v29)] = v36; // L64 + if (((v28 + (v25 * 4)) - 255) == 0) { // L65 + float v37 = v21[(v24 + v27)][(v26 + v29)]; // L66 + v19[v27][v29].write(v37); // L67 + } + } + } + } + } + } + } + return ; // L75 +} + +void node3( + float v38[10][256], + float v39[256][10] +) { // L77 + loop14: for (int v40 = 0; v40 < 10; v40++) { // L78 + loop15: for (int v41 = 0; v41 < 64; v41++) { // L79 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v42 = 0; v42 < 1; v42++) { // L80 + loop17: for (int v43 = 0; v43 < 4; v43++) { // L81 + float v44 = v38[(v40 + v42)][(v43 + (v41 * 4))]; // L82 + v39[(v43 + (v41 * 4))][(v40 + v42)] = v44; // L83 + } + } + } + } + return ; // L88 +} + +void node4( + hls::stream v45[1][4], + float v46[256], + hls::stream v47[1][4] +) { // L90 + loop18: for (int v48 = 0; v48 < 8; v48++) { // L91 + loop19: for (int v49 = 0; v49 < 64; v49++) { // L92 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop20: for (int v50 = 0; v50 < 1; v50++) { // L93 + loop21: for (int v51 = 0; v51 < 4; v51++) { // L94 + float v52 = v45[v50][v51].read(); // L95 + float v53 = v46[(v51 + (v49 * 4))]; // L96 + float v54 = v52 + v53; // L97 + v47[v50][v51].write(v54); // L98 + } + } + } + } + return ; // L103 +} + +void node5( + hls::stream v55[16][4], + hls::stream v56[1][16], + hls::stream v57[1][4], + float v58 +) { // L105 + float v59[8][256]; // L106 + float v60[512][256]; // L107 + float v61[8][512]; // L108 + loop22: for (int v62 = 0; v62 < 8; v62++) { // L109 + loop23: for (int v63 = 0; v63 < 32; v63++) { // L110 + loop24: for (int v64 = 0; v64 < 64; v64++) { // L111 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v65 = 0; v65 < 1; v65++) { // L112 + loop26: for (int v66 = 0; v66 < 16; v66++) { // L113 + loop27: for (int v67 = 0; v67 < 4; v67++) { // L114 + if ((v67 + (v64 * 4)) == 0) { // L115 + float v68 = v56[v65][v66].read(); // L116 + v61[(v62 + v65)][(v66 + (v63 * 16))] = v68; // L117 + } + float v69 = v61[(v62 + v65)][(v66 + (v63 * 16))]; // L119 + if ((v62 + v65) == 0) { // L120 + float v70 = v55[v66][v67].read(); // L121 + v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))] = v70; // L122 + } + float v71 = v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))]; // L124 + if ((v66 + (v63 * 16)) == 0) { // L125 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v58; // L126 + } + float v72 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L128 + float v73 = v69 * v71; // L129 + float v74 = v72 + v73; // L130 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v74; // L131 + if (((v66 + (v63 * 16)) - 511) == 0) { // L132 + float v75 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L133 + v57[v65][v67].write(v75); // L134 + } + } + } + } + } + } + } + return ; // L142 +} + +void node6( + float v76[256][512], + hls::stream v77[16][4] +) { // L144 + loop28: for (int v78 = 0; v78 < 32; v78++) { // L145 + loop29: for (int v79 = 0; v79 < 64; v79++) { // L146 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop30: for (int v80 = 0; v80 < 16; v80++) { // L147 + loop31: for (int v81 = 0; v81 < 4; v81++) { // L148 + float v82 = v76[(v81 + (v79 * 4))][(v80 + (v78 * 16))]; // L149 + v77[v80][v81].write(v82); // L150 + } + } + } + } + return ; // L155 +} + +void node7( + hls::stream v83[1][16], + float v84[512], + hls::stream v85[1][16], + hls::stream v86[1][16], + float v87 +) { // L157 + loop32: for (int v88 = 0; v88 < 8; v88++) { // L158 + loop33: for (int v89 = 0; v89 < 32; v89++) { // L159 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop34: for (int v90 = 0; v90 < 1; v90++) { // L160 + loop35: for (int v91 = 0; v91 < 16; v91++) { // L161 + float v92 = v83[v90][v91].read(); // L162 + float v93 = v84[(v91 + (v89 * 16))]; // L163 + float v94 = v85[v90][v91].read(); // L164 + float v95 = v92 + v93; // L165 + float v96 = v95 + v94; // L166 + bool v97 = v96 > v87; // L167 + float v98 = v97 ? (float)v96 : (float)v87; // L168 + v86[v90][v91].write(v98); // L169 + } + } + } + } + return ; // L174 +} + +void node8( + hls::stream v99[1][16], + hls::stream v100[16][16], + hls::stream v101[1][16], + float v102 +) { // L176 + float v103[8][512]; // L177 + float v104[512][512]; // L178 + float v105[8][512]; // L179 + loop36: for (int v106 = 0; v106 < 8; v106++) { // L180 + loop37: for (int v107 = 0; v107 < 32; v107++) { // L181 + loop38: for (int v108 = 0; v108 < 32; v108++) { // L182 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v109 = 0; v109 < 1; v109++) { // L183 + loop40: for (int v110 = 0; v110 < 16; v110++) { // L184 + loop41: for (int v111 = 0; v111 < 16; v111++) { // L185 + if ((v111 + (v108 * 16)) == 0) { // L186 + float v112 = v99[v109][v110].read(); // L187 + v105[(v106 + v109)][(v110 + (v107 * 16))] = v112; // L188 + } + float v113 = v105[(v106 + v109)][(v110 + (v107 * 16))]; // L190 + if ((v106 + v109) == 0) { // L191 + float v114 = v100[v110][v111].read(); // L192 + v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))] = v114; // L193 + } + float v115 = v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))]; // L195 + if ((v110 + (v107 * 16)) == 0) { // L196 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v102; // L197 + } + float v116 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L199 + float v117 = v113 * v115; // L200 + float v118 = v116 + v117; // L201 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v118; // L202 + if (((v110 + (v107 * 16)) - 511) == 0) { // L203 + float v119 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L204 + v101[v109][v111].write(v119); // L205 + } + } + } + } + } + } + } + return ; // L213 +} + +void node9( + float v120[512][512], + hls::stream v121[16][16] +) { // L215 + loop42: for (int v122 = 0; v122 < 32; v122++) { // L216 + loop43: for (int v123 = 0; v123 < 32; v123++) { // L217 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop44: for (int v124 = 0; v124 < 16; v124++) { // L218 + loop45: for (int v125 = 0; v125 < 16; v125++) { // L219 + float v126 = v120[(v125 + (v123 * 16))][(v124 + (v122 * 16))]; // L220 + v121[v124][v125].write(v126); // L221 + } + } + } + } + return ; // L226 +} + +void node10( + hls::stream v127[1][16], + hls::stream v128[1][16], + float v129 +) { // L228 + loop46: for (int v130 = 0; v130 < 8; v130++) { // L229 + loop47: for (int v131 = 0; v131 < 32; v131++) { // L230 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v132 = 0; v132 < 1; v132++) { // L231 + loop49: for (int v133 = 0; v133 < 16; v133++) { // L232 + float v134 = v127[v132][v133].read(); // L233 + bool v135 = v134 > v129; // L234 + float v136 = v135 ? (float)v134 : (float)v129; // L235 + v128[v132][v133].write(v136); // L236 + } + } + } + } + return ; // L241 +} + +void node11( + hls::stream v137[1][16], + float v138[512], + hls::stream v139[1][16], + hls::stream v140[1][16] +) { // L243 + loop50: for (int v141 = 0; v141 < 8; v141++) { // L244 + loop51: for (int v142 = 0; v142 < 32; v142++) { // L245 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop52: for (int v143 = 0; v143 < 1; v143++) { // L246 + loop53: for (int v144 = 0; v144 < 16; v144++) { // L247 + float v145 = v137[v143][v144].read(); // L248 + float v146 = v138[(v144 + (v142 * 16))]; // L249 + float v147 = v145 + v146; // L250 + v139[v143][v144].write(v147); // L251 + v140[v143][v144].write(v147); // L252 + } + } + } + } + return ; // L257 +} + +void node12( + hls::stream v148[8][16], + float v149[8][1024], + hls::stream v150[1][16], + float v151 +) { // L259 + float v152[8][512]; // L260 + float v153[1024][512]; // L261 + loop54: for (int v154 = 0; v154 < 8; v154++) { // L262 + loop55: for (int v155 = 0; v155 < 128; v155++) { // L263 + loop56: for (int v156 = 0; v156 < 32; v156++) { // L264 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v157 = 0; v157 < 1; v157++) { // L265 + loop58: for (int v158 = 0; v158 < 8; v158++) { // L266 + loop59: for (int v159 = 0; v159 < 16; v159++) { // L267 + float v160 = v149[(v154 + v157)][(v158 + (v155 * 8))]; // L268 + if ((v154 + v157) == 0) { // L269 + float v161 = v148[v158][v159].read(); // L270 + v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))] = v161; // L271 + } + float v162 = v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))]; // L273 + if ((v158 + (v155 * 8)) == 0) { // L274 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v151; // L275 + } + float v163 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L277 + float v164 = v160 * v162; // L278 + float v165 = v163 + v164; // L279 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v165; // L280 + if (((v158 + (v155 * 8)) - 1023) == 0) { // L281 + float v166 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L282 + v150[v157][v159].write(v166); // L283 + } + } + } + } + } + } + } + return ; // L291 +} + +void node13( + float v167[512][1024], + hls::stream v168[8][16] +) { // L293 + loop60: for (int v169 = 0; v169 < 128; v169++) { // L294 + loop61: for (int v170 = 0; v170 < 32; v170++) { // L295 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop62: for (int v171 = 0; v171 < 8; v171++) { // L296 + loop63: for (int v172 = 0; v172 < 16; v172++) { // L297 + float v173 = v167[(v172 + (v170 * 16))][(v171 + (v169 * 8))]; // L298 + v168[v171][v172].write(v173); // L299 + } + } + } + } + return ; // L304 +} + +void forward( + float v174[8][1024], + float v175[512], + float v176[512][1024], + float v177[512], + float v178[512][512], + float v179[256], + float v180[256][512], + float v181[10], + float v182[10][256], + float v183[8][10] +) { // L306 + #pragma HLS DATAFLOW + hls::stream v184[1][1]; + #pragma HLS STREAM variable=v184 depth=80 // L308 + hls::stream v185[1][1]; + #pragma HLS STREAM variable=v185 depth=80 // L309 + float v186[256][10]; // L310 + hls::stream v187[1][4]; + #pragma HLS STREAM variable=v187 depth=512 // L311 + hls::stream v188[1][4]; + #pragma HLS STREAM variable=v188 depth=512 // L312 + hls::stream v189[16][4]; + #pragma HLS STREAM variable=v189 depth=2048 // L313 + hls::stream v190[1][16]; + #pragma HLS STREAM variable=v190 depth=256 // L314 + hls::stream v191[1][16]; + #pragma HLS STREAM variable=v191 depth=256 // L315 + hls::stream v192[16][16]; + #pragma HLS STREAM variable=v192 depth=1024 // L316 + hls::stream v193[1][16]; + #pragma HLS STREAM variable=v193 depth=256 // L317 + hls::stream v194[1][16]; + #pragma HLS STREAM variable=v194 depth=256 // L318 + hls::stream v195[1][16]; + #pragma HLS STREAM variable=v195 depth=256 // L319 + hls::stream v196[1][16]; + #pragma HLS STREAM variable=v196 depth=256 // L320 + hls::stream v197[8][16]; + #pragma HLS STREAM variable=v197 depth=4096 // L321 + node13(v176, v197); // L322 + node12(v197, v174, v196, 0.000000); // L323 + node11(v196, v175, v195, v194); // L324 + node10(v195, v193, 0.000000); // L325 + node9(v178, v192); // L326 + node8(v193, v192, v191, 0.000000); // L327 + node7(v191, v177, v194, v190, 0.000000); // L328 + node6(v180, v189); // L329 + node5(v189, v190, v188, 0.000000); // L330 + node4(v188, v179, v187); // L331 + node3(v182, v186); // L332 + node2(v187, v186, v185, 0.000000); // L333 + node1(v185, v181, v184); // L334 + node0(v184, v183); // L335 + return ; // L336 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt5/src/ResMLP.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt5/src/ResMLP.cpp new file mode 100644 index 000000000000..3c59e22674b8 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResMLP__opt5/src/ResMLP.cpp @@ -0,0 +1,517 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[8][10] +) { // L23 + loop0: for (int v2 = 0; v2 < 8; v2++) { // L24 + loop1: for (int v3 = 0; v3 < 10; v3++) { // L25 + #pragma HLS pipeline II=1 + loop2: for (int v4 = 0; v4 < 1; v4++) { // L26 + loop3: for (int v5 = 0; v5 < 1; v5++) { // L27 + float v6 = v0[v4][v5].read(); // L28 + v1[(v2 + v4)][(v3 + v5)] = v6; // L29 + } + } + } + } + return ; // L34 +} + +void node1( + hls::stream v7[1][1], + float v8[10], + hls::stream v9[1][1] +) { // L36 + loop4: for (int v10 = 0; v10 < 8; v10++) { // L37 + loop5: for (int v11 = 0; v11 < 10; v11++) { // L38 + #pragma HLS pipeline II=1 + loop6: for (int v12 = 0; v12 < 1; v12++) { // L39 + loop7: for (int v13 = 0; v13 < 1; v13++) { // L40 + float v14 = v7[v12][v13].read(); // L41 + float v15 = v8[(v11 + v13)]; // L42 + float v16 = v14 + v15; // L43 + v9[v12][v13].write(v16); // L44 + } + } + } + } + return ; // L49 +} + +void node2( + hls::stream v17[1][4], + hls::stream v18[4][1], + hls::stream v19[1][1], + float v20 +) { // L51 + float v21[8][10]; // L52 + float v22[256][10]; // L53 + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + + float v23[8][256]; // L54 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=4 + + loop8: for (int v24 = 0; v24 < 8; v24++) { // L55 + loop9: for (int v25 = 0; v25 < 64; v25++) { // L56 + loop10: for (int v26 = 0; v26 < 10; v26++) { // L57 + #pragma HLS pipeline II=1 + loop11: for (int v27 = 0; v27 < 1; v27++) { // L58 + loop12: for (int v28 = 0; v28 < 4; v28++) { // L59 + loop13: for (int v29 = 0; v29 < 1; v29++) { // L60 + if ((v26 + v29) == 0) { // L61 + float v30 = v17[v27][v28].read(); // L62 + v23[(v24 + v27)][(v28 + (v25 * 4))] = v30; // L63 + } + float v31 = v23[(v24 + v27)][(v28 + (v25 * 4))]; // L65 + if ((v24 + v27) == 0) { // L66 + float v32 = v18[v28][v29].read(); // L67 + v22[(v28 + (v25 * 4))][(v26 + v29)] = v32; // L68 + } + float v33 = v22[(v28 + (v25 * 4))][(v26 + v29)]; // L70 + if ((v28 + (v25 * 4)) == 0) { // L71 + v21[(v24 + v27)][(v26 + v29)] = v20; // L72 + } + float v34 = v21[(v24 + v27)][(v26 + v29)]; // L74 + float v35 = v31 * v33; // L75 + float v36 = v34 + v35; // L76 + v21[(v24 + v27)][(v26 + v29)] = v36; // L77 + if (((v28 + (v25 * 4)) - 255) == 0) { // L78 + float v37 = v21[(v24 + v27)][(v26 + v29)]; // L79 + v19[v27][v29].write(v37); // L80 + } + } + } + } + } + } + } + return ; // L88 +} + +void node3( + float v38[10][256], + hls::stream v39[4][1] +) { // L90 + #pragma HLS array_partition variable=v38 cyclic dim=2 factor=4 + + loop14: for (int v40 = 0; v40 < 64; v40++) { // L91 + loop15: for (int v41 = 0; v41 < 10; v41++) { // L92 + #pragma HLS pipeline II=1 + loop16: for (int v42 = 0; v42 < 4; v42++) { // L93 + loop17: for (int v43 = 0; v43 < 1; v43++) { // L94 + float v44 = v38[(v41 + v43)][(v42 + (v40 * 4))]; // L95 + v39[v42][v43].write(v44); // L96 + } + } + } + } + return ; // L101 +} + +void node4( + hls::stream v45[1][4], + float v46[256], + hls::stream v47[1][4] +) { // L103 + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=4 + + loop18: for (int v48 = 0; v48 < 8; v48++) { // L104 + loop19: for (int v49 = 0; v49 < 64; v49++) { // L105 + #pragma HLS pipeline II=1 + loop20: for (int v50 = 0; v50 < 1; v50++) { // L106 + loop21: for (int v51 = 0; v51 < 4; v51++) { // L107 + float v52 = v45[v50][v51].read(); // L108 + float v53 = v46[(v51 + (v49 * 4))]; // L109 + float v54 = v52 + v53; // L110 + v47[v50][v51].write(v54); // L111 + } + } + } + } + return ; // L116 +} + +void node5( + hls::stream v55[16][4], + hls::stream v56[1][16], + hls::stream v57[1][4], + float v58 +) { // L118 + float v59[8][256]; // L119 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=4 + + float v60[512][256]; // L120 + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=4 + + float v61[8][512]; // L121 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=16 + + loop22: for (int v62 = 0; v62 < 8; v62++) { // L122 + loop23: for (int v63 = 0; v63 < 32; v63++) { // L123 + loop24: for (int v64 = 0; v64 < 64; v64++) { // L124 + #pragma HLS pipeline II=1 + loop25: for (int v65 = 0; v65 < 1; v65++) { // L125 + loop26: for (int v66 = 0; v66 < 16; v66++) { // L126 + loop27: for (int v67 = 0; v67 < 4; v67++) { // L127 + if ((v67 + (v64 * 4)) == 0) { // L128 + float v68 = v56[v65][v66].read(); // L129 + v61[(v62 + v65)][(v66 + (v63 * 16))] = v68; // L130 + } + float v69 = v61[(v62 + v65)][(v66 + (v63 * 16))]; // L132 + if ((v62 + v65) == 0) { // L133 + float v70 = v55[v66][v67].read(); // L134 + v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))] = v70; // L135 + } + float v71 = v60[(v66 + (v63 * 16))][(v67 + (v64 * 4))]; // L137 + if ((v66 + (v63 * 16)) == 0) { // L138 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v58; // L139 + } + float v72 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L141 + float v73 = v69 * v71; // L142 + float v74 = v72 + v73; // L143 + v59[(v62 + v65)][(v67 + (v64 * 4))] = v74; // L144 + if (((v66 + (v63 * 16)) - 511) == 0) { // L145 + float v75 = v59[(v62 + v65)][(v67 + (v64 * 4))]; // L146 + v57[v65][v67].write(v75); // L147 + } + } + } + } + } + } + } + return ; // L155 +} + +void node6( + float v76[256][512], + hls::stream v77[16][4] +) { // L157 + #pragma HLS array_partition variable=v76 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v76 cyclic dim=2 factor=16 + + loop28: for (int v78 = 0; v78 < 32; v78++) { // L158 + loop29: for (int v79 = 0; v79 < 64; v79++) { // L159 + #pragma HLS pipeline II=1 + loop30: for (int v80 = 0; v80 < 16; v80++) { // L160 + loop31: for (int v81 = 0; v81 < 4; v81++) { // L161 + float v82 = v76[(v81 + (v79 * 4))][(v80 + (v78 * 16))]; // L162 + v77[v80][v81].write(v82); // L163 + } + } + } + } + return ; // L168 +} + +void node7( + hls::stream v83[1][16], + float v84[512], + hls::stream v85[1][16], + hls::stream v86[1][16], + float v87 +) { // L170 + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=16 + + loop32: for (int v88 = 0; v88 < 8; v88++) { // L171 + loop33: for (int v89 = 0; v89 < 32; v89++) { // L172 + #pragma HLS pipeline II=1 + loop34: for (int v90 = 0; v90 < 1; v90++) { // L173 + loop35: for (int v91 = 0; v91 < 16; v91++) { // L174 + float v92 = v83[v90][v91].read(); // L175 + float v93 = v84[(v91 + (v89 * 16))]; // L176 + float v94 = v85[v90][v91].read(); // L177 + float v95 = v92 + v93; // L178 + float v96 = v95 + v94; // L179 + bool v97 = v96 > v87; // L180 + float v98 = v97 ? (float)v96 : (float)v87; // L181 + v86[v90][v91].write(v98); // L182 + } + } + } + } + return ; // L187 +} + +void node8( + hls::stream v99[16][16], + hls::stream v100[1][16], + hls::stream v101[1][16], + float v102 +) { // L189 + float v103[8][512]; // L190 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=16 + + float v104[512][512]; // L191 + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=16 + + float v105[8][512]; // L192 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=16 + + loop36: for (int v106 = 0; v106 < 8; v106++) { // L193 + loop37: for (int v107 = 0; v107 < 32; v107++) { // L194 + loop38: for (int v108 = 0; v108 < 32; v108++) { // L195 + #pragma HLS pipeline II=1 + loop39: for (int v109 = 0; v109 < 1; v109++) { // L196 + loop40: for (int v110 = 0; v110 < 16; v110++) { // L197 + loop41: for (int v111 = 0; v111 < 16; v111++) { // L198 + if ((v111 + (v108 * 16)) == 0) { // L199 + float v112 = v100[v109][v110].read(); // L200 + v105[(v106 + v109)][(v110 + (v107 * 16))] = v112; // L201 + } + float v113 = v105[(v106 + v109)][(v110 + (v107 * 16))]; // L203 + if ((v106 + v109) == 0) { // L204 + float v114 = v99[v110][v111].read(); // L205 + v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))] = v114; // L206 + } + float v115 = v104[(v110 + (v107 * 16))][(v111 + (v108 * 16))]; // L208 + if ((v110 + (v107 * 16)) == 0) { // L209 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v102; // L210 + } + float v116 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L212 + float v117 = v113 * v115; // L213 + float v118 = v116 + v117; // L214 + v103[(v106 + v109)][(v111 + (v108 * 16))] = v118; // L215 + if (((v110 + (v107 * 16)) - 511) == 0) { // L216 + float v119 = v103[(v106 + v109)][(v111 + (v108 * 16))]; // L217 + v101[v109][v111].write(v119); // L218 + } + } + } + } + } + } + } + return ; // L226 +} + +void node9( + float v120[512][512], + hls::stream v121[16][16] +) { // L228 + #pragma HLS array_partition variable=v120 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v120 cyclic dim=2 factor=16 + + loop42: for (int v122 = 0; v122 < 32; v122++) { // L229 + loop43: for (int v123 = 0; v123 < 32; v123++) { // L230 + #pragma HLS pipeline II=1 + loop44: for (int v124 = 0; v124 < 16; v124++) { // L231 + loop45: for (int v125 = 0; v125 < 16; v125++) { // L232 + float v126 = v120[(v125 + (v123 * 16))][(v124 + (v122 * 16))]; // L233 + v121[v124][v125].write(v126); // L234 + } + } + } + } + return ; // L239 +} + +void node10( + hls::stream v127[1][16], + hls::stream v128[1][16], + float v129 +) { // L241 + loop46: for (int v130 = 0; v130 < 8; v130++) { // L242 + loop47: for (int v131 = 0; v131 < 32; v131++) { // L243 + #pragma HLS pipeline II=1 + loop48: for (int v132 = 0; v132 < 1; v132++) { // L244 + loop49: for (int v133 = 0; v133 < 16; v133++) { // L245 + float v134 = v127[v132][v133].read(); // L246 + bool v135 = v134 > v129; // L247 + float v136 = v135 ? (float)v134 : (float)v129; // L248 + v128[v132][v133].write(v136); // L249 + } + } + } + } + return ; // L254 +} + +void node11( + hls::stream v137[1][16], + float v138[512], + hls::stream v139[1][16], + hls::stream v140[1][16] +) { // L256 + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=16 + + loop50: for (int v141 = 0; v141 < 8; v141++) { // L257 + loop51: for (int v142 = 0; v142 < 32; v142++) { // L258 + #pragma HLS pipeline II=1 + loop52: for (int v143 = 0; v143 < 1; v143++) { // L259 + loop53: for (int v144 = 0; v144 < 16; v144++) { // L260 + float v145 = v137[v143][v144].read(); // L261 + float v146 = v138[(v144 + (v142 * 16))]; // L262 + float v147 = v145 + v146; // L263 + v139[v143][v144].write(v147); // L264 + v140[v143][v144].write(v147); // L265 + } + } + } + } + return ; // L270 +} + +void node12( + float v148[8][1024], + hls::stream v149[8][16], + hls::stream v150[1][16], + float v151 +) { // L272 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=8 + + float v152[8][512]; // L273 + #pragma HLS array_partition variable=v152 cyclic dim=2 factor=16 + + float v153[1024][512]; // L274 + #pragma HLS array_partition variable=v153 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v153 cyclic dim=2 factor=16 + + loop54: for (int v154 = 0; v154 < 8; v154++) { // L275 + loop55: for (int v155 = 0; v155 < 128; v155++) { // L276 + loop56: for (int v156 = 0; v156 < 32; v156++) { // L277 + #pragma HLS pipeline II=1 + loop57: for (int v157 = 0; v157 < 1; v157++) { // L278 + loop58: for (int v158 = 0; v158 < 8; v158++) { // L279 + loop59: for (int v159 = 0; v159 < 16; v159++) { // L280 + float v160 = v148[(v154 + v157)][(v158 + (v155 * 8))]; // L281 + if ((v154 + v157) == 0) { // L282 + float v161 = v149[v158][v159].read(); // L283 + v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))] = v161; // L284 + } + float v162 = v153[(v158 + (v155 * 8))][(v159 + (v156 * 16))]; // L286 + if ((v158 + (v155 * 8)) == 0) { // L287 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v151; // L288 + } + float v163 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L290 + float v164 = v160 * v162; // L291 + float v165 = v163 + v164; // L292 + v152[(v154 + v157)][(v159 + (v156 * 16))] = v165; // L293 + if (((v158 + (v155 * 8)) - 1023) == 0) { // L294 + float v166 = v152[(v154 + v157)][(v159 + (v156 * 16))]; // L295 + v150[v157][v159].write(v166); // L296 + } + } + } + } + } + } + } + return ; // L304 +} + +void node13( + float v167[512][1024], + hls::stream v168[8][16] +) { // L306 + #pragma HLS array_partition variable=v167 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=8 + + loop60: for (int v169 = 0; v169 < 128; v169++) { // L307 + loop61: for (int v170 = 0; v170 < 32; v170++) { // L308 + #pragma HLS pipeline II=1 + loop62: for (int v171 = 0; v171 < 8; v171++) { // L309 + loop63: for (int v172 = 0; v172 < 16; v172++) { // L310 + float v173 = v167[(v172 + (v170 * 16))][(v171 + (v169 * 8))]; // L311 + v168[v171][v172].write(v173); // L312 + } + } + } + } + return ; // L317 +} + +void forward( + float v174[8][1024], + float v175[512], + float v176[512][1024], + float v177[512], + float v178[512][512], + float v179[256], + float v180[256][512], + float v181[10], + float v182[10][256], + float v183[8][10] +) { // L319 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v174 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v175 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v176 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v176 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v177 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v178 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v178 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v179 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v180 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v180 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v182 cyclic dim=2 factor=4 + + hls::stream v184[1][1]; + #pragma HLS STREAM variable=v184 depth=80 // L321 + hls::stream v185[1][1]; + #pragma HLS STREAM variable=v185 depth=80 // L322 + hls::stream v186[4][1]; + #pragma HLS STREAM variable=v186 depth=640 // L323 + hls::stream v187[1][4]; + #pragma HLS STREAM variable=v187 depth=512 // L324 + hls::stream v188[1][4]; + #pragma HLS STREAM variable=v188 depth=512 // L325 + hls::stream v189[16][4]; + #pragma HLS STREAM variable=v189 depth=2048 // L326 + hls::stream v190[1][16]; + #pragma HLS STREAM variable=v190 depth=256 // L327 + hls::stream v191[1][16]; + #pragma HLS STREAM variable=v191 depth=256 // L328 + hls::stream v192[16][16]; + #pragma HLS STREAM variable=v192 depth=1024 // L329 + hls::stream v193[1][16]; + #pragma HLS STREAM variable=v193 depth=256 // L330 + hls::stream v194[1][16]; + #pragma HLS STREAM variable=v194 depth=256 // L331 + hls::stream v195[1][16]; + #pragma HLS STREAM variable=v195 depth=256 // L332 + hls::stream v196[1][16]; + #pragma HLS STREAM variable=v196 depth=256 // L333 + hls::stream v197[8][16]; + #pragma HLS STREAM variable=v197 depth=4096 // L334 + node13(v176, v197); // L335 + node12(v174, v197, v196, 0.000000); // L336 + node11(v196, v175, v195, v194); // L337 + node10(v195, v193, 0.000000); // L338 + node9(v178, v192); // L339 + node8(v192, v193, v191, 0.000000); // L340 + node7(v191, v177, v194, v190, 0.000000); // L341 + node6(v180, v189); // L342 + node5(v189, v190, v188, 0.000000); // L343 + node4(v188, v179, v187); // L344 + node3(v182, v186); // L345 + node2(v187, v186, v185, 0.000000); // L346 + node1(v185, v181, v184); // L347 + node0(v184, v183); // L348 + return ; // L349 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt1/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt1/src/ResidualBlock.cpp new file mode 100644 index 000000000000..862e72ceb690 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt1/src/ResidualBlock.cpp @@ -0,0 +1,176 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { + #pragma HLS DATAFLOW + float v4[16][58][58]; + loop0: for (int v5 = 0; v5 < 16; v5++) { + loop1: for (int v6 = 0; v6 < 58; v6++) { + loop2: for (int v7 = 0; v7 < 58; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + v4[v5][v6][v7] = 0.000000; + } + } + } + loop3: for (int v8 = 0; v8 < 16; v8++) { + loop4: for (int v9 = 0; v9 < 56; v9++) { + loop5: for (int v10 = 0; v10 < 56; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v11 = v0[0][v8][v9][v10]; + v4[v8][(v9 + 1)][(v10 + 1)] = v11; + } + } + } + float v12[16][56][56]; + hls::stream v13("fifo_0"); + #pragma HLS STREAM variable=v13 depth=50176 + loop6: for (int v14 = 0; v14 < 16; v14++) { + loop7: for (int v15 = 0; v15 < 56; v15++) { + loop8: for (int v16 = 0; v16 < 56; v16++) { + loop9: for (int v17 = 0; v17 < 16; v17++) { + loop10: for (int v18 = 0; v18 < 3; v18++) { + loop11: for (int v19 = 0; v19 < 3; v19++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v20 = v4[v17][(v15 + v18)][(v16 + v19)]; + float v21 = v1[v14][v17][v18][v19]; + if (v17 == 0 && v18 == 0 && v19 == 0) { + v12[v14][v15][v16] = 0.000000; + } + float v22 = v12[v14][v15][v16]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v12[v14][v15][v16] = v24; + if ((v17 - 15) == 0 && (v18 - 2) == 0 && (v19 - 2) == 0) { + float v25 = v12[v14][v15][v16]; + v13.write(v25); + } + } + } + } + } + } + } + hls::stream v26("fifo_1"); + #pragma HLS STREAM variable=v26 depth=50176 + loop12: for (int v27 = 0; v27 < 16; v27++) { + loop13: for (int v28 = 0; v28 < 56; v28++) { + loop14: for (int v29 = 0; v29 < 56; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v30 = v13.read(); + float v31 = 0.000010; + float v32 = v31 + 1.000000; + float v33 = 1.0 / sqrt(v32); + float v34 = v30 * v33; + float v35 = v34 + 0.000000; + bool v36 = v35 > 0.000000; + float v37 = v36 ? (float)v35 : (float)0.000000; + v26.write(v37); + } + } + } + float v38[16][58][58]; + loop15: for (int v39 = 0; v39 < 16; v39++) { + loop16: for (int v40 = 0; v40 < 58; v40++) { + loop17: for (int v41 = 0; v41 < 58; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + v38[v39][v40][v41] = 0.000000; + } + } + } + loop18: for (int v42 = 0; v42 < 16; v42++) { + loop19: for (int v43 = 0; v43 < 56; v43++) { + loop20: for (int v44 = 0; v44 < 56; v44++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v45 = v26.read(); + v38[v42][(v43 + 1)][(v44 + 1)] = v45; + } + } + } + float v46[16][56][56]; + hls::stream v47("fifo_2"); + #pragma HLS STREAM variable=v47 depth=50176 + loop21: for (int v48 = 0; v48 < 16; v48++) { + loop22: for (int v49 = 0; v49 < 56; v49++) { + loop23: for (int v50 = 0; v50 < 56; v50++) { + loop24: for (int v51 = 0; v51 < 16; v51++) { + loop25: for (int v52 = 0; v52 < 3; v52++) { + loop26: for (int v53 = 0; v53 < 3; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v54 = v38[v51][(v49 + v52)][(v50 + v53)]; + float v55 = v2[v48][v51][v52][v53]; + if (v51 == 0 && v52 == 0 && v53 == 0) { + v46[v48][v49][v50] = 0.000000; + } + float v56 = v46[v48][v49][v50]; + float v57 = v54 * v55; + float v58 = v56 + v57; + v46[v48][v49][v50] = v58; + if ((v51 - 15) == 0 && (v52 - 2) == 0 && (v53 - 2) == 0) { + float v59 = v46[v48][v49][v50]; + v47.write(v59); + } + } + } + } + } + } + } + hls::stream v60("fifo_3"); + #pragma HLS STREAM variable=v60 depth=50176 + loop27: for (int v61 = 0; v61 < 16; v61++) { + loop28: for (int v62 = 0; v62 < 56; v62++) { + loop29: for (int v63 = 0; v63 < 56; v63++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v64 = v47.read(); + float v65 = v0[0][v61][v62][v63]; + float v66 = 0.000010; + float v67 = v66 + 1.000000; + float v68 = 1.0 / sqrt(v67); + float v69 = v64 * v68; + float v70 = v69 + 0.000000; + float v71 = v70 + v65; + bool v72 = v71 > 0.000000; + float v73 = v72 ? (float)v71 : (float)0.000000; + v60.write(v73); + } + } + } + loop30: for (int v74 = 0; v74 < 16; v74++) { + loop31: for (int v75 = 0; v75 < 56; v75++) { + loop32: for (int v76 = 0; v76 < 56; v76++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v77 = v60.read(); + v3[0][v74][v75][v76] = v77; + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt2/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt2/src/ResidualBlock.cpp new file mode 100644 index 000000000000..8b00eab7d1b6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt2/src/ResidualBlock.cpp @@ -0,0 +1,262 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[1][16][56][56] +) { // L6 + loop0: for (int v2 = 0; v2 < 56; v2++) { // L7 + loop1: for (int v3 = 0; v3 < 56; v3++) { // L8 + loop2: for (int v4 = 0; v4 < 16; v4++) { // L9 + #pragma HLS pipeline II=1 + float v5 = v0.read(); // L10 + v1[0][v4][v2][v3] = v5; // L11 + } + } + } + return ; // L15 +} + +void node1( + float v6[1][16][56][56], + hls::stream &v7, + hls::stream &v8, + double v9, + float v10, + float v11 +) { // L17 + loop3: for (int v12 = 0; v12 < 56; v12++) { // L18 + loop4: for (int v13 = 0; v13 < 56; v13++) { // L19 + loop5: for (int v14 = 0; v14 < 16; v14++) { // L20 + #pragma HLS pipeline II=1 + float v15 = v7.read(); // L21 + float v16 = v6[0][v14][v12][v13]; // L22 + float v17 = v9; // L23 + float v18 = v17 + v11; // L24 + float v19 = 1.0 / sqrt(v18); // L25 + float v20 = v15 * v19; // L26 + float v21 = v20 + v10; // L27 + float v22 = v21 + v16; // L28 + bool v23 = v22 > v10; // L29 + float v24 = v23 ? (float)v22 : (float)v10; // L30 + v8.write(v24); // L31 + } + } + } + return ; // L35 +} + +void node2( + hls::stream &v25, + float v26[16][16][3][3], + hls::stream &v27, + float v28 +) { // L37 + float v29[16]; // L38 + float v30[16][58][58]; // L39 + loop6: for (int v31 = 0; v31 < 58; v31++) { // L40 + loop7: for (int v32 = 0; v32 < 58; v32++) { // L41 + loop8: for (int v33 = 0; v33 < 16; v33++) { // L42 + loop9: for (int v34 = 0; v34 < 3; v34++) { // L43 + loop10: for (int v35 = 0; v35 < 3; v35++) { // L44 + loop11: for (int v36 = 0; v36 < 16; v36++) { // L45 + #pragma HLS pipeline II=1 + if (v36 == 0 && v34 == 0 && v35 == 0) { // L46 + float v37 = v25.read(); // L47 + v30[v33][v31][v32] = v37; // L48 + } + if ((v31 - 2) >= 0 && (v32 - 2) >= 0) { // L50 + float v38 = v30[v33][((v34 + v31) - 2)][((v35 + v32) - 2)]; // L51 + float v39 = v26[v36][v33][v34][v35]; // L52 + if (v33 == 0 && v34 == 0 && v35 == 0) { // L53 + v29[v36] = v28; // L54 + } + float v40 = v29[v36]; // L56 + float v41 = v38 * v39; // L57 + float v42 = v40 + v41; // L58 + v29[v36] = v42; // L59 + if ((v33 - 15) == 0 && (v34 - 2) == 0 && (v35 - 2) == 0) { // L60 + float v43 = v29[v36]; // L61 + v27.write(v43); // L62 + } + } + } + } + } + } + } + } + return ; // L71 +} + +void node3( + hls::stream &v44, + hls::stream &v45, + float v46 +) { // L73 + float v47[16][58][58]; // L74 + loop12: for (int v48 = 0; v48 < 58; v48++) { // L75 + loop13: for (int v49 = 0; v49 < 58; v49++) { // L76 + loop14: for (int v50 = 0; v50 < 16; v50++) { // L77 + #pragma HLS pipeline II=1 + v47[v50][v48][v49] = v46; // L78 + } + } + } + loop15: for (int v51 = 0; v51 < 58; v51++) { // L82 + loop16: for (int v52 = 0; v52 < 58; v52++) { // L83 + loop17: for (int v53 = 0; v53 < 16; v53++) { // L84 + #pragma HLS pipeline II=1 + if ((v51 - 1) >= 0 && (v52 - 1) >= 0 && ((-v51) + 56) >= 0 && ((-v52) + 56) >= 0) { // L85 + float v54 = v44.read(); // L86 + v47[v53][v51][v52] = v54; // L87 + } + float v55 = v47[v53][v51][v52]; // L89 + v45.write(v55); // L90 + } + } + } + return ; // L94 +} + +void node4( + hls::stream &v56, + hls::stream &v57, + double v58, + float v59, + float v60 +) { // L96 + loop18: for (int v61 = 0; v61 < 56; v61++) { // L97 + loop19: for (int v62 = 0; v62 < 56; v62++) { // L98 + loop20: for (int v63 = 0; v63 < 16; v63++) { // L99 + #pragma HLS pipeline II=1 + float v64 = v56.read(); // L100 + float v65 = v58; // L101 + float v66 = v65 + v59; // L102 + float v67 = 1.0 / sqrt(v66); // L103 + float v68 = v64 * v67; // L104 + float v69 = v68 + v60; // L105 + bool v70 = v69 > v60; // L106 + float v71 = v70 ? (float)v69 : (float)v60; // L107 + v57.write(v71); // L108 + } + } + } + return ; // L112 +} + +void node5( + float v72[16][16][3][3], + hls::stream &v73, + hls::stream &v74, + float v75 +) { // L114 + float v76[16]; // L115 + float v77[16][58][58]; // L116 + loop21: for (int v78 = 0; v78 < 58; v78++) { // L117 + loop22: for (int v79 = 0; v79 < 58; v79++) { // L118 + loop23: for (int v80 = 0; v80 < 3; v80++) { // L119 + loop24: for (int v81 = 0; v81 < 3; v81++) { // L120 + loop25: for (int v82 = 0; v82 < 16; v82++) { // L121 + loop26: for (int v83 = 0; v83 < 16; v83++) { // L122 + #pragma HLS pipeline II=1 + if (v83 == 0 && v80 == 0 && v81 == 0) { // L123 + float v84 = v73.read(); // L124 + v77[v82][v78][v79] = v84; // L125 + } + if ((v78 - 2) >= 0 && (v79 - 2) >= 0) { // L127 + float v85 = v77[v82][((v80 + v78) - 2)][((v81 + v79) - 2)]; // L128 + float v86 = v72[v83][v82][v80][v81]; // L129 + if (v82 == 0 && v80 == 0 && v81 == 0) { // L130 + v76[v83] = v75; // L131 + } + float v87 = v76[v83]; // L133 + float v88 = v85 * v86; // L134 + float v89 = v87 + v88; // L135 + v76[v83] = v89; // L136 + if ((v82 - 15) == 0 && (v80 - 2) == 0 && (v81 - 2) == 0) { // L137 + float v90 = v76[v83]; // L138 + v74.write(v90); // L139 + } + } + } + } + } + } + } + } + return ; // L148 +} + +void node6( + float v91[1][16][56][56], + hls::stream &v92, + float v93 +) { // L150 + float v94[16][58][58]; // L151 + loop27: for (int v95 = 0; v95 < 58; v95++) { // L152 + loop28: for (int v96 = 0; v96 < 58; v96++) { // L153 + loop29: for (int v97 = 0; v97 < 16; v97++) { // L154 + #pragma HLS pipeline II=1 + v94[v97][v95][v96] = v93; // L155 + } + } + } + loop30: for (int v98 = 0; v98 < 58; v98++) { // L159 + loop31: for (int v99 = 0; v99 < 58; v99++) { // L160 + loop32: for (int v100 = 0; v100 < 16; v100++) { // L161 + #pragma HLS pipeline II=1 + if ((v98 - 1) >= 0 && (v99 - 1) >= 0 && ((-v98) + 56) >= 0 && ((-v99) + 56) >= 0) { // L162 + float v101 = v91[0][v100][(v98 - 1)][(v99 - 1)]; // L163 + v94[v100][v98][v99] = v101; // L164 + } + float v102 = v94[v100][v98][v99]; // L166 + v92.write(v102); // L167 + } + } + } + return ; // L171 +} + +void forward( + float v103[1][16][56][56], + float v104[16][16][3][3], + float v105[16][16][3][3], + float v106[1][16][56][56] +) { // L173 + #pragma HLS DATAFLOW + hls::stream v107("fifo_0"); + #pragma HLS STREAM variable=v107 depth=50176 // L177 + hls::stream v108("fifo_1"); + #pragma HLS STREAM variable=v108 depth=50176 // L178 + hls::stream v109("fifo_2"); + #pragma HLS STREAM variable=v109 depth=53824 // L179 + hls::stream v110("fifo_3"); + #pragma HLS STREAM variable=v110 depth=50176 // L180 + hls::stream v111("fifo_4"); + #pragma HLS STREAM variable=v111 depth=50176 // L181 + hls::stream v112("fifo_5"); + #pragma HLS STREAM variable=v112 depth=53824 // L182 + node6(v103, v112, 0.000000); // L183 + node5(v104, v112, v111, 0.000000); // L184 + node4(v111, v110, 0.000010, 1.000000, 0.000000); // L185 + node3(v110, v109, 0.000000); // L186 + node2(v109, v105, v108, 0.000000); // L187 + node1(v103, v108, v107, 0.000010, 0.000000, 1.000000); // L188 + node0(v107, v106); // L189 + return ; // L190 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt3/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt3/src/ResidualBlock.cpp new file mode 100644 index 000000000000..1f61448e2b24 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt3/src/ResidualBlock.cpp @@ -0,0 +1,249 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { // L7 + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=7 + + float v4[16][58][58]; // L11 + loop0: for (int v5 = 0; v5 < 8; v5++) { // L12 + loop1: for (int v6 = 0; v6 < 29; v6++) { // L13 + loop2: for (int v7 = 0; v7 < 58; v7++) { // L14 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 2; v8++) { // L15 + loop4: for (int v9 = 0; v9 < 2; v9++) { // L16 + loop5: for (int v10 = 0; v10 < 1; v10++) { // L17 + v4[(v8 + (v5 * 2))][(v9 + (v6 * 2))][(v7 + v10)] = 0.000000; // L18 + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { // L25 + loop7: for (int v12 = 0; v12 < 28; v12++) { // L26 + loop8: for (int v13 = 0; v13 < 56; v13++) { // L27 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 2; v14++) { // L28 + loop10: for (int v15 = 0; v15 < 2; v15++) { // L29 + loop11: for (int v16 = 0; v16 < 1; v16++) { // L30 + float v17 = v0[0][(v14 + (v11 * 2))][(v15 + (v12 * 2))][(v13 + v16)]; // L31 + v4[(v14 + (v11 * 2))][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; // L32 + } + } + } + } + } + } + float v18[16][56][56]; // L39 + hls::stream v19[2][2][1]; + #pragma HLS STREAM variable=v19 depth=12544 // L40 + loop12: for (int v20 = 0; v20 < 8; v20++) { // L41 + loop13: for (int v21 = 0; v21 < 28; v21++) { // L42 + loop14: for (int v22 = 0; v22 < 56; v22++) { // L43 + loop15: for (int v23 = 0; v23 < 8; v23++) { // L44 + loop16: for (int v24 = 0; v24 < 3; v24++) { // L45 + loop17: for (int v25 = 0; v25 < 3; v25++) { // L46 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop18: for (int v26 = 0; v26 < 2; v26++) { // L47 + loop19: for (int v27 = 0; v27 < 2; v27++) { // L48 + loop20: for (int v28 = 0; v28 < 1; v28++) { // L49 + loop21: for (int v29 = 0; v29 < 2; v29++) { // L50 + loop22: for (int v30 = 0; v30 < 1; v30++) { // L51 + loop23: for (int v31 = 0; v31 < 1; v31++) { // L52 + float v32 = v4[(v29 + (v23 * 2))][(((v27 + (v21 * 2)) + v24) + v30)][(((v22 + v28) + v25) + v31)]; // L53 + float v33 = v1[(v26 + (v20 * 2))][(v29 + (v23 * 2))][(v24 + v30)][(v25 + v31)]; // L54 + if ((v29 + (v23 * 2)) == 0 && (v24 + v30) == 0 && (v25 + v31) == 0) { // L55 + v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)] = 0.000000; // L56 + } + float v34 = v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)]; // L58 + float v35 = v32 * v33; // L59 + float v36 = v34 + v35; // L60 + v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)] = v36; // L61 + if (((v29 + (v23 * 2)) - 15) == 0 && ((v24 + v30) - 2) == 0 && ((v25 + v31) - 2) == 0) { // L62 + float v37 = v18[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v22 + v28)]; // L63 + v19[v26][v27][v28].write(v37); // L64 + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v38[2][2][1]; + #pragma HLS STREAM variable=v38 depth=12544 // L78 + loop24: for (int v39 = 0; v39 < 8; v39++) { // L79 + loop25: for (int v40 = 0; v40 < 28; v40++) { // L80 + loop26: for (int v41 = 0; v41 < 56; v41++) { // L81 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop27: for (int v42 = 0; v42 < 2; v42++) { // L82 + loop28: for (int v43 = 0; v43 < 2; v43++) { // L83 + loop29: for (int v44 = 0; v44 < 1; v44++) { // L84 + float v45 = v19[v42][v43][v44].read(); // L85 + float v46 = 0.000010; // L86 + float v47 = v46 + 1.000000; // L87 + float v48 = 1.0 / sqrt(v47); // L88 + float v49 = v45 * v48; // L89 + float v50 = v49 + 0.000000; // L90 + bool v51 = v50 > 0.000000; // L91 + float v52 = v51 ? (float)v50 : (float)0.000000; // L92 + v38[v42][v43][v44].write(v52); // L93 + } + } + } + } + } + } + float v53[16][58][58]; // L100 + loop30: for (int v54 = 0; v54 < 8; v54++) { // L101 + loop31: for (int v55 = 0; v55 < 29; v55++) { // L102 + loop32: for (int v56 = 0; v56 < 58; v56++) { // L103 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v57 = 0; v57 < 2; v57++) { // L104 + loop34: for (int v58 = 0; v58 < 2; v58++) { // L105 + loop35: for (int v59 = 0; v59 < 1; v59++) { // L106 + v53[(v57 + (v54 * 2))][(v58 + (v55 * 2))][(v56 + v59)] = 0.000000; // L107 + } + } + } + } + } + } + loop36: for (int v60 = 0; v60 < 8; v60++) { // L114 + loop37: for (int v61 = 0; v61 < 28; v61++) { // L115 + loop38: for (int v62 = 0; v62 < 56; v62++) { // L116 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v63 = 0; v63 < 2; v63++) { // L117 + loop40: for (int v64 = 0; v64 < 2; v64++) { // L118 + loop41: for (int v65 = 0; v65 < 1; v65++) { // L119 + float v66 = v38[v63][v64][v65].read(); // L120 + v53[(v63 + (v60 * 2))][((v64 + (v61 * 2)) + 1)][((v62 + v65) + 1)] = v66; // L121 + } + } + } + } + } + } + float v67[16][56][56]; // L128 + hls::stream v68[2][2][7]; + #pragma HLS STREAM variable=v68 depth=1792 // L129 + loop42: for (int v69 = 0; v69 < 8; v69++) { // L130 + loop43: for (int v70 = 0; v70 < 28; v70++) { // L131 + loop44: for (int v71 = 0; v71 < 8; v71++) { // L132 + loop45: for (int v72 = 0; v72 < 8; v72++) { // L133 + loop46: for (int v73 = 0; v73 < 3; v73++) { // L134 + loop47: for (int v74 = 0; v74 < 3; v74++) { // L135 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v75 = 0; v75 < 2; v75++) { // L136 + loop49: for (int v76 = 0; v76 < 2; v76++) { // L137 + loop50: for (int v77 = 0; v77 < 7; v77++) { // L138 + loop51: for (int v78 = 0; v78 < 2; v78++) { // L139 + loop52: for (int v79 = 0; v79 < 1; v79++) { // L140 + loop53: for (int v80 = 0; v80 < 1; v80++) { // L141 + float v81 = v53[(v78 + (v72 * 2))][(((v76 + (v70 * 2)) + v73) + v79)][(((v77 + (v71 * 7)) + v74) + v80)]; // L142 + float v82 = v2[(v75 + (v69 * 2))][(v78 + (v72 * 2))][(v73 + v79)][(v74 + v80)]; // L143 + if ((v78 + (v72 * 2)) == 0 && (v73 + v79) == 0 && (v74 + v80) == 0) { // L144 + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))] = 0.000000; // L145 + } + float v83 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))]; // L147 + float v84 = v81 * v82; // L148 + float v85 = v83 + v84; // L149 + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))] = v85; // L150 + if (((v78 + (v72 * 2)) - 15) == 0 && ((v73 + v79) - 2) == 0 && ((v74 + v80) - 2) == 0) { // L151 + float v86 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v77 + (v71 * 7))]; // L152 + v68[v75][v76][v77].write(v86); // L153 + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v87[2][2][7]; + #pragma HLS STREAM variable=v87 depth=1792 // L167 + loop54: for (int v88 = 0; v88 < 8; v88++) { // L168 + loop55: for (int v89 = 0; v89 < 28; v89++) { // L169 + loop56: for (int v90 = 0; v90 < 8; v90++) { // L170 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v91 = 0; v91 < 2; v91++) { // L171 + loop58: for (int v92 = 0; v92 < 2; v92++) { // L172 + loop59: for (int v93 = 0; v93 < 7; v93++) { // L173 + float v94 = v68[v91][v92][v93].read(); // L174 + float v95 = v0[0][(v91 + (v88 * 2))][(v92 + (v89 * 2))][(v93 + (v90 * 7))]; // L175 + float v96 = 0.000010; // L176 + float v97 = v96 + 1.000000; // L177 + float v98 = 1.0 / sqrt(v97); // L178 + float v99 = v94 * v98; // L179 + float v100 = v99 + 0.000000; // L180 + float v101 = v100 + v95; // L181 + bool v102 = v101 > 0.000000; // L182 + float v103 = v102 ? (float)v101 : (float)0.000000; // L183 + v87[v91][v92][v93].write(v103); // L184 + } + } + } + } + } + } + loop60: for (int v104 = 0; v104 < 8; v104++) { // L191 + loop61: for (int v105 = 0; v105 < 28; v105++) { // L192 + loop62: for (int v106 = 0; v106 < 8; v106++) { // L193 + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v107 = 0; v107 < 2; v107++) { // L194 + loop64: for (int v108 = 0; v108 < 2; v108++) { // L195 + loop65: for (int v109 = 0; v109 < 7; v109++) { // L196 + float v110 = v87[v107][v108][v109].read(); // L197 + v3[0][(v107 + (v104 * 2))][(v108 + (v105 * 2))][(v109 + (v106 * 7))] = v110; // L198 + } + } + } + } + } + } + return ; // L205 +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt4/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt4/src/ResidualBlock.cpp new file mode 100644 index 000000000000..b7d0817fa8ca --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt4/src/ResidualBlock.cpp @@ -0,0 +1,249 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=7 + + float v4[16][58][58]; + loop0: for (int v5 = 0; v5 < 8; v5++) { + loop1: for (int v6 = 0; v6 < 58; v6++) { + loop2: for (int v7 = 0; v7 < 29; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 2; v8++) { + loop4: for (int v9 = 0; v9 < 1; v9++) { + loop5: for (int v10 = 0; v10 < 2; v10++) { + v4[(v8 + (v5 * 2))][(v10 + (v7 * 2))][(v6 + v9)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 56; v12++) { + loop8: for (int v13 = 0; v13 < 28; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 2; v14++) { + loop10: for (int v15 = 0; v15 < 1; v15++) { + loop11: for (int v16 = 0; v16 < 2; v16++) { + float v17 = v0[0][(v14 + (v11 * 2))][(v16 + (v13 * 2))][(v12 + v15)]; + v4[(v14 + (v11 * 2))][((v16 + (v13 * 2)) + 1)][((v12 + v15) + 1)] = v17; + } + } + } + } + } + } + float v18[16][56][56]; + hls::stream v19[2][2][1]; + #pragma HLS STREAM variable=v19 depth=12544 + loop12: for (int v20 = 0; v20 < 8; v20++) { + loop13: for (int v21 = 0; v21 < 8; v21++) { + loop14: for (int v22 = 0; v22 < 28; v22++) { + loop15: for (int v23 = 0; v23 < 3; v23++) { + loop16: for (int v24 = 0; v24 < 3; v24++) { + loop17: for (int v25 = 0; v25 < 56; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop18: for (int v26 = 0; v26 < 2; v26++) { + loop19: for (int v27 = 0; v27 < 2; v27++) { + loop20: for (int v28 = 0; v28 < 2; v28++) { + loop21: for (int v29 = 0; v29 < 1; v29++) { + loop22: for (int v30 = 0; v30 < 1; v30++) { + loop23: for (int v31 = 0; v31 < 1; v31++) { + float v32 = v4[(v27 + (v21 * 2))][(((v28 + (v22 * 2)) + v23) + v29)][(((v25 + v31) + v24) + v30)]; + float v33 = v1[(v26 + (v20 * 2))][(v27 + (v21 * 2))][(v23 + v29)][(v24 + v30)]; + if ((v27 + (v21 * 2)) == 0 && (v23 + v29) == 0 && (v24 + v30) == 0) { + v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)] = 0.000000; + } + float v34 = v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)]; + float v35 = v32 * v33; + float v36 = v34 + v35; + v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)] = v36; + if (((v27 + (v21 * 2)) - 15) == 0 && ((v23 + v29) - 2) == 0 && ((v24 + v30) - 2) == 0) { + float v37 = v18[(v26 + (v20 * 2))][(v28 + (v22 * 2))][(v25 + v31)]; + v19[v26][v28][v31].write(v37); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v38[2][2][1]; + #pragma HLS STREAM variable=v38 depth=12544 + loop24: for (int v39 = 0; v39 < 8; v39++) { + loop25: for (int v40 = 0; v40 < 28; v40++) { + loop26: for (int v41 = 0; v41 < 56; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop27: for (int v42 = 0; v42 < 2; v42++) { + loop28: for (int v43 = 0; v43 < 2; v43++) { + loop29: for (int v44 = 0; v44 < 1; v44++) { + float v45 = v19[v42][v43][v44].read(); + float v46 = 0.000010; + float v47 = v46 + 1.000000; + float v48 = 1.0 / sqrt(v47); + float v49 = v45 * v48; + float v50 = v49 + 0.000000; + bool v51 = v50 > 0.000000; + float v52 = v51 ? (float)v50 : (float)0.000000; + v38[v42][v43][v44].write(v52); + } + } + } + } + } + } + float v53[16][58][58]; + loop30: for (int v54 = 0; v54 < 8; v54++) { + loop31: for (int v55 = 0; v55 < 58; v55++) { + loop32: for (int v56 = 0; v56 < 29; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v57 = 0; v57 < 2; v57++) { + loop34: for (int v58 = 0; v58 < 1; v58++) { + loop35: for (int v59 = 0; v59 < 2; v59++) { + v53[(v57 + (v54 * 2))][(v59 + (v56 * 2))][(v55 + v58)] = 0.000000; + } + } + } + } + } + } + loop36: for (int v60 = 0; v60 < 8; v60++) { + loop37: for (int v61 = 0; v61 < 28; v61++) { + loop38: for (int v62 = 0; v62 < 56; v62++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v63 = 0; v63 < 2; v63++) { + loop40: for (int v64 = 0; v64 < 2; v64++) { + loop41: for (int v65 = 0; v65 < 1; v65++) { + float v66 = v38[v63][v64][v65].read(); + v53[(v63 + (v60 * 2))][((v64 + (v61 * 2)) + 1)][((v62 + v65) + 1)] = v66; + } + } + } + } + } + } + float v67[16][56][56]; + hls::stream v68[2][2][7]; + #pragma HLS STREAM variable=v68 depth=1792 + loop42: for (int v69 = 0; v69 < 8; v69++) { + loop43: for (int v70 = 0; v70 < 28; v70++) { + loop44: for (int v71 = 0; v71 < 8; v71++) { + loop45: for (int v72 = 0; v72 < 3; v72++) { + loop46: for (int v73 = 0; v73 < 3; v73++) { + loop47: for (int v74 = 0; v74 < 8; v74++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v75 = 0; v75 < 2; v75++) { + loop49: for (int v76 = 0; v76 < 2; v76++) { + loop50: for (int v77 = 0; v77 < 2; v77++) { + loop51: for (int v78 = 0; v78 < 1; v78++) { + loop52: for (int v79 = 0; v79 < 1; v79++) { + loop53: for (int v80 = 0; v80 < 7; v80++) { + float v81 = v53[(v77 + (v71 * 2))][(((v76 + (v70 * 2)) + v72) + v78)][(((v80 + (v74 * 7)) + v73) + v79)]; + float v82 = v2[(v75 + (v69 * 2))][(v77 + (v71 * 2))][(v72 + v78)][(v73 + v79)]; + if ((v77 + (v71 * 2)) == 0 && (v72 + v78) == 0 && (v73 + v79) == 0) { + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))] = 0.000000; + } + float v83 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))] = v85; + if (((v77 + (v71 * 2)) - 15) == 0 && ((v72 + v78) - 2) == 0 && ((v73 + v79) - 2) == 0) { + float v86 = v67[(v75 + (v69 * 2))][(v76 + (v70 * 2))][(v80 + (v74 * 7))]; + v68[v75][v76][v80].write(v86); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v87[2][2][7]; + #pragma HLS STREAM variable=v87 depth=1792 + loop54: for (int v88 = 0; v88 < 8; v88++) { + loop55: for (int v89 = 0; v89 < 28; v89++) { + loop56: for (int v90 = 0; v90 < 8; v90++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v91 = 0; v91 < 2; v91++) { + loop58: for (int v92 = 0; v92 < 2; v92++) { + loop59: for (int v93 = 0; v93 < 7; v93++) { + float v94 = v68[v91][v92][v93].read(); + float v95 = v0[0][(v91 + (v88 * 2))][(v92 + (v89 * 2))][(v93 + (v90 * 7))]; + float v96 = 0.000010; + float v97 = v96 + 1.000000; + float v98 = 1.0 / sqrt(v97); + float v99 = v94 * v98; + float v100 = v99 + 0.000000; + float v101 = v100 + v95; + bool v102 = v101 > 0.000000; + float v103 = v102 ? (float)v101 : (float)0.000000; + v87[v91][v92][v93].write(v103); + } + } + } + } + } + } + loop60: for (int v104 = 0; v104 < 8; v104++) { + loop61: for (int v105 = 0; v105 < 28; v105++) { + loop62: for (int v106 = 0; v106 < 8; v106++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v107 = 0; v107 < 2; v107++) { + loop64: for (int v108 = 0; v108 < 2; v108++) { + loop65: for (int v109 = 0; v109 < 7; v109++) { + float v110 = v87[v107][v108][v109].read(); + v3[0][(v107 + (v104 * 2))][(v108 + (v105 * 2))][(v109 + (v106 * 7))] = v110; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt5/src/ResidualBlock.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt5/src/ResidualBlock.cpp new file mode 100644 index 000000000000..9fea4e30213a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/ResidualBlock__opt5/src/ResidualBlock.cpp @@ -0,0 +1,249 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void forward( + float v0[1][16][56][56], + float v1[16][16][3][3], + float v2[16][16][3][3], + float v3[1][16][56][56] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v0 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v0 cyclic dim=3 factor=2 + + #pragma HLS array_partition variable=v3 cyclic dim=2 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=3 factor=2 + #pragma HLS array_partition variable=v3 cyclic dim=4 factor=7 + + float v4[16][58][58]; + loop0: for (int v5 = 0; v5 < 29; v5++) { + loop1: for (int v6 = 0; v6 < 8; v6++) { + loop2: for (int v7 = 0; v7 < 58; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 2; v8++) { + loop4: for (int v9 = 0; v9 < 2; v9++) { + loop5: for (int v10 = 0; v10 < 1; v10++) { + v4[(v9 + (v6 * 2))][(v8 + (v5 * 2))][(v7 + v10)] = 0.000000; + } + } + } + } + } + } + loop6: for (int v11 = 0; v11 < 8; v11++) { + loop7: for (int v12 = 0; v12 < 28; v12++) { + loop8: for (int v13 = 0; v13 < 56; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop9: for (int v14 = 0; v14 < 2; v14++) { + loop10: for (int v15 = 0; v15 < 2; v15++) { + loop11: for (int v16 = 0; v16 < 1; v16++) { + float v17 = v0[0][(v14 + (v11 * 2))][(v15 + (v12 * 2))][(v13 + v16)]; + v4[(v14 + (v11 * 2))][((v15 + (v12 * 2)) + 1)][((v13 + v16) + 1)] = v17; + } + } + } + } + } + } + float v18[16][56][56]; + hls::stream v19[2][2][1]; + #pragma HLS STREAM variable=v19 depth=12544 + loop12: for (int v20 = 0; v20 < 56; v20++) { + loop13: for (int v21 = 0; v21 < 8; v21++) { + loop14: for (int v22 = 0; v22 < 3; v22++) { + loop15: for (int v23 = 0; v23 < 3; v23++) { + loop16: for (int v24 = 0; v24 < 28; v24++) { + loop17: for (int v25 = 0; v25 < 8; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop18: for (int v26 = 0; v26 < 1; v26++) { + loop19: for (int v27 = 0; v27 < 2; v27++) { + loop20: for (int v28 = 0; v28 < 1; v28++) { + loop21: for (int v29 = 0; v29 < 1; v29++) { + loop22: for (int v30 = 0; v30 < 2; v30++) { + loop23: for (int v31 = 0; v31 < 2; v31++) { + float v32 = v4[(v27 + (v21 * 2))][(((v30 + (v24 * 2)) + v23) + v29)][(((v20 + v26) + v22) + v28)]; + float v33 = v1[(v31 + (v25 * 2))][(v27 + (v21 * 2))][(v23 + v29)][(v22 + v28)]; + if ((v27 + (v21 * 2)) == 0 && (v23 + v29) == 0 && (v22 + v28) == 0) { + v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)] = 0.000000; + } + float v34 = v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)]; + float v35 = v32 * v33; + float v36 = v34 + v35; + v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)] = v36; + if (((v27 + (v21 * 2)) - 15) == 0 && ((v23 + v29) - 2) == 0 && ((v22 + v28) - 2) == 0) { + float v37 = v18[(v31 + (v25 * 2))][(v30 + (v24 * 2))][(v20 + v26)]; + v19[v31][v30][v26].write(v37); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v38[2][2][1]; + #pragma HLS STREAM variable=v38 depth=12544 + loop24: for (int v39 = 0; v39 < 56; v39++) { + loop25: for (int v40 = 0; v40 < 28; v40++) { + loop26: for (int v41 = 0; v41 < 8; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop27: for (int v42 = 0; v42 < 1; v42++) { + loop28: for (int v43 = 0; v43 < 2; v43++) { + loop29: for (int v44 = 0; v44 < 2; v44++) { + float v45 = v19[v44][v43][v42].read(); + float v46 = 0.000010; + float v47 = v46 + 1.000000; + float v48 = 1.0 / sqrt(v47); + float v49 = v45 * v48; + float v50 = v49 + 0.000000; + bool v51 = v50 > 0.000000; + float v52 = v51 ? (float)v50 : (float)0.000000; + v38[v44][v43][v42].write(v52); + } + } + } + } + } + } + float v53[16][58][58]; + loop30: for (int v54 = 0; v54 < 8; v54++) { + loop31: for (int v55 = 0; v55 < 29; v55++) { + loop32: for (int v56 = 0; v56 < 58; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop33: for (int v57 = 0; v57 < 2; v57++) { + loop34: for (int v58 = 0; v58 < 2; v58++) { + loop35: for (int v59 = 0; v59 < 1; v59++) { + v53[(v57 + (v54 * 2))][(v58 + (v55 * 2))][(v56 + v59)] = 0.000000; + } + } + } + } + } + } + loop36: for (int v60 = 0; v60 < 56; v60++) { + loop37: for (int v61 = 0; v61 < 28; v61++) { + loop38: for (int v62 = 0; v62 < 8; v62++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop39: for (int v63 = 0; v63 < 1; v63++) { + loop40: for (int v64 = 0; v64 < 2; v64++) { + loop41: for (int v65 = 0; v65 < 2; v65++) { + float v66 = v38[v65][v64][v63].read(); + v53[(v65 + (v62 * 2))][((v64 + (v61 * 2)) + 1)][((v60 + v63) + 1)] = v66; + } + } + } + } + } + } + float v67[16][56][56]; + hls::stream v68[2][2][7]; + #pragma HLS STREAM variable=v68 depth=1792 + loop42: for (int v69 = 0; v69 < 8; v69++) { + loop43: for (int v70 = 0; v70 < 3; v70++) { + loop44: for (int v71 = 0; v71 < 28; v71++) { + loop45: for (int v72 = 0; v72 < 3; v72++) { + loop46: for (int v73 = 0; v73 < 8; v73++) { + loop47: for (int v74 = 0; v74 < 8; v74++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop48: for (int v75 = 0; v75 < 2; v75++) { + loop49: for (int v76 = 0; v76 < 1; v76++) { + loop50: for (int v77 = 0; v77 < 2; v77++) { + loop51: for (int v78 = 0; v78 < 1; v78++) { + loop52: for (int v79 = 0; v79 < 2; v79++) { + loop53: for (int v80 = 0; v80 < 7; v80++) { + float v81 = v53[(v75 + (v69 * 2))][(((v77 + (v71 * 2)) + v72) + v78)][(((v80 + (v74 * 7)) + v70) + v76)]; + float v82 = v2[(v79 + (v73 * 2))][(v75 + (v69 * 2))][(v72 + v78)][(v70 + v76)]; + if ((v75 + (v69 * 2)) == 0 && (v72 + v78) == 0 && (v70 + v76) == 0) { + v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))] = 0.000000; + } + float v83 = v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))] = v85; + if (((v75 + (v69 * 2)) - 15) == 0 && ((v72 + v78) - 2) == 0 && ((v70 + v76) - 2) == 0) { + float v86 = v67[(v79 + (v73 * 2))][(v77 + (v71 * 2))][(v80 + (v74 * 7))]; + v68[v79][v77][v80].write(v86); + } + } + } + } + } + } + } + } + } + } + } + } + } + hls::stream v87[2][2][7]; + #pragma HLS STREAM variable=v87 depth=1792 + loop54: for (int v88 = 0; v88 < 28; v88++) { + loop55: for (int v89 = 0; v89 < 8; v89++) { + loop56: for (int v90 = 0; v90 < 8; v90++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop57: for (int v91 = 0; v91 < 2; v91++) { + loop58: for (int v92 = 0; v92 < 2; v92++) { + loop59: for (int v93 = 0; v93 < 7; v93++) { + float v94 = v68[v92][v91][v93].read(); + float v95 = v0[0][(v92 + (v89 * 2))][(v91 + (v88 * 2))][(v93 + (v90 * 7))]; + float v96 = 0.000010; + float v97 = v96 + 1.000000; + float v98 = 1.0 / sqrt(v97); + float v99 = v94 * v98; + float v100 = v99 + 0.000000; + float v101 = v100 + v95; + bool v102 = v101 > 0.000000; + float v103 = v102 ? (float)v101 : (float)0.000000; + v87[v92][v91][v93].write(v103); + } + } + } + } + } + } + loop60: for (int v104 = 0; v104 < 28; v104++) { + loop61: for (int v105 = 0; v105 < 8; v105++) { + loop62: for (int v106 = 0; v106 < 8; v106++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop63: for (int v107 = 0; v107 < 2; v107++) { + loop64: for (int v108 = 0; v108 < 2; v108++) { + loop65: for (int v109 = 0; v109 < 7; v109++) { + float v110 = v87[v108][v107][v109].read(); + v3[0][(v108 + (v105 * 2))][(v107 + (v104 * 2))][(v109 + (v106 * 7))] = v110; + } + } + } + } + } + } + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt1/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt1/src/atax.cpp new file mode 100644 index 000000000000..d001dd12801f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt1/src/atax.cpp @@ -0,0 +1,125 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + float v4[410][390], + hls::stream &v5, + hls::stream &v6, + float v7 +) { + float v8[410]; + float v9[390]; + loop1: for (int v10 = 0; v10 < 410; v10++) { + loop2: for (int v11 = 0; v11 < 390; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v4[v10][v11]; + if (v10 == 0) { + float v13 = v5.read(); + v9[v11] = v13; + } + float v14 = v9[v11]; + if (v11 == 0) { + v8[v10] = v7; + } + float v15 = v8[v10]; + float v16 = v12 * v14; + float v17 = v15 + v16; + v8[v10] = v17; + if ((v11 - 389) == 0) { + float v18 = v8[v10]; + v6.write(v18); + } + } + } + return ; +} + +void node2( + float v19[390][410], + float v20[410][390] +) { + loop3: for (int v21 = 0; v21 < 390; v21++) { + loop4: for (int v22 = 0; v22 < 410; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v19[v21][v22]; + v20[v22][v21] = v23; + } + } + return ; +} + +void node3( + float v24[390][410], + float v25[410], + hls::stream &v26, + float v27 +) { + float v28[390]; + loop5: for (int v29 = 0; v29 < 390; v29++) { + loop6: for (int v30 = 0; v30 < 410; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v31 = v24[v29][v30]; + float v32 = v25[v30]; + if (v30 == 0) { + v28[v29] = v27; + } + float v33 = v28[v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v28[v29] = v35; + if ((v30 - 409) == 0) { + float v36 = v28[v29]; + v26.write(v36); + } + } + } + return ; +} + +void forward( + float v37[390][410], + float v38[410], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + float v41[410][390]; + hls::stream v42("fifo_1"); + #pragma HLS STREAM variable=v42 depth=390 + node3(v37, v38, v42, 0.000000); + node2(v37, v41); + node1(v41, v42, v40, 0.000000); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt2/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt2/src/atax.cpp new file mode 100644 index 000000000000..d2f1527f0b2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt2/src/atax.cpp @@ -0,0 +1,126 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + hls::stream &v5, + hls::stream &v6, + float v7 +) { + float v8[410]; + float v9[390]; + loop1: for (int v10 = 0; v10 < 390; v10++) { + loop2: for (int v11 = 0; v11 < 410; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v4.read(); + if (v11 == 0) { + float v13 = v5.read(); + v9[v10] = v13; + } + float v14 = v9[v10]; + if (v10 == 0) { + v8[v11] = v7; + } + float v15 = v8[v11]; + float v16 = v12 * v14; + float v17 = v15 + v16; + v8[v11] = v17; + if ((v10 - 389) == 0) { + float v18 = v8[v11]; + v6.write(v18); + } + } + } + return ; +} + +void node2( + float v19[390][410], + hls::stream &v20 +) { + loop3: for (int v21 = 0; v21 < 390; v21++) { + loop4: for (int v22 = 0; v22 < 410; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v19[v21][v22]; + v20.write(v23); + } + } + return ; +} + +void node3( + float v24[390][410], + float v25[410], + hls::stream &v26, + float v27 +) { + float v28[390]; + loop5: for (int v29 = 0; v29 < 410; v29++) { + loop6: for (int v30 = 0; v30 < 390; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v31 = v24[v30][v29]; + float v32 = v25[v29]; + if (v29 == 0) { + v28[v30] = v27; + } + float v33 = v28[v30]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v28[v30] = v35; + if ((v29 - 409) == 0) { + float v36 = v28[v30]; + v26.write(v36); + } + } + } + return ; +} + +void forward( + float v37[390][410], + float v38[410], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + hls::stream v41("fifo_1"); + #pragma HLS STREAM variable=v41 depth=159900 + hls::stream v42("fifo_2"); + #pragma HLS STREAM variable=v42 depth=390 + node3(v37, v38, v42, 0.000000); + node2(v37, v41); + node1(v41, v42, v40, 0.000000); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt3/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt3/src/atax.cpp new file mode 100644 index 000000000000..5042b43fe8c3 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt3/src/atax.cpp @@ -0,0 +1,171 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + float v5[410][390], + hls::stream v6[15], + hls::stream v7[10], + float v8 +) { + #pragma HLS array_partition variable=v5 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v5 cyclic dim=2 factor=15 + + float v9[410]; + #pragma HLS array_partition variable=v9 cyclic dim=1 factor=10 + + float v10[390]; + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=15 + + loop2: for (int v11 = 0; v11 < 41; v11++) { + loop3: for (int v12 = 0; v12 < 26; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop4: for (int v13 = 0; v13 < 10; v13++) { + loop5: for (int v14 = 0; v14 < 15; v14++) { + float v15 = v5[(v13 + (v11 * 10))][(v14 + (v12 * 15))]; + if ((v13 + (v11 * 10)) == 0) { + float v16 = v6[v14].read(); + v10[(v14 + (v12 * 15))] = v16; + } + float v17 = v10[(v14 + (v12 * 15))]; + if ((v14 + (v12 * 15)) == 0) { + v9[(v13 + (v11 * 10))] = v8; + } + float v18 = v9[(v13 + (v11 * 10))]; + float v19 = v15 * v17; + float v20 = v18 + v19; + v9[(v13 + (v11 * 10))] = v20; + if (((v14 + (v12 * 15)) - 389) == 0) { + float v21 = v9[(v13 + (v11 * 10))]; + v7[v13].write(v21); + } + } + } + } + } + return ; +} + +void node2( + float v22[390][410], + float v23[410][390] +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=15 + + loop6: for (int v24 = 0; v24 < 26; v24++) { + loop7: for (int v25 = 0; v25 < 41; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop8: for (int v26 = 0; v26 < 15; v26++) { + loop9: for (int v27 = 0; v27 < 10; v27++) { + float v28 = v22[(v26 + (v24 * 15))][(v27 + (v25 * 10))]; + v23[(v27 + (v25 * 10))][(v26 + (v24 * 15))] = v28; + } + } + } + } + return ; +} + +void node3( + float v29[390][410], + float v30[410], + hls::stream v31[15], + float v32 +) { + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + + float v33[390]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=15 + + loop10: for (int v34 = 0; v34 < 26; v34++) { + loop11: for (int v35 = 0; v35 < 41; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop12: for (int v36 = 0; v36 < 15; v36++) { + loop13: for (int v37 = 0; v37 < 10; v37++) { + float v38 = v29[(v36 + (v34 * 15))][(v37 + (v35 * 10))]; + float v39 = v30[(v37 + (v35 * 10))]; + if ((v37 + (v35 * 10)) == 0) { + v33[(v36 + (v34 * 15))] = v32; + } + float v40 = v33[(v36 + (v34 * 15))]; + float v41 = v38 * v39; + float v42 = v40 + v41; + v33[(v36 + (v34 * 15))] = v42; + if (((v37 + (v35 * 10)) - 409) == 0) { + float v43 = v33[(v36 + (v34 * 15))]; + v31[v36].write(v43); + } + } + } + } + } + return ; +} + +void forward( + float v44[390][410], + float v45[410], + float v46[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v44 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + + hls::stream v47[10]; + #pragma HLS STREAM variable=v47 depth=41 + float v48[410][390]; + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=15 + + hls::stream v49[15]; + #pragma HLS STREAM variable=v49 depth=26 + node3(v44, v45, v49, 0.000000); + node2(v44, v48); + node1(v48, v49, v47, 0.000000); + node0(v47, v46); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt4/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt4/src/atax.cpp new file mode 100644 index 000000000000..397622093e65 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt4/src/atax.cpp @@ -0,0 +1,163 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10][15], + hls::stream v6[15], + hls::stream v7[10], + float v8 +) { + float v9[410]; + #pragma HLS array_partition variable=v9 cyclic dim=1 factor=10 + + float v10[390]; + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=15 + + loop2: for (int v11 = 0; v11 < 26; v11++) { + loop3: for (int v12 = 0; v12 < 41; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop4: for (int v13 = 0; v13 < 15; v13++) { + loop5: for (int v14 = 0; v14 < 10; v14++) { + float v15 = v5[v14][v13].read(); + if ((v14 + (v12 * 10)) == 0) { + float v16 = v6[v13].read(); + v10[(v13 + (v11 * 15))] = v16; + } + float v17 = v10[(v13 + (v11 * 15))]; + if ((v13 + (v11 * 15)) == 0) { + v9[(v14 + (v12 * 10))] = v8; + } + float v18 = v9[(v14 + (v12 * 10))]; + float v19 = v15 * v17; + float v20 = v18 + v19; + v9[(v14 + (v12 * 10))] = v20; + if (((v13 + (v11 * 15)) - 389) == 0) { + float v21 = v9[(v14 + (v12 * 10))]; + v7[v14].write(v21); + } + } + } + } + } + return ; +} + +void node2( + float v22[390][410], + hls::stream v23[10][15] +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + loop6: for (int v24 = 0; v24 < 26; v24++) { + loop7: for (int v25 = 0; v25 < 41; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop8: for (int v26 = 0; v26 < 15; v26++) { + loop9: for (int v27 = 0; v27 < 10; v27++) { + float v28 = v22[(v26 + (v24 * 15))][(v27 + (v25 * 10))]; + v23[v27][v26].write(v28); + } + } + } + } + return ; +} + +void node3( + float v29[390][410], + float v30[410], + hls::stream v31[15], + float v32 +) { + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + + float v33[390]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=15 + + loop10: for (int v34 = 0; v34 < 41; v34++) { + loop11: for (int v35 = 0; v35 < 26; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop12: for (int v36 = 0; v36 < 10; v36++) { + loop13: for (int v37 = 0; v37 < 15; v37++) { + float v38 = v29[(v37 + (v35 * 15))][(v36 + (v34 * 10))]; + float v39 = v30[(v36 + (v34 * 10))]; + if ((v36 + (v34 * 10)) == 0) { + v33[(v37 + (v35 * 15))] = v32; + } + float v40 = v33[(v37 + (v35 * 15))]; + float v41 = v38 * v39; + float v42 = v40 + v41; + v33[(v37 + (v35 * 15))] = v42; + if (((v36 + (v34 * 10)) - 409) == 0) { + float v43 = v33[(v37 + (v35 * 15))]; + v31[v37].write(v43); + } + } + } + } + } + return ; +} + +void forward( + float v44[390][410], + float v45[410], + float v46[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v44 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + + hls::stream v47[10]; + #pragma HLS STREAM variable=v47 depth=41 + hls::stream v48[10][15]; + #pragma HLS STREAM variable=v48 depth=1066 + hls::stream v49[15]; + #pragma HLS STREAM variable=v49 depth=26 + node3(v44, v45, v49, 0.000000); + node2(v44, v48); + node1(v48, v49, v47, 0.000000); + node0(v47, v46); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt5/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt5/src/atax.cpp new file mode 100644 index 000000000000..4981e44779af --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/atax__opt5/src/atax.cpp @@ -0,0 +1,163 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + hls::stream v6[10][15], + hls::stream v7[10], + float v8 +) { + float v9[410]; + #pragma HLS array_partition variable=v9 cyclic dim=1 factor=10 + + float v10[390]; + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=15 + + loop2: for (int v11 = 0; v11 < 26; v11++) { + loop3: for (int v12 = 0; v12 < 41; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop4: for (int v13 = 0; v13 < 15; v13++) { + loop5: for (int v14 = 0; v14 < 10; v14++) { + float v15 = v6[v14][v13].read(); + if ((v14 + (v12 * 10)) == 0) { + float v16 = v5[v13].read(); + v10[(v13 + (v11 * 15))] = v16; + } + float v17 = v10[(v13 + (v11 * 15))]; + if ((v13 + (v11 * 15)) == 0) { + v9[(v14 + (v12 * 10))] = v8; + } + float v18 = v9[(v14 + (v12 * 10))]; + float v19 = v15 * v17; + float v20 = v18 + v19; + v9[(v14 + (v12 * 10))] = v20; + if (((v13 + (v11 * 15)) - 389) == 0) { + float v21 = v9[(v14 + (v12 * 10))]; + v7[v14].write(v21); + } + } + } + } + } + return ; +} + +void node2( + float v22[390][410], + hls::stream v23[10][15] +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + loop6: for (int v24 = 0; v24 < 26; v24++) { + loop7: for (int v25 = 0; v25 < 41; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop8: for (int v26 = 0; v26 < 15; v26++) { + loop9: for (int v27 = 0; v27 < 10; v27++) { + float v28 = v22[(v26 + (v24 * 15))][(v27 + (v25 * 10))]; + v23[v27][v26].write(v28); + } + } + } + } + return ; +} + +void node3( + float v29[390][410], + float v30[410], + hls::stream v31[15], + float v32 +) { + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + + float v33[390]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=15 + + loop10: for (int v34 = 0; v34 < 41; v34++) { + loop11: for (int v35 = 0; v35 < 26; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop12: for (int v36 = 0; v36 < 10; v36++) { + loop13: for (int v37 = 0; v37 < 15; v37++) { + float v38 = v29[(v37 + (v35 * 15))][(v36 + (v34 * 10))]; + float v39 = v30[(v36 + (v34 * 10))]; + if ((v36 + (v34 * 10)) == 0) { + v33[(v37 + (v35 * 15))] = v32; + } + float v40 = v33[(v37 + (v35 * 15))]; + float v41 = v38 * v39; + float v42 = v40 + v41; + v33[(v37 + (v35 * 15))] = v42; + if (((v36 + (v34 * 10)) - 409) == 0) { + float v43 = v33[(v37 + (v35 * 15))]; + v31[v37].write(v43); + } + } + } + } + } + return ; +} + +void forward( + float v44[390][410], + float v45[410], + float v46[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v44 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + + hls::stream v47[10]; + #pragma HLS STREAM variable=v47 depth=41 + hls::stream v48[10][15]; + #pragma HLS STREAM variable=v48 depth=1066 + hls::stream v49[15]; + #pragma HLS STREAM variable=v49 depth=26 + node3(v44, v45, v49, 0.000000); + node2(v44, v48); + node1(v49, v48, v47, 0.000000); + node0(v47, v46); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt1/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt1/src/bicg.cpp new file mode 100644 index 000000000000..92ecf2126eeb --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt1/src/bicg.cpp @@ -0,0 +1,120 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[390] +) { + loop1: for (int v6 = 0; v6 < 390; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + float v8[410][390], + float v9[390], + hls::stream &v10, + float v11 +) { + float v12[410]; + loop2: for (int v13 = 0; v13 < 410; v13++) { + loop3: for (int v14 = 0; v14 < 390; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8[v13][v14]; + float v16 = v9[v14]; + if (v14 == 0) { + v12[v13] = v11; + } + float v17 = v12[v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v13] = v19; + if ((v14 - 389) == 0) { + float v20 = v12[v13]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[410], + float v22[410][390], + hls::stream &v23, + float v24 +) { + float v25[390]; + loop4: for (int v26 = 0; v26 < 390; v26++) { + loop5: for (int v27 = 0; v27 < 410; v27++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v28 = v21[v27]; + float v29 = v22[v27][v26]; + if (v27 == 0) { + v25[v26] = v24; + } + float v30 = v25[v26]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v25[v26] = v32; + if ((v27 - 409) == 0) { + float v33 = v25[v26]; + v23.write(v33); + } + } + } + return ; +} + +void forward( + float v34[410][390], + float v35[410][390], + float v36[410], + float v37[390], + float v38[390], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + hls::stream v41("fifo_1"); + #pragma HLS STREAM variable=v41 depth=390 + node3(v36, v34, v41, 0.000000); + node2(v35, v37, v40, 0.000000); + node1(v41, v38); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt2/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt2/src/bicg.cpp new file mode 100644 index 000000000000..dd7eee778e94 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt2/src/bicg.cpp @@ -0,0 +1,120 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[390] +) { + loop1: for (int v6 = 0; v6 < 390; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + float v8[410][390], + float v9[390], + hls::stream &v10, + float v11 +) { + float v12[410]; + loop2: for (int v13 = 0; v13 < 390; v13++) { + loop3: for (int v14 = 0; v14 < 410; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8[v14][v13]; + float v16 = v9[v13]; + if (v13 == 0) { + v12[v14] = v11; + } + float v17 = v12[v14]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v14] = v19; + if ((v13 - 389) == 0) { + float v20 = v12[v14]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[410], + float v22[410][390], + hls::stream &v23, + float v24 +) { + float v25[390]; + loop4: for (int v26 = 0; v26 < 410; v26++) { + loop5: for (int v27 = 0; v27 < 390; v27++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v28 = v21[v26]; + float v29 = v22[v26][v27]; + if (v26 == 0) { + v25[v27] = v24; + } + float v30 = v25[v27]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v25[v27] = v32; + if ((v26 - 409) == 0) { + float v33 = v25[v27]; + v23.write(v33); + } + } + } + return ; +} + +void forward( + float v34[410][390], + float v35[410][390], + float v36[410], + float v37[390], + float v38[390], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + hls::stream v41("fifo_1"); + #pragma HLS STREAM variable=v41 depth=390 + node3(v36, v34, v41, 0.000000); + node2(v35, v37, v40, 0.000000); + node1(v41, v38); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt3/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt3/src/bicg.cpp new file mode 100644 index 000000000000..b4b049330583 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt3/src/bicg.cpp @@ -0,0 +1,164 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + float v6[390] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=15 + + loop2: for (int v7 = 0; v7 < 26; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 15; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 15))] = v9; + } + } + return ; +} + +void node2( + float v10[410][390], + float v11[390], + hls::stream v12[10], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=15 + + float v14[410]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=10 + + loop4: for (int v15 = 0; v15 < 41; v15++) { + loop5: for (int v16 = 0; v16 < 26; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 10; v17++) { + loop7: for (int v18 = 0; v18 < 15; v18++) { + float v19 = v10[(v17 + (v15 * 10))][(v18 + (v16 * 15))]; + float v20 = v11[(v18 + (v16 * 15))]; + if ((v18 + (v16 * 15)) == 0) { + v14[(v17 + (v15 * 10))] = v13; + } + float v21 = v14[(v17 + (v15 * 10))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v17 + (v15 * 10))] = v23; + if (((v18 + (v16 * 15)) - 389) == 0) { + float v24 = v14[(v17 + (v15 * 10))]; + v12[v17].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[410], + float v26[410][390], + hls::stream v27[15], + float v28 +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=15 + + float v29[390]; + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + + loop8: for (int v30 = 0; v30 < 26; v30++) { + loop9: for (int v31 = 0; v31 < 41; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v32 = 0; v32 < 15; v32++) { + loop11: for (int v33 = 0; v33 < 10; v33++) { + float v34 = v25[(v33 + (v31 * 10))]; + float v35 = v26[(v33 + (v31 * 10))][(v32 + (v30 * 15))]; + if ((v33 + (v31 * 10)) == 0) { + v29[(v32 + (v30 * 15))] = v28; + } + float v36 = v29[(v32 + (v30 * 15))]; + float v37 = v34 * v35; + float v38 = v36 + v37; + v29[(v32 + (v30 * 15))] = v38; + if (((v33 + (v31 * 10)) - 409) == 0) { + float v39 = v29[(v32 + (v30 * 15))]; + v27[v32].write(v39); + } + } + } + } + } + return ; +} + +void forward( + float v40[410][390], + float v41[410][390], + float v42[410], + float v43[390], + float v44[390], + float v45[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + hls::stream v46[10]; + #pragma HLS STREAM variable=v46 depth=41 + hls::stream v47[15]; + #pragma HLS STREAM variable=v47 depth=26 + node3(v42, v40, v47, 0.000000); + node2(v41, v43, v46, 0.000000); + node1(v47, v44); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt4/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt4/src/bicg.cpp new file mode 100644 index 000000000000..885cebfce0d2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt4/src/bicg.cpp @@ -0,0 +1,164 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + float v6[390] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=15 + + loop2: for (int v7 = 0; v7 < 26; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 15; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 15))] = v9; + } + } + return ; +} + +void node2( + float v10[410][390], + float v11[390], + hls::stream v12[10], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=15 + + float v14[410]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=10 + + loop4: for (int v15 = 0; v15 < 26; v15++) { + loop5: for (int v16 = 0; v16 < 41; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 15; v17++) { + loop7: for (int v18 = 0; v18 < 10; v18++) { + float v19 = v10[(v18 + (v16 * 10))][(v17 + (v15 * 15))]; + float v20 = v11[(v17 + (v15 * 15))]; + if ((v17 + (v15 * 15)) == 0) { + v14[(v18 + (v16 * 10))] = v13; + } + float v21 = v14[(v18 + (v16 * 10))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 10))] = v23; + if (((v17 + (v15 * 15)) - 389) == 0) { + float v24 = v14[(v18 + (v16 * 10))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[410], + float v26[410][390], + hls::stream v27[15], + float v28 +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=15 + + float v29[390]; + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + + loop8: for (int v30 = 0; v30 < 41; v30++) { + loop9: for (int v31 = 0; v31 < 26; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v32 = 0; v32 < 10; v32++) { + loop11: for (int v33 = 0; v33 < 15; v33++) { + float v34 = v25[(v32 + (v30 * 10))]; + float v35 = v26[(v32 + (v30 * 10))][(v33 + (v31 * 15))]; + if ((v32 + (v30 * 10)) == 0) { + v29[(v33 + (v31 * 15))] = v28; + } + float v36 = v29[(v33 + (v31 * 15))]; + float v37 = v34 * v35; + float v38 = v36 + v37; + v29[(v33 + (v31 * 15))] = v38; + if (((v32 + (v30 * 10)) - 409) == 0) { + float v39 = v29[(v33 + (v31 * 15))]; + v27[v33].write(v39); + } + } + } + } + } + return ; +} + +void forward( + float v40[410][390], + float v41[410][390], + float v42[410], + float v43[390], + float v44[390], + float v45[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + hls::stream v46[10]; + #pragma HLS STREAM variable=v46 depth=41 + hls::stream v47[15]; + #pragma HLS STREAM variable=v47 depth=26 + node3(v42, v40, v47, 0.000000); + node2(v41, v43, v46, 0.000000); + node1(v47, v44); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt5/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt5/src/bicg.cpp new file mode 100644 index 000000000000..885cebfce0d2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/bicg__opt5/src/bicg.cpp @@ -0,0 +1,164 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + float v6[390] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=15 + + loop2: for (int v7 = 0; v7 < 26; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 15; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 15))] = v9; + } + } + return ; +} + +void node2( + float v10[410][390], + float v11[390], + hls::stream v12[10], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=15 + + float v14[410]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=10 + + loop4: for (int v15 = 0; v15 < 26; v15++) { + loop5: for (int v16 = 0; v16 < 41; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 15; v17++) { + loop7: for (int v18 = 0; v18 < 10; v18++) { + float v19 = v10[(v18 + (v16 * 10))][(v17 + (v15 * 15))]; + float v20 = v11[(v17 + (v15 * 15))]; + if ((v17 + (v15 * 15)) == 0) { + v14[(v18 + (v16 * 10))] = v13; + } + float v21 = v14[(v18 + (v16 * 10))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 10))] = v23; + if (((v17 + (v15 * 15)) - 389) == 0) { + float v24 = v14[(v18 + (v16 * 10))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[410], + float v26[410][390], + hls::stream v27[15], + float v28 +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=15 + + float v29[390]; + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + + loop8: for (int v30 = 0; v30 < 41; v30++) { + loop9: for (int v31 = 0; v31 < 26; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v32 = 0; v32 < 10; v32++) { + loop11: for (int v33 = 0; v33 < 15; v33++) { + float v34 = v25[(v32 + (v30 * 10))]; + float v35 = v26[(v32 + (v30 * 10))][(v33 + (v31 * 15))]; + if ((v32 + (v30 * 10)) == 0) { + v29[(v33 + (v31 * 15))] = v28; + } + float v36 = v29[(v33 + (v31 * 15))]; + float v37 = v34 * v35; + float v38 = v36 + v37; + v29[(v33 + (v31 * 15))] = v38; + if (((v32 + (v30 * 10)) - 409) == 0) { + float v39 = v29[(v33 + (v31 * 15))]; + v27[v33].write(v39); + } + } + } + } + } + return ; +} + +void forward( + float v40[410][390], + float v41[410][390], + float v42[410], + float v43[390], + float v44[390], + float v45[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + hls::stream v46[10]; + #pragma HLS STREAM variable=v46 depth=41 + hls::stream v47[15]; + #pragma HLS STREAM variable=v47 depth=26 + node3(v42, v40, v47, 0.000000); + node2(v41, v43, v46, 0.000000); + node1(v47, v44); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt1/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt1/src/gemm.cpp new file mode 100644 index 000000000000..3c66c436d0e9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt1/src/gemm.cpp @@ -0,0 +1,102 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[200][220] +) { + loop0: for (int v2 = 0; v2 < 200; v2++) { + loop1: for (int v3 = 0; v3 < 220; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[200][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 200; v10++) { + loop3: for (int v11 = 0; v11 < 220; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v10][v11]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + float v18[200][240], + float v19[240][220], + hls::stream &v20, + float v21 +) { + float v22[200][220]; + loop4: for (int v23 = 0; v23 < 200; v23++) { + loop5: for (int v24 = 0; v24 < 220; v24++) { + loop6: for (int v25 = 0; v25 < 240; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v26 = v18[v23][v25]; + float v27 = v19[v25][v24]; + if (v25 == 0) { + v22[v23][v24] = v21; + } + float v28 = v22[v23][v24]; + float v29 = v26 * v27; + float v30 = v28 + v29; + v22[v23][v24] = v30; + if ((v25 - 239) == 0) { + float v31 = v22[v23][v24]; + v20.write(v31); + } + } + } + } + return ; +} + +void forward( + float v32[200][240], + float v33[240][220], + float v34[200][220], + float v35[200][220] +) { + #pragma HLS DATAFLOW + hls::stream v36("fifo_0"); + #pragma HLS STREAM variable=v36 depth=44000 + hls::stream v37("fifo_1"); + #pragma HLS STREAM variable=v37 depth=44000 + node2(v32, v33, v37, 0.000000); + node1(v37, v34, v36, 0.100000, 0.500000); + node0(v36, v35); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt2/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt2/src/gemm.cpp new file mode 100644 index 000000000000..3a44b0144371 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt2/src/gemm.cpp @@ -0,0 +1,102 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[200][220] +) { + loop0: for (int v2 = 0; v2 < 220; v2++) { + loop1: for (int v3 = 0; v3 < 200; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v3][v2] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[200][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 220; v10++) { + loop3: for (int v11 = 0; v11 < 200; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v11][v10]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + float v18[200][240], + float v19[240][220], + hls::stream &v20, + float v21 +) { + float v22[200][220]; + loop4: for (int v23 = 0; v23 < 240; v23++) { + loop5: for (int v24 = 0; v24 < 220; v24++) { + loop6: for (int v25 = 0; v25 < 200; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v26 = v18[v25][v23]; + float v27 = v19[v23][v24]; + if (v23 == 0) { + v22[v25][v24] = v21; + } + float v28 = v22[v25][v24]; + float v29 = v26 * v27; + float v30 = v28 + v29; + v22[v25][v24] = v30; + if ((v23 - 239) == 0) { + float v31 = v22[v25][v24]; + v20.write(v31); + } + } + } + } + return ; +} + +void forward( + float v32[200][240], + float v33[240][220], + float v34[200][220], + float v35[200][220] +) { + #pragma HLS DATAFLOW + hls::stream v36("fifo_0"); + #pragma HLS STREAM variable=v36 depth=44000 + hls::stream v37("fifo_1"); + #pragma HLS STREAM variable=v37 depth=44000 + node2(v32, v33, v37, 0.000000); + node1(v37, v34, v36, 0.100000, 0.500000); + node0(v36, v35); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt3/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt3/src/gemm.cpp new file mode 100644 index 000000000000..8bff20e689ef --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt3/src/gemm.cpp @@ -0,0 +1,143 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[200][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 50; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[200][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 50; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 4; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 4))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[240][220], + float v23[200][240], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=10 + + float v26[200][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + loop8: for (int v27 = 0; v27 < 50; v27++) { + loop9: for (int v28 = 0; v28 < 20; v28++) { + loop10: for (int v29 = 0; v29 < 24; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v30 = 0; v30 < 4; v30++) { + loop12: for (int v31 = 0; v31 < 11; v31++) { + loop13: for (int v32 = 0; v32 < 10; v32++) { + float v33 = v23[(v30 + (v27 * 4))][(v32 + (v29 * 10))]; + float v34 = v22[(v32 + (v29 * 10))][(v31 + (v28 * 11))]; + if ((v32 + (v29 * 10)) == 0) { + v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))] = v25; + } + float v35 = v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))] = v37; + if (((v32 + (v29 * 10)) - 239) == 0) { + float v38 = v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))]; + v24[v30][v31].write(v38); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v39[200][240], + float v40[240][220], + float v41[200][220], + float v42[200][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=11 + + hls::stream v43[4][11]; + #pragma HLS STREAM variable=v43 depth=1000 + hls::stream v44[4][11]; + #pragma HLS STREAM variable=v44 depth=1000 + node2(v40, v39, v44, 0.000000); + node1(v44, v41, v43, 0.100000, 0.500000); + node0(v43, v42); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt4/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt4/src/gemm.cpp new file mode 100644 index 000000000000..ce4d2516bc53 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt4/src/gemm.cpp @@ -0,0 +1,143 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[200][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 20; v2++) { + loop1: for (int v3 = 0; v3 < 50; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 11; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v4 + (v2 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[200][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 20; v12++) { + loop5: for (int v13 = 0; v13 < 50; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 11; v14++) { + loop7: for (int v15 = 0; v15 < 4; v15++) { + float v16 = v7[v15][v14].read(); + float v17 = v8[(v15 + (v13 * 4))][(v14 + (v12 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v15][v14].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[200][240], + float v23[240][220], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[200][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + loop8: for (int v27 = 0; v27 < 24; v27++) { + loop9: for (int v28 = 0; v28 < 20; v28++) { + loop10: for (int v29 = 0; v29 < 50; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v30 = 0; v30 < 10; v30++) { + loop12: for (int v31 = 0; v31 < 11; v31++) { + loop13: for (int v32 = 0; v32 < 4; v32++) { + float v33 = v22[(v32 + (v29 * 4))][(v30 + (v27 * 10))]; + float v34 = v23[(v30 + (v27 * 10))][(v31 + (v28 * 11))]; + if ((v30 + (v27 * 10)) == 0) { + v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))] = v25; + } + float v35 = v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))] = v37; + if (((v30 + (v27 * 10)) - 239) == 0) { + float v38 = v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))]; + v24[v32][v31].write(v38); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v39[200][240], + float v40[240][220], + float v41[200][220], + float v42[200][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=11 + + hls::stream v43[4][11]; + #pragma HLS STREAM variable=v43 depth=1000 + hls::stream v44[4][11]; + #pragma HLS STREAM variable=v44 depth=1000 + node2(v39, v40, v44, 0.000000); + node1(v44, v41, v43, 0.100000, 0.500000); + node0(v43, v42); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt5/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt5/src/gemm.cpp new file mode 100644 index 000000000000..bd3ead0d2e3f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gemm__opt5/src/gemm.cpp @@ -0,0 +1,143 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[200][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 50; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[200][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 50; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 4; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 4))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[200][240], + float v23[240][220], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[200][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + loop8: for (int v27 = 0; v27 < 24; v27++) { + loop9: for (int v28 = 0; v28 < 50; v28++) { + loop10: for (int v29 = 0; v29 < 20; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v30 = 0; v30 < 10; v30++) { + loop12: for (int v31 = 0; v31 < 4; v31++) { + loop13: for (int v32 = 0; v32 < 11; v32++) { + float v33 = v22[(v31 + (v28 * 4))][(v30 + (v27 * 10))]; + float v34 = v23[(v30 + (v27 * 10))][(v32 + (v29 * 11))]; + if ((v30 + (v27 * 10)) == 0) { + v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))] = v25; + } + float v35 = v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))] = v37; + if (((v30 + (v27 * 10)) - 239) == 0) { + float v38 = v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))]; + v24[v31][v32].write(v38); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v39[200][240], + float v40[240][220], + float v41[200][220], + float v42[200][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=11 + + hls::stream v43[4][11]; + #pragma HLS STREAM variable=v43 depth=1000 + hls::stream v44[4][11]; + #pragma HLS STREAM variable=v44 depth=1000 + node2(v39, v40, v44, 0.000000); + node1(v44, v41, v43, 0.100000, 0.500000); + node0(v43, v42); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt1/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt1/src/gesummv.cpp new file mode 100644 index 000000000000..cef5565bb1a0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt1/src/gesummv.cpp @@ -0,0 +1,128 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[250] +) { + loop0: for (int v2 = 0; v2 < 250; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + hls::stream &v5, + hls::stream &v6, + double v7, + float v8 +) { + loop1: for (int v9 = 0; v9 < 250; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v4.read(); + float v11 = v5.read(); + float v12 = v7; + float v13 = v11 * v12; + float v14 = v10 * v8; + float v15 = v14 + v13; + v6.write(v15); + } + return ; +} + +void node2( + float v16[250][250], + float v17[250], + hls::stream &v18, + float v19 +) { + float v20[250]; + loop2: for (int v21 = 0; v21 < 250; v21++) { + loop3: for (int v22 = 0; v22 < 250; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v16[v21][v22]; + float v24 = v17[v22]; + if (v22 == 0) { + v20[v21] = v19; + } + float v25 = v20[v21]; + float v26 = v23 * v24; + float v27 = v25 + v26; + v20[v21] = v27; + if ((v22 - 249) == 0) { + float v28 = v20[v21]; + v18.write(v28); + } + } + } + return ; +} + +void node3( + float v29[250][250], + float v30[250], + hls::stream &v31, + float v32 +) { + float v33[250]; + loop4: for (int v34 = 0; v34 < 250; v34++) { + loop5: for (int v35 = 0; v35 < 250; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v36 = v29[v34][v35]; + float v37 = v30[v35]; + if (v35 == 0) { + v33[v34] = v32; + } + float v38 = v33[v34]; + float v39 = v36 * v37; + float v40 = v38 + v39; + v33[v34] = v40; + if ((v35 - 249) == 0) { + float v41 = v33[v34]; + v31.write(v41); + } + } + } + return ; +} + +void forward( + float v42[250][250], + float v43[250][250], + float v44[250], + float v45[250] +) { + #pragma HLS DATAFLOW + hls::stream v46("fifo_0"); + #pragma HLS STREAM variable=v46 depth=250 + hls::stream v47("fifo_1"); + #pragma HLS STREAM variable=v47 depth=250 + hls::stream v48("fifo_2"); + #pragma HLS STREAM variable=v48 depth=250 + node3(v42, v44, v48, 0.000000); + node2(v43, v44, v47, 0.000000); + node1(v48, v47, v46, 1.200000, 1.500000); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt2/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt2/src/gesummv.cpp new file mode 100644 index 000000000000..7d0a0c3ebea9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt2/src/gesummv.cpp @@ -0,0 +1,128 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[250] +) { + loop0: for (int v2 = 0; v2 < 250; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + hls::stream &v5, + hls::stream &v6, + double v7, + float v8 +) { + loop1: for (int v9 = 0; v9 < 250; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v4.read(); + float v11 = v5.read(); + float v12 = v7; + float v13 = v11 * v12; + float v14 = v10 * v8; + float v15 = v14 + v13; + v6.write(v15); + } + return ; +} + +void node2( + float v16[250][250], + float v17[250], + hls::stream &v18, + float v19 +) { + float v20[250]; + loop2: for (int v21 = 0; v21 < 250; v21++) { + loop3: for (int v22 = 0; v22 < 250; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v16[v22][v21]; + float v24 = v17[v21]; + if (v21 == 0) { + v20[v22] = v19; + } + float v25 = v20[v22]; + float v26 = v23 * v24; + float v27 = v25 + v26; + v20[v22] = v27; + if ((v21 - 249) == 0) { + float v28 = v20[v22]; + v18.write(v28); + } + } + } + return ; +} + +void node3( + float v29[250][250], + float v30[250], + hls::stream &v31, + float v32 +) { + float v33[250]; + loop4: for (int v34 = 0; v34 < 250; v34++) { + loop5: for (int v35 = 0; v35 < 250; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v36 = v29[v35][v34]; + float v37 = v30[v34]; + if (v34 == 0) { + v33[v35] = v32; + } + float v38 = v33[v35]; + float v39 = v36 * v37; + float v40 = v38 + v39; + v33[v35] = v40; + if ((v34 - 249) == 0) { + float v41 = v33[v35]; + v31.write(v41); + } + } + } + return ; +} + +void forward( + float v42[250][250], + float v43[250][250], + float v44[250], + float v45[250] +) { + #pragma HLS DATAFLOW + hls::stream v46("fifo_0"); + #pragma HLS STREAM variable=v46 depth=250 + hls::stream v47("fifo_1"); + #pragma HLS STREAM variable=v47 depth=250 + hls::stream v48("fifo_2"); + #pragma HLS STREAM variable=v48 depth=250 + node3(v42, v44, v48, 0.000000); + node2(v43, v44, v47, 0.000000); + node1(v48, v47, v46, 1.200000, 1.500000); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt3/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt3/src/gesummv.cpp new file mode 100644 index 000000000000..320bdafe51f2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt3/src/gesummv.cpp @@ -0,0 +1,166 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[250] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + hls::stream v6[10], + hls::stream v7[10], + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 25; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v11 = 0; v11 < 10; v11++) { + float v12 = v5[v11].read(); + float v13 = v6[v11].read(); + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7[v11].write(v17); + } + } + return ; +} + +void node2( + float v18[250][250], + float v19[250], + hls::stream v20[10], + float v21 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v19 cyclic dim=1 factor=10 + + float v22[250]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + + loop4: for (int v23 = 0; v23 < 25; v23++) { + loop5: for (int v24 = 0; v24 < 25; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v25 = 0; v25 < 10; v25++) { + loop7: for (int v26 = 0; v26 < 10; v26++) { + float v27 = v18[(v25 + (v23 * 10))][(v26 + (v24 * 10))]; + float v28 = v19[(v26 + (v24 * 10))]; + if ((v26 + (v24 * 10)) == 0) { + v22[(v25 + (v23 * 10))] = v21; + } + float v29 = v22[(v25 + (v23 * 10))]; + float v30 = v27 * v28; + float v31 = v29 + v30; + v22[(v25 + (v23 * 10))] = v31; + if (((v26 + (v24 * 10)) - 249) == 0) { + float v32 = v22[(v25 + (v23 * 10))]; + v20[v25].write(v32); + } + } + } + } + } + return ; +} + +void node3( + float v33[250][250], + float v34[250], + hls::stream v35[10], + float v36 +) { + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=10 + + float v37[250]; + #pragma HLS array_partition variable=v37 cyclic dim=1 factor=10 + + loop8: for (int v38 = 0; v38 < 25; v38++) { + loop9: for (int v39 = 0; v39 < 25; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v40 = 0; v40 < 10; v40++) { + loop11: for (int v41 = 0; v41 < 10; v41++) { + float v42 = v33[(v40 + (v38 * 10))][(v41 + (v39 * 10))]; + float v43 = v34[(v41 + (v39 * 10))]; + if ((v41 + (v39 * 10)) == 0) { + v37[(v40 + (v38 * 10))] = v36; + } + float v44 = v37[(v40 + (v38 * 10))]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v37[(v40 + (v38 * 10))] = v46; + if (((v41 + (v39 * 10)) - 249) == 0) { + float v47 = v37[(v40 + (v38 * 10))]; + v35[v40].write(v47); + } + } + } + } + } + return ; +} + +void forward( + float v48[250][250], + float v49[250][250], + float v50[250], + float v51[250] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + hls::stream v52[10]; + #pragma HLS STREAM variable=v52 depth=25 + hls::stream v53[10]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[10]; + #pragma HLS STREAM variable=v54 depth=25 + node3(v48, v50, v54, 0.000000); + node2(v49, v50, v53, 0.000000); + node1(v54, v53, v52, 1.200000, 1.500000); + node0(v52, v51); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt4/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt4/src/gesummv.cpp new file mode 100644 index 000000000000..215e46416363 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt4/src/gesummv.cpp @@ -0,0 +1,166 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[250] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + hls::stream v6[10], + hls::stream v7[10], + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 25; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v11 = 0; v11 < 10; v11++) { + float v12 = v5[v11].read(); + float v13 = v6[v11].read(); + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7[v11].write(v17); + } + } + return ; +} + +void node2( + float v18[250][250], + float v19[250], + hls::stream v20[10], + float v21 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v19 cyclic dim=1 factor=10 + + float v22[250]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + + loop4: for (int v23 = 0; v23 < 25; v23++) { + loop5: for (int v24 = 0; v24 < 25; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v25 = 0; v25 < 10; v25++) { + loop7: for (int v26 = 0; v26 < 10; v26++) { + float v27 = v18[(v26 + (v24 * 10))][(v25 + (v23 * 10))]; + float v28 = v19[(v25 + (v23 * 10))]; + if ((v25 + (v23 * 10)) == 0) { + v22[(v26 + (v24 * 10))] = v21; + } + float v29 = v22[(v26 + (v24 * 10))]; + float v30 = v27 * v28; + float v31 = v29 + v30; + v22[(v26 + (v24 * 10))] = v31; + if (((v25 + (v23 * 10)) - 249) == 0) { + float v32 = v22[(v26 + (v24 * 10))]; + v20[v26].write(v32); + } + } + } + } + } + return ; +} + +void node3( + float v33[250][250], + float v34[250], + hls::stream v35[10], + float v36 +) { + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=10 + + float v37[250]; + #pragma HLS array_partition variable=v37 cyclic dim=1 factor=10 + + loop8: for (int v38 = 0; v38 < 25; v38++) { + loop9: for (int v39 = 0; v39 < 25; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v40 = 0; v40 < 10; v40++) { + loop11: for (int v41 = 0; v41 < 10; v41++) { + float v42 = v33[(v41 + (v39 * 10))][(v40 + (v38 * 10))]; + float v43 = v34[(v40 + (v38 * 10))]; + if ((v40 + (v38 * 10)) == 0) { + v37[(v41 + (v39 * 10))] = v36; + } + float v44 = v37[(v41 + (v39 * 10))]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v37[(v41 + (v39 * 10))] = v46; + if (((v40 + (v38 * 10)) - 249) == 0) { + float v47 = v37[(v41 + (v39 * 10))]; + v35[v41].write(v47); + } + } + } + } + } + return ; +} + +void forward( + float v48[250][250], + float v49[250][250], + float v50[250], + float v51[250] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + hls::stream v52[10]; + #pragma HLS STREAM variable=v52 depth=25 + hls::stream v53[10]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[10]; + #pragma HLS STREAM variable=v54 depth=25 + node3(v48, v50, v54, 0.000000); + node2(v49, v50, v53, 0.000000); + node1(v54, v53, v52, 1.200000, 1.500000); + node0(v52, v51); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt5/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt5/src/gesummv.cpp new file mode 100644 index 000000000000..215e46416363 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/gesummv__opt5/src/gesummv.cpp @@ -0,0 +1,166 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[250] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + hls::stream v6[10], + hls::stream v7[10], + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 25; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v11 = 0; v11 < 10; v11++) { + float v12 = v5[v11].read(); + float v13 = v6[v11].read(); + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7[v11].write(v17); + } + } + return ; +} + +void node2( + float v18[250][250], + float v19[250], + hls::stream v20[10], + float v21 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v19 cyclic dim=1 factor=10 + + float v22[250]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + + loop4: for (int v23 = 0; v23 < 25; v23++) { + loop5: for (int v24 = 0; v24 < 25; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v25 = 0; v25 < 10; v25++) { + loop7: for (int v26 = 0; v26 < 10; v26++) { + float v27 = v18[(v26 + (v24 * 10))][(v25 + (v23 * 10))]; + float v28 = v19[(v25 + (v23 * 10))]; + if ((v25 + (v23 * 10)) == 0) { + v22[(v26 + (v24 * 10))] = v21; + } + float v29 = v22[(v26 + (v24 * 10))]; + float v30 = v27 * v28; + float v31 = v29 + v30; + v22[(v26 + (v24 * 10))] = v31; + if (((v25 + (v23 * 10)) - 249) == 0) { + float v32 = v22[(v26 + (v24 * 10))]; + v20[v26].write(v32); + } + } + } + } + } + return ; +} + +void node3( + float v33[250][250], + float v34[250], + hls::stream v35[10], + float v36 +) { + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=10 + + float v37[250]; + #pragma HLS array_partition variable=v37 cyclic dim=1 factor=10 + + loop8: for (int v38 = 0; v38 < 25; v38++) { + loop9: for (int v39 = 0; v39 < 25; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v40 = 0; v40 < 10; v40++) { + loop11: for (int v41 = 0; v41 < 10; v41++) { + float v42 = v33[(v41 + (v39 * 10))][(v40 + (v38 * 10))]; + float v43 = v34[(v40 + (v38 * 10))]; + if ((v40 + (v38 * 10)) == 0) { + v37[(v41 + (v39 * 10))] = v36; + } + float v44 = v37[(v41 + (v39 * 10))]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v37[(v41 + (v39 * 10))] = v46; + if (((v40 + (v38 * 10)) - 249) == 0) { + float v47 = v37[(v41 + (v39 * 10))]; + v35[v41].write(v47); + } + } + } + } + } + return ; +} + +void forward( + float v48[250][250], + float v49[250][250], + float v50[250], + float v51[250] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + hls::stream v52[10]; + #pragma HLS STREAM variable=v52 depth=25 + hls::stream v53[10]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[10]; + #pragma HLS STREAM variable=v54 depth=25 + node3(v48, v50, v54, 0.000000); + node2(v49, v50, v53, 0.000000); + node1(v54, v53, v52, 1.200000, 1.500000); + node0(v52, v51); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt1/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt1/src/k2mm.cpp new file mode 100644 index 000000000000..dc8ef2c4cc96 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt1/src/k2mm.cpp @@ -0,0 +1,142 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[180][220] +) { + loop0: for (int v2 = 0; v2 < 180; v2++) { + loop1: for (int v3 = 0; v3 < 220; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[180][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 180; v10++) { + loop3: for (int v11 = 0; v11 < 220; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v10][v11]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + hls::stream &v18, + float v19[190][220], + hls::stream &v20, + float v21 +) { + float v22[180][220]; + float v23[180][190]; + loop4: for (int v24 = 0; v24 < 180; v24++) { + loop5: for (int v25 = 0; v25 < 220; v25++) { + loop6: for (int v26 = 0; v26 < 190; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v25 == 0) { + float v27 = v18.read(); + v23[v24][v26] = v27; + } + float v28 = v23[v24][v26]; + float v29 = v19[v26][v25]; + if (v26 == 0) { + v22[v24][v25] = v21; + } + float v30 = v22[v24][v25]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v22[v24][v25] = v32; + if ((v26 - 189) == 0) { + float v33 = v22[v24][v25]; + v20.write(v33); + } + } + } + } + return ; +} + +void node3( + float v34[180][210], + float v35[210][190], + hls::stream &v36, + float v37 +) { + float v38[180][190]; + loop7: for (int v39 = 0; v39 < 180; v39++) { + loop8: for (int v40 = 0; v40 < 190; v40++) { + loop9: for (int v41 = 0; v41 < 210; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v34[v39][v41]; + float v43 = v35[v41][v40]; + if (v41 == 0) { + v38[v39][v40] = v37; + } + float v44 = v38[v39][v40]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v38[v39][v40] = v46; + if ((v41 - 209) == 0) { + float v47 = v38[v39][v40]; + v36.write(v47); + } + } + } + } + return ; +} + +void forward( + float v48[180][210], + float v49[210][190], + float v50[190][220], + float v51[180][220], + float v52[180][220] +) { + #pragma HLS DATAFLOW + hls::stream v53("fifo_0"); + #pragma HLS STREAM variable=v53 depth=39600 + hls::stream v54("fifo_1"); + #pragma HLS STREAM variable=v54 depth=39600 + hls::stream v55("fifo_2"); + #pragma HLS STREAM variable=v55 depth=34200 + node3(v48, v49, v55, 0.000000); + node2(v55, v50, v54, 0.000000); + node1(v54, v51, v53, 0.100000, 0.500000); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt2/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt2/src/k2mm.cpp new file mode 100644 index 000000000000..1c7e562fbc2d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt2/src/k2mm.cpp @@ -0,0 +1,142 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[180][220] +) { + loop0: for (int v2 = 0; v2 < 220; v2++) { + loop1: for (int v3 = 0; v3 < 180; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v3][v2] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[180][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 220; v10++) { + loop3: for (int v11 = 0; v11 < 180; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v11][v10]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + hls::stream &v18, + float v19[190][220], + hls::stream &v20, + float v21 +) { + float v22[180][220]; + float v23[180][190]; + loop4: for (int v24 = 0; v24 < 190; v24++) { + loop5: for (int v25 = 0; v25 < 220; v25++) { + loop6: for (int v26 = 0; v26 < 180; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v25 == 0) { + float v27 = v18.read(); + v23[v26][v24] = v27; + } + float v28 = v23[v26][v24]; + float v29 = v19[v24][v25]; + if (v24 == 0) { + v22[v26][v25] = v21; + } + float v30 = v22[v26][v25]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v22[v26][v25] = v32; + if ((v24 - 189) == 0) { + float v33 = v22[v26][v25]; + v20.write(v33); + } + } + } + } + return ; +} + +void node3( + float v34[180][210], + float v35[210][190], + hls::stream &v36, + float v37 +) { + float v38[180][190]; + loop7: for (int v39 = 0; v39 < 190; v39++) { + loop8: for (int v40 = 0; v40 < 210; v40++) { + loop9: for (int v41 = 0; v41 < 180; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v34[v41][v40]; + float v43 = v35[v40][v39]; + if (v40 == 0) { + v38[v41][v39] = v37; + } + float v44 = v38[v41][v39]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v38[v41][v39] = v46; + if ((v40 - 209) == 0) { + float v47 = v38[v41][v39]; + v36.write(v47); + } + } + } + } + return ; +} + +void forward( + float v48[180][210], + float v49[210][190], + float v50[190][220], + float v51[180][220], + float v52[180][220] +) { + #pragma HLS DATAFLOW + hls::stream v53("fifo_0"); + #pragma HLS STREAM variable=v53 depth=39600 + hls::stream v54("fifo_1"); + #pragma HLS STREAM variable=v54 depth=39600 + hls::stream v55("fifo_2"); + #pragma HLS STREAM variable=v55 depth=34200 + node3(v48, v49, v55, 0.000000); + node2(v55, v50, v54, 0.000000); + node1(v54, v51, v53, 0.100000, 0.500000); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt3/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt3/src/k2mm.cpp new file mode 100644 index 000000000000..348cbd2c4524 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt3/src/k2mm.cpp @@ -0,0 +1,201 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][11], + float v1[180][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 90; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 2))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][11], + float v8[180][220], + hls::stream v9[2][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 90; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 2; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 2))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + hls::stream v22[2][10], + float v23[190][220], + hls::stream v24[2][11], + float v25 +) { + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[180][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + float v27[180][190]; + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=10 + + loop8: for (int v28 = 0; v28 < 90; v28++) { + loop9: for (int v29 = 0; v29 < 20; v29++) { + loop10: for (int v30 = 0; v30 < 19; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v31 = 0; v31 < 2; v31++) { + loop12: for (int v32 = 0; v32 < 11; v32++) { + loop13: for (int v33 = 0; v33 < 10; v33++) { + if ((v32 + (v29 * 11)) == 0) { + float v34 = v22[v31][v33].read(); + v27[(v31 + (v28 * 2))][(v33 + (v30 * 10))] = v34; + } + float v35 = v27[(v31 + (v28 * 2))][(v33 + (v30 * 10))]; + float v36 = v23[(v33 + (v30 * 10))][(v32 + (v29 * 11))]; + if ((v33 + (v30 * 10)) == 0) { + v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))] = v25; + } + float v37 = v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))]; + float v38 = v35 * v36; + float v39 = v37 + v38; + v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))] = v39; + if (((v33 + (v30 * 10)) - 189) == 0) { + float v40 = v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))]; + v24[v31][v32].write(v40); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v41[210][190], + float v42[180][210], + hls::stream v43[2][10], + float v44 +) { + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=10 + + float v45[180][190]; + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=10 + + loop14: for (int v46 = 0; v46 < 90; v46++) { + loop15: for (int v47 = 0; v47 < 19; v47++) { + loop16: for (int v48 = 0; v48 < 21; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v49 = 0; v49 < 2; v49++) { + loop18: for (int v50 = 0; v50 < 10; v50++) { + loop19: for (int v51 = 0; v51 < 10; v51++) { + float v52 = v42[(v49 + (v46 * 2))][(v51 + (v48 * 10))]; + float v53 = v41[(v51 + (v48 * 10))][(v50 + (v47 * 10))]; + if ((v51 + (v48 * 10)) == 0) { + v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))] = v44; + } + float v54 = v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))]; + float v55 = v52 * v53; + float v56 = v54 + v55; + v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))] = v56; + if (((v51 + (v48 * 10)) - 209) == 0) { + float v57 = v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))]; + v43[v49][v50].write(v57); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v58[180][210], + float v59[210][190], + float v60[190][220], + float v61[180][220], + float v62[180][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=11 + + hls::stream v63[2][11]; + #pragma HLS STREAM variable=v63 depth=1800 + hls::stream v64[2][11]; + #pragma HLS STREAM variable=v64 depth=1800 + hls::stream v65[2][10]; + #pragma HLS STREAM variable=v65 depth=1710 + node3(v59, v58, v65, 0.000000); + node2(v65, v60, v64, 0.000000); + node1(v64, v61, v63, 0.100000, 0.500000); + node0(v63, v62); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt4/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt4/src/k2mm.cpp new file mode 100644 index 000000000000..4c17a6f50b7b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt4/src/k2mm.cpp @@ -0,0 +1,201 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[180][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 20; v2++) { + loop1: for (int v3 = 0; v3 < 45; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 11; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v4 + (v2 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[180][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 20; v12++) { + loop5: for (int v13 = 0; v13 < 45; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 11; v14++) { + loop7: for (int v15 = 0; v15 < 4; v15++) { + float v16 = v7[v15][v14].read(); + float v17 = v8[(v15 + (v13 * 4))][(v14 + (v12 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v15][v14].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[190][220], + hls::stream v23[4][5], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=11 + + float v26[180][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + float v27[180][190]; + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=5 + + loop8: for (int v28 = 0; v28 < 38; v28++) { + loop9: for (int v29 = 0; v29 < 20; v29++) { + loop10: for (int v30 = 0; v30 < 45; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v31 = 0; v31 < 5; v31++) { + loop12: for (int v32 = 0; v32 < 11; v32++) { + loop13: for (int v33 = 0; v33 < 4; v33++) { + if ((v32 + (v29 * 11)) == 0) { + float v34 = v23[v33][v31].read(); + v27[(v33 + (v30 * 4))][(v31 + (v28 * 5))] = v34; + } + float v35 = v27[(v33 + (v30 * 4))][(v31 + (v28 * 5))]; + float v36 = v22[(v31 + (v28 * 5))][(v32 + (v29 * 11))]; + if ((v31 + (v28 * 5)) == 0) { + v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))] = v25; + } + float v37 = v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))]; + float v38 = v35 * v36; + float v39 = v37 + v38; + v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))] = v39; + if (((v31 + (v28 * 5)) - 189) == 0) { + float v40 = v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))]; + v24[v33][v32].write(v40); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v41[210][190], + float v42[180][210], + hls::stream v43[4][5], + float v44 +) { + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=10 + + float v45[180][190]; + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=5 + + loop14: for (int v46 = 0; v46 < 38; v46++) { + loop15: for (int v47 = 0; v47 < 21; v47++) { + loop16: for (int v48 = 0; v48 < 45; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v49 = 0; v49 < 5; v49++) { + loop18: for (int v50 = 0; v50 < 10; v50++) { + loop19: for (int v51 = 0; v51 < 4; v51++) { + float v52 = v42[(v51 + (v48 * 4))][(v50 + (v47 * 10))]; + float v53 = v41[(v50 + (v47 * 10))][(v49 + (v46 * 5))]; + if ((v50 + (v47 * 10)) == 0) { + v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))] = v44; + } + float v54 = v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))]; + float v55 = v52 * v53; + float v56 = v54 + v55; + v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))] = v56; + if (((v50 + (v47 * 10)) - 209) == 0) { + float v57 = v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))]; + v43[v51][v49].write(v57); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v58[180][210], + float v59[210][190], + float v60[190][220], + float v61[180][220], + float v62[180][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=11 + + hls::stream v63[4][11]; + #pragma HLS STREAM variable=v63 depth=900 + hls::stream v64[4][11]; + #pragma HLS STREAM variable=v64 depth=900 + hls::stream v65[4][5]; + #pragma HLS STREAM variable=v65 depth=1710 + node3(v59, v58, v65, 0.000000); + node2(v60, v65, v64, 0.000000); + node1(v64, v61, v63, 0.100000, 0.500000); + node0(v63, v62); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt5/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt5/src/k2mm.cpp new file mode 100644 index 000000000000..43cbb7456ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k2mm__opt5/src/k2mm.cpp @@ -0,0 +1,201 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][11], + float v1[180][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 90; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 2))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][11], + float v8[180][220], + hls::stream v9[2][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 90; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 2; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 2))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + hls::stream v22[2][10], + float v23[190][220], + hls::stream v24[2][11], + float v25 +) { + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[180][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + float v27[180][190]; + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=10 + + loop8: for (int v28 = 0; v28 < 90; v28++) { + loop9: for (int v29 = 0; v29 < 19; v29++) { + loop10: for (int v30 = 0; v30 < 20; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v31 = 0; v31 < 2; v31++) { + loop12: for (int v32 = 0; v32 < 10; v32++) { + loop13: for (int v33 = 0; v33 < 11; v33++) { + if ((v33 + (v30 * 11)) == 0) { + float v34 = v22[v31][v32].read(); + v27[(v31 + (v28 * 2))][(v32 + (v29 * 10))] = v34; + } + float v35 = v27[(v31 + (v28 * 2))][(v32 + (v29 * 10))]; + float v36 = v23[(v32 + (v29 * 10))][(v33 + (v30 * 11))]; + if ((v32 + (v29 * 10)) == 0) { + v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))] = v25; + } + float v37 = v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))]; + float v38 = v35 * v36; + float v39 = v37 + v38; + v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))] = v39; + if (((v32 + (v29 * 10)) - 189) == 0) { + float v40 = v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))]; + v24[v31][v33].write(v40); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v41[180][210], + float v42[210][190], + hls::stream v43[2][10], + float v44 +) { + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=10 + + float v45[180][190]; + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=10 + + loop14: for (int v46 = 0; v46 < 90; v46++) { + loop15: for (int v47 = 0; v47 < 21; v47++) { + loop16: for (int v48 = 0; v48 < 19; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v49 = 0; v49 < 2; v49++) { + loop18: for (int v50 = 0; v50 < 10; v50++) { + loop19: for (int v51 = 0; v51 < 10; v51++) { + float v52 = v41[(v49 + (v46 * 2))][(v50 + (v47 * 10))]; + float v53 = v42[(v50 + (v47 * 10))][(v51 + (v48 * 10))]; + if ((v50 + (v47 * 10)) == 0) { + v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))] = v44; + } + float v54 = v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))]; + float v55 = v52 * v53; + float v56 = v54 + v55; + v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))] = v56; + if (((v50 + (v47 * 10)) - 209) == 0) { + float v57 = v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))]; + v43[v49][v51].write(v57); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v58[180][210], + float v59[210][190], + float v60[190][220], + float v61[180][220], + float v62[180][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=11 + + hls::stream v63[2][11]; + #pragma HLS STREAM variable=v63 depth=1800 + hls::stream v64[2][11]; + #pragma HLS STREAM variable=v64 depth=1800 + hls::stream v65[2][10]; + #pragma HLS STREAM variable=v65 depth=1710 + node3(v58, v59, v65, 0.000000); + node2(v65, v60, v64, 0.000000); + node1(v64, v61, v63, 0.100000, 0.500000); + node0(v63, v62); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt1/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt1/src/k3mm.cpp new file mode 100644 index 000000000000..a139155ff481 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt1/src/k3mm.cpp @@ -0,0 +1,154 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[180][210] +) { + loop0: for (int v2 = 0; v2 < 180; v2++) { + loop1: for (int v3 = 0; v3 < 210; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[190][210], + hls::stream &v7, + float v8 +) { + float v9[180][210]; + float v10[190][210]; + float v11[180][190]; + loop2: for (int v12 = 0; v12 < 180; v12++) { + loop3: for (int v13 = 0; v13 < 210; v13++) { + loop4: for (int v14 = 0; v14 < 190; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v13 == 0) { + float v15 = v5.read(); + v11[v12][v14] = v15; + } + float v16 = v11[v12][v14]; + if (v12 == 0) { + float v17 = v6[v14][v13]; + v10[v14][v13] = v17; + } + float v18 = v10[v14][v13]; + if (v14 == 0) { + v9[v12][v13] = v8; + } + float v19 = v9[v12][v13]; + float v20 = v16 * v18; + float v21 = v19 + v20; + v9[v12][v13] = v21; + if ((v14 - 189) == 0) { + float v22 = v9[v12][v13]; + v7.write(v22); + } + } + } + } + return ; +} + +void node2( + float v23[190][220], + float v24[220][210], + float v25[190][210], + float v26 +) { + float v27[190][210]; + loop5: for (int v28 = 0; v28 < 190; v28++) { + loop6: for (int v29 = 0; v29 < 210; v29++) { + loop7: for (int v30 = 0; v30 < 220; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v31 = v23[v28][v30]; + float v32 = v24[v30][v29]; + if (v30 == 0) { + v27[v28][v29] = v26; + } + float v33 = v27[v28][v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v27[v28][v29] = v35; + if ((v30 - 219) == 0) { + float v36 = v27[v28][v29]; + v25[v28][v29] = v36; + } + } + } + } + return ; +} + +void node3( + float v37[180][200], + float v38[200][190], + hls::stream &v39, + float v40 +) { + float v41[180][190]; + loop8: for (int v42 = 0; v42 < 180; v42++) { + loop9: for (int v43 = 0; v43 < 190; v43++) { + loop10: for (int v44 = 0; v44 < 200; v44++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v45 = v37[v42][v44]; + float v46 = v38[v44][v43]; + if (v44 == 0) { + v41[v42][v43] = v40; + } + float v47 = v41[v42][v43]; + float v48 = v45 * v46; + float v49 = v47 + v48; + v41[v42][v43] = v49; + if ((v44 - 199) == 0) { + float v50 = v41[v42][v43]; + v39.write(v50); + } + } + } + } + return ; +} + +void forward( + float v51[180][200], + float v52[200][190], + float v53[190][220], + float v54[220][210], + float v55[180][210] +) { + #pragma HLS DATAFLOW + hls::stream v56("fifo_0"); + #pragma HLS STREAM variable=v56 depth=37800 + float v57[190][210]; + hls::stream v58("fifo_1"); + #pragma HLS STREAM variable=v58 depth=34200 + node3(v51, v52, v58, 0.000000); + node2(v53, v54, v57, 0.000000); + node1(v58, v57, v56, 0.000000); + node0(v56, v55); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt2/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt2/src/k3mm.cpp new file mode 100644 index 000000000000..cbeb4f0a74d4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt2/src/k3mm.cpp @@ -0,0 +1,145 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0(hls::stream &v0, float v1[180][210]) { +loop0: + for (int v2 = 0; v2 < 210; v2++) { + loop1: + for (int v3 = 0; v3 < 180; v3++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + float v4 = v0.read(); + v1[v3][v2] = v4; + } + } + return; +} + +void node1(hls::stream &v5, hls::stream &v6, + hls::stream &v7, float v8) { + float v9[180][210]; + float v10; + float v11[180]; +loop2: + for (int v12 = 0; v12 < 190; v12++) { + loop3: + for (int v13 = 0; v13 < 210; v13++) { + loop4: + for (int v14 = 0; v14 < 180; v14++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + if (v13 == 0) { + float v15 = v5.read(); + v11[v14] = v15; + } + float v16 = v11[v14]; + if (v14 == 0) { + float v17 = v6.read(); + v10 = v17; + } + float v18 = v10; + if (v12 == 0) { + v9[v14][v13] = v8; + } + float v19 = v9[v14][v13]; + float v20 = v16 * v18; + float v21 = v19 + v20; + v9[v14][v13] = v21; + if ((v12 - 189) == 0) { + float v22 = v9[v14][v13]; + v7.write(v22); + } + } + } + } + return; +} + +void node2(float v23[190][220], float v24[220][210], hls::stream &v25, + float v26) { + float v27[190][210]; +loop5: + for (int v28 = 0; v28 < 190; v28++) { + loop6: + for (int v29 = 0; v29 < 220; v29++) { + loop7: + for (int v30 = 0; v30 < 210; v30++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + float v31 = v23[v28][v29]; + float v32 = v24[v29][v30]; + if (v29 == 0) { + v27[v28][v30] = v26; + } + float v33 = v27[v28][v30]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v27[v28][v30] = v35; + if ((v29 - 219) == 0) { + float v36 = v27[v28][v30]; + v25.write(v36); + } + } + } + } + return; +} + +void node3(float v37[180][200], float v38[200][190], hls::stream &v39, + float v40) { + float v41[180][190]; +loop8: + for (int v42 = 0; v42 < 190; v42++) { + loop9: + for (int v43 = 0; v43 < 200; v43++) { + loop10: + for (int v44 = 0; v44 < 180; v44++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + float v45 = v37[v44][v43]; + float v46 = v38[v43][v42]; + if (v43 == 0) { + v41[v44][v42] = v40; + } + float v47 = v41[v44][v42]; + float v48 = v45 * v46; + float v49 = v47 + v48; + v41[v44][v42] = v49; + if ((v43 - 199) == 0) { + float v50 = v41[v44][v42]; + v39.write(v50); + } + } + } + } + return; +} + +void forward(float v51[180][200], float v52[200][190], float v53[190][220], + float v54[220][210], float v55[180][210]) { +#pragma HLS DATAFLOW + hls::stream v56("fifo_0"); +#pragma HLS STREAM variable = v56 depth = 37800 + hls::stream v57("fifo_1"); +#pragma HLS STREAM variable = v57 depth = 39900 + hls::stream v58("fifo_2"); +#pragma HLS STREAM variable = v58 depth = 34200 + node3(v51, v52, v58, 0.000000); + node2(v53, v54, v57, 0.000000); + node1(v58, v57, v56, 0.000000); + node0(v56, v55); + return; +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt3/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt3/src/k3mm.cpp new file mode 100644 index 000000000000..ccc77811461c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt3/src/k3mm.cpp @@ -0,0 +1,226 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10][2], + float v1[180][210] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + + loop0: for (int v2 = 0; v2 < 18; v2++) { + loop1: for (int v3 = 0; v3 < 105; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 10; v4++) { + loop3: for (int v5 = 0; v5 < 2; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 10))][(v5 + (v3 * 2))] = v6; + } + } + } + } + return ; +} + +void node1( + float v7[190][210], + hls::stream v8[10][10], + hls::stream v9[10][2], + float v10 +) { + #pragma HLS array_partition variable=v7 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v7 cyclic dim=2 factor=2 + + float v11[180][210]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=2 + + float v12[190][210]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + float v13[180][190]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=10 + + loop4: for (int v14 = 0; v14 < 18; v14++) { + loop5: for (int v15 = 0; v15 < 105; v15++) { + loop6: for (int v16 = 0; v16 < 19; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 10; v17++) { + loop8: for (int v18 = 0; v18 < 2; v18++) { + loop9: for (int v19 = 0; v19 < 10; v19++) { + if ((v18 + (v15 * 2)) == 0) { + float v20 = v8[v17][v19].read(); + v13[(v17 + (v14 * 10))][(v19 + (v16 * 10))] = v20; + } + float v21 = v13[(v17 + (v14 * 10))][(v19 + (v16 * 10))]; + if ((v17 + (v14 * 10)) == 0) { + float v22 = v7[(v19 + (v16 * 10))][(v18 + (v15 * 2))]; + v12[(v19 + (v16 * 10))][(v18 + (v15 * 2))] = v22; + } + float v23 = v12[(v19 + (v16 * 10))][(v18 + (v15 * 2))]; + if ((v19 + (v16 * 10)) == 0) { + v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))] = v10; + } + float v24 = v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))] = v26; + if (((v19 + (v16 * 10)) - 189) == 0) { + float v27 = v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))]; + v9[v17][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v28[220][210], + float v29[190][220], + float v30[190][210], + float v31 +) { + #pragma HLS array_partition variable=v28 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v32[190][210]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=2 + + loop10: for (int v33 = 0; v33 < 19; v33++) { + loop11: for (int v34 = 0; v34 < 105; v34++) { + loop12: for (int v35 = 0; v35 < 22; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v36 = 0; v36 < 10; v36++) { + loop14: for (int v37 = 0; v37 < 2; v37++) { + loop15: for (int v38 = 0; v38 < 10; v38++) { + float v39 = v29[(v36 + (v33 * 10))][(v38 + (v35 * 10))]; + float v40 = v28[(v38 + (v35 * 10))][(v37 + (v34 * 2))]; + if ((v38 + (v35 * 10)) == 0) { + v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))] = v31; + } + float v41 = v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))] = v43; + if (((v38 + (v35 * 10)) - 219) == 0) { + float v44 = v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))]; + v30[(v36 + (v33 * 10))][(v37 + (v34 * 2))] = v44; + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[180][200], + float v46[200][190], + hls::stream v47[10][10], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=10 + + float v49[180][190]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + loop16: for (int v50 = 0; v50 < 18; v50++) { + loop17: for (int v51 = 0; v51 < 19; v51++) { + loop18: for (int v52 = 0; v52 < 200; v52++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v53 = 0; v53 < 10; v53++) { + loop20: for (int v54 = 0; v54 < 10; v54++) { + loop21: for (int v55 = 0; v55 < 1; v55++) { + float v56 = v45[(v53 + (v50 * 10))][(v52 + v55)]; + float v57 = v46[(v52 + v55)][(v54 + (v51 * 10))]; + if ((v52 + v55) == 0) { + v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))] = v48; + } + float v58 = v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))]; + float v59 = v56 * v57; + float v60 = v58 + v59; + v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))] = v60; + if (((v52 + v55) - 199) == 0) { + float v61 = v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))]; + v47[v53][v54].write(v61); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v62[180][200], + float v63[200][190], + float v64[190][220], + float v65[220][210], + float v66[180][210] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=2 + + hls::stream v67[10][2]; + #pragma HLS STREAM variable=v67 depth=1890 + float v68[190][210]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=2 + + hls::stream v69[10][10]; + #pragma HLS STREAM variable=v69 depth=342 + node3(v62, v63, v69, 0.000000); + node2(v65, v64, v68, 0.000000); + node1(v68, v69, v67, 0.000000); + node0(v67, v66); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt4/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt4/src/k3mm.cpp new file mode 100644 index 000000000000..37f913d32685 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt4/src/k3mm.cpp @@ -0,0 +1,222 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[3][10], + float v1[180][210] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=10 + + loop0: for (int v2 = 0; v2 < 21; v2++) { + loop1: for (int v3 = 0; v3 < 60; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 10; v4++) { + loop3: for (int v5 = 0; v5 < 3; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 3))][(v4 + (v2 * 10))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[3][5], + hls::stream v8[5][10], + hls::stream v9[3][10], + float v10 +) { + float v11[180][210]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=10 + + float v12[190][210]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=10 + + float v13[180][190]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=5 + + loop4: for (int v14 = 0; v14 < 38; v14++) { + loop5: for (int v15 = 0; v15 < 21; v15++) { + loop6: for (int v16 = 0; v16 < 60; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 5; v17++) { + loop8: for (int v18 = 0; v18 < 10; v18++) { + loop9: for (int v19 = 0; v19 < 3; v19++) { + if ((v18 + (v15 * 10)) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))] = v20; + } + float v21 = v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))]; + if ((v19 + (v16 * 3)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))] = v22; + } + float v23 = v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))]; + if ((v17 + (v14 * 5)) == 0) { + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v10; + } + float v24 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v26; + if (((v17 + (v14 * 5)) - 189) == 0) { + float v27 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v28[190][220], + float v29[220][210], + hls::stream v30[5][10], + float v31 +) { + #pragma HLS array_partition variable=v28 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + float v32[190][210]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=10 + + loop10: for (int v33 = 0; v33 < 38; v33++) { + loop11: for (int v34 = 0; v34 < 55; v34++) { + loop12: for (int v35 = 0; v35 < 21; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v36 = 0; v36 < 5; v36++) { + loop14: for (int v37 = 0; v37 < 4; v37++) { + loop15: for (int v38 = 0; v38 < 10; v38++) { + float v39 = v28[(v36 + (v33 * 5))][(v37 + (v34 * 4))]; + float v40 = v29[(v37 + (v34 * 4))][(v38 + (v35 * 10))]; + if ((v37 + (v34 * 4)) == 0) { + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v31; + } + float v41 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v43; + if (((v37 + (v34 * 4)) - 219) == 0) { + float v44 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + v30[v36][v38].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[200][190], + float v46[180][200], + hls::stream v47[3][5], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=10 + + float v49[180][190]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=5 + + loop16: for (int v50 = 0; v50 < 38; v50++) { + loop17: for (int v51 = 0; v51 < 20; v51++) { + loop18: for (int v52 = 0; v52 < 60; v52++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v53 = 0; v53 < 5; v53++) { + loop20: for (int v54 = 0; v54 < 10; v54++) { + loop21: for (int v55 = 0; v55 < 3; v55++) { + float v56 = v46[(v55 + (v52 * 3))][(v54 + (v51 * 10))]; + float v57 = v45[(v54 + (v51 * 10))][(v53 + (v50 * 5))]; + if ((v54 + (v51 * 10)) == 0) { + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v48; + } + float v58 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + float v59 = v56 * v57; + float v60 = v58 + v59; + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v60; + if (((v54 + (v51 * 10)) - 199) == 0) { + float v61 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + v47[v55][v53].write(v61); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v62[180][200], + float v63[200][190], + float v64[190][220], + float v65[220][210], + float v66[180][210] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=10 + + hls::stream v67[3][10]; + #pragma HLS STREAM variable=v67 depth=1260 + hls::stream v68[5][10]; + #pragma HLS STREAM variable=v68 depth=798 + hls::stream v69[3][5]; + #pragma HLS STREAM variable=v69 depth=2280 + node3(v63, v62, v69, 0.000000); + node2(v64, v65, v68, 0.000000); + node1(v69, v68, v67, 0.000000); + node0(v67, v66); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt5/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt5/src/k3mm.cpp new file mode 100644 index 000000000000..302c9e31d0c5 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k3mm__opt5/src/k3mm.cpp @@ -0,0 +1,222 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[3][10], + float v1[180][210] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=10 + + loop0: for (int v2 = 0; v2 < 21; v2++) { + loop1: for (int v3 = 0; v3 < 60; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 10; v4++) { + loop3: for (int v5 = 0; v5 < 3; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 3))][(v4 + (v2 * 10))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[3][5], + hls::stream v8[5][10], + hls::stream v9[3][10], + float v10 +) { + float v11[180][210]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=10 + + float v12[190][210]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=10 + + float v13[180][190]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=5 + + loop4: for (int v14 = 0; v14 < 38; v14++) { + loop5: for (int v15 = 0; v15 < 21; v15++) { + loop6: for (int v16 = 0; v16 < 60; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 5; v17++) { + loop8: for (int v18 = 0; v18 < 10; v18++) { + loop9: for (int v19 = 0; v19 < 3; v19++) { + if ((v18 + (v15 * 10)) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))] = v20; + } + float v21 = v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))]; + if ((v19 + (v16 * 3)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))] = v22; + } + float v23 = v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))]; + if ((v17 + (v14 * 5)) == 0) { + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v10; + } + float v24 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v26; + if (((v17 + (v14 * 5)) - 189) == 0) { + float v27 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v28[190][220], + float v29[220][210], + hls::stream v30[5][10], + float v31 +) { + #pragma HLS array_partition variable=v28 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + float v32[190][210]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=10 + + loop10: for (int v33 = 0; v33 < 38; v33++) { + loop11: for (int v34 = 0; v34 < 55; v34++) { + loop12: for (int v35 = 0; v35 < 21; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v36 = 0; v36 < 5; v36++) { + loop14: for (int v37 = 0; v37 < 4; v37++) { + loop15: for (int v38 = 0; v38 < 10; v38++) { + float v39 = v28[(v36 + (v33 * 5))][(v37 + (v34 * 4))]; + float v40 = v29[(v37 + (v34 * 4))][(v38 + (v35 * 10))]; + if ((v37 + (v34 * 4)) == 0) { + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v31; + } + float v41 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v43; + if (((v37 + (v34 * 4)) - 219) == 0) { + float v44 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + v30[v36][v38].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[180][200], + float v46[200][190], + hls::stream v47[3][5], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=5 + + float v49[180][190]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=5 + + loop16: for (int v50 = 0; v50 < 38; v50++) { + loop17: for (int v51 = 0; v51 < 20; v51++) { + loop18: for (int v52 = 0; v52 < 60; v52++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v53 = 0; v53 < 5; v53++) { + loop20: for (int v54 = 0; v54 < 10; v54++) { + loop21: for (int v55 = 0; v55 < 3; v55++) { + float v56 = v45[(v55 + (v52 * 3))][(v54 + (v51 * 10))]; + float v57 = v46[(v54 + (v51 * 10))][(v53 + (v50 * 5))]; + if ((v54 + (v51 * 10)) == 0) { + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v48; + } + float v58 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + float v59 = v56 * v57; + float v60 = v58 + v59; + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v60; + if (((v54 + (v51 * 10)) - 199) == 0) { + float v61 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + v47[v55][v53].write(v61); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v62[180][200], + float v63[200][190], + float v64[190][220], + float v65[220][210], + float v66[180][210] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=10 + + hls::stream v67[3][10]; + #pragma HLS STREAM variable=v67 depth=1260 + hls::stream v68[5][10]; + #pragma HLS STREAM variable=v68 depth=798 + hls::stream v69[3][5]; + #pragma HLS STREAM variable=v69 depth=2280 + node3(v62, v63, v69, 0.000000); + node2(v64, v65, v68, 0.000000); + node1(v69, v68, v67, 0.000000); + node0(v67, v66); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..610ad767f306 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][64] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 64; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[64][64], + hls::stream &v7, + float v8 +) { + float v9[64][64]; + float v10[64][64]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 64; v12++) { + loop4: for (int v13 = 0; v13 < 64; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v12 == 0) { + float v14 = v5.read(); + v10[v11][v13] = v14; + } + float v15 = v10[v11][v13]; + float v16 = v6[v13][v12]; + if (v13 == 0) { + v9[v11][v12] = v8; + } + float v17 = v9[v11][v12]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v12] = v19; + if ((v13 - 63) == 0) { + float v20 = v9[v11][v12]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][64], + hls::stream &v23, + float v24 +) { + float v25[64][64]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 64; v28++) { + loop7: for (int v29 = 0; v29 < 64; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v28 == 0) { + float v30 = v21.read(); + v26[v27][v29] = v30; + } + float v31 = v26[v27][v29]; + float v32 = v22[v29][v28]; + if (v29 == 0) { + v25[v27][v28] = v24; + } + float v33 = v25[v27][v28]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v28] = v35; + if ((v29 - 63) == 0) { + float v36 = v25[v27][v28]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[64][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][64]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 64; v44++) { + loop10: for (int v45 = 0; v45 < 64; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v44 == 0) { + float v46 = v37.read(); + v42[v43][v45] = v46; + } + float v47 = v42[v43][v45]; + float v48 = v38[v45][v44]; + if (v45 == 0) { + v41[v43][v44] = v40; + } + float v49 = v41[v43][v44]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v44] = v51; + if ((v45 - 63) == 0) { + float v52 = v41[v43][v44]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[64][64], + hls::stream &v55, + float v56 +) { + float v57[64][64]; + float v58[64][64]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 64; v60++) { + loop13: for (int v61 = 0; v61 < 64; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { + float v62 = v53.read(); + v58[v59][v61] = v62; + } + float v63 = v58[v59][v61]; + float v64 = v54[v61][v60]; + if (v61 == 0) { + v57[v59][v60] = v56; + } + float v65 = v57[v59][v60]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v60] = v67; + if ((v61 - 63) == 0) { + float v68 = v57[v59][v60]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][64], + hls::stream &v71, + float v72 +) { + float v73[64][64]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 64; v76++) { + loop16: for (int v77 = 0; v77 < 64; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v76 == 0) { + float v78 = v69.read(); + v74[v75][v77] = v78; + } + float v79 = v74[v75][v77]; + float v80 = v70[v77][v76]; + if (v77 == 0) { + v73[v75][v76] = v72; + } + float v81 = v73[v75][v76]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v76] = v83; + if ((v77 - 63) == 0) { + float v84 = v73[v75][v76]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v92 == 0) { + float v94 = v85.read(); + v90[v91][v93] = v94; + } + float v95 = v90[v91][v93]; + float v96 = v86[v93][v92]; + if (v93 == 0) { + v89[v91][v92] = v88; + } + float v97 = v89[v91][v92]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v92] = v99; + if ((v93 - 63) == 0) { + float v100 = v89[v91][v92]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][64], + float v102[64][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 64; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v108]; + float v110 = v102[v108][v107]; + if (v108 == 0) { + v105[v106][v107] = v104; + } + float v111 = v105[v106][v107]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v107] = v113; + if ((v108 - 63) == 0) { + float v114 = v105[v106][v107]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][64], + float v116[64][64], + float v117[64][64], + float v118[64][64], + float v119[64][64], + float v120[64][64], + float v121[64][64], + float v122[64][64], + float v123[64][64] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=4096 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=4096 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=4096 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=4096 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..da1847f34942 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][64] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 64; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[64][64], + hls::stream &v7, + float v8 +) { + float v9[64][64]; + float v10[64][64]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 64; v12++) { + loop4: for (int v13 = 0; v13 < 64; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v13 == 0) { + float v14 = v5.read(); + v10[v11][v12] = v14; + } + float v15 = v10[v11][v12]; + float v16 = v6[v12][v13]; + if (v12 == 0) { + v9[v11][v13] = v8; + } + float v17 = v9[v11][v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v13] = v19; + if ((v12 - 63) == 0) { + float v20 = v9[v11][v13]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][64], + hls::stream &v23, + float v24 +) { + float v25[64][64]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 64; v28++) { + loop7: for (int v29 = 0; v29 < 64; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v29 == 0) { + float v30 = v21.read(); + v26[v27][v28] = v30; + } + float v31 = v26[v27][v28]; + float v32 = v22[v28][v29]; + if (v28 == 0) { + v25[v27][v29] = v24; + } + float v33 = v25[v27][v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v29] = v35; + if ((v28 - 63) == 0) { + float v36 = v25[v27][v29]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[64][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][64]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 64; v44++) { + loop10: for (int v45 = 0; v45 < 64; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v45 == 0) { + float v46 = v37.read(); + v42[v43][v44] = v46; + } + float v47 = v42[v43][v44]; + float v48 = v38[v44][v45]; + if (v44 == 0) { + v41[v43][v45] = v40; + } + float v49 = v41[v43][v45]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v45] = v51; + if ((v44 - 63) == 0) { + float v52 = v41[v43][v45]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[64][64], + hls::stream &v55, + float v56 +) { + float v57[64][64]; + float v58[64][64]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 64; v60++) { + loop13: for (int v61 = 0; v61 < 64; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v61 == 0) { + float v62 = v53.read(); + v58[v59][v60] = v62; + } + float v63 = v58[v59][v60]; + float v64 = v54[v60][v61]; + if (v60 == 0) { + v57[v59][v61] = v56; + } + float v65 = v57[v59][v61]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v61] = v67; + if ((v60 - 63) == 0) { + float v68 = v57[v59][v61]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][64], + hls::stream &v71, + float v72 +) { + float v73[64][64]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 64; v76++) { + loop16: for (int v77 = 0; v77 < 64; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v77 == 0) { + float v78 = v69.read(); + v74[v75][v76] = v78; + } + float v79 = v74[v75][v76]; + float v80 = v70[v76][v77]; + if (v76 == 0) { + v73[v75][v77] = v72; + } + float v81 = v73[v75][v77]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v77] = v83; + if ((v76 - 63) == 0) { + float v84 = v73[v75][v77]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v93 == 0) { + float v94 = v85.read(); + v90[v91][v92] = v94; + } + float v95 = v90[v91][v92]; + float v96 = v86[v92][v93]; + if (v92 == 0) { + v89[v91][v93] = v88; + } + float v97 = v89[v91][v93]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v93] = v99; + if ((v92 - 63) == 0) { + float v100 = v89[v91][v93]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][64], + float v102[64][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 64; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v107]; + float v110 = v102[v107][v108]; + if (v107 == 0) { + v105[v106][v108] = v104; + } + float v111 = v105[v106][v108]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v108] = v113; + if ((v107 - 63) == 0) { + float v114 = v105[v106][v108]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][64], + float v116[64][64], + float v117[64][64], + float v118[64][64], + float v119[64][64], + float v120[64][64], + float v121[64][64], + float v122[64][64], + float v123[64][64] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=4096 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=4096 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=4096 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=4096 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..30fbf33536a6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + float v8[64][64], + hls::stream v9[4][4], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=4 + + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 4; v17++) { + loop9: for (int v18 = 0; v18 < 4; v18++) { + if ((v17 + (v14 * 4)) == 0) { + float v19 = v7[v16][v18].read(); + v12[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + float v21 = v8[(v18 + (v15 * 4))][(v17 + (v14 * 4))]; + if ((v18 + (v15 * 4)) == 0) { + v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v24; + if (((v18 + (v15 * 4)) - 63) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + v9[v16][v17].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][64], + hls::stream v28[4][4], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=4 + + float v30[64][64]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=4 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v36 + (v33 * 4)) == 0) { + float v38 = v26[v35][v37].read(); + v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v40 = v27[(v37 + (v34 * 4))][(v36 + (v33 * 4))]; + if ((v37 + (v34 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v43; + if (((v37 + (v34 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + v28[v35][v36].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v45[4][4], + float v46[64][64], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][64]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v55 + (v52 * 4)) == 0) { + float v57 = v45[v54][v56].read(); + v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v59 = v46[(v56 + (v53 * 4))][(v55 + (v52 * 4))]; + if ((v56 + (v53 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v62; + if (((v56 + (v53 * 4)) - 63) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + v47[v54][v55].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[64][64], + hls::stream v65[4][4], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + float v68[64][64]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][64]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v74 + (v71 * 4)) == 0) { + float v76 = v65[v73][v75].read(); + v69[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v78 = v64[(v75 + (v72 * 4))][(v74 + (v71 * 4))]; + if ((v75 + (v72 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v81; + if (((v75 + (v72 * 4)) - 63) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + v66[v73][v74].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][64], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v93 + (v90 * 4)) == 0) { + float v95 = v83[v92][v94].read(); + v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v97 = v84[(v94 + (v91 * 4))][(v93 + (v90 * 4))]; + if ((v94 + (v91 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v100; + if (((v94 + (v91 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + v85[v92][v93].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v102[64][64], + hls::stream v103[4][4], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v102 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v102 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v112 + (v109 * 4)) == 0) { + float v114 = v103[v111][v113].read(); + v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v116 = v102[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + v104[v111][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v133 = v122[(v131 + (v128 * 4))][(v130 + (v127 * 4))]; + if ((v131 + (v128 * 4)) == 0) { + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v136; + if (((v131 + (v128 * 4)) - 63) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + v123[v129][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v140, v153, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v150, v143, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..9b7cfc44c8eb --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + float v7[64][64], + hls::stream v8[4][4], + hls::stream v9[4][4], + float v10 +) { + #pragma HLS array_partition variable=v7 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v7 cyclic dim=2 factor=4 + + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 4; v17++) { + loop9: for (int v18 = 0; v18 < 4; v18++) { + if ((v18 + (v15 * 4)) == 0) { + float v19 = v8[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + float v21 = v7[(v17 + (v14 * 4))][(v18 + (v15 * 4))]; + if ((v17 + (v14 * 4)) == 0) { + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v24; + if (((v17 + (v14 * 4)) - 63) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v26[64][64], + hls::stream v27[4][4], + hls::stream v28[4][4], + float v29 +) { + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=4 + + float v30[64][64]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=4 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v37 + (v34 * 4)) == 0) { + float v38 = v27[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v26[(v36 + (v33 * 4))][(v37 + (v34 * 4))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[64][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][64]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v46[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v59 = v45[(v55 + (v52 * 4))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 4)) - 63) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[64][64], + hls::stream v65[4][4], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + float v68[64][64]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][64]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v75 + (v72 * 4)) == 0) { + float v76 = v65[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v78 = v64[(v74 + (v71 * 4))][(v75 + (v72 * 4))]; + if ((v74 + (v71 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v81; + if (((v74 + (v71 * 4)) - 63) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][64], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v94 + (v91 * 4)) == 0) { + float v95 = v83[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v84[(v93 + (v90 * 4))][(v94 + (v91 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v113 + (v110 * 4)) == 0) { + float v114 = v102[v111][v112].read(); + v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v116 = v103[(v112 + (v109 * 4))][(v113 + (v110 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v119; + if (((v112 + (v109 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + v104[v111][v113].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v133 = v121[(v130 + (v127 * 4))][(v131 + (v128 * 4))]; + if ((v130 + (v127 * 4)) == 0) { + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v136; + if (((v130 + (v127 * 4)) - 63) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + v123[v129][v131].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v144, v149, v148, 0.000000); + node1(v145, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..4fbb80d4d29a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + float v8[64][64], + hls::stream v9[4][4], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=4 + + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 4; v17++) { + loop9: for (int v18 = 0; v18 < 4; v18++) { + if ((v18 + (v15 * 4)) == 0) { + float v19 = v7[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + float v21 = v8[(v17 + (v14 * 4))][(v18 + (v15 * 4))]; + if ((v17 + (v14 * 4)) == 0) { + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v24; + if (((v17 + (v14 * 4)) - 63) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][64], + hls::stream v28[4][4], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=4 + + float v30[64][64]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=4 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v37 + (v34 * 4)) == 0) { + float v38 = v26[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v27[(v36 + (v33 * 4))][(v37 + (v34 * 4))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[64][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][64]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v46[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v59 = v45[(v55 + (v52 * 4))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 4)) - 63) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[64][64], + hls::stream v65[4][4], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + float v68[64][64]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][64]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v75 + (v72 * 4)) == 0) { + float v76 = v65[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v78 = v64[(v74 + (v71 * 4))][(v75 + (v72 * 4))]; + if ((v74 + (v71 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v81; + if (((v74 + (v71 * 4)) - 63) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][64], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v94 + (v91 * 4)) == 0) { + float v95 = v83[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v84[(v93 + (v90 * 4))][(v94 + (v91 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v113 + (v110 * 4)) == 0) { + float v114 = v102[v111][v112].read(); + v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v116 = v103[(v112 + (v109 * 4))][(v113 + (v110 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v119; + if (((v112 + (v109 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + v104[v111][v113].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v133 = v121[(v130 + (v127 * 4))][(v131 + (v128 * 4))]; + if ((v130 + (v127 * 4)) == 0) { + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v136; + if (((v130 + (v127 * 4)) - 63) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + v123[v129][v131].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..f04050d017da --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][16] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[32][16], + hls::stream &v7, + float v8 +) { + float v9[64][16]; + float v10[64][32]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 16; v12++) { + loop4: for (int v13 = 0; v13 < 32; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v12 == 0) { + float v14 = v5.read(); + v10[v11][v13] = v14; + } + float v15 = v10[v11][v13]; + float v16 = v6[v13][v12]; + if (v13 == 0) { + v9[v11][v12] = v8; + } + float v17 = v9[v11][v12]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v12] = v19; + if ((v13 - 31) == 0) { + float v20 = v9[v11][v12]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][32], + hls::stream &v23, + float v24 +) { + float v25[64][32]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 32; v28++) { + loop7: for (int v29 = 0; v29 < 64; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v28 == 0) { + float v30 = v21.read(); + v26[v27][v29] = v30; + } + float v31 = v26[v27][v29]; + float v32 = v22[v29][v28]; + if (v29 == 0) { + v25[v27][v28] = v24; + } + float v33 = v25[v27][v28]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v28] = v35; + if ((v29 - 63) == 0) { + float v36 = v25[v27][v28]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[128][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][128]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 64; v44++) { + loop10: for (int v45 = 0; v45 < 128; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v44 == 0) { + float v46 = v37.read(); + v42[v43][v45] = v46; + } + float v47 = v42[v43][v45]; + float v48 = v38[v45][v44]; + if (v45 == 0) { + v41[v43][v44] = v40; + } + float v49 = v41[v43][v44]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v44] = v51; + if ((v45 - 127) == 0) { + float v52 = v41[v43][v44]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[128][128], + hls::stream &v55, + float v56 +) { + float v57[64][128]; + float v58[64][128]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 128; v60++) { + loop13: for (int v61 = 0; v61 < 128; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { + float v62 = v53.read(); + v58[v59][v61] = v62; + } + float v63 = v58[v59][v61]; + float v64 = v54[v61][v60]; + if (v61 == 0) { + v57[v59][v60] = v56; + } + float v65 = v57[v59][v60]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v60] = v67; + if ((v61 - 127) == 0) { + float v68 = v57[v59][v60]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][128], + hls::stream &v71, + float v72 +) { + float v73[64][128]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 128; v76++) { + loop16: for (int v77 = 0; v77 < 64; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v76 == 0) { + float v78 = v69.read(); + v74[v75][v77] = v78; + } + float v79 = v74[v75][v77]; + float v80 = v70[v77][v76]; + if (v77 == 0) { + v73[v75][v76] = v72; + } + float v81 = v73[v75][v76]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v76] = v83; + if ((v77 - 63) == 0) { + float v84 = v73[v75][v76]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v92 == 0) { + float v94 = v85.read(); + v90[v91][v93] = v94; + } + float v95 = v90[v91][v93]; + float v96 = v86[v93][v92]; + if (v93 == 0) { + v89[v91][v92] = v88; + } + float v97 = v89[v91][v92]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v92] = v99; + if ((v93 - 63) == 0) { + float v100 = v89[v91][v92]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][32], + float v102[32][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 32; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v108]; + float v110 = v102[v108][v107]; + if (v108 == 0) { + v105[v106][v107] = v104; + } + float v111 = v105[v106][v107]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v107] = v113; + if ((v108 - 31) == 0) { + float v114 = v105[v106][v107]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][32], + float v116[32][64], + float v117[64][64], + float v118[64][128], + float v119[128][128], + float v120[128][64], + float v121[64][32], + float v122[32][16], + float v123[64][16] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=1024 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=2048 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=8192 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=8192 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..1282c774174f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][16] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[32][16], + hls::stream &v7, + float v8 +) { + float v9[64][16]; + float v10[64][32]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 32; v12++) { + loop4: for (int v13 = 0; v13 < 16; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v13 == 0) { + float v14 = v5.read(); + v10[v11][v12] = v14; + } + float v15 = v10[v11][v12]; + float v16 = v6[v12][v13]; + if (v12 == 0) { + v9[v11][v13] = v8; + } + float v17 = v9[v11][v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v13] = v19; + if ((v12 - 31) == 0) { + float v20 = v9[v11][v13]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][32], + hls::stream &v23, + float v24 +) { + float v25[64][32]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 64; v28++) { + loop7: for (int v29 = 0; v29 < 32; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v29 == 0) { + float v30 = v21.read(); + v26[v27][v28] = v30; + } + float v31 = v26[v27][v28]; + float v32 = v22[v28][v29]; + if (v28 == 0) { + v25[v27][v29] = v24; + } + float v33 = v25[v27][v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v29] = v35; + if ((v28 - 63) == 0) { + float v36 = v25[v27][v29]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[128][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][128]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 128; v44++) { + loop10: for (int v45 = 0; v45 < 64; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v45 == 0) { + float v46 = v37.read(); + v42[v43][v44] = v46; + } + float v47 = v42[v43][v44]; + float v48 = v38[v44][v45]; + if (v44 == 0) { + v41[v43][v45] = v40; + } + float v49 = v41[v43][v45]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v45] = v51; + if ((v44 - 127) == 0) { + float v52 = v41[v43][v45]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[128][128], + hls::stream &v55, + float v56 +) { + float v57[64][128]; + float v58[64][128]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 128; v60++) { + loop13: for (int v61 = 0; v61 < 128; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v61 == 0) { + float v62 = v53.read(); + v58[v59][v60] = v62; + } + float v63 = v58[v59][v60]; + float v64 = v54[v60][v61]; + if (v60 == 0) { + v57[v59][v61] = v56; + } + float v65 = v57[v59][v61]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v61] = v67; + if ((v60 - 127) == 0) { + float v68 = v57[v59][v61]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][128], + hls::stream &v71, + float v72 +) { + float v73[64][128]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 64; v76++) { + loop16: for (int v77 = 0; v77 < 128; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v77 == 0) { + float v78 = v69.read(); + v74[v75][v76] = v78; + } + float v79 = v74[v75][v76]; + float v80 = v70[v76][v77]; + if (v76 == 0) { + v73[v75][v77] = v72; + } + float v81 = v73[v75][v77]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v77] = v83; + if ((v76 - 63) == 0) { + float v84 = v73[v75][v77]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v92 == 0) { + float v94 = v85.read(); + v90[v91][v93] = v94; + } + float v95 = v90[v91][v93]; + float v96 = v86[v93][v92]; + if (v93 == 0) { + v89[v91][v92] = v88; + } + float v97 = v89[v91][v92]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v92] = v99; + if ((v93 - 63) == 0) { + float v100 = v89[v91][v92]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][32], + float v102[32][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 32; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v108]; + float v110 = v102[v108][v107]; + if (v108 == 0) { + v105[v106][v107] = v104; + } + float v111 = v105[v106][v107]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v107] = v113; + if ((v108 - 31) == 0) { + float v114 = v105[v106][v107]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][32], + float v116[32][64], + float v117[64][64], + float v118[64][128], + float v119[128][128], + float v120[128][64], + float v121[64][32], + float v122[32][16], + float v123[64][16] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=1024 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=2048 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=8192 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=8192 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..48d9fb758721 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,449 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + float v7[32][16], + hls::stream v8[4][2], + hls::stream v9[4][1], + float v10 +) { + #pragma HLS array_partition variable=v7 cyclic dim=1 factor=2 + + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[64][32]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 1; v17++) { + loop9: for (int v18 = 0; v18 < 2; v18++) { + if ((v14 + v17) == 0) { + float v19 = v8[v16][v18].read(); + v12[(v16 + (v13 * 4))][(v18 + (v15 * 2))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v18 + (v15 * 2))]; + float v21 = v7[(v18 + (v15 * 2))][(v14 + v17)]; + if ((v18 + (v15 * 2)) == 0) { + v11[(v16 + (v13 * 4))][(v14 + v17)] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v14 + v17)]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v14 + v17)] = v24; + if (((v18 + (v15 * 2)) - 31) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v14 + v17)]; + v9[v16][v17].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][32], + hls::stream v28[4][2], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=2 + + float v30[64][32]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 2; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v36 + (v33 * 2)) == 0) { + float v38 = v26[v35][v37].read(); + v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v40 = v27[(v37 + (v34 * 4))][(v36 + (v33 * 2))]; + if ((v37 + (v34 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))] = v43; + if (((v37 + (v34 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))]; + v28[v35][v36].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[128][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][128]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 32; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v55 + (v52 * 4)) == 0) { + float v57 = v46[v54][v56].read(); + v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v59 = v45[(v56 + (v53 * 4))][(v55 + (v52 * 4))]; + if ((v56 + (v53 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v62; + if (((v56 + (v53 * 4)) - 127) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + v47[v54][v55].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v64[4][8], + float v65[128][128], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=4 + + float v68[64][128]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][128]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=8 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 32; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 8; v75++) { + if ((v74 + (v71 * 4)) == 0) { + float v76 = v64[v73][v75].read(); + v69[(v73 + (v70 * 4))][(v75 + (v72 * 8))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v75 + (v72 * 8))]; + float v78 = v65[(v75 + (v72 * 8))][(v74 + (v71 * 4))]; + if ((v75 + (v72 * 8)) == 0) { + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v81; + if (((v75 + (v72 * 8)) - 127) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + v66[v73][v74].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v83[64][128], + hls::stream v84[4][4], + hls::stream v85[4][8], + float v86 +) { + #pragma HLS array_partition variable=v83 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v83 cyclic dim=2 factor=8 + + float v87[64][128]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=8 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 8; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v93 + (v90 * 8)) == 0) { + float v95 = v84[v92][v94].read(); + v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v97 = v83[(v94 + (v91 * 4))][(v93 + (v90 * 8))]; + if ((v94 + (v91 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))] = v100; + if (((v94 + (v91 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))]; + v85[v92][v93].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v112 + (v109 * 4)) == 0) { + float v114 = v102[v111][v113].read(); + v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v116 = v103[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + v104[v111][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[32][64], + float v122[64][32], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=2 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 2; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v131 + (v128 * 2))]; + float v133 = v121[(v131 + (v128 * 2))][(v130 + (v127 * 4))]; + if ((v131 + (v128 * 2)) == 0) { + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v136; + if (((v131 + (v128 * 2)) - 31) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + v123[v129][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][2]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=512 + hls::stream v151[4][8]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v141, v152, v151, 0.000000); + node4(v151, v142, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v145, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..8866264cc737 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,449 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][2], + float v8[32][16], + hls::stream v9[4][1], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[64][32]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 2; v17++) { + loop9: for (int v18 = 0; v18 < 1; v18++) { + if ((v15 + v18) == 0) { + float v19 = v7[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))]; + float v21 = v8[(v17 + (v14 * 2))][(v15 + v18)]; + if ((v17 + (v14 * 2)) == 0) { + v11[(v16 + (v13 * 4))][(v15 + v18)] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v15 + v18)] = v24; + if (((v17 + (v14 * 2)) - 31) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][32], + hls::stream v28[4][2], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=2 + + float v30[64][32]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 2; v37++) { + if ((v37 + (v34 * 2)) == 0) { + float v38 = v26[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v27[(v36 + (v33 * 4))][(v37 + (v34 * 2))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[128][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][128]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 32; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v46[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v59 = v45[(v55 + (v52 * 4))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 4)) - 127) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v64[4][8], + float v65[128][128], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=4 + + float v68[64][128]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][128]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=8 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 32; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 8; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v75 + (v72 * 4)) == 0) { + float v76 = v64[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 8))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 8))]; + float v78 = v65[(v74 + (v71 * 8))][(v75 + (v72 * 4))]; + if ((v74 + (v71 * 8)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v81; + if (((v74 + (v71 * 8)) - 127) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v83[64][128], + hls::stream v84[4][4], + hls::stream v85[4][8], + float v86 +) { + #pragma HLS array_partition variable=v83 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v83 cyclic dim=2 factor=8 + + float v87[64][128]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=8 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 8; v94++) { + if ((v94 + (v91 * 8)) == 0) { + float v95 = v84[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v83[(v93 + (v90 * 4))][(v94 + (v91 * 8))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v102[64][64], + hls::stream v103[4][4], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v102 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v102 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v112 + (v109 * 4)) == 0) { + float v114 = v103[v111][v113].read(); + v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v116 = v102[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + v104[v111][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][32], + float v122[32][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 2; v131++) { + float v132 = v121[(v129 + (v126 * 4))][(v131 + (v128 * 2))]; + float v133 = v122[(v131 + (v128 * 2))][(v130 + (v127 * 4))]; + if ((v131 + (v128 * 2)) == 0) { + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v136; + if (((v131 + (v128 * 2)) - 31) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + v123[v129][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][2]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=512 + hls::stream v151[4][8]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v140, v153, v152, 0.000000); + node5(v141, v152, v151, 0.000000); + node4(v151, v142, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..a74a0ef2b42c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,449 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][2], + float v8[32][16], + hls::stream v9[4][1], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[64][32]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 2; v17++) { + loop9: for (int v18 = 0; v18 < 1; v18++) { + if ((v15 + v18) == 0) { + float v19 = v7[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))]; + float v21 = v8[(v17 + (v14 * 2))][(v15 + v18)]; + if ((v17 + (v14 * 2)) == 0) { + v11[(v16 + (v13 * 4))][(v15 + v18)] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v15 + v18)] = v24; + if (((v17 + (v14 * 2)) - 31) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][32], + hls::stream v28[4][2], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=2 + + float v30[64][32]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 2; v37++) { + if ((v37 + (v34 * 2)) == 0) { + float v38 = v26[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v27[(v36 + (v33 * 4))][(v37 + (v34 * 2))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v45[4][8], + float v46[128][64], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][128]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=8 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 8; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v45[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 8))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 8))]; + float v59 = v46[(v55 + (v52 * 8))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 8)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 8)) - 127) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[128][128], + hls::stream v65[4][4], + hls::stream v66[4][8], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + float v68[64][128]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=8 + + float v69[64][128]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 32; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 8; v75++) { + if ((v75 + (v72 * 8)) == 0) { + float v76 = v65[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v78 = v64[(v74 + (v71 * 4))][(v75 + (v72 * 8))]; + if ((v74 + (v71 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))] = v81; + if (((v74 + (v71 * 4)) - 127) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][128], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][128]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 32; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v94 + (v91 * 4)) == 0) { + float v95 = v83[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v84[(v93 + (v90 * 4))][(v94 + (v91 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v113 + (v110 * 4)) == 0) { + float v114 = v102[v111][v112].read(); + v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v116 = v103[(v112 + (v109 * 4))][(v113 + (v110 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v119; + if (((v112 + (v109 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + v104[v111][v113].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[32][64], + float v122[64][32], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=2 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 2; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 2))]; + float v133 = v121[(v130 + (v127 * 2))][(v131 + (v128 * 4))]; + if ((v130 + (v127 * 2)) == 0) { + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v136; + if (((v130 + (v127 * 2)) - 31) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + v123[v129][v131].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][2]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][8]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=512 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v150, v143, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp new file mode 100644 index 000000000000..50c0c6522a0a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v4 + (v2 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + hls::stream v8[4][4], + hls::stream v9[4][4], + float v10 +) { + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + float v13[64][64]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=4 + + loop4: for (int v14 = 0; v14 < 16; v14++) { + loop5: for (int v15 = 0; v15 < 16; v15++) { + loop6: for (int v16 = 0; v16 < 16; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 4; v17++) { + loop8: for (int v18 = 0; v18 < 4; v18++) { + loop9: for (int v19 = 0; v19 < 4; v19++) { + if ((v18 + (v15 * 4)) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 4))][(v17 + (v14 * 4))] = v20; + } + float v21 = v13[(v19 + (v16 * 4))][(v17 + (v14 * 4))]; + if ((v19 + (v16 * 4)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 4))][(v18 + (v15 * 4))] = v22; + } + float v23 = v12[(v17 + (v14 * 4))][(v18 + (v15 * 4))]; + if ((v17 + (v14 * 4)) == 0) { + v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))] = v10; + } + float v24 = v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))] = v26; + if (((v17 + (v14 * 4)) - 63) == 0) { + float v27 = v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v28[4][4], + hls::stream v29[4][4], + hls::stream v30[4][4], + float v31 +) { + float v32[64][64]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=4 + + float v33[64][64]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=4 + + float v34[64][64]; + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v34 cyclic dim=2 factor=4 + + loop10: for (int v35 = 0; v35 < 16; v35++) { + loop11: for (int v36 = 0; v36 < 16; v36++) { + loop12: for (int v37 = 0; v37 < 16; v37++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v38 = 0; v38 < 4; v38++) { + loop14: for (int v39 = 0; v39 < 4; v39++) { + loop15: for (int v40 = 0; v40 < 4; v40++) { + if ((v40 + (v37 * 4)) == 0) { + float v41 = v29[v38][v39].read(); + v34[(v38 + (v35 * 4))][(v39 + (v36 * 4))] = v41; + } + float v42 = v34[(v38 + (v35 * 4))][(v39 + (v36 * 4))]; + if ((v38 + (v35 * 4)) == 0) { + float v43 = v28[v39][v40].read(); + v33[(v39 + (v36 * 4))][(v40 + (v37 * 4))] = v43; + } + float v44 = v33[(v39 + (v36 * 4))][(v40 + (v37 * 4))]; + if ((v39 + (v36 * 4)) == 0) { + v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))] = v31; + } + float v45 = v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))]; + float v46 = v42 * v44; + float v47 = v45 + v46; + v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))] = v47; + if (((v39 + (v36 * 4)) - 63) == 0) { + float v48 = v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))]; + v30[v38][v40].write(v48); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v49[4][4], + hls::stream v50[4][4], + hls::stream v51[4][4], + float v52 +) { + float v53[64][64]; + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=4 + + float v54[64][64]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=4 + + float v55[64][64]; + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=4 + + loop16: for (int v56 = 0; v56 < 16; v56++) { + loop17: for (int v57 = 0; v57 < 16; v57++) { + loop18: for (int v58 = 0; v58 < 16; v58++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v59 = 0; v59 < 4; v59++) { + loop20: for (int v60 = 0; v60 < 4; v60++) { + loop21: for (int v61 = 0; v61 < 4; v61++) { + if ((v59 + (v56 * 4)) == 0) { + float v62 = v49[v61][v60].read(); + v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))] = v62; + } + float v63 = v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))]; + if ((v61 + (v58 * 4)) == 0) { + float v64 = v50[v60][v59].read(); + v54[(v60 + (v57 * 4))][(v59 + (v56 * 4))] = v64; + } + float v65 = v54[(v60 + (v57 * 4))][(v59 + (v56 * 4))]; + if ((v60 + (v57 * 4)) == 0) { + v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))] = v52; + } + float v66 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))]; + float v67 = v63 * v65; + float v68 = v66 + v67; + v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))] = v68; + if (((v60 + (v57 * 4)) - 63) == 0) { + float v69 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))]; + v51[v61][v59].write(v69); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v70[64][64], + float v71[64][64], + hls::stream v72[4][4], + float v73 +) { + #pragma HLS array_partition variable=v70 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v70 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v71 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v71 cyclic dim=2 factor=4 + + float v74[64][64]; + #pragma HLS array_partition variable=v74 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v74 cyclic dim=2 factor=4 + + loop22: for (int v75 = 0; v75 < 16; v75++) { + loop23: for (int v76 = 0; v76 < 16; v76++) { + loop24: for (int v77 = 0; v77 < 16; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v78 = 0; v78 < 4; v78++) { + loop26: for (int v79 = 0; v79 < 4; v79++) { + loop27: for (int v80 = 0; v80 < 4; v80++) { + float v81 = v70[(v79 + (v76 * 4))][(v78 + (v75 * 4))]; + float v82 = v71[(v78 + (v75 * 4))][(v80 + (v77 * 4))]; + if ((v78 + (v75 * 4)) == 0) { + v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))] = v73; + } + float v83 = v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))] = v85; + if (((v78 + (v75 * 4)) - 63) == 0) { + float v86 = v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))]; + v72[v79][v80].write(v86); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v87[64][64], + float v88[64][64], + hls::stream v89[4][4], + float v90 +) { + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + float v91[64][64]; + #pragma HLS array_partition variable=v91 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v91 cyclic dim=2 factor=4 + + loop28: for (int v92 = 0; v92 < 16; v92++) { + loop29: for (int v93 = 0; v93 < 16; v93++) { + loop30: for (int v94 = 0; v94 < 16; v94++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v95 = 0; v95 < 4; v95++) { + loop32: for (int v96 = 0; v96 < 4; v96++) { + loop33: for (int v97 = 0; v97 < 4; v97++) { + float v98 = v88[(v96 + (v93 * 4))][(v95 + (v92 * 4))]; + float v99 = v87[(v95 + (v92 * 4))][(v97 + (v94 * 4))]; + if ((v95 + (v92 * 4)) == 0) { + v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))] = v90; + } + float v100 = v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))]; + float v101 = v98 * v99; + float v102 = v100 + v101; + v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))] = v102; + if (((v95 + (v92 * 4)) - 63) == 0) { + float v103 = v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))]; + v89[v96][v97].write(v103); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v104[64][64], + float v105[64][64], + hls::stream v106[4][4], + float v107 +) { + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v105 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=4 + + float v108[64][64]; + #pragma HLS array_partition variable=v108 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v108 cyclic dim=2 factor=4 + + loop34: for (int v109 = 0; v109 < 16; v109++) { + loop35: for (int v110 = 0; v110 < 16; v110++) { + loop36: for (int v111 = 0; v111 < 16; v111++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v112 = 0; v112 < 4; v112++) { + loop38: for (int v113 = 0; v113 < 4; v113++) { + loop39: for (int v114 = 0; v114 < 4; v114++) { + float v115 = v105[(v114 + (v111 * 4))][(v113 + (v110 * 4))]; + float v116 = v104[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))] = v107; + } + float v117 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))]; + v106[v114][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[(v131 + (v128 * 4))][(v129 + (v126 * 4))]; + float v133 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + if ((v129 + (v126 * 4)) == 0) { + v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))] = v136; + if (((v129 + (v126 * 4)) - 63) == 0) { + float v137 = v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))]; + v123[v131][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v141, v140, v152, 0.000000); + node5(v143, v142, v151, 0.000000); + node4(v144, v145, v150, 0.000000); + node3(v153, v152, v149, 0.000000); + node2(v150, v151, v148, 0.000000); + node1(v149, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp new file mode 100644 index 000000000000..1e311dbe015f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp @@ -0,0 +1,445 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v2 + v4)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][8], + hls::stream v8[8][1], + hls::stream v9[4][1], + float v10 +) { + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[128][16]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=8 + + float v13[64][128]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=8 + + loop4: for (int v14 = 0; v14 < 16; v14++) { + loop5: for (int v15 = 0; v15 < 16; v15++) { + loop6: for (int v16 = 0; v16 < 16; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 8; v17++) { + loop8: for (int v18 = 0; v18 < 1; v18++) { + loop9: for (int v19 = 0; v19 < 4; v19++) { + if ((v15 + v18) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 4))][(v17 + (v14 * 8))] = v20; + } + float v21 = v13[(v19 + (v16 * 4))][(v17 + (v14 * 8))]; + if ((v19 + (v16 * 4)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 8))][(v15 + v18)] = v22; + } + float v23 = v12[(v17 + (v14 * 8))][(v15 + v18)]; + if ((v17 + (v14 * 8)) == 0) { + v11[(v19 + (v16 * 4))][(v15 + v18)] = v10; + } + float v24 = v11[(v19 + (v16 * 4))][(v15 + v18)]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 4))][(v15 + v18)] = v26; + if (((v17 + (v14 * 8)) - 127) == 0) { + float v27 = v11[(v19 + (v16 * 4))][(v15 + v18)]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v28[8][4], + hls::stream v29[4][1], + hls::stream v30[8][1], + float v31 +) { + float v32[128][16]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=8 + + float v33[64][16]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=4 + + float v34[128][64]; + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v34 cyclic dim=2 factor=4 + + loop10: for (int v35 = 0; v35 < 16; v35++) { + loop11: for (int v36 = 0; v36 < 16; v36++) { + loop12: for (int v37 = 0; v37 < 16; v37++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v38 = 0; v38 < 8; v38++) { + loop14: for (int v39 = 0; v39 < 4; v39++) { + loop15: for (int v40 = 0; v40 < 1; v40++) { + if ((v37 + v40) == 0) { + float v41 = v28[v38][v39].read(); + v34[(v38 + (v35 * 8))][(v39 + (v36 * 4))] = v41; + } + float v42 = v34[(v38 + (v35 * 8))][(v39 + (v36 * 4))]; + if ((v38 + (v35 * 8)) == 0) { + float v43 = v29[v39][v40].read(); + v33[(v39 + (v36 * 4))][(v37 + v40)] = v43; + } + float v44 = v33[(v39 + (v36 * 4))][(v37 + v40)]; + if ((v39 + (v36 * 4)) == 0) { + v32[(v38 + (v35 * 8))][(v37 + v40)] = v31; + } + float v45 = v32[(v38 + (v35 * 8))][(v37 + v40)]; + float v46 = v42 * v44; + float v47 = v45 + v46; + v32[(v38 + (v35 * 8))][(v37 + v40)] = v47; + if (((v39 + (v36 * 4)) - 63) == 0) { + float v48 = v32[(v38 + (v35 * 8))][(v37 + v40)]; + v30[v38][v40].write(v48); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v49[4][8], + hls::stream v50[4][4], + hls::stream v51[4][8], + float v52 +) { + float v53[64][128]; + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=8 + + float v54[64][128]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=8 + + float v55[64][64]; + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=4 + + loop16: for (int v56 = 0; v56 < 16; v56++) { + loop17: for (int v57 = 0; v57 < 16; v57++) { + loop18: for (int v58 = 0; v58 < 16; v58++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v59 = 0; v59 < 8; v59++) { + loop20: for (int v60 = 0; v60 < 4; v60++) { + loop21: for (int v61 = 0; v61 < 4; v61++) { + if ((v59 + (v56 * 8)) == 0) { + float v62 = v50[v61][v60].read(); + v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))] = v62; + } + float v63 = v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))]; + if ((v61 + (v58 * 4)) == 0) { + float v64 = v49[v60][v59].read(); + v54[(v60 + (v57 * 4))][(v59 + (v56 * 8))] = v64; + } + float v65 = v54[(v60 + (v57 * 4))][(v59 + (v56 * 8))]; + if ((v60 + (v57 * 4)) == 0) { + v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))] = v52; + } + float v66 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))]; + float v67 = v63 * v65; + float v68 = v66 + v67; + v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))] = v68; + if (((v60 + (v57 * 4)) - 63) == 0) { + float v69 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))]; + v51[v61][v59].write(v69); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v70[64][32], + float v71[32][16], + hls::stream v72[4][1], + float v73 +) { + #pragma HLS array_partition variable=v70 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v70 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v71 cyclic dim=1 factor=2 + + float v74[64][16]; + #pragma HLS array_partition variable=v74 cyclic dim=1 factor=4 + + loop22: for (int v75 = 0; v75 < 16; v75++) { + loop23: for (int v76 = 0; v76 < 16; v76++) { + loop24: for (int v77 = 0; v77 < 16; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v78 = 0; v78 < 2; v78++) { + loop26: for (int v79 = 0; v79 < 4; v79++) { + loop27: for (int v80 = 0; v80 < 1; v80++) { + float v81 = v70[(v79 + (v76 * 4))][(v78 + (v75 * 2))]; + float v82 = v71[(v78 + (v75 * 2))][(v77 + v80)]; + if ((v78 + (v75 * 2)) == 0) { + v74[(v79 + (v76 * 4))][(v77 + v80)] = v73; + } + float v83 = v74[(v79 + (v76 * 4))][(v77 + v80)]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v74[(v79 + (v76 * 4))][(v77 + v80)] = v85; + if (((v78 + (v75 * 2)) - 31) == 0) { + float v86 = v74[(v79 + (v76 * 4))][(v77 + v80)]; + v72[v79][v80].write(v86); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v87[128][128], + float v88[128][64], + hls::stream v89[8][4], + float v90 +) { + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + float v91[128][64]; + #pragma HLS array_partition variable=v91 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v91 cyclic dim=2 factor=4 + + loop28: for (int v92 = 0; v92 < 16; v92++) { + loop29: for (int v93 = 0; v93 < 32; v93++) { + loop30: for (int v94 = 0; v94 < 16; v94++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v95 = 0; v95 < 8; v95++) { + loop32: for (int v96 = 0; v96 < 4; v96++) { + loop33: for (int v97 = 0; v97 < 4; v97++) { + float v98 = v87[(v95 + (v92 * 8))][(v96 + (v93 * 4))]; + float v99 = v88[(v96 + (v93 * 4))][(v97 + (v94 * 4))]; + if ((v96 + (v93 * 4)) == 0) { + v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))] = v90; + } + float v100 = v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))]; + float v101 = v98 * v99; + float v102 = v100 + v101; + v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))] = v102; + if (((v96 + (v93 * 4)) - 127) == 0) { + float v103 = v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))]; + v89[v95][v97].write(v103); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v104[64][64], + float v105[64][128], + hls::stream v106[4][8], + float v107 +) { + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v105 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=8 + + float v108[64][128]; + #pragma HLS array_partition variable=v108 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v108 cyclic dim=2 factor=8 + + loop34: for (int v109 = 0; v109 < 16; v109++) { + loop35: for (int v110 = 0; v110 < 16; v110++) { + loop36: for (int v111 = 0; v111 < 16; v111++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v112 = 0; v112 < 8; v112++) { + loop38: for (int v113 = 0; v113 < 4; v113++) { + loop39: for (int v114 = 0; v114 < 4; v114++) { + float v115 = v104[(v114 + (v111 * 4))][(v113 + (v110 * 4))]; + float v116 = v105[(v113 + (v110 * 4))][(v112 + (v109 * 8))]; + if ((v113 + (v110 * 4)) == 0) { + v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))] = v107; + } + float v117 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))]; + v106[v114][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][32], + float v122[32][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 2; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[(v131 + (v128 * 4))][(v130 + (v127 * 2))]; + float v133 = v122[(v130 + (v127 * 2))][(v129 + (v126 * 4))]; + if ((v130 + (v127 * 2)) == 0) { + v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))] = v124; + } + float v134 = v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))] = v136; + if (((v130 + (v127 * 2)) - 31) == 0) { + float v137 = v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))]; + v123[v131][v129].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[8][1]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][8]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][1]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[8][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][8]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v140, v141, v152, 0.000000); + node5(v142, v143, v151, 0.000000); + node4(v144, v145, v150, 0.000000); + node3(v152, v153, v149, 0.000000); + node2(v151, v150, v148, 0.000000); + node1(v149, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt1/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt1/src/mvt.cpp new file mode 100644 index 000000000000..44bff911ab15 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt1/src/mvt.cpp @@ -0,0 +1,137 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[400] +) { + loop0: for (int v2 = 0; v2 < 400; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[400] +) { + loop1: for (int v6 = 0; v6 < 400; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + float v8[400][400], + float v9[400], + hls::stream &v10, + float v11 +) { + float v12[400]; + loop2: for (int v13 = 0; v13 < 400; v13++) { + loop3: for (int v14 = 0; v14 < 400; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8[v13][v14]; + float v16 = v9[v14]; + if (v14 == 0) { + v12[v13] = v11; + } + float v17 = v12[v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v13] = v19; + if ((v14 - 399) == 0) { + float v20 = v12[v13]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[400][400], + float v22[400][400] +) { + loop4: for (int v23 = 0; v23 < 400; v23++) { + loop5: for (int v24 = 0; v24 < 400; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v25 = v21[v23][v24]; + v22[v24][v23] = v25; + } + } + return ; +} + +void node4( + float v26[400][400], + float v27[400], + hls::stream &v28, + float v29 +) { + float v30[400]; + loop6: for (int v31 = 0; v31 < 400; v31++) { + loop7: for (int v32 = 0; v32 < 400; v32++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v33 = v26[v31][v32]; + float v34 = v27[v32]; + if (v32 == 0) { + v30[v31] = v29; + } + float v35 = v30[v31]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v30[v31] = v37; + if ((v32 - 399) == 0) { + float v38 = v30[v31]; + v28.write(v38); + } + } + } + return ; +} + +void forward( + float v39[400][400], + float v40[400][400], + float v41[400], + float v42[400], + float v43[400], + float v44[400] +) { + #pragma HLS DATAFLOW + hls::stream v45("fifo_0"); + #pragma HLS STREAM variable=v45 depth=400 + float v46[400][400]; + hls::stream v47("fifo_1"); + #pragma HLS STREAM variable=v47 depth=400 + node4(v39, v41, v47, 0.000000); + node3(v40, v46); + node2(v46, v42, v45, 0.000000); + node1(v47, v43); + node0(v45, v44); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt2/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt2/src/mvt.cpp new file mode 100644 index 000000000000..f5fbfe0f57a9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt2/src/mvt.cpp @@ -0,0 +1,138 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[400] +) { + loop0: for (int v2 = 0; v2 < 400; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[400] +) { + loop1: for (int v6 = 0; v6 < 400; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + hls::stream &v8, + float v9[400], + hls::stream &v10, + float v11 +) { + float v12[400]; + loop2: for (int v13 = 0; v13 < 400; v13++) { + loop3: for (int v14 = 0; v14 < 400; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8.read(); + float v16 = v9[v13]; + if (v13 == 0) { + v12[v14] = v11; + } + float v17 = v12[v14]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v14] = v19; + if ((v13 - 399) == 0) { + float v20 = v12[v14]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[400][400], + hls::stream &v22 +) { + loop4: for (int v23 = 0; v23 < 400; v23++) { + loop5: for (int v24 = 0; v24 < 400; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v25 = v21[v23][v24]; + v22.write(v25); + } + } + return ; +} + +void node4( + float v26[400][400], + float v27[400], + hls::stream &v28, + float v29 +) { + float v30[400]; + loop6: for (int v31 = 0; v31 < 400; v31++) { + loop7: for (int v32 = 0; v32 < 400; v32++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v33 = v26[v32][v31]; + float v34 = v27[v31]; + if (v31 == 0) { + v30[v32] = v29; + } + float v35 = v30[v32]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v30[v32] = v37; + if ((v31 - 399) == 0) { + float v38 = v30[v32]; + v28.write(v38); + } + } + } + return ; +} + +void forward( + float v39[400][400], + float v40[400][400], + float v41[400], + float v42[400], + float v43[400], + float v44[400] +) { + #pragma HLS DATAFLOW + hls::stream v45("fifo_0"); + #pragma HLS STREAM variable=v45 depth=400 + hls::stream v46("fifo_1"); + #pragma HLS STREAM variable=v46 depth=160000 + hls::stream v47("fifo_2"); + #pragma HLS STREAM variable=v47 depth=400 + node4(v39, v41, v47, 0.000000); + node3(v40, v46); + node2(v46, v42, v45, 0.000000); + node1(v47, v43); + node0(v45, v44); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt3/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt3/src/mvt.cpp new file mode 100644 index 000000000000..6019c1b096cf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt3/src/mvt.cpp @@ -0,0 +1,194 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[16], + float v1[400] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=16 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 16; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 16))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + float v6[400] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=10 + + loop2: for (int v7 = 0; v7 < 40; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 10; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 10))] = v9; + } + } + return ; +} + +void node2( + float v10[400][400], + float v11[400], + hls::stream v12[16], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=16 + + float v14[400]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=16 + + loop4: for (int v15 = 0; v15 < 25; v15++) { + loop5: for (int v16 = 0; v16 < 25; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 16; v17++) { + loop7: for (int v18 = 0; v18 < 16; v18++) { + float v19 = v10[(v17 + (v15 * 16))][(v18 + (v16 * 16))]; + float v20 = v11[(v18 + (v16 * 16))]; + if ((v18 + (v16 * 16)) == 0) { + v14[(v17 + (v15 * 16))] = v13; + } + float v21 = v14[(v17 + (v15 * 16))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v17 + (v15 * 16))] = v23; + if (((v18 + (v16 * 16)) - 399) == 0) { + float v24 = v14[(v17 + (v15 * 16))]; + v12[v17].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[400][400], + float v26[400][400] +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=16 + + loop8: for (int v27 = 0; v27 < 25; v27++) { + loop9: for (int v28 = 0; v28 < 25; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v29 = 0; v29 < 16; v29++) { + loop11: for (int v30 = 0; v30 < 16; v30++) { + float v31 = v25[(v29 + (v27 * 16))][(v30 + (v28 * 16))]; + v26[(v30 + (v28 * 16))][(v29 + (v27 * 16))] = v31; + } + } + } + } + return ; +} + +void node4( + float v32[400][400], + float v33[400], + hls::stream v34[10], + float v35 +) { + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=25 + + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=25 + + float v36[400]; + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=10 + + loop12: for (int v37 = 0; v37 < 40; v37++) { + loop13: for (int v38 = 0; v38 < 16; v38++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop14: for (int v39 = 0; v39 < 10; v39++) { + loop15: for (int v40 = 0; v40 < 25; v40++) { + float v41 = v32[(v39 + (v37 * 10))][(v40 + (v38 * 25))]; + float v42 = v33[(v40 + (v38 * 25))]; + if ((v40 + (v38 * 25)) == 0) { + v36[(v39 + (v37 * 10))] = v35; + } + float v43 = v36[(v39 + (v37 * 10))]; + float v44 = v41 * v42; + float v45 = v43 + v44; + v36[(v39 + (v37 * 10))] = v45; + if (((v40 + (v38 * 25)) - 399) == 0) { + float v46 = v36[(v39 + (v37 * 10))]; + v34[v39].write(v46); + } + } + } + } + } + return ; +} + +void forward( + float v47[400][400], + float v48[400][400], + float v49[400], + float v50[400], + float v51[400], + float v52[400] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v47 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v47 cyclic dim=2 factor=25 + + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=25 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=16 + + hls::stream v53[16]; + #pragma HLS STREAM variable=v53 depth=25 + float v54[400][400]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=16 + + hls::stream v55[10]; + #pragma HLS STREAM variable=v55 depth=40 + node4(v47, v49, v55, 0.000000); + node3(v48, v54); + node2(v54, v50, v53, 0.000000); + node1(v55, v51); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt4/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt4/src/mvt.cpp new file mode 100644 index 000000000000..08b24afcb559 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt4/src/mvt.cpp @@ -0,0 +1,186 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[16], + float v1[400] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=16 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 16; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 16))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[16], + float v6[400] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=16 + + loop2: for (int v7 = 0; v7 < 25; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 16; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 16))] = v9; + } + } + return ; +} + +void node2( + hls::stream v10[16][16], + float v11[400], + hls::stream v12[16], + float v13 +) { + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=16 + + float v14[400]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=16 + + loop4: for (int v15 = 0; v15 < 25; v15++) { + loop5: for (int v16 = 0; v16 < 25; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 16; v17++) { + loop7: for (int v18 = 0; v18 < 16; v18++) { + float v19 = v10[v18][v17].read(); + float v20 = v11[(v17 + (v15 * 16))]; + if ((v17 + (v15 * 16)) == 0) { + v14[(v18 + (v16 * 16))] = v13; + } + float v21 = v14[(v18 + (v16 * 16))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 16))] = v23; + if (((v17 + (v15 * 16)) - 399) == 0) { + float v24 = v14[(v18 + (v16 * 16))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[400][400], + hls::stream v26[16][16] +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=16 + + loop8: for (int v27 = 0; v27 < 25; v27++) { + loop9: for (int v28 = 0; v28 < 25; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v29 = 0; v29 < 16; v29++) { + loop11: for (int v30 = 0; v30 < 16; v30++) { + float v31 = v25[(v29 + (v27 * 16))][(v30 + (v28 * 16))]; + v26[v30][v29].write(v31); + } + } + } + } + return ; +} + +void node4( + float v32[400][400], + float v33[400], + hls::stream v34[16], + float v35 +) { + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=16 + + float v36[400]; + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=16 + + loop12: for (int v37 = 0; v37 < 25; v37++) { + loop13: for (int v38 = 0; v38 < 25; v38++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop14: for (int v39 = 0; v39 < 16; v39++) { + loop15: for (int v40 = 0; v40 < 16; v40++) { + float v41 = v32[(v40 + (v38 * 16))][(v39 + (v37 * 16))]; + float v42 = v33[(v39 + (v37 * 16))]; + if ((v39 + (v37 * 16)) == 0) { + v36[(v40 + (v38 * 16))] = v35; + } + float v43 = v36[(v40 + (v38 * 16))]; + float v44 = v41 * v42; + float v45 = v43 + v44; + v36[(v40 + (v38 * 16))] = v45; + if (((v39 + (v37 * 16)) - 399) == 0) { + float v46 = v36[(v40 + (v38 * 16))]; + v34[v40].write(v46); + } + } + } + } + } + return ; +} + +void forward( + float v47[400][400], + float v48[400][400], + float v49[400], + float v50[400], + float v51[400], + float v52[400] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v47 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v47 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=16 + + hls::stream v53[16]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[16][16]; + #pragma HLS STREAM variable=v54 depth=625 + hls::stream v55[16]; + #pragma HLS STREAM variable=v55 depth=25 + node4(v47, v49, v55, 0.000000); + node3(v48, v54); + node2(v54, v50, v53, 0.000000); + node1(v55, v51); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt5/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt5/src/mvt.cpp new file mode 100644 index 000000000000..08b24afcb559 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/____processed_dataset/mvt__opt5/src/mvt.cpp @@ -0,0 +1,186 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[16], + float v1[400] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=16 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 16; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 16))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[16], + float v6[400] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=16 + + loop2: for (int v7 = 0; v7 < 25; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 16; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 16))] = v9; + } + } + return ; +} + +void node2( + hls::stream v10[16][16], + float v11[400], + hls::stream v12[16], + float v13 +) { + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=16 + + float v14[400]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=16 + + loop4: for (int v15 = 0; v15 < 25; v15++) { + loop5: for (int v16 = 0; v16 < 25; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 16; v17++) { + loop7: for (int v18 = 0; v18 < 16; v18++) { + float v19 = v10[v18][v17].read(); + float v20 = v11[(v17 + (v15 * 16))]; + if ((v17 + (v15 * 16)) == 0) { + v14[(v18 + (v16 * 16))] = v13; + } + float v21 = v14[(v18 + (v16 * 16))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 16))] = v23; + if (((v17 + (v15 * 16)) - 399) == 0) { + float v24 = v14[(v18 + (v16 * 16))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[400][400], + hls::stream v26[16][16] +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=16 + + loop8: for (int v27 = 0; v27 < 25; v27++) { + loop9: for (int v28 = 0; v28 < 25; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v29 = 0; v29 < 16; v29++) { + loop11: for (int v30 = 0; v30 < 16; v30++) { + float v31 = v25[(v29 + (v27 * 16))][(v30 + (v28 * 16))]; + v26[v30][v29].write(v31); + } + } + } + } + return ; +} + +void node4( + float v32[400][400], + float v33[400], + hls::stream v34[16], + float v35 +) { + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=16 + + float v36[400]; + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=16 + + loop12: for (int v37 = 0; v37 < 25; v37++) { + loop13: for (int v38 = 0; v38 < 25; v38++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop14: for (int v39 = 0; v39 < 16; v39++) { + loop15: for (int v40 = 0; v40 < 16; v40++) { + float v41 = v32[(v40 + (v38 * 16))][(v39 + (v37 * 16))]; + float v42 = v33[(v39 + (v37 * 16))]; + if ((v39 + (v37 * 16)) == 0) { + v36[(v40 + (v38 * 16))] = v35; + } + float v43 = v36[(v40 + (v38 * 16))]; + float v44 = v41 * v42; + float v45 = v43 + v44; + v36[(v40 + (v38 * 16))] = v45; + if (((v39 + (v37 * 16)) - 399) == 0) { + float v46 = v36[(v40 + (v38 * 16))]; + v34[v40].write(v46); + } + } + } + } + } + return ; +} + +void forward( + float v47[400][400], + float v48[400][400], + float v49[400], + float v50[400], + float v51[400], + float v52[400] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v47 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v47 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=16 + + hls::stream v53[16]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[16][16]; + #pragma HLS STREAM variable=v54 depth=625 + hls::stream v55[16]; + #pragma HLS STREAM variable=v55 depth=25 + node4(v47, v49, v55, 0.000000); + node3(v48, v54); + node2(v54, v50, v53, 0.000000); + node1(v55, v51); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt1/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt1/src/atax.cpp new file mode 100644 index 000000000000..d001dd12801f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt1/src/atax.cpp @@ -0,0 +1,125 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + float v4[410][390], + hls::stream &v5, + hls::stream &v6, + float v7 +) { + float v8[410]; + float v9[390]; + loop1: for (int v10 = 0; v10 < 410; v10++) { + loop2: for (int v11 = 0; v11 < 390; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v4[v10][v11]; + if (v10 == 0) { + float v13 = v5.read(); + v9[v11] = v13; + } + float v14 = v9[v11]; + if (v11 == 0) { + v8[v10] = v7; + } + float v15 = v8[v10]; + float v16 = v12 * v14; + float v17 = v15 + v16; + v8[v10] = v17; + if ((v11 - 389) == 0) { + float v18 = v8[v10]; + v6.write(v18); + } + } + } + return ; +} + +void node2( + float v19[390][410], + float v20[410][390] +) { + loop3: for (int v21 = 0; v21 < 390; v21++) { + loop4: for (int v22 = 0; v22 < 410; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v19[v21][v22]; + v20[v22][v21] = v23; + } + } + return ; +} + +void node3( + float v24[390][410], + float v25[410], + hls::stream &v26, + float v27 +) { + float v28[390]; + loop5: for (int v29 = 0; v29 < 390; v29++) { + loop6: for (int v30 = 0; v30 < 410; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v31 = v24[v29][v30]; + float v32 = v25[v30]; + if (v30 == 0) { + v28[v29] = v27; + } + float v33 = v28[v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v28[v29] = v35; + if ((v30 - 409) == 0) { + float v36 = v28[v29]; + v26.write(v36); + } + } + } + return ; +} + +void forward( + float v37[390][410], + float v38[410], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + float v41[410][390]; + hls::stream v42("fifo_1"); + #pragma HLS STREAM variable=v42 depth=390 + node3(v37, v38, v42, 0.000000); + node2(v37, v41); + node1(v41, v42, v40, 0.000000); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt2/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt2/src/atax.cpp new file mode 100644 index 000000000000..d2f1527f0b2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt2/src/atax.cpp @@ -0,0 +1,126 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + hls::stream &v5, + hls::stream &v6, + float v7 +) { + float v8[410]; + float v9[390]; + loop1: for (int v10 = 0; v10 < 390; v10++) { + loop2: for (int v11 = 0; v11 < 410; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v4.read(); + if (v11 == 0) { + float v13 = v5.read(); + v9[v10] = v13; + } + float v14 = v9[v10]; + if (v10 == 0) { + v8[v11] = v7; + } + float v15 = v8[v11]; + float v16 = v12 * v14; + float v17 = v15 + v16; + v8[v11] = v17; + if ((v10 - 389) == 0) { + float v18 = v8[v11]; + v6.write(v18); + } + } + } + return ; +} + +void node2( + float v19[390][410], + hls::stream &v20 +) { + loop3: for (int v21 = 0; v21 < 390; v21++) { + loop4: for (int v22 = 0; v22 < 410; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v19[v21][v22]; + v20.write(v23); + } + } + return ; +} + +void node3( + float v24[390][410], + float v25[410], + hls::stream &v26, + float v27 +) { + float v28[390]; + loop5: for (int v29 = 0; v29 < 410; v29++) { + loop6: for (int v30 = 0; v30 < 390; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v31 = v24[v30][v29]; + float v32 = v25[v29]; + if (v29 == 0) { + v28[v30] = v27; + } + float v33 = v28[v30]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v28[v30] = v35; + if ((v29 - 409) == 0) { + float v36 = v28[v30]; + v26.write(v36); + } + } + } + return ; +} + +void forward( + float v37[390][410], + float v38[410], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + hls::stream v41("fifo_1"); + #pragma HLS STREAM variable=v41 depth=159900 + hls::stream v42("fifo_2"); + #pragma HLS STREAM variable=v42 depth=390 + node3(v37, v38, v42, 0.000000); + node2(v37, v41); + node1(v41, v42, v40, 0.000000); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt3/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt3/src/atax.cpp new file mode 100644 index 000000000000..5042b43fe8c3 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt3/src/atax.cpp @@ -0,0 +1,171 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + float v5[410][390], + hls::stream v6[15], + hls::stream v7[10], + float v8 +) { + #pragma HLS array_partition variable=v5 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v5 cyclic dim=2 factor=15 + + float v9[410]; + #pragma HLS array_partition variable=v9 cyclic dim=1 factor=10 + + float v10[390]; + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=15 + + loop2: for (int v11 = 0; v11 < 41; v11++) { + loop3: for (int v12 = 0; v12 < 26; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop4: for (int v13 = 0; v13 < 10; v13++) { + loop5: for (int v14 = 0; v14 < 15; v14++) { + float v15 = v5[(v13 + (v11 * 10))][(v14 + (v12 * 15))]; + if ((v13 + (v11 * 10)) == 0) { + float v16 = v6[v14].read(); + v10[(v14 + (v12 * 15))] = v16; + } + float v17 = v10[(v14 + (v12 * 15))]; + if ((v14 + (v12 * 15)) == 0) { + v9[(v13 + (v11 * 10))] = v8; + } + float v18 = v9[(v13 + (v11 * 10))]; + float v19 = v15 * v17; + float v20 = v18 + v19; + v9[(v13 + (v11 * 10))] = v20; + if (((v14 + (v12 * 15)) - 389) == 0) { + float v21 = v9[(v13 + (v11 * 10))]; + v7[v13].write(v21); + } + } + } + } + } + return ; +} + +void node2( + float v22[390][410], + float v23[410][390] +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=15 + + loop6: for (int v24 = 0; v24 < 26; v24++) { + loop7: for (int v25 = 0; v25 < 41; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop8: for (int v26 = 0; v26 < 15; v26++) { + loop9: for (int v27 = 0; v27 < 10; v27++) { + float v28 = v22[(v26 + (v24 * 15))][(v27 + (v25 * 10))]; + v23[(v27 + (v25 * 10))][(v26 + (v24 * 15))] = v28; + } + } + } + } + return ; +} + +void node3( + float v29[390][410], + float v30[410], + hls::stream v31[15], + float v32 +) { + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + + float v33[390]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=15 + + loop10: for (int v34 = 0; v34 < 26; v34++) { + loop11: for (int v35 = 0; v35 < 41; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop12: for (int v36 = 0; v36 < 15; v36++) { + loop13: for (int v37 = 0; v37 < 10; v37++) { + float v38 = v29[(v36 + (v34 * 15))][(v37 + (v35 * 10))]; + float v39 = v30[(v37 + (v35 * 10))]; + if ((v37 + (v35 * 10)) == 0) { + v33[(v36 + (v34 * 15))] = v32; + } + float v40 = v33[(v36 + (v34 * 15))]; + float v41 = v38 * v39; + float v42 = v40 + v41; + v33[(v36 + (v34 * 15))] = v42; + if (((v37 + (v35 * 10)) - 409) == 0) { + float v43 = v33[(v36 + (v34 * 15))]; + v31[v36].write(v43); + } + } + } + } + } + return ; +} + +void forward( + float v44[390][410], + float v45[410], + float v46[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v44 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + + hls::stream v47[10]; + #pragma HLS STREAM variable=v47 depth=41 + float v48[410][390]; + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=15 + + hls::stream v49[15]; + #pragma HLS STREAM variable=v49 depth=26 + node3(v44, v45, v49, 0.000000); + node2(v44, v48); + node1(v48, v49, v47, 0.000000); + node0(v47, v46); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt4/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt4/src/atax.cpp new file mode 100644 index 000000000000..397622093e65 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt4/src/atax.cpp @@ -0,0 +1,163 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10][15], + hls::stream v6[15], + hls::stream v7[10], + float v8 +) { + float v9[410]; + #pragma HLS array_partition variable=v9 cyclic dim=1 factor=10 + + float v10[390]; + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=15 + + loop2: for (int v11 = 0; v11 < 26; v11++) { + loop3: for (int v12 = 0; v12 < 41; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop4: for (int v13 = 0; v13 < 15; v13++) { + loop5: for (int v14 = 0; v14 < 10; v14++) { + float v15 = v5[v14][v13].read(); + if ((v14 + (v12 * 10)) == 0) { + float v16 = v6[v13].read(); + v10[(v13 + (v11 * 15))] = v16; + } + float v17 = v10[(v13 + (v11 * 15))]; + if ((v13 + (v11 * 15)) == 0) { + v9[(v14 + (v12 * 10))] = v8; + } + float v18 = v9[(v14 + (v12 * 10))]; + float v19 = v15 * v17; + float v20 = v18 + v19; + v9[(v14 + (v12 * 10))] = v20; + if (((v13 + (v11 * 15)) - 389) == 0) { + float v21 = v9[(v14 + (v12 * 10))]; + v7[v14].write(v21); + } + } + } + } + } + return ; +} + +void node2( + float v22[390][410], + hls::stream v23[10][15] +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + loop6: for (int v24 = 0; v24 < 26; v24++) { + loop7: for (int v25 = 0; v25 < 41; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop8: for (int v26 = 0; v26 < 15; v26++) { + loop9: for (int v27 = 0; v27 < 10; v27++) { + float v28 = v22[(v26 + (v24 * 15))][(v27 + (v25 * 10))]; + v23[v27][v26].write(v28); + } + } + } + } + return ; +} + +void node3( + float v29[390][410], + float v30[410], + hls::stream v31[15], + float v32 +) { + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + + float v33[390]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=15 + + loop10: for (int v34 = 0; v34 < 41; v34++) { + loop11: for (int v35 = 0; v35 < 26; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop12: for (int v36 = 0; v36 < 10; v36++) { + loop13: for (int v37 = 0; v37 < 15; v37++) { + float v38 = v29[(v37 + (v35 * 15))][(v36 + (v34 * 10))]; + float v39 = v30[(v36 + (v34 * 10))]; + if ((v36 + (v34 * 10)) == 0) { + v33[(v37 + (v35 * 15))] = v32; + } + float v40 = v33[(v37 + (v35 * 15))]; + float v41 = v38 * v39; + float v42 = v40 + v41; + v33[(v37 + (v35 * 15))] = v42; + if (((v36 + (v34 * 10)) - 409) == 0) { + float v43 = v33[(v37 + (v35 * 15))]; + v31[v37].write(v43); + } + } + } + } + } + return ; +} + +void forward( + float v44[390][410], + float v45[410], + float v46[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v44 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + + hls::stream v47[10]; + #pragma HLS STREAM variable=v47 depth=41 + hls::stream v48[10][15]; + #pragma HLS STREAM variable=v48 depth=1066 + hls::stream v49[15]; + #pragma HLS STREAM variable=v49 depth=26 + node3(v44, v45, v49, 0.000000); + node2(v44, v48); + node1(v48, v49, v47, 0.000000); + node0(v47, v46); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt5/src/atax.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt5/src/atax.cpp new file mode 100644 index 000000000000..4981e44779af --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/atax__opt5/src/atax.cpp @@ -0,0 +1,163 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + hls::stream v6[10][15], + hls::stream v7[10], + float v8 +) { + float v9[410]; + #pragma HLS array_partition variable=v9 cyclic dim=1 factor=10 + + float v10[390]; + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=15 + + loop2: for (int v11 = 0; v11 < 26; v11++) { + loop3: for (int v12 = 0; v12 < 41; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop4: for (int v13 = 0; v13 < 15; v13++) { + loop5: for (int v14 = 0; v14 < 10; v14++) { + float v15 = v6[v14][v13].read(); + if ((v14 + (v12 * 10)) == 0) { + float v16 = v5[v13].read(); + v10[(v13 + (v11 * 15))] = v16; + } + float v17 = v10[(v13 + (v11 * 15))]; + if ((v13 + (v11 * 15)) == 0) { + v9[(v14 + (v12 * 10))] = v8; + } + float v18 = v9[(v14 + (v12 * 10))]; + float v19 = v15 * v17; + float v20 = v18 + v19; + v9[(v14 + (v12 * 10))] = v20; + if (((v13 + (v11 * 15)) - 389) == 0) { + float v21 = v9[(v14 + (v12 * 10))]; + v7[v14].write(v21); + } + } + } + } + } + return ; +} + +void node2( + float v22[390][410], + hls::stream v23[10][15] +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + loop6: for (int v24 = 0; v24 < 26; v24++) { + loop7: for (int v25 = 0; v25 < 41; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop8: for (int v26 = 0; v26 < 15; v26++) { + loop9: for (int v27 = 0; v27 < 10; v27++) { + float v28 = v22[(v26 + (v24 * 15))][(v27 + (v25 * 10))]; + v23[v27][v26].write(v28); + } + } + } + } + return ; +} + +void node3( + float v29[390][410], + float v30[410], + hls::stream v31[15], + float v32 +) { + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + + float v33[390]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=15 + + loop10: for (int v34 = 0; v34 < 41; v34++) { + loop11: for (int v35 = 0; v35 < 26; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop12: for (int v36 = 0; v36 < 10; v36++) { + loop13: for (int v37 = 0; v37 < 15; v37++) { + float v38 = v29[(v37 + (v35 * 15))][(v36 + (v34 * 10))]; + float v39 = v30[(v36 + (v34 * 10))]; + if ((v36 + (v34 * 10)) == 0) { + v33[(v37 + (v35 * 15))] = v32; + } + float v40 = v33[(v37 + (v35 * 15))]; + float v41 = v38 * v39; + float v42 = v40 + v41; + v33[(v37 + (v35 * 15))] = v42; + if (((v36 + (v34 * 10)) - 409) == 0) { + float v43 = v33[(v37 + (v35 * 15))]; + v31[v37].write(v43); + } + } + } + } + } + return ; +} + +void forward( + float v44[390][410], + float v45[410], + float v46[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + #pragma HLS array_partition variable=v44 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + + hls::stream v47[10]; + #pragma HLS STREAM variable=v47 depth=41 + hls::stream v48[10][15]; + #pragma HLS STREAM variable=v48 depth=1066 + hls::stream v49[15]; + #pragma HLS STREAM variable=v49 depth=26 + node3(v44, v45, v49, 0.000000); + node2(v44, v48); + node1(v49, v48, v47, 0.000000); + node0(v47, v46); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt1/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt1/src/bicg.cpp new file mode 100644 index 000000000000..92ecf2126eeb --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt1/src/bicg.cpp @@ -0,0 +1,120 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[390] +) { + loop1: for (int v6 = 0; v6 < 390; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + float v8[410][390], + float v9[390], + hls::stream &v10, + float v11 +) { + float v12[410]; + loop2: for (int v13 = 0; v13 < 410; v13++) { + loop3: for (int v14 = 0; v14 < 390; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8[v13][v14]; + float v16 = v9[v14]; + if (v14 == 0) { + v12[v13] = v11; + } + float v17 = v12[v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v13] = v19; + if ((v14 - 389) == 0) { + float v20 = v12[v13]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[410], + float v22[410][390], + hls::stream &v23, + float v24 +) { + float v25[390]; + loop4: for (int v26 = 0; v26 < 390; v26++) { + loop5: for (int v27 = 0; v27 < 410; v27++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v28 = v21[v27]; + float v29 = v22[v27][v26]; + if (v27 == 0) { + v25[v26] = v24; + } + float v30 = v25[v26]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v25[v26] = v32; + if ((v27 - 409) == 0) { + float v33 = v25[v26]; + v23.write(v33); + } + } + } + return ; +} + +void forward( + float v34[410][390], + float v35[410][390], + float v36[410], + float v37[390], + float v38[390], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + hls::stream v41("fifo_1"); + #pragma HLS STREAM variable=v41 depth=390 + node3(v36, v34, v41, 0.000000); + node2(v35, v37, v40, 0.000000); + node1(v41, v38); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt2/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt2/src/bicg.cpp new file mode 100644 index 000000000000..dd7eee778e94 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt2/src/bicg.cpp @@ -0,0 +1,120 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[410] +) { + loop0: for (int v2 = 0; v2 < 410; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[390] +) { + loop1: for (int v6 = 0; v6 < 390; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + float v8[410][390], + float v9[390], + hls::stream &v10, + float v11 +) { + float v12[410]; + loop2: for (int v13 = 0; v13 < 390; v13++) { + loop3: for (int v14 = 0; v14 < 410; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8[v14][v13]; + float v16 = v9[v13]; + if (v13 == 0) { + v12[v14] = v11; + } + float v17 = v12[v14]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v14] = v19; + if ((v13 - 389) == 0) { + float v20 = v12[v14]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[410], + float v22[410][390], + hls::stream &v23, + float v24 +) { + float v25[390]; + loop4: for (int v26 = 0; v26 < 410; v26++) { + loop5: for (int v27 = 0; v27 < 390; v27++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v28 = v21[v26]; + float v29 = v22[v26][v27]; + if (v26 == 0) { + v25[v27] = v24; + } + float v30 = v25[v27]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v25[v27] = v32; + if ((v26 - 409) == 0) { + float v33 = v25[v27]; + v23.write(v33); + } + } + } + return ; +} + +void forward( + float v34[410][390], + float v35[410][390], + float v36[410], + float v37[390], + float v38[390], + float v39[410] +) { + #pragma HLS DATAFLOW + hls::stream v40("fifo_0"); + #pragma HLS STREAM variable=v40 depth=410 + hls::stream v41("fifo_1"); + #pragma HLS STREAM variable=v41 depth=390 + node3(v36, v34, v41, 0.000000); + node2(v35, v37, v40, 0.000000); + node1(v41, v38); + node0(v40, v39); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt3/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt3/src/bicg.cpp new file mode 100644 index 000000000000..b4b049330583 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt3/src/bicg.cpp @@ -0,0 +1,164 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + float v6[390] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=15 + + loop2: for (int v7 = 0; v7 < 26; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 15; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 15))] = v9; + } + } + return ; +} + +void node2( + float v10[410][390], + float v11[390], + hls::stream v12[10], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=15 + + float v14[410]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=10 + + loop4: for (int v15 = 0; v15 < 41; v15++) { + loop5: for (int v16 = 0; v16 < 26; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 10; v17++) { + loop7: for (int v18 = 0; v18 < 15; v18++) { + float v19 = v10[(v17 + (v15 * 10))][(v18 + (v16 * 15))]; + float v20 = v11[(v18 + (v16 * 15))]; + if ((v18 + (v16 * 15)) == 0) { + v14[(v17 + (v15 * 10))] = v13; + } + float v21 = v14[(v17 + (v15 * 10))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v17 + (v15 * 10))] = v23; + if (((v18 + (v16 * 15)) - 389) == 0) { + float v24 = v14[(v17 + (v15 * 10))]; + v12[v17].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[410], + float v26[410][390], + hls::stream v27[15], + float v28 +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=15 + + float v29[390]; + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + + loop8: for (int v30 = 0; v30 < 26; v30++) { + loop9: for (int v31 = 0; v31 < 41; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v32 = 0; v32 < 15; v32++) { + loop11: for (int v33 = 0; v33 < 10; v33++) { + float v34 = v25[(v33 + (v31 * 10))]; + float v35 = v26[(v33 + (v31 * 10))][(v32 + (v30 * 15))]; + if ((v33 + (v31 * 10)) == 0) { + v29[(v32 + (v30 * 15))] = v28; + } + float v36 = v29[(v32 + (v30 * 15))]; + float v37 = v34 * v35; + float v38 = v36 + v37; + v29[(v32 + (v30 * 15))] = v38; + if (((v33 + (v31 * 10)) - 409) == 0) { + float v39 = v29[(v32 + (v30 * 15))]; + v27[v32].write(v39); + } + } + } + } + } + return ; +} + +void forward( + float v40[410][390], + float v41[410][390], + float v42[410], + float v43[390], + float v44[390], + float v45[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + hls::stream v46[10]; + #pragma HLS STREAM variable=v46 depth=41 + hls::stream v47[15]; + #pragma HLS STREAM variable=v47 depth=26 + node3(v42, v40, v47, 0.000000); + node2(v41, v43, v46, 0.000000); + node1(v47, v44); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt4/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt4/src/bicg.cpp new file mode 100644 index 000000000000..885cebfce0d2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt4/src/bicg.cpp @@ -0,0 +1,164 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + float v6[390] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=15 + + loop2: for (int v7 = 0; v7 < 26; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 15; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 15))] = v9; + } + } + return ; +} + +void node2( + float v10[410][390], + float v11[390], + hls::stream v12[10], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=15 + + float v14[410]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=10 + + loop4: for (int v15 = 0; v15 < 26; v15++) { + loop5: for (int v16 = 0; v16 < 41; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 15; v17++) { + loop7: for (int v18 = 0; v18 < 10; v18++) { + float v19 = v10[(v18 + (v16 * 10))][(v17 + (v15 * 15))]; + float v20 = v11[(v17 + (v15 * 15))]; + if ((v17 + (v15 * 15)) == 0) { + v14[(v18 + (v16 * 10))] = v13; + } + float v21 = v14[(v18 + (v16 * 10))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 10))] = v23; + if (((v17 + (v15 * 15)) - 389) == 0) { + float v24 = v14[(v18 + (v16 * 10))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[410], + float v26[410][390], + hls::stream v27[15], + float v28 +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=15 + + float v29[390]; + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + + loop8: for (int v30 = 0; v30 < 41; v30++) { + loop9: for (int v31 = 0; v31 < 26; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v32 = 0; v32 < 10; v32++) { + loop11: for (int v33 = 0; v33 < 15; v33++) { + float v34 = v25[(v32 + (v30 * 10))]; + float v35 = v26[(v32 + (v30 * 10))][(v33 + (v31 * 15))]; + if ((v32 + (v30 * 10)) == 0) { + v29[(v33 + (v31 * 15))] = v28; + } + float v36 = v29[(v33 + (v31 * 15))]; + float v37 = v34 * v35; + float v38 = v36 + v37; + v29[(v33 + (v31 * 15))] = v38; + if (((v32 + (v30 * 10)) - 409) == 0) { + float v39 = v29[(v33 + (v31 * 15))]; + v27[v33].write(v39); + } + } + } + } + } + return ; +} + +void forward( + float v40[410][390], + float v41[410][390], + float v42[410], + float v43[390], + float v44[390], + float v45[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + hls::stream v46[10]; + #pragma HLS STREAM variable=v46 depth=41 + hls::stream v47[15]; + #pragma HLS STREAM variable=v47 depth=26 + node3(v42, v40, v47, 0.000000); + node2(v41, v43, v46, 0.000000); + node1(v47, v44); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt5/src/bicg.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt5/src/bicg.cpp new file mode 100644 index 000000000000..885cebfce0d2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/bicg__opt5/src/bicg.cpp @@ -0,0 +1,164 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[410] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 41; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[15], + float v6[390] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=15 + + loop2: for (int v7 = 0; v7 < 26; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 15; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 15))] = v9; + } + } + return ; +} + +void node2( + float v10[410][390], + float v11[390], + hls::stream v12[10], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=15 + + float v14[410]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=10 + + loop4: for (int v15 = 0; v15 < 26; v15++) { + loop5: for (int v16 = 0; v16 < 41; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 15; v17++) { + loop7: for (int v18 = 0; v18 < 10; v18++) { + float v19 = v10[(v18 + (v16 * 10))][(v17 + (v15 * 15))]; + float v20 = v11[(v17 + (v15 * 15))]; + if ((v17 + (v15 * 15)) == 0) { + v14[(v18 + (v16 * 10))] = v13; + } + float v21 = v14[(v18 + (v16 * 10))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 10))] = v23; + if (((v17 + (v15 * 15)) - 389) == 0) { + float v24 = v14[(v18 + (v16 * 10))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[410], + float v26[410][390], + hls::stream v27[15], + float v28 +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=15 + + float v29[390]; + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=15 + + loop8: for (int v30 = 0; v30 < 41; v30++) { + loop9: for (int v31 = 0; v31 < 26; v31++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v32 = 0; v32 < 10; v32++) { + loop11: for (int v33 = 0; v33 < 15; v33++) { + float v34 = v25[(v32 + (v30 * 10))]; + float v35 = v26[(v32 + (v30 * 10))][(v33 + (v31 * 15))]; + if ((v32 + (v30 * 10)) == 0) { + v29[(v33 + (v31 * 15))] = v28; + } + float v36 = v29[(v33 + (v31 * 15))]; + float v37 = v34 * v35; + float v38 = v36 + v37; + v29[(v33 + (v31 * 15))] = v38; + if (((v32 + (v30 * 10)) - 409) == 0) { + float v39 = v29[(v33 + (v31 * 15))]; + v27[v33].write(v39); + } + } + } + } + } + return ; +} + +void forward( + float v40[410][390], + float v41[410][390], + float v42[410], + float v43[390], + float v44[390], + float v45[410] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=15 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v44 cyclic dim=1 factor=15 + + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + hls::stream v46[10]; + #pragma HLS STREAM variable=v46 depth=41 + hls::stream v47[15]; + #pragma HLS STREAM variable=v47 depth=26 + node3(v42, v40, v47, 0.000000); + node2(v41, v43, v46, 0.000000); + node1(v47, v44); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt1/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt1/src/gemm.cpp new file mode 100644 index 000000000000..3c66c436d0e9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt1/src/gemm.cpp @@ -0,0 +1,102 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[200][220] +) { + loop0: for (int v2 = 0; v2 < 200; v2++) { + loop1: for (int v3 = 0; v3 < 220; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[200][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 200; v10++) { + loop3: for (int v11 = 0; v11 < 220; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v10][v11]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + float v18[200][240], + float v19[240][220], + hls::stream &v20, + float v21 +) { + float v22[200][220]; + loop4: for (int v23 = 0; v23 < 200; v23++) { + loop5: for (int v24 = 0; v24 < 220; v24++) { + loop6: for (int v25 = 0; v25 < 240; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v26 = v18[v23][v25]; + float v27 = v19[v25][v24]; + if (v25 == 0) { + v22[v23][v24] = v21; + } + float v28 = v22[v23][v24]; + float v29 = v26 * v27; + float v30 = v28 + v29; + v22[v23][v24] = v30; + if ((v25 - 239) == 0) { + float v31 = v22[v23][v24]; + v20.write(v31); + } + } + } + } + return ; +} + +void forward( + float v32[200][240], + float v33[240][220], + float v34[200][220], + float v35[200][220] +) { + #pragma HLS DATAFLOW + hls::stream v36("fifo_0"); + #pragma HLS STREAM variable=v36 depth=44000 + hls::stream v37("fifo_1"); + #pragma HLS STREAM variable=v37 depth=44000 + node2(v32, v33, v37, 0.000000); + node1(v37, v34, v36, 0.100000, 0.500000); + node0(v36, v35); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt2/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt2/src/gemm.cpp new file mode 100644 index 000000000000..3a44b0144371 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt2/src/gemm.cpp @@ -0,0 +1,102 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[200][220] +) { + loop0: for (int v2 = 0; v2 < 220; v2++) { + loop1: for (int v3 = 0; v3 < 200; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v3][v2] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[200][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 220; v10++) { + loop3: for (int v11 = 0; v11 < 200; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v11][v10]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + float v18[200][240], + float v19[240][220], + hls::stream &v20, + float v21 +) { + float v22[200][220]; + loop4: for (int v23 = 0; v23 < 240; v23++) { + loop5: for (int v24 = 0; v24 < 220; v24++) { + loop6: for (int v25 = 0; v25 < 200; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v26 = v18[v25][v23]; + float v27 = v19[v23][v24]; + if (v23 == 0) { + v22[v25][v24] = v21; + } + float v28 = v22[v25][v24]; + float v29 = v26 * v27; + float v30 = v28 + v29; + v22[v25][v24] = v30; + if ((v23 - 239) == 0) { + float v31 = v22[v25][v24]; + v20.write(v31); + } + } + } + } + return ; +} + +void forward( + float v32[200][240], + float v33[240][220], + float v34[200][220], + float v35[200][220] +) { + #pragma HLS DATAFLOW + hls::stream v36("fifo_0"); + #pragma HLS STREAM variable=v36 depth=44000 + hls::stream v37("fifo_1"); + #pragma HLS STREAM variable=v37 depth=44000 + node2(v32, v33, v37, 0.000000); + node1(v37, v34, v36, 0.100000, 0.500000); + node0(v36, v35); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt3/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt3/src/gemm.cpp new file mode 100644 index 000000000000..8bff20e689ef --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt3/src/gemm.cpp @@ -0,0 +1,143 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[200][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 50; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[200][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 50; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 4; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 4))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[240][220], + float v23[200][240], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=10 + + float v26[200][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + loop8: for (int v27 = 0; v27 < 50; v27++) { + loop9: for (int v28 = 0; v28 < 20; v28++) { + loop10: for (int v29 = 0; v29 < 24; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v30 = 0; v30 < 4; v30++) { + loop12: for (int v31 = 0; v31 < 11; v31++) { + loop13: for (int v32 = 0; v32 < 10; v32++) { + float v33 = v23[(v30 + (v27 * 4))][(v32 + (v29 * 10))]; + float v34 = v22[(v32 + (v29 * 10))][(v31 + (v28 * 11))]; + if ((v32 + (v29 * 10)) == 0) { + v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))] = v25; + } + float v35 = v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))] = v37; + if (((v32 + (v29 * 10)) - 239) == 0) { + float v38 = v26[(v30 + (v27 * 4))][(v31 + (v28 * 11))]; + v24[v30][v31].write(v38); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v39[200][240], + float v40[240][220], + float v41[200][220], + float v42[200][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=11 + + hls::stream v43[4][11]; + #pragma HLS STREAM variable=v43 depth=1000 + hls::stream v44[4][11]; + #pragma HLS STREAM variable=v44 depth=1000 + node2(v40, v39, v44, 0.000000); + node1(v44, v41, v43, 0.100000, 0.500000); + node0(v43, v42); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt4/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt4/src/gemm.cpp new file mode 100644 index 000000000000..ce4d2516bc53 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt4/src/gemm.cpp @@ -0,0 +1,143 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[200][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 20; v2++) { + loop1: for (int v3 = 0; v3 < 50; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 11; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v4 + (v2 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[200][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 20; v12++) { + loop5: for (int v13 = 0; v13 < 50; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 11; v14++) { + loop7: for (int v15 = 0; v15 < 4; v15++) { + float v16 = v7[v15][v14].read(); + float v17 = v8[(v15 + (v13 * 4))][(v14 + (v12 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v15][v14].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[200][240], + float v23[240][220], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[200][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + loop8: for (int v27 = 0; v27 < 24; v27++) { + loop9: for (int v28 = 0; v28 < 20; v28++) { + loop10: for (int v29 = 0; v29 < 50; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v30 = 0; v30 < 10; v30++) { + loop12: for (int v31 = 0; v31 < 11; v31++) { + loop13: for (int v32 = 0; v32 < 4; v32++) { + float v33 = v22[(v32 + (v29 * 4))][(v30 + (v27 * 10))]; + float v34 = v23[(v30 + (v27 * 10))][(v31 + (v28 * 11))]; + if ((v30 + (v27 * 10)) == 0) { + v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))] = v25; + } + float v35 = v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))] = v37; + if (((v30 + (v27 * 10)) - 239) == 0) { + float v38 = v26[(v32 + (v29 * 4))][(v31 + (v28 * 11))]; + v24[v32][v31].write(v38); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v39[200][240], + float v40[240][220], + float v41[200][220], + float v42[200][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=11 + + hls::stream v43[4][11]; + #pragma HLS STREAM variable=v43 depth=1000 + hls::stream v44[4][11]; + #pragma HLS STREAM variable=v44 depth=1000 + node2(v39, v40, v44, 0.000000); + node1(v44, v41, v43, 0.100000, 0.500000); + node0(v43, v42); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt5/src/gemm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt5/src/gemm.cpp new file mode 100644 index 000000000000..bd3ead0d2e3f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gemm__opt5/src/gemm.cpp @@ -0,0 +1,143 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[200][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 50; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[200][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 50; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 4; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 4))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[200][240], + float v23[240][220], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[200][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + loop8: for (int v27 = 0; v27 < 24; v27++) { + loop9: for (int v28 = 0; v28 < 50; v28++) { + loop10: for (int v29 = 0; v29 < 20; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v30 = 0; v30 < 10; v30++) { + loop12: for (int v31 = 0; v31 < 4; v31++) { + loop13: for (int v32 = 0; v32 < 11; v32++) { + float v33 = v22[(v31 + (v28 * 4))][(v30 + (v27 * 10))]; + float v34 = v23[(v30 + (v27 * 10))][(v32 + (v29 * 11))]; + if ((v30 + (v27 * 10)) == 0) { + v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))] = v25; + } + float v35 = v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))] = v37; + if (((v30 + (v27 * 10)) - 239) == 0) { + float v38 = v26[(v31 + (v28 * 4))][(v32 + (v29 * 11))]; + v24[v31][v32].write(v38); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v39[200][240], + float v40[240][220], + float v41[200][220], + float v42[200][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=11 + + hls::stream v43[4][11]; + #pragma HLS STREAM variable=v43 depth=1000 + hls::stream v44[4][11]; + #pragma HLS STREAM variable=v44 depth=1000 + node2(v39, v40, v44, 0.000000); + node1(v44, v41, v43, 0.100000, 0.500000); + node0(v43, v42); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt1/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt1/src/gesummv.cpp new file mode 100644 index 000000000000..cef5565bb1a0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt1/src/gesummv.cpp @@ -0,0 +1,128 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[250] +) { + loop0: for (int v2 = 0; v2 < 250; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + hls::stream &v5, + hls::stream &v6, + double v7, + float v8 +) { + loop1: for (int v9 = 0; v9 < 250; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v4.read(); + float v11 = v5.read(); + float v12 = v7; + float v13 = v11 * v12; + float v14 = v10 * v8; + float v15 = v14 + v13; + v6.write(v15); + } + return ; +} + +void node2( + float v16[250][250], + float v17[250], + hls::stream &v18, + float v19 +) { + float v20[250]; + loop2: for (int v21 = 0; v21 < 250; v21++) { + loop3: for (int v22 = 0; v22 < 250; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v16[v21][v22]; + float v24 = v17[v22]; + if (v22 == 0) { + v20[v21] = v19; + } + float v25 = v20[v21]; + float v26 = v23 * v24; + float v27 = v25 + v26; + v20[v21] = v27; + if ((v22 - 249) == 0) { + float v28 = v20[v21]; + v18.write(v28); + } + } + } + return ; +} + +void node3( + float v29[250][250], + float v30[250], + hls::stream &v31, + float v32 +) { + float v33[250]; + loop4: for (int v34 = 0; v34 < 250; v34++) { + loop5: for (int v35 = 0; v35 < 250; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v36 = v29[v34][v35]; + float v37 = v30[v35]; + if (v35 == 0) { + v33[v34] = v32; + } + float v38 = v33[v34]; + float v39 = v36 * v37; + float v40 = v38 + v39; + v33[v34] = v40; + if ((v35 - 249) == 0) { + float v41 = v33[v34]; + v31.write(v41); + } + } + } + return ; +} + +void forward( + float v42[250][250], + float v43[250][250], + float v44[250], + float v45[250] +) { + #pragma HLS DATAFLOW + hls::stream v46("fifo_0"); + #pragma HLS STREAM variable=v46 depth=250 + hls::stream v47("fifo_1"); + #pragma HLS STREAM variable=v47 depth=250 + hls::stream v48("fifo_2"); + #pragma HLS STREAM variable=v48 depth=250 + node3(v42, v44, v48, 0.000000); + node2(v43, v44, v47, 0.000000); + node1(v48, v47, v46, 1.200000, 1.500000); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt2/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt2/src/gesummv.cpp new file mode 100644 index 000000000000..7d0a0c3ebea9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt2/src/gesummv.cpp @@ -0,0 +1,128 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[250] +) { + loop0: for (int v2 = 0; v2 < 250; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + hls::stream &v5, + hls::stream &v6, + double v7, + float v8 +) { + loop1: for (int v9 = 0; v9 < 250; v9++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v10 = v4.read(); + float v11 = v5.read(); + float v12 = v7; + float v13 = v11 * v12; + float v14 = v10 * v8; + float v15 = v14 + v13; + v6.write(v15); + } + return ; +} + +void node2( + float v16[250][250], + float v17[250], + hls::stream &v18, + float v19 +) { + float v20[250]; + loop2: for (int v21 = 0; v21 < 250; v21++) { + loop3: for (int v22 = 0; v22 < 250; v22++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v23 = v16[v22][v21]; + float v24 = v17[v21]; + if (v21 == 0) { + v20[v22] = v19; + } + float v25 = v20[v22]; + float v26 = v23 * v24; + float v27 = v25 + v26; + v20[v22] = v27; + if ((v21 - 249) == 0) { + float v28 = v20[v22]; + v18.write(v28); + } + } + } + return ; +} + +void node3( + float v29[250][250], + float v30[250], + hls::stream &v31, + float v32 +) { + float v33[250]; + loop4: for (int v34 = 0; v34 < 250; v34++) { + loop5: for (int v35 = 0; v35 < 250; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v36 = v29[v35][v34]; + float v37 = v30[v34]; + if (v34 == 0) { + v33[v35] = v32; + } + float v38 = v33[v35]; + float v39 = v36 * v37; + float v40 = v38 + v39; + v33[v35] = v40; + if ((v34 - 249) == 0) { + float v41 = v33[v35]; + v31.write(v41); + } + } + } + return ; +} + +void forward( + float v42[250][250], + float v43[250][250], + float v44[250], + float v45[250] +) { + #pragma HLS DATAFLOW + hls::stream v46("fifo_0"); + #pragma HLS STREAM variable=v46 depth=250 + hls::stream v47("fifo_1"); + #pragma HLS STREAM variable=v47 depth=250 + hls::stream v48("fifo_2"); + #pragma HLS STREAM variable=v48 depth=250 + node3(v42, v44, v48, 0.000000); + node2(v43, v44, v47, 0.000000); + node1(v48, v47, v46, 1.200000, 1.500000); + node0(v46, v45); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt3/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt3/src/gesummv.cpp new file mode 100644 index 000000000000..320bdafe51f2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt3/src/gesummv.cpp @@ -0,0 +1,166 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[250] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + hls::stream v6[10], + hls::stream v7[10], + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 25; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v11 = 0; v11 < 10; v11++) { + float v12 = v5[v11].read(); + float v13 = v6[v11].read(); + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7[v11].write(v17); + } + } + return ; +} + +void node2( + float v18[250][250], + float v19[250], + hls::stream v20[10], + float v21 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v19 cyclic dim=1 factor=10 + + float v22[250]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + + loop4: for (int v23 = 0; v23 < 25; v23++) { + loop5: for (int v24 = 0; v24 < 25; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v25 = 0; v25 < 10; v25++) { + loop7: for (int v26 = 0; v26 < 10; v26++) { + float v27 = v18[(v25 + (v23 * 10))][(v26 + (v24 * 10))]; + float v28 = v19[(v26 + (v24 * 10))]; + if ((v26 + (v24 * 10)) == 0) { + v22[(v25 + (v23 * 10))] = v21; + } + float v29 = v22[(v25 + (v23 * 10))]; + float v30 = v27 * v28; + float v31 = v29 + v30; + v22[(v25 + (v23 * 10))] = v31; + if (((v26 + (v24 * 10)) - 249) == 0) { + float v32 = v22[(v25 + (v23 * 10))]; + v20[v25].write(v32); + } + } + } + } + } + return ; +} + +void node3( + float v33[250][250], + float v34[250], + hls::stream v35[10], + float v36 +) { + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=10 + + float v37[250]; + #pragma HLS array_partition variable=v37 cyclic dim=1 factor=10 + + loop8: for (int v38 = 0; v38 < 25; v38++) { + loop9: for (int v39 = 0; v39 < 25; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v40 = 0; v40 < 10; v40++) { + loop11: for (int v41 = 0; v41 < 10; v41++) { + float v42 = v33[(v40 + (v38 * 10))][(v41 + (v39 * 10))]; + float v43 = v34[(v41 + (v39 * 10))]; + if ((v41 + (v39 * 10)) == 0) { + v37[(v40 + (v38 * 10))] = v36; + } + float v44 = v37[(v40 + (v38 * 10))]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v37[(v40 + (v38 * 10))] = v46; + if (((v41 + (v39 * 10)) - 249) == 0) { + float v47 = v37[(v40 + (v38 * 10))]; + v35[v40].write(v47); + } + } + } + } + } + return ; +} + +void forward( + float v48[250][250], + float v49[250][250], + float v50[250], + float v51[250] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + hls::stream v52[10]; + #pragma HLS STREAM variable=v52 depth=25 + hls::stream v53[10]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[10]; + #pragma HLS STREAM variable=v54 depth=25 + node3(v48, v50, v54, 0.000000); + node2(v49, v50, v53, 0.000000); + node1(v54, v53, v52, 1.200000, 1.500000); + node0(v52, v51); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt4/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt4/src/gesummv.cpp new file mode 100644 index 000000000000..215e46416363 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt4/src/gesummv.cpp @@ -0,0 +1,166 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[250] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + hls::stream v6[10], + hls::stream v7[10], + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 25; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v11 = 0; v11 < 10; v11++) { + float v12 = v5[v11].read(); + float v13 = v6[v11].read(); + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7[v11].write(v17); + } + } + return ; +} + +void node2( + float v18[250][250], + float v19[250], + hls::stream v20[10], + float v21 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v19 cyclic dim=1 factor=10 + + float v22[250]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + + loop4: for (int v23 = 0; v23 < 25; v23++) { + loop5: for (int v24 = 0; v24 < 25; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v25 = 0; v25 < 10; v25++) { + loop7: for (int v26 = 0; v26 < 10; v26++) { + float v27 = v18[(v26 + (v24 * 10))][(v25 + (v23 * 10))]; + float v28 = v19[(v25 + (v23 * 10))]; + if ((v25 + (v23 * 10)) == 0) { + v22[(v26 + (v24 * 10))] = v21; + } + float v29 = v22[(v26 + (v24 * 10))]; + float v30 = v27 * v28; + float v31 = v29 + v30; + v22[(v26 + (v24 * 10))] = v31; + if (((v25 + (v23 * 10)) - 249) == 0) { + float v32 = v22[(v26 + (v24 * 10))]; + v20[v26].write(v32); + } + } + } + } + } + return ; +} + +void node3( + float v33[250][250], + float v34[250], + hls::stream v35[10], + float v36 +) { + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=10 + + float v37[250]; + #pragma HLS array_partition variable=v37 cyclic dim=1 factor=10 + + loop8: for (int v38 = 0; v38 < 25; v38++) { + loop9: for (int v39 = 0; v39 < 25; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v40 = 0; v40 < 10; v40++) { + loop11: for (int v41 = 0; v41 < 10; v41++) { + float v42 = v33[(v41 + (v39 * 10))][(v40 + (v38 * 10))]; + float v43 = v34[(v40 + (v38 * 10))]; + if ((v40 + (v38 * 10)) == 0) { + v37[(v41 + (v39 * 10))] = v36; + } + float v44 = v37[(v41 + (v39 * 10))]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v37[(v41 + (v39 * 10))] = v46; + if (((v40 + (v38 * 10)) - 249) == 0) { + float v47 = v37[(v41 + (v39 * 10))]; + v35[v41].write(v47); + } + } + } + } + } + return ; +} + +void forward( + float v48[250][250], + float v49[250][250], + float v50[250], + float v51[250] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + hls::stream v52[10]; + #pragma HLS STREAM variable=v52 depth=25 + hls::stream v53[10]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[10]; + #pragma HLS STREAM variable=v54 depth=25 + node3(v48, v50, v54, 0.000000); + node2(v49, v50, v53, 0.000000); + node1(v54, v53, v52, 1.200000, 1.500000); + node0(v52, v51); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt5/src/gesummv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt5/src/gesummv.cpp new file mode 100644 index 000000000000..215e46416363 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/gesummv__opt5/src/gesummv.cpp @@ -0,0 +1,166 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10], + float v1[250] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 10; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 10))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + hls::stream v6[10], + hls::stream v7[10], + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 25; v10++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v11 = 0; v11 < 10; v11++) { + float v12 = v5[v11].read(); + float v13 = v6[v11].read(); + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7[v11].write(v17); + } + } + return ; +} + +void node2( + float v18[250][250], + float v19[250], + hls::stream v20[10], + float v21 +) { + #pragma HLS array_partition variable=v18 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v18 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v19 cyclic dim=1 factor=10 + + float v22[250]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=10 + + loop4: for (int v23 = 0; v23 < 25; v23++) { + loop5: for (int v24 = 0; v24 < 25; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v25 = 0; v25 < 10; v25++) { + loop7: for (int v26 = 0; v26 < 10; v26++) { + float v27 = v18[(v26 + (v24 * 10))][(v25 + (v23 * 10))]; + float v28 = v19[(v25 + (v23 * 10))]; + if ((v25 + (v23 * 10)) == 0) { + v22[(v26 + (v24 * 10))] = v21; + } + float v29 = v22[(v26 + (v24 * 10))]; + float v30 = v27 * v28; + float v31 = v29 + v30; + v22[(v26 + (v24 * 10))] = v31; + if (((v25 + (v23 * 10)) - 249) == 0) { + float v32 = v22[(v26 + (v24 * 10))]; + v20[v26].write(v32); + } + } + } + } + } + return ; +} + +void node3( + float v33[250][250], + float v34[250], + hls::stream v35[10], + float v36 +) { + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=10 + + float v37[250]; + #pragma HLS array_partition variable=v37 cyclic dim=1 factor=10 + + loop8: for (int v38 = 0; v38 < 25; v38++) { + loop9: for (int v39 = 0; v39 < 25; v39++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v40 = 0; v40 < 10; v40++) { + loop11: for (int v41 = 0; v41 < 10; v41++) { + float v42 = v33[(v41 + (v39 * 10))][(v40 + (v38 * 10))]; + float v43 = v34[(v40 + (v38 * 10))]; + if ((v40 + (v38 * 10)) == 0) { + v37[(v41 + (v39 * 10))] = v36; + } + float v44 = v37[(v41 + (v39 * 10))]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v37[(v41 + (v39 * 10))] = v46; + if (((v40 + (v38 * 10)) - 249) == 0) { + float v47 = v37[(v41 + (v39 * 10))]; + v35[v41].write(v47); + } + } + } + } + } + return ; +} + +void forward( + float v48[250][250], + float v49[250][250], + float v50[250], + float v51[250] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + hls::stream v52[10]; + #pragma HLS STREAM variable=v52 depth=25 + hls::stream v53[10]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[10]; + #pragma HLS STREAM variable=v54 depth=25 + node3(v48, v50, v54, 0.000000); + node2(v49, v50, v53, 0.000000); + node1(v54, v53, v52, 1.200000, 1.500000); + node0(v52, v51); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq__opt5/src/k15mmseq.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq__opt5/src/k15mmseq.cpp new file mode 100644 index 000000000000..553cf854da00 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq__opt5/src/k15mmseq.cpp @@ -0,0 +1,936 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][2], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 32; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 2; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 2))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][2], + hls::stream v8[4][2], + float v9 +) { + loop4: for (int v10 = 0; v10 < 16; v10++) { + loop5: for (int v11 = 0; v11 < 32; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 4; v12++) { + loop7: for (int v13 = 0; v13 < 2; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v14 / v9; + v8[v12][v13].write(v15); + } + } + } + } + return ; +} + +void node2( + hls::stream v16[4][4], + float v17[64][64], + hls::stream v18[4][2], + float v19 +) { + #pragma HLS array_partition variable=v17 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v17 cyclic dim=2 factor=2 + + float v20[64][64]; + #pragma HLS array_partition variable=v20 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v20 cyclic dim=2 factor=2 + + float v21[64][64]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=4 + + loop8: for (int v22 = 0; v22 < 16; v22++) { + loop9: for (int v23 = 0; v23 < 16; v23++) { + loop10: for (int v24 = 0; v24 < 32; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v25 = 0; v25 < 4; v25++) { + loop12: for (int v26 = 0; v26 < 4; v26++) { + loop13: for (int v27 = 0; v27 < 2; v27++) { + if ((v27 + (v24 * 2)) == 0) { + float v28 = v16[v25][v26].read(); + v21[(v25 + (v22 * 4))][(v26 + (v23 * 4))] = v28; + } + float v29 = v21[(v25 + (v22 * 4))][(v26 + (v23 * 4))]; + float v30 = v17[(v26 + (v23 * 4))][(v27 + (v24 * 2))]; + if ((v26 + (v23 * 4)) == 0) { + v20[(v25 + (v22 * 4))][(v27 + (v24 * 2))] = v19; + } + float v31 = v20[(v25 + (v22 * 4))][(v27 + (v24 * 2))]; + float v32 = v29 * v30; + float v33 = v31 + v32; + v20[(v25 + (v22 * 4))][(v27 + (v24 * 2))] = v33; + if (((v26 + (v23 * 4)) - 63) == 0) { + float v34 = v20[(v25 + (v22 * 4))][(v27 + (v24 * 2))]; + v18[v25][v27].write(v34); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v35[64][64], + hls::stream v36[4][2], + hls::stream v37[4][4], + float v38 +) { + #pragma HLS array_partition variable=v35 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v35 cyclic dim=2 factor=4 + + float v39[64][64]; + #pragma HLS array_partition variable=v39 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v39 cyclic dim=2 factor=4 + + float v40[64][64]; + #pragma HLS array_partition variable=v40 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=2 + + loop14: for (int v41 = 0; v41 < 16; v41++) { + loop15: for (int v42 = 0; v42 < 32; v42++) { + loop16: for (int v43 = 0; v43 < 16; v43++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v44 = 0; v44 < 4; v44++) { + loop18: for (int v45 = 0; v45 < 2; v45++) { + loop19: for (int v46 = 0; v46 < 4; v46++) { + if ((v46 + (v43 * 4)) == 0) { + float v47 = v36[v44][v45].read(); + v40[(v44 + (v41 * 4))][(v45 + (v42 * 2))] = v47; + } + float v48 = v40[(v44 + (v41 * 4))][(v45 + (v42 * 2))]; + float v49 = v35[(v45 + (v42 * 2))][(v46 + (v43 * 4))]; + if ((v45 + (v42 * 2)) == 0) { + v39[(v44 + (v41 * 4))][(v46 + (v43 * 4))] = v38; + } + float v50 = v39[(v44 + (v41 * 4))][(v46 + (v43 * 4))]; + float v51 = v48 * v49; + float v52 = v50 + v51; + v39[(v44 + (v41 * 4))][(v46 + (v43 * 4))] = v52; + if (((v45 + (v42 * 2)) - 63) == 0) { + float v53 = v39[(v44 + (v41 * 4))][(v46 + (v43 * 4))]; + v37[v44][v46].write(v53); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v54[4][4], + float v55[64][64], + hls::stream v56[4][2], + float v57 +) { + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=2 + + float v58[64][64]; + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=2 + + float v59[64][64]; + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=4 + + loop20: for (int v60 = 0; v60 < 16; v60++) { + loop21: for (int v61 = 0; v61 < 16; v61++) { + loop22: for (int v62 = 0; v62 < 32; v62++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop23: for (int v63 = 0; v63 < 4; v63++) { + loop24: for (int v64 = 0; v64 < 4; v64++) { + loop25: for (int v65 = 0; v65 < 2; v65++) { + if ((v65 + (v62 * 2)) == 0) { + float v66 = v54[v63][v64].read(); + v59[(v63 + (v60 * 4))][(v64 + (v61 * 4))] = v66; + } + float v67 = v59[(v63 + (v60 * 4))][(v64 + (v61 * 4))]; + float v68 = v55[(v64 + (v61 * 4))][(v65 + (v62 * 2))]; + if ((v64 + (v61 * 4)) == 0) { + v58[(v63 + (v60 * 4))][(v65 + (v62 * 2))] = v57; + } + float v69 = v58[(v63 + (v60 * 4))][(v65 + (v62 * 2))]; + float v70 = v67 * v68; + float v71 = v69 + v70; + v58[(v63 + (v60 * 4))][(v65 + (v62 * 2))] = v71; + if (((v64 + (v61 * 4)) - 63) == 0) { + float v72 = v58[(v63 + (v60 * 4))][(v65 + (v62 * 2))]; + v56[v63][v65].write(v72); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v73[64][64], + hls::stream v74[4][2], + hls::stream v75[4][4], + float v76 +) { + #pragma HLS array_partition variable=v73 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v73 cyclic dim=2 factor=4 + + float v77[64][64]; + #pragma HLS array_partition variable=v77 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v77 cyclic dim=2 factor=4 + + float v78[64][64]; + #pragma HLS array_partition variable=v78 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v78 cyclic dim=2 factor=2 + + loop26: for (int v79 = 0; v79 < 16; v79++) { + loop27: for (int v80 = 0; v80 < 32; v80++) { + loop28: for (int v81 = 0; v81 < 16; v81++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop29: for (int v82 = 0; v82 < 4; v82++) { + loop30: for (int v83 = 0; v83 < 2; v83++) { + loop31: for (int v84 = 0; v84 < 4; v84++) { + if ((v84 + (v81 * 4)) == 0) { + float v85 = v74[v82][v83].read(); + v78[(v82 + (v79 * 4))][(v83 + (v80 * 2))] = v85; + } + float v86 = v78[(v82 + (v79 * 4))][(v83 + (v80 * 2))]; + float v87 = v73[(v83 + (v80 * 2))][(v84 + (v81 * 4))]; + if ((v83 + (v80 * 2)) == 0) { + v77[(v82 + (v79 * 4))][(v84 + (v81 * 4))] = v76; + } + float v88 = v77[(v82 + (v79 * 4))][(v84 + (v81 * 4))]; + float v89 = v86 * v87; + float v90 = v88 + v89; + v77[(v82 + (v79 * 4))][(v84 + (v81 * 4))] = v90; + if (((v83 + (v80 * 2)) - 63) == 0) { + float v91 = v77[(v82 + (v79 * 4))][(v84 + (v81 * 4))]; + v75[v82][v84].write(v91); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v92[4][4], + float v93[64][64], + hls::stream v94[4][2], + float v95 +) { + #pragma HLS array_partition variable=v93 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=2 + + float v96[64][64]; + #pragma HLS array_partition variable=v96 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=2 + + float v97[64][64]; + #pragma HLS array_partition variable=v97 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v97 cyclic dim=2 factor=4 + + loop32: for (int v98 = 0; v98 < 16; v98++) { + loop33: for (int v99 = 0; v99 < 16; v99++) { + loop34: for (int v100 = 0; v100 < 32; v100++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop35: for (int v101 = 0; v101 < 4; v101++) { + loop36: for (int v102 = 0; v102 < 4; v102++) { + loop37: for (int v103 = 0; v103 < 2; v103++) { + if ((v103 + (v100 * 2)) == 0) { + float v104 = v92[v101][v102].read(); + v97[(v101 + (v98 * 4))][(v102 + (v99 * 4))] = v104; + } + float v105 = v97[(v101 + (v98 * 4))][(v102 + (v99 * 4))]; + float v106 = v93[(v102 + (v99 * 4))][(v103 + (v100 * 2))]; + if ((v102 + (v99 * 4)) == 0) { + v96[(v101 + (v98 * 4))][(v103 + (v100 * 2))] = v95; + } + float v107 = v96[(v101 + (v98 * 4))][(v103 + (v100 * 2))]; + float v108 = v105 * v106; + float v109 = v107 + v108; + v96[(v101 + (v98 * 4))][(v103 + (v100 * 2))] = v109; + if (((v102 + (v99 * 4)) - 63) == 0) { + float v110 = v96[(v101 + (v98 * 4))][(v103 + (v100 * 2))]; + v94[v101][v103].write(v110); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v111[64][64], + hls::stream v112[4][2], + hls::stream v113[4][4], + float v114 +) { + #pragma HLS array_partition variable=v111 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v111 cyclic dim=2 factor=4 + + float v115[64][64]; + #pragma HLS array_partition variable=v115 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v115 cyclic dim=2 factor=4 + + float v116[64][64]; + #pragma HLS array_partition variable=v116 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v116 cyclic dim=2 factor=2 + + loop38: for (int v117 = 0; v117 < 16; v117++) { + loop39: for (int v118 = 0; v118 < 32; v118++) { + loop40: for (int v119 = 0; v119 < 16; v119++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v120 = 0; v120 < 4; v120++) { + loop42: for (int v121 = 0; v121 < 2; v121++) { + loop43: for (int v122 = 0; v122 < 4; v122++) { + if ((v122 + (v119 * 4)) == 0) { + float v123 = v112[v120][v121].read(); + v116[(v120 + (v117 * 4))][(v121 + (v118 * 2))] = v123; + } + float v124 = v116[(v120 + (v117 * 4))][(v121 + (v118 * 2))]; + float v125 = v111[(v121 + (v118 * 2))][(v122 + (v119 * 4))]; + if ((v121 + (v118 * 2)) == 0) { + v115[(v120 + (v117 * 4))][(v122 + (v119 * 4))] = v114; + } + float v126 = v115[(v120 + (v117 * 4))][(v122 + (v119 * 4))]; + float v127 = v124 * v125; + float v128 = v126 + v127; + v115[(v120 + (v117 * 4))][(v122 + (v119 * 4))] = v128; + if (((v121 + (v118 * 2)) - 63) == 0) { + float v129 = v115[(v120 + (v117 * 4))][(v122 + (v119 * 4))]; + v113[v120][v122].write(v129); + } + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v130[4][4], + float v131[64][64], + hls::stream v132[4][2], + float v133 +) { + #pragma HLS array_partition variable=v131 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v131 cyclic dim=2 factor=2 + + float v134[64][64]; + #pragma HLS array_partition variable=v134 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v134 cyclic dim=2 factor=2 + + float v135[64][64]; + #pragma HLS array_partition variable=v135 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v135 cyclic dim=2 factor=4 + + loop44: for (int v136 = 0; v136 < 16; v136++) { + loop45: for (int v137 = 0; v137 < 16; v137++) { + loop46: for (int v138 = 0; v138 < 32; v138++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop47: for (int v139 = 0; v139 < 4; v139++) { + loop48: for (int v140 = 0; v140 < 4; v140++) { + loop49: for (int v141 = 0; v141 < 2; v141++) { + if ((v141 + (v138 * 2)) == 0) { + float v142 = v130[v139][v140].read(); + v135[(v139 + (v136 * 4))][(v140 + (v137 * 4))] = v142; + } + float v143 = v135[(v139 + (v136 * 4))][(v140 + (v137 * 4))]; + float v144 = v131[(v140 + (v137 * 4))][(v141 + (v138 * 2))]; + if ((v140 + (v137 * 4)) == 0) { + v134[(v139 + (v136 * 4))][(v141 + (v138 * 2))] = v133; + } + float v145 = v134[(v139 + (v136 * 4))][(v141 + (v138 * 2))]; + float v146 = v143 * v144; + float v147 = v145 + v146; + v134[(v139 + (v136 * 4))][(v141 + (v138 * 2))] = v147; + if (((v140 + (v137 * 4)) - 63) == 0) { + float v148 = v134[(v139 + (v136 * 4))][(v141 + (v138 * 2))]; + v132[v139][v141].write(v148); + } + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v149[4][2], + float v150[64][64], + hls::stream v151[4][4], + float v152 +) { + #pragma HLS array_partition variable=v150 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v150 cyclic dim=2 factor=4 + + float v153[64][64]; + #pragma HLS array_partition variable=v153 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v153 cyclic dim=2 factor=4 + + float v154[64][64]; + #pragma HLS array_partition variable=v154 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v154 cyclic dim=2 factor=2 + + loop50: for (int v155 = 0; v155 < 16; v155++) { + loop51: for (int v156 = 0; v156 < 32; v156++) { + loop52: for (int v157 = 0; v157 < 16; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v158 = 0; v158 < 4; v158++) { + loop54: for (int v159 = 0; v159 < 2; v159++) { + loop55: for (int v160 = 0; v160 < 4; v160++) { + if ((v160 + (v157 * 4)) == 0) { + float v161 = v149[v158][v159].read(); + v154[(v158 + (v155 * 4))][(v159 + (v156 * 2))] = v161; + } + float v162 = v154[(v158 + (v155 * 4))][(v159 + (v156 * 2))]; + float v163 = v150[(v159 + (v156 * 2))][(v160 + (v157 * 4))]; + if ((v159 + (v156 * 2)) == 0) { + v153[(v158 + (v155 * 4))][(v160 + (v157 * 4))] = v152; + } + float v164 = v153[(v158 + (v155 * 4))][(v160 + (v157 * 4))]; + float v165 = v162 * v163; + float v166 = v164 + v165; + v153[(v158 + (v155 * 4))][(v160 + (v157 * 4))] = v166; + if (((v159 + (v156 * 2)) - 63) == 0) { + float v167 = v153[(v158 + (v155 * 4))][(v160 + (v157 * 4))]; + v151[v158][v160].write(v167); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v168[4][4], + float v169[64][64], + hls::stream v170[4][2], + float v171 +) { + #pragma HLS array_partition variable=v169 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=2 + + float v172[64][64]; + #pragma HLS array_partition variable=v172 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v172 cyclic dim=2 factor=2 + + float v173[64][64]; + #pragma HLS array_partition variable=v173 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v173 cyclic dim=2 factor=4 + + loop56: for (int v174 = 0; v174 < 16; v174++) { + loop57: for (int v175 = 0; v175 < 16; v175++) { + loop58: for (int v176 = 0; v176 < 32; v176++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop59: for (int v177 = 0; v177 < 4; v177++) { + loop60: for (int v178 = 0; v178 < 4; v178++) { + loop61: for (int v179 = 0; v179 < 2; v179++) { + if ((v179 + (v176 * 2)) == 0) { + float v180 = v168[v177][v178].read(); + v173[(v177 + (v174 * 4))][(v178 + (v175 * 4))] = v180; + } + float v181 = v173[(v177 + (v174 * 4))][(v178 + (v175 * 4))]; + float v182 = v169[(v178 + (v175 * 4))][(v179 + (v176 * 2))]; + if ((v178 + (v175 * 4)) == 0) { + v172[(v177 + (v174 * 4))][(v179 + (v176 * 2))] = v171; + } + float v183 = v172[(v177 + (v174 * 4))][(v179 + (v176 * 2))]; + float v184 = v181 * v182; + float v185 = v183 + v184; + v172[(v177 + (v174 * 4))][(v179 + (v176 * 2))] = v185; + if (((v178 + (v175 * 4)) - 63) == 0) { + float v186 = v172[(v177 + (v174 * 4))][(v179 + (v176 * 2))]; + v170[v177][v179].write(v186); + } + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v187[4][1], + float v188[64][64], + hls::stream v189[4][4], + float v190 +) { + #pragma HLS array_partition variable=v188 cyclic dim=2 factor=4 + + float v191[64][64]; + #pragma HLS array_partition variable=v191 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v191 cyclic dim=2 factor=4 + + float v192[64][64]; + #pragma HLS array_partition variable=v192 cyclic dim=1 factor=4 + + loop62: for (int v193 = 0; v193 < 16; v193++) { + loop63: for (int v194 = 0; v194 < 64; v194++) { + loop64: for (int v195 = 0; v195 < 16; v195++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop65: for (int v196 = 0; v196 < 4; v196++) { + loop66: for (int v197 = 0; v197 < 1; v197++) { + loop67: for (int v198 = 0; v198 < 4; v198++) { + if ((v198 + (v195 * 4)) == 0) { + float v199 = v187[v196][v197].read(); + v192[(v196 + (v193 * 4))][(v194 + v197)] = v199; + } + float v200 = v192[(v196 + (v193 * 4))][(v194 + v197)]; + float v201 = v188[(v194 + v197)][(v198 + (v195 * 4))]; + if ((v194 + v197) == 0) { + v191[(v196 + (v193 * 4))][(v198 + (v195 * 4))] = v190; + } + float v202 = v191[(v196 + (v193 * 4))][(v198 + (v195 * 4))]; + float v203 = v200 * v201; + float v204 = v202 + v203; + v191[(v196 + (v193 * 4))][(v198 + (v195 * 4))] = v204; + if (((v194 + v197) - 63) == 0) { + float v205 = v191[(v196 + (v193 * 4))][(v198 + (v195 * 4))]; + v189[v196][v198].write(v205); + } + } + } + } + } + } + } + return ; +} + +void node12( + hls::stream v206[4][4], + float v207[64][64], + hls::stream v208[4][1], + float v209 +) { + #pragma HLS array_partition variable=v207 cyclic dim=1 factor=4 + + float v210[64][64]; + #pragma HLS array_partition variable=v210 cyclic dim=1 factor=4 + + float v211[64][64]; + #pragma HLS array_partition variable=v211 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v211 cyclic dim=2 factor=4 + + loop68: for (int v212 = 0; v212 < 16; v212++) { + loop69: for (int v213 = 0; v213 < 16; v213++) { + loop70: for (int v214 = 0; v214 < 64; v214++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v215 = 0; v215 < 4; v215++) { + loop72: for (int v216 = 0; v216 < 4; v216++) { + loop73: for (int v217 = 0; v217 < 1; v217++) { + if ((v214 + v217) == 0) { + float v218 = v206[v215][v216].read(); + v211[(v215 + (v212 * 4))][(v216 + (v213 * 4))] = v218; + } + float v219 = v211[(v215 + (v212 * 4))][(v216 + (v213 * 4))]; + float v220 = v207[(v216 + (v213 * 4))][(v214 + v217)]; + if ((v216 + (v213 * 4)) == 0) { + v210[(v215 + (v212 * 4))][(v214 + v217)] = v209; + } + float v221 = v210[(v215 + (v212 * 4))][(v214 + v217)]; + float v222 = v219 * v220; + float v223 = v221 + v222; + v210[(v215 + (v212 * 4))][(v214 + v217)] = v223; + if (((v216 + (v213 * 4)) - 63) == 0) { + float v224 = v210[(v215 + (v212 * 4))][(v214 + v217)]; + v208[v215][v217].write(v224); + } + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v225[4][4], + float v226[64][64], + hls::stream v227[4][4], + float v228 +) { + #pragma HLS array_partition variable=v226 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v226 cyclic dim=2 factor=4 + + float v229[64][64]; + #pragma HLS array_partition variable=v229 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v229 cyclic dim=2 factor=4 + + float v230[64][64]; + #pragma HLS array_partition variable=v230 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v230 cyclic dim=2 factor=4 + + loop74: for (int v231 = 0; v231 < 16; v231++) { + loop75: for (int v232 = 0; v232 < 16; v232++) { + loop76: for (int v233 = 0; v233 < 16; v233++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop77: for (int v234 = 0; v234 < 4; v234++) { + loop78: for (int v235 = 0; v235 < 4; v235++) { + loop79: for (int v236 = 0; v236 < 4; v236++) { + if ((v235 + (v232 * 4)) == 0) { + float v237 = v225[v234][v236].read(); + v230[(v234 + (v231 * 4))][(v236 + (v233 * 4))] = v237; + } + float v238 = v230[(v234 + (v231 * 4))][(v236 + (v233 * 4))]; + float v239 = v226[(v236 + (v233 * 4))][(v235 + (v232 * 4))]; + if ((v236 + (v233 * 4)) == 0) { + v229[(v234 + (v231 * 4))][(v235 + (v232 * 4))] = v228; + } + float v240 = v229[(v234 + (v231 * 4))][(v235 + (v232 * 4))]; + float v241 = v238 * v239; + float v242 = v240 + v241; + v229[(v234 + (v231 * 4))][(v235 + (v232 * 4))] = v242; + if (((v236 + (v233 * 4)) - 63) == 0) { + float v243 = v229[(v234 + (v231 * 4))][(v235 + (v232 * 4))]; + v227[v234][v235].write(v243); + } + } + } + } + } + } + } + return ; +} + +void node14( + hls::stream v244[4][2], + float v245[64][64], + hls::stream v246[4][4], + float v247 +) { + #pragma HLS array_partition variable=v245 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v245 cyclic dim=2 factor=4 + + float v248[64][64]; + #pragma HLS array_partition variable=v248 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v248 cyclic dim=2 factor=4 + + float v249[64][64]; + #pragma HLS array_partition variable=v249 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v249 cyclic dim=2 factor=2 + + loop80: for (int v250 = 0; v250 < 16; v250++) { + loop81: for (int v251 = 0; v251 < 32; v251++) { + loop82: for (int v252 = 0; v252 < 16; v252++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v253 = 0; v253 < 4; v253++) { + loop84: for (int v254 = 0; v254 < 2; v254++) { + loop85: for (int v255 = 0; v255 < 4; v255++) { + if ((v255 + (v252 * 4)) == 0) { + float v256 = v244[v253][v254].read(); + v249[(v253 + (v250 * 4))][(v254 + (v251 * 2))] = v256; + } + float v257 = v249[(v253 + (v250 * 4))][(v254 + (v251 * 2))]; + float v258 = v245[(v254 + (v251 * 2))][(v255 + (v252 * 4))]; + if ((v254 + (v251 * 2)) == 0) { + v248[(v253 + (v250 * 4))][(v255 + (v252 * 4))] = v247; + } + float v259 = v248[(v253 + (v250 * 4))][(v255 + (v252 * 4))]; + float v260 = v257 * v258; + float v261 = v259 + v260; + v248[(v253 + (v250 * 4))][(v255 + (v252 * 4))] = v261; + if (((v254 + (v251 * 2)) - 63) == 0) { + float v262 = v248[(v253 + (v250 * 4))][(v255 + (v252 * 4))]; + v246[v253][v255].write(v262); + } + } + } + } + } + } + } + return ; +} + +void node15( + hls::stream v263[4][4], + float v264[64][64], + hls::stream v265[4][2], + float v266 +) { + #pragma HLS array_partition variable=v264 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v264 cyclic dim=2 factor=2 + + float v267[64][64]; + #pragma HLS array_partition variable=v267 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v267 cyclic dim=2 factor=2 + + float v268[64][64]; + #pragma HLS array_partition variable=v268 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v268 cyclic dim=2 factor=4 + + loop86: for (int v269 = 0; v269 < 16; v269++) { + loop87: for (int v270 = 0; v270 < 16; v270++) { + loop88: for (int v271 = 0; v271 < 32; v271++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v272 = 0; v272 < 4; v272++) { + loop90: for (int v273 = 0; v273 < 4; v273++) { + loop91: for (int v274 = 0; v274 < 2; v274++) { + if ((v274 + (v271 * 2)) == 0) { + float v275 = v263[v272][v273].read(); + v268[(v272 + (v269 * 4))][(v273 + (v270 * 4))] = v275; + } + float v276 = v268[(v272 + (v269 * 4))][(v273 + (v270 * 4))]; + float v277 = v264[(v273 + (v270 * 4))][(v274 + (v271 * 2))]; + if ((v273 + (v270 * 4)) == 0) { + v267[(v272 + (v269 * 4))][(v274 + (v271 * 2))] = v266; + } + float v278 = v267[(v272 + (v269 * 4))][(v274 + (v271 * 2))]; + float v279 = v276 * v277; + float v280 = v278 + v279; + v267[(v272 + (v269 * 4))][(v274 + (v271 * 2))] = v280; + if (((v273 + (v270 * 4)) - 63) == 0) { + float v281 = v267[(v272 + (v269 * 4))][(v274 + (v271 * 2))]; + v265[v272][v274].write(v281); + } + } + } + } + } + } + } + return ; +} + +void node16( + float v282[64][64], + float v283[64][64], + hls::stream v284[4][4], + float v285 +) { + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v283 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v283 cyclic dim=2 factor=4 + + float v286[64][64]; + #pragma HLS array_partition variable=v286 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v286 cyclic dim=2 factor=4 + + loop92: for (int v287 = 0; v287 < 16; v287++) { + loop93: for (int v288 = 0; v288 < 16; v288++) { + loop94: for (int v289 = 0; v289 < 16; v289++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop95: for (int v290 = 0; v290 < 4; v290++) { + loop96: for (int v291 = 0; v291 < 4; v291++) { + loop97: for (int v292 = 0; v292 < 4; v292++) { + float v293 = v283[(v290 + (v287 * 4))][(v292 + (v289 * 4))]; + float v294 = v282[(v292 + (v289 * 4))][(v291 + (v288 * 4))]; + if ((v292 + (v289 * 4)) == 0) { + v286[(v290 + (v287 * 4))][(v291 + (v288 * 4))] = v285; + } + float v295 = v286[(v290 + (v287 * 4))][(v291 + (v288 * 4))]; + float v296 = v293 * v294; + float v297 = v295 + v296; + v286[(v290 + (v287 * 4))][(v291 + (v288 * 4))] = v297; + if (((v292 + (v289 * 4)) - 63) == 0) { + float v298 = v286[(v290 + (v287 * 4))][(v291 + (v288 * 4))]; + v284[v290][v291].write(v298); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v299[64][64], + float v300[64][64], + float v301[64][64], + float v302[64][64], + float v303[64][64], + float v304[64][64], + float v305[64][64], + float v306[64][64], + float v307[64][64], + float v308[64][64], + float v309[64][64], + float v310[64][64], + float v311[64][64], + float v312[64][64], + float v313[64][64], + float v314[64][64], + float v315[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v299 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v299 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v300 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v300 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v301 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v301 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v302 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v302 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v303 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v303 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v304 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v305 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v306 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v306 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v307 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v307 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v308 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v308 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v309 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v309 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v310 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v310 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v312 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v312 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v313 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v313 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v314 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v314 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v315 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v315 cyclic dim=2 factor=2 + + hls::stream v316[4][2]; + #pragma HLS STREAM variable=v316 depth=512 + hls::stream v317[4][2]; + #pragma HLS STREAM variable=v317 depth=512 + hls::stream v318[4][4]; + #pragma HLS STREAM variable=v318 depth=256 + hls::stream v319[4][2]; + #pragma HLS STREAM variable=v319 depth=512 + hls::stream v320[4][4]; + #pragma HLS STREAM variable=v320 depth=256 + hls::stream v321[4][2]; + #pragma HLS STREAM variable=v321 depth=512 + hls::stream v322[4][4]; + #pragma HLS STREAM variable=v322 depth=256 + hls::stream v323[4][2]; + #pragma HLS STREAM variable=v323 depth=512 + hls::stream v324[4][4]; + #pragma HLS STREAM variable=v324 depth=256 + hls::stream v325[4][2]; + #pragma HLS STREAM variable=v325 depth=512 + hls::stream v326[4][4]; + #pragma HLS STREAM variable=v326 depth=256 + hls::stream v327[4][1]; + #pragma HLS STREAM variable=v327 depth=1024 + hls::stream v328[4][4]; + #pragma HLS STREAM variable=v328 depth=256 + hls::stream v329[4][4]; + #pragma HLS STREAM variable=v329 depth=256 + hls::stream v330[4][2]; + #pragma HLS STREAM variable=v330 depth=512 + hls::stream v331[4][4]; + #pragma HLS STREAM variable=v331 depth=256 + node16(v300, v299, v331, 0.000000); + node15(v331, v301, v330, 0.000000); + node14(v330, v302, v329, 0.000000); + node13(v329, v303, v328, 0.000000); + node12(v328, v304, v327, 0.000000); + node11(v327, v305, v326, 0.000000); + node10(v326, v306, v325, 0.000000); + node9(v325, v307, v324, 0.000000); + node8(v324, v308, v323, 0.000000); + node7(v309, v323, v322, 0.000000); + node6(v322, v310, v321, 0.000000); + node5(v311, v321, v320, 0.000000); + node4(v320, v312, v319, 0.000000); + node3(v313, v319, v318, 0.000000); + node2(v318, v314, v317, 0.000000); + node1(v317, v316, 1000000.000000); + node0(v316, v315); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_imbalanced__opt5/src/k15mmseq_imbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_imbalanced__opt5/src/k15mmseq_imbalanced.cpp new file mode 100644 index 000000000000..c4540b1ea896 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_imbalanced__opt5/src/k15mmseq_imbalanced.cpp @@ -0,0 +1,873 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[16][16] +) { + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v2 + v4)][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[1][1], + hls::stream v8[1][1], + float v9 +) { + loop4: for (int v10 = 0; v10 < 16; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 1; v12++) { + loop7: for (int v13 = 0; v13 < 1; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v14 / v9; + v8[v12][v13].write(v15); + } + } + } + } + return ; +} + +void node2( + float v16[16][16], + hls::stream v17[1][1], + hls::stream v18[1][1], + float v19 +) { + float v20[16][16]; + float v21[16][16]; + loop8: for (int v22 = 0; v22 < 16; v22++) { + loop9: for (int v23 = 0; v23 < 16; v23++) { + loop10: for (int v24 = 0; v24 < 16; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v25 = 0; v25 < 1; v25++) { + loop12: for (int v26 = 0; v26 < 1; v26++) { + loop13: for (int v27 = 0; v27 < 1; v27++) { + if ((v24 + v27) == 0) { + float v28 = v17[v25][v26].read(); + v21[(v22 + v25)][(v23 + v26)] = v28; + } + float v29 = v21[(v22 + v25)][(v23 + v26)]; + float v30 = v16[(v23 + v26)][(v24 + v27)]; + if ((v23 + v26) == 0) { + v20[(v22 + v25)][(v24 + v27)] = v19; + } + float v31 = v20[(v22 + v25)][(v24 + v27)]; + float v32 = v29 * v30; + float v33 = v31 + v32; + v20[(v22 + v25)][(v24 + v27)] = v33; + if (((v23 + v26) - 15) == 0) { + float v34 = v20[(v22 + v25)][(v24 + v27)]; + v18[v25][v27].write(v34); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v35[1][2], + float v36[32][16], + hls::stream v37[1][1], + float v38 +) { + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=2 + + float v39[16][16]; + float v40[16][32]; + #pragma HLS array_partition variable=v40 cyclic dim=2 factor=2 + + loop14: for (int v41 = 0; v41 < 16; v41++) { + loop15: for (int v42 = 0; v42 < 16; v42++) { + loop16: for (int v43 = 0; v43 < 16; v43++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v44 = 0; v44 < 1; v44++) { + loop18: for (int v45 = 0; v45 < 2; v45++) { + loop19: for (int v46 = 0; v46 < 1; v46++) { + if ((v43 + v46) == 0) { + float v47 = v35[v44][v45].read(); + v40[(v41 + v44)][(v45 + (v42 * 2))] = v47; + } + float v48 = v40[(v41 + v44)][(v45 + (v42 * 2))]; + float v49 = v36[(v45 + (v42 * 2))][(v43 + v46)]; + if ((v45 + (v42 * 2)) == 0) { + v39[(v41 + v44)][(v43 + v46)] = v38; + } + float v50 = v39[(v41 + v44)][(v43 + v46)]; + float v51 = v48 * v49; + float v52 = v50 + v51; + v39[(v41 + v44)][(v43 + v46)] = v52; + if (((v45 + (v42 * 2)) - 31) == 0) { + float v53 = v39[(v41 + v44)][(v43 + v46)]; + v37[v44][v46].write(v53); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v54[1][4], + float v55[64][32], + hls::stream v56[1][2], + float v57 +) { + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=2 + + float v58[16][32]; + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=2 + + float v59[16][64]; + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=4 + + loop20: for (int v60 = 0; v60 < 16; v60++) { + loop21: for (int v61 = 0; v61 < 16; v61++) { + loop22: for (int v62 = 0; v62 < 16; v62++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop23: for (int v63 = 0; v63 < 1; v63++) { + loop24: for (int v64 = 0; v64 < 4; v64++) { + loop25: for (int v65 = 0; v65 < 2; v65++) { + if ((v65 + (v62 * 2)) == 0) { + float v66 = v54[v63][v64].read(); + v59[(v60 + v63)][(v64 + (v61 * 4))] = v66; + } + float v67 = v59[(v60 + v63)][(v64 + (v61 * 4))]; + float v68 = v55[(v64 + (v61 * 4))][(v65 + (v62 * 2))]; + if ((v64 + (v61 * 4)) == 0) { + v58[(v60 + v63)][(v65 + (v62 * 2))] = v57; + } + float v69 = v58[(v60 + v63)][(v65 + (v62 * 2))]; + float v70 = v67 * v68; + float v71 = v69 + v70; + v58[(v60 + v63)][(v65 + (v62 * 2))] = v71; + if (((v64 + (v61 * 4)) - 63) == 0) { + float v72 = v58[(v60 + v63)][(v65 + (v62 * 2))]; + v56[v63][v65].write(v72); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v73[128][64], + hls::stream v74[1][8], + hls::stream v75[1][4], + float v76 +) { + #pragma HLS array_partition variable=v73 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v73 cyclic dim=2 factor=4 + + float v77[16][64]; + #pragma HLS array_partition variable=v77 cyclic dim=2 factor=4 + + float v78[16][128]; + #pragma HLS array_partition variable=v78 cyclic dim=2 factor=8 + + loop26: for (int v79 = 0; v79 < 16; v79++) { + loop27: for (int v80 = 0; v80 < 16; v80++) { + loop28: for (int v81 = 0; v81 < 16; v81++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop29: for (int v82 = 0; v82 < 1; v82++) { + loop30: for (int v83 = 0; v83 < 8; v83++) { + loop31: for (int v84 = 0; v84 < 4; v84++) { + if ((v84 + (v81 * 4)) == 0) { + float v85 = v74[v82][v83].read(); + v78[(v79 + v82)][(v83 + (v80 * 8))] = v85; + } + float v86 = v78[(v79 + v82)][(v83 + (v80 * 8))]; + float v87 = v73[(v83 + (v80 * 8))][(v84 + (v81 * 4))]; + if ((v83 + (v80 * 8)) == 0) { + v77[(v79 + v82)][(v84 + (v81 * 4))] = v76; + } + float v88 = v77[(v79 + v82)][(v84 + (v81 * 4))]; + float v89 = v86 * v87; + float v90 = v88 + v89; + v77[(v79 + v82)][(v84 + (v81 * 4))] = v90; + if (((v83 + (v80 * 8)) - 127) == 0) { + float v91 = v77[(v79 + v82)][(v84 + (v81 * 4))]; + v75[v82][v84].write(v91); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v92[1][4], + float v93[64][128], + hls::stream v94[1][8], + float v95 +) { + #pragma HLS array_partition variable=v93 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v93 cyclic dim=2 factor=8 + + float v96[16][128]; + #pragma HLS array_partition variable=v96 cyclic dim=2 factor=8 + + float v97[16][64]; + #pragma HLS array_partition variable=v97 cyclic dim=2 factor=4 + + loop32: for (int v98 = 0; v98 < 16; v98++) { + loop33: for (int v99 = 0; v99 < 16; v99++) { + loop34: for (int v100 = 0; v100 < 16; v100++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop35: for (int v101 = 0; v101 < 1; v101++) { + loop36: for (int v102 = 0; v102 < 4; v102++) { + loop37: for (int v103 = 0; v103 < 8; v103++) { + if ((v103 + (v100 * 8)) == 0) { + float v104 = v92[v101][v102].read(); + v97[(v98 + v101)][(v102 + (v99 * 4))] = v104; + } + float v105 = v97[(v98 + v101)][(v102 + (v99 * 4))]; + float v106 = v93[(v102 + (v99 * 4))][(v103 + (v100 * 8))]; + if ((v102 + (v99 * 4)) == 0) { + v96[(v98 + v101)][(v103 + (v100 * 8))] = v95; + } + float v107 = v96[(v98 + v101)][(v103 + (v100 * 8))]; + float v108 = v105 * v106; + float v109 = v107 + v108; + v96[(v98 + v101)][(v103 + (v100 * 8))] = v109; + if (((v102 + (v99 * 4)) - 63) == 0) { + float v110 = v96[(v98 + v101)][(v103 + (v100 * 8))]; + v94[v101][v103].write(v110); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v111[128][64], + hls::stream v112[1][8], + hls::stream v113[1][4], + float v114 +) { + #pragma HLS array_partition variable=v111 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v111 cyclic dim=2 factor=4 + + float v115[16][64]; + #pragma HLS array_partition variable=v115 cyclic dim=2 factor=4 + + float v116[16][128]; + #pragma HLS array_partition variable=v116 cyclic dim=2 factor=8 + + loop38: for (int v117 = 0; v117 < 16; v117++) { + loop39: for (int v118 = 0; v118 < 16; v118++) { + loop40: for (int v119 = 0; v119 < 16; v119++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v120 = 0; v120 < 1; v120++) { + loop42: for (int v121 = 0; v121 < 8; v121++) { + loop43: for (int v122 = 0; v122 < 4; v122++) { + if ((v122 + (v119 * 4)) == 0) { + float v123 = v112[v120][v121].read(); + v116[(v117 + v120)][(v121 + (v118 * 8))] = v123; + } + float v124 = v116[(v117 + v120)][(v121 + (v118 * 8))]; + float v125 = v111[(v121 + (v118 * 8))][(v122 + (v119 * 4))]; + if ((v121 + (v118 * 8)) == 0) { + v115[(v117 + v120)][(v122 + (v119 * 4))] = v114; + } + float v126 = v115[(v117 + v120)][(v122 + (v119 * 4))]; + float v127 = v124 * v125; + float v128 = v126 + v127; + v115[(v117 + v120)][(v122 + (v119 * 4))] = v128; + if (((v121 + (v118 * 8)) - 127) == 0) { + float v129 = v115[(v117 + v120)][(v122 + (v119 * 4))]; + v113[v120][v122].write(v129); + } + } + } + } + } + } + } + return ; +} + +void node8( + float v130[32][128], + hls::stream v131[1][2], + hls::stream v132[1][8], + float v133 +) { + #pragma HLS array_partition variable=v130 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v130 cyclic dim=2 factor=8 + + float v134[16][128]; + #pragma HLS array_partition variable=v134 cyclic dim=2 factor=8 + + float v135[16][32]; + #pragma HLS array_partition variable=v135 cyclic dim=2 factor=2 + + loop44: for (int v136 = 0; v136 < 16; v136++) { + loop45: for (int v137 = 0; v137 < 16; v137++) { + loop46: for (int v138 = 0; v138 < 16; v138++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop47: for (int v139 = 0; v139 < 1; v139++) { + loop48: for (int v140 = 0; v140 < 2; v140++) { + loop49: for (int v141 = 0; v141 < 8; v141++) { + if ((v141 + (v138 * 8)) == 0) { + float v142 = v131[v139][v140].read(); + v135[(v136 + v139)][(v140 + (v137 * 2))] = v142; + } + float v143 = v135[(v136 + v139)][(v140 + (v137 * 2))]; + float v144 = v130[(v140 + (v137 * 2))][(v141 + (v138 * 8))]; + if ((v140 + (v137 * 2)) == 0) { + v134[(v136 + v139)][(v141 + (v138 * 8))] = v133; + } + float v145 = v134[(v136 + v139)][(v141 + (v138 * 8))]; + float v146 = v143 * v144; + float v147 = v145 + v146; + v134[(v136 + v139)][(v141 + (v138 * 8))] = v147; + if (((v140 + (v137 * 2)) - 31) == 0) { + float v148 = v134[(v136 + v139)][(v141 + (v138 * 8))]; + v132[v139][v141].write(v148); + } + } + } + } + } + } + } + return ; +} + +void node9( + float v149[16][32], + hls::stream v150[1][1], + hls::stream v151[1][2], + float v152 +) { + #pragma HLS array_partition variable=v149 cyclic dim=2 factor=2 + + float v153[16][32]; + #pragma HLS array_partition variable=v153 cyclic dim=2 factor=2 + + float v154[16][16]; + loop50: for (int v155 = 0; v155 < 16; v155++) { + loop51: for (int v156 = 0; v156 < 16; v156++) { + loop52: for (int v157 = 0; v157 < 16; v157++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v158 = 0; v158 < 1; v158++) { + loop54: for (int v159 = 0; v159 < 1; v159++) { + loop55: for (int v160 = 0; v160 < 2; v160++) { + if ((v160 + (v157 * 2)) == 0) { + float v161 = v150[v158][v159].read(); + v154[(v155 + v158)][(v156 + v159)] = v161; + } + float v162 = v154[(v155 + v158)][(v156 + v159)]; + float v163 = v149[(v156 + v159)][(v160 + (v157 * 2))]; + if ((v156 + v159) == 0) { + v153[(v155 + v158)][(v160 + (v157 * 2))] = v152; + } + float v164 = v153[(v155 + v158)][(v160 + (v157 * 2))]; + float v165 = v162 * v163; + float v166 = v164 + v165; + v153[(v155 + v158)][(v160 + (v157 * 2))] = v166; + if (((v156 + v159) - 15) == 0) { + float v167 = v153[(v155 + v158)][(v160 + (v157 * 2))]; + v151[v158][v160].write(v167); + } + } + } + } + } + } + } + return ; +} + +void node10( + hls::stream v168[1][1], + float v169[16][16], + hls::stream v170[1][1], + float v171 +) { + float v172[16][16]; + float v173[16][16]; + loop56: for (int v174 = 0; v174 < 16; v174++) { + loop57: for (int v175 = 0; v175 < 16; v175++) { + loop58: for (int v176 = 0; v176 < 16; v176++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop59: for (int v177 = 0; v177 < 1; v177++) { + loop60: for (int v178 = 0; v178 < 1; v178++) { + loop61: for (int v179 = 0; v179 < 1; v179++) { + if ((v176 + v179) == 0) { + float v180 = v168[v177][v178].read(); + v173[(v174 + v177)][(v175 + v178)] = v180; + } + float v181 = v173[(v174 + v177)][(v175 + v178)]; + float v182 = v169[(v175 + v178)][(v176 + v179)]; + if ((v175 + v178) == 0) { + v172[(v174 + v177)][(v176 + v179)] = v171; + } + float v183 = v172[(v174 + v177)][(v176 + v179)]; + float v184 = v181 * v182; + float v185 = v183 + v184; + v172[(v174 + v177)][(v176 + v179)] = v185; + if (((v175 + v178) - 15) == 0) { + float v186 = v172[(v174 + v177)][(v176 + v179)]; + v170[v177][v179].write(v186); + } + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v187[1][2], + float v188[32][16], + hls::stream v189[1][1], + float v190 +) { + #pragma HLS array_partition variable=v188 cyclic dim=1 factor=2 + + float v191[16][16]; + float v192[16][32]; + #pragma HLS array_partition variable=v192 cyclic dim=2 factor=2 + + loop62: for (int v193 = 0; v193 < 16; v193++) { + loop63: for (int v194 = 0; v194 < 16; v194++) { + loop64: for (int v195 = 0; v195 < 16; v195++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop65: for (int v196 = 0; v196 < 1; v196++) { + loop66: for (int v197 = 0; v197 < 2; v197++) { + loop67: for (int v198 = 0; v198 < 1; v198++) { + if ((v195 + v198) == 0) { + float v199 = v187[v196][v197].read(); + v192[(v193 + v196)][(v197 + (v194 * 2))] = v199; + } + float v200 = v192[(v193 + v196)][(v197 + (v194 * 2))]; + float v201 = v188[(v197 + (v194 * 2))][(v195 + v198)]; + if ((v197 + (v194 * 2)) == 0) { + v191[(v193 + v196)][(v195 + v198)] = v190; + } + float v202 = v191[(v193 + v196)][(v195 + v198)]; + float v203 = v200 * v201; + float v204 = v202 + v203; + v191[(v193 + v196)][(v195 + v198)] = v204; + if (((v197 + (v194 * 2)) - 31) == 0) { + float v205 = v191[(v193 + v196)][(v195 + v198)]; + v189[v196][v198].write(v205); + } + } + } + } + } + } + } + return ; +} + +void node12( + float v206[64][32], + hls::stream v207[1][4], + hls::stream v208[1][2], + float v209 +) { + #pragma HLS array_partition variable=v206 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v206 cyclic dim=2 factor=2 + + float v210[16][32]; + #pragma HLS array_partition variable=v210 cyclic dim=2 factor=2 + + float v211[16][64]; + #pragma HLS array_partition variable=v211 cyclic dim=2 factor=4 + + loop68: for (int v212 = 0; v212 < 16; v212++) { + loop69: for (int v213 = 0; v213 < 16; v213++) { + loop70: for (int v214 = 0; v214 < 16; v214++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v215 = 0; v215 < 1; v215++) { + loop72: for (int v216 = 0; v216 < 4; v216++) { + loop73: for (int v217 = 0; v217 < 2; v217++) { + if ((v217 + (v214 * 2)) == 0) { + float v218 = v207[v215][v216].read(); + v211[(v212 + v215)][(v216 + (v213 * 4))] = v218; + } + float v219 = v211[(v212 + v215)][(v216 + (v213 * 4))]; + float v220 = v206[(v216 + (v213 * 4))][(v217 + (v214 * 2))]; + if ((v216 + (v213 * 4)) == 0) { + v210[(v212 + v215)][(v217 + (v214 * 2))] = v209; + } + float v221 = v210[(v212 + v215)][(v217 + (v214 * 2))]; + float v222 = v219 * v220; + float v223 = v221 + v222; + v210[(v212 + v215)][(v217 + (v214 * 2))] = v223; + if (((v216 + (v213 * 4)) - 63) == 0) { + float v224 = v210[(v212 + v215)][(v217 + (v214 * 2))]; + v208[v215][v217].write(v224); + } + } + } + } + } + } + } + return ; +} + +void node13( + float v225[128][64], + hls::stream v226[1][8], + hls::stream v227[1][4], + float v228 +) { + #pragma HLS array_partition variable=v225 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v225 cyclic dim=2 factor=4 + + float v229[16][64]; + #pragma HLS array_partition variable=v229 cyclic dim=2 factor=4 + + float v230[16][128]; + #pragma HLS array_partition variable=v230 cyclic dim=2 factor=8 + + loop74: for (int v231 = 0; v231 < 16; v231++) { + loop75: for (int v232 = 0; v232 < 16; v232++) { + loop76: for (int v233 = 0; v233 < 16; v233++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop77: for (int v234 = 0; v234 < 1; v234++) { + loop78: for (int v235 = 0; v235 < 8; v235++) { + loop79: for (int v236 = 0; v236 < 4; v236++) { + if ((v236 + (v233 * 4)) == 0) { + float v237 = v226[v234][v235].read(); + v230[(v231 + v234)][(v235 + (v232 * 8))] = v237; + } + float v238 = v230[(v231 + v234)][(v235 + (v232 * 8))]; + float v239 = v225[(v235 + (v232 * 8))][(v236 + (v233 * 4))]; + if ((v235 + (v232 * 8)) == 0) { + v229[(v231 + v234)][(v236 + (v233 * 4))] = v228; + } + float v240 = v229[(v231 + v234)][(v236 + (v233 * 4))]; + float v241 = v238 * v239; + float v242 = v240 + v241; + v229[(v231 + v234)][(v236 + (v233 * 4))] = v242; + if (((v235 + (v232 * 8)) - 127) == 0) { + float v243 = v229[(v231 + v234)][(v236 + (v233 * 4))]; + v227[v234][v236].write(v243); + } + } + } + } + } + } + } + return ; +} + +void node14( + float v244[64][128], + hls::stream v245[1][4], + hls::stream v246[1][8], + float v247 +) { + #pragma HLS array_partition variable=v244 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v244 cyclic dim=2 factor=8 + + float v248[16][128]; + #pragma HLS array_partition variable=v248 cyclic dim=2 factor=8 + + float v249[16][64]; + #pragma HLS array_partition variable=v249 cyclic dim=2 factor=4 + + loop80: for (int v250 = 0; v250 < 16; v250++) { + loop81: for (int v251 = 0; v251 < 16; v251++) { + loop82: for (int v252 = 0; v252 < 16; v252++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v253 = 0; v253 < 1; v253++) { + loop84: for (int v254 = 0; v254 < 4; v254++) { + loop85: for (int v255 = 0; v255 < 8; v255++) { + if ((v255 + (v252 * 8)) == 0) { + float v256 = v245[v253][v254].read(); + v249[(v250 + v253)][(v254 + (v251 * 4))] = v256; + } + float v257 = v249[(v250 + v253)][(v254 + (v251 * 4))]; + float v258 = v244[(v254 + (v251 * 4))][(v255 + (v252 * 8))]; + if ((v254 + (v251 * 4)) == 0) { + v248[(v250 + v253)][(v255 + (v252 * 8))] = v247; + } + float v259 = v248[(v250 + v253)][(v255 + (v252 * 8))]; + float v260 = v257 * v258; + float v261 = v259 + v260; + v248[(v250 + v253)][(v255 + (v252 * 8))] = v261; + if (((v254 + (v251 * 4)) - 63) == 0) { + float v262 = v248[(v250 + v253)][(v255 + (v252 * 8))]; + v246[v253][v255].write(v262); + } + } + } + } + } + } + } + return ; +} + +void node15( + hls::stream v263[1][8], + float v264[128][64], + hls::stream v265[1][4], + float v266 +) { + #pragma HLS array_partition variable=v264 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v264 cyclic dim=2 factor=4 + + float v267[16][64]; + #pragma HLS array_partition variable=v267 cyclic dim=2 factor=4 + + float v268[16][128]; + #pragma HLS array_partition variable=v268 cyclic dim=2 factor=8 + + loop86: for (int v269 = 0; v269 < 16; v269++) { + loop87: for (int v270 = 0; v270 < 16; v270++) { + loop88: for (int v271 = 0; v271 < 16; v271++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v272 = 0; v272 < 1; v272++) { + loop90: for (int v273 = 0; v273 < 8; v273++) { + loop91: for (int v274 = 0; v274 < 4; v274++) { + if ((v274 + (v271 * 4)) == 0) { + float v275 = v263[v272][v273].read(); + v268[(v269 + v272)][(v273 + (v270 * 8))] = v275; + } + float v276 = v268[(v269 + v272)][(v273 + (v270 * 8))]; + float v277 = v264[(v273 + (v270 * 8))][(v274 + (v271 * 4))]; + if ((v273 + (v270 * 8)) == 0) { + v267[(v269 + v272)][(v274 + (v271 * 4))] = v266; + } + float v278 = v267[(v269 + v272)][(v274 + (v271 * 4))]; + float v279 = v276 * v277; + float v280 = v278 + v279; + v267[(v269 + v272)][(v274 + (v271 * 4))] = v280; + if (((v273 + (v270 * 8)) - 127) == 0) { + float v281 = v267[(v269 + v272)][(v274 + (v271 * 4))]; + v265[v272][v274].write(v281); + } + } + } + } + } + } + } + return ; +} + +void node16( + float v282[32][128], + float v283[16][32], + hls::stream v284[1][8], + float v285 +) { + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v283 cyclic dim=2 factor=2 + + float v286[16][128]; + #pragma HLS array_partition variable=v286 cyclic dim=2 factor=8 + + loop92: for (int v287 = 0; v287 < 16; v287++) { + loop93: for (int v288 = 0; v288 < 16; v288++) { + loop94: for (int v289 = 0; v289 < 16; v289++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop95: for (int v290 = 0; v290 < 1; v290++) { + loop96: for (int v291 = 0; v291 < 2; v291++) { + loop97: for (int v292 = 0; v292 < 8; v292++) { + float v293 = v283[(v287 + v290)][(v291 + (v288 * 2))]; + float v294 = v282[(v291 + (v288 * 2))][(v292 + (v289 * 8))]; + if ((v291 + (v288 * 2)) == 0) { + v286[(v287 + v290)][(v292 + (v289 * 8))] = v285; + } + float v295 = v286[(v287 + v290)][(v292 + (v289 * 8))]; + float v296 = v293 * v294; + float v297 = v295 + v296; + v286[(v287 + v290)][(v292 + (v289 * 8))] = v297; + if (((v291 + (v288 * 2)) - 31) == 0) { + float v298 = v286[(v287 + v290)][(v292 + (v289 * 8))]; + v284[v290][v292].write(v298); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v299[16][32], + float v300[32][128], + float v301[128][64], + float v302[64][128], + float v303[128][64], + float v304[64][32], + float v305[32][16], + float v306[16][16], + float v307[16][32], + float v308[32][128], + float v309[128][64], + float v310[64][128], + float v311[128][64], + float v312[64][32], + float v313[32][16], + float v314[16][16], + float v315[16][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v299 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v300 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v300 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v301 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v301 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v302 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v302 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v303 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v303 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v304 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v304 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v305 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v307 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v308 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v308 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v309 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v309 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v310 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v310 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v312 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v312 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v313 cyclic dim=1 factor=2 + + hls::stream v316[1][1]; + #pragma HLS STREAM variable=v316 depth=256 + hls::stream v317[1][1]; + #pragma HLS STREAM variable=v317 depth=256 + hls::stream v318[1][1]; + #pragma HLS STREAM variable=v318 depth=256 + hls::stream v319[1][2]; + #pragma HLS STREAM variable=v319 depth=256 + hls::stream v320[1][4]; + #pragma HLS STREAM variable=v320 depth=256 + hls::stream v321[1][8]; + #pragma HLS STREAM variable=v321 depth=256 + hls::stream v322[1][4]; + #pragma HLS STREAM variable=v322 depth=256 + hls::stream v323[1][8]; + #pragma HLS STREAM variable=v323 depth=256 + hls::stream v324[1][2]; + #pragma HLS STREAM variable=v324 depth=256 + hls::stream v325[1][1]; + #pragma HLS STREAM variable=v325 depth=256 + hls::stream v326[1][1]; + #pragma HLS STREAM variable=v326 depth=256 + hls::stream v327[1][2]; + #pragma HLS STREAM variable=v327 depth=256 + hls::stream v328[1][4]; + #pragma HLS STREAM variable=v328 depth=256 + hls::stream v329[1][8]; + #pragma HLS STREAM variable=v329 depth=256 + hls::stream v330[1][4]; + #pragma HLS STREAM variable=v330 depth=256 + hls::stream v331[1][8]; + #pragma HLS STREAM variable=v331 depth=256 + node16(v300, v299, v331, 0.000000); + node15(v331, v301, v330, 0.000000); + node14(v302, v330, v329, 0.000000); + node13(v303, v329, v328, 0.000000); + node12(v304, v328, v327, 0.000000); + node11(v327, v305, v326, 0.000000); + node10(v326, v306, v325, 0.000000); + node9(v307, v325, v324, 0.000000); + node8(v308, v324, v323, 0.000000); + node7(v309, v323, v322, 0.000000); + node6(v322, v310, v321, 0.000000); + node5(v311, v321, v320, 0.000000); + node4(v320, v312, v319, 0.000000); + node3(v319, v313, v318, 0.000000); + node2(v314, v318, v317, 0.000000); + node1(v317, v316, 1000000.000000); + node0(v316, v315); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu__opt5/src/k15mmseq_relu.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu__opt5/src/k15mmseq_relu.cpp new file mode 100644 index 000000000000..c84ae52ad134 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu__opt5/src/k15mmseq_relu.cpp @@ -0,0 +1,1303 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 32; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 2; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 2))][(v4 + (v2 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][4], + hls::stream v8[2][4], + float v9, + float v10 +) { + loop4: for (int v11 = 0; v11 < 16; v11++) { + loop5: for (int v12 = 0; v12 < 32; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 4; v13++) { + loop7: for (int v14 = 0; v14 < 2; v14++) { + float v15 = v7[v14][v13].read(); + bool v16 = v15 > v9; + float v17 = v16 ? (float)v15 : (float)v9; + float v18 = v17 / v10; + v8[v14][v13].write(v18); + } + } + } + } + return ; +} + +void node2( + hls::stream v19[2][4], + float v20[64][64], + hls::stream v21[2][4], + float v22 +) { + #pragma HLS array_partition variable=v20 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v20 cyclic dim=2 factor=4 + + float v23[64][64]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=4 + + float v24[64][64]; + #pragma HLS array_partition variable=v24 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v24 cyclic dim=2 factor=4 + + loop8: for (int v25 = 0; v25 < 16; v25++) { + loop9: for (int v26 = 0; v26 < 16; v26++) { + loop10: for (int v27 = 0; v27 < 32; v27++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v28 = 0; v28 < 4; v28++) { + loop12: for (int v29 = 0; v29 < 4; v29++) { + loop13: for (int v30 = 0; v30 < 2; v30++) { + if ((v29 + (v26 * 4)) == 0) { + float v31 = v19[v30][v28].read(); + v24[(v30 + (v27 * 2))][(v28 + (v25 * 4))] = v31; + } + float v32 = v24[(v30 + (v27 * 2))][(v28 + (v25 * 4))]; + float v33 = v20[(v28 + (v25 * 4))][(v29 + (v26 * 4))]; + if ((v28 + (v25 * 4)) == 0) { + v23[(v30 + (v27 * 2))][(v29 + (v26 * 4))] = v22; + } + float v34 = v23[(v30 + (v27 * 2))][(v29 + (v26 * 4))]; + float v35 = v32 * v33; + float v36 = v34 + v35; + v23[(v30 + (v27 * 2))][(v29 + (v26 * 4))] = v36; + if (((v28 + (v25 * 4)) - 63) == 0) { + float v37 = v23[(v30 + (v27 * 2))][(v29 + (v26 * 4))]; + v21[v30][v29].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v38[2][4], + hls::stream v39[2][4], + float v40 +) { + loop14: for (int v41 = 0; v41 < 16; v41++) { + loop15: for (int v42 = 0; v42 < 32; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v43 = 0; v43 < 4; v43++) { + loop17: for (int v44 = 0; v44 < 2; v44++) { + float v45 = v38[v44][v43].read(); + bool v46 = v45 > v40; + float v47 = v46 ? (float)v45 : (float)v40; + v39[v44][v43].write(v47); + } + } + } + } + return ; +} + +void node4( + float v48[64][64], + hls::stream v49[2][4], + hls::stream v50[2][4], + float v51 +) { + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=4 + + float v52[64][64]; + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v52 cyclic dim=2 factor=4 + + float v53[64][64]; + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=4 + + loop18: for (int v54 = 0; v54 < 16; v54++) { + loop19: for (int v55 = 0; v55 < 16; v55++) { + loop20: for (int v56 = 0; v56 < 32; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop21: for (int v57 = 0; v57 < 4; v57++) { + loop22: for (int v58 = 0; v58 < 4; v58++) { + loop23: for (int v59 = 0; v59 < 2; v59++) { + if ((v57 + (v54 * 4)) == 0) { + float v60 = v49[v59][v58].read(); + v53[(v59 + (v56 * 2))][(v58 + (v55 * 4))] = v60; + } + float v61 = v53[(v59 + (v56 * 2))][(v58 + (v55 * 4))]; + float v62 = v48[(v58 + (v55 * 4))][(v57 + (v54 * 4))]; + if ((v58 + (v55 * 4)) == 0) { + v52[(v59 + (v56 * 2))][(v57 + (v54 * 4))] = v51; + } + float v63 = v52[(v59 + (v56 * 2))][(v57 + (v54 * 4))]; + float v64 = v61 * v62; + float v65 = v63 + v64; + v52[(v59 + (v56 * 2))][(v57 + (v54 * 4))] = v65; + if (((v58 + (v55 * 4)) - 63) == 0) { + float v66 = v52[(v59 + (v56 * 2))][(v57 + (v54 * 4))]; + v50[v59][v57].write(v66); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v67[64][64], + hls::stream v68[2][4], + float v69 +) { + #pragma HLS array_partition variable=v67 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v67 cyclic dim=2 factor=4 + + loop24: for (int v70 = 0; v70 < 16; v70++) { + loop25: for (int v71 = 0; v71 < 32; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v72 = 0; v72 < 4; v72++) { + loop27: for (int v73 = 0; v73 < 2; v73++) { + float v74 = v67[(v73 + (v71 * 2))][(v72 + (v70 * 4))]; + bool v75 = v74 > v69; + float v76 = v75 ? (float)v74 : (float)v69; + v68[v73][v72].write(v76); + } + } + } + } + return ; +} + +void node6( + hls::stream v77[2][4], + float v78[64][64], + float v79[64][64], + float v80 +) { + #pragma HLS array_partition variable=v78 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v78 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v79 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v79 cyclic dim=2 factor=4 + + float v81[64][64]; + #pragma HLS array_partition variable=v81 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v81 cyclic dim=2 factor=4 + + float v82[64][64]; + #pragma HLS array_partition variable=v82 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v82 cyclic dim=2 factor=4 + + loop28: for (int v83 = 0; v83 < 32; v83++) { + loop29: for (int v84 = 0; v84 < 16; v84++) { + loop30: for (int v85 = 0; v85 < 16; v85++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v86 = 0; v86 < 2; v86++) { + loop32: for (int v87 = 0; v87 < 4; v87++) { + loop33: for (int v88 = 0; v88 < 4; v88++) { + if ((v88 + (v85 * 4)) == 0) { + float v89 = v77[v86][v87].read(); + v82[(v86 + (v83 * 2))][(v87 + (v84 * 4))] = v89; + } + float v90 = v82[(v86 + (v83 * 2))][(v87 + (v84 * 4))]; + float v91 = v78[(v87 + (v84 * 4))][(v88 + (v85 * 4))]; + if ((v87 + (v84 * 4)) == 0) { + v81[(v86 + (v83 * 2))][(v88 + (v85 * 4))] = v80; + } + float v92 = v81[(v86 + (v83 * 2))][(v88 + (v85 * 4))]; + float v93 = v90 * v91; + float v94 = v92 + v93; + v81[(v86 + (v83 * 2))][(v88 + (v85 * 4))] = v94; + if (((v87 + (v84 * 4)) - 63) == 0) { + float v95 = v81[(v86 + (v83 * 2))][(v88 + (v85 * 4))]; + v79[(v86 + (v83 * 2))][(v88 + (v85 * 4))] = v95; + } + } + } + } + } + } + } + return ; +} + +void node7( + hls::stream v96[2][4], + hls::stream v97[2][4], + float v98 +) { + loop34: for (int v99 = 0; v99 < 32; v99++) { + loop35: for (int v100 = 0; v100 < 16; v100++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop36: for (int v101 = 0; v101 < 2; v101++) { + loop37: for (int v102 = 0; v102 < 4; v102++) { + float v103 = v96[v101][v102].read(); + bool v104 = v103 > v98; + float v105 = v104 ? (float)v103 : (float)v98; + v97[v101][v102].write(v105); + } + } + } + } + return ; +} + +void node8( + hls::stream v106[2][4], + float v107[64][64], + hls::stream v108[2][4], + float v109 +) { + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + float v110[64][64]; + #pragma HLS array_partition variable=v110 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=4 + + float v111[64][64]; + #pragma HLS array_partition variable=v111 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v111 cyclic dim=2 factor=4 + + loop38: for (int v112 = 0; v112 < 32; v112++) { + loop39: for (int v113 = 0; v113 < 16; v113++) { + loop40: for (int v114 = 0; v114 < 16; v114++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v115 = 0; v115 < 2; v115++) { + loop42: for (int v116 = 0; v116 < 4; v116++) { + loop43: for (int v117 = 0; v117 < 4; v117++) { + if ((v117 + (v114 * 4)) == 0) { + float v118 = v106[v115][v116].read(); + v111[(v115 + (v112 * 2))][(v116 + (v113 * 4))] = v118; + } + float v119 = v111[(v115 + (v112 * 2))][(v116 + (v113 * 4))]; + float v120 = v107[(v116 + (v113 * 4))][(v117 + (v114 * 4))]; + if ((v116 + (v113 * 4)) == 0) { + v110[(v115 + (v112 * 2))][(v117 + (v114 * 4))] = v109; + } + float v121 = v110[(v115 + (v112 * 2))][(v117 + (v114 * 4))]; + float v122 = v119 * v120; + float v123 = v121 + v122; + v110[(v115 + (v112 * 2))][(v117 + (v114 * 4))] = v123; + if (((v116 + (v113 * 4)) - 63) == 0) { + float v124 = v110[(v115 + (v112 * 2))][(v117 + (v114 * 4))]; + v108[v115][v117].write(v124); + } + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v125[2][4], + hls::stream v126[2][4], + float v127 +) { + loop44: for (int v128 = 0; v128 < 32; v128++) { + loop45: for (int v129 = 0; v129 < 16; v129++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop46: for (int v130 = 0; v130 < 2; v130++) { + loop47: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v125[v130][v131].read(); + bool v133 = v132 > v127; + float v134 = v133 ? (float)v132 : (float)v127; + v126[v130][v131].write(v134); + } + } + } + } + return ; +} + +void node10( + float v135[64][64], + hls::stream v136[2][4], + hls::stream v137[2][4], + float v138 +) { + #pragma HLS array_partition variable=v135 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v135 cyclic dim=2 factor=4 + + float v139[64][64]; + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + float v140[64][64]; + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + loop48: for (int v141 = 0; v141 < 32; v141++) { + loop49: for (int v142 = 0; v142 < 16; v142++) { + loop50: for (int v143 = 0; v143 < 16; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v144 = 0; v144 < 2; v144++) { + loop52: for (int v145 = 0; v145 < 4; v145++) { + loop53: for (int v146 = 0; v146 < 4; v146++) { + if ((v146 + (v143 * 4)) == 0) { + float v147 = v136[v144][v145].read(); + v140[(v144 + (v141 * 2))][(v145 + (v142 * 4))] = v147; + } + float v148 = v140[(v144 + (v141 * 2))][(v145 + (v142 * 4))]; + float v149 = v135[(v145 + (v142 * 4))][(v146 + (v143 * 4))]; + if ((v145 + (v142 * 4)) == 0) { + v139[(v144 + (v141 * 2))][(v146 + (v143 * 4))] = v138; + } + float v150 = v139[(v144 + (v141 * 2))][(v146 + (v143 * 4))]; + float v151 = v148 * v149; + float v152 = v150 + v151; + v139[(v144 + (v141 * 2))][(v146 + (v143 * 4))] = v152; + if (((v145 + (v142 * 4)) - 63) == 0) { + float v153 = v139[(v144 + (v141 * 2))][(v146 + (v143 * 4))]; + v137[v144][v146].write(v153); + } + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v154[2][4], + hls::stream v155[2][4], + float v156 +) { + loop54: for (int v157 = 0; v157 < 32; v157++) { + loop55: for (int v158 = 0; v158 < 16; v158++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop56: for (int v159 = 0; v159 < 2; v159++) { + loop57: for (int v160 = 0; v160 < 4; v160++) { + float v161 = v154[v159][v160].read(); + bool v162 = v161 > v156; + float v163 = v162 ? (float)v161 : (float)v156; + v155[v159][v160].write(v163); + } + } + } + } + return ; +} + +void node12( + float v164[64][64], + hls::stream v165[2][4], + hls::stream v166[2][4], + float v167 +) { + #pragma HLS array_partition variable=v164 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=4 + + float v168[64][64]; + #pragma HLS array_partition variable=v168 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=4 + + float v169[64][64]; + #pragma HLS array_partition variable=v169 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=4 + + loop58: for (int v170 = 0; v170 < 32; v170++) { + loop59: for (int v171 = 0; v171 < 16; v171++) { + loop60: for (int v172 = 0; v172 < 16; v172++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop61: for (int v173 = 0; v173 < 2; v173++) { + loop62: for (int v174 = 0; v174 < 4; v174++) { + loop63: for (int v175 = 0; v175 < 4; v175++) { + if ((v175 + (v172 * 4)) == 0) { + float v176 = v165[v173][v174].read(); + v169[(v173 + (v170 * 2))][(v174 + (v171 * 4))] = v176; + } + float v177 = v169[(v173 + (v170 * 2))][(v174 + (v171 * 4))]; + float v178 = v164[(v174 + (v171 * 4))][(v175 + (v172 * 4))]; + if ((v174 + (v171 * 4)) == 0) { + v168[(v173 + (v170 * 2))][(v175 + (v172 * 4))] = v167; + } + float v179 = v168[(v173 + (v170 * 2))][(v175 + (v172 * 4))]; + float v180 = v177 * v178; + float v181 = v179 + v180; + v168[(v173 + (v170 * 2))][(v175 + (v172 * 4))] = v181; + if (((v174 + (v171 * 4)) - 63) == 0) { + float v182 = v168[(v173 + (v170 * 2))][(v175 + (v172 * 4))]; + v166[v173][v175].write(v182); + } + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v183[2][4], + hls::stream v184[2][4], + float v185 +) { + loop64: for (int v186 = 0; v186 < 32; v186++) { + loop65: for (int v187 = 0; v187 < 16; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop66: for (int v188 = 0; v188 < 2; v188++) { + loop67: for (int v189 = 0; v189 < 4; v189++) { + float v190 = v183[v188][v189].read(); + bool v191 = v190 > v185; + float v192 = v191 ? (float)v190 : (float)v185; + v184[v188][v189].write(v192); + } + } + } + } + return ; +} + +void node14( + float v193[64][64], + hls::stream v194[2][4], + hls::stream v195[2][4], + float v196 +) { + #pragma HLS array_partition variable=v193 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v193 cyclic dim=2 factor=4 + + float v197[64][64]; + #pragma HLS array_partition variable=v197 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v197 cyclic dim=2 factor=4 + + float v198[64][64]; + #pragma HLS array_partition variable=v198 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v198 cyclic dim=2 factor=4 + + loop68: for (int v199 = 0; v199 < 32; v199++) { + loop69: for (int v200 = 0; v200 < 16; v200++) { + loop70: for (int v201 = 0; v201 < 16; v201++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v202 = 0; v202 < 2; v202++) { + loop72: for (int v203 = 0; v203 < 4; v203++) { + loop73: for (int v204 = 0; v204 < 4; v204++) { + if ((v204 + (v201 * 4)) == 0) { + float v205 = v194[v202][v203].read(); + v198[(v202 + (v199 * 2))][(v203 + (v200 * 4))] = v205; + } + float v206 = v198[(v202 + (v199 * 2))][(v203 + (v200 * 4))]; + float v207 = v193[(v203 + (v200 * 4))][(v204 + (v201 * 4))]; + if ((v203 + (v200 * 4)) == 0) { + v197[(v202 + (v199 * 2))][(v204 + (v201 * 4))] = v196; + } + float v208 = v197[(v202 + (v199 * 2))][(v204 + (v201 * 4))]; + float v209 = v206 * v207; + float v210 = v208 + v209; + v197[(v202 + (v199 * 2))][(v204 + (v201 * 4))] = v210; + if (((v203 + (v200 * 4)) - 63) == 0) { + float v211 = v197[(v202 + (v199 * 2))][(v204 + (v201 * 4))]; + v195[v202][v204].write(v211); + } + } + } + } + } + } + } + return ; +} + +void node15( + hls::stream v212[2][4], + hls::stream v213[2][4], + float v214 +) { + loop74: for (int v215 = 0; v215 < 32; v215++) { + loop75: for (int v216 = 0; v216 < 16; v216++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v217 = 0; v217 < 2; v217++) { + loop77: for (int v218 = 0; v218 < 4; v218++) { + float v219 = v212[v217][v218].read(); + bool v220 = v219 > v214; + float v221 = v220 ? (float)v219 : (float)v214; + v213[v217][v218].write(v221); + } + } + } + } + return ; +} + +void node16( + float v222[64][64], + hls::stream v223[2][4], + hls::stream v224[2][4], + float v225 +) { + #pragma HLS array_partition variable=v222 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v222 cyclic dim=2 factor=4 + + float v226[64][64]; + #pragma HLS array_partition variable=v226 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v226 cyclic dim=2 factor=4 + + float v227[64][64]; + #pragma HLS array_partition variable=v227 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v227 cyclic dim=2 factor=4 + + loop78: for (int v228 = 0; v228 < 32; v228++) { + loop79: for (int v229 = 0; v229 < 16; v229++) { + loop80: for (int v230 = 0; v230 < 16; v230++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v231 = 0; v231 < 2; v231++) { + loop82: for (int v232 = 0; v232 < 4; v232++) { + loop83: for (int v233 = 0; v233 < 4; v233++) { + if ((v233 + (v230 * 4)) == 0) { + float v234 = v223[v231][v232].read(); + v227[(v231 + (v228 * 2))][(v232 + (v229 * 4))] = v234; + } + float v235 = v227[(v231 + (v228 * 2))][(v232 + (v229 * 4))]; + float v236 = v222[(v232 + (v229 * 4))][(v233 + (v230 * 4))]; + if ((v232 + (v229 * 4)) == 0) { + v226[(v231 + (v228 * 2))][(v233 + (v230 * 4))] = v225; + } + float v237 = v226[(v231 + (v228 * 2))][(v233 + (v230 * 4))]; + float v238 = v235 * v236; + float v239 = v237 + v238; + v226[(v231 + (v228 * 2))][(v233 + (v230 * 4))] = v239; + if (((v232 + (v229 * 4)) - 63) == 0) { + float v240 = v226[(v231 + (v228 * 2))][(v233 + (v230 * 4))]; + v224[v231][v233].write(v240); + } + } + } + } + } + } + } + return ; +} + +void node17( + hls::stream v241[2][4], + hls::stream v242[2][4], + float v243 +) { + loop84: for (int v244 = 0; v244 < 32; v244++) { + loop85: for (int v245 = 0; v245 < 16; v245++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v246 = 0; v246 < 2; v246++) { + loop87: for (int v247 = 0; v247 < 4; v247++) { + float v248 = v241[v246][v247].read(); + bool v249 = v248 > v243; + float v250 = v249 ? (float)v248 : (float)v243; + v242[v246][v247].write(v250); + } + } + } + } + return ; +} + +void node18( + hls::stream v251[2][4], + float v252[64][64], + hls::stream v253[2][4], + float v254 +) { + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=4 + + float v255[64][64]; + #pragma HLS array_partition variable=v255 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v255 cyclic dim=2 factor=4 + + float v256[64][64]; + #pragma HLS array_partition variable=v256 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v256 cyclic dim=2 factor=4 + + loop88: for (int v257 = 0; v257 < 32; v257++) { + loop89: for (int v258 = 0; v258 < 16; v258++) { + loop90: for (int v259 = 0; v259 < 16; v259++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop91: for (int v260 = 0; v260 < 2; v260++) { + loop92: for (int v261 = 0; v261 < 4; v261++) { + loop93: for (int v262 = 0; v262 < 4; v262++) { + if ((v262 + (v259 * 4)) == 0) { + float v263 = v251[v260][v261].read(); + v256[(v260 + (v257 * 2))][(v261 + (v258 * 4))] = v263; + } + float v264 = v256[(v260 + (v257 * 2))][(v261 + (v258 * 4))]; + float v265 = v252[(v261 + (v258 * 4))][(v262 + (v259 * 4))]; + if ((v261 + (v258 * 4)) == 0) { + v255[(v260 + (v257 * 2))][(v262 + (v259 * 4))] = v254; + } + float v266 = v255[(v260 + (v257 * 2))][(v262 + (v259 * 4))]; + float v267 = v264 * v265; + float v268 = v266 + v267; + v255[(v260 + (v257 * 2))][(v262 + (v259 * 4))] = v268; + if (((v261 + (v258 * 4)) - 63) == 0) { + float v269 = v255[(v260 + (v257 * 2))][(v262 + (v259 * 4))]; + v253[v260][v262].write(v269); + } + } + } + } + } + } + } + return ; +} + +void node19( + hls::stream v270[2][4], + hls::stream v271[2][4], + float v272 +) { + loop94: for (int v273 = 0; v273 < 32; v273++) { + loop95: for (int v274 = 0; v274 < 16; v274++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop96: for (int v275 = 0; v275 < 2; v275++) { + loop97: for (int v276 = 0; v276 < 4; v276++) { + float v277 = v270[v275][v276].read(); + bool v278 = v277 > v272; + float v279 = v278 ? (float)v277 : (float)v272; + v271[v275][v276].write(v279); + } + } + } + } + return ; +} + +void node20( + float v280[64][64], + hls::stream v281[2][4], + hls::stream v282[2][4], + float v283 +) { + #pragma HLS array_partition variable=v280 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v280 cyclic dim=2 factor=4 + + float v284[64][64]; + #pragma HLS array_partition variable=v284 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v284 cyclic dim=2 factor=4 + + float v285[64][64]; + #pragma HLS array_partition variable=v285 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v285 cyclic dim=2 factor=4 + + loop98: for (int v286 = 0; v286 < 32; v286++) { + loop99: for (int v287 = 0; v287 < 16; v287++) { + loop100: for (int v288 = 0; v288 < 16; v288++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop101: for (int v289 = 0; v289 < 2; v289++) { + loop102: for (int v290 = 0; v290 < 4; v290++) { + loop103: for (int v291 = 0; v291 < 4; v291++) { + if ((v291 + (v288 * 4)) == 0) { + float v292 = v281[v289][v290].read(); + v285[(v289 + (v286 * 2))][(v290 + (v287 * 4))] = v292; + } + float v293 = v285[(v289 + (v286 * 2))][(v290 + (v287 * 4))]; + float v294 = v280[(v290 + (v287 * 4))][(v291 + (v288 * 4))]; + if ((v290 + (v287 * 4)) == 0) { + v284[(v289 + (v286 * 2))][(v291 + (v288 * 4))] = v283; + } + float v295 = v284[(v289 + (v286 * 2))][(v291 + (v288 * 4))]; + float v296 = v293 * v294; + float v297 = v295 + v296; + v284[(v289 + (v286 * 2))][(v291 + (v288 * 4))] = v297; + if (((v290 + (v287 * 4)) - 63) == 0) { + float v298 = v284[(v289 + (v286 * 2))][(v291 + (v288 * 4))]; + v282[v289][v291].write(v298); + } + } + } + } + } + } + } + return ; +} + +void node21( + hls::stream v299[2][4], + hls::stream v300[2][4], + float v301 +) { + loop104: for (int v302 = 0; v302 < 32; v302++) { + loop105: for (int v303 = 0; v303 < 16; v303++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop106: for (int v304 = 0; v304 < 2; v304++) { + loop107: for (int v305 = 0; v305 < 4; v305++) { + float v306 = v299[v304][v305].read(); + bool v307 = v306 > v301; + float v308 = v307 ? (float)v306 : (float)v301; + v300[v304][v305].write(v308); + } + } + } + } + return ; +} + +void node22( + hls::stream v309[2][4], + float v310[64][64], + hls::stream v311[2][4], + float v312 +) { + #pragma HLS array_partition variable=v310 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v310 cyclic dim=2 factor=4 + + float v313[64][64]; + #pragma HLS array_partition variable=v313 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v313 cyclic dim=2 factor=4 + + float v314[64][64]; + #pragma HLS array_partition variable=v314 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v314 cyclic dim=2 factor=4 + + loop108: for (int v315 = 0; v315 < 32; v315++) { + loop109: for (int v316 = 0; v316 < 16; v316++) { + loop110: for (int v317 = 0; v317 < 16; v317++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop111: for (int v318 = 0; v318 < 2; v318++) { + loop112: for (int v319 = 0; v319 < 4; v319++) { + loop113: for (int v320 = 0; v320 < 4; v320++) { + if ((v320 + (v317 * 4)) == 0) { + float v321 = v309[v318][v319].read(); + v314[(v318 + (v315 * 2))][(v319 + (v316 * 4))] = v321; + } + float v322 = v314[(v318 + (v315 * 2))][(v319 + (v316 * 4))]; + float v323 = v310[(v319 + (v316 * 4))][(v320 + (v317 * 4))]; + if ((v319 + (v316 * 4)) == 0) { + v313[(v318 + (v315 * 2))][(v320 + (v317 * 4))] = v312; + } + float v324 = v313[(v318 + (v315 * 2))][(v320 + (v317 * 4))]; + float v325 = v322 * v323; + float v326 = v324 + v325; + v313[(v318 + (v315 * 2))][(v320 + (v317 * 4))] = v326; + if (((v319 + (v316 * 4)) - 63) == 0) { + float v327 = v313[(v318 + (v315 * 2))][(v320 + (v317 * 4))]; + v311[v318][v320].write(v327); + } + } + } + } + } + } + } + return ; +} + +void node23( + hls::stream v328[2][4], + hls::stream v329[2][4], + float v330 +) { + loop114: for (int v331 = 0; v331 < 32; v331++) { + loop115: for (int v332 = 0; v332 < 16; v332++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop116: for (int v333 = 0; v333 < 2; v333++) { + loop117: for (int v334 = 0; v334 < 4; v334++) { + float v335 = v328[v333][v334].read(); + bool v336 = v335 > v330; + float v337 = v336 ? (float)v335 : (float)v330; + v329[v333][v334].write(v337); + } + } + } + } + return ; +} + +void node24( + float v338[64][64], + hls::stream v339[2][4], + hls::stream v340[2][4], + float v341 +) { + #pragma HLS array_partition variable=v338 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v338 cyclic dim=2 factor=4 + + float v342[64][64]; + #pragma HLS array_partition variable=v342 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=4 + + float v343[64][64]; + #pragma HLS array_partition variable=v343 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=4 + + loop118: for (int v344 = 0; v344 < 32; v344++) { + loop119: for (int v345 = 0; v345 < 16; v345++) { + loop120: for (int v346 = 0; v346 < 16; v346++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop121: for (int v347 = 0; v347 < 2; v347++) { + loop122: for (int v348 = 0; v348 < 4; v348++) { + loop123: for (int v349 = 0; v349 < 4; v349++) { + if ((v349 + (v346 * 4)) == 0) { + float v350 = v339[v347][v348].read(); + v343[(v347 + (v344 * 2))][(v348 + (v345 * 4))] = v350; + } + float v351 = v343[(v347 + (v344 * 2))][(v348 + (v345 * 4))]; + float v352 = v338[(v348 + (v345 * 4))][(v349 + (v346 * 4))]; + if ((v348 + (v345 * 4)) == 0) { + v342[(v347 + (v344 * 2))][(v349 + (v346 * 4))] = v341; + } + float v353 = v342[(v347 + (v344 * 2))][(v349 + (v346 * 4))]; + float v354 = v351 * v352; + float v355 = v353 + v354; + v342[(v347 + (v344 * 2))][(v349 + (v346 * 4))] = v355; + if (((v348 + (v345 * 4)) - 63) == 0) { + float v356 = v342[(v347 + (v344 * 2))][(v349 + (v346 * 4))]; + v340[v347][v349].write(v356); + } + } + } + } + } + } + } + return ; +} + +void node25( + hls::stream v357[2][4], + hls::stream v358[2][4], + float v359 +) { + loop124: for (int v360 = 0; v360 < 32; v360++) { + loop125: for (int v361 = 0; v361 < 16; v361++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop126: for (int v362 = 0; v362 < 2; v362++) { + loop127: for (int v363 = 0; v363 < 4; v363++) { + float v364 = v357[v362][v363].read(); + bool v365 = v364 > v359; + float v366 = v365 ? (float)v364 : (float)v359; + v358[v362][v363].write(v366); + } + } + } + } + return ; +} + +void node26( + float v367[64][64], + hls::stream v368[2][4], + hls::stream v369[2][4], + float v370 +) { + #pragma HLS array_partition variable=v367 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v367 cyclic dim=2 factor=4 + + float v371[64][64]; + #pragma HLS array_partition variable=v371 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v371 cyclic dim=2 factor=4 + + float v372[64][64]; + #pragma HLS array_partition variable=v372 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v372 cyclic dim=2 factor=4 + + loop128: for (int v373 = 0; v373 < 32; v373++) { + loop129: for (int v374 = 0; v374 < 16; v374++) { + loop130: for (int v375 = 0; v375 < 16; v375++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop131: for (int v376 = 0; v376 < 2; v376++) { + loop132: for (int v377 = 0; v377 < 4; v377++) { + loop133: for (int v378 = 0; v378 < 4; v378++) { + if ((v378 + (v375 * 4)) == 0) { + float v379 = v368[v376][v377].read(); + v372[(v376 + (v373 * 2))][(v377 + (v374 * 4))] = v379; + } + float v380 = v372[(v376 + (v373 * 2))][(v377 + (v374 * 4))]; + float v381 = v367[(v377 + (v374 * 4))][(v378 + (v375 * 4))]; + if ((v377 + (v374 * 4)) == 0) { + v371[(v376 + (v373 * 2))][(v378 + (v375 * 4))] = v370; + } + float v382 = v371[(v376 + (v373 * 2))][(v378 + (v375 * 4))]; + float v383 = v380 * v381; + float v384 = v382 + v383; + v371[(v376 + (v373 * 2))][(v378 + (v375 * 4))] = v384; + if (((v377 + (v374 * 4)) - 63) == 0) { + float v385 = v371[(v376 + (v373 * 2))][(v378 + (v375 * 4))]; + v369[v376][v378].write(v385); + } + } + } + } + } + } + } + return ; +} + +void node27( + hls::stream v386[2][4], + hls::stream v387[2][4], + float v388 +) { + loop134: for (int v389 = 0; v389 < 32; v389++) { + loop135: for (int v390 = 0; v390 < 16; v390++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v391 = 0; v391 < 2; v391++) { + loop137: for (int v392 = 0; v392 < 4; v392++) { + float v393 = v386[v391][v392].read(); + bool v394 = v393 > v388; + float v395 = v394 ? (float)v393 : (float)v388; + v387[v391][v392].write(v395); + } + } + } + } + return ; +} + +void node28( + float v396[64][64], + hls::stream v397[2][4], + hls::stream v398[2][4], + float v399 +) { + #pragma HLS array_partition variable=v396 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v396 cyclic dim=2 factor=4 + + float v400[64][64]; + #pragma HLS array_partition variable=v400 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v400 cyclic dim=2 factor=4 + + float v401[64][64]; + #pragma HLS array_partition variable=v401 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v401 cyclic dim=2 factor=4 + + loop138: for (int v402 = 0; v402 < 16; v402++) { + loop139: for (int v403 = 0; v403 < 32; v403++) { + loop140: for (int v404 = 0; v404 < 16; v404++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop141: for (int v405 = 0; v405 < 4; v405++) { + loop142: for (int v406 = 0; v406 < 2; v406++) { + loop143: for (int v407 = 0; v407 < 4; v407++) { + if ((v407 + (v404 * 4)) == 0) { + float v408 = v397[v406][v405].read(); + v401[(v406 + (v403 * 2))][(v405 + (v402 * 4))] = v408; + } + float v409 = v401[(v406 + (v403 * 2))][(v405 + (v402 * 4))]; + float v410 = v396[(v405 + (v402 * 4))][(v407 + (v404 * 4))]; + if ((v405 + (v402 * 4)) == 0) { + v400[(v406 + (v403 * 2))][(v407 + (v404 * 4))] = v399; + } + float v411 = v400[(v406 + (v403 * 2))][(v407 + (v404 * 4))]; + float v412 = v409 * v410; + float v413 = v411 + v412; + v400[(v406 + (v403 * 2))][(v407 + (v404 * 4))] = v413; + if (((v405 + (v402 * 4)) - 63) == 0) { + float v414 = v400[(v406 + (v403 * 2))][(v407 + (v404 * 4))]; + v398[v406][v407].write(v414); + } + } + } + } + } + } + } + return ; +} + +void node29( + hls::stream v415[2][4], + hls::stream v416[2][4], + float v417 +) { + loop144: for (int v418 = 0; v418 < 16; v418++) { + loop145: for (int v419 = 0; v419 < 32; v419++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop146: for (int v420 = 0; v420 < 4; v420++) { + loop147: for (int v421 = 0; v421 < 2; v421++) { + float v422 = v415[v421][v420].read(); + bool v423 = v422 > v417; + float v424 = v423 ? (float)v422 : (float)v417; + v416[v421][v420].write(v424); + } + } + } + } + return ; +} + +void node30( + float v425[64][64], + float v426[64][64], + hls::stream v427[2][4], + float v428 +) { + #pragma HLS array_partition variable=v425 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v425 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v426 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v426 cyclic dim=2 factor=4 + + float v429[64][64]; + #pragma HLS array_partition variable=v429 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v429 cyclic dim=2 factor=4 + + loop148: for (int v430 = 0; v430 < 16; v430++) { + loop149: for (int v431 = 0; v431 < 16; v431++) { + loop150: for (int v432 = 0; v432 < 32; v432++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop151: for (int v433 = 0; v433 < 4; v433++) { + loop152: for (int v434 = 0; v434 < 4; v434++) { + loop153: for (int v435 = 0; v435 < 2; v435++) { + float v436 = v426[(v435 + (v432 * 2))][(v434 + (v431 * 4))]; + float v437 = v425[(v434 + (v431 * 4))][(v433 + (v430 * 4))]; + if ((v434 + (v431 * 4)) == 0) { + v429[(v435 + (v432 * 2))][(v433 + (v430 * 4))] = v428; + } + float v438 = v429[(v435 + (v432 * 2))][(v433 + (v430 * 4))]; + float v439 = v436 * v437; + float v440 = v438 + v439; + v429[(v435 + (v432 * 2))][(v433 + (v430 * 4))] = v440; + if (((v434 + (v431 * 4)) - 63) == 0) { + float v441 = v429[(v435 + (v432 * 2))][(v433 + (v430 * 4))]; + v427[v435][v433].write(v441); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v442[64][64], + float v443[64][64], + float v444[64][64], + float v445[64][64], + float v446[64][64], + float v447[64][64], + float v448[64][64], + float v449[64][64], + float v450[64][64], + float v451[64][64], + float v452[64][64], + float v453[64][64], + float v454[64][64], + float v455[64][64], + float v456[64][64], + float v457[64][64], + float v458[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v442 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v442 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v443 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v443 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v444 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v444 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v445 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v445 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v446 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v446 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v447 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v447 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v448 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v448 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v449 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v449 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v450 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v450 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v451 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v451 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v452 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v452 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v453 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v453 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v454 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v454 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v455 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v455 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v456 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v456 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v457 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v457 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v458 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v458 cyclic dim=2 factor=4 + + hls::stream v459[2][4]; + #pragma HLS STREAM variable=v459 depth=512 + hls::stream v460[2][4]; + #pragma HLS STREAM variable=v460 depth=512 + hls::stream v461[2][4]; + #pragma HLS STREAM variable=v461 depth=512 + hls::stream v462[2][4]; + #pragma HLS STREAM variable=v462 depth=512 + hls::stream v463[2][4]; + #pragma HLS STREAM variable=v463 depth=512 + float v464[64][64]; + #pragma HLS array_partition variable=v464 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v464 cyclic dim=2 factor=4 + + hls::stream v465[2][4]; + #pragma HLS STREAM variable=v465 depth=512 + hls::stream v466[2][4]; + #pragma HLS STREAM variable=v466 depth=512 + hls::stream v467[2][4]; + #pragma HLS STREAM variable=v467 depth=512 + hls::stream v468[2][4]; + #pragma HLS STREAM variable=v468 depth=512 + hls::stream v469[2][4]; + #pragma HLS STREAM variable=v469 depth=512 + hls::stream v470[2][4]; + #pragma HLS STREAM variable=v470 depth=512 + hls::stream v471[2][4]; + #pragma HLS STREAM variable=v471 depth=512 + hls::stream v472[2][4]; + #pragma HLS STREAM variable=v472 depth=512 + hls::stream v473[2][4]; + #pragma HLS STREAM variable=v473 depth=512 + hls::stream v474[2][4]; + #pragma HLS STREAM variable=v474 depth=512 + hls::stream v475[2][4]; + #pragma HLS STREAM variable=v475 depth=512 + hls::stream v476[2][4]; + #pragma HLS STREAM variable=v476 depth=512 + hls::stream v477[2][4]; + #pragma HLS STREAM variable=v477 depth=512 + hls::stream v478[2][4]; + #pragma HLS STREAM variable=v478 depth=512 + hls::stream v479[2][4]; + #pragma HLS STREAM variable=v479 depth=512 + hls::stream v480[2][4]; + #pragma HLS STREAM variable=v480 depth=512 + hls::stream v481[2][4]; + #pragma HLS STREAM variable=v481 depth=512 + hls::stream v482[2][4]; + #pragma HLS STREAM variable=v482 depth=512 + hls::stream v483[2][4]; + #pragma HLS STREAM variable=v483 depth=512 + hls::stream v484[2][4]; + #pragma HLS STREAM variable=v484 depth=512 + hls::stream v485[2][4]; + #pragma HLS STREAM variable=v485 depth=512 + hls::stream v486[2][4]; + #pragma HLS STREAM variable=v486 depth=512 + hls::stream v487[2][4]; + #pragma HLS STREAM variable=v487 depth=512 + hls::stream v488[2][4]; + #pragma HLS STREAM variable=v488 depth=512 + node30(v443, v442, v488, 0.000000); + node29(v488, v487, 0.000000); + node28(v444, v487, v486, 0.000000); + node27(v486, v485, 0.000000); + node26(v445, v485, v484, 0.000000); + node25(v484, v483, 0.000000); + node24(v446, v483, v482, 0.000000); + node23(v482, v481, 0.000000); + node22(v481, v447, v480, 0.000000); + node21(v480, v479, 0.000000); + node20(v448, v479, v478, 0.000000); + node19(v478, v477, 0.000000); + node18(v477, v449, v476, 0.000000); + node17(v476, v475, 0.000000); + node16(v450, v475, v474, 0.000000); + node15(v474, v473, 0.000000); + node14(v451, v473, v472, 0.000000); + node13(v472, v471, 0.000000); + node12(v452, v471, v470, 0.000000); + node11(v470, v469, 0.000000); + node10(v453, v469, v468, 0.000000); + node9(v468, v467, 0.000000); + node8(v467, v454, v466, 0.000000); + node7(v466, v465, 0.000000); + node6(v465, v455, v464, 0.000000); + node5(v464, v463, 0.000000); + node4(v456, v463, v462, 0.000000); + node3(v462, v461, 0.000000); + node2(v461, v457, v460, 0.000000); + node1(v460, v459, 0.000000, 1000000.000000); + node0(v459, v458); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu_imbalanced__opt5/src/k15mmseq_relu_imbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu_imbalanced__opt5/src/k15mmseq_relu_imbalanced.cpp new file mode 100644 index 000000000000..372d2f71861b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmseq_relu_imbalanced__opt5/src/k15mmseq_relu_imbalanced.cpp @@ -0,0 +1,1226 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[16][16] +) { + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v2 + v4)][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[1][1], + hls::stream v8[1][1], + float v9, + float v10 +) { + loop4: for (int v11 = 0; v11 < 16; v11++) { + loop5: for (int v12 = 0; v12 < 16; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 1; v13++) { + loop7: for (int v14 = 0; v14 < 1; v14++) { + float v15 = v7[v13][v14].read(); + bool v16 = v15 > v9; + float v17 = v16 ? (float)v15 : (float)v9; + float v18 = v17 / v10; + v8[v13][v14].write(v18); + } + } + } + } + return ; +} + +void node2( + float v19[16][16], + hls::stream v20[1][1], + hls::stream v21[1][1], + float v22 +) { + float v23[16][16]; + float v24[16][16]; + loop8: for (int v25 = 0; v25 < 16; v25++) { + loop9: for (int v26 = 0; v26 < 16; v26++) { + loop10: for (int v27 = 0; v27 < 16; v27++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v28 = 0; v28 < 1; v28++) { + loop12: for (int v29 = 0; v29 < 1; v29++) { + loop13: for (int v30 = 0; v30 < 1; v30++) { + if ((v27 + v30) == 0) { + float v31 = v20[v28][v29].read(); + v24[(v25 + v28)][(v26 + v29)] = v31; + } + float v32 = v24[(v25 + v28)][(v26 + v29)]; + float v33 = v19[(v26 + v29)][(v27 + v30)]; + if ((v26 + v29) == 0) { + v23[(v25 + v28)][(v27 + v30)] = v22; + } + float v34 = v23[(v25 + v28)][(v27 + v30)]; + float v35 = v32 * v33; + float v36 = v34 + v35; + v23[(v25 + v28)][(v27 + v30)] = v36; + if (((v26 + v29) - 15) == 0) { + float v37 = v23[(v25 + v28)][(v27 + v30)]; + v21[v28][v30].write(v37); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v38[1][1], + hls::stream v39[1][1], + float v40 +) { + loop14: for (int v41 = 0; v41 < 16; v41++) { + loop15: for (int v42 = 0; v42 < 16; v42++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v43 = 0; v43 < 1; v43++) { + loop17: for (int v44 = 0; v44 < 1; v44++) { + float v45 = v38[v43][v44].read(); + bool v46 = v45 > v40; + float v47 = v46 ? (float)v45 : (float)v40; + v39[v43][v44].write(v47); + } + } + } + } + return ; +} + +void node4( + hls::stream v48[1][2], + float v49[32][16], + hls::stream v50[1][1], + float v51 +) { + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=2 + + float v52[16][16]; + float v53[16][32]; + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=2 + + loop18: for (int v54 = 0; v54 < 16; v54++) { + loop19: for (int v55 = 0; v55 < 16; v55++) { + loop20: for (int v56 = 0; v56 < 16; v56++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop21: for (int v57 = 0; v57 < 1; v57++) { + loop22: for (int v58 = 0; v58 < 2; v58++) { + loop23: for (int v59 = 0; v59 < 1; v59++) { + if ((v56 + v59) == 0) { + float v60 = v48[v57][v58].read(); + v53[(v54 + v57)][(v58 + (v55 * 2))] = v60; + } + float v61 = v53[(v54 + v57)][(v58 + (v55 * 2))]; + float v62 = v49[(v58 + (v55 * 2))][(v56 + v59)]; + if ((v58 + (v55 * 2)) == 0) { + v52[(v54 + v57)][(v56 + v59)] = v51; + } + float v63 = v52[(v54 + v57)][(v56 + v59)]; + float v64 = v61 * v62; + float v65 = v63 + v64; + v52[(v54 + v57)][(v56 + v59)] = v65; + if (((v58 + (v55 * 2)) - 31) == 0) { + float v66 = v52[(v54 + v57)][(v56 + v59)]; + v50[v57][v59].write(v66); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v67[1][2], + hls::stream v68[1][2], + float v69 +) { + loop24: for (int v70 = 0; v70 < 16; v70++) { + loop25: for (int v71 = 0; v71 < 16; v71++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v72 = 0; v72 < 1; v72++) { + loop27: for (int v73 = 0; v73 < 2; v73++) { + float v74 = v67[v72][v73].read(); + bool v75 = v74 > v69; + float v76 = v75 ? (float)v74 : (float)v69; + v68[v72][v73].write(v76); + } + } + } + } + return ; +} + +void node6( + float v77[64][32], + hls::stream v78[1][4], + hls::stream v79[1][2], + float v80 +) { + #pragma HLS array_partition variable=v77 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v77 cyclic dim=2 factor=2 + + float v81[16][32]; + #pragma HLS array_partition variable=v81 cyclic dim=2 factor=2 + + float v82[16][64]; + #pragma HLS array_partition variable=v82 cyclic dim=2 factor=4 + + loop28: for (int v83 = 0; v83 < 16; v83++) { + loop29: for (int v84 = 0; v84 < 16; v84++) { + loop30: for (int v85 = 0; v85 < 16; v85++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v86 = 0; v86 < 1; v86++) { + loop32: for (int v87 = 0; v87 < 4; v87++) { + loop33: for (int v88 = 0; v88 < 2; v88++) { + if ((v88 + (v85 * 2)) == 0) { + float v89 = v78[v86][v87].read(); + v82[(v83 + v86)][(v87 + (v84 * 4))] = v89; + } + float v90 = v82[(v83 + v86)][(v87 + (v84 * 4))]; + float v91 = v77[(v87 + (v84 * 4))][(v88 + (v85 * 2))]; + if ((v87 + (v84 * 4)) == 0) { + v81[(v83 + v86)][(v88 + (v85 * 2))] = v80; + } + float v92 = v81[(v83 + v86)][(v88 + (v85 * 2))]; + float v93 = v90 * v91; + float v94 = v92 + v93; + v81[(v83 + v86)][(v88 + (v85 * 2))] = v94; + if (((v87 + (v84 * 4)) - 63) == 0) { + float v95 = v81[(v83 + v86)][(v88 + (v85 * 2))]; + v79[v86][v88].write(v95); + } + } + } + } + } + } + } + return ; +} + +void node7( + hls::stream v96[1][4], + hls::stream v97[1][4], + float v98 +) { + loop34: for (int v99 = 0; v99 < 16; v99++) { + loop35: for (int v100 = 0; v100 < 16; v100++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop36: for (int v101 = 0; v101 < 1; v101++) { + loop37: for (int v102 = 0; v102 < 4; v102++) { + float v103 = v96[v101][v102].read(); + bool v104 = v103 > v98; + float v105 = v104 ? (float)v103 : (float)v98; + v97[v101][v102].write(v105); + } + } + } + } + return ; +} + +void node8( + hls::stream v106[1][8], + float v107[128][64], + hls::stream v108[1][4], + float v109 +) { + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + float v110[16][64]; + #pragma HLS array_partition variable=v110 cyclic dim=2 factor=4 + + float v111[16][128]; + #pragma HLS array_partition variable=v111 cyclic dim=2 factor=8 + + loop38: for (int v112 = 0; v112 < 16; v112++) { + loop39: for (int v113 = 0; v113 < 16; v113++) { + loop40: for (int v114 = 0; v114 < 16; v114++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v115 = 0; v115 < 1; v115++) { + loop42: for (int v116 = 0; v116 < 8; v116++) { + loop43: for (int v117 = 0; v117 < 4; v117++) { + if ((v117 + (v114 * 4)) == 0) { + float v118 = v106[v115][v116].read(); + v111[(v112 + v115)][(v116 + (v113 * 8))] = v118; + } + float v119 = v111[(v112 + v115)][(v116 + (v113 * 8))]; + float v120 = v107[(v116 + (v113 * 8))][(v117 + (v114 * 4))]; + if ((v116 + (v113 * 8)) == 0) { + v110[(v112 + v115)][(v117 + (v114 * 4))] = v109; + } + float v121 = v110[(v112 + v115)][(v117 + (v114 * 4))]; + float v122 = v119 * v120; + float v123 = v121 + v122; + v110[(v112 + v115)][(v117 + (v114 * 4))] = v123; + if (((v116 + (v113 * 8)) - 127) == 0) { + float v124 = v110[(v112 + v115)][(v117 + (v114 * 4))]; + v108[v115][v117].write(v124); + } + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v125[1][8], + hls::stream v126[1][8], + float v127 +) { + loop44: for (int v128 = 0; v128 < 16; v128++) { + loop45: for (int v129 = 0; v129 < 16; v129++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop46: for (int v130 = 0; v130 < 1; v130++) { + loop47: for (int v131 = 0; v131 < 8; v131++) { + float v132 = v125[v130][v131].read(); + bool v133 = v132 > v127; + float v134 = v133 ? (float)v132 : (float)v127; + v126[v130][v131].write(v134); + } + } + } + } + return ; +} + +void node10( + hls::stream v135[1][4], + float v136[64][128], + hls::stream v137[1][8], + float v138 +) { + #pragma HLS array_partition variable=v136 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v136 cyclic dim=2 factor=8 + + float v139[16][128]; + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=8 + + float v140[16][64]; + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + loop48: for (int v141 = 0; v141 < 16; v141++) { + loop49: for (int v142 = 0; v142 < 16; v142++) { + loop50: for (int v143 = 0; v143 < 16; v143++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v144 = 0; v144 < 1; v144++) { + loop52: for (int v145 = 0; v145 < 4; v145++) { + loop53: for (int v146 = 0; v146 < 8; v146++) { + if ((v146 + (v143 * 8)) == 0) { + float v147 = v135[v144][v145].read(); + v140[(v141 + v144)][(v145 + (v142 * 4))] = v147; + } + float v148 = v140[(v141 + v144)][(v145 + (v142 * 4))]; + float v149 = v136[(v145 + (v142 * 4))][(v146 + (v143 * 8))]; + if ((v145 + (v142 * 4)) == 0) { + v139[(v141 + v144)][(v146 + (v143 * 8))] = v138; + } + float v150 = v139[(v141 + v144)][(v146 + (v143 * 8))]; + float v151 = v148 * v149; + float v152 = v150 + v151; + v139[(v141 + v144)][(v146 + (v143 * 8))] = v152; + if (((v145 + (v142 * 4)) - 63) == 0) { + float v153 = v139[(v141 + v144)][(v146 + (v143 * 8))]; + v137[v144][v146].write(v153); + } + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v154[1][4], + hls::stream v155[1][4], + float v156 +) { + loop54: for (int v157 = 0; v157 < 16; v157++) { + loop55: for (int v158 = 0; v158 < 16; v158++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop56: for (int v159 = 0; v159 < 1; v159++) { + loop57: for (int v160 = 0; v160 < 4; v160++) { + float v161 = v154[v159][v160].read(); + bool v162 = v161 > v156; + float v163 = v162 ? (float)v161 : (float)v156; + v155[v159][v160].write(v163); + } + } + } + } + return ; +} + +void node12( + float v164[128][64], + hls::stream v165[1][8], + hls::stream v166[1][4], + float v167 +) { + #pragma HLS array_partition variable=v164 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=4 + + float v168[16][64]; + #pragma HLS array_partition variable=v168 cyclic dim=2 factor=4 + + float v169[16][128]; + #pragma HLS array_partition variable=v169 cyclic dim=2 factor=8 + + loop58: for (int v170 = 0; v170 < 16; v170++) { + loop59: for (int v171 = 0; v171 < 16; v171++) { + loop60: for (int v172 = 0; v172 < 16; v172++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop61: for (int v173 = 0; v173 < 1; v173++) { + loop62: for (int v174 = 0; v174 < 8; v174++) { + loop63: for (int v175 = 0; v175 < 4; v175++) { + if ((v175 + (v172 * 4)) == 0) { + float v176 = v165[v173][v174].read(); + v169[(v170 + v173)][(v174 + (v171 * 8))] = v176; + } + float v177 = v169[(v170 + v173)][(v174 + (v171 * 8))]; + float v178 = v164[(v174 + (v171 * 8))][(v175 + (v172 * 4))]; + if ((v174 + (v171 * 8)) == 0) { + v168[(v170 + v173)][(v175 + (v172 * 4))] = v167; + } + float v179 = v168[(v170 + v173)][(v175 + (v172 * 4))]; + float v180 = v177 * v178; + float v181 = v179 + v180; + v168[(v170 + v173)][(v175 + (v172 * 4))] = v181; + if (((v174 + (v171 * 8)) - 127) == 0) { + float v182 = v168[(v170 + v173)][(v175 + (v172 * 4))]; + v166[v173][v175].write(v182); + } + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v183[1][8], + hls::stream v184[1][8], + float v185 +) { + loop64: for (int v186 = 0; v186 < 16; v186++) { + loop65: for (int v187 = 0; v187 < 16; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop66: for (int v188 = 0; v188 < 1; v188++) { + loop67: for (int v189 = 0; v189 < 8; v189++) { + float v190 = v183[v188][v189].read(); + bool v191 = v190 > v185; + float v192 = v191 ? (float)v190 : (float)v185; + v184[v188][v189].write(v192); + } + } + } + } + return ; +} + +void node14( + float v193[32][128], + hls::stream v194[1][2], + hls::stream v195[1][8], + float v196 +) { + #pragma HLS array_partition variable=v193 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v193 cyclic dim=2 factor=8 + + float v197[16][128]; + #pragma HLS array_partition variable=v197 cyclic dim=2 factor=8 + + float v198[16][32]; + #pragma HLS array_partition variable=v198 cyclic dim=2 factor=2 + + loop68: for (int v199 = 0; v199 < 16; v199++) { + loop69: for (int v200 = 0; v200 < 16; v200++) { + loop70: for (int v201 = 0; v201 < 16; v201++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v202 = 0; v202 < 1; v202++) { + loop72: for (int v203 = 0; v203 < 2; v203++) { + loop73: for (int v204 = 0; v204 < 8; v204++) { + if ((v204 + (v201 * 8)) == 0) { + float v205 = v194[v202][v203].read(); + v198[(v199 + v202)][(v203 + (v200 * 2))] = v205; + } + float v206 = v198[(v199 + v202)][(v203 + (v200 * 2))]; + float v207 = v193[(v203 + (v200 * 2))][(v204 + (v201 * 8))]; + if ((v203 + (v200 * 2)) == 0) { + v197[(v199 + v202)][(v204 + (v201 * 8))] = v196; + } + float v208 = v197[(v199 + v202)][(v204 + (v201 * 8))]; + float v209 = v206 * v207; + float v210 = v208 + v209; + v197[(v199 + v202)][(v204 + (v201 * 8))] = v210; + if (((v203 + (v200 * 2)) - 31) == 0) { + float v211 = v197[(v199 + v202)][(v204 + (v201 * 8))]; + v195[v202][v204].write(v211); + } + } + } + } + } + } + } + return ; +} + +void node15( + hls::stream v212[1][2], + hls::stream v213[1][2], + float v214 +) { + loop74: for (int v215 = 0; v215 < 16; v215++) { + loop75: for (int v216 = 0; v216 < 16; v216++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v217 = 0; v217 < 1; v217++) { + loop77: for (int v218 = 0; v218 < 2; v218++) { + float v219 = v212[v217][v218].read(); + bool v220 = v219 > v214; + float v221 = v220 ? (float)v219 : (float)v214; + v213[v217][v218].write(v221); + } + } + } + } + return ; +} + +void node16( + hls::stream v222[1][1], + float v223[16][32], + hls::stream v224[1][2], + float v225 +) { + #pragma HLS array_partition variable=v223 cyclic dim=2 factor=2 + + float v226[16][32]; + #pragma HLS array_partition variable=v226 cyclic dim=2 factor=2 + + float v227[16][16]; + loop78: for (int v228 = 0; v228 < 16; v228++) { + loop79: for (int v229 = 0; v229 < 16; v229++) { + loop80: for (int v230 = 0; v230 < 16; v230++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v231 = 0; v231 < 1; v231++) { + loop82: for (int v232 = 0; v232 < 1; v232++) { + loop83: for (int v233 = 0; v233 < 2; v233++) { + if ((v233 + (v230 * 2)) == 0) { + float v234 = v222[v231][v232].read(); + v227[(v228 + v231)][(v229 + v232)] = v234; + } + float v235 = v227[(v228 + v231)][(v229 + v232)]; + float v236 = v223[(v229 + v232)][(v233 + (v230 * 2))]; + if ((v229 + v232) == 0) { + v226[(v228 + v231)][(v233 + (v230 * 2))] = v225; + } + float v237 = v226[(v228 + v231)][(v233 + (v230 * 2))]; + float v238 = v235 * v236; + float v239 = v237 + v238; + v226[(v228 + v231)][(v233 + (v230 * 2))] = v239; + if (((v229 + v232) - 15) == 0) { + float v240 = v226[(v228 + v231)][(v233 + (v230 * 2))]; + v224[v231][v233].write(v240); + } + } + } + } + } + } + } + return ; +} + +void node17( + hls::stream v241[1][1], + hls::stream v242[1][1], + float v243 +) { + loop84: for (int v244 = 0; v244 < 16; v244++) { + loop85: for (int v245 = 0; v245 < 16; v245++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v246 = 0; v246 < 1; v246++) { + loop87: for (int v247 = 0; v247 < 1; v247++) { + float v248 = v241[v246][v247].read(); + bool v249 = v248 > v243; + float v250 = v249 ? (float)v248 : (float)v243; + v242[v246][v247].write(v250); + } + } + } + } + return ; +} + +void node18( + float v251[16][16], + hls::stream v252[1][1], + hls::stream v253[1][1], + float v254 +) { + float v255[16][16]; + float v256[16][16]; + loop88: for (int v257 = 0; v257 < 16; v257++) { + loop89: for (int v258 = 0; v258 < 16; v258++) { + loop90: for (int v259 = 0; v259 < 16; v259++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop91: for (int v260 = 0; v260 < 1; v260++) { + loop92: for (int v261 = 0; v261 < 1; v261++) { + loop93: for (int v262 = 0; v262 < 1; v262++) { + if ((v259 + v262) == 0) { + float v263 = v252[v260][v261].read(); + v256[(v257 + v260)][(v258 + v261)] = v263; + } + float v264 = v256[(v257 + v260)][(v258 + v261)]; + float v265 = v251[(v258 + v261)][(v259 + v262)]; + if ((v258 + v261) == 0) { + v255[(v257 + v260)][(v259 + v262)] = v254; + } + float v266 = v255[(v257 + v260)][(v259 + v262)]; + float v267 = v264 * v265; + float v268 = v266 + v267; + v255[(v257 + v260)][(v259 + v262)] = v268; + if (((v258 + v261) - 15) == 0) { + float v269 = v255[(v257 + v260)][(v259 + v262)]; + v253[v260][v262].write(v269); + } + } + } + } + } + } + } + return ; +} + +void node19( + hls::stream v270[1][1], + hls::stream v271[1][1], + float v272 +) { + loop94: for (int v273 = 0; v273 < 16; v273++) { + loop95: for (int v274 = 0; v274 < 16; v274++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop96: for (int v275 = 0; v275 < 1; v275++) { + loop97: for (int v276 = 0; v276 < 1; v276++) { + float v277 = v270[v275][v276].read(); + bool v278 = v277 > v272; + float v279 = v278 ? (float)v277 : (float)v272; + v271[v275][v276].write(v279); + } + } + } + } + return ; +} + +void node20( + hls::stream v280[1][2], + float v281[32][16], + hls::stream v282[1][1], + float v283 +) { + #pragma HLS array_partition variable=v281 cyclic dim=1 factor=2 + + float v284[16][16]; + float v285[16][32]; + #pragma HLS array_partition variable=v285 cyclic dim=2 factor=2 + + loop98: for (int v286 = 0; v286 < 16; v286++) { + loop99: for (int v287 = 0; v287 < 16; v287++) { + loop100: for (int v288 = 0; v288 < 16; v288++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop101: for (int v289 = 0; v289 < 1; v289++) { + loop102: for (int v290 = 0; v290 < 2; v290++) { + loop103: for (int v291 = 0; v291 < 1; v291++) { + if ((v288 + v291) == 0) { + float v292 = v280[v289][v290].read(); + v285[(v286 + v289)][(v290 + (v287 * 2))] = v292; + } + float v293 = v285[(v286 + v289)][(v290 + (v287 * 2))]; + float v294 = v281[(v290 + (v287 * 2))][(v288 + v291)]; + if ((v290 + (v287 * 2)) == 0) { + v284[(v286 + v289)][(v288 + v291)] = v283; + } + float v295 = v284[(v286 + v289)][(v288 + v291)]; + float v296 = v293 * v294; + float v297 = v295 + v296; + v284[(v286 + v289)][(v288 + v291)] = v297; + if (((v290 + (v287 * 2)) - 31) == 0) { + float v298 = v284[(v286 + v289)][(v288 + v291)]; + v282[v289][v291].write(v298); + } + } + } + } + } + } + } + return ; +} + +void node21( + hls::stream v299[1][2], + hls::stream v300[1][2], + float v301 +) { + loop104: for (int v302 = 0; v302 < 16; v302++) { + loop105: for (int v303 = 0; v303 < 16; v303++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop106: for (int v304 = 0; v304 < 1; v304++) { + loop107: for (int v305 = 0; v305 < 2; v305++) { + float v306 = v299[v304][v305].read(); + bool v307 = v306 > v301; + float v308 = v307 ? (float)v306 : (float)v301; + v300[v304][v305].write(v308); + } + } + } + } + return ; +} + +void node22( + float v309[64][32], + hls::stream v310[1][4], + hls::stream v311[1][2], + float v312 +) { + #pragma HLS array_partition variable=v309 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v309 cyclic dim=2 factor=2 + + float v313[16][32]; + #pragma HLS array_partition variable=v313 cyclic dim=2 factor=2 + + float v314[16][64]; + #pragma HLS array_partition variable=v314 cyclic dim=2 factor=4 + + loop108: for (int v315 = 0; v315 < 16; v315++) { + loop109: for (int v316 = 0; v316 < 16; v316++) { + loop110: for (int v317 = 0; v317 < 16; v317++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop111: for (int v318 = 0; v318 < 1; v318++) { + loop112: for (int v319 = 0; v319 < 4; v319++) { + loop113: for (int v320 = 0; v320 < 2; v320++) { + if ((v320 + (v317 * 2)) == 0) { + float v321 = v310[v318][v319].read(); + v314[(v315 + v318)][(v319 + (v316 * 4))] = v321; + } + float v322 = v314[(v315 + v318)][(v319 + (v316 * 4))]; + float v323 = v309[(v319 + (v316 * 4))][(v320 + (v317 * 2))]; + if ((v319 + (v316 * 4)) == 0) { + v313[(v315 + v318)][(v320 + (v317 * 2))] = v312; + } + float v324 = v313[(v315 + v318)][(v320 + (v317 * 2))]; + float v325 = v322 * v323; + float v326 = v324 + v325; + v313[(v315 + v318)][(v320 + (v317 * 2))] = v326; + if (((v319 + (v316 * 4)) - 63) == 0) { + float v327 = v313[(v315 + v318)][(v320 + (v317 * 2))]; + v311[v318][v320].write(v327); + } + } + } + } + } + } + } + return ; +} + +void node23( + hls::stream v328[1][4], + hls::stream v329[1][4], + float v330 +) { + loop114: for (int v331 = 0; v331 < 16; v331++) { + loop115: for (int v332 = 0; v332 < 16; v332++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop116: for (int v333 = 0; v333 < 1; v333++) { + loop117: for (int v334 = 0; v334 < 4; v334++) { + float v335 = v328[v333][v334].read(); + bool v336 = v335 > v330; + float v337 = v336 ? (float)v335 : (float)v330; + v329[v333][v334].write(v337); + } + } + } + } + return ; +} + +void node24( + float v338[128][64], + hls::stream v339[1][8], + hls::stream v340[1][4], + float v341 +) { + #pragma HLS array_partition variable=v338 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v338 cyclic dim=2 factor=4 + + float v342[16][64]; + #pragma HLS array_partition variable=v342 cyclic dim=2 factor=4 + + float v343[16][128]; + #pragma HLS array_partition variable=v343 cyclic dim=2 factor=8 + + loop118: for (int v344 = 0; v344 < 16; v344++) { + loop119: for (int v345 = 0; v345 < 16; v345++) { + loop120: for (int v346 = 0; v346 < 16; v346++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop121: for (int v347 = 0; v347 < 1; v347++) { + loop122: for (int v348 = 0; v348 < 8; v348++) { + loop123: for (int v349 = 0; v349 < 4; v349++) { + if ((v349 + (v346 * 4)) == 0) { + float v350 = v339[v347][v348].read(); + v343[(v344 + v347)][(v348 + (v345 * 8))] = v350; + } + float v351 = v343[(v344 + v347)][(v348 + (v345 * 8))]; + float v352 = v338[(v348 + (v345 * 8))][(v349 + (v346 * 4))]; + if ((v348 + (v345 * 8)) == 0) { + v342[(v344 + v347)][(v349 + (v346 * 4))] = v341; + } + float v353 = v342[(v344 + v347)][(v349 + (v346 * 4))]; + float v354 = v351 * v352; + float v355 = v353 + v354; + v342[(v344 + v347)][(v349 + (v346 * 4))] = v355; + if (((v348 + (v345 * 8)) - 127) == 0) { + float v356 = v342[(v344 + v347)][(v349 + (v346 * 4))]; + v340[v347][v349].write(v356); + } + } + } + } + } + } + } + return ; +} + +void node25( + hls::stream v357[1][8], + hls::stream v358[1][8], + float v359 +) { + loop124: for (int v360 = 0; v360 < 16; v360++) { + loop125: for (int v361 = 0; v361 < 16; v361++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop126: for (int v362 = 0; v362 < 1; v362++) { + loop127: for (int v363 = 0; v363 < 8; v363++) { + float v364 = v357[v362][v363].read(); + bool v365 = v364 > v359; + float v366 = v365 ? (float)v364 : (float)v359; + v358[v362][v363].write(v366); + } + } + } + } + return ; +} + +void node26( + hls::stream v367[1][4], + float v368[64][128], + hls::stream v369[1][8], + float v370 +) { + #pragma HLS array_partition variable=v368 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v368 cyclic dim=2 factor=8 + + float v371[16][128]; + #pragma HLS array_partition variable=v371 cyclic dim=2 factor=8 + + float v372[16][64]; + #pragma HLS array_partition variable=v372 cyclic dim=2 factor=4 + + loop128: for (int v373 = 0; v373 < 16; v373++) { + loop129: for (int v374 = 0; v374 < 16; v374++) { + loop130: for (int v375 = 0; v375 < 16; v375++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop131: for (int v376 = 0; v376 < 1; v376++) { + loop132: for (int v377 = 0; v377 < 4; v377++) { + loop133: for (int v378 = 0; v378 < 8; v378++) { + if ((v378 + (v375 * 8)) == 0) { + float v379 = v367[v376][v377].read(); + v372[(v373 + v376)][(v377 + (v374 * 4))] = v379; + } + float v380 = v372[(v373 + v376)][(v377 + (v374 * 4))]; + float v381 = v368[(v377 + (v374 * 4))][(v378 + (v375 * 8))]; + if ((v377 + (v374 * 4)) == 0) { + v371[(v373 + v376)][(v378 + (v375 * 8))] = v370; + } + float v382 = v371[(v373 + v376)][(v378 + (v375 * 8))]; + float v383 = v380 * v381; + float v384 = v382 + v383; + v371[(v373 + v376)][(v378 + (v375 * 8))] = v384; + if (((v377 + (v374 * 4)) - 63) == 0) { + float v385 = v371[(v373 + v376)][(v378 + (v375 * 8))]; + v369[v376][v378].write(v385); + } + } + } + } + } + } + } + return ; +} + +void node27( + hls::stream v386[1][4], + hls::stream v387[1][4], + float v388 +) { + loop134: for (int v389 = 0; v389 < 16; v389++) { + loop135: for (int v390 = 0; v390 < 16; v390++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v391 = 0; v391 < 1; v391++) { + loop137: for (int v392 = 0; v392 < 4; v392++) { + float v393 = v386[v391][v392].read(); + bool v394 = v393 > v388; + float v395 = v394 ? (float)v393 : (float)v388; + v387[v391][v392].write(v395); + } + } + } + } + return ; +} + +void node28( + hls::stream v396[1][8], + float v397[128][64], + hls::stream v398[1][4], + float v399 +) { + #pragma HLS array_partition variable=v397 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v397 cyclic dim=2 factor=4 + + float v400[16][64]; + #pragma HLS array_partition variable=v400 cyclic dim=2 factor=4 + + float v401[16][128]; + #pragma HLS array_partition variable=v401 cyclic dim=2 factor=8 + + loop138: for (int v402 = 0; v402 < 16; v402++) { + loop139: for (int v403 = 0; v403 < 16; v403++) { + loop140: for (int v404 = 0; v404 < 16; v404++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop141: for (int v405 = 0; v405 < 1; v405++) { + loop142: for (int v406 = 0; v406 < 8; v406++) { + loop143: for (int v407 = 0; v407 < 4; v407++) { + if ((v407 + (v404 * 4)) == 0) { + float v408 = v396[v405][v406].read(); + v401[(v402 + v405)][(v406 + (v403 * 8))] = v408; + } + float v409 = v401[(v402 + v405)][(v406 + (v403 * 8))]; + float v410 = v397[(v406 + (v403 * 8))][(v407 + (v404 * 4))]; + if ((v406 + (v403 * 8)) == 0) { + v400[(v402 + v405)][(v407 + (v404 * 4))] = v399; + } + float v411 = v400[(v402 + v405)][(v407 + (v404 * 4))]; + float v412 = v409 * v410; + float v413 = v411 + v412; + v400[(v402 + v405)][(v407 + (v404 * 4))] = v413; + if (((v406 + (v403 * 8)) - 127) == 0) { + float v414 = v400[(v402 + v405)][(v407 + (v404 * 4))]; + v398[v405][v407].write(v414); + } + } + } + } + } + } + } + return ; +} + +void node29( + hls::stream v415[1][8], + hls::stream v416[1][8], + float v417 +) { + loop144: for (int v418 = 0; v418 < 16; v418++) { + loop145: for (int v419 = 0; v419 < 16; v419++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop146: for (int v420 = 0; v420 < 1; v420++) { + loop147: for (int v421 = 0; v421 < 8; v421++) { + float v422 = v415[v420][v421].read(); + bool v423 = v422 > v417; + float v424 = v423 ? (float)v422 : (float)v417; + v416[v420][v421].write(v424); + } + } + } + } + return ; +} + +void node30( + float v425[32][128], + float v426[16][32], + hls::stream v427[1][8], + float v428 +) { + #pragma HLS array_partition variable=v425 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v425 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v426 cyclic dim=2 factor=2 + + float v429[16][128]; + #pragma HLS array_partition variable=v429 cyclic dim=2 factor=8 + + loop148: for (int v430 = 0; v430 < 16; v430++) { + loop149: for (int v431 = 0; v431 < 16; v431++) { + loop150: for (int v432 = 0; v432 < 16; v432++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop151: for (int v433 = 0; v433 < 1; v433++) { + loop152: for (int v434 = 0; v434 < 2; v434++) { + loop153: for (int v435 = 0; v435 < 8; v435++) { + float v436 = v426[(v430 + v433)][(v434 + (v431 * 2))]; + float v437 = v425[(v434 + (v431 * 2))][(v435 + (v432 * 8))]; + if ((v434 + (v431 * 2)) == 0) { + v429[(v430 + v433)][(v435 + (v432 * 8))] = v428; + } + float v438 = v429[(v430 + v433)][(v435 + (v432 * 8))]; + float v439 = v436 * v437; + float v440 = v438 + v439; + v429[(v430 + v433)][(v435 + (v432 * 8))] = v440; + if (((v434 + (v431 * 2)) - 31) == 0) { + float v441 = v429[(v430 + v433)][(v435 + (v432 * 8))]; + v427[v433][v435].write(v441); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v442[16][32], + float v443[32][128], + float v444[128][64], + float v445[64][128], + float v446[128][64], + float v447[64][32], + float v448[32][16], + float v449[16][16], + float v450[16][32], + float v451[32][128], + float v452[128][64], + float v453[64][128], + float v454[128][64], + float v455[64][32], + float v456[32][16], + float v457[16][16], + float v458[16][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v442 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v443 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v443 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v444 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v444 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v445 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v445 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v446 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v446 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v447 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v447 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v448 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v450 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v451 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v451 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v452 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v452 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v453 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v453 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v454 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v454 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v455 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v455 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v456 cyclic dim=1 factor=2 + + hls::stream v459[1][1]; + #pragma HLS STREAM variable=v459 depth=256 + hls::stream v460[1][1]; + #pragma HLS STREAM variable=v460 depth=256 + hls::stream v461[1][1]; + #pragma HLS STREAM variable=v461 depth=256 + hls::stream v462[1][1]; + #pragma HLS STREAM variable=v462 depth=256 + hls::stream v463[1][2]; + #pragma HLS STREAM variable=v463 depth=256 + hls::stream v464[1][2]; + #pragma HLS STREAM variable=v464 depth=256 + hls::stream v465[1][4]; + #pragma HLS STREAM variable=v465 depth=256 + hls::stream v466[1][4]; + #pragma HLS STREAM variable=v466 depth=256 + hls::stream v467[1][8]; + #pragma HLS STREAM variable=v467 depth=256 + hls::stream v468[1][8]; + #pragma HLS STREAM variable=v468 depth=256 + hls::stream v469[1][4]; + #pragma HLS STREAM variable=v469 depth=256 + hls::stream v470[1][4]; + #pragma HLS STREAM variable=v470 depth=256 + hls::stream v471[1][8]; + #pragma HLS STREAM variable=v471 depth=256 + hls::stream v472[1][8]; + #pragma HLS STREAM variable=v472 depth=256 + hls::stream v473[1][2]; + #pragma HLS STREAM variable=v473 depth=256 + hls::stream v474[1][2]; + #pragma HLS STREAM variable=v474 depth=256 + hls::stream v475[1][1]; + #pragma HLS STREAM variable=v475 depth=256 + hls::stream v476[1][1]; + #pragma HLS STREAM variable=v476 depth=256 + hls::stream v477[1][1]; + #pragma HLS STREAM variable=v477 depth=256 + hls::stream v478[1][1]; + #pragma HLS STREAM variable=v478 depth=256 + hls::stream v479[1][2]; + #pragma HLS STREAM variable=v479 depth=256 + hls::stream v480[1][2]; + #pragma HLS STREAM variable=v480 depth=256 + hls::stream v481[1][4]; + #pragma HLS STREAM variable=v481 depth=256 + hls::stream v482[1][4]; + #pragma HLS STREAM variable=v482 depth=256 + hls::stream v483[1][8]; + #pragma HLS STREAM variable=v483 depth=256 + hls::stream v484[1][8]; + #pragma HLS STREAM variable=v484 depth=256 + hls::stream v485[1][4]; + #pragma HLS STREAM variable=v485 depth=256 + hls::stream v486[1][4]; + #pragma HLS STREAM variable=v486 depth=256 + hls::stream v487[1][8]; + #pragma HLS STREAM variable=v487 depth=256 + hls::stream v488[1][8]; + #pragma HLS STREAM variable=v488 depth=256 + node30(v443, v442, v488, 0.000000); + node29(v488, v487, 0.000000); + node28(v487, v444, v486, 0.000000); + node27(v486, v485, 0.000000); + node26(v485, v445, v484, 0.000000); + node25(v484, v483, 0.000000); + node24(v446, v483, v482, 0.000000); + node23(v482, v481, 0.000000); + node22(v447, v481, v480, 0.000000); + node21(v480, v479, 0.000000); + node20(v479, v448, v478, 0.000000); + node19(v478, v477, 0.000000); + node18(v449, v477, v476, 0.000000); + node17(v476, v475, 0.000000); + node16(v475, v450, v474, 0.000000); + node15(v474, v473, 0.000000); + node14(v451, v473, v472, 0.000000); + node13(v472, v471, 0.000000); + node12(v452, v471, v470, 0.000000); + node11(v470, v469, 0.000000); + node10(v469, v453, v468, 0.000000); + node9(v468, v467, 0.000000); + node8(v467, v454, v466, 0.000000); + node7(v466, v465, 0.000000); + node6(v455, v465, v464, 0.000000); + node5(v464, v463, 0.000000); + node4(v463, v456, v462, 0.000000); + node3(v462, v461, 0.000000); + node2(v457, v461, v460, 0.000000); + node1(v460, v459, 0.000000, 1000000.000000); + node0(v459, v458); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree__opt5/src/k15mmtree.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree__opt5/src/k15mmtree.cpp new file mode 100644 index 000000000000..ab6fc885aa37 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree__opt5/src/k15mmtree.cpp @@ -0,0 +1,938 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + hls::stream v8[4][4], + float v9 +) { + loop4: for (int v10 = 0; v10 < 16; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 4; v12++) { + loop7: for (int v13 = 0; v13 < 4; v13++) { + float v14 = v7[v12][v13].read(); + float v15 = v14 / v9; + v8[v12][v13].write(v15); + } + } + } + } + return ; +} + +void node2( + hls::stream v16[4][4], + hls::stream v17[4][4], + hls::stream v18[4][4], + float v19 +) { + float v20[64][64]; + #pragma HLS array_partition variable=v20 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v20 cyclic dim=2 factor=4 + + float v21[64][64]; + #pragma HLS array_partition variable=v21 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v21 cyclic dim=2 factor=4 + + float v22[64][64]; + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=4 + + loop8: for (int v23 = 0; v23 < 16; v23++) { + loop9: for (int v24 = 0; v24 < 16; v24++) { + loop10: for (int v25 = 0; v25 < 16; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v26 = 0; v26 < 4; v26++) { + loop12: for (int v27 = 0; v27 < 4; v27++) { + loop13: for (int v28 = 0; v28 < 4; v28++) { + if ((v28 + (v25 * 4)) == 0) { + float v29 = v16[v27][v26].read(); + v22[(v27 + (v24 * 4))][(v26 + (v23 * 4))] = v29; + } + float v30 = v22[(v27 + (v24 * 4))][(v26 + (v23 * 4))]; + if ((v27 + (v24 * 4)) == 0) { + float v31 = v17[v26][v28].read(); + v21[(v26 + (v23 * 4))][(v28 + (v25 * 4))] = v31; + } + float v32 = v21[(v26 + (v23 * 4))][(v28 + (v25 * 4))]; + if ((v26 + (v23 * 4)) == 0) { + v20[(v27 + (v24 * 4))][(v28 + (v25 * 4))] = v19; + } + float v33 = v20[(v27 + (v24 * 4))][(v28 + (v25 * 4))]; + float v34 = v30 * v32; + float v35 = v33 + v34; + v20[(v27 + (v24 * 4))][(v28 + (v25 * 4))] = v35; + if (((v26 + (v23 * 4)) - 63) == 0) { + float v36 = v20[(v27 + (v24 * 4))][(v28 + (v25 * 4))]; + v18[v27][v28].write(v36); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v37[2][4], + hls::stream v38[4][2], + hls::stream v39[4][4], + float v40 +) { + float v41[64][64]; + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=4 + + float v42[64][64]; + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=4 + + float v43[64][64]; + #pragma HLS array_partition variable=v43 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v43 cyclic dim=2 factor=2 + + loop14: for (int v44 = 0; v44 < 32; v44++) { + loop15: for (int v45 = 0; v45 < 16; v45++) { + loop16: for (int v46 = 0; v46 < 16; v46++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v47 = 0; v47 < 2; v47++) { + loop18: for (int v48 = 0; v48 < 4; v48++) { + loop19: for (int v49 = 0; v49 < 4; v49++) { + if ((v49 + (v46 * 4)) == 0) { + float v50 = v38[v48][v47].read(); + v43[(v48 + (v45 * 4))][(v47 + (v44 * 2))] = v50; + } + float v51 = v43[(v48 + (v45 * 4))][(v47 + (v44 * 2))]; + if ((v48 + (v45 * 4)) == 0) { + float v52 = v37[v47][v49].read(); + v42[(v47 + (v44 * 2))][(v49 + (v46 * 4))] = v52; + } + float v53 = v42[(v47 + (v44 * 2))][(v49 + (v46 * 4))]; + if ((v47 + (v44 * 2)) == 0) { + v41[(v48 + (v45 * 4))][(v49 + (v46 * 4))] = v40; + } + float v54 = v41[(v48 + (v45 * 4))][(v49 + (v46 * 4))]; + float v55 = v51 * v53; + float v56 = v54 + v55; + v41[(v48 + (v45 * 4))][(v49 + (v46 * 4))] = v56; + if (((v47 + (v44 * 2)) - 63) == 0) { + float v57 = v41[(v48 + (v45 * 4))][(v49 + (v46 * 4))]; + v39[v48][v49].write(v57); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v58[4][2], + hls::stream v59[2][4], + hls::stream v60[4][4], + float v61 +) { + float v62[64][64]; + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=4 + + float v63[64][64]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=4 + + float v64[64][64]; + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=2 + + loop20: for (int v65 = 0; v65 < 16; v65++) { + loop21: for (int v66 = 0; v66 < 32; v66++) { + loop22: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop23: for (int v68 = 0; v68 < 4; v68++) { + loop24: for (int v69 = 0; v69 < 2; v69++) { + loop25: for (int v70 = 0; v70 < 4; v70++) { + if ((v68 + (v65 * 4)) == 0) { + float v71 = v58[v70][v69].read(); + v64[(v70 + (v67 * 4))][(v69 + (v66 * 2))] = v71; + } + float v72 = v64[(v70 + (v67 * 4))][(v69 + (v66 * 2))]; + if ((v70 + (v67 * 4)) == 0) { + float v73 = v59[v69][v68].read(); + v63[(v69 + (v66 * 2))][(v68 + (v65 * 4))] = v73; + } + float v74 = v63[(v69 + (v66 * 2))][(v68 + (v65 * 4))]; + if ((v69 + (v66 * 2)) == 0) { + v62[(v70 + (v67 * 4))][(v68 + (v65 * 4))] = v61; + } + float v75 = v62[(v70 + (v67 * 4))][(v68 + (v65 * 4))]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v70 + (v67 * 4))][(v68 + (v65 * 4))] = v77; + if (((v69 + (v66 * 2)) - 63) == 0) { + float v78 = v62[(v70 + (v67 * 4))][(v68 + (v65 * 4))]; + v60[v70][v68].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v79[4][4], + hls::stream v80[2][4], + hls::stream v81[2][4], + float v82 +) { + float v83[64][64]; + #pragma HLS array_partition variable=v83 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v83 cyclic dim=2 factor=4 + + float v84[64][64]; + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v85[64][64]; + #pragma HLS array_partition variable=v85 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=4 + + loop26: for (int v86 = 0; v86 < 32; v86++) { + loop27: for (int v87 = 0; v87 < 16; v87++) { + loop28: for (int v88 = 0; v88 < 16; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop29: for (int v89 = 0; v89 < 2; v89++) { + loop30: for (int v90 = 0; v90 < 4; v90++) { + loop31: for (int v91 = 0; v91 < 4; v91++) { + if ((v91 + (v88 * 4)) == 0) { + float v92 = v80[v89][v90].read(); + v85[(v89 + (v86 * 2))][(v90 + (v87 * 4))] = v92; + } + float v93 = v85[(v89 + (v86 * 2))][(v90 + (v87 * 4))]; + if ((v89 + (v86 * 2)) == 0) { + float v94 = v79[v90][v91].read(); + v84[(v90 + (v87 * 4))][(v91 + (v88 * 4))] = v94; + } + float v95 = v84[(v90 + (v87 * 4))][(v91 + (v88 * 4))]; + if ((v90 + (v87 * 4)) == 0) { + v83[(v89 + (v86 * 2))][(v91 + (v88 * 4))] = v82; + } + float v96 = v83[(v89 + (v86 * 2))][(v91 + (v88 * 4))]; + float v97 = v93 * v95; + float v98 = v96 + v97; + v83[(v89 + (v86 * 2))][(v91 + (v88 * 4))] = v98; + if (((v90 + (v87 * 4)) - 63) == 0) { + float v99 = v83[(v89 + (v86 * 2))][(v91 + (v88 * 4))]; + v81[v89][v91].write(v99); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v100[4][2], + hls::stream v101[4][4], + hls::stream v102[4][2], + float v103 +) { + float v104[64][64]; + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=2 + + float v105[64][64]; + #pragma HLS array_partition variable=v105 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=2 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + loop32: for (int v107 = 0; v107 < 32; v107++) { + loop33: for (int v108 = 0; v108 < 16; v108++) { + loop34: for (int v109 = 0; v109 < 16; v109++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop35: for (int v110 = 0; v110 < 2; v110++) { + loop36: for (int v111 = 0; v111 < 4; v111++) { + loop37: for (int v112 = 0; v112 < 4; v112++) { + if ((v110 + (v107 * 2)) == 0) { + float v113 = v101[v112][v111].read(); + v106[(v112 + (v109 * 4))][(v111 + (v108 * 4))] = v113; + } + float v114 = v106[(v112 + (v109 * 4))][(v111 + (v108 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + float v115 = v100[v111][v110].read(); + v105[(v111 + (v108 * 4))][(v110 + (v107 * 2))] = v115; + } + float v116 = v105[(v111 + (v108 * 4))][(v110 + (v107 * 2))]; + if ((v111 + (v108 * 4)) == 0) { + v104[(v112 + (v109 * 4))][(v110 + (v107 * 2))] = v103; + } + float v117 = v104[(v112 + (v109 * 4))][(v110 + (v107 * 2))]; + float v118 = v114 * v116; + float v119 = v117 + v118; + v104[(v112 + (v109 * 4))][(v110 + (v107 * 2))] = v119; + if (((v111 + (v108 * 4)) - 63) == 0) { + float v120 = v104[(v112 + (v109 * 4))][(v110 + (v107 * 2))]; + v102[v112][v110].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + hls::stream v121[4][4], + hls::stream v122[2][4], + hls::stream v123[2][4], + float v124 +) { + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + float v126[64][64]; + #pragma HLS array_partition variable=v126 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v126 cyclic dim=2 factor=4 + + float v127[64][64]; + #pragma HLS array_partition variable=v127 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v127 cyclic dim=2 factor=4 + + loop38: for (int v128 = 0; v128 < 16; v128++) { + loop39: for (int v129 = 0; v129 < 16; v129++) { + loop40: for (int v130 = 0; v130 < 32; v130++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v131 = 0; v131 < 4; v131++) { + loop42: for (int v132 = 0; v132 < 4; v132++) { + loop43: for (int v133 = 0; v133 < 2; v133++) { + if ((v131 + (v128 * 4)) == 0) { + float v134 = v122[v133][v132].read(); + v127[(v133 + (v130 * 2))][(v132 + (v129 * 4))] = v134; + } + float v135 = v127[(v133 + (v130 * 2))][(v132 + (v129 * 4))]; + if ((v133 + (v130 * 2)) == 0) { + float v136 = v121[v132][v131].read(); + v126[(v132 + (v129 * 4))][(v131 + (v128 * 4))] = v136; + } + float v137 = v126[(v132 + (v129 * 4))][(v131 + (v128 * 4))]; + if ((v132 + (v129 * 4)) == 0) { + v125[(v133 + (v130 * 2))][(v131 + (v128 * 4))] = v124; + } + float v138 = v125[(v133 + (v130 * 2))][(v131 + (v128 * 4))]; + float v139 = v135 * v137; + float v140 = v138 + v139; + v125[(v133 + (v130 * 2))][(v131 + (v128 * 4))] = v140; + if (((v132 + (v129 * 4)) - 63) == 0) { + float v141 = v125[(v133 + (v130 * 2))][(v131 + (v128 * 4))]; + v123[v133][v131].write(v141); + } + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v142[4][4], + hls::stream v143[4][2], + hls::stream v144[4][2], + float v145 +) { + float v146[64][64]; + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=2 + + float v147[64][64]; + #pragma HLS array_partition variable=v147 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v147 cyclic dim=2 factor=2 + + float v148[64][64]; + #pragma HLS array_partition variable=v148 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=4 + + loop44: for (int v149 = 0; v149 < 16; v149++) { + loop45: for (int v150 = 0; v150 < 32; v150++) { + loop46: for (int v151 = 0; v151 < 16; v151++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop47: for (int v152 = 0; v152 < 4; v152++) { + loop48: for (int v153 = 0; v153 < 2; v153++) { + loop49: for (int v154 = 0; v154 < 4; v154++) { + if ((v153 + (v150 * 2)) == 0) { + float v155 = v142[v154][v152].read(); + v148[(v154 + (v151 * 4))][(v152 + (v149 * 4))] = v155; + } + float v156 = v148[(v154 + (v151 * 4))][(v152 + (v149 * 4))]; + if ((v154 + (v151 * 4)) == 0) { + float v157 = v143[v152][v153].read(); + v147[(v152 + (v149 * 4))][(v153 + (v150 * 2))] = v157; + } + float v158 = v147[(v152 + (v149 * 4))][(v153 + (v150 * 2))]; + if ((v152 + (v149 * 4)) == 0) { + v146[(v154 + (v151 * 4))][(v153 + (v150 * 2))] = v145; + } + float v159 = v146[(v154 + (v151 * 4))][(v153 + (v150 * 2))]; + float v160 = v156 * v158; + float v161 = v159 + v160; + v146[(v154 + (v151 * 4))][(v153 + (v150 * 2))] = v161; + if (((v152 + (v149 * 4)) - 63) == 0) { + float v162 = v146[(v154 + (v151 * 4))][(v153 + (v150 * 2))]; + v144[v154][v153].write(v162); + } + } + } + } + } + } + } + return ; +} + +void node9( + float v163[64][64], + float v164[64][64], + hls::stream v165[4][4], + float v166 +) { + #pragma HLS array_partition variable=v163 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v163 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v164 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v164 cyclic dim=2 factor=4 + + float v167[64][64]; + #pragma HLS array_partition variable=v167 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v167 cyclic dim=2 factor=4 + + loop50: for (int v168 = 0; v168 < 16; v168++) { + loop51: for (int v169 = 0; v169 < 32; v169++) { + loop52: for (int v170 = 0; v170 < 16; v170++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v171 = 0; v171 < 4; v171++) { + loop54: for (int v172 = 0; v172 < 2; v172++) { + loop55: for (int v173 = 0; v173 < 4; v173++) { + float v174 = v163[(v171 + (v168 * 4))][(v172 + (v169 * 2))]; + float v175 = v164[(v172 + (v169 * 2))][(v173 + (v170 * 4))]; + if ((v172 + (v169 * 2)) == 0) { + v167[(v171 + (v168 * 4))][(v173 + (v170 * 4))] = v166; + } + float v176 = v167[(v171 + (v168 * 4))][(v173 + (v170 * 4))]; + float v177 = v174 * v175; + float v178 = v176 + v177; + v167[(v171 + (v168 * 4))][(v173 + (v170 * 4))] = v178; + if (((v172 + (v169 * 2)) - 63) == 0) { + float v179 = v167[(v171 + (v168 * 4))][(v173 + (v170 * 4))]; + v165[v171][v173].write(v179); + } + } + } + } + } + } + } + return ; +} + +void node10( + float v180[64][64], + float v181[64][64], + hls::stream v182[2][4], + float v183 +) { + #pragma HLS array_partition variable=v180 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v180 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v181 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v181 cyclic dim=2 factor=4 + + float v184[64][64]; + #pragma HLS array_partition variable=v184 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v184 cyclic dim=2 factor=4 + + loop56: for (int v185 = 0; v185 < 32; v185++) { + loop57: for (int v186 = 0; v186 < 16; v186++) { + loop58: for (int v187 = 0; v187 < 16; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop59: for (int v188 = 0; v188 < 2; v188++) { + loop60: for (int v189 = 0; v189 < 4; v189++) { + loop61: for (int v190 = 0; v190 < 4; v190++) { + float v191 = v180[(v188 + (v185 * 2))][(v189 + (v186 * 4))]; + float v192 = v181[(v189 + (v186 * 4))][(v190 + (v187 * 4))]; + if ((v189 + (v186 * 4)) == 0) { + v184[(v188 + (v185 * 2))][(v190 + (v187 * 4))] = v183; + } + float v193 = v184[(v188 + (v185 * 2))][(v190 + (v187 * 4))]; + float v194 = v191 * v192; + float v195 = v193 + v194; + v184[(v188 + (v185 * 2))][(v190 + (v187 * 4))] = v195; + if (((v189 + (v186 * 4)) - 63) == 0) { + float v196 = v184[(v188 + (v185 * 2))][(v190 + (v187 * 4))]; + v182[v188][v190].write(v196); + } + } + } + } + } + } + } + return ; +} + +void node11( + float v197[64][64], + float v198[64][64], + hls::stream v199[4][2], + float v200 +) { + #pragma HLS array_partition variable=v197 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v197 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v198 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v198 cyclic dim=2 factor=2 + + float v201[64][64]; + #pragma HLS array_partition variable=v201 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v201 cyclic dim=2 factor=2 + + loop62: for (int v202 = 0; v202 < 32; v202++) { + loop63: for (int v203 = 0; v203 < 16; v203++) { + loop64: for (int v204 = 0; v204 < 16; v204++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop65: for (int v205 = 0; v205 < 2; v205++) { + loop66: for (int v206 = 0; v206 < 4; v206++) { + loop67: for (int v207 = 0; v207 < 4; v207++) { + float v208 = v197[(v207 + (v204 * 4))][(v206 + (v203 * 4))]; + float v209 = v198[(v206 + (v203 * 4))][(v205 + (v202 * 2))]; + if ((v206 + (v203 * 4)) == 0) { + v201[(v207 + (v204 * 4))][(v205 + (v202 * 2))] = v200; + } + float v210 = v201[(v207 + (v204 * 4))][(v205 + (v202 * 2))]; + float v211 = v208 * v209; + float v212 = v210 + v211; + v201[(v207 + (v204 * 4))][(v205 + (v202 * 2))] = v212; + if (((v206 + (v203 * 4)) - 63) == 0) { + float v213 = v201[(v207 + (v204 * 4))][(v205 + (v202 * 2))]; + v199[v207][v205].write(v213); + } + } + } + } + } + } + } + return ; +} + +void node12( + float v214[64][64], + float v215[64][64], + hls::stream v216[4][4], + float v217 +) { + #pragma HLS array_partition variable=v214 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v214 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v215 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v215 cyclic dim=2 factor=2 + + float v218[64][64]; + #pragma HLS array_partition variable=v218 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=4 + + loop68: for (int v219 = 0; v219 < 16; v219++) { + loop69: for (int v220 = 0; v220 < 32; v220++) { + loop70: for (int v221 = 0; v221 < 16; v221++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v222 = 0; v222 < 4; v222++) { + loop72: for (int v223 = 0; v223 < 2; v223++) { + loop73: for (int v224 = 0; v224 < 4; v224++) { + float v225 = v215[(v224 + (v221 * 4))][(v223 + (v220 * 2))]; + float v226 = v214[(v223 + (v220 * 2))][(v222 + (v219 * 4))]; + if ((v223 + (v220 * 2)) == 0) { + v218[(v224 + (v221 * 4))][(v222 + (v219 * 4))] = v217; + } + float v227 = v218[(v224 + (v221 * 4))][(v222 + (v219 * 4))]; + float v228 = v225 * v226; + float v229 = v227 + v228; + v218[(v224 + (v221 * 4))][(v222 + (v219 * 4))] = v229; + if (((v223 + (v220 * 2)) - 63) == 0) { + float v230 = v218[(v224 + (v221 * 4))][(v222 + (v219 * 4))]; + v216[v224][v222].write(v230); + } + } + } + } + } + } + } + return ; +} + +void node13( + float v231[64][64], + float v232[64][64], + hls::stream v233[4][4], + float v234 +) { + #pragma HLS array_partition variable=v231 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v232 cyclic dim=2 factor=4 + + float v235[64][64]; + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v235 cyclic dim=2 factor=4 + + loop74: for (int v236 = 0; v236 < 16; v236++) { + loop75: for (int v237 = 0; v237 < 64; v237++) { + loop76: for (int v238 = 0; v238 < 16; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop77: for (int v239 = 0; v239 < 4; v239++) { + loop78: for (int v240 = 0; v240 < 1; v240++) { + loop79: for (int v241 = 0; v241 < 4; v241++) { + float v242 = v231[(v241 + (v238 * 4))][(v237 + v240)]; + float v243 = v232[(v237 + v240)][(v239 + (v236 * 4))]; + if ((v237 + v240) == 0) { + v235[(v241 + (v238 * 4))][(v239 + (v236 * 4))] = v234; + } + float v244 = v235[(v241 + (v238 * 4))][(v239 + (v236 * 4))]; + float v245 = v242 * v243; + float v246 = v244 + v245; + v235[(v241 + (v238 * 4))][(v239 + (v236 * 4))] = v246; + if (((v237 + v240) - 63) == 0) { + float v247 = v235[(v241 + (v238 * 4))][(v239 + (v236 * 4))]; + v233[v241][v239].write(v247); + } + } + } + } + } + } + } + return ; +} + +void node14( + float v248[64][64], + float v249[64][64], + hls::stream v250[2][4], + float v251 +) { + #pragma HLS array_partition variable=v248 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v248 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v249 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v249 cyclic dim=2 factor=4 + + float v252[64][64]; + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=4 + + loop80: for (int v253 = 0; v253 < 16; v253++) { + loop81: for (int v254 = 0; v254 < 16; v254++) { + loop82: for (int v255 = 0; v255 < 32; v255++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v256 = 0; v256 < 4; v256++) { + loop84: for (int v257 = 0; v257 < 4; v257++) { + loop85: for (int v258 = 0; v258 < 2; v258++) { + float v259 = v249[(v258 + (v255 * 2))][(v257 + (v254 * 4))]; + float v260 = v248[(v257 + (v254 * 4))][(v256 + (v253 * 4))]; + if ((v257 + (v254 * 4)) == 0) { + v252[(v258 + (v255 * 2))][(v256 + (v253 * 4))] = v251; + } + float v261 = v252[(v258 + (v255 * 2))][(v256 + (v253 * 4))]; + float v262 = v259 * v260; + float v263 = v261 + v262; + v252[(v258 + (v255 * 2))][(v256 + (v253 * 4))] = v263; + if (((v257 + (v254 * 4)) - 63) == 0) { + float v264 = v252[(v258 + (v255 * 2))][(v256 + (v253 * 4))]; + v250[v258][v256].write(v264); + } + } + } + } + } + } + } + return ; +} + +void node15( + float v265[64][64], + float v266[64][64], + hls::stream v267[4][2], + float v268 +) { + #pragma HLS array_partition variable=v265 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v265 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v266 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v266 cyclic dim=2 factor=2 + + float v269[64][64]; + #pragma HLS array_partition variable=v269 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v269 cyclic dim=2 factor=2 + + loop86: for (int v270 = 0; v270 < 16; v270++) { + loop87: for (int v271 = 0; v271 < 16; v271++) { + loop88: for (int v272 = 0; v272 < 32; v272++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v273 = 0; v273 < 4; v273++) { + loop90: for (int v274 = 0; v274 < 4; v274++) { + loop91: for (int v275 = 0; v275 < 2; v275++) { + float v276 = v265[(v273 + (v270 * 4))][(v274 + (v271 * 4))]; + float v277 = v266[(v274 + (v271 * 4))][(v275 + (v272 * 2))]; + if ((v274 + (v271 * 4)) == 0) { + v269[(v273 + (v270 * 4))][(v275 + (v272 * 2))] = v268; + } + float v278 = v269[(v273 + (v270 * 4))][(v275 + (v272 * 2))]; + float v279 = v276 * v277; + float v280 = v278 + v279; + v269[(v273 + (v270 * 4))][(v275 + (v272 * 2))] = v280; + if (((v274 + (v271 * 4)) - 63) == 0) { + float v281 = v269[(v273 + (v270 * 4))][(v275 + (v272 * 2))]; + v267[v273][v275].write(v281); + } + } + } + } + } + } + } + return ; +} + +void node16( + float v282[64][64], + float v283[64][64], + hls::stream v284[4][4], + float v285 +) { + #pragma HLS array_partition variable=v282 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v283 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v283 cyclic dim=2 factor=4 + + float v286[64][64]; + #pragma HLS array_partition variable=v286 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v286 cyclic dim=2 factor=4 + + loop92: for (int v287 = 0; v287 < 16; v287++) { + loop93: for (int v288 = 0; v288 < 32; v288++) { + loop94: for (int v289 = 0; v289 < 16; v289++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop95: for (int v290 = 0; v290 < 4; v290++) { + loop96: for (int v291 = 0; v291 < 2; v291++) { + loop97: for (int v292 = 0; v292 < 4; v292++) { + float v293 = v282[(v292 + (v289 * 4))][(v291 + (v288 * 2))]; + float v294 = v283[(v291 + (v288 * 2))][(v290 + (v287 * 4))]; + if ((v291 + (v288 * 2)) == 0) { + v286[(v292 + (v289 * 4))][(v290 + (v287 * 4))] = v285; + } + float v295 = v286[(v292 + (v289 * 4))][(v290 + (v287 * 4))]; + float v296 = v293 * v294; + float v297 = v295 + v296; + v286[(v292 + (v289 * 4))][(v290 + (v287 * 4))] = v297; + if (((v291 + (v288 * 2)) - 63) == 0) { + float v298 = v286[(v292 + (v289 * 4))][(v290 + (v287 * 4))]; + v284[v292][v290].write(v298); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v299[64][64], + float v300[64][64], + float v301[64][64], + float v302[64][64], + float v303[64][64], + float v304[64][64], + float v305[64][64], + float v306[64][64], + float v307[64][64], + float v308[64][64], + float v309[64][64], + float v310[64][64], + float v311[64][64], + float v312[64][64], + float v313[64][64], + float v314[64][64], + float v315[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v299 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v299 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v300 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v300 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v301 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v301 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v302 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v302 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v303 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v303 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v304 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v304 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v305 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v306 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v307 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v307 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v308 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v308 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v309 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v309 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v310 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v310 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v312 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v312 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v313 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v313 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v314 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v314 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v315 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v315 cyclic dim=2 factor=4 + + hls::stream v316[4][4]; + #pragma HLS STREAM variable=v316 depth=256 + hls::stream v317[4][4]; + #pragma HLS STREAM variable=v317 depth=256 + hls::stream v318[4][4]; + #pragma HLS STREAM variable=v318 depth=256 + hls::stream v319[4][4]; + #pragma HLS STREAM variable=v319 depth=256 + hls::stream v320[2][4]; + #pragma HLS STREAM variable=v320 depth=512 + hls::stream v321[4][2]; + #pragma HLS STREAM variable=v321 depth=512 + hls::stream v322[2][4]; + #pragma HLS STREAM variable=v322 depth=512 + hls::stream v323[4][2]; + #pragma HLS STREAM variable=v323 depth=512 + hls::stream v324[4][4]; + #pragma HLS STREAM variable=v324 depth=256 + hls::stream v325[2][4]; + #pragma HLS STREAM variable=v325 depth=512 + hls::stream v326[4][2]; + #pragma HLS STREAM variable=v326 depth=512 + hls::stream v327[4][4]; + #pragma HLS STREAM variable=v327 depth=256 + hls::stream v328[4][4]; + #pragma HLS STREAM variable=v328 depth=256 + hls::stream v329[2][4]; + #pragma HLS STREAM variable=v329 depth=512 + hls::stream v330[4][2]; + #pragma HLS STREAM variable=v330 depth=512 + hls::stream v331[4][4]; + #pragma HLS STREAM variable=v331 depth=256 + node16(v299, v300, v331, 0.000000); + node15(v301, v302, v330, 0.000000); + node14(v304, v303, v329, 0.000000); + node13(v305, v306, v328, 0.000000); + node12(v308, v307, v327, 0.000000); + node11(v309, v310, v326, 0.000000); + node10(v311, v312, v325, 0.000000); + node9(v313, v314, v324, 0.000000); + node8(v331, v330, v323, 0.000000); + node7(v328, v329, v322, 0.000000); + node6(v326, v327, v321, 0.000000); + node5(v324, v325, v320, 0.000000); + node4(v323, v322, v319, 0.000000); + node3(v320, v321, v318, 0.000000); + node2(v319, v318, v317, 0.000000); + node1(v317, v316, 1000000.000000); + node0(v316, v315); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_imbalanced__opt5/src/k15mmtree_imbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_imbalanced__opt5/src/k15mmtree_imbalanced.cpp new file mode 100644 index 000000000000..e317a9bd849c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_imbalanced__opt5/src/k15mmtree_imbalanced.cpp @@ -0,0 +1,872 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[16][16] +) { + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v3 + v5)][(v2 + v4)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[1][1], + hls::stream v8[1][1], + float v9 +) { + loop4: for (int v10 = 0; v10 < 16; v10++) { + loop5: for (int v11 = 0; v11 < 16; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v12 = 0; v12 < 1; v12++) { + loop7: for (int v13 = 0; v13 < 1; v13++) { + float v14 = v7[v13][v12].read(); + float v15 = v14 / v9; + v8[v13][v12].write(v15); + } + } + } + } + return ; +} + +void node2( + hls::stream v16[1][1], + hls::stream v17[1][1], + hls::stream v18[1][1], + float v19 +) { + float v20[16][16]; + float v21[16][16]; + float v22[16][16]; + loop8: for (int v23 = 0; v23 < 16; v23++) { + loop9: for (int v24 = 0; v24 < 16; v24++) { + loop10: for (int v25 = 0; v25 < 16; v25++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v26 = 0; v26 < 1; v26++) { + loop12: for (int v27 = 0; v27 < 1; v27++) { + loop13: for (int v28 = 0; v28 < 1; v28++) { + if ((v23 + v26) == 0) { + float v29 = v17[v28][v27].read(); + v22[(v25 + v28)][(v24 + v27)] = v29; + } + float v30 = v22[(v25 + v28)][(v24 + v27)]; + if ((v25 + v28) == 0) { + float v31 = v16[v27][v26].read(); + v21[(v24 + v27)][(v23 + v26)] = v31; + } + float v32 = v21[(v24 + v27)][(v23 + v26)]; + if ((v24 + v27) == 0) { + v20[(v25 + v28)][(v23 + v26)] = v19; + } + float v33 = v20[(v25 + v28)][(v23 + v26)]; + float v34 = v30 * v32; + float v35 = v33 + v34; + v20[(v25 + v28)][(v23 + v26)] = v35; + if (((v24 + v27) - 15) == 0) { + float v36 = v20[(v25 + v28)][(v23 + v26)]; + v18[v28][v26].write(v36); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v37[1][8], + hls::stream v38[8][1], + hls::stream v39[1][1], + float v40 +) { + float v41[16][16]; + float v42[128][16]; + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=8 + + float v43[16][128]; + #pragma HLS array_partition variable=v43 cyclic dim=2 factor=8 + + loop14: for (int v44 = 0; v44 < 16; v44++) { + loop15: for (int v45 = 0; v45 < 16; v45++) { + loop16: for (int v46 = 0; v46 < 16; v46++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v47 = 0; v47 < 1; v47++) { + loop18: for (int v48 = 0; v48 < 8; v48++) { + loop19: for (int v49 = 0; v49 < 1; v49++) { + if ((v44 + v47) == 0) { + float v50 = v37[v49][v48].read(); + v43[(v46 + v49)][(v48 + (v45 * 8))] = v50; + } + float v51 = v43[(v46 + v49)][(v48 + (v45 * 8))]; + if ((v46 + v49) == 0) { + float v52 = v38[v48][v47].read(); + v42[(v48 + (v45 * 8))][(v44 + v47)] = v52; + } + float v53 = v42[(v48 + (v45 * 8))][(v44 + v47)]; + if ((v48 + (v45 * 8)) == 0) { + v41[(v46 + v49)][(v44 + v47)] = v40; + } + float v54 = v41[(v46 + v49)][(v44 + v47)]; + float v55 = v51 * v53; + float v56 = v54 + v55; + v41[(v46 + v49)][(v44 + v47)] = v56; + if (((v48 + (v45 * 8)) - 127) == 0) { + float v57 = v41[(v46 + v49)][(v44 + v47)]; + v39[v49][v47].write(v57); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v58[128][16], + hls::stream v59[1][8], + hls::stream v60[1][1], + float v61 +) { + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=8 + + float v62[16][16]; + float v63[128][16]; + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=8 + + float v64[16][128]; + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + loop20: for (int v65 = 0; v65 < 16; v65++) { + loop21: for (int v66 = 0; v66 < 16; v66++) { + loop22: for (int v67 = 0; v67 < 16; v67++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop23: for (int v68 = 0; v68 < 8; v68++) { + loop24: for (int v69 = 0; v69 < 1; v69++) { + loop25: for (int v70 = 0; v70 < 1; v70++) { + if ((v66 + v69) == 0) { + float v71 = v59[v70][v68].read(); + v64[(v67 + v70)][(v68 + (v65 * 8))] = v71; + } + float v72 = v64[(v67 + v70)][(v68 + (v65 * 8))]; + if ((v67 + v70) == 0) { + float v73 = v58[(v68 + (v65 * 8))][(v66 + v69)]; + v63[(v68 + (v65 * 8))][(v66 + v69)] = v73; + } + float v74 = v63[(v68 + (v65 * 8))][(v66 + v69)]; + if ((v68 + (v65 * 8)) == 0) { + v62[(v67 + v70)][(v66 + v69)] = v61; + } + float v75 = v62[(v67 + v70)][(v66 + v69)]; + float v76 = v72 * v74; + float v77 = v75 + v76; + v62[(v67 + v70)][(v66 + v69)] = v77; + if (((v68 + (v65 * 8)) - 127) == 0) { + float v78 = v62[(v67 + v70)][(v66 + v69)]; + v60[v70][v69].write(v78); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v79[1][1], + hls::stream v80[8][1], + hls::stream v81[8][1], + float v82 +) { + float v83[128][16]; + #pragma HLS array_partition variable=v83 cyclic dim=1 factor=8 + + float v84[32][16]; + float v85[128][32]; + #pragma HLS array_partition variable=v85 cyclic dim=1 factor=8 + + loop26: for (int v86 = 0; v86 < 32; v86++) { + loop27: for (int v87 = 0; v87 < 16; v87++) { + loop28: for (int v88 = 0; v88 < 16; v88++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop29: for (int v89 = 0; v89 < 1; v89++) { + loop30: for (int v90 = 0; v90 < 1; v90++) { + loop31: for (int v91 = 0; v91 < 8; v91++) { + if ((v87 + v90) == 0) { + float v92 = v80[v91][v89].read(); + v85[(v91 + (v88 * 8))][(v86 + v89)] = v92; + } + float v93 = v85[(v91 + (v88 * 8))][(v86 + v89)]; + if ((v91 + (v88 * 8)) == 0) { + float v94 = v79[v89][v90].read(); + v84[(v86 + v89)][(v87 + v90)] = v94; + } + float v95 = v84[(v86 + v89)][(v87 + v90)]; + if ((v86 + v89) == 0) { + v83[(v91 + (v88 * 8))][(v87 + v90)] = v82; + } + float v96 = v83[(v91 + (v88 * 8))][(v87 + v90)]; + float v97 = v93 * v95; + float v98 = v96 + v97; + v83[(v91 + (v88 * 8))][(v87 + v90)] = v98; + if (((v86 + v89) - 31) == 0) { + float v99 = v83[(v91 + (v88 * 8))][(v87 + v90)]; + v81[v91][v90].write(v99); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v100[4][8], + hls::stream v101[1][4], + hls::stream v102[1][8], + float v103 +) { + float v104[16][128]; + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=8 + + float v105[128][128]; + #pragma HLS array_partition variable=v105 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=8 + + float v106[16][128]; + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + loop32: for (int v107 = 0; v107 < 32; v107++) { + loop33: for (int v108 = 0; v108 < 16; v108++) { + loop34: for (int v109 = 0; v109 < 16; v109++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop35: for (int v110 = 0; v110 < 4; v110++) { + loop36: for (int v111 = 0; v111 < 8; v111++) { + loop37: for (int v112 = 0; v112 < 1; v112++) { + if ((v111 + (v108 * 8)) == 0) { + float v113 = v101[v112][v110].read(); + v106[(v109 + v112)][(v110 + (v107 * 4))] = v113; + } + float v114 = v106[(v109 + v112)][(v110 + (v107 * 4))]; + if ((v109 + v112) == 0) { + float v115 = v100[v110][v111].read(); + v105[(v110 + (v107 * 4))][(v111 + (v108 * 8))] = v115; + } + float v116 = v105[(v110 + (v107 * 4))][(v111 + (v108 * 8))]; + if ((v110 + (v107 * 4)) == 0) { + v104[(v109 + v112)][(v111 + (v108 * 8))] = v103; + } + float v117 = v104[(v109 + v112)][(v111 + (v108 * 8))]; + float v118 = v114 * v116; + float v119 = v117 + v118; + v104[(v109 + v112)][(v111 + (v108 * 8))] = v119; + if (((v110 + (v107 * 4)) - 127) == 0) { + float v120 = v104[(v109 + v112)][(v111 + (v108 * 8))]; + v102[v112][v111].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + hls::stream v121[2][1], + hls::stream v122[8][2], + float v123[128][16], + float v124 +) { + #pragma HLS array_partition variable=v123 cyclic dim=1 factor=8 + + float v125[128][16]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=8 + + float v126[32][16]; + #pragma HLS array_partition variable=v126 cyclic dim=1 factor=2 + + float v127[128][32]; + #pragma HLS array_partition variable=v127 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v127 cyclic dim=2 factor=2 + + loop38: for (int v128 = 0; v128 < 16; v128++) { + loop39: for (int v129 = 0; v129 < 16; v129++) { + loop40: for (int v130 = 0; v130 < 16; v130++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v131 = 0; v131 < 2; v131++) { + loop42: for (int v132 = 0; v132 < 1; v132++) { + loop43: for (int v133 = 0; v133 < 8; v133++) { + if ((v129 + v132) == 0) { + float v134 = v122[v133][v131].read(); + v127[(v133 + (v130 * 8))][(v131 + (v128 * 2))] = v134; + } + float v135 = v127[(v133 + (v130 * 8))][(v131 + (v128 * 2))]; + if ((v133 + (v130 * 8)) == 0) { + float v136 = v121[v131][v132].read(); + v126[(v131 + (v128 * 2))][(v129 + v132)] = v136; + } + float v137 = v126[(v131 + (v128 * 2))][(v129 + v132)]; + if ((v131 + (v128 * 2)) == 0) { + v125[(v133 + (v130 * 8))][(v129 + v132)] = v124; + } + float v138 = v125[(v133 + (v130 * 8))][(v129 + v132)]; + float v139 = v135 * v137; + float v140 = v138 + v139; + v125[(v133 + (v130 * 8))][(v129 + v132)] = v140; + if (((v131 + (v128 * 2)) - 31) == 0) { + float v141 = v125[(v133 + (v130 * 8))][(v129 + v132)]; + v123[(v133 + (v130 * 8))][(v129 + v132)] = v141; + } + } + } + } + } + } + } + return ; +} + +void node8( + hls::stream v142[8][8], + hls::stream v143[1][8], + hls::stream v144[1][8], + float v145 +) { + float v146[16][128]; + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=8 + + float v147[128][128]; + #pragma HLS array_partition variable=v147 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v147 cyclic dim=2 factor=8 + + float v148[16][128]; + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=8 + + loop44: for (int v149 = 0; v149 < 16; v149++) { + loop45: for (int v150 = 0; v150 < 16; v150++) { + loop46: for (int v151 = 0; v151 < 16; v151++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop47: for (int v152 = 0; v152 < 8; v152++) { + loop48: for (int v153 = 0; v153 < 8; v153++) { + loop49: for (int v154 = 0; v154 < 1; v154++) { + if ((v153 + (v150 * 8)) == 0) { + float v155 = v143[v154][v152].read(); + v148[(v151 + v154)][(v152 + (v149 * 8))] = v155; + } + float v156 = v148[(v151 + v154)][(v152 + (v149 * 8))]; + if ((v151 + v154) == 0) { + float v157 = v142[v152][v153].read(); + v147[(v152 + (v149 * 8))][(v153 + (v150 * 8))] = v157; + } + float v158 = v147[(v152 + (v149 * 8))][(v153 + (v150 * 8))]; + if ((v152 + (v149 * 8)) == 0) { + v146[(v151 + v154)][(v153 + (v150 * 8))] = v145; + } + float v159 = v146[(v151 + v154)][(v153 + (v150 * 8))]; + float v160 = v156 * v158; + float v161 = v159 + v160; + v146[(v151 + v154)][(v153 + (v150 * 8))] = v161; + if (((v152 + (v149 * 8)) - 127) == 0) { + float v162 = v146[(v151 + v154)][(v153 + (v150 * 8))]; + v144[v154][v153].write(v162); + } + } + } + } + } + } + } + return ; +} + +void node9( + float v163[16][16], + float v164[32][16], + hls::stream v165[1][1], + float v166 +) { + float v167[32][16]; + loop50: for (int v168 = 0; v168 < 32; v168++) { + loop51: for (int v169 = 0; v169 < 16; v169++) { + loop52: for (int v170 = 0; v170 < 16; v170++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop53: for (int v171 = 0; v171 < 1; v171++) { + loop54: for (int v172 = 0; v172 < 1; v172++) { + loop55: for (int v173 = 0; v173 < 1; v173++) { + float v174 = v164[(v168 + v171)][(v169 + v172)]; + float v175 = v163[(v169 + v172)][(v170 + v173)]; + if ((v169 + v172) == 0) { + v167[(v168 + v171)][(v170 + v173)] = v166; + } + float v176 = v167[(v168 + v171)][(v170 + v173)]; + float v177 = v174 * v175; + float v178 = v176 + v177; + v167[(v168 + v171)][(v170 + v173)] = v178; + if (((v169 + v172) - 15) == 0) { + float v179 = v167[(v168 + v171)][(v170 + v173)]; + v165[v171][v173].write(v179); + } + } + } + } + } + } + } + return ; +} + +void node10( + float v180[64][32], + float v181[128][64], + hls::stream v182[8][1], + float v183 +) { + #pragma HLS array_partition variable=v180 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v181 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v181 cyclic dim=2 factor=4 + + float v184[128][32]; + #pragma HLS array_partition variable=v184 cyclic dim=1 factor=8 + + loop56: for (int v185 = 0; v185 < 32; v185++) { + loop57: for (int v186 = 0; v186 < 16; v186++) { + loop58: for (int v187 = 0; v187 < 16; v187++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop59: for (int v188 = 0; v188 < 1; v188++) { + loop60: for (int v189 = 0; v189 < 4; v189++) { + loop61: for (int v190 = 0; v190 < 8; v190++) { + float v191 = v181[(v190 + (v187 * 8))][(v189 + (v186 * 4))]; + float v192 = v180[(v189 + (v186 * 4))][(v185 + v188)]; + if ((v189 + (v186 * 4)) == 0) { + v184[(v190 + (v187 * 8))][(v185 + v188)] = v183; + } + float v193 = v184[(v190 + (v187 * 8))][(v185 + v188)]; + float v194 = v191 * v192; + float v195 = v193 + v194; + v184[(v190 + (v187 * 8))][(v185 + v188)] = v195; + if (((v189 + (v186 * 4)) - 63) == 0) { + float v196 = v184[(v190 + (v187 * 8))][(v185 + v188)]; + v182[v190][v188].write(v196); + } + } + } + } + } + } + } + return ; +} + +void node11( + float v197[128][64], + float v198[64][128], + hls::stream v199[4][8], + float v200 +) { + #pragma HLS array_partition variable=v197 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v197 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v198 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v198 cyclic dim=2 factor=8 + + float v201[128][128]; + #pragma HLS array_partition variable=v201 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v201 cyclic dim=2 factor=8 + + loop62: for (int v202 = 0; v202 < 32; v202++) { + loop63: for (int v203 = 0; v203 < 16; v203++) { + loop64: for (int v204 = 0; v204 < 16; v204++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop65: for (int v205 = 0; v205 < 4; v205++) { + loop66: for (int v206 = 0; v206 < 4; v206++) { + loop67: for (int v207 = 0; v207 < 8; v207++) { + float v208 = v197[(v205 + (v202 * 4))][(v206 + (v203 * 4))]; + float v209 = v198[(v206 + (v203 * 4))][(v207 + (v204 * 8))]; + if ((v206 + (v203 * 4)) == 0) { + v201[(v205 + (v202 * 4))][(v207 + (v204 * 8))] = v200; + } + float v210 = v201[(v205 + (v202 * 4))][(v207 + (v204 * 8))]; + float v211 = v208 * v209; + float v212 = v210 + v211; + v201[(v205 + (v202 * 4))][(v207 + (v204 * 8))] = v212; + if (((v206 + (v203 * 4)) - 63) == 0) { + float v213 = v201[(v205 + (v202 * 4))][(v207 + (v204 * 8))]; + v199[v205][v207].write(v213); + } + } + } + } + } + } + } + return ; +} + +void node12( + float v214[16][32], + float v215[32][128], + hls::stream v216[1][4], + float v217 +) { + #pragma HLS array_partition variable=v214 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v215 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v215 cyclic dim=2 factor=4 + + float v218[16][128]; + #pragma HLS array_partition variable=v218 cyclic dim=2 factor=4 + + loop68: for (int v219 = 0; v219 < 32; v219++) { + loop69: for (int v220 = 0; v220 < 16; v220++) { + loop70: for (int v221 = 0; v221 < 16; v221++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v222 = 0; v222 < 4; v222++) { + loop72: for (int v223 = 0; v223 < 2; v223++) { + loop73: for (int v224 = 0; v224 < 1; v224++) { + float v225 = v214[(v221 + v224)][(v223 + (v220 * 2))]; + float v226 = v215[(v223 + (v220 * 2))][(v222 + (v219 * 4))]; + if ((v223 + (v220 * 2)) == 0) { + v218[(v221 + v224)][(v222 + (v219 * 4))] = v217; + } + float v227 = v218[(v221 + v224)][(v222 + (v219 * 4))]; + float v228 = v225 * v226; + float v229 = v227 + v228; + v218[(v221 + v224)][(v222 + (v219 * 4))] = v229; + if (((v223 + (v220 * 2)) - 31) == 0) { + float v230 = v218[(v221 + v224)][(v222 + (v219 * 4))]; + v216[v224][v222].write(v230); + } + } + } + } + } + } + } + return ; +} + +void node13( + float v231[32][16], + float v232[16][16], + hls::stream v233[2][1], + float v234 +) { + #pragma HLS array_partition variable=v231 cyclic dim=1 factor=2 + + float v235[32][16]; + #pragma HLS array_partition variable=v235 cyclic dim=1 factor=2 + + loop74: for (int v236 = 0; v236 < 16; v236++) { + loop75: for (int v237 = 0; v237 < 16; v237++) { + loop76: for (int v238 = 0; v238 < 16; v238++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop77: for (int v239 = 0; v239 < 2; v239++) { + loop78: for (int v240 = 0; v240 < 1; v240++) { + loop79: for (int v241 = 0; v241 < 1; v241++) { + float v242 = v231[(v239 + (v236 * 2))][(v237 + v240)]; + float v243 = v232[(v237 + v240)][(v238 + v241)]; + if ((v237 + v240) == 0) { + v235[(v239 + (v236 * 2))][(v238 + v241)] = v234; + } + float v244 = v235[(v239 + (v236 * 2))][(v238 + v241)]; + float v245 = v242 * v243; + float v246 = v244 + v245; + v235[(v239 + (v236 * 2))][(v238 + v241)] = v246; + if (((v237 + v240) - 15) == 0) { + float v247 = v235[(v239 + (v236 * 2))][(v238 + v241)]; + v233[v239][v241].write(v247); + } + } + } + } + } + } + } + return ; +} + +void node14( + float v248[64][32], + float v249[128][64], + hls::stream v250[8][2], + float v251 +) { + #pragma HLS array_partition variable=v248 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v248 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v249 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v249 cyclic dim=2 factor=4 + + float v252[128][32]; + #pragma HLS array_partition variable=v252 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v252 cyclic dim=2 factor=2 + + loop80: for (int v253 = 0; v253 < 16; v253++) { + loop81: for (int v254 = 0; v254 < 16; v254++) { + loop82: for (int v255 = 0; v255 < 16; v255++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop83: for (int v256 = 0; v256 < 2; v256++) { + loop84: for (int v257 = 0; v257 < 4; v257++) { + loop85: for (int v258 = 0; v258 < 8; v258++) { + float v259 = v249[(v258 + (v255 * 8))][(v257 + (v254 * 4))]; + float v260 = v248[(v257 + (v254 * 4))][(v256 + (v253 * 2))]; + if ((v257 + (v254 * 4)) == 0) { + v252[(v258 + (v255 * 8))][(v256 + (v253 * 2))] = v251; + } + float v261 = v252[(v258 + (v255 * 8))][(v256 + (v253 * 2))]; + float v262 = v259 * v260; + float v263 = v261 + v262; + v252[(v258 + (v255 * 8))][(v256 + (v253 * 2))] = v263; + if (((v257 + (v254 * 4)) - 63) == 0) { + float v264 = v252[(v258 + (v255 * 8))][(v256 + (v253 * 2))]; + v250[v258][v256].write(v264); + } + } + } + } + } + } + } + return ; +} + +void node15( + float v265[128][64], + float v266[64][128], + hls::stream v267[8][8], + float v268 +) { + #pragma HLS array_partition variable=v265 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v265 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v266 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v266 cyclic dim=2 factor=8 + + float v269[128][128]; + #pragma HLS array_partition variable=v269 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v269 cyclic dim=2 factor=8 + + loop86: for (int v270 = 0; v270 < 16; v270++) { + loop87: for (int v271 = 0; v271 < 32; v271++) { + loop88: for (int v272 = 0; v272 < 16; v272++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop89: for (int v273 = 0; v273 < 8; v273++) { + loop90: for (int v274 = 0; v274 < 2; v274++) { + loop91: for (int v275 = 0; v275 < 8; v275++) { + float v276 = v265[(v273 + (v270 * 8))][(v274 + (v271 * 2))]; + float v277 = v266[(v274 + (v271 * 2))][(v275 + (v272 * 8))]; + if ((v274 + (v271 * 2)) == 0) { + v269[(v273 + (v270 * 8))][(v275 + (v272 * 8))] = v268; + } + float v278 = v269[(v273 + (v270 * 8))][(v275 + (v272 * 8))]; + float v279 = v276 * v277; + float v280 = v278 + v279; + v269[(v273 + (v270 * 8))][(v275 + (v272 * 8))] = v280; + if (((v274 + (v271 * 2)) - 63) == 0) { + float v281 = v269[(v273 + (v270 * 8))][(v275 + (v272 * 8))]; + v267[v273][v275].write(v281); + } + } + } + } + } + } + } + return ; +} + +void node16( + float v282[32][128], + float v283[16][32], + hls::stream v284[1][8], + float v285 +) { + #pragma HLS array_partition variable=v282 cyclic dim=2 factor=8 + + float v286[16][128]; + #pragma HLS array_partition variable=v286 cyclic dim=2 factor=8 + + loop92: for (int v287 = 0; v287 < 16; v287++) { + loop93: for (int v288 = 0; v288 < 32; v288++) { + loop94: for (int v289 = 0; v289 < 16; v289++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop95: for (int v290 = 0; v290 < 8; v290++) { + loop96: for (int v291 = 0; v291 < 1; v291++) { + loop97: for (int v292 = 0; v292 < 1; v292++) { + float v293 = v283[(v289 + v292)][(v288 + v291)]; + float v294 = v282[(v288 + v291)][(v290 + (v287 * 8))]; + if ((v288 + v291) == 0) { + v286[(v289 + v292)][(v290 + (v287 * 8))] = v285; + } + float v295 = v286[(v289 + v292)][(v290 + (v287 * 8))]; + float v296 = v293 * v294; + float v297 = v295 + v296; + v286[(v289 + v292)][(v290 + (v287 * 8))] = v297; + if (((v288 + v291) - 31) == 0) { + float v298 = v286[(v289 + v292)][(v290 + (v287 * 8))]; + v284[v292][v290].write(v298); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v299[16][32], + float v300[32][128], + float v301[128][64], + float v302[64][128], + float v303[128][64], + float v304[64][32], + float v305[32][16], + float v306[16][16], + float v307[16][32], + float v308[32][128], + float v309[128][64], + float v310[64][128], + float v311[128][64], + float v312[64][32], + float v313[32][16], + float v314[16][16], + float v315[16][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v300 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v301 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v301 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v302 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v302 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v303 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v303 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v304 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v304 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v305 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v307 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v308 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v308 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v309 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v309 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v310 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v310 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v311 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v311 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v312 cyclic dim=1 factor=4 + + hls::stream v316[1][1]; + #pragma HLS STREAM variable=v316 depth=256 + hls::stream v317[1][1]; + #pragma HLS STREAM variable=v317 depth=256 + hls::stream v318[1][1]; + #pragma HLS STREAM variable=v318 depth=256 + hls::stream v319[1][1]; + #pragma HLS STREAM variable=v319 depth=256 + hls::stream v320[8][1]; + #pragma HLS STREAM variable=v320 depth=256 + hls::stream v321[1][8]; + #pragma HLS STREAM variable=v321 depth=256 + float v322[128][16]; + #pragma HLS array_partition variable=v322 cyclic dim=1 factor=8 + + hls::stream v323[1][8]; + #pragma HLS STREAM variable=v323 depth=256 + hls::stream v324[1][1]; + #pragma HLS STREAM variable=v324 depth=512 + hls::stream v325[8][1]; + #pragma HLS STREAM variable=v325 depth=512 + hls::stream v326[4][8]; + #pragma HLS STREAM variable=v326 depth=512 + hls::stream v327[1][4]; + #pragma HLS STREAM variable=v327 depth=512 + hls::stream v328[2][1]; + #pragma HLS STREAM variable=v328 depth=256 + hls::stream v329[8][2]; + #pragma HLS STREAM variable=v329 depth=256 + hls::stream v330[8][8]; + #pragma HLS STREAM variable=v330 depth=256 + hls::stream v331[1][8]; + #pragma HLS STREAM variable=v331 depth=256 + node16(v300, v299, v331, 0.000000); + node15(v301, v302, v330, 0.000000); + node14(v304, v303, v329, 0.000000); + node13(v305, v306, v328, 0.000000); + node12(v307, v308, v327, 0.000000); + node11(v309, v310, v326, 0.000000); + node10(v312, v311, v325, 0.000000); + node9(v314, v313, v324, 0.000000); + node8(v330, v331, v323, 0.000000); + node7(v328, v329, v322, 0.000000); + node6(v326, v327, v321, 0.000000); + node5(v324, v325, v320, 0.000000); + node4(v322, v323, v319, 0.000000); + node3(v321, v320, v318, 0.000000); + node2(v318, v319, v317, 0.000000); + node1(v317, v316, 1000000.000000); + node0(v316, v315); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu__opt5/src/k15mmtree_relu.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu__opt5/src/k15mmtree_relu.cpp new file mode 100644 index 000000000000..0c4211bc27e4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu__opt5/src/k15mmtree_relu.cpp @@ -0,0 +1,1295 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + hls::stream v8[4][4], + float v9, + float v10 +) { + loop4: for (int v11 = 0; v11 < 16; v11++) { + loop5: for (int v12 = 0; v12 < 16; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 4; v13++) { + loop7: for (int v14 = 0; v14 < 4; v14++) { + float v15 = v7[v13][v14].read(); + bool v16 = v15 > v9; + float v17 = v16 ? (float)v15 : (float)v9; + float v18 = v17 / v10; + v8[v13][v14].write(v18); + } + } + } + } + return ; +} + +void node2( + hls::stream v19[4][2], + hls::stream v20[2][4], + hls::stream v21[4][4], + float v22 +) { + float v23[64][64]; + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=4 + + float v24[64][64]; + #pragma HLS array_partition variable=v24 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v24 cyclic dim=2 factor=4 + + float v25[64][64]; + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=2 + + loop8: for (int v26 = 0; v26 < 32; v26++) { + loop9: for (int v27 = 0; v27 < 16; v27++) { + loop10: for (int v28 = 0; v28 < 16; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v29 = 0; v29 < 2; v29++) { + loop12: for (int v30 = 0; v30 < 4; v30++) { + loop13: for (int v31 = 0; v31 < 4; v31++) { + if ((v31 + (v28 * 4)) == 0) { + float v32 = v19[v30][v29].read(); + v25[(v30 + (v27 * 4))][(v29 + (v26 * 2))] = v32; + } + float v33 = v25[(v30 + (v27 * 4))][(v29 + (v26 * 2))]; + if ((v30 + (v27 * 4)) == 0) { + float v34 = v20[v29][v31].read(); + v24[(v29 + (v26 * 2))][(v31 + (v28 * 4))] = v34; + } + float v35 = v24[(v29 + (v26 * 2))][(v31 + (v28 * 4))]; + if ((v29 + (v26 * 2)) == 0) { + v23[(v30 + (v27 * 4))][(v31 + (v28 * 4))] = v22; + } + float v36 = v23[(v30 + (v27 * 4))][(v31 + (v28 * 4))]; + float v37 = v33 * v35; + float v38 = v36 + v37; + v23[(v30 + (v27 * 4))][(v31 + (v28 * 4))] = v38; + if (((v29 + (v26 * 2)) - 63) == 0) { + float v39 = v23[(v30 + (v27 * 4))][(v31 + (v28 * 4))]; + v21[v30][v31].write(v39); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v40[2][4], + hls::stream v41[2][4], + float v42 +) { + loop14: for (int v43 = 0; v43 < 32; v43++) { + loop15: for (int v44 = 0; v44 < 16; v44++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v45 = 0; v45 < 2; v45++) { + loop17: for (int v46 = 0; v46 < 4; v46++) { + float v47 = v40[v45][v46].read(); + bool v48 = v47 > v42; + float v49 = v48 ? (float)v47 : (float)v42; + v41[v45][v46].write(v49); + } + } + } + } + return ; +} + +void node4( + hls::stream v50[4][4], + hls::stream v51[2][4], + hls::stream v52[2][4], + float v53 +) { + float v54[64][64]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=4 + + float v55[64][64]; + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=4 + + float v56[64][64]; + #pragma HLS array_partition variable=v56 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v56 cyclic dim=2 factor=4 + + loop18: for (int v57 = 0; v57 < 32; v57++) { + loop19: for (int v58 = 0; v58 < 16; v58++) { + loop20: for (int v59 = 0; v59 < 16; v59++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop21: for (int v60 = 0; v60 < 2; v60++) { + loop22: for (int v61 = 0; v61 < 4; v61++) { + loop23: for (int v62 = 0; v62 < 4; v62++) { + if ((v62 + (v59 * 4)) == 0) { + float v63 = v51[v60][v61].read(); + v56[(v60 + (v57 * 2))][(v61 + (v58 * 4))] = v63; + } + float v64 = v56[(v60 + (v57 * 2))][(v61 + (v58 * 4))]; + if ((v60 + (v57 * 2)) == 0) { + float v65 = v50[v61][v62].read(); + v55[(v61 + (v58 * 4))][(v62 + (v59 * 4))] = v65; + } + float v66 = v55[(v61 + (v58 * 4))][(v62 + (v59 * 4))]; + if ((v61 + (v58 * 4)) == 0) { + v54[(v60 + (v57 * 2))][(v62 + (v59 * 4))] = v53; + } + float v67 = v54[(v60 + (v57 * 2))][(v62 + (v59 * 4))]; + float v68 = v64 * v66; + float v69 = v67 + v68; + v54[(v60 + (v57 * 2))][(v62 + (v59 * 4))] = v69; + if (((v61 + (v58 * 4)) - 63) == 0) { + float v70 = v54[(v60 + (v57 * 2))][(v62 + (v59 * 4))]; + v52[v60][v62].write(v70); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v71[4][2], + hls::stream v72[4][2], + float v73 +) { + loop24: for (int v74 = 0; v74 < 32; v74++) { + loop25: for (int v75 = 0; v75 < 16; v75++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v76 = 0; v76 < 2; v76++) { + loop27: for (int v77 = 0; v77 < 4; v77++) { + float v78 = v71[v77][v76].read(); + bool v79 = v78 > v73; + float v80 = v79 ? (float)v78 : (float)v73; + v72[v77][v76].write(v80); + } + } + } + } + return ; +} + +void node6( + hls::stream v81[4][4], + hls::stream v82[4][2], + hls::stream v83[4][2], + float v84 +) { + float v85[64][64]; + #pragma HLS array_partition variable=v85 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v85 cyclic dim=2 factor=2 + + float v86[64][64]; + #pragma HLS array_partition variable=v86 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v86 cyclic dim=2 factor=2 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + loop28: for (int v88 = 0; v88 < 32; v88++) { + loop29: for (int v89 = 0; v89 < 16; v89++) { + loop30: for (int v90 = 0; v90 < 16; v90++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v91 = 0; v91 < 2; v91++) { + loop32: for (int v92 = 0; v92 < 4; v92++) { + loop33: for (int v93 = 0; v93 < 4; v93++) { + if ((v91 + (v88 * 2)) == 0) { + float v94 = v81[v93][v92].read(); + v87[(v93 + (v90 * 4))][(v92 + (v89 * 4))] = v94; + } + float v95 = v87[(v93 + (v90 * 4))][(v92 + (v89 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + float v96 = v82[v92][v91].read(); + v86[(v92 + (v89 * 4))][(v91 + (v88 * 2))] = v96; + } + float v97 = v86[(v92 + (v89 * 4))][(v91 + (v88 * 2))]; + if ((v92 + (v89 * 4)) == 0) { + v85[(v93 + (v90 * 4))][(v91 + (v88 * 2))] = v84; + } + float v98 = v85[(v93 + (v90 * 4))][(v91 + (v88 * 2))]; + float v99 = v95 * v97; + float v100 = v98 + v99; + v85[(v93 + (v90 * 4))][(v91 + (v88 * 2))] = v100; + if (((v92 + (v89 * 4)) - 63) == 0) { + float v101 = v85[(v93 + (v90 * 4))][(v91 + (v88 * 2))]; + v83[v93][v91].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node7( + hls::stream v102[4][4], + hls::stream v103[4][4], + float v104 +) { + loop34: for (int v105 = 0; v105 < 16; v105++) { + loop35: for (int v106 = 0; v106 < 16; v106++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop36: for (int v107 = 0; v107 < 4; v107++) { + loop37: for (int v108 = 0; v108 < 4; v108++) { + float v109 = v102[v107][v108].read(); + bool v110 = v109 > v104; + float v111 = v110 ? (float)v109 : (float)v104; + v103[v107][v108].write(v111); + } + } + } + } + return ; +} + +void node8( + hls::stream v112[2][4], + hls::stream v113[4][2], + hls::stream v114[4][4], + float v115 +) { + float v116[64][64]; + #pragma HLS array_partition variable=v116 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v116 cyclic dim=2 factor=4 + + float v117[64][64]; + #pragma HLS array_partition variable=v117 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v117 cyclic dim=2 factor=4 + + float v118[64][64]; + #pragma HLS array_partition variable=v118 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v118 cyclic dim=2 factor=2 + + loop38: for (int v119 = 0; v119 < 32; v119++) { + loop39: for (int v120 = 0; v120 < 16; v120++) { + loop40: for (int v121 = 0; v121 < 16; v121++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v122 = 0; v122 < 2; v122++) { + loop42: for (int v123 = 0; v123 < 4; v123++) { + loop43: for (int v124 = 0; v124 < 4; v124++) { + if ((v124 + (v121 * 4)) == 0) { + float v125 = v113[v123][v122].read(); + v118[(v123 + (v120 * 4))][(v122 + (v119 * 2))] = v125; + } + float v126 = v118[(v123 + (v120 * 4))][(v122 + (v119 * 2))]; + if ((v123 + (v120 * 4)) == 0) { + float v127 = v112[v122][v124].read(); + v117[(v122 + (v119 * 2))][(v124 + (v121 * 4))] = v127; + } + float v128 = v117[(v122 + (v119 * 2))][(v124 + (v121 * 4))]; + if ((v122 + (v119 * 2)) == 0) { + v116[(v123 + (v120 * 4))][(v124 + (v121 * 4))] = v115; + } + float v129 = v116[(v123 + (v120 * 4))][(v124 + (v121 * 4))]; + float v130 = v126 * v128; + float v131 = v129 + v130; + v116[(v123 + (v120 * 4))][(v124 + (v121 * 4))] = v131; + if (((v122 + (v119 * 2)) - 63) == 0) { + float v132 = v116[(v123 + (v120 * 4))][(v124 + (v121 * 4))]; + v114[v123][v124].write(v132); + } + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v133[2][4], + hls::stream v134[2][4], + float v135 +) { + loop44: for (int v136 = 0; v136 < 32; v136++) { + loop45: for (int v137 = 0; v137 < 16; v137++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop46: for (int v138 = 0; v138 < 2; v138++) { + loop47: for (int v139 = 0; v139 < 4; v139++) { + float v140 = v133[v138][v139].read(); + bool v141 = v140 > v135; + float v142 = v141 ? (float)v140 : (float)v135; + v134[v138][v139].write(v142); + } + } + } + } + return ; +} + +void node10( + hls::stream v143[4][4], + hls::stream v144[2][4], + hls::stream v145[2][4], + float v146 +) { + float v147[64][64]; + #pragma HLS array_partition variable=v147 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v147 cyclic dim=2 factor=4 + + float v148[64][64]; + #pragma HLS array_partition variable=v148 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=4 + + float v149[64][64]; + #pragma HLS array_partition variable=v149 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v149 cyclic dim=2 factor=4 + + loop48: for (int v150 = 0; v150 < 16; v150++) { + loop49: for (int v151 = 0; v151 < 32; v151++) { + loop50: for (int v152 = 0; v152 < 16; v152++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v153 = 0; v153 < 4; v153++) { + loop52: for (int v154 = 0; v154 < 2; v154++) { + loop53: for (int v155 = 0; v155 < 4; v155++) { + if ((v155 + (v152 * 4)) == 0) { + float v156 = v144[v154][v153].read(); + v149[(v154 + (v151 * 2))][(v153 + (v150 * 4))] = v156; + } + float v157 = v149[(v154 + (v151 * 2))][(v153 + (v150 * 4))]; + if ((v154 + (v151 * 2)) == 0) { + float v158 = v143[v153][v155].read(); + v148[(v153 + (v150 * 4))][(v155 + (v152 * 4))] = v158; + } + float v159 = v148[(v153 + (v150 * 4))][(v155 + (v152 * 4))]; + if ((v153 + (v150 * 4)) == 0) { + v147[(v154 + (v151 * 2))][(v155 + (v152 * 4))] = v146; + } + float v160 = v147[(v154 + (v151 * 2))][(v155 + (v152 * 4))]; + float v161 = v157 * v159; + float v162 = v160 + v161; + v147[(v154 + (v151 * 2))][(v155 + (v152 * 4))] = v162; + if (((v153 + (v150 * 4)) - 63) == 0) { + float v163 = v147[(v154 + (v151 * 2))][(v155 + (v152 * 4))]; + v145[v154][v155].write(v163); + } + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v164[4][2], + hls::stream v165[4][2], + float v166 +) { + loop54: for (int v167 = 0; v167 < 32; v167++) { + loop55: for (int v168 = 0; v168 < 16; v168++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop56: for (int v169 = 0; v169 < 2; v169++) { + loop57: for (int v170 = 0; v170 < 4; v170++) { + float v171 = v164[v170][v169].read(); + bool v172 = v171 > v166; + float v173 = v172 ? (float)v171 : (float)v166; + v165[v170][v169].write(v173); + } + } + } + } + return ; +} + +void node12( + hls::stream v174[4][4], + hls::stream v175[4][2], + hls::stream v176[4][2], + float v177 +) { + float v178[64][64]; + #pragma HLS array_partition variable=v178 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v178 cyclic dim=2 factor=2 + + float v179[64][64]; + #pragma HLS array_partition variable=v179 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v179 cyclic dim=2 factor=2 + + float v180[64][64]; + #pragma HLS array_partition variable=v180 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v180 cyclic dim=2 factor=4 + + loop58: for (int v181 = 0; v181 < 16; v181++) { + loop59: for (int v182 = 0; v182 < 32; v182++) { + loop60: for (int v183 = 0; v183 < 16; v183++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop61: for (int v184 = 0; v184 < 4; v184++) { + loop62: for (int v185 = 0; v185 < 2; v185++) { + loop63: for (int v186 = 0; v186 < 4; v186++) { + if ((v185 + (v182 * 2)) == 0) { + float v187 = v174[v186][v184].read(); + v180[(v186 + (v183 * 4))][(v184 + (v181 * 4))] = v187; + } + float v188 = v180[(v186 + (v183 * 4))][(v184 + (v181 * 4))]; + if ((v186 + (v183 * 4)) == 0) { + float v189 = v175[v184][v185].read(); + v179[(v184 + (v181 * 4))][(v185 + (v182 * 2))] = v189; + } + float v190 = v179[(v184 + (v181 * 4))][(v185 + (v182 * 2))]; + if ((v184 + (v181 * 4)) == 0) { + v178[(v186 + (v183 * 4))][(v185 + (v182 * 2))] = v177; + } + float v191 = v178[(v186 + (v183 * 4))][(v185 + (v182 * 2))]; + float v192 = v188 * v190; + float v193 = v191 + v192; + v178[(v186 + (v183 * 4))][(v185 + (v182 * 2))] = v193; + if (((v184 + (v181 * 4)) - 63) == 0) { + float v194 = v178[(v186 + (v183 * 4))][(v185 + (v182 * 2))]; + v176[v186][v185].write(v194); + } + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v195[4][4], + hls::stream v196[4][4], + float v197 +) { + loop64: for (int v198 = 0; v198 < 16; v198++) { + loop65: for (int v199 = 0; v199 < 16; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop66: for (int v200 = 0; v200 < 4; v200++) { + loop67: for (int v201 = 0; v201 < 4; v201++) { + float v202 = v195[v201][v200].read(); + bool v203 = v202 > v197; + float v204 = v203 ? (float)v202 : (float)v197; + v196[v201][v200].write(v204); + } + } + } + } + return ; +} + +void node14( + hls::stream v205[4][2], + hls::stream v206[2][4], + hls::stream v207[4][4], + float v208 +) { + float v209[64][64]; + #pragma HLS array_partition variable=v209 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v209 cyclic dim=2 factor=4 + + float v210[64][64]; + #pragma HLS array_partition variable=v210 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v210 cyclic dim=2 factor=4 + + float v211[64][64]; + #pragma HLS array_partition variable=v211 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v211 cyclic dim=2 factor=2 + + loop68: for (int v212 = 0; v212 < 32; v212++) { + loop69: for (int v213 = 0; v213 < 16; v213++) { + loop70: for (int v214 = 0; v214 < 16; v214++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v215 = 0; v215 < 2; v215++) { + loop72: for (int v216 = 0; v216 < 4; v216++) { + loop73: for (int v217 = 0; v217 < 4; v217++) { + if ((v216 + (v213 * 4)) == 0) { + float v218 = v205[v217][v215].read(); + v211[(v217 + (v214 * 4))][(v215 + (v212 * 2))] = v218; + } + float v219 = v211[(v217 + (v214 * 4))][(v215 + (v212 * 2))]; + if ((v217 + (v214 * 4)) == 0) { + float v220 = v206[v215][v216].read(); + v210[(v215 + (v212 * 2))][(v216 + (v213 * 4))] = v220; + } + float v221 = v210[(v215 + (v212 * 2))][(v216 + (v213 * 4))]; + if ((v215 + (v212 * 2)) == 0) { + v209[(v217 + (v214 * 4))][(v216 + (v213 * 4))] = v208; + } + float v222 = v209[(v217 + (v214 * 4))][(v216 + (v213 * 4))]; + float v223 = v219 * v221; + float v224 = v222 + v223; + v209[(v217 + (v214 * 4))][(v216 + (v213 * 4))] = v224; + if (((v215 + (v212 * 2)) - 63) == 0) { + float v225 = v209[(v217 + (v214 * 4))][(v216 + (v213 * 4))]; + v207[v217][v216].write(v225); + } + } + } + } + } + } + } + return ; +} + +void node15( + hls::stream v226[2][4], + hls::stream v227[2][4], + float v228 +) { + loop74: for (int v229 = 0; v229 < 32; v229++) { + loop75: for (int v230 = 0; v230 < 16; v230++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v231 = 0; v231 < 2; v231++) { + loop77: for (int v232 = 0; v232 < 4; v232++) { + float v233 = v226[v231][v232].read(); + bool v234 = v233 > v228; + float v235 = v234 ? (float)v233 : (float)v228; + v227[v231][v232].write(v235); + } + } + } + } + return ; +} + +void node16( + float v236[64][64], + float v237[64][64], + hls::stream v238[2][4], + float v239 +) { + #pragma HLS array_partition variable=v236 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v236 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v237 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v237 cyclic dim=2 factor=4 + + float v240[64][64]; + #pragma HLS array_partition variable=v240 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v240 cyclic dim=2 factor=4 + + loop78: for (int v241 = 0; v241 < 32; v241++) { + loop79: for (int v242 = 0; v242 < 16; v242++) { + loop80: for (int v243 = 0; v243 < 16; v243++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v244 = 0; v244 < 2; v244++) { + loop82: for (int v245 = 0; v245 < 4; v245++) { + loop83: for (int v246 = 0; v246 < 4; v246++) { + float v247 = v237[(v244 + (v241 * 2))][(v245 + (v242 * 4))]; + float v248 = v236[(v245 + (v242 * 4))][(v246 + (v243 * 4))]; + if ((v245 + (v242 * 4)) == 0) { + v240[(v244 + (v241 * 2))][(v246 + (v243 * 4))] = v239; + } + float v249 = v240[(v244 + (v241 * 2))][(v246 + (v243 * 4))]; + float v250 = v247 * v248; + float v251 = v249 + v250; + v240[(v244 + (v241 * 2))][(v246 + (v243 * 4))] = v251; + if (((v245 + (v242 * 4)) - 63) == 0) { + float v252 = v240[(v244 + (v241 * 2))][(v246 + (v243 * 4))]; + v238[v244][v246].write(v252); + } + } + } + } + } + } + } + return ; +} + +void node17( + hls::stream v253[4][2], + hls::stream v254[4][2], + float v255 +) { + loop84: for (int v256 = 0; v256 < 32; v256++) { + loop85: for (int v257 = 0; v257 < 16; v257++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v258 = 0; v258 < 2; v258++) { + loop87: for (int v259 = 0; v259 < 4; v259++) { + float v260 = v253[v259][v258].read(); + bool v261 = v260 > v255; + float v262 = v261 ? (float)v260 : (float)v255; + v254[v259][v258].write(v262); + } + } + } + } + return ; +} + +void node18( + float v263[64][64], + float v264[64][64], + hls::stream v265[4][2], + float v266 +) { + #pragma HLS array_partition variable=v263 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v263 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v264 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v264 cyclic dim=2 factor=2 + + float v267[64][64]; + #pragma HLS array_partition variable=v267 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v267 cyclic dim=2 factor=2 + + loop88: for (int v268 = 0; v268 < 32; v268++) { + loop89: for (int v269 = 0; v269 < 16; v269++) { + loop90: for (int v270 = 0; v270 < 16; v270++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop91: for (int v271 = 0; v271 < 2; v271++) { + loop92: for (int v272 = 0; v272 < 4; v272++) { + loop93: for (int v273 = 0; v273 < 4; v273++) { + float v274 = v263[(v273 + (v270 * 4))][(v272 + (v269 * 4))]; + float v275 = v264[(v272 + (v269 * 4))][(v271 + (v268 * 2))]; + if ((v272 + (v269 * 4)) == 0) { + v267[(v273 + (v270 * 4))][(v271 + (v268 * 2))] = v266; + } + float v276 = v267[(v273 + (v270 * 4))][(v271 + (v268 * 2))]; + float v277 = v274 * v275; + float v278 = v276 + v277; + v267[(v273 + (v270 * 4))][(v271 + (v268 * 2))] = v278; + if (((v272 + (v269 * 4)) - 63) == 0) { + float v279 = v267[(v273 + (v270 * 4))][(v271 + (v268 * 2))]; + v265[v273][v271].write(v279); + } + } + } + } + } + } + } + return ; +} + +void node19( + hls::stream v280[4][4], + hls::stream v281[4][4], + float v282 +) { + loop94: for (int v283 = 0; v283 < 16; v283++) { + loop95: for (int v284 = 0; v284 < 16; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop96: for (int v285 = 0; v285 < 4; v285++) { + loop97: for (int v286 = 0; v286 < 4; v286++) { + float v287 = v280[v285][v286].read(); + bool v288 = v287 > v282; + float v289 = v288 ? (float)v287 : (float)v282; + v281[v285][v286].write(v289); + } + } + } + } + return ; +} + +void node20( + float v290[64][64], + float v291[64][64], + hls::stream v292[4][4], + float v293 +) { + #pragma HLS array_partition variable=v290 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v290 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v291 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v291 cyclic dim=2 factor=4 + + float v294[64][64]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=4 + + loop98: for (int v295 = 0; v295 < 16; v295++) { + loop99: for (int v296 = 0; v296 < 16; v296++) { + loop100: for (int v297 = 0; v297 < 16; v297++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop101: for (int v298 = 0; v298 < 4; v298++) { + loop102: for (int v299 = 0; v299 < 4; v299++) { + loop103: for (int v300 = 0; v300 < 4; v300++) { + float v301 = v291[(v298 + (v295 * 4))][(v299 + (v296 * 4))]; + float v302 = v290[(v299 + (v296 * 4))][(v300 + (v297 * 4))]; + if ((v299 + (v296 * 4)) == 0) { + v294[(v298 + (v295 * 4))][(v300 + (v297 * 4))] = v293; + } + float v303 = v294[(v298 + (v295 * 4))][(v300 + (v297 * 4))]; + float v304 = v301 * v302; + float v305 = v303 + v304; + v294[(v298 + (v295 * 4))][(v300 + (v297 * 4))] = v305; + if (((v299 + (v296 * 4)) - 63) == 0) { + float v306 = v294[(v298 + (v295 * 4))][(v300 + (v297 * 4))]; + v292[v298][v300].write(v306); + } + } + } + } + } + } + } + return ; +} + +void node21( + hls::stream v307[2][4], + hls::stream v308[2][4], + float v309 +) { + loop104: for (int v310 = 0; v310 < 16; v310++) { + loop105: for (int v311 = 0; v311 < 32; v311++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop106: for (int v312 = 0; v312 < 4; v312++) { + loop107: for (int v313 = 0; v313 < 2; v313++) { + float v314 = v307[v313][v312].read(); + bool v315 = v314 > v309; + float v316 = v315 ? (float)v314 : (float)v309; + v308[v313][v312].write(v316); + } + } + } + } + return ; +} + +void node22( + float v317[64][64], + float v318[64][64], + hls::stream v319[2][4], + float v320 +) { + #pragma HLS array_partition variable=v317 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v317 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v318 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v318 cyclic dim=2 factor=4 + + float v321[64][64]; + #pragma HLS array_partition variable=v321 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v321 cyclic dim=2 factor=4 + + loop108: for (int v322 = 0; v322 < 16; v322++) { + loop109: for (int v323 = 0; v323 < 16; v323++) { + loop110: for (int v324 = 0; v324 < 32; v324++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop111: for (int v325 = 0; v325 < 4; v325++) { + loop112: for (int v326 = 0; v326 < 4; v326++) { + loop113: for (int v327 = 0; v327 < 2; v327++) { + float v328 = v317[(v327 + (v324 * 2))][(v326 + (v323 * 4))]; + float v329 = v318[(v326 + (v323 * 4))][(v325 + (v322 * 4))]; + if ((v326 + (v323 * 4)) == 0) { + v321[(v327 + (v324 * 2))][(v325 + (v322 * 4))] = v320; + } + float v330 = v321[(v327 + (v324 * 2))][(v325 + (v322 * 4))]; + float v331 = v328 * v329; + float v332 = v330 + v331; + v321[(v327 + (v324 * 2))][(v325 + (v322 * 4))] = v332; + if (((v326 + (v323 * 4)) - 63) == 0) { + float v333 = v321[(v327 + (v324 * 2))][(v325 + (v322 * 4))]; + v319[v327][v325].write(v333); + } + } + } + } + } + } + } + return ; +} + +void node23( + hls::stream v334[4][2], + hls::stream v335[4][2], + float v336 +) { + loop114: for (int v337 = 0; v337 < 16; v337++) { + loop115: for (int v338 = 0; v338 < 32; v338++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop116: for (int v339 = 0; v339 < 4; v339++) { + loop117: for (int v340 = 0; v340 < 2; v340++) { + float v341 = v334[v339][v340].read(); + bool v342 = v341 > v336; + float v343 = v342 ? (float)v341 : (float)v336; + v335[v339][v340].write(v343); + } + } + } + } + return ; +} + +void node24( + float v344[64][64], + float v345[64][64], + hls::stream v346[4][2], + float v347 +) { + #pragma HLS array_partition variable=v344 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v344 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v345 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v345 cyclic dim=2 factor=2 + + float v348[64][64]; + #pragma HLS array_partition variable=v348 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v348 cyclic dim=2 factor=2 + + loop118: for (int v349 = 0; v349 < 16; v349++) { + loop119: for (int v350 = 0; v350 < 16; v350++) { + loop120: for (int v351 = 0; v351 < 32; v351++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop121: for (int v352 = 0; v352 < 4; v352++) { + loop122: for (int v353 = 0; v353 < 4; v353++) { + loop123: for (int v354 = 0; v354 < 2; v354++) { + float v355 = v344[(v352 + (v349 * 4))][(v353 + (v350 * 4))]; + float v356 = v345[(v353 + (v350 * 4))][(v354 + (v351 * 2))]; + if ((v353 + (v350 * 4)) == 0) { + v348[(v352 + (v349 * 4))][(v354 + (v351 * 2))] = v347; + } + float v357 = v348[(v352 + (v349 * 4))][(v354 + (v351 * 2))]; + float v358 = v355 * v356; + float v359 = v357 + v358; + v348[(v352 + (v349 * 4))][(v354 + (v351 * 2))] = v359; + if (((v353 + (v350 * 4)) - 63) == 0) { + float v360 = v348[(v352 + (v349 * 4))][(v354 + (v351 * 2))]; + v346[v352][v354].write(v360); + } + } + } + } + } + } + } + return ; +} + +void node25( + hls::stream v361[4][4], + hls::stream v362[4][4], + float v363 +) { + loop124: for (int v364 = 0; v364 < 16; v364++) { + loop125: for (int v365 = 0; v365 < 16; v365++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop126: for (int v366 = 0; v366 < 4; v366++) { + loop127: for (int v367 = 0; v367 < 4; v367++) { + float v368 = v361[v367][v366].read(); + bool v369 = v368 > v363; + float v370 = v369 ? (float)v368 : (float)v363; + v362[v367][v366].write(v370); + } + } + } + } + return ; +} + +void node26( + float v371[64][64], + float v372[64][64], + hls::stream v373[4][4], + float v374 +) { + #pragma HLS array_partition variable=v371 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v371 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v372 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v372 cyclic dim=2 factor=4 + + float v375[64][64]; + #pragma HLS array_partition variable=v375 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v375 cyclic dim=2 factor=4 + + loop128: for (int v376 = 0; v376 < 16; v376++) { + loop129: for (int v377 = 0; v377 < 32; v377++) { + loop130: for (int v378 = 0; v378 < 16; v378++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop131: for (int v379 = 0; v379 < 4; v379++) { + loop132: for (int v380 = 0; v380 < 2; v380++) { + loop133: for (int v381 = 0; v381 < 4; v381++) { + float v382 = v371[(v381 + (v378 * 4))][(v380 + (v377 * 2))]; + float v383 = v372[(v380 + (v377 * 2))][(v379 + (v376 * 4))]; + if ((v380 + (v377 * 2)) == 0) { + v375[(v381 + (v378 * 4))][(v379 + (v376 * 4))] = v374; + } + float v384 = v375[(v381 + (v378 * 4))][(v379 + (v376 * 4))]; + float v385 = v382 * v383; + float v386 = v384 + v385; + v375[(v381 + (v378 * 4))][(v379 + (v376 * 4))] = v386; + if (((v380 + (v377 * 2)) - 63) == 0) { + float v387 = v375[(v381 + (v378 * 4))][(v379 + (v376 * 4))]; + v373[v381][v379].write(v387); + } + } + } + } + } + } + } + return ; +} + +void node27( + hls::stream v388[2][4], + hls::stream v389[2][4], + float v390 +) { + loop134: for (int v391 = 0; v391 < 32; v391++) { + loop135: for (int v392 = 0; v392 < 16; v392++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v393 = 0; v393 < 2; v393++) { + loop137: for (int v394 = 0; v394 < 4; v394++) { + float v395 = v388[v393][v394].read(); + bool v396 = v395 > v390; + float v397 = v396 ? (float)v395 : (float)v390; + v389[v393][v394].write(v397); + } + } + } + } + return ; +} + +void node28( + float v398[64][64], + float v399[64][64], + hls::stream v400[2][4], + float v401 +) { + #pragma HLS array_partition variable=v398 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v398 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v399 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v399 cyclic dim=2 factor=4 + + float v402[64][64]; + #pragma HLS array_partition variable=v402 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v402 cyclic dim=2 factor=4 + + loop138: for (int v403 = 0; v403 < 32; v403++) { + loop139: for (int v404 = 0; v404 < 16; v404++) { + loop140: for (int v405 = 0; v405 < 16; v405++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop141: for (int v406 = 0; v406 < 2; v406++) { + loop142: for (int v407 = 0; v407 < 4; v407++) { + loop143: for (int v408 = 0; v408 < 4; v408++) { + float v409 = v399[(v406 + (v403 * 2))][(v407 + (v404 * 4))]; + float v410 = v398[(v407 + (v404 * 4))][(v408 + (v405 * 4))]; + if ((v407 + (v404 * 4)) == 0) { + v402[(v406 + (v403 * 2))][(v408 + (v405 * 4))] = v401; + } + float v411 = v402[(v406 + (v403 * 2))][(v408 + (v405 * 4))]; + float v412 = v409 * v410; + float v413 = v411 + v412; + v402[(v406 + (v403 * 2))][(v408 + (v405 * 4))] = v413; + if (((v407 + (v404 * 4)) - 63) == 0) { + float v414 = v402[(v406 + (v403 * 2))][(v408 + (v405 * 4))]; + v400[v406][v408].write(v414); + } + } + } + } + } + } + } + return ; +} + +void node29( + hls::stream v415[4][2], + hls::stream v416[4][2], + float v417 +) { + loop144: for (int v418 = 0; v418 < 32; v418++) { + loop145: for (int v419 = 0; v419 < 16; v419++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop146: for (int v420 = 0; v420 < 2; v420++) { + loop147: for (int v421 = 0; v421 < 4; v421++) { + float v422 = v415[v421][v420].read(); + bool v423 = v422 > v417; + float v424 = v423 ? (float)v422 : (float)v417; + v416[v421][v420].write(v424); + } + } + } + } + return ; +} + +void node30( + float v425[64][64], + float v426[64][64], + hls::stream v427[4][2], + float v428 +) { + #pragma HLS array_partition variable=v425 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v425 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v426 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v426 cyclic dim=2 factor=4 + + float v429[64][64]; + #pragma HLS array_partition variable=v429 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v429 cyclic dim=2 factor=2 + + loop148: for (int v430 = 0; v430 < 32; v430++) { + loop149: for (int v431 = 0; v431 < 16; v431++) { + loop150: for (int v432 = 0; v432 < 16; v432++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop151: for (int v433 = 0; v433 < 2; v433++) { + loop152: for (int v434 = 0; v434 < 4; v434++) { + loop153: for (int v435 = 0; v435 < 4; v435++) { + float v436 = v426[(v435 + (v432 * 4))][(v434 + (v431 * 4))]; + float v437 = v425[(v434 + (v431 * 4))][(v433 + (v430 * 2))]; + if ((v434 + (v431 * 4)) == 0) { + v429[(v435 + (v432 * 4))][(v433 + (v430 * 2))] = v428; + } + float v438 = v429[(v435 + (v432 * 4))][(v433 + (v430 * 2))]; + float v439 = v436 * v437; + float v440 = v438 + v439; + v429[(v435 + (v432 * 4))][(v433 + (v430 * 2))] = v440; + if (((v434 + (v431 * 4)) - 63) == 0) { + float v441 = v429[(v435 + (v432 * 4))][(v433 + (v430 * 2))]; + v427[v435][v433].write(v441); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v442[64][64], + float v443[64][64], + float v444[64][64], + float v445[64][64], + float v446[64][64], + float v447[64][64], + float v448[64][64], + float v449[64][64], + float v450[64][64], + float v451[64][64], + float v452[64][64], + float v453[64][64], + float v454[64][64], + float v455[64][64], + float v456[64][64], + float v457[64][64], + float v458[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v442 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v442 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v443 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v443 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v444 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v444 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v445 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v445 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v446 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v446 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v447 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v447 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v448 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v448 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v449 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v449 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v450 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v450 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v451 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v451 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v452 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v452 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v453 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v453 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v454 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v454 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v455 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v455 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v456 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v456 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v457 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v457 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v458 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v458 cyclic dim=2 factor=4 + + hls::stream v459[4][4]; + #pragma HLS STREAM variable=v459 depth=256 + hls::stream v460[4][4]; + #pragma HLS STREAM variable=v460 depth=256 + hls::stream v461[2][4]; + #pragma HLS STREAM variable=v461 depth=512 + hls::stream v462[2][4]; + #pragma HLS STREAM variable=v462 depth=512 + hls::stream v463[4][2]; + #pragma HLS STREAM variable=v463 depth=512 + hls::stream v464[4][2]; + #pragma HLS STREAM variable=v464 depth=512 + hls::stream v465[4][4]; + #pragma HLS STREAM variable=v465 depth=256 + hls::stream v466[4][4]; + #pragma HLS STREAM variable=v466 depth=256 + hls::stream v467[2][4]; + #pragma HLS STREAM variable=v467 depth=512 + hls::stream v468[2][4]; + #pragma HLS STREAM variable=v468 depth=512 + hls::stream v469[4][2]; + #pragma HLS STREAM variable=v469 depth=512 + hls::stream v470[4][2]; + #pragma HLS STREAM variable=v470 depth=512 + hls::stream v471[4][4]; + #pragma HLS STREAM variable=v471 depth=256 + hls::stream v472[4][4]; + #pragma HLS STREAM variable=v472 depth=256 + hls::stream v473[2][4]; + #pragma HLS STREAM variable=v473 depth=512 + hls::stream v474[2][4]; + #pragma HLS STREAM variable=v474 depth=512 + hls::stream v475[4][2]; + #pragma HLS STREAM variable=v475 depth=512 + hls::stream v476[4][2]; + #pragma HLS STREAM variable=v476 depth=512 + hls::stream v477[4][4]; + #pragma HLS STREAM variable=v477 depth=256 + hls::stream v478[4][4]; + #pragma HLS STREAM variable=v478 depth=256 + hls::stream v479[2][4]; + #pragma HLS STREAM variable=v479 depth=512 + hls::stream v480[2][4]; + #pragma HLS STREAM variable=v480 depth=512 + hls::stream v481[4][2]; + #pragma HLS STREAM variable=v481 depth=512 + hls::stream v482[4][2]; + #pragma HLS STREAM variable=v482 depth=512 + hls::stream v483[4][4]; + #pragma HLS STREAM variable=v483 depth=256 + hls::stream v484[4][4]; + #pragma HLS STREAM variable=v484 depth=256 + hls::stream v485[2][4]; + #pragma HLS STREAM variable=v485 depth=512 + hls::stream v486[2][4]; + #pragma HLS STREAM variable=v486 depth=512 + hls::stream v487[4][2]; + #pragma HLS STREAM variable=v487 depth=512 + hls::stream v488[4][2]; + #pragma HLS STREAM variable=v488 depth=512 + node30(v443, v442, v488, 0.000000); + node29(v488, v487, 0.000000); + node28(v445, v444, v486, 0.000000); + node27(v486, v485, 0.000000); + node26(v446, v447, v484, 0.000000); + node25(v484, v483, 0.000000); + node24(v448, v449, v482, 0.000000); + node23(v482, v481, 0.000000); + node22(v450, v451, v480, 0.000000); + node21(v480, v479, 0.000000); + node20(v453, v452, v478, 0.000000); + node19(v478, v477, 0.000000); + node18(v454, v455, v476, 0.000000); + node17(v476, v475, 0.000000); + node16(v457, v456, v474, 0.000000); + node15(v474, v473, 0.000000); + node14(v487, v485, v472, 0.000000); + node13(v472, v471, 0.000000); + node12(v483, v481, v470, 0.000000); + node11(v470, v469, 0.000000); + node10(v477, v479, v468, 0.000000); + node9(v468, v467, 0.000000); + node8(v473, v475, v466, 0.000000); + node7(v466, v465, 0.000000); + node6(v471, v469, v464, 0.000000); + node5(v464, v463, 0.000000); + node4(v465, v467, v462, 0.000000); + node3(v462, v461, 0.000000); + node2(v463, v461, v460, 0.000000); + node1(v460, v459, 0.000000, 100000000.000000); + node0(v459, v458); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu_imbalanced__opt5/src/k15mmtree_relu_imbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu_imbalanced__opt5/src/k15mmtree_relu_imbalanced.cpp new file mode 100644 index 000000000000..6e0b7528780f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k15mmtree_relu_imbalanced__opt5/src/k15mmtree_relu_imbalanced.cpp @@ -0,0 +1,1220 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[1][1], + float v1[16][16] +) { + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v2 + v4)][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[1][1], + hls::stream v8[1][1], + float v9, + float v10 +) { + loop4: for (int v11 = 0; v11 < 16; v11++) { + loop5: for (int v12 = 0; v12 < 16; v12++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v13 = 0; v13 < 1; v13++) { + loop7: for (int v14 = 0; v14 < 1; v14++) { + float v15 = v7[v13][v14].read(); + bool v16 = v15 > v9; + float v17 = v16 ? (float)v15 : (float)v9; + float v18 = v17 / v10; + v8[v13][v14].write(v18); + } + } + } + } + return ; +} + +void node2( + hls::stream v19[1][1], + hls::stream v20[1][1], + hls::stream v21[1][1], + float v22 +) { + float v23[16][16]; + float v24[16][16]; + float v25[16][16]; + loop8: for (int v26 = 0; v26 < 16; v26++) { + loop9: for (int v27 = 0; v27 < 16; v27++) { + loop10: for (int v28 = 0; v28 < 16; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v29 = 0; v29 < 1; v29++) { + loop12: for (int v30 = 0; v30 < 1; v30++) { + loop13: for (int v31 = 0; v31 < 1; v31++) { + if ((v28 + v31) == 0) { + float v32 = v20[v29][v30].read(); + v25[(v26 + v29)][(v27 + v30)] = v32; + } + float v33 = v25[(v26 + v29)][(v27 + v30)]; + if ((v26 + v29) == 0) { + float v34 = v19[v30][v31].read(); + v24[(v27 + v30)][(v28 + v31)] = v34; + } + float v35 = v24[(v27 + v30)][(v28 + v31)]; + if ((v27 + v30) == 0) { + v23[(v26 + v29)][(v28 + v31)] = v22; + } + float v36 = v23[(v26 + v29)][(v28 + v31)]; + float v37 = v33 * v35; + float v38 = v36 + v37; + v23[(v26 + v29)][(v28 + v31)] = v38; + if (((v27 + v30) - 15) == 0) { + float v39 = v23[(v26 + v29)][(v28 + v31)]; + v21[v29][v31].write(v39); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v40[1][1], + hls::stream v41[1][1], + float v42 +) { + loop14: for (int v43 = 0; v43 < 16; v43++) { + loop15: for (int v44 = 0; v44 < 16; v44++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop16: for (int v45 = 0; v45 < 1; v45++) { + loop17: for (int v46 = 0; v46 < 1; v46++) { + float v47 = v40[v45][v46].read(); + bool v48 = v47 > v42; + float v49 = v48 ? (float)v47 : (float)v42; + v41[v45][v46].write(v49); + } + } + } + } + return ; +} + +void node4( + hls::stream v50[1][8], + hls::stream v51[8][1], + hls::stream v52[1][1], + float v53 +) { + float v54[16][16]; + float v55[128][16]; + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=8 + + float v56[16][128]; + #pragma HLS array_partition variable=v56 cyclic dim=2 factor=8 + + loop18: for (int v57 = 0; v57 < 16; v57++) { + loop19: for (int v58 = 0; v58 < 16; v58++) { + loop20: for (int v59 = 0; v59 < 16; v59++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop21: for (int v60 = 0; v60 < 1; v60++) { + loop22: for (int v61 = 0; v61 < 8; v61++) { + loop23: for (int v62 = 0; v62 < 1; v62++) { + if ((v59 + v62) == 0) { + float v63 = v50[v60][v61].read(); + v56[(v57 + v60)][(v61 + (v58 * 8))] = v63; + } + float v64 = v56[(v57 + v60)][(v61 + (v58 * 8))]; + if ((v57 + v60) == 0) { + float v65 = v51[v61][v62].read(); + v55[(v61 + (v58 * 8))][(v59 + v62)] = v65; + } + float v66 = v55[(v61 + (v58 * 8))][(v59 + v62)]; + if ((v61 + (v58 * 8)) == 0) { + v54[(v57 + v60)][(v59 + v62)] = v53; + } + float v67 = v54[(v57 + v60)][(v59 + v62)]; + float v68 = v64 * v66; + float v69 = v67 + v68; + v54[(v57 + v60)][(v59 + v62)] = v69; + if (((v61 + (v58 * 8)) - 127) == 0) { + float v70 = v54[(v57 + v60)][(v59 + v62)]; + v52[v60][v62].write(v70); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v71[1][1], + hls::stream v72[1][1], + float v73 +) { + loop24: for (int v74 = 0; v74 < 16; v74++) { + loop25: for (int v75 = 0; v75 < 16; v75++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop26: for (int v76 = 0; v76 < 1; v76++) { + loop27: for (int v77 = 0; v77 < 1; v77++) { + float v78 = v71[v76][v77].read(); + bool v79 = v78 > v73; + float v80 = v79 ? (float)v78 : (float)v73; + v72[v76][v77].write(v80); + } + } + } + } + return ; +} + +void node6( + hls::stream v81[8][1], + hls::stream v82[1][8], + hls::stream v83[1][1], + float v84 +) { + float v85[16][16]; + float v86[128][16]; + #pragma HLS array_partition variable=v86 cyclic dim=1 factor=8 + + float v87[16][128]; + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=8 + + loop28: for (int v88 = 0; v88 < 16; v88++) { + loop29: for (int v89 = 0; v89 < 16; v89++) { + loop30: for (int v90 = 0; v90 < 16; v90++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v91 = 0; v91 < 1; v91++) { + loop32: for (int v92 = 0; v92 < 8; v92++) { + loop33: for (int v93 = 0; v93 < 1; v93++) { + if ((v90 + v93) == 0) { + float v94 = v82[v91][v92].read(); + v87[(v88 + v91)][(v92 + (v89 * 8))] = v94; + } + float v95 = v87[(v88 + v91)][(v92 + (v89 * 8))]; + if ((v88 + v91) == 0) { + float v96 = v81[v92][v93].read(); + v86[(v92 + (v89 * 8))][(v90 + v93)] = v96; + } + float v97 = v86[(v92 + (v89 * 8))][(v90 + v93)]; + if ((v92 + (v89 * 8)) == 0) { + v85[(v88 + v91)][(v90 + v93)] = v84; + } + float v98 = v85[(v88 + v91)][(v90 + v93)]; + float v99 = v95 * v97; + float v100 = v98 + v99; + v85[(v88 + v91)][(v90 + v93)] = v100; + if (((v92 + (v89 * 8)) - 127) == 0) { + float v101 = v85[(v88 + v91)][(v90 + v93)]; + v83[v91][v93].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node7( + hls::stream v102[8][1], + hls::stream v103[8][1], + float v104 +) { + loop34: for (int v105 = 0; v105 < 16; v105++) { + loop35: for (int v106 = 0; v106 < 16; v106++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop36: for (int v107 = 0; v107 < 8; v107++) { + loop37: for (int v108 = 0; v108 < 1; v108++) { + float v109 = v102[v107][v108].read(); + bool v110 = v109 > v104; + float v111 = v110 ? (float)v109 : (float)v104; + v103[v107][v108].write(v111); + } + } + } + } + return ; +} + +void node8( + hls::stream v112[8][2], + hls::stream v113[2][1], + hls::stream v114[8][1], + float v115 +) { + float v116[128][16]; + #pragma HLS array_partition variable=v116 cyclic dim=1 factor=8 + + float v117[32][16]; + #pragma HLS array_partition variable=v117 cyclic dim=1 factor=2 + + float v118[128][32]; + #pragma HLS array_partition variable=v118 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v118 cyclic dim=2 factor=2 + + loop38: for (int v119 = 0; v119 < 16; v119++) { + loop39: for (int v120 = 0; v120 < 16; v120++) { + loop40: for (int v121 = 0; v121 < 16; v121++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop41: for (int v122 = 0; v122 < 2; v122++) { + loop42: for (int v123 = 0; v123 < 8; v123++) { + loop43: for (int v124 = 0; v124 < 1; v124++) { + if ((v121 + v124) == 0) { + float v125 = v112[v123][v122].read(); + v118[(v123 + (v120 * 8))][(v122 + (v119 * 2))] = v125; + } + float v126 = v118[(v123 + (v120 * 8))][(v122 + (v119 * 2))]; + if ((v123 + (v120 * 8)) == 0) { + float v127 = v113[v122][v124].read(); + v117[(v122 + (v119 * 2))][(v121 + v124)] = v127; + } + float v128 = v117[(v122 + (v119 * 2))][(v121 + v124)]; + if ((v122 + (v119 * 2)) == 0) { + v116[(v123 + (v120 * 8))][(v121 + v124)] = v115; + } + float v129 = v116[(v123 + (v120 * 8))][(v121 + v124)]; + float v130 = v126 * v128; + float v131 = v129 + v130; + v116[(v123 + (v120 * 8))][(v121 + v124)] = v131; + if (((v122 + (v119 * 2)) - 31) == 0) { + float v132 = v116[(v123 + (v120 * 8))][(v121 + v124)]; + v114[v123][v124].write(v132); + } + } + } + } + } + } + } + return ; +} + +void node9( + hls::stream v133[1][8], + hls::stream v134[1][8], + float v135 +) { + loop44: for (int v136 = 0; v136 < 16; v136++) { + loop45: for (int v137 = 0; v137 < 16; v137++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop46: for (int v138 = 0; v138 < 1; v138++) { + loop47: for (int v139 = 0; v139 < 8; v139++) { + float v140 = v133[v138][v139].read(); + bool v141 = v140 > v135; + float v142 = v141 ? (float)v140 : (float)v135; + v134[v138][v139].write(v142); + } + } + } + } + return ; +} + +void node10( + hls::stream v143[8][8], + hls::stream v144[1][8], + hls::stream v145[1][8], + float v146 +) { + float v147[16][128]; + #pragma HLS array_partition variable=v147 cyclic dim=2 factor=8 + + float v148[128][128]; + #pragma HLS array_partition variable=v148 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v148 cyclic dim=2 factor=8 + + float v149[16][128]; + #pragma HLS array_partition variable=v149 cyclic dim=2 factor=8 + + loop48: for (int v150 = 0; v150 < 16; v150++) { + loop49: for (int v151 = 0; v151 < 16; v151++) { + loop50: for (int v152 = 0; v152 < 16; v152++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop51: for (int v153 = 0; v153 < 8; v153++) { + loop52: for (int v154 = 0; v154 < 1; v154++) { + loop53: for (int v155 = 0; v155 < 8; v155++) { + if ((v155 + (v152 * 8)) == 0) { + float v156 = v144[v154][v153].read(); + v149[(v151 + v154)][(v153 + (v150 * 8))] = v156; + } + float v157 = v149[(v151 + v154)][(v153 + (v150 * 8))]; + if ((v151 + v154) == 0) { + float v158 = v143[v153][v155].read(); + v148[(v153 + (v150 * 8))][(v155 + (v152 * 8))] = v158; + } + float v159 = v148[(v153 + (v150 * 8))][(v155 + (v152 * 8))]; + if ((v153 + (v150 * 8)) == 0) { + v147[(v151 + v154)][(v155 + (v152 * 8))] = v146; + } + float v160 = v147[(v151 + v154)][(v155 + (v152 * 8))]; + float v161 = v157 * v159; + float v162 = v160 + v161; + v147[(v151 + v154)][(v155 + (v152 * 8))] = v162; + if (((v153 + (v150 * 8)) - 127) == 0) { + float v163 = v147[(v151 + v154)][(v155 + (v152 * 8))]; + v145[v154][v155].write(v163); + } + } + } + } + } + } + } + return ; +} + +void node11( + hls::stream v164[8][1], + hls::stream v165[8][1], + float v166 +) { + loop54: for (int v167 = 0; v167 < 16; v167++) { + loop55: for (int v168 = 0; v168 < 16; v168++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop56: for (int v169 = 0; v169 < 8; v169++) { + loop57: for (int v170 = 0; v170 < 1; v170++) { + float v171 = v164[v169][v170].read(); + bool v172 = v171 > v166; + float v173 = v172 ? (float)v171 : (float)v166; + v165[v169][v170].write(v173); + } + } + } + } + return ; +} + +void node12( + hls::stream v174[8][1], + hls::stream v175[1][1], + hls::stream v176[8][1], + float v177 +) { + float v178[128][16]; + #pragma HLS array_partition variable=v178 cyclic dim=1 factor=8 + + float v179[32][16]; + float v180[128][32]; + #pragma HLS array_partition variable=v180 cyclic dim=1 factor=8 + + loop58: for (int v181 = 0; v181 < 32; v181++) { + loop59: for (int v182 = 0; v182 < 16; v182++) { + loop60: for (int v183 = 0; v183 < 16; v183++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop61: for (int v184 = 0; v184 < 1; v184++) { + loop62: for (int v185 = 0; v185 < 8; v185++) { + loop63: for (int v186 = 0; v186 < 1; v186++) { + if ((v183 + v186) == 0) { + float v187 = v174[v185][v184].read(); + v180[(v185 + (v182 * 8))][(v181 + v184)] = v187; + } + float v188 = v180[(v185 + (v182 * 8))][(v181 + v184)]; + if ((v185 + (v182 * 8)) == 0) { + float v189 = v175[v184][v186].read(); + v179[(v181 + v184)][(v183 + v186)] = v189; + } + float v190 = v179[(v181 + v184)][(v183 + v186)]; + if ((v181 + v184) == 0) { + v178[(v185 + (v182 * 8))][(v183 + v186)] = v177; + } + float v191 = v178[(v185 + (v182 * 8))][(v183 + v186)]; + float v192 = v188 * v190; + float v193 = v191 + v192; + v178[(v185 + (v182 * 8))][(v183 + v186)] = v193; + if (((v181 + v184) - 31) == 0) { + float v194 = v178[(v185 + (v182 * 8))][(v183 + v186)]; + v176[v185][v186].write(v194); + } + } + } + } + } + } + } + return ; +} + +void node13( + hls::stream v195[1][8], + hls::stream v196[1][8], + float v197 +) { + loop64: for (int v198 = 0; v198 < 16; v198++) { + loop65: for (int v199 = 0; v199 < 16; v199++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop66: for (int v200 = 0; v200 < 1; v200++) { + loop67: for (int v201 = 0; v201 < 8; v201++) { + float v202 = v195[v200][v201].read(); + bool v203 = v202 > v197; + float v204 = v203 ? (float)v202 : (float)v197; + v196[v200][v201].write(v204); + } + } + } + } + return ; +} + +void node14( + hls::stream v205[1][4], + hls::stream v206[4][8], + hls::stream v207[1][8], + float v208 +) { + float v209[16][128]; + #pragma HLS array_partition variable=v209 cyclic dim=2 factor=8 + + float v210[128][128]; + #pragma HLS array_partition variable=v210 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v210 cyclic dim=2 factor=8 + + float v211[16][128]; + #pragma HLS array_partition variable=v211 cyclic dim=2 factor=4 + + loop68: for (int v212 = 0; v212 < 32; v212++) { + loop69: for (int v213 = 0; v213 < 16; v213++) { + loop70: for (int v214 = 0; v214 < 16; v214++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop71: for (int v215 = 0; v215 < 4; v215++) { + loop72: for (int v216 = 0; v216 < 1; v216++) { + loop73: for (int v217 = 0; v217 < 8; v217++) { + if ((v217 + (v214 * 8)) == 0) { + float v218 = v205[v216][v215].read(); + v211[(v213 + v216)][(v215 + (v212 * 4))] = v218; + } + float v219 = v211[(v213 + v216)][(v215 + (v212 * 4))]; + if ((v213 + v216) == 0) { + float v220 = v206[v215][v217].read(); + v210[(v215 + (v212 * 4))][(v217 + (v214 * 8))] = v220; + } + float v221 = v210[(v215 + (v212 * 4))][(v217 + (v214 * 8))]; + if ((v215 + (v212 * 4)) == 0) { + v209[(v213 + v216)][(v217 + (v214 * 8))] = v208; + } + float v222 = v209[(v213 + v216)][(v217 + (v214 * 8))]; + float v223 = v219 * v221; + float v224 = v222 + v223; + v209[(v213 + v216)][(v217 + (v214 * 8))] = v224; + if (((v215 + (v212 * 4)) - 127) == 0) { + float v225 = v209[(v213 + v216)][(v217 + (v214 * 8))]; + v207[v216][v217].write(v225); + } + } + } + } + } + } + } + return ; +} + +void node15( + hls::stream v226[2][1], + hls::stream v227[2][1], + float v228 +) { + loop74: for (int v229 = 0; v229 < 16; v229++) { + loop75: for (int v230 = 0; v230 < 16; v230++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop76: for (int v231 = 0; v231 < 2; v231++) { + loop77: for (int v232 = 0; v232 < 1; v232++) { + float v233 = v226[v231][v232].read(); + bool v234 = v233 > v228; + float v235 = v234 ? (float)v233 : (float)v228; + v227[v231][v232].write(v235); + } + } + } + } + return ; +} + +void node16( + float v236[16][16], + float v237[32][16], + hls::stream v238[2][1], + float v239 +) { + #pragma HLS array_partition variable=v237 cyclic dim=1 factor=2 + + float v240[32][16]; + #pragma HLS array_partition variable=v240 cyclic dim=1 factor=2 + + loop78: for (int v241 = 0; v241 < 16; v241++) { + loop79: for (int v242 = 0; v242 < 16; v242++) { + loop80: for (int v243 = 0; v243 < 16; v243++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop81: for (int v244 = 0; v244 < 2; v244++) { + loop82: for (int v245 = 0; v245 < 1; v245++) { + loop83: for (int v246 = 0; v246 < 1; v246++) { + float v247 = v237[(v244 + (v241 * 2))][(v242 + v245)]; + float v248 = v236[(v242 + v245)][(v243 + v246)]; + if ((v242 + v245) == 0) { + v240[(v244 + (v241 * 2))][(v243 + v246)] = v239; + } + float v249 = v240[(v244 + (v241 * 2))][(v243 + v246)]; + float v250 = v247 * v248; + float v251 = v249 + v250; + v240[(v244 + (v241 * 2))][(v243 + v246)] = v251; + if (((v242 + v245) - 15) == 0) { + float v252 = v240[(v244 + (v241 * 2))][(v243 + v246)]; + v238[v244][v246].write(v252); + } + } + } + } + } + } + } + return ; +} + +void node17( + hls::stream v253[8][2], + hls::stream v254[8][2], + float v255 +) { + loop84: for (int v256 = 0; v256 < 16; v256++) { + loop85: for (int v257 = 0; v257 < 16; v257++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop86: for (int v258 = 0; v258 < 2; v258++) { + loop87: for (int v259 = 0; v259 < 8; v259++) { + float v260 = v253[v259][v258].read(); + bool v261 = v260 > v255; + float v262 = v261 ? (float)v260 : (float)v255; + v254[v259][v258].write(v262); + } + } + } + } + return ; +} + +void node18( + float v263[128][64], + float v264[64][32], + hls::stream v265[8][2], + float v266 +) { + #pragma HLS array_partition variable=v263 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v263 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v264 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v264 cyclic dim=2 factor=2 + + float v267[128][32]; + #pragma HLS array_partition variable=v267 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v267 cyclic dim=2 factor=2 + + loop88: for (int v268 = 0; v268 < 16; v268++) { + loop89: for (int v269 = 0; v269 < 16; v269++) { + loop90: for (int v270 = 0; v270 < 16; v270++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop91: for (int v271 = 0; v271 < 2; v271++) { + loop92: for (int v272 = 0; v272 < 4; v272++) { + loop93: for (int v273 = 0; v273 < 8; v273++) { + float v274 = v263[(v273 + (v270 * 8))][(v272 + (v269 * 4))]; + float v275 = v264[(v272 + (v269 * 4))][(v271 + (v268 * 2))]; + if ((v272 + (v269 * 4)) == 0) { + v267[(v273 + (v270 * 8))][(v271 + (v268 * 2))] = v266; + } + float v276 = v267[(v273 + (v270 * 8))][(v271 + (v268 * 2))]; + float v277 = v274 * v275; + float v278 = v276 + v277; + v267[(v273 + (v270 * 8))][(v271 + (v268 * 2))] = v278; + if (((v272 + (v269 * 4)) - 63) == 0) { + float v279 = v267[(v273 + (v270 * 8))][(v271 + (v268 * 2))]; + v265[v273][v271].write(v279); + } + } + } + } + } + } + } + return ; +} + +void node19( + hls::stream v280[8][8], + hls::stream v281[8][8], + float v282 +) { + loop94: for (int v283 = 0; v283 < 16; v283++) { + loop95: for (int v284 = 0; v284 < 16; v284++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop96: for (int v285 = 0; v285 < 8; v285++) { + loop97: for (int v286 = 0; v286 < 8; v286++) { + float v287 = v280[v285][v286].read(); + bool v288 = v287 > v282; + float v289 = v288 ? (float)v287 : (float)v282; + v281[v285][v286].write(v289); + } + } + } + } + return ; +} + +void node20( + float v290[64][128], + float v291[128][64], + hls::stream v292[8][8], + float v293 +) { + #pragma HLS array_partition variable=v290 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v290 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v291 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v291 cyclic dim=2 factor=2 + + float v294[128][128]; + #pragma HLS array_partition variable=v294 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v294 cyclic dim=2 factor=8 + + loop98: for (int v295 = 0; v295 < 16; v295++) { + loop99: for (int v296 = 0; v296 < 32; v296++) { + loop100: for (int v297 = 0; v297 < 16; v297++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop101: for (int v298 = 0; v298 < 8; v298++) { + loop102: for (int v299 = 0; v299 < 2; v299++) { + loop103: for (int v300 = 0; v300 < 8; v300++) { + float v301 = v291[(v298 + (v295 * 8))][(v299 + (v296 * 2))]; + float v302 = v290[(v299 + (v296 * 2))][(v300 + (v297 * 8))]; + if ((v299 + (v296 * 2)) == 0) { + v294[(v298 + (v295 * 8))][(v300 + (v297 * 8))] = v293; + } + float v303 = v294[(v298 + (v295 * 8))][(v300 + (v297 * 8))]; + float v304 = v301 * v302; + float v305 = v303 + v304; + v294[(v298 + (v295 * 8))][(v300 + (v297 * 8))] = v305; + if (((v299 + (v296 * 2)) - 63) == 0) { + float v306 = v294[(v298 + (v295 * 8))][(v300 + (v297 * 8))]; + v292[v298][v300].write(v306); + } + } + } + } + } + } + } + return ; +} + +void node21( + hls::stream v307[1][8], + hls::stream v308[1][8], + float v309 +) { + loop104: for (int v310 = 0; v310 < 16; v310++) { + loop105: for (int v311 = 0; v311 < 16; v311++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop106: for (int v312 = 0; v312 < 8; v312++) { + loop107: for (int v313 = 0; v313 < 1; v313++) { + float v314 = v307[v313][v312].read(); + bool v315 = v314 > v309; + float v316 = v315 ? (float)v314 : (float)v309; + v308[v313][v312].write(v316); + } + } + } + } + return ; +} + +void node22( + float v317[32][128], + float v318[16][32], + hls::stream v319[1][8], + float v320 +) { + #pragma HLS array_partition variable=v317 cyclic dim=2 factor=8 + + float v321[16][128]; + #pragma HLS array_partition variable=v321 cyclic dim=2 factor=8 + + loop108: for (int v322 = 0; v322 < 16; v322++) { + loop109: for (int v323 = 0; v323 < 32; v323++) { + loop110: for (int v324 = 0; v324 < 16; v324++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop111: for (int v325 = 0; v325 < 8; v325++) { + loop112: for (int v326 = 0; v326 < 1; v326++) { + loop113: for (int v327 = 0; v327 < 1; v327++) { + float v328 = v318[(v324 + v327)][(v323 + v326)]; + float v329 = v317[(v323 + v326)][(v325 + (v322 * 8))]; + if ((v323 + v326) == 0) { + v321[(v324 + v327)][(v325 + (v322 * 8))] = v320; + } + float v330 = v321[(v324 + v327)][(v325 + (v322 * 8))]; + float v331 = v328 * v329; + float v332 = v330 + v331; + v321[(v324 + v327)][(v325 + (v322 * 8))] = v332; + if (((v323 + v326) - 31) == 0) { + float v333 = v321[(v324 + v327)][(v325 + (v322 * 8))]; + v319[v327][v325].write(v333); + } + } + } + } + } + } + } + return ; +} + +void node23( + hls::stream v334[1][1], + hls::stream v335[1][1], + float v336 +) { + loop114: for (int v337 = 0; v337 < 32; v337++) { + loop115: for (int v338 = 0; v338 < 16; v338++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop116: for (int v339 = 0; v339 < 1; v339++) { + loop117: for (int v340 = 0; v340 < 1; v340++) { + float v341 = v334[v339][v340].read(); + bool v342 = v341 > v336; + float v343 = v342 ? (float)v341 : (float)v336; + v335[v339][v340].write(v343); + } + } + } + } + return ; +} + +void node24( + float v344[32][16], + float v345[16][16], + hls::stream v346[1][1], + float v347 +) { + float v348[32][16]; + loop118: for (int v349 = 0; v349 < 32; v349++) { + loop119: for (int v350 = 0; v350 < 16; v350++) { + loop120: for (int v351 = 0; v351 < 16; v351++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop121: for (int v352 = 0; v352 < 1; v352++) { + loop122: for (int v353 = 0; v353 < 1; v353++) { + loop123: for (int v354 = 0; v354 < 1; v354++) { + float v355 = v344[(v349 + v352)][(v350 + v353)]; + float v356 = v345[(v350 + v353)][(v351 + v354)]; + if ((v350 + v353) == 0) { + v348[(v349 + v352)][(v351 + v354)] = v347; + } + float v357 = v348[(v349 + v352)][(v351 + v354)]; + float v358 = v355 * v356; + float v359 = v357 + v358; + v348[(v349 + v352)][(v351 + v354)] = v359; + if (((v350 + v353) - 15) == 0) { + float v360 = v348[(v349 + v352)][(v351 + v354)]; + v346[v352][v354].write(v360); + } + } + } + } + } + } + } + return ; +} + +void node25( + hls::stream v361[8][1], + hls::stream v362[8][1], + float v363 +) { + loop124: for (int v364 = 0; v364 < 32; v364++) { + loop125: for (int v365 = 0; v365 < 16; v365++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop126: for (int v366 = 0; v366 < 1; v366++) { + loop127: for (int v367 = 0; v367 < 8; v367++) { + float v368 = v361[v367][v366].read(); + bool v369 = v368 > v363; + float v370 = v369 ? (float)v368 : (float)v363; + v362[v367][v366].write(v370); + } + } + } + } + return ; +} + +void node26( + float v371[128][64], + float v372[64][32], + hls::stream v373[8][1], + float v374 +) { + #pragma HLS array_partition variable=v371 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v371 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v372 cyclic dim=1 factor=4 + + float v375[128][32]; + #pragma HLS array_partition variable=v375 cyclic dim=1 factor=8 + + loop128: for (int v376 = 0; v376 < 32; v376++) { + loop129: for (int v377 = 0; v377 < 16; v377++) { + loop130: for (int v378 = 0; v378 < 16; v378++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop131: for (int v379 = 0; v379 < 1; v379++) { + loop132: for (int v380 = 0; v380 < 4; v380++) { + loop133: for (int v381 = 0; v381 < 8; v381++) { + float v382 = v371[(v381 + (v378 * 8))][(v380 + (v377 * 4))]; + float v383 = v372[(v380 + (v377 * 4))][(v376 + v379)]; + if ((v380 + (v377 * 4)) == 0) { + v375[(v381 + (v378 * 8))][(v376 + v379)] = v374; + } + float v384 = v375[(v381 + (v378 * 8))][(v376 + v379)]; + float v385 = v382 * v383; + float v386 = v384 + v385; + v375[(v381 + (v378 * 8))][(v376 + v379)] = v386; + if (((v380 + (v377 * 4)) - 63) == 0) { + float v387 = v375[(v381 + (v378 * 8))][(v376 + v379)]; + v373[v381][v379].write(v387); + } + } + } + } + } + } + } + return ; +} + +void node27( + hls::stream v388[4][8], + hls::stream v389[4][8], + float v390 +) { + loop134: for (int v391 = 0; v391 < 32; v391++) { + loop135: for (int v392 = 0; v392 < 16; v392++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop136: for (int v393 = 0; v393 < 4; v393++) { + loop137: for (int v394 = 0; v394 < 8; v394++) { + float v395 = v388[v393][v394].read(); + bool v396 = v395 > v390; + float v397 = v396 ? (float)v395 : (float)v390; + v389[v393][v394].write(v397); + } + } + } + } + return ; +} + +void node28( + float v398[64][128], + float v399[128][64], + hls::stream v400[4][8], + float v401 +) { + #pragma HLS array_partition variable=v398 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v398 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v399 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v399 cyclic dim=2 factor=4 + + float v402[128][128]; + #pragma HLS array_partition variable=v402 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v402 cyclic dim=2 factor=8 + + loop138: for (int v403 = 0; v403 < 32; v403++) { + loop139: for (int v404 = 0; v404 < 16; v404++) { + loop140: for (int v405 = 0; v405 < 16; v405++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop141: for (int v406 = 0; v406 < 4; v406++) { + loop142: for (int v407 = 0; v407 < 4; v407++) { + loop143: for (int v408 = 0; v408 < 8; v408++) { + float v409 = v399[(v406 + (v403 * 4))][(v407 + (v404 * 4))]; + float v410 = v398[(v407 + (v404 * 4))][(v408 + (v405 * 8))]; + if ((v407 + (v404 * 4)) == 0) { + v402[(v406 + (v403 * 4))][(v408 + (v405 * 8))] = v401; + } + float v411 = v402[(v406 + (v403 * 4))][(v408 + (v405 * 8))]; + float v412 = v409 * v410; + float v413 = v411 + v412; + v402[(v406 + (v403 * 4))][(v408 + (v405 * 8))] = v413; + if (((v407 + (v404 * 4)) - 63) == 0) { + float v414 = v402[(v406 + (v403 * 4))][(v408 + (v405 * 8))]; + v400[v406][v408].write(v414); + } + } + } + } + } + } + } + return ; +} + +void node29( + hls::stream v415[1][4], + hls::stream v416[1][4], + float v417 +) { + loop144: for (int v418 = 0; v418 < 32; v418++) { + loop145: for (int v419 = 0; v419 < 16; v419++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop146: for (int v420 = 0; v420 < 4; v420++) { + loop147: for (int v421 = 0; v421 < 1; v421++) { + float v422 = v415[v421][v420].read(); + bool v423 = v422 > v417; + float v424 = v423 ? (float)v422 : (float)v417; + v416[v421][v420].write(v424); + } + } + } + } + return ; +} + +void node30( + float v425[16][32], + float v426[32][128], + hls::stream v427[1][4], + float v428 +) { + #pragma HLS array_partition variable=v425 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v426 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v426 cyclic dim=2 factor=4 + + float v429[16][128]; + #pragma HLS array_partition variable=v429 cyclic dim=2 factor=4 + + loop148: for (int v430 = 0; v430 < 32; v430++) { + loop149: for (int v431 = 0; v431 < 16; v431++) { + loop150: for (int v432 = 0; v432 < 16; v432++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop151: for (int v433 = 0; v433 < 4; v433++) { + loop152: for (int v434 = 0; v434 < 2; v434++) { + loop153: for (int v435 = 0; v435 < 1; v435++) { + float v436 = v425[(v432 + v435)][(v434 + (v431 * 2))]; + float v437 = v426[(v434 + (v431 * 2))][(v433 + (v430 * 4))]; + if ((v434 + (v431 * 2)) == 0) { + v429[(v432 + v435)][(v433 + (v430 * 4))] = v428; + } + float v438 = v429[(v432 + v435)][(v433 + (v430 * 4))]; + float v439 = v436 * v437; + float v440 = v438 + v439; + v429[(v432 + v435)][(v433 + (v430 * 4))] = v440; + if (((v434 + (v431 * 2)) - 31) == 0) { + float v441 = v429[(v432 + v435)][(v433 + (v430 * 4))]; + v427[v435][v433].write(v441); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v442[16][32], + float v443[32][128], + float v444[128][64], + float v445[64][128], + float v446[128][64], + float v447[64][32], + float v448[32][16], + float v449[16][16], + float v450[16][32], + float v451[32][128], + float v452[128][64], + float v453[64][128], + float v454[128][64], + float v455[64][32], + float v456[32][16], + float v457[16][16], + float v458[16][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v442 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v443 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v443 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v444 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v444 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v445 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v445 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v446 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v446 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v447 cyclic dim=1 factor=4 + + #pragma HLS array_partition variable=v451 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v452 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v452 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v453 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v453 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v454 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v454 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v455 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v455 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v456 cyclic dim=1 factor=2 + + hls::stream v459[1][1]; + #pragma HLS STREAM variable=v459 depth=256 + hls::stream v460[1][1]; + #pragma HLS STREAM variable=v460 depth=256 + hls::stream v461[1][1]; + #pragma HLS STREAM variable=v461 depth=256 + hls::stream v462[1][1]; + #pragma HLS STREAM variable=v462 depth=256 + hls::stream v463[1][1]; + #pragma HLS STREAM variable=v463 depth=256 + hls::stream v464[1][1]; + #pragma HLS STREAM variable=v464 depth=256 + hls::stream v465[8][1]; + #pragma HLS STREAM variable=v465 depth=256 + hls::stream v466[8][1]; + #pragma HLS STREAM variable=v466 depth=256 + hls::stream v467[1][8]; + #pragma HLS STREAM variable=v467 depth=256 + hls::stream v468[1][8]; + #pragma HLS STREAM variable=v468 depth=256 + hls::stream v469[8][1]; + #pragma HLS STREAM variable=v469 depth=256 + hls::stream v470[8][1]; + #pragma HLS STREAM variable=v470 depth=256 + hls::stream v471[1][8]; + #pragma HLS STREAM variable=v471 depth=256 + hls::stream v472[1][8]; + #pragma HLS STREAM variable=v472 depth=256 + hls::stream v473[2][1]; + #pragma HLS STREAM variable=v473 depth=256 + hls::stream v474[2][1]; + #pragma HLS STREAM variable=v474 depth=256 + hls::stream v475[8][2]; + #pragma HLS STREAM variable=v475 depth=256 + hls::stream v476[8][2]; + #pragma HLS STREAM variable=v476 depth=256 + hls::stream v477[8][8]; + #pragma HLS STREAM variable=v477 depth=256 + hls::stream v478[8][8]; + #pragma HLS STREAM variable=v478 depth=256 + hls::stream v479[1][8]; + #pragma HLS STREAM variable=v479 depth=256 + hls::stream v480[1][8]; + #pragma HLS STREAM variable=v480 depth=256 + hls::stream v481[1][1]; + #pragma HLS STREAM variable=v481 depth=512 + hls::stream v482[1][1]; + #pragma HLS STREAM variable=v482 depth=512 + hls::stream v483[8][1]; + #pragma HLS STREAM variable=v483 depth=512 + hls::stream v484[8][1]; + #pragma HLS STREAM variable=v484 depth=512 + hls::stream v485[4][8]; + #pragma HLS STREAM variable=v485 depth=512 + hls::stream v486[4][8]; + #pragma HLS STREAM variable=v486 depth=512 + hls::stream v487[1][4]; + #pragma HLS STREAM variable=v487 depth=512 + hls::stream v488[1][4]; + #pragma HLS STREAM variable=v488 depth=512 + node30(v442, v443, v488, 0.000000); + node29(v488, v487, 0.000000); + node28(v445, v444, v486, 0.000000); + node27(v486, v485, 0.000000); + node26(v446, v447, v484, 0.000000); + node25(v484, v483, 0.000000); + node24(v448, v449, v482, 0.000000); + node23(v482, v481, 0.000000); + node22(v451, v450, v480, 0.000000); + node21(v480, v479, 0.000000); + node20(v453, v452, v478, 0.000000); + node19(v478, v477, 0.000000); + node18(v454, v455, v476, 0.000000); + node17(v476, v475, 0.000000); + node16(v457, v456, v474, 0.000000); + node15(v474, v473, 0.000000); + node14(v487, v485, v472, 0.000000); + node13(v472, v471, 0.000000); + node12(v483, v481, v470, 0.000000); + node11(v470, v469, 0.000000); + node10(v477, v479, v468, 0.000000); + node9(v468, v467, 0.000000); + node8(v475, v473, v466, 0.000000); + node7(v466, v465, 0.000000); + node6(v469, v471, v464, 0.000000); + node5(v464, v463, 0.000000); + node4(v467, v465, v462, 0.000000); + node3(v462, v461, 0.000000); + node2(v461, v463, v460, 0.000000); + node1(v460, v459, 0.000000, 100000000.000000); + node0(v459, v458); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt1/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt1/src/k2mm.cpp new file mode 100644 index 000000000000..dc8ef2c4cc96 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt1/src/k2mm.cpp @@ -0,0 +1,142 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[180][220] +) { + loop0: for (int v2 = 0; v2 < 180; v2++) { + loop1: for (int v3 = 0; v3 < 220; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[180][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 180; v10++) { + loop3: for (int v11 = 0; v11 < 220; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v10][v11]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + hls::stream &v18, + float v19[190][220], + hls::stream &v20, + float v21 +) { + float v22[180][220]; + float v23[180][190]; + loop4: for (int v24 = 0; v24 < 180; v24++) { + loop5: for (int v25 = 0; v25 < 220; v25++) { + loop6: for (int v26 = 0; v26 < 190; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v25 == 0) { + float v27 = v18.read(); + v23[v24][v26] = v27; + } + float v28 = v23[v24][v26]; + float v29 = v19[v26][v25]; + if (v26 == 0) { + v22[v24][v25] = v21; + } + float v30 = v22[v24][v25]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v22[v24][v25] = v32; + if ((v26 - 189) == 0) { + float v33 = v22[v24][v25]; + v20.write(v33); + } + } + } + } + return ; +} + +void node3( + float v34[180][210], + float v35[210][190], + hls::stream &v36, + float v37 +) { + float v38[180][190]; + loop7: for (int v39 = 0; v39 < 180; v39++) { + loop8: for (int v40 = 0; v40 < 190; v40++) { + loop9: for (int v41 = 0; v41 < 210; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v34[v39][v41]; + float v43 = v35[v41][v40]; + if (v41 == 0) { + v38[v39][v40] = v37; + } + float v44 = v38[v39][v40]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v38[v39][v40] = v46; + if ((v41 - 209) == 0) { + float v47 = v38[v39][v40]; + v36.write(v47); + } + } + } + } + return ; +} + +void forward( + float v48[180][210], + float v49[210][190], + float v50[190][220], + float v51[180][220], + float v52[180][220] +) { + #pragma HLS DATAFLOW + hls::stream v53("fifo_0"); + #pragma HLS STREAM variable=v53 depth=39600 + hls::stream v54("fifo_1"); + #pragma HLS STREAM variable=v54 depth=39600 + hls::stream v55("fifo_2"); + #pragma HLS STREAM variable=v55 depth=34200 + node3(v48, v49, v55, 0.000000); + node2(v55, v50, v54, 0.000000); + node1(v54, v51, v53, 0.100000, 0.500000); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt2/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt2/src/k2mm.cpp new file mode 100644 index 000000000000..1c7e562fbc2d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt2/src/k2mm.cpp @@ -0,0 +1,142 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[180][220] +) { + loop0: for (int v2 = 0; v2 < 220; v2++) { + loop1: for (int v3 = 0; v3 < 180; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v3][v2] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[180][220], + hls::stream &v7, + double v8, + float v9 +) { + loop2: for (int v10 = 0; v10 < 220; v10++) { + loop3: for (int v11 = 0; v11 < 180; v11++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v12 = v5.read(); + float v13 = v6[v11][v10]; + float v14 = v8; + float v15 = v13 * v14; + float v16 = v12 * v9; + float v17 = v16 + v15; + v7.write(v17); + } + } + return ; +} + +void node2( + hls::stream &v18, + float v19[190][220], + hls::stream &v20, + float v21 +) { + float v22[180][220]; + float v23[180][190]; + loop4: for (int v24 = 0; v24 < 190; v24++) { + loop5: for (int v25 = 0; v25 < 220; v25++) { + loop6: for (int v26 = 0; v26 < 180; v26++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v25 == 0) { + float v27 = v18.read(); + v23[v26][v24] = v27; + } + float v28 = v23[v26][v24]; + float v29 = v19[v24][v25]; + if (v24 == 0) { + v22[v26][v25] = v21; + } + float v30 = v22[v26][v25]; + float v31 = v28 * v29; + float v32 = v30 + v31; + v22[v26][v25] = v32; + if ((v24 - 189) == 0) { + float v33 = v22[v26][v25]; + v20.write(v33); + } + } + } + } + return ; +} + +void node3( + float v34[180][210], + float v35[210][190], + hls::stream &v36, + float v37 +) { + float v38[180][190]; + loop7: for (int v39 = 0; v39 < 190; v39++) { + loop8: for (int v40 = 0; v40 < 210; v40++) { + loop9: for (int v41 = 0; v41 < 180; v41++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v42 = v34[v41][v40]; + float v43 = v35[v40][v39]; + if (v40 == 0) { + v38[v41][v39] = v37; + } + float v44 = v38[v41][v39]; + float v45 = v42 * v43; + float v46 = v44 + v45; + v38[v41][v39] = v46; + if ((v40 - 209) == 0) { + float v47 = v38[v41][v39]; + v36.write(v47); + } + } + } + } + return ; +} + +void forward( + float v48[180][210], + float v49[210][190], + float v50[190][220], + float v51[180][220], + float v52[180][220] +) { + #pragma HLS DATAFLOW + hls::stream v53("fifo_0"); + #pragma HLS STREAM variable=v53 depth=39600 + hls::stream v54("fifo_1"); + #pragma HLS STREAM variable=v54 depth=39600 + hls::stream v55("fifo_2"); + #pragma HLS STREAM variable=v55 depth=34200 + node3(v48, v49, v55, 0.000000); + node2(v55, v50, v54, 0.000000); + node1(v54, v51, v53, 0.100000, 0.500000); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt3/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt3/src/k2mm.cpp new file mode 100644 index 000000000000..348cbd2c4524 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt3/src/k2mm.cpp @@ -0,0 +1,201 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][11], + float v1[180][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 90; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 2))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][11], + float v8[180][220], + hls::stream v9[2][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 90; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 2; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 2))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + hls::stream v22[2][10], + float v23[190][220], + hls::stream v24[2][11], + float v25 +) { + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[180][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + float v27[180][190]; + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=10 + + loop8: for (int v28 = 0; v28 < 90; v28++) { + loop9: for (int v29 = 0; v29 < 20; v29++) { + loop10: for (int v30 = 0; v30 < 19; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v31 = 0; v31 < 2; v31++) { + loop12: for (int v32 = 0; v32 < 11; v32++) { + loop13: for (int v33 = 0; v33 < 10; v33++) { + if ((v32 + (v29 * 11)) == 0) { + float v34 = v22[v31][v33].read(); + v27[(v31 + (v28 * 2))][(v33 + (v30 * 10))] = v34; + } + float v35 = v27[(v31 + (v28 * 2))][(v33 + (v30 * 10))]; + float v36 = v23[(v33 + (v30 * 10))][(v32 + (v29 * 11))]; + if ((v33 + (v30 * 10)) == 0) { + v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))] = v25; + } + float v37 = v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))]; + float v38 = v35 * v36; + float v39 = v37 + v38; + v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))] = v39; + if (((v33 + (v30 * 10)) - 189) == 0) { + float v40 = v26[(v31 + (v28 * 2))][(v32 + (v29 * 11))]; + v24[v31][v32].write(v40); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v41[210][190], + float v42[180][210], + hls::stream v43[2][10], + float v44 +) { + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=10 + + float v45[180][190]; + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=10 + + loop14: for (int v46 = 0; v46 < 90; v46++) { + loop15: for (int v47 = 0; v47 < 19; v47++) { + loop16: for (int v48 = 0; v48 < 21; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v49 = 0; v49 < 2; v49++) { + loop18: for (int v50 = 0; v50 < 10; v50++) { + loop19: for (int v51 = 0; v51 < 10; v51++) { + float v52 = v42[(v49 + (v46 * 2))][(v51 + (v48 * 10))]; + float v53 = v41[(v51 + (v48 * 10))][(v50 + (v47 * 10))]; + if ((v51 + (v48 * 10)) == 0) { + v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))] = v44; + } + float v54 = v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))]; + float v55 = v52 * v53; + float v56 = v54 + v55; + v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))] = v56; + if (((v51 + (v48 * 10)) - 209) == 0) { + float v57 = v45[(v49 + (v46 * 2))][(v50 + (v47 * 10))]; + v43[v49][v50].write(v57); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v58[180][210], + float v59[210][190], + float v60[190][220], + float v61[180][220], + float v62[180][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=11 + + hls::stream v63[2][11]; + #pragma HLS STREAM variable=v63 depth=1800 + hls::stream v64[2][11]; + #pragma HLS STREAM variable=v64 depth=1800 + hls::stream v65[2][10]; + #pragma HLS STREAM variable=v65 depth=1710 + node3(v59, v58, v65, 0.000000); + node2(v65, v60, v64, 0.000000); + node1(v64, v61, v63, 0.100000, 0.500000); + node0(v63, v62); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt4/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt4/src/k2mm.cpp new file mode 100644 index 000000000000..4c17a6f50b7b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt4/src/k2mm.cpp @@ -0,0 +1,201 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][11], + float v1[180][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 20; v2++) { + loop1: for (int v3 = 0; v3 < 45; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 11; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v4 + (v2 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][11], + float v8[180][220], + hls::stream v9[4][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 20; v12++) { + loop5: for (int v13 = 0; v13 < 45; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 11; v14++) { + loop7: for (int v15 = 0; v15 < 4; v15++) { + float v16 = v7[v15][v14].read(); + float v17 = v8[(v15 + (v13 * 4))][(v14 + (v12 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v15][v14].write(v21); + } + } + } + } + return ; +} + +void node2( + float v22[190][220], + hls::stream v23[4][5], + hls::stream v24[4][11], + float v25 +) { + #pragma HLS array_partition variable=v22 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v22 cyclic dim=2 factor=11 + + float v26[180][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + float v27[180][190]; + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=5 + + loop8: for (int v28 = 0; v28 < 38; v28++) { + loop9: for (int v29 = 0; v29 < 20; v29++) { + loop10: for (int v30 = 0; v30 < 45; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v31 = 0; v31 < 5; v31++) { + loop12: for (int v32 = 0; v32 < 11; v32++) { + loop13: for (int v33 = 0; v33 < 4; v33++) { + if ((v32 + (v29 * 11)) == 0) { + float v34 = v23[v33][v31].read(); + v27[(v33 + (v30 * 4))][(v31 + (v28 * 5))] = v34; + } + float v35 = v27[(v33 + (v30 * 4))][(v31 + (v28 * 5))]; + float v36 = v22[(v31 + (v28 * 5))][(v32 + (v29 * 11))]; + if ((v31 + (v28 * 5)) == 0) { + v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))] = v25; + } + float v37 = v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))]; + float v38 = v35 * v36; + float v39 = v37 + v38; + v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))] = v39; + if (((v31 + (v28 * 5)) - 189) == 0) { + float v40 = v26[(v33 + (v30 * 4))][(v32 + (v29 * 11))]; + v24[v33][v32].write(v40); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v41[210][190], + float v42[180][210], + hls::stream v43[4][5], + float v44 +) { + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=10 + + float v45[180][190]; + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=5 + + loop14: for (int v46 = 0; v46 < 38; v46++) { + loop15: for (int v47 = 0; v47 < 21; v47++) { + loop16: for (int v48 = 0; v48 < 45; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v49 = 0; v49 < 5; v49++) { + loop18: for (int v50 = 0; v50 < 10; v50++) { + loop19: for (int v51 = 0; v51 < 4; v51++) { + float v52 = v42[(v51 + (v48 * 4))][(v50 + (v47 * 10))]; + float v53 = v41[(v50 + (v47 * 10))][(v49 + (v46 * 5))]; + if ((v50 + (v47 * 10)) == 0) { + v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))] = v44; + } + float v54 = v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))]; + float v55 = v52 * v53; + float v56 = v54 + v55; + v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))] = v56; + if (((v50 + (v47 * 10)) - 209) == 0) { + float v57 = v45[(v51 + (v48 * 4))][(v49 + (v46 * 5))]; + v43[v51][v49].write(v57); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v58[180][210], + float v59[210][190], + float v60[190][220], + float v61[180][220], + float v62[180][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=11 + + hls::stream v63[4][11]; + #pragma HLS STREAM variable=v63 depth=900 + hls::stream v64[4][11]; + #pragma HLS STREAM variable=v64 depth=900 + hls::stream v65[4][5]; + #pragma HLS STREAM variable=v65 depth=1710 + node3(v59, v58, v65, 0.000000); + node2(v60, v65, v64, 0.000000); + node1(v64, v61, v63, 0.100000, 0.500000); + node0(v63, v62); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt5/src/k2mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt5/src/k2mm.cpp new file mode 100644 index 000000000000..43cbb7456ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k2mm__opt5/src/k2mm.cpp @@ -0,0 +1,201 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[2][11], + float v1[180][220] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=11 + + loop0: for (int v2 = 0; v2 < 90; v2++) { + loop1: for (int v3 = 0; v3 < 20; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 2; v4++) { + loop3: for (int v5 = 0; v5 < 11; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 2))][(v5 + (v3 * 11))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[2][11], + float v8[180][220], + hls::stream v9[2][11], + double v10, + float v11 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=11 + + loop4: for (int v12 = 0; v12 < 90; v12++) { + loop5: for (int v13 = 0; v13 < 20; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v14 = 0; v14 < 2; v14++) { + loop7: for (int v15 = 0; v15 < 11; v15++) { + float v16 = v7[v14][v15].read(); + float v17 = v8[(v14 + (v12 * 2))][(v15 + (v13 * 11))]; + float v18 = v10; + float v19 = v17 * v18; + float v20 = v16 * v11; + float v21 = v20 + v19; + v9[v14][v15].write(v21); + } + } + } + } + return ; +} + +void node2( + hls::stream v22[2][10], + float v23[190][220], + hls::stream v24[2][11], + float v25 +) { + #pragma HLS array_partition variable=v23 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v23 cyclic dim=2 factor=11 + + float v26[180][220]; + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=11 + + float v27[180][190]; + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=10 + + loop8: for (int v28 = 0; v28 < 90; v28++) { + loop9: for (int v29 = 0; v29 < 19; v29++) { + loop10: for (int v30 = 0; v30 < 20; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop11: for (int v31 = 0; v31 < 2; v31++) { + loop12: for (int v32 = 0; v32 < 10; v32++) { + loop13: for (int v33 = 0; v33 < 11; v33++) { + if ((v33 + (v30 * 11)) == 0) { + float v34 = v22[v31][v32].read(); + v27[(v31 + (v28 * 2))][(v32 + (v29 * 10))] = v34; + } + float v35 = v27[(v31 + (v28 * 2))][(v32 + (v29 * 10))]; + float v36 = v23[(v32 + (v29 * 10))][(v33 + (v30 * 11))]; + if ((v32 + (v29 * 10)) == 0) { + v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))] = v25; + } + float v37 = v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))]; + float v38 = v35 * v36; + float v39 = v37 + v38; + v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))] = v39; + if (((v32 + (v29 * 10)) - 189) == 0) { + float v40 = v26[(v31 + (v28 * 2))][(v33 + (v30 * 11))]; + v24[v31][v33].write(v40); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v41[180][210], + float v42[210][190], + hls::stream v43[2][10], + float v44 +) { + #pragma HLS array_partition variable=v41 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v41 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v42 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v42 cyclic dim=2 factor=10 + + float v45[180][190]; + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=10 + + loop14: for (int v46 = 0; v46 < 90; v46++) { + loop15: for (int v47 = 0; v47 < 21; v47++) { + loop16: for (int v48 = 0; v48 < 19; v48++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop17: for (int v49 = 0; v49 < 2; v49++) { + loop18: for (int v50 = 0; v50 < 10; v50++) { + loop19: for (int v51 = 0; v51 < 10; v51++) { + float v52 = v41[(v49 + (v46 * 2))][(v50 + (v47 * 10))]; + float v53 = v42[(v50 + (v47 * 10))][(v51 + (v48 * 10))]; + if ((v50 + (v47 * 10)) == 0) { + v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))] = v44; + } + float v54 = v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))]; + float v55 = v52 * v53; + float v56 = v54 + v55; + v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))] = v56; + if (((v50 + (v47 * 10)) - 209) == 0) { + float v57 = v45[(v49 + (v46 * 2))][(v51 + (v48 * 10))]; + v43[v49][v51].write(v57); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v58[180][210], + float v59[210][190], + float v60[190][220], + float v61[180][220], + float v62[180][220] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v58 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v58 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v59 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v59 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v60 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v60 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v61 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v61 cyclic dim=2 factor=11 + + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=11 + + hls::stream v63[2][11]; + #pragma HLS STREAM variable=v63 depth=1800 + hls::stream v64[2][11]; + #pragma HLS STREAM variable=v64 depth=1800 + hls::stream v65[2][10]; + #pragma HLS STREAM variable=v65 depth=1710 + node3(v58, v59, v65, 0.000000); + node2(v65, v60, v64, 0.000000); + node1(v64, v61, v63, 0.100000, 0.500000); + node0(v63, v62); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt1/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt1/src/k3mm.cpp new file mode 100644 index 000000000000..a139155ff481 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt1/src/k3mm.cpp @@ -0,0 +1,154 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[180][210] +) { + loop0: for (int v2 = 0; v2 < 180; v2++) { + loop1: for (int v3 = 0; v3 < 210; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[190][210], + hls::stream &v7, + float v8 +) { + float v9[180][210]; + float v10[190][210]; + float v11[180][190]; + loop2: for (int v12 = 0; v12 < 180; v12++) { + loop3: for (int v13 = 0; v13 < 210; v13++) { + loop4: for (int v14 = 0; v14 < 190; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v13 == 0) { + float v15 = v5.read(); + v11[v12][v14] = v15; + } + float v16 = v11[v12][v14]; + if (v12 == 0) { + float v17 = v6[v14][v13]; + v10[v14][v13] = v17; + } + float v18 = v10[v14][v13]; + if (v14 == 0) { + v9[v12][v13] = v8; + } + float v19 = v9[v12][v13]; + float v20 = v16 * v18; + float v21 = v19 + v20; + v9[v12][v13] = v21; + if ((v14 - 189) == 0) { + float v22 = v9[v12][v13]; + v7.write(v22); + } + } + } + } + return ; +} + +void node2( + float v23[190][220], + float v24[220][210], + float v25[190][210], + float v26 +) { + float v27[190][210]; + loop5: for (int v28 = 0; v28 < 190; v28++) { + loop6: for (int v29 = 0; v29 < 210; v29++) { + loop7: for (int v30 = 0; v30 < 220; v30++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v31 = v23[v28][v30]; + float v32 = v24[v30][v29]; + if (v30 == 0) { + v27[v28][v29] = v26; + } + float v33 = v27[v28][v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v27[v28][v29] = v35; + if ((v30 - 219) == 0) { + float v36 = v27[v28][v29]; + v25[v28][v29] = v36; + } + } + } + } + return ; +} + +void node3( + float v37[180][200], + float v38[200][190], + hls::stream &v39, + float v40 +) { + float v41[180][190]; + loop8: for (int v42 = 0; v42 < 180; v42++) { + loop9: for (int v43 = 0; v43 < 190; v43++) { + loop10: for (int v44 = 0; v44 < 200; v44++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v45 = v37[v42][v44]; + float v46 = v38[v44][v43]; + if (v44 == 0) { + v41[v42][v43] = v40; + } + float v47 = v41[v42][v43]; + float v48 = v45 * v46; + float v49 = v47 + v48; + v41[v42][v43] = v49; + if ((v44 - 199) == 0) { + float v50 = v41[v42][v43]; + v39.write(v50); + } + } + } + } + return ; +} + +void forward( + float v51[180][200], + float v52[200][190], + float v53[190][220], + float v54[220][210], + float v55[180][210] +) { + #pragma HLS DATAFLOW + hls::stream v56("fifo_0"); + #pragma HLS STREAM variable=v56 depth=37800 + float v57[190][210]; + hls::stream v58("fifo_1"); + #pragma HLS STREAM variable=v58 depth=34200 + node3(v51, v52, v58, 0.000000); + node2(v53, v54, v57, 0.000000); + node1(v58, v57, v56, 0.000000); + node0(v56, v55); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt2/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt2/src/k3mm.cpp new file mode 100644 index 000000000000..cbeb4f0a74d4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt2/src/k3mm.cpp @@ -0,0 +1,145 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0(hls::stream &v0, float v1[180][210]) { +loop0: + for (int v2 = 0; v2 < 210; v2++) { + loop1: + for (int v3 = 0; v3 < 180; v3++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + float v4 = v0.read(); + v1[v3][v2] = v4; + } + } + return; +} + +void node1(hls::stream &v5, hls::stream &v6, + hls::stream &v7, float v8) { + float v9[180][210]; + float v10; + float v11[180]; +loop2: + for (int v12 = 0; v12 < 190; v12++) { + loop3: + for (int v13 = 0; v13 < 210; v13++) { + loop4: + for (int v14 = 0; v14 < 180; v14++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + if (v13 == 0) { + float v15 = v5.read(); + v11[v14] = v15; + } + float v16 = v11[v14]; + if (v14 == 0) { + float v17 = v6.read(); + v10 = v17; + } + float v18 = v10; + if (v12 == 0) { + v9[v14][v13] = v8; + } + float v19 = v9[v14][v13]; + float v20 = v16 * v18; + float v21 = v19 + v20; + v9[v14][v13] = v21; + if ((v12 - 189) == 0) { + float v22 = v9[v14][v13]; + v7.write(v22); + } + } + } + } + return; +} + +void node2(float v23[190][220], float v24[220][210], hls::stream &v25, + float v26) { + float v27[190][210]; +loop5: + for (int v28 = 0; v28 < 190; v28++) { + loop6: + for (int v29 = 0; v29 < 220; v29++) { + loop7: + for (int v30 = 0; v30 < 210; v30++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + float v31 = v23[v28][v29]; + float v32 = v24[v29][v30]; + if (v29 == 0) { + v27[v28][v30] = v26; + } + float v33 = v27[v28][v30]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v27[v28][v30] = v35; + if ((v29 - 219) == 0) { + float v36 = v27[v28][v30]; + v25.write(v36); + } + } + } + } + return; +} + +void node3(float v37[180][200], float v38[200][190], hls::stream &v39, + float v40) { + float v41[180][190]; +loop8: + for (int v42 = 0; v42 < 190; v42++) { + loop9: + for (int v43 = 0; v43 < 200; v43++) { + loop10: + for (int v44 = 0; v44 < 180; v44++) { +#pragma HLS pipeline II = 1 +#pragma HLS loop_flatten + float v45 = v37[v44][v43]; + float v46 = v38[v43][v42]; + if (v43 == 0) { + v41[v44][v42] = v40; + } + float v47 = v41[v44][v42]; + float v48 = v45 * v46; + float v49 = v47 + v48; + v41[v44][v42] = v49; + if ((v43 - 199) == 0) { + float v50 = v41[v44][v42]; + v39.write(v50); + } + } + } + } + return; +} + +void forward(float v51[180][200], float v52[200][190], float v53[190][220], + float v54[220][210], float v55[180][210]) { +#pragma HLS DATAFLOW + hls::stream v56("fifo_0"); +#pragma HLS STREAM variable = v56 depth = 37800 + hls::stream v57("fifo_1"); +#pragma HLS STREAM variable = v57 depth = 39900 + hls::stream v58("fifo_2"); +#pragma HLS STREAM variable = v58 depth = 34200 + node3(v51, v52, v58, 0.000000); + node2(v53, v54, v57, 0.000000); + node1(v58, v57, v56, 0.000000); + node0(v56, v55); + return; +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt3/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt3/src/k3mm.cpp new file mode 100644 index 000000000000..ccc77811461c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt3/src/k3mm.cpp @@ -0,0 +1,226 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[10][2], + float v1[180][210] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=2 + + loop0: for (int v2 = 0; v2 < 18; v2++) { + loop1: for (int v3 = 0; v3 < 105; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 10; v4++) { + loop3: for (int v5 = 0; v5 < 2; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 10))][(v5 + (v3 * 2))] = v6; + } + } + } + } + return ; +} + +void node1( + float v7[190][210], + hls::stream v8[10][10], + hls::stream v9[10][2], + float v10 +) { + #pragma HLS array_partition variable=v7 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v7 cyclic dim=2 factor=2 + + float v11[180][210]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=2 + + float v12[190][210]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + float v13[180][190]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=10 + + loop4: for (int v14 = 0; v14 < 18; v14++) { + loop5: for (int v15 = 0; v15 < 105; v15++) { + loop6: for (int v16 = 0; v16 < 19; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 10; v17++) { + loop8: for (int v18 = 0; v18 < 2; v18++) { + loop9: for (int v19 = 0; v19 < 10; v19++) { + if ((v18 + (v15 * 2)) == 0) { + float v20 = v8[v17][v19].read(); + v13[(v17 + (v14 * 10))][(v19 + (v16 * 10))] = v20; + } + float v21 = v13[(v17 + (v14 * 10))][(v19 + (v16 * 10))]; + if ((v17 + (v14 * 10)) == 0) { + float v22 = v7[(v19 + (v16 * 10))][(v18 + (v15 * 2))]; + v12[(v19 + (v16 * 10))][(v18 + (v15 * 2))] = v22; + } + float v23 = v12[(v19 + (v16 * 10))][(v18 + (v15 * 2))]; + if ((v19 + (v16 * 10)) == 0) { + v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))] = v10; + } + float v24 = v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))] = v26; + if (((v19 + (v16 * 10)) - 189) == 0) { + float v27 = v11[(v17 + (v14 * 10))][(v18 + (v15 * 2))]; + v9[v17][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v28[220][210], + float v29[190][220], + float v30[190][210], + float v31 +) { + #pragma HLS array_partition variable=v28 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v32[190][210]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=2 + + loop10: for (int v33 = 0; v33 < 19; v33++) { + loop11: for (int v34 = 0; v34 < 105; v34++) { + loop12: for (int v35 = 0; v35 < 22; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v36 = 0; v36 < 10; v36++) { + loop14: for (int v37 = 0; v37 < 2; v37++) { + loop15: for (int v38 = 0; v38 < 10; v38++) { + float v39 = v29[(v36 + (v33 * 10))][(v38 + (v35 * 10))]; + float v40 = v28[(v38 + (v35 * 10))][(v37 + (v34 * 2))]; + if ((v38 + (v35 * 10)) == 0) { + v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))] = v31; + } + float v41 = v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))] = v43; + if (((v38 + (v35 * 10)) - 219) == 0) { + float v44 = v32[(v36 + (v33 * 10))][(v37 + (v34 * 2))]; + v30[(v36 + (v33 * 10))][(v37 + (v34 * 2))] = v44; + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[180][200], + float v46[200][190], + hls::stream v47[10][10], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=10 + + float v49[180][190]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=10 + + loop16: for (int v50 = 0; v50 < 18; v50++) { + loop17: for (int v51 = 0; v51 < 19; v51++) { + loop18: for (int v52 = 0; v52 < 200; v52++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v53 = 0; v53 < 10; v53++) { + loop20: for (int v54 = 0; v54 < 10; v54++) { + loop21: for (int v55 = 0; v55 < 1; v55++) { + float v56 = v45[(v53 + (v50 * 10))][(v52 + v55)]; + float v57 = v46[(v52 + v55)][(v54 + (v51 * 10))]; + if ((v52 + v55) == 0) { + v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))] = v48; + } + float v58 = v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))]; + float v59 = v56 * v57; + float v60 = v58 + v59; + v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))] = v60; + if (((v52 + v55) - 199) == 0) { + float v61 = v49[(v53 + (v50 * 10))][(v54 + (v51 * 10))]; + v47[v53][v54].write(v61); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v62[180][200], + float v63[200][190], + float v64[190][220], + float v65[220][210], + float v66[180][210] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=2 + + hls::stream v67[10][2]; + #pragma HLS STREAM variable=v67 depth=1890 + float v68[190][210]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=2 + + hls::stream v69[10][10]; + #pragma HLS STREAM variable=v69 depth=342 + node3(v62, v63, v69, 0.000000); + node2(v65, v64, v68, 0.000000); + node1(v68, v69, v67, 0.000000); + node0(v67, v66); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt4/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt4/src/k3mm.cpp new file mode 100644 index 000000000000..37f913d32685 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt4/src/k3mm.cpp @@ -0,0 +1,222 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[3][10], + float v1[180][210] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=10 + + loop0: for (int v2 = 0; v2 < 21; v2++) { + loop1: for (int v3 = 0; v3 < 60; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 10; v4++) { + loop3: for (int v5 = 0; v5 < 3; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 3))][(v4 + (v2 * 10))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[3][5], + hls::stream v8[5][10], + hls::stream v9[3][10], + float v10 +) { + float v11[180][210]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=10 + + float v12[190][210]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=10 + + float v13[180][190]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=5 + + loop4: for (int v14 = 0; v14 < 38; v14++) { + loop5: for (int v15 = 0; v15 < 21; v15++) { + loop6: for (int v16 = 0; v16 < 60; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 5; v17++) { + loop8: for (int v18 = 0; v18 < 10; v18++) { + loop9: for (int v19 = 0; v19 < 3; v19++) { + if ((v18 + (v15 * 10)) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))] = v20; + } + float v21 = v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))]; + if ((v19 + (v16 * 3)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))] = v22; + } + float v23 = v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))]; + if ((v17 + (v14 * 5)) == 0) { + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v10; + } + float v24 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v26; + if (((v17 + (v14 * 5)) - 189) == 0) { + float v27 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v28[190][220], + float v29[220][210], + hls::stream v30[5][10], + float v31 +) { + #pragma HLS array_partition variable=v28 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + float v32[190][210]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=10 + + loop10: for (int v33 = 0; v33 < 38; v33++) { + loop11: for (int v34 = 0; v34 < 55; v34++) { + loop12: for (int v35 = 0; v35 < 21; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v36 = 0; v36 < 5; v36++) { + loop14: for (int v37 = 0; v37 < 4; v37++) { + loop15: for (int v38 = 0; v38 < 10; v38++) { + float v39 = v28[(v36 + (v33 * 5))][(v37 + (v34 * 4))]; + float v40 = v29[(v37 + (v34 * 4))][(v38 + (v35 * 10))]; + if ((v37 + (v34 * 4)) == 0) { + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v31; + } + float v41 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v43; + if (((v37 + (v34 * 4)) - 219) == 0) { + float v44 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + v30[v36][v38].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[200][190], + float v46[180][200], + hls::stream v47[3][5], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=10 + + float v49[180][190]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=5 + + loop16: for (int v50 = 0; v50 < 38; v50++) { + loop17: for (int v51 = 0; v51 < 20; v51++) { + loop18: for (int v52 = 0; v52 < 60; v52++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v53 = 0; v53 < 5; v53++) { + loop20: for (int v54 = 0; v54 < 10; v54++) { + loop21: for (int v55 = 0; v55 < 3; v55++) { + float v56 = v46[(v55 + (v52 * 3))][(v54 + (v51 * 10))]; + float v57 = v45[(v54 + (v51 * 10))][(v53 + (v50 * 5))]; + if ((v54 + (v51 * 10)) == 0) { + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v48; + } + float v58 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + float v59 = v56 * v57; + float v60 = v58 + v59; + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v60; + if (((v54 + (v51 * 10)) - 199) == 0) { + float v61 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + v47[v55][v53].write(v61); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v62[180][200], + float v63[200][190], + float v64[190][220], + float v65[220][210], + float v66[180][210] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=10 + + hls::stream v67[3][10]; + #pragma HLS STREAM variable=v67 depth=1260 + hls::stream v68[5][10]; + #pragma HLS STREAM variable=v68 depth=798 + hls::stream v69[3][5]; + #pragma HLS STREAM variable=v69 depth=2280 + node3(v63, v62, v69, 0.000000); + node2(v64, v65, v68, 0.000000); + node1(v69, v68, v67, 0.000000); + node0(v67, v66); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt5/src/k3mm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt5/src/k3mm.cpp new file mode 100644 index 000000000000..302c9e31d0c5 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k3mm__opt5/src/k3mm.cpp @@ -0,0 +1,222 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[3][10], + float v1[180][210] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=10 + + loop0: for (int v2 = 0; v2 < 21; v2++) { + loop1: for (int v3 = 0; v3 < 60; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 10; v4++) { + loop3: for (int v5 = 0; v5 < 3; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 3))][(v4 + (v2 * 10))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[3][5], + hls::stream v8[5][10], + hls::stream v9[3][10], + float v10 +) { + float v11[180][210]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=10 + + float v12[190][210]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=10 + + float v13[180][190]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=5 + + loop4: for (int v14 = 0; v14 < 38; v14++) { + loop5: for (int v15 = 0; v15 < 21; v15++) { + loop6: for (int v16 = 0; v16 < 60; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 5; v17++) { + loop8: for (int v18 = 0; v18 < 10; v18++) { + loop9: for (int v19 = 0; v19 < 3; v19++) { + if ((v18 + (v15 * 10)) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))] = v20; + } + float v21 = v13[(v19 + (v16 * 3))][(v17 + (v14 * 5))]; + if ((v19 + (v16 * 3)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))] = v22; + } + float v23 = v12[(v17 + (v14 * 5))][(v18 + (v15 * 10))]; + if ((v17 + (v14 * 5)) == 0) { + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v10; + } + float v24 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))] = v26; + if (((v17 + (v14 * 5)) - 189) == 0) { + float v27 = v11[(v19 + (v16 * 3))][(v18 + (v15 * 10))]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v28[190][220], + float v29[220][210], + hls::stream v30[5][10], + float v31 +) { + #pragma HLS array_partition variable=v28 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v28 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v29 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v29 cyclic dim=2 factor=10 + + float v32[190][210]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=10 + + loop10: for (int v33 = 0; v33 < 38; v33++) { + loop11: for (int v34 = 0; v34 < 55; v34++) { + loop12: for (int v35 = 0; v35 < 21; v35++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v36 = 0; v36 < 5; v36++) { + loop14: for (int v37 = 0; v37 < 4; v37++) { + loop15: for (int v38 = 0; v38 < 10; v38++) { + float v39 = v28[(v36 + (v33 * 5))][(v37 + (v34 * 4))]; + float v40 = v29[(v37 + (v34 * 4))][(v38 + (v35 * 10))]; + if ((v37 + (v34 * 4)) == 0) { + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v31; + } + float v41 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))] = v43; + if (((v37 + (v34 * 4)) - 219) == 0) { + float v44 = v32[(v36 + (v33 * 5))][(v38 + (v35 * 10))]; + v30[v36][v38].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[180][200], + float v46[200][190], + hls::stream v47[3][5], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=5 + + float v49[180][190]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=5 + + loop16: for (int v50 = 0; v50 < 38; v50++) { + loop17: for (int v51 = 0; v51 < 20; v51++) { + loop18: for (int v52 = 0; v52 < 60; v52++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v53 = 0; v53 < 5; v53++) { + loop20: for (int v54 = 0; v54 < 10; v54++) { + loop21: for (int v55 = 0; v55 < 3; v55++) { + float v56 = v45[(v55 + (v52 * 3))][(v54 + (v51 * 10))]; + float v57 = v46[(v54 + (v51 * 10))][(v53 + (v50 * 5))]; + if ((v54 + (v51 * 10)) == 0) { + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v48; + } + float v58 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + float v59 = v56 * v57; + float v60 = v58 + v59; + v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))] = v60; + if (((v54 + (v51 * 10)) - 199) == 0) { + float v61 = v49[(v55 + (v52 * 3))][(v53 + (v50 * 5))]; + v47[v55][v53].write(v61); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v62[180][200], + float v63[200][190], + float v64[190][220], + float v65[220][210], + float v66[180][210] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v62 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v62 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v63 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v63 cyclic dim=2 factor=5 + + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=5 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=10 + + #pragma HLS array_partition variable=v66 cyclic dim=1 factor=3 + #pragma HLS array_partition variable=v66 cyclic dim=2 factor=10 + + hls::stream v67[3][10]; + #pragma HLS STREAM variable=v67 depth=1260 + hls::stream v68[5][10]; + #pragma HLS STREAM variable=v68 depth=798 + hls::stream v69[3][5]; + #pragma HLS STREAM variable=v69 depth=2280 + node3(v62, v63, v69, 0.000000); + node2(v64, v65, v68, 0.000000); + node1(v69, v68, v67, 0.000000); + node0(v67, v66); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..610ad767f306 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt1/src/k7mmseq_balanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][64] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 64; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[64][64], + hls::stream &v7, + float v8 +) { + float v9[64][64]; + float v10[64][64]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 64; v12++) { + loop4: for (int v13 = 0; v13 < 64; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v12 == 0) { + float v14 = v5.read(); + v10[v11][v13] = v14; + } + float v15 = v10[v11][v13]; + float v16 = v6[v13][v12]; + if (v13 == 0) { + v9[v11][v12] = v8; + } + float v17 = v9[v11][v12]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v12] = v19; + if ((v13 - 63) == 0) { + float v20 = v9[v11][v12]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][64], + hls::stream &v23, + float v24 +) { + float v25[64][64]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 64; v28++) { + loop7: for (int v29 = 0; v29 < 64; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v28 == 0) { + float v30 = v21.read(); + v26[v27][v29] = v30; + } + float v31 = v26[v27][v29]; + float v32 = v22[v29][v28]; + if (v29 == 0) { + v25[v27][v28] = v24; + } + float v33 = v25[v27][v28]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v28] = v35; + if ((v29 - 63) == 0) { + float v36 = v25[v27][v28]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[64][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][64]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 64; v44++) { + loop10: for (int v45 = 0; v45 < 64; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v44 == 0) { + float v46 = v37.read(); + v42[v43][v45] = v46; + } + float v47 = v42[v43][v45]; + float v48 = v38[v45][v44]; + if (v45 == 0) { + v41[v43][v44] = v40; + } + float v49 = v41[v43][v44]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v44] = v51; + if ((v45 - 63) == 0) { + float v52 = v41[v43][v44]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[64][64], + hls::stream &v55, + float v56 +) { + float v57[64][64]; + float v58[64][64]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 64; v60++) { + loop13: for (int v61 = 0; v61 < 64; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { + float v62 = v53.read(); + v58[v59][v61] = v62; + } + float v63 = v58[v59][v61]; + float v64 = v54[v61][v60]; + if (v61 == 0) { + v57[v59][v60] = v56; + } + float v65 = v57[v59][v60]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v60] = v67; + if ((v61 - 63) == 0) { + float v68 = v57[v59][v60]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][64], + hls::stream &v71, + float v72 +) { + float v73[64][64]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 64; v76++) { + loop16: for (int v77 = 0; v77 < 64; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v76 == 0) { + float v78 = v69.read(); + v74[v75][v77] = v78; + } + float v79 = v74[v75][v77]; + float v80 = v70[v77][v76]; + if (v77 == 0) { + v73[v75][v76] = v72; + } + float v81 = v73[v75][v76]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v76] = v83; + if ((v77 - 63) == 0) { + float v84 = v73[v75][v76]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v92 == 0) { + float v94 = v85.read(); + v90[v91][v93] = v94; + } + float v95 = v90[v91][v93]; + float v96 = v86[v93][v92]; + if (v93 == 0) { + v89[v91][v92] = v88; + } + float v97 = v89[v91][v92]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v92] = v99; + if ((v93 - 63) == 0) { + float v100 = v89[v91][v92]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][64], + float v102[64][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 64; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v108]; + float v110 = v102[v108][v107]; + if (v108 == 0) { + v105[v106][v107] = v104; + } + float v111 = v105[v106][v107]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v107] = v113; + if ((v108 - 63) == 0) { + float v114 = v105[v106][v107]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][64], + float v116[64][64], + float v117[64][64], + float v118[64][64], + float v119[64][64], + float v120[64][64], + float v121[64][64], + float v122[64][64], + float v123[64][64] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=4096 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=4096 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=4096 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=4096 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..da1847f34942 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt2/src/k7mmseq_balanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][64] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 64; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[64][64], + hls::stream &v7, + float v8 +) { + float v9[64][64]; + float v10[64][64]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 64; v12++) { + loop4: for (int v13 = 0; v13 < 64; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v13 == 0) { + float v14 = v5.read(); + v10[v11][v12] = v14; + } + float v15 = v10[v11][v12]; + float v16 = v6[v12][v13]; + if (v12 == 0) { + v9[v11][v13] = v8; + } + float v17 = v9[v11][v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v13] = v19; + if ((v12 - 63) == 0) { + float v20 = v9[v11][v13]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][64], + hls::stream &v23, + float v24 +) { + float v25[64][64]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 64; v28++) { + loop7: for (int v29 = 0; v29 < 64; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v29 == 0) { + float v30 = v21.read(); + v26[v27][v28] = v30; + } + float v31 = v26[v27][v28]; + float v32 = v22[v28][v29]; + if (v28 == 0) { + v25[v27][v29] = v24; + } + float v33 = v25[v27][v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v29] = v35; + if ((v28 - 63) == 0) { + float v36 = v25[v27][v29]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[64][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][64]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 64; v44++) { + loop10: for (int v45 = 0; v45 < 64; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v45 == 0) { + float v46 = v37.read(); + v42[v43][v44] = v46; + } + float v47 = v42[v43][v44]; + float v48 = v38[v44][v45]; + if (v44 == 0) { + v41[v43][v45] = v40; + } + float v49 = v41[v43][v45]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v45] = v51; + if ((v44 - 63) == 0) { + float v52 = v41[v43][v45]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[64][64], + hls::stream &v55, + float v56 +) { + float v57[64][64]; + float v58[64][64]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 64; v60++) { + loop13: for (int v61 = 0; v61 < 64; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v61 == 0) { + float v62 = v53.read(); + v58[v59][v60] = v62; + } + float v63 = v58[v59][v60]; + float v64 = v54[v60][v61]; + if (v60 == 0) { + v57[v59][v61] = v56; + } + float v65 = v57[v59][v61]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v61] = v67; + if ((v60 - 63) == 0) { + float v68 = v57[v59][v61]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][64], + hls::stream &v71, + float v72 +) { + float v73[64][64]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 64; v76++) { + loop16: for (int v77 = 0; v77 < 64; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v77 == 0) { + float v78 = v69.read(); + v74[v75][v76] = v78; + } + float v79 = v74[v75][v76]; + float v80 = v70[v76][v77]; + if (v76 == 0) { + v73[v75][v77] = v72; + } + float v81 = v73[v75][v77]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v77] = v83; + if ((v76 - 63) == 0) { + float v84 = v73[v75][v77]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v93 == 0) { + float v94 = v85.read(); + v90[v91][v92] = v94; + } + float v95 = v90[v91][v92]; + float v96 = v86[v92][v93]; + if (v92 == 0) { + v89[v91][v93] = v88; + } + float v97 = v89[v91][v93]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v93] = v99; + if ((v92 - 63) == 0) { + float v100 = v89[v91][v93]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][64], + float v102[64][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 64; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v107]; + float v110 = v102[v107][v108]; + if (v107 == 0) { + v105[v106][v108] = v104; + } + float v111 = v105[v106][v108]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v108] = v113; + if ((v107 - 63) == 0) { + float v114 = v105[v106][v108]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][64], + float v116[64][64], + float v117[64][64], + float v118[64][64], + float v119[64][64], + float v120[64][64], + float v121[64][64], + float v122[64][64], + float v123[64][64] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=4096 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=4096 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=4096 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=4096 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..30fbf33536a6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt3/src/k7mmseq_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + float v8[64][64], + hls::stream v9[4][4], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=4 + + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 4; v17++) { + loop9: for (int v18 = 0; v18 < 4; v18++) { + if ((v17 + (v14 * 4)) == 0) { + float v19 = v7[v16][v18].read(); + v12[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + float v21 = v8[(v18 + (v15 * 4))][(v17 + (v14 * 4))]; + if ((v18 + (v15 * 4)) == 0) { + v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v24; + if (((v18 + (v15 * 4)) - 63) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + v9[v16][v17].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][64], + hls::stream v28[4][4], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=4 + + float v30[64][64]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=4 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v36 + (v33 * 4)) == 0) { + float v38 = v26[v35][v37].read(); + v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v40 = v27[(v37 + (v34 * 4))][(v36 + (v33 * 4))]; + if ((v37 + (v34 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v43; + if (((v37 + (v34 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + v28[v35][v36].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v45[4][4], + float v46[64][64], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][64]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v55 + (v52 * 4)) == 0) { + float v57 = v45[v54][v56].read(); + v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v59 = v46[(v56 + (v53 * 4))][(v55 + (v52 * 4))]; + if ((v56 + (v53 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v62; + if (((v56 + (v53 * 4)) - 63) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + v47[v54][v55].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[64][64], + hls::stream v65[4][4], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + float v68[64][64]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][64]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v74 + (v71 * 4)) == 0) { + float v76 = v65[v73][v75].read(); + v69[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v78 = v64[(v75 + (v72 * 4))][(v74 + (v71 * 4))]; + if ((v75 + (v72 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v81; + if (((v75 + (v72 * 4)) - 63) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + v66[v73][v74].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][64], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v93 + (v90 * 4)) == 0) { + float v95 = v83[v92][v94].read(); + v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v97 = v84[(v94 + (v91 * 4))][(v93 + (v90 * 4))]; + if ((v94 + (v91 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v100; + if (((v94 + (v91 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + v85[v92][v93].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v102[64][64], + hls::stream v103[4][4], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v102 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v102 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v112 + (v109 * 4)) == 0) { + float v114 = v103[v111][v113].read(); + v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v116 = v102[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + v104[v111][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v133 = v122[(v131 + (v128 * 4))][(v130 + (v127 * 4))]; + if ((v131 + (v128 * 4)) == 0) { + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v136; + if (((v131 + (v128 * 4)) - 63) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + v123[v129][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v140, v153, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v150, v143, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..9b7cfc44c8eb --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt4/src/k7mmseq_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + float v7[64][64], + hls::stream v8[4][4], + hls::stream v9[4][4], + float v10 +) { + #pragma HLS array_partition variable=v7 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v7 cyclic dim=2 factor=4 + + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 4; v17++) { + loop9: for (int v18 = 0; v18 < 4; v18++) { + if ((v18 + (v15 * 4)) == 0) { + float v19 = v8[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + float v21 = v7[(v17 + (v14 * 4))][(v18 + (v15 * 4))]; + if ((v17 + (v14 * 4)) == 0) { + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v24; + if (((v17 + (v14 * 4)) - 63) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + float v26[64][64], + hls::stream v27[4][4], + hls::stream v28[4][4], + float v29 +) { + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=4 + + float v30[64][64]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=4 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v37 + (v34 * 4)) == 0) { + float v38 = v27[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v26[(v36 + (v33 * 4))][(v37 + (v34 * 4))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[64][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][64]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v46[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v59 = v45[(v55 + (v52 * 4))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 4)) - 63) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[64][64], + hls::stream v65[4][4], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + float v68[64][64]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][64]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v75 + (v72 * 4)) == 0) { + float v76 = v65[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v78 = v64[(v74 + (v71 * 4))][(v75 + (v72 * 4))]; + if ((v74 + (v71 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v81; + if (((v74 + (v71 * 4)) - 63) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][64], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v94 + (v91 * 4)) == 0) { + float v95 = v83[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v84[(v93 + (v90 * 4))][(v94 + (v91 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v113 + (v110 * 4)) == 0) { + float v114 = v102[v111][v112].read(); + v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v116 = v103[(v112 + (v109 * 4))][(v113 + (v110 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v119; + if (((v112 + (v109 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + v104[v111][v113].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v133 = v121[(v130 + (v127 * 4))][(v131 + (v128 * 4))]; + if ((v130 + (v127 * 4)) == 0) { + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v136; + if (((v130 + (v127 * 4)) - 63) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + v123[v129][v131].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v144, v149, v148, 0.000000); + node1(v145, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp new file mode 100644 index 000000000000..4fbb80d4d29a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_balanced__opt5/src/k7mmseq_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v5 + (v3 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + float v8[64][64], + hls::stream v9[4][4], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v8 cyclic dim=2 factor=4 + + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 4; v17++) { + loop9: for (int v18 = 0; v18 < 4; v18++) { + if ((v18 + (v15 * 4)) == 0) { + float v19 = v7[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 4))]; + float v21 = v8[(v17 + (v14 * 4))][(v18 + (v15 * 4))]; + if ((v17 + (v14 * 4)) == 0) { + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))] = v24; + if (((v17 + (v14 * 4)) - 63) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v18 + (v15 * 4))]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][64], + hls::stream v28[4][4], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=4 + + float v30[64][64]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=4 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v37 + (v34 * 4)) == 0) { + float v38 = v26[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v27[(v36 + (v33 * 4))][(v37 + (v34 * 4))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[64][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][64]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v46[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v59 = v45[(v55 + (v52 * 4))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 4)) - 63) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[64][64], + hls::stream v65[4][4], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=4 + + float v68[64][64]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][64]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v75 + (v72 * 4)) == 0) { + float v76 = v65[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v78 = v64[(v74 + (v71 * 4))][(v75 + (v72 * 4))]; + if ((v74 + (v71 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v81; + if (((v74 + (v71 * 4)) - 63) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][64], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][64]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v94 + (v91 * 4)) == 0) { + float v95 = v83[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v84[(v93 + (v90 * 4))][(v94 + (v91 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v113 + (v110 * 4)) == 0) { + float v114 = v102[v111][v112].read(); + v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v116 = v103[(v112 + (v109 * 4))][(v113 + (v110 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v119; + if (((v112 + (v109 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + v104[v111][v113].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v133 = v121[(v130 + (v127 * 4))][(v131 + (v128 * 4))]; + if ((v130 + (v127 * 4)) == 0) { + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v136; + if (((v130 + (v127 * 4)) - 63) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + v123[v129][v131].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..f04050d017da --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt1/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][16] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[32][16], + hls::stream &v7, + float v8 +) { + float v9[64][16]; + float v10[64][32]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 16; v12++) { + loop4: for (int v13 = 0; v13 < 32; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v12 == 0) { + float v14 = v5.read(); + v10[v11][v13] = v14; + } + float v15 = v10[v11][v13]; + float v16 = v6[v13][v12]; + if (v13 == 0) { + v9[v11][v12] = v8; + } + float v17 = v9[v11][v12]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v12] = v19; + if ((v13 - 31) == 0) { + float v20 = v9[v11][v12]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][32], + hls::stream &v23, + float v24 +) { + float v25[64][32]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 32; v28++) { + loop7: for (int v29 = 0; v29 < 64; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v28 == 0) { + float v30 = v21.read(); + v26[v27][v29] = v30; + } + float v31 = v26[v27][v29]; + float v32 = v22[v29][v28]; + if (v29 == 0) { + v25[v27][v28] = v24; + } + float v33 = v25[v27][v28]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v28] = v35; + if ((v29 - 63) == 0) { + float v36 = v25[v27][v28]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[128][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][128]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 64; v44++) { + loop10: for (int v45 = 0; v45 < 128; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v44 == 0) { + float v46 = v37.read(); + v42[v43][v45] = v46; + } + float v47 = v42[v43][v45]; + float v48 = v38[v45][v44]; + if (v45 == 0) { + v41[v43][v44] = v40; + } + float v49 = v41[v43][v44]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v44] = v51; + if ((v45 - 127) == 0) { + float v52 = v41[v43][v44]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[128][128], + hls::stream &v55, + float v56 +) { + float v57[64][128]; + float v58[64][128]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 128; v60++) { + loop13: for (int v61 = 0; v61 < 128; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v60 == 0) { + float v62 = v53.read(); + v58[v59][v61] = v62; + } + float v63 = v58[v59][v61]; + float v64 = v54[v61][v60]; + if (v61 == 0) { + v57[v59][v60] = v56; + } + float v65 = v57[v59][v60]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v60] = v67; + if ((v61 - 127) == 0) { + float v68 = v57[v59][v60]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][128], + hls::stream &v71, + float v72 +) { + float v73[64][128]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 128; v76++) { + loop16: for (int v77 = 0; v77 < 64; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v76 == 0) { + float v78 = v69.read(); + v74[v75][v77] = v78; + } + float v79 = v74[v75][v77]; + float v80 = v70[v77][v76]; + if (v77 == 0) { + v73[v75][v76] = v72; + } + float v81 = v73[v75][v76]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v76] = v83; + if ((v77 - 63) == 0) { + float v84 = v73[v75][v76]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v92 == 0) { + float v94 = v85.read(); + v90[v91][v93] = v94; + } + float v95 = v90[v91][v93]; + float v96 = v86[v93][v92]; + if (v93 == 0) { + v89[v91][v92] = v88; + } + float v97 = v89[v91][v92]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v92] = v99; + if ((v93 - 63) == 0) { + float v100 = v89[v91][v92]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][32], + float v102[32][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 32; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v108]; + float v110 = v102[v108][v107]; + if (v108 == 0) { + v105[v106][v107] = v104; + } + float v111 = v105[v106][v107]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v107] = v113; + if ((v108 - 31) == 0) { + float v114 = v105[v106][v107]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][32], + float v116[32][64], + float v117[64][64], + float v118[64][128], + float v119[128][128], + float v120[128][64], + float v121[64][32], + float v122[32][16], + float v123[64][16] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=1024 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=2048 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=8192 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=8192 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..1282c774174f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt2/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,315 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[64][16] +) { + loop0: for (int v2 = 0; v2 < 64; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v4 = v0.read(); + v1[v2][v3] = v4; + } + } + return ; +} + +void node1( + hls::stream &v5, + float v6[32][16], + hls::stream &v7, + float v8 +) { + float v9[64][16]; + float v10[64][32]; + loop2: for (int v11 = 0; v11 < 64; v11++) { + loop3: for (int v12 = 0; v12 < 32; v12++) { + loop4: for (int v13 = 0; v13 < 16; v13++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v13 == 0) { + float v14 = v5.read(); + v10[v11][v12] = v14; + } + float v15 = v10[v11][v12]; + float v16 = v6[v12][v13]; + if (v12 == 0) { + v9[v11][v13] = v8; + } + float v17 = v9[v11][v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v9[v11][v13] = v19; + if ((v12 - 31) == 0) { + float v20 = v9[v11][v13]; + v7.write(v20); + } + } + } + } + return ; +} + +void node2( + hls::stream &v21, + float v22[64][32], + hls::stream &v23, + float v24 +) { + float v25[64][32]; + float v26[64][64]; + loop5: for (int v27 = 0; v27 < 64; v27++) { + loop6: for (int v28 = 0; v28 < 64; v28++) { + loop7: for (int v29 = 0; v29 < 32; v29++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v29 == 0) { + float v30 = v21.read(); + v26[v27][v28] = v30; + } + float v31 = v26[v27][v28]; + float v32 = v22[v28][v29]; + if (v28 == 0) { + v25[v27][v29] = v24; + } + float v33 = v25[v27][v29]; + float v34 = v31 * v32; + float v35 = v33 + v34; + v25[v27][v29] = v35; + if ((v28 - 63) == 0) { + float v36 = v25[v27][v29]; + v23.write(v36); + } + } + } + } + return ; +} + +void node3( + hls::stream &v37, + float v38[128][64], + hls::stream &v39, + float v40 +) { + float v41[64][64]; + float v42[64][128]; + loop8: for (int v43 = 0; v43 < 64; v43++) { + loop9: for (int v44 = 0; v44 < 128; v44++) { + loop10: for (int v45 = 0; v45 < 64; v45++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v45 == 0) { + float v46 = v37.read(); + v42[v43][v44] = v46; + } + float v47 = v42[v43][v44]; + float v48 = v38[v44][v45]; + if (v44 == 0) { + v41[v43][v45] = v40; + } + float v49 = v41[v43][v45]; + float v50 = v47 * v48; + float v51 = v49 + v50; + v41[v43][v45] = v51; + if ((v44 - 127) == 0) { + float v52 = v41[v43][v45]; + v39.write(v52); + } + } + } + } + return ; +} + +void node4( + hls::stream &v53, + float v54[128][128], + hls::stream &v55, + float v56 +) { + float v57[64][128]; + float v58[64][128]; + loop11: for (int v59 = 0; v59 < 64; v59++) { + loop12: for (int v60 = 0; v60 < 128; v60++) { + loop13: for (int v61 = 0; v61 < 128; v61++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v61 == 0) { + float v62 = v53.read(); + v58[v59][v60] = v62; + } + float v63 = v58[v59][v60]; + float v64 = v54[v60][v61]; + if (v60 == 0) { + v57[v59][v61] = v56; + } + float v65 = v57[v59][v61]; + float v66 = v63 * v64; + float v67 = v65 + v66; + v57[v59][v61] = v67; + if ((v60 - 127) == 0) { + float v68 = v57[v59][v61]; + v55.write(v68); + } + } + } + } + return ; +} + +void node5( + hls::stream &v69, + float v70[64][128], + hls::stream &v71, + float v72 +) { + float v73[64][128]; + float v74[64][64]; + loop14: for (int v75 = 0; v75 < 64; v75++) { + loop15: for (int v76 = 0; v76 < 64; v76++) { + loop16: for (int v77 = 0; v77 < 128; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v77 == 0) { + float v78 = v69.read(); + v74[v75][v76] = v78; + } + float v79 = v74[v75][v76]; + float v80 = v70[v76][v77]; + if (v76 == 0) { + v73[v75][v77] = v72; + } + float v81 = v73[v75][v77]; + float v82 = v79 * v80; + float v83 = v81 + v82; + v73[v75][v77] = v83; + if ((v76 - 63) == 0) { + float v84 = v73[v75][v77]; + v71.write(v84); + } + } + } + } + return ; +} + +void node6( + hls::stream &v85, + float v86[64][64], + hls::stream &v87, + float v88 +) { + float v89[64][64]; + float v90[64][64]; + loop17: for (int v91 = 0; v91 < 64; v91++) { + loop18: for (int v92 = 0; v92 < 64; v92++) { + loop19: for (int v93 = 0; v93 < 64; v93++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + if (v92 == 0) { + float v94 = v85.read(); + v90[v91][v93] = v94; + } + float v95 = v90[v91][v93]; + float v96 = v86[v93][v92]; + if (v93 == 0) { + v89[v91][v92] = v88; + } + float v97 = v89[v91][v92]; + float v98 = v95 * v96; + float v99 = v97 + v98; + v89[v91][v92] = v99; + if ((v93 - 63) == 0) { + float v100 = v89[v91][v92]; + v87.write(v100); + } + } + } + } + return ; +} + +void node7( + float v101[64][32], + float v102[32][64], + hls::stream &v103, + float v104 +) { + float v105[64][64]; + loop20: for (int v106 = 0; v106 < 64; v106++) { + loop21: for (int v107 = 0; v107 < 64; v107++) { + loop22: for (int v108 = 0; v108 < 32; v108++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v109 = v101[v106][v108]; + float v110 = v102[v108][v107]; + if (v108 == 0) { + v105[v106][v107] = v104; + } + float v111 = v105[v106][v107]; + float v112 = v109 * v110; + float v113 = v111 + v112; + v105[v106][v107] = v113; + if ((v108 - 31) == 0) { + float v114 = v105[v106][v107]; + v103.write(v114); + } + } + } + } + return ; +} + +void forward( + float v115[64][32], + float v116[32][64], + float v117[64][64], + float v118[64][128], + float v119[128][128], + float v120[128][64], + float v121[64][32], + float v122[32][16], + float v123[64][16] +) { + #pragma HLS DATAFLOW + hls::stream v124("fifo_0"); + #pragma HLS STREAM variable=v124 depth=1024 + hls::stream v125("fifo_1"); + #pragma HLS STREAM variable=v125 depth=2048 + hls::stream v126("fifo_2"); + #pragma HLS STREAM variable=v126 depth=4096 + hls::stream v127("fifo_3"); + #pragma HLS STREAM variable=v127 depth=8192 + hls::stream v128("fifo_4"); + #pragma HLS STREAM variable=v128 depth=8192 + hls::stream v129("fifo_5"); + #pragma HLS STREAM variable=v129 depth=4096 + hls::stream v130("fifo_6"); + #pragma HLS STREAM variable=v130 depth=4096 + node7(v115, v116, v130, 0.000000); + node6(v130, v117, v129, 0.000000); + node5(v129, v118, v128, 0.000000); + node4(v128, v119, v127, 0.000000); + node3(v127, v120, v126, 0.000000); + node2(v126, v121, v125, 0.000000); + node1(v125, v122, v124, 0.000000); + node0(v124, v123); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..48d9fb758721 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt3/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,449 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + float v7[32][16], + hls::stream v8[4][2], + hls::stream v9[4][1], + float v10 +) { + #pragma HLS array_partition variable=v7 cyclic dim=1 factor=2 + + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[64][32]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 1; v17++) { + loop9: for (int v18 = 0; v18 < 2; v18++) { + if ((v14 + v17) == 0) { + float v19 = v8[v16][v18].read(); + v12[(v16 + (v13 * 4))][(v18 + (v15 * 2))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v18 + (v15 * 2))]; + float v21 = v7[(v18 + (v15 * 2))][(v14 + v17)]; + if ((v18 + (v15 * 2)) == 0) { + v11[(v16 + (v13 * 4))][(v14 + v17)] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v14 + v17)]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v14 + v17)] = v24; + if (((v18 + (v15 * 2)) - 31) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v14 + v17)]; + v9[v16][v17].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][32], + hls::stream v28[4][2], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=2 + + float v30[64][32]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 2; v36++) { + loop15: for (int v37 = 0; v37 < 4; v37++) { + if ((v36 + (v33 * 2)) == 0) { + float v38 = v26[v35][v37].read(); + v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v37 + (v34 * 4))]; + float v40 = v27[(v37 + (v34 * 4))][(v36 + (v33 * 2))]; + if ((v37 + (v34 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))] = v43; + if (((v37 + (v34 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v36 + (v33 * 2))]; + v28[v35][v36].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[128][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][128]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 32; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v55 + (v52 * 4)) == 0) { + float v57 = v46[v54][v56].read(); + v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v59 = v45[(v56 + (v53 * 4))][(v55 + (v52 * 4))]; + if ((v56 + (v53 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v62; + if (((v56 + (v53 * 4)) - 127) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + v47[v54][v55].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v64[4][8], + float v65[128][128], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=4 + + float v68[64][128]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][128]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=8 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 32; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 8; v75++) { + if ((v74 + (v71 * 4)) == 0) { + float v76 = v64[v73][v75].read(); + v69[(v73 + (v70 * 4))][(v75 + (v72 * 8))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v75 + (v72 * 8))]; + float v78 = v65[(v75 + (v72 * 8))][(v74 + (v71 * 4))]; + if ((v75 + (v72 * 8)) == 0) { + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v81; + if (((v75 + (v72 * 8)) - 127) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + v66[v73][v74].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v83[64][128], + hls::stream v84[4][4], + hls::stream v85[4][8], + float v86 +) { + #pragma HLS array_partition variable=v83 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v83 cyclic dim=2 factor=8 + + float v87[64][128]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=8 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 8; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v93 + (v90 * 8)) == 0) { + float v95 = v84[v92][v94].read(); + v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v97 = v83[(v94 + (v91 * 4))][(v93 + (v90 * 8))]; + if ((v94 + (v91 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))] = v100; + if (((v94 + (v91 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v93 + (v90 * 8))]; + v85[v92][v93].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v112 + (v109 * 4)) == 0) { + float v114 = v102[v111][v113].read(); + v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v116 = v103[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + v104[v111][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[32][64], + float v122[64][32], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=2 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 2; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v131 + (v128 * 2))]; + float v133 = v121[(v131 + (v128 * 2))][(v130 + (v127 * 4))]; + if ((v131 + (v128 * 2)) == 0) { + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v136; + if (((v131 + (v128 * 2)) - 31) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + v123[v129][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][2]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=512 + hls::stream v151[4][8]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v141, v152, v151, 0.000000); + node4(v151, v142, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v145, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..8866264cc737 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt4/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,449 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][2], + float v8[32][16], + hls::stream v9[4][1], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[64][32]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 2; v17++) { + loop9: for (int v18 = 0; v18 < 1; v18++) { + if ((v15 + v18) == 0) { + float v19 = v7[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))]; + float v21 = v8[(v17 + (v14 * 2))][(v15 + v18)]; + if ((v17 + (v14 * 2)) == 0) { + v11[(v16 + (v13 * 4))][(v15 + v18)] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v15 + v18)] = v24; + if (((v17 + (v14 * 2)) - 31) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][32], + hls::stream v28[4][2], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=2 + + float v30[64][32]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 2; v37++) { + if ((v37 + (v34 * 2)) == 0) { + float v38 = v26[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v27[(v36 + (v33 * 4))][(v37 + (v34 * 2))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + float v45[128][64], + hls::stream v46[4][4], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v45 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v45 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][128]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=4 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 32; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 4; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v46[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 4))]; + float v59 = v45[(v55 + (v52 * 4))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 4)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 4)) - 127) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + hls::stream v64[4][8], + float v65[128][128], + hls::stream v66[4][4], + float v67 +) { + #pragma HLS array_partition variable=v65 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v65 cyclic dim=2 factor=4 + + float v68[64][128]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=4 + + float v69[64][128]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=8 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 16; v71++) { + loop24: for (int v72 = 0; v72 < 32; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 8; v74++) { + loop27: for (int v75 = 0; v75 < 4; v75++) { + if ((v75 + (v72 * 4)) == 0) { + float v76 = v64[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 8))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 8))]; + float v78 = v65[(v74 + (v71 * 8))][(v75 + (v72 * 4))]; + if ((v74 + (v71 * 8)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))] = v81; + if (((v74 + (v71 * 8)) - 127) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 4))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v83[64][128], + hls::stream v84[4][4], + hls::stream v85[4][8], + float v86 +) { + #pragma HLS array_partition variable=v83 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v83 cyclic dim=2 factor=8 + + float v87[64][128]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=8 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 16; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 8; v94++) { + if ((v94 + (v91 * 8)) == 0) { + float v95 = v84[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v83[(v93 + (v90 * 4))][(v94 + (v91 * 8))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 8))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v102[64][64], + hls::stream v103[4][4], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v102 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v102 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v112 + (v109 * 4)) == 0) { + float v114 = v103[v111][v113].read(); + v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v116 = v102[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + v104[v111][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][32], + float v122[32][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 2; v131++) { + float v132 = v121[(v129 + (v126 * 4))][(v131 + (v128 * 2))]; + float v133 = v122[(v131 + (v128 * 2))][(v130 + (v127 * 4))]; + if ((v131 + (v128 * 2)) == 0) { + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))] = v136; + if (((v131 + (v128 * 2)) - 31) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + v123[v129][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][2]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=512 + hls::stream v151[4][8]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v140, v153, v152, 0.000000); + node5(v141, v152, v151, 0.000000); + node4(v151, v142, v150, 0.000000); + node3(v143, v150, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp new file mode 100644 index 000000000000..a74a0ef2b42c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmseq_unbalanced__opt5/src/k7mmseq_unbalanced.cpp @@ -0,0 +1,449 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 1; v5++) { + float v6 = v0[v4][v5].read(); + v1[(v4 + (v2 * 4))][(v3 + v5)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][2], + float v8[32][16], + hls::stream v9[4][1], + float v10 +) { + #pragma HLS array_partition variable=v8 cyclic dim=1 factor=2 + + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[64][32]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=2 + + loop4: for (int v13 = 0; v13 < 16; v13++) { + loop5: for (int v14 = 0; v14 < 16; v14++) { + loop6: for (int v15 = 0; v15 < 16; v15++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v16 = 0; v16 < 4; v16++) { + loop8: for (int v17 = 0; v17 < 2; v17++) { + loop9: for (int v18 = 0; v18 < 1; v18++) { + if ((v15 + v18) == 0) { + float v19 = v7[v16][v17].read(); + v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))] = v19; + } + float v20 = v12[(v16 + (v13 * 4))][(v17 + (v14 * 2))]; + float v21 = v8[(v17 + (v14 * 2))][(v15 + v18)]; + if ((v17 + (v14 * 2)) == 0) { + v11[(v16 + (v13 * 4))][(v15 + v18)] = v10; + } + float v22 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + float v23 = v20 * v21; + float v24 = v22 + v23; + v11[(v16 + (v13 * 4))][(v15 + v18)] = v24; + if (((v17 + (v14 * 2)) - 31) == 0) { + float v25 = v11[(v16 + (v13 * 4))][(v15 + v18)]; + v9[v16][v18].write(v25); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v26[4][4], + float v27[64][32], + hls::stream v28[4][2], + float v29 +) { + #pragma HLS array_partition variable=v27 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v27 cyclic dim=2 factor=2 + + float v30[64][32]; + #pragma HLS array_partition variable=v30 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v30 cyclic dim=2 factor=2 + + float v31[64][64]; + #pragma HLS array_partition variable=v31 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v31 cyclic dim=2 factor=4 + + loop10: for (int v32 = 0; v32 < 16; v32++) { + loop11: for (int v33 = 0; v33 < 16; v33++) { + loop12: for (int v34 = 0; v34 < 16; v34++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v35 = 0; v35 < 4; v35++) { + loop14: for (int v36 = 0; v36 < 4; v36++) { + loop15: for (int v37 = 0; v37 < 2; v37++) { + if ((v37 + (v34 * 2)) == 0) { + float v38 = v26[v35][v36].read(); + v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))] = v38; + } + float v39 = v31[(v35 + (v32 * 4))][(v36 + (v33 * 4))]; + float v40 = v27[(v36 + (v33 * 4))][(v37 + (v34 * 2))]; + if ((v36 + (v33 * 4)) == 0) { + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v29; + } + float v41 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + float v42 = v39 * v40; + float v43 = v41 + v42; + v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))] = v43; + if (((v36 + (v33 * 4)) - 63) == 0) { + float v44 = v30[(v35 + (v32 * 4))][(v37 + (v34 * 2))]; + v28[v35][v37].write(v44); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v45[4][8], + float v46[128][64], + hls::stream v47[4][4], + float v48 +) { + #pragma HLS array_partition variable=v46 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v46 cyclic dim=2 factor=4 + + float v49[64][64]; + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v49 cyclic dim=2 factor=4 + + float v50[64][128]; + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v50 cyclic dim=2 factor=8 + + loop16: for (int v51 = 0; v51 < 16; v51++) { + loop17: for (int v52 = 0; v52 < 16; v52++) { + loop18: for (int v53 = 0; v53 < 16; v53++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v54 = 0; v54 < 4; v54++) { + loop20: for (int v55 = 0; v55 < 8; v55++) { + loop21: for (int v56 = 0; v56 < 4; v56++) { + if ((v56 + (v53 * 4)) == 0) { + float v57 = v45[v54][v55].read(); + v50[(v54 + (v51 * 4))][(v55 + (v52 * 8))] = v57; + } + float v58 = v50[(v54 + (v51 * 4))][(v55 + (v52 * 8))]; + float v59 = v46[(v55 + (v52 * 8))][(v56 + (v53 * 4))]; + if ((v55 + (v52 * 8)) == 0) { + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v48; + } + float v60 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + float v61 = v58 * v59; + float v62 = v60 + v61; + v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))] = v62; + if (((v55 + (v52 * 8)) - 127) == 0) { + float v63 = v49[(v54 + (v51 * 4))][(v56 + (v53 * 4))]; + v47[v54][v56].write(v63); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v64[128][128], + hls::stream v65[4][4], + hls::stream v66[4][8], + float v67 +) { + #pragma HLS array_partition variable=v64 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v64 cyclic dim=2 factor=8 + + float v68[64][128]; + #pragma HLS array_partition variable=v68 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v68 cyclic dim=2 factor=8 + + float v69[64][128]; + #pragma HLS array_partition variable=v69 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v69 cyclic dim=2 factor=4 + + loop22: for (int v70 = 0; v70 < 16; v70++) { + loop23: for (int v71 = 0; v71 < 32; v71++) { + loop24: for (int v72 = 0; v72 < 16; v72++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v73 = 0; v73 < 4; v73++) { + loop26: for (int v74 = 0; v74 < 4; v74++) { + loop27: for (int v75 = 0; v75 < 8; v75++) { + if ((v75 + (v72 * 8)) == 0) { + float v76 = v65[v73][v74].read(); + v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))] = v76; + } + float v77 = v69[(v73 + (v70 * 4))][(v74 + (v71 * 4))]; + float v78 = v64[(v74 + (v71 * 4))][(v75 + (v72 * 8))]; + if ((v74 + (v71 * 4)) == 0) { + v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))] = v67; + } + float v79 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))]; + float v80 = v77 * v78; + float v81 = v79 + v80; + v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))] = v81; + if (((v74 + (v71 * 4)) - 127) == 0) { + float v82 = v68[(v73 + (v70 * 4))][(v75 + (v72 * 8))]; + v66[v73][v75].write(v82); + } + } + } + } + } + } + } + return ; +} + +void node5( + hls::stream v83[4][4], + float v84[64][128], + hls::stream v85[4][4], + float v86 +) { + #pragma HLS array_partition variable=v84 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v84 cyclic dim=2 factor=4 + + float v87[64][128]; + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + float v88[64][64]; + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + loop28: for (int v89 = 0; v89 < 16; v89++) { + loop29: for (int v90 = 0; v90 < 16; v90++) { + loop30: for (int v91 = 0; v91 < 32; v91++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v92 = 0; v92 < 4; v92++) { + loop32: for (int v93 = 0; v93 < 4; v93++) { + loop33: for (int v94 = 0; v94 < 4; v94++) { + if ((v94 + (v91 * 4)) == 0) { + float v95 = v83[v92][v93].read(); + v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))] = v95; + } + float v96 = v88[(v92 + (v89 * 4))][(v93 + (v90 * 4))]; + float v97 = v84[(v93 + (v90 * 4))][(v94 + (v91 * 4))]; + if ((v93 + (v90 * 4)) == 0) { + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v86; + } + float v98 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + float v99 = v96 * v97; + float v100 = v98 + v99; + v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))] = v100; + if (((v93 + (v90 * 4)) - 63) == 0) { + float v101 = v87[(v92 + (v89 * 4))][(v94 + (v91 * 4))]; + v85[v92][v94].write(v101); + } + } + } + } + } + } + } + return ; +} + +void node6( + hls::stream v102[4][4], + float v103[64][64], + hls::stream v104[4][4], + float v105 +) { + #pragma HLS array_partition variable=v103 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v103 cyclic dim=2 factor=4 + + float v106[64][64]; + #pragma HLS array_partition variable=v106 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v106 cyclic dim=2 factor=4 + + float v107[64][64]; + #pragma HLS array_partition variable=v107 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v107 cyclic dim=2 factor=4 + + loop34: for (int v108 = 0; v108 < 16; v108++) { + loop35: for (int v109 = 0; v109 < 16; v109++) { + loop36: for (int v110 = 0; v110 < 16; v110++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v111 = 0; v111 < 4; v111++) { + loop38: for (int v112 = 0; v112 < 4; v112++) { + loop39: for (int v113 = 0; v113 < 4; v113++) { + if ((v113 + (v110 * 4)) == 0) { + float v114 = v102[v111][v112].read(); + v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))] = v114; + } + float v115 = v107[(v111 + (v108 * 4))][(v112 + (v109 * 4))]; + float v116 = v103[(v112 + (v109 * 4))][(v113 + (v110 * 4))]; + if ((v112 + (v109 * 4)) == 0) { + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v105; + } + float v117 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))] = v119; + if (((v112 + (v109 * 4)) - 63) == 0) { + float v120 = v106[(v111 + (v108 * 4))][(v113 + (v110 * 4))]; + v104[v111][v113].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[32][64], + float v122[64][32], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=2 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 2; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 2))]; + float v133 = v121[(v130 + (v127 * 2))][(v131 + (v128 * 4))]; + if ((v130 + (v127 * 2)) == 0) { + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v124; + } + float v134 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))] = v136; + if (((v130 + (v127 * 2)) - 31) == 0) { + float v137 = v125[(v129 + (v126 * 4))][(v131 + (v128 * 4))]; + v123[v129][v131].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][2]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][8]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=512 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v139, v138, v153, 0.000000); + node6(v153, v140, v152, 0.000000); + node5(v152, v141, v151, 0.000000); + node4(v142, v151, v150, 0.000000); + node3(v150, v143, v149, 0.000000); + node2(v149, v144, v148, 0.000000); + node1(v148, v145, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp new file mode 100644 index 000000000000..50c0c6522a0a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_balanced__opt5/src/k7mmtree_balanced.cpp @@ -0,0 +1,454 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][4], + float v1[64][64] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v1 cyclic dim=2 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 4; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v4 + (v2 * 4))] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][4], + hls::stream v8[4][4], + hls::stream v9[4][4], + float v10 +) { + float v11[64][64]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v11 cyclic dim=2 factor=4 + + float v12[64][64]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v12 cyclic dim=2 factor=4 + + float v13[64][64]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=4 + + loop4: for (int v14 = 0; v14 < 16; v14++) { + loop5: for (int v15 = 0; v15 < 16; v15++) { + loop6: for (int v16 = 0; v16 < 16; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 4; v17++) { + loop8: for (int v18 = 0; v18 < 4; v18++) { + loop9: for (int v19 = 0; v19 < 4; v19++) { + if ((v18 + (v15 * 4)) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 4))][(v17 + (v14 * 4))] = v20; + } + float v21 = v13[(v19 + (v16 * 4))][(v17 + (v14 * 4))]; + if ((v19 + (v16 * 4)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 4))][(v18 + (v15 * 4))] = v22; + } + float v23 = v12[(v17 + (v14 * 4))][(v18 + (v15 * 4))]; + if ((v17 + (v14 * 4)) == 0) { + v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))] = v10; + } + float v24 = v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))] = v26; + if (((v17 + (v14 * 4)) - 63) == 0) { + float v27 = v11[(v19 + (v16 * 4))][(v18 + (v15 * 4))]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v28[4][4], + hls::stream v29[4][4], + hls::stream v30[4][4], + float v31 +) { + float v32[64][64]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=4 + + float v33[64][64]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v33 cyclic dim=2 factor=4 + + float v34[64][64]; + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v34 cyclic dim=2 factor=4 + + loop10: for (int v35 = 0; v35 < 16; v35++) { + loop11: for (int v36 = 0; v36 < 16; v36++) { + loop12: for (int v37 = 0; v37 < 16; v37++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v38 = 0; v38 < 4; v38++) { + loop14: for (int v39 = 0; v39 < 4; v39++) { + loop15: for (int v40 = 0; v40 < 4; v40++) { + if ((v40 + (v37 * 4)) == 0) { + float v41 = v29[v38][v39].read(); + v34[(v38 + (v35 * 4))][(v39 + (v36 * 4))] = v41; + } + float v42 = v34[(v38 + (v35 * 4))][(v39 + (v36 * 4))]; + if ((v38 + (v35 * 4)) == 0) { + float v43 = v28[v39][v40].read(); + v33[(v39 + (v36 * 4))][(v40 + (v37 * 4))] = v43; + } + float v44 = v33[(v39 + (v36 * 4))][(v40 + (v37 * 4))]; + if ((v39 + (v36 * 4)) == 0) { + v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))] = v31; + } + float v45 = v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))]; + float v46 = v42 * v44; + float v47 = v45 + v46; + v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))] = v47; + if (((v39 + (v36 * 4)) - 63) == 0) { + float v48 = v32[(v38 + (v35 * 4))][(v40 + (v37 * 4))]; + v30[v38][v40].write(v48); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v49[4][4], + hls::stream v50[4][4], + hls::stream v51[4][4], + float v52 +) { + float v53[64][64]; + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=4 + + float v54[64][64]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=4 + + float v55[64][64]; + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=4 + + loop16: for (int v56 = 0; v56 < 16; v56++) { + loop17: for (int v57 = 0; v57 < 16; v57++) { + loop18: for (int v58 = 0; v58 < 16; v58++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v59 = 0; v59 < 4; v59++) { + loop20: for (int v60 = 0; v60 < 4; v60++) { + loop21: for (int v61 = 0; v61 < 4; v61++) { + if ((v59 + (v56 * 4)) == 0) { + float v62 = v49[v61][v60].read(); + v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))] = v62; + } + float v63 = v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))]; + if ((v61 + (v58 * 4)) == 0) { + float v64 = v50[v60][v59].read(); + v54[(v60 + (v57 * 4))][(v59 + (v56 * 4))] = v64; + } + float v65 = v54[(v60 + (v57 * 4))][(v59 + (v56 * 4))]; + if ((v60 + (v57 * 4)) == 0) { + v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))] = v52; + } + float v66 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))]; + float v67 = v63 * v65; + float v68 = v66 + v67; + v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))] = v68; + if (((v60 + (v57 * 4)) - 63) == 0) { + float v69 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 4))]; + v51[v61][v59].write(v69); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v70[64][64], + float v71[64][64], + hls::stream v72[4][4], + float v73 +) { + #pragma HLS array_partition variable=v70 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v70 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v71 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v71 cyclic dim=2 factor=4 + + float v74[64][64]; + #pragma HLS array_partition variable=v74 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v74 cyclic dim=2 factor=4 + + loop22: for (int v75 = 0; v75 < 16; v75++) { + loop23: for (int v76 = 0; v76 < 16; v76++) { + loop24: for (int v77 = 0; v77 < 16; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v78 = 0; v78 < 4; v78++) { + loop26: for (int v79 = 0; v79 < 4; v79++) { + loop27: for (int v80 = 0; v80 < 4; v80++) { + float v81 = v70[(v79 + (v76 * 4))][(v78 + (v75 * 4))]; + float v82 = v71[(v78 + (v75 * 4))][(v80 + (v77 * 4))]; + if ((v78 + (v75 * 4)) == 0) { + v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))] = v73; + } + float v83 = v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))] = v85; + if (((v78 + (v75 * 4)) - 63) == 0) { + float v86 = v74[(v79 + (v76 * 4))][(v80 + (v77 * 4))]; + v72[v79][v80].write(v86); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v87[64][64], + float v88[64][64], + hls::stream v89[4][4], + float v90 +) { + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + float v91[64][64]; + #pragma HLS array_partition variable=v91 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v91 cyclic dim=2 factor=4 + + loop28: for (int v92 = 0; v92 < 16; v92++) { + loop29: for (int v93 = 0; v93 < 16; v93++) { + loop30: for (int v94 = 0; v94 < 16; v94++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v95 = 0; v95 < 4; v95++) { + loop32: for (int v96 = 0; v96 < 4; v96++) { + loop33: for (int v97 = 0; v97 < 4; v97++) { + float v98 = v88[(v96 + (v93 * 4))][(v95 + (v92 * 4))]; + float v99 = v87[(v95 + (v92 * 4))][(v97 + (v94 * 4))]; + if ((v95 + (v92 * 4)) == 0) { + v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))] = v90; + } + float v100 = v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))]; + float v101 = v98 * v99; + float v102 = v100 + v101; + v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))] = v102; + if (((v95 + (v92 * 4)) - 63) == 0) { + float v103 = v91[(v96 + (v93 * 4))][(v97 + (v94 * 4))]; + v89[v96][v97].write(v103); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v104[64][64], + float v105[64][64], + hls::stream v106[4][4], + float v107 +) { + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v105 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=4 + + float v108[64][64]; + #pragma HLS array_partition variable=v108 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v108 cyclic dim=2 factor=4 + + loop34: for (int v109 = 0; v109 < 16; v109++) { + loop35: for (int v110 = 0; v110 < 16; v110++) { + loop36: for (int v111 = 0; v111 < 16; v111++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v112 = 0; v112 < 4; v112++) { + loop38: for (int v113 = 0; v113 < 4; v113++) { + loop39: for (int v114 = 0; v114 < 4; v114++) { + float v115 = v105[(v114 + (v111 * 4))][(v113 + (v110 * 4))]; + float v116 = v104[(v113 + (v110 * 4))][(v112 + (v109 * 4))]; + if ((v113 + (v110 * 4)) == 0) { + v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))] = v107; + } + float v117 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 4))]; + v106[v114][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][64], + float v122[64][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 4; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[(v131 + (v128 * 4))][(v129 + (v126 * 4))]; + float v133 = v122[(v129 + (v126 * 4))][(v130 + (v127 * 4))]; + if ((v129 + (v126 * 4)) == 0) { + v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))] = v124; + } + float v134 = v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))] = v136; + if (((v129 + (v126 * 4)) - 63) == 0) { + float v137 = v125[(v131 + (v128 * 4))][(v130 + (v127 * 4))]; + v123[v131][v130].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][64], + float v139[64][64], + float v140[64][64], + float v141[64][64], + float v142[64][64], + float v143[64][64], + float v144[64][64], + float v145[64][64], + float v146[64][64] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v145 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v146 cyclic dim=2 factor=4 + + hls::stream v147[4][4]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[4][4]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][4]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][4]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[4][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][4]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v141, v140, v152, 0.000000); + node5(v143, v142, v151, 0.000000); + node4(v144, v145, v150, 0.000000); + node3(v153, v152, v149, 0.000000); + node2(v150, v151, v148, 0.000000); + node1(v149, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp new file mode 100644 index 000000000000..1e311dbe015f --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/k7mmtree_unbalanced__opt5/src/k7mmtree_unbalanced.cpp @@ -0,0 +1,445 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[4][1], + float v1[64][16] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=4 + + loop0: for (int v2 = 0; v2 < 16; v2++) { + loop1: for (int v3 = 0; v3 < 16; v3++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop2: for (int v4 = 0; v4 < 1; v4++) { + loop3: for (int v5 = 0; v5 < 4; v5++) { + float v6 = v0[v5][v4].read(); + v1[(v5 + (v3 * 4))][(v2 + v4)] = v6; + } + } + } + } + return ; +} + +void node1( + hls::stream v7[4][8], + hls::stream v8[8][1], + hls::stream v9[4][1], + float v10 +) { + float v11[64][16]; + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=4 + + float v12[128][16]; + #pragma HLS array_partition variable=v12 cyclic dim=1 factor=8 + + float v13[64][128]; + #pragma HLS array_partition variable=v13 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v13 cyclic dim=2 factor=8 + + loop4: for (int v14 = 0; v14 < 16; v14++) { + loop5: for (int v15 = 0; v15 < 16; v15++) { + loop6: for (int v16 = 0; v16 < 16; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop7: for (int v17 = 0; v17 < 8; v17++) { + loop8: for (int v18 = 0; v18 < 1; v18++) { + loop9: for (int v19 = 0; v19 < 4; v19++) { + if ((v15 + v18) == 0) { + float v20 = v7[v19][v17].read(); + v13[(v19 + (v16 * 4))][(v17 + (v14 * 8))] = v20; + } + float v21 = v13[(v19 + (v16 * 4))][(v17 + (v14 * 8))]; + if ((v19 + (v16 * 4)) == 0) { + float v22 = v8[v17][v18].read(); + v12[(v17 + (v14 * 8))][(v15 + v18)] = v22; + } + float v23 = v12[(v17 + (v14 * 8))][(v15 + v18)]; + if ((v17 + (v14 * 8)) == 0) { + v11[(v19 + (v16 * 4))][(v15 + v18)] = v10; + } + float v24 = v11[(v19 + (v16 * 4))][(v15 + v18)]; + float v25 = v21 * v23; + float v26 = v24 + v25; + v11[(v19 + (v16 * 4))][(v15 + v18)] = v26; + if (((v17 + (v14 * 8)) - 127) == 0) { + float v27 = v11[(v19 + (v16 * 4))][(v15 + v18)]; + v9[v19][v18].write(v27); + } + } + } + } + } + } + } + return ; +} + +void node2( + hls::stream v28[8][4], + hls::stream v29[4][1], + hls::stream v30[8][1], + float v31 +) { + float v32[128][16]; + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=8 + + float v33[64][16]; + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=4 + + float v34[128][64]; + #pragma HLS array_partition variable=v34 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v34 cyclic dim=2 factor=4 + + loop10: for (int v35 = 0; v35 < 16; v35++) { + loop11: for (int v36 = 0; v36 < 16; v36++) { + loop12: for (int v37 = 0; v37 < 16; v37++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop13: for (int v38 = 0; v38 < 8; v38++) { + loop14: for (int v39 = 0; v39 < 4; v39++) { + loop15: for (int v40 = 0; v40 < 1; v40++) { + if ((v37 + v40) == 0) { + float v41 = v28[v38][v39].read(); + v34[(v38 + (v35 * 8))][(v39 + (v36 * 4))] = v41; + } + float v42 = v34[(v38 + (v35 * 8))][(v39 + (v36 * 4))]; + if ((v38 + (v35 * 8)) == 0) { + float v43 = v29[v39][v40].read(); + v33[(v39 + (v36 * 4))][(v37 + v40)] = v43; + } + float v44 = v33[(v39 + (v36 * 4))][(v37 + v40)]; + if ((v39 + (v36 * 4)) == 0) { + v32[(v38 + (v35 * 8))][(v37 + v40)] = v31; + } + float v45 = v32[(v38 + (v35 * 8))][(v37 + v40)]; + float v46 = v42 * v44; + float v47 = v45 + v46; + v32[(v38 + (v35 * 8))][(v37 + v40)] = v47; + if (((v39 + (v36 * 4)) - 63) == 0) { + float v48 = v32[(v38 + (v35 * 8))][(v37 + v40)]; + v30[v38][v40].write(v48); + } + } + } + } + } + } + } + return ; +} + +void node3( + hls::stream v49[4][8], + hls::stream v50[4][4], + hls::stream v51[4][8], + float v52 +) { + float v53[64][128]; + #pragma HLS array_partition variable=v53 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v53 cyclic dim=2 factor=8 + + float v54[64][128]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=8 + + float v55[64][64]; + #pragma HLS array_partition variable=v55 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v55 cyclic dim=2 factor=4 + + loop16: for (int v56 = 0; v56 < 16; v56++) { + loop17: for (int v57 = 0; v57 < 16; v57++) { + loop18: for (int v58 = 0; v58 < 16; v58++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop19: for (int v59 = 0; v59 < 8; v59++) { + loop20: for (int v60 = 0; v60 < 4; v60++) { + loop21: for (int v61 = 0; v61 < 4; v61++) { + if ((v59 + (v56 * 8)) == 0) { + float v62 = v50[v61][v60].read(); + v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))] = v62; + } + float v63 = v55[(v61 + (v58 * 4))][(v60 + (v57 * 4))]; + if ((v61 + (v58 * 4)) == 0) { + float v64 = v49[v60][v59].read(); + v54[(v60 + (v57 * 4))][(v59 + (v56 * 8))] = v64; + } + float v65 = v54[(v60 + (v57 * 4))][(v59 + (v56 * 8))]; + if ((v60 + (v57 * 4)) == 0) { + v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))] = v52; + } + float v66 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))]; + float v67 = v63 * v65; + float v68 = v66 + v67; + v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))] = v68; + if (((v60 + (v57 * 4)) - 63) == 0) { + float v69 = v53[(v61 + (v58 * 4))][(v59 + (v56 * 8))]; + v51[v61][v59].write(v69); + } + } + } + } + } + } + } + return ; +} + +void node4( + float v70[64][32], + float v71[32][16], + hls::stream v72[4][1], + float v73 +) { + #pragma HLS array_partition variable=v70 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v70 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v71 cyclic dim=1 factor=2 + + float v74[64][16]; + #pragma HLS array_partition variable=v74 cyclic dim=1 factor=4 + + loop22: for (int v75 = 0; v75 < 16; v75++) { + loop23: for (int v76 = 0; v76 < 16; v76++) { + loop24: for (int v77 = 0; v77 < 16; v77++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop25: for (int v78 = 0; v78 < 2; v78++) { + loop26: for (int v79 = 0; v79 < 4; v79++) { + loop27: for (int v80 = 0; v80 < 1; v80++) { + float v81 = v70[(v79 + (v76 * 4))][(v78 + (v75 * 2))]; + float v82 = v71[(v78 + (v75 * 2))][(v77 + v80)]; + if ((v78 + (v75 * 2)) == 0) { + v74[(v79 + (v76 * 4))][(v77 + v80)] = v73; + } + float v83 = v74[(v79 + (v76 * 4))][(v77 + v80)]; + float v84 = v81 * v82; + float v85 = v83 + v84; + v74[(v79 + (v76 * 4))][(v77 + v80)] = v85; + if (((v78 + (v75 * 2)) - 31) == 0) { + float v86 = v74[(v79 + (v76 * 4))][(v77 + v80)]; + v72[v79][v80].write(v86); + } + } + } + } + } + } + } + return ; +} + +void node5( + float v87[128][128], + float v88[128][64], + hls::stream v89[8][4], + float v90 +) { + #pragma HLS array_partition variable=v87 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v87 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v88 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v88 cyclic dim=2 factor=4 + + float v91[128][64]; + #pragma HLS array_partition variable=v91 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v91 cyclic dim=2 factor=4 + + loop28: for (int v92 = 0; v92 < 16; v92++) { + loop29: for (int v93 = 0; v93 < 32; v93++) { + loop30: for (int v94 = 0; v94 < 16; v94++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop31: for (int v95 = 0; v95 < 8; v95++) { + loop32: for (int v96 = 0; v96 < 4; v96++) { + loop33: for (int v97 = 0; v97 < 4; v97++) { + float v98 = v87[(v95 + (v92 * 8))][(v96 + (v93 * 4))]; + float v99 = v88[(v96 + (v93 * 4))][(v97 + (v94 * 4))]; + if ((v96 + (v93 * 4)) == 0) { + v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))] = v90; + } + float v100 = v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))]; + float v101 = v98 * v99; + float v102 = v100 + v101; + v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))] = v102; + if (((v96 + (v93 * 4)) - 127) == 0) { + float v103 = v91[(v95 + (v92 * 8))][(v97 + (v94 * 4))]; + v89[v95][v97].write(v103); + } + } + } + } + } + } + } + return ; +} + +void node6( + float v104[64][64], + float v105[64][128], + hls::stream v106[4][8], + float v107 +) { + #pragma HLS array_partition variable=v104 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v104 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v105 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v105 cyclic dim=2 factor=8 + + float v108[64][128]; + #pragma HLS array_partition variable=v108 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v108 cyclic dim=2 factor=8 + + loop34: for (int v109 = 0; v109 < 16; v109++) { + loop35: for (int v110 = 0; v110 < 16; v110++) { + loop36: for (int v111 = 0; v111 < 16; v111++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop37: for (int v112 = 0; v112 < 8; v112++) { + loop38: for (int v113 = 0; v113 < 4; v113++) { + loop39: for (int v114 = 0; v114 < 4; v114++) { + float v115 = v104[(v114 + (v111 * 4))][(v113 + (v110 * 4))]; + float v116 = v105[(v113 + (v110 * 4))][(v112 + (v109 * 8))]; + if ((v113 + (v110 * 4)) == 0) { + v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))] = v107; + } + float v117 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))]; + float v118 = v115 * v116; + float v119 = v117 + v118; + v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))] = v119; + if (((v113 + (v110 * 4)) - 63) == 0) { + float v120 = v108[(v114 + (v111 * 4))][(v112 + (v109 * 8))]; + v106[v114][v112].write(v120); + } + } + } + } + } + } + } + return ; +} + +void node7( + float v121[64][32], + float v122[32][64], + hls::stream v123[4][4], + float v124 +) { + #pragma HLS array_partition variable=v121 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v121 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v122 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v122 cyclic dim=2 factor=4 + + float v125[64][64]; + #pragma HLS array_partition variable=v125 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v125 cyclic dim=2 factor=4 + + loop40: for (int v126 = 0; v126 < 16; v126++) { + loop41: for (int v127 = 0; v127 < 16; v127++) { + loop42: for (int v128 = 0; v128 < 16; v128++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop43: for (int v129 = 0; v129 < 4; v129++) { + loop44: for (int v130 = 0; v130 < 2; v130++) { + loop45: for (int v131 = 0; v131 < 4; v131++) { + float v132 = v121[(v131 + (v128 * 4))][(v130 + (v127 * 2))]; + float v133 = v122[(v130 + (v127 * 2))][(v129 + (v126 * 4))]; + if ((v130 + (v127 * 2)) == 0) { + v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))] = v124; + } + float v134 = v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))]; + float v135 = v132 * v133; + float v136 = v134 + v135; + v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))] = v136; + if (((v130 + (v127 * 2)) - 31) == 0) { + float v137 = v125[(v131 + (v128 * 4))][(v129 + (v126 * 4))]; + v123[v131][v129].write(v137); + } + } + } + } + } + } + } + return ; +} + +void forward( + float v138[64][32], + float v139[32][64], + float v140[64][64], + float v141[64][128], + float v142[128][128], + float v143[128][64], + float v144[64][32], + float v145[32][16], + float v146[64][16] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v138 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v138 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v139 cyclic dim=1 factor=2 + #pragma HLS array_partition variable=v139 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v140 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v140 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v141 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v141 cyclic dim=2 factor=8 + + #pragma HLS array_partition variable=v142 cyclic dim=1 factor=8 + #pragma HLS array_partition variable=v142 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v143 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v143 cyclic dim=2 factor=4 + + #pragma HLS array_partition variable=v144 cyclic dim=1 factor=4 + #pragma HLS array_partition variable=v144 cyclic dim=2 factor=2 + + #pragma HLS array_partition variable=v145 cyclic dim=1 factor=2 + + #pragma HLS array_partition variable=v146 cyclic dim=1 factor=4 + + hls::stream v147[4][1]; + #pragma HLS STREAM variable=v147 depth=256 + hls::stream v148[8][1]; + #pragma HLS STREAM variable=v148 depth=256 + hls::stream v149[4][8]; + #pragma HLS STREAM variable=v149 depth=256 + hls::stream v150[4][1]; + #pragma HLS STREAM variable=v150 depth=256 + hls::stream v151[8][4]; + #pragma HLS STREAM variable=v151 depth=256 + hls::stream v152[4][8]; + #pragma HLS STREAM variable=v152 depth=256 + hls::stream v153[4][4]; + #pragma HLS STREAM variable=v153 depth=256 + node7(v138, v139, v153, 0.000000); + node6(v140, v141, v152, 0.000000); + node5(v142, v143, v151, 0.000000); + node4(v144, v145, v150, 0.000000); + node3(v152, v153, v149, 0.000000); + node2(v151, v150, v148, 0.000000); + node1(v149, v148, v147, 0.000000); + node0(v147, v146); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt1/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt1/src/mvt.cpp new file mode 100644 index 000000000000..44bff911ab15 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt1/src/mvt.cpp @@ -0,0 +1,137 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[400] +) { + loop0: for (int v2 = 0; v2 < 400; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[400] +) { + loop1: for (int v6 = 0; v6 < 400; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + float v8[400][400], + float v9[400], + hls::stream &v10, + float v11 +) { + float v12[400]; + loop2: for (int v13 = 0; v13 < 400; v13++) { + loop3: for (int v14 = 0; v14 < 400; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8[v13][v14]; + float v16 = v9[v14]; + if (v14 == 0) { + v12[v13] = v11; + } + float v17 = v12[v13]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v13] = v19; + if ((v14 - 399) == 0) { + float v20 = v12[v13]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[400][400], + float v22[400][400] +) { + loop4: for (int v23 = 0; v23 < 400; v23++) { + loop5: for (int v24 = 0; v24 < 400; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v25 = v21[v23][v24]; + v22[v24][v23] = v25; + } + } + return ; +} + +void node4( + float v26[400][400], + float v27[400], + hls::stream &v28, + float v29 +) { + float v30[400]; + loop6: for (int v31 = 0; v31 < 400; v31++) { + loop7: for (int v32 = 0; v32 < 400; v32++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v33 = v26[v31][v32]; + float v34 = v27[v32]; + if (v32 == 0) { + v30[v31] = v29; + } + float v35 = v30[v31]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v30[v31] = v37; + if ((v32 - 399) == 0) { + float v38 = v30[v31]; + v28.write(v38); + } + } + } + return ; +} + +void forward( + float v39[400][400], + float v40[400][400], + float v41[400], + float v42[400], + float v43[400], + float v44[400] +) { + #pragma HLS DATAFLOW + hls::stream v45("fifo_0"); + #pragma HLS STREAM variable=v45 depth=400 + float v46[400][400]; + hls::stream v47("fifo_1"); + #pragma HLS STREAM variable=v47 depth=400 + node4(v39, v41, v47, 0.000000); + node3(v40, v46); + node2(v46, v42, v45, 0.000000); + node1(v47, v43); + node0(v45, v44); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt2/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt2/src/mvt.cpp new file mode 100644 index 000000000000..f5fbfe0f57a9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt2/src/mvt.cpp @@ -0,0 +1,138 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream &v0, + float v1[400] +) { + loop0: for (int v2 = 0; v2 < 400; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v3 = v0.read(); + v1[v2] = v3; + } + return ; +} + +void node1( + hls::stream &v4, + float v5[400] +) { + loop1: for (int v6 = 0; v6 < 400; v6++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v7 = v4.read(); + v5[v6] = v7; + } + return ; +} + +void node2( + hls::stream &v8, + float v9[400], + hls::stream &v10, + float v11 +) { + float v12[400]; + loop2: for (int v13 = 0; v13 < 400; v13++) { + loop3: for (int v14 = 0; v14 < 400; v14++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v15 = v8.read(); + float v16 = v9[v13]; + if (v13 == 0) { + v12[v14] = v11; + } + float v17 = v12[v14]; + float v18 = v15 * v16; + float v19 = v17 + v18; + v12[v14] = v19; + if ((v13 - 399) == 0) { + float v20 = v12[v14]; + v10.write(v20); + } + } + } + return ; +} + +void node3( + float v21[400][400], + hls::stream &v22 +) { + loop4: for (int v23 = 0; v23 < 400; v23++) { + loop5: for (int v24 = 0; v24 < 400; v24++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v25 = v21[v23][v24]; + v22.write(v25); + } + } + return ; +} + +void node4( + float v26[400][400], + float v27[400], + hls::stream &v28, + float v29 +) { + float v30[400]; + loop6: for (int v31 = 0; v31 < 400; v31++) { + loop7: for (int v32 = 0; v32 < 400; v32++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + float v33 = v26[v32][v31]; + float v34 = v27[v31]; + if (v31 == 0) { + v30[v32] = v29; + } + float v35 = v30[v32]; + float v36 = v33 * v34; + float v37 = v35 + v36; + v30[v32] = v37; + if ((v31 - 399) == 0) { + float v38 = v30[v32]; + v28.write(v38); + } + } + } + return ; +} + +void forward( + float v39[400][400], + float v40[400][400], + float v41[400], + float v42[400], + float v43[400], + float v44[400] +) { + #pragma HLS DATAFLOW + hls::stream v45("fifo_0"); + #pragma HLS STREAM variable=v45 depth=400 + hls::stream v46("fifo_1"); + #pragma HLS STREAM variable=v46 depth=160000 + hls::stream v47("fifo_2"); + #pragma HLS STREAM variable=v47 depth=400 + node4(v39, v41, v47, 0.000000); + node3(v40, v46); + node2(v46, v42, v45, 0.000000); + node1(v47, v43); + node0(v45, v44); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt3/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt3/src/mvt.cpp new file mode 100644 index 000000000000..6019c1b096cf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt3/src/mvt.cpp @@ -0,0 +1,194 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[16], + float v1[400] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=16 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 16; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 16))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[10], + float v6[400] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=10 + + loop2: for (int v7 = 0; v7 < 40; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 10; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 10))] = v9; + } + } + return ; +} + +void node2( + float v10[400][400], + float v11[400], + hls::stream v12[16], + float v13 +) { + #pragma HLS array_partition variable=v10 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v10 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=16 + + float v14[400]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=16 + + loop4: for (int v15 = 0; v15 < 25; v15++) { + loop5: for (int v16 = 0; v16 < 25; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 16; v17++) { + loop7: for (int v18 = 0; v18 < 16; v18++) { + float v19 = v10[(v17 + (v15 * 16))][(v18 + (v16 * 16))]; + float v20 = v11[(v18 + (v16 * 16))]; + if ((v18 + (v16 * 16)) == 0) { + v14[(v17 + (v15 * 16))] = v13; + } + float v21 = v14[(v17 + (v15 * 16))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v17 + (v15 * 16))] = v23; + if (((v18 + (v16 * 16)) - 399) == 0) { + float v24 = v14[(v17 + (v15 * 16))]; + v12[v17].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[400][400], + float v26[400][400] +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v26 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v26 cyclic dim=2 factor=16 + + loop8: for (int v27 = 0; v27 < 25; v27++) { + loop9: for (int v28 = 0; v28 < 25; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v29 = 0; v29 < 16; v29++) { + loop11: for (int v30 = 0; v30 < 16; v30++) { + float v31 = v25[(v29 + (v27 * 16))][(v30 + (v28 * 16))]; + v26[(v30 + (v28 * 16))][(v29 + (v27 * 16))] = v31; + } + } + } + } + return ; +} + +void node4( + float v32[400][400], + float v33[400], + hls::stream v34[10], + float v35 +) { + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=25 + + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=25 + + float v36[400]; + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=10 + + loop12: for (int v37 = 0; v37 < 40; v37++) { + loop13: for (int v38 = 0; v38 < 16; v38++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop14: for (int v39 = 0; v39 < 10; v39++) { + loop15: for (int v40 = 0; v40 < 25; v40++) { + float v41 = v32[(v39 + (v37 * 10))][(v40 + (v38 * 25))]; + float v42 = v33[(v40 + (v38 * 25))]; + if ((v40 + (v38 * 25)) == 0) { + v36[(v39 + (v37 * 10))] = v35; + } + float v43 = v36[(v39 + (v37 * 10))]; + float v44 = v41 * v42; + float v45 = v43 + v44; + v36[(v39 + (v37 * 10))] = v45; + if (((v40 + (v38 * 25)) - 399) == 0) { + float v46 = v36[(v39 + (v37 * 10))]; + v34[v39].write(v46); + } + } + } + } + } + return ; +} + +void forward( + float v47[400][400], + float v48[400][400], + float v49[400], + float v50[400], + float v51[400], + float v52[400] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v47 cyclic dim=1 factor=10 + #pragma HLS array_partition variable=v47 cyclic dim=2 factor=25 + + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=25 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=10 + + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=16 + + hls::stream v53[16]; + #pragma HLS STREAM variable=v53 depth=25 + float v54[400][400]; + #pragma HLS array_partition variable=v54 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v54 cyclic dim=2 factor=16 + + hls::stream v55[10]; + #pragma HLS STREAM variable=v55 depth=40 + node4(v47, v49, v55, 0.000000); + node3(v48, v54); + node2(v54, v50, v53, 0.000000); + node1(v55, v51); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt4/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt4/src/mvt.cpp new file mode 100644 index 000000000000..08b24afcb559 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt4/src/mvt.cpp @@ -0,0 +1,186 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[16], + float v1[400] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=16 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 16; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 16))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[16], + float v6[400] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=16 + + loop2: for (int v7 = 0; v7 < 25; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 16; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 16))] = v9; + } + } + return ; +} + +void node2( + hls::stream v10[16][16], + float v11[400], + hls::stream v12[16], + float v13 +) { + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=16 + + float v14[400]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=16 + + loop4: for (int v15 = 0; v15 < 25; v15++) { + loop5: for (int v16 = 0; v16 < 25; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 16; v17++) { + loop7: for (int v18 = 0; v18 < 16; v18++) { + float v19 = v10[v18][v17].read(); + float v20 = v11[(v17 + (v15 * 16))]; + if ((v17 + (v15 * 16)) == 0) { + v14[(v18 + (v16 * 16))] = v13; + } + float v21 = v14[(v18 + (v16 * 16))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 16))] = v23; + if (((v17 + (v15 * 16)) - 399) == 0) { + float v24 = v14[(v18 + (v16 * 16))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[400][400], + hls::stream v26[16][16] +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=16 + + loop8: for (int v27 = 0; v27 < 25; v27++) { + loop9: for (int v28 = 0; v28 < 25; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v29 = 0; v29 < 16; v29++) { + loop11: for (int v30 = 0; v30 < 16; v30++) { + float v31 = v25[(v29 + (v27 * 16))][(v30 + (v28 * 16))]; + v26[v30][v29].write(v31); + } + } + } + } + return ; +} + +void node4( + float v32[400][400], + float v33[400], + hls::stream v34[16], + float v35 +) { + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=16 + + float v36[400]; + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=16 + + loop12: for (int v37 = 0; v37 < 25; v37++) { + loop13: for (int v38 = 0; v38 < 25; v38++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop14: for (int v39 = 0; v39 < 16; v39++) { + loop15: for (int v40 = 0; v40 < 16; v40++) { + float v41 = v32[(v40 + (v38 * 16))][(v39 + (v37 * 16))]; + float v42 = v33[(v39 + (v37 * 16))]; + if ((v39 + (v37 * 16)) == 0) { + v36[(v40 + (v38 * 16))] = v35; + } + float v43 = v36[(v40 + (v38 * 16))]; + float v44 = v41 * v42; + float v45 = v43 + v44; + v36[(v40 + (v38 * 16))] = v45; + if (((v39 + (v37 * 16)) - 399) == 0) { + float v46 = v36[(v40 + (v38 * 16))]; + v34[v40].write(v46); + } + } + } + } + } + return ; +} + +void forward( + float v47[400][400], + float v48[400][400], + float v49[400], + float v50[400], + float v51[400], + float v52[400] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v47 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v47 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=16 + + hls::stream v53[16]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[16][16]; + #pragma HLS STREAM variable=v54 depth=625 + hls::stream v55[16]; + #pragma HLS STREAM variable=v55 depth=25 + node4(v47, v49, v55, 0.000000); + node3(v48, v54); + node2(v54, v50, v53, 0.000000); + node1(v55, v51); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt5/src/mvt.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt5/src/mvt.cpp new file mode 100644 index 000000000000..08b24afcb559 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/WIP/stream_hls/mvt__opt5/src/mvt.cpp @@ -0,0 +1,186 @@ + +//===------------------------------------------------------------*- C++ -*-===// +// +// Automatically generated file for High-level Synthesis (HLS). +// +//===----------------------------------------------------------------------===// +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void node0( + hls::stream v0[16], + float v1[400] +) { + #pragma HLS array_partition variable=v1 cyclic dim=1 factor=16 + + loop0: for (int v2 = 0; v2 < 25; v2++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop1: for (int v3 = 0; v3 < 16; v3++) { + float v4 = v0[v3].read(); + v1[(v3 + (v2 * 16))] = v4; + } + } + return ; +} + +void node1( + hls::stream v5[16], + float v6[400] +) { + #pragma HLS array_partition variable=v6 cyclic dim=1 factor=16 + + loop2: for (int v7 = 0; v7 < 25; v7++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop3: for (int v8 = 0; v8 < 16; v8++) { + float v9 = v5[v8].read(); + v6[(v8 + (v7 * 16))] = v9; + } + } + return ; +} + +void node2( + hls::stream v10[16][16], + float v11[400], + hls::stream v12[16], + float v13 +) { + #pragma HLS array_partition variable=v11 cyclic dim=1 factor=16 + + float v14[400]; + #pragma HLS array_partition variable=v14 cyclic dim=1 factor=16 + + loop4: for (int v15 = 0; v15 < 25; v15++) { + loop5: for (int v16 = 0; v16 < 25; v16++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop6: for (int v17 = 0; v17 < 16; v17++) { + loop7: for (int v18 = 0; v18 < 16; v18++) { + float v19 = v10[v18][v17].read(); + float v20 = v11[(v17 + (v15 * 16))]; + if ((v17 + (v15 * 16)) == 0) { + v14[(v18 + (v16 * 16))] = v13; + } + float v21 = v14[(v18 + (v16 * 16))]; + float v22 = v19 * v20; + float v23 = v21 + v22; + v14[(v18 + (v16 * 16))] = v23; + if (((v17 + (v15 * 16)) - 399) == 0) { + float v24 = v14[(v18 + (v16 * 16))]; + v12[v18].write(v24); + } + } + } + } + } + return ; +} + +void node3( + float v25[400][400], + hls::stream v26[16][16] +) { + #pragma HLS array_partition variable=v25 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v25 cyclic dim=2 factor=16 + + loop8: for (int v27 = 0; v27 < 25; v27++) { + loop9: for (int v28 = 0; v28 < 25; v28++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop10: for (int v29 = 0; v29 < 16; v29++) { + loop11: for (int v30 = 0; v30 < 16; v30++) { + float v31 = v25[(v29 + (v27 * 16))][(v30 + (v28 * 16))]; + v26[v30][v29].write(v31); + } + } + } + } + return ; +} + +void node4( + float v32[400][400], + float v33[400], + hls::stream v34[16], + float v35 +) { + #pragma HLS array_partition variable=v32 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v32 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v33 cyclic dim=1 factor=16 + + float v36[400]; + #pragma HLS array_partition variable=v36 cyclic dim=1 factor=16 + + loop12: for (int v37 = 0; v37 < 25; v37++) { + loop13: for (int v38 = 0; v38 < 25; v38++) { + #pragma HLS pipeline II=1 + #pragma HLS loop_flatten + loop14: for (int v39 = 0; v39 < 16; v39++) { + loop15: for (int v40 = 0; v40 < 16; v40++) { + float v41 = v32[(v40 + (v38 * 16))][(v39 + (v37 * 16))]; + float v42 = v33[(v39 + (v37 * 16))]; + if ((v39 + (v37 * 16)) == 0) { + v36[(v40 + (v38 * 16))] = v35; + } + float v43 = v36[(v40 + (v38 * 16))]; + float v44 = v41 * v42; + float v45 = v43 + v44; + v36[(v40 + (v38 * 16))] = v45; + if (((v39 + (v37 * 16)) - 399) == 0) { + float v46 = v36[(v40 + (v38 * 16))]; + v34[v40].write(v46); + } + } + } + } + } + return ; +} + +void forward( + float v47[400][400], + float v48[400][400], + float v49[400], + float v50[400], + float v51[400], + float v52[400] +) { + #pragma HLS DATAFLOW + #pragma HLS array_partition variable=v47 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v47 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v48 cyclic dim=1 factor=16 + #pragma HLS array_partition variable=v48 cyclic dim=2 factor=16 + + #pragma HLS array_partition variable=v49 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v50 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v51 cyclic dim=1 factor=16 + + #pragma HLS array_partition variable=v52 cyclic dim=1 factor=16 + + hls::stream v53[16]; + #pragma HLS STREAM variable=v53 depth=25 + hls::stream v54[16][16]; + #pragma HLS STREAM variable=v54 depth=625 + hls::stream v55[16]; + #pragma HLS STREAM variable=v55 depth=25 + node4(v47, v49, v55, 0.000000); + node3(v48, v54); + node2(v54, v50, v53, 0.000000); + node1(v55, v51); + node0(v53, v52); + return ; +} + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_EvolveGCN/src/DGNN-booster1-EvolveGCN.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_EvolveGCN/src/DGNN-booster1-EvolveGCN.cpp new file mode 100644 index 000000000000..426a87c9acd2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_EvolveGCN/src/DGNN-booster1-EvolveGCN.cpp @@ -0,0 +1,1254 @@ +#include +#include + +//#include "dcl.h" +#include +#include +#include +#include + +#include +#include "hls_stream.h" + +#include +//#include "D:\vivado2018setup\Vivado\2018.3\include\gmp.h" +#include +#include +#include +#include +#include +#include "hls_stream.h" +#include +#include +#include +#include + +#include + +//global weights for evolveGCN. It contains GNN weighrs, RNN weights and final layer classifier weights +#define WEIGHT_LAYER1_INPUTDIM 67 +#define WEIGHT_LAYER1_OUTPUTDIM 122 +#define WEIGHT_LAYER2_INPUTDIM 122 +#define WEIGHT_LAYER2_OUTPUTDIM 122 +#define TIME_STEP 10 + +#define NUM_EDGE 51732 +#define NUM_NODE 3783 +#define LAYER1_INPUTDIM 67 +#define TOTAL_TIME 192 +#define TIME_STEP 10 + +#define MAX_DEGREE 160 + +#define SUB_GRAPH_NODE_NUM 600 +#define SUB_GRAPH_EDGE_NUM 1800 + +using namespace std; + +typedef ap_fixed<32, 10> FM_TYPE; +typedef ap_fixed<32, 10> WT_TYPE; + +// GCN and GRU weights for layer1 +float gcn_node_weight_layer1[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; // [67,122] +WT_TYPE gcn_node_weight_layer1_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; + +WT_TYPE gcn_node_weight_layer1_buffer_1[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; +WT_TYPE gcn_node_weight_layer1_buffer_2[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + + +float gru_update_layer1_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_update_layer1_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_update_layer1_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; //[67,122] + + +WT_TYPE gru_update_layer1_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +WT_TYPE gru_update_layer1_W_buffer_1[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +WT_TYPE gru_update_layer1_W_buffer_2[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; + +WT_TYPE gru_update_layer1_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; + +WT_TYPE gru_update_layer1_bias_buffer_1[WEIGHT_LAYER1_OUTPUTDIM]; +WT_TYPE gru_update_layer1_bias_buffer_2[WEIGHT_LAYER1_OUTPUTDIM]; + +float gru_reset_layer1_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_reset_layer1_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_reset_layer1_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + +float gru_htilda_layer1_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_htilda_layer1_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_htilda_layer1_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + +float topk_layer1_W[WEIGHT_LAYER1_INPUTDIM][1]; + +// GCN and GRU weights for layer2 +float gcn_node_weight_layer2[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; //[122,122] + + + +float gru_update_layer2_W[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; //[122,122] +//WT_TYPE gru_update_layer2_W_fixed[WEIGHT_LAYER2_INPUTDIM * WEIGHT_LAYER2_OUTPUTDIM]; //for the third MLP part + + +float gru_update_layer2_U[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_update_layer2_bias[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; + + + + +float gru_reset_layer2_W[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_reset_layer2_U[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_reset_layer2_bias[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; + +float gru_htilda_layer2_W[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_htilda_layer2_U[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_htilda_layer2_bias[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; + +float topk_layer2_W[WEIGHT_LAYER2_INPUTDIM][1]; + +// final classfication layer weights + +float mlp_layer1_weight[77][244]; +float mlp_layer1_bias[77]; +float mlp_layer2_weight[2][77]; +float mlp_layer2_bias[2]; + + +float f_edge_list[NUM_EDGE * 2]; +float f_edge_list_time[TIME_STEP][NUM_EDGE * 2]; + +float edge_val[NUM_EDGE]; +float edge_val_time[TIME_STEP][NUM_EDGE]; + +char info_file_edge_list[1000]; +char info_file_edge_val[1000]; + +float node_embedding_list[NUM_NODE][2]; +float node_embedding_list_time[TIME_STEP][NUM_NODE][2]; + +float node_embedding_val[NUM_NODE]; +float node_embedding_val_time[TIME_STEP][NUM_NODE]; + + + +char info_file_node_embeddings_list[1000]; +char info_file_node_embedding_val[1000]; + +//float node_embedding[NUM_NODE][WEIGHT_LAYER1_INPUTDIM]; +//float node_embedding_time[TIME_STEP][NUM_NODE][WEIGHT_LAYER1_INPUTDIM]; + +float num_edges[TOTAL_TIME + 1]; +int num_edges_time[TIME_STEP]; +int num_nodes_time[TIME_STEP]; + +int node_out_degree[NUM_NODE]; +int node_out_degree_time[TIME_STEP][NUM_NODE]; + + +float node_embedding_subgraph[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +float node_embedding_subgraph_time[TIME_STEP][SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +float edge_embedding_subgraph[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; +float edge_embedding_subgraph_time[TIME_STEP][SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; + +int degree_table[SUB_GRAPH_NODE_NUM * 3]; +int neighbor_table[SUB_GRAPH_NODE_NUM * MAX_DEGREE * 2]; +int neighborhood_ref_table[NUM_NODE]; +int neighborhood_ref_table_time[TIME_STEP][NUM_NODE]; + +std::vector node_record_vector; + + +FM_TYPE node_embedding_in[TIME_STEP * SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE edge_embedding_in[TIME_STEP * SUB_GRAPH_EDGE_NUM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE output_fixed[SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_OUTPUTDIM]; + +FM_TYPE node_embedding_table_1[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE edge_embedding_table_1[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE node_embedding_table_2[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE edge_embedding_table_2[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; + +FM_TYPE node_embedding_table_time[TIME_STEP][SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE edge_embedding_table_time[TIME_STEP][SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; + +FM_TYPE output_table[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_OUTPUTDIM]; + + +//int edge_list[SUB_GRAPH_EDGE_NUM * 2]; + +int edge_list_time[TIME_STEP][SUB_GRAPH_EDGE_NUM * 2]; + + + +FM_TYPE weight_buffer_1[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; +FM_TYPE weight_buffer_2[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + +FM_TYPE emb_buffer_1[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE emb_buffer_2[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; + + +FM_TYPE rnn_update_weight_W_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_update_weight_U_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_update_bias_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; +FM_TYPE rnn_reset_weight_W_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_reset_weight_U_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_reset_bias_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; +FM_TYPE rnn_htilda_weight_W_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_htilda_weight_U_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_htilda_bias_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + + +FM_TYPE rnn_update_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_update_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_update_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; +FM_TYPE rnn_reset_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_reset_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_reset_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; +FM_TYPE rnn_htilda_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_htilda_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE rnn_htilda_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; + + + +float node_embedding[NUM_NODE][WEIGHT_LAYER1_INPUTDIM]; +float node_embedding_time[TIME_STEP][SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +float edge_embedding[NUM_EDGE][WEIGHT_LAYER1_INPUTDIM]; +float edge_embedding_time[TIME_STEP][SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; +float cell_state[NUM_NODE][WEIGHT_LAYER1_INPUTDIM]; +float edge_info_temp[103464]; +int edge_info[103464]; +float edge_num_temp[TOTAL_TIME]; +int edge_num[TOTAL_TIME]; +int edge_num_time[TIME_STEP]; +float node_num_temp[TOTAL_TIME]; +int node_num[TOTAL_TIME]; +int node_num_time[TIME_STEP]; +int edge_list[2 * SUB_GRAPH_EDGE_NUM]; + +float neighborhood_renumbering_table_temp[TOTAL_TIME][NUM_NODE]; +int neighborhood_renumbering_table[TOTAL_TIME][NUM_NODE]; +int neighborhood_renumbering_table_time[TIME_STEP][NUM_NODE]; +float neighborhood_reverse_renumbering_table_temp[TOTAL_TIME][501]; +int neighborhood_reverse_renumbering_table[TOTAL_TIME][501]; +int neighborhood_reverse_renumbering_table_time[TIME_STEP][SUB_GRAPH_NODE_NUM]; + + + +void load_weights_float() { // This function has been checked. + printf("Loading weights for evolveGCN (RNN + GCN)...\n"); + // printf("execute here now!\n"); + // FILE *f_2 = fopen("../DGNN_parameters/EvolveGCN_weights/EvolveGCN.bin", "r"); // Open in read mode as an example + // if (f_2 == NULL) { + // perror("Error opening file"); + // // Handle the error, e.g., exit the program or attempt to open another file + // } + + FILE* f; + //printf("execute here!"); + f = fopen("EvolveGCN.bin", "rb"); + //printf("execute here!"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gcn_node_weight_layer1, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_update_layer1_W, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_update_layer1_U, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_update_layer1_bias, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM; + + + + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_reset_layer1_W, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_reset_layer1_U, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_reset_layer1_bias, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM; + + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_htilda_layer1_W, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_htilda_layer1_U, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(gru_htilda_layer1_bias, sizeof(float), WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM, f); + number_count += WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM; + + +} + +void load_node_embedding() { + FILE* f; + f = fopen("node_embedding.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(node_embedding, sizeof(float), NUM_NODE * WEIGHT_LAYER1_INPUTDIM, f); + number_count += NUM_NODE * WEIGHT_LAYER1_INPUTDIM; + + +} + + +void load_edge_embedding() { + FILE* f; + f = fopen("edge_embedding.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(edge_embedding, sizeof(float), NUM_EDGE * WEIGHT_LAYER1_INPUTDIM, f); + number_count += NUM_EDGE * WEIGHT_LAYER1_INPUTDIM; + + + +} + + +void load_edge_info() { + FILE* f; + f = fopen("edge_info.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(edge_info_temp, sizeof(float), 103464, f); + number_count += 103464; + for (int i = 0; i < 103464; i++) { + edge_info[i] = (int)edge_info_temp[i]; + } + +} + +void load_edge_num() { + FILE* f; + f = fopen("edge_num.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(edge_num_temp, sizeof(float), TOTAL_TIME, f); + number_count += TOTAL_TIME; + for (int i = 0; i < TOTAL_TIME; i++) { + edge_num[i] = (int)edge_num_temp[i]; + } + +} + + +void load_node_num() { + FILE* f; + f = fopen("node_num.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(node_num_temp, sizeof(float), TOTAL_TIME, f); + number_count += TOTAL_TIME; + for (int i = 0; i < TOTAL_TIME; i++) { + node_num[i] = (int)node_num_temp[i]; + } + +} + +void load_renumbering_table() { + FILE* f; + f = fopen("neighborhood_ref_table.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(neighborhood_renumbering_table_temp, sizeof(float), TOTAL_TIME * NUM_NODE, f); + number_count += TOTAL_TIME * NUM_NODE; + for (int i = 0; i < TOTAL_TIME; i++) { + for (int j = 0; j < NUM_NODE; j++) { + neighborhood_renumbering_table[i][j] = (int)neighborhood_renumbering_table_temp[i][j]; + + } + + } + +} + + +void load_reverse_renumbering_table() { + FILE* f; + f = fopen("neighborhood_reverse_ref_table.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(neighborhood_reverse_renumbering_table_temp, sizeof(float), TOTAL_TIME * 501, f); + number_count += TOTAL_TIME * 501; + for (int i = 0; i < TOTAL_TIME; i++) { + for (int j = 0; j < 501; j++) { + neighborhood_reverse_renumbering_table[i][j] = (int)neighborhood_reverse_renumbering_table_temp[i][j]; + + } + + } + +} + + +void process_edge_list_info(int time, int time_step) { + int total = 0; + int total_internel = 0; + for (int i = 0; i < time; i++) { + total = total + 2 * edge_num[i]; + } + for (int t = 0; t < time_step; t++) { + for (int i = 0; i < edge_num[time + t]; i++) { + edge_list_time[t][2 * i] = edge_info[total + total_internel + 2 * i]; + edge_list_time[t][2 * i + 1] = edge_info[total + total_internel + 2 * i + 1]; + + } + total_internel = total_internel + 2 * edge_num[time + t]; + } + + +} + +void process_node_embedding(int time, int time_step, int neighborhood_reverse_renumbering_table[TOTAL_TIME][501]) { // This function has been checked. + for (int t = 0; t < time_step; t++) { + for (int nd = 0; nd < node_num[time + t]; nd++) { + int position = neighborhood_reverse_renumbering_table[time + t][nd]; + //printf("the value of pos is:%d\n", position); + for (int dim = 0; dim < WEIGHT_LAYER1_INPUTDIM; dim++) { + + + node_embedding_time[t][nd][dim] = node_embedding[position][dim]; + } + } + } + + +} + +void process_edge_embedding(int time, int time_step) {// This function has been checked. + int total = 0; + int total_internel = 0; + for (int i = 0; i < time; i++) { + total = total + edge_num[i]; + } + for (int t = 0; t < time_step; t++) { + + for (int e = 0; e < edge_num[time + t]; e++) { + for (int dim = 0; dim < WEIGHT_LAYER1_INPUTDIM; dim++) { + edge_embedding_time[t][e][dim] = edge_embedding[total + total_internel + e][dim]; + } + } + total_internel = total_internel + edge_num[time + t]; + } +} + +void process_num(int time, int time_step) { // This function has been checked. + int total_node = 0; + int total_edge = 0; + int total_internel = 0; + for (int i = 0; i < time; i++) { + total_node = total_node + 1; + total_edge = total_edge + 1; + } + for (int t = 0; t < time_step; t++) { + node_num_time[t] = node_num[total_node + total_internel + t]; + edge_num_time[t] = edge_num[total_edge + total_internel + t]; + } +} + +void process_renumbering_table(int time, int time_step) {// This function has been checked. + int total_1 = 0; + int total_2 = 0; + int total_internel_1 = 0; + int total_internel_2 = 0; + for (int i = 0; i < time; i++) { + total_1 = total_1 + 1; + total_2 = total_2 + 1; + } + + for (int t = 0; t < time_step; t++) { + for (int nd = 0; nd < NUM_NODE; nd++) { + neighborhood_renumbering_table_time[t][nd] = neighborhood_renumbering_table[total_1 + t][nd]; + } + } + + for (int t = 0; t < time_step; t++) { + for (int nd = 0; nd < SUB_GRAPH_NODE_NUM; nd++) { + neighborhood_reverse_renumbering_table_time[t][nd] = neighborhood_reverse_renumbering_table[total_2 + t][nd]; + } + } + +} + + +void convert_weights_to_fix() { //the weight input layer 1 is 67. the weight output layer 1 is 122 (GNN); the weight input layer 2 is 122, the weight output of layer 2 is 122 (RNN�� + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + gcn_node_weight_layer1_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out] = (WT_TYPE)gcn_node_weight_layer1[dim_in][dim_out]; + } + } + + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_update_weight_W_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out] = (WT_TYPE)gru_update_layer1_W[dim_in][dim_out]; + + } + } + + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_update_weight_U_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out] = (WT_TYPE)gru_update_layer1_U[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + rnn_update_bias_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out] = (WT_TYPE)gru_update_layer1_bias[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_reset_weight_W_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out] = (WT_TYPE)gru_reset_layer1_W[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_reset_weight_U_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out] = (WT_TYPE)gru_reset_layer1_U[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + rnn_reset_bias_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out] = (WT_TYPE)gru_reset_layer1_bias[dim_in][dim_out]; + + } + } + + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_htilda_weight_W_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out] = (WT_TYPE)gru_htilda_layer1_W[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_htilda_weight_U_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out] = (WT_TYPE)gru_htilda_layer1_U[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + rnn_htilda_bias_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out] = (WT_TYPE)gru_htilda_layer1_bias[dim_in][dim_out]; + + } + } + + printf("Convert weights to fix finished ...\n"); +} + + +void convert_embedding_to_fix() { + for (int time = 0; time < TIME_STEP; time++) { + for (int i = 0; i < SUB_GRAPH_NODE_NUM; i++) { + for (int j = 0; j < WEIGHT_LAYER1_INPUTDIM; j++) { + node_embedding_in[time * SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_INPUTDIM + i * WEIGHT_LAYER1_INPUTDIM + j] = (FM_TYPE)node_embedding_time[time][i][j]; + } + } + } + + for (int time = 0; time < TIME_STEP; time++) { + for (int i = 0; i < SUB_GRAPH_EDGE_NUM; i++) { + for (int j = 0; j < WEIGHT_LAYER1_INPUTDIM; j++) { + edge_embedding_in[time * SUB_GRAPH_EDGE_NUM * WEIGHT_LAYER1_INPUTDIM + i * WEIGHT_LAYER1_INPUTDIM + j] = (FM_TYPE)edge_embedding_time[time][i][j]; + } + } + } + +} + + + +void load_weights(WT_TYPE gnn_layer_1_weight_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_update_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_reset_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_htilda_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM] +) { // This function has been checked. + +#pragma HLS inline off + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + weight_buffer_2[dim_in][dim_out] = gnn_layer_1_weight_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out]; + //printf("the value is:%.6f\n", (float)weight_buffer_2[dim_in][dim_out]); + } + } + + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_update_weight_W_buffer[dim_in][dim_out] = rnn_update_weight_W_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_update_weight_U_buffer[dim_in][dim_out] = rnn_update_weight_U_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + rnn_update_bias_buffer[dim_in][dim_out] = rnn_update_bias_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out]; + + } + } + + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_reset_weight_W_buffer[dim_in][dim_out] = rnn_reset_weight_W_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_reset_weight_U_buffer[dim_in][dim_out] = rnn_reset_weight_U_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + rnn_reset_bias_buffer[dim_in][dim_out] = rnn_reset_bias_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_htilda_weight_W_buffer[dim_in][dim_out] = rnn_htilda_weight_W_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_INPUTDIM; dim_out++) { + rnn_htilda_weight_U_buffer[dim_in][dim_out] = rnn_htilda_weight_U_fixed[dim_in * WEIGHT_LAYER1_INPUTDIM + dim_out]; + + } + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + rnn_htilda_bias_buffer[dim_in][dim_out] = rnn_htilda_bias_fixed[dim_in * WEIGHT_LAYER1_OUTPUTDIM + dim_out]; + //printf("the value is:%.6f\n", (float)rnn_htilda_bias_buffer[dim_in][dim_out]); + + } + } + + + +} + + +void load_graph(int edge_list_in[TIME_STEP][SUB_GRAPH_EDGE_NUM * 2], + int edge_list[SUB_GRAPH_EDGE_NUM * 2], + int neighborhood_ref_table_time[TIME_STEP][NUM_NODE], + WT_TYPE node_embedding_in[TIME_STEP * SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE edge_attr_in[TIME_STEP * SUB_GRAPH_EDGE_NUM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE node_embedding_table[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE edge_embedding_table[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM], + int num_of_nodes, int num_of_edges, int time) +{ // This function has been checked. +#pragma HLS inline off + for (int i = 0; i < num_of_nodes; i++) { + for (int dim = 0; dim < WEIGHT_LAYER1_INPUTDIM; dim++) { + node_embedding_table[i][dim] = node_embedding_in[time * SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_INPUTDIM + i * WEIGHT_LAYER1_INPUTDIM + dim]; + } + + } + + for (int e = 0; e < num_of_edges; e++) { + for (int dim = 0; dim < WEIGHT_LAYER1_INPUTDIM; dim++) { + edge_embedding_table[e][dim] = edge_attr_in[time * SUB_GRAPH_EDGE_NUM * WEIGHT_LAYER1_INPUTDIM + e * WEIGHT_LAYER1_INPUTDIM + dim]; + } + } + + for (int i = 0; i < num_of_edges * 2; i++) { + edge_list[i] = edge_list_in[time][i]; + } + + + for (int n = 0; n < num_of_nodes * 3; n++) { + degree_table[n] = 0; + } + + for (int e = 0; e < num_of_edges; e++) { + int u = neighborhood_ref_table_time[time][edge_list[e * 2]]; // source node id + //printf("the original source node id is:%d\n", edge_list[e * 2]); + //printf("the source node id is:%d\n", u); + int v = neighborhood_ref_table_time[time][edge_list[e * 2 + 1]]; // target node id + //printf("the original target node id is:%d\n", edge_list[e * 2 + 1]); + //printf("the target node id is:%d\n", v); + + degree_table[u * 3] += 1; //the format of degree table: [ total_neighbrhood_number | start_idx_for_neigh_table | offset_idx_for_neigh_table ] + } //the format of neighbor table: [neighborhood_node_index | edge number] + + for (int n = 1; n < num_of_nodes; n++) { + degree_table[n * 3 + 1] = degree_table[(n - 1) * 3] * 2 + degree_table[(n - 1) * 3 + 1]; // *2: one is for the neighbor node id; the next one is for the corresponding edge id + }// this for loop is used to define the start idx = past node start idx + past node degree *2 ( for neighbor_idx and edge_index) + + for (int e = 0; e < num_of_edges; e++) { + int u = neighborhood_ref_table_time[time][edge_list[e * 2]]; // source node id + int v = neighborhood_ref_table_time[time][edge_list[e * 2 + 1]]; // target node id + + int total_neigh = degree_table[u * 3]; + int start_idx = degree_table[u * 3 + 1]; + int offset_idx = degree_table[u * 3 + 2]; + + neighbor_table[start_idx + offset_idx] = v; + //printf("the number of v is:%d\n", v); + //printf("the number of e is:%d\n", e); + //printf("the number of index is:%d\n", start_idx + offset_idx + 1); + neighbor_table[start_idx + offset_idx + 1] = e; + degree_table[u * 3 + 2] += 2; + } + + + +} + + + +void message_passing(FM_TYPE emb_val[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM], + int num_of_nodes, int num_of_edges, + FM_TYPE message_tb[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM], + FM_TYPE edge_attr[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]) +{ //This function has been checked. +#pragma HLS inline off +#pragma HLS array_partition variable=message_tb dim=2 complete +#pragma HLS array_partition variable=edge_attr dim=2 complete + + for (int nd = 0; nd < num_of_nodes; nd++) { + int u = nd; // u is the source node + int total_neigh = degree_table[u * 3]; // we need a degree table 1. neighborhood number, start index in the neighbor table. + int start_idx = degree_table[u * 3 + 1]; + + FM_TYPE norm[160]; + FM_TYPE node_embedding_vec[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE msg = 0; //this is used to store message for one edge + + for (int i = 0; i < 160; i++) { + norm[i] = 0; + } + + for (int i = 0; i < WEIGHT_LAYER1_INPUTDIM; i++) { + node_embedding_vec[i] = 0; + } + + for (int i = 0; i < total_neigh; i++) { + int v = neighbor_table[start_idx + i * 2]; // v is the neighborhood node index + int e = neighbor_table[start_idx + i * 2 + 1];// e is the edge index + norm[i] = (1.0 / sqrt(degree_table[u * 3] + 1.0)) * (1.0 / sqrt(degree_table[v * 3] + 1.0)); + //printf("the value is:%.6f",) + for (int dim = 0; dim < WEIGHT_LAYER1_INPUTDIM; dim++) { +#pragma HLS pipeline II = 1 + //msg = norm[i] * (node_embedding_vec[dim] + edge_attr[dim]); //for each node, we need to load an edge embedding table on chip + msg = norm[i] * (edge_attr[e][dim] + message_tb[v][dim]); //? + node_embedding_vec[dim] += msg; + } + } + + for (int dim = 0; dim < WEIGHT_LAYER1_INPUTDIM; dim++) { +#pragma HLS pipeline II = 1 + FM_TYPE temp = (1.0 / (degree_table[u * 3] + 1.0)); + node_embedding_vec[dim] += temp * message_tb[u][dim]; + emb_val[nd][dim] = node_embedding_vec[dim]; + + + } + } + +} + +void write_to_fifo(FM_TYPE rnn_input[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + hls::stream& rnn_input_fifo_1, + hls::stream& rnn_input_fifo_2, + hls::stream& rnn_input_fifo_3, + hls::stream& rnn_input_fifo_4, + hls::stream& rnn_input_fifo_5, + hls::stream& rnn_input_fifo_6, + hls::stream& rnn_input_fifo_7) { // This function has been checked. + /* + + for (int i = 0; i < WEIGHT_LAYER1_INPUTDIM; i++) { + for (int j = 0; j < WEIGHT_LAYER1_OUTPUTDIM; j++) { + printf("the value is:%.6f\n", (float)rnn_input[i][j]); + } + } + + */ + + + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + rnn_input_fifo_1.write(rnn_input[dim_in][dim_out]); + rnn_input_fifo_2.write(rnn_input[dim_in][dim_out]); + rnn_input_fifo_3.write(rnn_input[dim_in][dim_out]); + rnn_input_fifo_4.write(rnn_input[dim_in][dim_out]); + rnn_input_fifo_5.write(rnn_input[dim_in][dim_out]); + rnn_input_fifo_6.write(rnn_input[dim_in][dim_out]); + rnn_input_fifo_7.write(rnn_input[dim_in][dim_out]); + } + } +} + +void GRU_cell_sigmoid(hls::stream& rnn_input_1, + hls::stream& rnn_input_2, + hls::stream& rnn_output, + WT_TYPE rnn_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]) + + +{// This function has been checked. +#pragma HLS array_partition variable=rnn_weight_W dim=2 complete +#pragma HLS array_partition variable=rnn_weight_U dim=2 complete + + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + FM_TYPE rnn_input_1_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE rnn_input_2_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE rnn_output_vector[WEIGHT_LAYER1_INPUTDIM]; +#pragma HLS array_partition variable=rnn_input_1_vector dim=1 complete +#pragma HLS array_partition variable=rnn_input_2_vector dim=1 complete + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + rnn_input_1_vector[dim_in] = rnn_input_1.read(); + + rnn_input_2_vector[dim_in] = rnn_input_2.read(); + //printf("the value is:%.6f\n", (float)rnn_input_2_vector[dim_in]); + } + for (int nd = 0; nd < WEIGHT_LAYER1_INPUTDIM; nd++) { + +#pragma HLS pipeline II = 1 + FM_TYPE tmp = rnn_bias[nd][dim_out]; + //printf("the value is:%.6f\n", (float)tmp); + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + //tmp += rnn_input[nd][dim_in] * rnn_weight[dim_in][dim_out]; + tmp += rnn_weight_W[nd][dim_in] * rnn_input_1_vector[dim_in] + rnn_weight_U[nd][dim_in] * rnn_input_2_vector[dim_in]; + } + rnn_output_vector[nd] = tmp; + + rnn_output_vector[nd] = 1.0 / (1.0 + expf(-rnn_output_vector[nd])); + rnn_output.write(rnn_output_vector[nd]); + //printf("the value is:%.6f\n", (float)rnn_output_vector[nd]); + } + } +} + + +void GRU_multi_1(hls::stream& rnn_input, + hls::stream& reset_output_fifo, + hls::stream& htilda_output_fifo) { + // This function has been checked. + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + FM_TYPE rnn_input_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE reset_output_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE htilda_output_vector[WEIGHT_LAYER1_INPUTDIM]; +#pragma HLS array_partition variable=rnn_input_vector dim=1 complete +#pragma HLS array_partition variable=reset_output_vector dim=1 complete +#pragma HLS array_partition variable=htilda_output_vector dim=1 complete + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + rnn_input_vector[dim_in] = rnn_input.read(); + reset_output_vector[dim_in] = reset_output_fifo.read(); + } + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { +#pragma HLS pipeline II = 1 + htilda_output_vector[dim_in] = rnn_input_vector[dim_in] * reset_output_vector[dim_in]; + } + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + htilda_output_fifo.write(htilda_output_vector[dim_in]); + //printf("the value is:%.6f\n", (float)htilda_output_vector[dim_in]); + } + } + + +} + + +void GRU_cell_tanh(hls::stream& rnn_input_1, + hls::stream& rnn_input_2, + hls::stream& rnn_output, + WT_TYPE rnn_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]) { +#pragma HLS array_partition variable=rnn_weight_W dim=2 complete +#pragma HLS array_partition variable=rnn_weight_U dim=2 complete + + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + FM_TYPE rnn_input_1_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE rnn_input_2_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE rnn_output_vector[WEIGHT_LAYER1_INPUTDIM]; +#pragma HLS array_partition variable=rnn_input_1_vector dim=1 complete +#pragma HLS array_partition variable=rnn_input_2_vector dim=1 complete + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + rnn_input_1_vector[dim_in] = rnn_input_1.read(); + rnn_input_2_vector[dim_in] = rnn_input_2.read(); + } + for (int nd = 0; nd < WEIGHT_LAYER1_INPUTDIM; nd++) { + +#pragma HLS pipeline II = 1 + FM_TYPE tmp = rnn_bias[nd][dim_out]; + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + //tmp += rnn_input[nd][dim_in] * rnn_weight[dim_in][dim_out]; + tmp += rnn_weight_W[nd][dim_in] * rnn_input_1_vector[dim_in] + rnn_weight_U[nd][dim_in] * rnn_input_2_vector[dim_in]; + } + rnn_output_vector[nd] = tmp; + rnn_output_vector[nd] = (expf(rnn_output_vector[nd]) - expf(-rnn_output_vector[nd])) / (expf(rnn_output_vector[nd]) + expf(-rnn_output_vector[nd])); + rnn_output.write(rnn_output_vector[nd]); + //printf("the value is:%.6f\n", (float)rnn_output_vector[nd]); + } + } +} + + +void GRU_multi_2(hls::stream& update_output, + hls::stream& rnn_input, + hls::stream& htilda_output, + WT_TYPE rnn_output[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]) + +{ //This function has been checked. +#pragma HLS array_partition variable=rnn_output dim=1 complete + + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + FM_TYPE update_output_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE rnn_input_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE htilda_output_vector[WEIGHT_LAYER1_INPUTDIM]; + FM_TYPE rnn_output_vector[WEIGHT_LAYER1_INPUTDIM]; +#pragma HLS array_partition variable=update_output_vector dim=1 complete +#pragma HLS array_partition variable=rnn_input_vector dim=1 complete +#pragma HLS array_partition variable=htilda_output_vector dim=1 complete + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + update_output_vector[dim_in] = update_output.read(); + //printf("the value is:%.6f\n", (float)update_output_vector[dim_in]); + rnn_input_vector[dim_in] = rnn_input.read(); + htilda_output_vector[dim_in] = htilda_output.read(); + + } + + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { +#pragma HLS pipeline II = 1 + + rnn_output[dim_in][dim_out] = ((WT_TYPE)1.0 - update_output_vector[dim_in]) * rnn_input_vector[dim_in] + update_output_vector[dim_in] * htilda_output_vector[dim_in]; + //printf("the value is:%.6f\n", (float)rnn_output[dim_in][dim_out]); + } + } + + +} + + +void CONV_GNN(FM_TYPE gnn_input[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM], + FM_TYPE gnn_output[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_OUTPUTDIM], + FM_TYPE conv_weights[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_OUTPUTDIM], + int num_of_nodes, int num_of_edges) +{ //This function has been checked. +#pragma HLS inline off +#pragma HLS array_partition variable=conv_weights dim=1 complete +#pragma HLS array_partition variable=gnn_input dim=2 complete + + + for (int nd = 0; nd < num_of_nodes; nd++) { + + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { +#pragma HLS PIPELINE II = 1 + + + FM_TYPE tmp = 0; + gnn_output[nd][dim_out] = 0; + for (int dim_in = 0; dim_in < WEIGHT_LAYER1_INPUTDIM; dim_in++) { + + tmp += gnn_input[nd][dim_in] * conv_weights[dim_in][dim_out]; + } + gnn_output[nd][dim_out] += tmp; + + } + + } +} + + + + +void GRU_dataflow(FM_TYPE rnn_input[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + FM_TYPE rnn_output[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_update_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_reset_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_htilda_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]) + + +{ + FM_TYPE update_output[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + FM_TYPE reset_output[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + FM_TYPE htilda_output_temp[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + FM_TYPE htilda_output[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + + + hls::stream rnn_input_fifo_1; + hls::stream rnn_input_fifo_2; + hls::stream rnn_input_fifo_3; + hls::stream rnn_input_fifo_4; + hls::stream rnn_input_fifo_5; + hls::stream rnn_input_fifo_6; + hls::stream rnn_input_fifo_7; + + + + hls::stream update_output_fifo; + hls::stream reset_output_fifo; + hls::stream htilda_output_temp_fifo; + hls::stream htilda_output_fifo; + + +#pragma HLS STREAM variable=rnn_input_fifo_1 depth=400 +#pragma HLS STREAM variable=rnn_input_fifo_2 depth=400 +#pragma HLS STREAM variable=rnn_input_fifo_3 depth=400 +#pragma HLS STREAM variable=rnn_input_fifo_4 depth=400 +#pragma HLS STREAM variable=rnn_input_fifo_5 depth=400 +#pragma HLS STREAM variable=rnn_input_fifo_6 depth=400 +#pragma HLS STREAM variable=rnn_input_fifo_7 depth=400 + + + +#pragma HLS STREAM variable=update_output_fifo depth=400 +#pragma HLS STREAM variable=reset_output_fifo depth=400 +#pragma HLS STREAM variable=htilda_output_temp_fifo depth=400 +#pragma HLS STREAM variable=htilda_output_fifo depth=400 +#pragma HLS dataflow + write_to_fifo(rnn_input, rnn_input_fifo_1, rnn_input_fifo_2, rnn_input_fifo_3, rnn_input_fifo_4, rnn_input_fifo_5, rnn_input_fifo_6, rnn_input_fifo_7); + GRU_cell_sigmoid(rnn_input_fifo_1, rnn_input_fifo_2, update_output_fifo, rnn_update_weight_W, rnn_update_weight_U, rnn_update_bias); + GRU_cell_sigmoid(rnn_input_fifo_3, rnn_input_fifo_4, reset_output_fifo, rnn_reset_weight_W, rnn_reset_weight_U, rnn_reset_bias); + GRU_multi_1(rnn_input_fifo_5, reset_output_fifo, htilda_output_temp_fifo); + GRU_cell_tanh(rnn_input_fifo_6, htilda_output_temp_fifo, htilda_output_fifo, rnn_htilda_weight_W, rnn_htilda_weight_U, rnn_htilda_bias); + GRU_multi_2(update_output_fifo, rnn_input_fifo_7, htilda_output_fifo, rnn_output); + + +} + + + + + + + +void compute_dataflow(int edge_list_in[TIME_STEP][SUB_GRAPH_EDGE_NUM * 2], + int edge_list[SUB_GRAPH_EDGE_NUM * 2], + int neighborhood_ref_table_time[TIME_STEP][NUM_NODE], + FM_TYPE node_embedding_in[TIME_STEP * SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_INPUTDIM], + FM_TYPE edge_attr_in[TIME_STEP * SUB_GRAPH_EDGE_NUM * WEIGHT_LAYER1_INPUTDIM], + //WT_TYPE gnn_weights[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + + FM_TYPE output[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_OUTPUTDIM], + + WT_TYPE rnn_update_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_reset_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_htilda_weight_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_weight_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM], + int node_number_time[TIME_STEP], int edge_number_time[TIME_STEP], int step + ) + +{ +#pragma HLS inline off + for (int time = 0; time < step; time++) { + if (time % 2 == 0) { + load_graph(edge_list_in, edge_list, neighborhood_ref_table_time, node_embedding_in, edge_attr_in, node_embedding_table_1, edge_embedding_table_1, node_number_time[time], edge_number_time[time], time); + message_passing(emb_buffer_1, node_number_time[time], edge_number_time[time], node_embedding_table_1, edge_embedding_table_1); + GRU_dataflow(weight_buffer_2, weight_buffer_1, rnn_update_weight_W, rnn_update_weight_U, rnn_update_bias, rnn_reset_weight_W, rnn_reset_weight_U, rnn_reset_bias, rnn_htilda_weight_W, rnn_htilda_weight_U, rnn_htilda_bias); + CONV_GNN(emb_buffer_1, output, weight_buffer_1, node_number_time[time], edge_number_time[time]); + + } + else if (time % 2 == 1) { + + + load_graph(edge_list_in, edge_list, neighborhood_ref_table_time, node_embedding_in, edge_attr_in, node_embedding_table_1, edge_embedding_table_1, node_number_time[time], edge_number_time[time], time); + message_passing(emb_buffer_2, node_number_time[time], edge_number_time[time], node_embedding_table_1, edge_embedding_table_1); + GRU_dataflow(weight_buffer_1, weight_buffer_2, rnn_update_weight_W, rnn_update_weight_U, rnn_update_bias, rnn_reset_weight_W, rnn_reset_weight_U, rnn_reset_bias, rnn_htilda_weight_W, rnn_htilda_weight_U, rnn_htilda_bias); + CONV_GNN(emb_buffer_2, output, weight_buffer_2, node_number_time[time], edge_number_time[time]); + + } + + } + + + +} + + +void write_back(FM_TYPE output[SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_OUTPUTDIM], + FM_TYPE output_table[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_OUTPUTDIM], + int num_of_nodes) { + for (int nd = 0; nd < num_of_nodes; nd++) { + for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + output[nd * WEIGHT_LAYER1_OUTPUTDIM + dim_out] = output_table[nd][dim_out]; + //printf("the value is:%.6f\n", (float)output_table[nd][dim_out]); + } + } +} + + +void DGNN_booster_evolveGCN( + int edge_list_in[TIME_STEP][SUB_GRAPH_EDGE_NUM * 2], + int node_number_time[TIME_STEP], + int edge_number_time[TIME_STEP], + int neighborhood_ref_table_time[TIME_STEP][NUM_NODE], + int neighborhood_reverse_ref_table_time[TIME_STEP][SUB_GRAPH_NODE_NUM], + + WT_TYPE gnn_layer_1_weight_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + + + WT_TYPE rnn_update_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_update_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_reset_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_reset_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + WT_TYPE rnn_htilda_weight_W_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_weight_U_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_INPUTDIM], + WT_TYPE rnn_htilda_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM], + + + FM_TYPE node_embedding_fixed[TIME_STEP * SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_INPUTDIM], + FM_TYPE edge_attr_in_fixed[TIME_STEP * SUB_GRAPH_EDGE_NUM * WEIGHT_LAYER1_INPUTDIM], + + FM_TYPE output_fixed[SUB_GRAPH_NODE_NUM * WEIGHT_LAYER1_OUTPUTDIM], + int step[100] +) + +{ + +#pragma HLS INTERFACE s_axilite port=return + +#pragma HLS INTERFACE m_axi depth=100000 port=edge_list_in offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=node_number_time offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=edge_number_time offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=neighborhood_ref_table_time offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=neighborhood_reverse_ref_table_time offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_layer_1_weight_fixed offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_update_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_update_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_update_bias_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_reset_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_reset_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_reset_bias_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_htilda_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_htilda_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=rnn_htilda_bias_fixed offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=100000 port=node_embedding_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=edge_attr_in_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=output_fixed offset=slave bundle=OUTPUT +#pragma HLS INTERFACE m_axi depth=100000 port=step offset=slave bundle=INPUT + +#pragma HLS bind_storage variable=weight_buffer_1 impl = bram +#pragma HLS bind_storage variable=weight_buffer_2 impl = bram + +#pragma HLS bind_storage variable=emb_buffer_1 impl = bram +#pragma HLS bind_storage variable=emb_buffer_2 impl = bram + +#pragma HLS bind_storage variable=rnn_update_weight_W_buffer impl = bram +#pragma HLS bind_storage variable=rnn_update_weight_U_buffer impl = bram +#pragma HLS bind_storage variable=rnn_update_bias_buffer impl = bram + +#pragma HLS bind_storage variable=rnn_reset_weight_W_buffer impl = bram +#pragma HLS bind_storage variable=rnn_reset_weight_U_buffer impl = bram +#pragma HLS bind_storage variable=rnn_reset_bias_buffer impl = bram + +#pragma HLS bind_storage variable=rnn_htilda_weight_W_buffer impl = bram +#pragma HLS bind_storage variable=rnn_htilda_weight_U_buffer impl = bram +#pragma HLS bind_storage variable=rnn_htilda_bias_buffer impl = bram + +#pragma HLS bind_storage variable=output_table impl = bram + + + load_weights(gnn_layer_1_weight_fixed, rnn_update_weight_W_fixed, rnn_update_weight_U_fixed, rnn_update_bias_fixed, rnn_reset_weight_W_fixed, rnn_reset_weight_U_fixed, rnn_reset_bias_fixed, rnn_htilda_weight_W_fixed, rnn_htilda_weight_U_fixed, rnn_htilda_bias_fixed); + + compute_dataflow(edge_list_in, edge_list, neighborhood_ref_table_time, node_embedding_fixed, edge_attr_in_fixed, output_table, rnn_update_weight_W_buffer, rnn_update_weight_U_buffer, rnn_update_bias_buffer, rnn_reset_weight_W_buffer, rnn_reset_weight_U_buffer, rnn_reset_bias_buffer, rnn_htilda_weight_W_buffer, rnn_htilda_weight_U_buffer, rnn_htilda_bias_buffer, node_number_time, edge_number_time, step[0]); + write_back(output_fixed, output_table, node_number_time[step[0]-1]); + + +} + + + + +int main() { + + load_weights_float(); + //printf("execute at chkpt 1\n"); + load_node_embedding(); + //printf("execute at chkpt 2\n"); + load_edge_embedding(); + load_edge_num(); + load_node_num(); + load_edge_info(); + load_renumbering_table(); + load_reverse_renumbering_table(); + + process_edge_list_info(0, 3); + process_node_embedding(0, 3, neighborhood_reverse_renumbering_table); + process_edge_embedding(0, 3); + process_num(0, 3); + process_renumbering_table(0, 3); + + convert_weights_to_fix(); + convert_embedding_to_fix(); + + int step[100]; + step[0] = 10; + DGNN_booster_evolveGCN(edge_list_time, node_num_time, edge_num_time, neighborhood_renumbering_table_time, neighborhood_reverse_renumbering_table_time, gcn_node_weight_layer1_fixed, rnn_update_weight_W_fixed, rnn_update_weight_U_fixed, rnn_update_bias_fixed, rnn_reset_weight_W_fixed, rnn_reset_weight_U_fixed, rnn_reset_bias_fixed, rnn_htilda_weight_W_fixed, rnn_htilda_weight_U_fixed, rnn_htilda_bias_fixed, node_embedding_in, edge_embedding_in, output_fixed, step); + + printf("the simulation ends!\n"); + // for (int nd = 0; nd < SUB_GRAPH_NODE_NUM; nd++) { + // for (int dim_out = 0; dim_out < WEIGHT_LAYER1_OUTPUTDIM; dim_out++) { + // printf("the value is:%.6f\n", (float)output_fixed[nd * WEIGHT_LAYER1_OUTPUTDIM + dim_out]); + // } + // } + + + +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_convLSTM/src/DGNN-booster2-GCRN-M2.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_convLSTM/src/DGNN-booster2-GCRN-M2.cpp new file mode 100644 index 000000000000..2997937647c3 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/DGNN_Booster_convLSTM/src/DGNN-booster2-GCRN-M2.cpp @@ -0,0 +1,1372 @@ +#include +#include + +//#include "dcl.h" +#include +#include +#include +#include + +#include +//#include "D:\vivado2018setup\Vivado\2018.3\include\gmp.h" +#include +#include +#include +#include +#include +#include "hls_stream.h" +#include +#include +#include +#include + +#include + +typedef ap_fixed<32, 10> FM_TYPE; +typedef ap_fixed<32, 10> WT_TYPE; + +#define WEIGHT_LAYER1_INPUTDIM 67 +#define WEIGHT_LAYER1_OUTPUTDIM 122 +#define WEIGHT_LAYER2_INPUTDIM 122 +#define WEIGHT_LAYER2_OUTPUTDIM 122 +#define TIME_STEP 10 + +#define NUM_EDGE 51732 +#define NUM_NODE 3783 +#define LAYER1_INPUTDIM 67 +#define TOTAL_TIME 192 +#define TIME_STEP 10 + +#define MAX_DEGREE 160 + +#define SUB_GRAPH_NODE_NUM 600 +#define SUB_GRAPH_EDGE_NUM 1800 + + + +#define INPUTDIM 67 +#define OUTPUTDIM 67 + +using namespace std; + + +float gcn_node_weight_layer1[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; // [67,122] +WT_TYPE gcn_node_weight_layer1_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; + +WT_TYPE gcn_node_weight_layer1_buffer[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + + +float gru_update_layer1_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_update_layer1_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_update_layer1_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; //[67,122] +WT_TYPE gru_update_layer1_bias_fixed[WEIGHT_LAYER1_INPUTDIM * WEIGHT_LAYER1_OUTPUTDIM]; + +WT_TYPE gru_update_layer1_bias_buffer[WEIGHT_LAYER1_OUTPUTDIM]; + +float gru_reset_layer1_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_reset_layer1_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_reset_layer1_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + +float gru_htilda_layer1_W[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_htilda_layer1_U[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_INPUTDIM]; +float gru_htilda_layer1_bias[WEIGHT_LAYER1_INPUTDIM][WEIGHT_LAYER1_OUTPUTDIM]; + +float topk_layer1_W[WEIGHT_LAYER1_INPUTDIM][1]; + + + +//create weights for convLSTM + +float rnn_update_W[INPUTDIM][OUTPUTDIM]; +float rnn_update_U[INPUTDIM][OUTPUTDIM]; +float rnn_update_bias[OUTPUTDIM]; +float rnn_reset_W[INPUTDIM][OUTPUTDIM]; +float rnn_reset_U[INPUTDIM][OUTPUTDIM]; +float rnn_reset_bias[OUTPUTDIM]; +float rnn_htilda_W[INPUTDIM][OUTPUTDIM]; +float rnn_htilda_U[INPUTDIM][OUTPUTDIM]; +float rnn_htilda_bias[OUTPUTDIM]; +float rnn_output_W[INPUTDIM][OUTPUTDIM]; +float rnn_output_U[INPUTDIM][OUTPUTDIM]; +float rnn_output_bias[OUTPUTDIM]; +float node_embedding[NUM_NODE][INPUTDIM]; +float edge_embedding[NUM_EDGE][INPUTDIM]; +float cell_state[NUM_NODE][INPUTDIM]; +float edge_info_temp[103464]; +int edge_info[103464]; +float edge_num_temp[TOTAL_TIME]; +int edge_num[TOTAL_TIME]; +float node_num_temp[TOTAL_TIME]; +int node_num[TOTAL_TIME]; +int edge_list[2 * SUB_GRAPH_EDGE_NUM]; + +FM_TYPE node_embedding_fixed[NUM_NODE * INPUTDIM]; +FM_TYPE cell_table_fixed[NUM_NODE * INPUTDIM]; +FM_TYPE edge_embedding_fixed[SUB_GRAPH_EDGE_NUM * INPUTDIM]; + +float neighborhood_renumbering_table_temp[TOTAL_TIME][NUM_NODE]; +int neighborhood_renumbering_table[TOTAL_TIME][NUM_NODE]; +float neighborhood_reverse_renumbering_table_temp[TOTAL_TIME][578]; +int neighborhood_reverse_renumbering_table[TOTAL_TIME][578]; + + +// GCN and GRU weights for layer2 +float gcn_node_weight_layer2[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; //[122,122] +WT_TYPE gcn_node_weight_layer2_fixed[WEIGHT_LAYER2_INPUTDIM * WEIGHT_LAYER2_OUTPUTDIM]; + +WT_TYPE gcn_node_weight_layer2_buffer[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; + + +float gru_update_layer2_W[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; //[122,122] +//WT_TYPE gru_update_layer2_W_fixed[WEIGHT_LAYER2_INPUTDIM * WEIGHT_LAYER2_OUTPUTDIM]; //for the third MLP part + + +float gru_update_layer2_U[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_update_layer2_bias[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; +WT_TYPE gru_update_layer2_bias_fixed[WEIGHT_LAYER2_INPUTDIM * WEIGHT_LAYER2_OUTPUTDIM]; + +WT_TYPE gru_update_layer2_bias_buffer[WEIGHT_LAYER2_OUTPUTDIM]; + + + +float gru_reset_layer2_W[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_reset_layer2_U[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_reset_layer2_bias[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; + +float gru_htilda_layer2_W[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_htilda_layer2_U[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_INPUTDIM]; +float gru_htilda_layer2_bias[WEIGHT_LAYER2_INPUTDIM][WEIGHT_LAYER2_OUTPUTDIM]; + +float topk_layer2_W[WEIGHT_LAYER2_INPUTDIM][1]; + +// final classfication layer weights + +float mlp_layer1_weight[77][244]; +float mlp_layer1_bias[77]; +float mlp_layer2_weight[2][77]; +float mlp_layer2_bias[2]; + + +float f_edge_list[NUM_EDGE * 2]; +float f_edge_list_time[TIME_STEP][NUM_EDGE * 2]; + +float edge_val[NUM_EDGE]; +float edge_val_time[TIME_STEP][NUM_EDGE]; + +char info_file_edge_list[1000]; +char info_file_edge_val[1000]; + +float node_embedding_list[NUM_NODE][2]; +float node_embedding_list_time[TIME_STEP][NUM_NODE][2]; + +float node_embedding_val[NUM_NODE]; +float node_embedding_val_time[TIME_STEP][NUM_NODE]; + + + +char info_file_node_embeddings_list[1000]; +char info_file_node_embedding_val[1000]; + +//float node_embedding[NUM_NODE][WEIGHT_LAYER1_INPUTDIM]; +float node_embedding_time[TIME_STEP][NUM_NODE][WEIGHT_LAYER1_INPUTDIM]; + + +FM_TYPE node_embedding_time_fixed[NUM_NODE * INPUTDIM]; + + + +float num_edges[TOTAL_TIME + 1]; +int num_edges_time[TIME_STEP]; +int num_nodes_time[TIME_STEP]; + +int node_out_degree[NUM_NODE]; +int node_out_degree_time[TIME_STEP][NUM_NODE]; + + +float node_embedding_subgraph[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +float edge_embedding_subgraph[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; + +int degree_table[SUB_GRAPH_NODE_NUM * 3]; +int neighbor_table[SUB_GRAPH_NODE_NUM * MAX_DEGREE * 2]; +int neighborhood_ref_table[NUM_NODE]; + +FM_TYPE node_embedding_fixed_output[SUB_GRAPH_NODE_NUM * INPUTDIM]; + + +std::vector node_record_vector; +std::vector node_record_vector_previous; +std::vector node_record_vector_new; + + +WT_TYPE node_embedding_in[SUB_GRAPH_NODE_NUM * INPUTDIM]; +WT_TYPE edge_embedding_in[SUB_GRAPH_EDGE_NUM * INPUTDIM]; + + + + +FM_TYPE node_embedding_table[SUB_GRAPH_NODE_NUM][INPUTDIM]; +FM_TYPE edge_embedding_table[SUB_GRAPH_EDGE_NUM][INPUTDIM]; +FM_TYPE cell_table[SUB_GRAPH_NODE_NUM][OUTPUTDIM]; + + +WT_TYPE output_table[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER2_OUTPUTDIM]; +//int edge_list[SUB_GRAPH_EDGE_NUM * 2]; + + +WT_TYPE gnn_update_weight_W[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_update_weight_U[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_update_weight_bias[OUTPUTDIM]; + +WT_TYPE gnn_reset_weight_W[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_reset_weight_U[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_reset_weight_bias[OUTPUTDIM]; + + +WT_TYPE gnn_htilda_weight_W[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_htilda_weight_U[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_htilda_weight_bias[OUTPUTDIM]; + +WT_TYPE gnn_output_weight_W[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_output_weight_U[INPUTDIM][OUTPUTDIM]; +WT_TYPE gnn_output_weight_bias[OUTPUTDIM]; + + + +WT_TYPE gnn_update_weight_W_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_update_weight_U_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_update_weight_bias_fixed[OUTPUTDIM]; + +WT_TYPE gnn_reset_weight_W_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_reset_weight_U_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_reset_weight_bias_fixed[OUTPUTDIM]; + +WT_TYPE gnn_htilda_weight_W_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_htilda_weight_U_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_htilda_weight_bias_fixed[OUTPUTDIM]; + + +WT_TYPE gnn_output_weight_W_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_output_weight_U_fixed[INPUTDIM * OUTPUTDIM]; +WT_TYPE gnn_output_weight_bias_fixed[OUTPUTDIM]; + + +float edge_embedding_subgraph_time[TIME_STEP][SUB_GRAPH_EDGE_NUM][INPUTDIM]; +float node_embedding_subgraph_time[TIME_STEP][SUB_GRAPH_NODE_NUM][INPUTDIM]; +int neighborhood_ref_table_time[TIME_STEP][NUM_NODE]; + +int neighborhood_inverse_ref_table_time[TIME_STEP][NUM_NODE]; +int edge_list_time[TIME_STEP][SUB_GRAPH_EDGE_NUM * 2]; + + +FM_TYPE node_embedding_table_1[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE edge_embedding_table_1[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE node_embedding_table_2[SUB_GRAPH_NODE_NUM][WEIGHT_LAYER1_INPUTDIM]; +FM_TYPE edge_embedding_table_2[SUB_GRAPH_EDGE_NUM][WEIGHT_LAYER1_INPUTDIM]; + +int origin_node_index_time[TIME_STEP][SUB_GRAPH_NODE_NUM]; +int origin_node_index_time_old[TIME_STEP][SUB_GRAPH_NODE_NUM]; +std::vector origin_node_index_time_vector; +std::vector origin_node_index_time_old_vector; + +std::vector old_node_on_chip_position_vector; +std::vector replace_node_on_chip_position_vector; + + +std::vector valid_node_position; +std::vector invalid_node_position; +int old_node_on_chip_position[TIME_STEP][SUB_GRAPH_NODE_NUM]; +int replace_node_on_chip_position[TIME_STEP][SUB_GRAPH_NODE_NUM]; + +int origin_node_index_time_fixed[TIME_STEP * SUB_GRAPH_NODE_NUM]; + +int old_node_num[TIME_STEP]; +int new_node_num[TIME_STEP]; + +int mask[TIME_STEP][SUB_GRAPH_NODE_NUM]; + +int load_list[TIME_STEP][SUB_GRAPH_NODE_NUM]; +int store_list[TIME_STEP][SUB_GRAPH_NODE_NUM]; +int valid_list[TIME_STEP][SUB_GRAPH_NODE_NUM]; + +int load_list_size[TIME_STEP]; +int store_list_size[TIME_STEP]; +int valid_list_size[TIME_STEP]; +std::vector load_vector; +std::vector store_vector; +std::vector valid_vector; + +std::vector new_node_index_vector; + +FM_TYPE node_embedding_table_temp[SUB_GRAPH_NODE_NUM][INPUTDIM]; +FM_TYPE cell_state_table_temp[SUB_GRAPH_NODE_NUM][OUTPUTDIM]; + +//FM_TYPE cell_table_fixed[NUM_NODE * OUTPUTDIM]; + + +void load_weights_convLSTM() +{ + + printf("Loading weights for evolveGCN (RNN + GCN)...\n"); + + FILE* f; + f = fopen("convLSTM.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_update_W, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_update_U, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_update_bias, sizeof(float), OUTPUTDIM, f); + number_count += OUTPUTDIM; + + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_reset_W, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_reset_U, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_reset_bias, sizeof(float), OUTPUTDIM, f); + number_count += OUTPUTDIM; + + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_htilda_W, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_htilda_U, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_htilda_bias, sizeof(float), OUTPUTDIM, f); + number_count += OUTPUTDIM; + + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_output_W, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_output_U, sizeof(float), INPUTDIM * OUTPUTDIM, f); + number_count += INPUTDIM * OUTPUTDIM; + + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(rnn_output_bias, sizeof(float), OUTPUTDIM, f); + number_count += OUTPUTDIM; + + + + +} + +void load_node_embedding() { + FILE* f; + f = fopen("node_embedding.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(node_embedding, sizeof(float), NUM_NODE * INPUTDIM, f); + number_count += NUM_NODE * INPUTDIM; + + +} + + +void load_edge_embedding() { + FILE* f; + f = fopen("edge_embedding.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(edge_embedding, sizeof(float), NUM_EDGE * INPUTDIM, f); + number_count += NUM_EDGE * INPUTDIM; + + + +} + +void load_edge_info() { + FILE* f; + f = fopen("edge_info.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(edge_info_temp, sizeof(float), 103464, f); + number_count += 103464; + for (int i = 0; i < 103464; i++) { + edge_info[i] = (int)edge_info_temp[i]; + } + +} + +void load_edge_num() { + FILE* f; + f = fopen("edge_num.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(edge_num_temp, sizeof(float), TOTAL_TIME, f); + number_count += TOTAL_TIME; + for (int i = 0; i < TOTAL_TIME; i++) { + edge_num[i] = (int)edge_num_temp[i]; + } + +} + +void load_node_num() { + FILE* f; + f = fopen("node_num.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(node_num_temp, sizeof(float), TOTAL_TIME, f); + number_count += TOTAL_TIME; + for (int i = 0; i < TOTAL_TIME; i++) { + node_num[i] = (int)node_num_temp[i]; + } + +} + +void load_renumbering_table() { + FILE* f; + f = fopen("neighborhood_ref_table.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(neighborhood_renumbering_table_temp, sizeof(float), TOTAL_TIME * NUM_NODE, f); + number_count += TOTAL_TIME * NUM_NODE; + for (int i = 0; i < TOTAL_TIME; i++) { + for (int j = 0; j < NUM_NODE; j++) { + neighborhood_renumbering_table[i][j] = (int)neighborhood_renumbering_table_temp[i][j]; + + } + + } + + + +} + + +void load_reverse_renumbering_table() { + FILE* f; + f = fopen("neighborhood_reverse_ref_table.bin", "rb"); + int number_count = 0; + fseek(f, number_count * sizeof(float), SEEK_SET); + fread(neighborhood_reverse_renumbering_table_temp, sizeof(float), TOTAL_TIME * 578, f); + number_count += TOTAL_TIME * 578; + for (int i = 0; i < TOTAL_TIME; i++) { + for (int j = 0; j < 578; j++) { + neighborhood_reverse_renumbering_table[i][j] = (int)neighborhood_reverse_renumbering_table_temp[i][j]; + + } + + } + +} + +void process_info(int time) { + int total = 0; + for (int i = 0; i < time ; i++) { + total = total + 2 * edge_num[i]; + } + for (int i = 0; i < edge_num[time]; i++) { + edge_list[ 2 * i] = edge_info[total + 2 * i]; + edge_list[2 * i + 1] = edge_info[total + 2 * i + 1]; + + } + + + + + +} + + + +void convert_weights_to_fix() { //the weight input layer 1 is 67. the weight output layer 1 is 122 (GNN); the weight input layer 2 is 122, the weight output of layer 2 is 122 (RNN�� + + + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_update_weight_W_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_update_W[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_update_weight_U_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_update_U[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_reset_weight_W_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_reset_W[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_reset_weight_U_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_reset_U[dim_in][dim_out]; + + } + } + + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_htilda_weight_W_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_htilda_W[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_htilda_weight_U_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_htilda_U[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_output_weight_W_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_output_W[dim_in][dim_out]; + + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_output_weight_U_fixed[dim_in * OUTPUTDIM + dim_out] = (WT_TYPE)rnn_output_U[dim_in][dim_out]; + + } + } + + + + + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_update_weight_bias_fixed[dim_out] = (WT_TYPE)rnn_update_bias[dim_out]; + + } + + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_reset_weight_bias_fixed[dim_out] = (WT_TYPE)rnn_reset_bias[dim_out]; + + } + + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_htilda_weight_bias_fixed[dim_out] = (WT_TYPE)rnn_htilda_bias[dim_out]; + + } + + + + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_output_weight_bias_fixed[dim_out] = (WT_TYPE)rnn_output_bias[dim_out]; + + } + + + + + + printf("Convert weights to fix finished ...\n"); +} + + +void convert_embedding_to_fix() { + + for (int nd = 0; nd < NUM_NODE; nd++) { + for (int dim = 0; dim < INPUTDIM; dim++) { + cell_table_fixed[nd * INPUTDIM + dim] = (FM_TYPE)cell_state[nd][dim]; + node_embedding_fixed[nd * INPUTDIM + dim] = (FM_TYPE)node_embedding[nd][dim]; + } + } +} + +void convert_edge_embedding_to_fix(int time) { + int total = 0; + for (int i = 0; i < time; i++) { + total = total + edge_num[i]; + } + + for (int i = 0; i < edge_num[time]; i++) { + for (int dim = 0; dim < INPUTDIM; dim++) { + edge_embedding_fixed[i * INPUTDIM + dim] = (FM_TYPE)edge_embedding[total + i][dim]; + } + + + } + + + +} + + +/// + +//weights are stored in on-chip buffers +void load_weights( // this function check has passed. + + WT_TYPE gnn_update_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_update_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_reset_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_reset_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_htilda_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_htilda_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_output_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_output_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_update_weight_bias_fixed[OUTPUTDIM], + WT_TYPE gnn_reset_weight_bias_fixed[OUTPUTDIM], + WT_TYPE gnn_htilda_weight_bias_fixed[OUTPUTDIM], + WT_TYPE gnn_output_weight_bias_fixed[OUTPUTDIM] +) { +#pragma HLS inline off + + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_update_weight_W[dim_in][dim_out] = gnn_update_weight_W_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_update_weight_U[dim_in][dim_out] = gnn_update_weight_U_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_reset_weight_W[dim_in][dim_out] = gnn_reset_weight_W_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_reset_weight_U[dim_in][dim_out] = gnn_reset_weight_U_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_htilda_weight_W[dim_in][dim_out] = gnn_htilda_weight_W_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_htilda_weight_U[dim_in][dim_out] = gnn_htilda_weight_U_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_output_weight_W[dim_in][dim_out] = gnn_output_weight_W_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_output_weight_U[dim_in][dim_out] = gnn_output_weight_U_fixed[dim_in * OUTPUTDIM + dim_out]; + } + } + + + + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_update_weight_bias[dim_out] = gnn_update_weight_bias_fixed[dim_out]; + } + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_reset_weight_bias[dim_out] = gnn_reset_weight_bias_fixed[dim_out]; + } + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_htilda_weight_bias[dim_out] = gnn_htilda_weight_bias_fixed[dim_out]; + } + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + gnn_output_weight_bias[dim_out] = gnn_output_weight_bias_fixed[dim_out]; + + } + + + +} + + +void load_graph_new( //This function has been checked. + FM_TYPE node_embedding_in[NUM_NODE * INPUTDIM], + FM_TYPE cell_state_in[NUM_NODE * OUTPUTDIM], + FM_TYPE edge_attr_in[SUB_GRAPH_EDGE_NUM * INPUTDIM], + FM_TYPE node_embedding_table[SUB_GRAPH_NODE_NUM][INPUTDIM], + FM_TYPE cell_table[SUB_GRAPH_NODE_NUM][INPUTDIM], + FM_TYPE edge_embedding_table[SUB_GRAPH_EDGE_NUM][INPUTDIM], + int num_of_nodes, + int num_of_edges, + int time, + int neighborhood_inverse_ref_table_time[578]) +{ + +#pragma HLS inline off + + //first adjust the node_embedding_table + for (int i = 0; i < num_of_nodes; i++) { + for (int dim = 0; dim < INPUTDIM; dim++) { + + int location_off_chip = neighborhood_inverse_ref_table_time[i]; + node_embedding_table[i][dim] = node_embedding_in[location_off_chip * INPUTDIM + dim]; + } + } + + + + + for (int i = 0; i < num_of_nodes; i++) { + for (int dim = 0; dim < OUTPUTDIM; dim++) { + int location_off_chip = neighborhood_inverse_ref_table_time[i]; + cell_table[i][dim] = cell_state_in[location_off_chip * OUTPUTDIM + dim]; + } + } + + + + + for (int e = 0; e < num_of_edges; e++) { + for (int dim = 0; dim < INPUTDIM; dim++) { + edge_embedding_table[e][dim] = edge_attr_in[ e * INPUTDIM + dim]; + } + } + + + +} + + +void prepare_degree_neighbor_table_new(int edge_list[SUB_GRAPH_EDGE_NUM * 2], + int num_of_nodes, int num_of_edges, int time, + int neighborhood_ref_table[NUM_NODE]) // this function has been ckecked by C++ (but not python) +{ +#pragma HLS inline off + + + + for (int n = 0; n < num_of_nodes * 3; n++) { + degree_table[n] = 0; + } + + for (int e = 0; e < num_of_edges; e++) { + int u = neighborhood_ref_table[edge_list[e * 2]]; // source node id in the on-chip buffer. + + int v = neighborhood_ref_table[edge_list[e * 2 + 1]]; // target node id in the on-chip buffer. + + degree_table[u * 3] += 1; //the format of degree table: [ total_neighbrhood_number | start_idx_for_neigh_table | offset_idx_for_neigh_table ] + } + + + for (int n = 1; n < num_of_nodes; n++) { + + degree_table[n * 3 + 1] = degree_table[(n - 1) * 3] * 2 + degree_table[(n - 1) * 3 + 1]; // *2: one is for the neighbor node id; the next one is for the corresponding edge id + }// this for loop is used to define the start idx = past node start idx + past node degree *2 ( for neighbor_idx and edge_index) + + for (int e = 0; e < num_of_edges; e++) { +#pragma HLS inline off + int u = neighborhood_ref_table[edge_list[e * 2]]; // source node id in the on-chip buffer. + int v = neighborhood_ref_table[edge_list[e * 2 + 1]]; // target node id in the on-chip buffer. + + int total_neigh = degree_table[u * 3]; + int start_idx = degree_table[u * 3 + 1]; + int offset_idx = degree_table[u * 3 + 2]; + + neighbor_table[start_idx + offset_idx] = v; + //printf("the number of v is:%d\n", v); + //printf("the number of e is:%d\n", e); + //printf("the number of index is:%d\n", start_idx + offset_idx + 1); + neighbor_table[start_idx + offset_idx + 1] = e; + degree_table[u * 3 + 2] += 2; + } + + +} + + +void message_passing_one_node_vec(hls::stream& emb_val_1, + hls::stream& emb_val_2, + hls::stream& emb_val_3, + hls::stream& emb_val_4, + hls::stream& emb_val_5, + hls::stream& emb_val_6, + hls::stream& emb_val_7, + hls::stream& emb_val_8, + hls::stream& cell_state, + int num_of_nodes, int num_of_edges, + FM_TYPE message_tb[SUB_GRAPH_NODE_NUM][INPUTDIM], + FM_TYPE edge_attr[SUB_GRAPH_EDGE_NUM][INPUTDIM], + FM_TYPE cell_table[SUB_GRAPH_NODE_NUM][INPUTDIM], + int time) // This function has been checked. +{ + +#pragma HLS inline off +#pragma HLS array_partition variable=message_tb dim=2 complete +#pragma HLS array_partition variable=edge_attr dim=2 complete + + for (int nd = 0; nd < num_of_nodes; nd++) { + int u = nd; // u is the source node position on chip + int total_neigh = degree_table[u * 3]; // we need a degree table 1. neighborhood number, start index in the neighbor table. + int start_idx = degree_table[u * 3 + 1]; + + FM_TYPE norm[160]; + FM_TYPE node_embedding_vec[INPUTDIM]; + FM_TYPE msg = 0; //this is used to store message for one edge + for (int i = 0; i < 160; i++) { + norm[i] = 0; + } + + for (int i = 0; i < INPUTDIM; i++) { + node_embedding_vec[i] = 0; + } + + //total_neigh = 20; + for (int i = 0; i < total_neigh; i++) { + int v = neighbor_table[start_idx + i * 2]; // v is the neighborhood node index + //printf("the number of v is :%d\n", v); + int e = neighbor_table[start_idx + i * 2 + 1];// e is the edge index + norm[i] = (1.0 / sqrt(degree_table[u * 3] + 1)) * (1.0 / sqrt(degree_table[v * 3] + 1)); + + for (int dim = 0; dim < INPUTDIM; dim++) { + //msg = norm[i] * (node_embedding_vec[dim] + edge_attr[dim]); //for each node, we need to load an edge embedding table on chip +#pragma HLS pipeline II = 1 + msg = norm[i] * (edge_attr[e][dim] + message_tb[v][dim]); //? + node_embedding_vec[dim] += msg; + } + } + + + for (int dim = 0; dim < INPUTDIM; dim++) { +#pragma HLS pipeline II = 1 + FM_TYPE temp = (1.0 / (degree_table[u * 3] + 1.0)); + node_embedding_vec[dim] += message_tb[u][dim] * temp; + //printf("the value of node_embed is:%.6f\n", (float)node_embedding_vec[dim]); + + emb_val_1.write(node_embedding_vec[dim]); + emb_val_2.write(node_embedding_vec[dim]); + emb_val_3.write(node_embedding_vec[dim]); + emb_val_4.write(node_embedding_vec[dim]); + emb_val_5.write(node_embedding_vec[dim]); + emb_val_6.write(node_embedding_vec[dim]); + emb_val_7.write(node_embedding_vec[dim]); + emb_val_8.write(node_embedding_vec[dim]); + //i++; + //printf("the number of emb_val is:%.3f\n", (float)emb_val.read()); + //printf("the total number of value in the stream is:%d\n", i); + + } + + for (int dim = 0; dim < INPUTDIM; dim++) { + cell_state.write(cell_table[u][dim]); + } + + + + } + +} + +void CONV_GNN_sigmoid(hls::stream& emb_input_W, + hls::stream& emb_input_U, + hls::stream& emb_output, + WT_TYPE convs_weight_W[INPUTDIM][OUTPUTDIM], + WT_TYPE convs_weight_U[INPUTDIM][OUTPUTDIM], + WT_TYPE convs_bias[OUTPUTDIM], + int num_of_nodes, int num_of_edges) +{ // This function has been checked. +#pragma HLS array_partition variable=convs_weight_W dim=1 complete +#pragma HLS array_partition variable=convs_weight_U dim=1 complete + //#pragma HLS array_partition variable=convs_bias dim=1 complete + + + //linear, x = self.linear(x) + for (int nd = 0; nd < num_of_nodes; nd++) { + FM_TYPE node_emb_input_W[INPUTDIM]; + FM_TYPE node_emb_input_U[INPUTDIM]; + FM_TYPE node_emb_output[OUTPUTDIM]; + //#pragma HLS array_partition variable=node_emb_output dim=1 complete +#pragma HLS array_partition variable=node_emb_input_W dim=1 complete +#pragma HLS array_partition variable=node_emb_input_U dim=1 complete + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + + node_emb_input_W[dim_in] = emb_input_W.read(); + + node_emb_input_U[dim_in] = emb_input_U.read(); + } + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { +#pragma HLS PIPELINE II = 1 + + + node_emb_output[dim_out] = convs_bias[dim_out]; + FM_TYPE tmp = 0; + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + + tmp += node_emb_input_W[dim_in] * convs_weight_W[dim_in][dim_out] + node_emb_input_U[dim_in] * convs_weight_U[dim_in][dim_out]; + } + node_emb_output[dim_out] += tmp; + node_emb_output[dim_out] = 1.0 / (1.0 + expf(-node_emb_output[dim_out])); + //printf("the value of output is:%.6f\n", (float)node_emb_output[dim_out]); + emb_output.write(node_emb_output[dim_out]); + + } + + } +} + + +void CONV_GNN_tanh(hls::stream& emb_input_W, + hls::stream& emb_input_U, + hls::stream& emb_output, + WT_TYPE convs_weight_W[INPUTDIM][OUTPUTDIM], + WT_TYPE convs_weight_U[INPUTDIM][OUTPUTDIM], + WT_TYPE convs_bias[OUTPUTDIM], + int num_of_nodes, int num_of_edges) +{ +#pragma HLS array_partition variable=convs_weight_W dim=1 complete +#pragma HLS array_partition variable=convs_weight_U dim=1 complete + //#pragma HLS array_partition variable=convs_bias dim=1 complete + + + //linear, x = self.linear(x) + for (int nd = 0; nd < num_of_nodes; nd++) { + FM_TYPE node_emb_input_W[INPUTDIM]; + FM_TYPE node_emb_input_U[INPUTDIM]; + FM_TYPE node_emb_output[OUTPUTDIM]; + //#pragma HLS array_partition variable=node_emb_output dim=1 complete +#pragma HLS array_partition variable=node_emb_input_W dim=1 complete +#pragma HLS array_partition variable=node_emb_input_U dim=1 complete + + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + + node_emb_input_W[dim_in] = emb_input_W.read(); + + node_emb_input_U[dim_in] = emb_input_U.read(); + } + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { +#pragma HLS PIPELINE II = 1 + + //node_emb_output[dim_out] = convs_bias[dim_out]; + node_emb_output[dim_out] = convs_bias[dim_out]; + FM_TYPE tmp = 0; + for (int dim_in = 0; dim_in < INPUTDIM; dim_in++) { + + tmp += node_emb_input_W[dim_in] * convs_weight_W[dim_in][dim_out] + node_emb_input_U[dim_in] * convs_weight_U[dim_in][dim_out]; + } + node_emb_output[dim_out] += tmp; + + + node_emb_output[dim_out] = (expf(node_emb_output[dim_out]) - expf(-node_emb_output[dim_out])) / (expf(node_emb_output[dim_out]) + expf(-node_emb_output[dim_out])); + //printf("the value of output is:%.6f\n", (float)node_emb_output[dim_out]); + emb_output.write(node_emb_output[dim_out]); + } + + } +} + + + +void LSTM_multi_1(hls::stream& update_output, + hls::stream& cell_input, + hls::stream& reset_output, + hls::stream& htilda_output, + hls::stream& cell_output_temp, + hls::stream& cell_output, + int num_of_nodes, int num_of_edges) { // This function has been checked. + + for (int nd = 0; nd < num_of_nodes; nd++) { + FM_TYPE update_output_vector[OUTPUTDIM]; + FM_TYPE cell_input_vector[OUTPUTDIM]; + FM_TYPE reset_output_vector[OUTPUTDIM]; + FM_TYPE htilda_output_vector[OUTPUTDIM]; + FM_TYPE cell_output_vector[OUTPUTDIM]; +#pragma HLS array_partition variable=update_output_vector dim=1 complete +#pragma HLS array_partition variable=cell_input_vector dim=1 complete +#pragma HLS array_partition variable=reset_output_vector dim=1 complete +#pragma HLS array_partition variable=htilda_output_vector dim=1 complete +#pragma HLS array_partition variable=cell_output_vector dim=1 complete + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + update_output_vector[dim_out] = update_output.read(); + cell_input_vector[dim_out] = cell_input.read(); + reset_output_vector[dim_out] = reset_output.read(); + htilda_output_vector[dim_out] = htilda_output.read(); + } + + + GRU_multi_1_loop: for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + #pragma HLS pipeline II = 1 + cell_output_vector[dim_out] = update_output_vector[dim_out] * cell_input_vector[dim_out] + reset_output_vector[dim_out] * htilda_output_vector[dim_out]; + //htilda_output.write(htilda_output_vector[dim_out]); + } + + GRU_multi_1_wrtie_loop: for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + cell_output_temp.write(cell_output_vector[dim_out]); + cell_output.write(cell_output_vector[dim_out]); + + } + } + +} + + + +void LSTM_multi_2(hls::stream& output_output, + hls::stream& cell_input, + hls::stream& rnn_output, + int num_of_nodes, int num_of_edges) { // This function has been checked. + + for (int nd = 0; nd < num_of_nodes; nd++) { + FM_TYPE output_output_vector[OUTPUTDIM]; + FM_TYPE cell_input_vector[OUTPUTDIM]; + FM_TYPE rnn_output_vector[OUTPUTDIM]; + +#pragma HLS array_partition variable=output_output_vector dim=1 complete +#pragma HLS array_partition variable=cell_input_vector dim=1 complete +#pragma HLS array_partition variable=rnn_output_vector dim=1 complete + + + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + output_output_vector[dim_out] = output_output.read(); + cell_input_vector[dim_out] = cell_input.read(); + + } + + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { +#pragma HLS pipeline II = 1 + rnn_output_vector[dim_out] = (expf(cell_input_vector[dim_out]) - expf(-cell_input_vector[dim_out])) / (expf(cell_input_vector[dim_out]) + expf(-cell_input_vector[dim_out])); + rnn_output_vector[dim_out] = rnn_output_vector[dim_out] * output_output_vector[dim_out]; + + } + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + rnn_output.write(rnn_output_vector[dim_out]); + //printf("the value is:%.6f\n", (float)rnn_output_vector[dim_out]); + } + } + +} + + +void write_back(hls::stream& rnn_output, + hls::stream& cell_output, + int num_of_nodes, int time, WT_TYPE node_embedding_fixed_output[NUM_NODE * INPUTDIM], + WT_TYPE cell_state_fixed_output[NUM_NODE * OUTPUTDIM], + int neighborhood_inverse_ref_table_time[578] + + ) { +#pragma HLS inline off + for (int nd = 0; nd < num_of_nodes; nd++) { + FM_TYPE rnn_output_vector[OUTPUTDIM]; + FM_TYPE cell_output_vector[OUTPUTDIM]; + + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + rnn_output_vector[dim_out] = rnn_output.read(); + cell_output_vector[dim_out] = cell_output.read(); + + node_embedding_table_temp[nd][dim_out] = rnn_output_vector[dim_out]; + cell_state_table_temp[nd][dim_out] = cell_output_vector[dim_out]; + } + + } + for (int i = 0; i < num_of_nodes; i++) { + for (int dim_out = 0; dim_out < OUTPUTDIM; dim_out++) { + node_embedding_fixed_output[neighborhood_inverse_ref_table_time[i] * OUTPUTDIM + dim_out] = node_embedding_table_temp[i][dim_out]; + cell_state_fixed_output[neighborhood_inverse_ref_table_time[i] * OUTPUTDIM + dim_out] = cell_state_table_temp[i][dim_out]; + } + + } + + +} + + + + + + +void dataflow_region( + WT_TYPE node_embedding_output[NUM_NODE * INPUTDIM], + WT_TYPE cell_state[NUM_NODE * OUTPUTDIM], + FM_TYPE node_embedding_table[SUB_GRAPH_NODE_NUM][INPUTDIM], + FM_TYPE cell_table[SUB_GRAPH_NODE_NUM][INPUTDIM], + FM_TYPE edge_embedding_table[SUB_GRAPH_NODE_NUM][INPUTDIM], + int neighborhood_inverse_ref_table_time[578], + + WT_TYPE gnn_update_weight_W[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_update_weight_U[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_reset_weight_W[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_reset_weight_U[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_htilda_weight_W[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_htilda_weight_U[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_output_weight_W[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_output_weight_U[INPUTDIM][OUTPUTDIM], + WT_TYPE gnn_update_weight_bias[OUTPUTDIM], + WT_TYPE gnn_reset_weight_bias[OUTPUTDIM], + WT_TYPE gnn_htilda_weight_bias[OUTPUTDIM], + WT_TYPE gnn_output_weight_bias[OUTPUTDIM], + + + + int node_number_time, + int edge_number_time, + int time + + +) +{ + + hls::stream message_passing_fifo_1; + hls::stream message_passing_fifo_2; + hls::stream message_passing_fifo_3; + hls::stream message_passing_fifo_4; + hls::stream message_passing_fifo_5; + hls::stream message_passing_fifo_6; + hls::stream message_passing_fifo_7; + hls::stream message_passing_fifo_8; + + hls::stream update_output_fifo; + //hls::stream update_output_fifo_U; + hls::stream reset_output_fifo; + + hls::stream output_output_fifo; + //hls::stream reset_output_fifo_U; + hls::stream htilda_output_temp_fifo; + //hls::stream htilda_output_temp_fifo_U; + + hls::stream htilda_output_fifo; + + hls::stream cell_state_fifo; + + hls::stream cell_output_temp_fifo; + hls::stream cell_output_fifo; + //hls::stream htilda_output_fifo_U; + + hls::stream rnn_output_fifo; +#pragma HLS STREAM variable=message_passing_fifo_1 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_2 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_3 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_4 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_5 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_6 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_7 depth=400 +#pragma HLS STREAM variable=message_passing_fifo_8 depth=400 + + +#pragma HLS STREAM variable=update_output_fifo depth=400 + //#pragma HLS STREAM variable=update_output_fifo_U depth=400 +#pragma HLS STREAM variable=reset_output_fifo depth=400 + +#pragma HLS STREAM variable=output_output_fifo depth=400 +//#pragma HLS STREAM variable=reset_output_fifo_U depth=400 +//#pragma HLS STREAM variable=htilda_output_temp_fifo depth=400 +#pragma HLS STREAM variable=htilda_output_fifo depth=400 + +#pragma HLS STREAM variable=cell_state_fifo depth=400 +#pragma HLS STREAM variable=cell_output_temp_fifo depth=400 +#pragma HLS STREAM variable=cell_output_fifo depth=400 + +#pragma HLS STREAM variable=rnn_output_fifo depth=400 +//#pragma HLS STREAM variable=htilda_output_fifo_U depth=400 + + + +#pragma HLS dataflow + + + message_passing_one_node_vec(message_passing_fifo_1, message_passing_fifo_2, message_passing_fifo_3, message_passing_fifo_4, message_passing_fifo_5, message_passing_fifo_6, message_passing_fifo_7, message_passing_fifo_8, cell_state_fifo, node_number_time, edge_number_time, node_embedding_table, edge_embedding_table, cell_table, time); + + CONV_GNN_sigmoid(message_passing_fifo_1, message_passing_fifo_2, update_output_fifo, gnn_update_weight_W, gnn_update_weight_U, gnn_update_weight_bias, node_number_time, edge_number_time); + CONV_GNN_sigmoid(message_passing_fifo_3, message_passing_fifo_4, reset_output_fifo, gnn_reset_weight_W, gnn_reset_weight_U, gnn_reset_weight_bias, node_number_time, edge_number_time); + CONV_GNN_sigmoid(message_passing_fifo_5, message_passing_fifo_6, output_output_fifo, gnn_output_weight_W, gnn_output_weight_U, gnn_output_weight_bias, node_number_time, edge_number_time); + CONV_GNN_tanh(message_passing_fifo_7, message_passing_fifo_8, htilda_output_fifo, gnn_htilda_weight_W, gnn_htilda_weight_U, gnn_htilda_weight_bias, node_number_time, edge_number_time); + LSTM_multi_1(update_output_fifo, cell_state_fifo, reset_output_fifo, htilda_output_fifo, cell_output_temp_fifo, cell_output_fifo, node_number_time, edge_number_time); + LSTM_multi_2(output_output_fifo, cell_output_temp_fifo, rnn_output_fifo, node_number_time, edge_number_time); + write_back(rnn_output_fifo, cell_output_fifo, node_number_time, time, node_embedding_output, cell_state, neighborhood_inverse_ref_table_time); +} + + + + + + + +void DGNN_Booster_convLSTM( + int edge_list_in[SUB_GRAPH_EDGE_NUM * 2], + int node_number_time[192], // need to change from 137 to 192 for bitcoin dataset + int edge_number_time[192], + + + WT_TYPE gnn_update_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_update_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_update_weight_bias_fixed[OUTPUTDIM], + + + WT_TYPE gnn_reset_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_reset_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_reset_weight_bias_fixed[OUTPUTDIM], + + + WT_TYPE gnn_htilda_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_htilda_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_htilda_weight_bias_fixed[OUTPUTDIM], + + WT_TYPE gnn_output_weight_W_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_output_weight_U_fixed[INPUTDIM * OUTPUTDIM], + WT_TYPE gnn_output_weight_bias_fixed[OUTPUTDIM], + + + FM_TYPE node_embedding_fixed[NUM_NODE * INPUTDIM], // need to change to NUM-NODE + FM_TYPE cell_table_fixed[NUM_NODE * INPUTDIM], + FM_TYPE edge_attr_in_fixed[SUB_GRAPH_EDGE_NUM * INPUTDIM], + + + int neighborhood_ref_table_time[NUM_NODE], //need to change to NUM_NODE + int neighborhood_inverse_ref_table_time[578], // need to change from 501 -> 578 + int time[100] + +) +{ +#pragma HLS INTERFACE s_axilite port=return + +#pragma HLS INTERFACE m_axi depth=100000 port=edge_list_in offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=node_number_time offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=edge_number_time offset=slave bundle=INPUT + + +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_update_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_update_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_update_weight_bias_fixed offset=slave bundle=INPUT + + +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_reset_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_reset_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_reset_weight_bias_fixed offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_htilda_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_htilda_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_htilda_weight_bias_fixed offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_output_weight_W_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_output_weight_U_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=gnn_output_weight_bias_fixed offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=100000 port=node_embedding_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=cell_table_fixed offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=100000 port=edge_attr_in_fixed offset=slave bundle=INPUT + + +#pragma HLS INTERFACE m_axi depth=100000 port=neighborhood_ref_table_time offset=slave bundle=INPUT2 +#pragma HLS INTERFACE m_axi depth=100000 port=neighborhood_inverse_ref_table_time offset=slave bundle=INPUT2 +#pragma HLS INTERFACE m_axi depth=100000 port=time offset=slave bundle=INPUT2 + + +#pragma HLS bind_storage variable=gnn_update_weight_W impl = bram +#pragma HLS bind_storage variable=gnn_update_weight_U impl = bram +#pragma HLS bind_storage variable=gnn_update_weight_bias impl = bram +#pragma HLS bind_storage variable=gnn_reset_weight_W impl = bram +#pragma HLS bind_storage variable=gnn_reset_weight_U impl = bram +#pragma HLS bind_storage variable=gnn_reset_weight_bias impl = bram +#pragma HLS bind_storage variable=gnn_htilda_weight_W impl = bram +#pragma HLS bind_storage variable=gnn_htilda_weight_U impl = bram +#pragma HLS bind_storage variable=gnn_htilda_weight_bias impl = bram +#pragma HLS bind_storage variable=gnn_output_weight_W impl = bram +#pragma HLS bind_storage variable=gnn_output_weight_U impl = bram +#pragma HLS bind_storage variable=gnn_output_weight_bias impl = bram + +#pragma HLS bind_storage variable=node_embedding_table impl = bram +#pragma HLS bind_storage variable=edge_embedding_table impl = bram +#pragma HLS bind_storage variable=node_embedding_table_temp impl = bram +#pragma HLS bind_storage variable=cell_state_table_temp impl = bram + + if (time[0] == 0) { + load_weights(gnn_update_weight_W_fixed, gnn_update_weight_U_fixed, gnn_reset_weight_W_fixed, gnn_reset_weight_U_fixed, gnn_htilda_weight_W_fixed, gnn_htilda_weight_U_fixed, gnn_output_weight_W_fixed, gnn_output_weight_U_fixed, gnn_update_weight_bias_fixed, gnn_reset_weight_bias_fixed, gnn_htilda_weight_bias_fixed, gnn_output_weight_bias_fixed); + + } + + int node_number = node_number_time[time[0]]; + int edge_number = edge_number_time[time[0]]; + load_graph_new(node_embedding_fixed, cell_table_fixed, edge_attr_in_fixed, node_embedding_table, cell_table, edge_embedding_table, node_number, edge_number, time[0], neighborhood_inverse_ref_table_time); + + prepare_degree_neighbor_table_new(edge_list_in, node_number, edge_number, time[0], neighborhood_ref_table_time); + //compute_workflow(edge_list_in, edge_list, edge_attr_in_fixed, cell_table_fixed, node_embedding_fixed, gnn_update_weight_W, gnn_update_weight_U, gnn_update_weight_bias, gnn_reset_weight_W, gnn_reset_weight_U, gnn_reset_weight_bias, gnn_htilda_weight_W, gnn_htilda_weight_U, gnn_htilda_weight_bias, gnn_output_weight_W, gnn_output_weight_U, gnn_output_weight_bias, node_number_time, edge_number_time, valid_list, store_list, store_list_size); + dataflow_region(node_embedding_fixed, cell_table_fixed, node_embedding_table, cell_table, edge_embedding_table, neighborhood_inverse_ref_table_time, gnn_update_weight_W, gnn_update_weight_U, gnn_reset_weight_W, gnn_reset_weight_U, gnn_htilda_weight_W, gnn_htilda_weight_U, gnn_output_weight_W, gnn_output_weight_U, gnn_update_weight_bias, gnn_reset_weight_bias, gnn_htilda_weight_bias, gnn_output_weight_bias, node_number, edge_number, time[0]); + +} + + + +int main() { + + load_weights_convLSTM(); + load_node_embedding(); + load_edge_embedding(); + load_edge_num(); + load_node_num(); + load_edge_info(); + load_renumbering_table(); + load_reverse_renumbering_table(); + + //initialize cell_state to 0 + for (int nd = 0; nd < NUM_NODE; nd++) { + for (int dim = 0; dim < INPUTDIM; dim++) { + cell_state[nd][dim] = 0; + } + } + + convert_weights_to_fix(); + convert_embedding_to_fix(); + + //process_info(0);//load edge list + //convert_edge_embedding_to_fix(0); + + int total_time = 2; + int time_array[100]; + for (int time = 0; time < total_time; time++) { + //printf("the time now is:%d\n", time); + process_info(time);//load edge list + convert_edge_embedding_to_fix(time); + time_array[0] = time; + DGNN_Booster_convLSTM(edge_list, node_num, edge_num, gnn_update_weight_W_fixed, gnn_update_weight_U_fixed, gnn_update_weight_bias_fixed, gnn_reset_weight_W_fixed, gnn_reset_weight_U_fixed, gnn_reset_weight_bias_fixed, gnn_htilda_weight_W_fixed, gnn_htilda_weight_U_fixed, gnn_htilda_weight_bias_fixed, gnn_output_weight_W_fixed, gnn_output_weight_U_fixed, gnn_output_weight_bias_fixed, node_embedding_fixed, cell_table_fixed, edge_embedding_fixed, neighborhood_renumbering_table[time], neighborhood_reverse_renumbering_table[time], time_array); + } + + + for (int nd = 0; nd < 5; nd++) { + for (int dim = 0; dim < 67; dim++) { + printf("the value is:%.6f\n", (float)cell_table_fixed[nd * 67 + dim]); + printf("the value is:%.6f\n", (float)node_embedding_fixed[nd * 67 + dim]); + } + } + + +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_fixed_dataset/src/GP_kernel_100_10_success_fixed.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_fixed_dataset/src/GP_kernel_100_10_success_fixed.cpp new file mode 100644 index 000000000000..875e69fbab5b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_fixed_dataset/src/GP_kernel_100_10_success_fixed.cpp @@ -0,0 +1,1812 @@ +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include "hls_stream.h" +#include "hls_math.h" + +#include +#include + +#include + + + +// #define N 128 //The number of clients +// #define C 10 //The number of clients to be selected +// #define SORT_NUM 32 + +// #define N_CLIENT 72 + +// #define BUFFER_SIZE 64 +// #define UNROLL_FACTOR 16 + +#define N 104 //The number of clients +#define C 10 //The number of clients to be selected +#define SORT_NUM 32 + +#define N_CLIENT 100 + +#define BUFFER_SIZE 13 +#define UNROLL_FACTOR 13 + +#define SCALE 5 + + + +//typedef float DATA_TYPE; +//typedef float Key_Type; +typedef ap_fixed<32,16> DATA_TYPE; +typedef ap_fixed<32,16> Key_Type; +typedef struct { + Key_Type number; + int index; +} Data_Sort; + +// define some on-chip buffers + +DATA_TYPE mu[N]; +DATA_TYPE sigma[BUFFER_SIZE][BUFFER_SIZE]; +DATA_TYPE a[N]; +DATA_TYPE beta[N]; +DATA_TYPE sigma_1d[N]; + + + +DATA_TYPE mu_bar_accumu[N]; +bool client_selection_flag[N_CLIENT]; +DATA_TYPE sigma_12_22_multiply[N_CLIENT][C]; // sigma_12 * sigma_22_inverse [N - m * m] +DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N_CLIENT]; // [N - m * N - M] + +DATA_TYPE delta_l[N]; + +//DATA_TYPE sigma_11[N][N - 1][N - 1]; +//DATA_TYPE sigma_12[N][N]; // The actual size is N * (N - 1) +//DATA_TYPE sigma_21[N][N - 1]; +DATA_TYPE sigma_12[BUFFER_SIZE][N]; +DATA_TYPE sigma_22[N]; +//DATA_TYPE mu_1[N][N]; // The actual size is N * (N - 1) +DATA_TYPE mu_1[BUFFER_SIZE][N]; +DATA_TYPE mu_2[N]; +DATA_TYPE mu_bar[BUFFER_SIZE][N]; + +Data_Sort sort_client_list[N_CLIENT]; +//Data_Sort input_sort[SORT_NUM]; +Data_Sort output_sort[SORT_NUM]; +DATA_TYPE mu_bar_sorted_data[N]; +int mu_bar_sorted_index[N]; + +int selected_client_index_table[C]; +int non_selected_client_index_table[N_CLIENT]; + +DATA_TYPE sigma_11_select[BUFFER_SIZE][N_CLIENT]; +DATA_TYPE sigma_12_select[N_CLIENT][C]; +DATA_TYPE sigma_21_select[C][N_CLIENT]; +DATA_TYPE sigma_22_select[C][C]; +DATA_TYPE sigma_22_select_inverse[C][C]; +DATA_TYPE sigma_updated[BUFFER_SIZE][N_CLIENT]; + +DATA_TYPE alpha_mu_2_selected[C]; +DATA_TYPE sigma_mu_multiply[N_CLIENT]; +DATA_TYPE mu_1_select[N]; +DATA_TYPE mu_updated[N_CLIENT]; + +//bool client_selection_flag[N]; + +void load_parameters(DATA_TYPE mu_dram[N], DATA_TYPE a_dram[N], DATA_TYPE beta_dram[N] ) +{ + for (int i = 0; i < N; i++) + { +#pragma HLS pipeline II=1 + mu[i] = mu_dram[i]; + + a[i] = a_dram[i]; + + beta[i] = beta_dram[i]; + } + +} + +void load_sigma_1d(DATA_TYPE sigma_dram[N][N]) +{ + for (int i = 0; i < N ;i++) + { +#pragma HLS pipeline II=1 + sigma_1d[i] = sigma_dram[i][i]; + } +} + + +void on_chip_buffer_initialization(DATA_TYPE mu_bar_accumu[N], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + for (int client_index = 0; client_index < N; client_index++) + { +#pragma HLS pipeline II=1 + mu_bar_accumu[client_index] = 0; + //client_selection_flag[client_index] = 0; //initialization, 0 means non client is selected. + } + + for (int i = 0; i < C;i++) + { +#pragma HLS pipeline II=1 + selected_client_index_table[i] = 0; + } + + for (int i = 0; i < N_CLIENT; i++) + { +#pragma HLS pipeline II=1 + non_selected_client_index_table[i] = 0; + } + +} + +void compute_delta_l_kernel(DATA_TYPE mu[N], DATA_TYPE sigma_1d[N], DATA_TYPE a[N], DATA_TYPE beta[N], DATA_TYPE delta_l[N], int index) +{ + +DATA_TYPE mu_buffer[UNROLL_FACTOR]; +DATA_TYPE sigma_buffer[UNROLL_FACTOR]; +DATA_TYPE a_buffer[UNROLL_FACTOR]; +DATA_TYPE beta_buffer[UNROLL_FACTOR]; +DATA_TYPE delta_l_buffer[UNROLL_FACTOR]; + +#pragma HLS ARRAY_PARTITION variable=a_buffer complete dim=1 +#pragma HLS ARRAY_PARTITION variable=beta_buffer complete dim=1 +#pragma HLS ARRAY_PARTITION variable=mu_buffer complete dim=1 +#pragma HLS ARRAY_PARTITION variable=sigma_buffer complete dim=1 +#pragma HLS inline off + +for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) +{ +#pragma HLS pipeline II = 1 + mu_buffer[client_index] = mu[UNROLL_FACTOR * index + client_index]; + a_buffer[client_index] = a[UNROLL_FACTOR * index + client_index]; + beta_buffer[client_index] = beta[UNROLL_FACTOR * index + client_index]; + sigma_buffer[client_index] = sigma_1d[UNROLL_FACTOR * index + client_index]; +} + +//#pragma HLS ARRAY_PARTITION variable=temp complete dim=1 + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + //partition to get mu_1 +#pragma HLS unroll + delta_l_buffer[client_index] = a_buffer[client_index] * beta_buffer[client_index]; + delta_l_buffer[client_index] = mu_buffer[client_index] - delta_l_buffer[client_index] * hls::sqrt(hls::abs(sigma_buffer[client_index])); + + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { +#pragma HLS pipeline II = 1 + delta_l[UNROLL_FACTOR * index + client_index] = delta_l_buffer[client_index]; + } +} + + +void compute_delta_l(DATA_TYPE mu[N], DATA_TYPE sigma_1d[N], DATA_TYPE a[N], DATA_TYPE beta[N], DATA_TYPE delta_l[N]) +{ + +#pragma HLS inline off + + for (int index = 0; index < N/UNROLL_FACTOR; index++) + { + compute_delta_l_kernel(mu, sigma_1d, a, beta, delta_l, index); + } +} + +void mu_sigma_selection(DATA_TYPE mu[N], DATA_TYPE sigma_dram[N][N], DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_1d[N], DATA_TYPE sigma_22[N], int selection_index) + +{ +// The actual size of mu_1 is N * (N - 1) +// The actual size of sigma_12 is N * (N -1) + +#pragma HLS inline off + + for (int client_index = 0; client_index < BUFFER_SIZE; client_index++) + { + for (int i = 0; i < BUFFER_SIZE * selection_index + client_index ; i++) + { + #pragma HLS pipeline II = 1 + mu_1[client_index][i] = mu[i]; + } + + for (int i = BUFFER_SIZE * selection_index + client_index + 1; i < N; i++) + { + #pragma HLS pipeline II = 1 + mu_1[ client_index][i - 1] = mu[i]; + } + + mu_1[client_index][N - 1] = (DATA_TYPE) 0.0; + //partition to get mu_2 + mu_2[BUFFER_SIZE * selection_index + client_index] = mu[BUFFER_SIZE * selection_index + client_index]; + + //partition to get sigma_12 + for (int i = 0; i < BUFFER_SIZE * selection_index + client_index; i++) + { + #pragma HLS pipeline II = 1 + sigma_12[ client_index][i] = sigma_dram[i][0]; + } + + for (int i = BUFFER_SIZE * selection_index + client_index + 1; i < N; i++) + { + #pragma HLS pipeline II = 1 + sigma_12[ client_index][i - 1] = sigma_dram[i][0]; + } + sigma_12[client_index][N -1] = (DATA_TYPE) 0.0; + + //partiton to get sigma_22 + + //sigma_22[client_index] = (DATA_TYPE) 1.0/sigma[client_index][client_index]; + } + + for (int client_index = 0; client_index < N_CLIENT; client_index++) + { + #pragma HLS pipeline II = 1 + sigma_22[client_index] = (DATA_TYPE) 1.0/sigma_1d[client_index]; + } + for (int client_index = N_CLIENT; client_index < N; client_index++) + { + #pragma HLS pipeline II = 1 + sigma_22[client_index] = (DATA_TYPE) 0.0; + + } + + // for (int client_index = 0; client_index < N_CLIENT; client_index++) + // { + // #pragma HLS pipeline II = 1 + // //sigma_22[BUFFER_SIZE * selection_index + client_index] = (DATA_TYPE) 1.0/sigma_1d[BUFFER_SIZE * selection_index + client_index]; + // sigma_22[client_index] + + // } + +} + +void mu_bar_accumulator(DATA_TYPE mu_bar[BUFFER_SIZE][N], DATA_TYPE mu_bar_accumu[N], int index, int index_outside) +{ + + DATA_TYPE mu_bar_accumu_buffer[UNROLL_FACTOR]; + DATA_TYPE mu_bar_buffer[UNROLL_FACTOR][N - 1]; + #pragma HLS ARRAY_PARTITION variable=mu_bar_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_bar_accumu_buffer complete dim=1 + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + mu_bar_accumu_buffer[client_index] = 0; + for (int i = 0; i < N - 1; i++) + { + #pragma HLS pipeline II = 1 + mu_bar_buffer[client_index][i] = mu_bar[UNROLL_FACTOR * index + client_index][i]; + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + #pragma HLS unroll + + for (int i = 0; i < N - 1; i++) + { + #pragma HLS pipeline II = 1 + //#pragma HLS unroll + mu_bar_accumu_buffer[client_index] = mu_bar_accumu_buffer[client_index] + mu_bar_buffer[client_index][i]; + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + #pragma HLS pipeline II = 1 + mu_bar_accumu[BUFFER_SIZE * index_outside + UNROLL_FACTOR * index + client_index] = mu_bar_accumu_buffer[client_index]; + } + + +} + + +void compute_mu_bar_accumu_kernel(DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_22[N], DATA_TYPE delta_l[N], DATA_TYPE mu_bar[BUFFER_SIZE][N], int index_x, int index_y, int index) +{ + //update the mu_bar + DATA_TYPE mu_1_buffer[UNROLL_FACTOR][UNROLL_FACTOR]; + DATA_TYPE mu_2_buffer[UNROLL_FACTOR]; + DATA_TYPE sigma_12_buffer[UNROLL_FACTOR][UNROLL_FACTOR]; + DATA_TYPE sigma_22_buffer[UNROLL_FACTOR]; + DATA_TYPE delta_l_buffer[UNROLL_FACTOR]; + DATA_TYPE mu_bar_buffer[UNROLL_FACTOR][UNROLL_FACTOR]; + //DATA_TYPE mu_bar_accumu_buffer[UNROLL_FACTOR]; + + #pragma HLS ARRAY_PARTITION variable=mu_1_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_1_buffer complete dim=2 + #pragma HLS ARRAY_PARTITION variable=mu_2_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=sigma_12_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=sigma_12_buffer complete dim=2 + #pragma HLS ARRAY_PARTITION variable=sigma_22_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=delta_l_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_bar_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_bar_buffer complete dim=2 + //#pragma HLS ARRAY_PARTITION variable=mu_bar_accumu_buffer complete dim=1 + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + sigma_22_buffer[client_index] = sigma_22[BUFFER_SIZE * index + UNROLL_FACTOR * index_x + client_index]; + delta_l_buffer[client_index] = delta_l[BUFFER_SIZE * index + UNROLL_FACTOR * index_x + client_index]; + mu_2_buffer[client_index] = mu_2[BUFFER_SIZE * index + UNROLL_FACTOR * index_x + client_index]; + for (int i = 0; i < UNROLL_FACTOR; i++) + { + mu_1_buffer[client_index][i] = mu_1[ UNROLL_FACTOR * index_x + client_index][ UNROLL_FACTOR * index_y + i]; + sigma_12_buffer[client_index][i] = sigma_12[ UNROLL_FACTOR * index_x + client_index][UNROLL_FACTOR * index_y + i]; + + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + #pragma HLS unroll + for (int i = 0; i < UNROLL_FACTOR; i++) + { + #pragma HLS unroll + mu_bar_buffer[client_index][i] = mu_1_buffer[client_index][i] + sigma_12_buffer[client_index][i] * sigma_22_buffer[client_index] * (delta_l_buffer[client_index] - mu_2_buffer[client_index]); + + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + for (int i = 0; i < UNROLL_FACTOR; i++) + { + #pragma HLS pipeline II = 1 + mu_bar[UNROLL_FACTOR * index_x + client_index][UNROLL_FACTOR * index_y + i] = mu_bar_buffer[client_index][i]; + } + + } + +} + + + + +void compute_mu_bar_accumu(DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_22[N], DATA_TYPE delta_l[N], DATA_TYPE mu_bar[BUFFER_SIZE][N], DATA_TYPE mu_bar_accumu[N], int index_outside) +{ + //update the mu_bar + + // The actual size of the mu_bar is N * (N -1) + + for (int index_x = 0; index_x < BUFFER_SIZE/UNROLL_FACTOR; index_x++) + { + for (int index_y = 0; index_y < N/UNROLL_FACTOR; index_y++) + { + compute_mu_bar_accumu_kernel(mu_1, mu_2, sigma_12, sigma_22, delta_l, mu_bar, index_x, index_y, index_outside); + } + mu_bar_accumulator(mu_bar, mu_bar_accumu, index_x, index_outside); + } +} + +void compute_mu_ba_scale(DATA_TYPE mu[N], DATA_TYPE sigma_dram[N][N], DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_1d[N], DATA_TYPE sigma_22[N]) +{ + for (int index_outside = 0; index_outside < N/BUFFER_SIZE; index_outside++) + { + mu_sigma_selection(mu, sigma_dram, mu_1, mu_2, sigma_12, sigma_1d, sigma_22, index_outside); + compute_mu_bar_accumu(mu_1, mu_2, sigma_12, sigma_22, delta_l, mu_bar, mu_bar_accumu, index_outside); + } +} + +Data_Sort sorting_kernel_2 (Data_Sort input_1, Data_Sort input_2) +{ +//#pragma HLS inline off + if (input_1.number < input_2.number) + { + return input_1; + } + else + { + return input_2; + } + +} + +Data_Sort sorting_kernel_4(Data_Sort input [4]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp[2]; + #pragma HLS ARRAY_PARTITION variable=out_temp complete dim=1 + for (int i = 0; i < 2; i++) + { + #pragma HLS unroll + + out_temp[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + return sorting_kernel_2(out_temp[0], out_temp[1]); + +} + +Data_Sort sorting_kernel_8(Data_Sort input[8]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp complete dim=1 + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + return sorting_kernel_4(out_temp); +} + + + +Data_Sort sorting_kernnel_16 (Data_Sort input[16]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp_1[8]; + #pragma HLS ARRAY_PARTITION variable=out_temp_1 complete dim=1 + Data_Sort out_temp_2[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp_2 complete dim=1 + + for (int i = 0; i < 8; i++) + { + #pragma HLS unroll + + out_temp_1[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp_2[i] = sorting_kernel_2(out_temp_1[2 * i], out_temp_1[2 * i + 1]); + } + + + return sorting_kernel_4(out_temp_2); +} + +Data_Sort sorting_kernel_32 (Data_Sort input[32]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp_1[16]; + #pragma HLS ARRAY_PARTITION variable=out_temp_1 complete dim=1 + Data_Sort out_temp_2[8]; + #pragma HLS ARRAY_PARTITION variable=out_temp_2 complete dim=1 + Data_Sort out_temp_3[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp_3 complete dim=1 + + for (int i = 0; i < 16; i++) + { + #pragma HLS unroll + + out_temp_1[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + for (int i = 0; i < 8; i++) + { + #pragma HLS unroll + + out_temp_2[i] = sorting_kernel_2(out_temp_1[2 * i], out_temp_1[2 * i + 1]); + } + + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp_3[i] = sorting_kernel_2(out_temp_2[2 * i], out_temp_2[2 * i + 1]); + } + + return sorting_kernel_4(out_temp_3); +} + + +Data_Sort sorting_kernel_64 (Data_Sort input[64]) + +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp_1[32]; + #pragma HLS ARRAY_PARTITION variable=out_temp_1 complete dim=1 + Data_Sort out_temp_2[16]; + #pragma HLS ARRAY_PARTITION variable=out_temp_2 complete dim=1 + Data_Sort out_temp_3[8]; + #pragma HLS ARRAY_PARTITION variable=out_temp_3 complete dim=1 + Data_Sort out_temp_4[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp_4 complete dim=1 + + for (int i = 0; i < 32; i++) + { + #pragma HLS unroll + + out_temp_1[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + for (int i = 0; i < 16; i++) + { + #pragma HLS unroll + + out_temp_2[i] = sorting_kernel_2(out_temp_1[2 * i], out_temp_1[2 * i + 1]); + } + + for (int i = 0; i < 8; i++) + { + #pragma HLS unroll + + out_temp_3[i] = sorting_kernel_2(out_temp_2[2 * i], out_temp_2[2 * i + 1]); + } + + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp_4[i] = sorting_kernel_2(out_temp_3[2 * i], out_temp_3[2 * i + 1]); + } + + return sorting_kernel_4(out_temp_4); + +} + +Data_Sort sorting_kernel(Data_Sort sort_input[SORT_NUM]) + +{ + Data_Sort sort_output; + DATA_TYPE sort_output_number; + DATA_TYPE sort_output_index; + #pragma HLS ARRAY_PARTITION variable=sort_input complete dim=1 +#pragma HLS inline off + + if (SORT_NUM == 64) + { + sort_output = sorting_kernel_64(sort_input); + } + + if (SORT_NUM == 32) + { + sort_output = sorting_kernel_32(sort_input); + } + + if (SORT_NUM == 16) + { + sort_output = sorting_kernnel_16(sort_input); + } + + if (SORT_NUM == 8) + { + sort_output = sorting_kernel_8(sort_input); + } + + if (SORT_NUM == 4) + { + sort_output = sorting_kernel_4(sort_input); + } + + if (SORT_NUM == 2) + { + sort_output = sorting_kernel_2(sort_input[0], sort_input[1]); + } + + + return sort_output; + +} + +int sorting(DATA_TYPE mu_bar_accumu[N], bool client_selection_flag[N_CLIENT], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + Data_Sort input_sort[SORT_NUM]; + #pragma HLS ARRAY_PARTITION variable=input_sort complete dim=1 + int selected_sorting_client_num = 0; + Data_Sort sort_output_result; + Data_Sort output_sort_buffer[SORT_NUM]; + #pragma HLS ARRAY_PARTITION variable=output_sort_buffer complete dim=1 + for (int i = 0; i < N_CLIENT; i++) + { + #pragma HLS pipeline II = 1 + if (client_selection_flag[i] == 0) + { + sort_client_list[selected_sorting_client_num].number = mu_bar_accumu[i]; + sort_client_list[selected_sorting_client_num].index = i; + selected_sorting_client_num++; + } + + } + + if (selected_sorting_client_num > SORT_NUM) + { + + int iteration_num = selected_sorting_client_num/SORT_NUM; + int iter_counter = 0; + for (int iter = 0; iter < iteration_num; iter++) + { + for (int i = 0; i < SORT_NUM; i++) + { + #pragma HLS pipeline II = 1 + input_sort[i] = sort_client_list[iter * SORT_NUM + i]; + } + output_sort_buffer[iter] = sorting_kernel(input_sort); + iter_counter = iter_counter + 1; + } + int bound = selected_sorting_client_num - (iter_counter * SORT_NUM); + + for (int i = 0; i < bound; i++) + { + #pragma HLS pipeline II = 1 + input_sort[i] = sort_client_list[iter_counter * SORT_NUM + i]; + } + + for (int i = bound; i < SORT_NUM; i++) + { + #pragma HLS pipeline II = 1 + input_sort[i].number = 9999; + input_sort[i].index = 9999; + } + + output_sort_buffer[iter_counter] = sorting_kernel(input_sort); + iter_counter = iter_counter + 1; + + for (int i = iter_counter; i < SORT_NUM; i++) + { + output_sort_buffer[i].number = 9999; + output_sort_buffer[i].index = 9999; + } + + + sort_output_result = sorting_kernel(output_sort_buffer); + + } + + else + { + for (int i = 0; i < selected_sorting_client_num; i++) + { + input_sort[i] = sort_client_list[i]; + } + + for (int i = selected_sorting_client_num; i < SORT_NUM; i++) + { + input_sort[i].number = 9999; + input_sort[i].index = 9999; + } + + sort_output_result = sorting_kernel(input_sort); + + } + + int select_client_index = sort_output_result.index; + + client_selection_flag[select_client_index] = 1; + + + int client_selected_num = 0; + int client_not_selected_num = 0; + // calculate the total number of clients selected. + for (int i = 0; i < N_CLIENT; i++) + { + #pragma HLS pipeline II = 1 + if (client_selection_flag[i] == 1) + { + selected_client_index_table[client_selected_num] = i; + client_selected_num = client_selected_num + 1; + + } + + else + { + non_selected_client_index_table[client_not_selected_num] = i; + client_not_selected_num = client_not_selected_num + 1; + } + + + } + + return client_selected_num; + +} + + +// void sorting_kernel(DATA_TYPE mu_bar_accumu[SORT_NUM], DATA_TYPE mu_bar_sorted_data[SORT_NUM], int mu_bar_sorted_index[N]) + +// { +// // get the accumulation for each client of the mu_bar +// bool order = 1; +// //generate the sorting information + +// #pragma HLS aggregate variable=input_sort +// #pragma HLS aggregate variable=output_sort +// // #pragma HLS ARRAY_PARTITION variable=input_sort complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=output_sort complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=mu_bar_accumu complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=mu_bar_sorted_data complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=mu_bar_sorted_index complete dim=1 + +// #pragma HLS inline off + +// for (int i = 0; i < SORT_NUM; i++) +// { +// #pragma HLS pipeline II = 1 +// input_sort[i].number = mu_bar_accumu[SORT_NUM * index + i]; +// input_sort[i].index = SORT_NUM * index + i; +// } +// // for (int i = 0; i < N; i++) +// // { +// // #pragma HLS pipeline II = 1 +// // input_sort[i].number = mu_bar_accumu[i]; +// // input_sort[i].index = i; +// // } + +// // for (int i = N ; i < SORT_NUM; i++) +// // { +// // #pragma HLS pipeline II = 1 +// // input_sort[i].number = 9999; +// // input_sort[i].index = i; + +// // } +// hls::stream kin_strm; +// hls::stream kin_strm_end; +// hls::stream kout_strm; +// hls::stream kout_strm_end; +// #pragma HLS STREAM variable=kin_strm depth=SORT_NUM +// #pragma HLS STREAM variable=kin_strm_end depth=SORT_NUM + 1 +// #pragma HLS STREAM variable=kout_strm depth=SORT_NUM +// #pragma HLS STREAM variable=kout_strm_end depth=SORT_NUM + 1 + +// load_data(input_sort, kin_strm, kin_strm_end, SORT_NUM); +// bitonic_sort_top(kin_strm, kin_strm_end, kout_strm, kout_strm_end, order); +// store_data(output_sort, kout_strm, kout_strm_end, SORT_NUM); + +// for (int i = 0; i < SORT_NUM; i++) +// { +// #pragma HLS pipeline II = 1 +// mu_bar_sorted_data[SORT_NUM * index + i] = output_sort[i].number; +// mu_bar_sorted_index[SORT_NUM * index + i] = output_sort[i].index; +// } +// // for (int i = 0; i < N; i++) +// // { +// // //#pragma HLS unroll +// // mu_bar_sorted_data[i] = output_sort[i].number; +// // mu_bar_sorted_index[i] = output_sort[i].index; +// // } + +// } + +// int select_client(bool client_selection_flag[N], int selected_client_index_table[C], int non_selected_client_index_table[N]) +// { +// // if we want to select the client with the minimum value, then select mu_bar_sorted_index[0] +// #pragma HLS inline off +// for (int i = 0; i < N; i++) +// { +// #pragma HLS pipeline II = 1 +// if (client_selection_flag[mu_bar_sorted_index[i]] == 0) +// { +// client_selection_flag[mu_bar_sorted_index[i]] = 1; +// break; +// } +// } + + +// int client_selected_num = 0; +// int client_not_selected_num = 0; +// // calculate the total number of clients selected. +// for (int i = 0; i < N; i++) +// { +// #pragma HLS pipeline II = 1 +// if (client_selection_flag[i] == 1) +// { +// selected_client_index_table[client_selected_num] = i; +// client_selected_num = client_selected_num + 1; + +// } + +// else +// { +// non_selected_client_index_table[client_not_selected_num] = i; +// client_not_selected_num = client_not_selected_num + 1; +// } + + +// } + +// return client_selected_num; +// } + +void sigma_selection_new(int client_selected_num, DATA_TYPE sigma_dram[N][N], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT] ) +{ + +// #pragma HLS ARRAY_PARTITION variable=sigma complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_22_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_22_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=selected_client_index_table complete dim=1 +#pragma HLS inline off + for (int i = 0; i < client_selected_num; i++) + { + for (int j = 0; j < client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_22_select[i][j] = sigma_dram[selected_client_index_table[i]][selected_client_index_table[j]]; + } + } + + for (int i = 0; i < client_selected_num; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_21_select[i][j] = sigma_dram[selected_client_index_table[i]][non_selected_client_index_table[j]]; + } + } + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + + for (int j = 0; j < client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_12_select[i][j] = sigma_dram[non_selected_client_index_table[i]][selected_client_index_table[j]]; + } + } + + // for (int i = 0; i < N - client_selected_num; i++) + // { + // for (int j = 0; j < N - client_selected_num; j++) + // { + // #pragma HLS pipeline II = 1 + // sigma_11_select[i][j] = sigma[non_selected_client_index_table[i]][non_selected_client_index_table[j]]; + // } + // } +} + + +void sigma_11_selection_new(int client_selected_num, DATA_TYPE sigma_dram[N][N], int index_outside, int total_iter_num, int remaining_iteration) +{ + if (index_outside != total_iter_num - 1) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_11_select[i][j] = sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]]; + } + } + + } + + else + + { + for (int i = 0; i < remaining_iteration; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_11_select[i][j] = sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]]; + } + } + } + + + +} + + + + +// void sigma_selection(int client_selected_num, DATA_TYPE sigma[N][N], bool client_selection_flag[N]) +// { +// int sigma_22_select_dim_i = client_selected_num; +// int sigma_22_select_dim_j = client_selected_num; // the dimension of sigma_22 is [m * m] +// int sigma_21_select_dim_i = client_selected_num; +// int sigma_21_select_dim_j = N - client_selected_num; // the dimension of sigma_21 is [m * N -m] +// int sigma_12_select_dim_i = N - client_selected_num; +// int sigma_12_select_dim_j = client_selected_num; // the dimension of sigma_12 is [N - m * m] +// int sigma_11_select_dim_i = N - client_selected_num; +// int sigma_11_select_dim_j = N - client_selected_num; // the dimension of sigma_11 is [N - m * N - m] + +// int sigma_22_select_dim_i_counter = 0; +// int sigma_22_select_dim_j_counter = 0; +// int sigma_21_select_dim_i_counter = 0; +// int sigma_21_select_dim_j_counter = 0; +// int sigma_12_select_dim_i_counter = 0; +// int sigma_12_select_dim_j_counter = 0; +// int sigma_11_select_dim_i_counter = 0; +// int sigma_11_select_dim_j_counter = 0; + +// // generate the sigma matrixs. +// for (int i = 0; i < N; i++) +// { +// #pragma HLS unroll +// for (int j = 0; j < N ;j++) +// { +// #pragma HLS unroll +// if (client_selection_flag[i] == 1 & client_selection_flag[j] == 1) +// { +// sigma_22_select[sigma_22_select_dim_i_counter][sigma_22_select_dim_j_counter] = sigma[i][j]; +// sigma_22_select_dim_j_counter++; +// if (sigma_22_select_dim_j_counter == sigma_22_select_dim_j) +// { +// sigma_22_select_dim_j_counter = 0; +// sigma_22_select_dim_i_counter++; +// } +// } +// else if (client_selection_flag[i] == 1 & client_selection_flag[j] == 0) +// { +// sigma_21_select[sigma_21_select_dim_i_counter][sigma_21_select_dim_j_counter] = sigma[i][j]; +// sigma_21_select_dim_j_counter++; +// if (sigma_21_select_dim_j_counter == sigma_21_select_dim_j) +// { +// sigma_21_select_dim_j_counter = 0; +// sigma_21_select_dim_i_counter++; +// } +// } +// else if (client_selection_flag[i] == 0 & client_selection_flag[j] == 1) +// { +// sigma_12_select[sigma_12_select_dim_i_counter][sigma_12_select_dim_j_counter] = sigma[i][j]; +// sigma_12_select_dim_j_counter++; +// if (sigma_12_select_dim_j_counter == sigma_12_select_dim_j) +// { +// sigma_12_select_dim_j_counter = 0; +// sigma_12_select_dim_i_counter++; +// } +// } +// else if (client_selection_flag[i] == 0 & client_selection_flag[j] == 0) +// { +// sigma_11_select[sigma_11_select_dim_i_counter][sigma_11_select_dim_j_counter] = sigma[i][j]; +// sigma_11_select_dim_j_counter++; +// if (sigma_11_select_dim_j_counter == sigma_11_select_dim_j) +// { +// sigma_11_select_dim_j_counter = 0; +// sigma_11_select_dim_i_counter++; +// } +// } +// } +// } +// } + +// int inverseMatrix(DATA_TYPE mat[C][C], DATA_TYPE inv[C][C], int matrix_dim) { + +// #pragma HLS inline off +// #pragma HLS ARRAY_PARTITION variable=mat complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=mat complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=inv complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=inv complete dim=2 + +// DATA_TYPE temp; + +// //Initialize the inverse matrix as the identity matrix +// for (int i = 0; i < matrix_dim; i++) { +// #pragma HLS unroll +// for (int j = 0; j < matrix_dim; j++) { +// #pragma HLS unroll +// if (i == j) +// inv[i][j] = 1.0; +// else +// inv[i][j] = 0.0; +// } +// } +// // Perform Gauss-Jordan elimination +// for (int i = 0; i < matrix_dim; i++) { +// #pragma HLS unroll +// if (mat[i][i] == 0.0) +// return 0; // Matrix is not invertible + +// // Scale the current row +// temp = mat[i][i]; +// for (int j = 0; j < matrix_dim; j++) { +// //#pragma HLS pipeline II = 1 +// #pragma HLS unroll +// mat[i][j] /= temp; +// inv[i][j] /= temp; +// } + +// // Eliminate other rows +// for (int j = 0; j < matrix_dim; j++) { +// if (i != j) { +// temp = mat[j][i]; +// for (int k1 = 0; k1 < i+ 1; k1++) // k1 < i+1 +// { +// #pragma HLS unroll +// inv[j][k1] -= temp * inv[i][k1]; +// } +// for (int k2 = i; k2 < matrix_dim; k2++) { +// #pragma HLS unroll +// mat[j][k2] -= temp * mat[i][k2]; +// //inv[j][k] -= temp * inv[i][k]; +// } +// } +// } +// } + +// return 1; // Matrix is invertible +// } + + +void inverse_matrix_new(DATA_TYPE mat[C][C], DATA_TYPE inv[C][C], int matrix_dim) +{ + inv[0][0] = (DATA_TYPE) 1.0/mat[0][0]; + DATA_TYPE c_matrix[C]; + DATA_TYPE b_matrix[C]; + for (int iter = 1; iter < matrix_dim; iter++) + { + DATA_TYPE d = mat[iter][iter]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + c_matrix[i] = mat[iter][i]; + b_matrix[i] = mat[i][iter]; + } + + DATA_TYPE c_a_inverse[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + c_a_inverse[i] = 0; + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + c_a_inverse[i] += c_matrix[j] * inv[j][i]; + } + + } + + DATA_TYPE b = 0; + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + b = b + c_a_inverse[i] * b_matrix[i]; + } + + DATA_TYPE t; + + t = (DATA_TYPE)1.0/ (d - b); + + //printf("the value of t is:%f\n", t); + + DATA_TYPE a_inverse_b[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + a_inverse_b[i] = 0; + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + a_inverse_b[i] += inv[i][j] * b_matrix[j]; + } + + } + + DATA_TYPE Y[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + Y[i] = -a_inverse_b[i] * t; + } + + // for (int i = 0; i < 2; i++) + // { + // printf("the value of Y is:%f\n", Y[i]); + // } + + // DATA_TYPE c_a_inverse[C]; + // for (int i = 0; i < iter; i++) + // { + // for (int j = 0; j < iter; j++) + // { + // c_a_inverse[i] += c_matrix[j] * inv[j][i]; + // } + // } + + DATA_TYPE Z[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + Z[i] = -c_a_inverse[i] * t; + } + + // for (int i = 0; i < 2; i++) + // { + // printf("the value of Z is:%f\n", Z[i]); + // } + + + DATA_TYPE BZ[C][C]; + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + BZ[i][j] = b_matrix[i] * Z[j]; + } + } + + DATA_TYPE I_minus_BZ[C][C]; + + for (int i = 0; i < C; i++) + { + for (int j = 0; j < C; j++) + { + #pragma HLS pipeline II = 1 + if (i == j) + { + I_minus_BZ[i][j] = 1; + } + else + { + I_minus_BZ[i][j] = 0; + } + } + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + I_minus_BZ[i][j] = I_minus_BZ[i][j] - BZ[i][j]; + } + } + + DATA_TYPE I_minus_BZ_A_inverse[C][C]; + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + I_minus_BZ_A_inverse[i][j] = 0; + } + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + for (int k = 0; k < iter; k++) + { + #pragma HLS pipeline II = 1 + I_minus_BZ_A_inverse[i][j] += inv[i][k] * I_minus_BZ[k][j]; + } + } + } + + // Theen we need to update the inverse matrix + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + inv[i][j] = I_minus_BZ_A_inverse[i][j]; + } + } + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + inv[i][iter] = Y[i]; + } + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + inv[iter][i] = Z[i]; + } + + inv[iter][iter] = t; + + } + +} + + +void compute_sigma_12_21_multiply(DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N_CLIENT], DATA_TYPE sigma_12_22_multiply[N_CLIENT][C], DATA_TYPE sigma_21_select[C][N_CLIENT], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) +{ + + for (int i = 0; i < BUFFER_SIZE;i++) + { + for (int j = 0; j < N_CLIENT; j++) + { + #pragma HLS pipeline II=1 + sigma_12_21_multiply[i][j] = 0; + } + } + + if (index_outside != iter_total_num -1 ) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + //#pragma HLS pipeline II = 1 + for (int k = 0; k < client_selected_num; k++) + { + #pragma HLS pipeline II = 1 + sigma_12_21_multiply[i][j] += sigma_12_22_multiply[BUFFER_SIZE * index_outside + i][k] * sigma_21_select[k][j]; + } + } + } + } + + else + { + for (int i = 0; i < iter_remaining; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + //#pragma HLS pipeline II = 1 + for (int k = 0; k < client_selected_num; k++) + { + #pragma HLS pipeline II = 1 + sigma_12_21_multiply[i][j] += sigma_12_22_multiply[BUFFER_SIZE * index_outside + i][k] * sigma_21_select[k][j]; + } + } + } + } + +} + +void compute_sigma_updated(DATA_TYPE sigma_11_select[BUFFER_SIZE][N_CLIENT], DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N_CLIENT], DATA_TYPE sigma_updaated[BUFFER_SIZE][N_CLIENT], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) +{ + if (index_outside != iter_total_num - 1) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_updated[i][j] = sigma_11_select[i][j] - sigma_12_21_multiply[i][j]; + } + } + } + + else + + { + for (int i = 0; i < iter_remaining; i++) + { + + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_updated[i][j] = sigma_11_select[i][j] - sigma_12_21_multiply[i][j]; + } + } + } + + +} + +void compute_sigma_12_22_multiply(DATA_TYPE sigma_12_select[N_CLIENT][C], DATA_TYPE sigma_22_select_inverse[C][C], DATA_TYPE sigma_12_22_multiply[N_CLIENT][C], int client_selected_num) +{ + for (int i = 0; i < N_CLIENT;i++) + { + for (int j = 0; j < client_selected_num; j++) + { +#pragma HLS pipeline II=1 + sigma_12_22_multiply[i][j] = 0; + } + } + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + for (int j = 0; j < client_selected_num; j++) + { + //#pragma HLS pipeline II = 1 + for (int k = 0; k < client_selected_num; k++) + { + //#pragma HLS unroll + #pragma HLS pipeline II = 1 + sigma_12_22_multiply[i][j] += sigma_12_select[i][k] * sigma_22_select_inverse[k][j]; + } + } + } +} + +// void compute_sigma_updated(DATA_TYPE sigma_11_select[N][N], DATA_TYPE sigma_12_select[N][C], DATA_TYPE sigma_22_select_inverse[C][C], DATA_TYPE sigma_12_22_multiply[N][C], DATA_TYPE sigma_12_21_multiply[N][N], DATA_TYPE sigma_updated[N][N], int client_selected_num) +// { + +// // #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_22_select_inverse complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_22_select_inverse complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_21_multiply complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_21_multiply complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=2 +// #pragma HLS inline off + +// for (int i = 0; i < N - client_selected_num; i++) +// { +// for (int j = 0; j < client_selected_num; j++) +// { +// //#pragma HLS pipeline II = 1 +// for (int k = 0; k < client_selected_num; k++) +// { +// //#pragma HLS unroll +// #pragma HLS pipeline II = 1 +// sigma_12_22_multiply[i][j] += sigma_12_select[i][k] * sigma_22_select_inverse[k][j]; +// } +// } +// } + +// for (int i = 0; i < N - client_selected_num; i++) +// { +// for (int j = 0; j < N - client_selected_num; j++) +// { +// //#pragma HLS pipeline II = 1 +// for (int k = 0; k < client_selected_num; k++) +// { +// #pragma HLS pipeline II = 1 +// sigma_12_21_multiply[i][j] += sigma_12_22_multiply[i][k] * sigma_21_select[k][j]; +// } +// } +// } + +// for (int i = 0; i < N - client_selected_num; i++) +// { + +// for (int j = 0; j < N - client_selected_num; j++) +// { +// #pragma HLS pipeline II = 1 +// sigma_updated[i][j] = sigma_11_select[i][j] - sigma_12_21_multiply[i][j]; +// } +// } +// } + + + + +void compute_mu_updated (DATA_TYPE mu[N], DATA_TYPE mu_1_select[N_CLIENT], DATA_TYPE mu_2[N], DATA_TYPE delta_l[N], DATA_TYPE mu_updated[N_CLIENT], DATA_TYPE sigma_12_22_multiply[N_CLIENT][C], DATA_TYPE alpha_mu_2_selected[C], int client_selected_num, int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + // #pragma HLS ARRAY_PARTITION variable=mu complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=mu_1_select complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=mu_2 complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=delta_l complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=mu_updated complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=2 + // #pragma HLS ARRAY_PARTITION variable=alpha_mu_2_selected complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=selected_client_index_table complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=non_selected_client_index_table complete dim=1 + #pragma HLS inline off + + + for (int i = 0; i < client_selected_num;i++) + { + #pragma HLS pipeline II = 1 + alpha_mu_2_selected[i] = delta_l[selected_client_index_table[i]] - mu_2[selected_client_index_table[i]]; + } + + // for (int i = 0; i < client_selected_num; i++) + // { + // printf("alpha_mu_2_selected[%d] = %f\n", i, alpha_mu_2_selected[i]); + // } + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + #pragma HLS pipeline II = 1 + mu_1_select[i] = mu[non_selected_client_index_table[i]]; + } + + + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + //#pragma HLS pipeline II = 1 + for (int j = 0; j < client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_mu_multiply[i] = sigma_12_22_multiply[i][j] * alpha_mu_2_selected[j]; + } + } + + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + #pragma HLS pipeline II = 1 + mu_updated[i] = mu_1_select[i] + sigma_mu_multiply[i]; + } + + +} + +void update_sigma(DATA_TYPE sigma_dram[N][N], DATA_TYPE sigma_updated[BUFFER_SIZE][N_CLIENT], int non_selected_client_index_table[N_CLIENT], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) +{ + + if (index_outside != iter_total_num - 1) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + + #pragma HLS pipeline II = 1 + sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]] = sigma_updated[i][j]/SCALE; + } + + } + } + + else + + { + + for (int i = 0; i < iter_remaining; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + + #pragma HLS pipeline II = 1 + sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]] = sigma_updated[i][j]/SCALE; + } + + } + } + +} + + + +void update_sigma_scale(int client_selected_num, DATA_TYPE sigma_dram[N][N], DATA_TYPE sigma_updated[N_CLIENT][N_CLIENT], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + + int total_client_count = N_CLIENT - client_selected_num; + int iter_total_num = total_client_count / BUFFER_SIZE + 1; + int iter_remaining = total_client_count - (iter_total_num - 1) * BUFFER_SIZE; + + //void compute_sigma_12_21_multiply(DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N], DATA_TYPE sigma_12_22_multiply[N][C], DATA_TYPE sigma_21_select[C][C], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) + for (int index_outside = 0; index_outside < iter_total_num; index_outside++) + { + + sigma_11_selection_new(client_selected_num, sigma_dram, index_outside, iter_total_num, iter_remaining); + compute_sigma_12_21_multiply(sigma_12_21_multiply, sigma_12_22_multiply, sigma_21_select, client_selected_num, index_outside, iter_total_num, iter_remaining); + compute_sigma_updated(sigma_11_select, sigma_12_21_multiply, sigma_updated, client_selected_num, index_outside, iter_total_num, iter_remaining); + update_sigma(sigma_dram, sigma_updated, non_selected_client_index_table, client_selected_num, index_outside, iter_total_num, iter_remaining); + } + +} + +// void update_mu_sigma(DATA_TYPE mu[N], DATA_TYPE sigma[N][N], DATA_TYPE mu_updated[N], DATA_TYPE sigma_updated[N][N], int client_selected_num, int non_selected_client_index_table[N]) +// { + +// // #pragma HLS ARRAY_PARTITION variable=mu complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=mu_updated complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=non_selected_client_index_table complete dim=1 +// #pragma HLS inline off + +// for (int i = 0; i < N - client_selected_num; i++) +// { +// #pragma HLS pipeline II = 1 +// mu[non_selected_client_index_table[i]] = mu_updated[i]; +// } + +// for (int i = 0; i < N - client_selected_num; i++) +// { + +// for (int j = 0; j < N - client_selected_num; j++) +// { +// #pragma HLS pipeline II = 1 +// sigma[non_selected_client_index_table[i]][non_selected_client_index_table[j]] = sigma_updated[i][j]; +// } +// } + +// } + +void update_mu(DATA_TYPE mu[N], DATA_TYPE mu_updated[N_CLIENT],int non_selected_client_index_table[N_CLIENT], int client_selected_num ) +{ +#pragma HLS inline off + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + #pragma HLS pipeline II = 1 + mu[non_selected_client_index_table[i]] = mu_updated[i]/SCALE; + } + + +} + +void write_back(DATA_TYPE result[N][N], DATA_TYPE result_dram[N][N]) +{ + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + #pragma HLS pipeline ii = 1 + result_dram[i][j] = result[i][j]; + } + + } +} + +void write_back_mu(DATA_TYPE result[N], DATA_TYPE result_dram[N]) +{ + for (int i = 0; i < N; i++) + { + #pragma HLS pipeline II = 1 + + result_dram[i] = result[i]; + + + } +} + + void write_back_index_table(int client_index_list[C], int selected_client_index_table[C]) +{ + for (int i = 0; i < C; i++) + { + #pragma HLS pipeline II = 1 + client_index_list[i] = selected_client_index_table[i]; + } + + // for (int i = C; i < N; i++) + // { + // client_index_list[i] = 100; + // } +} + + +void client_selection(DATA_TYPE sigma_dram[N][N], DATA_TYPE mu[N], DATA_TYPE a[N], DATA_TYPE beta[N], int client_number) +{ + + for (int i = 0; i < N_CLIENT; i++) + { + #pragma HLS pipeline II = 1 + client_selection_flag[i] = 0; + } + + for (int iter = 0; iter < client_number; iter++) + { + //on_chip_buffer_initialization(mu_bar_accumu, sigma_12_22_multiply, sigma_12_21_multiply, selected_client_index_table, non_selected_client_index_table); + on_chip_buffer_initialization(mu_bar_accumu, selected_client_index_table, non_selected_client_index_table); + load_sigma_1d(sigma_dram); + compute_delta_l(mu, sigma_1d, a, beta, delta_l); + + // for (int i = 0; i < N; i++) + // { + // printf("the current iter is:%d, the value of delta_l is: %f\n", iter, delta_l[i]); + // } + //mu_sigma_selection(mu, sigma, mu_1, mu_2, sigma_12, sigma_22); + //compute_mu_bar_accumu(mu_1, mu_2, sigma_12, sigma_22, delta_l, mu_bar, mu_bar_accumu); + + //void compute_mu_ba_scale(DATA_TYPE mu[N], DATA_TYPE sigma_dram[N][N], DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_1d[N], DATA_TYPE sigma_22[N]) + compute_mu_ba_scale(mu, sigma_dram, mu_1, mu_2, sigma_12, sigma_1d, sigma_22); + //compute_mu_ba_scale(mu, sigma, delta_l, mu_bar_accumu); + //sorting(mu_bar_accumu, mu_bar_sorted_data, mu_bar_sorted_index); + int client_selected_num = 0; + //client_selected_num = select_client(client_selection_flag, selected_client_index_table, non_selected_client_index_table); + //DATA_TYPE mu_bar_accumu[N], bool client_selection_flag[N_CLIENT], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT] + client_selected_num = sorting(mu_bar_accumu, client_selection_flag, selected_client_index_table, non_selected_client_index_table); + // for (int i = 0; i < N; i++) + // { + + // printf("the current iter is: %d, the value of accumu is: %f\n", iter, mu_bar_accumu[i]); + // } + //sigma_selection(client_selected_num, sigma, client_selection_flag); + sigma_selection_new(client_selected_num, sigma_dram, selected_client_index_table, non_selected_client_index_table); + int inverse_flag = 0; + inverse_matrix_new(sigma_22_select, sigma_22_select_inverse, client_selected_num); + + compute_sigma_12_22_multiply(sigma_12_select, sigma_22_select_inverse, sigma_12_22_multiply, client_selected_num); + compute_mu_updated(mu, mu_1_select, mu_2, delta_l, mu_updated, sigma_12_22_multiply, alpha_mu_2_selected, client_selected_num, selected_client_index_table, non_selected_client_index_table); + update_mu(mu, mu_updated, non_selected_client_index_table, client_selected_num); + + + + update_sigma_scale(client_selected_num, sigma_dram, sigma_updated, selected_client_index_table, non_selected_client_index_table); + + + // compute_sigma_updated(sigma_11_select, sigma_12_select, sigma_22_select_inverse, sigma_12_22_multiply, sigma_12_21_multiply, sigma_updated, client_selected_num); + // compute_mu_updated(mu, mu_1_select, mu_2, delta_l, mu_updated, sigma_12_22_multiply, alpha_mu_2_selected, client_selected_num, selected_client_index_table, non_selected_client_index_table); + // update_mu_sigma(mu, sigma, mu_updated, sigma_updated, client_selected_num, non_selected_client_index_table); + + } + +} + + + +void GP_kernel_fixed(DATA_TYPE *mu_dram, DATA_TYPE sigma_dram[N][N], DATA_TYPE *a_dram, DATA_TYPE *beta_dram, int client_number_array[10], int client_index_list[C], DATA_TYPE result_dram[N][N], DATA_TYPE result_dram_2[N]) + +{ + #pragma HLS interface m_axi port=mu_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=sigma_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=a_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=beta_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=client_index_list depth=200 bundle = gmem3 + //#pragma HLS interface s_axilite port=client_number + #pragma HLS interface s_axilite port=return + #pragma HLS interface m_axi port=client_number_array depth=200 bundle = gmem3 + + #pragma HLS interface m_axi port=result_dram depth=200 bundle = gmem2 + #pragma HLS interface m_axi port=result_dram_2 depth=200 bundle = gmem2 + + + int client_number = client_number_array[0]; + load_parameters(mu_dram, a_dram, beta_dram); + client_selection(sigma_dram, mu, a, beta, client_number); + //write_back(sigma, result_dram); + write_back_mu(mu, result_dram_2); + write_back_index_table(client_index_list, selected_client_index_table); + + + +} + + + +//int main() +// +//{ +// +// // Seed the random number generator with the current time +// srand(333); +// +// // Define the size of the array +// int arraySize = N_CLIENT; // Change this to the desired size +// int client_number = C; //The maximum number of clients to be selected. +// +// // Create an array to store the random numbers +// DATA_TYPE mu_dram[N]; +// DATA_TYPE a_dram[N]; +// DATA_TYPE sigma_dram[N][N]; +// DATA_TYPE beta_dram[N]; +// +// int client_index_list[C]; +// +// DATA_TYPE result_dram[N][N]; +// DATA_TYPE result_dram_2[N]; +// +// +// float mu_float[N_CLIENT]; +// float a_float[N_CLIENT]; +// float sigma_float[N_CLIENT][N_CLIENT]; +// float beta_float[N_CLIENT]; +// float result_float[N_CLIENT][N_CLIENT]; +// float result_float_2[N_CLIENT]; +// int client_number_array[10]; +// client_number_array[0] = client_number; +// +// +// +// // Generate random numbers in the range [0, 1) +// for (int i = 0; i < arraySize; i++) { +// mu_float[i] = (float)rand() / RAND_MAX; +// printf("the value of mu_float is: %f\n", mu_float[i]); +// +// } +// +// for (int i = 0; i < arraySize; i++) { +// a_float[i] = (float)rand() / RAND_MAX; +// +// } +// +// for (int i = 0; i < arraySize; i++) { +// beta_float[i] = (float)rand() / RAND_MAX; +// +// } +// +// for (int i = 0; i < arraySize; i++) { +// for (int j = 0; j < arraySize; j++) +// { +// sigma_float[i][j] = (float)rand() / RAND_MAX; +// } +// +// } +// +// for (int i = 0; i < N; i++) +// { +// mu_dram[i] = 0; +// a_dram[i] = 0; +// beta_dram[i] = 0; +// for (int j = 0; j < N; j++) +// { +// sigma_dram[i][j] = 0; +// } +// } +// +// +// for (int i = 0; i < arraySize; i++) +// { +// mu_dram[i] = (DATA_TYPE) mu_float[i]; +// a_dram[i] = (DATA_TYPE) a_float[i]; +// beta_dram[i] = (DATA_TYPE) beta_float[i]; +// for (int j = 0; j < arraySize; j++) +// { +// sigma_dram[i][j] = (DATA_TYPE) sigma_float[i][j]; +// } +// } +// +// +// +// +// GP_kernel(mu_dram, sigma_dram, a_dram, beta_dram, client_number_array, client_index_list, result_dram, result_dram_2); +// +// // Print the generated array +// // printf("Random numbers in the range [0, 1):\n"); +// // printf("mu_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%.6f\n", mu[i]); +// // } +// // printf("a_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%.6f\n", a[i]); +// // } +// // printf("beta_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%.6f\n", beta[i]); +// // } +// // printf("sigma_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // for (int j = 0; j < arraySize - 1; j++) +// // { +// // printf("%.6f\n", sigma_12[i][j]); +// // } +// +// // } +// +// // printf("delta_l:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%d\n", non_selected_client_index_table[i]); +// // } +// +// for (int i = 0; i < arraySize; i++) +// { +// result_float_2[i] = (float) result_dram_2[i]; +// for (int j = 0; j < arraySize; j++) +// { +// result_float[i][j] = (float) result_dram[i][j]; +// } +// +// } +// +// printf("client_index_list:\n"); +// for (int i = 0; i < C; i++) { +// printf("%d\n", client_index_list[i]); +// } +// +// +// printf("mu updated:\n"); +// for (int i = 0; i < arraySize; i++) { +// printf("%.6f\n", result_float_2[i]); +// } +// // printf("sigma_22:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // for (int j = 0; j < arraySize; j++) +// // { +// // printf("%.6f\n", sigma_dram[i][j]); +// // } +// +// // } +// +// return 0; +//} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_float_dataset/src/GP_kernel_100_10_success.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_float_dataset/src/GP_kernel_100_10_success.cpp new file mode 100644 index 000000000000..32503eeb5a06 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/GP_selection_kernel_float_dataset/src/GP_kernel_100_10_success.cpp @@ -0,0 +1,1812 @@ +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include "hls_stream.h" +#include "hls_math.h" + +#include +#include + +#include + + + +// #define N 128 //The number of clients +// #define C 10 //The number of clients to be selected +// #define SORT_NUM 32 + +// #define N_CLIENT 72 + +// #define BUFFER_SIZE 64 +// #define UNROLL_FACTOR 16 + +#define N 100 //The number of clients +#define C 10 //The number of clients to be selected +#define SORT_NUM 32 + +#define N_CLIENT 100 + +#define BUFFER_SIZE 20 +#define UNROLL_FACTOR 20 + +#define SCALE 5 + + + +typedef float DATA_TYPE; +typedef float Key_Type; +//typedef ap_fixed<32,10> DATA_TYPE; +//typedef ap_fixed<32,10> Key_Type; +typedef struct { + Key_Type number; + int index; +} Data_Sort; + +// define some on-chip buffers + +DATA_TYPE mu[N]; +DATA_TYPE sigma[BUFFER_SIZE][BUFFER_SIZE]; +DATA_TYPE a[N]; +DATA_TYPE beta[N]; +DATA_TYPE sigma_1d[N]; + + + +DATA_TYPE mu_bar_accumu[N]; +bool client_selection_flag[N_CLIENT]; +DATA_TYPE sigma_12_22_multiply[N_CLIENT][C]; // sigma_12 * sigma_22_inverse [N - m * m] +DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N_CLIENT]; // [N - m * N - M] + +DATA_TYPE delta_l[N]; + +//DATA_TYPE sigma_11[N][N - 1][N - 1]; +//DATA_TYPE sigma_12[N][N]; // The actual size is N * (N - 1) +//DATA_TYPE sigma_21[N][N - 1]; +DATA_TYPE sigma_12[BUFFER_SIZE][N]; +DATA_TYPE sigma_22[N]; +//DATA_TYPE mu_1[N][N]; // The actual size is N * (N - 1) +DATA_TYPE mu_1[BUFFER_SIZE][N]; +DATA_TYPE mu_2[N]; +DATA_TYPE mu_bar[BUFFER_SIZE][N]; + +Data_Sort sort_client_list[N_CLIENT]; +//Data_Sort input_sort[SORT_NUM]; +Data_Sort output_sort[SORT_NUM]; +DATA_TYPE mu_bar_sorted_data[N]; +int mu_bar_sorted_index[N]; + +int selected_client_index_table[C]; +int non_selected_client_index_table[N_CLIENT]; + +DATA_TYPE sigma_11_select[BUFFER_SIZE][N_CLIENT]; +DATA_TYPE sigma_12_select[N_CLIENT][C]; +DATA_TYPE sigma_21_select[C][N_CLIENT]; +DATA_TYPE sigma_22_select[C][C]; +DATA_TYPE sigma_22_select_inverse[C][C]; +DATA_TYPE sigma_updated[BUFFER_SIZE][N_CLIENT]; + +DATA_TYPE alpha_mu_2_selected[C]; +DATA_TYPE sigma_mu_multiply[N_CLIENT]; +DATA_TYPE mu_1_select[N]; +DATA_TYPE mu_updated[N_CLIENT]; + +//bool client_selection_flag[N]; + +void load_parameters(DATA_TYPE mu_dram[N], DATA_TYPE a_dram[N], DATA_TYPE beta_dram[N] ) +{ + for (int i = 0; i < N; i++) + { +#pragma HLS pipeline II=1 + mu[i] = mu_dram[i]; + + a[i] = a_dram[i]; + + beta[i] = beta_dram[i]; + } + +} + +void load_sigma_1d(DATA_TYPE sigma_dram[N][N]) +{ + for (int i = 0; i < N ;i++) + { +#pragma HLS pipeline II=1 + sigma_1d[i] = sigma_dram[i][i]; + } +} + + +void on_chip_buffer_initialization(DATA_TYPE mu_bar_accumu[N], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + for (int client_index = 0; client_index < N; client_index++) + { +#pragma HLS pipeline II=1 + mu_bar_accumu[client_index] = 0; + //client_selection_flag[client_index] = 0; //initialization, 0 means non client is selected. + } + + for (int i = 0; i < C;i++) + { +#pragma HLS pipeline II=1 + selected_client_index_table[i] = 0; + } + + for (int i = 0; i < N_CLIENT; i++) + { +#pragma HLS pipeline II=1 + non_selected_client_index_table[i] = 0; + } + +} + +void compute_delta_l_kernel(DATA_TYPE mu[N], DATA_TYPE sigma_1d[N], DATA_TYPE a[N], DATA_TYPE beta[N], DATA_TYPE delta_l[N], int index) +{ + +DATA_TYPE mu_buffer[UNROLL_FACTOR]; +DATA_TYPE sigma_buffer[UNROLL_FACTOR]; +DATA_TYPE a_buffer[UNROLL_FACTOR]; +DATA_TYPE beta_buffer[UNROLL_FACTOR]; +DATA_TYPE delta_l_buffer[UNROLL_FACTOR]; + +#pragma HLS ARRAY_PARTITION variable=a_buffer complete dim=1 +#pragma HLS ARRAY_PARTITION variable=beta_buffer complete dim=1 +#pragma HLS ARRAY_PARTITION variable=mu_buffer complete dim=1 +#pragma HLS ARRAY_PARTITION variable=sigma_buffer complete dim=1 +#pragma HLS inline off + +for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) +{ +#pragma HLS pipeline II = 1 + mu_buffer[client_index] = mu[UNROLL_FACTOR * index + client_index]; + a_buffer[client_index] = a[UNROLL_FACTOR * index + client_index]; + beta_buffer[client_index] = beta[UNROLL_FACTOR * index + client_index]; + sigma_buffer[client_index] = sigma_1d[UNROLL_FACTOR * index + client_index]; +} + +//#pragma HLS ARRAY_PARTITION variable=temp complete dim=1 + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + //partition to get mu_1 +#pragma HLS unroll + delta_l_buffer[client_index] = a_buffer[client_index] * beta_buffer[client_index]; + delta_l_buffer[client_index] = mu_buffer[client_index] - delta_l_buffer[client_index] * sqrt(abs(sigma_buffer[client_index])); + + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { +#pragma HLS pipeline II = 1 + delta_l[UNROLL_FACTOR * index + client_index] = delta_l_buffer[client_index]; + } +} + + +void compute_delta_l(DATA_TYPE mu[N], DATA_TYPE sigma_1d[N], DATA_TYPE a[N], DATA_TYPE beta[N], DATA_TYPE delta_l[N]) +{ + +#pragma HLS inline off + + for (int index = 0; index < N/UNROLL_FACTOR; index++) + { + compute_delta_l_kernel(mu, sigma_1d, a, beta, delta_l, index); + } +} + +void mu_sigma_selection(DATA_TYPE mu[N], DATA_TYPE sigma_dram[N][N], DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_1d[N], DATA_TYPE sigma_22[N], int selection_index) + +{ +// The actual size of mu_1 is N * (N - 1) +// The actual size of sigma_12 is N * (N -1) + +#pragma HLS inline off + + for (int client_index = 0; client_index < BUFFER_SIZE; client_index++) + { + for (int i = 0; i < BUFFER_SIZE * selection_index + client_index ; i++) + { + #pragma HLS pipeline II = 1 + mu_1[client_index][i] = mu[i]; + } + + for (int i = BUFFER_SIZE * selection_index + client_index + 1; i < N; i++) + { + #pragma HLS pipeline II = 1 + mu_1[ client_index][i - 1] = mu[i]; + } + + mu_1[client_index][N - 1] = (DATA_TYPE) 0.0; + //partition to get mu_2 + mu_2[BUFFER_SIZE * selection_index + client_index] = mu[BUFFER_SIZE * selection_index + client_index]; + + //partition to get sigma_12 + for (int i = 0; i < BUFFER_SIZE * selection_index + client_index; i++) + { + #pragma HLS pipeline II = 1 + sigma_12[ client_index][i] = sigma_dram[i][0]; + } + + for (int i = BUFFER_SIZE * selection_index + client_index + 1; i < N; i++) + { + #pragma HLS pipeline II = 1 + sigma_12[ client_index][i - 1] = sigma_dram[i][0]; + } + sigma_12[client_index][N -1] = (DATA_TYPE) 0.0; + + //partiton to get sigma_22 + + //sigma_22[client_index] = (DATA_TYPE) 1.0/sigma[client_index][client_index]; + } + + for (int client_index = 0; client_index < N_CLIENT; client_index++) + { + #pragma HLS pipeline II = 1 + sigma_22[client_index] = (DATA_TYPE) 1.0/sigma_1d[client_index]; + } + for (int client_index = N_CLIENT; client_index < N; client_index++) + { + #pragma HLS pipeline II = 1 + sigma_22[client_index] = (DATA_TYPE) 0.0; + + } + + // for (int client_index = 0; client_index < N_CLIENT; client_index++) + // { + // #pragma HLS pipeline II = 1 + // //sigma_22[BUFFER_SIZE * selection_index + client_index] = (DATA_TYPE) 1.0/sigma_1d[BUFFER_SIZE * selection_index + client_index]; + // sigma_22[client_index] + + // } + +} + +void mu_bar_accumulator(DATA_TYPE mu_bar[BUFFER_SIZE][N], DATA_TYPE mu_bar_accumu[N], int index, int index_outside) +{ + + DATA_TYPE mu_bar_accumu_buffer[UNROLL_FACTOR]; + DATA_TYPE mu_bar_buffer[UNROLL_FACTOR][N - 1]; + #pragma HLS ARRAY_PARTITION variable=mu_bar_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_bar_accumu_buffer complete dim=1 + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + mu_bar_accumu_buffer[client_index] = 0; + for (int i = 0; i < N - 1; i++) + { + #pragma HLS pipeline II = 1 + mu_bar_buffer[client_index][i] = mu_bar[UNROLL_FACTOR * index + client_index][i]; + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + #pragma HLS unroll + + for (int i = 0; i < N - 1; i++) + { + #pragma HLS pipeline II = 1 + //#pragma HLS unroll + mu_bar_accumu_buffer[client_index] = mu_bar_accumu_buffer[client_index] + mu_bar_buffer[client_index][i]; + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + #pragma HLS pipeline II = 1 + mu_bar_accumu[BUFFER_SIZE * index_outside + UNROLL_FACTOR * index + client_index] = mu_bar_accumu_buffer[client_index]; + } + + +} + + +void compute_mu_bar_accumu_kernel(DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_22[N], DATA_TYPE delta_l[N], DATA_TYPE mu_bar[BUFFER_SIZE][N], int index_x, int index_y, int index) +{ + //update the mu_bar + DATA_TYPE mu_1_buffer[UNROLL_FACTOR][UNROLL_FACTOR]; + DATA_TYPE mu_2_buffer[UNROLL_FACTOR]; + DATA_TYPE sigma_12_buffer[UNROLL_FACTOR][UNROLL_FACTOR]; + DATA_TYPE sigma_22_buffer[UNROLL_FACTOR]; + DATA_TYPE delta_l_buffer[UNROLL_FACTOR]; + DATA_TYPE mu_bar_buffer[UNROLL_FACTOR][UNROLL_FACTOR]; + //DATA_TYPE mu_bar_accumu_buffer[UNROLL_FACTOR]; + + #pragma HLS ARRAY_PARTITION variable=mu_1_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_1_buffer complete dim=2 + #pragma HLS ARRAY_PARTITION variable=mu_2_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=sigma_12_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=sigma_12_buffer complete dim=2 + #pragma HLS ARRAY_PARTITION variable=sigma_22_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=delta_l_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_bar_buffer complete dim=1 + #pragma HLS ARRAY_PARTITION variable=mu_bar_buffer complete dim=2 + //#pragma HLS ARRAY_PARTITION variable=mu_bar_accumu_buffer complete dim=1 + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + sigma_22_buffer[client_index] = sigma_22[BUFFER_SIZE * index + UNROLL_FACTOR * index_x + client_index]; + delta_l_buffer[client_index] = delta_l[BUFFER_SIZE * index + UNROLL_FACTOR * index_x + client_index]; + mu_2_buffer[client_index] = mu_2[BUFFER_SIZE * index + UNROLL_FACTOR * index_x + client_index]; + for (int i = 0; i < UNROLL_FACTOR; i++) + { + mu_1_buffer[client_index][i] = mu_1[ UNROLL_FACTOR * index_x + client_index][ UNROLL_FACTOR * index_y + i]; + sigma_12_buffer[client_index][i] = sigma_12[ UNROLL_FACTOR * index_x + client_index][UNROLL_FACTOR * index_y + i]; + + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + #pragma HLS unroll + for (int i = 0; i < UNROLL_FACTOR; i++) + { + #pragma HLS unroll + mu_bar_buffer[client_index][i] = mu_1_buffer[client_index][i] + sigma_12_buffer[client_index][i] * sigma_22_buffer[client_index] * (delta_l_buffer[client_index] - mu_2_buffer[client_index]); + + } + } + + for (int client_index = 0; client_index < UNROLL_FACTOR; client_index++) + { + for (int i = 0; i < UNROLL_FACTOR; i++) + { + #pragma HLS pipeline II = 1 + mu_bar[UNROLL_FACTOR * index_x + client_index][UNROLL_FACTOR * index_y + i] = mu_bar_buffer[client_index][i]; + } + + } + +} + + + + +void compute_mu_bar_accumu(DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_22[N], DATA_TYPE delta_l[N], DATA_TYPE mu_bar[BUFFER_SIZE][N], DATA_TYPE mu_bar_accumu[N], int index_outside) +{ + //update the mu_bar + + // The actual size of the mu_bar is N * (N -1) + + for (int index_x = 0; index_x < BUFFER_SIZE/UNROLL_FACTOR; index_x++) + { + for (int index_y = 0; index_y < N/UNROLL_FACTOR; index_y++) + { + compute_mu_bar_accumu_kernel(mu_1, mu_2, sigma_12, sigma_22, delta_l, mu_bar, index_x, index_y, index_outside); + } + mu_bar_accumulator(mu_bar, mu_bar_accumu, index_x, index_outside); + } +} + +void compute_mu_ba_scale(DATA_TYPE mu[N], DATA_TYPE sigma_dram[N][N], DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_1d[N], DATA_TYPE sigma_22[N]) +{ + for (int index_outside = 0; index_outside < N/BUFFER_SIZE; index_outside++) + { + mu_sigma_selection(mu, sigma_dram, mu_1, mu_2, sigma_12, sigma_1d, sigma_22, index_outside); + compute_mu_bar_accumu(mu_1, mu_2, sigma_12, sigma_22, delta_l, mu_bar, mu_bar_accumu, index_outside); + } +} + +Data_Sort sorting_kernel_2 (Data_Sort input_1, Data_Sort input_2) +{ +//#pragma HLS inline off + if (input_1.number < input_2.number) + { + return input_1; + } + else + { + return input_2; + } + +} + +Data_Sort sorting_kernel_4(Data_Sort input [4]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp[2]; + #pragma HLS ARRAY_PARTITION variable=out_temp complete dim=1 + for (int i = 0; i < 2; i++) + { + #pragma HLS unroll + + out_temp[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + return sorting_kernel_2(out_temp[0], out_temp[1]); + +} + +Data_Sort sorting_kernel_8(Data_Sort input[8]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp complete dim=1 + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + return sorting_kernel_4(out_temp); +} + + + +Data_Sort sorting_kernnel_16 (Data_Sort input[16]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp_1[8]; + #pragma HLS ARRAY_PARTITION variable=out_temp_1 complete dim=1 + Data_Sort out_temp_2[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp_2 complete dim=1 + + for (int i = 0; i < 8; i++) + { + #pragma HLS unroll + + out_temp_1[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp_2[i] = sorting_kernel_2(out_temp_1[2 * i], out_temp_1[2 * i + 1]); + } + + + return sorting_kernel_4(out_temp_2); +} + +Data_Sort sorting_kernel_32 (Data_Sort input[32]) +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp_1[16]; + #pragma HLS ARRAY_PARTITION variable=out_temp_1 complete dim=1 + Data_Sort out_temp_2[8]; + #pragma HLS ARRAY_PARTITION variable=out_temp_2 complete dim=1 + Data_Sort out_temp_3[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp_3 complete dim=1 + + for (int i = 0; i < 16; i++) + { + #pragma HLS unroll + + out_temp_1[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + for (int i = 0; i < 8; i++) + { + #pragma HLS unroll + + out_temp_2[i] = sorting_kernel_2(out_temp_1[2 * i], out_temp_1[2 * i + 1]); + } + + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp_3[i] = sorting_kernel_2(out_temp_2[2 * i], out_temp_2[2 * i + 1]); + } + + return sorting_kernel_4(out_temp_3); +} + + +Data_Sort sorting_kernel_64 (Data_Sort input[64]) + +{ + #pragma HLS ARRAY_PARTITION variable=input complete dim=1 + Data_Sort out_temp_1[32]; + #pragma HLS ARRAY_PARTITION variable=out_temp_1 complete dim=1 + Data_Sort out_temp_2[16]; + #pragma HLS ARRAY_PARTITION variable=out_temp_2 complete dim=1 + Data_Sort out_temp_3[8]; + #pragma HLS ARRAY_PARTITION variable=out_temp_3 complete dim=1 + Data_Sort out_temp_4[4]; + #pragma HLS ARRAY_PARTITION variable=out_temp_4 complete dim=1 + + for (int i = 0; i < 32; i++) + { + #pragma HLS unroll + + out_temp_1[i] = sorting_kernel_2(input[2 * i], input[2 * i + 1]); + } + + for (int i = 0; i < 16; i++) + { + #pragma HLS unroll + + out_temp_2[i] = sorting_kernel_2(out_temp_1[2 * i], out_temp_1[2 * i + 1]); + } + + for (int i = 0; i < 8; i++) + { + #pragma HLS unroll + + out_temp_3[i] = sorting_kernel_2(out_temp_2[2 * i], out_temp_2[2 * i + 1]); + } + + for (int i = 0; i < 4; i++) + { + #pragma HLS unroll + + out_temp_4[i] = sorting_kernel_2(out_temp_3[2 * i], out_temp_3[2 * i + 1]); + } + + return sorting_kernel_4(out_temp_4); + +} + +Data_Sort sorting_kernel(Data_Sort sort_input[SORT_NUM]) + +{ + Data_Sort sort_output; + DATA_TYPE sort_output_number; + DATA_TYPE sort_output_index; + #pragma HLS ARRAY_PARTITION variable=sort_input complete dim=1 +#pragma HLS inline off + + if (SORT_NUM == 64) + { + sort_output = sorting_kernel_64(sort_input); + } + + if (SORT_NUM == 32) + { + sort_output = sorting_kernel_32(sort_input); + } + + if (SORT_NUM == 16) + { + sort_output = sorting_kernnel_16(sort_input); + } + + if (SORT_NUM == 8) + { + sort_output = sorting_kernel_8(sort_input); + } + + if (SORT_NUM == 4) + { + sort_output = sorting_kernel_4(sort_input); + } + + if (SORT_NUM == 2) + { + sort_output = sorting_kernel_2(sort_input[0], sort_input[1]); + } + + + return sort_output; + +} + +int sorting(DATA_TYPE mu_bar_accumu[N], bool client_selection_flag[N_CLIENT], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + Data_Sort input_sort[SORT_NUM]; + #pragma HLS ARRAY_PARTITION variable=input_sort complete dim=1 + int selected_sorting_client_num = 0; + Data_Sort sort_output_result; + Data_Sort output_sort_buffer[SORT_NUM]; + #pragma HLS ARRAY_PARTITION variable=output_sort_buffer complete dim=1 + for (int i = 0; i < N_CLIENT; i++) + { + #pragma HLS pipeline II = 1 + if (client_selection_flag[i] == 0) + { + sort_client_list[selected_sorting_client_num].number = mu_bar_accumu[i]; + sort_client_list[selected_sorting_client_num].index = i; + selected_sorting_client_num++; + } + + } + + if (selected_sorting_client_num > SORT_NUM) + { + + int iteration_num = selected_sorting_client_num/SORT_NUM; + int iter_counter = 0; + for (int iter = 0; iter < iteration_num; iter++) + { + for (int i = 0; i < SORT_NUM; i++) + { + #pragma HLS pipeline II = 1 + input_sort[i] = sort_client_list[iter * SORT_NUM + i]; + } + output_sort_buffer[iter] = sorting_kernel(input_sort); + iter_counter = iter_counter + 1; + } + int bound = selected_sorting_client_num - (iter_counter * SORT_NUM); + + for (int i = 0; i < bound; i++) + { + #pragma HLS pipeline II = 1 + input_sort[i] = sort_client_list[iter_counter * SORT_NUM + i]; + } + + for (int i = bound; i < SORT_NUM; i++) + { + #pragma HLS pipeline II = 1 + input_sort[i].number = 9999; + input_sort[i].index = 9999; + } + + output_sort_buffer[iter_counter] = sorting_kernel(input_sort); + iter_counter = iter_counter + 1; + + for (int i = iter_counter; i < SORT_NUM; i++) + { + output_sort_buffer[i].number = 9999; + output_sort_buffer[i].index = 9999; + } + + + sort_output_result = sorting_kernel(output_sort_buffer); + + } + + else + { + for (int i = 0; i < selected_sorting_client_num; i++) + { + input_sort[i] = sort_client_list[i]; + } + + for (int i = selected_sorting_client_num; i < SORT_NUM; i++) + { + input_sort[i].number = 9999; + input_sort[i].index = 9999; + } + + sort_output_result = sorting_kernel(input_sort); + + } + + int select_client_index = sort_output_result.index; + + client_selection_flag[select_client_index] = 1; + + + int client_selected_num = 0; + int client_not_selected_num = 0; + // calculate the total number of clients selected. + for (int i = 0; i < N_CLIENT; i++) + { + #pragma HLS pipeline II = 1 + if (client_selection_flag[i] == 1) + { + selected_client_index_table[client_selected_num] = i; + client_selected_num = client_selected_num + 1; + + } + + else + { + non_selected_client_index_table[client_not_selected_num] = i; + client_not_selected_num = client_not_selected_num + 1; + } + + + } + + return client_selected_num; + +} + + +// void sorting_kernel(DATA_TYPE mu_bar_accumu[SORT_NUM], DATA_TYPE mu_bar_sorted_data[SORT_NUM], int mu_bar_sorted_index[N]) + +// { +// // get the accumulation for each client of the mu_bar +// bool order = 1; +// //generate the sorting information + +// #pragma HLS aggregate variable=input_sort +// #pragma HLS aggregate variable=output_sort +// // #pragma HLS ARRAY_PARTITION variable=input_sort complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=output_sort complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=mu_bar_accumu complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=mu_bar_sorted_data complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=mu_bar_sorted_index complete dim=1 + +// #pragma HLS inline off + +// for (int i = 0; i < SORT_NUM; i++) +// { +// #pragma HLS pipeline II = 1 +// input_sort[i].number = mu_bar_accumu[SORT_NUM * index + i]; +// input_sort[i].index = SORT_NUM * index + i; +// } +// // for (int i = 0; i < N; i++) +// // { +// // #pragma HLS pipeline II = 1 +// // input_sort[i].number = mu_bar_accumu[i]; +// // input_sort[i].index = i; +// // } + +// // for (int i = N ; i < SORT_NUM; i++) +// // { +// // #pragma HLS pipeline II = 1 +// // input_sort[i].number = 9999; +// // input_sort[i].index = i; + +// // } +// hls::stream kin_strm; +// hls::stream kin_strm_end; +// hls::stream kout_strm; +// hls::stream kout_strm_end; +// #pragma HLS STREAM variable=kin_strm depth=SORT_NUM +// #pragma HLS STREAM variable=kin_strm_end depth=SORT_NUM + 1 +// #pragma HLS STREAM variable=kout_strm depth=SORT_NUM +// #pragma HLS STREAM variable=kout_strm_end depth=SORT_NUM + 1 + +// load_data(input_sort, kin_strm, kin_strm_end, SORT_NUM); +// bitonic_sort_top(kin_strm, kin_strm_end, kout_strm, kout_strm_end, order); +// store_data(output_sort, kout_strm, kout_strm_end, SORT_NUM); + +// for (int i = 0; i < SORT_NUM; i++) +// { +// #pragma HLS pipeline II = 1 +// mu_bar_sorted_data[SORT_NUM * index + i] = output_sort[i].number; +// mu_bar_sorted_index[SORT_NUM * index + i] = output_sort[i].index; +// } +// // for (int i = 0; i < N; i++) +// // { +// // //#pragma HLS unroll +// // mu_bar_sorted_data[i] = output_sort[i].number; +// // mu_bar_sorted_index[i] = output_sort[i].index; +// // } + +// } + +// int select_client(bool client_selection_flag[N], int selected_client_index_table[C], int non_selected_client_index_table[N]) +// { +// // if we want to select the client with the minimum value, then select mu_bar_sorted_index[0] +// #pragma HLS inline off +// for (int i = 0; i < N; i++) +// { +// #pragma HLS pipeline II = 1 +// if (client_selection_flag[mu_bar_sorted_index[i]] == 0) +// { +// client_selection_flag[mu_bar_sorted_index[i]] = 1; +// break; +// } +// } + + +// int client_selected_num = 0; +// int client_not_selected_num = 0; +// // calculate the total number of clients selected. +// for (int i = 0; i < N; i++) +// { +// #pragma HLS pipeline II = 1 +// if (client_selection_flag[i] == 1) +// { +// selected_client_index_table[client_selected_num] = i; +// client_selected_num = client_selected_num + 1; + +// } + +// else +// { +// non_selected_client_index_table[client_not_selected_num] = i; +// client_not_selected_num = client_not_selected_num + 1; +// } + + +// } + +// return client_selected_num; +// } + +void sigma_selection_new(int client_selected_num, DATA_TYPE sigma_dram[N][N], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT] ) +{ + +// #pragma HLS ARRAY_PARTITION variable=sigma complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_22_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_22_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=selected_client_index_table complete dim=1 +#pragma HLS inline off + for (int i = 0; i < client_selected_num; i++) + { + for (int j = 0; j < client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_22_select[i][j] = sigma_dram[selected_client_index_table[i]][selected_client_index_table[j]]; + } + } + + for (int i = 0; i < client_selected_num; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_21_select[i][j] = sigma_dram[selected_client_index_table[i]][non_selected_client_index_table[j]]; + } + } + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + + for (int j = 0; j < client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_12_select[i][j] = sigma_dram[non_selected_client_index_table[i]][selected_client_index_table[j]]; + } + } + + // for (int i = 0; i < N - client_selected_num; i++) + // { + // for (int j = 0; j < N - client_selected_num; j++) + // { + // #pragma HLS pipeline II = 1 + // sigma_11_select[i][j] = sigma[non_selected_client_index_table[i]][non_selected_client_index_table[j]]; + // } + // } +} + + +void sigma_11_selection_new(int client_selected_num, DATA_TYPE sigma_dram[N][N], int index_outside, int total_iter_num, int remaining_iteration) +{ + if (index_outside != total_iter_num - 1) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_11_select[i][j] = sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]]; + } + } + + } + + else + + { + for (int i = 0; i < remaining_iteration; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_11_select[i][j] = sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]]; + } + } + } + + + +} + + + + +// void sigma_selection(int client_selected_num, DATA_TYPE sigma[N][N], bool client_selection_flag[N]) +// { +// int sigma_22_select_dim_i = client_selected_num; +// int sigma_22_select_dim_j = client_selected_num; // the dimension of sigma_22 is [m * m] +// int sigma_21_select_dim_i = client_selected_num; +// int sigma_21_select_dim_j = N - client_selected_num; // the dimension of sigma_21 is [m * N -m] +// int sigma_12_select_dim_i = N - client_selected_num; +// int sigma_12_select_dim_j = client_selected_num; // the dimension of sigma_12 is [N - m * m] +// int sigma_11_select_dim_i = N - client_selected_num; +// int sigma_11_select_dim_j = N - client_selected_num; // the dimension of sigma_11 is [N - m * N - m] + +// int sigma_22_select_dim_i_counter = 0; +// int sigma_22_select_dim_j_counter = 0; +// int sigma_21_select_dim_i_counter = 0; +// int sigma_21_select_dim_j_counter = 0; +// int sigma_12_select_dim_i_counter = 0; +// int sigma_12_select_dim_j_counter = 0; +// int sigma_11_select_dim_i_counter = 0; +// int sigma_11_select_dim_j_counter = 0; + +// // generate the sigma matrixs. +// for (int i = 0; i < N; i++) +// { +// #pragma HLS unroll +// for (int j = 0; j < N ;j++) +// { +// #pragma HLS unroll +// if (client_selection_flag[i] == 1 & client_selection_flag[j] == 1) +// { +// sigma_22_select[sigma_22_select_dim_i_counter][sigma_22_select_dim_j_counter] = sigma[i][j]; +// sigma_22_select_dim_j_counter++; +// if (sigma_22_select_dim_j_counter == sigma_22_select_dim_j) +// { +// sigma_22_select_dim_j_counter = 0; +// sigma_22_select_dim_i_counter++; +// } +// } +// else if (client_selection_flag[i] == 1 & client_selection_flag[j] == 0) +// { +// sigma_21_select[sigma_21_select_dim_i_counter][sigma_21_select_dim_j_counter] = sigma[i][j]; +// sigma_21_select_dim_j_counter++; +// if (sigma_21_select_dim_j_counter == sigma_21_select_dim_j) +// { +// sigma_21_select_dim_j_counter = 0; +// sigma_21_select_dim_i_counter++; +// } +// } +// else if (client_selection_flag[i] == 0 & client_selection_flag[j] == 1) +// { +// sigma_12_select[sigma_12_select_dim_i_counter][sigma_12_select_dim_j_counter] = sigma[i][j]; +// sigma_12_select_dim_j_counter++; +// if (sigma_12_select_dim_j_counter == sigma_12_select_dim_j) +// { +// sigma_12_select_dim_j_counter = 0; +// sigma_12_select_dim_i_counter++; +// } +// } +// else if (client_selection_flag[i] == 0 & client_selection_flag[j] == 0) +// { +// sigma_11_select[sigma_11_select_dim_i_counter][sigma_11_select_dim_j_counter] = sigma[i][j]; +// sigma_11_select_dim_j_counter++; +// if (sigma_11_select_dim_j_counter == sigma_11_select_dim_j) +// { +// sigma_11_select_dim_j_counter = 0; +// sigma_11_select_dim_i_counter++; +// } +// } +// } +// } +// } + +// int inverseMatrix(DATA_TYPE mat[C][C], DATA_TYPE inv[C][C], int matrix_dim) { + +// #pragma HLS inline off +// #pragma HLS ARRAY_PARTITION variable=mat complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=mat complete dim=2 +// #pragma HLS ARRAY_PARTITION variable=inv complete dim=1 +// #pragma HLS ARRAY_PARTITION variable=inv complete dim=2 + +// DATA_TYPE temp; + +// //Initialize the inverse matrix as the identity matrix +// for (int i = 0; i < matrix_dim; i++) { +// #pragma HLS unroll +// for (int j = 0; j < matrix_dim; j++) { +// #pragma HLS unroll +// if (i == j) +// inv[i][j] = 1.0; +// else +// inv[i][j] = 0.0; +// } +// } +// // Perform Gauss-Jordan elimination +// for (int i = 0; i < matrix_dim; i++) { +// #pragma HLS unroll +// if (mat[i][i] == 0.0) +// return 0; // Matrix is not invertible + +// // Scale the current row +// temp = mat[i][i]; +// for (int j = 0; j < matrix_dim; j++) { +// //#pragma HLS pipeline II = 1 +// #pragma HLS unroll +// mat[i][j] /= temp; +// inv[i][j] /= temp; +// } + +// // Eliminate other rows +// for (int j = 0; j < matrix_dim; j++) { +// if (i != j) { +// temp = mat[j][i]; +// for (int k1 = 0; k1 < i+ 1; k1++) // k1 < i+1 +// { +// #pragma HLS unroll +// inv[j][k1] -= temp * inv[i][k1]; +// } +// for (int k2 = i; k2 < matrix_dim; k2++) { +// #pragma HLS unroll +// mat[j][k2] -= temp * mat[i][k2]; +// //inv[j][k] -= temp * inv[i][k]; +// } +// } +// } +// } + +// return 1; // Matrix is invertible +// } + + +void inverse_matrix_new(DATA_TYPE mat[C][C], DATA_TYPE inv[C][C], int matrix_dim) +{ + inv[0][0] = 1.0/mat[0][0]; + DATA_TYPE c_matrix[C]; + DATA_TYPE b_matrix[C]; + for (int iter = 1; iter < matrix_dim; iter++) + { + DATA_TYPE d = mat[iter][iter]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + c_matrix[i] = mat[iter][i]; + b_matrix[i] = mat[i][iter]; + } + + DATA_TYPE c_a_inverse[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + c_a_inverse[i] = 0; + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + c_a_inverse[i] += c_matrix[j] * inv[j][i]; + } + + } + + DATA_TYPE b = 0; + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + b = b + c_a_inverse[i] * b_matrix[i]; + } + + DATA_TYPE t; + + t = 1.0/ (d - b); + + //printf("the value of t is:%f\n", t); + + DATA_TYPE a_inverse_b[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + a_inverse_b[i] = 0; + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + a_inverse_b[i] += inv[i][j] * b_matrix[j]; + } + + } + + DATA_TYPE Y[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + Y[i] = -a_inverse_b[i] * t; + } + + // for (int i = 0; i < 2; i++) + // { + // printf("the value of Y is:%f\n", Y[i]); + // } + + // DATA_TYPE c_a_inverse[C]; + // for (int i = 0; i < iter; i++) + // { + // for (int j = 0; j < iter; j++) + // { + // c_a_inverse[i] += c_matrix[j] * inv[j][i]; + // } + // } + + DATA_TYPE Z[C]; + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + Z[i] = -c_a_inverse[i] * t; + } + + // for (int i = 0; i < 2; i++) + // { + // printf("the value of Z is:%f\n", Z[i]); + // } + + + DATA_TYPE BZ[C][C]; + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + BZ[i][j] = b_matrix[i] * Z[j]; + } + } + + DATA_TYPE I_minus_BZ[C][C]; + + for (int i = 0; i < C; i++) + { + for (int j = 0; j < C; j++) + { + #pragma HLS pipeline II = 1 + if (i == j) + { + I_minus_BZ[i][j] = 1; + } + else + { + I_minus_BZ[i][j] = 0; + } + } + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + I_minus_BZ[i][j] = I_minus_BZ[i][j] - BZ[i][j]; + } + } + + DATA_TYPE I_minus_BZ_A_inverse[C][C]; + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + I_minus_BZ_A_inverse[i][j] = 0; + } + } + + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + for (int k = 0; k < iter; k++) + { + #pragma HLS pipeline II = 1 + I_minus_BZ_A_inverse[i][j] += inv[i][k] * I_minus_BZ[k][j]; + } + } + } + + // Theen we need to update the inverse matrix + for (int i = 0; i < iter; i++) + { + for (int j = 0; j < iter; j++) + { + #pragma HLS pipeline II = 1 + inv[i][j] = I_minus_BZ_A_inverse[i][j]; + } + } + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + inv[i][iter] = Y[i]; + } + + for (int i = 0; i < iter; i++) + { + #pragma HLS pipeline II = 1 + inv[iter][i] = Z[i]; + } + + inv[iter][iter] = t; + + } + +} + + +void compute_sigma_12_21_multiply(DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N_CLIENT], DATA_TYPE sigma_12_22_multiply[N_CLIENT][C], DATA_TYPE sigma_21_select[C][N_CLIENT], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) +{ + + for (int i = 0; i < BUFFER_SIZE;i++) + { + for (int j = 0; j < N_CLIENT; j++) + { + #pragma HLS pipeline II=1 + sigma_12_21_multiply[i][j] = 0; + } + } + + if (index_outside != iter_total_num -1 ) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + //#pragma HLS pipeline II = 1 + for (int k = 0; k < client_selected_num; k++) + { + #pragma HLS pipeline II = 1 + sigma_12_21_multiply[i][j] += sigma_12_22_multiply[BUFFER_SIZE * index_outside + i][k] * sigma_21_select[k][j]; + } + } + } + } + + else + { + for (int i = 0; i < iter_remaining; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + //#pragma HLS pipeline II = 1 + for (int k = 0; k < client_selected_num; k++) + { + #pragma HLS pipeline II = 1 + sigma_12_21_multiply[i][j] += sigma_12_22_multiply[BUFFER_SIZE * index_outside + i][k] * sigma_21_select[k][j]; + } + } + } + } + +} + +void compute_sigma_updated(DATA_TYPE sigma_11_select[BUFFER_SIZE][N_CLIENT], DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N_CLIENT], DATA_TYPE sigma_updaated[BUFFER_SIZE][N_CLIENT], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) +{ + if (index_outside != iter_total_num - 1) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_updated[i][j] = sigma_11_select[i][j] - sigma_12_21_multiply[i][j]; + } + } + } + + else + + { + for (int i = 0; i < iter_remaining; i++) + { + + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_updated[i][j] = sigma_11_select[i][j] - sigma_12_21_multiply[i][j]; + } + } + } + + +} + +void compute_sigma_12_22_multiply(DATA_TYPE sigma_12_select[N_CLIENT][C], DATA_TYPE sigma_22_select_inverse[C][C], DATA_TYPE sigma_12_22_multiply[N_CLIENT][C], int client_selected_num) +{ + for (int i = 0; i < N_CLIENT;i++) + { + for (int j = 0; j < client_selected_num; j++) + { +#pragma HLS pipeline II=1 + sigma_12_22_multiply[i][j] = 0; + } + } + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + for (int j = 0; j < client_selected_num; j++) + { + //#pragma HLS pipeline II = 1 + for (int k = 0; k < client_selected_num; k++) + { + //#pragma HLS unroll + #pragma HLS pipeline II = 1 + sigma_12_22_multiply[i][j] += sigma_12_select[i][k] * sigma_22_select_inverse[k][j]; + } + } + } +} + +// void compute_sigma_updated(DATA_TYPE sigma_11_select[N][N], DATA_TYPE sigma_12_select[N][C], DATA_TYPE sigma_22_select_inverse[C][C], DATA_TYPE sigma_12_22_multiply[N][C], DATA_TYPE sigma_12_21_multiply[N][N], DATA_TYPE sigma_updated[N][N], int client_selected_num) +// { + +// // #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_11_select complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_select complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_21_select complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_22_select_inverse complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_22_select_inverse complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_21_multiply complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_12_21_multiply complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=2 +// #pragma HLS inline off + +// for (int i = 0; i < N - client_selected_num; i++) +// { +// for (int j = 0; j < client_selected_num; j++) +// { +// //#pragma HLS pipeline II = 1 +// for (int k = 0; k < client_selected_num; k++) +// { +// //#pragma HLS unroll +// #pragma HLS pipeline II = 1 +// sigma_12_22_multiply[i][j] += sigma_12_select[i][k] * sigma_22_select_inverse[k][j]; +// } +// } +// } + +// for (int i = 0; i < N - client_selected_num; i++) +// { +// for (int j = 0; j < N - client_selected_num; j++) +// { +// //#pragma HLS pipeline II = 1 +// for (int k = 0; k < client_selected_num; k++) +// { +// #pragma HLS pipeline II = 1 +// sigma_12_21_multiply[i][j] += sigma_12_22_multiply[i][k] * sigma_21_select[k][j]; +// } +// } +// } + +// for (int i = 0; i < N - client_selected_num; i++) +// { + +// for (int j = 0; j < N - client_selected_num; j++) +// { +// #pragma HLS pipeline II = 1 +// sigma_updated[i][j] = sigma_11_select[i][j] - sigma_12_21_multiply[i][j]; +// } +// } +// } + + + + +void compute_mu_updated (DATA_TYPE mu[N], DATA_TYPE mu_1_select[N_CLIENT], DATA_TYPE mu_2[N], DATA_TYPE delta_l[N], DATA_TYPE mu_updated[N_CLIENT], DATA_TYPE sigma_12_22_multiply[N_CLIENT][C], DATA_TYPE alpha_mu_2_selected[C], int client_selected_num, int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + // #pragma HLS ARRAY_PARTITION variable=mu complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=mu_1_select complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=mu_2 complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=delta_l complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=mu_updated complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=sigma_12_22_multiply complete dim=2 + // #pragma HLS ARRAY_PARTITION variable=alpha_mu_2_selected complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=selected_client_index_table complete dim=1 + // #pragma HLS ARRAY_PARTITION variable=non_selected_client_index_table complete dim=1 + #pragma HLS inline off + + + for (int i = 0; i < client_selected_num;i++) + { + #pragma HLS pipeline II = 1 + alpha_mu_2_selected[i] = delta_l[selected_client_index_table[i]] - mu_2[selected_client_index_table[i]]; + } + + // for (int i = 0; i < client_selected_num; i++) + // { + // printf("alpha_mu_2_selected[%d] = %f\n", i, alpha_mu_2_selected[i]); + // } + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + #pragma HLS pipeline II = 1 + mu_1_select[i] = mu[non_selected_client_index_table[i]]; + } + + + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + //#pragma HLS pipeline II = 1 + for (int j = 0; j < client_selected_num; j++) + { + #pragma HLS pipeline II = 1 + sigma_mu_multiply[i] = sigma_12_22_multiply[i][j] * alpha_mu_2_selected[j]; + } + } + + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + #pragma HLS pipeline II = 1 + mu_updated[i] = mu_1_select[i] + sigma_mu_multiply[i]; + } + + +} + +void update_sigma(DATA_TYPE sigma_dram[N][N], DATA_TYPE sigma_updated[BUFFER_SIZE][N_CLIENT], int non_selected_client_index_table[N_CLIENT], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) +{ + + if (index_outside != iter_total_num - 1) + { + for (int i = 0; i < BUFFER_SIZE; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + + #pragma HLS pipeline II = 1 + sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]] = sigma_updated[i][j]/SCALE; + } + + } + } + + else + + { + + for (int i = 0; i < iter_remaining; i++) + { + for (int j = 0; j < N_CLIENT - client_selected_num; j++) + { + + #pragma HLS pipeline II = 1 + sigma_dram[non_selected_client_index_table[BUFFER_SIZE * index_outside + i]][non_selected_client_index_table[j]] = sigma_updated[i][j]/SCALE; + } + + } + } + +} + + + +void update_sigma_scale(int client_selected_num, DATA_TYPE sigma_dram[N][N], DATA_TYPE sigma_updated[N_CLIENT][N_CLIENT], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT]) +{ + + int total_client_count = N_CLIENT - client_selected_num; + int iter_total_num = total_client_count / BUFFER_SIZE + 1; + int iter_remaining = total_client_count - (iter_total_num - 1) * BUFFER_SIZE; + + //void compute_sigma_12_21_multiply(DATA_TYPE sigma_12_21_multiply[BUFFER_SIZE][N], DATA_TYPE sigma_12_22_multiply[N][C], DATA_TYPE sigma_21_select[C][C], int client_selected_num, int index_outside, int iter_total_num, int iter_remaining) + for (int index_outside = 0; index_outside < iter_total_num; index_outside++) + { + + sigma_11_selection_new(client_selected_num, sigma_dram, index_outside, iter_total_num, iter_remaining); + compute_sigma_12_21_multiply(sigma_12_21_multiply, sigma_12_22_multiply, sigma_21_select, client_selected_num, index_outside, iter_total_num, iter_remaining); + compute_sigma_updated(sigma_11_select, sigma_12_21_multiply, sigma_updated, client_selected_num, index_outside, iter_total_num, iter_remaining); + update_sigma(sigma_dram, sigma_updated, non_selected_client_index_table, client_selected_num, index_outside, iter_total_num, iter_remaining); + } + +} + +// void update_mu_sigma(DATA_TYPE mu[N], DATA_TYPE sigma[N][N], DATA_TYPE mu_updated[N], DATA_TYPE sigma_updated[N][N], int client_selected_num, int non_selected_client_index_table[N]) +// { + +// // #pragma HLS ARRAY_PARTITION variable=mu complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=mu_updated complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=1 +// // #pragma HLS ARRAY_PARTITION variable=sigma_updated complete dim=2 +// // #pragma HLS ARRAY_PARTITION variable=non_selected_client_index_table complete dim=1 +// #pragma HLS inline off + +// for (int i = 0; i < N - client_selected_num; i++) +// { +// #pragma HLS pipeline II = 1 +// mu[non_selected_client_index_table[i]] = mu_updated[i]; +// } + +// for (int i = 0; i < N - client_selected_num; i++) +// { + +// for (int j = 0; j < N - client_selected_num; j++) +// { +// #pragma HLS pipeline II = 1 +// sigma[non_selected_client_index_table[i]][non_selected_client_index_table[j]] = sigma_updated[i][j]; +// } +// } + +// } + +void update_mu(DATA_TYPE mu[N], DATA_TYPE mu_updated[N_CLIENT],int non_selected_client_index_table[N_CLIENT], int client_selected_num ) +{ +#pragma HLS inline off + + for (int i = 0; i < N_CLIENT - client_selected_num; i++) + { + #pragma HLS pipeline II = 1 + mu[non_selected_client_index_table[i]] = mu_updated[i]/SCALE; + } + + +} + +void write_back(DATA_TYPE result[N][N], DATA_TYPE result_dram[N][N]) +{ + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + #pragma HLS pipeline ii = 1 + result_dram[i][j] = result[i][j]; + } + + } +} + +void write_back_mu(DATA_TYPE result[N], DATA_TYPE result_dram[N]) +{ + for (int i = 0; i < N; i++) + { + #pragma HLS pipeline II = 1 + + result_dram[i] = result[i]; + + + } +} + + void write_back_index_table(int client_index_list[C], int selected_client_index_table[C]) +{ + for (int i = 0; i < C; i++) + { + #pragma HLS pipeline II = 1 + client_index_list[i] = selected_client_index_table[i]; + } + + // for (int i = C; i < N; i++) + // { + // client_index_list[i] = 100; + // } +} + + +void client_selection(DATA_TYPE sigma_dram[N][N], DATA_TYPE mu[N], DATA_TYPE a[N], DATA_TYPE beta[N], int client_number) +{ + + for (int i = 0; i < N_CLIENT; i++) + { + #pragma HLS pipeline II = 1 + client_selection_flag[i] = 0; + } + + for (int iter = 0; iter < client_number; iter++) + { + //on_chip_buffer_initialization(mu_bar_accumu, sigma_12_22_multiply, sigma_12_21_multiply, selected_client_index_table, non_selected_client_index_table); + on_chip_buffer_initialization(mu_bar_accumu, selected_client_index_table, non_selected_client_index_table); + load_sigma_1d(sigma_dram); + compute_delta_l(mu, sigma_1d, a, beta, delta_l); + + // for (int i = 0; i < N; i++) + // { + // printf("the current iter is:%d, the value of delta_l is: %f\n", iter, delta_l[i]); + // } + //mu_sigma_selection(mu, sigma, mu_1, mu_2, sigma_12, sigma_22); + //compute_mu_bar_accumu(mu_1, mu_2, sigma_12, sigma_22, delta_l, mu_bar, mu_bar_accumu); + + //void compute_mu_ba_scale(DATA_TYPE mu[N], DATA_TYPE sigma_dram[N][N], DATA_TYPE mu_1[BUFFER_SIZE][N], DATA_TYPE mu_2[N], DATA_TYPE sigma_12[BUFFER_SIZE][N], DATA_TYPE sigma_1d[N], DATA_TYPE sigma_22[N]) + compute_mu_ba_scale(mu, sigma_dram, mu_1, mu_2, sigma_12, sigma_1d, sigma_22); + //compute_mu_ba_scale(mu, sigma, delta_l, mu_bar_accumu); + //sorting(mu_bar_accumu, mu_bar_sorted_data, mu_bar_sorted_index); + int client_selected_num = 0; + //client_selected_num = select_client(client_selection_flag, selected_client_index_table, non_selected_client_index_table); + //DATA_TYPE mu_bar_accumu[N], bool client_selection_flag[N_CLIENT], int selected_client_index_table[C], int non_selected_client_index_table[N_CLIENT] + client_selected_num = sorting(mu_bar_accumu, client_selection_flag, selected_client_index_table, non_selected_client_index_table); + // for (int i = 0; i < N; i++) + // { + + // printf("the current iter is: %d, the value of accumu is: %f\n", iter, mu_bar_accumu[i]); + // } + //sigma_selection(client_selected_num, sigma, client_selection_flag); + sigma_selection_new(client_selected_num, sigma_dram, selected_client_index_table, non_selected_client_index_table); + int inverse_flag = 0; + inverse_matrix_new(sigma_22_select, sigma_22_select_inverse, client_selected_num); + + compute_sigma_12_22_multiply(sigma_12_select, sigma_22_select_inverse, sigma_12_22_multiply, client_selected_num); + compute_mu_updated(mu, mu_1_select, mu_2, delta_l, mu_updated, sigma_12_22_multiply, alpha_mu_2_selected, client_selected_num, selected_client_index_table, non_selected_client_index_table); + update_mu(mu, mu_updated, non_selected_client_index_table, client_selected_num); + + + + update_sigma_scale(client_selected_num, sigma_dram, sigma_updated, selected_client_index_table, non_selected_client_index_table); + + + // compute_sigma_updated(sigma_11_select, sigma_12_select, sigma_22_select_inverse, sigma_12_22_multiply, sigma_12_21_multiply, sigma_updated, client_selected_num); + // compute_mu_updated(mu, mu_1_select, mu_2, delta_l, mu_updated, sigma_12_22_multiply, alpha_mu_2_selected, client_selected_num, selected_client_index_table, non_selected_client_index_table); + // update_mu_sigma(mu, sigma, mu_updated, sigma_updated, client_selected_num, non_selected_client_index_table); + + } + +} + + + +void GP_kernel_float(DATA_TYPE *mu_dram, DATA_TYPE sigma_dram[N][N], DATA_TYPE *a_dram, DATA_TYPE *beta_dram, int client_number_array[10], int client_index_list[C], DATA_TYPE result_dram[N][N], DATA_TYPE result_dram_2[N]) + +{ + #pragma HLS interface m_axi port=mu_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=sigma_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=a_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=beta_dram depth=200 bundle = gmem1 + #pragma HLS interface m_axi port=client_index_list depth=200 bundle = gmem3 + //#pragma HLS interface s_axilite port=client_number + #pragma HLS interface s_axilite port=return + #pragma HLS interface m_axi port=client_number_array depth=200 bundle = gmem3 + + #pragma HLS interface m_axi port=result_dram depth=200 bundle = gmem2 + #pragma HLS interface m_axi port=result_dram_2 depth=200 bundle = gmem2 + + + int client_number = client_number_array[0]; + load_parameters(mu_dram, a_dram, beta_dram); + client_selection(sigma_dram, mu, a, beta, client_number); + //write_back(sigma, result_dram); + write_back_mu(mu, result_dram_2); + write_back_index_table(client_index_list, selected_client_index_table); + + + +} + + + +//int main() +// +//{ +// +// // Seed the random number generator with the current time +// srand(333); +// +// // Define the size of the array +// int arraySize = N_CLIENT; // Change this to the desired size +// int client_number = C; //The maximum number of clients to be selected. +// +// // Create an array to store the random numbers +// DATA_TYPE mu_dram[N]; +// DATA_TYPE a_dram[N]; +// DATA_TYPE sigma_dram[N][N]; +// DATA_TYPE beta_dram[N]; +// +// int client_index_list[C]; +// +// DATA_TYPE result_dram[N][N]; +// DATA_TYPE result_dram_2[N]; +// +// +// float mu_float[N_CLIENT]; +// float a_float[N_CLIENT]; +// float sigma_float[N_CLIENT][N_CLIENT]; +// float beta_float[N_CLIENT]; +// float result_float[N_CLIENT][N_CLIENT]; +// float result_float_2[N_CLIENT]; +// int client_number_array[10]; +// client_number_array[0] = client_number; +// +// +// +// // Generate random numbers in the range [0, 1) +// for (int i = 0; i < arraySize; i++) { +// mu_float[i] = (float)rand() / RAND_MAX; +// printf("the value of mu_float is: %f\n", mu_float[i]); +// +// } +// +// for (int i = 0; i < arraySize; i++) { +// a_float[i] = (float)rand() / RAND_MAX; +// +// } +// +// for (int i = 0; i < arraySize; i++) { +// beta_float[i] = (float)rand() / RAND_MAX; +// +// } +// +// for (int i = 0; i < arraySize; i++) { +// for (int j = 0; j < arraySize; j++) +// { +// sigma_float[i][j] = (float)rand() / RAND_MAX; +// } +// +// } +// +// for (int i = 0; i < N; i++) +// { +// mu_dram[i] = 0; +// a_dram[i] = 0; +// beta_dram[i] = 0; +// for (int j = 0; j < N; j++) +// { +// sigma_dram[i][j] = 0; +// } +// } +// +// +// for (int i = 0; i < arraySize; i++) +// { +// mu_dram[i] = (DATA_TYPE) mu_float[i]; +// a_dram[i] = (DATA_TYPE) a_float[i]; +// beta_dram[i] = (DATA_TYPE) beta_float[i]; +// for (int j = 0; j < arraySize; j++) +// { +// sigma_dram[i][j] = (DATA_TYPE) sigma_float[i][j]; +// } +// } +// +// +// +// +// GP_kernel(mu_dram, sigma_dram, a_dram, beta_dram, client_number_array, client_index_list, result_dram, result_dram_2); +// +// // Print the generated array +// // printf("Random numbers in the range [0, 1):\n"); +// // printf("mu_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%.6f\n", mu[i]); +// // } +// // printf("a_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%.6f\n", a[i]); +// // } +// // printf("beta_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%.6f\n", beta[i]); +// // } +// // printf("sigma_dram:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // for (int j = 0; j < arraySize - 1; j++) +// // { +// // printf("%.6f\n", sigma_12[i][j]); +// // } +// +// // } +// +// // printf("delta_l:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // printf("%d\n", non_selected_client_index_table[i]); +// // } +// +// for (int i = 0; i < arraySize; i++) +// { +// result_float_2[i] = (float) result_dram_2[i]; +// for (int j = 0; j < arraySize; j++) +// { +// result_float[i][j] = (float) result_dram[i][j]; +// } +// +// } +// +// printf("client_index_list:\n"); +// for (int i = 0; i < C; i++) { +// printf("%d\n", client_index_list[i]); +// } +// +// +// printf("mu updated:\n"); +// for (int i = 0; i < arraySize; i++) { +// printf("%.6f\n", result_float_2[i]); +// } +// // printf("sigma_22:\n"); +// // for (int i = 0; i < arraySize; i++) { +// // for (int j = 0; j < arraySize; j++) +// // { +// // printf("%.6f\n", sigma_dram[i][j]); +// // } +// +// // } +// +// return 0; +//} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/conv1x1_new.cc b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/conv1x1_new.cc new file mode 100644 index 000000000000..fbe3730eeba6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/conv1x1_new.cc @@ -0,0 +1,157 @@ +// Conv 1x1 PE + +#include "net_hls.h" +#include +#include +#include +#include "hls_stream.h" + +FIX_FM_acc compute_engine_16_new(FIX_WT w0, FIX_FM b0, + FIX_WT w1, FIX_FM b1, + FIX_WT w2, FIX_FM b2, + FIX_WT w3, FIX_FM b3, + FIX_WT w4, FIX_FM b4, + FIX_WT w5, FIX_FM b5, + FIX_WT w6, FIX_FM b6, + FIX_WT w7, FIX_FM b7, + FIX_WT w8, FIX_FM b8, + FIX_WT w9, FIX_FM b9, + FIX_WT w10, FIX_FM b10, + FIX_WT w11, FIX_FM b11, + FIX_WT w12, FIX_FM b12, + FIX_WT w13, FIX_FM b13, + FIX_WT w14, FIX_FM b14, + FIX_WT w15, FIX_FM b15) +{ + FIX_32_10 mul0, mul1, mul2, mul3, mul4, mul5, mul6, mul7; + FIX_32_10 mul8, mul9, mul10, mul11, mul12, mul13, mul14, mul15; + FIX_32_10 add0, add1, add2, add3, add4, add5, add6; + FIX_32_10 add7, add8, add9, add10, add11, add12, add13, add14; + + mul0 = w0 * b0; + mul1 = w1 * b1; + mul2 = w2 * b2; + mul3 = w3 * b3; + mul4 = w4 * b4; + mul5 = w5 * b5; + mul6 = w6 * b6; + mul7 = w7 * b7; + mul8 = w8 * b8; + mul9 = w9 * b9; + mul10 = w10 * b10; + mul11 = w11 * b11; + mul12 = w12 * b12; + mul13 = w13 * b13; + mul14 = w14 * b14; + mul15 = w15 * b15; + + add0 = mul0 + mul1; + add1 = mul2 + mul3; + add2 = mul4 + mul5; + add3 = mul6 + mul7; + add4 = mul8 + mul9; + add5 = mul10 + mul11; + add6 = mul12 + mul13; + add7 = mul14 + mul15; + + add8 = add0 + add1; + add9 = add2 + add3; + add10 = add4 + add5; + add11 = add6 + add7; + + add12 = add8 + add9; + add13 = add10 + add11; + + add14 = add12 + add13; + + return add14; + +} + + + + +void load_weights_new(FIX_WT weights[32][32], FIX_WT weight_buf[32][16], int CI) +{ + for (int ci = 0; ci < 16; ci++) { + for (int co = 0; co < 32; co++) { +#pragma HLS pipeline + weight_buf[co][ci] = weights[co][ci + CI]; + } + } +} + +void compute_1x1(FIX_FM bottom[32][44][84], FIX_FM_acc top[32][44][84], FIX_WT weight_buf[32][16], uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax, int ci) { + for (uint8 h = xmin; h < xmax; h++) { + for (uint8 w = ymin; w < ymax; w++) { + + + FIX_FM_acc a = 0; + FIX_FM_acc b = 0; + for (int coo = 0; coo < 32; coo++) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + a = compute_engine_16_new( + weight_buf[coo][0], bottom[ci + 0][h][w], + weight_buf[coo][1], bottom[ci + 1][h][w], + weight_buf[coo][2], bottom[ci + 2][h][w], + weight_buf[coo][3], bottom[ci + 3][h][w], + weight_buf[coo][4], bottom[ci + 4][h][w], + weight_buf[coo][5], bottom[ci + 5][h][w], + weight_buf[coo][6], bottom[ci + 6][h][w], + weight_buf[coo][7], bottom[ci + 7][h][w], + weight_buf[coo][8], bottom[ci + 8][h][w], + weight_buf[coo][9], bottom[ci + 9][h][w], + weight_buf[coo][10], bottom[ci + 10][h][w], + weight_buf[coo][11], bottom[ci + 11][h][w], + weight_buf[coo][12], bottom[ci + 12][h][w], + weight_buf[coo][13], bottom[ci + 13][h][w], + weight_buf[coo][14], bottom[ci + 14][h][w], + weight_buf[coo][15], bottom[ci + 15][h][w]); + b = top[coo][h][w] + a; + top[coo][h][w] = b; + + } + } + } +} + + + + +void CONV_1x1_new(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][32], + int index,uint8 mask_bound[16]) +{ + +#pragma HLS array_partition variable=top dim=1 complete +#pragma HLS array_partition variable=bottom dim=1 complete + +#pragma HLS array_partition variable=weights dim=1 complete +#pragma HLS array_partition variable=mask_bound dim=1 complete + + + FIX_WT weight_buf[32][16]; +#pragma HLS array_partition variable=weight_buf dim=1 complete +#pragma HLS array_partition variable=weight_buf dim=2 complete + + + for (int ci = 0; ci < 32; ci += 16) { + + load_weights_new(weights, weight_buf, ci); + + int buf_idx = ci / 16; + if (index == 0) { + compute_1x1(bottom, top, weight_buf, 1, 43, 1, 83, ci); + } + if (index == 1) { + compute_1x1(bottom, top, weight_buf, mask_bound[0] + 1, mask_bound[1] + 1, mask_bound[2] + 1, mask_bound[3] + 1, ci); + compute_1x1(bottom, top, weight_buf, mask_bound[4] + 1, mask_bound[5] + 1, mask_bound[6] + 3, mask_bound[7] + 3, ci); + compute_1x1(bottom, top, weight_buf, mask_bound[8] + 3, mask_bound[9] + 3, mask_bound[10] + 1, mask_bound[11] + 1, ci); + compute_1x1(bottom, top, weight_buf, mask_bound[12] + 3, mask_bound[13] + 3, mask_bound[14] + 3, mask_bound[15] + 3, ci); + } + + } + +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/dwconv3x3_new.cc b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/dwconv3x3_new.cc new file mode 100644 index 000000000000..1de3b23f8524 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/dwconv3x3_new.cc @@ -0,0 +1,98 @@ +// dw_conv 3x3 + +#include "net_hls.h" +#include +#include +#include +#include "hls_stream.h" +#include "hls_math.h" + +//using namespace hls; +//using namespace std; + +inline FIX_FM relu_single(FIX_FM d) { + if (d > 6) + return 6; + if (d < 0) + return 0; + return d; +} + +void compute_3x3(FIX_FM bottom[32][44][84], FIX_FM top[32][44][84], FIX_WT weights[32][3][3], uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax) { +//#pragma HLS array_partition variable=top dim=1 complete +//#pragma HLS array_partition variable=bottom dim=1 complete +//#pragma HLS array_partition variable=weights dim=1 complete + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + for (uint8 h =xmin ; h +#include +#include +#include "hls_stream.h" + + +void compute_DW_CONV_5x5(FIX_FM bottom[32][44][84], FIX_FM_acc top[32][44][84], FIX_WT weights[32][5][5], int imin, int imax, int jmin, int jmax, int hmin, int hmax, int wmin, int wmax, int offsetx, int offsety) { +//#pragma HLS array_partition variable=top dim=1 complete +//#pragma HLS array_partition variable=bottom dim=1 complete +//#pragma HLS array_partition variable=weights dim=1 complete + for (int i = imin; i < imax; i++) { + for (int j = jmin; j < jmax; j++) { + for (int h = hmin; h <= hmax; h++) { + for (int w = wmin; w <= wmax; w++) { + + FIX_FM_acc a = 0; + FIX_FM_acc b = 0; + for (int co = 0; co < 32; co++) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + a = weights[co][i][j] * bottom[co][h + offsetx*22 + i - 2][w + offsety*42 + j - 2]; + b = top[co][h + offsetx*22][w + offsety*42] + a; + top[co][h + offsetx*22][w + offsety*42] = b; + } + } + } + } + } +} + + +void DW_CONV_5x5(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][5][5], + FIX_WT bias[32], + int offsetx, + int offsety + ) +{ + +//#pragma HLS array_partition variable=top dim=1 complete +//#pragma HLS array_partition variable=bottom dim=1 complete +//#pragma HLS array_partition variable=weights dim=1 complete +//#pragma HLS array_partition variable=bias dim=1 complete + + compute_DW_CONV_5x5(bottom, top, weights, 0, 5, 0, 5, 2 + offsetx * 22, 19 + offsetx * 22, 2 + offsety * 42, 39 + offsety * 42, 0, 0); + compute_DW_CONV_5x5(bottom, top, weights, 1, 5, 0, 5, 1, 1, 2 + offsety * 42, 39 + offsety * 42, offsetx, 0); + compute_DW_CONV_5x5(bottom, top, weights, 0, 4, 0, 5, 20, 20, 2 + offsety * 42, 39 + offsety * 42, offsetx, 0); + compute_DW_CONV_5x5(bottom, top, weights, 0, 5, 1, 5, 2 + offsetx * 22, 19 + offsetx * 22, 1, 1, 0, offsety); + compute_DW_CONV_5x5(bottom, top, weights, 0, 5, 0, 4, 2 + offsetx * 22, 19 + offsetx * 22, 40, 40, 0, offsety); + compute_DW_CONV_5x5(bottom, top, weights, 1, 5, 1, 5, 1, 1, 1, 1, offsetx, offsety); + compute_DW_CONV_5x5(bottom, top, weights, 0, 4, 1, 5, 20, 20, 1, 1, offsetx, offsety); + compute_DW_CONV_5x5(bottom, top, weights, 1, 5, 0, 4, 1, 1, 40, 40, offsetx, offsety); + compute_DW_CONV_5x5(bottom, top, weights, 0, 4, 0, 4, 20, 20, 40, 40, offsetx, offsety); + +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.cc b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.cc new file mode 100644 index 000000000000..061429b9e617 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.cc @@ -0,0 +1,1807 @@ +#include "net_hls.h" +#include +#include +#include +#include + +#include + +using namespace std; +extern FILE* fo; + +// feature map buffers +FIX_FM FM_buf1[32][44][84]; +FIX_FM FM_buf2[32][44][84]; +FIX_FM FM_buf3[32][44][84]; +FIX_FM FM_buf4[32][44][84]; +FIX_FM_acc FM_buf_acc[32][44][84]; + +//confidence mask buffer +FIX_FM mask[13][13]; + + +// weight buffers +FIX_WT weight_buf_1x1[4][32][32]; +FIX_WT weight_buf_3x3[4][32][3][3]; +FIX_WT bias_buf[4][32]; +FIX_WT weight_buf_5x5[3][32][5][5]; + +void compute_bounding_box(float predict_box[4][5], int constant[4][3],uint8 mask_bound[16]) +{ + FIX_32_4 conf_thresh = -100.0; + int conf_j = 0; + int conf_m = 0; + int conf_n = 0; + FIX_32_4 conf_box1 = 0.0; + FIX_32_4 conf_box2 = 0.0; + //int h = 20; + //int w = 40; + uint8 xmin1 = mask_bound[0] + 1; + uint8 xmax1 = mask_bound[1] + 1; + uint8 ymin1 = mask_bound[2] + 1; + uint8 ymax1 = mask_bound[3] + 1; + + uint8 xmin2 = mask_bound[4] + 1; + uint8 xmax2 = mask_bound[5] + 1; + uint8 ymin2 = mask_bound[6] + 3; + uint8 ymax2 = mask_bound[7] + 3; + + uint8 xmin3 = mask_bound[8] + 3; + uint8 xmax3 = mask_bound[9] + 3; + uint8 ymin3 = mask_bound[10] + 1; + uint8 ymax3 = mask_bound[11] + 1; + + uint8 xmin4 = mask_bound[12] + 3; + uint8 xmax4 = mask_bound[13] + 3; + uint8 ymin4 = mask_bound[14] + 3; + uint8 ymax4 = mask_bound[15] + 3; + + //// 0 + for (uint8 m =xmin1 ; m < xmax1; m++) { + for (uint8 n = ymin1; n < ymax1; n++) { + + conf_box1 = FM_buf_acc[4][m][n]; + if (conf_box1 > conf_thresh) { + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for (uint8 m = xmin1; m < xmax1; m++) { + for (uint8 n = ymin1; n < ymax1; n++) { + + conf_box2 = FM_buf_acc[9][m][n]; + if (conf_box2 > conf_thresh) { + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if (conf_j == 0) { + // first bounding box + predict_box[0][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[0][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[0][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[0][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[0][4] = conf_thresh; + + } + else if (conf_j == 1) { + // second bounding box + predict_box[0][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[0][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[0][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[0][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[0][4] = conf_thresh; + } + + constant[0][0] = conf_j; + constant[0][1] = conf_n - 1; + constant[0][2] = conf_m - 1; + + //// 1 + conf_thresh = -100.0; + conf_j = 0; + conf_m = 0; + conf_n = 0; + conf_box1 = 0.0; + conf_box2 = 0.0; + + for (int m = xmin2; m < xmax2; m++) { + for (int n = ymin2; n < ymax2; n++) { + + conf_box1 = FM_buf_acc[4][m][n]; + if (conf_box1 > conf_thresh) { + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for (int m = xmin2; m < xmax2; m++) { + for (int n = ymin2; n < ymax2; n++) { + + conf_box2 = FM_buf_acc[9][m][n]; + if (conf_box2 > conf_thresh) { + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if (conf_j == 0) { + // first bounding box + predict_box[1][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[1][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[1][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[1][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[1][4] = conf_thresh; + + } + else if (conf_j == 1) { + // second bounding box + predict_box[1][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[1][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[1][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[1][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[1][4] = conf_thresh; + } + + constant[1][0] = conf_j; + constant[1][1] = conf_n - 43; + constant[1][2] = conf_m - 1; + + //// 2 + conf_thresh = -100.0; + conf_j = 0; + conf_m = 0; + conf_n = 0; + conf_box1 = 0.0; + conf_box2 = 0.0; + + for (int m = xmin3; m < xmax3; m++) { + for (int n = ymin3; n < ymax3; n++) { + + conf_box1 = FM_buf_acc[4][m][n]; + if (conf_box1 > conf_thresh) { + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for (int m = xmin3; m < xmax3; m++) { + for (int n = ymin3; n < ymax3; n++) { + + conf_box2 = FM_buf_acc[9][m][n]; + if (conf_box2 > conf_thresh) { + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if (conf_j == 0) { + // first bounding box + predict_box[2][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[2][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[2][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[2][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[2][4] = conf_thresh; + + } + else if (conf_j == 1) { + // second bounding box + predict_box[2][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[2][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[2][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[2][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[2][4] = conf_thresh; + } + + constant[2][0] = conf_j; + constant[2][1] = conf_n - 1; + constant[2][2] = conf_m - 23; + + //// 3 + conf_thresh = -100.0; + conf_j = 0; + conf_m = 0; + conf_n = 0; + conf_box1 = 0.0; + conf_box2 = 0.0; + + for (int m = xmin4; m < xmax4; m++) { + for (int n = ymin4; n < ymax4; n++) { + + conf_box1 = FM_buf_acc[4][m][n]; + if (conf_box1 > conf_thresh) { + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for (int m = xmin4; m < xmax4; m++) { + for (int n = ymin4; n < ymax4; n++) { + + conf_box2 = FM_buf_acc[9][m][n]; + if (conf_box2 > conf_thresh) { + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if (conf_j == 0) { + // first bounding box + predict_box[3][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[3][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[3][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[3][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[3][4] = conf_thresh; + + } + else if (conf_j == 1) { + // second bounding box + predict_box[3][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[3][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[3][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[3][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[3][4] = conf_thresh; + } + + constant[3][0] = conf_j; + constant[3][1] = conf_n - 43; + constant[3][2] = conf_m - 23; + + +} + + + + + + + + +inline FIX_FM relu_single( FIX_FM d ) { + if( d > 6 ) + return 6; + if( d < 0 ) + return 0; + return d; +} + + + +void compute_relu_copy_buf_to_DDR_new(uint512* dest, int buf_id, FIX_FM src[32][44][84], uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax) { + uint512* dest_ptr = dest + 44 * 84 * buf_id + (xmin) * 84; + for (uint8 h = xmin; h < xmax; h++) { + + + for (uint8 w = ymin; w < ymax; w++) { + + + uint512 DATA = 0; + for (int c = 0; c < 32; c++) { +//#pragma HLS pipeline II = 1 +//#pragma HLS unroll + FIX_FM d = relu_single(src[c][h][w]); + DATA.range(FM_RG + 16 * c, 16 * c) = d.range(FM_RG, 0); + } + dest_ptr[w].range(511, 0) = DATA.range(511, 0); + } + + dest_ptr += 84; + } +} + +void relu_copy_buf_to_DDR_new(uint512* dest, int buf_id, FIX_FM src[32][44][84], int offset_h, int offset_w, int index,uint8 mask_bound[16]) +{ + uint512* dest_ptr = dest + 44 * 84 * buf_id + (offset_h * 22) * 84 + (offset_w * 42); + if (index == 0) { + compute_relu_copy_buf_to_DDR_new(dest, buf_id, src, 0, 44, 0, 84); + } + else { + compute_relu_copy_buf_to_DDR_new(dest, buf_id, src, mask_bound[0] + 1, mask_bound[1] + 1, mask_bound[2] + 1, mask_bound[3] + 1); + compute_relu_copy_buf_to_DDR_new(dest, buf_id, src, mask_bound[4] + 1, mask_bound[5] + 1, mask_bound[6] + 3, mask_bound[7] + 3); + compute_relu_copy_buf_to_DDR_new(dest, buf_id, src, mask_bound[8] + 3, mask_bound[9] + 3, mask_bound[10] + 1, mask_bound[11] + 1); + compute_relu_copy_buf_to_DDR_new(dest, buf_id, src, mask_bound[12] + 3, mask_bound[13] + 3, mask_bound[14] + 3, mask_bound[15] + 3); + } + +} + + + +void compute_relu_copy_buf_to_DDR_acc_new(uint512* dest, int buf_id, FIX_FM_acc src[32][44][84], uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax) { + uint512* dest_ptr = dest + 44 * 84 * buf_id + (xmin) * 84; + for (uint8 h = xmin; h < xmax; h++) { + + + for (uint8 w = ymin; w < ymax; w++) { + + + uint512 DATA = 0; + for (int c = 0; c < 32; c++) { +//#pragma HLS pipeline II = 1 +//#pragma HLS unroll + FIX_FM d = relu_single(src[c][h][w]); + DATA.range(FM_RG + 16 * c, 16 * c) = d.range(FM_RG, 0); + } + dest_ptr[w].range(511, 0) = DATA.range(511, 0); + } + + dest_ptr += 84; + } +} + + + +void relu_copy_buf_to_DDR_acc_new(uint512* dest, int buf_id, FIX_FM_acc src[32][44][84], int offset_h, int offset_w, int index,uint8 mask_bound[16]) +{ + uint512* dest_ptr = dest + 44 * 84 * buf_id + (offset_h * 22) * 84 + (offset_w * 42); + if (index == 0) { + compute_relu_copy_buf_to_DDR_acc_new(dest, buf_id, src, 0, 44, 0, 84); + } + else { + compute_relu_copy_buf_to_DDR_acc_new(dest, buf_id, src, mask_bound[0] + 1, mask_bound[1] + 1, mask_bound[2] + 1, mask_bound[3] + 1); + compute_relu_copy_buf_to_DDR_acc_new(dest, buf_id, src, mask_bound[4] + 1, mask_bound[5] + 1, mask_bound[6] + 3, mask_bound[7] + 3); + compute_relu_copy_buf_to_DDR_acc_new(dest, buf_id, src, mask_bound[8] + 3, mask_bound[9] + 3, mask_bound[10] + 1, mask_bound[11] + 1); + compute_relu_copy_buf_to_DDR_acc_new(dest, buf_id, src, mask_bound[12] + 3, mask_bound[13] + 3, mask_bound[14] + 3, mask_bound[15] + 3); + } + + +} + + +void compute_load_buf_from_DDR_new(FIX_FM dest[32][44][84], uint512* src, int buf_id, uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax) { + uint512* src_ptr = src + 44 * 84 * buf_id + (xmin) * 84; + + for (int h = xmin; h < xmax; h++) { + + for (int w = ymin; w < ymax; w++) { + + + uint512 DATA = src_ptr[w]; + for (int c = 0; c < 32; c++) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + dest[c][h][w].range(FM_RG, 0) = DATA.range(FM_RG + c * 16, 16 * c); + } + } + + src_ptr += 84; + } +} + +void load_buf_from_DDR_new(FIX_FM dest[32][44][84], uint512* src, int buf_id, int index, uint8 mask_bound[16]) +{ + if (index == 0) { + compute_load_buf_from_DDR_new(dest, src, buf_id, 0, 44, 0, 84); + } + else { + compute_load_buf_from_DDR_new(dest, src, buf_id, mask_bound[0] + 1, mask_bound[1] + 1, mask_bound[2] + 1, mask_bound[3] + 1); + compute_load_buf_from_DDR_new(dest, src, buf_id, mask_bound[4] + 1, mask_bound[5] + 1, mask_bound[6] + 3, mask_bound[7] + 3); + compute_load_buf_from_DDR_new(dest, src, buf_id, mask_bound[8] + 3, mask_bound[9] + 3, mask_bound[10] + 1, mask_bound[11] + 1); + compute_load_buf_from_DDR_new(dest, src, buf_id, mask_bound[12] + 3, mask_bound[13] + 3, mask_bound[14] + 3, mask_bound[15] + 3); + } +} + +void compute_load_buf_from_DDR_new_branch(FIX_FM dest[32][44][84], uint512* src, int buf_id, int number,int cmin, int offset) { + uint512* src_ptr = src; + + src_ptr = src + 44 * 84 * (buf_id + number); + + for (int h = 0; h < 44; h++) { + + for (int w = 0; w < 84; w++) { + + + uint512 DATA = src_ptr[w]; + for (int c = 0; c < 32; c = c + 6) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + if (c < 32 - cmin) { + dest[c / 6 + offset][h][w].range(FM_RG, 0) = DATA.range(FM_RG + (c+cmin) * 16, 16 * (c+cmin)); + } + + + } + } + src_ptr += 84; + } + + +} + +void compute_load_buf_from_DDR_new_branch_channel(FIX_FM dest[32][44][84], uint512* src, int buf_id, int offset1, int offset2, int offset3) { + + compute_load_buf_from_DDR_new_branch(dest, src, buf_id, 0, 0 + offset1 - ((0 + offset1) / 6) * 6, 0); + compute_load_buf_from_DDR_new_branch(dest, src, buf_id, 1, 4 + offset1 - ((4 + offset1) / 6) * 6, 6 - offset2); + compute_load_buf_from_DDR_new_branch(dest, src, buf_id, 2, 2 + offset1 - ((2 + offset1) / 6) * 6, 11 - offset3); + compute_load_buf_from_DDR_new_branch(dest, src, buf_id, 3, 0 + offset1 - ((0 + offset1) / 6) * 6, 16); + compute_load_buf_from_DDR_new_branch(dest, src, buf_id, 4, 4 + offset1 - ((4 + offset1) / 6) * 6, 22 - offset2); + compute_load_buf_from_DDR_new_branch(dest, src, buf_id, 5, 2 + offset1 - ((2 + offset1) / 6) * 6, 27 - offset3); +} + +void load_weight_1x1_from_axi( FIX_WT dest[32][32], uint512 src[32]) +{ + + for(int ci = 0; ci < 32; ci++) { + + uint512 DATA = 0; + DATA.range(511, 0) = src[ci].range(511, 0); + for(int co = 0; co < 32; co++) { +//#pragma HLS pipeline +//#pragma HLS unroll + dest[co][ci].range(WT_RG, 0) = DATA.range(WT_RG + co*16, co*16); + } + } +} + + + +void load_weight_3x3_from_axi( FIX_WT dest[32][3][3], uint512 src[3][3]) +{ + for(int m = 0; m < 3; m++) { + for(int n = 0; n < 3; n++) { + + uint512 DATA = 0; + DATA.range(511, 0) = src[m][n].range(511, 0); + for(int c = 0; c < 32; c++) { +//#pragma HLS pipeline +//#pragma HLS unroll + + dest[c][m][n].range(WT_RG, 0) = DATA.range(WT_RG + c*16, c*16); + } + } + } +} + + +void load_weight_5x5_from_axi(FIX_WT dest[32][5][5], uint512 src[5][5]) +{ + + for (int m = 0; m < 5; m++) { + for (int n = 0; n < 5; n++) { +// + uint512 DATA = 0; + DATA.range(511, 0) = src[m][n].range(511, 0); + for (int co = 0; co < 32; co++) { +//#pragma HLS pipeline +//#pragma HLS unroll + + dest[co][m][n].range(WT_RG, 0) = DATA.range(WT_RG + co * 16, co * 16); + } + } + } +} + + +void load_bias_from_axi(FIX_WT dest[32], uint512 src) +{ + for(int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + dest[c].range(WT_RG, 0) = src.range(WT_RG + c*16, c*16); + } +} + +void compute_set_bias_1x1_new(FIX_FM_acc buf[32][44][84], FIX_WT bias[32], uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax) { + for (uint8 h = xmin; h < xmax; h+=2) { + for (uint8 w = ymin; w < ymax; w++) { +//#pragma HLS pipeline + for (int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + buf[c][h][w] = bias[c]; + buf[c][h + 1][w] = bias[c]; + + } + } + } +} + +void set_bias_1x1_new(FIX_FM_acc buf[32][44][84], FIX_WT bias[32],int index, uint8 mask_bound[16]) +{ + if (index == 0) { + compute_set_bias_1x1_new(buf, bias, 1, 43, 1, 83); + + } + else { + compute_set_bias_1x1_new(buf, bias, mask_bound[0] + 1, mask_bound[1] + 1, mask_bound[2] + 1, mask_bound[3] + 1); + compute_set_bias_1x1_new(buf, bias, mask_bound[4] + 1, mask_bound[5] + 1, mask_bound[6] + 3, mask_bound[7] + 3); + compute_set_bias_1x1_new(buf, bias, mask_bound[8] + 3, mask_bound[9] + 3, mask_bound[10] + 1, mask_bound[11] + 1); + compute_set_bias_1x1_new(buf, bias, mask_bound[12] + 3, mask_bound[13] + 3, mask_bound[14] + 3, mask_bound[15] + 3); + } + +} + +void compute_set_bias_3x3_new(FIX_FM buf[32][44][84], FIX_WT bias[32], uint8 xmin, uint8 xmax, uint8 ymin, uint8 ymax) { + for (uint8 h = xmin; h < xmax; h+=2) { + for (uint8 w = ymin; w < ymax; w++) { +//#pragma HLS pipeline + for (int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + buf[c][h][w] = bias[c]; + buf[c][h + 1][w] = bias[c]; + + } + } + } +} + + + + + + +void set_bias_3x3_new(FIX_FM buf[32][44][84], FIX_WT bias[32], int index, uint8 mask_bound[16]) +{ + if (index == 0) { + compute_set_bias_3x3_new(buf, bias, 1, 43, 1, 83); + + } + else { + compute_set_bias_3x3_new(buf, bias, mask_bound[0] + 1, mask_bound[1] + 1, mask_bound[2] + 1, mask_bound[3] + 1); + compute_set_bias_3x3_new(buf, bias, mask_bound[4] + 1, mask_bound[5] + 1, mask_bound[6] + 3, mask_bound[7] + 3); + compute_set_bias_3x3_new(buf, bias, mask_bound[8] + 3, mask_bound[9] + 3, mask_bound[10] + 1, mask_bound[11] + 1); + compute_set_bias_3x3_new(buf, bias, mask_bound[12] + 3, mask_bound[13] + 3, mask_bound[14] + 3, mask_bound[15] + 3); + } + + +} + + + + + +void set_bias_5x5(FIX_FM_acc buf[32][44][84], FIX_WT bias[32]) +{ + for (int h = 1; h <= 42; h += 2) { + for (int w = 1; w <= 82; w++) { +//#pragma HLS pipeline + for (int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + buf[c][h][w] = bias[c]; + buf[c][h + 1][w] = bias[c]; + } + } + } +} + + + +void load_dw1_pool_from_DDR( uint512* ddr_dw1_pool_burst, + FIX_FM buf[32][44][84], + int ch, int col, int row, int offset_h, int offset_w) +{ + uint512* ddr_dw1_pool_burst_ptr =ddr_dw1_pool_burst + ch*82*2*162*2 + (col*40 + offset_h*2)*162*2 + (row*80 + offset_w*2); + + for(int h = 0; h < 42; h++) { + for(int w = 0; w < 82; w++) { +//#pragma HLS pipeline + uint512 DATA = 0; + DATA.range(511, 0) = ddr_dw1_pool_burst_ptr[w].range(511, 0); + for(int c = 0; c < 32; c++) { +//#pragma HLS pipeline +//#pragma HLS unroll + + buf[c][h][w].range(FM_RG, 0) = DATA.range(FM_RG + c*16, c*16); + } + } + ddr_dw1_pool_burst_ptr += 162*2; + } +} + + + +void load_dw2_pool_from_DDR( uint512* ddr_dw2_pool_burst, + FIX_FM buf[32][44][84], + int ch, int col, int row, int offset_h, int offset_w) +{ + uint512* ddr_dw2_pool_burst_ptr = ddr_dw2_pool_burst + ch*42*2*82*2 + (col*40 + offset_h*2)*82*2 + (row*80 + offset_w*2); + + for(int h = 0; h < 42; h++) { + for(int w = 0; w < 82; w++) { +//#pragma HLS pipeline + uint512 DATA = 0; + DATA.range(511, 0) = ddr_dw2_pool_burst_ptr[w].range(511, 0); + for(int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + buf[c][h][w].range(FM_RG, 0) = DATA.range(FM_RG + c*16, c*16); + } + } + ddr_dw2_pool_burst_ptr += 82*2; + } +} + + + + +void clear_buffer( FIX_FM_acc buf[32][44][84] ) +{ + for(int h = 0; h < 44; h+=2) { + for(int w = 0; w < 84; w++) { +//#pragma HLS pipeline + for(int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + buf[c][h ][w] = 0; + buf[c][h+1][w] = 0; + } + } + } +} + +void clear_buffer_new(FIX_FM buf[32][44][84]) +{ + for (int h = 0; h < 44; h += 2) { + for (int w = 0; w < 84; w++) { +//#pragma HLS pipeline + for (int c = 0; c < 32; c++) { +//#pragma HLS pipeline +//#pragma HLS unroll + buf[c][h][w] = 0; + buf[c][h + 1][w] = 0; + } + } + } +} + +void clear_mask(FIX_FM_acc buf[16][16]) +{ + for (int h = 0; h < 16; h += 2) { + +//#pragma HLS pipeline + for (int w = 0; w < 16; w++) { + +//#pragma HLS pipeline +//#pragma HLS unroll + buf[h][w] = 0; + buf[h + 1][w] = 0; + } + } + + + +} + + + +FIX_FM img_norm_ch[256] = { + -2.000000, -1.984314, -1.968627, -1.952941, -1.937255, -1.921569, -1.905882, -1.890196, -1.874510, -1.858824, -1.843137, -1.827451, -1.811765, -1.796078, -1.780392, -1.764706, -1.749020, + -1.733333, -1.717647, -1.701961, -1.686275, -1.670588, -1.654902, -1.639216, -1.623529, -1.607843, -1.592157, -1.576471, -1.560784, -1.545098, -1.529412, -1.513725, -1.498039, + -1.482353, -1.466667, -1.450980, -1.435294, -1.419608, -1.403922, -1.388235, -1.372549, -1.356863, -1.341176, -1.325490, -1.309804, -1.294118, -1.278431, -1.262745, -1.247059, + -1.231373, -1.215686, -1.200000, -1.184314, -1.168627, -1.152941, -1.137255, -1.121569, -1.105882, -1.090196, -1.074510, -1.058824, -1.043137, -1.027451, -1.011765, -0.996078, + -0.980392, -0.964706, -0.949020, -0.933333, -0.917647, -0.901961, -0.886275, -0.870588, -0.854902, -0.839216, -0.823529, -0.807843, -0.792157, -0.776471, -0.760784, -0.745098, + -0.729412, -0.713725, -0.698039, -0.682353, -0.666667, -0.650980, -0.635294, -0.619608, -0.603922, -0.588235, -0.572549, -0.556863, -0.541176, -0.525490, -0.509804, -0.494118, + -0.478431, -0.462745, -0.447059, -0.431373, -0.415686, -0.400000, -0.384314, -0.368627, -0.352941, -0.337255, -0.321569, -0.305882, -0.290196, -0.274510, -0.258824, -0.243137, + -0.227451, -0.211765, -0.196078, -0.180392, -0.164706, -0.149020, -0.133333, -0.117647, -0.101961, -0.086275, -0.070588, -0.054902, -0.039216, -0.023529, -0.007843, 0.007843, + 0.023529, 0.039216, 0.054902, 0.070588, 0.086275, 0.101961, 0.117647, 0.133333, 0.149020, 0.164706, 0.180392, 0.196078, 0.211765, 0.227451, 0.243137, 0.258824, + 0.274510, 0.290196, 0.305882, 0.321569, 0.337255, 0.352941, 0.368627, 0.384314, 0.400000, 0.415686, 0.431373, 0.447059, 0.462745, 0.478431, 0.494118, 0.509804, + 0.525490, 0.541176, 0.556863, 0.572549, 0.588235, 0.603922, 0.619608, 0.635294, 0.650980, 0.666667, 0.682353, 0.698039, 0.713725, 0.729412, 0.745098, 0.760784, + 0.776471, 0.792157, 0.807843, 0.823529, 0.839216, 0.854902, 0.870588, 0.886275, 0.901961, 0.917647, 0.933333, 0.949020, 0.964706, 0.980392, 0.996078, 1.011765, + 1.027451, 1.043137, 1.058824, 1.074510, 1.090196, 1.105882, 1.121569, 1.137255, 1.152941, 1.168627, 1.184314, 1.200000, 1.215686, 1.231373, 1.247059, 1.262745, + 1.278431, 1.294118, 1.309804, 1.325490, 1.341176, 1.356863, 1.372549, 1.388235, 1.403922, 1.419608, 1.435294, 1.450980, 1.466667, 1.482353, 1.498039, 1.513725, + 1.529412, 1.545098, 1.560784, 1.576471, 1.592157, 1.607843, 1.623529, 1.639216, 1.654902, 1.670588, 1.686275, 1.701961, 1.717647, 1.733333, 1.749020, 1.764706, + 1.780392, 1.796078, 1.811765, 1.827451, 1.843137, 1.858824, 1.874510, 1.890196, 1.905882, 1.921569, 1.937255, 1.952941, 1.968627, 1.984314, 2.000000 +}; + + + +void load_image_chunk_norm(FIX_FM img_buf[32][44][84], uint8 image_in_raw_pad_burst[3*162*2*322*2], + int col, int row, int offset_h = 0, int offset_w = 0) +{ + uint8* image_in_raw_pad_burst_ptr; + + image_in_raw_pad_burst_ptr = image_in_raw_pad_burst + (col*40 + offset_h*2)*322*2 + row*80 + offset_w*2; + + for(int i = 0; i < 44; i++) { + for(int j = 0; j < 84; j++) { +//#pragma HLS pipeline + img_buf[0][i][j] = img_norm_ch[((image_in_raw_pad_burst_ptr[j])).to_uint()]; + } + image_in_raw_pad_burst_ptr += 322*2; + } + + image_in_raw_pad_burst_ptr = image_in_raw_pad_burst + 1*162*2*322*2 + (col*40 + offset_h*2)*322*2 + row*80 + offset_w*2; + for(int i = 0; i < 44; i++) { + for(int j = 0; j < 84; j++) { +//#pragma HLS pipeline + img_buf[1][i][j] = img_norm_ch[((image_in_raw_pad_burst_ptr[j])).to_uint()]; + } + image_in_raw_pad_burst_ptr += 322*2; + } + + image_in_raw_pad_burst_ptr = image_in_raw_pad_burst + 2*162*2*322*2 + (col*40 + offset_h*2)*322*2 + row*80 + offset_w*2; + for(int i = 0; i < 44; i++) { + for(int j = 0; j < 84; j++) { +//#pragma HLS pipeline + img_buf[2][i][j] = img_norm_ch[((image_in_raw_pad_burst_ptr[j])).to_uint()]; + } + image_in_raw_pad_burst_ptr += 322*2; + } +} + + +void Relu6_3x3( FIX_FM buf[32][44][84]) +{ + for(int h = 1; h <= 42; h+=2) { + for(int w = 1; w <= 82; w++) { + + for(int c = 0; c < 32; c++) { +//#pragma HLS unroll +//#pragma HLS pipeline + buf[c][h ][w] = relu_single(buf[c][h ][w]); + buf[c][h+1][w] = relu_single(buf[c][h+1][w]); + } + } + } +} + + + + +//relu and maxpool2x2 used in backbone +inline FIX_FM relu_max(FIX_FM a, FIX_FM b, FIX_FM c, FIX_FM d) +{ + FIX_FM t1, t2; + + if(a > b) t1 = relu_single(a); + else t1 = relu_single(b); + + if(c > d) t2 = relu_single(c); + else t2 = relu_single(d); + + if(t1 > t2) return t1; + else return t2; +} + + +//relu and maxpool5x5 used in new branch +inline FIX_FM relu_max_5x5(FIX_FM a, FIX_FM b, FIX_FM c, FIX_FM d, FIX_FM e) +{ + FIX_FM t1, t2 , t3; + + if (a > b) t1 = relu_single(a); + else t1 = relu_single(b); + + if (c > d) t2 = relu_single(c); + else t2 = relu_single(d); + + if (t1 > t2) t3 = t1; + else t3 = t2; + + if (relu_single(e) > t3) return relu_single(e); + else return t3; + + +} + +//maxpool 1x2 used in new branch +inline FIX_FM max_1x2(FIX_FM a, FIX_FM b) { + if (a > b) return a; + else return b; +} + +//activation function in after the final layer of new branch +inline FIX_FM sigmoid_single(FIX_FM d) { + + FIX_FM f = 1 / (1 + expf(-d)); + return f; +} + +void compute_sigmoid(FIX_FM top[32][44][84], FIX_FM bottom[13][13]) { + + for (int h = 1; h <= 12; h++) { +//#pragma HLS pipeline + for (int w = 1; w <= 12; w++) { + bottom[h][w] = sigmoid_single(top[h][w]); + } + } +} + + + +void accumulate_sigmoid(FIX_FM top[32][44][84], FIX_FM bottom[13][13]) { +//#pragma HLS array_partition variable=top dim=1 complete +//#pragma HLS array_partition variable=bottom dim=1 complete + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + for (int h = 1; h < 13; h++) { + for (int w = 1; w < 13; w++) { +//#pragma HLS pipeline + FIX_FM d = 0; + + for (int co = 0; co < 32; co++) { +//#pragma HLS pipeline +//#pragma HLS unroll + d += top[co][h][w]; + + } + d = sigmoid_single(d); + bottom[h][w] = d; + } + } + } + } + +} + +void Relu_Max_Pooling( + FIX_FM_acc buf_in[32][44][84], + uint512* ddr_dw1_pool_burst, + uint512* ddr_dw2_pool_burst, + uint512* ddr_buf, int buf_id, + int ch, int col, int row, int offset_h, int offset_w, int layer) +{ + + uint512* buf_in_ptr = ddr_buf + buf_id*44*84 + (1 + offset_h*22)*84 + offset_w*42; + uint512* ddr_dw1_pool_burst_ptr = ddr_dw1_pool_burst + ch*82*2*162*2 + (1 + col*20 + offset_h*2)*162*2 + (row*40 + offset_w*2); + uint512* ddr_dw2_pool_burst_ptr = ddr_dw2_pool_burst + ch*42*2*82*2 + (1 + col*20 + offset_h*2)*82*2 + (row*40 + offset_w*2); + +//#pragma HLS array_partition variable=buf_in dim=1 complete + + for(int h = 1; h <= 20; h++) { + for(int w = 1; w <= 40; w++) { +//#pragma HLS pipeline II=2 + uint512 DATA = 0; + for(int c = 0; c < 32; c++) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + FIX_FM d = relu_max(buf_in[c][h*2-1][w*2-1], buf_in[c][h*2-1][w*2], + buf_in[c][h*2][w*2-1], buf_in[c][h*2][w*2]); + + DATA.range(FM_RG + c*16, c*16) = d.range(FM_RG, 0); + } + + if( layer == 1 ) { + ddr_dw1_pool_burst_ptr[w].range(511, 0) = DATA.range(511, 0); + } + else if( layer == 2 ) { + ddr_dw2_pool_burst_ptr[w].range(511, 0) = DATA.range(511, 0); + } + else if( layer == 3 ) { + buf_in_ptr[w].range(511, 0) = DATA.range(511, 0); + } + } + + buf_in_ptr += 84; + ddr_dw1_pool_burst_ptr += 162*2; + ddr_dw2_pool_burst_ptr += 82*2; + } +} + + +void compute_Relu_Max_Pooling_2x2(FIX_FM buf_in[32][44][84], FIX_FM buf_out[32][44][84], int hmin, int hmax, int wmin, int wmax, int offsetx, int offsety) { +//#pragma HLS array_partition variable=buf_in dim=1 complete +//#pragma HLS array_partition variable=buf_out dim=1 complete + for (int h = hmin; h <= hmax; h++) { + for (int w = wmin; w <= wmax; w++) { +//#pragma HLS pipeline II=2 + for (int c = 0; c < 32; c++) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + buf_out[c][h][w] = relu_max(buf_in[c][h * 2 - 1 - 2 * offsetx][w * 2 - 1 - 2 * offsety], buf_in[c][h * 2 - 1 - 2 * offsetx][w * 2 - 0 - 2 * offsety], + buf_in[c][h * 2 - 0 - 2 * offsetx][w * 2 - 1 - 2 * offsety], buf_in[c][h * 2 - 0 - 2 * offsetx][w * 2 - 0 - 2 * offsety]); + } + + } + } +} + + +void compute_Relu_Max_Pooling_1x2(FIX_FM buf_in[32][44][84], FIX_FM buf_out[32][44][84], int hmin, int hmax,int wmin, int wmax, int offsety) { +//#pragma HLS array_partition variable=buf_in dim=1 complete +//#pragma HLS array_partition variable=buf_out dim=1 complete + for (int h = hmin; h <= hmax; h++) { + for (int w = wmin; w <= wmax; w++) { +//#pragma HLS pipeline II=2 + for (int c = 0; c < 32; c++) { +//#pragma HLS pipeline II=1 +//#pragma HLS unroll + buf_out[c][h][w] = max_1x2(buf_in[c][h][w * 2 - 1 -2*offsety], buf_in[c][h][w * 2 - 2*offsety]); + } + } + } +} + +void Relu_Max_Pooling_1x2(FIX_FM buf_in[32][44][84], FIX_FM buf_out[32][44][84]) { +//#pragma HLS array_partition variable=buf_in dim=1 complete +//#pragma HLS array_partition variable=buf_out dim=1 complete + compute_Relu_Max_Pooling_1x2(buf_in, buf_out, 1, 5, 1, 5, 0); + compute_Relu_Max_Pooling_1x2(buf_in, buf_out, 1, 5, 8, 12, 1); + compute_Relu_Max_Pooling_1x2(buf_in, buf_out, 8, 12, 1, 5, 0); + compute_Relu_Max_Pooling_1x2(buf_in, buf_out, 8, 12, 8, 12, 1); +} + + +void load_and_reorg_part_new(uint512* buf_in, int buf_id, + FIX_FM buf_out_1[32][44][84], + FIX_FM buf_out_2[32][44][84], + FIX_FM buf_out_3[32][44][84], + FIX_FM_acc buf_out_4[32][44][84], // borrow one + int offset_h, int offset_w,uint8 xmin, uint8 xmax,uint8 ymin, uint8 ymax) +{ + uint512* buf_in_ptr = buf_in + buf_id * 44 * 84; + + for (int h = xmin; h <= xmax; h += 4) { + for (int w = ymin; w <= ymax; w += 4) { + + uint512 DATA[16] = { 0 }; + DATA[0].range(511, 0) = buf_in_ptr[(h) * 84 + w].range(511, 0); + DATA[1].range(511, 0) = buf_in_ptr[(h + 2) * 84 + w].range(511, 0); + DATA[2].range(511, 0) = buf_in_ptr[(h) * 84 + w + 2].range(511, 0); + DATA[3].range(511, 0) = buf_in_ptr[(h + 2) * 84 + w + 2].range(511, 0); + DATA[4].range(511, 0) = buf_in_ptr[(h) * 84 + w + 1].range(511, 0); + DATA[5].range(511, 0) = buf_in_ptr[(h + 2) * 84 + w + 1].range(511, 0); + DATA[6].range(511, 0) = buf_in_ptr[(h) * 84 + w + 3].range(511, 0); + DATA[7].range(511, 0) = buf_in_ptr[(h + 2) * 84 + w + 3].range(511, 0); + DATA[8].range(511, 0) = buf_in_ptr[(h + 1) * 84 + w].range(511, 0); + DATA[9].range(511, 0) = buf_in_ptr[(h + 3) * 84 + w].range(511, 0); + DATA[10].range(511, 0) = buf_in_ptr[(h + 1) * 84 + w + 2].range(511, 0); + DATA[11].range(511, 0) = buf_in_ptr[(h + 3) * 84 + w + 2].range(511, 0); + DATA[12].range(511, 0) = buf_in_ptr[(h + 1) * 84 + w + 1].range(511, 0); + DATA[13].range(511, 0) = buf_in_ptr[(h + 3) * 84 + w + 1].range(511, 0); + DATA[14].range(511, 0) = buf_in_ptr[(h + 1) * 84 + w + 3].range(511, 0); + DATA[15].range(511, 0) = buf_in_ptr[(h + 3) * 84 + w + 3].range(511, 0); + + for (int c = 0; c < 8; c++) { + /////////////////// + buf_out_1[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[0].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[1].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[2].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[3].range(FM_RG + c * 16, c * 16); + + buf_out_1[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[4].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[5].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[6].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[7].range(FM_RG + c * 16, c * 16); + + buf_out_1[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[8].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[9].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[10].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[11].range(FM_RG + c * 16, c * 16); + + buf_out_1[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[12].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[13].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[14].range(FM_RG + c * 16, c * 16); + buf_out_1[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[15].range(FM_RG + c * 16, c * 16); + + /////////////////// + buf_out_2[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[0].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[1].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[2].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[3].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_2[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[4].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[5].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[6].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[7].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_2[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[8].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[9].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[10].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[11].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_2[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[12].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[13].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[14].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[15].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_3[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[0].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[1].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[2].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[3].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + buf_out_3[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[4].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[5].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[6].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[7].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + buf_out_3[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[8].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[9].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[10].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[11].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + buf_out_3[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[12].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(FM_RG, 0) = DATA[13].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[14].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(FM_RG, 0) = DATA[15].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + ///////////////////// + buf_out_4[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[0].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[1].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[2].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[3].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + + buf_out_4[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[4].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[5].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 1][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[6].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 1][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[7].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + + buf_out_4[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[8].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[9].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 2][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[10].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 2][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[11].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + + buf_out_4[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[12].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + offset_w * 42].range(WT_RG, 0) = DATA[13].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 3][(h + 1) / 2 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[14].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c * 4 + 3][(h + 1) / 2 + 1 + offset_h * 22][(w + 1) / 2 + 1 + offset_w * 42].range(WT_RG, 0) = DATA[15].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + } + } + } +} + + + +void load_and_reorg_new(uint512* buf_1, int buf_id_1, uint512* buf_2, int buf_id_2, + uint512* buf_3, int buf_id_3, uint512* buf_4, int buf_id_4, + FIX_FM buf_out_1[32][44][84], + FIX_FM buf_out_2[32][44][84], + FIX_FM buf_out_3[32][44][84], + FIX_FM_acc buf_out_4[32][44][84], + uint8 mask_bound_reorg[16]) +{ + load_and_reorg_part_new(buf_1, buf_id_1, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 0, 0,mask_bound_reorg[0] + 1,mask_bound_reorg[1],mask_bound_reorg[2] + 1,mask_bound_reorg[3]); + load_and_reorg_part_new(buf_2, buf_id_2, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 0, 1, mask_bound_reorg[4] + 1, mask_bound_reorg[5], mask_bound_reorg[6] + 1, mask_bound_reorg[7]); + load_and_reorg_part_new(buf_3, buf_id_3, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 1, 0, mask_bound_reorg[8] + 1, mask_bound_reorg[9], mask_bound_reorg[10] + 1, mask_bound_reorg[11]); + load_and_reorg_part_new(buf_4, buf_id_4, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 1, 1, mask_bound_reorg[12] + 1, mask_bound_reorg[13], mask_bound_reorg[14] + 1, mask_bound_reorg[15]); +} + + +void local_buf_copy( FIX_FM dest[32][44][84], FIX_FM_acc src[32][44][84]) +{ + for(int h = 0; h < 44; h+=2) { + for(int w = 0; w < 84; w++) { +//#pragma HLS pipeline + for(int c = 0; c < 32; c++) { + dest[c][h ][w].range(FM_RG, 0) = src[c][h ][w].range(FM_RG, 0); + dest[c][h+1][w].range(FM_RG, 0) = src[c][h+1][w].range(FM_RG, 0); + } + } + } +} + +//buffer copy used in new branch +void local_buf_copy_new(FIX_FM dest[32][44][84], FIX_FM_acc src[32][44][84]) +{ + for (int h = 0; h < 44; h += 2) { + for (int w = 0; w < 84; w++) { +//#pragma HLS pipeline + for (int c = 0; c < 32; c++) { + dest[c][h][w] = src[c][h][w]; + dest[c][h + 1][w] = src[c][h + 1][w]; + } + } + } +} + + +void compute_generate_mask_fix(FIX_FM input[13][13], uint8 xmin[1], uint8 xmax[1], uint8 ymin[1], uint8 ymax[1], uint8 offsetx, uint8 offsety, uint8 index[1]) { +//#pragma HLS array_partition variable=input dim=1 complete + for (int m = 0 ; m < 5 ; m++) { +//# pragma HLS pipeline + for (int n = 0 ; n < 5 ; n++) { +//#pragma HLS pipeline +//#pragma HLS unroll + if (input[m + 1 + 7 * offsetx][n + 1 + 7 * offsety] > 0.3 ) { + index[0]++; + if ((m + 5*offsetx) < xmin[0]) xmin[0] = m + 5 * offsetx; + if ((n + 5*offsety) < ymin[0]) ymin[0] = n + 5 * offsety; + if ((m + 5 * offsetx) > xmax[0]) xmax[0] = m + 5 * offsetx; + if ((n + 5 * offsety) > ymax[0]) ymax[0] = n + 5 * offsety; + } + } + } +} + +void generate_mask_fix(uint8 xmin1[1], uint8 xmax1[1], uint8 ymin1[1], uint8 ymax1[1], + uint8 xmin2[1], uint8 xmax2[1], uint8 ymin2[1], uint8 ymax2[1], + uint8 xmin3[1], uint8 xmax3[1], uint8 ymin3[1], uint8 ymax3[1], + uint8 xmin4[1], uint8 xmax4[1], uint8 ymin4[1], uint8 ymax4[1], + FIX_FM temp[13][13], uint8 index1[1], uint8 index2[1], uint8 index3[1], uint8 index4[1]) +{ + xmin1[0] = 4; ymin1[0] = 4; xmin2[0] = 4; ymin3[0] = 4; + xmax1[0] = 0; ymax1[0] = 0; xmax2[0] = 0; ymax3[0] = 0; + xmin3[0] = 9; xmin4[0] = 9; ymin2[0] = 9; ymin4[0] = 9; + xmax3[0] = 5; xmax4[0] = 5; ymax2[0] = 5; ymax4[0] = 5; + index1[0] = 0; + index2[0] = 0; + index3[0] = 0; + index4[0] = 0; + +//#pragma HLS array_partition variable=temp dim=1 complete + compute_generate_mask_fix(temp, xmin1, xmax1, ymin1, ymax1, 0, 0, index1); + compute_generate_mask_fix(temp, xmin2, xmax2, ymin2, ymax2, 0, 1, index2); + compute_generate_mask_fix(temp, xmin3, xmax3, ymin3, ymax3, 1, 0, index3); + compute_generate_mask_fix(temp, xmin4, xmax4, ymin4, ymax4, 1, 1, index4); + + + +} + + + + + + +void MaskNet( uint8 image_in_raw_pad[3*162*2*322*2], + + uint512 conv_weight_1x1_all[1000][32], + uint512 conv_weight_3x3_all[1000][3][3], + uint512 bias_all[500], + uint512 conv_weight_5x5_all[6][5][5], + + + uint512 DDR_dw1_pool_out_PL_burst[64/32*82*2*162*2], + uint512 DDR_dw2_pool_out_PL_burst[96/32*42*2*82*2], + uint512 DDR_buf_burst[128*44*84], + + + + float debug[10][32][44][84], + float predict_boxes[4][5], + int constant[4][3] +) +{ + +#pragma HLS INTERFACE m_axi depth=3*162*322 port=image_in_raw_pad offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=306*32*32 port=conv_weight_1x1_all offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=24*32*3*3 port=conv_weight_3x3_all offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=63*32 port=bias_all offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=6*5*5 port=conv_weight_5x5_all offset=slave bundle=INPUT + + + +#pragma HLS INTERFACE m_axi depth=106272 port=DDR_dw1_pool_out_PL_burst offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=41328 port=DDR_dw2_pool_out_PL_burst offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=473088 port=DDR_buf_burst offset=slave bundle=INPUT + + +#pragma HLS INTERFACE m_axi depth=5 port=predict_boxes offset=slave bundle=OUTPUT +#pragma HLS INTERFACE m_axi depth=5 port=constant offset=slave bundle=OUTPUT +#pragma HLS INTERFACE m_axi depth=10*32*22*42 port=debug offset=slave bundle=OUTPUT + +#pragma HLS INTERFACE s_axilite register port=return + + +// #pragma HLS ALLOCATION instances=CONV_1x1_new limit=1 function +// #pragma HLS ALLOCATION instances=DW_CONV_3x3_new limit=1 function +// #pragma HLS ALLOCATION instances=Relu_Max_Pooling limit=1 function +// #pragma HLS ALLOCATION instances=load_image_chunk_norm limit=1 function +// #pragma HLS ALLOCATION instances=DW_CONV_5x5 limit=1 function +// #pragma HLS ALLOCATION instances=Relu_Max_Pooling_1x2 limit=1 function + + + int CI_N, CO_N , CI_N_new_branch , CO_N_new_branch; + int weight_3x3_index, weight_1x1_index, bias_3x3_index, bias_1x1_index; + uint8 mask_bound[16]; + uint8 mask_bound_reorg[16]; + + /////////////////////////////// DW1_CONV_3x3 + DW1_CONV_1x1 + POOL //////////////////////////// + /// DW1_CONV_3x3 + weight_3x3_index = 0; + bias_3x3_index = 0; + weight_1x1_index = 0; + bias_1x1_index = 1; + + CI_N = 32 / 32; + CO_N = 64 / 32; + + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index]); + load_bias_from_axi(bias_buf[1], bias_all[bias_1x1_index + 0]); + load_bias_from_axi(bias_buf[2], bias_all[bias_1x1_index + 1]); + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + 0]); + load_weight_1x1_from_axi(weight_buf_1x1[1], conv_weight_1x1_all[weight_1x1_index + 1]); + + for(int row = 0; row < 8; row++) { + + load_image_chunk_norm(FM_buf1, image_in_raw_pad, 0, row, 0/4, row/4); + for(int col = 0; col < 8; col++) { + set_bias_3x3_new(FM_buf2, bias_buf[0],0,mask_bound); + + if( col % 2 == 0 ) { + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 1,0,0,mask_bound); + load_image_chunk_norm(FM_buf3, image_in_raw_pad, col+1, row, (col+1)/4, row/4); + } + else { + DW_CONV_3x3_new(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 1,0,0,mask_bound); + load_image_chunk_norm(FM_buf1, image_in_raw_pad, col+1, row, (col+1)/4, row/4); + } + + for(int co = 0; co < CO_N; co++) { + set_bias_1x1_new(FM_buf_acc, bias_buf[1 + co],0,mask_bound); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[co],0,mask_bound); + Relu_Max_Pooling(FM_buf_acc, DDR_dw1_pool_out_PL_burst, DDR_dw2_pool_out_PL_burst, DDR_buf_burst, 0, co, col, row, col/4, row/4, 1); + + } + } + } + + + printf("DW1 Done\n"); + + + /////////////////////////////// DW2_CONV_3x3 + DW2_CONV_1x1 + POOL //////////////////////////// + /// DW2_CONV_3x3 + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + load_weight_3x3_from_axi(weight_buf_3x3[1], conv_weight_3x3_all[weight_3x3_index + 0]); + load_weight_3x3_from_axi(weight_buf_3x3[2], conv_weight_3x3_all[weight_3x3_index + 1]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + 0]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + 1]); + + CI_N = 64 / 32; + CO_N = 96 / 32; + + for(int row = 0; row < 4; row++) { + for(int col = 0; col < 4; col++) { + + load_dw1_pool_from_DDR(DDR_dw1_pool_out_PL_burst, FM_buf1, 0, col, row, col/2, row/2); + set_bias_3x3_new(FM_buf2, bias_buf[0 + 0],0,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[1 + 0], bias_buf[0 + 0], 1,0,0,mask_bound); + + load_dw1_pool_from_DDR(DDR_dw1_pool_out_PL_burst, FM_buf4, 1, col, row, col/2, row/2); + set_bias_3x3_new(FM_buf3, bias_buf[0 + 1],0,mask_bound); + DW_CONV_3x3_new(FM_buf4, FM_buf3, weight_buf_3x3[1 + 1], bias_buf[0 + 1], 1,0,0,mask_bound); + + for(int co = 0; co < CO_N; co++) { + load_bias_from_axi(bias_buf[2], bias_all[bias_1x1_index + co]); + set_bias_1x1_new(FM_buf_acc, bias_buf[2],0,mask_bound); + + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + 0 + co * CI_N]); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[0],0,mask_bound); + + load_weight_1x1_from_axi(weight_buf_1x1[1], conv_weight_1x1_all[weight_1x1_index + 1 + co * CI_N]); + CONV_1x1_new(FM_buf3, FM_buf_acc, weight_buf_1x1[1],0,mask_bound); + + Relu_Max_Pooling(FM_buf_acc, DDR_dw1_pool_out_PL_burst, DDR_dw2_pool_out_PL_burst, DDR_buf_burst, 0, co, col, row, col/2, row/2, 2); + } + } + } + + + printf("DW2 Done\n"); + + + /////////////////////////////// DW3_CONV_3x3 + DW3_CONV_1x1 + POOL //////////////////////////// + + + /// DW3_CONV_3x3 + // output in DDR_buf[0] - DDR_buf[2] + + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + 0]); + load_weight_3x3_from_axi(weight_buf_3x3[1], conv_weight_3x3_all[weight_3x3_index + 1]); + load_weight_3x3_from_axi(weight_buf_3x3[2], conv_weight_3x3_all[weight_3x3_index + 2]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + 0]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + 1]); + load_bias_from_axi(bias_buf[2], bias_all[bias_3x3_index + 2]); + + CI_N = 96 / 32; + CO_N = 192 / 32; + for(int row = 0; row < 2; row++) { + for(int col = 0; col < 2; col++) { + + load_dw2_pool_from_DDR(DDR_dw2_pool_out_PL_burst, FM_buf1, 0, col, row, col/1, row/1 ); + set_bias_3x3_new(FM_buf2, bias_buf[0 + 0],0,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[0 + 0], bias_buf[0 + 0], 1,0,0,mask_bound); + + load_dw2_pool_from_DDR(DDR_dw2_pool_out_PL_burst, FM_buf1, 1, col, row, col/1, row/1 ); + set_bias_3x3_new(FM_buf3, bias_buf[0 + 1],0,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf3, weight_buf_3x3[0 + 1], bias_buf[0 + 1], 1,0,0,mask_bound); + + load_dw2_pool_from_DDR(DDR_dw2_pool_out_PL_burst, FM_buf1, 2, col, row, col/1, row/1 ); + set_bias_3x3_new(FM_buf4, bias_buf[0 + 2],0,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf4, weight_buf_3x3[0 + 2], bias_buf[0 + 2], 1,0,0,mask_bound); + + /// DW3_CONV_1x1 + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[3], bias_all[bias_1x1_index + co]); + set_bias_1x1_new(FM_buf_acc, bias_buf[3],0,mask_bound); + + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + 0 + co * CI_N]); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[0],0,mask_bound); + + load_weight_1x1_from_axi(weight_buf_1x1[1], conv_weight_1x1_all[weight_1x1_index + 1 + co * CI_N]); + CONV_1x1_new(FM_buf3, FM_buf_acc, weight_buf_1x1[1],0,mask_bound); + + load_weight_1x1_from_axi(weight_buf_1x1[2], conv_weight_1x1_all[weight_1x1_index + 2 + co * CI_N]); + CONV_1x1_new(FM_buf4, FM_buf_acc, weight_buf_1x1[2],0,mask_bound); + + relu_copy_buf_to_DDR_acc_new(DDR_buf_burst, 100 + co + (col*2 + row) * CO_N, FM_buf_acc, 0, 0,0, mask_bound); + Relu_Max_Pooling(FM_buf_acc, DDR_dw1_pool_out_PL_burst, DDR_dw2_pool_out_PL_burst, DDR_buf_burst, 6 + co, co, col, row, col, row, 3 ); + } + } + } + + + printf("DW3 Done\n"); + + /////////////////////////////////////////New branch group Conv5x5 group size = 32////////////////////////////////////////////// + + + + load_bias_from_axi(bias_buf[0], bias_all[106]); + set_bias_5x5(FM_buf_acc, bias_buf[0]); + load_weight_5x5_from_axi(weight_buf_5x5[0], conv_weight_5x5_all[0]); + compute_load_buf_from_DDR_new_branch_channel(FM_buf1, DDR_buf_burst, 6, 0, 0, 0); //channel shuffle in group convolution + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0],0,0); + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 0, 1); + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 1, 0); + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 1, 1); + + + load_weight_5x5_from_axi(weight_buf_5x5[1], conv_weight_5x5_all[1]); + compute_load_buf_from_DDR_new_branch_channel(FM_buf2, DDR_buf_burst, 6, 1, 0, 0);//channel shuffle in group convolution + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 0, 0); + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 0, 1); + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 1, 0); + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 1, 1); + + + + load_weight_5x5_from_axi(weight_buf_5x5[2], conv_weight_5x5_all[2]); + compute_load_buf_from_DDR_new_branch_channel(FM_buf3, DDR_buf_burst, 6, 2, 1, 0);//channel shuffle in group convolution + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 0, 0); + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 0, 1); + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 1, 0); + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 1, 1); + + + + load_weight_5x5_from_axi(weight_buf_5x5[0], conv_weight_5x5_all[3]); + compute_load_buf_from_DDR_new_branch_channel(FM_buf1, DDR_buf_burst, 6, 3, 1, 0);//channel shuffle in group convolution + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 0, 0); + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 0, 1); + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 1, 0); + DW_CONV_5x5(FM_buf1, FM_buf_acc, weight_buf_5x5[0], bias_buf[0], 1, 1); + + + + load_weight_5x5_from_axi(weight_buf_5x5[1], conv_weight_5x5_all[4]); + compute_load_buf_from_DDR_new_branch_channel(FM_buf2, DDR_buf_burst, 6, 4, 1, 1);//channel shuffle in group convolution + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 0, 0); + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 0, 1); + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 1, 0); + DW_CONV_5x5(FM_buf2, FM_buf_acc, weight_buf_5x5[1], bias_buf[0], 1, 1); + + + + load_weight_5x5_from_axi(weight_buf_5x5[2], conv_weight_5x5_all[5]); + compute_load_buf_from_DDR_new_branch_channel(FM_buf3, DDR_buf_burst, 6, 5, 1, 1);//channel shuffle in group convolution + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 0, 0); + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 0, 1); + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 1, 0); + DW_CONV_5x5(FM_buf3, FM_buf_acc, weight_buf_5x5[2], bias_buf[0], 1, 1); + + /////////////////////////////////////////New branch group Conv5x5 end////////////////////////////////////////////// + + + /////////////////////////////////////////prepare buffers which can be used later////////////////////////////////////////////// + clear_buffer_new(FM_buf2); + clear_buffer_new(FM_buf4); + clear_buffer_new(FM_buf3); + local_buf_copy_new(FM_buf1, FM_buf_acc); + /////////////////////////////////////////prepare buffers end////////////////////////////////////////////// + + + /////////////////////////////////////////Relu and Maxpooling 5x5 ////////////////////////////////////////////// + //We separate maxpooling 5x5 into three parts: the first part is relu_maxpooling 2x2, the second part is relu_maxpooling 2x2, the final part is relu_maxpooling 1x2 + + compute_Relu_Max_Pooling_2x2(FM_buf1, FM_buf2, 1, 10, 1, 20, 0, 0); + compute_Relu_Max_Pooling_2x2(FM_buf1, FM_buf2, 1, 10, 23, 42, 0, 1); + compute_Relu_Max_Pooling_2x2(FM_buf1, FM_buf2, 13, 22, 1, 20, 1, 0); + compute_Relu_Max_Pooling_2x2(FM_buf1, FM_buf2, 13, 22, 23, 42, 1, 1); + + compute_Relu_Max_Pooling_2x2(FM_buf2, FM_buf3, 1, 5, 1, 10, 0, 0); + compute_Relu_Max_Pooling_2x2(FM_buf2, FM_buf3, 1, 5, 13, 22, 0, 1); + compute_Relu_Max_Pooling_2x2(FM_buf2, FM_buf3, 8, 12, 1, 10, 1, 0); + compute_Relu_Max_Pooling_2x2(FM_buf2, FM_buf3, 8, 12, 13, 22, 1, 1); + + Relu_Max_Pooling_1x2(FM_buf3, FM_buf4); + /////////////////////////////////////////Relu and Maxpooling 5x5 end////////////////////////////////////////////// + + + + + /////////////////////////////////////////Conv3x3 + sigmoid in new branch////////////////////////////////////////////// + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[64]); + clear_buffer_new(FM_buf1); + DW_CONV_3x3_new(FM_buf4, FM_buf1, weight_buf_3x3[0], bias_buf[0],0,0,1, mask_bound); + accumulate_sigmoid(FM_buf1, mask); + /////////////////////////////////////////Conv3x3 + sigmoid in new branch end////////////////////////////////////////////// + + + + /////////////////////////////////////////generate confidence mask////////////////////////////////////////////// + + uint8 xmin1[1], ymin1[1], xmin2[1], ymin3[1]; + uint8 xmax1[1], ymax1[1], xmax2[1], ymax3[1]; + uint8 xmin3[1], xmin4[1], ymin2[1], ymin4[1]; + uint8 xmax3[1], xmax4[1], ymax2[1], ymax4[1]; + uint8 index1[1], index2[1], index3[1], index4[1]; + + + + generate_mask_fix(xmin1, xmax1, ymin1, ymax1, xmin2, xmax2, ymin2, ymax2, xmin3, xmax3, ymin3, ymax3, xmin4, xmax4, ymin4, ymax4, mask, index1,index2,index3,index4); + if (index1[0] == 0) { + xmin1[0] = 0; + xmax1[0] = 4; + ymin1[0] = 0; + ymax1[0] = 4; + + } + if (index2[0] == 0) { + xmin2[0] = 0; + xmax2[0] = 4; + ymin2[0] = 5; + ymax2[0] = 9; + + } + if (index3[0] == 0) { + xmin3[0] = 5; + xmax3[0] = 9; + ymin3[0] = 0; + ymax3[0] = 4; + + } + if (index4[0] == 0) { + xmin4[0] = 5; + xmax4[0] = 9; + ymin4[0] = 5; + ymax4[0] = 9; + + } + /////////////////////////////////////////generate confidence mask end////////////////////////////////////////////// + + /////////////////////////////////////////upsample confidence mask///////////////////////////////////////////////// + + mask_bound[0] = xmin1[0] * 4; + mask_bound[1] = (xmax1[0] + 1) * 4; + mask_bound[2] = ymin1[0] * 8; + mask_bound[3] = (ymax1[0] + 1) * 8; + + mask_bound[4] = xmin2[0] * 4; + mask_bound[5] = (xmax2[0] + 1) * 4; + mask_bound[6] = ymin2[0] * 8; + mask_bound[7] = (ymax2[0] + 1) * 8; + + mask_bound[8] = xmin3[0] * 4; + mask_bound[9] = (xmax3[0] + 1) * 4; + mask_bound[10] = ymin3[0] * 8; + mask_bound[11] = (ymax3[0] + 1) * 8; + + mask_bound[12] = xmin4[0] * 4; + mask_bound[13] = (xmax4[0] + 1) * 4; + mask_bound[14] = ymin4[0] * 8; + mask_bound[15] = (ymax4[0] + 1) * 8; + + mask_bound_reorg[0] = xmin1[0] * 8; + mask_bound_reorg[1] = (xmax1[0] + 1) * 8; + mask_bound_reorg[2] = ymin1[0] * 16; + mask_bound_reorg[3] = (ymax1[0] + 1) * 16; + + mask_bound_reorg[4] = xmin2[0] * 8; + mask_bound_reorg[5] = (xmax2[0] + 1) * 8; + mask_bound_reorg[6] = (ymin2[0] - 5) * 16; + mask_bound_reorg[7] = (ymax2[0] - 4) * 16; + + mask_bound_reorg[8] = (xmin3[0] - 5) * 8; + mask_bound_reorg[9] = (xmax3[0] - 4) * 8; + mask_bound_reorg[10] = ymin3[0] * 16; + mask_bound_reorg[11] = (ymax3[0] + 1) * 16; + + mask_bound_reorg[12] = (xmin4[0] - 5) * 8; + mask_bound_reorg[13] = (xmax4[0] - 4) * 8; + mask_bound_reorg[14] = (ymin4[0] - 5) * 16; + mask_bound_reorg[15] = (ymax4[0] - 4) * 16; + + + printf("new branch done\n"); + + + /////////////////////////////// DW4_CONV_3x3 + DW4_CONV_1x1 //////////////////////////// + + /// DW4_CONV_3x3 + // input in DDR_buf[6] - DDR_buf[11] + // output in DDR_buf[12] - DDR_buf[17] + + clear_buffer_new(FM_buf1); + clear_buffer_new(FM_buf2); + clear_buffer_new(FM_buf3); + clear_buffer_new(FM_buf4); + clear_buffer(FM_buf_acc); + + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + CI_N = 192 / 32; + + /// conv3x3: ping-pong in: FM_buf1 and FM_buf3 + /// conv3x3: out: FM_buf2 + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 6 + 0,1, mask_bound); + for(int c = 0; c < CI_N; c++) { + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c]); + set_bias_3x3_new(FM_buf2, bias_buf[0],1,mask_bound); + + if( c % 2 == 0 ) { + load_buf_from_DDR_new(FM_buf3, DDR_buf_burst, 6 + c+1,1,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0,1,0,mask_bound); + } + else { + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 6 + c+1,1,mask_bound); + DW_CONV_3x3_new(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0,1,0,mask_bound); + } + + relu_copy_buf_to_DDR_new(DDR_buf_burst, 12 + c, FM_buf2, 0, 0,1, mask_bound); + } + + /// DW4_CONV_1x1 + // input in DDR_buf[12] - DDR_buf[17] + // output in DDR_buf[18] - DDR_buf[29] + + CO_N = 384 / 32; + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[0], bias_all[bias_1x1_index + co]); + set_bias_1x1_new(FM_buf_acc, bias_buf[0], 1,mask_bound); + + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 12 + 0, 1,mask_bound); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + + if( ci % 2 == 0) { + load_buf_from_DDR_new(FM_buf2, DDR_buf_burst, 12 + ci+1, 1,mask_bound); + CONV_1x1_new(FM_buf1, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + else { + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 12 + ci+1, 1,mask_bound); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + } + relu_copy_buf_to_DDR_acc_new(DDR_buf_burst, 18 + co, FM_buf_acc, 0, 0, 1,mask_bound); + } + + + printf("DW4 Done\n"); + + + /////////////////////////////// DW5_CONV_3x3 + DW5_CONV_1x1 //////////////////////////// + + /// DW5_CONV_3x3 + // input in DDR_buf[18] - DDR_buf[29] + // output in DDR_buf[30] - DDR_buf[41] + + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + CI_N = 384 / 32; + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 18 + 0, 1,mask_bound); + for(int c = 0; c < CI_N; c++) { + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c]); + set_bias_3x3_new(FM_buf2, bias_buf[0], 1,mask_bound); + + if( c % 2 == 0) { + load_buf_from_DDR_new(FM_buf3, DDR_buf_burst, 18 + c+1, 1,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0, 1,0,mask_bound); + } + else { + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 18 + c+1, 1,mask_bound); + DW_CONV_3x3_new(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0, 1,0,mask_bound); + } + + + relu_copy_buf_to_DDR_new(DDR_buf_burst, 30 + c, FM_buf2, 0, 0, 1,mask_bound); + } + + /// DW5_CONV_1x1 + // input in DDR_buf[30] - DDR_buf[41] + // output in DDR_buf[42] - DDR_buf[57] + + CO_N = 512 / 32; + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[0], bias_all[bias_1x1_index + co]); + set_bias_1x1_new(FM_buf_acc, bias_buf[0], 1,mask_bound); + + load_buf_from_DDR_new(FM_buf2, DDR_buf_burst, 30 + 0, 1,mask_bound); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + + if( ci % 2 == 0) { + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 30 + ci+1, 1,mask_bound); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + else { + load_buf_from_DDR_new(FM_buf2, DDR_buf_burst, 30 + ci+1, 1,mask_bound); + CONV_1x1_new(FM_buf1, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + } + relu_copy_buf_to_DDR_acc_new(DDR_buf_burst, 42 + co, FM_buf_acc, 0, 0, 1,mask_bound); + } + + + printf("DW5 Done\n"); + + /////////////////////////////// CONCAT DW3_CONV_1x1_OUT & DW5_CONV_1x1_OUT ///////////// + /////////////////////////////// DW6_CONV_3x3 + DW6_CONV_1x1 //////////////////////////// + + //// DW6_CONV_3x3 + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + + // First half: 0~767 channels from DW3_conv_1x1_output + // Output of DW3_CONV_1x1_OUT are stored in DDR_buf[100] to DDR_buf[123] + // Output of first half are stored in DDR_buf[58] to DDR_buf[81] + CI_N = 768 / 32; + for(int c = 0; c < CI_N; c+=4) { + + // From DDR_buf[100] to DDR_buf[123] + // Img 0: 100 ~ 105 + // Img 1: 106 ~ 111 + // Img 2: 112 ~ 117 + // Img 3: 118 ~ 123 + + load_and_reorg_new(DDR_buf_burst, 100 + c/4, DDR_buf_burst, 100 + c/4 + 6, + DDR_buf_burst, 100 + c/4 + 6 * 2, DDR_buf_burst, 100 + c/4 + 6 * 3, + FM_buf1, FM_buf3, FM_buf4, FM_buf_acc,mask_bound_reorg); + + //// 1/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c + 0]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c + 0]); + set_bias_3x3_new(FM_buf2, bias_buf[0],1,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0,1, 0,mask_bound); + local_buf_copy(FM_buf1, FM_buf_acc); + relu_copy_buf_to_DDR_new(DDR_buf_burst, 58 + c + 0, FM_buf2, 0, 0, 1,mask_bound); + + //// 2/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[1], conv_weight_3x3_all[weight_3x3_index + c + 1]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + c + 1]); + set_bias_3x3_new(FM_buf2, bias_buf[1], 1,mask_bound); + DW_CONV_3x3_new(FM_buf3, FM_buf2, weight_buf_3x3[1], bias_buf[1], 0, 1,0,mask_bound); + relu_copy_buf_to_DDR_new(DDR_buf_burst, 58 + c + 1, FM_buf2, 0, 0,1, mask_bound); + + //// 3/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[2], conv_weight_3x3_all[weight_3x3_index + c + 2]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c + 2]); + set_bias_3x3_new(FM_buf2, bias_buf[0], 1,mask_bound); + DW_CONV_3x3_new(FM_buf4, FM_buf2, weight_buf_3x3[2], bias_buf[0], 0, 1,0,mask_bound); + relu_copy_buf_to_DDR_new(DDR_buf_burst, 58 + c + 2, FM_buf2, 0, 0,1, mask_bound); + + //// 4/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[3], conv_weight_3x3_all[weight_3x3_index + c + 3]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + c + 3]); + set_bias_3x3_new(FM_buf2, bias_buf[1], 1,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[3], bias_buf[1], 0,1, 0,mask_bound); + relu_copy_buf_to_DDR_new(DDR_buf_burst, 58 + c + 3, FM_buf2, 0, 0, 1,mask_bound); + } + + // Second half: 768~1280 channels from DW5_conv_1x1_output + // Output of DW5_CONV_1x1_OUT are stored in DDR_buf[42] - DDR_buf[57] + // Output of first half are stored in DDR_buf[82] to DDR_buf[97] + CI_N = 512 / 32; + + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 42 + 0, 1,mask_bound); + for(int c = 0; c < CI_N; c++) { + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c + 24]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c + 24]); + set_bias_3x3_new(FM_buf2, bias_buf[0], 1,mask_bound); + + if( c % 2 == 0) { + load_buf_from_DDR_new(FM_buf3, DDR_buf_burst, 42 + c+1, 1,mask_bound); + DW_CONV_3x3_new(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0, 1,0,mask_bound); + } + else { + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 42 + c+1, 1,mask_bound); + DW_CONV_3x3_new(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0, 1,0,mask_bound); + } + relu_copy_buf_to_DDR_new(DDR_buf_burst, 82 + c, FM_buf2, 0, 0, 1,mask_bound); + } + + /// DW6_CONV_1x1 + // input in DDR_buf[58] - DDR_buf[97] + // output in DDR_buf[98] - DDR_buf[100] + + bias_1x1_index += 24; + CO_N = 96 / 32; + CI_N = 1280 / 32; + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[0], bias_all[bias_1x1_index + co]); + set_bias_1x1_new(FM_buf_acc, bias_buf[0], 1,mask_bound); + + load_buf_from_DDR_new(FM_buf2, DDR_buf_burst, 58 + 0, 1,mask_bound); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + + if( ci % 2 == 0) { + load_buf_from_DDR_new(FM_buf1, DDR_buf_burst, 58 + ci+1, 1,mask_bound); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + else { + load_buf_from_DDR_new(FM_buf2, DDR_buf_burst, 58 + ci+1, 1,mask_bound); + CONV_1x1_new(FM_buf1, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + } + + relu_copy_buf_to_DDR_acc_new(DDR_buf_burst, 98 + co, FM_buf_acc, 0, 0, 1,mask_bound); + } + + + printf("DW6 Done\n"); + + + /////////////////////////////// PW7_CONV_1x1 //////////////////////////// + weight_1x1_index += CO_N * CI_N; + // input in DDR_buf[98] - DDR_buf[100] + // output in FM_buf_acc + + CO_N = 32 / 32; + CI_N = 96 / 32; + for(int co = 0; co < CO_N; co++) { + clear_buffer(FM_buf_acc); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + load_buf_from_DDR_new(FM_buf2, DDR_buf_burst, 98 + ci, 1,mask_bound); + CONV_1x1_new(FM_buf2, FM_buf_acc, weight_buf_1x1[0], 1,mask_bound); + } + } + + printf("PW7 Done\n"); + + + compute_bounding_box(predict_boxes, constant,mask_bound); + + return; + + + +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.h new file mode 100644 index 000000000000..e3825947709a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/Mask-Net_dataset/src/net_hls.h @@ -0,0 +1,185 @@ +#include +#include +#include +#include +#include +#include "hls_stream.h" +#include +#include +#include + + + +//#define CSIM_DEBUG +//#define CSIM_CMP_OUTPUT + + +// for .range(Hi, Lo) +#define FM_RG 8 +#define FM_ACC_RG 11 +#define WT_RG 10 + + //#define FM_RG 15 + //#define FM_ACC_RG 15 +// #define WT_RG 15 + + + +#ifdef CSIM_DEBUG + typedef float FIX_32_4; //fix point + typedef float FIX_32_25; //fix point + typedef float FIX_FM; //fix point for feature map + typedef float FIX_FM_acc; //fix point for feature map + typedef float FIX_FM_last; + typedef float FIX_WT; //fix point for weights + typedef float FIX_32_16; + typedef float FIX_32_10; + typedef float FIX_32_12; + typedef float FIX_16_6; + typedef float FIX_16_5; + typedef float FIX_16_4; + typedef float FIX_16_10; + + typedef float uint8; + typedef float uint16; + typedef float uint128; + typedef float uint256; + typedef float uint512; + +#else + + typedef ap_fixed<9, 3, AP_RND, AP_SAT> FIX_FM; //fix point for feature map + typedef ap_fixed<12, 4, AP_RND, AP_SAT> FIX_FM_acc; //fix point for accumulation + typedef ap_fixed<11, 4, AP_RND, AP_SAT> FIX_WT; //fix point for weights + //typedef ap_fixed<16, 8, AP_RND, AP_SAT> FIX_FM; //fix point for feature map + //typedef ap_fixed<16, 8, AP_RND, AP_SAT> FIX_FM_acc; //fix point for accumulation + //typedef ap_fixed<16, 8, AP_RND, AP_SAT> FIX_WT; //fix point for weights + + + + + typedef ap_fixed<16, 8, AP_RND, AP_SAT> FIX_16_8; + typedef ap_fixed<16, 6, AP_RND, AP_SAT> FIX_16_6; + typedef ap_fixed<16, 5, AP_RND, AP_SAT> FIX_16_5; + typedef ap_fixed<16, 4, AP_RND, AP_SAT> FIX_16_4; + typedef ap_fixed<16, 3, AP_RND, AP_SAT> FIX_16_3; + typedef ap_fixed<16, 10, AP_RND, AP_SAT> FIX_16_10; + typedef ap_fixed<32,16, AP_RND, AP_SAT> FIX_32_16; + typedef ap_fixed<32,12, AP_RND, AP_SAT> FIX_32_12; + typedef ap_fixed<32,10, AP_RND, AP_SAT> FIX_32_10; + typedef ap_fixed<32, 4, AP_RND, AP_SAT> FIX_32_4; + typedef ap_fixed<32, 7, AP_RND, AP_SAT> FIX_32_7; + typedef ap_fixed<32,25, AP_RND, AP_SAT> FIX_32_25; + + typedef ap_uint<2> uint2; + typedef ap_uint<4> uint4; + typedef ap_uint<8> uint8; + typedef ap_uint<16> uint16; + typedef ap_uint<256> uint256; + typedef ap_uint<512> uint512; + + +#endif +//int golden_model(); + +void MaskNet(uint8 image_in_raw_pad[3*162*2*322*2], + + uint512 fix_conv_weight_1x1_all_512bit[1000][32], + uint512 fix_conv_weight_3x3_all_512bit[1000][3][3], + uint512 fix_bias_all_512bit[500], + uint512 fix_conv_weight_5x5_all_512bit[6][5][5], + + + uint512 DDR_dw1_pool_out_PL[64/32*82*2*162*2], + uint512 DDR_dw2_pool_out_PL[96/32*42*2*82*2], + + uint512 DDR_buf[128*44*84], + //uint512 DDR_buf_burst_new_branch1[6 * 88 * 88], + //uint512 DDR_buf_burst_new_branch2[3*44*84], + + float debug[10][32][44][84], + float predict_box[4][5], + int constant[4][3] +); + +void DW_CONV_3x3(FIX_FM bottom[32][44][84], + FIX_FM top[32][44][84], + FIX_WT weight[32][3][3], + FIX_WT bias[32], + int relu +); + +void CONV_1x1(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][32] +); + +void DW_CONV_5x5(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][5][5], + FIX_WT bias[32], + int offsetx, + int offsety +); + + +void DW_CONV_3x3_new(FIX_FM bottom[32][44][84], + FIX_FM top[32][44][84], + FIX_WT weights[32][3][3], + FIX_WT bias[32], + int relu, int index,int sigmoid, uint8 mask_bound[16]); + +void CONV_1x1_new(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][32], + int index, uint8 mask_bound[16]); + +float max_2(float a1, float a2); +float max_5(float a1, float a2, float a3, float a4, float a5); + + +void fill_output_dw1_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw1_conv1x1( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw1_pool( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw2_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw2_conv1x1( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw2_pool( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw3_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw3_conv1x1( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw3_pool( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw4_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw4_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw5_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw5_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw6_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw6_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void fill_output_pw7_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void PL_golden_compare_dw1_conv3x3(); +void PL_golden_compare_dw1_conv1x1(); +void PL_golden_compare_dw1_pool(); + +void PL_golden_compare_dw2_conv3x3(); +void PL_golden_compare_dw2_conv1x1(); +void PL_golden_compare_dw2_pool(); + +void PL_golden_compare_dw3_conv3x3(); +void PL_golden_compare_dw3_conv1x1(); +void PL_golden_compare_dw3_pool(); + +void PL_golden_compare_dw4_conv3x3(); +void PL_golden_compare_dw4_conv1x1(); + +void PL_golden_compare_dw5_conv3x3(); +void PL_golden_compare_dw5_conv1x1(); + +void PL_golden_compare_dw6_conv3x3(); +void PL_golden_compare_dw6_conv1x1(); + +void PL_golden_compare_pw7_conv1x1(); diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/conv1x1.cc b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/conv1x1.cc new file mode 100644 index 000000000000..a71c27c1baae --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/conv1x1.cc @@ -0,0 +1,142 @@ + + +// Conv 1x1 PE + +#include "net_hls.h" +#include +#include +#include +#include "hls_stream.h" + +FIX_FM_acc compute_engine_16(FIX_WT w0, FIX_FM b0, + FIX_WT w1, FIX_FM b1, + FIX_WT w2, FIX_FM b2, + FIX_WT w3, FIX_FM b3, + FIX_WT w4, FIX_FM b4, + FIX_WT w5, FIX_FM b5, + FIX_WT w6, FIX_FM b6, + FIX_WT w7, FIX_FM b7, + FIX_WT w8, FIX_FM b8, + FIX_WT w9, FIX_FM b9, + FIX_WT w10, FIX_FM b10, + FIX_WT w11, FIX_FM b11, + FIX_WT w12, FIX_FM b12, + FIX_WT w13, FIX_FM b13, + FIX_WT w14, FIX_FM b14, + FIX_WT w15, FIX_FM b15) +{ + FIX_32_10 mul0, mul1, mul2, mul3, mul4, mul5, mul6, mul7; + FIX_32_10 mul8, mul9, mul10, mul11, mul12, mul13, mul14, mul15; + FIX_32_10 add0, add1, add2, add3, add4, add5, add6; + FIX_32_10 add7, add8, add9, add10, add11, add12, add13, add14; + + mul0 = w0 * b0; + mul1 = w1 * b1; + mul2 = w2 * b2; + mul3 = w3 * b3; + mul4 = w4 * b4; + mul5 = w5 * b5; + mul6 = w6 * b6; + mul7 = w7 * b7; + mul8 = w8 * b8; + mul9 = w9 * b9; + mul10 = w10 * b10; + mul11 = w11 * b11; + mul12 = w12 * b12; + mul13 = w13 * b13; + mul14 = w14 * b14; + mul15 = w15 * b15; + + add0 = mul0 + mul1; + add1 = mul2 + mul3; + add2 = mul4 + mul5; + add3 = mul6 + mul7; + add4 = mul8 + mul9; + add5 = mul10 + mul11; + add6 = mul12 + mul13; + add7 = mul14 + mul15; + + add8 = add0 + add1; + add9 = add2 + add3; + add10 = add4 + add5; + add11 = add6 + add7; + + add12 = add8 + add9; + add13 = add10 + add11; + + add14 = add12 + add13; + + return add14; + +} + + + + +void load_weights(FIX_WT weights[32][32], FIX_WT weight_buf[32][16], int CI) +{ + for(int ci = 0; ci < 16; ci++) { +//#pragma HLS pipeline + for(int co = 0; co < 32; co++) { +//#pragma HLS unroll +#pragma HLS pipeline + weight_buf[co][ci] = weights[co][ci + CI]; + } + } +} + + + + +void CONV_1x1(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][32]) +{ + +#pragma HLS array_partition variable=top dim=1 complete +#pragma HLS array_partition variable=bottom dim=1 complete + +#pragma HLS array_partition variable=weights dim=1 complete + +FIX_WT weight_buf[32][16]; +#pragma HLS array_partition variable=weight_buf dim=1 complete +#pragma HLS array_partition variable=weight_buf dim=2 complete + + + for(int ci = 0; ci < 32; ci += 16) { + //for(int co = 0; co < 32; co += 32) { + + load_weights(weights, weight_buf, ci); + + int buf_idx = ci/16; + for(int h = 1; h <= 42; h++){ + for(int w = 1; w <= 82; w++) { + +#pragma HLS pipeline II=2 + for(int coo = 0; coo < 32; coo++) { +#pragma HLS unroll + top[coo][h][w] += compute_engine_16( + weight_buf[coo][0], bottom[ci+0][h][w], + weight_buf[coo][1], bottom[ci+1][h][w], + weight_buf[coo][2], bottom[ci+2][h][w], + weight_buf[coo][3], bottom[ci+3][h][w], + weight_buf[coo][4], bottom[ci+4][h][w], + weight_buf[coo][5], bottom[ci+5][h][w], + weight_buf[coo][6], bottom[ci+6][h][w], + weight_buf[coo][7], bottom[ci+7][h][w], + weight_buf[coo][8], bottom[ci+8][h][w], + weight_buf[coo][9], bottom[ci+9][h][w], + weight_buf[coo][10], bottom[ci+10][h][w], + weight_buf[coo][11], bottom[ci+11][h][w], + weight_buf[coo][12], bottom[ci+12][h][w], + weight_buf[coo][13], bottom[ci+13][h][w], + weight_buf[coo][14], bottom[ci+14][h][w], + weight_buf[coo][15], bottom[ci+15][h][w]); + + } + } + } + } + //} + +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/dwconv3x3.cc b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/dwconv3x3.cc new file mode 100644 index 000000000000..0abbeba1d24c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/dwconv3x3.cc @@ -0,0 +1,61 @@ + + +// dw_conv 3x3 + +#include "net_hls.h" +#include +#include +#include +#include "hls_stream.h" + + +inline FIX_FM relu_single( FIX_FM d ) { + if( d > 6 ) + return 6; + if( d < 0 ) + return 0; + return d; +} + + +void DW_CONV_3x3(FIX_FM bottom[32][44][84], + FIX_FM top[32][44][84], + FIX_WT weights[32][3][3], + FIX_WT bias[32], + int relu) +{ + +#pragma HLS array_partition variable=top dim=1 complete +#pragma HLS array_partition variable=bottom dim=1 complete +#pragma HLS array_partition variable=weights dim=1 complete +#pragma HLS array_partition variable=bias dim=1 complete + + + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + for(int h = 1; h <= 42; h++){ + for(int w = 1; w <= 82; w++){ +#pragma HLS pipeline + for(int co = 0; co < 32; co++){ +#pragma HLS unroll + top[co][h][w] += (weights[co][i][j] * bottom[co][h+i-1][w+j-1]); + } + } + } + } + } + + if(relu == 1) { + for(int h = 1; h <= 42; h+=2){ + for(int w = 1; w <= 82; w++){ + #pragma HLS pipeline + for(int co = 0; co < 32; co++){ + top[co][h ][w] = relu_single( top[co][h ][w ]); + top[co][h+1][w] = relu_single( top[co][h+1][w ]); + } + } + } + } +} + + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.cc b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.cc new file mode 100644 index 000000000000..b40727cc261a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.cc @@ -0,0 +1,1223 @@ +#include "net_hls.h" +#include +#include +#include +#include +#include + +using namespace std; + + +// feature map buffers +FIX_FM FM_buf1[32][44][84]; +FIX_FM FM_buf2[32][44][84]; +FIX_FM FM_buf3[32][44][84]; +FIX_FM FM_buf4[32][44][84]; +FIX_FM_acc FM_buf_acc[32][44][84]; + +// weight buffers +FIX_WT weight_buf_1x1[4][32][32]; +FIX_WT weight_buf_3x3[4][32][3][3]; +FIX_WT bias_buf[4][32]; + + + +void compute_bounding_box(float predict_box[4][5], int constant[4][3]) +{ + FIX_32_4 conf_thresh = -100.0; + int conf_j = 0; + int conf_m = 0; + int conf_n = 0; + FIX_32_4 conf_box1 = 0.0; + FIX_32_4 conf_box2 = 0.0; + //int h = 20; + //int w = 40; + + //// 0 + for(int m = 1; m <= 20; m++){ + for(int n = 1; n <= 40; n++){ + //conf_box1 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[4][m][n])); + conf_box1 = FM_buf_acc[4][m][n]; + if(conf_box1 > conf_thresh){ + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for(int m = 1; m <= 20; m++){ + for(int n = 1; n <= 40; n++){ + //conf_box2 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[9][m][n])); + conf_box2 = FM_buf_acc[9][m][n]; + if(conf_box2 > conf_thresh){ + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if( conf_j == 0 ) { + // first bounding box + predict_box[0][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[0][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[0][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[0][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[0][4] = conf_thresh; + + } + else if( conf_j == 1 ) { + // second bounding box + predict_box[0][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[0][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[0][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[0][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[0][4] = conf_thresh; + } + + constant[0][0] = conf_j; + constant[0][1] = conf_n-1; + constant[0][2] = conf_m-1; + + //printf("0: conf_m: %d, conf_n:%d\n", conf_m-1, conf_n-1); + + + + //// 1 + conf_thresh = -100.0; + conf_j = 0; + conf_m = 0; + conf_n = 0; + conf_box1 = 0.0; + conf_box2 = 0.0; + + for(int m = 1; m <= 20; m++){ + for(int n = 43; n <= 82; n++){ + //conf_box1 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[4][m][n])); + conf_box1 = FM_buf_acc[4][m][n]; + if(conf_box1 > conf_thresh){ + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for(int m = 1; m <= 20; m++){ + for(int n = 43; n <= 82; n++){ + //conf_box2 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[9][m][n])); + conf_box2 = FM_buf_acc[9][m][n]; + if(conf_box2 > conf_thresh){ + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if( conf_j == 0 ) { + // first bounding box + predict_box[1][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[1][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[1][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[1][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[1][4] = conf_thresh; + + } + else if( conf_j == 1 ) { + // second bounding box + predict_box[1][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[1][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[1][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[1][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[1][4] = conf_thresh; + } + + constant[1][0] = conf_j; + constant[1][1] = conf_n-43; + constant[1][2] = conf_m-1; + + //printf("1: conf_m: %d, conf_n:%d\n", conf_m-1, conf_n-1); + + + //// 2 + conf_thresh = -100.0; + conf_j = 0; + conf_m = 0; + conf_n = 0; + conf_box1 = 0.0; + conf_box2 = 0.0; + + for(int m = 23; m <= 42; m++){ + for(int n = 1; n <= 40; n++){ + //conf_box1 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[4][m][n])); + conf_box1 = FM_buf_acc[4][m][n]; + if(conf_box1 > conf_thresh){ + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for(int m = 23; m <= 42; m++){ + for(int n = 1; n <= 40; n++){ + //conf_box2 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[9][m][n])); + conf_box2 = FM_buf_acc[9][m][n]; + if(conf_box2 > conf_thresh){ + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if( conf_j == 0 ) { + // first bounding box + predict_box[2][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[2][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[2][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[2][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[2][4] = conf_thresh; + + } + else if( conf_j == 1 ) { + // second bounding box + predict_box[2][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[2][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[2][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[2][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[2][4] = conf_thresh; + } + + constant[2][0] = conf_j; + constant[2][1] = conf_n-1; + constant[2][2] = conf_m-23; + + //printf("2: conf_m: %d, conf_n:%d\n", conf_m-1, conf_n-1); + + + + //// 3 + conf_thresh = -100.0; + conf_j = 0; + conf_m = 0; + conf_n = 0; + conf_box1 = 0.0; + conf_box2 = 0.0; + + for(int m = 23; m <= 42; m++){ + for(int n = 43; n <= 82; n++){ + //conf_box1 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[4][m][n])); + conf_box1 = FM_buf_acc[4][m][n]; + if(conf_box1 > conf_thresh){ + conf_thresh = conf_box1; + conf_j = 0; + conf_m = m; + conf_n = n; + + } + } + } + + for(int m = 23; m <= 42; m++){ + for(int n = 43; n <= 82; n++){ + //conf_box2 = (FIX_32_25)1 / ((FIX_32_25)1 + my_exp_fix(-FM_buf_acc[9][m][n])); + conf_box2 = FM_buf_acc[9][m][n]; + if(conf_box2 > conf_thresh){ + conf_thresh = conf_box2; + conf_j = 1; + conf_m = m; + conf_n = n; + } + } + } + + if( conf_j == 0 ) { + // first bounding box + predict_box[3][0] = FM_buf_acc[0][conf_m][conf_n]; + predict_box[3][1] = FM_buf_acc[1][conf_m][conf_n]; + predict_box[3][2] = FM_buf_acc[2][conf_m][conf_n]; + predict_box[3][3] = FM_buf_acc[3][conf_m][conf_n]; + predict_box[3][4] = conf_thresh; + + } + else if( conf_j == 1 ) { + // second bounding box + predict_box[3][0] = FM_buf_acc[5][conf_m][conf_n]; + predict_box[3][1] = FM_buf_acc[6][conf_m][conf_n]; + predict_box[3][2] = FM_buf_acc[7][conf_m][conf_n]; + predict_box[3][3] = FM_buf_acc[8][conf_m][conf_n]; + predict_box[3][4] = conf_thresh; + } + + constant[3][0] = conf_j; + constant[3][1] = conf_n-43; + constant[3][2] = conf_m-23; + + //printf("3: conf_m: %d, conf_n:%d\n", conf_m-1, conf_n-1); + +} + + +inline FIX_FM relu_single( FIX_FM d ) { + if( d > 6 ) + return 6; + if( d < 0 ) + return 0; + return d; +} + + + +void relu_copy_buf_to_DDR( uint512* dest, int buf_id, FIX_FM src[32][44][84], int offset_h, int offset_w) +{ + uint512* dest_ptr = dest + 44*84*buf_id + (offset_h*22)*84 + (offset_w*42); + + for(int h = 0; h < 44; h++) { + + + for(int w = 0; w < 84; w++) { +#pragma HLS pipeline + + uint512 DATA = 0; + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + FIX_FM d = relu_single(src[c][h][w]); + DATA.range(FM_RG + 16*c, 16*c) = d.range(FM_RG, 0); + } + dest_ptr[w].range(511, 0) = DATA.range(511, 0); + } + + dest_ptr += 84; + } +} + + + + +void relu_copy_buf_to_DDR_acc( uint512* dest, int buf_id, FIX_FM_acc src[32][44][84], int offset_h, int offset_w) +{ + uint512* dest_ptr = dest + 44*84*buf_id + (offset_h*22)*84 + (offset_w*42); + + for(int h = 0; h < 44; h++) { + + for(int w = 0; w < 84; w++) { +#pragma HLS pipeline + + uint512 DATA = 0; + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + FIX_FM d = relu_single((FIX_FM)src[c][h][w]); + DATA.range(FM_RG + 16*c, 16*c) = d.range(FM_RG, 0); + } + dest_ptr[w].range(511, 0) = DATA.range(511, 0); + } + + dest_ptr += 84; + } +} + + + +void load_buf_from_DDR( FIX_FM dest[32][44][84], uint512* src, int buf_id) +{ + uint512* src_ptr = src + 44*84*buf_id; + + for(int h = 0; h < 44; h++) { + + for(int w = 0; w < 84; w++) { +#pragma HLS pipeline II=1 + + uint512 DATA= src_ptr[w]; + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + dest[c][h][w].range(FM_RG, 0) = DATA.range(FM_RG + c*16, 16*c); + } + } + src_ptr += 84; + } +} + + + + +void load_weight_1x1_from_axi( FIX_WT dest[32][32], uint512 src[32]) +{ + + for(int ci = 0; ci < 32; ci++) { +#pragma HLS pipeline + uint512 DATA = 0; + DATA.range(511, 0) = src[ci].range(511, 0); + for(int co = 0; co < 32; co++) { +#pragma HLS unroll + dest[co][ci].range(WT_RG, 0) = DATA.range(WT_RG + co*16, co*16); + } + } +} + + + +void load_weight_3x3_from_axi( FIX_WT dest[32][3][3], uint512 src[3][3]) +{ + for(int m = 0; m < 3; m++) { + for(int n = 0; n < 3; n++) { +#pragma HLS pipeline + uint512 DATA = 0; + DATA.range(511, 0) = src[m][n].range(511, 0); + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + + dest[c][m][n].range(WT_RG, 0) = DATA.range(WT_RG + c*16, c*16); + } + } + } +} + + + +void load_bias_from_axi(FIX_WT dest[32], uint512 src) +{ + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + dest[c].range(WT_RG, 0) = src.range(WT_RG + c*16, c*16); + } +} + + +void set_bias_1x1( FIX_FM_acc buf[32][44][84], FIX_WT bias[32]) +{ + for(int h = 1; h <= 42; h+=2) { + for(int w = 1; w <= 82; w++) { +#pragma HLS pipeline + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + buf[c][h ][w] = bias[c]; + buf[c][h+1][w] = bias[c]; + } + } + } +} + + +void set_bias_3x3( FIX_FM buf[32][44][84], FIX_WT bias[32]) +{ + for(int h = 1; h <= 42; h+=2) { + for(int w = 1; w <= 82; w++) { +#pragma HLS pipeline + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + buf[c][h ][w] = bias[c]; + buf[c][h+1][w] = bias[c]; + } + } + } +} + + + +void load_dw1_pool_from_DDR( uint512* ddr_dw1_pool_burst, + FIX_FM buf[32][44][84], + int ch, int col, int row, int offset_h, int offset_w) +{ + uint512* ddr_dw1_pool_burst_ptr =ddr_dw1_pool_burst + ch*82*2*162*2 + (col*40 + offset_h*2)*162*2 + (row*80 + offset_w*2); + + for(int h = 0; h < 42; h++) { + for(int w = 0; w < 82; w++) { +#pragma HLS pipeline + uint512 DATA = 0; + DATA.range(511, 0) = ddr_dw1_pool_burst_ptr[w].range(511, 0); + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + + buf[c][h][w].range(FM_RG, 0) = DATA.range(FM_RG + c*16, c*16); + } + } + ddr_dw1_pool_burst_ptr += 162*2; + } +} + + + +void load_dw2_pool_from_DDR( uint512* ddr_dw2_pool_burst, + FIX_FM buf[32][44][84], + int ch, int col, int row, int offset_h, int offset_w) +{ + uint512* ddr_dw2_pool_burst_ptr = ddr_dw2_pool_burst + ch*42*2*82*2 + (col*40 + offset_h*2)*82*2 + (row*80 + offset_w*2); + + for(int h = 0; h < 42; h++) { + for(int w = 0; w < 82; w++) { +#pragma HLS pipeline + uint512 DATA = 0; + DATA.range(511, 0) = ddr_dw2_pool_burst_ptr[w].range(511, 0); + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + + buf[c][h][w].range(FM_RG, 0) = DATA.range(FM_RG + c*16, c*16); + } + } + ddr_dw2_pool_burst_ptr += 82*2; + } +} + + + + +void clear_buffer( FIX_FM_acc buf[32][44][84] ) +{ + for(int h = 0; h < 44; h+=2) { + for(int w = 0; w < 84; w++) { +#pragma HLS pipeline + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + buf[c][h ][w] = 0; + buf[c][h+1][w] = 0; + } + } + } +} + + +FIX_FM img_norm_ch[256] = { + -2.000000, -1.984314, -1.968627, -1.952941, -1.937255, -1.921569, -1.905882, -1.890196, -1.874510, -1.858824, -1.843137, -1.827451, -1.811765, -1.796078, -1.780392, -1.764706, -1.749020, + -1.733333, -1.717647, -1.701961, -1.686275, -1.670588, -1.654902, -1.639216, -1.623529, -1.607843, -1.592157, -1.576471, -1.560784, -1.545098, -1.529412, -1.513725, -1.498039, + -1.482353, -1.466667, -1.450980, -1.435294, -1.419608, -1.403922, -1.388235, -1.372549, -1.356863, -1.341176, -1.325490, -1.309804, -1.294118, -1.278431, -1.262745, -1.247059, + -1.231373, -1.215686, -1.200000, -1.184314, -1.168627, -1.152941, -1.137255, -1.121569, -1.105882, -1.090196, -1.074510, -1.058824, -1.043137, -1.027451, -1.011765, -0.996078, + -0.980392, -0.964706, -0.949020, -0.933333, -0.917647, -0.901961, -0.886275, -0.870588, -0.854902, -0.839216, -0.823529, -0.807843, -0.792157, -0.776471, -0.760784, -0.745098, + -0.729412, -0.713725, -0.698039, -0.682353, -0.666667, -0.650980, -0.635294, -0.619608, -0.603922, -0.588235, -0.572549, -0.556863, -0.541176, -0.525490, -0.509804, -0.494118, + -0.478431, -0.462745, -0.447059, -0.431373, -0.415686, -0.400000, -0.384314, -0.368627, -0.352941, -0.337255, -0.321569, -0.305882, -0.290196, -0.274510, -0.258824, -0.243137, + -0.227451, -0.211765, -0.196078, -0.180392, -0.164706, -0.149020, -0.133333, -0.117647, -0.101961, -0.086275, -0.070588, -0.054902, -0.039216, -0.023529, -0.007843, 0.007843, + 0.023529, 0.039216, 0.054902, 0.070588, 0.086275, 0.101961, 0.117647, 0.133333, 0.149020, 0.164706, 0.180392, 0.196078, 0.211765, 0.227451, 0.243137, 0.258824, + 0.274510, 0.290196, 0.305882, 0.321569, 0.337255, 0.352941, 0.368627, 0.384314, 0.400000, 0.415686, 0.431373, 0.447059, 0.462745, 0.478431, 0.494118, 0.509804, + 0.525490, 0.541176, 0.556863, 0.572549, 0.588235, 0.603922, 0.619608, 0.635294, 0.650980, 0.666667, 0.682353, 0.698039, 0.713725, 0.729412, 0.745098, 0.760784, + 0.776471, 0.792157, 0.807843, 0.823529, 0.839216, 0.854902, 0.870588, 0.886275, 0.901961, 0.917647, 0.933333, 0.949020, 0.964706, 0.980392, 0.996078, 1.011765, + 1.027451, 1.043137, 1.058824, 1.074510, 1.090196, 1.105882, 1.121569, 1.137255, 1.152941, 1.168627, 1.184314, 1.200000, 1.215686, 1.231373, 1.247059, 1.262745, + 1.278431, 1.294118, 1.309804, 1.325490, 1.341176, 1.356863, 1.372549, 1.388235, 1.403922, 1.419608, 1.435294, 1.450980, 1.466667, 1.482353, 1.498039, 1.513725, + 1.529412, 1.545098, 1.560784, 1.576471, 1.592157, 1.607843, 1.623529, 1.639216, 1.654902, 1.670588, 1.686275, 1.701961, 1.717647, 1.733333, 1.749020, 1.764706, + 1.780392, 1.796078, 1.811765, 1.827451, 1.843137, 1.858824, 1.874510, 1.890196, 1.905882, 1.921569, 1.937255, 1.952941, 1.968627, 1.984314, 2.000000 +}; + + + +void load_image_chunk_norm(FIX_FM img_buf[32][44][84], uint8 image_in_raw_pad_burst[3*162*2*322*2], + int col, int row, int offset_h = 0, int offset_w = 0) +{ + uint8* image_in_raw_pad_burst_ptr; + + image_in_raw_pad_burst_ptr = image_in_raw_pad_burst + (col*40 + offset_h*2)*322*2 + row*80 + offset_w*2; + + for(int i = 0; i < 44; i++) { + for(int j = 0; j < 84; j++) { +#pragma HLS pipeline + img_buf[0][i][j] = img_norm_ch[((image_in_raw_pad_burst_ptr[j])).to_uint()]; + } + image_in_raw_pad_burst_ptr += 322*2; + } + + image_in_raw_pad_burst_ptr = image_in_raw_pad_burst + 1*162*2*322*2 + (col*40 + offset_h*2)*322*2 + row*80 + offset_w*2; + for(int i = 0; i < 44; i++) { + for(int j = 0; j < 84; j++) { +#pragma HLS pipeline + img_buf[1][i][j] = img_norm_ch[((image_in_raw_pad_burst_ptr[j])).to_uint()]; + } + image_in_raw_pad_burst_ptr += 322*2; + } + + image_in_raw_pad_burst_ptr = image_in_raw_pad_burst + 2*162*2*322*2 + (col*40 + offset_h*2)*322*2 + row*80 + offset_w*2; + for(int i = 0; i < 44; i++) { + for(int j = 0; j < 84; j++) { +#pragma HLS pipeline + img_buf[2][i][j] = img_norm_ch[((image_in_raw_pad_burst_ptr[j])).to_uint()]; + } + image_in_raw_pad_burst_ptr += 322*2; + } +} + + +void Relu6_3x3( FIX_FM buf[32][44][84]) +{ + for(int h = 1; h <= 42; h+=2) { + for(int w = 1; w <= 82; w++) { +#pragma HLS pipeline + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + buf[c][h ][w] = relu_single(buf[c][h ][w]); + buf[c][h+1][w] = relu_single(buf[c][h+1][w]); + } + } + } +} + + + + + +inline FIX_FM relu_max(FIX_FM a, FIX_FM b, FIX_FM c, FIX_FM d) +{ + FIX_FM t1, t2; + + if(a > b) t1 = relu_single(a); + else t1 = relu_single(b); + + if(c > d) t2 = relu_single(c); + else t2 = relu_single(d); + + if(t1 > t2) return t1; + else return t2; +} + + + + +void Relu_Max_Pooling( + FIX_FM_acc buf_in[32][44][84], + uint512* ddr_dw1_pool_burst, + uint512* ddr_dw2_pool_burst, + uint512* ddr_buf, int buf_id, + int ch, int col, int row, int offset_h, int offset_w, int layer) +{ + + uint512* buf_in_ptr = ddr_buf + buf_id*44*84 + (1 + offset_h*22)*84 + offset_w*42; + uint512* ddr_dw1_pool_burst_ptr = ddr_dw1_pool_burst + ch*82*2*162*2 + (1 + col*20 + offset_h*2)*162*2 + (row*40 + offset_w*2); + uint512* ddr_dw2_pool_burst_ptr = ddr_dw2_pool_burst + ch*42*2*82*2 + (1 + col*20 + offset_h*2)*82*2 + (row*40 + offset_w*2); + +#pragma HLS array_partition variable=buf_in dim=1 complete + + for(int h = 1; h <= 20; h++) { + for(int w = 1; w <= 40; w++) { +#pragma HLS pipeline II=2 + uint512 DATA = 0; + for(int c = 0; c < 32; c++) { +#pragma HLS unroll + FIX_FM d = relu_max(buf_in[c][h*2-1][w*2-1], buf_in[c][h*2-1][w*2], + buf_in[c][h*2][w*2-1], buf_in[c][h*2][w*2]); + + DATA.range(FM_RG + c*16, c*16) = d.range(FM_RG, 0); + } + + if( layer == 1 ) { + ddr_dw1_pool_burst_ptr[w].range(511, 0) = DATA.range(511, 0); + } + else if( layer == 2 ) { + ddr_dw2_pool_burst_ptr[w].range(511, 0) = DATA.range(511, 0); + } + else if( layer == 3 ) { + buf_in_ptr[w].range(511, 0) = DATA.range(511, 0); + } + } + + buf_in_ptr += 84; + ddr_dw1_pool_burst_ptr += 162*2; + ddr_dw2_pool_burst_ptr += 82*2; + } +} + + +void load_and_reorg_part( uint512* buf_in, int buf_id, + FIX_FM buf_out_1[32][44][84], + FIX_FM buf_out_2[32][44][84], + FIX_FM buf_out_3[32][44][84], + FIX_FM_acc buf_out_4[32][44][84], // borrow one + int offset_h, int offset_w) +{ + uint512* buf_in_ptr = buf_in + buf_id*44*84; + + for(int h = 1; h <= 40; h+=4) { + for(int w = 1; w <= 80; w+=4) { + + uint512 DATA[16] = {0}; + DATA[0].range(511, 0) = buf_in_ptr[(h )*84 + w ].range(511, 0); + DATA[1].range(511, 0) = buf_in_ptr[(h+2)*84 + w ].range(511, 0); + DATA[2].range(511, 0) = buf_in_ptr[(h )*84 + w+2].range(511, 0); + DATA[3].range(511, 0) = buf_in_ptr[(h+2)*84 + w+2].range(511, 0); + DATA[4].range(511, 0) = buf_in_ptr[(h )*84 + w+1].range(511, 0); + DATA[5].range(511, 0) = buf_in_ptr[(h+2)*84 + w+1].range(511, 0); + DATA[6].range(511, 0) = buf_in_ptr[(h )*84 + w+3].range(511, 0); + DATA[7].range(511, 0) = buf_in_ptr[(h+2)*84 + w+3].range(511, 0); + DATA[8].range(511, 0) = buf_in_ptr[(h+1)*84 + w ].range(511, 0); + DATA[9].range(511, 0) = buf_in_ptr[(h+3)*84 + w ].range(511, 0); + DATA[10].range(511, 0) = buf_in_ptr[(h+1)*84 + w+2].range(511, 0); + DATA[11].range(511, 0) = buf_in_ptr[(h+3)*84 + w+2].range(511, 0); + DATA[12].range(511, 0) = buf_in_ptr[(h+1)*84 + w+1].range(511, 0); + DATA[13].range(511, 0) = buf_in_ptr[(h+3)*84 + w+1].range(511, 0); + DATA[14].range(511, 0) = buf_in_ptr[(h+1)*84 + w+3].range(511, 0); + DATA[15].range(511, 0) = buf_in_ptr[(h+3)*84 + w+3].range(511, 0); + + for(int c = 0; c < 8; c++) { + /////////////////// + buf_out_1[c*4][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[0].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[1].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[2].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[3].range(FM_RG + c * 16, c * 16); + + buf_out_1[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[4].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[5].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[6].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[7].range(FM_RG + c * 16, c * 16); + + buf_out_1[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[8].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[9].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[10].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[11].range(FM_RG + c * 16, c * 16); + + buf_out_1[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[12].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[13].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[14].range(FM_RG + c * 16, c * 16); + buf_out_1[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[15].range(FM_RG + c * 16, c * 16); + + /////////////////// + buf_out_2[c*4][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[0].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[1].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[2].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[3].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_2[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[4].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[5].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[6].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[7].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_2[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[8].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[9].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[10].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[11].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_2[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[12].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[13].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[14].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + buf_out_2[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[15].range(FM_RG + (c + 8) * 16, (c + 8) * 16); + + buf_out_3[c*4][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[0].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[1].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[2].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[3].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + buf_out_3[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[4].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[5].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[6].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[7].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + buf_out_3[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[8].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[9].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[10].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[11].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + buf_out_3[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[12].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(FM_RG, 0) = DATA[13].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[14].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + buf_out_3[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(FM_RG, 0) = DATA[15].range(FM_RG + (c + 16) * 16, (c + 16) * 16); + + ///////////////////// + buf_out_4[c*4][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[0].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[1].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[2].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[3].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + + buf_out_4[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[4].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[5].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+1][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[6].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+1][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[7].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + + buf_out_4[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[8].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[9].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+2][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[10].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+2][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[11].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + + buf_out_4[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[12].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2 + offset_w*42].range(WT_RG, 0) = DATA[13].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+3][(h+1)/2 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[14].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + buf_out_4[c*4+3][(h+1)/2+1 + offset_h*22][(w+1)/2+1 + offset_w*42].range(WT_RG, 0) = DATA[15].range(WT_RG + (c + 24) * 16, (c + 24) * 16); + } + } + } +} + + + +void load_and_reorg( uint512* buf_1, int buf_id_1, uint512* buf_2, int buf_id_2, + uint512* buf_3, int buf_id_3, uint512* buf_4, int buf_id_4, + FIX_FM buf_out_1[32][44][84], + FIX_FM buf_out_2[32][44][84], + FIX_FM buf_out_3[32][44][84], + FIX_FM_acc buf_out_4[32][44][84]) +{ + load_and_reorg_part( buf_1, buf_id_1, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 0, 0); + load_and_reorg_part( buf_2, buf_id_2, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 0, 1); + load_and_reorg_part( buf_3, buf_id_3, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 1, 0); + load_and_reorg_part( buf_4, buf_id_4, buf_out_1, buf_out_2, buf_out_3, buf_out_4, 1, 1); +} + + +void local_buf_copy( FIX_FM dest[32][44][84], FIX_FM_acc src[32][44][84]) +{ + for(int h = 0; h < 44; h+=2) { + for(int w = 0; w < 84; w++) { +#pragma HLS pipeline + for(int c = 0; c < 32; c++) { + dest[c][h ][w].range(FM_RG, 0) = src[c][h ][w].range(FM_RG, 0); + dest[c][h+1][w].range(FM_RG, 0) = src[c][h+1][w].range(FM_RG, 0); + } + } + } +} + +void SkyNet( uint8 image_in_raw_pad[3*162*2*322*2], + + uint512 conv_weight_1x1_all[1000][32], + uint512 conv_weight_3x3_all[1000][3][3], + uint512 bias_all[500], + + uint512 DDR_dw1_pool_out_PL_burst[64/32*82*2*162*2], + uint512 DDR_dw2_pool_out_PL_burst[96/32*42*2*82*2], + uint512 DDR_buf_burst[128*44*84], + + float debug[10][32][44][84], + float predict_boxes[4][5], + int constant[4][3] +) +{ + +#pragma HLS INTERFACE m_axi depth=3*162*322 port=image_in_raw_pad offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=306*32*32 port=conv_weight_1x1_all offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=24*32*3*3 port=conv_weight_3x3_all offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=63*32 port=bias_all offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=106272 port=DDR_dw1_pool_out_PL_burst offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=41328 port=DDR_dw2_pool_out_PL_burst offset=slave bundle=INPUT +#pragma HLS INTERFACE m_axi depth=473088 port=DDR_buf_burst offset=slave bundle=INPUT + +#pragma HLS INTERFACE m_axi depth=5 port=predict_boxes offset=slave bundle=OUTPUT +#pragma HLS INTERFACE m_axi depth=5 port=constant offset=slave bundle=OUTPUT +#pragma HLS INTERFACE m_axi depth=10*32*22*42 port=debug offset=slave bundle=OUTPUT + +#pragma HLS INTERFACE s_axilite register port=return + + +#pragma HLS ALLOCATION instances=CONV_1x1 limit=1 function +#pragma HLS ALLOCATION instances=DW_CONV_3x3 limit=1 function +#pragma HLS ALLOCATION instances=Relu_Max_Pooling limit=1 function +#pragma HLS ALLOCATION instances=load_image_chunk_norm limit=1 function + + + int CI_N, CO_N; + int weight_3x3_index, weight_1x1_index, bias_3x3_index, bias_1x1_index; + + /////////////////////////////// DW1_CONV_3x3 + DW1_CONV_1x1 + POOL //////////////////////////// + /// DW1_CONV_3x3 + weight_3x3_index = 0; + bias_3x3_index = 0; + weight_1x1_index = 0; + bias_1x1_index = 1; + + CI_N = 32 / 32; + CO_N = 64 / 32; + + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index]); + load_bias_from_axi(bias_buf[1], bias_all[bias_1x1_index + 0]); + load_bias_from_axi(bias_buf[2], bias_all[bias_1x1_index + 1]); + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + 0]); + load_weight_1x1_from_axi(weight_buf_1x1[1], conv_weight_1x1_all[weight_1x1_index + 1]); + + for(int row = 0; row < 8; row++) { + + load_image_chunk_norm(FM_buf1, image_in_raw_pad, 0, row, 0/4, row/4); + for(int col = 0; col < 8; col++) { + set_bias_3x3(FM_buf2, bias_buf[0]); + + if( col % 2 == 0 ) { + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 1); + load_image_chunk_norm(FM_buf3, image_in_raw_pad, col+1, row, (col+1)/4, row/4); + } + else { + DW_CONV_3x3(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 1); + load_image_chunk_norm(FM_buf1, image_in_raw_pad, col+1, row, (col+1)/4, row/4); + } + + for(int co = 0; co < CO_N; co++) { + set_bias_1x1(FM_buf_acc, bias_buf[1 + co]); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[co]); + Relu_Max_Pooling(FM_buf_acc, DDR_dw1_pool_out_PL_burst, DDR_dw2_pool_out_PL_burst, DDR_buf_burst, 0, co, col, row, col/4, row/4, 1); + + } + } + } + + + printf("DW1 Done\n"); + + + /////////////////////////////// DW2_CONV_3x3 + DW2_CONV_1x1 + POOL //////////////////////////// + /// DW2_CONV_3x3 + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + load_weight_3x3_from_axi(weight_buf_3x3[1], conv_weight_3x3_all[weight_3x3_index + 0]); + load_weight_3x3_from_axi(weight_buf_3x3[2], conv_weight_3x3_all[weight_3x3_index + 1]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + 0]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + 1]); + + CI_N = 64 / 32; + CO_N = 96 / 32; + + for(int row = 0; row < 4; row++) { + for(int col = 0; col < 4; col++) { + + load_dw1_pool_from_DDR(DDR_dw1_pool_out_PL_burst, FM_buf1, 0, col, row, col/2, row/2); + set_bias_3x3(FM_buf2, bias_buf[0 + 0]); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[1 + 0], bias_buf[0 + 0], 1); + + load_dw1_pool_from_DDR(DDR_dw1_pool_out_PL_burst, FM_buf4, 1, col, row, col/2, row/2); + set_bias_3x3(FM_buf3, bias_buf[0 + 1]); + DW_CONV_3x3(FM_buf4, FM_buf3, weight_buf_3x3[1 + 1], bias_buf[0 + 1], 1); + + for(int co = 0; co < CO_N; co++) { + load_bias_from_axi(bias_buf[2], bias_all[bias_1x1_index + co]); + set_bias_1x1(FM_buf_acc, bias_buf[2]); + + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + 0 + co * CI_N]); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[0]); + + load_weight_1x1_from_axi(weight_buf_1x1[1], conv_weight_1x1_all[weight_1x1_index + 1 + co * CI_N]); + CONV_1x1(FM_buf3, FM_buf_acc, weight_buf_1x1[1]); + + Relu_Max_Pooling(FM_buf_acc, DDR_dw1_pool_out_PL_burst, DDR_dw2_pool_out_PL_burst, DDR_buf_burst, 0, co, col, row, col/2, row/2, 2); + } + } + } + + + printf("DW2 Done\n"); + + + /////////////////////////////// DW3_CONV_3x3 + DW3_CONV_1x1 + POOL //////////////////////////// + + + /// DW3_CONV_3x3 + // output in DDR_buf[0] - DDR_buf[2] + + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + 0]); + load_weight_3x3_from_axi(weight_buf_3x3[1], conv_weight_3x3_all[weight_3x3_index + 1]); + load_weight_3x3_from_axi(weight_buf_3x3[2], conv_weight_3x3_all[weight_3x3_index + 2]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + 0]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + 1]); + load_bias_from_axi(bias_buf[2], bias_all[bias_3x3_index + 2]); + + CI_N = 96 / 32; + CO_N = 192 / 32; + for(int row = 0; row < 2; row++) { + for(int col = 0; col < 2; col++) { + + load_dw2_pool_from_DDR(DDR_dw2_pool_out_PL_burst, FM_buf1, 0, col, row, col/1, row/1 ); + set_bias_3x3(FM_buf2, bias_buf[0 + 0]); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[0 + 0], bias_buf[0 + 0], 1); + + load_dw2_pool_from_DDR(DDR_dw2_pool_out_PL_burst, FM_buf1, 1, col, row, col/1, row/1 ); + set_bias_3x3(FM_buf3, bias_buf[0 + 1]); + DW_CONV_3x3(FM_buf1, FM_buf3, weight_buf_3x3[0 + 1], bias_buf[0 + 1], 1); + + load_dw2_pool_from_DDR(DDR_dw2_pool_out_PL_burst, FM_buf1, 2, col, row, col/1, row/1 ); + set_bias_3x3(FM_buf4, bias_buf[0 + 2]); + DW_CONV_3x3(FM_buf1, FM_buf4, weight_buf_3x3[0 + 2], bias_buf[0 + 2], 1); + + /// DW3_CONV_1x1 + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[3], bias_all[bias_1x1_index + co]); + set_bias_1x1(FM_buf_acc, bias_buf[3]); + + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + 0 + co * CI_N]); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[0]); + + load_weight_1x1_from_axi(weight_buf_1x1[1], conv_weight_1x1_all[weight_1x1_index + 1 + co * CI_N]); + CONV_1x1(FM_buf3, FM_buf_acc, weight_buf_1x1[1]); + + load_weight_1x1_from_axi(weight_buf_1x1[2], conv_weight_1x1_all[weight_1x1_index + 2 + co * CI_N]); + CONV_1x1(FM_buf4, FM_buf_acc, weight_buf_1x1[2]); + + relu_copy_buf_to_DDR_acc(DDR_buf_burst, 100 + co + (col*2 + row) * CO_N, FM_buf_acc, 0, 0); + Relu_Max_Pooling(FM_buf_acc, DDR_dw1_pool_out_PL_burst, DDR_dw2_pool_out_PL_burst, DDR_buf_burst, 6 + co, co, col, row, col, row, 3 ); + } + } + } + + + printf("DW3 Done\n"); + + + /////////////////////////////// DW4_CONV_3x3 + DW4_CONV_1x1 //////////////////////////// + + /// DW4_CONV_3x3 + // input in DDR_buf[6] - DDR_buf[11] + // output in DDR_buf[12] - DDR_buf[17] + + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + CI_N = 192 / 32; + + /// conv3x3: ping-pong in: FM_buf1 and FM_buf3 + /// conv3x3: out: FM_buf2 + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 6 + 0); + for(int c = 0; c < CI_N; c++) { + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c]); + set_bias_3x3(FM_buf2, bias_buf[0]); + + if( c % 2 == 0 ) { + load_buf_from_DDR(FM_buf3, DDR_buf_burst, 6 + c+1); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + } + else { + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 6 + c+1); + DW_CONV_3x3(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + } + + relu_copy_buf_to_DDR(DDR_buf_burst, 12 + c, FM_buf2, 0, 0); + } + + /// DW4_CONV_1x1 + // input in DDR_buf[12] - DDR_buf[17] + // output in DDR_buf[18] - DDR_buf[29] + + CO_N = 384 / 32; + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[0], bias_all[bias_1x1_index + co]); + set_bias_1x1(FM_buf_acc, bias_buf[0]); + + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 12 + 0); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + + if( ci % 2 == 0) { + load_buf_from_DDR(FM_buf2, DDR_buf_burst, 12 + ci+1); + CONV_1x1(FM_buf1, FM_buf_acc, weight_buf_1x1[0]); + } + else { + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 12 + ci+1); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[0]); + } + } + relu_copy_buf_to_DDR_acc(DDR_buf_burst, 18 + co, FM_buf_acc, 0, 0); + } + + + printf("DW4 Done\n"); + + + /////////////////////////////// DW5_CONV_3x3 + DW5_CONV_1x1 //////////////////////////// + + /// DW5_CONV_3x3 + // input in DDR_buf[18] - DDR_buf[29] + // output in DDR_buf[30] - DDR_buf[41] + + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + CI_N = 384 / 32; + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 18 + 0); + for(int c = 0; c < CI_N; c++) { + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c]); + set_bias_3x3(FM_buf2, bias_buf[0]); + + if( c % 2 == 0) { + load_buf_from_DDR(FM_buf3, DDR_buf_burst, 18 + c+1); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + } + else { + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 18 + c+1); + DW_CONV_3x3(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + } + + + relu_copy_buf_to_DDR(DDR_buf_burst, 30 + c, FM_buf2, 0, 0); + } + + /// DW5_CONV_1x1 + // input in DDR_buf[30] - DDR_buf[41] + // output in DDR_buf[42] - DDR_buf[57] + + CO_N = 512 / 32; + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[0], bias_all[bias_1x1_index + co]); + set_bias_1x1(FM_buf_acc, bias_buf[0]); + + load_buf_from_DDR(FM_buf2, DDR_buf_burst, 30 + 0); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + + if( ci % 2 == 0) { + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 30 + ci+1); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[0]); + } + else { + load_buf_from_DDR(FM_buf2, DDR_buf_burst, 30 + ci+1); + CONV_1x1(FM_buf1, FM_buf_acc, weight_buf_1x1[0]); + } + } + relu_copy_buf_to_DDR_acc(DDR_buf_burst, 42 + co, FM_buf_acc, 0, 0); + } + + + printf("DW5 Done\n"); + + /////////////////////////////// CONCAT DW3_CONV_1x1_OUT & DW5_CONV_1x1_OUT ///////////// + /////////////////////////////// DW6_CONV_3x3 + DW6_CONV_1x1 //////////////////////////// + + //// DW6_CONV_3x3 + weight_3x3_index += CI_N; + bias_3x3_index += CI_N + CO_N; + weight_1x1_index += CO_N * CI_N; + bias_1x1_index += CO_N + CO_N; + + + // First half: 0~767 channels from DW3_conv_1x1_output + // Output of DW3_CONV_1x1_OUT are stored in DDR_buf[100] to DDR_buf[123] + // Output of first half are stored in DDR_buf[58] to DDR_buf[81] + CI_N = 768 / 32; + for(int c = 0; c < CI_N; c+=4) { + + // From DDR_buf[100] to DDR_buf[123] + // Img 0: 100 ~ 105 + // Img 1: 106 ~ 111 + // Img 2: 112 ~ 117 + // Img 3: 118 ~ 123 + + load_and_reorg(DDR_buf_burst, 100 + c/4, DDR_buf_burst, 100 + c/4 + 6, + DDR_buf_burst, 100 + c/4 + 6 * 2, DDR_buf_burst, 100 + c/4 + 6 * 3, + FM_buf1, FM_buf3, FM_buf4, FM_buf_acc); + + //// 1/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c + 0]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c + 0]); + set_bias_3x3(FM_buf2, bias_buf[0]); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + local_buf_copy(FM_buf1, FM_buf_acc); + relu_copy_buf_to_DDR(DDR_buf_burst, 58 + c + 0, FM_buf2, 0, 0); + + //// 2/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[1], conv_weight_3x3_all[weight_3x3_index + c + 1]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + c + 1]); + set_bias_3x3(FM_buf2, bias_buf[1]); + DW_CONV_3x3(FM_buf3, FM_buf2, weight_buf_3x3[1], bias_buf[1], 0); + relu_copy_buf_to_DDR(DDR_buf_burst, 58 + c + 1, FM_buf2, 0, 0); + + //// 3/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[2], conv_weight_3x3_all[weight_3x3_index + c + 2]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c + 2]); + set_bias_3x3(FM_buf2, bias_buf[0]); + DW_CONV_3x3(FM_buf4, FM_buf2, weight_buf_3x3[2], bias_buf[0], 0); + relu_copy_buf_to_DDR(DDR_buf_burst, 58 + c + 2, FM_buf2, 0, 0); + + //// 4/4 channels + load_weight_3x3_from_axi(weight_buf_3x3[3], conv_weight_3x3_all[weight_3x3_index + c + 3]); + load_bias_from_axi(bias_buf[1], bias_all[bias_3x3_index + c + 3]); + set_bias_3x3(FM_buf2, bias_buf[1]); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[3], bias_buf[1], 0); + relu_copy_buf_to_DDR(DDR_buf_burst, 58 + c + 3, FM_buf2, 0, 0); + } + + // Second half: 768~1280 channels from DW5_conv_1x1_output + // Output of DW5_CONV_1x1_OUT are stored in DDR_buf[42] - DDR_buf[57] + // Output of first half are stored in DDR_buf[82] to DDR_buf[97] + CI_N = 512 / 32; + + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 42 + 0); + for(int c = 0; c < CI_N; c++) { + load_weight_3x3_from_axi(weight_buf_3x3[0], conv_weight_3x3_all[weight_3x3_index + c + 24]); + load_bias_from_axi(bias_buf[0], bias_all[bias_3x3_index + c + 24]); + set_bias_3x3(FM_buf2, bias_buf[0]); + + if( c % 2 == 0) { + load_buf_from_DDR(FM_buf3, DDR_buf_burst, 42 + c+1); + DW_CONV_3x3(FM_buf1, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + } + else { + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 42 + c+1); + DW_CONV_3x3(FM_buf3, FM_buf2, weight_buf_3x3[0], bias_buf[0], 0); + } + relu_copy_buf_to_DDR(DDR_buf_burst, 82 + c, FM_buf2, 0, 0); + } + + /// DW6_CONV_1x1 + // input in DDR_buf[58] - DDR_buf[97] + // output in DDR_buf[98] - DDR_buf[100] + + bias_1x1_index += 24; + CO_N = 96 / 32; + CI_N = 1280 / 32; + for(int co = 0; co < CO_N; co++) { + + load_bias_from_axi(bias_buf[0], bias_all[bias_1x1_index + co]); + set_bias_1x1(FM_buf_acc, bias_buf[0]); + + load_buf_from_DDR(FM_buf2, DDR_buf_burst, 58 + 0); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + + if( ci % 2 == 0) { + load_buf_from_DDR(FM_buf1, DDR_buf_burst, 58 + ci+1); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[0]); + } + else { + load_buf_from_DDR(FM_buf2, DDR_buf_burst, 58 + ci+1); + CONV_1x1(FM_buf1, FM_buf_acc, weight_buf_1x1[0]); + } + } + + relu_copy_buf_to_DDR_acc(DDR_buf_burst, 98 + co, FM_buf_acc, 0, 0); + } + + + printf("DW6 Done\n"); + + + /////////////////////////////// PW7_CONV_1x1 //////////////////////////// + weight_1x1_index += CO_N * CI_N; + // input in DDR_buf[98] - DDR_buf[100] + // output in FM_buf_acc + + CO_N = 32 / 32; + CI_N = 96 / 32; + for(int co = 0; co < CO_N; co++) { + clear_buffer(FM_buf_acc); + for(int ci = 0; ci < CI_N; ci++) { + load_weight_1x1_from_axi(weight_buf_1x1[0], conv_weight_1x1_all[weight_1x1_index + ci + co * CI_N]); + load_buf_from_DDR(FM_buf2, DDR_buf_burst, 98 + ci); + CONV_1x1(FM_buf2, FM_buf_acc, weight_buf_1x1[0]); + } + } + + printf("PW7 Done\n"); + + + compute_bounding_box(predict_boxes, constant); + + return; + + + +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.h new file mode 100644 index 000000000000..b4fe1c2517d2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/SkyNet_dataset/src/net_hls.h @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include "hls_stream.h" +#include +#include +#include + + + +//#define CSIM_DEBUG +//#define CSIM_CMP_OUTPUT + + +// for .range(Hi, Lo) +#define FM_RG 8 +#define FM_ACC_RG 11 +#define WT_RG 10 + + +#ifdef CSIM_DEBUG + typedef float FIX_32_4; //fix point + typedef float FIX_32_25; //fix point + typedef float FIX_FM; //fix point for feature map + typedef float FIX_FM_acc; //fix point for feature map + typedef float FIX_FM_last; + typedef float FIX_WT; //fix point for weights + typedef float FIX_32_16; + typedef float FIX_32_10; + typedef float FIX_32_12; + typedef float FIX_16_6; + typedef float FIX_16_5; + typedef float FIX_16_4; + typedef float FIX_16_10; + + typedef float uint8; + typedef float uint16; + typedef float uint128; + typedef float uint256; + typedef float uint512; + +#else + + typedef ap_fixed<9, 3, AP_RND, AP_SAT> FIX_FM; //fix point for feature map + typedef ap_fixed<12, 4, AP_RND, AP_SAT> FIX_FM_acc; //fix point for accumulation + typedef ap_fixed<11, 4, AP_RND, AP_SAT> FIX_WT; //fix point for weights + + typedef ap_fixed<16, 8, AP_RND, AP_SAT> FIX_16_8; + typedef ap_fixed<16, 6, AP_RND, AP_SAT> FIX_16_6; + typedef ap_fixed<16, 5, AP_RND, AP_SAT> FIX_16_5; + typedef ap_fixed<16, 4, AP_RND, AP_SAT> FIX_16_4; + typedef ap_fixed<16, 3, AP_RND, AP_SAT> FIX_16_3; + typedef ap_fixed<16, 10, AP_RND, AP_SAT> FIX_16_10; + typedef ap_fixed<32,16, AP_RND, AP_SAT> FIX_32_16; + typedef ap_fixed<32,12, AP_RND, AP_SAT> FIX_32_12; + typedef ap_fixed<32,10, AP_RND, AP_SAT> FIX_32_10; + typedef ap_fixed<32, 4, AP_RND, AP_SAT> FIX_32_4; + typedef ap_fixed<32, 7, AP_RND, AP_SAT> FIX_32_7; + typedef ap_fixed<32,25, AP_RND, AP_SAT> FIX_32_25; + + typedef ap_uint<2> uint2; + typedef ap_uint<4> uint4; + typedef ap_uint<8> uint8; + typedef ap_uint<16> uint16; + typedef ap_uint<256> uint256; + typedef ap_uint<512> uint512; + + +#endif + + +void SkyNet(uint8 image_in_raw_pad[3*162*2*322*2], + + uint512 fix_conv_weight_1x1_all_512bit[1000][32], + uint512 fix_conv_weight_3x3_all_512bit[1000][3][3], + uint512 fix_bias_all_512bit[500], + + uint512 DDR_dw1_pool_out_PL[64/32*82*2*162*2], + uint512 DDR_dw2_pool_out_PL[96/32*42*2*82*2], + + uint512 DDR_buf[128*44*84], + + float debug[10][32][44][84], + float predict_box[4][5], + int constant[4][3] +); + +void DW_CONV_3x3(FIX_FM bottom[32][44][84], + FIX_FM top[32][44][84], + FIX_WT weight[32][3][3], + FIX_WT bias[32], + int relu +); + +void CONV_1x1(FIX_FM bottom[32][44][84], + FIX_FM_acc top[32][44][84], + FIX_WT weights[32][32] +); + + +void fill_output_dw1_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw1_conv1x1( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw1_pool( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw2_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw2_conv1x1( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw2_pool( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw3_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw3_conv1x1( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw3_pool( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw4_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw4_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw5_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw5_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void fill_output_dw6_conv3x3( float buf[32][44][84], int ch, int col, int row); +void fill_output_dw6_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void fill_output_pw7_conv1x1( float buf[32][44][84], int ch, int col, int row); + +void PL_golden_compare_dw1_conv3x3(); +void PL_golden_compare_dw1_conv1x1(); +void PL_golden_compare_dw1_pool(); + +void PL_golden_compare_dw2_conv3x3(); +void PL_golden_compare_dw2_conv1x1(); +void PL_golden_compare_dw2_pool(); + +void PL_golden_compare_dw3_conv3x3(); +void PL_golden_compare_dw3_conv1x1(); +void PL_golden_compare_dw3_pool(); + +void PL_golden_compare_dw4_conv3x3(); +void PL_golden_compare_dw4_conv1x1(); + +void PL_golden_compare_dw5_conv3x3(); +void PL_golden_compare_dw5_conv1x1(); + +void PL_golden_compare_dw6_conv3x3(); +void PL_golden_compare_dw6_conv1x1(); + +void PL_golden_compare_pw7_conv1x1(); + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/add.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/add.hpp new file mode 100644 index 000000000000..c86afe0516c4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/add.hpp @@ -0,0 +1,8 @@ +#ifndef __ADD_HPP__ +#define __ADD_HPP__ + +#include "dcl.hpp" + +void compute_add(patch_blocks_t x, patch_blocks_t y, patch_blocks_t out); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/attention.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/attention.hpp new file mode 100644 index 000000000000..320a5562fa45 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/attention.hpp @@ -0,0 +1,30 @@ +#ifndef __ATTENTION_HPP__ +#define __ATTENTION_HPP__ + +#include "dcl.hpp" +#include "linear.hpp" + +enum AttentionLinear { + ATTN_Q = 0, + ATTN_K = 1, + ATTN_V = 2, + ATTN_PROJ = 3, + NUM_ATTN_LINEAR +}; + +extern fm_t attn_scale; + +void compute_q_matmul_k( + patch_blocks_t q, + patch_blocks_t k, + qxk_out_t attn, + softmax_info_t attn_softmax_info +); +void compute_attn_matmul_v( + patch_blocks_t v, + qxk_out_t attn, + softmax_info_t attn_softmax_info, + patch_blocks_t attn_matmul_v +); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/conv.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/conv.hpp new file mode 100644 index 000000000000..2a93f2bce9e2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/conv.hpp @@ -0,0 +1,11 @@ +#ifndef __CONV_HPP__ +#define __CONV_HPP__ + +#include "dcl.hpp" + +extern wt_patch_embed_t patch_embed_weights[FEATURE_DIM][INPUT_CHANNELS][PATCH_HEIGHT][PATCH_WIDTH]; +extern wt_bias_t patch_embed_bias[FEATURE_DIM]; + +void compute_patch_embed(image_t x, patch_blocks_t out, patch_blocks_t pos_embed); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/datatypes.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/datatypes.hpp new file mode 100644 index 000000000000..c0a39b278cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/datatypes.hpp @@ -0,0 +1,18 @@ +#ifndef __DATATYPES_HPP__ +#define __DATATYPES_HPP__ + +#include "model.hpp" +#include +#include + +typedef ap_fixed<32, 10> fm_t; +typedef ap_fixed<16, 2> wt_linear_t; +typedef ap_fixed<16, 7> wt_attn_bias_t; +typedef ap_fixed<16, 5> wt_bias_t; +typedef ap_fixed<16, 5> wt_norm_t; +typedef ap_fixed<16, 0> wt_patch_embed_t; + +typedef ap_ufixed<8, 0> pixel_t; +typedef pixel_t image_t[INPUT_CHANNELS][INPUT_HEIGHT][INPUT_WIDTH]; + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/dcl.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/dcl.hpp new file mode 100644 index 000000000000..3653f18ff134 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/dcl.hpp @@ -0,0 +1,9 @@ +#ifndef __DCL_HPP__ +#define __DCL_HPP__ + +#include "util.hpp" +#include "datatypes.hpp" +#include "model.hpp" +#include "hardware.hpp" + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/gelu.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/gelu.hpp new file mode 100644 index 000000000000..92a4befd8bb3 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/gelu.hpp @@ -0,0 +1,11 @@ +#ifndef __GELU_HPP__ +#define __GELU_HPP__ + +#include "dcl.hpp" + +fm_t gelu(fm_t x); + +template +hls::vector gelu(hls::vector x); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/hardware.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/hardware.hpp new file mode 100644 index 000000000000..dc7787b9a6f4 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/hardware.hpp @@ -0,0 +1,30 @@ +#ifndef __HARDWARE_HPP__ +#define __HARDWARE_HPP__ + +#include "datatypes.hpp" +#include "model.hpp" +#include "util.hpp" +#include "hls_vector.h" + +constexpr unsigned int AXI_XFER_BIT_WIDTH = 256; +constexpr unsigned int FEATURE_BLOCK_SIZE = (AXI_XFER_BIT_WIDTH / fm_t::width); +constexpr unsigned int NUM_FEATURE_BLOCKS = ceildiv(FEATURE_DIM, FEATURE_BLOCK_SIZE); + +constexpr unsigned int LINEAR_IN_SIZE = 2 * FEATURE_BLOCK_SIZE; +constexpr unsigned int LINEAR_OUT_SIZE = 2 * FEATURE_BLOCK_SIZE; +constexpr unsigned int ATTN_MATMUL_PARALLEL = 4; + +typedef hls::vector fm_block_t; +typedef fm_block_t fm_blocks_t[NUM_FEATURE_BLOCKS]; +typedef fm_blocks_t patch_blocks_t[NUM_PATCHES]; + +typedef hls::vector linear_in_t; +typedef hls::vector linear_out_t; + +typedef hls::vector heads_t; +typedef hls::vector attn_parallel_t; +typedef heads_t qxk_out_t[ceildiv(NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1, ATTN_MATMUL_PARALLEL)][NUM_PATCHES][ATTN_MATMUL_PARALLEL]; +typedef hls::vector softmax_info_row_t; +typedef softmax_info_row_t softmax_info_t[NUM_PATCHES]; + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/kernel.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/kernel.hpp new file mode 100644 index 000000000000..6542e54cd9c5 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/kernel.hpp @@ -0,0 +1,46 @@ +#ifndef __KERNEL_HPP__ +#define __KERNEL_HPP__ + +// https://support.xilinx.com/s/question/0D52E00006iHkfp/vivado-20153-hls-bug-gmph?language=en_US +#include +#define __gmp_const const + +#include "dcl.hpp" +#include "attention.hpp" +#include "layernorm.hpp" + +extern "C" +{ + void ViT_compute( + unsigned int num_images, + bool reload_one_time_weights, + image_t images[], + patch_blocks_t x[], + patch_blocks_t tmp1, + patch_blocks_t tmp2, + patch_blocks_t tmp3, + patch_blocks_t tmp4, + fm_block_t tmp_hidden[NUM_PATCHES * ceildiv(max(VIT_HIDDEN_DIM, EXPERT_HIDDEN_DIM), FEATURE_BLOCK_SIZE)], + qxk_out_t attn, + softmax_info_t attn_softmax_info, + wt_patch_embed_t patch_embed_weights[FEATURE_DIM][INPUT_CHANNELS][PATCH_HEIGHT][PATCH_WIDTH], + wt_bias_t patch_embed_bias[FEATURE_DIM], + patch_blocks_t pos_embed, + wt_linear_t attn_weights[NUM_LAYERS][NUM_ATTN_LINEAR][FEATURE_DIM][FEATURE_DIM], + wt_attn_bias_t attn_bias[NUM_LAYERS][NUM_ATTN_LINEAR][FEATURE_DIM], + wt_linear_t moe_w_gate[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][FEATURE_DIM], + wt_linear_t moe_weights_l1[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][EXPERT_HIDDEN_DIM][FEATURE_DIM], + wt_bias_t moe_bias_l1[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][EXPERT_HIDDEN_DIM], + wt_linear_t moe_weights_l2[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][FEATURE_DIM][EXPERT_HIDDEN_DIM], + wt_bias_t moe_bias_l2[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][FEATURE_DIM], + wt_linear_t vit_weights_l1[max((NUM_LAYERS + 1) / 2, 1U)][VIT_HIDDEN_DIM][FEATURE_DIM], + wt_bias_t vit_bias_l1[max((NUM_LAYERS + 1) / 2, 1U)][VIT_HIDDEN_DIM], + wt_linear_t vit_weights_l2[max((NUM_LAYERS + 1) / 2, 1U)][FEATURE_DIM][VIT_HIDDEN_DIM], + wt_bias_t vit_bias_l2[max((NUM_LAYERS + 1) / 2, 1U)][FEATURE_DIM], + wt_norm_t norm_weights[NUM_LAYERS][NUM_LAYER_NORMS][FEATURE_DIM], + wt_bias_t norm_bias[NUM_LAYERS][NUM_LAYER_NORMS][FEATURE_DIM], + unsigned int debug_id + ); +} + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/layernorm.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/layernorm.hpp new file mode 100644 index 000000000000..0f7169de4015 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/layernorm.hpp @@ -0,0 +1,21 @@ +#ifndef __LAYERNORM_HPP__ +#define __LAYERNORM_HPP__ + +#include "dcl.hpp" + +enum LayerNorm { + NORM_1 = 0, + NORM_2 = 1, + NUM_LAYER_NORMS +}; + +extern fm_t norm_eps; + +void load_norms( + wt_norm_t norm_weights[NUM_LAYER_NORMS][FEATURE_DIM], + wt_bias_t norm_bias[NUM_LAYER_NORMS][FEATURE_DIM] +); +void compute_norm1(patch_blocks_t x, patch_blocks_t out); +void compute_norm2(patch_blocks_t x, patch_blocks_t out); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/linear.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/linear.hpp new file mode 100644 index 000000000000..b4620cf7b1bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/linear.hpp @@ -0,0 +1,46 @@ +#ifndef __LINEAR_HPP__ +#define __LINEAR_HPP__ + +#include "dcl.hpp" +#include "hls_stream.h" + +constexpr unsigned int MAX_LINEAR_IN_DIM = VIT_HIDDEN_DIM; +constexpr unsigned int MAX_LINEAR_OUT_DIM = VIT_HIDDEN_DIM; +constexpr unsigned int MAX_LINEAR_DIM_PRODUCT = VIT_HIDDEN_DIM * FEATURE_DIM; + +typedef ap_fixed wt_wbias_t; +typedef hls::vector, LINEAR_OUT_SIZE> wt_linear_block_t; +typedef hls::vector wt_bias_block_t; + +extern wt_linear_block_t linear_weights_ping[ceildiv(MAX_LINEAR_DIM_PRODUCT, LINEAR_IN_SIZE * LINEAR_OUT_SIZE)]; +extern wt_bias_block_t linear_bias_ping[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)]; +extern wt_linear_block_t linear_weights_pong[ceildiv(MAX_LINEAR_DIM_PRODUCT, LINEAR_IN_SIZE * LINEAR_OUT_SIZE)]; +extern wt_bias_block_t linear_bias_pong[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)]; + +void load_linear_weights( + wt_linear_block_t weights_dst[ceildiv(MAX_LINEAR_DIM_PRODUCT, LINEAR_IN_SIZE * LINEAR_OUT_SIZE)], + wt_linear_t weights_src[], + unsigned int out_dim, + unsigned int in_dim +); +template +void load_linear_bias( + wt_bias_block_t bias_dst[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)], + T bias_src[], + unsigned int out_dim +); + +void compute_linear( + fm_block_t dst[], + const fm_block_t src[], + const wt_linear_block_t weights[], + const wt_bias_block_t bias[], + unsigned int out_dim, + unsigned int in_dim, + unsigned int expert, + bool use_gelu, + bool use_expert, + bool use_score +); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/model.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/model.hpp new file mode 100644 index 000000000000..eba5f23c7d9c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/model.hpp @@ -0,0 +1,22 @@ +#ifndef __MODEL_HPP__ +#define __MODEL_HPP__ + +constexpr unsigned int INPUT_CHANNELS = 3; +constexpr unsigned int INPUT_WIDTH = 256; +constexpr unsigned int INPUT_HEIGHT = 128; + +constexpr unsigned int FEATURE_DIM = 192; +constexpr unsigned int VIT_HIDDEN_DIM = 768; +constexpr unsigned int EXPERT_HIDDEN_DIM = 384; + +constexpr unsigned int PATCH_WIDTH = 16; +constexpr unsigned int PATCH_HEIGHT = 16; +constexpr unsigned int NUM_PATCHES = (INPUT_WIDTH / PATCH_WIDTH) * (INPUT_HEIGHT / PATCH_HEIGHT) + 1; + +constexpr unsigned int NUM_LAYERS = 12; +constexpr unsigned int NUM_HEADS = 3; + +constexpr unsigned int NUM_EXPERTS = 16; +constexpr unsigned int NUM_SELECTED_EXPERTS = 2; + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/moe.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/moe.hpp new file mode 100644 index 000000000000..4795922eaf42 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/moe.hpp @@ -0,0 +1,21 @@ +#ifndef __MOE_HPP__ +#define __MOE_HPP__ + +#include "dcl.hpp" + +extern unsigned int expert_queues[NUM_EXPERTS][NUM_PATCHES]; +extern fm_t expert_scores[NUM_EXPERTS][NUM_PATCHES]; +extern unsigned int expert_queue_lens[NUM_EXPERTS]; + +void load_w_gate(wt_linear_t w_gate_load[NUM_EXPERTS][FEATURE_DIM]); +void compute_moe( + patch_blocks_t gate_inp, + patch_blocks_t out, + fm_block_t tmp_hidden[], + wt_linear_t all_weights_l1[NUM_EXPERTS][EXPERT_HIDDEN_DIM][FEATURE_DIM], + wt_bias_t all_bias_l1[NUM_EXPERTS][EXPERT_HIDDEN_DIM], + wt_linear_t all_weights_l2[NUM_EXPERTS][FEATURE_DIM][EXPERT_HIDDEN_DIM], + wt_bias_t all_bias_l2[NUM_EXPERTS][FEATURE_DIM] +); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/tbutil.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/tbutil.hpp new file mode 100644 index 000000000000..66c86a4208b9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/tbutil.hpp @@ -0,0 +1,89 @@ +#ifndef __LOAD_UTIL_HPP__ +#define __LOAD_UTIL_HPP__ + +#include +#include +#include +#include +#include "linear.hpp" + +template +std::istream& read(std::istream& stream, ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& value) +{ + union { + float value; + char bytes[sizeof(float)]; + } readable; + stream.read(readable.bytes, sizeof(float)); + value = readable.value; + return stream; +} + +template +std::istream& read(std::istream& stream, hls::vector& vector) +{ + for (size_t i = 0; i < N; i++) + { + read(stream, vector[i]); + } + return stream; +} + +template +std::istream& read(std::istream& stream, T(&array)[N]) +{ + for (size_t i = 0; i < N; i++) + { + read(stream, array[i]); + } + return stream; +} + +// template +// void load_array(T& array, std::ifstream& file) +// { +// if (is_fixedtype()) +// { +// union { +// T value; +// char bytes[sizeof(T)]; +// } data; + +// file.read(data.bytes, sizeof(T)); +// array = data.value; +// } +// else +// { +// union { +// decltype(array[0]) value; +// char bytes[sizeof(decltype(array[0]))]; +// } data; + +// for (unsigned int i = 0; i < array.size(); i++) +// { +// file.read(data.bytes, sizeof(decltype(array[0]))); +// array[i] = data.value; +// } +// } +// } + +// template +// void load_array(T(&array)[N], std::ifstream& file) +// { +// for (unsigned int i = 0; i < N; i++) +// { +// load_array(array[i], file); +// } +// } + +// Template instantiations for debugging +template double fm_t::Base::to_double() const; +template double wt_linear_t::Base::to_double() const; +template double wt_attn_bias_t::Base::to_double() const; +template double wt_bias_t::Base::to_double() const; +template double wt_wbias_t::Base::to_double() const; +// template double wt_norm_t::Base::to_double() const; +template double wt_patch_embed_t::Base::to_double() const; +template double pixel_t::Base::to_double() const; + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/util.hpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/util.hpp new file mode 100644 index 000000000000..82e1f2afd8d1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/include/util.hpp @@ -0,0 +1,99 @@ +#ifndef __UTIL_HPP__ +#define __UTIL_HPP__ + +#include "hls_math.h" + +#define _LABEL_FOR_EACH_HELPER(line, var) _ln ## line ## _for_each_ ## var +#define _LABEL_FOR_EACH(line, var) _LABEL_FOR_EACH_HELPER(line, var) +#define FOR_EACH(var, limit) _LABEL_FOR_EACH(__LINE__, var): for (unsigned int var = 0; var < limit; var++) + +#define _LABEL_FOR_BLOCK_HELPER(line, var) _ln ## line ## _for_block_ ## var +#define _LABEL_FOR_BLOCK(line, var) _LABEL_FOR_BLOCK_HELPER(line, var) +#define FOR_BLOCK(var, limit, block_size) \ + constexpr unsigned int var##_step = (block_size); \ + constexpr unsigned int var##_limit = (limit); \ + constexpr unsigned int var##_iters = ((limit) + (block_size) - 1) / (block_size); \ + _LABEL_FOR_BLOCK(__LINE__, var): for ( \ + unsigned int var##_base = 0, var##_block = 0; \ + var##_base < var##_limit; \ + var##_base += var##_step, var##_block++ \ + ) + +#define _LABEL_FOR_OFFSET_HELPER(line, var) _ln ## line ## _for_offset_ ## var +#define _LABEL_FOR_OFFSET(line, var) _LABEL_FOR_OFFSET_HELPER(line, var) +#define FOR_OFFSET(var) \ + _LABEL_FOR_OFFSET(__LINE__, var): for ( \ + unsigned int var##_offset = 0, var = var##_base; \ + var##_offset < var##_step; \ + var##_offset++, var++ \ + ) \ + if (var##_limit % var##_step == 0 || var < var##_limit) + +#define _LABEL_FOR_OFFSET_NOCHK_HELPER(line, var) _ln ## line ## _for_offset_ ## var +#define _LABEL_FOR_OFFSET_NOCHK(line, var) _LABEL_FOR_OFFSET_NOCHK_HELPER(line, var) +#define FOR_OFFSET_NOCHK(var) \ + static_assert(var##_limit % var##_step == 0, "Cannot use FOR_OFFSET_NOCHK; use FOR_OFFSET instead."); \ + _LABEL_FOR_OFFSET_NOCHK(__LINE__, var): for ( \ + unsigned int var##_offset = 0, var = var##_base; \ + var##_offset < var##_step; \ + var##_offset++, var++ \ + ) + +#define _LABEL_FOR_OFFSET_UNSAFE_HELPER(line, var) _ln ## line ## _for_offset_ ## var +#define _LABEL_FOR_OFFSET_UNSAFE(line, var) _LABEL_FOR_OFFSET_UNSAFE_HELPER(line, var) +#define FOR_OFFSET_UNSAFE(var) \ + _LABEL_FOR_OFFSET_UNSAFE(__LINE__, var): for ( \ + unsigned int var##_offset = 0, var = var##_base; \ + var##_offset < var##_step; \ + var##_offset++, var++ \ + ) + +template +static constexpr T ceildiv(T dividend, T divisor) +{ + return (dividend + divisor - 1) / divisor; +} + +template +static constexpr T roundup(T dividend, T divisor) +{ + return ceildiv(dividend, divisor) * divisor; +} + +template +static constexpr T max(T a, T b) +{ + return (a > b) ? a : b; +} + +template +static constexpr T roundup_p2(T num) +{ + return (num == 0 || num == 1) ? 1 : 2 * roundup_p2((num + 1) / 2); +} + +template +static constexpr T bitcount(T num) +{ + return (num == 0 || num == 1) ? num : 1 + bitcount(num >> 1); +} + +template +static constexpr T ap_fixed_relu(T x) +{ + return hls::signbit(x) ? T(0) : x; +} + +template +static constexpr T ap_fixed_epsilon() +{ + return T(1.0 / (1 << (T::width - T::iwidth))); +} + +template +static constexpr T ap_fixed_min() +{ + return T(-(1 << (T::iwidth - 1))); +} + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/ViT_compute.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/ViT_compute.cpp new file mode 100644 index 000000000000..d0e87e5ce1d9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/ViT_compute.cpp @@ -0,0 +1,208 @@ +#include "../include/add.hpp" +#include "../include/conv.hpp" +#include "../include/kernel.hpp" +#include "../include/moe.hpp" + +void load_one_time_weights( + wt_patch_embed_t patch_embed_weights_load[FEATURE_DIM][INPUT_CHANNELS][PATCH_HEIGHT][PATCH_WIDTH], + wt_bias_t patch_embed_bias_load[FEATURE_DIM] +) +{ + #pragma HLS inline off + + { + hls::vector* bias_blocks = reinterpret_cast*>(patch_embed_bias_load); + FOR_BLOCK(dim_out, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + hls::vector bias_block = bias_blocks[dim_out_block]; + FOR_OFFSET(dim_out) + { + patch_embed_bias[dim_out] = bias_block[dim_out_offset]; + } + } + } + + { + hls::vector (*weights_blocks)[INPUT_CHANNELS][PATCH_HEIGHT] = reinterpret_cast (*)[INPUT_CHANNELS][PATCH_HEIGHT]>(patch_embed_weights_load); + + hls::vector weights_cache[FEATURE_BLOCK_SIZE]; + #pragma HLS array_partition variable=weights_cache complete dim=1 + + FOR_EACH(channel, INPUT_CHANNELS) + { + FOR_EACH(y, PATCH_HEIGHT) + { + FOR_BLOCK(dim_out, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + FOR_OFFSET_NOCHK(dim_out) + { + #pragma HLS pipeline + + weights_cache[dim_out_offset] = weights_blocks[dim_out][channel][y]; + + if (dim_out_offset == dim_out_step - 1) + { + #pragma HLS occurrence cycle=dim_out_step + + FOR_EACH(dim_out_write_offset, dim_out_step) + { + unsigned int dim_out_write = dim_out_base + dim_out_write_offset; + FOR_EACH(x, PATCH_WIDTH) + { + patch_embed_weights[dim_out_write][channel][y][x] = weights_cache[dim_out_write_offset][x]; + } + } + } + } + } + } + } + } + + attn_scale = 0.125; + norm_eps = 1e-6; +} + +extern "C" { +void ViT_compute( + unsigned int num_images, + bool reload_one_time_weights, + image_t images[], + patch_blocks_t x[], + patch_blocks_t tmp1, + patch_blocks_t tmp2, + patch_blocks_t tmp3, + patch_blocks_t tmp4, + fm_block_t tmp_hidden[NUM_PATCHES * ceildiv(max(VIT_HIDDEN_DIM, EXPERT_HIDDEN_DIM), FEATURE_BLOCK_SIZE)], + qxk_out_t attn, + softmax_info_t attn_softmax_info, + wt_patch_embed_t patch_embed_weights[FEATURE_DIM][INPUT_CHANNELS][PATCH_HEIGHT][PATCH_WIDTH], + wt_bias_t patch_embed_bias[FEATURE_DIM], + patch_blocks_t pos_embed, + wt_linear_t attn_weights[NUM_LAYERS][NUM_ATTN_LINEAR][FEATURE_DIM][FEATURE_DIM], + wt_attn_bias_t attn_bias[NUM_LAYERS][NUM_ATTN_LINEAR][FEATURE_DIM], + wt_linear_t moe_w_gate[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][FEATURE_DIM], + wt_linear_t moe_weights_l1[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][EXPERT_HIDDEN_DIM][FEATURE_DIM], + wt_bias_t moe_bias_l1[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][EXPERT_HIDDEN_DIM], + wt_linear_t moe_weights_l2[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][FEATURE_DIM][EXPERT_HIDDEN_DIM], + wt_bias_t moe_bias_l2[max(NUM_LAYERS / 2, 1U)][NUM_EXPERTS][FEATURE_DIM], + wt_linear_t vit_weights_l1[max((NUM_LAYERS + 1) / 2, 1U)][VIT_HIDDEN_DIM][FEATURE_DIM], + wt_bias_t vit_bias_l1[max((NUM_LAYERS + 1) / 2, 1U)][VIT_HIDDEN_DIM], + wt_linear_t vit_weights_l2[max((NUM_LAYERS + 1) / 2, 1U)][FEATURE_DIM][VIT_HIDDEN_DIM], + wt_bias_t vit_bias_l2[max((NUM_LAYERS + 1) / 2, 1U)][FEATURE_DIM], + wt_norm_t norm_weights[NUM_LAYERS][NUM_LAYER_NORMS][FEATURE_DIM], + wt_bias_t norm_bias[NUM_LAYERS][NUM_LAYER_NORMS][FEATURE_DIM], + unsigned int debug_id +) +{ + #pragma HLS interface s_axilite port=return + + #pragma HLS interface m_axi depth=1 port=tmp1 offset=slave bundle=inout1 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=tmp2 offset=slave bundle=inout2 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=tmp3 offset=slave bundle=inout3 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=tmp4 offset=slave bundle=inout4 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=tmp_hidden offset=slave bundle=inout4 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=attn offset=slave bundle=inout1 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=attn_softmax_info offset=slave bundle=inout4 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=images offset=slave bundle=inout1 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=x offset=slave bundle=inout2 max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=patch_embed_weights offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=patch_embed_bias offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=pos_embed offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=attn_weights offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=attn_bias offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=moe_w_gate offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=moe_weights_l1 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=moe_bias_l1 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=moe_weights_l2 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=moe_bias_l2 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=vit_weights_l1 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=vit_bias_l1 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=vit_weights_l2 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=vit_bias_l2 offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=norm_weights offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + #pragma HLS interface m_axi depth=1 port=norm_bias offset=slave bundle=weights max_widen_bitwidth=AXI_XFER_BIT_WIDTH + + #pragma HLS allocation function instances=compute_linear limit=1 + #pragma HLS allocation function instances=load_linear_weights limit=1 + #pragma HLS allocation function instances=load_linear_weights limit=1 + #pragma HLS allocation function instances=load_linear_weights limit=1 + + if (reload_one_time_weights) + { + load_one_time_weights(patch_embed_weights, patch_embed_bias); + } + + FOR_EACH(image, num_images) + { + #pragma HLS loop_tripcount min=1 max=1 avg=1 + #pragma HLS pipeline off + + compute_patch_embed(images[image], x[image], pos_embed); + if (debug_id == 256) return; + + FOR_EACH(layer, NUM_LAYERS) + { + #pragma HLS pipeline off + + load_norms(norm_weights[layer], norm_bias[layer]); + compute_norm1(x[image], tmp1); + if (debug_id == layer * 16 + 1) return; + load_linear_weights(linear_weights_ping, reinterpret_cast(attn_weights[layer][ATTN_Q]), FEATURE_DIM, FEATURE_DIM); + load_linear_bias(linear_bias_ping, reinterpret_cast(attn_bias[layer][ATTN_Q]), FEATURE_DIM); + compute_linear(reinterpret_cast(tmp2), reinterpret_cast(tmp1), linear_weights_ping, linear_bias_ping, FEATURE_DIM, FEATURE_DIM, 0, false, false, false); + if (debug_id == layer * 16 + 2) return; + load_linear_weights(linear_weights_pong, reinterpret_cast(attn_weights[layer][ATTN_K]), FEATURE_DIM, FEATURE_DIM); + load_linear_bias(linear_bias_pong, reinterpret_cast(attn_bias[layer][ATTN_K]), FEATURE_DIM); + compute_linear(reinterpret_cast(tmp3), reinterpret_cast(tmp1), linear_weights_pong, linear_bias_pong, FEATURE_DIM, FEATURE_DIM, 0, false, false, false); + if (debug_id == layer * 16 + 3) return; + compute_q_matmul_k(tmp2, tmp3, attn, attn_softmax_info); + if (debug_id == layer * 16 + 4) return; + load_linear_weights(linear_weights_ping, reinterpret_cast(attn_weights[layer][ATTN_V]), FEATURE_DIM, FEATURE_DIM); + load_linear_bias(linear_bias_ping, reinterpret_cast(attn_bias[layer][ATTN_V]), FEATURE_DIM); + compute_linear(reinterpret_cast(tmp2), reinterpret_cast(tmp1), linear_weights_ping, linear_bias_ping, FEATURE_DIM, FEATURE_DIM, 0, false, false, false); + if (debug_id == layer * 16 + 5) return; + compute_attn_matmul_v(tmp2, attn, attn_softmax_info, tmp1); + if (debug_id == layer * 16 + 6) return; + load_linear_weights(linear_weights_pong, reinterpret_cast(attn_weights[layer][ATTN_PROJ]), FEATURE_DIM, FEATURE_DIM); + load_linear_bias(linear_bias_pong, reinterpret_cast(attn_bias[layer][ATTN_PROJ]), FEATURE_DIM); + compute_linear(reinterpret_cast(tmp3), reinterpret_cast(tmp1), linear_weights_pong, linear_bias_pong, FEATURE_DIM, FEATURE_DIM, 0, false, false, false); + if (debug_id == layer * 16 + 7) return; + compute_add(x[image], tmp3, x[image]); + if (debug_id == layer * 16 + 8) return; + compute_norm2(x[image], tmp1); + if (debug_id == layer * 16 + 9) return; + + if (layer % 2 == 0) + { + load_linear_weights(linear_weights_ping, reinterpret_cast(vit_weights_l1[layer / 2]), VIT_HIDDEN_DIM, FEATURE_DIM); + load_linear_bias(linear_bias_ping, reinterpret_cast(vit_bias_l1[layer / 2]), VIT_HIDDEN_DIM); + compute_linear(tmp_hidden, reinterpret_cast(tmp1), linear_weights_ping, linear_bias_ping, VIT_HIDDEN_DIM, FEATURE_DIM, 0, true, false, false); + if (debug_id == layer * 16 + 10) return; + load_linear_weights(linear_weights_pong, reinterpret_cast(vit_weights_l2[layer / 2]), FEATURE_DIM, VIT_HIDDEN_DIM); + load_linear_bias(linear_bias_pong, reinterpret_cast(vit_bias_l2[layer / 2]), FEATURE_DIM); + compute_linear(reinterpret_cast(tmp3), tmp_hidden, linear_weights_pong, linear_bias_pong, FEATURE_DIM, VIT_HIDDEN_DIM, 0, false, false, false); + if (debug_id == layer * 16 + 11) return; + } + else + { + load_w_gate(moe_w_gate[layer / 2]); + compute_moe( + tmp1, + tmp3, + tmp_hidden, + moe_weights_l1[layer / 2], + moe_bias_l1[layer / 2], + moe_weights_l2[layer / 2], + moe_bias_l2[layer / 2] + ); + if (debug_id == layer * 16 + 10 || debug_id == layer * 16 + 11) return; + } + compute_add(x[image], tmp3, x[image]); + if (debug_id == layer * 16 + 12) return; + } + } +} +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/add.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/add.cpp new file mode 100644 index 000000000000..37d5caadf705 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/add.cpp @@ -0,0 +1,20 @@ +#include "../include/add.hpp" + +void compute_add(patch_blocks_t x, patch_blocks_t y, patch_blocks_t out) +{ + #pragma HLS inline off + + fm_block_t* x_blocks = reinterpret_cast(x); + fm_block_t* y_blocks = reinterpret_cast(y); + fm_block_t* out_blocks = reinterpret_cast(out); + + FOR_EACH(i, NUM_PATCHES * NUM_FEATURE_BLOCKS) + { + #pragma HLS pipeline + #pragma HLS dependence variable=x_blocks inter false + #pragma HLS dependence variable=y_blocks inter false + #pragma HLS dependence variable=out_blocks inter false + + out_blocks[i] = x_blocks[i] + y_blocks[i]; + } +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/attention.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/attention.cpp new file mode 100644 index 000000000000..5d0657f2836c --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/attention.cpp @@ -0,0 +1,494 @@ +#include "../include/attention.hpp" +#include "../include/linear.hpp" +#include +#include + +static constexpr unsigned int DIM_PER_HEAD = FEATURE_DIM / NUM_HEADS; + +fm_t attn_scale; + +void read_x(hls::stream& x_stream, patch_blocks_t x) +{ + #pragma HLS inline off + + FOR_EACH(patch, NUM_PATCHES) + { + FOR_BLOCK(in_dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + x_stream << x[patch][in_dim_block]; + } + } +} + +void read_kv(hls::stream& k_stream, patch_blocks_t k) +{ + #pragma HLS inline off + + FOR_BLOCK(q_patch, NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1, ATTN_MATMUL_PARALLEL) + { + FOR_EACH(k_patch, NUM_PATCHES) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + constexpr unsigned int overflow_iters = q_patch_limit % q_patch_step; + if (overflow_iters > 0 && q_patch_base >= NUM_PATCHES && k_patch >= overflow_iters) return; + + k_stream << k[k_patch][dim_block]; + } + } + } +} + +void compute_q_matmul_k( + hls::stream& attn_stream, + hls::stream& q_stream, + hls::stream& k_stream +) +{ + #pragma HLS inline off + + fm_blocks_t q_blocks[ATTN_MATMUL_PARALLEL]; + #pragma HLS array_partition variable=q_blocks complete dim=1 + + fm_t attn_blocks[ATTN_MATMUL_PARALLEL][NUM_HEADS]; + #pragma HLS array_partition variable=attn_blocks complete dim=1 + #pragma HLS array_partition variable=attn_blocks complete dim=2 + + static_assert(ATTN_MATMUL_PARALLEL < NUM_PATCHES, "ATTN_MATMUL_PARALLEL must be less than NUM_PATCHES"); + + FOR_BLOCK(q_patch, NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1, ATTN_MATMUL_PARALLEL) + { + FOR_EACH(k_patch, NUM_PATCHES) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + constexpr unsigned int overflow_iters = q_patch_limit % q_patch_step; + if (overflow_iters > 0 && q_patch_base >= NUM_PATCHES && k_patch >= overflow_iters) return; + + if (k_patch < ATTN_MATMUL_PARALLEL && q_patch_base + k_patch < NUM_PATCHES) + { + q_stream >> q_blocks[k_patch][dim_block]; + } + + fm_block_t k_block; + k_stream >> k_block; + + if (dim_block == 0) + { + #pragma HLS occurrence cycle=dim_iters + + FOR_OFFSET_UNSAFE(q_patch) + { + FOR_EACH(head, NUM_HEADS) + { + attn_blocks[q_patch_offset][head] = 0; + } + } + } + + static_assert(DIM_PER_HEAD % FEATURE_BLOCK_SIZE == 0, "DIM_PER_HEAD must be a multiple of FEATURE_BLOCK_SIZE"); + unsigned int head = dim_block / (DIM_PER_HEAD / FEATURE_BLOCK_SIZE); + FOR_OFFSET_UNSAFE(q_patch) + { + fm_block_t q_block = q_blocks[q_patch_offset][dim_block]; + + fm_t attn_addend = 0; + FOR_OFFSET(dim) + { + attn_addend += q_block[dim_offset] * k_block[dim_offset]; + } + attn_addend *= attn_scale; + attn_blocks[q_patch_offset][head] += attn_addend; + } + + if (dim_block == dim_iters - 1) + { + #pragma HLS occurrence cycle=dim_iters + + attn_parallel_t finalized; + FOR_OFFSET_UNSAFE(q_patch) + { + FOR_EACH(head, NUM_HEADS) + { + finalized[q_patch_offset][head] = attn_blocks[q_patch_offset][head]; + } + } + attn_stream << finalized; + } + } + } + } +} + +void finalize_attn( + hls::stream& qxk_stream, + hls::stream& attn_stream, + hls::stream& attn_softmax_info_stream +) +{ + #pragma HLS inline off + + fm_t softmax_sums[ATTN_MATMUL_PARALLEL][NUM_HEADS]; + #pragma HLS array_partition variable=softmax_sums complete dim=1 + #pragma HLS array_partition variable=softmax_sums complete dim=2 + fm_t softmax_biases[ATTN_MATMUL_PARALLEL][NUM_HEADS]; + #pragma HLS array_partition variable=softmax_biases complete dim=1 + #pragma HLS array_partition variable=softmax_biases complete dim=2 + + heads_t attn_blocks[ATTN_MATMUL_PARALLEL]; + #pragma HLS array_partition variable=attn_blocks complete dim=1 + + FOR_BLOCK(q_patch_unadjusted, NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1, ATTN_MATMUL_PARALLEL) + { + FOR_EACH(k_patch, NUM_PATCHES) + { + FOR_OFFSET_UNSAFE(q_patch_unadjusted) + { + #pragma HLS pipeline + #pragma HLS dependence variable=softmax_sums inter true distance=q_patch_unadjusted_step + #pragma HLS dependence variable=softmax_biases inter true distance=q_patch_unadjusted_step + constexpr unsigned int overflow_iters = q_patch_unadjusted_limit % q_patch_unadjusted_step; + if (overflow_iters > 0 && q_patch_unadjusted_base >= NUM_PATCHES && k_patch >= overflow_iters) return; + + if (q_patch_unadjusted_offset == 0) + { + #pragma HLS occurrence cycle=q_patch_unadjusted_step + attn_parallel_t attn_blocks_packed; + qxk_stream >> attn_blocks_packed; + FOR_EACH(unpack_idx, ATTN_MATMUL_PARALLEL) + { + attn_blocks[unpack_idx] = attn_blocks_packed[unpack_idx]; + } + } + + softmax_info_row_t softmax_info_row; + FOR_EACH(head, NUM_HEADS) + { + fm_t attn_head = attn_blocks[q_patch_unadjusted_offset][head]; + fm_t curr_softmax_sum = 0.0; + fm_t curr_softmax_bias = ap_fixed_min(); + if (k_patch != q_patch_unadjusted_offset) + { + curr_softmax_sum = softmax_sums[q_patch_unadjusted_offset][head]; + curr_softmax_bias = softmax_biases[q_patch_unadjusted_offset][head]; + } + + auto exp_arg_noclip = curr_softmax_bias - attn_head; + bool is_new_bias = hls::signbit(exp_arg_noclip); + fm_t exp_arg = (is_new_bias) ? fm_t(exp_arg_noclip) : fm_t(-exp_arg_noclip); + fm_t exp = hls::exp(exp_arg); + if (is_new_bias) + { + curr_softmax_sum *= exp; + curr_softmax_sum += 1; + curr_softmax_bias = attn_head; + } + else + { + curr_softmax_sum += exp; + } + + fm_t curr_softmax_sum_recip = hls::recip(curr_softmax_sum); + softmax_sums[q_patch_unadjusted_offset][head] = curr_softmax_sum; + softmax_biases[q_patch_unadjusted_offset][head] = curr_softmax_bias; + softmax_info_row[head * 2] = curr_softmax_sum_recip; + softmax_info_row[head * 2 + 1] = curr_softmax_bias; + } + + unsigned int q_patch = (k_patch >= q_patch_unadjusted_offset) ? q_patch_unadjusted : q_patch_unadjusted - ATTN_MATMUL_PARALLEL; + bool q_patch_valid = ((k_patch >= q_patch_unadjusted_offset) || (q_patch_unadjusted_block > 0)) && (q_patch < NUM_PATCHES); + if (q_patch_valid && k_patch == ((q_patch_unadjusted_offset == 0) ? (NUM_PATCHES - 1) : (q_patch_unadjusted_offset - 1))) + { + #pragma HLS occurrence cycle=(NUM_PATCHES + 1) + attn_softmax_info_stream << softmax_info_row; + } + attn_stream << attn_blocks[q_patch_unadjusted_offset]; + } + } + } +} + +void write_attn( + hls::stream& attn_stream, + qxk_out_t attn +) +{ + #pragma HLS inline off + + constexpr unsigned int q_patch_limit = NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1; + constexpr unsigned int q_patch_step = ATTN_MATMUL_PARALLEL; + constexpr unsigned int q_patch_block_limit = q_patch_limit / q_patch_step; + constexpr unsigned int overflow_iters = q_patch_limit % q_patch_step; + + FOR_EACH(q_patch_block, q_patch_block_limit) + { + FOR_EACH(k_patch, NUM_PATCHES) + { + FOR_EACH(q_patch_offset, q_patch_step) + { + #pragma HLS pipeline + attn_stream >> attn[q_patch_block][k_patch][q_patch_offset]; + } + } + } + FOR_EACH(k_patch, overflow_iters) + { + FOR_EACH(q_patch_offset, q_patch_step) + { + #pragma HLS pipeline + attn_stream >> attn[q_patch_block_limit][k_patch][q_patch_offset]; + } + } +} + +void write_attn_softmax_info( + hls::stream& attn_softmax_info_stream, + softmax_info_t attn_softmax_info +) +{ + #pragma HLS inline off + + FOR_EACH(q_patch, NUM_PATCHES) + { + #pragma HLS pipeline + attn_softmax_info_stream >> attn_softmax_info[q_patch]; + } +} + +void compute_q_matmul_k( + patch_blocks_t q, + patch_blocks_t k, + qxk_out_t attn, + softmax_info_t attn_softmax_info +) +{ + #pragma HLS inline off + #pragma HLS dataflow + + hls::stream q_stream("q_stream"); + hls::stream k_stream("k_stream"); + hls::stream qxk_stream("qxk_stream"); + hls::stream attn_stream("attn_stream"); + hls::stream attn_softmax_info_stream("attn_softmax_info_stream"); + + read_x(q_stream, q); + read_kv(k_stream, k); + compute_q_matmul_k(qxk_stream, q_stream, k_stream); + finalize_attn(qxk_stream, attn_stream, attn_softmax_info_stream); + write_attn(attn_stream, attn); + write_attn_softmax_info(attn_softmax_info_stream, attn_softmax_info); +} + +void read_attn( + hls::stream& attn_stream, + qxk_out_t attn +) +{ + #pragma HLS inline off + + constexpr unsigned int q_patch_limit = NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1; + constexpr unsigned int q_patch_step = ATTN_MATMUL_PARALLEL; + constexpr unsigned int q_patch_block_limit = q_patch_limit / q_patch_step; + constexpr unsigned int overflow_iters = q_patch_limit % q_patch_step; + + FOR_EACH(q_patch_block, q_patch_block_limit) + { + FOR_EACH(k_patch, NUM_PATCHES) + { + FOR_EACH(q_patch_offset, q_patch_step) + { + #pragma HLS pipeline + attn_stream << attn[q_patch_block][k_patch][q_patch_offset]; + } + } + } + FOR_EACH(k_patch, overflow_iters) + { + FOR_EACH(q_patch_offset, q_patch_step) + { + #pragma HLS pipeline + attn_stream << attn[q_patch_block_limit][k_patch][q_patch_offset]; + } + } +} + +void prepare_attn( + hls::stream& attn_stream, + hls::stream& qxk_out_stream +) +{ + #pragma HLS inline off + + heads_t attn_blocks[ATTN_MATMUL_PARALLEL]; + #pragma HLS array_partition variable=attn_blocks complete dim=1 + + FOR_BLOCK(q_patch, NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1, ATTN_MATMUL_PARALLEL) + { + FOR_EACH(k_patch, NUM_PATCHES) + { + FOR_OFFSET_UNSAFE(q_patch) + { + #pragma HLS pipeline + constexpr unsigned int overflow_iters = q_patch_limit % q_patch_step; + if (overflow_iters > 0 && q_patch_base >= NUM_PATCHES && k_patch >= overflow_iters) return; + + attn_stream >> attn_blocks[q_patch_offset]; + if (q_patch_offset == q_patch_step - 1) + { + #pragma HLS occurrence cycle=q_patch_step + attn_parallel_t attn_packed; + FOR_EACH(pack_idx, ATTN_MATMUL_PARALLEL) + { + attn_packed[pack_idx] = attn_blocks[pack_idx]; + } + qxk_out_stream << attn_packed; + } + } + } + } +} + +void read_attn_softmax_info( + hls::stream& attn_softmax_info_stream, + softmax_info_t attn_softmax_info +) +{ + #pragma HLS inline off + + FOR_EACH(q_patch, NUM_PATCHES) + { + #pragma HLS pipeline + attn_softmax_info_stream << attn_softmax_info[q_patch]; + } +} + +void write_attn_matmul_v( + patch_blocks_t attn_matmul_v, + hls::stream& attn_matmul_v_stream +) +{ + #pragma HLS inline off + + FOR_EACH(patch, NUM_PATCHES) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + attn_matmul_v_stream >> attn_matmul_v[patch][dim_block]; + } + } +} + +void compute_attn_matmul_v( + hls::stream& attn_matmul_v_stream, + hls::stream& qxk_out_stream, + hls::stream& attn_softmax_info_stream, + hls::stream& v_stream +) +{ + #pragma HLS inline off + + fm_blocks_t acc_blocks[ATTN_MATMUL_PARALLEL]; + #pragma HLS array_partition variable=acc_blocks complete dim=1 + fm_t attn[ATTN_MATMUL_PARALLEL][NUM_HEADS]; + #pragma HLS array_partition variable=attn complete dim=1 + #pragma HLS array_partition variable=attn complete dim=2 + softmax_info_row_t attn_softmax_info[ATTN_MATMUL_PARALLEL]; + #pragma HLS array_partition variable=attn_softmax_info complete dim=1 + + FOR_BLOCK(attn_patch, NUM_PATCHES + ATTN_MATMUL_PARALLEL - 1, ATTN_MATMUL_PARALLEL) + { + FOR_EACH(v_patch, NUM_PATCHES) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + constexpr unsigned int overflow_iters = attn_patch_limit % attn_patch_step; + if (overflow_iters > 0 && attn_patch_base >= NUM_PATCHES && v_patch >= overflow_iters) return; + + if (dim_block == 0) + { + #pragma HLS occurrence cycle=dim_iters + + if (v_patch < ATTN_MATMUL_PARALLEL && attn_patch_base + v_patch < NUM_PATCHES) + { + attn_softmax_info_stream >> attn_softmax_info[v_patch]; + } + + attn_parallel_t attn_packed; + qxk_out_stream >> attn_packed; + FOR_OFFSET_UNSAFE(attn_patch) + { + FOR_EACH(head, NUM_HEADS) + { + fm_t softmax_sum_recip = attn_softmax_info[attn_patch_offset][head * 2]; + fm_t softmax_bias = attn_softmax_info[attn_patch_offset][head * 2 + 1]; + attn[attn_patch_offset][head] = ( + hls::exp(fm_t(attn_packed[attn_patch_offset][head] - softmax_bias)) + * softmax_sum_recip + ); + } + } + } + + fm_block_t v_block; + v_stream >> v_block; + + static_assert(DIM_PER_HEAD % FEATURE_BLOCK_SIZE == 0, "DIM_PER_HEAD must be a multiple of FEATURE_BLOCK_SIZE"); + unsigned int head = dim_block / (DIM_PER_HEAD / FEATURE_BLOCK_SIZE); + FOR_OFFSET_UNSAFE(attn_patch) + { + fm_block_t acc_block; + FOR_OFFSET(dim) + { + acc_block[dim_offset] = v_block[dim_offset] * attn[attn_patch_offset][head]; + } + + if (v_patch != attn_patch_offset) + { + acc_block += acc_blocks[attn_patch_offset][dim_block]; + } + acc_blocks[attn_patch_offset][dim_block] = acc_block; + } + + if (v_patch == NUM_PATCHES - 1) + { + attn_matmul_v_stream << acc_blocks[0][dim_block]; + } + else if (v_patch < ATTN_MATMUL_PARALLEL - 1 && attn_patch_block > 0) + { + attn_matmul_v_stream << acc_blocks[v_patch + 1][dim_block]; + } + } + } + } +} + +void compute_attn_matmul_v( + patch_blocks_t v, + qxk_out_t attn, + softmax_info_t attn_softmax_info, + patch_blocks_t attn_matmul_v +) +{ + #pragma HLS inline off + #pragma HLS dataflow + + hls::stream attn_matmul_v_stream("attn_matmul_v_stream"); + hls::stream attn_stream("attn_stream"); + hls::stream qxk_out_stream("qxk_out_stream"); + hls::stream attn_softmax_info_stream("attn_softmax_info_stream"); + hls::stream v_stream("v_stream"); + + read_kv(v_stream, v); + read_attn(attn_stream, attn); + read_attn_softmax_info(attn_softmax_info_stream, attn_softmax_info); + prepare_attn(attn_stream, qxk_out_stream); + compute_attn_matmul_v(attn_matmul_v_stream, qxk_out_stream, attn_softmax_info_stream, v_stream); + write_attn_matmul_v(attn_matmul_v, attn_matmul_v_stream); +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/conv.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/conv.cpp new file mode 100644 index 000000000000..60dccb764337 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/conv.cpp @@ -0,0 +1,166 @@ +#include "../include/conv.hpp" +#include + +constexpr unsigned int IMAGE_BLOCK_SIZE = (AXI_XFER_BIT_WIDTH / pixel_t::width); +typedef hls::vector image_block_t; + +wt_patch_embed_t patch_embed_weights[FEATURE_DIM][INPUT_CHANNELS][PATCH_HEIGHT][PATCH_WIDTH]; +wt_bias_t patch_embed_bias[FEATURE_DIM]; + +template +void patch_embed_accumulate_read( + image_t image, + hls::stream& image_stream, + unsigned int y_base +) +{ + #pragma HLS inline off + + image_block_t (*image_ptr)[INPUT_HEIGHT][INPUT_WIDTH / IMAGE_BLOCK_SIZE] = reinterpret_cast(image); + + FOR_EACH(channel, INPUT_CHANNELS) + { + FOR_OFFSET(y) + { + FOR_BLOCK(patch_x, INPUT_WIDTH / PATCH_WIDTH, IMAGE_BLOCK_SIZE / PATCH_WIDTH) + { + image_stream << image_ptr[channel][y][patch_x_block]; + } + } + } +} + +template +void patch_embed_accumulate_compute( + hls::stream& image_stream, + fm_blocks_t patches[INPUT_WIDTH / PATCH_WIDTH], + unsigned int y_base +) +{ + #pragma HLS inline off + #pragma HLS array_reshape variable=patches cyclic factor=(IMAGE_BLOCK_SIZE / PATCH_WIDTH) dim=1 + #pragma HLS array_reshape variable=patch_embed_weights cyclic factor=FEATURE_BLOCK_SIZE dim=1 + #pragma HLS array_reshape variable=patch_embed_weights cyclic factor=PATCH_WIDTH dim=4 + #pragma HLS array_reshape variable=patch_embed_bias cyclic factor=FEATURE_BLOCK_SIZE dim=1 + + image_block_t image_block; + + FOR_EACH(channel, INPUT_CHANNELS) + { + FOR_OFFSET(y) + { + FOR_BLOCK(patch_x, INPUT_WIDTH / PATCH_WIDTH, IMAGE_BLOCK_SIZE / PATCH_WIDTH) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + if (dim_block == 0) + { + #pragma HLS occurrence cycle=dim_iters + + image_stream >> image_block; + } + + if (channel == 0 && y_offset == 0) + { + fm_block_t bias_block; + FOR_OFFSET(dim) + { + bias_block[dim_offset] = patch_embed_bias[dim]; + } + + FOR_BLOCK(x, IMAGE_BLOCK_SIZE, PATCH_WIDTH) + { + unsigned int patch_x = patch_x_base + x_block; + patches[patch_x][dim_block] = bias_block; + } + } + + FOR_BLOCK(x, IMAGE_BLOCK_SIZE, PATCH_WIDTH) + { + unsigned int patch_x = patch_x_base + x_block; + fm_block_t addend; + FOR_OFFSET(dim) + { + fm_t addend_dim = 0.0; + FOR_OFFSET(x) + { + addend_dim += image_block[x] * patch_embed_weights[dim][channel][y_offset][x_offset]; + } + addend[dim_offset] = addend_dim; + } + patches[patch_x][dim_block] += addend; + } + } + } + } + } +} + +template +void patch_embed_accumulate( + image_t image, + fm_blocks_t patches[INPUT_WIDTH / PATCH_WIDTH], + unsigned int y_block +) +{ + #pragma HLS inline off + #pragma HLS dataflow + + unsigned int y_base = y_block * PATCH_HEIGHT; + hls::stream image_stream; + + patch_embed_accumulate_read(image, image_stream, y_base); + patch_embed_accumulate_compute(image_stream, patches, y_base); +} + +void patch_embed_output( + fm_blocks_t patches[INPUT_WIDTH / PATCH_WIDTH], + patch_blocks_t out, + patch_blocks_t pos_embed, + unsigned int y_block +) +{ + #pragma HLS inline off + + unsigned int patch_base = y_block * (INPUT_WIDTH / PATCH_WIDTH) + 1; + // +1 because the first patch is the cls_tokens + + FOR_EACH(patch_x, INPUT_WIDTH / PATCH_WIDTH) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + unsigned int patch = patch_base + patch_x; + + out[patch][dim_block] = patches[patch_x][dim_block] + pos_embed[patch][dim_block]; + } + } +} + +void compute_patch_embed(image_t x, patch_blocks_t out, patch_blocks_t pos_embed) +{ + #pragma HLS inline off + + static_assert(INPUT_WIDTH % IMAGE_BLOCK_SIZE == 0, "INPUT_WIDTH must be a multiple of IMAGE_BLOCK_SIZE"); + static_assert(IMAGE_BLOCK_SIZE % PATCH_WIDTH == 0, "IMAGE_BLOCK_SIZE must be a multiple of PATCH_WIDTH"); + + FOR_BLOCK(y, INPUT_HEIGHT, PATCH_HEIGHT) + { + #pragma HLS dataflow + + fm_blocks_t patches[INPUT_WIDTH / PATCH_WIDTH]; + + patch_embed_accumulate(x, patches, y_block); + patch_embed_output(patches, out, pos_embed, y_block); + } + + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + out[0][dim_block] = pos_embed[0][dim_block]; + } +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/gelu.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/gelu.cpp new file mode 100644 index 000000000000..5b5479ae45d1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/gelu.cpp @@ -0,0 +1,227 @@ +#include "../include/gelu.hpp" +#include +#include + +typedef ap_ufixed fm_frac_t; +static const fm_frac_t GELU_DELTA_TABLE[] = { + 0.0, + 0.015235424041748047, + 0.029692649841308594, + 0.043373823165893555, + 0.056282758712768555, + 0.06842470169067383, + 0.07980632781982422, + 0.09043622016906738, + 0.10032343864440918, + 0.10947918891906738, + 0.11791563034057617, + 0.12564659118652344, + 0.13268637657165527, + 0.13905096054077148, + 0.14475750923156738, + 0.14982390403747559, + 0.15426874160766602, + 0.1581120491027832, + 0.16137433052062988, + 0.164076566696167, + 0.16624093055725098, + 0.16788959503173828, + 0.16904520988464355, + 0.16973090171813965, + 0.16997051239013672, + 0.16978740692138672, + 0.1692051887512207, + 0.16824769973754883, + 0.16693854331970215, + 0.16530156135559082, + 0.1633601188659668, + 0.16113710403442383, + 0.15865516662597656, + 0.15593719482421875, + 0.15300464630126953, + 0.14987921714782715, + 0.14658141136169434, + 0.14313149452209473, + 0.13954925537109375, + 0.13585352897644043, + 0.13206219673156738, + 0.12819290161132812, + 0.12426185607910156, + 0.1202852725982666, + 0.11627793312072754, + 0.11225390434265137, + 0.10822653770446777, + 0.10420823097229004, + 0.10021090507507324, + 0.09624481201171875, + 0.09232044219970703, + 0.08844685554504395, + 0.08463215827941895, + 0.08088397979736328, + 0.0772092342376709, + 0.07361388206481934, + 0.07010340690612793, + 0.06668257713317871, + 0.0633549690246582, + 0.06012439727783203, + 0.05699324607849121, + 0.05396389961242676, + 0.05103778839111328, + 0.04821658134460449, + 0.04550027847290039, + 0.04288959503173828, + 0.04038381576538086, + 0.037982940673828125, + 0.03568577766418457, + 0.03349113464355469, + 0.031397342681884766, + 0.029402494430541992, + 0.027505159378051758, + 0.025702476501464844, + 0.023992300033569336, + 0.02237224578857422, + 0.020839452743530273, + 0.01939105987548828, + 0.018024444580078125, + 0.016736268997192383, + 0.015524148941040039, + 0.014384746551513672, + 0.013314962387084961, + 0.012311935424804688, + 0.011372566223144531, + 0.010494232177734375, + 0.009673595428466797, + 0.008907794952392578, + 0.008194446563720703, + 0.00753021240234375, + 0.006912946701049805, + 0.006339550018310547, + 0.0058078765869140625, + 0.005315303802490234, + 0.0048596858978271484, + 0.0044384002685546875, + 0.004049777984619141, + 0.0036911964416503906, + 0.0033609867095947266, + 0.003057241439819336, + 0.002778291702270508, + 0.002521991729736328, + 0.002287149429321289, + 0.0020720958709716797, + 0.0018754005432128906, + 0.0016956329345703125, + 0.001531362533569336, + 0.0013818740844726562, + 0.001245737075805664, + 0.0011217594146728516, + 0.0010089874267578125, + 0.0009069442749023438, + 0.0008141994476318359, + 0.0007302761077880859, + 0.0006542205810546875, + 0.0005857944488525391, + 0.0005238056182861328, + 0.0004677772521972656, + 0.00041747093200683594, + 0.00037217140197753906, + 0.00033164024353027344, + 0.0002949237823486328, + 0.00026226043701171875, + 0.00023293495178222656, + 0.00020647048950195312, + 0.00018310546875, + 0.0001621246337890625, + 0.00014328956604003906, + 0.0001266002655029297, + 0.00011181831359863281, + 9.870529174804688e-05, + 8.678436279296875e-05, + 7.653236389160156e-05, + 6.723403930664062e-05, + 5.91278076171875e-05, + 5.173683166503906e-05, + 4.553794860839844e-05, + 3.981590270996094e-05, + 3.4809112548828125e-05, + 3.0517578125e-05, + 2.6464462280273438e-05, + 2.3126602172851562e-05, + 2.0265579223632812e-05, + 1.7642974853515625e-05, + 1.52587890625e-05, + 1.33514404296875e-05, + 1.1444091796875e-05, + 1.0013580322265625e-05, + 8.58306884765625e-06, + 7.3909759521484375e-06, + 6.4373016357421875e-06, + 5.4836273193359375e-06, + 4.76837158203125e-06, + 4.0531158447265625e-06, + 3.5762786865234375e-06, + 3.0994415283203125e-06, + 2.6226043701171875e-06, + 2.384185791015625e-06, + 1.9073486328125e-06, + 1.6689300537109375e-06, + 1.430511474609375e-06, + 1.1920928955078125e-06, + 9.5367431640625e-07, + 9.5367431640625e-07, + 7.152557373046875e-07, + 7.152557373046875e-07, + 4.76837158203125e-07, + 4.76837158203125e-07, + 4.76837158203125e-07, + 2.384185791015625e-07, + 2.384185791015625e-07, + 2.384185791015625e-07, + 2.384185791015625e-07, + 2.384185791015625e-07, + 2.384185791015625e-07, + 2.384185791015625e-07, + 0.0 +}; + +static constexpr unsigned int GELU_DELTA_TABLE_SIZE = sizeof(GELU_DELTA_TABLE) / sizeof(GELU_DELTA_TABLE[0]); +typedef ap_uint gelu_delta_table_index_t; + +static const fm_t GELU_DELTA_TABLE_STEP = 0.03125; +static const fm_t GELU_DELTA_TABLE_MAX = GELU_DELTA_TABLE_STEP * (GELU_DELTA_TABLE_SIZE - 1); + +fm_t gelu(fm_t x) +{ + #pragma HLS inline off + #pragma HLS bind_storage variable=GELU_DELTA_TABLE type=ROM_NP + + fm_t relu = ap_fixed_relu(x); + fm_t x_abs = hls::signbit(x) ? fm_t(-x) : x; + + if (x_abs >= GELU_DELTA_TABLE_MAX) return relu; + + auto index_exact = x_abs / GELU_DELTA_TABLE_STEP; + gelu_delta_table_index_t index = index_exact; + + fm_frac_t a = GELU_DELTA_TABLE[index]; + fm_frac_t b = GELU_DELTA_TABLE[index + 1]; + fm_frac_t t = index_exact - index; + + fm_frac_t gelu_delta = a + t * (b - a); + return relu - gelu_delta; +} + +template +hls::vector gelu(hls::vector x) +{ + hls::vector y; + gelu_loop: for (size_t i = 0; i < N; i++) + { + #pragma HLS unroll + y[i] = gelu(x[i]); + } + return y; +} + +template hls::vector gelu(hls::vector x); +template hls::vector gelu(hls::vector x); +template hls::vector gelu(hls::vector x); diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/layernorm.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/layernorm.cpp new file mode 100644 index 000000000000..9f9058737a62 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/layernorm.cpp @@ -0,0 +1,172 @@ +#include "../include/layernorm.hpp" +#include + +wt_norm_t norm1_weights[FEATURE_DIM]; +wt_bias_t norm1_bias[FEATURE_DIM]; +wt_norm_t norm2_weights[FEATURE_DIM]; +wt_bias_t norm2_bias[FEATURE_DIM]; +fm_t norm_eps; + +void load_norms( + wt_norm_t norm_weights[NUM_LAYER_NORMS][FEATURE_DIM], + wt_bias_t norm_bias[NUM_LAYER_NORMS][FEATURE_DIM] +) +{ + #pragma HLS inline off + + { + hls::vector* bias_blocks = reinterpret_cast*>(norm_bias[NORM_1]); + FOR_BLOCK(dim_out, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + hls::vector bias_block = bias_blocks[dim_out_block]; + FOR_OFFSET(dim_out) + { + norm1_bias[dim_out] = bias_block[dim_out_offset]; + } + } + } + + { + hls::vector* weights_blocks = reinterpret_cast*>(norm_weights[NORM_1]); + FOR_BLOCK(dim_out, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + hls::vector weights_block = weights_blocks[dim_out_block]; + FOR_OFFSET(dim_out) + { + norm1_weights[dim_out] = weights_block[dim_out_offset]; + } + } + } + + { + hls::vector* bias_blocks = reinterpret_cast*>(norm_bias[NORM_2]); + FOR_BLOCK(dim_out, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + hls::vector bias_block = bias_blocks[dim_out_block]; + FOR_OFFSET(dim_out) + { + norm2_bias[dim_out] = bias_block[dim_out_offset]; + } + } + } + + { + hls::vector* weights_blocks = reinterpret_cast*>(norm_weights[NORM_2]); + FOR_BLOCK(dim_out, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + hls::vector weights_block = weights_blocks[dim_out_block]; + FOR_OFFSET(dim_out) + { + norm2_weights[dim_out] = weights_block[dim_out_offset]; + } + } + } +} + +void layernorm_accumulate(fm_blocks_t& x, fm_blocks_t& x_patch, fm_t& mean, fm_t& mean_sq) +{ + #pragma HLS inline off + + mean = 0.0; + mean_sq = 0.0; + + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline rewind + + fm_block_t x_block = x[dim_block]; + fm_t partial_mean = 0.0; + fm_t partial_mean_sq = 0.0; + + FOR_OFFSET(dim) + { + fm_t x_dim = x_block[dim_offset]; + fm_t x_dim_mean_term = x_dim * fm_t(1.0 / FEATURE_DIM); + partial_mean += x_dim_mean_term; + partial_mean_sq += x_dim * x_dim_mean_term; + } + + x_patch[dim_block] = x_block; + mean += partial_mean; + mean_sq += partial_mean_sq; + } +} + +void layernorm_output( + fm_blocks_t& out, + fm_blocks_t& x_patch, + fm_t& mean, + fm_t& mean_sq, + wt_norm_t weights[FEATURE_DIM], + wt_bias_t bias[FEATURE_DIM] +) +{ + #pragma HLS inline off + #pragma HLS array_reshape variable=weights cyclic factor=FEATURE_BLOCK_SIZE dim=1 + #pragma HLS array_reshape variable=bias cyclic factor=FEATURE_BLOCK_SIZE dim=1 + + fm_t sq_mean = mean * mean; + fm_t variance = mean_sq - sq_mean + norm_eps; + fm_t rstddev = fm_t(1) / hls::sqrt(variance); + + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline rewind + + fm_block_t x_block = x_patch[dim_block]; + FOR_OFFSET(dim) + { + fm_t x_dim = x_block[dim_offset]; + x_dim -= mean; + x_dim *= rstddev; + x_dim *= weights[dim]; + x_dim += bias[dim]; + x_block[dim_offset] = x_dim; + } + out[dim_block] = x_block; + } +} + +void compute_norm( + patch_blocks_t x, + patch_blocks_t out, + wt_norm_t weights[FEATURE_DIM], + wt_bias_t bias[FEATURE_DIM] +) +{ + #pragma HLS inline off + + FOR_EACH(patch, NUM_PATCHES) + { + #pragma HLS dataflow + + fm_blocks_t x_patch; + fm_t mean; + fm_t mean_sq; + + layernorm_accumulate(x[patch], x_patch, mean, mean_sq); + layernorm_output(out[patch], x_patch, mean, mean_sq, weights, bias); + } +} + +void compute_norm1(patch_blocks_t x, patch_blocks_t out) +{ + #pragma HLS inline + + compute_norm(x, out, norm1_weights, norm1_bias); +} + +void compute_norm2(patch_blocks_t x, patch_blocks_t out) +{ + #pragma HLS inline + + compute_norm(x, out, norm2_weights, norm2_bias); +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/linear.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/linear.cpp new file mode 100644 index 000000000000..8a41b8b81942 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/linear.cpp @@ -0,0 +1,530 @@ +#include "../include/linear.hpp" +#include "../include/gelu.hpp" +#include "../include/moe.hpp" + +wt_linear_block_t linear_weights_ping[ceildiv(MAX_LINEAR_DIM_PRODUCT, LINEAR_IN_SIZE * LINEAR_OUT_SIZE)]; +wt_bias_block_t linear_bias_ping[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)]; +wt_linear_block_t linear_weights_pong[ceildiv(MAX_LINEAR_DIM_PRODUCT, LINEAR_IN_SIZE * LINEAR_OUT_SIZE)]; +wt_bias_block_t linear_bias_pong[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)]; + +void load_linear_weights( + wt_linear_block_t weights_dst[ceildiv(MAX_LINEAR_DIM_PRODUCT, LINEAR_IN_SIZE * LINEAR_OUT_SIZE)], + wt_linear_t weights_src[], + unsigned int out_dim, + unsigned int in_dim +) +{ + #pragma HLS inline off + + constexpr unsigned int WEIGHT_BLOCK_SIZE = AXI_XFER_BIT_WIDTH / wt_linear_t::width; + constexpr unsigned int num_src_blocks_in_dst_block = LINEAR_IN_SIZE / WEIGHT_BLOCK_SIZE; + constexpr unsigned int last_src_block_in_dst_block = num_src_blocks_in_dst_block - 1; + + static_assert(LINEAR_IN_SIZE % WEIGHT_BLOCK_SIZE == 0, "LINEAR_IN_SIZE must be a multiple of WEIGHT_BLOCK_SIZE"); + + unsigned int num_src_col_blocks = ceildiv(in_dim, WEIGHT_BLOCK_SIZE); + unsigned int last_src_col_block = num_src_col_blocks - 1; + unsigned int num_src_blocks = out_dim * num_src_col_blocks; + unsigned int last_src_row = out_dim - 1; + unsigned int num_dst_col_blocks = ceildiv(in_dim, LINEAR_IN_SIZE); + unsigned int last_dst_col_block = num_dst_col_blocks - 1; + + hls::vector* weights_blocks = reinterpret_cast*>(weights_src); + hls::vector weights_cache[LINEAR_OUT_SIZE][num_src_blocks_in_dst_block][ceildiv(MAX_LINEAR_IN_DIM, LINEAR_IN_SIZE)]; + #pragma HLS array_partition variable=weights_cache complete dim=1 + #pragma HLS array_partition variable=weights_cache complete dim=2 + + unsigned int next_src_col_block = 0; + unsigned int next_src_row = 0; + unsigned int next_src_block_in_dst_block = 0; + unsigned int next_dst_col_block = 0; + unsigned int next_dst_row_offset = 0; + unsigned int next_dst_block = 0; + + FOR_EACH(src_block, num_src_blocks) + { + #pragma HLS pipeline + + unsigned int src_col_block = next_src_col_block; + next_src_col_block = (src_col_block == last_src_col_block) ? 0 : src_col_block + 1; + unsigned int src_row = next_src_row; + next_src_row = (src_col_block == last_src_col_block) ? src_row + 1 : src_row; + unsigned int src_block_in_dst_block = next_src_block_in_dst_block; + next_src_block_in_dst_block = (src_block_in_dst_block == last_src_block_in_dst_block) ? 0 : src_block_in_dst_block + 1; + unsigned int dst_col_block = next_dst_col_block; + next_dst_col_block = (src_block_in_dst_block == last_src_block_in_dst_block) + ? ((dst_col_block == last_dst_col_block) ? 0 : dst_col_block + 1) + : dst_col_block; + unsigned int dst_row_offset = next_dst_row_offset; + next_dst_row_offset = (src_col_block == last_src_col_block) + ? ((dst_row_offset == LINEAR_OUT_SIZE - 1) ? 0 : dst_row_offset + 1) + : dst_row_offset; + + weights_cache[dst_row_offset][src_block_in_dst_block][dst_col_block] = weights_blocks[src_block]; + + if ( + (src_block_in_dst_block == last_src_block_in_dst_block || src_col_block == last_src_col_block) + && (dst_row_offset == LINEAR_OUT_SIZE - 1 || src_row == last_src_row) + ) + { + unsigned int dst_block = next_dst_block; + next_dst_block = dst_block + 1; + + wt_linear_block_t block_for_dst; + FOR_EACH(row, LINEAR_OUT_SIZE) + { + hls::vector row_for_dst; + FOR_BLOCK(col, LINEAR_IN_SIZE, WEIGHT_BLOCK_SIZE) + { + hls::vector cached = weights_cache[row][col_block][dst_col_block]; + FOR_OFFSET(col) + { + row_for_dst[col] = cached[col_offset]; + } + } + block_for_dst[row] = row_for_dst; + } + weights_dst[dst_block] = block_for_dst; + } + } +} + +template void load_linear_bias( + wt_bias_block_t bias_dst[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)], + wt_bias_t bias_src[], + unsigned int out_dim +); +template void load_linear_bias( + wt_bias_block_t bias_dst[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)], + wt_attn_bias_t bias_src[], + unsigned int out_dim +); +template +void load_linear_bias( + wt_bias_block_t bias_dst[ceildiv(MAX_LINEAR_OUT_DIM, LINEAR_OUT_SIZE)], + T bias_src[], + unsigned int out_dim +) +{ + #pragma HLS inline off + + constexpr unsigned int BIAS_BLOCK_SIZE = AXI_XFER_BIT_WIDTH / T::width; + constexpr unsigned int num_src_blocks_in_dst_block = LINEAR_OUT_SIZE / BIAS_BLOCK_SIZE; + constexpr unsigned int last_src_block_in_dst_block = num_src_blocks_in_dst_block - 1; + + static_assert(LINEAR_OUT_SIZE % BIAS_BLOCK_SIZE == 0, "LINEAR_OUT_SIZE must be a multiple of BIAS_BLOCK_SIZE"); + + unsigned int num_src_blocks = ceildiv(out_dim, BIAS_BLOCK_SIZE); + unsigned int last_src_block = num_src_blocks - 1; + + hls::vector* bias_blocks = reinterpret_cast*>(bias_src); + hls::vector bias_cache[num_src_blocks_in_dst_block]; + #pragma HLS array_partition variable=bias_cache complete dim=1 + + unsigned int next_src_block_in_dst_block = 0; + unsigned int next_dst_block = 0; + + FOR_EACH(src_block, num_src_blocks) + { + #pragma HLS pipeline + + unsigned int src_block_in_dst_block = next_src_block_in_dst_block; + next_src_block_in_dst_block = (src_block_in_dst_block == last_src_block_in_dst_block) ? 0 : src_block_in_dst_block + 1; + + bias_cache[src_block_in_dst_block] = bias_blocks[src_block]; + + if (src_block_in_dst_block == last_src_block_in_dst_block || src_block == last_src_block) + { + unsigned int dst_block = next_dst_block; + next_dst_block = dst_block + 1; + + wt_bias_block_t block; + FOR_BLOCK(dim, LINEAR_OUT_SIZE, BIAS_BLOCK_SIZE) + { + FOR_OFFSET(dim) + { + block[dim] = bias_cache[dim_block][dim_offset]; + } + } + bias_dst[dst_block] = block; + } + } +} + +void read_in_stream_direct( + hls::stream& in_stream, + const fm_block_t src[], + unsigned int in_dim +) +{ + #pragma HLS inline off + + static_assert(LINEAR_IN_SIZE % FEATURE_BLOCK_SIZE == 0, "LINEAR_IN_SIZE must be a multiple of FEATURE_BLOCK_SIZE"); + + constexpr unsigned int num_blocks = LINEAR_IN_SIZE / FEATURE_BLOCK_SIZE; + fm_block_t blocks[num_blocks]; + #pragma HLS array_partition variable=blocks complete + + constexpr unsigned int last_block = num_blocks - 1; + unsigned int next_block = 0; + + unsigned int iters = NUM_PATCHES * ceildiv(in_dim, FEATURE_BLOCK_SIZE); + + FOR_EACH(i, iters) + { + #pragma HLS pipeline + + unsigned int block = next_block; + next_block = (block == last_block) ? 0 : block + 1; + + blocks[block] = src[i]; + + if (block == last_block) + { + #pragma HLS occurrence cycle=num_blocks + + linear_in_t stream_block; + FOR_BLOCK(j, LINEAR_IN_SIZE, FEATURE_BLOCK_SIZE) + { + FOR_OFFSET_NOCHK(j) + { + stream_block[j] = blocks[j_block][j_offset]; + } + } + in_stream << stream_block; + } + } +} + +void write_out_stream_direct( + fm_block_t dst[], + hls::stream& out_stream, + unsigned int out_dim +) +{ + #pragma HLS inline off + + static_assert(LINEAR_OUT_SIZE % FEATURE_BLOCK_SIZE == 0, "LINEAR_OUT_SIZE must be a multiple of FEATURE_BLOCK_SIZE"); + + constexpr unsigned int num_blocks = LINEAR_OUT_SIZE / FEATURE_BLOCK_SIZE; + fm_block_t blocks[num_blocks]; + #pragma HLS array_partition variable=blocks complete + + constexpr unsigned int last_block = num_blocks - 1; + unsigned int next_block = 0; + + unsigned int iters = NUM_PATCHES * ceildiv(out_dim, FEATURE_BLOCK_SIZE); + + FOR_EACH(i, iters) + { + #pragma HLS pipeline + + unsigned int block = next_block; + next_block = (block == last_block) ? 0 : block + 1; + + if (block == 0) + { + #pragma HLS occurrence cycle=num_blocks + + linear_out_t stream_block; + out_stream >> stream_block; + FOR_BLOCK(j, LINEAR_OUT_SIZE, FEATURE_BLOCK_SIZE) + { + fm_block_t slice; + FOR_OFFSET_NOCHK(j) + { + slice[j_offset] = stream_block[j]; + } + blocks[j_block] = slice; + } + } + + dst[i] = blocks[block]; + } +} + +void read_in_stream_indirect( + hls::stream& in_stream, + hls::stream& index_stream, + const fm_block_t src[], + unsigned int in_dim, + unsigned int expert, + unsigned int length +) +{ + #pragma HLS inline off + + static_assert(LINEAR_IN_SIZE % FEATURE_BLOCK_SIZE == 0, "LINEAR_IN_SIZE must be a multiple of FEATURE_BLOCK_SIZE"); + + constexpr unsigned int num_blocks = LINEAR_IN_SIZE / FEATURE_BLOCK_SIZE; + unsigned int num_dim_blocks = ceildiv(in_dim, FEATURE_BLOCK_SIZE); + fm_block_t blocks[num_blocks]; + #pragma HLS array_partition variable=blocks complete + + constexpr unsigned int last_block = num_blocks - 1; + unsigned int last_dim_block = num_dim_blocks - 1; + unsigned int next_block = 0; + unsigned int next_patch_idx = 0; + unsigned int next_dim_block = 0; + unsigned int src_base = 0; + + unsigned int iters = length * num_dim_blocks; + + FOR_EACH(i, iters) + { + #pragma HLS pipeline + + unsigned int block = next_block; + next_block = (block == last_block) ? 0 : block + 1; + unsigned int dim_block = next_dim_block; + next_dim_block = (dim_block == last_dim_block) ? 0 : dim_block + 1; + unsigned int patch_idx = next_patch_idx; + next_patch_idx = (dim_block == last_dim_block) ? patch_idx + 1 : patch_idx; + + if (dim_block == 0) + { + unsigned int patch = expert_queues[expert][patch_idx]; + src_base = patch * num_dim_blocks; + index_stream << patch; + } + + blocks[block] = src[src_base + dim_block]; + + if (block == last_block) + { + #pragma HLS occurrence cycle=num_blocks + + linear_in_t stream_block; + FOR_BLOCK(j, LINEAR_IN_SIZE, FEATURE_BLOCK_SIZE) + { + FOR_OFFSET_NOCHK(j) + { + stream_block[j] = blocks[j_block][j_offset]; + } + } + in_stream << stream_block; + } + } +} + +void write_out_stream_indirect( + fm_block_t dst[], + hls::stream& out_stream, + hls::stream& index_stream, + unsigned int out_dim, + unsigned int expert, + unsigned int length, + bool use_score +) +{ + #pragma HLS inline off + + static_assert(LINEAR_OUT_SIZE % FEATURE_BLOCK_SIZE == 0, "LINEAR_OUT_SIZE must be a multiple of FEATURE_BLOCK_SIZE"); + + constexpr unsigned int num_blocks = LINEAR_OUT_SIZE / FEATURE_BLOCK_SIZE; + unsigned int num_dim_blocks = ceildiv(out_dim, FEATURE_BLOCK_SIZE); + fm_block_t blocks[num_blocks]; + #pragma HLS array_partition variable=blocks complete + fm_t score; + + constexpr unsigned int last_block = num_blocks - 1; + unsigned int last_dim_block = num_dim_blocks - 1; + unsigned int next_block = 0; + unsigned int next_patch_idx = 0; + unsigned int next_dim_block = 0; + unsigned int dst_base = 0; + + unsigned int iters = length * num_dim_blocks; + + FOR_EACH(i, iters) + { + #pragma HLS pipeline + #pragma HLS dependence variable=dst inter false + + unsigned int block = next_block; + next_block = (block == last_block) ? 0 : block + 1; + unsigned int dim_block = next_dim_block; + next_dim_block = (dim_block == last_dim_block) ? 0 : dim_block + 1; + unsigned int patch_idx = next_patch_idx; + next_patch_idx = (dim_block == last_dim_block) ? patch_idx + 1 : patch_idx; + + if (dim_block == 0) + { + unsigned int patch; + index_stream >> patch; + dst_base = patch * num_dim_blocks; + score = expert_scores[expert][patch_idx]; + } + + if (block == 0) + { + #pragma HLS occurrence cycle=num_blocks + + linear_out_t stream_block; + out_stream >> stream_block; + FOR_BLOCK(j, LINEAR_OUT_SIZE, FEATURE_BLOCK_SIZE) + { + fm_block_t slice; + FOR_OFFSET_NOCHK(j) + { + slice[j_offset] = stream_block[j]; + } + blocks[j_block] = slice; + } + } + + unsigned int dst_idx = dst_base + dim_block; + fm_block_t block_out = blocks[block]; + if (use_score) + { + block_out *= score; + block_out += dst[dst_idx]; + } + dst[dst_idx] = block_out; + } +} + +void read_in_stream( + hls::stream& in_stream, + hls::stream& index_stream, + const fm_block_t src[], + unsigned int in_dim, + unsigned int expert, + unsigned int length +) +{ + #pragma HLS inline off + + if (length == NUM_PATCHES) + { + read_in_stream_direct(in_stream, src, in_dim); + } + else + { + read_in_stream_indirect(in_stream, index_stream, src, in_dim, expert, length); + } +} + +void write_out_stream( + fm_block_t dst[], + hls::stream& out_stream, + hls::stream& index_stream, + unsigned int out_dim, + unsigned int expert, + unsigned int length, + bool use_score +) +{ + #pragma HLS inline off + + if (!use_score && length == NUM_PATCHES) + { + write_out_stream_direct(dst, out_stream, out_dim); + } + else + { + write_out_stream_indirect(dst, out_stream, index_stream, out_dim, expert, length, use_score); + } +} + +void compute_linear_on_stream( + hls::stream& out_stream, + hls::stream& in_stream, + const wt_linear_block_t weights[], + const wt_bias_block_t bias[], + unsigned int out_dim, + unsigned int in_dim, + unsigned int length, + bool use_gelu +) +{ + #pragma HLS inline off + + #pragma HLS aggregate variable=weights + #pragma HLS aggregate variable=bias + + linear_in_t in_blocks[ceildiv(MAX_LINEAR_IN_DIM, LINEAR_IN_SIZE)]; + linear_out_t out_block; + + unsigned int out_dim_iters = ceildiv(out_dim, LINEAR_OUT_SIZE); + unsigned int last_out_dim_iter = out_dim_iters - 1; + unsigned int in_dim_iters = ceildiv(in_dim, LINEAR_IN_SIZE); + unsigned int last_in_dim_iter = in_dim_iters - 1; + unsigned int total_dim_iters = out_dim_iters * in_dim_iters; + unsigned int last_total_dim_iter = total_dim_iters - 1; + unsigned int iters = length * total_dim_iters; + + unsigned int next_total_dim_block = 0; + unsigned int next_in_dim_block = 0; + unsigned int next_out_dim_block = 0; + + FOR_EACH(i, iters) + { + #pragma HLS pipeline + + unsigned int total_dim_block = next_total_dim_block; + next_total_dim_block = (total_dim_block == last_total_dim_iter) ? 0 : total_dim_block + 1; + unsigned int in_dim_block = next_in_dim_block; + next_in_dim_block = (in_dim_block == last_in_dim_iter) ? 0 : in_dim_block + 1; + unsigned int out_dim_block = next_out_dim_block; + next_out_dim_block = (total_dim_block == last_total_dim_iter) ? 0 : (in_dim_block == last_in_dim_iter) ? out_dim_block + 1 : out_dim_block; + + if (out_dim_block == 0) + { + in_stream >> in_blocks[in_dim_block]; + } + linear_in_t in_block = in_blocks[in_dim_block]; + + if (in_dim_block == 0) + { + wt_bias_block_t bias_block = bias[out_dim_block]; + FOR_EACH(out_dim_offset, LINEAR_OUT_SIZE) + { + out_block[out_dim_offset] = bias_block[out_dim_offset]; + } + } + + FOR_EACH(in_dim_offset, LINEAR_IN_SIZE) + { + linear_out_t addend; + FOR_EACH(out_dim_offset, LINEAR_OUT_SIZE) + { + addend[out_dim_offset] = in_block[in_dim_offset] * weights[total_dim_block][out_dim_offset][in_dim_offset]; + } + out_block += addend; + } + + if (in_dim_block == last_in_dim_iter) + { + out_stream << ((use_gelu) ? gelu(out_block) : out_block); + } + } +} + +void compute_linear( + fm_block_t dst[], + const fm_block_t src[], + const wt_linear_block_t weights[], + const wt_bias_block_t bias[], + unsigned int out_dim, + unsigned int in_dim, + unsigned int expert, + bool use_gelu, + bool use_expert, + bool use_score +) +{ + #pragma HLS inline off + #pragma HLS dataflow + + hls::stream in_stream; + #pragma HLS stream variable=in_stream depth=(MAX_LINEAR_IN_DIM / LINEAR_IN_SIZE) + hls::stream out_stream; + hls::stream index_stream; + #pragma HLS stream variable=index_stream depth=8 + + unsigned int length = (use_expert) ? expert_queue_lens[expert] : NUM_PATCHES; + read_in_stream(in_stream, index_stream, src, in_dim, expert, length); + compute_linear_on_stream(out_stream, in_stream, weights, bias, out_dim, in_dim, length, use_gelu); + write_out_stream(dst, out_stream, index_stream, out_dim, expert, length, use_score); +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/moe.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/moe.cpp new file mode 100644 index 000000000000..82d87bede026 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/accelerators/edgemoe/src/moe.cpp @@ -0,0 +1,436 @@ +#include "../include/add.hpp" +#include "../include/moe.hpp" +#include "../include/linear.hpp" +#include +#include + +typedef hls::vector experts_block_t; +typedef hls::vector topk_indices_t; +typedef hls::vector topk_scores_t; + +wt_linear_t w_gate[NUM_EXPERTS][FEATURE_DIM]; + +unsigned int expert_queues[NUM_EXPERTS][NUM_PATCHES]; +fm_t expert_scores[NUM_EXPERTS][NUM_PATCHES]; +unsigned int expert_queue_lens[NUM_EXPERTS]; +unsigned int expert_metaqueue[NUM_EXPERTS]; +unsigned int expert_metaqueue_len; + +void load_w_gate(wt_linear_t w_gate_load[NUM_EXPERTS][FEATURE_DIM]) +{ + #pragma HLS inline off + + hls::vector (*w_gate_blocks)[FEATURE_DIM / FEATURE_BLOCK_SIZE] = reinterpret_cast (*)[FEATURE_DIM / FEATURE_BLOCK_SIZE]>(w_gate_load); + + hls::vector w_gate_cache[NUM_EXPERTS]; + #pragma HLS array_partition variable=w_gate_cache complete dim=1 + + FOR_BLOCK(expert, NUM_EXPERTS, NUM_EXPERTS) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + FOR_OFFSET_NOCHK(expert) + { + #pragma HLS pipeline + + w_gate_cache[expert_offset] = w_gate_blocks[expert][dim_block]; + + if (expert_offset == expert_step - 1) + { + #pragma HLS occurrence cycle=expert_step + + FOR_EACH(expert_write_offset, expert_step) + { + unsigned int expert_write = expert_base + expert_write_offset; + FOR_OFFSET(dim) + { + w_gate[expert_write][dim] = w_gate_cache[expert_write_offset][dim_offset]; + } + } + } + } + } + } +} + +void read_gate_inp(hls::stream& gate_inp_stream, patch_blocks_t gate_inp) +{ + #pragma HLS inline off + + FOR_EACH(patch, NUM_PATCHES) + { + FOR_BLOCK(out_dim, NUM_EXPERTS, NUM_EXPERTS) + { + FOR_BLOCK(in_dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline + + gate_inp_stream << gate_inp[patch][in_dim_block]; + } + } + } +} + +void write_gate_results( + hls::stream& topk_indices_stream, + hls::stream& topk_scores_stream, + unsigned int expert_queues[NUM_EXPERTS][NUM_PATCHES], + fm_t expert_scores[NUM_EXPERTS][NUM_PATCHES], + unsigned int expert_queue_lens[NUM_EXPERTS] +) +{ + #pragma HLS inline off + + #pragma HLS array_partition variable=expert_queues complete dim=1 + #pragma HLS array_partition variable=expert_scores complete dim=1 + #pragma HLS array_partition variable=expert_queue_lens complete dim=1 + + FOR_EACH(expert, NUM_EXPERTS) + { + #pragma HLS unroll + + expert_queue_lens[expert] = 0; + } + + FOR_EACH(patch, NUM_PATCHES) + { + #pragma HLS pipeline + + topk_indices_t topk_indices; + topk_scores_t topk_scores; + topk_indices_stream >> topk_indices; + topk_scores_stream >> topk_scores; + + FOR_EACH(expert_index, NUM_SELECTED_EXPERTS) + { + unsigned int expert = topk_indices[expert_index]; + unsigned int queue_index = expert_queue_lens[expert]; + expert_queue_lens[expert] = queue_index + 1; + + expert_queues[expert][queue_index] = patch; + expert_scores[expert][queue_index] = topk_scores[expert_index]; + } + } + + expert_metaqueue_len = 0; + FOR_EACH(expert, NUM_EXPERTS) + { + #pragma HLS unroll + + if (expert_queue_lens[expert] > 0) + { + expert_metaqueue[expert_metaqueue_len] = expert; + expert_metaqueue_len++; + } + } +} + +void top_k( + topk_indices_t& indices, + topk_scores_t& scores, + experts_block_t& update +) +{ + #pragma HLS inline off + + FOR_EACH(i, NUM_EXPERTS) + { + #pragma HLS pipeline rewind + + topk_indices_t prev_indices = indices; + topk_scores_t prev_scores = scores; + topk_indices_t new_indices; + topk_scores_t new_scores; + fm_t score = update[i]; + bool shift = false; + + FOR_EACH(j, NUM_SELECTED_EXPERTS) + { + #pragma HLS unroll + + if (shift) + { + new_scores[j] = prev_scores[j - 1]; + new_indices[j] = prev_indices[j - 1]; + } + else if (score > prev_scores[j]) + { + new_scores[j] = score; + new_indices[j] = i; + shift = true; + } + } + + indices = new_indices; + scores = new_scores; + } +} + +experts_block_t compute_gating_for_patch(hls::stream& gate_inp_stream) +{ + #pragma HLS inline off + + hls::vector scores = fm_t(0); + + FOR_BLOCK(in_dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + #pragma HLS pipeline rewind + + experts_block_t addend = fm_t(0); + fm_block_t gate_inp_block; + gate_inp_stream >> gate_inp_block; + FOR_EACH(out_dim, NUM_EXPERTS) + { + #pragma HLS unroll + FOR_OFFSET_NOCHK(in_dim) + { + #pragma HLS unroll + addend[out_dim] += gate_inp_block[in_dim_offset] * w_gate[out_dim][in_dim]; + } + } + scores += addend; + } + + return scores; +} + +void update_softmax_info( + fm_t& scores_softmax_sum, + fm_t& scores_softmax_bias, + experts_block_t scores +) +{ + #pragma HLS inline off + + FOR_EACH(out_dim, NUM_EXPERTS) + { + #pragma HLS pipeline rewind II=3 + + fm_t score = scores[out_dim]; + auto exp_arg_noclip = scores_softmax_bias - score; + bool is_new_bias = hls::signbit(exp_arg_noclip); + fm_t exp_arg = (is_new_bias) ? fm_t(exp_arg_noclip) : fm_t(-exp_arg_noclip); + fm_t exp = hls::exp(exp_arg); + if (is_new_bias) + { + scores_softmax_sum *= exp; + scores_softmax_sum += 1; + scores_softmax_bias = score; + } + else + { + scores_softmax_sum += exp; + } + } +} + +topk_scores_t finalize_topk_scores_softmax( + topk_scores_t top_k_scores, + fm_t scores_softmax_sum, + fm_t scores_softmax_bias +) +{ + #pragma HLS inline off + + topk_scores_t top_k_scores_softmax; + FOR_EACH(expert, NUM_SELECTED_EXPERTS) + { + #pragma HLS unroll + top_k_scores_softmax[expert] = hls::exp(fm_t(top_k_scores[expert] - scores_softmax_bias)) / scores_softmax_sum; + } + return top_k_scores_softmax; +} + +void compute_gating( + hls::stream& gate_inp_stream, + hls::stream& topk_indices_stream, + hls::stream& topk_scores_stream +) +{ + #pragma HLS inline off + + #pragma HLS array_reshape variable=w_gate cyclic factor=NUM_EXPERTS dim=1 + #pragma HLS array_reshape variable=w_gate cyclic factor=FEATURE_BLOCK_SIZE dim=2 + + FOR_EACH(patch, NUM_PATCHES) + { + topk_indices_t top_k_indices = 0; + topk_scores_t top_k_scores = ap_fixed_min(); + fm_t scores_softmax_sum = 0; + fm_t scores_softmax_bias = ap_fixed_min(); + + hls::vector scores = compute_gating_for_patch(gate_inp_stream); + update_softmax_info(scores_softmax_sum, scores_softmax_bias, scores); + top_k(top_k_indices, top_k_scores, scores); + + topk_scores_t top_k_scores_softmax = finalize_topk_scores_softmax(top_k_scores, scores_softmax_sum, scores_softmax_bias); + topk_indices_stream << top_k_indices; + topk_scores_stream << top_k_scores_softmax; + } +} + +void compute_gating( + patch_blocks_t gate_inp, + unsigned int expert_queues[NUM_EXPERTS][NUM_PATCHES], + fm_t expert_scores[NUM_EXPERTS][NUM_PATCHES], + unsigned int expert_queue_lens[NUM_EXPERTS] +) +{ + #pragma HLS inline off + #pragma HLS dataflow + + hls::stream gate_inp_stream; + hls::stream topk_indices_stream; + hls::stream topk_scores_stream; + + read_gate_inp(gate_inp_stream, gate_inp); + compute_gating(gate_inp_stream, topk_indices_stream, topk_scores_stream); + write_gate_results(topk_indices_stream, topk_scores_stream, expert_queues, expert_scores, expert_queue_lens); +} + +void zero_output(patch_blocks_t out) +{ + #pragma HLS inline off + + FOR_EACH(patch, NUM_PATCHES) + { + FOR_BLOCK(dim, FEATURE_DIM, FEATURE_BLOCK_SIZE) + { + out[patch][dim_block] = fm_t(0); + } + } +} + +void compute_moe( + patch_blocks_t gate_inp, + patch_blocks_t out, + fm_block_t tmp_hidden[], + wt_linear_t all_weights_l1[NUM_EXPERTS][EXPERT_HIDDEN_DIM][FEATURE_DIM], + wt_bias_t all_bias_l1[NUM_EXPERTS][EXPERT_HIDDEN_DIM], + wt_linear_t all_weights_l2[NUM_EXPERTS][FEATURE_DIM][EXPERT_HIDDEN_DIM], + wt_bias_t all_bias_l2[NUM_EXPERTS][FEATURE_DIM] +) +{ + #pragma HLS inline + + compute_gating(gate_inp, expert_queues, expert_scores, expert_queue_lens); + zero_output(out); + + unsigned int expert_load = expert_metaqueue[0]; + if (NUM_SELECTED_EXPERTS > 0 || expert_metaqueue_len > 0) + { + load_linear_weights( + linear_weights_ping, + reinterpret_cast(all_weights_l1[expert_load]), + EXPERT_HIDDEN_DIM, + FEATURE_DIM + ); + load_linear_bias( + linear_bias_ping, + reinterpret_cast(all_bias_l1[expert_load]), + EXPERT_HIDDEN_DIM + ); + } + + unsigned int expert_compute = expert_load; + _LABEL_FOR_EACH(__LINE__, expert_load_idx): for ( + unsigned int expert_load_idx = 1; + expert_load_idx < expert_metaqueue_len; + expert_load_idx++ + ) + { + #pragma HLS pipeline off + #pragma HLS loop_tripcount min=0 avg=(NUM_EXPERTS - 1) max=(NUM_EXPERTS - 1) + + expert_compute = expert_load; + compute_linear( + tmp_hidden, + reinterpret_cast(gate_inp), + linear_weights_ping, + linear_bias_ping, + EXPERT_HIDDEN_DIM, + FEATURE_DIM, + expert_compute, + true, + true, + false + ); + load_linear_weights( + linear_weights_pong, + reinterpret_cast(all_weights_l2[expert_compute]), + FEATURE_DIM, + EXPERT_HIDDEN_DIM + ); + load_linear_bias( + linear_bias_pong, + reinterpret_cast(all_bias_l2[expert_compute]), + FEATURE_DIM + ); + + expert_load = expert_metaqueue[expert_load_idx]; + compute_linear( + reinterpret_cast(out), + tmp_hidden, + linear_weights_pong, + linear_bias_pong, + FEATURE_DIM, + EXPERT_HIDDEN_DIM, + expert_compute, + false, + true, + true + ); + load_linear_weights( + linear_weights_ping, + reinterpret_cast(all_weights_l1[expert_load]), + EXPERT_HIDDEN_DIM, + FEATURE_DIM + ); + load_linear_bias( + linear_bias_ping, + reinterpret_cast(all_bias_l1[expert_load]), + EXPERT_HIDDEN_DIM + ); + } + + if (NUM_SELECTED_EXPERTS > 0 || expert_metaqueue_len > 0) + { + expert_compute = expert_load; + compute_linear( + tmp_hidden, + reinterpret_cast(gate_inp), + linear_weights_ping, + linear_bias_ping, + EXPERT_HIDDEN_DIM, + FEATURE_DIM, + expert_compute, + true, + true, + false + ); + load_linear_weights( + linear_weights_pong, + reinterpret_cast(all_weights_l2[expert_compute]), + FEATURE_DIM, + EXPERT_HIDDEN_DIM + ); + load_linear_bias( + linear_bias_pong, + reinterpret_cast(all_bias_l2[expert_compute]), + FEATURE_DIM + ); + + compute_linear( + reinterpret_cast(out), + tmp_hidden, + linear_weights_pong, + linear_bias_pong, + FEATURE_DIM, + EXPERT_HIDDEN_DIM, + expert_compute, + false, + true, + true + ); + } +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/BU.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/BU.cpp new file mode 100644 index 000000000000..cf99c169db65 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/BU.cpp @@ -0,0 +1,616 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ){ +#pragma HLS disaggregate variable = fwd_inVal0 +#pragma HLS interface ap_fifo port = fwd_inVal0._ +#pragma HLS aggregate variable = fwd_inVal0._ bit +#pragma HLS interface ap_fifo port = fwd_inVal0._peek +#pragma HLS aggregate variable = fwd_inVal0._peek bit +void(fwd_inVal0._.empty()); +void(fwd_inVal0._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal1 +#pragma HLS interface ap_fifo port = fwd_inVal1._ +#pragma HLS aggregate variable = fwd_inVal1._ bit +#pragma HLS interface ap_fifo port = fwd_inVal1._peek +#pragma HLS aggregate variable = fwd_inVal1._peek bit +void(fwd_inVal1._.empty()); +void(fwd_inVal1._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal0 +#pragma HLS interface ap_fifo port = inv_inVal0._ +#pragma HLS aggregate variable = inv_inVal0._ bit +#pragma HLS interface ap_fifo port = inv_inVal0._peek +#pragma HLS aggregate variable = inv_inVal0._peek bit +void(inv_inVal0._.empty()); +void(inv_inVal0._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal1 +#pragma HLS interface ap_fifo port = inv_inVal1._ +#pragma HLS aggregate variable = inv_inVal1._ bit +#pragma HLS interface ap_fifo port = inv_inVal1._peek +#pragma HLS aggregate variable = inv_inVal1._peek bit +void(inv_inVal1._.empty()); +void(inv_inVal1._peek.empty()); + +#pragma HLS disaggregate variable = tf_inVal +#pragma HLS interface ap_fifo port = tf_inVal._ +#pragma HLS aggregate variable = tf_inVal._ bit +#pragma HLS interface ap_fifo port = tf_inVal._peek +#pragma HLS aggregate variable = tf_inVal._peek bit +void(tf_inVal._.empty()); +void(tf_inVal._peek.empty()); + +#pragma HLS disaggregate variable = fwd_outVal0 +#pragma HLS interface ap_fifo port = fwd_outVal0._ +#pragma HLS aggregate variable = fwd_outVal0._ bit +void(fwd_outVal0._.full()); + +#pragma HLS disaggregate variable = fwd_outVal1 +#pragma HLS interface ap_fifo port = fwd_outVal1._ +#pragma HLS aggregate variable = fwd_outVal1._ bit +void(fwd_outVal1._.full()); + +#pragma HLS disaggregate variable = inv_outVal0 +#pragma HLS interface ap_fifo port = inv_outVal0._ +#pragma HLS aggregate variable = inv_outVal0._ bit +void(inv_outVal0._.full()); + +#pragma HLS disaggregate variable = inv_outVal1 +#pragma HLS interface ap_fifo port = inv_outVal1._ +#pragma HLS aggregate variable = inv_outVal1._ bit +void(inv_outVal1._.full()); + + + + + + + + + + VAR_TYPE_32 totalIterDataCount = 0; + VAR_TYPE_16 singleIterDataCount = 0; + VAR_TYPE_32 totalIterDataLimit = (N/V_TOTAL_DATA) * ( (VAR_TYPE_32)(logN+(H_BUG_SIZE-1))/H_BUG_SIZE ) * (iter+1); + VAR_TYPE_16 singleIterDataLimit = (N/V_TOTAL_DATA) * ( (VAR_TYPE_16)(logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + VAR_TYPE_16 nonCompleteStageLimit = ( (logN%H_BUG_SIZE) >= (layer_id+1) ) ? 1 : 0; + VAR_TYPE_16 fwd_singleIterCompLimit = (N/V_TOTAL_DATA) * ( ((VAR_TYPE_16)logN/H_BUG_SIZE) + nonCompleteStageLimit ); + VAR_TYPE_16 inv_singleIterCompLimit = singleIterDataLimit - fwd_singleIterCompLimit; + + WORD left; + WORD right; + WORD tfVal; + WORD updatedLeft; + WORD updatedRight; + + BU_COMP:for (;totalIterDataCount=q){ + updatedLeft = intemAdd - q; + } + else{ + updatedLeft = intemAdd; + } + + if(left >= reducedProduct){ + updatedRight = left - reducedProduct; + } + else{ + updatedRight = q - (reducedProduct - left); + } + + if(!direction){ //Multiply with 2 inverse here. Equation=> (a>>1) + a[0]((mod+1)/2) + multiplyTwoInverse(&updatedLeft, &twoInverse); + multiplyTwoInverse(&updatedRight, &twoInverse); + } + + if( ( (direction) && (singleIterDataCount >= fwd_singleIterCompLimit) ) || ( (!direction) && (singleIterDataCount < inv_singleIterCompLimit) ) ){ + updatedLeft = left; + updatedRight = right; + } + + if(direction){ + fwd_outVal0.write(updatedLeft); + fwd_outVal1.write(updatedRight); + } + else{ + inv_outVal0.write(updatedLeft); + inv_outVal1.write(updatedRight); + } + + totalIterDataCount++; + singleIterDataCount = (singleIterDataCount==(singleIterDataLimit-1)) ? (0) : (singleIterDataCount+1); + } + } + +} + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/BU/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/Mmap2Stream_tf_0_1_limbs.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/Mmap2Stream_tf_0_1_limbs.cpp new file mode 100644 index 000000000000..3716a308dba5 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/Mmap2Stream_tf_0_1_limbs.cpp @@ -0,0 +1,574 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(tapa::async_mmap& tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) { +#pragma HLS disaggregate variable = tf_mmap +#pragma HLS interface ap_fifo port = tf_mmap.read_addr._ +#pragma HLS aggregate variable = tf_mmap.read_addr._ bit +#pragma HLS interface ap_fifo port = tf_mmap.read_data._ +#pragma HLS aggregate variable = tf_mmap.read_data._ bit +#pragma HLS interface ap_fifo port = tf_mmap.write_addr._ +#pragma HLS aggregate variable = tf_mmap.write_addr._ bit +#pragma HLS interface ap_fifo port = tf_mmap.write_data._ +#pragma HLS aggregate variable = tf_mmap.write_data._ bit +#pragma HLS interface ap_fifo port = tf_mmap.write_resp._ +#pragma HLS aggregate variable = tf_mmap.write_resp._ bit +#pragma HLS disaggregate variable = tf_mmap .read_data +#pragma HLS interface ap_fifo port = tf_mmap.read_data._peek +#pragma HLS aggregate variable = tf_mmap.read_data._peek bit +#pragma HLS disaggregate variable = tf_mmap .write_resp +#pragma HLS interface ap_fifo port = tf_mmap.write_resp._peek +#pragma HLS aggregate variable = tf_mmap.write_resp._peek bit +void(tf_mmap.read_addr._.full()); +void(tf_mmap.read_data._.empty()); +void(tf_mmap.read_data._peek.empty()); +void(tf_mmap.write_addr._.full()); +void(tf_mmap.write_data._.full()); +void(tf_mmap.write_resp._.empty()); +void(tf_mmap.write_resp._peek.empty()); + +#pragma HLS disaggregate variable = tf_stream_L0_0 +#pragma HLS array_partition variable = tf_stream_L0_0 complete +#pragma HLS interface ap_fifo port = tf_stream_L0_0[0]._ +#pragma HLS aggregate variable = tf_stream_L0_0[0]._ bit +void(tf_stream_L0_0[0]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[1]._ +#pragma HLS aggregate variable = tf_stream_L0_0[1]._ bit +void(tf_stream_L0_0[1]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[2]._ +#pragma HLS aggregate variable = tf_stream_L0_0[2]._ bit +void(tf_stream_L0_0[2]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[3]._ +#pragma HLS aggregate variable = tf_stream_L0_0[3]._ bit +void(tf_stream_L0_0[3]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[4]._ +#pragma HLS aggregate variable = tf_stream_L0_0[4]._ bit +void(tf_stream_L0_0[4]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[5]._ +#pragma HLS aggregate variable = tf_stream_L0_0[5]._ bit +void(tf_stream_L0_0[5]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[6]._ +#pragma HLS aggregate variable = tf_stream_L0_0[6]._ bit +void(tf_stream_L0_0[6]._.full()); +#pragma HLS interface ap_fifo port = tf_stream_L0_0[7]._ +#pragma HLS aggregate variable = tf_stream_L0_0[7]._ bit +void(tf_stream_L0_0[7]._.full()); + + + + + + VAR_TYPE_16 fwd_total_depth = 242; + VAR_TYPE_16 inv_total_depth = 204; + + VAR_TYPE_16 total_depth; + if(direction){ + total_depth = fwd_total_depth; + } + else{ + total_depth = inv_total_depth; + } + + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + LOAD_TF:for (int i_req = 0, i_resp=0; i_resp < (total_depth);) { + #pragma HLS PIPELINE II=1 + + if( ( i_req < (total_depth) ) && (tf_mmap.read_addr.try_write(i_req)) ){ + i_req++; + } + + if( !tf_mmap.read_data.empty() ){ + TF_WIDE_DATA val = tf_mmap.read_data.read(); + + for(VAR_TYPE_8 j=0; j>= (2*DRAM_WORD_SIZE); + } + + i_resp++; + } + + } + } + + #ifndef __SYNTHESIS__ + printf("[Mmap2Stream_tf]: TF loading done\n"); + #endif + +} + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/Mmap2Stream_tf_0_1_limbs/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/NTT_kernel.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/NTT_kernel.cpp new file mode 100644 index 000000000000..dc9888026448 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/NTT_kernel.cpp @@ -0,0 +1,520 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +extern "C" { + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +{ + +#pragma HLS interface s_axilite port = polyVectorInOut_G0 bundle = control +{ auto val = reinterpret_cast(polyVectorInOut_G0); } +{ auto val = reinterpret_cast(polyVectorInOut_G0); } + +#pragma HLS interface s_axilite port = TFArr_G0 bundle = control +{ auto val = reinterpret_cast(TFArr_G0); } +{ auto val = reinterpret_cast(TFArr_G0); } + +#pragma HLS interface s_axilite port = TFArr_G1 bundle = control +{ auto val = reinterpret_cast(TFArr_G1); } +{ auto val = reinterpret_cast(TFArr_G1); } + +#pragma HLS interface s_axilite port = polyVectorInOut_G1 bundle = control +{ auto val = reinterpret_cast(polyVectorInOut_G1); } +{ auto val = reinterpret_cast(polyVectorInOut_G1); } + +#pragma HLS interface s_axilite port = q0 bundle = control +{ auto val = reinterpret_cast(q0); } + +#pragma HLS interface s_axilite port = twoInverse0 bundle = control +{ auto val = reinterpret_cast(twoInverse0); } + +#pragma HLS interface s_axilite port = factor0 bundle = control +{ auto val = reinterpret_cast(factor0); } + +#pragma HLS interface s_axilite port = direction bundle = control +{ auto val = reinterpret_cast(direction); } + +#pragma HLS interface s_axilite port = iter bundle = control +{ auto val = reinterpret_cast(iter); } + + +#pragma HLS interface s_axilite port = return bundle = control +} + + +} // extern "C" + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/NTT_kernel/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/TFBuf_wiFW_0.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/TFBuf_wiFW_0.cpp new file mode 100644 index 000000000000..ebb6ee5286de --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/TFBuf_wiFW_0.cpp @@ -0,0 +1,541 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = loadTFStream +#pragma HLS interface ap_fifo port = loadTFStream._ +#pragma HLS aggregate variable = loadTFStream._ bit +#pragma HLS interface ap_fifo port = loadTFStream._peek +#pragma HLS aggregate variable = loadTFStream._peek bit +void(loadTFStream._.empty()); +void(loadTFStream._peek.empty()); + +#pragma HLS disaggregate variable = loadTFToNext +#pragma HLS interface ap_fifo port = loadTFToNext._ +#pragma HLS aggregate variable = loadTFToNext._ bit +void(loadTFToNext._.full()); + +#pragma HLS disaggregate variable = tfToBu_0 +#pragma HLS interface ap_fifo port = tfToBu_0._ +#pragma HLS aggregate variable = tfToBu_0._ bit +void(tfToBu_0._.full()); + +#pragma HLS disaggregate variable = tfToBu_1 +#pragma HLS interface ap_fifo port = tfToBu_1._ +#pragma HLS aggregate variable = tfToBu_1._ bit +void(tfToBu_1._.full()); + + + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 dataFlowIterLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + + //==== Auto generated variables start ====// + const VAR_TYPE_16 TFArr_size = 162; + const VAR_TYPE_16 fwd_tf_load_counter = 242; + const VAR_TYPE_16 inv_tf_load_counter = 204; + const VAR_TYPE_16 fwd_this_buf_limit = 35; + const VAR_TYPE_16 inv_this_buf_limit = 81; + + const VAR_TYPE_16 fwd_log_stageWiseTFs[dataFlowIterLimit] = {0, 2, 6}; + const VAR_TYPE_16 inv_log_stageWiseTFs[dataFlowIterLimit] = {1, 5, 7}; + const VAR_TYPE_16 fwd_stageWiseOffset[dataFlowIterLimit] = {0, 1, 5}; + const VAR_TYPE_16 inv_stageWiseOffset[dataFlowIterLimit] = {0, 2, 34}; + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {0, 0, 0}; + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {1, 1, 1}; + //==== Auto generated variables end ====// + + const VAR_TYPE_16 tf_load_counter = (direction) ? (fwd_tf_load_counter) : (inv_tf_load_counter); + const VAR_TYPE_16 this_buf_limit = (direction) ? (fwd_this_buf_limit) : (inv_this_buf_limit); + + WORD TFArr[2][TFArr_size]; + #pragma HLS bind_storage variable=TFArr type=RAM_T2P impl=uram latency=1 + #pragma HLS array_partition variable=TFArr type=complete dim=1 + + VAR_TYPE_8 unit_id_0 = 2*unit_id; + VAR_TYPE_8 unit_id_1 = 2*unit_id+1; + + TF_ITER:for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + TFBuf_loadTF_wiFW(loadTFStream, loadTFToNext, TFArr[iterCount%2], tf_load_counter, this_buf_limit); + TFBuf_comp(tfToBu_0, tfToBu_1, TFArr[(iterCount+1)%2], fwd_log_stageWiseTFs, inv_log_stageWiseTFs, fwd_stageWiseOffset, inv_stageWiseOffset, fwd_log_num_val_accessed_by_consec_BUs_arr, inv_log_num_val_accessed_by_consec_BUs_arr, unit_id_0, unit_id_1, dataCount, dataFlowIterLimit, direction); + } +} + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_0/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/TFBuf_wiFW_1.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/TFBuf_wiFW_1.cpp new file mode 100644 index 000000000000..164553cb88c6 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/TFBuf_wiFW_1.cpp @@ -0,0 +1,541 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = loadTFStream +#pragma HLS interface ap_fifo port = loadTFStream._ +#pragma HLS aggregate variable = loadTFStream._ bit +#pragma HLS interface ap_fifo port = loadTFStream._peek +#pragma HLS aggregate variable = loadTFStream._peek bit +void(loadTFStream._.empty()); +void(loadTFStream._peek.empty()); + +#pragma HLS disaggregate variable = loadTFToNext +#pragma HLS interface ap_fifo port = loadTFToNext._ +#pragma HLS aggregate variable = loadTFToNext._ bit +void(loadTFToNext._.full()); + +#pragma HLS disaggregate variable = tfToBu_0 +#pragma HLS interface ap_fifo port = tfToBu_0._ +#pragma HLS aggregate variable = tfToBu_0._ bit +void(tfToBu_0._.full()); + +#pragma HLS disaggregate variable = tfToBu_1 +#pragma HLS interface ap_fifo port = tfToBu_1._ +#pragma HLS aggregate variable = tfToBu_1._ bit +void(tfToBu_1._.full()); + + + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 dataFlowIterLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + + //==== Auto generated variables start ====// + const VAR_TYPE_16 TFArr_size = 138; + const VAR_TYPE_16 fwd_tf_load_counter = 207; + const VAR_TYPE_16 inv_tf_load_counter = 123; + const VAR_TYPE_16 fwd_this_buf_limit = 69; + const VAR_TYPE_16 inv_this_buf_limit = 41; + + const VAR_TYPE_16 fwd_log_stageWiseTFs[dataFlowIterLimit] = {1, 3, 7}; + const VAR_TYPE_16 inv_log_stageWiseTFs[dataFlowIterLimit] = {0, 4, 6}; + const VAR_TYPE_16 fwd_stageWiseOffset[dataFlowIterLimit] = {0, 2, 10}; + const VAR_TYPE_16 inv_stageWiseOffset[dataFlowIterLimit] = {0, 1, 17}; + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {1, 1, 1}; + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {0, 0, 0}; + //==== Auto generated variables end ====// + + const VAR_TYPE_16 tf_load_counter = (direction) ? (fwd_tf_load_counter) : (inv_tf_load_counter); + const VAR_TYPE_16 this_buf_limit = (direction) ? (fwd_this_buf_limit) : (inv_this_buf_limit); + + WORD TFArr[2][TFArr_size]; + #pragma HLS bind_storage variable=TFArr type=RAM_T2P impl=uram latency=1 + #pragma HLS array_partition variable=TFArr type=complete dim=1 + + VAR_TYPE_8 unit_id_0 = 2*unit_id; + VAR_TYPE_8 unit_id_1 = 2*unit_id+1; + + TF_ITER:for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + TFBuf_loadTF_wiFW(loadTFStream, loadTFToNext, TFArr[iterCount%2], tf_load_counter, this_buf_limit); + TFBuf_comp(tfToBu_0, tfToBu_1, TFArr[(iterCount+1)%2], fwd_log_stageWiseTFs, inv_log_stageWiseTFs, fwd_stageWiseOffset, inv_stageWiseOffset, fwd_log_num_val_accessed_by_consec_BUs_arr, inv_log_num_val_accessed_by_consec_BUs_arr, unit_id_0, unit_id_1, dataCount, dataFlowIterLimit, direction); + } +} + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_1/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/TFBuf_wiFW_2.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/TFBuf_wiFW_2.cpp new file mode 100644 index 000000000000..f7a704eccd77 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/TFBuf_wiFW_2.cpp @@ -0,0 +1,541 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = loadTFStream +#pragma HLS interface ap_fifo port = loadTFStream._ +#pragma HLS aggregate variable = loadTFStream._ bit +#pragma HLS interface ap_fifo port = loadTFStream._peek +#pragma HLS aggregate variable = loadTFStream._peek bit +void(loadTFStream._.empty()); +void(loadTFStream._peek.empty()); + +#pragma HLS disaggregate variable = loadTFToNext +#pragma HLS interface ap_fifo port = loadTFToNext._ +#pragma HLS aggregate variable = loadTFToNext._ bit +void(loadTFToNext._.full()); + +#pragma HLS disaggregate variable = tfToBu_0 +#pragma HLS interface ap_fifo port = tfToBu_0._ +#pragma HLS aggregate variable = tfToBu_0._ bit +void(tfToBu_0._.full()); + +#pragma HLS disaggregate variable = tfToBu_1 +#pragma HLS interface ap_fifo port = tfToBu_1._ +#pragma HLS aggregate variable = tfToBu_1._ bit +void(tfToBu_1._.full()); + + + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 dataFlowIterLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + + //==== Auto generated variables start ====// + const VAR_TYPE_16 TFArr_size = 138; + const VAR_TYPE_16 fwd_tf_load_counter = 138; + const VAR_TYPE_16 inv_tf_load_counter = 82; + const VAR_TYPE_16 fwd_this_buf_limit = 69; + const VAR_TYPE_16 inv_this_buf_limit = 41; + + const VAR_TYPE_16 fwd_log_stageWiseTFs[dataFlowIterLimit] = {1, 3, 7}; + const VAR_TYPE_16 inv_log_stageWiseTFs[dataFlowIterLimit] = {0, 4, 6}; + const VAR_TYPE_16 fwd_stageWiseOffset[dataFlowIterLimit] = {0, 2, 10}; + const VAR_TYPE_16 inv_stageWiseOffset[dataFlowIterLimit] = {0, 1, 17}; + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {1, 1, 1}; + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {0, 0, 0}; + //==== Auto generated variables end ====// + + const VAR_TYPE_16 tf_load_counter = (direction) ? (fwd_tf_load_counter) : (inv_tf_load_counter); + const VAR_TYPE_16 this_buf_limit = (direction) ? (fwd_this_buf_limit) : (inv_this_buf_limit); + + WORD TFArr[2][TFArr_size]; + #pragma HLS bind_storage variable=TFArr type=RAM_T2P impl=uram latency=1 + #pragma HLS array_partition variable=TFArr type=complete dim=1 + + VAR_TYPE_8 unit_id_0 = 2*unit_id; + VAR_TYPE_8 unit_id_1 = 2*unit_id+1; + + TF_ITER:for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + TFBuf_loadTF_wiFW(loadTFStream, loadTFToNext, TFArr[iterCount%2], tf_load_counter, this_buf_limit); + TFBuf_comp(tfToBu_0, tfToBu_1, TFArr[(iterCount+1)%2], fwd_log_stageWiseTFs, inv_log_stageWiseTFs, fwd_stageWiseOffset, inv_stageWiseOffset, fwd_log_num_val_accessed_by_consec_BUs_arr, inv_log_num_val_accessed_by_consec_BUs_arr, unit_id_0, unit_id_1, dataCount, dataFlowIterLimit, direction); + } +} + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_wiFW_2/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/TFBuf_woFW_3.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/TFBuf_woFW_3.cpp new file mode 100644 index 000000000000..e0e86d5f4ad1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/TFBuf_woFW_3.cpp @@ -0,0 +1,537 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = loadTFStream +#pragma HLS interface ap_fifo port = loadTFStream._ +#pragma HLS aggregate variable = loadTFStream._ bit +#pragma HLS interface ap_fifo port = loadTFStream._peek +#pragma HLS aggregate variable = loadTFStream._peek bit +void(loadTFStream._.empty()); +void(loadTFStream._peek.empty()); + +#pragma HLS disaggregate variable = tfToBu_0 +#pragma HLS interface ap_fifo port = tfToBu_0._ +#pragma HLS aggregate variable = tfToBu_0._ bit +void(tfToBu_0._.full()); + +#pragma HLS disaggregate variable = tfToBu_1 +#pragma HLS interface ap_fifo port = tfToBu_1._ +#pragma HLS aggregate variable = tfToBu_1._ bit +void(tfToBu_1._.full()); + + + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 dataFlowIterLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + + //==== Auto generated variables start ====// + const VAR_TYPE_16 TFArr_size = 138; + const VAR_TYPE_16 fwd_tf_load_counter = 69; + const VAR_TYPE_16 inv_tf_load_counter = 41; + const VAR_TYPE_16 fwd_this_buf_limit = 69; + const VAR_TYPE_16 inv_this_buf_limit = 41; + + const VAR_TYPE_16 fwd_log_stageWiseTFs[dataFlowIterLimit] = {1, 3, 7}; + const VAR_TYPE_16 inv_log_stageWiseTFs[dataFlowIterLimit] = {0, 4, 6}; + const VAR_TYPE_16 fwd_stageWiseOffset[dataFlowIterLimit] = {0, 2, 10}; + const VAR_TYPE_16 inv_stageWiseOffset[dataFlowIterLimit] = {0, 1, 17}; + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {1, 1, 1}; + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[dataFlowIterLimit] = {0, 0, 0}; + //==== Auto generated variables end ====// + + const VAR_TYPE_16 tf_load_counter = (direction) ? (fwd_tf_load_counter) : (inv_tf_load_counter); + const VAR_TYPE_16 this_buf_limit = (direction) ? (fwd_this_buf_limit) : (inv_this_buf_limit); + + WORD TFArr[2][TFArr_size]; + #pragma HLS bind_storage variable=TFArr type=RAM_T2P impl=uram latency=1 + #pragma HLS array_partition variable=TFArr type=complete dim=1 + + VAR_TYPE_8 unit_id_0 = 2*unit_id; + VAR_TYPE_8 unit_id_1 = 2*unit_id+1; + + //comp + TF_ITER:for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + TFBuf_loadTF_woFW(loadTFStream, TFArr[iterCount%2], tf_load_counter); + TFBuf_comp(tfToBu_0, tfToBu_1, TFArr[(iterCount+1)%2], fwd_log_stageWiseTFs, inv_log_stageWiseTFs, fwd_stageWiseOffset, inv_stageWiseOffset, fwd_log_num_val_accessed_by_consec_BUs_arr, inv_log_num_val_accessed_by_consec_BUs_arr, unit_id_0, unit_id_1, dataCount, dataFlowIterLimit, direction); + } +} + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/TFBuf_woFW_3/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/dual_interface_FIFO_receive.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/dual_interface_FIFO_receive.cpp new file mode 100644 index 000000000000..a04bc39d2c7a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/dual_interface_FIFO_receive.cpp @@ -0,0 +1,517 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction){ +#pragma HLS disaggregate variable = fwd_inVal +#pragma HLS interface ap_fifo port = fwd_inVal._ +#pragma HLS aggregate variable = fwd_inVal._ bit +#pragma HLS interface ap_fifo port = fwd_inVal._peek +#pragma HLS aggregate variable = fwd_inVal._peek bit +void(fwd_inVal._.empty()); +void(fwd_inVal._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal +#pragma HLS interface ap_fifo port = inv_inVal._ +#pragma HLS aggregate variable = inv_inVal._ bit +#pragma HLS interface ap_fifo port = inv_inVal._peek +#pragma HLS aggregate variable = inv_inVal._peek bit +void(inv_inVal._.empty()); +void(inv_inVal._peek.empty()); + +#pragma HLS disaggregate variable = common_outVal +#pragma HLS interface ap_fifo port = common_outVal._ +#pragma HLS aggregate variable = common_outVal._ bit +void(common_outVal._.full()); + + + + bool inpStreamNotEmpty; + for(;;){ + + inpStreamNotEmpty = ( !fwd_inVal.empty() ) || ( !inv_inVal.empty() ); + + if(inpStreamNotEmpty){ + if(direction){ + common_outVal.write(fwd_inVal.read()); + } + else{ + common_outVal.write(inv_inVal.read()); + } + } + } +} + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_receive/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/dual_interface_FIFO_send.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/dual_interface_FIFO_send.cpp new file mode 100644 index 000000000000..57f3f79d1db3 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/dual_interface_FIFO_send.cpp @@ -0,0 +1,514 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction){ +#pragma HLS disaggregate variable = common_inVal +#pragma HLS interface ap_fifo port = common_inVal._ +#pragma HLS aggregate variable = common_inVal._ bit +#pragma HLS interface ap_fifo port = common_inVal._peek +#pragma HLS aggregate variable = common_inVal._peek bit +void(common_inVal._.empty()); +void(common_inVal._peek.empty()); + +#pragma HLS disaggregate variable = fwd_outVal +#pragma HLS interface ap_fifo port = fwd_outVal._ +#pragma HLS aggregate variable = fwd_outVal._ bit +void(fwd_outVal._.full()); + +#pragma HLS disaggregate variable = inv_outVal +#pragma HLS interface ap_fifo port = inv_outVal._ +#pragma HLS aggregate variable = inv_outVal._ bit +void(inv_outVal._.full()); + + + + bool inpStreamNotEmpty; + for(;;){ + + inpStreamNotEmpty = !common_inVal.empty(); + + if(inpStreamNotEmpty){ + if(direction){ + fwd_outVal.write(common_inVal.read()); + } + else{ + inv_outVal.write(common_inVal.read()); + } + } + } +} + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/dual_interface_FIFO_send/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/fwd_load_inv_store_poly_1_limbs.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/fwd_load_inv_store_poly_1_limbs.cpp new file mode 100644 index 000000000000..34210cb2508e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/fwd_load_inv_store_poly_1_limbs.cpp @@ -0,0 +1,1222 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(tapa::async_mmap& poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) { +#pragma HLS disaggregate variable = poly_mmap +#pragma HLS interface ap_fifo port = poly_mmap.read_addr._ +#pragma HLS aggregate variable = poly_mmap.read_addr._ bit +#pragma HLS interface ap_fifo port = poly_mmap.read_data._ +#pragma HLS aggregate variable = poly_mmap.read_data._ bit +#pragma HLS interface ap_fifo port = poly_mmap.write_addr._ +#pragma HLS aggregate variable = poly_mmap.write_addr._ bit +#pragma HLS interface ap_fifo port = poly_mmap.write_data._ +#pragma HLS aggregate variable = poly_mmap.write_data._ bit +#pragma HLS interface ap_fifo port = poly_mmap.write_resp._ +#pragma HLS aggregate variable = poly_mmap.write_resp._ bit +#pragma HLS disaggregate variable = poly_mmap .read_data +#pragma HLS interface ap_fifo port = poly_mmap.read_data._peek +#pragma HLS aggregate variable = poly_mmap.read_data._peek bit +#pragma HLS disaggregate variable = poly_mmap .write_resp +#pragma HLS interface ap_fifo port = poly_mmap.write_resp._peek +#pragma HLS aggregate variable = poly_mmap.write_resp._peek bit +void(poly_mmap.read_addr._.full()); +void(poly_mmap.read_data._.empty()); +void(poly_mmap.read_data._peek.empty()); +void(poly_mmap.write_addr._.full()); +void(poly_mmap.write_data._.full()); +void(poly_mmap.write_resp._.empty()); +void(poly_mmap.write_resp._peek.empty()); + +#pragma HLS disaggregate variable = inv_in_poly_L0_stream0 +#pragma HLS array_partition variable = inv_in_poly_L0_stream0 complete +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[0]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[0]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[0]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[0]._peek bit +void(inv_in_poly_L0_stream0[0]._.empty()); +void(inv_in_poly_L0_stream0[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[1]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[1]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[1]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[1]._peek bit +void(inv_in_poly_L0_stream0[1]._.empty()); +void(inv_in_poly_L0_stream0[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[2]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[2]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[2]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[2]._peek bit +void(inv_in_poly_L0_stream0[2]._.empty()); +void(inv_in_poly_L0_stream0[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[3]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[3]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[3]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[3]._peek bit +void(inv_in_poly_L0_stream0[3]._.empty()); +void(inv_in_poly_L0_stream0[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[4]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[4]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[4]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[4]._peek bit +void(inv_in_poly_L0_stream0[4]._.empty()); +void(inv_in_poly_L0_stream0[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[5]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[5]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[5]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[5]._peek bit +void(inv_in_poly_L0_stream0[5]._.empty()); +void(inv_in_poly_L0_stream0[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[6]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[6]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[6]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[6]._peek bit +void(inv_in_poly_L0_stream0[6]._.empty()); +void(inv_in_poly_L0_stream0[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[7]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[7]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[7]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[7]._peek bit +void(inv_in_poly_L0_stream0[7]._.empty()); +void(inv_in_poly_L0_stream0[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[8]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[8]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[8]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[8]._peek bit +void(inv_in_poly_L0_stream0[8]._.empty()); +void(inv_in_poly_L0_stream0[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[9]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[9]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[9]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[9]._peek bit +void(inv_in_poly_L0_stream0[9]._.empty()); +void(inv_in_poly_L0_stream0[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[10]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[10]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[10]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[10]._peek bit +void(inv_in_poly_L0_stream0[10]._.empty()); +void(inv_in_poly_L0_stream0[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[11]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[11]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[11]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[11]._peek bit +void(inv_in_poly_L0_stream0[11]._.empty()); +void(inv_in_poly_L0_stream0[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[12]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[12]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[12]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[12]._peek bit +void(inv_in_poly_L0_stream0[12]._.empty()); +void(inv_in_poly_L0_stream0[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[13]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[13]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[13]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[13]._peek bit +void(inv_in_poly_L0_stream0[13]._.empty()); +void(inv_in_poly_L0_stream0[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[14]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[14]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[14]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[14]._peek bit +void(inv_in_poly_L0_stream0[14]._.empty()); +void(inv_in_poly_L0_stream0[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[15]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[15]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream0[15]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream0[15]._peek bit +void(inv_in_poly_L0_stream0[15]._.empty()); +void(inv_in_poly_L0_stream0[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_in_poly_L0_stream1 +#pragma HLS array_partition variable = inv_in_poly_L0_stream1 complete +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[0]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[0]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[0]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[0]._peek bit +void(inv_in_poly_L0_stream1[0]._.empty()); +void(inv_in_poly_L0_stream1[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[1]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[1]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[1]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[1]._peek bit +void(inv_in_poly_L0_stream1[1]._.empty()); +void(inv_in_poly_L0_stream1[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[2]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[2]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[2]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[2]._peek bit +void(inv_in_poly_L0_stream1[2]._.empty()); +void(inv_in_poly_L0_stream1[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[3]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[3]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[3]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[3]._peek bit +void(inv_in_poly_L0_stream1[3]._.empty()); +void(inv_in_poly_L0_stream1[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[4]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[4]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[4]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[4]._peek bit +void(inv_in_poly_L0_stream1[4]._.empty()); +void(inv_in_poly_L0_stream1[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[5]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[5]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[5]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[5]._peek bit +void(inv_in_poly_L0_stream1[5]._.empty()); +void(inv_in_poly_L0_stream1[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[6]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[6]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[6]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[6]._peek bit +void(inv_in_poly_L0_stream1[6]._.empty()); +void(inv_in_poly_L0_stream1[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[7]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[7]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[7]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[7]._peek bit +void(inv_in_poly_L0_stream1[7]._.empty()); +void(inv_in_poly_L0_stream1[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[8]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[8]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[8]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[8]._peek bit +void(inv_in_poly_L0_stream1[8]._.empty()); +void(inv_in_poly_L0_stream1[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[9]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[9]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[9]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[9]._peek bit +void(inv_in_poly_L0_stream1[9]._.empty()); +void(inv_in_poly_L0_stream1[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[10]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[10]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[10]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[10]._peek bit +void(inv_in_poly_L0_stream1[10]._.empty()); +void(inv_in_poly_L0_stream1[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[11]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[11]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[11]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[11]._peek bit +void(inv_in_poly_L0_stream1[11]._.empty()); +void(inv_in_poly_L0_stream1[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[12]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[12]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[12]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[12]._peek bit +void(inv_in_poly_L0_stream1[12]._.empty()); +void(inv_in_poly_L0_stream1[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[13]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[13]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[13]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[13]._peek bit +void(inv_in_poly_L0_stream1[13]._.empty()); +void(inv_in_poly_L0_stream1[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[14]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[14]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[14]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[14]._peek bit +void(inv_in_poly_L0_stream1[14]._.empty()); +void(inv_in_poly_L0_stream1[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[15]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[15]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream1[15]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream1[15]._peek bit +void(inv_in_poly_L0_stream1[15]._.empty()); +void(inv_in_poly_L0_stream1[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_in_poly_L0_stream2 +#pragma HLS array_partition variable = inv_in_poly_L0_stream2 complete +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[0]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[0]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[0]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[0]._peek bit +void(inv_in_poly_L0_stream2[0]._.empty()); +void(inv_in_poly_L0_stream2[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[1]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[1]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[1]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[1]._peek bit +void(inv_in_poly_L0_stream2[1]._.empty()); +void(inv_in_poly_L0_stream2[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[2]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[2]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[2]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[2]._peek bit +void(inv_in_poly_L0_stream2[2]._.empty()); +void(inv_in_poly_L0_stream2[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[3]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[3]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[3]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[3]._peek bit +void(inv_in_poly_L0_stream2[3]._.empty()); +void(inv_in_poly_L0_stream2[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[4]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[4]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[4]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[4]._peek bit +void(inv_in_poly_L0_stream2[4]._.empty()); +void(inv_in_poly_L0_stream2[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[5]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[5]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[5]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[5]._peek bit +void(inv_in_poly_L0_stream2[5]._.empty()); +void(inv_in_poly_L0_stream2[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[6]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[6]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[6]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[6]._peek bit +void(inv_in_poly_L0_stream2[6]._.empty()); +void(inv_in_poly_L0_stream2[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[7]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[7]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[7]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[7]._peek bit +void(inv_in_poly_L0_stream2[7]._.empty()); +void(inv_in_poly_L0_stream2[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[8]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[8]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[8]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[8]._peek bit +void(inv_in_poly_L0_stream2[8]._.empty()); +void(inv_in_poly_L0_stream2[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[9]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[9]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[9]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[9]._peek bit +void(inv_in_poly_L0_stream2[9]._.empty()); +void(inv_in_poly_L0_stream2[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[10]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[10]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[10]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[10]._peek bit +void(inv_in_poly_L0_stream2[10]._.empty()); +void(inv_in_poly_L0_stream2[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[11]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[11]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[11]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[11]._peek bit +void(inv_in_poly_L0_stream2[11]._.empty()); +void(inv_in_poly_L0_stream2[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[12]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[12]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[12]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[12]._peek bit +void(inv_in_poly_L0_stream2[12]._.empty()); +void(inv_in_poly_L0_stream2[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[13]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[13]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[13]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[13]._peek bit +void(inv_in_poly_L0_stream2[13]._.empty()); +void(inv_in_poly_L0_stream2[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[14]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[14]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[14]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[14]._peek bit +void(inv_in_poly_L0_stream2[14]._.empty()); +void(inv_in_poly_L0_stream2[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[15]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[15]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream2[15]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream2[15]._peek bit +void(inv_in_poly_L0_stream2[15]._.empty()); +void(inv_in_poly_L0_stream2[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_in_poly_L0_stream3 +#pragma HLS array_partition variable = inv_in_poly_L0_stream3 complete +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[0]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[0]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[0]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[0]._peek bit +void(inv_in_poly_L0_stream3[0]._.empty()); +void(inv_in_poly_L0_stream3[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[1]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[1]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[1]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[1]._peek bit +void(inv_in_poly_L0_stream3[1]._.empty()); +void(inv_in_poly_L0_stream3[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[2]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[2]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[2]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[2]._peek bit +void(inv_in_poly_L0_stream3[2]._.empty()); +void(inv_in_poly_L0_stream3[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[3]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[3]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[3]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[3]._peek bit +void(inv_in_poly_L0_stream3[3]._.empty()); +void(inv_in_poly_L0_stream3[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[4]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[4]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[4]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[4]._peek bit +void(inv_in_poly_L0_stream3[4]._.empty()); +void(inv_in_poly_L0_stream3[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[5]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[5]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[5]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[5]._peek bit +void(inv_in_poly_L0_stream3[5]._.empty()); +void(inv_in_poly_L0_stream3[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[6]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[6]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[6]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[6]._peek bit +void(inv_in_poly_L0_stream3[6]._.empty()); +void(inv_in_poly_L0_stream3[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[7]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[7]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[7]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[7]._peek bit +void(inv_in_poly_L0_stream3[7]._.empty()); +void(inv_in_poly_L0_stream3[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[8]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[8]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[8]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[8]._peek bit +void(inv_in_poly_L0_stream3[8]._.empty()); +void(inv_in_poly_L0_stream3[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[9]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[9]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[9]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[9]._peek bit +void(inv_in_poly_L0_stream3[9]._.empty()); +void(inv_in_poly_L0_stream3[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[10]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[10]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[10]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[10]._peek bit +void(inv_in_poly_L0_stream3[10]._.empty()); +void(inv_in_poly_L0_stream3[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[11]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[11]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[11]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[11]._peek bit +void(inv_in_poly_L0_stream3[11]._.empty()); +void(inv_in_poly_L0_stream3[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[12]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[12]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[12]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[12]._peek bit +void(inv_in_poly_L0_stream3[12]._.empty()); +void(inv_in_poly_L0_stream3[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[13]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[13]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[13]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[13]._peek bit +void(inv_in_poly_L0_stream3[13]._.empty()); +void(inv_in_poly_L0_stream3[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[14]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[14]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[14]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[14]._peek bit +void(inv_in_poly_L0_stream3[14]._.empty()); +void(inv_in_poly_L0_stream3[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[15]._ +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[15]._ bit +#pragma HLS interface ap_fifo port = inv_in_poly_L0_stream3[15]._peek +#pragma HLS aggregate variable = inv_in_poly_L0_stream3[15]._peek bit +void(inv_in_poly_L0_stream3[15]._.empty()); +void(inv_in_poly_L0_stream3[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_out_poly_L0_stream0 +#pragma HLS array_partition variable = fwd_out_poly_L0_stream0 complete +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[0]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[0]._ bit +void(fwd_out_poly_L0_stream0[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[1]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[1]._ bit +void(fwd_out_poly_L0_stream0[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[2]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[2]._ bit +void(fwd_out_poly_L0_stream0[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[3]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[3]._ bit +void(fwd_out_poly_L0_stream0[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[4]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[4]._ bit +void(fwd_out_poly_L0_stream0[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[5]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[5]._ bit +void(fwd_out_poly_L0_stream0[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[6]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[6]._ bit +void(fwd_out_poly_L0_stream0[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[7]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[7]._ bit +void(fwd_out_poly_L0_stream0[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[8]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[8]._ bit +void(fwd_out_poly_L0_stream0[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[9]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[9]._ bit +void(fwd_out_poly_L0_stream0[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[10]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[10]._ bit +void(fwd_out_poly_L0_stream0[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[11]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[11]._ bit +void(fwd_out_poly_L0_stream0[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[12]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[12]._ bit +void(fwd_out_poly_L0_stream0[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[13]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[13]._ bit +void(fwd_out_poly_L0_stream0[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[14]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[14]._ bit +void(fwd_out_poly_L0_stream0[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream0[15]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream0[15]._ bit +void(fwd_out_poly_L0_stream0[15]._.full()); + +#pragma HLS disaggregate variable = fwd_out_poly_L0_stream1 +#pragma HLS array_partition variable = fwd_out_poly_L0_stream1 complete +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[0]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[0]._ bit +void(fwd_out_poly_L0_stream1[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[1]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[1]._ bit +void(fwd_out_poly_L0_stream1[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[2]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[2]._ bit +void(fwd_out_poly_L0_stream1[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[3]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[3]._ bit +void(fwd_out_poly_L0_stream1[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[4]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[4]._ bit +void(fwd_out_poly_L0_stream1[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[5]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[5]._ bit +void(fwd_out_poly_L0_stream1[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[6]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[6]._ bit +void(fwd_out_poly_L0_stream1[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[7]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[7]._ bit +void(fwd_out_poly_L0_stream1[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[8]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[8]._ bit +void(fwd_out_poly_L0_stream1[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[9]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[9]._ bit +void(fwd_out_poly_L0_stream1[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[10]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[10]._ bit +void(fwd_out_poly_L0_stream1[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[11]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[11]._ bit +void(fwd_out_poly_L0_stream1[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[12]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[12]._ bit +void(fwd_out_poly_L0_stream1[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[13]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[13]._ bit +void(fwd_out_poly_L0_stream1[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[14]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[14]._ bit +void(fwd_out_poly_L0_stream1[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream1[15]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream1[15]._ bit +void(fwd_out_poly_L0_stream1[15]._.full()); + +#pragma HLS disaggregate variable = fwd_out_poly_L0_stream2 +#pragma HLS array_partition variable = fwd_out_poly_L0_stream2 complete +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[0]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[0]._ bit +void(fwd_out_poly_L0_stream2[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[1]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[1]._ bit +void(fwd_out_poly_L0_stream2[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[2]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[2]._ bit +void(fwd_out_poly_L0_stream2[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[3]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[3]._ bit +void(fwd_out_poly_L0_stream2[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[4]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[4]._ bit +void(fwd_out_poly_L0_stream2[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[5]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[5]._ bit +void(fwd_out_poly_L0_stream2[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[6]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[6]._ bit +void(fwd_out_poly_L0_stream2[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[7]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[7]._ bit +void(fwd_out_poly_L0_stream2[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[8]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[8]._ bit +void(fwd_out_poly_L0_stream2[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[9]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[9]._ bit +void(fwd_out_poly_L0_stream2[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[10]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[10]._ bit +void(fwd_out_poly_L0_stream2[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[11]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[11]._ bit +void(fwd_out_poly_L0_stream2[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[12]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[12]._ bit +void(fwd_out_poly_L0_stream2[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[13]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[13]._ bit +void(fwd_out_poly_L0_stream2[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[14]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[14]._ bit +void(fwd_out_poly_L0_stream2[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream2[15]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream2[15]._ bit +void(fwd_out_poly_L0_stream2[15]._.full()); + +#pragma HLS disaggregate variable = fwd_out_poly_L0_stream3 +#pragma HLS array_partition variable = fwd_out_poly_L0_stream3 complete +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[0]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[0]._ bit +void(fwd_out_poly_L0_stream3[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[1]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[1]._ bit +void(fwd_out_poly_L0_stream3[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[2]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[2]._ bit +void(fwd_out_poly_L0_stream3[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[3]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[3]._ bit +void(fwd_out_poly_L0_stream3[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[4]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[4]._ bit +void(fwd_out_poly_L0_stream3[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[5]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[5]._ bit +void(fwd_out_poly_L0_stream3[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[6]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[6]._ bit +void(fwd_out_poly_L0_stream3[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[7]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[7]._ bit +void(fwd_out_poly_L0_stream3[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[8]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[8]._ bit +void(fwd_out_poly_L0_stream3[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[9]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[9]._ bit +void(fwd_out_poly_L0_stream3[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[10]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[10]._ bit +void(fwd_out_poly_L0_stream3[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[11]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[11]._ bit +void(fwd_out_poly_L0_stream3[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[12]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[12]._ bit +void(fwd_out_poly_L0_stream3[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[13]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[13]._ bit +void(fwd_out_poly_L0_stream3[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[14]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[14]._ bit +void(fwd_out_poly_L0_stream3[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_out_poly_L0_stream3[15]._ +#pragma HLS aggregate variable = fwd_out_poly_L0_stream3[15]._ bit +void(fwd_out_poly_L0_stream3[15]._.full()); + + + + + VAR_TYPE_16 totalDataCount = (N/V_TOTAL_DATA)*(SEQ_BUG_PER_PARA_LIMB_POLY_PORT); + POLY_WIDE_DATA val; + WORD smallData; + + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + LOAD_STORE_POLY_0:for (int i_req = 0, i_resp=0; i_resp < totalDataCount;) { + #pragma HLS PIPELINE II=1 + + if(direction){ //fwd load + if( ( i_req < totalDataCount ) && (poly_mmap.read_addr.try_write(i_req)) ){ + i_req++; + } + + if( !poly_mmap.read_data.empty() ){ + POLY_WIDE_DATA val = poly_mmap.read_data.read(nullptr); + + VAR_TYPE_16 seq_group_idx = i_resp/(N/V_TOTAL_DATA); + + for(int j=0; j<(2*V_BUG_SIZE); j++){ + #pragma HLS UNROLL + WORD smallVal = (WORD)(val & ((((POLY_WIDE_DATA)1)<>= DRAM_WORD_SIZE; + } + + i_resp++; + } + } + else{ //inv store + VAR_TYPE_16 seq_group_idx = i_req/(N/V_TOTAL_DATA); + + val = 0; + + bool inpStreamNotEmpty; + if( seq_group_idx==0 ){ + inpStreamNotEmpty = ( !inv_in_poly_L0_stream0[0].empty() ); + } + else if( seq_group_idx==1 ){ + inpStreamNotEmpty = ( !inv_in_poly_L0_stream1[0].empty() ); + } + else if( seq_group_idx==2 ){ + inpStreamNotEmpty = ( !inv_in_poly_L0_stream2[0].empty() ); + } + else{ + inpStreamNotEmpty = ( !inv_in_poly_L0_stream3[0].empty() ); + } + + for(int j=1; j<(2*V_BUG_SIZE); j++){ + if( seq_group_idx==0 ){ + inpStreamNotEmpty &= ( !inv_in_poly_L0_stream0[j].empty() ); + } + else if( seq_group_idx==1 ){ + inpStreamNotEmpty &= ( !inv_in_poly_L0_stream1[j].empty() ); + } + else if( seq_group_idx==2 ){ + inpStreamNotEmpty &= ( !inv_in_poly_L0_stream2[j].empty() ); + } + else{ + inpStreamNotEmpty &= ( !inv_in_poly_L0_stream3[j].empty() ); + } + } + + if( ( i_req < (totalDataCount) ) && ( inpStreamNotEmpty ) ){ + + //read FIFOs + for(int j=(2*V_BUG_SIZE)-1; j>=0; j--){ + #pragma HLS UNROLL + val <<= DRAM_WORD_SIZE; + if( seq_group_idx==0 ){ + smallData = inv_in_poly_L0_stream0[j].read(); + } + else if( seq_group_idx==1 ){ + smallData = inv_in_poly_L0_stream1[j].read(); + } + else if( seq_group_idx==2 ){ + smallData = inv_in_poly_L0_stream2[j].read(); + } + else{ + smallData = inv_in_poly_L0_stream3[j].read(); + } + val |= (POLY_WIDE_DATA)(smallData); + } + + //write mem + poly_mmap.write_addr.write(i_req); + poly_mmap.write_data.write(val); + i_req++; + } + + if( !poly_mmap.write_resp.empty() ){ + i_resp += unsigned(poly_mmap.write_resp.read(nullptr)) + 1; + } + } + } + } + #ifndef __SYNTHESIS__ + if(direction){ + printf("[fwd_load_inv_store_poly]: Polynomial loading done\n"); + } + else{ + printf("[fwd_load_inv_store_poly]: Polynomial storing done\n"); + } + #endif +} + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_load_inv_store_poly_1_limbs/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/fwd_store_inv_load_poly_1_limbs.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/fwd_store_inv_load_poly_1_limbs.cpp new file mode 100644 index 000000000000..41481f0e159a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/fwd_store_inv_load_poly_1_limbs.cpp @@ -0,0 +1,1222 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(tapa::async_mmap& poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) { +#pragma HLS disaggregate variable = poly_mmap +#pragma HLS interface ap_fifo port = poly_mmap.read_addr._ +#pragma HLS aggregate variable = poly_mmap.read_addr._ bit +#pragma HLS interface ap_fifo port = poly_mmap.read_data._ +#pragma HLS aggregate variable = poly_mmap.read_data._ bit +#pragma HLS interface ap_fifo port = poly_mmap.write_addr._ +#pragma HLS aggregate variable = poly_mmap.write_addr._ bit +#pragma HLS interface ap_fifo port = poly_mmap.write_data._ +#pragma HLS aggregate variable = poly_mmap.write_data._ bit +#pragma HLS interface ap_fifo port = poly_mmap.write_resp._ +#pragma HLS aggregate variable = poly_mmap.write_resp._ bit +#pragma HLS disaggregate variable = poly_mmap .read_data +#pragma HLS interface ap_fifo port = poly_mmap.read_data._peek +#pragma HLS aggregate variable = poly_mmap.read_data._peek bit +#pragma HLS disaggregate variable = poly_mmap .write_resp +#pragma HLS interface ap_fifo port = poly_mmap.write_resp._peek +#pragma HLS aggregate variable = poly_mmap.write_resp._peek bit +void(poly_mmap.read_addr._.full()); +void(poly_mmap.read_data._.empty()); +void(poly_mmap.read_data._peek.empty()); +void(poly_mmap.write_addr._.full()); +void(poly_mmap.write_data._.full()); +void(poly_mmap.write_resp._.empty()); +void(poly_mmap.write_resp._peek.empty()); + +#pragma HLS disaggregate variable = fwd_in_poly_L0_stream0 +#pragma HLS array_partition variable = fwd_in_poly_L0_stream0 complete +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[0]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[0]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[0]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[0]._peek bit +void(fwd_in_poly_L0_stream0[0]._.empty()); +void(fwd_in_poly_L0_stream0[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[1]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[1]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[1]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[1]._peek bit +void(fwd_in_poly_L0_stream0[1]._.empty()); +void(fwd_in_poly_L0_stream0[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[2]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[2]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[2]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[2]._peek bit +void(fwd_in_poly_L0_stream0[2]._.empty()); +void(fwd_in_poly_L0_stream0[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[3]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[3]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[3]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[3]._peek bit +void(fwd_in_poly_L0_stream0[3]._.empty()); +void(fwd_in_poly_L0_stream0[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[4]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[4]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[4]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[4]._peek bit +void(fwd_in_poly_L0_stream0[4]._.empty()); +void(fwd_in_poly_L0_stream0[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[5]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[5]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[5]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[5]._peek bit +void(fwd_in_poly_L0_stream0[5]._.empty()); +void(fwd_in_poly_L0_stream0[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[6]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[6]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[6]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[6]._peek bit +void(fwd_in_poly_L0_stream0[6]._.empty()); +void(fwd_in_poly_L0_stream0[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[7]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[7]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[7]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[7]._peek bit +void(fwd_in_poly_L0_stream0[7]._.empty()); +void(fwd_in_poly_L0_stream0[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[8]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[8]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[8]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[8]._peek bit +void(fwd_in_poly_L0_stream0[8]._.empty()); +void(fwd_in_poly_L0_stream0[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[9]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[9]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[9]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[9]._peek bit +void(fwd_in_poly_L0_stream0[9]._.empty()); +void(fwd_in_poly_L0_stream0[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[10]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[10]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[10]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[10]._peek bit +void(fwd_in_poly_L0_stream0[10]._.empty()); +void(fwd_in_poly_L0_stream0[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[11]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[11]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[11]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[11]._peek bit +void(fwd_in_poly_L0_stream0[11]._.empty()); +void(fwd_in_poly_L0_stream0[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[12]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[12]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[12]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[12]._peek bit +void(fwd_in_poly_L0_stream0[12]._.empty()); +void(fwd_in_poly_L0_stream0[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[13]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[13]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[13]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[13]._peek bit +void(fwd_in_poly_L0_stream0[13]._.empty()); +void(fwd_in_poly_L0_stream0[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[14]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[14]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[14]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[14]._peek bit +void(fwd_in_poly_L0_stream0[14]._.empty()); +void(fwd_in_poly_L0_stream0[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[15]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[15]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream0[15]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream0[15]._peek bit +void(fwd_in_poly_L0_stream0[15]._.empty()); +void(fwd_in_poly_L0_stream0[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_in_poly_L0_stream1 +#pragma HLS array_partition variable = fwd_in_poly_L0_stream1 complete +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[0]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[0]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[0]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[0]._peek bit +void(fwd_in_poly_L0_stream1[0]._.empty()); +void(fwd_in_poly_L0_stream1[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[1]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[1]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[1]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[1]._peek bit +void(fwd_in_poly_L0_stream1[1]._.empty()); +void(fwd_in_poly_L0_stream1[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[2]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[2]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[2]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[2]._peek bit +void(fwd_in_poly_L0_stream1[2]._.empty()); +void(fwd_in_poly_L0_stream1[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[3]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[3]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[3]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[3]._peek bit +void(fwd_in_poly_L0_stream1[3]._.empty()); +void(fwd_in_poly_L0_stream1[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[4]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[4]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[4]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[4]._peek bit +void(fwd_in_poly_L0_stream1[4]._.empty()); +void(fwd_in_poly_L0_stream1[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[5]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[5]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[5]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[5]._peek bit +void(fwd_in_poly_L0_stream1[5]._.empty()); +void(fwd_in_poly_L0_stream1[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[6]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[6]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[6]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[6]._peek bit +void(fwd_in_poly_L0_stream1[6]._.empty()); +void(fwd_in_poly_L0_stream1[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[7]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[7]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[7]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[7]._peek bit +void(fwd_in_poly_L0_stream1[7]._.empty()); +void(fwd_in_poly_L0_stream1[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[8]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[8]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[8]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[8]._peek bit +void(fwd_in_poly_L0_stream1[8]._.empty()); +void(fwd_in_poly_L0_stream1[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[9]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[9]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[9]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[9]._peek bit +void(fwd_in_poly_L0_stream1[9]._.empty()); +void(fwd_in_poly_L0_stream1[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[10]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[10]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[10]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[10]._peek bit +void(fwd_in_poly_L0_stream1[10]._.empty()); +void(fwd_in_poly_L0_stream1[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[11]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[11]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[11]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[11]._peek bit +void(fwd_in_poly_L0_stream1[11]._.empty()); +void(fwd_in_poly_L0_stream1[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[12]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[12]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[12]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[12]._peek bit +void(fwd_in_poly_L0_stream1[12]._.empty()); +void(fwd_in_poly_L0_stream1[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[13]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[13]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[13]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[13]._peek bit +void(fwd_in_poly_L0_stream1[13]._.empty()); +void(fwd_in_poly_L0_stream1[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[14]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[14]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[14]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[14]._peek bit +void(fwd_in_poly_L0_stream1[14]._.empty()); +void(fwd_in_poly_L0_stream1[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[15]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[15]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream1[15]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream1[15]._peek bit +void(fwd_in_poly_L0_stream1[15]._.empty()); +void(fwd_in_poly_L0_stream1[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_in_poly_L0_stream2 +#pragma HLS array_partition variable = fwd_in_poly_L0_stream2 complete +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[0]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[0]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[0]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[0]._peek bit +void(fwd_in_poly_L0_stream2[0]._.empty()); +void(fwd_in_poly_L0_stream2[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[1]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[1]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[1]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[1]._peek bit +void(fwd_in_poly_L0_stream2[1]._.empty()); +void(fwd_in_poly_L0_stream2[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[2]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[2]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[2]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[2]._peek bit +void(fwd_in_poly_L0_stream2[2]._.empty()); +void(fwd_in_poly_L0_stream2[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[3]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[3]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[3]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[3]._peek bit +void(fwd_in_poly_L0_stream2[3]._.empty()); +void(fwd_in_poly_L0_stream2[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[4]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[4]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[4]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[4]._peek bit +void(fwd_in_poly_L0_stream2[4]._.empty()); +void(fwd_in_poly_L0_stream2[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[5]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[5]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[5]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[5]._peek bit +void(fwd_in_poly_L0_stream2[5]._.empty()); +void(fwd_in_poly_L0_stream2[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[6]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[6]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[6]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[6]._peek bit +void(fwd_in_poly_L0_stream2[6]._.empty()); +void(fwd_in_poly_L0_stream2[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[7]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[7]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[7]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[7]._peek bit +void(fwd_in_poly_L0_stream2[7]._.empty()); +void(fwd_in_poly_L0_stream2[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[8]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[8]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[8]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[8]._peek bit +void(fwd_in_poly_L0_stream2[8]._.empty()); +void(fwd_in_poly_L0_stream2[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[9]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[9]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[9]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[9]._peek bit +void(fwd_in_poly_L0_stream2[9]._.empty()); +void(fwd_in_poly_L0_stream2[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[10]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[10]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[10]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[10]._peek bit +void(fwd_in_poly_L0_stream2[10]._.empty()); +void(fwd_in_poly_L0_stream2[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[11]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[11]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[11]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[11]._peek bit +void(fwd_in_poly_L0_stream2[11]._.empty()); +void(fwd_in_poly_L0_stream2[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[12]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[12]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[12]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[12]._peek bit +void(fwd_in_poly_L0_stream2[12]._.empty()); +void(fwd_in_poly_L0_stream2[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[13]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[13]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[13]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[13]._peek bit +void(fwd_in_poly_L0_stream2[13]._.empty()); +void(fwd_in_poly_L0_stream2[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[14]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[14]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[14]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[14]._peek bit +void(fwd_in_poly_L0_stream2[14]._.empty()); +void(fwd_in_poly_L0_stream2[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[15]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[15]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream2[15]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream2[15]._peek bit +void(fwd_in_poly_L0_stream2[15]._.empty()); +void(fwd_in_poly_L0_stream2[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_in_poly_L0_stream3 +#pragma HLS array_partition variable = fwd_in_poly_L0_stream3 complete +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[0]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[0]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[0]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[0]._peek bit +void(fwd_in_poly_L0_stream3[0]._.empty()); +void(fwd_in_poly_L0_stream3[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[1]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[1]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[1]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[1]._peek bit +void(fwd_in_poly_L0_stream3[1]._.empty()); +void(fwd_in_poly_L0_stream3[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[2]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[2]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[2]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[2]._peek bit +void(fwd_in_poly_L0_stream3[2]._.empty()); +void(fwd_in_poly_L0_stream3[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[3]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[3]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[3]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[3]._peek bit +void(fwd_in_poly_L0_stream3[3]._.empty()); +void(fwd_in_poly_L0_stream3[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[4]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[4]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[4]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[4]._peek bit +void(fwd_in_poly_L0_stream3[4]._.empty()); +void(fwd_in_poly_L0_stream3[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[5]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[5]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[5]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[5]._peek bit +void(fwd_in_poly_L0_stream3[5]._.empty()); +void(fwd_in_poly_L0_stream3[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[6]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[6]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[6]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[6]._peek bit +void(fwd_in_poly_L0_stream3[6]._.empty()); +void(fwd_in_poly_L0_stream3[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[7]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[7]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[7]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[7]._peek bit +void(fwd_in_poly_L0_stream3[7]._.empty()); +void(fwd_in_poly_L0_stream3[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[8]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[8]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[8]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[8]._peek bit +void(fwd_in_poly_L0_stream3[8]._.empty()); +void(fwd_in_poly_L0_stream3[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[9]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[9]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[9]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[9]._peek bit +void(fwd_in_poly_L0_stream3[9]._.empty()); +void(fwd_in_poly_L0_stream3[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[10]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[10]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[10]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[10]._peek bit +void(fwd_in_poly_L0_stream3[10]._.empty()); +void(fwd_in_poly_L0_stream3[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[11]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[11]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[11]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[11]._peek bit +void(fwd_in_poly_L0_stream3[11]._.empty()); +void(fwd_in_poly_L0_stream3[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[12]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[12]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[12]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[12]._peek bit +void(fwd_in_poly_L0_stream3[12]._.empty()); +void(fwd_in_poly_L0_stream3[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[13]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[13]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[13]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[13]._peek bit +void(fwd_in_poly_L0_stream3[13]._.empty()); +void(fwd_in_poly_L0_stream3[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[14]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[14]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[14]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[14]._peek bit +void(fwd_in_poly_L0_stream3[14]._.empty()); +void(fwd_in_poly_L0_stream3[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[15]._ +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[15]._ bit +#pragma HLS interface ap_fifo port = fwd_in_poly_L0_stream3[15]._peek +#pragma HLS aggregate variable = fwd_in_poly_L0_stream3[15]._peek bit +void(fwd_in_poly_L0_stream3[15]._.empty()); +void(fwd_in_poly_L0_stream3[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_out_poly_L0_stream0 +#pragma HLS array_partition variable = inv_out_poly_L0_stream0 complete +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[0]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[0]._ bit +void(inv_out_poly_L0_stream0[0]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[1]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[1]._ bit +void(inv_out_poly_L0_stream0[1]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[2]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[2]._ bit +void(inv_out_poly_L0_stream0[2]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[3]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[3]._ bit +void(inv_out_poly_L0_stream0[3]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[4]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[4]._ bit +void(inv_out_poly_L0_stream0[4]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[5]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[5]._ bit +void(inv_out_poly_L0_stream0[5]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[6]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[6]._ bit +void(inv_out_poly_L0_stream0[6]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[7]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[7]._ bit +void(inv_out_poly_L0_stream0[7]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[8]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[8]._ bit +void(inv_out_poly_L0_stream0[8]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[9]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[9]._ bit +void(inv_out_poly_L0_stream0[9]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[10]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[10]._ bit +void(inv_out_poly_L0_stream0[10]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[11]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[11]._ bit +void(inv_out_poly_L0_stream0[11]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[12]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[12]._ bit +void(inv_out_poly_L0_stream0[12]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[13]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[13]._ bit +void(inv_out_poly_L0_stream0[13]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[14]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[14]._ bit +void(inv_out_poly_L0_stream0[14]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream0[15]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream0[15]._ bit +void(inv_out_poly_L0_stream0[15]._.full()); + +#pragma HLS disaggregate variable = inv_out_poly_L0_stream1 +#pragma HLS array_partition variable = inv_out_poly_L0_stream1 complete +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[0]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[0]._ bit +void(inv_out_poly_L0_stream1[0]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[1]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[1]._ bit +void(inv_out_poly_L0_stream1[1]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[2]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[2]._ bit +void(inv_out_poly_L0_stream1[2]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[3]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[3]._ bit +void(inv_out_poly_L0_stream1[3]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[4]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[4]._ bit +void(inv_out_poly_L0_stream1[4]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[5]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[5]._ bit +void(inv_out_poly_L0_stream1[5]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[6]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[6]._ bit +void(inv_out_poly_L0_stream1[6]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[7]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[7]._ bit +void(inv_out_poly_L0_stream1[7]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[8]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[8]._ bit +void(inv_out_poly_L0_stream1[8]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[9]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[9]._ bit +void(inv_out_poly_L0_stream1[9]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[10]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[10]._ bit +void(inv_out_poly_L0_stream1[10]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[11]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[11]._ bit +void(inv_out_poly_L0_stream1[11]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[12]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[12]._ bit +void(inv_out_poly_L0_stream1[12]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[13]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[13]._ bit +void(inv_out_poly_L0_stream1[13]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[14]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[14]._ bit +void(inv_out_poly_L0_stream1[14]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream1[15]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream1[15]._ bit +void(inv_out_poly_L0_stream1[15]._.full()); + +#pragma HLS disaggregate variable = inv_out_poly_L0_stream2 +#pragma HLS array_partition variable = inv_out_poly_L0_stream2 complete +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[0]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[0]._ bit +void(inv_out_poly_L0_stream2[0]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[1]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[1]._ bit +void(inv_out_poly_L0_stream2[1]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[2]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[2]._ bit +void(inv_out_poly_L0_stream2[2]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[3]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[3]._ bit +void(inv_out_poly_L0_stream2[3]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[4]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[4]._ bit +void(inv_out_poly_L0_stream2[4]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[5]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[5]._ bit +void(inv_out_poly_L0_stream2[5]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[6]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[6]._ bit +void(inv_out_poly_L0_stream2[6]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[7]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[7]._ bit +void(inv_out_poly_L0_stream2[7]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[8]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[8]._ bit +void(inv_out_poly_L0_stream2[8]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[9]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[9]._ bit +void(inv_out_poly_L0_stream2[9]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[10]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[10]._ bit +void(inv_out_poly_L0_stream2[10]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[11]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[11]._ bit +void(inv_out_poly_L0_stream2[11]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[12]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[12]._ bit +void(inv_out_poly_L0_stream2[12]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[13]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[13]._ bit +void(inv_out_poly_L0_stream2[13]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[14]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[14]._ bit +void(inv_out_poly_L0_stream2[14]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream2[15]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream2[15]._ bit +void(inv_out_poly_L0_stream2[15]._.full()); + +#pragma HLS disaggregate variable = inv_out_poly_L0_stream3 +#pragma HLS array_partition variable = inv_out_poly_L0_stream3 complete +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[0]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[0]._ bit +void(inv_out_poly_L0_stream3[0]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[1]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[1]._ bit +void(inv_out_poly_L0_stream3[1]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[2]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[2]._ bit +void(inv_out_poly_L0_stream3[2]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[3]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[3]._ bit +void(inv_out_poly_L0_stream3[3]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[4]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[4]._ bit +void(inv_out_poly_L0_stream3[4]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[5]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[5]._ bit +void(inv_out_poly_L0_stream3[5]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[6]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[6]._ bit +void(inv_out_poly_L0_stream3[6]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[7]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[7]._ bit +void(inv_out_poly_L0_stream3[7]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[8]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[8]._ bit +void(inv_out_poly_L0_stream3[8]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[9]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[9]._ bit +void(inv_out_poly_L0_stream3[9]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[10]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[10]._ bit +void(inv_out_poly_L0_stream3[10]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[11]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[11]._ bit +void(inv_out_poly_L0_stream3[11]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[12]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[12]._ bit +void(inv_out_poly_L0_stream3[12]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[13]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[13]._ bit +void(inv_out_poly_L0_stream3[13]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[14]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[14]._ bit +void(inv_out_poly_L0_stream3[14]._.full()); +#pragma HLS interface ap_fifo port = inv_out_poly_L0_stream3[15]._ +#pragma HLS aggregate variable = inv_out_poly_L0_stream3[15]._ bit +void(inv_out_poly_L0_stream3[15]._.full()); + + + + + VAR_TYPE_16 totalDataCount = (N/V_TOTAL_DATA)*(SEQ_BUG_PER_PARA_LIMB_POLY_PORT); + POLY_WIDE_DATA val; + WORD smallData; + + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + LOAD_STORE_POLY_0:for (int i_req = 0, i_resp=0; i_resp < totalDataCount;) { + #pragma HLS PIPELINE II=1 + + if(!direction){ //inv load + if( ( i_req < totalDataCount ) && (poly_mmap.read_addr.try_write(i_req)) ){ + i_req++; + } + + if( !poly_mmap.read_data.empty() ){ + POLY_WIDE_DATA val = poly_mmap.read_data.read(nullptr); + + VAR_TYPE_16 seq_group_idx = i_resp/(N/V_TOTAL_DATA); + + for(int j=0; j<(2*V_BUG_SIZE); j++){ + #pragma HLS UNROLL + WORD smallVal = (WORD)(val & ((((POLY_WIDE_DATA)1)<>= DRAM_WORD_SIZE; + } + + i_resp++; + } + } + else{ //fwd store + VAR_TYPE_16 seq_group_idx = i_req/(N/V_TOTAL_DATA); + + val = 0; + + bool inpStreamNotEmpty; + if( seq_group_idx==0 ){ + inpStreamNotEmpty = ( !fwd_in_poly_L0_stream0[0].empty() ); + } + else if( seq_group_idx==1 ){ + inpStreamNotEmpty = ( !fwd_in_poly_L0_stream1[0].empty() ); + } + else if( seq_group_idx==2 ){ + inpStreamNotEmpty = ( !fwd_in_poly_L0_stream2[0].empty() ); + } + else{ + inpStreamNotEmpty = ( !fwd_in_poly_L0_stream3[0].empty() ); + } + + for(int j=1; j<(2*V_BUG_SIZE); j++){ + if( seq_group_idx==0 ){ + inpStreamNotEmpty &= ( !fwd_in_poly_L0_stream0[j].empty() ); + } + else if( seq_group_idx==1 ){ + inpStreamNotEmpty &= ( !fwd_in_poly_L0_stream1[j].empty() ); + } + else if( seq_group_idx==2 ){ + inpStreamNotEmpty &= ( !fwd_in_poly_L0_stream2[j].empty() ); + } + else{ + inpStreamNotEmpty &= ( !fwd_in_poly_L0_stream3[j].empty() ); + } + } + + if( ( i_req < (totalDataCount) ) && ( inpStreamNotEmpty ) ){ + + //read FIFOs + for(int j=(2*V_BUG_SIZE)-1; j>=0; j--){ + #pragma HLS UNROLL + val <<= DRAM_WORD_SIZE; + if( seq_group_idx==0 ){ + smallData = fwd_in_poly_L0_stream0[j].read(); + } + else if( seq_group_idx==1 ){ + smallData = fwd_in_poly_L0_stream1[j].read(); + } + else if( seq_group_idx==2 ){ + smallData = fwd_in_poly_L0_stream2[j].read(); + } + else{ + smallData = fwd_in_poly_L0_stream3[j].read(); + } + val |= (POLY_WIDE_DATA)(smallData); + } + + //write mem + poly_mmap.write_addr.write(i_req); + poly_mmap.write_data.write(val); + i_req++; + } + + if( !poly_mmap.write_resp.empty() ){ + i_resp += unsigned(poly_mmap.write_resp.read(nullptr)) + 1; + } + } + } + } + #ifndef __SYNTHESIS__ + if(direction){ + printf("[fwd_store_inv_load_poly]: Polynomial storing done\n"); + } + else{ + printf("[fwd_store_inv_load_poly]: Polynomial loading done\n"); + } + #endif +} + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/fwd_store_inv_load_poly_1_limbs/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/input_selector_single.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/input_selector_single.cpp new file mode 100644 index 000000000000..23f1ccbcce77 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/input_selector_single.cpp @@ -0,0 +1,565 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = fwd_valFromLoad_0 +#pragma HLS interface ap_fifo port = fwd_valFromLoad_0._ +#pragma HLS aggregate variable = fwd_valFromLoad_0._ bit +#pragma HLS interface ap_fifo port = fwd_valFromLoad_0._peek +#pragma HLS aggregate variable = fwd_valFromLoad_0._peek bit +void(fwd_valFromLoad_0._.empty()); +void(fwd_valFromLoad_0._peek.empty()); + +#pragma HLS disaggregate variable = fwd_valFromShuf +#pragma HLS interface ap_fifo port = fwd_valFromShuf._ +#pragma HLS aggregate variable = fwd_valFromShuf._ bit +#pragma HLS interface ap_fifo port = fwd_valFromShuf._peek +#pragma HLS aggregate variable = fwd_valFromShuf._peek bit +void(fwd_valFromShuf._.empty()); +void(fwd_valFromShuf._peek.empty()); + +#pragma HLS disaggregate variable = inv_valFromBU +#pragma HLS interface ap_fifo port = inv_valFromBU._ +#pragma HLS aggregate variable = inv_valFromBU._ bit +#pragma HLS interface ap_fifo port = inv_valFromBU._peek +#pragma HLS aggregate variable = inv_valFromBU._peek bit +void(inv_valFromBU._.empty()); +void(inv_valFromBU._peek.empty()); + +#pragma HLS disaggregate variable = fwd_valToBU +#pragma HLS interface ap_fifo port = fwd_valToBU._ +#pragma HLS aggregate variable = fwd_valToBU._ bit +void(fwd_valToBU._.full()); + +#pragma HLS disaggregate variable = inv_valToShuf +#pragma HLS interface ap_fifo port = inv_valToShuf._ +#pragma HLS aggregate variable = inv_valToShuf._ bit +void(inv_valToShuf._.full()); + +#pragma HLS disaggregate variable = inv_valToStore_0 +#pragma HLS interface ap_fifo port = inv_valToStore_0._ +#pragma HLS aggregate variable = inv_valToStore_0._ bit +void(inv_valToStore_0._.full()); + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 dataFlowIterLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + + WORD val; + + bool inpStreamNotEmpty; + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + for(VAR_TYPE_8 dataFlowIter=0; dataFlowIter& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/input_selector_single/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/output_slector_single.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/output_slector_single.cpp new file mode 100644 index 000000000000..8296f3fee032 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/cpp/output_slector_single.cpp @@ -0,0 +1,566 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = fwd_valFromBU +#pragma HLS interface ap_fifo port = fwd_valFromBU._ +#pragma HLS aggregate variable = fwd_valFromBU._ bit +#pragma HLS interface ap_fifo port = fwd_valFromBU._peek +#pragma HLS aggregate variable = fwd_valFromBU._peek bit +void(fwd_valFromBU._.empty()); +void(fwd_valFromBU._peek.empty()); + +#pragma HLS disaggregate variable = inv_valFromLoad_0 +#pragma HLS interface ap_fifo port = inv_valFromLoad_0._ +#pragma HLS aggregate variable = inv_valFromLoad_0._ bit +#pragma HLS interface ap_fifo port = inv_valFromLoad_0._peek +#pragma HLS aggregate variable = inv_valFromLoad_0._peek bit +void(inv_valFromLoad_0._.empty()); +void(inv_valFromLoad_0._peek.empty()); + +#pragma HLS disaggregate variable = inv_valFromShuf +#pragma HLS interface ap_fifo port = inv_valFromShuf._ +#pragma HLS aggregate variable = inv_valFromShuf._ bit +#pragma HLS interface ap_fifo port = inv_valFromShuf._peek +#pragma HLS aggregate variable = inv_valFromShuf._peek bit +void(inv_valFromShuf._.empty()); +void(inv_valFromShuf._peek.empty()); + +#pragma HLS disaggregate variable = fwd_valToShuf +#pragma HLS interface ap_fifo port = fwd_valToShuf._ +#pragma HLS aggregate variable = fwd_valToShuf._ bit +void(fwd_valToShuf._.full()); + +#pragma HLS disaggregate variable = fwd_valToStore_0 +#pragma HLS interface ap_fifo port = fwd_valToStore_0._ +#pragma HLS aggregate variable = fwd_valToStore_0._ bit +void(fwd_valToStore_0._.full()); + +#pragma HLS disaggregate variable = inv_valToBU +#pragma HLS interface ap_fifo port = inv_valToBU._ +#pragma HLS aggregate variable = inv_valToBU._ bit +void(inv_valToBU._.full()); + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 dataFlowIterLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ); + WORD val; + + bool inpStreamNotEmpty; + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + for(VAR_TYPE_8 dataFlowIter=0; dataFlowIter& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/output_slector_single/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/shuffler_buf.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/shuffler_buf.cpp new file mode 100644 index 000000000000..ff9f7942340e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/cpp/shuffler_buf.cpp @@ -0,0 +1,989 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter){ +#pragma HLS disaggregate variable = fwd_inVal +#pragma HLS array_partition variable = fwd_inVal complete +#pragma HLS interface ap_fifo port = fwd_inVal[0]._ +#pragma HLS aggregate variable = fwd_inVal[0]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[0]._peek +#pragma HLS aggregate variable = fwd_inVal[0]._peek bit +void(fwd_inVal[0]._.empty()); +void(fwd_inVal[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[1]._ +#pragma HLS aggregate variable = fwd_inVal[1]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[1]._peek +#pragma HLS aggregate variable = fwd_inVal[1]._peek bit +void(fwd_inVal[1]._.empty()); +void(fwd_inVal[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[2]._ +#pragma HLS aggregate variable = fwd_inVal[2]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[2]._peek +#pragma HLS aggregate variable = fwd_inVal[2]._peek bit +void(fwd_inVal[2]._.empty()); +void(fwd_inVal[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[3]._ +#pragma HLS aggregate variable = fwd_inVal[3]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[3]._peek +#pragma HLS aggregate variable = fwd_inVal[3]._peek bit +void(fwd_inVal[3]._.empty()); +void(fwd_inVal[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[4]._ +#pragma HLS aggregate variable = fwd_inVal[4]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[4]._peek +#pragma HLS aggregate variable = fwd_inVal[4]._peek bit +void(fwd_inVal[4]._.empty()); +void(fwd_inVal[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[5]._ +#pragma HLS aggregate variable = fwd_inVal[5]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[5]._peek +#pragma HLS aggregate variable = fwd_inVal[5]._peek bit +void(fwd_inVal[5]._.empty()); +void(fwd_inVal[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[6]._ +#pragma HLS aggregate variable = fwd_inVal[6]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[6]._peek +#pragma HLS aggregate variable = fwd_inVal[6]._peek bit +void(fwd_inVal[6]._.empty()); +void(fwd_inVal[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[7]._ +#pragma HLS aggregate variable = fwd_inVal[7]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[7]._peek +#pragma HLS aggregate variable = fwd_inVal[7]._peek bit +void(fwd_inVal[7]._.empty()); +void(fwd_inVal[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[8]._ +#pragma HLS aggregate variable = fwd_inVal[8]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[8]._peek +#pragma HLS aggregate variable = fwd_inVal[8]._peek bit +void(fwd_inVal[8]._.empty()); +void(fwd_inVal[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[9]._ +#pragma HLS aggregate variable = fwd_inVal[9]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[9]._peek +#pragma HLS aggregate variable = fwd_inVal[9]._peek bit +void(fwd_inVal[9]._.empty()); +void(fwd_inVal[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[10]._ +#pragma HLS aggregate variable = fwd_inVal[10]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[10]._peek +#pragma HLS aggregate variable = fwd_inVal[10]._peek bit +void(fwd_inVal[10]._.empty()); +void(fwd_inVal[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[11]._ +#pragma HLS aggregate variable = fwd_inVal[11]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[11]._peek +#pragma HLS aggregate variable = fwd_inVal[11]._peek bit +void(fwd_inVal[11]._.empty()); +void(fwd_inVal[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[12]._ +#pragma HLS aggregate variable = fwd_inVal[12]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[12]._peek +#pragma HLS aggregate variable = fwd_inVal[12]._peek bit +void(fwd_inVal[12]._.empty()); +void(fwd_inVal[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[13]._ +#pragma HLS aggregate variable = fwd_inVal[13]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[13]._peek +#pragma HLS aggregate variable = fwd_inVal[13]._peek bit +void(fwd_inVal[13]._.empty()); +void(fwd_inVal[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[14]._ +#pragma HLS aggregate variable = fwd_inVal[14]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[14]._peek +#pragma HLS aggregate variable = fwd_inVal[14]._peek bit +void(fwd_inVal[14]._.empty()); +void(fwd_inVal[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[15]._ +#pragma HLS aggregate variable = fwd_inVal[15]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[15]._peek +#pragma HLS aggregate variable = fwd_inVal[15]._peek bit +void(fwd_inVal[15]._.empty()); +void(fwd_inVal[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal +#pragma HLS array_partition variable = inv_inVal complete +#pragma HLS interface ap_fifo port = inv_inVal[0]._ +#pragma HLS aggregate variable = inv_inVal[0]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[0]._peek +#pragma HLS aggregate variable = inv_inVal[0]._peek bit +void(inv_inVal[0]._.empty()); +void(inv_inVal[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[1]._ +#pragma HLS aggregate variable = inv_inVal[1]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[1]._peek +#pragma HLS aggregate variable = inv_inVal[1]._peek bit +void(inv_inVal[1]._.empty()); +void(inv_inVal[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[2]._ +#pragma HLS aggregate variable = inv_inVal[2]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[2]._peek +#pragma HLS aggregate variable = inv_inVal[2]._peek bit +void(inv_inVal[2]._.empty()); +void(inv_inVal[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[3]._ +#pragma HLS aggregate variable = inv_inVal[3]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[3]._peek +#pragma HLS aggregate variable = inv_inVal[3]._peek bit +void(inv_inVal[3]._.empty()); +void(inv_inVal[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[4]._ +#pragma HLS aggregate variable = inv_inVal[4]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[4]._peek +#pragma HLS aggregate variable = inv_inVal[4]._peek bit +void(inv_inVal[4]._.empty()); +void(inv_inVal[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[5]._ +#pragma HLS aggregate variable = inv_inVal[5]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[5]._peek +#pragma HLS aggregate variable = inv_inVal[5]._peek bit +void(inv_inVal[5]._.empty()); +void(inv_inVal[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[6]._ +#pragma HLS aggregate variable = inv_inVal[6]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[6]._peek +#pragma HLS aggregate variable = inv_inVal[6]._peek bit +void(inv_inVal[6]._.empty()); +void(inv_inVal[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[7]._ +#pragma HLS aggregate variable = inv_inVal[7]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[7]._peek +#pragma HLS aggregate variable = inv_inVal[7]._peek bit +void(inv_inVal[7]._.empty()); +void(inv_inVal[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[8]._ +#pragma HLS aggregate variable = inv_inVal[8]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[8]._peek +#pragma HLS aggregate variable = inv_inVal[8]._peek bit +void(inv_inVal[8]._.empty()); +void(inv_inVal[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[9]._ +#pragma HLS aggregate variable = inv_inVal[9]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[9]._peek +#pragma HLS aggregate variable = inv_inVal[9]._peek bit +void(inv_inVal[9]._.empty()); +void(inv_inVal[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[10]._ +#pragma HLS aggregate variable = inv_inVal[10]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[10]._peek +#pragma HLS aggregate variable = inv_inVal[10]._peek bit +void(inv_inVal[10]._.empty()); +void(inv_inVal[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[11]._ +#pragma HLS aggregate variable = inv_inVal[11]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[11]._peek +#pragma HLS aggregate variable = inv_inVal[11]._peek bit +void(inv_inVal[11]._.empty()); +void(inv_inVal[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[12]._ +#pragma HLS aggregate variable = inv_inVal[12]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[12]._peek +#pragma HLS aggregate variable = inv_inVal[12]._peek bit +void(inv_inVal[12]._.empty()); +void(inv_inVal[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[13]._ +#pragma HLS aggregate variable = inv_inVal[13]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[13]._peek +#pragma HLS aggregate variable = inv_inVal[13]._peek bit +void(inv_inVal[13]._.empty()); +void(inv_inVal[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[14]._ +#pragma HLS aggregate variable = inv_inVal[14]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[14]._peek +#pragma HLS aggregate variable = inv_inVal[14]._peek bit +void(inv_inVal[14]._.empty()); +void(inv_inVal[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[15]._ +#pragma HLS aggregate variable = inv_inVal[15]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[15]._peek +#pragma HLS aggregate variable = inv_inVal[15]._peek bit +void(inv_inVal[15]._.empty()); +void(inv_inVal[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_outVal +#pragma HLS array_partition variable = fwd_outVal complete +#pragma HLS interface ap_fifo port = fwd_outVal[0]._ +#pragma HLS aggregate variable = fwd_outVal[0]._ bit +void(fwd_outVal[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[1]._ +#pragma HLS aggregate variable = fwd_outVal[1]._ bit +void(fwd_outVal[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[2]._ +#pragma HLS aggregate variable = fwd_outVal[2]._ bit +void(fwd_outVal[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[3]._ +#pragma HLS aggregate variable = fwd_outVal[3]._ bit +void(fwd_outVal[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[4]._ +#pragma HLS aggregate variable = fwd_outVal[4]._ bit +void(fwd_outVal[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[5]._ +#pragma HLS aggregate variable = fwd_outVal[5]._ bit +void(fwd_outVal[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[6]._ +#pragma HLS aggregate variable = fwd_outVal[6]._ bit +void(fwd_outVal[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[7]._ +#pragma HLS aggregate variable = fwd_outVal[7]._ bit +void(fwd_outVal[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[8]._ +#pragma HLS aggregate variable = fwd_outVal[8]._ bit +void(fwd_outVal[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[9]._ +#pragma HLS aggregate variable = fwd_outVal[9]._ bit +void(fwd_outVal[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[10]._ +#pragma HLS aggregate variable = fwd_outVal[10]._ bit +void(fwd_outVal[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[11]._ +#pragma HLS aggregate variable = fwd_outVal[11]._ bit +void(fwd_outVal[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[12]._ +#pragma HLS aggregate variable = fwd_outVal[12]._ bit +void(fwd_outVal[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[13]._ +#pragma HLS aggregate variable = fwd_outVal[13]._ bit +void(fwd_outVal[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[14]._ +#pragma HLS aggregate variable = fwd_outVal[14]._ bit +void(fwd_outVal[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[15]._ +#pragma HLS aggregate variable = fwd_outVal[15]._ bit +void(fwd_outVal[15]._.full()); + +#pragma HLS disaggregate variable = inv_outVal +#pragma HLS array_partition variable = inv_outVal complete +#pragma HLS interface ap_fifo port = inv_outVal[0]._ +#pragma HLS aggregate variable = inv_outVal[0]._ bit +void(inv_outVal[0]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[1]._ +#pragma HLS aggregate variable = inv_outVal[1]._ bit +void(inv_outVal[1]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[2]._ +#pragma HLS aggregate variable = inv_outVal[2]._ bit +void(inv_outVal[2]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[3]._ +#pragma HLS aggregate variable = inv_outVal[3]._ bit +void(inv_outVal[3]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[4]._ +#pragma HLS aggregate variable = inv_outVal[4]._ bit +void(inv_outVal[4]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[5]._ +#pragma HLS aggregate variable = inv_outVal[5]._ bit +void(inv_outVal[5]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[6]._ +#pragma HLS aggregate variable = inv_outVal[6]._ bit +void(inv_outVal[6]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[7]._ +#pragma HLS aggregate variable = inv_outVal[7]._ bit +void(inv_outVal[7]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[8]._ +#pragma HLS aggregate variable = inv_outVal[8]._ bit +void(inv_outVal[8]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[9]._ +#pragma HLS aggregate variable = inv_outVal[9]._ bit +void(inv_outVal[9]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[10]._ +#pragma HLS aggregate variable = inv_outVal[10]._ bit +void(inv_outVal[10]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[11]._ +#pragma HLS aggregate variable = inv_outVal[11]._ bit +void(inv_outVal[11]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[12]._ +#pragma HLS aggregate variable = inv_outVal[12]._ bit +void(inv_outVal[12]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[13]._ +#pragma HLS aggregate variable = inv_outVal[13]._ bit +void(inv_outVal[13]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[14]._ +#pragma HLS aggregate variable = inv_outVal[14]._ bit +void(inv_outVal[14]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[15]._ +#pragma HLS aggregate variable = inv_outVal[15]._ bit +void(inv_outVal[15]._.full()); + + + + + + WORD poly_buf[2*V_BUG_SIZE][2*SINGLE_LIMB_BUF_SIZE]; + #pragma HLS bind_storage variable=poly_buf type=RAM_S2P impl=BRAM latency=1 + #pragma HLS array_partition variable=poly_buf type=complete dim=1 + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_16 shuffleLimit = (VAR_TYPE_32)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ) - 1; + + VAR_TYPE_16 max_data_offset = (V_BUG_SIZE*2); + VAR_TYPE_16 receiveCount[2]; + VAR_TYPE_16 sendCount[2]; + + //==== Auto generated variables start ====// + VAR_TYPE_16 log_shift_freq_table[shuffleLimit] = {0, 2}; + VAR_TYPE_16 log_mini_shift_reset_freq_table[shuffleLimit] = {0, 0}; + VAR_TYPE_16 log_mini_shift_amount_table[shuffleLimit] = {0, 0}; + VAR_TYPE_16 log_max_buf_offset_table[shuffleLimit] = {4, 4}; + VAR_TYPE_16 shift_counts_table[shuffleLimit] = {2, 0}; + VAR_TYPE_16 poly_group_line_offset_num_line_table[shuffleLimit] = {16, 16}; + VAR_TYPE_16 log_poly_group_total_num_line_table[shuffleLimit] = {2, 6}; + VAR_TYPE_16 log_out_data_cycles_per_bufGrp_table[shuffleLimit] = {2, 6}; + VAR_TYPE_16 total_lines_in_group_mask_table[shuffleLimit] = {15, 63}; + + #pragma HLS array_partition variable=log_shift_freq_table type=complete dim=0 + #pragma HLS array_partition variable=log_mini_shift_reset_freq_table type=complete dim=0 + #pragma HLS array_partition variable=log_mini_shift_amount_table type=complete dim=0 + #pragma HLS array_partition variable=log_max_buf_offset_table type=complete dim=0 + #pragma HLS array_partition variable=shift_counts_table type=complete dim=0 + #pragma HLS array_partition variable=poly_group_line_offset_num_line_table type=complete dim=0 + #pragma HLS array_partition variable=log_poly_group_total_num_line_table type=complete dim=0 + #pragma HLS array_partition variable=log_out_data_cycles_per_bufGrp_table type=complete dim=0 + #pragma HLS array_partition variable=total_lines_in_group_mask_table type=complete dim=0 + //==== Auto generated variables end ====// + + ITER_LOOP:for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + + for(VAR_TYPE_16 i=0; i<2; i++){ + #pragma HLS UNROLL + receiveCount[i] = 0; + sendCount[i] = 0; + } + + VAR_TYPE_16 non_seq_idx[2*V_BUG_SIZE]; + WORD read_val[2*V_BUG_SIZE]; + bool val_send_success[2*V_BUG_SIZE]; + for(VAR_TYPE_16 i=0; i<2*V_BUG_SIZE; i++){ + val_send_success[i] = false; + } + bool all_val_send_success = true; + VAR_TYPE_16 seq_idx; + + VAR_TYPE_16 write_shuffler_id = 0; + VAR_TYPE_16 read_shuffler_id = 0; + VAR_TYPE_16 inv_write_shuffler_id = shuffleLimit - 1; + VAR_TYPE_16 inv_read_shuffler_id = shuffleLimit - 1; + VAR_TYPE_16 comp_write_shuffler_id = 0; + VAR_TYPE_16 comp_read_shuffler_id = 0; + + VAR_TYPE_16 shuffleCount = 0; + + BUF_COMP:for(; shuffleCount> log_out_data_cycles_per_bufGrp) << (log_poly_group_total_num_line) ) & SINGLE_LIMB_BUF_SIZE_MASK; + VAR_TYPE_16 cycle_start_idx_buffer_id = ( ( non_seq_addr_count >> (log_shift_freq - log_mini_shift_reset_freq) ) << (shift_counts + log_mini_shift_amount ) ) & ( (1<> (shift_counts + log_mini_shift_reset_freq + log_mini_shift_amount)) << log_shift_freq ) + \ + ( ( ( ( local_buf_id + index_offset_based_on_strat_buffer ) % (V_BUG_SIZE*2)) & ( ( 1 << (log_mini_shift_reset_freq + log_mini_shift_amount) ) -1 ) ) >> (log_mini_shift_amount) ) ) & total_lines_in_group_mask ) + \ + (read_idx_iter_offset); + } + + for(VAR_TYPE_16 local_buf_id=0; local_buf_id<2*V_BUG_SIZE; local_buf_id++){ + if(direction){ + read_val[local_buf_id] = poly_buf[local_buf_id][non_seq_idx[local_buf_id]]; + } + else{ + read_val[local_buf_id] = poly_buf[local_buf_id][seq_idx]; + } + } + + if( all_val_send_success && ( (receiveCount[comp_read_shuffler_id%2] >> log_poly_group_total_num_line) > (sendCount[comp_read_shuffler_id%2] >> log_poly_group_total_num_line) ) ){ + all_val_send_success = false; + for(VAR_TYPE_16 local_buf_id=0; local_buf_id<2*V_BUG_SIZE; local_buf_id++){ + #pragma HLS UNROLL + val_send_success[local_buf_id] = false; + } + } + + if(sendCount[comp_read_shuffler_id%2]==dataCount){ + sendCount[comp_read_shuffler_id%2] = 0; + receiveCount[comp_read_shuffler_id%2] = 0; + read_shuffler_id++; + inv_read_shuffler_id--; + shuffleCount++; + } + + //receive + bool inFifoNotEmpty = ( !fwd_inVal[0].empty() ) || ( !inv_inVal[0].empty() ) ; + + for(VAR_TYPE_16 local_buf_id=0; local_buf_id<2*V_BUG_SIZE; local_buf_id++){ + #pragma HLS UNROLL + inFifoNotEmpty &= ( !fwd_inVal[local_buf_id].empty() ) || ( !inv_inVal[local_buf_id].empty() ) ; + } + + if(inFifoNotEmpty){ + for(VAR_TYPE_16 local_buf_id=0; local_buf_id<2*V_BUG_SIZE; local_buf_id++){ + #pragma HLS UNROLL + if(direction){ + poly_buf[local_buf_id][seq_idx] = fwd_inVal[local_buf_id].read(); + } + else{ + poly_buf[local_buf_id][non_seq_idx[local_buf_id]] = inv_inVal[local_buf_id].read(); + } + } + receiveCount[comp_write_shuffler_id%2]++; + } + + if( receiveCount[comp_write_shuffler_id%2] == dataCount ){ //received all the data in this iteration + write_shuffler_id++; + inv_write_shuffler_id = (inv_write_shuffler_id==0) ? (0) : inv_write_shuffler_id-1; + } + + } + } +} + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_buf/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/shuffler_in.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/shuffler_in.cpp new file mode 100644 index 000000000000..184352ee1d13 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/cpp/shuffler_in.cpp @@ -0,0 +1,872 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ){ +#pragma HLS disaggregate variable = fwd_inVal +#pragma HLS array_partition variable = fwd_inVal complete +#pragma HLS interface ap_fifo port = fwd_inVal[0]._ +#pragma HLS aggregate variable = fwd_inVal[0]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[0]._peek +#pragma HLS aggregate variable = fwd_inVal[0]._peek bit +void(fwd_inVal[0]._.empty()); +void(fwd_inVal[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[1]._ +#pragma HLS aggregate variable = fwd_inVal[1]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[1]._peek +#pragma HLS aggregate variable = fwd_inVal[1]._peek bit +void(fwd_inVal[1]._.empty()); +void(fwd_inVal[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[2]._ +#pragma HLS aggregate variable = fwd_inVal[2]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[2]._peek +#pragma HLS aggregate variable = fwd_inVal[2]._peek bit +void(fwd_inVal[2]._.empty()); +void(fwd_inVal[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[3]._ +#pragma HLS aggregate variable = fwd_inVal[3]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[3]._peek +#pragma HLS aggregate variable = fwd_inVal[3]._peek bit +void(fwd_inVal[3]._.empty()); +void(fwd_inVal[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[4]._ +#pragma HLS aggregate variable = fwd_inVal[4]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[4]._peek +#pragma HLS aggregate variable = fwd_inVal[4]._peek bit +void(fwd_inVal[4]._.empty()); +void(fwd_inVal[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[5]._ +#pragma HLS aggregate variable = fwd_inVal[5]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[5]._peek +#pragma HLS aggregate variable = fwd_inVal[5]._peek bit +void(fwd_inVal[5]._.empty()); +void(fwd_inVal[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[6]._ +#pragma HLS aggregate variable = fwd_inVal[6]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[6]._peek +#pragma HLS aggregate variable = fwd_inVal[6]._peek bit +void(fwd_inVal[6]._.empty()); +void(fwd_inVal[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[7]._ +#pragma HLS aggregate variable = fwd_inVal[7]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[7]._peek +#pragma HLS aggregate variable = fwd_inVal[7]._peek bit +void(fwd_inVal[7]._.empty()); +void(fwd_inVal[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[8]._ +#pragma HLS aggregate variable = fwd_inVal[8]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[8]._peek +#pragma HLS aggregate variable = fwd_inVal[8]._peek bit +void(fwd_inVal[8]._.empty()); +void(fwd_inVal[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[9]._ +#pragma HLS aggregate variable = fwd_inVal[9]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[9]._peek +#pragma HLS aggregate variable = fwd_inVal[9]._peek bit +void(fwd_inVal[9]._.empty()); +void(fwd_inVal[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[10]._ +#pragma HLS aggregate variable = fwd_inVal[10]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[10]._peek +#pragma HLS aggregate variable = fwd_inVal[10]._peek bit +void(fwd_inVal[10]._.empty()); +void(fwd_inVal[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[11]._ +#pragma HLS aggregate variable = fwd_inVal[11]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[11]._peek +#pragma HLS aggregate variable = fwd_inVal[11]._peek bit +void(fwd_inVal[11]._.empty()); +void(fwd_inVal[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[12]._ +#pragma HLS aggregate variable = fwd_inVal[12]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[12]._peek +#pragma HLS aggregate variable = fwd_inVal[12]._peek bit +void(fwd_inVal[12]._.empty()); +void(fwd_inVal[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[13]._ +#pragma HLS aggregate variable = fwd_inVal[13]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[13]._peek +#pragma HLS aggregate variable = fwd_inVal[13]._peek bit +void(fwd_inVal[13]._.empty()); +void(fwd_inVal[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[14]._ +#pragma HLS aggregate variable = fwd_inVal[14]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[14]._peek +#pragma HLS aggregate variable = fwd_inVal[14]._peek bit +void(fwd_inVal[14]._.empty()); +void(fwd_inVal[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[15]._ +#pragma HLS aggregate variable = fwd_inVal[15]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[15]._peek +#pragma HLS aggregate variable = fwd_inVal[15]._peek bit +void(fwd_inVal[15]._.empty()); +void(fwd_inVal[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal +#pragma HLS array_partition variable = inv_inVal complete +#pragma HLS interface ap_fifo port = inv_inVal[0]._ +#pragma HLS aggregate variable = inv_inVal[0]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[0]._peek +#pragma HLS aggregate variable = inv_inVal[0]._peek bit +void(inv_inVal[0]._.empty()); +void(inv_inVal[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[1]._ +#pragma HLS aggregate variable = inv_inVal[1]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[1]._peek +#pragma HLS aggregate variable = inv_inVal[1]._peek bit +void(inv_inVal[1]._.empty()); +void(inv_inVal[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[2]._ +#pragma HLS aggregate variable = inv_inVal[2]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[2]._peek +#pragma HLS aggregate variable = inv_inVal[2]._peek bit +void(inv_inVal[2]._.empty()); +void(inv_inVal[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[3]._ +#pragma HLS aggregate variable = inv_inVal[3]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[3]._peek +#pragma HLS aggregate variable = inv_inVal[3]._peek bit +void(inv_inVal[3]._.empty()); +void(inv_inVal[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[4]._ +#pragma HLS aggregate variable = inv_inVal[4]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[4]._peek +#pragma HLS aggregate variable = inv_inVal[4]._peek bit +void(inv_inVal[4]._.empty()); +void(inv_inVal[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[5]._ +#pragma HLS aggregate variable = inv_inVal[5]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[5]._peek +#pragma HLS aggregate variable = inv_inVal[5]._peek bit +void(inv_inVal[5]._.empty()); +void(inv_inVal[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[6]._ +#pragma HLS aggregate variable = inv_inVal[6]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[6]._peek +#pragma HLS aggregate variable = inv_inVal[6]._peek bit +void(inv_inVal[6]._.empty()); +void(inv_inVal[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[7]._ +#pragma HLS aggregate variable = inv_inVal[7]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[7]._peek +#pragma HLS aggregate variable = inv_inVal[7]._peek bit +void(inv_inVal[7]._.empty()); +void(inv_inVal[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[8]._ +#pragma HLS aggregate variable = inv_inVal[8]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[8]._peek +#pragma HLS aggregate variable = inv_inVal[8]._peek bit +void(inv_inVal[8]._.empty()); +void(inv_inVal[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[9]._ +#pragma HLS aggregate variable = inv_inVal[9]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[9]._peek +#pragma HLS aggregate variable = inv_inVal[9]._peek bit +void(inv_inVal[9]._.empty()); +void(inv_inVal[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[10]._ +#pragma HLS aggregate variable = inv_inVal[10]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[10]._peek +#pragma HLS aggregate variable = inv_inVal[10]._peek bit +void(inv_inVal[10]._.empty()); +void(inv_inVal[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[11]._ +#pragma HLS aggregate variable = inv_inVal[11]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[11]._peek +#pragma HLS aggregate variable = inv_inVal[11]._peek bit +void(inv_inVal[11]._.empty()); +void(inv_inVal[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[12]._ +#pragma HLS aggregate variable = inv_inVal[12]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[12]._peek +#pragma HLS aggregate variable = inv_inVal[12]._peek bit +void(inv_inVal[12]._.empty()); +void(inv_inVal[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[13]._ +#pragma HLS aggregate variable = inv_inVal[13]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[13]._peek +#pragma HLS aggregate variable = inv_inVal[13]._peek bit +void(inv_inVal[13]._.empty()); +void(inv_inVal[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[14]._ +#pragma HLS aggregate variable = inv_inVal[14]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[14]._peek +#pragma HLS aggregate variable = inv_inVal[14]._peek bit +void(inv_inVal[14]._.empty()); +void(inv_inVal[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[15]._ +#pragma HLS aggregate variable = inv_inVal[15]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[15]._peek +#pragma HLS aggregate variable = inv_inVal[15]._peek bit +void(inv_inVal[15]._.empty()); +void(inv_inVal[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_outVal +#pragma HLS array_partition variable = fwd_outVal complete +#pragma HLS interface ap_fifo port = fwd_outVal[0]._ +#pragma HLS aggregate variable = fwd_outVal[0]._ bit +void(fwd_outVal[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[1]._ +#pragma HLS aggregate variable = fwd_outVal[1]._ bit +void(fwd_outVal[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[2]._ +#pragma HLS aggregate variable = fwd_outVal[2]._ bit +void(fwd_outVal[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[3]._ +#pragma HLS aggregate variable = fwd_outVal[3]._ bit +void(fwd_outVal[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[4]._ +#pragma HLS aggregate variable = fwd_outVal[4]._ bit +void(fwd_outVal[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[5]._ +#pragma HLS aggregate variable = fwd_outVal[5]._ bit +void(fwd_outVal[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[6]._ +#pragma HLS aggregate variable = fwd_outVal[6]._ bit +void(fwd_outVal[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[7]._ +#pragma HLS aggregate variable = fwd_outVal[7]._ bit +void(fwd_outVal[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[8]._ +#pragma HLS aggregate variable = fwd_outVal[8]._ bit +void(fwd_outVal[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[9]._ +#pragma HLS aggregate variable = fwd_outVal[9]._ bit +void(fwd_outVal[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[10]._ +#pragma HLS aggregate variable = fwd_outVal[10]._ bit +void(fwd_outVal[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[11]._ +#pragma HLS aggregate variable = fwd_outVal[11]._ bit +void(fwd_outVal[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[12]._ +#pragma HLS aggregate variable = fwd_outVal[12]._ bit +void(fwd_outVal[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[13]._ +#pragma HLS aggregate variable = fwd_outVal[13]._ bit +void(fwd_outVal[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[14]._ +#pragma HLS aggregate variable = fwd_outVal[14]._ bit +void(fwd_outVal[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[15]._ +#pragma HLS aggregate variable = fwd_outVal[15]._ bit +void(fwd_outVal[15]._.full()); + +#pragma HLS disaggregate variable = inv_outVal +#pragma HLS array_partition variable = inv_outVal complete +#pragma HLS interface ap_fifo port = inv_outVal[0]._ +#pragma HLS aggregate variable = inv_outVal[0]._ bit +void(inv_outVal[0]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[1]._ +#pragma HLS aggregate variable = inv_outVal[1]._ bit +void(inv_outVal[1]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[2]._ +#pragma HLS aggregate variable = inv_outVal[2]._ bit +void(inv_outVal[2]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[3]._ +#pragma HLS aggregate variable = inv_outVal[3]._ bit +void(inv_outVal[3]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[4]._ +#pragma HLS aggregate variable = inv_outVal[4]._ bit +void(inv_outVal[4]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[5]._ +#pragma HLS aggregate variable = inv_outVal[5]._ bit +void(inv_outVal[5]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[6]._ +#pragma HLS aggregate variable = inv_outVal[6]._ bit +void(inv_outVal[6]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[7]._ +#pragma HLS aggregate variable = inv_outVal[7]._ bit +void(inv_outVal[7]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[8]._ +#pragma HLS aggregate variable = inv_outVal[8]._ bit +void(inv_outVal[8]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[9]._ +#pragma HLS aggregate variable = inv_outVal[9]._ bit +void(inv_outVal[9]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[10]._ +#pragma HLS aggregate variable = inv_outVal[10]._ bit +void(inv_outVal[10]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[11]._ +#pragma HLS aggregate variable = inv_outVal[11]._ bit +void(inv_outVal[11]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[12]._ +#pragma HLS aggregate variable = inv_outVal[12]._ bit +void(inv_outVal[12]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[13]._ +#pragma HLS aggregate variable = inv_outVal[13]._ bit +void(inv_outVal[13]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[14]._ +#pragma HLS aggregate variable = inv_outVal[14]._ bit +void(inv_outVal[14]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[15]._ +#pragma HLS aggregate variable = inv_outVal[15]._ bit +void(inv_outVal[15]._.full()); + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 shuffleLimit = ( (VAR_TYPE_32)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ) ) - 1; + VAR_TYPE_8 max_data_offset = (V_BUG_SIZE*2); + + VAR_TYPE_8 mini_shift = 0; + VAR_TYPE_8 major_shift = 0; + VAR_TYPE_8 shift_amount = 0; + + WORD inValRegArr[2*V_BUG_SIZE]; + WORD outValRegArr[2*V_BUG_SIZE]; + + //==== Auto generated variables start ====// + VAR_TYPE_8 log_shift_freq_table[shuffleLimit] = {0, 2}; + VAR_TYPE_8 log_mini_shift_reset_freq_table[shuffleLimit] = {0, 0}; + VAR_TYPE_8 log_mini_shift_amount_table[shuffleLimit] = {0, 0}; + VAR_TYPE_8 log_shift_jump_table[shuffleLimit] = {2, 0}; + //==== Auto generated variables end ====// + + bool inpStreamNotEmpty; + VAR_TYPE_8 comp_shuffler_id; + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + for(VAR_TYPE_8 shuffler_id=0, inv_shuffler_id=shuffleLimit-1; shuffler_id> log_shift_freq) << log_shift_jump) % (max_data_offset)) : (major_shift); + mini_shift = ( ( i & ( (1<& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_in/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/shuffler_out_shift.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/shuffler_out_shift.cpp new file mode 100644 index 000000000000..7bdf6a5cb8b9 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/cpp/shuffler_out_shift.cpp @@ -0,0 +1,1029 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id){ +#pragma HLS disaggregate variable = fwd_inVal +#pragma HLS array_partition variable = fwd_inVal complete +#pragma HLS interface ap_fifo port = fwd_inVal[0]._ +#pragma HLS aggregate variable = fwd_inVal[0]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[0]._peek +#pragma HLS aggregate variable = fwd_inVal[0]._peek bit +void(fwd_inVal[0]._.empty()); +void(fwd_inVal[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[1]._ +#pragma HLS aggregate variable = fwd_inVal[1]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[1]._peek +#pragma HLS aggregate variable = fwd_inVal[1]._peek bit +void(fwd_inVal[1]._.empty()); +void(fwd_inVal[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[2]._ +#pragma HLS aggregate variable = fwd_inVal[2]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[2]._peek +#pragma HLS aggregate variable = fwd_inVal[2]._peek bit +void(fwd_inVal[2]._.empty()); +void(fwd_inVal[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[3]._ +#pragma HLS aggregate variable = fwd_inVal[3]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[3]._peek +#pragma HLS aggregate variable = fwd_inVal[3]._peek bit +void(fwd_inVal[3]._.empty()); +void(fwd_inVal[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[4]._ +#pragma HLS aggregate variable = fwd_inVal[4]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[4]._peek +#pragma HLS aggregate variable = fwd_inVal[4]._peek bit +void(fwd_inVal[4]._.empty()); +void(fwd_inVal[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[5]._ +#pragma HLS aggregate variable = fwd_inVal[5]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[5]._peek +#pragma HLS aggregate variable = fwd_inVal[5]._peek bit +void(fwd_inVal[5]._.empty()); +void(fwd_inVal[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[6]._ +#pragma HLS aggregate variable = fwd_inVal[6]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[6]._peek +#pragma HLS aggregate variable = fwd_inVal[6]._peek bit +void(fwd_inVal[6]._.empty()); +void(fwd_inVal[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[7]._ +#pragma HLS aggregate variable = fwd_inVal[7]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[7]._peek +#pragma HLS aggregate variable = fwd_inVal[7]._peek bit +void(fwd_inVal[7]._.empty()); +void(fwd_inVal[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[8]._ +#pragma HLS aggregate variable = fwd_inVal[8]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[8]._peek +#pragma HLS aggregate variable = fwd_inVal[8]._peek bit +void(fwd_inVal[8]._.empty()); +void(fwd_inVal[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[9]._ +#pragma HLS aggregate variable = fwd_inVal[9]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[9]._peek +#pragma HLS aggregate variable = fwd_inVal[9]._peek bit +void(fwd_inVal[9]._.empty()); +void(fwd_inVal[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[10]._ +#pragma HLS aggregate variable = fwd_inVal[10]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[10]._peek +#pragma HLS aggregate variable = fwd_inVal[10]._peek bit +void(fwd_inVal[10]._.empty()); +void(fwd_inVal[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[11]._ +#pragma HLS aggregate variable = fwd_inVal[11]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[11]._peek +#pragma HLS aggregate variable = fwd_inVal[11]._peek bit +void(fwd_inVal[11]._.empty()); +void(fwd_inVal[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[12]._ +#pragma HLS aggregate variable = fwd_inVal[12]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[12]._peek +#pragma HLS aggregate variable = fwd_inVal[12]._peek bit +void(fwd_inVal[12]._.empty()); +void(fwd_inVal[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[13]._ +#pragma HLS aggregate variable = fwd_inVal[13]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[13]._peek +#pragma HLS aggregate variable = fwd_inVal[13]._peek bit +void(fwd_inVal[13]._.empty()); +void(fwd_inVal[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[14]._ +#pragma HLS aggregate variable = fwd_inVal[14]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[14]._peek +#pragma HLS aggregate variable = fwd_inVal[14]._peek bit +void(fwd_inVal[14]._.empty()); +void(fwd_inVal[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal[15]._ +#pragma HLS aggregate variable = fwd_inVal[15]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal[15]._peek +#pragma HLS aggregate variable = fwd_inVal[15]._peek bit +void(fwd_inVal[15]._.empty()); +void(fwd_inVal[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal_inter_0 +#pragma HLS array_partition variable = inv_inVal_inter_0 complete +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[0]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[0]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[0]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[0]._peek bit +void(inv_inVal_inter_0[0]._.empty()); +void(inv_inVal_inter_0[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[1]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[1]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[1]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[1]._peek bit +void(inv_inVal_inter_0[1]._.empty()); +void(inv_inVal_inter_0[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[2]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[2]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[2]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[2]._peek bit +void(inv_inVal_inter_0[2]._.empty()); +void(inv_inVal_inter_0[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[3]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[3]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[3]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[3]._peek bit +void(inv_inVal_inter_0[3]._.empty()); +void(inv_inVal_inter_0[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[4]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[4]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[4]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[4]._peek bit +void(inv_inVal_inter_0[4]._.empty()); +void(inv_inVal_inter_0[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[5]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[5]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[5]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[5]._peek bit +void(inv_inVal_inter_0[5]._.empty()); +void(inv_inVal_inter_0[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[6]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[6]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[6]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[6]._peek bit +void(inv_inVal_inter_0[6]._.empty()); +void(inv_inVal_inter_0[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[7]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[7]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[7]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[7]._peek bit +void(inv_inVal_inter_0[7]._.empty()); +void(inv_inVal_inter_0[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[8]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[8]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[8]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[8]._peek bit +void(inv_inVal_inter_0[8]._.empty()); +void(inv_inVal_inter_0[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[9]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[9]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[9]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[9]._peek bit +void(inv_inVal_inter_0[9]._.empty()); +void(inv_inVal_inter_0[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[10]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[10]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[10]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[10]._peek bit +void(inv_inVal_inter_0[10]._.empty()); +void(inv_inVal_inter_0[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[11]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[11]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[11]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[11]._peek bit +void(inv_inVal_inter_0[11]._.empty()); +void(inv_inVal_inter_0[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[12]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[12]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[12]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[12]._peek bit +void(inv_inVal_inter_0[12]._.empty()); +void(inv_inVal_inter_0[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[13]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[13]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[13]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[13]._peek bit +void(inv_inVal_inter_0[13]._.empty()); +void(inv_inVal_inter_0[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[14]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[14]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[14]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[14]._peek bit +void(inv_inVal_inter_0[14]._.empty()); +void(inv_inVal_inter_0[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[15]._ +#pragma HLS aggregate variable = inv_inVal_inter_0[15]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_inter_0[15]._peek +#pragma HLS aggregate variable = inv_inVal_inter_0[15]._peek bit +void(inv_inVal_inter_0[15]._.empty()); +void(inv_inVal_inter_0[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal_intra +#pragma HLS array_partition variable = inv_inVal_intra complete +#pragma HLS interface ap_fifo port = inv_inVal_intra[0]._ +#pragma HLS aggregate variable = inv_inVal_intra[0]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[0]._peek +#pragma HLS aggregate variable = inv_inVal_intra[0]._peek bit +void(inv_inVal_intra[0]._.empty()); +void(inv_inVal_intra[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[1]._ +#pragma HLS aggregate variable = inv_inVal_intra[1]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[1]._peek +#pragma HLS aggregate variable = inv_inVal_intra[1]._peek bit +void(inv_inVal_intra[1]._.empty()); +void(inv_inVal_intra[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[2]._ +#pragma HLS aggregate variable = inv_inVal_intra[2]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[2]._peek +#pragma HLS aggregate variable = inv_inVal_intra[2]._peek bit +void(inv_inVal_intra[2]._.empty()); +void(inv_inVal_intra[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[3]._ +#pragma HLS aggregate variable = inv_inVal_intra[3]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[3]._peek +#pragma HLS aggregate variable = inv_inVal_intra[3]._peek bit +void(inv_inVal_intra[3]._.empty()); +void(inv_inVal_intra[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[4]._ +#pragma HLS aggregate variable = inv_inVal_intra[4]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[4]._peek +#pragma HLS aggregate variable = inv_inVal_intra[4]._peek bit +void(inv_inVal_intra[4]._.empty()); +void(inv_inVal_intra[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[5]._ +#pragma HLS aggregate variable = inv_inVal_intra[5]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[5]._peek +#pragma HLS aggregate variable = inv_inVal_intra[5]._peek bit +void(inv_inVal_intra[5]._.empty()); +void(inv_inVal_intra[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[6]._ +#pragma HLS aggregate variable = inv_inVal_intra[6]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[6]._peek +#pragma HLS aggregate variable = inv_inVal_intra[6]._peek bit +void(inv_inVal_intra[6]._.empty()); +void(inv_inVal_intra[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[7]._ +#pragma HLS aggregate variable = inv_inVal_intra[7]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[7]._peek +#pragma HLS aggregate variable = inv_inVal_intra[7]._peek bit +void(inv_inVal_intra[7]._.empty()); +void(inv_inVal_intra[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[8]._ +#pragma HLS aggregate variable = inv_inVal_intra[8]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[8]._peek +#pragma HLS aggregate variable = inv_inVal_intra[8]._peek bit +void(inv_inVal_intra[8]._.empty()); +void(inv_inVal_intra[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[9]._ +#pragma HLS aggregate variable = inv_inVal_intra[9]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[9]._peek +#pragma HLS aggregate variable = inv_inVal_intra[9]._peek bit +void(inv_inVal_intra[9]._.empty()); +void(inv_inVal_intra[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[10]._ +#pragma HLS aggregate variable = inv_inVal_intra[10]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[10]._peek +#pragma HLS aggregate variable = inv_inVal_intra[10]._peek bit +void(inv_inVal_intra[10]._.empty()); +void(inv_inVal_intra[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[11]._ +#pragma HLS aggregate variable = inv_inVal_intra[11]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[11]._peek +#pragma HLS aggregate variable = inv_inVal_intra[11]._peek bit +void(inv_inVal_intra[11]._.empty()); +void(inv_inVal_intra[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[12]._ +#pragma HLS aggregate variable = inv_inVal_intra[12]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[12]._peek +#pragma HLS aggregate variable = inv_inVal_intra[12]._peek bit +void(inv_inVal_intra[12]._.empty()); +void(inv_inVal_intra[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[13]._ +#pragma HLS aggregate variable = inv_inVal_intra[13]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[13]._peek +#pragma HLS aggregate variable = inv_inVal_intra[13]._peek bit +void(inv_inVal_intra[13]._.empty()); +void(inv_inVal_intra[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[14]._ +#pragma HLS aggregate variable = inv_inVal_intra[14]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[14]._peek +#pragma HLS aggregate variable = inv_inVal_intra[14]._peek bit +void(inv_inVal_intra[14]._.empty()); +void(inv_inVal_intra[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal_intra[15]._ +#pragma HLS aggregate variable = inv_inVal_intra[15]._ bit +#pragma HLS interface ap_fifo port = inv_inVal_intra[15]._peek +#pragma HLS aggregate variable = inv_inVal_intra[15]._peek bit +void(inv_inVal_intra[15]._.empty()); +void(inv_inVal_intra[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_outVal_inter_0 +#pragma HLS array_partition variable = fwd_outVal_inter_0 complete +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[0]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[0]._ bit +void(fwd_outVal_inter_0[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[1]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[1]._ bit +void(fwd_outVal_inter_0[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[2]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[2]._ bit +void(fwd_outVal_inter_0[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[3]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[3]._ bit +void(fwd_outVal_inter_0[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[4]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[4]._ bit +void(fwd_outVal_inter_0[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[5]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[5]._ bit +void(fwd_outVal_inter_0[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[6]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[6]._ bit +void(fwd_outVal_inter_0[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[7]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[7]._ bit +void(fwd_outVal_inter_0[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[8]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[8]._ bit +void(fwd_outVal_inter_0[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[9]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[9]._ bit +void(fwd_outVal_inter_0[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[10]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[10]._ bit +void(fwd_outVal_inter_0[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[11]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[11]._ bit +void(fwd_outVal_inter_0[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[12]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[12]._ bit +void(fwd_outVal_inter_0[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[13]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[13]._ bit +void(fwd_outVal_inter_0[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[14]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[14]._ bit +void(fwd_outVal_inter_0[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_inter_0[15]._ +#pragma HLS aggregate variable = fwd_outVal_inter_0[15]._ bit +void(fwd_outVal_inter_0[15]._.full()); + +#pragma HLS disaggregate variable = fwd_outVal_intra +#pragma HLS array_partition variable = fwd_outVal_intra complete +#pragma HLS interface ap_fifo port = fwd_outVal_intra[0]._ +#pragma HLS aggregate variable = fwd_outVal_intra[0]._ bit +void(fwd_outVal_intra[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[1]._ +#pragma HLS aggregate variable = fwd_outVal_intra[1]._ bit +void(fwd_outVal_intra[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[2]._ +#pragma HLS aggregate variable = fwd_outVal_intra[2]._ bit +void(fwd_outVal_intra[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[3]._ +#pragma HLS aggregate variable = fwd_outVal_intra[3]._ bit +void(fwd_outVal_intra[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[4]._ +#pragma HLS aggregate variable = fwd_outVal_intra[4]._ bit +void(fwd_outVal_intra[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[5]._ +#pragma HLS aggregate variable = fwd_outVal_intra[5]._ bit +void(fwd_outVal_intra[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[6]._ +#pragma HLS aggregate variable = fwd_outVal_intra[6]._ bit +void(fwd_outVal_intra[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[7]._ +#pragma HLS aggregate variable = fwd_outVal_intra[7]._ bit +void(fwd_outVal_intra[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[8]._ +#pragma HLS aggregate variable = fwd_outVal_intra[8]._ bit +void(fwd_outVal_intra[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[9]._ +#pragma HLS aggregate variable = fwd_outVal_intra[9]._ bit +void(fwd_outVal_intra[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[10]._ +#pragma HLS aggregate variable = fwd_outVal_intra[10]._ bit +void(fwd_outVal_intra[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[11]._ +#pragma HLS aggregate variable = fwd_outVal_intra[11]._ bit +void(fwd_outVal_intra[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[12]._ +#pragma HLS aggregate variable = fwd_outVal_intra[12]._ bit +void(fwd_outVal_intra[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[13]._ +#pragma HLS aggregate variable = fwd_outVal_intra[13]._ bit +void(fwd_outVal_intra[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[14]._ +#pragma HLS aggregate variable = fwd_outVal_intra[14]._ bit +void(fwd_outVal_intra[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal_intra[15]._ +#pragma HLS aggregate variable = fwd_outVal_intra[15]._ bit +void(fwd_outVal_intra[15]._.full()); + +#pragma HLS disaggregate variable = inv_outVal +#pragma HLS array_partition variable = inv_outVal complete +#pragma HLS interface ap_fifo port = inv_outVal[0]._ +#pragma HLS aggregate variable = inv_outVal[0]._ bit +void(inv_outVal[0]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[1]._ +#pragma HLS aggregate variable = inv_outVal[1]._ bit +void(inv_outVal[1]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[2]._ +#pragma HLS aggregate variable = inv_outVal[2]._ bit +void(inv_outVal[2]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[3]._ +#pragma HLS aggregate variable = inv_outVal[3]._ bit +void(inv_outVal[3]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[4]._ +#pragma HLS aggregate variable = inv_outVal[4]._ bit +void(inv_outVal[4]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[5]._ +#pragma HLS aggregate variable = inv_outVal[5]._ bit +void(inv_outVal[5]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[6]._ +#pragma HLS aggregate variable = inv_outVal[6]._ bit +void(inv_outVal[6]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[7]._ +#pragma HLS aggregate variable = inv_outVal[7]._ bit +void(inv_outVal[7]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[8]._ +#pragma HLS aggregate variable = inv_outVal[8]._ bit +void(inv_outVal[8]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[9]._ +#pragma HLS aggregate variable = inv_outVal[9]._ bit +void(inv_outVal[9]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[10]._ +#pragma HLS aggregate variable = inv_outVal[10]._ bit +void(inv_outVal[10]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[11]._ +#pragma HLS aggregate variable = inv_outVal[11]._ bit +void(inv_outVal[11]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[12]._ +#pragma HLS aggregate variable = inv_outVal[12]._ bit +void(inv_outVal[12]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[13]._ +#pragma HLS aggregate variable = inv_outVal[13]._ bit +void(inv_outVal[13]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[14]._ +#pragma HLS aggregate variable = inv_outVal[14]._ bit +void(inv_outVal[14]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal[15]._ +#pragma HLS aggregate variable = inv_outVal[15]._ bit +void(inv_outVal[15]._.full()); + + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 shuffleLimit = (VAR_TYPE_8)( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE ) - 1; + VAR_TYPE_8 max_data_offset = (V_BUG_SIZE*2); + + WORD inValRegArr[2*V_BUG_SIZE]; + WORD outValRegArr[2*V_BUG_SIZE]; + + //==== Auto generated variables start ====// + VAR_TYPE_8 log_shift_freq_table[shuffleLimit] = {0, 2}; + VAR_TYPE_8 log_mini_shift_reset_freq_table[shuffleLimit] = {0, 0}; + VAR_TYPE_8 log_mini_shift_amount_table[shuffleLimit] = {0, 0}; + VAR_TYPE_8 shift_counts_table[shuffleLimit] = {2, 0}; + //==== Auto generated variables end ====// + + bool inpStreamNotEmpty; + VAR_TYPE_8 comp_shuffler_id; + VAR_TYPE_8 shift_amount = 0; + VAR_TYPE_8 adjusted_shift_amount = 0; + + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + for(VAR_TYPE_8 shuffler_id=0, inv_shuffler_id=shuffleLimit-1; shuffler_id> (log_shift_freq-log_mini_shift_reset_freq)) << (shift_counts + log_mini_shift_amount)) % (max_data_offset)) ) % (max_data_offset) ) : (shift_amount); + + if(direction){ + adjusted_shift_amount = shift_amount; + } + else{ + adjusted_shift_amount = ( max_data_offset - shift_amount ) % max_data_offset; + } + + //shuffle + for(VAR_TYPE_8 j=0; j<2*V_BUG_SIZE; j++){ + #pragma HLS UNROLL + outValRegArr[(j+adjusted_shift_amount)%max_data_offset] = inValRegArr[j]; + } + + //write data to out stream + for(VAR_TYPE_8 j=0; j<2*V_BUG_SIZE; j++){ + #pragma HLS UNROLL + if(direction){ + if(comp_shuffler_id==0){ + fwd_outVal_inter_0[j].write(outValRegArr[j]); + } + else{ + fwd_outVal_intra[j].write(outValRegArr[j]); + } + } + else{ + inv_outVal[j].write(outValRegArr[j]); + } + } + i++; + } + } + } + } +} + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ); + + +// /******************************************************************************************** +// * TF buffer tasks * +// ********************************************************************************************/ + +void TFBuf_loadTF_wiFW( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shift/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/ntt.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/ntt.h new file mode 100644 index 000000000000..414fd80529fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/ntt.h @@ -0,0 +1,91 @@ +#ifndef _H_GEMM_H_ +#define _H_GEMM_H_ +#define __gmp_const const +#include +#include "ap_int.h" + +// inbuilt data types +#define VAR_TYPE_32 uint32_t +#define VAR_TYPE_64 uint64_t +#define VAR_TYPE_8 uint8_t +#define VAR_TYPE_16 uint16_t + +// Polynomial size related +const uint8_t logN=12; +const uint32_t N=(1U<32)?64:32; + +// custom data types +#define WORD ap_uint +#define DRAM_WORD ap_uint +#define WORD_PLUS1 ap_uint +#define WORD_PLUS2 ap_uint +#define WORD_PLUS3 ap_uint +#define DWORD ap_uint +#define DWORD_PLUS1 ap_uint +#define DWORD_PLUS3 ap_uint +#define TWORD ap_uint // TWORD +#define TWORD_PLUS1 ap_uint // TWORD_PLUS1 +#define DDWORD ap_uint + +// predefined vals +const WORD WORD_SIZE_MASK=(WORD)(((WORD_PLUS1)1< +const uint8_t POLY_LS_PORTS_PER_PARA_LIMB=1; +const uint8_t BUG_PER_PARA_LIMB_POLY_PORT = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (V_TOTAL_DATA/(POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT*POLY_LS_PORTS_PER_PARA_LIMB)) : (BUG_CONCAT_FACTOR/POLY_LS_PORTS_PER_PARA_LIMB); +const uint8_t BUG_PER_PARA_LIMB_POLY_WIDE_DATA = (2*V_BUG_SIZE>POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT) ? (1) : (POLY_CONCAT_FACTOR_PER_PARA_LIMB_PORT/(2*V_BUG_SIZE)); +const uint8_t SEQ_BUG_PER_PARA_LIMB_POLY_PORT = (BUG_PER_PARA_LIMB_POLY_PORT/BUG_PER_PARA_LIMB_POLY_WIDE_DATA); + +const uint16_t PARA_LIMB_PORTS_PER_POLY_PORT = (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/POLY_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t POLY_LS_PORTS = ((PARA_LIMBS + PARA_LIMB_PORTS_PER_POLY_PORT-1)/PARA_LIMB_PORTS_PER_POLY_PORT) * POLY_LS_PORTS_PER_PARA_LIMB; //ceil divsion +#define POLY_WIDE_DATA ap_uint + +// TF DRAM related +const uint16_t TF_DRAM_PORT_WIDTH_PER_PARA_LIMB = 512; +const uint16_t TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT = (TF_DRAM_PORT_WIDTH_PER_PARA_LIMB/DRAM_WORD_SIZE); +#define TF_WIDE_DATA_PER_PARA_LIMB ap_uint + +const uint8_t TF_PORTS_PER_PARA_LIMB=2; +const uint8_t TF_LOAD_V_SEGS_PER_PARA_LIMB=( ( (V_BUG_SIZE/2) * BUG_CONCAT_FACTOR * 2 ) / TF_CONCAT_FACTOR_PER_PARA_LIMB_PORT ); //i.e., vertically how many TFBuffers the design has and each can take 2 values at a time +const uint8_t TF_LOAD_H_SEGS_PER_PARA_LIMB=TF_PORTS_PER_PARA_LIMB/TF_LOAD_V_SEGS_PER_PARA_LIMB; //i.e., How many segments total H_BUG_SIZE layers are bokern into + +const uint16_t PARA_LIMB_PORTS_PER_TF_PORT = (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB > PARA_LIMBS) ? (PARA_LIMBS) : (DEFAULT_DRAM_PORT_WIDTH/TF_DRAM_PORT_WIDTH_PER_PARA_LIMB); +const uint16_t TF_PORTS = ((PARA_LIMBS+PARA_LIMB_PORTS_PER_TF_PORT-1)/PARA_LIMB_PORTS_PER_TF_PORT) * TF_PORTS_PER_PARA_LIMB; //ceil divsion +#define TF_WIDE_DATA ap_uint + +// in/out FIFO size. Ideally this is equal to N/V_TOTAL_DATA. In order to force the FIFO into SRAM, larger sizes are used. +const uint16_t LS_FIFO_BUF_SIZE=1024; + +#endif + diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/shuffler_out_shuff.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/shuffler_out_shuff.cpp new file mode 100644 index 000000000000..3ec7ed3dccd7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/cpp/shuffler_out_shuff.cpp @@ -0,0 +1,1123 @@ +#include + +#include +#include "ntt.h" + +// /******************************************************************************************** +// * Polynomial load store tasks * +// ********************************************************************************************/ + +void fwd_load_inv_store_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& inv_in_poly_L0_stream0, + tapa::istreams& inv_in_poly_L0_stream1, + tapa::istreams& inv_in_poly_L0_stream2, + tapa::istreams& inv_in_poly_L0_stream3, + tapa::ostreams& fwd_out_poly_L0_stream0, + tapa::ostreams& fwd_out_poly_L0_stream1, + tapa::ostreams& fwd_out_poly_L0_stream2, + tapa::ostreams& fwd_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +void fwd_store_inv_load_poly_1_limbs(uint64_t poly_mmap, + tapa::istreams& fwd_in_poly_L0_stream0, + tapa::istreams& fwd_in_poly_L0_stream1, + tapa::istreams& fwd_in_poly_L0_stream2, + tapa::istreams& fwd_in_poly_L0_stream3, + tapa::ostreams& inv_out_poly_L0_stream0, + tapa::ostreams& inv_out_poly_L0_stream1, + tapa::ostreams& inv_out_poly_L0_stream2, + tapa::ostreams& inv_out_poly_L0_stream3, + bool direction, + VAR_TYPE_16 iter) ; + + +// /******************************************************************************************** +// * TF load tasks * +// ********************************************************************************************/ + +void Mmap2Stream_tf_0_1_limbs(uint64_t tf_mmap, + tapa::ostreams& tf_stream_L0_0, + bool direction, + VAR_TYPE_16 iter) ; + +// /******************************************************************************************** +// * Function to multiply with two inverse * +// ********************************************************************************************/ + +void multiplyTwoInverse(WORD *val, WORD *twoInverse){ + #pragma HLS inline + *val = (*val>>1) + (*val & 1)*(*twoInverse); +} + +// /******************************************************************************************** +// * Modulo multiplication functions * +// ********************************************************************************************/ + +ap_uint<64> hardcoded_fullMul_0(ap_uint<32> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<15> u_1 = u & ((1<<15)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<42> mul_1 = ((ap_uint<42>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<20> mul_3 = ((ap_uint<20>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<64> res = ( (((ap_uint<64>)mul_0)<<0) + (((ap_uint<64>)mul_1)<<17) + (((ap_uint<64>)mul_2)<<27) + (((ap_uint<64>)mul_3)<<44) ); + return res; +} + +ap_uint<33> hardcoded_fullMul_1(ap_uint<35> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<18> u_0 = u & ((1<<18)-1); + u = u >> 18; + ap_uint<17> u_1 = u & ((1<<17)-1); + + ap_uint<26> v_0 = v & ((1<<26)-1); + v = v >> 26; + ap_uint<6> v_1 = v & ((1<<6)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<18 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<24> mul_2 = ((ap_uint<24>)(u_0) * v_1); //<<26 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + ap_uint<23> mul_3 = ((ap_uint<23>)(u_1) * v_1); //<<44 + #pragma HLS bind_op variable=mul_3 op=mul impl=dsp + + + ap_uint<33> res = ( (((ap_uint<67>)mul_0)<<0) + (((ap_uint<67>)mul_1)<<18) + (((ap_uint<67>)mul_2)<<26) + (((ap_uint<67>)mul_3)<<44) ) >> (WORD_SIZE+2); + return res; +} + +ap_uint<34> hardcoded_lowerHalfMul_2(ap_uint<33> u, ap_uint<32> v){ + #pragma HLS inline + + ap_uint<17> u_0 = u & ((1<<17)-1); + u = u >> 17; + ap_uint<16> u_1 = u & ((1<<16)-1); + + ap_uint<27> v_0 = v & ((1<<27)-1); + v = v >> 27; + ap_uint<5> v_1 = v & ((1<<5)-1); + + ap_uint<44> mul_0 = ((ap_uint<44>)(u_0) * v_0); //<<0 + #pragma HLS bind_op variable=mul_0 op=mul impl=dsp + ap_uint<43> mul_1 = ((ap_uint<43>)(u_1) * v_0); //<<17 + #pragma HLS bind_op variable=mul_1 op=mul impl=dsp + + ap_uint<22> mul_2 = ((ap_uint<22>)(u_0) * v_1); //<<27 + #pragma HLS bind_op variable=mul_2 op=mul impl=dsp + + + ap_uint<34> res = ( (((ap_uint<34>)mul_0)<<0) + (((ap_uint<34>)mul_1)<<17) + (((ap_uint<34>)mul_2)<<27) ) & WORD_SIZE_PLUS2_MASK; + return res; +} + +WORD barrett_reduce(WORD u, WORD v, WORD mod, WORD_PLUS3 factor) +{ + #pragma HLS inline + + DWORD U = hardcoded_fullMul_0(u,v); + WORD_PLUS2 Y = (U) & WORD_SIZE_PLUS2_MASK; + + WORD V = U >> WORD_SIZE; + WORD_PLUS1 W_1 = hardcoded_fullMul_1(factor, V); + + WORD_PLUS2 X_1 = hardcoded_lowerHalfMul_2(W_1, mod); + + WORD_PLUS1 Z; + if(X_1<=Y){ + Z = Y - X_1; + } + else{ + Z = (WORD_PLUS3(1)<<(WORD_SIZE+2)) - X_1 + Y; + } + + if(Z >= (3*mod)){ + Z = Z - 3*mod; + } + else if(Z >= (2*mod)){ + Z = Z - 2*mod; + } + else if(Z >= mod){ + Z = Z - mod; + } + + return (WORD)Z; +} + +// /******************************************************************************************** +// * Butterfly Unit(BU) * +// ********************************************************************************************/ + +void BU( + tapa::istream& fwd_inVal0, + tapa::istream& fwd_inVal1, + tapa::istream& inv_inVal0, + tapa::istream& inv_inVal1, + tapa::istream& tf_inVal, + tapa::ostream& fwd_outVal0, + tapa::ostream& fwd_outVal1, + tapa::ostream& inv_outVal0, + tapa::ostream& inv_outVal1, + WORD q, + WORD twoInverse, + WORD_PLUS3 factor, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 layer_id + ); + +// /******************************************************************************************** +// * Shuffler tasks * +// ********************************************************************************************/ + +void shuffler_in(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_idx + ); + +void shuffler_buf(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 BUG_id, + VAR_TYPE_16 iter); + +void shuffler_out_shift(tapa::istreams& fwd_inVal, + tapa::istreams& inv_inVal_inter_0, + tapa::istreams& inv_inVal_intra, + tapa::ostreams& fwd_outVal_inter_0, + tapa::ostreams& fwd_outVal_intra, + tapa::ostreams& inv_outVal, + bool direction, + VAR_TYPE_16 iter, + VAR_TYPE_16 task_id); + +void shuffler_out_shuff( + tapa::istream& fwd_inVal_inter0_0, + tapa::istream& fwd_inVal_inter0_1, + tapa::istream& fwd_inVal_inter0_2, + tapa::istream& fwd_inVal_inter0_3, + tapa::istream& fwd_inVal_inter0_4, + tapa::istream& fwd_inVal_inter0_5, + tapa::istream& fwd_inVal_inter0_6, + tapa::istream& fwd_inVal_inter0_7, + tapa::istream& fwd_inVal_inter0_8, + tapa::istream& fwd_inVal_inter0_9, + tapa::istream& fwd_inVal_inter0_10, + tapa::istream& fwd_inVal_inter0_11, + tapa::istream& fwd_inVal_inter0_12, + tapa::istream& fwd_inVal_inter0_13, + tapa::istream& fwd_inVal_inter0_14, + tapa::istream& fwd_inVal_inter0_15, + tapa::istreams& fwd_inVal_intra, + tapa::istreams& inv_inVal, + tapa::ostreams& fwd_outVal, + tapa::ostreams& inv_outVal_intra, + tapa::ostream& inv_outVal_inter0_0, + tapa::ostream& inv_outVal_inter0_1, + tapa::ostream& inv_outVal_inter0_2, + tapa::ostream& inv_outVal_inter0_3, + tapa::ostream& inv_outVal_inter0_4, + tapa::ostream& inv_outVal_inter0_5, + tapa::ostream& inv_outVal_inter0_6, + tapa::ostream& inv_outVal_inter0_7, + tapa::ostream& inv_outVal_inter0_8, + tapa::ostream& inv_outVal_inter0_9, + tapa::ostream& inv_outVal_inter0_10, + tapa::ostream& inv_outVal_inter0_11, + tapa::ostream& inv_outVal_inter0_12, + tapa::ostream& inv_outVal_inter0_13, + tapa::ostream& inv_outVal_inter0_14, + tapa::ostream& inv_outVal_inter0_15, + bool direction, + VAR_TYPE_16 iter + ){ +#pragma HLS disaggregate variable = fwd_inVal_inter0_0 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_0._ +#pragma HLS aggregate variable = fwd_inVal_inter0_0._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_0._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_0._peek bit +void(fwd_inVal_inter0_0._.empty()); +void(fwd_inVal_inter0_0._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_1 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_1._ +#pragma HLS aggregate variable = fwd_inVal_inter0_1._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_1._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_1._peek bit +void(fwd_inVal_inter0_1._.empty()); +void(fwd_inVal_inter0_1._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_2 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_2._ +#pragma HLS aggregate variable = fwd_inVal_inter0_2._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_2._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_2._peek bit +void(fwd_inVal_inter0_2._.empty()); +void(fwd_inVal_inter0_2._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_3 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_3._ +#pragma HLS aggregate variable = fwd_inVal_inter0_3._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_3._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_3._peek bit +void(fwd_inVal_inter0_3._.empty()); +void(fwd_inVal_inter0_3._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_4 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_4._ +#pragma HLS aggregate variable = fwd_inVal_inter0_4._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_4._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_4._peek bit +void(fwd_inVal_inter0_4._.empty()); +void(fwd_inVal_inter0_4._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_5 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_5._ +#pragma HLS aggregate variable = fwd_inVal_inter0_5._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_5._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_5._peek bit +void(fwd_inVal_inter0_5._.empty()); +void(fwd_inVal_inter0_5._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_6 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_6._ +#pragma HLS aggregate variable = fwd_inVal_inter0_6._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_6._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_6._peek bit +void(fwd_inVal_inter0_6._.empty()); +void(fwd_inVal_inter0_6._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_7 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_7._ +#pragma HLS aggregate variable = fwd_inVal_inter0_7._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_7._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_7._peek bit +void(fwd_inVal_inter0_7._.empty()); +void(fwd_inVal_inter0_7._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_8 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_8._ +#pragma HLS aggregate variable = fwd_inVal_inter0_8._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_8._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_8._peek bit +void(fwd_inVal_inter0_8._.empty()); +void(fwd_inVal_inter0_8._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_9 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_9._ +#pragma HLS aggregate variable = fwd_inVal_inter0_9._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_9._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_9._peek bit +void(fwd_inVal_inter0_9._.empty()); +void(fwd_inVal_inter0_9._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_10 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_10._ +#pragma HLS aggregate variable = fwd_inVal_inter0_10._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_10._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_10._peek bit +void(fwd_inVal_inter0_10._.empty()); +void(fwd_inVal_inter0_10._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_11 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_11._ +#pragma HLS aggregate variable = fwd_inVal_inter0_11._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_11._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_11._peek bit +void(fwd_inVal_inter0_11._.empty()); +void(fwd_inVal_inter0_11._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_12 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_12._ +#pragma HLS aggregate variable = fwd_inVal_inter0_12._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_12._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_12._peek bit +void(fwd_inVal_inter0_12._.empty()); +void(fwd_inVal_inter0_12._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_13 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_13._ +#pragma HLS aggregate variable = fwd_inVal_inter0_13._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_13._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_13._peek bit +void(fwd_inVal_inter0_13._.empty()); +void(fwd_inVal_inter0_13._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_14 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_14._ +#pragma HLS aggregate variable = fwd_inVal_inter0_14._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_14._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_14._peek bit +void(fwd_inVal_inter0_14._.empty()); +void(fwd_inVal_inter0_14._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_inter0_15 +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_15._ +#pragma HLS aggregate variable = fwd_inVal_inter0_15._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_inter0_15._peek +#pragma HLS aggregate variable = fwd_inVal_inter0_15._peek bit +void(fwd_inVal_inter0_15._.empty()); +void(fwd_inVal_inter0_15._peek.empty()); + +#pragma HLS disaggregate variable = fwd_inVal_intra +#pragma HLS array_partition variable = fwd_inVal_intra complete +#pragma HLS interface ap_fifo port = fwd_inVal_intra[0]._ +#pragma HLS aggregate variable = fwd_inVal_intra[0]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[0]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[0]._peek bit +void(fwd_inVal_intra[0]._.empty()); +void(fwd_inVal_intra[0]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[1]._ +#pragma HLS aggregate variable = fwd_inVal_intra[1]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[1]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[1]._peek bit +void(fwd_inVal_intra[1]._.empty()); +void(fwd_inVal_intra[1]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[2]._ +#pragma HLS aggregate variable = fwd_inVal_intra[2]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[2]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[2]._peek bit +void(fwd_inVal_intra[2]._.empty()); +void(fwd_inVal_intra[2]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[3]._ +#pragma HLS aggregate variable = fwd_inVal_intra[3]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[3]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[3]._peek bit +void(fwd_inVal_intra[3]._.empty()); +void(fwd_inVal_intra[3]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[4]._ +#pragma HLS aggregate variable = fwd_inVal_intra[4]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[4]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[4]._peek bit +void(fwd_inVal_intra[4]._.empty()); +void(fwd_inVal_intra[4]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[5]._ +#pragma HLS aggregate variable = fwd_inVal_intra[5]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[5]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[5]._peek bit +void(fwd_inVal_intra[5]._.empty()); +void(fwd_inVal_intra[5]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[6]._ +#pragma HLS aggregate variable = fwd_inVal_intra[6]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[6]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[6]._peek bit +void(fwd_inVal_intra[6]._.empty()); +void(fwd_inVal_intra[6]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[7]._ +#pragma HLS aggregate variable = fwd_inVal_intra[7]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[7]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[7]._peek bit +void(fwd_inVal_intra[7]._.empty()); +void(fwd_inVal_intra[7]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[8]._ +#pragma HLS aggregate variable = fwd_inVal_intra[8]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[8]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[8]._peek bit +void(fwd_inVal_intra[8]._.empty()); +void(fwd_inVal_intra[8]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[9]._ +#pragma HLS aggregate variable = fwd_inVal_intra[9]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[9]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[9]._peek bit +void(fwd_inVal_intra[9]._.empty()); +void(fwd_inVal_intra[9]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[10]._ +#pragma HLS aggregate variable = fwd_inVal_intra[10]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[10]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[10]._peek bit +void(fwd_inVal_intra[10]._.empty()); +void(fwd_inVal_intra[10]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[11]._ +#pragma HLS aggregate variable = fwd_inVal_intra[11]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[11]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[11]._peek bit +void(fwd_inVal_intra[11]._.empty()); +void(fwd_inVal_intra[11]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[12]._ +#pragma HLS aggregate variable = fwd_inVal_intra[12]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[12]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[12]._peek bit +void(fwd_inVal_intra[12]._.empty()); +void(fwd_inVal_intra[12]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[13]._ +#pragma HLS aggregate variable = fwd_inVal_intra[13]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[13]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[13]._peek bit +void(fwd_inVal_intra[13]._.empty()); +void(fwd_inVal_intra[13]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[14]._ +#pragma HLS aggregate variable = fwd_inVal_intra[14]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[14]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[14]._peek bit +void(fwd_inVal_intra[14]._.empty()); +void(fwd_inVal_intra[14]._peek.empty()); +#pragma HLS interface ap_fifo port = fwd_inVal_intra[15]._ +#pragma HLS aggregate variable = fwd_inVal_intra[15]._ bit +#pragma HLS interface ap_fifo port = fwd_inVal_intra[15]._peek +#pragma HLS aggregate variable = fwd_inVal_intra[15]._peek bit +void(fwd_inVal_intra[15]._.empty()); +void(fwd_inVal_intra[15]._peek.empty()); + +#pragma HLS disaggregate variable = inv_inVal +#pragma HLS array_partition variable = inv_inVal complete +#pragma HLS interface ap_fifo port = inv_inVal[0]._ +#pragma HLS aggregate variable = inv_inVal[0]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[0]._peek +#pragma HLS aggregate variable = inv_inVal[0]._peek bit +void(inv_inVal[0]._.empty()); +void(inv_inVal[0]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[1]._ +#pragma HLS aggregate variable = inv_inVal[1]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[1]._peek +#pragma HLS aggregate variable = inv_inVal[1]._peek bit +void(inv_inVal[1]._.empty()); +void(inv_inVal[1]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[2]._ +#pragma HLS aggregate variable = inv_inVal[2]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[2]._peek +#pragma HLS aggregate variable = inv_inVal[2]._peek bit +void(inv_inVal[2]._.empty()); +void(inv_inVal[2]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[3]._ +#pragma HLS aggregate variable = inv_inVal[3]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[3]._peek +#pragma HLS aggregate variable = inv_inVal[3]._peek bit +void(inv_inVal[3]._.empty()); +void(inv_inVal[3]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[4]._ +#pragma HLS aggregate variable = inv_inVal[4]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[4]._peek +#pragma HLS aggregate variable = inv_inVal[4]._peek bit +void(inv_inVal[4]._.empty()); +void(inv_inVal[4]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[5]._ +#pragma HLS aggregate variable = inv_inVal[5]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[5]._peek +#pragma HLS aggregate variable = inv_inVal[5]._peek bit +void(inv_inVal[5]._.empty()); +void(inv_inVal[5]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[6]._ +#pragma HLS aggregate variable = inv_inVal[6]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[6]._peek +#pragma HLS aggregate variable = inv_inVal[6]._peek bit +void(inv_inVal[6]._.empty()); +void(inv_inVal[6]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[7]._ +#pragma HLS aggregate variable = inv_inVal[7]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[7]._peek +#pragma HLS aggregate variable = inv_inVal[7]._peek bit +void(inv_inVal[7]._.empty()); +void(inv_inVal[7]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[8]._ +#pragma HLS aggregate variable = inv_inVal[8]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[8]._peek +#pragma HLS aggregate variable = inv_inVal[8]._peek bit +void(inv_inVal[8]._.empty()); +void(inv_inVal[8]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[9]._ +#pragma HLS aggregate variable = inv_inVal[9]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[9]._peek +#pragma HLS aggregate variable = inv_inVal[9]._peek bit +void(inv_inVal[9]._.empty()); +void(inv_inVal[9]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[10]._ +#pragma HLS aggregate variable = inv_inVal[10]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[10]._peek +#pragma HLS aggregate variable = inv_inVal[10]._peek bit +void(inv_inVal[10]._.empty()); +void(inv_inVal[10]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[11]._ +#pragma HLS aggregate variable = inv_inVal[11]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[11]._peek +#pragma HLS aggregate variable = inv_inVal[11]._peek bit +void(inv_inVal[11]._.empty()); +void(inv_inVal[11]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[12]._ +#pragma HLS aggregate variable = inv_inVal[12]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[12]._peek +#pragma HLS aggregate variable = inv_inVal[12]._peek bit +void(inv_inVal[12]._.empty()); +void(inv_inVal[12]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[13]._ +#pragma HLS aggregate variable = inv_inVal[13]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[13]._peek +#pragma HLS aggregate variable = inv_inVal[13]._peek bit +void(inv_inVal[13]._.empty()); +void(inv_inVal[13]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[14]._ +#pragma HLS aggregate variable = inv_inVal[14]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[14]._peek +#pragma HLS aggregate variable = inv_inVal[14]._peek bit +void(inv_inVal[14]._.empty()); +void(inv_inVal[14]._peek.empty()); +#pragma HLS interface ap_fifo port = inv_inVal[15]._ +#pragma HLS aggregate variable = inv_inVal[15]._ bit +#pragma HLS interface ap_fifo port = inv_inVal[15]._peek +#pragma HLS aggregate variable = inv_inVal[15]._peek bit +void(inv_inVal[15]._.empty()); +void(inv_inVal[15]._peek.empty()); + +#pragma HLS disaggregate variable = fwd_outVal +#pragma HLS array_partition variable = fwd_outVal complete +#pragma HLS interface ap_fifo port = fwd_outVal[0]._ +#pragma HLS aggregate variable = fwd_outVal[0]._ bit +void(fwd_outVal[0]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[1]._ +#pragma HLS aggregate variable = fwd_outVal[1]._ bit +void(fwd_outVal[1]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[2]._ +#pragma HLS aggregate variable = fwd_outVal[2]._ bit +void(fwd_outVal[2]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[3]._ +#pragma HLS aggregate variable = fwd_outVal[3]._ bit +void(fwd_outVal[3]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[4]._ +#pragma HLS aggregate variable = fwd_outVal[4]._ bit +void(fwd_outVal[4]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[5]._ +#pragma HLS aggregate variable = fwd_outVal[5]._ bit +void(fwd_outVal[5]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[6]._ +#pragma HLS aggregate variable = fwd_outVal[6]._ bit +void(fwd_outVal[6]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[7]._ +#pragma HLS aggregate variable = fwd_outVal[7]._ bit +void(fwd_outVal[7]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[8]._ +#pragma HLS aggregate variable = fwd_outVal[8]._ bit +void(fwd_outVal[8]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[9]._ +#pragma HLS aggregate variable = fwd_outVal[9]._ bit +void(fwd_outVal[9]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[10]._ +#pragma HLS aggregate variable = fwd_outVal[10]._ bit +void(fwd_outVal[10]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[11]._ +#pragma HLS aggregate variable = fwd_outVal[11]._ bit +void(fwd_outVal[11]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[12]._ +#pragma HLS aggregate variable = fwd_outVal[12]._ bit +void(fwd_outVal[12]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[13]._ +#pragma HLS aggregate variable = fwd_outVal[13]._ bit +void(fwd_outVal[13]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[14]._ +#pragma HLS aggregate variable = fwd_outVal[14]._ bit +void(fwd_outVal[14]._.full()); +#pragma HLS interface ap_fifo port = fwd_outVal[15]._ +#pragma HLS aggregate variable = fwd_outVal[15]._ bit +void(fwd_outVal[15]._.full()); + +#pragma HLS disaggregate variable = inv_outVal_intra +#pragma HLS array_partition variable = inv_outVal_intra complete +#pragma HLS interface ap_fifo port = inv_outVal_intra[0]._ +#pragma HLS aggregate variable = inv_outVal_intra[0]._ bit +void(inv_outVal_intra[0]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[1]._ +#pragma HLS aggregate variable = inv_outVal_intra[1]._ bit +void(inv_outVal_intra[1]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[2]._ +#pragma HLS aggregate variable = inv_outVal_intra[2]._ bit +void(inv_outVal_intra[2]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[3]._ +#pragma HLS aggregate variable = inv_outVal_intra[3]._ bit +void(inv_outVal_intra[3]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[4]._ +#pragma HLS aggregate variable = inv_outVal_intra[4]._ bit +void(inv_outVal_intra[4]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[5]._ +#pragma HLS aggregate variable = inv_outVal_intra[5]._ bit +void(inv_outVal_intra[5]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[6]._ +#pragma HLS aggregate variable = inv_outVal_intra[6]._ bit +void(inv_outVal_intra[6]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[7]._ +#pragma HLS aggregate variable = inv_outVal_intra[7]._ bit +void(inv_outVal_intra[7]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[8]._ +#pragma HLS aggregate variable = inv_outVal_intra[8]._ bit +void(inv_outVal_intra[8]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[9]._ +#pragma HLS aggregate variable = inv_outVal_intra[9]._ bit +void(inv_outVal_intra[9]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[10]._ +#pragma HLS aggregate variable = inv_outVal_intra[10]._ bit +void(inv_outVal_intra[10]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[11]._ +#pragma HLS aggregate variable = inv_outVal_intra[11]._ bit +void(inv_outVal_intra[11]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[12]._ +#pragma HLS aggregate variable = inv_outVal_intra[12]._ bit +void(inv_outVal_intra[12]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[13]._ +#pragma HLS aggregate variable = inv_outVal_intra[13]._ bit +void(inv_outVal_intra[13]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[14]._ +#pragma HLS aggregate variable = inv_outVal_intra[14]._ bit +void(inv_outVal_intra[14]._.full()); +#pragma HLS interface ap_fifo port = inv_outVal_intra[15]._ +#pragma HLS aggregate variable = inv_outVal_intra[15]._ bit +void(inv_outVal_intra[15]._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_0 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_0._ +#pragma HLS aggregate variable = inv_outVal_inter0_0._ bit +void(inv_outVal_inter0_0._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_1 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_1._ +#pragma HLS aggregate variable = inv_outVal_inter0_1._ bit +void(inv_outVal_inter0_1._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_2 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_2._ +#pragma HLS aggregate variable = inv_outVal_inter0_2._ bit +void(inv_outVal_inter0_2._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_3 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_3._ +#pragma HLS aggregate variable = inv_outVal_inter0_3._ bit +void(inv_outVal_inter0_3._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_4 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_4._ +#pragma HLS aggregate variable = inv_outVal_inter0_4._ bit +void(inv_outVal_inter0_4._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_5 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_5._ +#pragma HLS aggregate variable = inv_outVal_inter0_5._ bit +void(inv_outVal_inter0_5._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_6 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_6._ +#pragma HLS aggregate variable = inv_outVal_inter0_6._ bit +void(inv_outVal_inter0_6._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_7 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_7._ +#pragma HLS aggregate variable = inv_outVal_inter0_7._ bit +void(inv_outVal_inter0_7._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_8 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_8._ +#pragma HLS aggregate variable = inv_outVal_inter0_8._ bit +void(inv_outVal_inter0_8._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_9 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_9._ +#pragma HLS aggregate variable = inv_outVal_inter0_9._ bit +void(inv_outVal_inter0_9._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_10 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_10._ +#pragma HLS aggregate variable = inv_outVal_inter0_10._ bit +void(inv_outVal_inter0_10._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_11 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_11._ +#pragma HLS aggregate variable = inv_outVal_inter0_11._ bit +void(inv_outVal_inter0_11._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_12 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_12._ +#pragma HLS aggregate variable = inv_outVal_inter0_12._ bit +void(inv_outVal_inter0_12._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_13 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_13._ +#pragma HLS aggregate variable = inv_outVal_inter0_13._ bit +void(inv_outVal_inter0_13._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_14 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_14._ +#pragma HLS aggregate variable = inv_outVal_inter0_14._ bit +void(inv_outVal_inter0_14._.full()); + +#pragma HLS disaggregate variable = inv_outVal_inter0_15 +#pragma HLS interface ap_fifo port = inv_outVal_inter0_15._ +#pragma HLS aggregate variable = inv_outVal_inter0_15._ bit +void(inv_outVal_inter0_15._.full()); + + + + + const VAR_TYPE_16 dataCount = (N/(V_TOTAL_DATA)); + const VAR_TYPE_8 shuffleLimit = ( (VAR_TYPE_32)(logN+(H_BUG_SIZE-1))/H_BUG_SIZE ) - 1; + + WORD inValRegArr[V_TOTAL_DATA]; + WORD outValRegArr[V_TOTAL_DATA]; + + bool inpStreamNotEmpty; + VAR_TYPE_8 comp_shuffler_id = 0; + + for(VAR_TYPE_16 iterCount=0; iterCount<(iter+1); iterCount++){ + for(VAR_TYPE_8 shuffler_id=0, inv_shuffler_id=shuffleLimit-1; shuffler_id& loadTFStream, + tapa::ostream& loadTFToNext, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter, + VAR_TYPE_16 this_buf_limit){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + } + else{ + loadTFToNext.write((loadTFStream.read())); + } + i++; + } + } +} + +void TFBuf_loadTF_woFW( + tapa::istream& loadTFStream, + WORD TFArr[N/2], + VAR_TYPE_16 tf_load_counter){ + + #pragma HLS inline off + + //load + TF_LOAD:for(VAR_TYPE_16 i=0; i> WORD_SIZE); + i++; + } + } +} + +void TFBuf_comp( + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + WORD TFArr[N/2], + const VAR_TYPE_16 fwd_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_stageWiseTFs[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_stageWiseOffset[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 fwd_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + const VAR_TYPE_16 inv_log_num_val_accessed_by_consec_BUs_arr[( (logN+(H_BUG_SIZE-1))/H_BUG_SIZE )], + VAR_TYPE_8 unit_id_0, + VAR_TYPE_8 unit_id_1, + VAR_TYPE_16 dataCount, + VAR_TYPE_8 dataFlowIterLimit, + bool direction){ + + #pragma HLS inline off + + TF_DF_ITER:for(VAR_TYPE_8 dataFlowIter = 0; dataFlowIter> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_0 & ( (1<> (log_countLimit) ) << log_num_val_accessed_by_consec_BUs ) + (unit_id_1 & ( (1<& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_1( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_wiFW_2( + tapa::istream& loadTFStream, + tapa::ostream& loadTFToNext, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + +void TFBuf_woFW_3( + tapa::istream& loadTFStream, + tapa::ostream& tfToBu_0, + tapa::ostream& tfToBu_1, + bool direction, + VAR_TYPE_8 BUG_id, + VAR_TYPE_8 TFGen_offset, + VAR_TYPE_8 unit_id, + VAR_TYPE_16 iter); + + +// /******************************************************************************************** +// * Input/Output selector tasks * +// ********************************************************************************************/ + +void input_selector_single( + tapa::istream& fwd_valFromLoad_0, + tapa::istream& fwd_valFromShuf, + tapa::istream& inv_valFromBU, + tapa::ostream& fwd_valToBU, + tapa::ostream& inv_valToShuf, + tapa::ostream& inv_valToStore_0, + bool direction, + VAR_TYPE_16 iter); +void output_slector_single( + tapa::istream& fwd_valFromBU, + tapa::istream& inv_valFromLoad_0, + tapa::istream& inv_valFromShuf, + tapa::ostream& fwd_valToShuf, + tapa::ostream& fwd_valToStore_0, + tapa::ostream& inv_valToBU, + bool direction, + VAR_TYPE_16 iter); + +// /******************************************************************************************** +// * Dual interface FIFO tasks * +// ********************************************************************************************/ + +void dual_interface_FIFO_receive( + tapa::istream& fwd_inVal, + tapa::istream& inv_inVal, + tapa::ostream& common_outVal, + bool direction); + +void dual_interface_FIFO_send( + tapa::istream& common_inVal, + tapa::ostream& fwd_outVal, + tapa::ostream& inv_outVal, + bool direction); + +// /******************************************************************************************** +// * Top kernel * +// ********************************************************************************************/ + +void NTT_kernel( + uint64_t polyVectorInOut_G0, + uint64_t TFArr_G0, + uint64_t TFArr_G1, + uint64_t polyVectorInOut_G1, + WORD q0, + WORD twoInverse0, + WORD_PLUS3 factor0, + bool direction, + VAR_TYPE_16 iter + ) +; diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa.h new file mode 100644 index 000000000000..7f4e7f2b8553 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa.h @@ -0,0 +1,20 @@ +#ifndef TAPA_TAPA_H_ +#define TAPA_TAPA_H_ + +// added a hard definition because we never +// perform C simulation +#define TAPA_TARGET_ (XILINX_HLS) + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/tapa.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/tapa.h" + +#endif + +#include "tapa/traits.h" + +#endif // TAPA_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/buffer.h new file mode 100644 index 000000000000..492be21d1cbf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/buffer.h @@ -0,0 +1,30 @@ +#ifndef TAPA_BASE_BUFFER_H +#define TAPA_BASE_BUFFER_H + +namespace tapa { + +struct normal {}; +struct complete {}; + +template +struct cyclic { + const int factor = ft; +}; + +template +struct block { + const int factor = ft; +}; + +template +struct array_partition {}; + +struct bram {}; +struct uram {}; + +template +struct memcore {}; + +} // namespace tapa + +#endif // TAPA_BASE_BUFFER_H \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/mmap.h new file mode 100644 index 000000000000..03d7fef9bd74 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/mmap.h @@ -0,0 +1,6 @@ +#ifndef TAPA_BASE_MMAP_H_ +#define TAPA_BASE_MMAP_H_ + +namespace tapa {} // namespace tapa + +#endif // TAPA_BASE_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/stream.h new file mode 100644 index 000000000000..6baed1f76f5a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/stream.h @@ -0,0 +1,20 @@ +#ifndef TAPA_BASE_STREAM_H_ +#define TAPA_BASE_STREAM_H_ + +namespace tapa { + +inline constexpr int kStreamDefaultDepth = 2; + +namespace internal { + +template +struct elem_t { + T val; + bool eot; +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_BASE_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/tapa.h new file mode 100644 index 000000000000..79e469322156 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/tapa.h @@ -0,0 +1,12 @@ +#ifndef TAPA_BASE_TAPA_H_ +#define TAPA_BASE_TAPA_H_ + +#include "tapa/base/mmap.h" +#include "tapa/base/stream.h" +#include "tapa/base/util.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/base/buffer.h" +#endif + +#endif // TAPA_BASE_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/task.h new file mode 100644 index 000000000000..ab7905345b6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/task.h @@ -0,0 +1,37 @@ +#ifndef TAPA_BASE_TASK_H_ +#define TAPA_BASE_TASK_H_ + +namespace tapa { + +inline constexpr int join = 0; +inline constexpr int detach = -1; + +/// Class that generates a sequence of integers as task arguments. +/// +/// Canonical usage: +/// @code{.cpp} +/// void TaskFoo(int i, ...) { +/// ... +/// } +/// tapa::task() +/// .invoke<3>(TaskFoo, tapa::seq(), ...) +/// ... +/// ; +/// @endcode +/// +/// @c TaskFoo will be invoked three times, receiving @c 0, @c 1, and @c 2 as +/// the first argument, respectively. +struct seq { + /// Constructs a @c tapa::seq. This is the only public API. + seq() = default; + + seq(const seq&) = delete; + seq(seq&&) = delete; + seq& operator=(const seq&) = delete; + seq& operator=(seq&&) = delete; + int pos = 0; +}; + +} // namespace tapa + +#endif // TAPA_BASE_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/util.h new file mode 100644 index 000000000000..7aa9f95d3174 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/base/util.h @@ -0,0 +1,96 @@ +#ifndef TAPA_BASE_UTIL_H_ +#define TAPA_BASE_UTIL_H_ + +#include +#include + +#include +#include + +namespace tapa { + +namespace internal { + +template +inline constexpr int widthof(int) { + return T::width; +} + +template +inline constexpr int widthof(short) { + return sizeof(T) * CHAR_BIT; +} + +} // namespace internal + +/// Queries width (in bits) of the type. +/// +/// @tparam T Type to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof() { + return internal::widthof(0); +} + +/// Queries width (in bits) of the object. +/// +/// @note Unlike @c sizeof, the argument expression is evaluated (though +/// unused). +/// @tparam T Type of @c object. +/// @param object Object to be queried. +/// @return @c T::width if it exists, `sizeof(T) * CHAR_BIT` otherwise. +template +inline constexpr int widthof(T object) { + return internal::widthof(0); +} + +template +inline constexpr uint64_t round_up_div(uint64_t i) { + return ((i - 1) / N + 1); +} + +template +inline constexpr uint64_t round_up(uint64_t i) { + return ((i - 1) / N + 1) * N; +} + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept; + +template +T reg(T x); + +template +struct packet { + Addr addr; + Payload payload; +}; + +template +inline std::ostream& operator<<(std::ostream& os, + const packet& obj) { + return os << "{addr: " << obj.addr << ", payload: " << obj.payload << "}"; +} + +} // namespace tapa + +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + if (tapa_##fifo##_valid) + +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid) + +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + if (tapa_##fifo1##_valid && tapa_##fifo2##_valid && tapa_##fifo3##_valid) + +#endif // TAPA_BASE_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/buffer.h new file mode 100644 index 000000000000..33ed182c5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/buffer.h @@ -0,0 +1,486 @@ +#ifndef TAPA_HOST_BUFFER_H_ +#define TAPA_HOST_BUFFER_H_ + +#include "tapa/base/buffer.h" +#include "tapa/host/stream.h" + +namespace tapa { + +template +class buffer; + +template +class ibuffer; + +template +class obuffer; + +template +class section; + +template +class buffers; + +template +class ibuffers; + +template +class obuffers; + +namespace internal { + +template +class basic_buffers; + +template +struct buffer_data { + buffer_data(const std::string& name = "") + : name(name), ptr(new T[n_sections]) { + for (int i = 0; i < n_sections; i++) { + free_sections.write(i); + } + free_sections.set_name(name + "'s free sections FIFO"); + occupied_sections.set_name(name + "'s occupied sections FIFO"); + } + + ~buffer_data() { + // to avoid the warning that filled FIFOs were destroyed + for (int i = 0; i < n_sections; i++) { + free_sections.read(); + } + } + + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { + this->name = name; + free_sections.set_name(this->name + "'s free sections FIFO"); + occupied_sections.set_name(this->name + "'s occupied sections FIFO"); + } + + stream free_sections; + stream occupied_sections; + // the memory buffer is an std::array wrapped by std::shared_ptr because + // while being passed down to the task, the buffer object gets copied + // because of std::forward; it should be a single unique buffer in all + // copies and should not be freed when these copies go out of scope; + // std::shared_ptr insures this + std::shared_ptr ptr; + std::string name; +}; + +template +class basic_buffer { + protected: + basic_buffer(const std::shared_ptr>& ptr) + : inner_data(ptr) {} + + basic_buffer(const basic_buffer&) = default; + basic_buffer(basic_buffer&&) = default; + basic_buffer& operator=(const basic_buffer&) = default; + basic_buffer& operator=(basic_buffer&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return inner_data->get_name(); } + void set_name(const std::string& name) { inner_data->set_name(name); } + + public: + std::shared_ptr> inner_data; +}; + +} // namespace internal + +/// Provides producer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +// +/// Example usage as follows. +/// ```cpp +/// void producer_task(tapa::obuffer& buf_out, ...) { +/// { +/// // acquire a free section of buf_out +/// auto buf_out_accessor = buf_out.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_out_accessor[i] = ...; +/// } +/// // as buf_out_accessor goes out of scope, the +/// // section is marked as occupied so the +/// // consumer side can read it +/// } +/// } +/// ``` +template +class obuffer : public virtual internal::basic_buffer { + protected: + obuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, true); } +}; + +/// Provides consumer-side access to a @c tapa::buffer object where it is used +/// as an @a input +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +/// +/// Example usage as follows. +/// ```cpp +/// void consumer_task(tapa::ibuffer& buf_in, ...) { +/// { +/// // acquire an occupied section of buf_in +/// auto buf_in_accessor = buf_in.acquire(); +/// // read/write the section like a regular array +/// for(int i = 0; i < BUF_SIZE; i++) { +/// buf_in_accessor[i] = ...; +/// } +/// // as buf_in_accessor goes in of scope, the +/// // section is marked as free so the producer +/// // side can write to it again +/// } +/// } +/// ``` +template +class ibuffer : public virtual internal::basic_buffer { + protected: + ibuffer() : internal::basic_buffer(nullptr) {} + + public: + using section_t = section; + section_t acquire() { return section_t(*this, false); } +}; + +// diamond inheritance so that `buffer&` can be cast to `ibuffer&` and +// `obuffer&` but they can't be cast to each other + +/// Defines a PingPong Buffer based communication channel between +/// two task instances. +/// +/// To use the PingPong buffer, instantiate `tapa::buffer` in parent +/// task and pass it either as `tapa::ibuffer` or `tapa::obuffer` +/// reference to children tasks. +/// +/// Internally, the buffer object keeps multiple sections, indicated +/// by the template parameter @c n_sections. A section is said to be +/// free if it can be written to by the producer task and it is said to +/// be occupied if it can be read from by the consumer task. +/// +/// @tparam T the data type to store in the buffer +/// @tparam n_sections the total number of PingPong buffers; mostly two. +template +class buffer : public ibuffer, + public obuffer { + public: + buffer(const std::string& name = "") + : internal::basic_buffer( + std::make_shared>(name)) {} +}; + +// A helper class to let users access a section of +// the pingpong buffer memory core +template +class section { + public: + T& operator()() { return data.inner_data->ptr[section_id]; } + const T& operator()() const { return data.inner_data->ptr[section_id]; } + + ~section() { + if (for_producer) { + data.inner_data->occupied_sections.write(section_id); + } else { + data.inner_data->free_sections.write(section_id); + } + } + + private: + using buffer_t = internal::basic_buffer; + + // section class should be instantiated only by an `ibuffer` + // or `obuffer`; Hence private constructor and friend class + // declarations + friend class obuffer; + friend class ibuffer; + + // block on the src fifo for the section ID + section(buffer_t& buf, bool for_producer = true) + : data(buf), for_producer(for_producer) { + if (for_producer) { + section_id = data.inner_data->free_sections.read(); + } else { + section_id = data.inner_data->occupied_sections.read(); + } + } + + // the actual buffer object and the section_id this instance + // is supposed to access + buffer_t& data; + int section_id; + // whether the instance is for a producer task or a consumer task + const bool for_producer; +}; + +namespace internal { + +template +class basic_buffers { + // TODO: This shouldn't be public as `ibuffers` and `obuffers` + // are both friend classes, for some reason, g++ compiles that fine + // however we run into trouble with Clang. Before I get to the bottom + // of this, I'm making metadata_t public. This should be fixed! + public: + using buffer_t = buffer; + + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + const std::string name; + const int pos; + std::vector refs; + }; + + protected: + template + friend class ibuffers; + + template + friend class obuffers; + + template + friend class buffers; + + basic_buffers(const std::shared_ptr& ptr) : ptr(ptr) {} + basic_buffers(const basic_buffers&) = default; + basic_buffers(basic_buffers&&) = default; + basic_buffers& operator=(const basic_buffers&) = default; + basic_buffers& operator=(basic_buffers&&) = delete; // -Wvirtual-move-assign + + const std::string& get_name() const { return ptr->name; } + void set_name(const std::string& name) { ptr->name = name; } + + buffer_t operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::shared_ptr ptr; +}; + +} // namespace internal + +template +class ibuffers + : public virtual internal::basic_buffers { + using ibuffer_t = ibuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + ibuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class ibuffers; + + int access_pos_ = 0; + + ibuffers() : basic_buffers_t(nullptr) {} + + buffer access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ibuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + ibuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + ibuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + ibuffer_t access() { return access_(); } +}; + +template +class obuffers + : public virtual internal::basic_buffers { + using obuffer_t = obuffer; + using buffer_t = buffer; + using basic_buffers_t = internal::basic_buffers; + + template + using obuffers_slice_t = obuffers; + + template + using basic_buffers_slice_t = + internal::basic_buffers; + + public: + obuffer_t& operator[](int pos) const { return this->ptr->refs[pos]; } + + protected: + template + friend struct internal::accessor; + + template + friend class obuffers; + + int access_pos_ = 0; + + obuffers() : basic_buffers_t(nullptr) {} + + buffer_t access_() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as obuffer for " + << access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return basic_buffers_t::operator[](access_pos_++); + } + + template + obuffers_slice_t access() { + CHECK_NOTNULL(this->ptr.get()); + obuffers_slice_t result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; i++) { + result.ptr->refs.emplace_back(access_()); + } + return result; + } + + obuffer_t access() { return access_(); } +}; + +template +class buffers : public ibuffers, + public obuffers { + using basic_buffers_t = internal::basic_buffers; + using ibuffer_t = ibuffer; + using obuffer_t = obuffer; + using buffer_t = buffer; + + using ibuffers_t = ibuffers; + using obuffers_t = obuffers; + + template + using ibuffers_slice_t = ibuffers; + + template + using obuffers_slice_t = obuffers; + + public: + buffers(const std::string& name = "") + : basic_buffers_t( + std::make_shared(name, 0)) { + this->ptr->refs.reserve(len); + for (int i = 0; i < len; i++) { + this->ptr->refs.emplace_back(name + ":" + std::to_string(i)); + } + } + + buffer_t operator[](int pos) const { + return basic_buffers_t::operator[](pos); + } + + protected: + template + friend struct internal::accessor; + + obuffer_t access_as_obuffer() { return obuffers_t::access(); } + + template + obuffers_slice_t access_as_obuffers() { + return obuffers_t::template access(); + } + + template + ibuffers_slice_t access_as_ibuffers() { + return ibuffers_t::template access(); + } + + ibuffer_t access_as_ibuffer() { return ibuffers_t::access(); } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/obuffer, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffer access( \ + buffers& arg) { \ + return arg.access_as_##io##buffer(); \ + } \ + }; \ + \ + /* param = i/obuffer, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffer access( \ + io##buffers& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = buffers */ \ + template \ + struct accessor reference, \ + buffers&> { \ + static io##buffers access( \ + buffers& arg) { \ + return arg.template access_as_##io##buffers(); \ + } \ + }; \ + \ + /* param = i/obuffers, arg = i/obuffers */ \ + template \ + struct accessor reference, \ + io##buffers&> { \ + static io##buffers access( \ + io##buffers& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_BUFFER_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/coroutine.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/coroutine.h new file mode 100644 index 000000000000..b4d4ad3472bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/coroutine.h @@ -0,0 +1,14 @@ +#ifndef TAPA_HOST_COROUTINE_H_ +#define TAPA_HOST_COROUTINE_H_ + +#include +#include + +namespace tapa { +namespace internal { +void schedule(bool detach, const std::function&); +void yield(const std::string& msg); +} // namespace internal +} // namespace tapa + +#endif // TAPA_HOST_COROUTINE_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/logging.h new file mode 100644 index 000000000000..47cbbedc2d2e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/logging.h @@ -0,0 +1,7 @@ + +#ifndef TAPA_HOST_LOGGING_H_ +#define TAPA_HOST_LOGGING_H_ + +#include + +#endif // TAPA_HOST_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/mmap.h new file mode 100644 index 000000000000..fa548cc0cb07 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/mmap.h @@ -0,0 +1,566 @@ +#ifndef TAPA_HOST_MMAP_H_ +#define TAPA_HOST_MMAP_H_ + +#include + +#include +#include +#include +#include + +#include + +#include "tapa/base/mmap.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/stream.h" +#include "tapa/host/vec.h" + +namespace tapa { + +namespace internal { + +template +struct accessor; + +} // namespace internal + +template +class async_mmap; + +/// Defines a view of a piece of consecutive memory with synchronous random +/// accesses. +template +class mmap { + public: + /// Constructs a @c tapa::mmap with unknown size. + /// + /// @param ptr Pointer to the start of the mapped memory. + explicit mmap(T* ptr) : ptr_{ptr}, size_{0} {} + + /// Constructs a @c tapa::mmap with the given @c size. + /// + /// @param ptr Pointer to the start of the mapped memory. + /// @param size Size of the mapped memory (in unit of element count). + mmap(T* ptr, uint64_t size) : ptr_{ptr}, size_{size} {} + + /// Constructs a @c tapa::mmap from the given @c container. + /// + /// @param container Container holding a @c tapa::mmap. Must implement + /// @c data() and @c size(). + template + explicit mmap(Container& container) + : ptr_{container.data()}, size_{container.size()} {} + + /// Implicitly casts to a regular pointer. + /// + /// @c tapa::mmap should be used just like a pointer in the kernel. + operator T*() { return ptr_; } + + /// Increments the start of the mapped memory. + /// + /// @return The incremented @c tapa::mmap. + mmap& operator++() { + ++ptr_; + return *this; + } + + /// Decrements the start of the mapped memory. + /// + /// @return The decremented @c tapa::mmap. + mmap& operator--() { + --ptr_; + return *this; + } + + /// Increments the start of the mapped memory. + /// + /// @return The @c tapa::mmap before incrementation. + mmap operator++(int) { return mmap(ptr_++); } + + /// Decrements the start of the mapped memory. + /// + /// @return The @c tapa::mmap before decrementation. + mmap operator--(int) { return mmap(ptr_--); } + + /// Retrieves the start of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The start of the mapped memory. + T* get() const { return ptr_; } + + /// Retrieves the size of the mapped memory. + /// + /// This should be used on the host only. + /// + /// @return The size of the mapped memory (in unit of element count). + uint64_t size() const { return size_; } + + /// Reinterprets the element type of the mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same piece of memory but of type + /// tapa::vec_t. + template + mmap> vectorized() const { + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << size() << ", N = " << N << ", but " << size() << " % " << N + << " != 0"; + return mmap>(reinterpret_cast*>(get()), size() / N); + } + + /// Reinterprets the element type of the mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointer must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T), the size of mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T), @c sizeof(T) must be a multiple of + /// @c sizeof(U). + /// + /// @tparam U The new element type. + /// @return @c tapa::mmap of the same piece of memory. + template + mmap reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + if (sizeof(U) > sizeof(T)) { + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + CHECK_EQ(size() % N, 0) + << "size of mmap must be a multiple of N (= sizeof(U)/sizeof(T)) " + "when reinterpreted as mmap (i.e., `reinterpret()`); got " + "size = " + << size() << ", N = " << sizeof(U) << " / " << sizeof(T) << " = " << N + << ", but " << size() << " % " << N << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + return mmap(reinterpret_cast(get()), size() * sizeof(T) / sizeof(U)); + } + + protected: + T* ptr_; + uint64_t size_; +}; + +/// Defines a view of a piece of consecutive memory with asynchronous random +/// accesses. +template +class async_mmap : public mmap { + public: + /// Type of the addresses. + using addr_t = int64_t; + + /// Type of the write responses. + using resp_t = uint8_t; + + private: + using super = mmap; + + stream read_addr_q_{"read_addr"}; + stream read_data_q_{"read_data"}; + stream write_addr_q_{"write_addr"}; + stream write_data_q_{"write_data"}; + stream write_resp_q_{"write_resp"}; + + // Only convert when scheduled. + async_mmap(const super& mem) + : super(mem), + read_addr(read_addr_q_), + read_data(read_data_q_), + write_addr(write_addr_q_), + write_data(write_data_q_), + write_resp(write_resp_q_) {} + + // Must be operated via the read/write addr/data stream APIs. + operator T*() { return super::ptr_; } + + // Dereference not permitted. + T& operator[](std::size_t idx) { return super::ptr_[idx]; } + const T& operator[](std::size_t idx) const { return super::ptr_[idx]; } + T& operator*() { return *super::ptr_; } + const T& operator*() const { return *super::ptr_; } + + // Increment / decrement not permitted. + T& operator++() { return *++super::ptr_; } + T& operator--() { return *--super::ptr_; } + T operator++(int) { return *super::ptr_++; } + T operator--(int) { return *super::ptr_--; } + + // Arithmetic not permitted. + async_mmap operator+(std::ptrdiff_t diff) { return super::ptr_ + diff; } + async_mmap operator-(std::ptrdiff_t diff) { return super::ptr_ - diff; } + std::ptrdiff_t operator-(async_mmap ptr) { return super::ptr_ - ptr; } + + public: + /// Provides access to the read address channel. + /// + /// Each value written to this channel triggers an asynchronous memory read + /// request. Consecutive requests may be coalesced into a long burst request. + ostream read_addr; + + /// Provides access to the read data channel. + /// + /// Each value read from this channel represents the data retrieved from the + /// underlying memory system. + istream read_data; + + /// Provides access to the write address channel. + /// + /// Each value written to this channel triggers an asynchronous memory write + /// request. Consecutive requests may be coalesced into a long burst request. + ostream write_addr; + + /// Provides access to the write data channel. + /// + /// Each value written to this channel supplies data to the memory write + /// request. + ostream write_data; + + /// Provides access to the write response channel. + /// + /// Each value read from this channel represents the data count acknowledged + /// by the underlying memory system. + istream write_resp; + + void operator()() { + int16_t write_count = 0; + for (;;) { + if (!read_addr_q_.empty() && !read_data_q_.full()) { + const auto addr = read_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + read_data_q_.write(this->ptr_[addr]); + } + if (write_count != 256 && !write_addr_q_.empty() && + !write_data_q_.empty()) { + const auto addr = write_addr_q_.read(); + CHECK_GE(addr, 0); + if (addr != 0) { + CHECK_LT(addr, this->size_); + } + this->ptr_[addr] = write_data_q_.read(); + ++write_count; + } else if (write_count > 0 && + this->write_resp_q_.try_write(resp_t(write_count - 1))) { + CHECK_LE(write_count, 256); + write_count = 0; + } + } + } + + static async_mmap schedule(super mem) { + // a copy of async_mem is stored in std::function + async_mmap async_mem(mem); + internal::schedule(/*detach=*/true, async_mem); + return async_mem; + } +}; + +/// Defines an array of @c tapa::mmap. +template +class mmaps { + protected: + std::vector> mmaps_; + + public: + /// Constructs a @c tapa::mmap array from the given @c pointers and @c sizes. + /// + /// @param ptrs Pointers to the start of the array of mapped memory. + /// @param sizes Sizes of each mapped memory (in unit of element count). + template + mmaps(const PtrContainer& pointers, const SizeContainer& sizes) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(pointers[i], sizes[i]); + } + } + + /// Constructs a @c tapa::mmap array from the given @c container. + /// + /// @param container Container holding an array of @c tapa::mmap. @c container + /// must implement @c operator[] that returns a container + /// suitable for constructing a @c tapa::mmap. + template + explicit mmaps(Container& container) { + for (uint64_t i = 0; i < S; ++i) { + mmaps_.emplace_back(container[i]); + } + } + + // defaultd copy constructor + mmaps(const mmaps&) = default; + // default move constructor + mmaps(mmaps&&) = default; + // defaultd copy assignment operator + mmaps& operator=(const mmaps&) = default; + // default move assignment operator + mmaps& operator=(mmaps&&) = default; + + /// References a @c tapa::mmap in the array. + mmap& operator[](int idx) { return mmaps_[idx]; }; + + template + mmaps slice() { + static_assert(offset + length < S, "invalid slice"); + mmaps result; + for (uint64_t i = 0; i < length; ++i) { + result.mmaps_[i] = this->mmaps_[offset + i]; + } + return result; + } + + /// Reinterprets the element type of each mapped memory as + /// tapa::vec_t. + /// + /// This should be used on the host only. + /// The size of each mapped memory must be a multiple of @c N. + /// + /// @tparam N Vector length of the new element type. + /// @return @c tapa::mmap of the same pieces of memory but of type + /// tapa::vec_t. + template + mmaps, S> vectorized() const { + std::array*, S> ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N when vectorized as a " + "mmap> (i.e., `vectorized()`); got size = " + << mmaps_[i].size() << ", N = " << N << ", but " << mmaps_[i].size() + << " % " << N << " != 0"; + ptrs[i] = reinterpret_cast*>(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() / N; + } + return mmaps, S>(ptrs, sizes); + } + + /// Reinterprets the element type of each mapped memory as @c U. + /// + /// This should be used on the host only. + /// Both @c T and @c U must have standard layout. + /// The host memory pointers must be properly aligned. + /// If @c sizeof(U) > @c sizeof(T) , the size of each mapped memory must be a + /// multiple of @c sizeof(U)/sizeof(T) (which must be an integer itself). + /// If @c sizeof(U) < @c sizeof(T) , @c sizeof(T) must be a multiple of + /// @c sizeof(N). + /// + /// @tparam U The new element type. + /// @return tapa::mmaps of the same pieces of memory. + template + mmaps reinterpret() const { + static_assert(std::is_standard_layout::value, + "T must have standard layout"); + static_assert(std::is_standard_layout::value, + "U must have standard layout"); + + std::array ptrs; + std::array sizes; + for (uint64_t i = 0; i < S; ++i) { + if (sizeof(U) > sizeof(T)) { + CHECK_EQ(sizeof(U) % sizeof(T), 0) + << "sizeof(U) must be a multiple of sizeof(T) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(U) = " + << sizeof(U) << ", sizeof(T) = " << sizeof(T); + constexpr auto N = sizeof(U) / sizeof(T); + CHECK_EQ(mmaps_[i].size() % N, 0) + << "size of mmap must be a multiple of N (= " + "sizeof(U)/sizeof(T)) when reinterpreted as mmap (i.e., " + "`reinterpret()`); got size = " + << mmaps_[i].size() << ", N = " << sizeof(U) << " / " << sizeof(T) + << " = " << N << ", but " << mmaps_[i].size() << " % " << N + << " != 0"; + } else if (sizeof(U) < sizeof(T)) { + CHECK_EQ(sizeof(T) % sizeof(U), 0) + << "sizeof(T) must be a multiple of sizeof(U) when mmap is " + "reinterpreted as mmap (i.e., `reinterpret()`); got " + "sizeof(T) = " + << sizeof(T) << ", sizeof(U) = " << sizeof(U); + } + CHECK_EQ(reinterpret_cast(mmaps_[i].get()) % alignof(U), 0) + << "data of mmap must be " << alignof(U) + << "-byte aligned when reinterpreted as mmap (i.e., " + "`reinterpret()`) because alignof(U) = " + << alignof(U); + ptrs[i] = reinterpret_cast(mmaps_[i].get()); + sizes[i] = mmaps_[i].size() * sizeof(T) / sizeof(U); + } + return mmaps(ptrs, sizes); + } + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + mmap access() { + LOG_IF(WARNING, access_pos_ >= S) + << "invocation #" << access_pos_ << " accesses mmaps[" + << access_pos_ % S << "]"; + return mmaps_[access_pos_++ % S]; + } +}; + +// Host-only mmap types that must have correct size. +#define TAPA_DEFINE_MMAP(tag) \ + template \ + class tag##_mmap : public mmap { \ + tag##_mmap(T* ptr) : mmap(ptr) {} \ + \ + public: \ + using mmap::mmap; \ + tag##_mmap(const mmap& base) : mmap(base) {} \ + \ + template \ + tag##_mmap> vectorized() const { \ + return mmap::template vectorized(); \ + } \ + template \ + tag##_mmap reinterpret() const { \ + return mmap::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAP(placeholder); +TAPA_DEFINE_MMAP(read_only); +TAPA_DEFINE_MMAP(write_only); +TAPA_DEFINE_MMAP(read_write); +#undef TAPA_DEFINE_MMAP +#define TAPA_DEFINE_MMAPS(tag) \ + template \ + class tag##_mmaps : public mmaps { \ + tag##_mmaps(const std::array& ptrs) : mmaps(ptrs){}; \ + \ + public: \ + using mmaps::mmaps; \ + tag##_mmaps(const mmaps& base) : mmaps(base) {} \ + \ + template \ + tag##_mmaps, S> vectorized() const { \ + return mmaps::template vectorized(); \ + } \ + template \ + tag##_mmaps reinterpret() const { \ + return mmaps::template reinterpret(); \ + } \ + } +TAPA_DEFINE_MMAPS(placeholder); +TAPA_DEFINE_MMAPS(read_only); +TAPA_DEFINE_MMAPS(write_only); +TAPA_DEFINE_MMAPS(read_write); +#undef TAPA_DEFINE_MMAPS + +namespace internal { + +template +struct accessor, mmap&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmap& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg); + } +}; + +template +struct accessor&, mmap&> { + static async_mmap access(mmap& arg) { + return async_mmap::schedule(arg); + } +}; + +template +struct accessor, mmaps&> { + static mmap access(mmaps& arg) { return arg.access(); } +}; + +template +struct accessor, mmaps&> { + [[deprecated("please use async_mmap& in formal parameters")]] // + static async_mmap + access(mmaps& arg) { + LOG_FIRST_N(ERROR, 1) << "please use async_mmap& in formal parameters"; + return async_mmap::schedule(arg.access()); + } +}; + +template +struct accessor&, mmaps&> { + static async_mmap access(mmaps& arg) { + return async_mmap::schedule(arg.access()); + } +}; + +#define TAPA_DEFINE_ACCESSER(tag, frt_tag) \ + template \ + struct accessor, tag##_mmap> { \ + static mmap access(tag##_mmap arg) { return arg; } \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmap arg) { \ + auto buf = fpga::frt_tag(arg.get(), arg.size()); \ + instance.SetArg(idx++, buf); \ + } \ + }; \ + template \ + struct accessor, tag##_mmaps> { \ + static void access(fpga::Instance& instance, int& idx, \ + tag##_mmaps arg) { \ + for (uint64_t i = 0; i < S; ++i) { \ + auto buf = fpga::frt_tag(arg[i].get(), arg[i].size()); \ + instance.SetArg(idx++, buf); \ + } \ + } \ + } +TAPA_DEFINE_ACCESSER(placeholder, Placeholder); +// read/write are with respect to the kernel in tapa but host in frt +TAPA_DEFINE_ACCESSER(read_only, WriteOnly); +TAPA_DEFINE_ACCESSER(write_only, ReadOnly); +TAPA_DEFINE_ACCESSER(read_write, ReadWrite); +#undef TAPA_DEFINE_ACCESSER +template +struct accessor, mmap> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmap/read_only_mmap/write_only_mmap/" + "read_write_mmap in tapa::invoke"); +}; +template +struct accessor, mmaps> { + static_assert(!std::is_same::value, + "must use one of " + "placeholder_mmaps/read_only_mmaps/write_only_mmaps/" + "read_write_mmaps in tapa::invoke"); +}; + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/stream.h new file mode 100644 index 000000000000..0c6c308c7573 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/stream.h @@ -0,0 +1,874 @@ +#ifndef TAPA_HOST_STREAM_H_ +#define TAPA_HOST_STREAM_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tapa/base/stream.h" + +#include "tapa/host/coroutine.h" + +namespace tapa { + +template +class istream; + +template +class ostream; + +template +class istreams; + +template +class ostreams; + +namespace internal { + +template +struct accessor; + +class base_queue { + public: + // debug helpers + const std::string& get_name() const { return this->name; } + void set_name(const std::string& name) { this->name = name; } + + protected: + std::string name; + + base_queue(const std::string& name) : name(name) {} + + virtual bool empty() const = 0; + + void check_leftover() { + if (!this->empty()) { + LOG(WARNING) << "channel '" << this->name + << "' destructed with leftovers; hardware behavior may be " + "unexpected in consecutive invocations"; + } + } +}; + +template +class lock_free_queue : public base_queue { + // producer writes to head and consumer reads from tail + // okay to keep incrementing because it'll take > 100 yr to overflow uint64_t + std::atomic tail{0}; + std::atomic head{0}; + + std::vector buffer; + + public: + // constructors + lock_free_queue(size_t depth, const std::string& name = "") + : base_queue(name) { + this->buffer.resize(depth); + } + + // debug helpers + uint64_t get_depth() const { return this->buffer.size(); } + + // basic queue operations + bool empty() const override { return this->head - this->tail <= 0; } + bool full() const { return this->head - this->tail >= this->buffer.size(); } + const T& front() const { return this->buffer[this->tail % buffer.size()]; } + T pop() { + auto val = this->front(); + ++this->tail; + return val; + } + void push(const T& val) { + this->buffer[this->head % buffer.size()] = val; + ++this->head; + } + + ~lock_free_queue() { this->check_leftover(); } +}; + +template +class locked_queue : public base_queue { + size_t depth; + mutable std::mutex mtx; + std::deque buffer; + + public: + // constructors + locked_queue(size_t depth, const std::string& name = "") + : base_queue(name), depth(depth) {} + + // debug helpers + uint64_t get_depth() const { return this->depth; } + + // basic queue operations + bool empty() const override { + std::unique_lock lock(this->mtx); + return this->buffer.empty(); + } + bool full() const { + std::unique_lock lock(this->mtx); + return this->buffer.size() >= this->depth; + } + const T& front() const { + std::unique_lock lock(this->mtx); + return this->buffer.front(); + } + T pop() { + std::unique_lock lock(this->mtx); + auto val = this->buffer.front(); + this->buffer.pop_front(); + return val; + } + void push(const T& val) { + std::unique_lock lock(this->mtx); + this->buffer.push_back(val); + } + + ~locked_queue() { this->check_leftover(); } +}; + +template +#ifdef TAPA_USE_LOCKED_QUEUE +using queue = locked_queue; +#else // TAPA_USE_LOCKED_QUEUE +using queue = lock_free_queue; +#endif // TAPA_USE_LOCKED_QUEUE + +// shared pointer of a queue +template +class basic_stream { + public: + // debug helpers + const std::string& get_name() const { return this->ptr->get_name(); } + void set_name(const std::string& name) { ptr->set_name(name); } + uint64_t get_depth() const { return this->ptr->get_depth(); } + + // not protected since we'll use std::vector> + basic_stream(const std::shared_ptr>>& ptr) : ptr(ptr) {} + basic_stream(const basic_stream&) = default; + basic_stream(basic_stream&&) = default; + basic_stream& operator=(const basic_stream&) = default; + basic_stream& operator=(basic_stream&&) = delete; // -Wvirtual-move-assign + + protected: + std::shared_ptr>> ptr; +}; + +// shared pointer of multiple queues +template +class basic_streams { + protected: + struct metadata_t { + metadata_t(const std::string& name, int pos) : name(name), pos(pos) {} + std::vector> refs; // references to the original streams + const std::string name; // name of the original streams + const int pos; // position in the original streams + }; + + basic_streams(const std::shared_ptr& ptr) : ptr({ptr}) {} + basic_streams(const basic_streams&) = default; + basic_streams(basic_streams&&) = default; + basic_streams& operator=(const basic_streams&) = default; + basic_streams& operator=(basic_streams&&) = delete; // -Wvirtual-move-assign + + basic_stream operator[](int pos) const { + CHECK_NOTNULL(ptr.get()); + CHECK_GE(pos, 0); + CHECK_LT(pos, ptr->refs.size()); + return ptr->refs[pos]; + } + + std::string get_slice_name(int length) { + return ptr->name + "[" + std::to_string(ptr->pos) + ":" + + std::to_string(ptr->pos + length) + ")"; + } + + std::shared_ptr ptr; +}; + +// stream without a bound depth; can be default-constructed by a derived class +template +class unbound_stream : public istream, public ostream { + protected: + unbound_stream() : basic_stream(nullptr) {} +}; + +// streams without a bound depth; can be default-constructed by a derived class +template +class unbound_streams : public istreams, public ostreams { + protected: + unbound_streams() : basic_streams(nullptr) {} +}; + +} // namespace internal + +/// Provides consumer-side operations to a @c tapa::stream where it is used as +/// an @a input. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is empty. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is empty. + bool empty() const { + bool is_empty = this->ptr->empty(); + if (is_empty) { + internal::yield("channel '" + this->get_name() + "' is empty"); + } + return is_empty; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_eot Uninitialized if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return Whether @c is_eot is updated. + bool try_eot(bool& is_eot) const { + if (!empty()) { + is_eot = this->ptr->front().eot; + return true; + } + return false; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @return Whether the next token is available and is EoT. + bool eot(bool& is_success) const { + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + /// Tests whether the next token is EoT. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the next token is available and is EoT. + bool eot(std::nullptr_t) const { + bool eot = false; + try_eot(eot); + return eot; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_peek(T& value) const { + if (!empty()) { + auto& elem = this->ptr->front(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' peeked when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success) const { + T val; + is_success = try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T peek(std::nullptr_t) const { + T val; + try_peek(val); + return val; + } + + /// Peeks the stream. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @param[out] is_success Whether the next token is available. + /// @param[out] is_eot Set to @c false if the stream is empty. Otherwise, + /// updated to indicate whether the next token is EoT. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T peek(bool& is_success, bool& is_eot) const { + if (!empty()) { + auto& elem = this->ptr->front(); + is_success = true; + is_eot = elem.eot; + return elem.val; + } + is_success = false; + is_eot = false; + return {}; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value Uninitialized if the stream is empty. Otherwise, updated + /// to be the value of the next token. + /// @return Whether @c value is updated. + bool try_read(T& value) { + if (!empty()) { + auto elem = this->ptr->pop(); + if (elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() << "' read when closed"; + } + value = elem.val; + return true; + } + return false; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token. + T read() { + T val; + while (!try_read(val)) { + } + return val; + } + + /// Reads the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] value The value of the next token. + /// @return @c *this. + istream& operator>>(T& value) { + value = read(); + return *this; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @param[out] is_success Whether the next token is available. + /// @return The value of the next token is returned if it is + /// available. Otherwise, default-constructed @c T() is + /// returned. + T read(bool& is_success) { + T val; + is_success = try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must not be EoT. + /// + /// @return The value of the next token is returned if it is available. + /// Otherwise, default-constructed @c T() is returned. + T read(std::nullptr_t) { + T val; + try_read(val); + return val; + } + + /// Reads the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] default_value Value to return if the stream is empty. + /// @param[out] is_success Updated to indicate whether the next token is + /// available if @c is_success is not @c nullptr. + /// @return The value of the next token is returned if it is + /// available. Otherwise, @c default_value is + /// returned. + T read(const T& default_value, bool* is_success = nullptr) { + T val; + bool succeeded = try_read(val); + if (is_success != nullptr) { + *is_success = succeeded; + } + return succeeded ? val : default_value; + } + + /// Consumes an EoT token. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// The next token must be EoT. + /// + /// @return Whether an EoT token is consumed. + bool try_open() { + if (!empty()) { + auto elem = this->ptr->pop(); + if (!elem.eot) { + LOG(FATAL) << "channel '" << this->get_name() + << "' opened when not closed"; + } + return true; + } + return false; + } + + /// Consumes an EoT token. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// The next token must be EoT. + void open() { + while (!try_open()) { + } + } + + protected: + // allow derived class to omit initialization + istream() : internal::basic_stream(nullptr) {} + + private: + // allow istreams and streams to return istream + template + friend class istreams; + template + friend class streams; + istream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides producer-side operations to a @c tapa::stream where it is used as +/// an @a output. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostream : virtual public internal::basic_stream { + public: + /// Tests whether the stream is full. + /// + /// This is a @a non-blocking and @a non-destructive operation. + /// + /// @return Whether the stream is full. + bool full() const { + bool is_full = this->ptr->full(); + if (is_full) { + internal::yield("channel '" + this->get_name() + "' is full"); + } + return is_full; + } + + /// Writes @c value to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return Whether @c value has been written successfully. + bool try_write(const T& value) { + if (!full()) { + this->ptr->push({value, false}); + return true; + } + return false; + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + void write(const T& value) { + while (!try_write(value)) { + } + } + + /// Writes @c value to the stream. + /// + /// This is a @a blocking and @a destructive operation. + /// + /// @param[in] value The value to write. + /// @return @c *this. + ostream& operator<<(const T& value) { + write(value); + return *this; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a non-blocking and @a destructive operation. + /// + /// @return Whether the EoT token has been written successfully. + bool try_close() { + if (!full()) { + this->ptr->push({{}, true}); + return true; + } + return false; + } + + /// Produces an EoT token to the stream. + /// + /// This is a @a blocking and @a destructive operation. + void close() { + while (!try_close()) { + } + } + + protected: + // allow derived class to omit initialization + ostream() : internal::basic_stream(nullptr) {} + + private: + // allow ostreams and streams to return ostream + template + friend class ostreams; + template + friend class streams; + ostream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Defines a communication channel between two task instances. +template +class stream : public internal::unbound_stream { + public: + /// Depth of the communication channel. + constexpr static int depth = N; + + /// Constructs a @c tapa::stream. + stream() + : internal::basic_stream( + std::make_shared>>(N)) {} + + /// Constructs a @c tapa::stream with the given name for debugging. + /// + /// @param[in] name Name of the communication channel (for debugging only). + template + stream(const char (&name)[S]) + : internal::basic_stream( + std::make_shared>>(N, name)) {} + + private: + template + friend class streams; + stream(const internal::basic_stream& base) + : internal::basic_stream(base) {} +}; + +/// Provides consumer-side operations to an array of @c tapa::stream where they +/// are used as @a inputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class istreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::istream referenced in the array. + istream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + istreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return istreams + template + friend class streams; + + // allow istreams of any length to return istreams + template + friend class istreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + istream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "istream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + istreams access() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Provides producer-side operations to an array of @c tapa::stream where they +/// are used as @a outputs. +/// +/// This class should only be used in task function parameters and should never +/// be instatiated directly. +template +class ostreams : virtual public internal::basic_streams { + public: + /// Length of the @c tapa::stream array. + constexpr static int length = S; + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::ostream referenced in the array. + ostream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + } + + protected: + // allow derived class to omit initialization + ostreams() : internal::basic_streams(nullptr) {} + + // allow streams of any length to return ostreams + template + friend class streams; + + // allow ostreams of any length to return istreams + template + friend class ostreams; + + private: + template + friend struct internal::accessor; + + int access_pos_ = 0; + + ostream access() { + CHECK_LT(access_pos_, this->ptr->refs.size()) + << "ostream slice '" << this->get_slice_name(length) + << "' accessed for " << access_pos_ + 1 + << " times but it only contains " << this->ptr->refs.size() + << " channels"; + return this->ptr->refs[access_pos_++]; + } + template + ostreams access() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, this->ptr->pos); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access()); + } + return result; + } +}; + +/// Defines an array of @c tapa::stream. +template +class streams : public internal::unbound_streams { + public: + /// Count of @c tapa::stream in the array. + constexpr static int length = S; + + /// Depth of each @c tapa::stream in the array. + constexpr static int depth = N; + + /// Constructs a @c tapa::streams array. + streams() + : internal::basic_streams( + std::make_shared::metadata_t>( + "", 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>(N)); + } + } + + /// Constructs a @c tapa::streams array with the given base name for + /// debugging. + /// + /// The actual name of each @c tapa::stream would be name[i]. + /// + /// @param[in] name Base name of the streams (for debugging only). + template + streams(const char (&name)[name_length]) + : internal::basic_streams( + std::make_shared::metadata_t>( + name, 0)) { + for (int i = 0; i < S; ++i) { + this->ptr->refs.emplace_back( + std::make_shared>>( + N, this->ptr->name + "[" + std::to_string(i) + "]")); + } + } + + /// References a @c tapa::stream in the array. + /// + /// @param pos Position of the array reference. + /// @return @c tapa::stream referenced in the array. + stream operator[](int pos) const { + return internal::basic_streams::operator[](pos); + }; + + private: + template + friend struct internal::accessor; + + int istream_access_pos_ = 0; + int ostream_access_pos_ = 0; + + istream access_as_istream() { + CHECK_LT(istream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as istream for " + << istream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[istream_access_pos_++]; + } + ostream access_as_ostream() { + CHECK_LT(ostream_access_pos_, this->ptr->refs.size()) + << "channels '" << this->ptr->name << "' accessed as ostream for " + << ostream_access_pos_ + 1 << " times but it only contains " + << this->ptr->refs.size() << " channels"; + return this->ptr->refs[ostream_access_pos_++]; + } + template + istreams access_as_istreams() { + CHECK_NOTNULL(this->ptr.get()); + istreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, istream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_istream()); + } + return result; + } + template + ostreams access_as_ostreams() { + CHECK_NOTNULL(this->ptr.get()); + ostreams result; + result.ptr = + std::make_shared::metadata_t>( + this->ptr->name, ostream_access_pos_); + result.ptr->refs.reserve(length); + for (int i = 0; i < length; ++i) { + result.ptr->refs.emplace_back(access_as_ostream()); + } + return result; + } +}; + +namespace internal { + +#define TAPA_DEFINE_ACCESSER(io, reference) \ + /* param = i/ostream, arg = streams */ \ + template \ + struct accessor reference, streams&> { \ + static io##stream access(streams& arg) { \ + return arg.access_as_##io##stream(); \ + } \ + }; \ + \ + /* param = i/ostream, arg = i/ostreams */ \ + template \ + struct accessor reference, io##streams&> { \ + static io##stream access(io##streams& arg) { \ + return arg.access(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = streams */ \ + template \ + struct accessor reference, \ + streams&> { \ + static io##streams access( \ + streams& arg) { \ + return arg.template access_as_##io##streams(); \ + } \ + }; \ + \ + /* param = i/ostreams, arg = i/ostreams */ \ + template \ + struct accessor reference, \ + io##streams&> { \ + static io##streams access( \ + io##streams& arg) { \ + return arg.template access(); \ + } \ + }; + +TAPA_DEFINE_ACCESSER(i, ) +TAPA_DEFINE_ACCESSER(i, &) +TAPA_DEFINE_ACCESSER(i, &&) +TAPA_DEFINE_ACCESSER(o, ) +TAPA_DEFINE_ACCESSER(o, &) +TAPA_DEFINE_ACCESSER(o, &&) + +#undef TAPA_DEFINE_ACCESSER + +} // namespace internal + +} // namespace tapa + +#endif // TAPA_HOST_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/tapa.h new file mode 100644 index 000000000000..64b5f98128b7 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/tapa.h @@ -0,0 +1,82 @@ +#ifndef TAPA_HOST_TAPA_H_ +#define TAPA_HOST_TAPA_H_ + +#include "tapa/base/tapa.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/mmap.h" +#include "tapa/host/stream.h" +#include "tapa/host/task.h" +#include "tapa/host/util.h" +#include "tapa/host/vec.h" + +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/host/buffer.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace tapa { + +// Host-only invoke that takes path to a bistream file as an argument. Returns +// the kernel time in nanoseconds. +template +inline int64_t invoke(Func&& f, const std::string& bitstream, Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke() must be a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ false, std::forward(f), bitstream, + std::forward(args)...); +} + +// Workaround for the fact that Xilinx's cosim cannot run for more than once in +// each process. The mmap pointers MUST be allocated via mmap, or the updates +// won't be seen by the caller process! +template +inline int64_t invoke_in_new_process(Func&& f, const std::string& bitstream, + Args&&... args) { + static_assert(std::is_function_v>, + "the first argument for tapa::invoke_in_new_process() must be " + "a function"); + return internal::invoker::template invoke( + /*run_in_new_process*/ true, std::forward(f), bitstream, + std::forward(args)...); +} + +template +struct aligned_allocator { + using value_type = T; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + template + void construct(U* ptr) { + ::new (static_cast(ptr)) U; + } + template + void construct(U* ptr, Args&&... args) { + ::new (static_cast(ptr)) U(std::forward(args)...); + } + T* allocate(size_t count) { + return reinterpret_cast(internal::allocate(count * sizeof(T))); + } + void deallocate(T* ptr, std::size_t count) { + internal::deallocate(ptr, count * sizeof(T)); + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/task.h new file mode 100644 index 000000000000..f4200643e71d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/task.h @@ -0,0 +1,198 @@ +#ifndef TAPA_HOST_TASK_H_ +#define TAPA_HOST_TASK_H_ + +#include "tapa/base/task.h" + +#include "tapa/host/coroutine.h" +#include "tapa/host/logging.h" + +#include +#include +#include +#include + +#include + +namespace tapa { + +namespace internal { + +template +struct accessor { + static Param access(Arg&& arg) { return arg; } + static void access(fpga::Instance& instance, int& idx, Arg&& arg) { + instance.SetArg(idx++, static_cast(arg)); + } +}; + +template +struct accessor { + static T access(seq&& arg) { return arg.pos++; } + static void access(fpga::Instance& instance, int& idx, seq&& arg) { + instance.SetArg(idx++, static_cast(arg.pos++)); + } +}; + +void* allocate(size_t length); +void deallocate(void* addr, size_t length); + +template +struct invoker; + +template +struct invoker { + template + static void invoke(bool detach, void (&f)(Params...), Args&&... args) { + // std::bind creates a copy of args + internal::schedule(detach, std::bind(f, accessor::access( + std::forward(args))...)); + } + + template + static int64_t invoke(bool run_in_new_process, void (&f)(Params...), + const std::string& bitstream, Args&&... args) { + if (bitstream.empty()) { + LOG(INFO) << "running software simulation with TAPA library"; + const auto tic = std::chrono::steady_clock::now(); + f(std::forward(args)...); + const auto toc = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(toc - tic) + .count(); + } else { + if (run_in_new_process) { + auto kernel_time_ns_raw = allocate(sizeof(int64_t)); + auto deleter = [](int64_t* p) { deallocate(p, sizeof(int64_t)); }; + std::unique_ptr kernel_time_ns( + reinterpret_cast(kernel_time_ns_raw), deleter); + if (pid_t pid = fork()) { + // Parent. + PCHECK(pid != -1); + int status = 0; + CHECK_EQ(wait(&status), pid); + CHECK(WIFEXITED(status)); + CHECK_EQ(WEXITSTATUS(status), EXIT_SUCCESS); + return *kernel_time_ns; + } + + // Child. + *kernel_time_ns = invoke(f, bitstream, std::forward(args)...); + exit(EXIT_SUCCESS); + } else { + return invoke(f, bitstream, std::forward(args)...); + } + } + } + + private: + template + static int64_t invoke(void (&f)(Params...), const std::string& bitstream, + Args&&... args) { + auto instance = fpga::Instance(bitstream); + int idx = 0; + int _[] = {( + accessor::access(instance, idx, std::forward(args)), + 0)...}; + instance.WriteToDevice(); + instance.Exec(); + instance.ReadFromDevice(); + instance.Finish(); + return instance.ComputeTimeNanoSeconds(); + } +}; + +} // namespace internal + +/// Defines a parent task instantiating children task instances. +/// +/// Canonical usage: +/// @code{.cpp} +/// tapa::task() +/// .invoke(...) +/// .invoke(...) +/// ... +/// ; +/// @endcode +/// +/// A parent task itself does not do any computation. By default, a parent task +/// will not finish until all its children task instances finish. Such children +/// task instances are @a joined to their parent. The alternative is to @a +/// detach a child from the parent. If a child task instance is instantiated and +/// detached, the parent will no longer wait for the child task to finish. +/// Detached tasks are very useful when infinite loops can be used. +struct task { + /// Constructs a @c tapa::task. + task(); + task(task&&) = delete; + task(const task&) = delete; + ~task(); + + task& operator=(task&&) = delete; + task& operator=(const task&) = delete; + + /// Invokes a task and instantiates a child task instance. + /// + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + /// Invokes a task and instantiates a child task instance with the given + /// instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + static_assert( + std::is_function_v>, + "the first argument for tapa::task::invoke() must be a function"); + internal::invoker::template invoke( + /* detach= */ mode < 0, std::forward(func), + std::forward(args)...); + return *this; + } + + /// Invokes a task @c n times and instantiates @c n child task + /// instances with the given instatiation mode. + /// + /// @tparam mode Instatiation mode (@c join or @c detach). + /// @tparam n Instatiation count. + /// @param func Task function definition of the instantiated child. + /// @param args Arguments passed to @c func. + /// @return Reference to the caller @c tapa::task. + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#endif // TAPA_HOST_TASK_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/util.h new file mode 100644 index 000000000000..e4cbd2843fa0 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/util.h @@ -0,0 +1,42 @@ +#ifndef TAPA_HOST_UTIL_H_ +#define TAPA_HOST_UTIL_H_ + +#include + +#include + +#include "tapa/base/util.h" + +// FIXME: TAPA should provide its equivalence +#ifndef ap_wait +void ap_wait(void); +#endif + +#ifndef ap_wait_n +void ap_wait_n(int); +#endif + +namespace tapa { + +/// Obtain a value of type @c To by reinterpreting the object representation of +/// @c from. +/// +/// @note This function is slightly different from C++20 @c std::bit_cast. +/// @tparam To Target type. +/// @param from Source object. +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +inline T reg(T x) { + return x; +} + +} // namespace tapa + +#endif // TAPA_HOST_UTIL_H_ \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/vec.h new file mode 100644 index 000000000000..5bbeaa957554 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/host/vec.h @@ -0,0 +1,336 @@ +#ifndef TAPA_HOST_VEC_H_ +#define TAPA_HOST_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/host/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { + return base_type::operator[](pos); + } + reference operator[](size_type pos) { return base_type::operator[](pos); } + constexpr const_reference get(size_type pos) const { return (*this)[pos]; } + void set(size_type pos, const T& value) { (*this)[pos] = value; } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { *this = val; } + + // all-element assignment operator + vec_t& operator=(T val) { + for (size_type i = 0; i < N; ++i) { + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + for (size_type i = 0; i < N; ++i) { \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { + for (size_type i = 1; i < N; ++i) { + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { + bool result = false; + for (size_type i = 0; i < N; ++i) { + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; + for (int i = 0; i < end - begin; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; + for (int i = 0; i < length; ++i) { + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; + for (int i = 0; i < N; ++i) { + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; + result.set(0, val); + for (int i = 0; i < N; ++i) { + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; + for (int i = 0; i < N1; ++i) { + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + for (int i = 0; i < N; ++i) { \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_HOST_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/stream.h new file mode 100644 index 000000000000..1c6073f84404 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/stream.h @@ -0,0 +1,14 @@ +#ifndef TAPA_STREAM_H_ +#define TAPA_STREAM_H_ + +#if !defined(TAPA_TARGET_) + +#include "tapa/host/stream.h" + +#elif TAPA_TARGET_ == XILINX_HLS + +#include "tapa/xilinx/hls/stream.h" + +#endif + +#endif // TAPA_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/traits.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/traits.h new file mode 100644 index 000000000000..f76cf7545816 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/traits.h @@ -0,0 +1,32 @@ +#ifndef TAPA_TRAITS_H_ +#define TAPA_TRAITS_H_ + +#include "tapa/stream.h" + +namespace tapa { + +template +struct elem_type {}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; +template +struct elem_type&> { + using type = T; +}; + +} // namespace tapa + +#define TAPA_ELEM_TYPE(variable) \ + typename ::tapa::elem_type::type + +#endif // TAPA_TRAITS_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/buffer.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/buffer.h new file mode 100644 index 000000000000..be04b562747a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/buffer.h @@ -0,0 +1,93 @@ +#ifndef TAPA_XILINX_HLS_BUFFER_H_ +#define TAPA_XILINX_HLS_BUFFER_H_ + +#include +#include "tapa/base/buffer.h" + +namespace tapa { + +template +class _buffer; + +template +class section { + public: + T& operator()() { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + const T& operator()() const { +#pragma HLS inline + last = true; + return buf_ref.data[section_id]; + } + + ~section() { +#pragma HLS inline + if (last) { + buf_ref.sink.write(section_id); + } + } + + private: + using buffer_t = _buffer; + friend buffer_t; + + section(buffer_t& buf_ref) : buf_ref(buf_ref) { +#pragma HLS inline + section_id = buf_ref.src.read(); + } + + buffer_t& buf_ref; + int section_id; + mutable volatile bool last = true; +}; + +template +class _buffer { + public: + using section_t = section; + section_t acquire() { +#pragma HLS inline + return *this; + } + + hls::stream src; + hls::stream sink; + + // This +1 is not needed, however, if we don't do this, + // whenever users use single buffers, fake dependency is + // not respected. Of course, doing it this way adds more + // address lines, however, that may not matter much. Not + // sure, but Vivado might be able to optimize it too since + // the wire won't have an external connection + // TODO: confirm this from physical design + T data[n_sections == 1 ? 2 : n_sections]; +}; + +// for HLS interface, ibuffer and obuffer can be totally +// same as we take care of src and sink FIFOs in the +// stitching process +template +using ibuffer = _buffer; + +template +using obuffer = _buffer; + +template +using buffer = _buffer; + +template +using ibuffers = ibuffer[len]; + +template +using obuffers = obuffer[len]; + +template +class buffers; + +} // namespace tapa + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/logging.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/logging.h new file mode 100644 index 000000000000..ab8237b73671 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/logging.h @@ -0,0 +1,49 @@ + +#ifndef TAPA_XILINX_HLS_LOGGING_H_ +#define TAPA_XILINX_HLS_LOGGING_H_ + +namespace tapa { +namespace internal { + +struct dummy { + template + dummy& operator<<(const T&) { + return *this; + } +}; + +} // namespace internal +} // namespace tapa + +#define LOG(level) ::tapa::internal::dummy() +#define LOG_IF(level, cond) ::tapa::internal::dummy() +#define LOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define LOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define LOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#define DLOG(level) ::tapa::internal::dummy() +#define DLOG_IF(level, cond) ::tapa::internal::dummy() +#define DLOG_EVERY_N(level, n) ::tapa::internal::dummy() + +#define CHECK(cond) ::tapa::internal::dummy() +#define CHECK_NE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_EQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_GT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_LT(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_NOTNULL(ptr) (ptr) +#define CHECK_STREQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRNE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASEEQ(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_STRCASENE(lhs, rhs) ::tapa::internal::dummy() +#define CHECK_DOUBLE_EQ(lhs, rhs) ::tapa::internal::dummy() + +#define VLOG_IS_ON(level) false +#define VLOG(level) ::tapa::internal::dummy() +#define VLOG_IF(level, cond) ::tapa::internal::dummy() +#define VLOG_EVERY_N(level, n) ::tapa::internal::dummy() +#define VLOG_IF_EVERY_N(level, cond, n) ::tapa::internal::dummy() +#define VLOG_FIRST_N(level, n) ::tapa::internal::dummy() + +#endif // TAPA_XILINX_HLS_LOGGING_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/mmap.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/mmap.h new file mode 100644 index 000000000000..e1cf563b2e28 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/mmap.h @@ -0,0 +1,40 @@ +#ifndef TAPA_XILINX_HLS_MMAP_H_ +#define TAPA_XILINX_HLS_MMAP_H_ + +#include "tapa/base/mmap.h" + +#ifdef __SYNTHESIS__ + +#include + +#include "tapa/xilinx/hls/stream.h" + +namespace tapa { + +template +using mmap = T*; + +template +struct async_mmap { + using addr_t = int64_t; + using resp_t = uint8_t; + + tapa::ostream read_addr; + tapa::istream read_data; + tapa::ostream write_addr; + tapa::ostream write_data; + tapa::istream write_resp; +}; + +template +class mmaps; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/mmap.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_MMAP_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/stream.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/stream.h new file mode 100644 index 000000000000..fed15732f1fe --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/stream.h @@ -0,0 +1,199 @@ +#ifndef TAPA_XILINX_HLS_STREAM_H_ +#define TAPA_XILINX_HLS_STREAM_H_ + +#include "tapa/base/stream.h" + +#ifdef __SYNTHESIS__ + +#include +#include +#include + +#include + +namespace tapa { + +template +class istream { + public: + bool empty() const { +#pragma HLS inline + return _.empty(); + } + + bool try_eot(bool& is_eot) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + is_eot = elem.eot; + return is_success; + } + + bool eot(bool& is_success) const { +#pragma HLS inline + bool eot = false; + is_success = try_eot(eot); + return eot; + } + + bool eot(std::nullptr_t) const { +#pragma HLS inline + bool is_success; + return eot(is_success) && is_success; + } + + bool try_peek(T& value) const { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = !empty() && _peek.read_nb(elem); + value = elem.val; + return is_success; + } + + T peek(bool& is_success) const { +#pragma HLS inline + T val; + is_success = try_peek(val); + return val; + } + + T peek(std::nullptr_t) const { +#pragma HLS inline + T val; + try_peek(val); + return val; + } + + T peek(bool& is_success, bool& is_eot) const { +#pragma HLS inline + internal::elem_t peek_val; + (is_success = !empty()) && _peek.read_nb(peek_val); + is_eot = peek_val.eot && is_success; + return peek_val.val; + } + + bool try_read(T& value) { +#pragma HLS inline + internal::elem_t elem; + const bool is_success = _.read_nb(elem); + value = elem.val; + return is_success; + } + + T read() { +#pragma HLS inline + return _.read().val; + } + + istream& operator>>(T& value) { +#pragma HLS inline + value = read(); + return *this; + } + + T read(bool& is_success) { +#pragma HLS inline + internal::elem_t elem; + is_success = _.read_nb(elem); + return elem.val; + } + + T read(std::nullptr_t) { +#pragma HLS inline + internal::elem_t elem; + _.read_nb(elem); + return elem.val; + } + + T read(const T& default_value, bool* is_success = nullptr) { +#pragma HLS inline + internal::elem_t elem; + bool is_success_val = _.read_nb(elem); + if (is_success != nullptr) { + *is_success = is_success_val; + } + return is_success_val ? elem.val : default_value; + } + + bool try_open() { +#pragma HLS inline + internal::elem_t elem; + const bool succeeded = _.read_nb(elem); + assert(!succeeded || elem.eot); + return succeeded; + } + + void open() { +#pragma HLS inline + const auto elem = _.read(); + assert(elem.eot); + } + + hls::stream> _; + mutable hls::stream> _peek; +}; + +template +class ostream { + public: + bool full() const { +#pragma HLS inline + return _.full(); + } + + bool try_write(const T& value) { +#pragma HLS inline + return _.write_nb({value, false}); + } + + void write(const T& value) { +#pragma HLS inline + _.write({value, false}); + } + + ostream& operator<<(const T& value) { +#pragma HLS inline + write(value); + return *this; + } + + bool try_close() { +#pragma HLS inline + internal::elem_t elem; + memset(&elem.val, 0, sizeof(elem.val)); + elem.eot = true; + return _.write_nb(elem); + } + + void close() { +#pragma HLS inline + internal::elem_t elem; + elem.eot = true; + _.write(elem); + } + + hls::stream> _; +}; + +/// Defines a communication channel between two task instances. +template +class stream; + +template +using istreams = istream[S]; + +template +using ostreams = ostream[S]; + +template +class streams; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/stream.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_STREAM_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/tapa.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/tapa.h new file mode 100644 index 000000000000..5b6ce0a9df6a --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/tapa.h @@ -0,0 +1,23 @@ +#ifndef TAPA_XILINX_HLS_TAPA_H_ +#define TAPA_XILINX_HLS_TAPA_H_ + +#include "tapa/base/tapa.h" + +#ifdef __SYNTHESIS__ + +#include "tapa/xilinx/hls/mmap.h" +#include "tapa/xilinx/hls/stream.h" +#include "tapa/xilinx/hls/task.h" +#include "tapa/xilinx/hls/util.h" +#include "tapa/xilinx/hls/vec.h" +#ifdef TAPA_BUFFER_SUPPORT +#include "tapa/xilinx/hls/buffer.h" +#endif + +#else // __SYNTHESIS__ + +#include "tapa/host/tapa.h" + +#endif + +#endif // TAPA_XILINX_HLS_TAPA_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/task.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/task.h new file mode 100644 index 000000000000..40251e8b8937 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/task.h @@ -0,0 +1,58 @@ +#ifndef TAPA_XILINX_HLS_TASK_H_ +#define TAPA_XILINX_HLS_TASK_H_ + +#include "tapa/base/task.h" + +#ifdef __SYNTHESIS__ + +namespace tapa { + +struct task { + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + return invoke(std::forward(func), name, + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + f(std::forward(args)...); + return *this; + } + + template + task& invoke(Func&& func, Args&&... args) { + return invoke(std::forward(func), "", + std::forward(args)...); + } + + template + task& invoke(Func&& func, const char (&name)[name_size], Args&&... args) { + for (int i = 0; i < n; ++i) { + invoke(std::forward(func), std::forward(args)...); + } + return *this; + } +}; + +} // namespace tapa + +#else // __SYNTHESIS__ + +#include "tapa/host/task.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_TASK_H diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/util.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/util.h new file mode 100644 index 000000000000..4e5d0a4d8ea1 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/util.h @@ -0,0 +1,61 @@ +#ifndef TAPA_XILINX_HLS_UTIL_H_ +#define TAPA_XILINX_HLS_UTIL_H_ + +#include "tapa/base/util.h" + +#include + +#ifdef __SYNTHESIS__ + +namespace tapa { + +template +inline typename std::enable_if::type // +bit_cast(From from) noexcept { +#pragma HLS inline + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} + +template +T reg(T x) { +#pragma HLS inline off +#pragma HLS pipeline II = 1 +#pragma HLS latency min = 1 max = 1 + return x; +} + +} // namespace tapa + +#undef TAPA_WHILE_NOT_EOT +#define TAPA_WHILE_NOT_EOT(fifo) \ + for (bool tapa_##fifo##_valid; \ + !fifo.eot(tapa_##fifo##_valid) || !tapa_##fifo##_valid;) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo##_valid) + +#undef TAPA_WHILE_NEITHER_EOT +#define TAPA_WHILE_NEITHER_EOT(fifo1, fifo2) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid) + +#undef TAPA_WHILE_NONE_EOT +#define TAPA_WHILE_NONE_EOT(fifo1, fifo2, fifo3) \ + for (bool tapa_##fifo1##_valid, tapa_##fifo2##_valid, tapa_##fifo3##_valid; \ + (!fifo1.eot(tapa_##fifo1##_valid) || !tapa_##fifo1##_valid) && \ + (!fifo2.eot(tapa_##fifo2##_valid) || !tapa_##fifo2##_valid) && \ + (!fifo3.eot(tapa_##fifo3##_valid) || !tapa_##fifo3##_valid);) \ + _Pragma("HLS pipeline II = 1") if (tapa_##fifo1##_valid && \ + tapa_##fifo2##_valid && \ + tapa_##fifo3##_valid) + +#else // __SYNTHESIS__ + +#include "tapa/host/util.h" + +#endif // __SYNTHESIS__ + +#endif // TAPA_XILINX_HLS_UTIL_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/vec.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/vec.h new file mode 100644 index 000000000000..e73d5e6d28ec --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/auto_ntt/shuffler_out_shuff/src/tapa/xilinx/hls/vec.h @@ -0,0 +1,391 @@ +#ifndef TAPA_XILINX_VEC_H_ +#define TAPA_XILINX_VEC_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tapa/xilinx/hls/logging.h" +#include "tapa/xilinx/hls/util.h" + +namespace tapa { + +template +struct vec_t : protected std::array { + private: + using base_type = std::array; + + public: + // static constexpr metadata + static constexpr int length = N; + static constexpr int width = widthof() * N; + + // public type alias + using size_type = int; + using typename base_type::const_iterator; + using typename base_type::const_pointer; + using typename base_type::const_reference; + using typename base_type::const_reverse_iterator; + using typename base_type::difference_type; + using typename base_type::iterator; + using typename base_type::pointer; + using typename base_type::reference; + using typename base_type::reverse_iterator; + using typename base_type::value_type; + + // single-element getter and setter + constexpr const_reference operator[](size_type pos) const { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + reference operator[](size_type pos) { +#pragma HLS inline +#pragma HLS aggregate variable = this bit + return base_type::operator[](pos); + } + constexpr const_reference get(size_type pos) const { +#pragma HLS inline + return (*this)[pos]; + } + void set(size_type pos, const T& value) { +#pragma HLS inline + (*this)[pos] = value; + } + + // use base type constructors and assignment operators + using base_type::base_type; + using base_type::operator=; + + // constructors from base_type + explicit vec_t(const base_type& other) : base_type(other) {} + explicit vec_t(base_type&& other) : base_type(other) {} + + // static cast to vec_t of another type + template + explicit operator vec_t() const { +#pragma HLS inline + vec_t result; + for (size_type i = 0; i < N; ++i) { + result.set(i, static_cast(get(i))); + } + return result; + } + + // all-element setter + void set(T val) { +#pragma HLS inline + *this = val; + } + + // all-element assignment operator + vec_t& operator=(T val) { +#pragma HLS inline + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + set(i, val); + } + return *this; + } + +// assignment operators +#define DEFINE_OP(op) \ + template \ + vec_t& operator op##=(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs[i]); \ + } \ + return *this; \ + } \ + template \ + vec_t& operator op##=(const T2& rhs) { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, get(i) op rhs); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + +// unary arithemetic operators +#define DEFINE_OP(op) \ + vec_t operator op() { \ + _Pragma("HLS inline"); \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + set(i, op get(i)); \ + } \ + return *this; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(~) +#undef DEFINE_OP + +// binary arithemetic operators +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs[i]); \ + } \ + return result; \ + } \ + template \ + vec_t operator op(const T2& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (size_type i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, get(i) op rhs); \ + } \ + return result; \ + } + DEFINE_OP(+) + DEFINE_OP(-) + DEFINE_OP(*) + DEFINE_OP(/) + DEFINE_OP(%) + DEFINE_OP(&) + DEFINE_OP(|) + DEFINE_OP(^) + DEFINE_OP(<<) + DEFINE_OP(>>) +#undef DEFINE_OP + + // shift all elements by 1, put val at [N-1], and through away [0] + void shift(const T& val) { +#pragma HLS inline + for (size_type i = 1; i < N; ++i) { +#pragma HLS unroll + set(i - 1, get(i)); + } + set(N - 1, val); + } + + // return true if and only if val exists + bool has(const T& val) { +#pragma HLS inline + bool result = false; + for (size_type i = 0; i < N; ++i) { +#pragma HLS unroll + if (val == get(i)) result |= true; + } + return result; + } +}; + +// return vec[begin:end] +template +inline vec_t truncated(const vec_t& vec) { + static_assert(begin >= 0, "cannot truncate before 0"); + static_assert(end <= N, "cannot truncate after N"); + vec_t result; +#pragma HLS inline + for (int i = 0; i < end - begin; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:length] +template +inline vec_t truncated(const vec_t& vec) { +#pragma HLS inline + return truncated<0, length>(vec); +} + +// return vec[begin:begin+length] +template +inline vec_t truncated(const vec_t& vec, int begin) { + static_assert(length <= N, "cannot enlarge vector"); + int end = begin + length; + CHECK_GE(begin, 0) << "cannot truncate before 0"; + CHECK_LE(end, N) << "cannot truncate after N"; + vec_t result; +#pragma HLS inline + for (int i = 0; i < length; ++i) { +#pragma HLS unroll + result.set(i, vec[begin + i]); + } + return result; +} + +// return vec[:] + [val] +template +inline vec_t cat(const vec_t& vec, const T& val) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i, vec[i]); + } + result.set(N, val); + return result; +} + +// return [val] + vec[:] +template +inline vec_t cat(const T& val, const vec_t& vec) { + vec_t result; +#pragma HLS inline + result.set(0, val); + for (int i = 0; i < N; ++i) { +#pragma HLS unroll + result.set(i + 1, vec[i]); + } + return result; +} + +// return v1[:] + v2[:] +template +inline vec_t cat(const vec_t& v1, const vec_t& v2) { + vec_t result; +#pragma HLS inline + for (int i = 0; i < N1; ++i) { +#pragma HLS unroll + result.set(i, v1[i]); + } + for (int i = 0; i < N2; ++i) { +#pragma HLS unroll + result.set(i + N1, v2[i]); + } + return result; +} + +#if __cplusplus >= 201402L +template +inline auto cat(T arg, Args... args) { +#pragma HLS inline + return cat(arg, cat(args...)); +} +#endif // __cplusplus >= 201402L + +// binary arithemetic operators, vector on the right-hand side +#define DEFINE_OP(op) \ + template \ + vec_t operator op(const T2& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, lhs op rhs[i]); \ + } \ + return result; \ + } +DEFINE_OP(+) +DEFINE_OP(-) +DEFINE_OP(*) +DEFINE_OP(/) +DEFINE_OP(%) +DEFINE_OP(&) +DEFINE_OP(|) +DEFINE_OP(^) +DEFINE_OP(<<) +DEFINE_OP(>>) +#undef DEFINE_OP + +template +vec_t make_vec(T val) { +#pragma HLS inline + vec_t result; + result.set(val); + return result; +} + +// unary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(vec_t vec) { \ + _Pragma("HLS inline"); \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + vec.set(i, std::func(vec[i])); \ + } \ + return vec; \ + } +DEFINE_FUNC(exp) +DEFINE_FUNC(exp2) +DEFINE_FUNC(expm1) +DEFINE_FUNC(log) +DEFINE_FUNC(log10) +DEFINE_FUNC(log1p) +DEFINE_FUNC(log2) +#undef DEFINE_FUNC + +// binary operation functions +#define DEFINE_FUNC(func) \ + template \ + vec_t func(const vec_t& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline"); \ + vec_t result; \ + for (int i = 0; i < N; ++i) { \ + _Pragma("HLS unroll"); \ + result.set(i, std::func(lhs[i], rhs[i])); \ + } \ + return result; \ + } \ + template \ + vec_t func(const T& lhs, const vec_t& rhs) { \ + _Pragma("HLS inline") return func(make_vec(lhs), rhs); \ + } \ + template \ + vec_t func(const vec_t& lhs, const T& rhs) { \ + _Pragma("HLS inline") return func(lhs, make_vec(rhs)); \ + } +DEFINE_FUNC(max) +DEFINE_FUNC(min) +#undef DEFINE_FUNC + +// reduction operation functions +#define DEFINE_FUNC(func, op) \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return vec[0]; \ + } \ + template \ + T func(const vec_t& vec) { \ + _Pragma("HLS inline"); \ + return func(truncated(vec)) op func(truncated(vec)); \ + } +DEFINE_FUNC(sum, +) +DEFINE_FUNC(product, *) +#undef DEFINE_FUNC + +template +inline std::ostream& operator<<(std::ostream& os, const vec_t& obj) { + os << "{"; + for (int i = 0; i < N; ++i) { + if (i > 0) os << ", "; + os << "[" << i << "]: " << obj[i]; + } + return os << "}"; +} + +} // namespace tapa + +#endif // TAPA_XILINX_VEC_H_ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/add.c b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/add.c new file mode 100644 index 000000000000..400457f9bae8 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/add.c @@ -0,0 +1,159 @@ +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/add.c,v 1.5 1994/12/30 22:35:09 jutta Exp $ */ + +/* + * See private.h for the more commonly used macro versions. + */ +#include "private.h" + +#define saturate(x) \ + ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x)) + +word +gsm_add (word a, word b) +{ + longword sum; + sum = (longword) a + (longword) b; + return saturate (sum); +} + +word +gsm_mult (word a, word b) +{ + if (a == MIN_WORD && b == MIN_WORD) + return MAX_WORD; + else + return SASR ((longword) a * (longword) b, 15); +} + +word +gsm_mult_r (word a, word b) +{ + longword prod; + if (b == MIN_WORD && a == MIN_WORD) + return MAX_WORD; + else + { + prod = (longword) a *(longword) b + 16384; + prod >>= 15; + return prod & 0xFFFF; + } +} + +word +gsm_abs (word a) +{ + return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a; +} + +const unsigned char bitoff[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +word +gsm_norm (longword a) +/* + * the number of left shifts needed to normalize the 32 bit + * variable L_var1 for positive values on the interval + * + * with minimum of + * minimum of 1073741824 (01000000000000000000000000000000) and + * maximum of 2147483647 (01111111111111111111111111111111) + * + * + * and for negative values on the interval with + * minimum of -2147483648 (-10000000000000000000000000000000) and + * maximum of -1073741824 ( -1000000000000000000000000000000). + * + * in order to normalize the result, the following + * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 ); + * + * (That's 'ffs', only from the left, not the right..) + */ +{ + + if (a < 0) + { + if (a <= -1073741824) + return 0; + a = ~a; + } + + return a & 0xffff0000 ? + (a & 0xff000000 ? -1 + bitoff[0xFF & (a >> 24)] : + 7 + bitoff[0xFF & (a >> 16)]) + : (a & 0xff00 ? 15 + bitoff[0xFF & (a >> 8)] : 23 + bitoff[0xFF & a]); +} + +word +gsm_div (word num, word denum) +{ + longword L_num; + longword L_denum; + word div; + int k; + + L_num = num; + L_denum = denum; + div = 0; + k = 15; + /* The parameter num sometimes becomes zero. + * Although this is explicitly guarded against in 4.2.5, + * we assume that the result should then be zero as well. + */ + + if (num == 0) + return 0; + + gsmdiv_lp: while (k--) + { + div <<= 1; + L_num <<= 1; + + if (L_num >= L_denum) + { + L_num -= L_denum; + div++; + } + } + + return div; +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/lpc.c b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/lpc.c new file mode 100644 index 000000000000..a0f03d0892e2 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/gsm/lpc.c @@ -0,0 +1,321 @@ +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/lpc.c,v 1.5 1994/12/30 23:14:54 jutta Exp $ */ + +#include "private.h" + +/* + * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION + */ + +/* 4.2.4 */ + + +void +Autocorrelation (word * s /* [0..159] IN/OUT */ , + longword * L_ACF /* [0..8] OUT */ ) +/* + * The goal is to compute the array L_ACF[k]. The signal s[i] must + * be scaled in order to avoid an overflow situation. + */ +{ + register int k, i; + + word temp; + word smax; + word scalauto, n; + word *sp; + word sl; + + /* Search for the maximum. + */ + smax = 0; + autocol_lp1: for (k = 0; k <= 159; k++) + { + temp = GSM_ABS (s[k]); + if (temp > smax) + smax = temp; + } + + /* Computation of the scaling factor. + */ + if (smax == 0) + scalauto = 0; + else + scalauto = 4 - gsm_norm ((longword) smax << 16); /* sub(4,..) */ + + if (scalauto > 0 && scalauto <= 4) + { + n = scalauto; + for (k = 0; k <= 159; k++) + s[k] = GSM_MULT_R (s[k], 16384 >> (n - 1)); + } + + /* Compute the L_ACF[..]. + */ + { + sp = s; + sl = *sp; + +#define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]); + +#define NEXTI sl = *++sp + for (k = 8; k >= 0; k--) + L_ACF[k] = 0; + + STEP (0); + NEXTI; + STEP (0); + STEP (1); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + STEP (6); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + STEP (6); + STEP (7); + + autocol_lp2: for (i = 8; i <= 159; i++) + { + + NEXTI; + + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + STEP (6); + STEP (7); + STEP (8); + } + + autocol_lp3: for (k = 8; k >= 0; k--) + L_ACF[k] <<= 1; + + } + /* Rescaling of the array s[0..159] + */ + if (scalauto > 0) + autocol_lp4: for (k = 159; k >= 0; k--) + *s++ <<= scalauto; +} + +/* 4.2.5 */ + +void +Reflection_coefficients (longword * L_ACF /* 0...8 IN */ , + register word * r /* 0...7 OUT */ ) +{ + register int i, m, n; + register word temp; + word ACF[9]; /* 0..8 */ + word P[9]; /* 0..8 */ + word K[9]; /* 2..8 */ + + /* Schur recursion with 16 bits arithmetic. + */ + + if (L_ACF[0] == 0) + { + for (i = 8; i > 0; i--) + *r++ = 0; + return; + } + + temp = gsm_norm (L_ACF[0]); + Reflc_lp1: for (i = 0; i <= 8; i++) + ACF[i] = SASR (L_ACF[i] << temp, 16); + + /* Initialize array P[..] and K[..] for the recursion. + */ + + Reflc_lp2: for (i = 1; i <= 7; i++) + K[i] = ACF[i]; + Reflc_lp3: for (i = 0; i <= 8; i++) + P[i] = ACF[i]; + + /* Compute reflection coefficients + */ + Reflc_lp4: for (n = 1; n <= 8; n++, r++) + { + + temp = P[1]; + temp = GSM_ABS (temp); + if (P[0] < temp) + { + Reflc_lp5: for (i = n; i <= 8; i++) + *r++ = 0; + return; + } + + *r = gsm_div (temp, P[0]); + + if (P[1] > 0) + *r = -*r; /* r[n] = sub(0, r[n]) */ + if (n == 8) + return; + + /* Schur recursion + */ + temp = GSM_MULT_R (P[1], *r); + P[0] = GSM_ADD (P[0], temp); + + Reflc_lp6: for (m = 1; m <= 8 - n; m++) + { + temp = GSM_MULT_R (K[m], *r); + P[m] = GSM_ADD (P[m + 1], temp); + + temp = GSM_MULT_R (P[m + 1], *r); + K[m] = GSM_ADD (K[m], temp); + } + } +} + +/* 4.2.6 */ + +void +Transformation_to_Log_Area_Ratios (register word * r /* 0..7 IN/OUT */ ) +/* + * The following scaling for r[..] and LAR[..] has been used: + * + * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1. + * LAR[..] = integer( real_LAR[..] * 16384 ); + * with -1.625 <= real_LAR <= 1.625 + */ +{ + register word temp; + register int i; + + + /* Computation of the LAR[0..7] from the r[0..7] + */ + trans_lp: for (i = 1; i <= 8; i++, r++) + { + + temp = *r; + temp = GSM_ABS (temp); + + if (temp < 22118) + { + temp >>= 1; + } + else if (temp < 31130) + { + temp -= 11059; + } + else + { + temp -= 26112; + temp <<= 2; + } + + *r = *r < 0 ? -temp : temp; + } +} + +/* 4.2.7 */ + +void +Quantization_and_coding (register word * LAR /* [0..7] IN/OUT */ ) +{ + register word temp; + + + /* This procedure needs four tables; the following equations + * give the optimum scaling for the constants: + * + * A[0..7] = integer( real_A[0..7] * 1024 ) + * B[0..7] = integer( real_B[0..7] * 512 ) + * MAC[0..7] = maximum of the LARc[0..7] + * MIC[0..7] = minimum of the LARc[0..7] + */ + +# undef STEP +# define STEP( A, B, MAC, MIC ) \ + temp = GSM_MULT( A, *LAR ); \ + temp = GSM_ADD( temp, B ); \ + temp = GSM_ADD( temp, 256 ); \ + temp = SASR( temp, 9 ); \ + *LAR = temp>MAC ? MAC - MIC : (temp> (by)) + +word gsm_add(word a, word b); +word gsm_mult(word a, word b); +word gsm_mult_r(word a, word b); +word gsm_abs(word a); +word gsm_norm(longword a); +word gsm_div(word num, word denum); + +#define GSM_MULT_R(a, b) gsm_mult_r(a, b) +#define GSM_MULT(a, b) gsm_mult(a, b) +#define GSM_ADD(a, b) gsm_add(a, b) +#define GSM_ABS(a) gsm_abs(a) + +#endif /* PRIVATE_H */ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.c b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.c new file mode 100644 index 000000000000..5c65fcf653b3 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.c @@ -0,0 +1,218 @@ +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +/* NIST Secure Hash Algorithm */ +/* heavily modified by Uwe Hollerbach uh@alumni.caltech edu */ +/* from Peter C. Gutmann's implementation as found in */ +/* Applied Cryptography by Bruce Schneier */ + +/* NIST's proposed modification to SHA of 7/11/94 may be */ +/* activated by defining USE_MODIFIED_SHA */ + + +/* SHA f()-functions */ + +#define f1(x,y,z) ((x & y) | (~x & z)) +#define f2(x,y,z) (x ^ y ^ z) +#define f3(x,y,z) ((x & y) | (x & z) | (y & z)) +#define f4(x,y,z) (x ^ y ^ z) + +/* SHA constants */ + +#define CONST1 0x5a827999L +#define CONST2 0x6ed9eba1L +#define CONST3 0x8f1bbcdcL +#define CONST4 0xca62c1d6L + +/* 32-bit rotate */ +#include "sha.h" + +#define ROT32(x,n) ((x << n) | (x >> (32 - n))) + +#define FUNC(n,i) \ + temp = ROT32(A,5) + f##n(B,C,D) + E + W[i] + CONST##n; \ + E = D; D = C; C = ROT32(B,30); B = A; A = temp + +void +local_memset (INT32 * s, int c, int n, int e) +{ + INT32 uc; + INT32 *p; + int m; + + m = n / 4; + uc = c; + p = (INT32 *) s; + while (e-- > 0) + { + p++; + } + while (m-- > 0) + { + *p++ = uc; + } +} + +void +local_memcpy (INT32 * s1, const BYTE * s2, int n) +{ + INT32 *p1; + BYTE *p2; + INT32 tmp; + int m; + m = n / 4; + p1 = (INT32 *) s1; + p2 = (BYTE *) s2; + + while (m-- > 0) + { + tmp = 0; + tmp |= 0xFF & *p2++; + tmp |= (0xFF & *p2++) << 8; + tmp |= (0xFF & *p2++) << 16; + tmp |= (0xFF & *p2++) << 24; + *p1 = tmp; + p1++; + } +} + +/* do SHA transformation */ + +static void +sha_transform () +{ + int i; + INT32 temp, A, B, C, D, E, W[80]; + + trans_lp1: for (i = 0; i < 16; ++i) + { + W[i] = sha_info_data[i]; + } + trans_lp2: for (i = 16; i < 80; ++i) + { + W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + } + A = sha_info_digest[0]; + B = sha_info_digest[1]; + C = sha_info_digest[2]; + D = sha_info_digest[3]; + E = sha_info_digest[4]; + + trans_lp3: for (i = 0; i < 20; ++i) + { + FUNC (1, i); + } + trans_lp4: for (i = 20; i < 40; ++i) + { + FUNC (2, i); + } + trans_lp5: for (i = 40; i < 60; ++i) + { + FUNC (3, i); + } + trans_lp6: for (i = 60; i < 80; ++i) + { + FUNC (4, i); + } + + sha_info_digest[0] += A; + sha_info_digest[1] += B; + sha_info_digest[2] += C; + sha_info_digest[3] += D; + sha_info_digest[4] += E; +} + +/* initialize the SHA digest */ + +void +sha_init () +{ + sha_info_digest[0] = 0x67452301L; + sha_info_digest[1] = 0xefcdab89L; + sha_info_digest[2] = 0x98badcfeL; + sha_info_digest[3] = 0x10325476L; + sha_info_digest[4] = 0xc3d2e1f0L; + sha_info_count_lo = 0L; + sha_info_count_hi = 0L; +} + +/* update the SHA digest */ + +void +sha_update (const BYTE * buffer, int count) +{ + if ((sha_info_count_lo + ((INT32) count << 3)) < sha_info_count_lo) + { + ++sha_info_count_hi; + } + sha_info_count_lo += (INT32) count << 3; + sha_info_count_hi += (INT32) count >> 29; + while (count >= SHA_BLOCKSIZE) + { + local_memcpy (sha_info_data, buffer, SHA_BLOCKSIZE); + sha_transform (); + buffer += SHA_BLOCKSIZE; + count -= SHA_BLOCKSIZE; + } + local_memcpy (sha_info_data, buffer, count); +} + +/* finish computing the SHA digest */ + +void +sha_final () +{ + int count; + INT32 lo_bit_count; + INT32 hi_bit_count; + + lo_bit_count = sha_info_count_lo; + hi_bit_count = sha_info_count_hi; + count = (int) ((lo_bit_count >> 3) & 0x3f); + sha_info_data[count++] = 0x80; + if (count > 56) + { + local_memset (sha_info_data, 0, 64 - count, count); + sha_transform (); + local_memset (sha_info_data, 0, 56, 0); + } + else + { + local_memset (sha_info_data, 0, 56 - count, count); + } + sha_info_data[14] = hi_bit_count; + sha_info_data[15] = lo_bit_count; + sha_transform (); +} + +/* compute the SHA digest of a FILE stream */ +void +sha_stream () +{ + int i, j; + const BYTE *p; + + sha_init (); + main_loop:for (j = 0; j < VSIZE; j++) + { + i = in_i[j]; + p = &indata[j][0]; + sha_update (p, i); + } + sha_final (); +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.h new file mode 100644 index 000000000000..da4c9cae0f81 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/chstone/sha/sha.h @@ -0,0 +1,1137 @@ +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +#ifndef SHA_H +#define SHA_H + +/* NIST Secure Hash Algorithm */ +/* heavily modified from Peter C. Gutmann's implementation */ + +/* Useful defines & typedefs */ + +typedef unsigned char BYTE; +typedef unsigned int INT32; + +#define SHA_BLOCKSIZE 64 + +INT32 sha_info_digest[5]; /* message digest */ +INT32 sha_info_count_lo, sha_info_count_hi; /* 64-bit bit count */ +INT32 sha_info_data[16]; + +void sha_init (); +void sha_update (const BYTE *, int); +void sha_final (); + +void sha_stream (); +void sha_print (); + +#define BLOCK_SIZE 8192 +#define VSIZE 2 + +/* ++--------------------------------------------------------------------------+ +| * Test Vectors (added for CHStone) | +| indata, in_i : input data | ++--------------------------------------------------------------------------+ +*/ +const BYTE indata[VSIZE][BLOCK_SIZE] = { + {75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, + 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, + 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, + 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, + 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, + 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, + 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, + 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, + 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, + 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, + 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, + 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, + 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, + 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, + 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, + 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, + 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, + 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, + 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, + 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, + 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, + 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, + 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, + 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, + 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, + 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, + 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, + 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, + 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, + 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, + 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, + 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, + 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, + 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, + 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, + 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, + 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, + 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, + 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, + 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, + 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, + 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, + 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, + 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, + 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, + 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, + 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, + 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, + 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, + 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, + 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, + 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, + 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, + 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, + 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, + 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, + 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, + 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, + 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, + 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, + 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, + 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, + 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, + 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, + 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 79, 114, 119, 111, 114, 114, 121, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, + 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, + 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, + 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, + 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, + 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, + 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, + 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, + 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, + 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, + 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, + 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, + 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, + 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, + 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, + 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, + 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, + 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, + 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, + 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, + 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, + 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, + 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, + 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, + 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, + 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, + 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, + 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, + 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, + 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, + 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, + 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, + 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, + 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, + 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, + 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, + 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, + 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, + 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, + 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, + 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, + 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, + 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, + 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, + 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, + 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, + 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, + 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, + 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, + 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, + 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, + 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, + 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, + 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, + 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, + 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, + 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, + 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, + 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, + 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, + 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, + 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, + 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, + 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, + 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, + 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, + 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, + 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, + 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, + 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, + 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, + 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, + 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, + 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, + 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, + 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, + 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, + 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 75, 117, 114, 116, + 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, + 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, + 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, + 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, + 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, + 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, + 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, + 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, + 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, + 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, + 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, + 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, + 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, + 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, + 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, + 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, + 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, + 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, + 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, + 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, + 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, + 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, + 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, + 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, + 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, + 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, + 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, + 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, + 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, + 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, + 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, + 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, + 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, + 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, + 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, + 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, + 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, + 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, + 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, + 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117}, + {116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, + 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, + 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, + 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, + 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, + 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, + 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, + 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, + 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, + 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, + 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, + 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, + 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, + 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, + 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, + 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, + 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, + 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, + 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, + 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, + 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, + 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, + 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, + 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, + 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, + 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, + 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, + 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, + 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, + 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, + 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, + 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, + 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, + 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, + 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, + 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, + 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, + 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, + 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, + 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, + 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, + 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, + 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, + 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, + 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, + 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, + 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, + 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, + 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, + 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, + 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, + 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, + 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, + 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, + 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, + 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, + 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, + 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, + 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, + 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, + 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, + 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, + 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, + 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, + 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, + 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, + 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, + 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, + 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, + 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, + 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, + 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, + 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, + 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, + 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, + 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, + 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, + 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, + 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, + 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, + 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, + 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, + 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, + 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, + 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, + 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, + 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, + 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, + 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, + 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, + 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, + 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, + 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, + 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, + 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, + 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, + 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, + 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, + 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, + 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, + 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, + 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, + 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, + 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, + 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, + 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, + 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, + 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, + 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, + 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, + 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, + 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, + 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, + 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, + 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, + 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, + 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, + 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, + 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, + 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, + 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, + 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, + 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, + 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, + 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, + 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, + 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, + 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, + 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, + 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, + 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, + 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, + 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, + 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, + 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, + 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, + 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, + 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, + 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, + 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, + 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, + 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, + 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, + 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, + 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, + 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, + 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, + 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, + 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, + 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, + 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, + 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, + 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, + 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, + 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, + 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, + 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, + 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, + 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, + 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, + 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, + 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, + 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, + 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, + 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, + 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, + 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, + 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, + 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, + 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, + 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, + 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, + 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, + 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, + 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, + 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, + 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, + 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, + 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, + 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, + 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, + 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, + 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, + 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, + 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, + 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, + 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, + 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, + 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, + 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, + 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, + 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, + 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, + 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, + 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, + 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, + 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, + 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, + 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, + 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, + 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, + 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, + 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, + 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, + 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, + 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, + 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, + 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, + 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, + 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, + 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, + 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, + 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, + 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, + 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, + 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, + 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, + 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, + 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, + 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, + 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, + 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111} +}; +const int in_i[VSIZE] = { 8192, 8192 }; +#endif /* SHA_H */ diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/debayer.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/debayer.cpp new file mode 100644 index 000000000000..bee2014ac733 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/debayer.cpp @@ -0,0 +1,127 @@ +#include "pipeline.h" + +/* Function to apply a single debayering fiter and generate output */ +INT_TYPE applyKernel(INT_TYPE in_3x3[9], INT_TYPE kernel_3x3[9]) +{ + INT_TYPE out = (in_3x3[0] * kernel_3x3[0] + in_3x3[1] * kernel_3x3[1] + in_3x3[2] * kernel_3x3[2] + + in_3x3[3] * kernel_3x3[3] + in_3x3[4] * kernel_3x3[4] + in_3x3[5] * kernel_3x3[5] + + in_3x3[6] * kernel_3x3[6] + in_3x3[7] * kernel_3x3[7] + in_3x3[8] * kernel_3x3[8]) >> + 2; + return out; +} + +// INT_TYPE debMul(INT_TYPE in_3x3, INT_TYPE kernel_3x3, INT_TYPE factor) +// { +// INT_TYPE out = (in_3x3 * ((kernel_3x3 >> factor) & 0xF)) >> 2; +// return out; +// } + +void updateHist(INT_TYPE val, LONG_INT_TYPE hist[COLOR_INT]) +{ + hist[val]++; +} + +void debayer(INT_TYPE in[IN_TILE_HEIGHT][IN_TILE_WIDTH], INT_TYPE out[TILE_HEIGHT][TILE_WIDTH][3], int ti, int tj, + LONG_INT_TYPE blue_hist[COLOR_INT], LONG_INT_TYPE green_hist[COLOR_INT], LONG_INT_TYPE red_hist[COLOR_INT]) +{ + + const int height_offset = ti * IN_TILE_HEIGHT; + const int width_offset = tj * IN_TILE_WIDTH; + + // Combine these???? Use some 2 bits and combine them to single 10 bit value or use 2 bit value only??? + // Combine and SHift to applykernel?? -> Linear Interpolation Kernel?? + /*INT_TYPE hor_K[9] = { 0, 0, 0, 2, 0, 2, 0, 0, 0}; + INT_TYPE ver_K[9] = { 0, 2, 0, 0, 0, 0, 0, 2, 0}; + INT_TYPE cross_K[9] = {0, 1, 0, 1, 0, 1, 0, 1, 0}; + INT_TYPE diag_K[9] = { 1, 0, 1, 0, 0, 0, 1, 0, 1}; + INT_TYPE static_K[9] = { 0, 0, 0, 0, 4, 0, 0, 0, 0};*/ + + // static, hor, ver, diag encoded as 1 type + // cross, static, static, cross + // diag, ver, hor, static + INT16_TYPE blue_K[9] = {0x0001, 0x0200, 0x0001, 0x0020, 0x4000, 0x0020, 0x0001, 0x0200, 0x0001}; + INT16_TYPE green_K[9] = {0x0000, 0x1001, 0x0000, 0x1001, 0x0440, 0x1001, 0x0000, 0x1001, 0x0000}; + INT16_TYPE red_K[9] = {0x1000, 0x0020, 0x1000, 0x0200, 0x0004, 0x0200, 0x1000, 0x0020, 0x1000}; + + for (INT_TYPE i = 1; i < IN_TILE_HEIGHT - 1; i++) + { + for (INT_TYPE j = 1; j < IN_TILE_WIDTH - 1; j++) + { + +// #pragma HLS pipeline + + INT_TYPE tempRed[9], tempGreen[9], tempBlue[9]; + INT_TYPE factor = (((height_offset + i - 1) & 1) | (((width_offset + j - 1) & 1) << 1)) << 2; + +#pragma HLS array_partition variable = tempRed dim = 1 complete +#pragma HLS array_partition variable = tempGreen dim = 1 complete +#pragma HLS array_partition variable = tempBlue dim = 1 complete + + out[i - 1][j - 1][0] = 0; + out[i - 1][j - 1][1] = 0; + out[i - 1][j - 1][2] = 0; + + for (INT_TYPE kv = 0; kv < 3; kv++) + { + for (INT_TYPE kh = 0; kh < 3; kh++) + { + tempRed[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((red_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + tempGreen[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((green_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + tempBlue[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((blue_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + // tempRed[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], red_K[kv*3 + kh], factor); + // tempGreen[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], green_K[kv*3 + kh], factor); + // tempBlue[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], blue_K[kv*3 + kh], factor); + } + } + + for (int c = 0; c < 9; c++) + { + out[i - 1][j - 1][0] += tempRed[c]; + out[i - 1][j - 1][1] += tempGreen[c]; + out[i - 1][j - 1][2] += tempBlue[c]; + } + + updateHist(out[i - 1][j - 1][0], blue_hist); + updateHist(out[i - 1][j - 1][1], green_hist); + updateHist(out[i - 1][j - 1][2], red_hist); + } + } + + /*for(INT_TYPE i=1; i +#include + +#include +#include + +typedef ap_uint<8> INT_TYPE; +typedef ap_uint<16> INT16_TYPE; +typedef ap_uint<20> LONG_INT_TYPE; +typedef ap_int<20> LONG_SINT_TYPE; + +#define IMG_HEIGHT 384 // height +#define IMG_WIDTH 512 // width +// #define IMG_HEIGHT 512 // height +// #define IMG_WIDTH 384 // width + +#define IN_TILE_HEIGHT 72 // height 64 + 1*2 + 3*2 +#define IN_TILE_WIDTH 72 // width 64 + 1*2 + 3*2 +// #define IN_TILE_HEIGHT 392 // height 16 + 1*2 + 3*2 +// #define IN_TILE_WIDTH 72 // width 16 + 1*2 + 3*2 + +#define TILE_HEIGHT (IN_TILE_HEIGHT - 2) +#define TILE_WIDTH (IN_TILE_WIDTH - 2) + +#define N_TILES_X IMG_WIDTH / (IN_TILE_WIDTH - 8) +#define N_TILES_Y IMG_HEIGHT / (IN_TILE_HEIGHT - 8) + +#define COLOR_INT 256 + +// #define DEBUG_ROW 155 +// #define DEBUG_COL 299 + +/* IP Blocks */ +void img_pipeline(INT_TYPE in[IMG_HEIGHT][IMG_WIDTH], + INT_TYPE out[IMG_HEIGHT][IMG_WIDTH][3]); + +void debayer(INT_TYPE in[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE out[TILE_HEIGHT][TILE_WIDTH][3], + int ti, + int tj, + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT]); + +void tile_dehaze(INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3]); + +void update_vmin_vmax( + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT], + INT_TYPE vmin[3], + INT_TYPE vmax[3]); + +void wb_apply_transform_tile( + INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE vmin[3], + INT_TYPE vmax[3]); + +/* Util Functions */ +void load_input_tile_from_DRAM( + INT_TYPE in_tile[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE in_img[IMG_HEIGHT][IMG_WIDTH], + int ti, + int tj); +void store_output_tile_to_DRAM( + INT_TYPE out_fm_buf[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE out_fm[IMG_HEIGHT][IMG_WIDTH][3], + int ti, + int tj); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/utils.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/utils.cpp new file mode 100644 index 000000000000..c88d75f8bd0b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/utils.cpp @@ -0,0 +1,60 @@ +#include "pipeline.h" + +void load_input_tile_from_DRAM( + INT_TYPE in_tile[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE in_img[IMG_HEIGHT][IMG_WIDTH], + int ti, + int tj) +{ + const int height_offset = (ti * (IN_TILE_HEIGHT - 8)); // OUT_BUF is intended, not a typo. + const int width_offset = (tj * (IN_TILE_WIDTH - 8)); + +INPUT_BUFFER_HEIGHT: + for (int i = 0; i < IN_TILE_HEIGHT; i++) + { + INPUT_BUFFER_WIDTH: + for (int j = 0; j < IN_TILE_WIDTH; j++) + { + if (!((height_offset + i - 4 < 0) || (width_offset + j - 4 < 0) || (height_offset + i - 4 > IMG_HEIGHT) || (width_offset + j - 4 > IMG_WIDTH))) + { + in_tile[i][j] = in_img[height_offset + i - 4][width_offset + j - 4]; + } + } + } +} + +void store_output_tile_to_DRAM( + INT_TYPE out_fm_buf[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE out_fm[IMG_HEIGHT][IMG_WIDTH][3], + int ti, + int tj) +{ + const int height_offset = (ti * (TILE_HEIGHT - 6)); + const int width_offset = (tj * (TILE_WIDTH - 6)); + +OUTPUT_BUFFER_HEIGHT: + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + OUTPUT_BUFFER_WIDTH: + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][0] = out_fm_buf[i][j][0]; + } + } + + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][1] = out_fm_buf[i][j][1]; + } + } + + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][2] = out_fm_buf[i][j][2]; + } + } +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/whitebalance.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/whitebalance.cpp new file mode 100644 index 000000000000..7131e2302e21 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src/whitebalance.cpp @@ -0,0 +1,113 @@ +#include +#include "pipeline.h" + + +void update_vmin_vmax( + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT], + INT_TYPE vmin[3], + INT_TYPE vmax[3] +) +{ + + LONG_INT_TYPE pixel_cnt[3] = {0,0,0}; + #pragma HLS ARRAY_PARTITION variable = pixel_cnt complete dim = 1 + LONG_INT_TYPE pixel_cnt2[3] = {0,0,0}; + #pragma HLS ARRAY_PARTITION variable = pixel_cnt2 complete dim = 1 + + LONG_INT_TYPE N = IMG_HEIGHT * IMG_WIDTH; + INT_TYPE factor = 20; + + for(int i=0; i < COLOR_INT; i++) + { + if(pixel_cnt[0] <= N/factor){ + pixel_cnt[0] += blue_hist[i]; + vmin[0] = i; + } + if(pixel_cnt[1] <= N/factor){ + pixel_cnt[1] += green_hist[i]; + vmin[1] = i; + } + if(pixel_cnt[2] <= N/factor){ + pixel_cnt[2] += red_hist[i]; + vmin[2] = i; + } + + if(pixel_cnt2[0] <= (N*factor-N)/factor){ + pixel_cnt2[0] += blue_hist[i]; + vmax[0] = i; + } + if(pixel_cnt2[1] <= (N*factor-N)/factor){ + pixel_cnt2[1] += green_hist[i]; + vmax[1] = i; + } + if(pixel_cnt2[2] <= (N*factor-N)/factor){ + pixel_cnt2[2] += red_hist[i]; + vmax[2] = i; + } + } +} + +void wb_apply_transform_tile(INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3], INT_TYPE vmin[3], INT_TYPE vmax[3]) +{ + //white balance the image + for (int i = 0; i < TILE_HEIGHT; i++) + { + for (int j = 0; j < TILE_WIDTH; j++) + { + + if(image_tile[i][j][0] > vmax[0]) + image_tile[i][j][0] = vmax[0]; + + if(image_tile[i][j][0] < vmin[0]) + image_tile[i][j][0] = vmin[0]; + + if(image_tile[i][j][1] > vmax[1]) + image_tile[i][j][1] = vmax[1]; + + if(image_tile[i][j][1] < vmin[1]) + image_tile[i][j][1] = vmin[1]; + + if(image_tile[i][j][2] > vmax[2]) + image_tile[i][j][2] = vmax[2]; + + if(image_tile[i][j][2] < vmin[2]) + image_tile[i][j][2] = vmin[2]; + + //APPLY AFFINE TRANSFORMATION + + //image_tile[i][j][0] = ((image_tile[i][j][0] - vmin[0]) * COLOR_INT) / (vmax[0] - vmin[0]); + //image_tile[i][j][1] = ((image_tile[i][j][1] - vmin[1]) * COLOR_INT) / (vmax[1] - vmin[1]); + //image_tile[i][j][2] = ((image_tile[i][j][2] - vmin[2]) * COLOR_INT) / (vmax[2] - vmin[2]); + + LONG_SINT_TYPE image_tile_0 = ((image_tile[i][j][0] - vmin[0]) * COLOR_INT) / (vmax[0] - vmin[0]); + LONG_SINT_TYPE image_tile_1 = ((image_tile[i][j][1] - vmin[1]) * COLOR_INT) / (vmax[1] - vmin[1]); + LONG_SINT_TYPE image_tile_2 = ((image_tile[i][j][2] - vmin[2]) * COLOR_INT) / (vmax[2] - vmin[2]); + + //APPLY FLOOR AND CEIL + + if(image_tile_0 >= COLOR_INT) + image_tile[i][j][0] = COLOR_INT - 1; + else if(image_tile_0 < 0) + image_tile[i][j][0] = 0; + else + image_tile[i][j][0] = image_tile_0; + + if(image_tile_1 >= COLOR_INT) + image_tile[i][j][1] = COLOR_INT - 1; + else if(image_tile_1 < 0) + image_tile[i][j][1] = 0; + else + image_tile[i][j][1] = image_tile_1; + + if(image_tile_2 >= COLOR_INT) + image_tile[i][j][2] = COLOR_INT - 1; + else if(image_tile_2 < 0) + image_tile[i][j][2] = 0; + else + image_tile[i][j][2] = image_tile_2; + } + } + +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/debayer.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/debayer.cpp new file mode 100644 index 000000000000..bee2014ac733 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/debayer.cpp @@ -0,0 +1,127 @@ +#include "pipeline.h" + +/* Function to apply a single debayering fiter and generate output */ +INT_TYPE applyKernel(INT_TYPE in_3x3[9], INT_TYPE kernel_3x3[9]) +{ + INT_TYPE out = (in_3x3[0] * kernel_3x3[0] + in_3x3[1] * kernel_3x3[1] + in_3x3[2] * kernel_3x3[2] + + in_3x3[3] * kernel_3x3[3] + in_3x3[4] * kernel_3x3[4] + in_3x3[5] * kernel_3x3[5] + + in_3x3[6] * kernel_3x3[6] + in_3x3[7] * kernel_3x3[7] + in_3x3[8] * kernel_3x3[8]) >> + 2; + return out; +} + +// INT_TYPE debMul(INT_TYPE in_3x3, INT_TYPE kernel_3x3, INT_TYPE factor) +// { +// INT_TYPE out = (in_3x3 * ((kernel_3x3 >> factor) & 0xF)) >> 2; +// return out; +// } + +void updateHist(INT_TYPE val, LONG_INT_TYPE hist[COLOR_INT]) +{ + hist[val]++; +} + +void debayer(INT_TYPE in[IN_TILE_HEIGHT][IN_TILE_WIDTH], INT_TYPE out[TILE_HEIGHT][TILE_WIDTH][3], int ti, int tj, + LONG_INT_TYPE blue_hist[COLOR_INT], LONG_INT_TYPE green_hist[COLOR_INT], LONG_INT_TYPE red_hist[COLOR_INT]) +{ + + const int height_offset = ti * IN_TILE_HEIGHT; + const int width_offset = tj * IN_TILE_WIDTH; + + // Combine these???? Use some 2 bits and combine them to single 10 bit value or use 2 bit value only??? + // Combine and SHift to applykernel?? -> Linear Interpolation Kernel?? + /*INT_TYPE hor_K[9] = { 0, 0, 0, 2, 0, 2, 0, 0, 0}; + INT_TYPE ver_K[9] = { 0, 2, 0, 0, 0, 0, 0, 2, 0}; + INT_TYPE cross_K[9] = {0, 1, 0, 1, 0, 1, 0, 1, 0}; + INT_TYPE diag_K[9] = { 1, 0, 1, 0, 0, 0, 1, 0, 1}; + INT_TYPE static_K[9] = { 0, 0, 0, 0, 4, 0, 0, 0, 0};*/ + + // static, hor, ver, diag encoded as 1 type + // cross, static, static, cross + // diag, ver, hor, static + INT16_TYPE blue_K[9] = {0x0001, 0x0200, 0x0001, 0x0020, 0x4000, 0x0020, 0x0001, 0x0200, 0x0001}; + INT16_TYPE green_K[9] = {0x0000, 0x1001, 0x0000, 0x1001, 0x0440, 0x1001, 0x0000, 0x1001, 0x0000}; + INT16_TYPE red_K[9] = {0x1000, 0x0020, 0x1000, 0x0200, 0x0004, 0x0200, 0x1000, 0x0020, 0x1000}; + + for (INT_TYPE i = 1; i < IN_TILE_HEIGHT - 1; i++) + { + for (INT_TYPE j = 1; j < IN_TILE_WIDTH - 1; j++) + { + +// #pragma HLS pipeline + + INT_TYPE tempRed[9], tempGreen[9], tempBlue[9]; + INT_TYPE factor = (((height_offset + i - 1) & 1) | (((width_offset + j - 1) & 1) << 1)) << 2; + +#pragma HLS array_partition variable = tempRed dim = 1 complete +#pragma HLS array_partition variable = tempGreen dim = 1 complete +#pragma HLS array_partition variable = tempBlue dim = 1 complete + + out[i - 1][j - 1][0] = 0; + out[i - 1][j - 1][1] = 0; + out[i - 1][j - 1][2] = 0; + + for (INT_TYPE kv = 0; kv < 3; kv++) + { + for (INT_TYPE kh = 0; kh < 3; kh++) + { + tempRed[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((red_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + tempGreen[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((green_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + tempBlue[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((blue_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + // tempRed[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], red_K[kv*3 + kh], factor); + // tempGreen[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], green_K[kv*3 + kh], factor); + // tempBlue[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], blue_K[kv*3 + kh], factor); + } + } + + for (int c = 0; c < 9; c++) + { + out[i - 1][j - 1][0] += tempRed[c]; + out[i - 1][j - 1][1] += tempGreen[c]; + out[i - 1][j - 1][2] += tempBlue[c]; + } + + updateHist(out[i - 1][j - 1][0], blue_hist); + updateHist(out[i - 1][j - 1][1], green_hist); + updateHist(out[i - 1][j - 1][2], red_hist); + } + } + + /*for(INT_TYPE i=1; i +#include + +#include +#include + +typedef ap_uint<8> INT_TYPE; +typedef ap_uint<16> INT16_TYPE; +typedef ap_uint<20> LONG_INT_TYPE; +typedef ap_int<20> LONG_SINT_TYPE; + +#define IMG_HEIGHT 384 // height +#define IMG_WIDTH 512 // width +// #define IMG_HEIGHT 512 // height +// #define IMG_WIDTH 384 // width + +#define IN_TILE_HEIGHT 72 // height 64 + 1*2 + 3*2 +#define IN_TILE_WIDTH 72 // width 64 + 1*2 + 3*2 +// #define IN_TILE_HEIGHT 392 // height 16 + 1*2 + 3*2 +// #define IN_TILE_WIDTH 72 // width 16 + 1*2 + 3*2 + +#define TILE_HEIGHT (IN_TILE_HEIGHT - 2) +#define TILE_WIDTH (IN_TILE_WIDTH - 2) + +#define N_TILES_X IMG_WIDTH / (IN_TILE_WIDTH - 8) +#define N_TILES_Y IMG_HEIGHT / (IN_TILE_HEIGHT - 8) + +#define COLOR_INT 256 + +// #define DEBUG_ROW 155 +// #define DEBUG_COL 299 + +/* IP Blocks */ +void img_pipeline(INT_TYPE in[IMG_HEIGHT][IMG_WIDTH], + INT_TYPE out[IMG_HEIGHT][IMG_WIDTH][3]); + +void debayer(INT_TYPE in[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE out[TILE_HEIGHT][TILE_WIDTH][3], + int ti, + int tj, + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT]); + +void tile_dehaze(INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3]); + +void update_vmin_vmax( + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT], + INT_TYPE vmin[3], + INT_TYPE vmax[3]); + +void wb_apply_transform_tile( + INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE vmin[3], + INT_TYPE vmax[3]); + +/* Util Functions */ +void load_input_tile_from_DRAM( + INT_TYPE in_tile[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE in_img[IMG_HEIGHT][IMG_WIDTH], + int ti, + int tj); +void store_output_tile_to_DRAM( + INT_TYPE out_fm_buf[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE out_fm[IMG_HEIGHT][IMG_WIDTH][3], + int ti, + int tj); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/utils.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/utils.cpp new file mode 100644 index 000000000000..c88d75f8bd0b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/utils.cpp @@ -0,0 +1,60 @@ +#include "pipeline.h" + +void load_input_tile_from_DRAM( + INT_TYPE in_tile[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE in_img[IMG_HEIGHT][IMG_WIDTH], + int ti, + int tj) +{ + const int height_offset = (ti * (IN_TILE_HEIGHT - 8)); // OUT_BUF is intended, not a typo. + const int width_offset = (tj * (IN_TILE_WIDTH - 8)); + +INPUT_BUFFER_HEIGHT: + for (int i = 0; i < IN_TILE_HEIGHT; i++) + { + INPUT_BUFFER_WIDTH: + for (int j = 0; j < IN_TILE_WIDTH; j++) + { + if (!((height_offset + i - 4 < 0) || (width_offset + j - 4 < 0) || (height_offset + i - 4 > IMG_HEIGHT) || (width_offset + j - 4 > IMG_WIDTH))) + { + in_tile[i][j] = in_img[height_offset + i - 4][width_offset + j - 4]; + } + } + } +} + +void store_output_tile_to_DRAM( + INT_TYPE out_fm_buf[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE out_fm[IMG_HEIGHT][IMG_WIDTH][3], + int ti, + int tj) +{ + const int height_offset = (ti * (TILE_HEIGHT - 6)); + const int width_offset = (tj * (TILE_WIDTH - 6)); + +OUTPUT_BUFFER_HEIGHT: + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + OUTPUT_BUFFER_WIDTH: + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][0] = out_fm_buf[i][j][0]; + } + } + + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][1] = out_fm_buf[i][j][1]; + } + } + + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][2] = out_fm_buf[i][j][2]; + } + } +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/whitebalance.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/whitebalance.cpp new file mode 100644 index 000000000000..7131e2302e21 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__debayer_csynth/whitebalance.cpp @@ -0,0 +1,113 @@ +#include +#include "pipeline.h" + + +void update_vmin_vmax( + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT], + INT_TYPE vmin[3], + INT_TYPE vmax[3] +) +{ + + LONG_INT_TYPE pixel_cnt[3] = {0,0,0}; + #pragma HLS ARRAY_PARTITION variable = pixel_cnt complete dim = 1 + LONG_INT_TYPE pixel_cnt2[3] = {0,0,0}; + #pragma HLS ARRAY_PARTITION variable = pixel_cnt2 complete dim = 1 + + LONG_INT_TYPE N = IMG_HEIGHT * IMG_WIDTH; + INT_TYPE factor = 20; + + for(int i=0; i < COLOR_INT; i++) + { + if(pixel_cnt[0] <= N/factor){ + pixel_cnt[0] += blue_hist[i]; + vmin[0] = i; + } + if(pixel_cnt[1] <= N/factor){ + pixel_cnt[1] += green_hist[i]; + vmin[1] = i; + } + if(pixel_cnt[2] <= N/factor){ + pixel_cnt[2] += red_hist[i]; + vmin[2] = i; + } + + if(pixel_cnt2[0] <= (N*factor-N)/factor){ + pixel_cnt2[0] += blue_hist[i]; + vmax[0] = i; + } + if(pixel_cnt2[1] <= (N*factor-N)/factor){ + pixel_cnt2[1] += green_hist[i]; + vmax[1] = i; + } + if(pixel_cnt2[2] <= (N*factor-N)/factor){ + pixel_cnt2[2] += red_hist[i]; + vmax[2] = i; + } + } +} + +void wb_apply_transform_tile(INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3], INT_TYPE vmin[3], INT_TYPE vmax[3]) +{ + //white balance the image + for (int i = 0; i < TILE_HEIGHT; i++) + { + for (int j = 0; j < TILE_WIDTH; j++) + { + + if(image_tile[i][j][0] > vmax[0]) + image_tile[i][j][0] = vmax[0]; + + if(image_tile[i][j][0] < vmin[0]) + image_tile[i][j][0] = vmin[0]; + + if(image_tile[i][j][1] > vmax[1]) + image_tile[i][j][1] = vmax[1]; + + if(image_tile[i][j][1] < vmin[1]) + image_tile[i][j][1] = vmin[1]; + + if(image_tile[i][j][2] > vmax[2]) + image_tile[i][j][2] = vmax[2]; + + if(image_tile[i][j][2] < vmin[2]) + image_tile[i][j][2] = vmin[2]; + + //APPLY AFFINE TRANSFORMATION + + //image_tile[i][j][0] = ((image_tile[i][j][0] - vmin[0]) * COLOR_INT) / (vmax[0] - vmin[0]); + //image_tile[i][j][1] = ((image_tile[i][j][1] - vmin[1]) * COLOR_INT) / (vmax[1] - vmin[1]); + //image_tile[i][j][2] = ((image_tile[i][j][2] - vmin[2]) * COLOR_INT) / (vmax[2] - vmin[2]); + + LONG_SINT_TYPE image_tile_0 = ((image_tile[i][j][0] - vmin[0]) * COLOR_INT) / (vmax[0] - vmin[0]); + LONG_SINT_TYPE image_tile_1 = ((image_tile[i][j][1] - vmin[1]) * COLOR_INT) / (vmax[1] - vmin[1]); + LONG_SINT_TYPE image_tile_2 = ((image_tile[i][j][2] - vmin[2]) * COLOR_INT) / (vmax[2] - vmin[2]); + + //APPLY FLOOR AND CEIL + + if(image_tile_0 >= COLOR_INT) + image_tile[i][j][0] = COLOR_INT - 1; + else if(image_tile_0 < 0) + image_tile[i][j][0] = 0; + else + image_tile[i][j][0] = image_tile_0; + + if(image_tile_1 >= COLOR_INT) + image_tile[i][j][1] = COLOR_INT - 1; + else if(image_tile_1 < 0) + image_tile[i][j][1] = 0; + else + image_tile[i][j][1] = image_tile_1; + + if(image_tile_2 >= COLOR_INT) + image_tile[i][j][2] = COLOR_INT - 1; + else if(image_tile_2 < 0) + image_tile[i][j][2] = 0; + else + image_tile[i][j][2] = image_tile_2; + } + } + +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/debayer.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/debayer.cpp new file mode 100644 index 000000000000..bee2014ac733 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/debayer.cpp @@ -0,0 +1,127 @@ +#include "pipeline.h" + +/* Function to apply a single debayering fiter and generate output */ +INT_TYPE applyKernel(INT_TYPE in_3x3[9], INT_TYPE kernel_3x3[9]) +{ + INT_TYPE out = (in_3x3[0] * kernel_3x3[0] + in_3x3[1] * kernel_3x3[1] + in_3x3[2] * kernel_3x3[2] + + in_3x3[3] * kernel_3x3[3] + in_3x3[4] * kernel_3x3[4] + in_3x3[5] * kernel_3x3[5] + + in_3x3[6] * kernel_3x3[6] + in_3x3[7] * kernel_3x3[7] + in_3x3[8] * kernel_3x3[8]) >> + 2; + return out; +} + +// INT_TYPE debMul(INT_TYPE in_3x3, INT_TYPE kernel_3x3, INT_TYPE factor) +// { +// INT_TYPE out = (in_3x3 * ((kernel_3x3 >> factor) & 0xF)) >> 2; +// return out; +// } + +void updateHist(INT_TYPE val, LONG_INT_TYPE hist[COLOR_INT]) +{ + hist[val]++; +} + +void debayer(INT_TYPE in[IN_TILE_HEIGHT][IN_TILE_WIDTH], INT_TYPE out[TILE_HEIGHT][TILE_WIDTH][3], int ti, int tj, + LONG_INT_TYPE blue_hist[COLOR_INT], LONG_INT_TYPE green_hist[COLOR_INT], LONG_INT_TYPE red_hist[COLOR_INT]) +{ + + const int height_offset = ti * IN_TILE_HEIGHT; + const int width_offset = tj * IN_TILE_WIDTH; + + // Combine these???? Use some 2 bits and combine them to single 10 bit value or use 2 bit value only??? + // Combine and SHift to applykernel?? -> Linear Interpolation Kernel?? + /*INT_TYPE hor_K[9] = { 0, 0, 0, 2, 0, 2, 0, 0, 0}; + INT_TYPE ver_K[9] = { 0, 2, 0, 0, 0, 0, 0, 2, 0}; + INT_TYPE cross_K[9] = {0, 1, 0, 1, 0, 1, 0, 1, 0}; + INT_TYPE diag_K[9] = { 1, 0, 1, 0, 0, 0, 1, 0, 1}; + INT_TYPE static_K[9] = { 0, 0, 0, 0, 4, 0, 0, 0, 0};*/ + + // static, hor, ver, diag encoded as 1 type + // cross, static, static, cross + // diag, ver, hor, static + INT16_TYPE blue_K[9] = {0x0001, 0x0200, 0x0001, 0x0020, 0x4000, 0x0020, 0x0001, 0x0200, 0x0001}; + INT16_TYPE green_K[9] = {0x0000, 0x1001, 0x0000, 0x1001, 0x0440, 0x1001, 0x0000, 0x1001, 0x0000}; + INT16_TYPE red_K[9] = {0x1000, 0x0020, 0x1000, 0x0200, 0x0004, 0x0200, 0x1000, 0x0020, 0x1000}; + + for (INT_TYPE i = 1; i < IN_TILE_HEIGHT - 1; i++) + { + for (INT_TYPE j = 1; j < IN_TILE_WIDTH - 1; j++) + { + +// #pragma HLS pipeline + + INT_TYPE tempRed[9], tempGreen[9], tempBlue[9]; + INT_TYPE factor = (((height_offset + i - 1) & 1) | (((width_offset + j - 1) & 1) << 1)) << 2; + +#pragma HLS array_partition variable = tempRed dim = 1 complete +#pragma HLS array_partition variable = tempGreen dim = 1 complete +#pragma HLS array_partition variable = tempBlue dim = 1 complete + + out[i - 1][j - 1][0] = 0; + out[i - 1][j - 1][1] = 0; + out[i - 1][j - 1][2] = 0; + + for (INT_TYPE kv = 0; kv < 3; kv++) + { + for (INT_TYPE kh = 0; kh < 3; kh++) + { + tempRed[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((red_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + tempGreen[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((green_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + tempBlue[kv * 3 + kh] = (in[i + kv - 1][j + kh - 1] * ((blue_K[kv * 3 + kh] >> factor) & 0xF)) >> 2; + // tempRed[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], red_K[kv*3 + kh], factor); + // tempGreen[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], green_K[kv*3 + kh], factor); + // tempBlue[kv*3 + kh] = debMul(in[i+kv-1][j+kh-1], blue_K[kv*3 + kh], factor); + } + } + + for (int c = 0; c < 9; c++) + { + out[i - 1][j - 1][0] += tempRed[c]; + out[i - 1][j - 1][1] += tempGreen[c]; + out[i - 1][j - 1][2] += tempBlue[c]; + } + + updateHist(out[i - 1][j - 1][0], blue_hist); + updateHist(out[i - 1][j - 1][1], green_hist); + updateHist(out[i - 1][j - 1][2], red_hist); + } + } + + /*for(INT_TYPE i=1; i +#include + +#include +#include + +typedef ap_uint<8> INT_TYPE; +typedef ap_uint<16> INT16_TYPE; +typedef ap_uint<20> LONG_INT_TYPE; +typedef ap_int<20> LONG_SINT_TYPE; + +#define IMG_HEIGHT 384 // height +#define IMG_WIDTH 512 // width +// #define IMG_HEIGHT 512 // height +// #define IMG_WIDTH 384 // width + +#define IN_TILE_HEIGHT 72 // height 64 + 1*2 + 3*2 +#define IN_TILE_WIDTH 72 // width 64 + 1*2 + 3*2 +// #define IN_TILE_HEIGHT 392 // height 16 + 1*2 + 3*2 +// #define IN_TILE_WIDTH 72 // width 16 + 1*2 + 3*2 + +#define TILE_HEIGHT (IN_TILE_HEIGHT - 2) +#define TILE_WIDTH (IN_TILE_WIDTH - 2) + +#define N_TILES_X IMG_WIDTH / (IN_TILE_WIDTH - 8) +#define N_TILES_Y IMG_HEIGHT / (IN_TILE_HEIGHT - 8) + +#define COLOR_INT 256 + +// #define DEBUG_ROW 155 +// #define DEBUG_COL 299 + +/* IP Blocks */ +void img_pipeline(INT_TYPE in[IMG_HEIGHT][IMG_WIDTH], + INT_TYPE out[IMG_HEIGHT][IMG_WIDTH][3]); + +void debayer(INT_TYPE in[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE out[TILE_HEIGHT][TILE_WIDTH][3], + int ti, + int tj, + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT]); + +void tile_dehaze(INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3]); + +void update_vmin_vmax( + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT], + INT_TYPE vmin[3], + INT_TYPE vmax[3]); + +void wb_apply_transform_tile( + INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE vmin[3], + INT_TYPE vmax[3]); + +/* Util Functions */ +void load_input_tile_from_DRAM( + INT_TYPE in_tile[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE in_img[IMG_HEIGHT][IMG_WIDTH], + int ti, + int tj); +void store_output_tile_to_DRAM( + INT_TYPE out_fm_buf[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE out_fm[IMG_HEIGHT][IMG_WIDTH][3], + int ti, + int tj); + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/utils.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/utils.cpp new file mode 100644 index 000000000000..c88d75f8bd0b --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/utils.cpp @@ -0,0 +1,60 @@ +#include "pipeline.h" + +void load_input_tile_from_DRAM( + INT_TYPE in_tile[IN_TILE_HEIGHT][IN_TILE_WIDTH], + INT_TYPE in_img[IMG_HEIGHT][IMG_WIDTH], + int ti, + int tj) +{ + const int height_offset = (ti * (IN_TILE_HEIGHT - 8)); // OUT_BUF is intended, not a typo. + const int width_offset = (tj * (IN_TILE_WIDTH - 8)); + +INPUT_BUFFER_HEIGHT: + for (int i = 0; i < IN_TILE_HEIGHT; i++) + { + INPUT_BUFFER_WIDTH: + for (int j = 0; j < IN_TILE_WIDTH; j++) + { + if (!((height_offset + i - 4 < 0) || (width_offset + j - 4 < 0) || (height_offset + i - 4 > IMG_HEIGHT) || (width_offset + j - 4 > IMG_WIDTH))) + { + in_tile[i][j] = in_img[height_offset + i - 4][width_offset + j - 4]; + } + } + } +} + +void store_output_tile_to_DRAM( + INT_TYPE out_fm_buf[TILE_HEIGHT][TILE_WIDTH][3], + INT_TYPE out_fm[IMG_HEIGHT][IMG_WIDTH][3], + int ti, + int tj) +{ + const int height_offset = (ti * (TILE_HEIGHT - 6)); + const int width_offset = (tj * (TILE_WIDTH - 6)); + +OUTPUT_BUFFER_HEIGHT: + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + OUTPUT_BUFFER_WIDTH: + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][0] = out_fm_buf[i][j][0]; + } + } + + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][1] = out_fm_buf[i][j][1]; + } + } + + for (int i = 3; i < TILE_HEIGHT - 3; i++) + { + for (int j = 3; j < TILE_WIDTH - 3; j++) + { + out_fm[height_offset + i - 3][width_offset + j - 3][2] = out_fm_buf[i][j][2]; + } + } +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/whitebalance.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/whitebalance.cpp new file mode 100644 index 000000000000..7131e2302e21 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Dehazing-denoising/source_code/src__script/whitebalance.cpp @@ -0,0 +1,113 @@ +#include +#include "pipeline.h" + + +void update_vmin_vmax( + LONG_INT_TYPE blue_hist[COLOR_INT], + LONG_INT_TYPE green_hist[COLOR_INT], + LONG_INT_TYPE red_hist[COLOR_INT], + INT_TYPE vmin[3], + INT_TYPE vmax[3] +) +{ + + LONG_INT_TYPE pixel_cnt[3] = {0,0,0}; + #pragma HLS ARRAY_PARTITION variable = pixel_cnt complete dim = 1 + LONG_INT_TYPE pixel_cnt2[3] = {0,0,0}; + #pragma HLS ARRAY_PARTITION variable = pixel_cnt2 complete dim = 1 + + LONG_INT_TYPE N = IMG_HEIGHT * IMG_WIDTH; + INT_TYPE factor = 20; + + for(int i=0; i < COLOR_INT; i++) + { + if(pixel_cnt[0] <= N/factor){ + pixel_cnt[0] += blue_hist[i]; + vmin[0] = i; + } + if(pixel_cnt[1] <= N/factor){ + pixel_cnt[1] += green_hist[i]; + vmin[1] = i; + } + if(pixel_cnt[2] <= N/factor){ + pixel_cnt[2] += red_hist[i]; + vmin[2] = i; + } + + if(pixel_cnt2[0] <= (N*factor-N)/factor){ + pixel_cnt2[0] += blue_hist[i]; + vmax[0] = i; + } + if(pixel_cnt2[1] <= (N*factor-N)/factor){ + pixel_cnt2[1] += green_hist[i]; + vmax[1] = i; + } + if(pixel_cnt2[2] <= (N*factor-N)/factor){ + pixel_cnt2[2] += red_hist[i]; + vmax[2] = i; + } + } +} + +void wb_apply_transform_tile(INT_TYPE image_tile[TILE_HEIGHT][TILE_WIDTH][3], INT_TYPE vmin[3], INT_TYPE vmax[3]) +{ + //white balance the image + for (int i = 0; i < TILE_HEIGHT; i++) + { + for (int j = 0; j < TILE_WIDTH; j++) + { + + if(image_tile[i][j][0] > vmax[0]) + image_tile[i][j][0] = vmax[0]; + + if(image_tile[i][j][0] < vmin[0]) + image_tile[i][j][0] = vmin[0]; + + if(image_tile[i][j][1] > vmax[1]) + image_tile[i][j][1] = vmax[1]; + + if(image_tile[i][j][1] < vmin[1]) + image_tile[i][j][1] = vmin[1]; + + if(image_tile[i][j][2] > vmax[2]) + image_tile[i][j][2] = vmax[2]; + + if(image_tile[i][j][2] < vmin[2]) + image_tile[i][j][2] = vmin[2]; + + //APPLY AFFINE TRANSFORMATION + + //image_tile[i][j][0] = ((image_tile[i][j][0] - vmin[0]) * COLOR_INT) / (vmax[0] - vmin[0]); + //image_tile[i][j][1] = ((image_tile[i][j][1] - vmin[1]) * COLOR_INT) / (vmax[1] - vmin[1]); + //image_tile[i][j][2] = ((image_tile[i][j][2] - vmin[2]) * COLOR_INT) / (vmax[2] - vmin[2]); + + LONG_SINT_TYPE image_tile_0 = ((image_tile[i][j][0] - vmin[0]) * COLOR_INT) / (vmax[0] - vmin[0]); + LONG_SINT_TYPE image_tile_1 = ((image_tile[i][j][1] - vmin[1]) * COLOR_INT) / (vmax[1] - vmin[1]); + LONG_SINT_TYPE image_tile_2 = ((image_tile[i][j][2] - vmin[2]) * COLOR_INT) / (vmax[2] - vmin[2]); + + //APPLY FLOOR AND CEIL + + if(image_tile_0 >= COLOR_INT) + image_tile[i][j][0] = COLOR_INT - 1; + else if(image_tile_0 < 0) + image_tile[i][j][0] = 0; + else + image_tile[i][j][0] = image_tile_0; + + if(image_tile_1 >= COLOR_INT) + image_tile[i][j][1] = COLOR_INT - 1; + else if(image_tile_1 < 0) + image_tile[i][j][1] = 0; + else + image_tile[i][j][1] = image_tile_1; + + if(image_tile_2 >= COLOR_INT) + image_tile[i][j][2] = COLOR_INT - 1; + else if(image_tile_2 < 0) + image_tile[i][j][2] = 0; + else + image_tile[i][j][2] = image_tile_2; + } + } + +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp.h new file mode 100644 index 000000000000..7c12d349891d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp.h @@ -0,0 +1,150 @@ +#include "../gradient.h" + +template +void model_relu_fc_grad( + fm_t input_gradient_map[inp_height][inp_width], + fm_t input_relu_map[inp_width], + fm_t output_gradient_map[inp_height][inp_width] +) +{ +//-------------------------------------------------------------------------- +// Performs Relu activation for gradients of an FC layer ` +//-------------------------------------------------------------------------- + + for(int i=0; i 0) + output_gradient_map[j][i] = input_relu_map[i]; + else + output_gradient_map[j][i] = 0; + } + } +} + +template +void model_fc_grad( + fm_t input_gradient_map[inp_height][inp_width], + wt_t layer_weights[inp_width][out_width], + fm_t output_gradient_map[inp_height][out_width] +) +{ +//-------------------------------------------------------------------------- +// Performs gradient computation across two FC layers +//-------------------------------------------------------------------------- + + + for(int i=0; i +void model_reshape( + fm_t input_gradient_map[num_classes][out_channel*out_height*out_width], + fm_t output_gradient_map[num_classes][out_channel][out_height][out_width] +) +{ +//-------------------------------------------------------------------------- +// Reshapes FC layer gradient into previous Conv layers shape +// Useful at the transition between FC and CONV layers +//-------------------------------------------------------------------------- + + for(int i=0; i +void model_upsample( + fm_t input_gradient_map[num_classes][inp_channel][inp_height][inp_width], + mk_t mask_map[inp_channel][inp_height][inp_width], + fm_t output_gradient_map[num_classes][inp_channel][inp_height*2][inp_width*2] +) +{ +//-------------------------------------------------------------------------- +// Upsamples the gradient to propagate back from a max-pool layer +//-------------------------------------------------------------------------- + + for(int ic=0; ic +void model_flipped_conv( + fm_t input_gradient_map[num_classes][inp_channel][inp_height][inp_width], + wt_t layer_weights[inp_channel][out_channel][3][3], + fm_t output_gradient_map[num_classes][out_channel][inp_height][inp_width] +) +{ + + fm_t current_ip; + + for(int i=0; i inp_height || \ + (ow+fw) > inp_width){ + current_ip = 0; + } + + else{ + current_ip = input_gradient_map[ic][oh+fh-1][ow+fw-1]; + } + + // MAC operation + if(ic == 0 && fh == 0 && fw == 0) + output_gradient_map[oc][oh][ow] = current_ip * layer_weights[ic][oc][2-fh][2-fw]; + else + output_gradient_map[oc][oh][ow] += current_ip * layer_weights[ic][oc][2-fh][2-fw]; + + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp_single_class.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp_single_class.h new file mode 100644 index 000000000000..4aab7b58424d --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/bp_single_class.h @@ -0,0 +1,139 @@ +#include "../gradient.h" + +template +void model_relu_fc_grad_single( + fm_t input_gradient_map[inp_width], + fm_t input_relu_map[inp_width], + fm_t output_gradient_map[inp_width] +) +{ +//-------------------------------------------------------------------------- +// Performs Relu activation for gradients of an FC layer +//-------------------------------------------------------------------------- + + for(int i=0; i 0) + output_gradient_map[i] = input_gradient_map[i]; + else + output_gradient_map[i] = 0; + } +} + +template +void model_fc_grad_single( + fm_t input_gradient_map[inp_width], + wt_t layer_weights[inp_width][out_width], + fm_t output_gradient_map[out_width] +) +{ +//-------------------------------------------------------------------------- +// Performs gradient computation across two FC layers +//-------------------------------------------------------------------------- + + for(int j=0; j +void model_reshape_single( + fm_t input_gradient_map[out_channel*out_height*out_width], + fm_t output_gradient_map[out_channel][out_height][out_width] +) +{ +//-------------------------------------------------------------------------- +// Reshapes FC layer gradient into previous Conv layers shape +// Useful at the transition between FC and CONV layers +//-------------------------------------------------------------------------- + + for(int oc=0; oc +void model_upsample_single( + fm_t input_gradient_map[inp_channel][inp_height][inp_width], + mk_t mask_map[inp_channel][inp_height][inp_width], + fm_t output_gradient_map[inp_channel][inp_height*2][inp_width*2] +) +{ +//-------------------------------------------------------------------------- +// Upsamples the gradient to propagate back from a max-pool layer +//-------------------------------------------------------------------------- + + for(int ic=0; ic +void model_flipped_conv_single( + fm_t input_gradient_map[inp_channel][inp_height][inp_width], + wt_t layer_weights[inp_channel][out_channel][3][3], + fm_t output_gradient_map[out_channel][inp_height][inp_width] +) +{ + + fm_t current_ip; + + for(int oc=0; oc inp_height || \ + (ow+fw) > inp_width){ + current_ip = 0; + } + + else{ + current_ip = input_gradient_map[ic][oh+fh-1][ow+fw-1]; + } + + // MAC operation + if(ic == 0 && fh == 0 && fw == 0) + output_gradient_map[oc][oh][ow] = current_ip * layer_weights[ic][oc][2-fh][2-fw]; + else + output_gradient_map[oc][oh][ow] += current_ip * layer_weights[ic][oc][2-fh][2-fw]; + + } + } + } + } + } + } +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/fp.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/fp.h new file mode 100644 index 000000000000..844aa5e894bf --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/cmodel/fp.h @@ -0,0 +1,160 @@ +#include "../gradient.h" + +template +void model_conv( + fm_t input_feature_map[inp_channel][inp_height][inp_width], + wt_t layer_weights[out_channel][inp_channel][3][3], + wt_t layer_bias[out_channel], + fm_t output_feature_map[out_channel][inp_height][inp_width] +) +{ +//-------------------------------------------------------------------------- +// Performs convolution with padding along with adding bias +// No activation function at the end +//-------------------------------------------------------------------------- + + fm_t current_ip; + + for(int oc=0; oc inp_height || \ + (ow+fw) > inp_width){ + current_ip = 0; + } + + else{ + current_ip = input_feature_map[ic][oh+fh-1][ow+fw-1]; + } + + // MAC operation + if(ic == 0 && fh == 0 && fw == 0) + output_feature_map[oc][oh][ow] = current_ip * layer_weights[oc][ic][fh][fw] + layer_bias[oc]; + else + output_feature_map[oc][oh][ow] += current_ip * layer_weights[oc][ic][fh][fw]; + + } + } + } + } + } + } + +} + +template +void model_conv_flatten_fc( + fm_t input_feature_map[inp_channel][inp_height][inp_width], + wt_t layer_weights[wt_height][wt_width], + wt_t layer_bias[wt_height], + fm_t output_feature_map[wt_height] +) +{ +//-------------------------------------------------------------------------- +// For convolution layer going into a fully-connected layer +// Flattens the CNN feature map and, +// computes the matrix multiplication with the FC layer weights +// No activation function at the end +//-------------------------------------------------------------------------- + + for(int i=0; i +void model_max_pool( + fm_t input_feature_map[inp_channel][inp_height][inp_width], + fm_t output_feature_map[inp_channel][inp_height/2][inp_width/2], + mk_t mask_map[inp_channel][inp_height/2][inp_width/2] +) +{ +//-------------------------------------------------------------------------- +// Performs max-pooling +//-------------------------------------------------------------------------- + + fm_t max; + mk_t pos; + + for(int ic = 0; ic < inp_channel; ic++){ + for(int ih = 0; ih < inp_height; ih+=2){ + for(int iw = 0; iw < inp_width; iw+=2){ + + max = input_feature_map[ic][ih][iw]; + pos = 0; + + if(max < input_feature_map[ic][ih][iw+1]){ + max = input_feature_map[ic][ih][iw+1]; + pos = 1; + } + + if(max < input_feature_map[ic][ih+1][iw]){ + max = input_feature_map[ic][ih+1][iw]; + pos = 2; + } + + if(max < input_feature_map[ic][ih+1][iw+1]){ + max = input_feature_map[ic][ih+1][iw+1]; + pos = 3; + } + + output_feature_map[ic][ih/2][iw/2] = max; + mask_map[ic][ih/2][iw/2] = pos; + + } + } + } +} + +template +void model_relu_fc( + fm_t input_feature_map[inp_length], + fm_t output_feature_map[inp_length] +) +{ +//-------------------------------------------------------------------------- +// Performs Relu activation on a flatten channel +//-------------------------------------------------------------------------- + + for(int i = 0; i < inp_length; i++){ + if(input_feature_map[i] > 0) + output_feature_map[i] = input_feature_map[i]; + else + output_feature_map[i] = 0; + } +} + +template +void model_mat_mul( + fm_t input_feature_map[inp_length], + wt_t layer_weights[out_length][inp_length], + wt_t layer_bias[out_length], + fm_t output_feature_map[out_length] +) +{ + + for(int i=0; i +#include +#include +#include + +//-------------------------------------------------------------------------- +// Compiler Defines +//-------------------------------------------------------------------------- +#ifdef HLS_SIM + #include "config.h" +#endif + +//-------------------------------------------------------------------------- +// Type Conversions +//-------------------------------------------------------------------------- +#ifdef CSIM_DEBUG + typedef float fm_t; + typedef float wt_t; + typedef float fm_t; + typedef float mk_t; + +#else + typedef ap_fixed<16,2> fm_t; + typedef ap_fixed<16,2> wt_t; + typedef ap_fixed<16,2> fm_t; + typedef ap_int<2> mk_t; // mask bits +#endif +//-------------------------------------------------------------------------- +// Function Declarations +//-------------------------------------------------------------------------- + +#define IM_SIZE 32 + +#define IN_BUF_DEPTH 8 +#define OUT_BUF_DEPTH 8 + +#define OUT_BUF_HEIGHT 8 +#define OUT_BUF_WIDTH 8 +#define IN_BUF_HEIGHT OUT_BUF_HEIGHT + 2 +#define IN_BUF_WIDTH OUT_BUF_WIDTH + 2 + +#define BLOCK_SIZE_M 16 +#define BLOCK_SIZE_N 16 + + +void tiled_conv( + fm_t fixp_layer1_ifmap[3][IM_SIZE][IM_SIZE], // input image + fm_t fixp_layer2_ifmap[32][IM_SIZE][IM_SIZE], // output of conv1 + fm_t fixp_layer3_ifmap[32][IM_SIZE][IM_SIZE], // output of conv2 + fm_t fixp_layer4_ifmap[32][IM_SIZE/2][IM_SIZE/2], // output of max_pool1 + fm_t fixp_layer5_ifmap[64][IM_SIZE/2][IM_SIZE/2], // output of conv3 + fm_t fixp_layer6_ifmap[64][IM_SIZE/2][IM_SIZE/2], // output of conv4 + fm_t fixp_layer7_ifmap[64][IM_SIZE/4][IM_SIZE/4], // output of max_pool2 + fm_t fixp_layer8_ifmap[128], // output of fc1 + fm_t fixp_layer9_ifmap[128], // output of ReLU1 + fm_t fixp_layer10_ifmap[10], // output of fc2 + + wt_t fixp_conv1_weights[32][3][3][3], + wt_t fixp_conv1_bias[32], + wt_t fixp_conv2_weights[32][32][3][3], + wt_t fixp_conv2_bias[32], + wt_t fixp_conv3_weights[64][32][3][3], + wt_t fixp_conv3_bias[64], + wt_t fixp_conv4_weights[64][64][3][3], + wt_t fixp_conv4_bias[64], + wt_t fixp_fc1_weights[128][4096], + wt_t fixp_fc1_bias[128], + wt_t fixp_fc2_weights[10][128], + wt_t fixp_fc2_bias[10], + + fm_t fixp_grad1[128], + fm_t fixp_grad2[128], + fm_t fixp_grad3[4096], + fm_t fixp_grad4[64][IM_SIZE/4][IM_SIZE/4], + fm_t fixp_grad5[64][IM_SIZE/2][IM_SIZE/2], + fm_t fixp_grad6[64][IM_SIZE/2][IM_SIZE/2], + fm_t fixp_grad7[32][IM_SIZE/2][IM_SIZE/2], + fm_t fixp_grad8[32][IM_SIZE][IM_SIZE], + fm_t fixp_grad9[32][IM_SIZE][IM_SIZE], + fm_t fixp_grad10[3][IM_SIZE][IM_SIZE], + + mk_t fixp_mask_maxpool2[64][IM_SIZE/4][IM_SIZE/4], + mk_t fixp_mask_maxpool1[32][IM_SIZE/2][IM_SIZE/2] + +); + + +// void tiled_conv_forward( + +// ); + +#endif \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/io.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/io.h new file mode 100644 index 000000000000..76a432c502dc --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/io.h @@ -0,0 +1,114 @@ +#include "gradient.h" +#include +#include +#include +#include + +using namespace std; + +template +void read_input_feature(float ifmap[inp_channel][inp_height][inp_width]){ + + for(int ic=0; ic +void read_conv_weight(const string& file, float conv_weight[out_channel][inp_channel][k_height][k_width]){ + int size = out_channel*inp_channel*k_height*k_width; + + ifstream ifs_conv_input(file, ios::in | ios::binary); + ifs_conv_input.read((char*)(***conv_weight), size*sizeof(float)); + ifs_conv_input.close(); +} + +template +void read_conv_bias(const string& file, float conv_bias[out_channel]){ + + ifstream ifs_conv_bias(file, ios::in | ios::binary); + ifs_conv_bias.read((char*)(conv_bias), out_channel*sizeof(float)); + ifs_conv_bias.close(); +} + +template +void read_fc_weight(string file, float fc_weight[length][width]){ + + ifstream ifs_fc_weight(file, ios::in | ios::binary); + ifs_fc_weight.read((char*)(*fc_weight), width*length*sizeof(float)); + ifs_fc_weight.close(); +} + +template +void read_fc_bias(string file, float fc_bias[length]){ + + ifstream ifs_fc_bias(file, ios::in | ios::binary); + ifs_fc_bias.read((char*)(fc_bias), length*sizeof(float)); + ifs_fc_bias.close(); +} + +template +void convert_input_3d( + float conv_feature_map[inp_channel][inp_height][inp_width], + fm_t fixp_conv_feature_map[inp_channel][inp_height][inp_width] +) +{ + for(int c = 0; c < inp_channel; c++) + for(int i = 0; i < inp_height; i++) + for(int j = 0; j < inp_width; j++) + fixp_conv_feature_map[c][i][j] = (fm_t) conv_feature_map[c][i][j]; +} + +template +void convert_input_1d( + float fc_feature_map[length], + fm_t fixp_fc_feature_map[length] +) +{ + for(int i=0; i +void convert_conv_layer_params( + float conv_layer_weights[out_channel][inp_channel][3][3], + float conv_layer_bias[out_channel], + wt_t fixp_conv_layer_weights[out_channel][inp_channel][3][3], + wt_t fixp_conv_layer_bias[out_channel] +) +{ + for(int oc=0; oc +void convert_fc_layer_params( + float fc_layer_weights[out_length][inp_length], + float fc_layer_bias[out_length], + wt_t fixp_fc_layer_weights[out_length][inp_length], + wt_t fixp_fc_layer_bias[out_length] +) +{ + for(int i=0; i( + conv_in_buf, + fixp_layer1_ifmap, + ti, + tj, + d + ); + + load_conv_layer_params_from_DRAM <32,3> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv1_weights, + fixp_conv1_bias, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 3, + 32 + ); + } + + store_output_tile_to_DRAM <32, IM_SIZE, IM_SIZE> ( + fixp_layer2_ifmap, + conv_out_buf, + ti, + tj, + b, + 0 + ); + } + } + } + + std::cout << "----------------Layer 2: Conv2---------------------\n"; + + fp_conv2: + for(int ti = 0; ti < IM_SIZE/OUT_BUF_HEIGHT; ti++) + { + for(int tj = 0; tj < IM_SIZE/OUT_BUF_WIDTH; tj++) + { + std::cout << "Processing Tile " << ti*IM_SIZE/OUT_BUF_WIDTH + tj + 1; + std::cout << "/" << IM_SIZE/OUT_BUF_HEIGHT * IM_SIZE/OUT_BUF_WIDTH << std::endl; + + for(int b=0; b<32/OUT_BUF_DEPTH; b++){ + + for(int d=0; d<32/IN_BUF_DEPTH; d++){ + + fp_conv2_load_in: load_input_tile_block_from_DRAM <32,IM_SIZE,IM_SIZE>( + conv_in_buf, + fixp_layer2_ifmap, + ti, + tj, + d + ); + + fp_conv2_load_wt: load_conv_layer_params_from_DRAM <32,32> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv2_weights, + fixp_conv2_bias, + b, + d + ); + + fp_conv2_conv3x3: conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 32, + 32 + ); + } + + fp_conv2_store_out: store_output_tile_to_DRAM <32, IM_SIZE, IM_SIZE> ( + fixp_layer3_ifmap, + conv_out_buf, + ti, + tj, + b, + 0 + ); + + // Layer 4 maxpooling -- can remove the above function to skip layer3 storing to DRAM + store_maxpool_output_tile_to_DRAM <32, IM_SIZE/2, IM_SIZE/2> ( + fixp_layer4_ifmap, + fixp_mask_maxpool1, + conv_out_buf, + ti, + tj, + b + ); + } + } + } + + std::cout << "----------------Layer 4: Conv3---------------------\n"; + + fp_conv3: + for(int ti = 0; ti < IM_SIZE/2/OUT_BUF_HEIGHT; ti++) + { + for(int tj = 0; tj < IM_SIZE/2/OUT_BUF_WIDTH; tj++) + { + std::cout << "Processing Tile " << ti*IM_SIZE/2/OUT_BUF_WIDTH + tj + 1; + std::cout << "/" << IM_SIZE/2/OUT_BUF_HEIGHT * IM_SIZE/2/OUT_BUF_WIDTH << std::endl; + + for(int b=0; b<64/OUT_BUF_DEPTH; b++){ + + for(int d=0; d<32/IN_BUF_DEPTH; d++){ + + load_input_tile_block_from_DRAM <32,IM_SIZE/2,IM_SIZE/2>( + conv_in_buf, + fixp_layer4_ifmap, + ti, + tj, + d + ); + + load_conv_layer_params_from_DRAM <64,32> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv3_weights, + fixp_conv3_bias, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 32, + 64 + ); + } + + store_output_tile_to_DRAM <64, IM_SIZE/2, IM_SIZE/2> ( + fixp_layer5_ifmap, + conv_out_buf, + ti, + tj, + b, + 0 + ); + + } + } + } + + std::cout << "----------------Layer 5: Conv4---------------------\n"; + + fp_conv4: + for(int ti = 0; ti < IM_SIZE/2/OUT_BUF_HEIGHT; ti++) + { + for(int tj = 0; tj < IM_SIZE/2/OUT_BUF_WIDTH; tj++) + { + std::cout << "Processing Tile " << ti*IM_SIZE/2/OUT_BUF_WIDTH + tj + 1; + std::cout << "/" << IM_SIZE/2/OUT_BUF_HEIGHT * IM_SIZE/2/OUT_BUF_WIDTH << std::endl; + + for(int b=0; b<64/OUT_BUF_DEPTH; b++){ + + for(int d=0; d<64/IN_BUF_DEPTH; d++){ + + load_input_tile_block_from_DRAM <64,IM_SIZE/2,IM_SIZE/2>( + conv_in_buf, + fixp_layer5_ifmap, + ti, + tj, + d + ); + + load_conv_layer_params_from_DRAM <64,64> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv4_weights, + fixp_conv4_bias, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 64, + 64 + ); + } + + store_output_tile_to_DRAM <64, IM_SIZE/2, IM_SIZE/2> ( + fixp_layer6_ifmap, + conv_out_buf, + ti, + tj, + b, + 0 + ); + + store_maxpool_output_tile_to_DRAM <64, IM_SIZE/4, IM_SIZE/4> ( + fixp_layer7_ifmap, + fixp_mask_maxpool2, + conv_out_buf, + ti, + tj, + b + ); + + } + } + } + + // for (int i=0; i<8; i++){ + // cout << fixp_layer7_ifmap[0][0][i] << endl; + // } + + std::cout << "----------------Layer 7: FC1---------------------\n"; + + mk_t relu_mask_fc1[128]; + + fp_fc1: + for(int tm = 0; tm < 128/BLOCK_SIZE_M; tm++){ + for(int tn = 0; tn < 4096/BLOCK_SIZE_N; tn++){ + load_flattened_mat_vec_tile_block_from_DRAM <64*8*8, 128, 64, 8, 8> ( + fixp_layer7_ifmap, + fixp_fc1_weights, + fixp_fc1_bias, + vecB_buf, + matA_buf, + fc_bias_buf, + tm, + tn + ); + + mat_vec_mul( + vecB_buf, + matA_buf, + fc_bias_buf, + vecC_buf, + tn + ); + } + + store_output_vec_tile_to_DRAM <128>( + fixp_layer9_ifmap, + relu_mask_fc1, + vecC_buf, + tm, + 1 + ); + } + + std::cout << "----------------Layer 9: FC2---------------------\n"; + + mk_t relu_mask_fc2[10]; + + fp_fc2: + for(int tm = 0; tm < 1; tm++){ + for(int tn = 0; tn < 128/BLOCK_SIZE_N; tn++){ + load_mat_vec_tile_block_from_DRAM <128,10> ( + fixp_layer9_ifmap, + fixp_fc2_weights, + fixp_fc2_bias, + vecB_buf, + matA_buf, + fc_bias_buf, + tm, + tn + ); + + mat_vec_mul( + vecB_buf, + matA_buf, + fc_bias_buf, + vecC_buf, + tn + ); + } + + store_output_vec_tile_to_DRAM <10>( + fixp_layer10_ifmap, + relu_mask_fc2, + vecC_buf, + tm, + 0 + ); + } + + // for (int i=0; i<10; i++){ + // std::cout << fixp_layer10_ifmap[i] << std::endl; + // } + + std::cout << "----------------BACKWARD PASS---------------------\n"; + + std::cout << "----------------FC2---------------------\n"; + bp_fc2: + for (int i=0; i<128; i++){ + fixp_grad1[i] = (fm_t) fixp_fc2_weights[0][i]; + fixp_grad2[i] = (fm_t) fixp_grad1[i] * (1-relu_mask_fc1[i]); + }; + + mk_t relu_mask_fc1_bp[4096]; + + std::cout << "----------------FC1---------------------\n"; + + bp_fc1: + for(int tm = 0; tm < 4096/BLOCK_SIZE_M; tm++){ + for(int tn = 0; tn < 128/BLOCK_SIZE_N; tn++){ + load_transpose_mat_vec_tile_block_from_DRAM <128,4096> ( + fixp_grad2, + fixp_fc1_weights, + vecB_buf, + matA_buf, + fc_bias_buf, + tm, + tn + ); + + mat_vec_mul( + vecB_buf, + matA_buf, + fc_bias_buf, + vecC_buf, + tn + ); + } + + + store_output_vec_tile_to_DRAM <4096>( + fixp_grad3, + relu_mask_fc1_bp, + vecC_buf, + tm, + 0 + ); + } + + std::cout << "----------------Maxpool2---------------------\n"; + + bp_maxp2: + fm_t temp; + for(int ic=0; ic<64; ic++){ + for(int ih=0; ih( + conv_in_buf, + fixp_grad5, + ti, + tj, + d + ); + + load_transpose_flipped_conv_layer_params_from_DRAM <64,64> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv4_weights, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 64, + 64 + ); + } + + store_output_tile_to_DRAM <64, IM_SIZE/2, IM_SIZE/2> ( + fixp_grad6, + conv_out_buf, + ti, + tj, + b, + 0 + ); + } + } + } + + + std::cout << "----------------Conv 3---------------------\n"; + + bp_conv3: + for(int ti = 0; ti < IM_SIZE/2/OUT_BUF_HEIGHT; ti++) + { + for(int tj = 0; tj < IM_SIZE/2/OUT_BUF_WIDTH; tj++) + { + std::cout << "Processing Tile " << ti*IM_SIZE/2/OUT_BUF_WIDTH + tj + 1; + std::cout << "/" << IM_SIZE/2/OUT_BUF_HEIGHT * IM_SIZE/2/OUT_BUF_WIDTH << std::endl; + + for(int b=0; b<32/OUT_BUF_DEPTH; b++){ + + for(int d=0; d<64/IN_BUF_DEPTH; d++){ + + load_input_tile_block_from_DRAM <64,IM_SIZE/2,IM_SIZE/2>( + conv_in_buf, + fixp_grad6, + ti, + tj, + d + ); + + load_transpose_flipped_conv_layer_params_from_DRAM <32,64> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv3_weights, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 64, + 32 + ); + } + + store_output_tile_to_DRAM <32, IM_SIZE/2, IM_SIZE/2> ( + fixp_grad7, + conv_out_buf, + ti, + tj, + b, + 0 + ); + } + } + } + + std::cout << "----------------Maxpool1---------------------\n"; + + bp_maxp1: + for(int ic=0; ic<64; ic++){ + for(int ih=0; ih( + conv_in_buf, + fixp_grad8, + ti, + tj, + d + ); + + load_transpose_flipped_conv_layer_params_from_DRAM <32,32> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv2_weights, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 32, + 32 + ); + } + + store_output_tile_to_DRAM <32, IM_SIZE, IM_SIZE> ( + fixp_grad9, + conv_out_buf, + ti, + tj, + b, + 0 + ); + } + } + } + + std::cout << "----------------Conv 1---------------------\n"; + + bp_conv1: + for(int ti = 0; ti < IM_SIZE/OUT_BUF_HEIGHT; ti++) + { + for(int tj = 0; tj < IM_SIZE/OUT_BUF_WIDTH; tj++) + { + std::cout << "Processing Tile " << ti*IM_SIZE/OUT_BUF_WIDTH + tj + 1; + std::cout << "/" << IM_SIZE/OUT_BUF_HEIGHT * IM_SIZE/OUT_BUF_WIDTH << std::endl; + + for(int b=0; b<1; b++){ + + for(int d=0; d<32/IN_BUF_DEPTH; d++){ + + load_input_tile_block_from_DRAM <32,IM_SIZE,IM_SIZE>( + conv_in_buf, + fixp_grad9, + ti, + tj, + d + ); + + load_transpose_flipped_conv_layer_params_from_DRAM <3,32> ( + conv_wt_buf, + conv_bias_buf, + fixp_conv1_weights, + b, + d + ); + + conv_3x3( + conv_out_buf, + conv_in_buf, + conv_wt_buf, + conv_bias_buf, + d, + 32, + 3 + ); + } + + store_output_tile_to_DRAM <3, IM_SIZE, IM_SIZE> ( + fixp_grad10, + conv_out_buf, + ti, + tj, + b, + 0 + ); + } + } + } + +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/utils.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/utils.h new file mode 100644 index 000000000000..535b2a8e5d70 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/Explainable-ML/source_code/utils.h @@ -0,0 +1,480 @@ +#include "gradient.h" + +//-------------------------------------------------------------------------- +// Function to load input feature map tile block from DRAM to on-chip BRAM. +//-------------------------------------------------------------------------- +template +void load_input_tile_block_from_DRAM ( + fm_t in_fm_buf[IN_BUF_DEPTH][IN_BUF_HEIGHT][IN_BUF_WIDTH], + fm_t in_fm[inp_channel][inp_height][inp_width], + int ti, + int tj, + int d +) +{ + #pragma HLS inline off + + int IN_BUF_DEPTH_MUX; + if (inp_channel < IN_BUF_DEPTH) + IN_BUF_DEPTH_MUX = inp_channel; + else + IN_BUF_DEPTH_MUX = IN_BUF_DEPTH; + + const int depth_offset = d * IN_BUF_DEPTH; + const int height_offset = ti * OUT_BUF_HEIGHT; // OUT_BUF is intended, not a typo. + const int width_offset = tj * OUT_BUF_WIDTH; + + INPUT_BUFFER_DEPTH: + for(int c = 0; c < IN_BUF_DEPTH_MUX; c++) + { + INPUT_BUFFER_HEIGHT: + for(int i = 0; i < IN_BUF_HEIGHT; i++) + { + INPUT_BUFFER_WIDTH: + for(int j = 0; j < IN_BUF_WIDTH; j++) + { + // TODO: Handle border features here + if ( height_offset+i-1 >= 0 && height_offset+i-1 < inp_height && width_offset + j -1 >=0 && width_offset + j -1 < inp_width ) + { + in_fm_buf[c][i][j] = in_fm[depth_offset + c][height_offset + i - 1][width_offset + j - 1]; + } + else + in_fm_buf[c][i][j] = 0; + } + } + } +} + +//-------------------------------------------------------------------------- +// Function to load layer parameters (weights and bias) for convolution. +//-------------------------------------------------------------------------- +template +void load_conv_layer_params_from_DRAM( + wt_t weight_buf[OUT_BUF_DEPTH][IN_BUF_DEPTH][3][3], + wt_t bias_buf[OUT_BUF_DEPTH], + wt_t weights[out_channel][inp_channel][3][3], + wt_t bias[out_channel], + int b, + int d +) +{ + #pragma HLS inline off + + int IN_BUF_DEPTH_MUX; + if (inp_channel < IN_BUF_DEPTH) + IN_BUF_DEPTH_MUX = inp_channel; + else + IN_BUF_DEPTH_MUX = IN_BUF_DEPTH; + + const int kernel_offset = b * OUT_BUF_DEPTH; + const int channel_offset = d * IN_BUF_DEPTH; + + WEIGHT_KERNEL_NUM: + for(int f = 0; f < OUT_BUF_DEPTH; f++) + { + WEIGHT_KERNEL_DEPTH: + for(int c = 0; c < IN_BUF_DEPTH_MUX; c++) + { + WEIGHT_KERNEL_HEIGHT: + for(int kh = 0; kh < 3; kh++) + { + WEIGHT_KERNEL_WIDTH: + for(int kw = 0; kw < 3; kw++) + { + weight_buf[f][c][kh][kw] = weights[kernel_offset + f][channel_offset + c][kh][kw]; + } + } + } + } + + BIAS: + for(int f = 0; f < OUT_BUF_DEPTH; f++) + { + bias_buf[f] = bias[kernel_offset + f]; + } +} + +template +void load_transpose_flipped_conv_layer_params_from_DRAM( + wt_t weight_buf[OUT_BUF_DEPTH][IN_BUF_DEPTH][3][3], + wt_t bias_buf[OUT_BUF_DEPTH], + wt_t weights[inp_channel][out_channel][3][3], + int b, + int d +) +{ + #pragma HLS inline off + + int OUT_BUF_DEPTH_MUX; + if (out_channel < IN_BUF_DEPTH) + OUT_BUF_DEPTH_MUX = out_channel; + else + OUT_BUF_DEPTH_MUX = OUT_BUF_DEPTH; + + const int kernel_offset = b * OUT_BUF_DEPTH; + const int channel_offset = d * IN_BUF_DEPTH; + + WEIGHT_KERNEL_NUM: + for(int f = 0; f < OUT_BUF_DEPTH_MUX; f++) + { + WEIGHT_KERNEL_DEPTH: + for(int c = 0; c < IN_BUF_DEPTH; c++) + { + WEIGHT_KERNEL_HEIGHT: + for(int kh = 0; kh < 3; kh++) + { + WEIGHT_KERNEL_WIDTH: + for(int kw = 0; kw < 3; kw++) + { + weight_buf[f][c][kh][kw] = weights[channel_offset + c][kernel_offset + f][2-kh][2-kw]; + } + } + } + } + + BIAS: + for(int f = 0; f < OUT_BUF_DEPTH; f++) + { + bias_buf[f] = 0; + } + +} + + + +//--------------------------------------------------------------------------- +// Perform synthesizable tiling-based convolution for a single tile. +//--------------------------------------------------------------------------- + +void conv_3x3 ( + fm_t Y_buf[OUT_BUF_DEPTH][OUT_BUF_HEIGHT][OUT_BUF_WIDTH], + fm_t X_buf[IN_BUF_DEPTH][IN_BUF_HEIGHT][IN_BUF_WIDTH], + wt_t W_buf[OUT_BUF_DEPTH][IN_BUF_DEPTH][3][3], + wt_t bias_buf[OUT_BUF_DEPTH], + int d, + int inp_channel, + int out_channel +) +{ + if(d==0){ + init: + for(int oh=0; oh +void store_output_tile_to_DRAM ( + fm_t out_fm[out_channel][inp_height][inp_width], + fm_t out_fm_buf[OUT_BUF_DEPTH][OUT_BUF_HEIGHT][OUT_BUF_WIDTH], + int ti, + int tj, + int b, + bool relu_enable +) +{ + #pragma HLS inline + const int depth_offset = b * OUT_BUF_DEPTH; + const int height_offset = ti * OUT_BUF_HEIGHT; + const int width_offset = tj * OUT_BUF_WIDTH; + + int OUT_BUF_DEPTH_MUX = OUT_BUF_DEPTH; + + if(out_channel < OUT_BUF_DEPTH) + OUT_BUF_DEPTH_MUX = out_channel; + + OUTPUT_BUFFER_DEPTH: + for(int f = 0; f < OUT_BUF_DEPTH_MUX; f++) + { + OUTPUT_BUFFER_HEIGHT: + for(int i = 0; i < OUT_BUF_HEIGHT; i++) + { + OUTPUT_BUFFER_WIDTH: + for(int j = 0; j < OUT_BUF_WIDTH; j++) + { + // ReLU in-place + if(out_fm_buf[f][i][j] < (fm_t) 0 && relu_enable) + { + out_fm[depth_offset + f][height_offset + i][width_offset + j] = (fm_t) 0; + } + else + { + out_fm[depth_offset + f][height_offset + i][width_offset + j] = out_fm_buf[f][i][j]; + } + } + } + } +} + +//-------------------------------------------------------------------------- +// Function to store maxpooled subsampled output tile block from BRAM to DRAM. +//-------------------------------------------------------------------------- +template +void store_maxpool_output_tile_to_DRAM ( + fm_t out_fm[out_channel][inp_height][inp_width], + mk_t mask_fm[out_channel][inp_height][inp_width], + fm_t out_fm_buf[OUT_BUF_DEPTH][OUT_BUF_HEIGHT][OUT_BUF_WIDTH], + int ti, + int tj, + int b +) +{ + #pragma HLS inline + const int depth_offset = b * OUT_BUF_DEPTH; + const int height_offset = ti * OUT_BUF_HEIGHT; + const int width_offset = tj * OUT_BUF_WIDTH; + + fm_t max; + mk_t pos; + + OUTPUT_BUFFER_DEPTH: + for(int f = 0; f < OUT_BUF_DEPTH; f++) + { + OUTPUT_BUFFER_HEIGHT: + for(int i = 0; i < OUT_BUF_HEIGHT; i+=2) + { + OUTPUT_BUFFER_WIDTH: + for(int j = 0; j < OUT_BUF_WIDTH; j+=2) + { + max = out_fm_buf[f][i][j]; + pos = (mk_t) 0; + + if(max < out_fm_buf[f][i][j+1]){ + max = out_fm_buf[f][i][j+1]; + pos = (mk_t) 1; + } + + if(max < out_fm_buf[f][i+1][j]){ + max = out_fm_buf[f][i+1][j]; + pos = (mk_t) 2; + } + + if(max < out_fm_buf[f][i+1][j+1]){ + max = out_fm_buf[f][i+1][j+1]; + pos = (mk_t) 3; + } + + out_fm[depth_offset + f][(height_offset + i)/2][(width_offset + j)/2] = max; + mask_fm[depth_offset + f][(height_offset + i)/2][(width_offset + j)/2] = pos; + } + } + } +} + + +/////////////// +//-------------------------------------------------------------------------- +// Function to load Matrix and Vector tile block from DRAM to on-chip BRAM +// for FC layer convolution. +//-------------------------------------------------------------------------- +template +void load_mat_vec_tile_block_from_DRAM( + fm_t VecB_DRAM[inp_length], // inp_feature_map + wt_t MatA_DRAM[out_length][inp_length], // Layer weigths + wt_t layer_bias[out_length], // bias + fm_t VecB_buf[BLOCK_SIZE_N], + wt_t MatA_buf[BLOCK_SIZE_M][BLOCK_SIZE_N], + wt_t layer_bias_buf[BLOCK_SIZE_M], + int tm, + int tn +) +{ + #pragma HLS inline off + + const int kernel_offset = tm * BLOCK_SIZE_M; + const int channel_offset = tn * BLOCK_SIZE_N; + + // Read in the data from DRAM to BRAM + Read_A: for(int i = 0; i < BLOCK_SIZE_M; i++) + for(int j = 0; j < BLOCK_SIZE_N; j++) + MatA_buf[i][j] = MatA_DRAM[kernel_offset + i][channel_offset + j]; + + Read_B: for(int i = 0; i < BLOCK_SIZE_N; i++) + VecB_buf[i] = VecB_DRAM[channel_offset + i]; + + Read_bias: for(int i = 0; i < BLOCK_SIZE_M; i++) + layer_bias_buf[i] = layer_bias[kernel_offset + i]; +} + +template +void load_transpose_mat_vec_tile_block_from_DRAM( + fm_t VecB_DRAM[inp_length], // inp_feature_map + wt_t MatA_DRAM[inp_length][out_length], // Layer weigths + fm_t VecB_buf[BLOCK_SIZE_N], + wt_t MatA_buf[BLOCK_SIZE_M][BLOCK_SIZE_N], + wt_t layer_bias_buf[BLOCK_SIZE_M], + int tm, + int tn +) +{ + #pragma HLS inline off + + const int kernel_offset = tm * BLOCK_SIZE_M; + const int channel_offset = tn * BLOCK_SIZE_N; + + // Read in the data from DRAM to BRAM + Read_A: for(int i = 0; i < BLOCK_SIZE_M; i++) + for(int j = 0; j < BLOCK_SIZE_N; j++) + MatA_buf[i][j] = MatA_DRAM[channel_offset + j][kernel_offset + i]; + + Read_B: for(int i = 0; i < BLOCK_SIZE_N; i++) + VecB_buf[i] = VecB_DRAM[channel_offset + i]; + + Read_bias: for(int i = 0; i < BLOCK_SIZE_M; i++) + layer_bias_buf[i] = 0; + +} + +template +void load_flattened_mat_vec_tile_block_from_DRAM( + fm_t in_fm[inp_channel][inp_height][inp_width], + wt_t MatA_DRAM[out_length][inp_length], // Layer weigths + wt_t layer_bias[out_length], // bias + fm_t VecB_buf[BLOCK_SIZE_N], + wt_t MatA_buf[BLOCK_SIZE_M][BLOCK_SIZE_N], + wt_t layer_bias_buf[BLOCK_SIZE_M], + int tm, + int tn +) +{ + #pragma HLS inline off + + const int kernel_offset = tm * BLOCK_SIZE_M; + const int channel_offset = tn * BLOCK_SIZE_N; + + int ic, ih, iw, index; + + // Read in the data from DRAM to BRAM + Read_A: for(int i = 0; i < BLOCK_SIZE_M; i++) + for(int j = 0; j < BLOCK_SIZE_N; j++) + MatA_buf[i][j] = MatA_DRAM[kernel_offset + i][channel_offset + j]; + + Read_B: for(int i = 0; i < BLOCK_SIZE_N; i++){ + index = channel_offset + i; + ic = (int) index/inp_channel; + index = index - ic*inp_channel; + ih = (int) index/inp_height; + iw = index - ih*inp_height; + VecB_buf[i] = in_fm[ic][ih][iw]; + } + + Read_bias: for(int i = 0; i < BLOCK_SIZE_M; i++) + layer_bias_buf[i] = layer_bias[kernel_offset + i]; +} + +//-------------------------------------------------------------------------- +// Function to perform matrix-vec multiplication for FC layer +//-------------------------------------------------------------------------- +void mat_vec_mul( + fm_t VecB_buf[BLOCK_SIZE_N], //inp_feature_map + wt_t MatA_buf[BLOCK_SIZE_M][BLOCK_SIZE_N], //weights + wt_t layer_bias_buf[BLOCK_SIZE_M], //bias + fm_t VecC_buf[BLOCK_SIZE_M], //output_feature_map + int tn +) +{ + #pragma HLS inline off + // initialization of output vector + if (tn == 0) { + Crow_buf_init: for(int m = 0; m < BLOCK_SIZE_M; m++) + #pragma HLS unroll + VecC_buf[m] = layer_bias_buf[m]; + } + + // Compute the matrix_vec multiplication + mat_vec_row: for(int n = 0; n < BLOCK_SIZE_N; n++) { + // #pragma HLS pipeline + mat_vec_col: for(int m = 0; m < BLOCK_SIZE_M; m++) { + // #pragma HLS unroll + VecC_buf[m] += MatA_buf[m][n] * VecB_buf[n]; + } + } + +} + + +//-------------------------------------------------------------------------- +// Function to store complete output tile block from BRAM to DRAM for FC layer. +//-------------------------------------------------------------------------- +template +void store_output_vec_tile_to_DRAM( + fm_t VecC_DRAM[out_length], + mk_t relu_mask[out_length], + fm_t VecC_buf[BLOCK_SIZE_M], + int tm, + bool relu_enable +) +{ + #pragma HLS inline off + + const int kernel_offset = tm * BLOCK_SIZE_M; + + int BLOCK_SIZE_M_MUX; + if (out_length < BLOCK_SIZE_M) + BLOCK_SIZE_M_MUX = out_length; + else + BLOCK_SIZE_M_MUX = BLOCK_SIZE_M; + + Crow_dram: for(int m = 0; m < BLOCK_SIZE_M_MUX; m++) + if(relu_enable && VecC_buf[m] < 0){ + VecC_DRAM[kernel_offset + m] = 0; + relu_mask[kernel_offset + m] = (mk_t) 1; + } + else { + VecC_DRAM[kernel_offset + m] = VecC_buf[m]; + relu_mask[kernel_offset + m] = (mk_t) 0; + } +} \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/config.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/config.h new file mode 100644 index 000000000000..5314c722adc8 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/config.h @@ -0,0 +1,2 @@ +//#define CSIM_DEBUG +#define CMODEL_SIM \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.cpp new file mode 100644 index 000000000000..b78ae69d719e --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.cpp @@ -0,0 +1,253 @@ +#include "flat.h" +#include +#include +#include "hls_math.h" + +void FlatDataflow( + data_t query[576][64][16][64], + data_t key[576][64][16][64], + data_t value[576][64][16][64], + data_t bias[64][16][64][64], + data_t attention_out[576][64][16][64]) + // MEM_TYPE query[576][64][16], + // MEM_TYPE key[576][64][16], + // MEM_TYPE value[576][64][16], + // MEM_TYPE bias[64][16][64], +{ +//-------------------------------------------------------------------------- +// Defines interface IO ports for HLS. +//-------------------------------------------------------------------------- +#pragma HLS INTERFACE m_axi port=query bundle=Query offset=slave +#pragma HLS INTERFACE m_axi port=key bundle=Key offset=slave +#pragma HLS INTERFACE m_axi port=value bundle=Value_Bias offset=slave +#pragma HLS INTERFACE m_axi port=bias bundle=Value_Bias offset=slave +#pragma HLS INTERFACE m_axi port=attention_out bundle=Attention_out offset=slave + +#pragma HLS INTERFACE s_axilite register port = return + data_t query_buffer_ping[QUERY_LENGTH_F][HEAD_DIM_H], query_buffer_pong[QUERY_LENGTH_F][HEAD_DIM_H]; + data_t key_buffer_ping[KEY_LENGTH_T][HEAD_DIM_H], key_buffer_pong[KEY_LENGTH_T][HEAD_DIM_H]; + data_t value_buffer_ping[KEY_LENGTH_T][HEAD_DIM_H], value_buffer_pong[KEY_LENGTH_T][HEAD_DIM_H]; + data_t bias_buffer_ping[QUERY_LENGTH_F][KEY_LENGTH_T], bias_buffer_pong[QUERY_LENGTH_F][KEY_LENGTH_T]; + data_t logit_ping[QUERY_LENGTH_F][KEY_LENGTH_T], logit_pong[QUERY_LENGTH_F][KEY_LENGTH_T]; + data_t max_ping[QUERY_LENGTH_F], max_pong[QUERY_LENGTH_F]; + data_t softmax_ping[QUERY_LENGTH_F][KEY_LENGTH_T], softmax_pong[QUERY_LENGTH_F][KEY_LENGTH_T]; + data_t attention_out_ping[QUERY_LENGTH_F][HEAD_DIM_H], attention_out_pong[QUERY_LENGTH_F][HEAD_DIM_H]; + + //Partition the array for DRAM burst read +#pragma HLS ARRAY_PARTITION variable=query_buffer_ping dim=0 type=cyclic factor=4 +#pragma HLS ARRAY_PARTITION variable=query_buffer_pong dim=0 type=cyclic factor=4 + +#pragma HLS ARRAY_PARTITION variable=key_buffer_ping dim=0 type=block factor=4 +#pragma HLS ARRAY_PARTITION variable=key_buffer_pong dim=0 type=block factor=4 + +#pragma HLS ARRAY_PARTITION variable=value_buffer_ping dim=0 type=block factor=4 +#pragma HLS ARRAY_PARTITION variable=value_buffer_pong dim=0 type=block factor=4 + +#pragma HLS ARRAY_PARTITION variable=bias_buffer_ping dim=0 type=cyclic factor=4 +#pragma HLS ARRAY_PARTITION variable=bias_buffer_pong dim=0 type=cyclic factor=4 + +#pragma HLS ARRAY_PARTITION variable=logit_ping dim=0 type=cyclic factor=4 +#pragma HLS ARRAY_PARTITION variable=logit_pong dim=0 type=cyclic factor=4 + +#pragma HLS ARRAY_PARTITION variable=max_ping dim=0 type=complete +#pragma HLS ARRAY_PARTITION variable=max_pong dim=0 type=complete + +#pragma HLS ARRAY_PARTITION variable=softmax_ping dim=0 type=cyclic factor=4 +#pragma HLS ARRAY_PARTITION variable=softmax_pong dim=0 type=cyclic factor=4 + +#pragma HLS ARRAY_PARTITION variable=attention_out_ping dim=0 type=cyclic factor=4 +#pragma HLS ARRAY_PARTITION variable=attention_out_pong dim=0 type=cyclic factor=4 + + // Loop through all batches at one time + for (int b = 0; b < 576; ++b) + { + if (b%64 == 0) std::cout << "Next" << std::endl; + for (int n = 0; n < NUM_HEAD_N; ++n) + { + if (n == 0) + { + Load_Query_ROW_Gran(b, n, query_buffer_ping, query); + Load_Key_ROW_Gran(b, n, key_buffer_ping, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_ping, bias); + } + else if (n == 1) + { + Load_Query_ROW_Gran(b, n, query_buffer_pong, query); + Load_Key_ROW_Gran(b, n, key_buffer_pong, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_pong, bias); + + computeLogit(query_buffer_ping, key_buffer_ping, bias_buffer_ping, logit_ping, max_ping); + } + else if (n == 2) + { + Load_Query_ROW_Gran(b, n, query_buffer_ping, query); + Load_Key_ROW_Gran(b, n, key_buffer_ping, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_ping, bias); + + Load_Value_ROW_Gran(b, n - 2, value_buffer_ping, value); + + computeLogit(query_buffer_pong, key_buffer_pong, bias_buffer_pong, logit_pong, max_pong); + Inter_Softmax(logit_ping, softmax_pong, max_ping); + } + else if (n == 3) + { + Load_Query_ROW_Gran(b, n, query_buffer_pong, query); + Load_Key_ROW_Gran(b, n, key_buffer_pong, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_pong, bias); + + Load_Value_ROW_Gran(b, n - 2, value_buffer_pong, value); + + computeLogit(query_buffer_ping, key_buffer_ping, bias_buffer_ping, logit_ping, max_ping); + Inter_Softmax(logit_pong, softmax_ping, max_pong); + computeAttention(softmax_pong, value_buffer_ping, attention_out_ping); + } + else if (n == 4) + { + Load_Query_ROW_Gran(b, n, query_buffer_ping, query); + Load_Key_ROW_Gran(b, n, key_buffer_ping, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_ping, bias); + + Load_Value_ROW_Gran(b, n - 2, value_buffer_ping, value); + + computeLogit(query_buffer_pong, key_buffer_pong, bias_buffer_pong, logit_pong, max_pong); + Inter_Softmax(logit_ping, softmax_pong, max_ping); + computeAttention(softmax_ping, value_buffer_pong, attention_out_pong); + Write_Attention_Back(b, n - 4, attention_out, attention_out_ping); + } + else if (n != NUM_HEAD_N - 1) + { + if (n % 2 == 1) + { + Load_Query_ROW_Gran(b, n, query_buffer_pong, query); + Load_Key_ROW_Gran(b, n, key_buffer_pong, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_pong, bias); + + Load_Value_ROW_Gran(b, n - 2, value_buffer_pong, value); + + computeLogit(query_buffer_ping, key_buffer_ping, bias_buffer_ping, logit_ping, max_ping); + Inter_Softmax(logit_pong, softmax_ping, max_pong); + computeAttention(softmax_pong, value_buffer_ping, attention_out_ping); + Write_Attention_Back(b, n - 4, attention_out, attention_out_pong); + } + else if (n % 2 == 0) + { + Load_Query_ROW_Gran(b, n, query_buffer_ping, query); + Load_Key_ROW_Gran(b, n, key_buffer_ping, key); + Load_Bias_ROW_Gran(b, n, bias_buffer_ping, bias); + + Load_Value_ROW_Gran(b, n - 2, value_buffer_ping, value); + + computeLogit(query_buffer_pong, key_buffer_pong, bias_buffer_pong, logit_pong, max_pong); + Inter_Softmax(logit_ping, softmax_pong, max_ping); + computeAttention(softmax_ping, value_buffer_pong, attention_out_pong); + Write_Attention_Back(b, n - 4, attention_out, attention_out_ping); + } + } + else + { + // iteration 1 + Load_Value_ROW_Gran(b, n - 1, value_buffer_pong, value); + + computeLogit(query_buffer_ping, key_buffer_ping, bias_buffer_ping, logit_ping, max_ping); + Inter_Softmax(logit_pong, softmax_ping, max_pong); + computeAttention(softmax_pong, value_buffer_ping, attention_out_ping); + Write_Attention_Back(b, n - 3, attention_out, attention_out_pong); + + // iteration 2 + Load_Value_ROW_Gran(b, n, value_buffer_ping, value); + + Inter_Softmax(logit_ping, softmax_pong, max_ping); + computeAttention(softmax_ping, value_buffer_pong, attention_out_pong); + Write_Attention_Back(b, n - 2, attention_out, attention_out_ping); + + // iteration 3 + computeAttention(softmax_pong, value_buffer_ping, attention_out_ping); + Write_Attention_Back(b, n - 1, attention_out, attention_out_pong); + + // iteration 4 + Write_Attention_Back(b, n, attention_out, attention_out_ping); + } + } + } + + // //STEP 1: Load batches from DRAM to BRAM + // Load_Bias_from_DRAM(bias_buffer, bias); + // for (int idx = 0; idx < (576 / BATCH_B); ++idx) //576 batches in total + // { + // std::cout << "File number!!!!!!!!!!!!!!!!!!!" << idx << std::endl; + // Load_Query_from_DRAM(query_buffer, query, idx); + // //std::cout << "test5" << std::endl; + // Load_Key_from_DRAM(key_buffer, key, idx); + // //std::cout << "test6" << std::endl; + // Load_Value_from_DRAM(value_buffer, value, idx); + // //STEP 2: Implement different FLAT tilings here + // // USE BASELINE Implementation for now + + // Pipelined_FLAT(query_buffer, key_buffer, bias_buffer, value_buffer, attention_out_buffer); + + // //Save_Partial_Output(); + // Store_Output_to_DRAM(attention_out_buffer, attention_out, idx); + + // } +} + +// void Pipelined_FLAT(data_t query_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H], data_t key_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t bias_buffer[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T], +// data_t value_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t attention_out_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H]) +// { +// for (int b = 0; b < BATCH_B; ++b) +// { +// for (int n = 0; n < NUM_HEAD_N; ++n) +// { +// data_t query_row_gran[QUERY_LENGTH_F][HEAD_DIM_H] = {0}; +// data_t key_row_gran[KEY_LENGTH_T][HEAD_DIM_H] = {0}; +// data_t value_row_gran[KEY_LENGTH_T][HEAD_DIM_H] = {0}; +// data_t bias_row_gran[QUERY_LENGTH_F][KEY_LENGTH_T] = {0}; +// data_t attention_out_row_gran[QUERY_LENGTH_F][HEAD_DIM_H] = {0}; +// Load_Query_ROW_Gran(b, n, query_buffer, query_row_gran); +// Load_Key_ROW_Gran(b, n, key_buffer, key_row_gran); +// Load_Value_ROW_Gran(b, n, value_buffer, value_row_gran); +// Load_Bias_ROW_Gran(b, n, bias_buffer, bias_row_gran); + +// data_t logit_ping[QUERY_LENGTH_F][KEY_LENGTH_T], logit_pong[QUERY_LENGTH_F][KEY_LENGTH_T]; +// data_t max_ping[QUERY_LENGTH_F], max_pong[QUERY_LENGTH_F]; +// data_t softmax_ping[QUERY_LENGTH_F][KEY_LENGTH_T], softmax_pong[QUERY_LENGTH_F][KEY_LENGTH_T]; + +// if (n == 0) +// { +// computeLogit(query_row_gran, key_row_gran, bias_row_gran, logit_ping, max_ping); +// //Inter_Softmax(logit_ping, softmax_pong); +// //computeAttention(softmax_pong, value_row_gran, attention_out_row_gran); +// } +// else if (n == 1) +// { +// computeLogit(query_row_gran, key_row_gran, bias_row_gran, logit_pong, max_pong); +// Inter_Softmax(logit_ping, softmax_pong, max_ping); +// } +// else if (n != NUM_HEAD_N - 1) +// { +// if (n%2 == 0) +// { +// computeLogit(query_row_gran, key_row_gran, bias_row_gran, logit_ping, max_ping); +// Inter_Softmax(logit_pong, softmax_ping, max_pong); +// computeAttention(softmax_pong, value_row_gran, attention_out_row_gran); +// Write_Attention_Back(b, n-2, attention_out_buffer, attention_out_row_gran); +// } +// else if (n%2==1) +// { +// computeLogit(query_row_gran, key_row_gran, bias_row_gran, logit_pong, max_pong); +// Inter_Softmax(logit_ping, softmax_pong, max_ping); +// computeAttention(softmax_ping, value_row_gran, attention_out_row_gran); +// Write_Attention_Back(b, n-2, attention_out_buffer, attention_out_row_gran); +// } +// } +// else +// { +// Inter_Softmax(logit_ping, softmax_pong, max_ping); +// computeAttention(softmax_ping, value_row_gran, attention_out_row_gran); +// Write_Attention_Back(b, n-1, attention_out_buffer, attention_out_row_gran); +// computeAttention(softmax_pong, value_row_gran, attention_out_row_gran); +// Write_Attention_Back(b, n, attention_out_buffer, attention_out_row_gran); +// } +// } +// } +// } diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.h new file mode 100644 index 000000000000..46d8deeb3254 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/flat.h @@ -0,0 +1,94 @@ +#ifndef FLAT_H_ +#define FLAT_H_ + +#include +#include + +//-------------------------------------------------------------------------- +// Compiler Defines +//-------------------------------------------------------------------------- +#ifdef HLS_SIM + #include "config.h" +#endif + +//-------------------------------------------------------------------------- +// Type Conversions +//-------------------------------------------------------------------------- +#ifdef CSIM_DEBUG + typedef float data_t; +#else + typedef ap_fixed<16,3> data_t; +#endif + +typedef ap_uint<1024> MEM_TYPE; + +#define IF_ROW 0 //Length Granularity +#define IF_HEAD 1 //Head Granularity +#define IF_BARCH 0 //Batch Granularity +#define BATCH_B 64 //How many batches we want to process at a time? +#define KEY_LENGTH_T 64 //How many words we want to process at a time? +#define QUERY_LENGTH_F 64 //How many words we want to process at a time? +#define VALUE_LENGTH_T 64 //How many words we want to process at a time? +#define NUM_HEAD_N 16 //How many heads we want to process at a time? +#define HEAD_DIM_H 64 //How many context scores per head we want to process at a time? + +/////////////////////////////////////////// +// Adjustable parameters :: How we want to set up the test? +// 1. FILE +// 2/ Large piece of memory : Manually set length and batch we want to process at one time +/////////////////////////////////////////// +#define FILE_TOTAL 10 //How many files we want to process? [Load TEN 64 * 64 * 16 * 64 bin file] + +void GenerateKey(std::vector& key_matrix); +void GenerateValue(std::vector& value_matrix); +void GenerateQuery(std::vector& query_matrix); +void GenerateBias(std::vector& input_matrix); + +/** + * @brief Load tile from DRAM block + * Apply Double Buffering if needed (ONE Block for data loading and the Other for Computation) + * Not Provided index for loading for now. Assume only one block in DRAM to load + */ +void Load_Query_from_DRAM(int b, int n, data_t query_buffer[QUERY_LENGTH_F][HEAD_DIM_H], MEM_TYPE query[576][64][16]); +void Load_Key_from_DRAM(int b, int n, data_t key_buffer[KEY_LENGTH_T][HEAD_DIM_H], MEM_TYPE key[576][64][16]); +void Load_Value_from_DRAM(int b, int n, data_t value_buffer[KEY_LENGTH_T][HEAD_DIM_H], MEM_TYPE value[576][64][16]); +void Load_Bias_from_DRAM(int b, int n, data_t bias_buffer[QUERY_LENGTH_F][KEY_LENGTH_T], MEM_TYPE bias[64][16][64]); +void Write_Attention_Back(int b, int n, data_t attention_out[576][64][16][64], data_t attention_out_buffer[QUERY_LENGTH_F][HEAD_DIM_H]); + +void Load_Query_ROW_Gran(int b, int n, data_t query_row_gran[QUERY_LENGTH_F][HEAD_DIM_H], data_t query[576][64][16][64]); +void Load_Key_ROW_Gran(int b, int n, data_t key_row_gran[KEY_LENGTH_T][HEAD_DIM_H], data_t key[576][64][16][64]); +void Load_Value_ROW_Gran(int b, int n, data_t value_row_gran[KEY_LENGTH_T][HEAD_DIM_H], data_t value[576][64][16][64]); +void Load_Bias_ROW_Gran(int b, int n, data_t bias_row_gran[QUERY_LENGTH_F][KEY_LENGTH_T], data_t bias[576][16][64][64]); + +//void Write_Attention_Back(int b, int n, data_t attention_out_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H], data_t attention_out_row_gran[QUERY_LENGTH_F][HEAD_DIM_H]); + +void Fused_Logit_Operator(data_t query_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H], data_t key_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t bias_buffer[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T], data_t out_buffer[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T]); +void Softmax(data_t logit_out[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T], data_t softmanx_out[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T]); +void Fused_Attention_Operator(data_t softmax_out[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T], data_t value_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], + data_t attention_out_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H]); + +void computeLogit(data_t query_matrix[QUERY_LENGTH_F][HEAD_DIM_H], data_t key_matrix[KEY_LENGTH_T][HEAD_DIM_H], + data_t bias_matrix[QUERY_LENGTH_F][KEY_LENGTH_T], data_t logit[QUERY_LENGTH_F][KEY_LENGTH_T], data_t max[QUERY_LENGTH_F]); +void computeAttention(data_t softmax[QUERY_LENGTH_F][KEY_LENGTH_T], data_t value_matrix[QUERY_LENGTH_F][KEY_LENGTH_T], data_t output[QUERY_LENGTH_F][KEY_LENGTH_T]); +void Inter_Softmax(data_t logit[QUERY_LENGTH_F][KEY_LENGTH_T], data_t softmax[QUERY_LENGTH_F][KEY_LENGTH_T], data_t max[QUERY_LENGTH_F]); + +void Pipelined_FLAT(data_t query_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H], data_t key_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t bias_buffer[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T], + data_t value_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t attention_out_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H]); +/** + * @brief This function is specifically for flat to save partial output + * + */ +void Save_Partial_Output(); +void Store_Output_to_DRAM(data_t attention_out_buffer[64][64][16][64], data_t attention_out[576][64][16][64], int idx); + + +void FlatDataflow(data_t query[576][64][16][64], data_t key[576][64][16][64], data_t value[576][64][16][64], data_t bias[64][16][64][64], data_t attention_out[576][64][16][64]); + +//void FlatDataflow(MEM_TYPE query[576][64][16], MEM_TYPE key[576][64][16], MEM_TYPE value[576][64][16], MEM_TYPE bias[64][16][64], data_t attention_out[576][64][16][64]); + + +void Load_Query_from_DRAM_old(data_t query_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H], data_t query[576][64][16][64], int idx); +void Load_Key_from_DRAM_old(data_t key_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t key[576][64][16][64], int idx); +void Load_Value_from_DRAM_old(data_t value_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t value[576][64][16][64], int idx); +void Load_Bias_from_DRAM_old(data_t bias_buffer[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][KEY_LENGTH_T], data_t bias[64][16][64][64], int idx); +#endif // MACRO diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/systolic_array.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/systolic_array.cpp new file mode 100644 index 000000000000..55be86fb4cba --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/systolic_array.cpp @@ -0,0 +1,206 @@ +#include "flat.h" +#include "hls_math.h" + +#define SYSTOLIC_DIM 16 + +void Inter_Softmax(data_t logit[QUERY_LENGTH_F][KEY_LENGTH_T], data_t softmax[QUERY_LENGTH_F][KEY_LENGTH_T], data_t max_arr[QUERY_LENGTH_F]) +{ + for (int f = 0; f < QUERY_LENGTH_F; ++f) { + data_t buffer[KEY_LENGTH_T]; + data_t max = max_arr[f]; + data_t sum = 0; + for (int t = 0; t < KEY_LENGTH_T; ++t) { + buffer[t] = exp(logit[f][t] - max); + sum += buffer[t]; + } + if (sum == 0) sum = 1; + for (int t = 0; t < KEY_LENGTH_T; ++t) { + //std::cout << sum << std::endl; + softmax[f][t] = buffer[t] / sum; + } + } + //softmax = logit; +} + +// Key weight stationary +void computeLogit(data_t query_matrix[QUERY_LENGTH_F][KEY_LENGTH_T], data_t key_matrix[QUERY_LENGTH_F][KEY_LENGTH_T], + data_t bias_matrix[QUERY_LENGTH_F][KEY_LENGTH_T], data_t logit[QUERY_LENGTH_F][KEY_LENGTH_T], data_t max[QUERY_LENGTH_F]) +{ + +// #pragma HLS ARRAY_PARTITION variable=key_matrix dim=0 type=complete +// #pragma HLS ARRAY_PARTITION variable=query_matrix dim=0 type=cyclic factor=4 +// #pragma HLS ARRAY_PARTITION variable=bias_matrix dim=0 type=cyclic factor=4 +// #pragma HLS ARRAY_PARTITION variable=logit dim=0 type=complete + + data_t local_out[QUERY_LENGTH_F][KEY_LENGTH_T]; + +#pragma HLS ARRAY_PARTITION variable=local_out dim=0 type=cyclic factor=4 +// #pragma HLS ARRAY_PARTITION variable=max dim=1 type=complete + + int maxf = QUERY_LENGTH_F+KEY_LENGTH_T-2; + // Systolic array is TxH, iterations are F + systolic_f: + for (int f = 0; f < QUERY_LENGTH_F + maxf; ++f) { +//#pragma HLS PIPELINE OFF +//#pragma HLS UNROLL factor=1 +//#pragma HLS LOOP_FLATTEN OFF + + systolic_t_outer: + for (int t0 = QUERY_LENGTH_F/SYSTOLIC_DIM; t0 > 0; --t0) { +#pragma HLS UNROLL factor=16 + systolic_h_outer: + for (int h0 = KEY_LENGTH_T/SYSTOLIC_DIM; h0 > 0; --h0) { +#pragma HLS UNROLL factor=16 + + systolic_t_inner: + for (int t = t0*SYSTOLIC_DIM-1; t > (t0-1)*SYSTOLIC_DIM-1; --t) { + systolic_h_inner: + for (int h = h0*SYSTOLIC_DIM-1; h > (h0-1)*SYSTOLIC_DIM-1; --h) { +#pragma HLS PIPELINE II=1 +#pragma HLS LOOP_FLATTEN + + data_t query = query_matrix[(f-t-h) % QUERY_LENGTH_F][h]; + data_t prev_sum = (h == 0) ? bias_matrix[(f-t) % QUERY_LENGTH_F][t] : local_out[t][(h-1) % KEY_LENGTH_T]; + + data_t val; +#pragma HLS BIND_OP variable=val op=mul impl=dsp latency=-1 + val = query * key_matrix[t][h] + prev_sum; + local_out[t][h] = val; + + unsigned findex = f-t-QUERY_LENGTH_F+1; + if (h == KEY_LENGTH_T-1 && findex <= KEY_LENGTH_T-1) { + // Write back + logit[findex % QUERY_LENGTH_F][t] = val; + // Update max + //std::cout << max[findex] << " " << findex << std::endl; + max[findex] = (t == 0) ? val : ((val > max[findex]) ? val : max[findex]); + } + } + } + } + } + } +} + + +// Value weight stationary +void computeAttention(data_t logit[QUERY_LENGTH_F][KEY_LENGTH_T], data_t value_matrix[QUERY_LENGTH_F][KEY_LENGTH_T], data_t output[QUERY_LENGTH_F][KEY_LENGTH_T]) +{ +// #pragma HLS ARRAY_PARTITION variable=logit dim=0 type=complete +// #pragma HLS ARRAY_PARTITION variable=value_matrix dim=0 type=complete +// #pragma HLS ARRAY_PARTITION variable=output dim=0 type=complete + +data_t local_out[QUERY_LENGTH_F][KEY_LENGTH_T]; + +#pragma HLS ARRAY_PARTITION variable=local_out dim=0 type=cyclic factor=4 + +int maxk = QUERY_LENGTH_F+KEY_LENGTH_T-2; +systolic1: + for (int k = 0; k < KEY_LENGTH_T + maxk; ++k) { +//#pragma HLS PIPELINE off +//#pragma HLS UNROLL factor=1 +//#pragma HLS LOOP_FLATTEN OFF + + systolic2_outer: + for (int i0 = QUERY_LENGTH_F/SYSTOLIC_DIM; i0 > 0; --i0) { +#pragma HLS UNROLL factor=16 + systolic3_outer: + for (int j0 = KEY_LENGTH_T/SYSTOLIC_DIM; j0 > 0; --j0) { +#pragma HLS UNROLL factor=16 + + systolic2_inner: + for (int i = i0*SYSTOLIC_DIM-1; i > (i0-1)*SYSTOLIC_DIM-1; --i) { + systolic3_inner: + for (int j = j0*SYSTOLIC_DIM-1; j > (j0-1)*SYSTOLIC_DIM-1; --j) { +#pragma HLS PIPELINE II=1 +#pragma HLS LOOP_FLATTEN + + data_t a_val = logit[i][(k-i-j) % KEY_LENGTH_T]; + data_t b_val = value_matrix[(k-i-j) % QUERY_LENGTH_F][j]; + data_t last = (j == 0) ? (data_t) 0 : local_out[i][(j-1) % KEY_LENGTH_T]; + + data_t val; +#pragma HLS BIND_OP variable=val op=mul impl=dsp latency=-1 + val = last + a_val * b_val; + local_out[i][j] = val; + + unsigned kindex = k-i-QUERY_LENGTH_F+1; + if (j == KEY_LENGTH_T-1 && kindex <= KEY_LENGTH_T-1) { + // Write back + output[kindex % QUERY_LENGTH_F][i] = val; + } + } + } + } + } + } +} + +// Output stationary +// static void computeAttentionOSTATIONARY(data_t logit[ROW][COLUMN], data_t value_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]) +// { + +// #pragma HLS ARRAY_PARTITION variable=value_matrix dim=1 type=complete +// #pragma HLS ARRAY_PARTITION variable=output dim=0 type=complete + +// int maxk = ROW+COLUMN-2; +// systolic1: +// for (int k = 0; k < COLUMN + maxk; ++k) { +// #pragma HLS PIPELINE off +// #pragma HLS UNROLL factor=1 +// #pragma HLS LOOP_FLATTEN OFF + +// systolic2_outer: +// for (int i0 = ROW/SYSTOLIC_DIM; i0 > 0; --i0) { +// #pragma HLS UNROLL factor=16 +// systolic3_outer: +// for (int j0 = COLUMN/SYSTOLIC_DIM; j0 > 0; --j0) { +// #pragma HLS UNROLL factor=16 + +// systolic2_inner: +// for (int i = i0*SYSTOLIC_DIM-1; i > (i0-1)*SYSTOLIC_DIM-1; --i) { +// #pragma HLS PIPELINE II=1 +// systolic3_inner: +// for (int j = j0*SYSTOLIC_DIM-1; j > (j0-1)*SYSTOLIC_DIM-1; --j) { + +// bool active = (k-i-j >= 0 && k-i-j < ROW); +// data_t a_val = (active) ? logit[i][k-i-j] : (data_t) 0; +// data_t b_val = (active) ? value_matrix[k-i-j][j] : (data_t) 0; +// data_t last = (k == 0) ? (data_t) 0 : output[i][j]; +// #pragma HLS BIND_OP variable=output op=mul impl=dsp latency=-1 +// output[i][j] = last + a_val * b_val; + +// } +// } +// } +// } +// } +// } + +// // Output stationary +// static void computeAttentionORIGINAL(data_t logit[ROW][COLUMN], data_t value_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]) +// { + +// #pragma HLS ARRAY_PARTITION variable=value_matrix dim=1 type=complete +// #pragma HLS ARRAY_PARTITION variable=output dim=0 type=complete + +// systolic1: +// for (int k = 0; k < COLUMN; k++) { +// #pragma HLS PIPELINE off +// #pragma HLS UNROLL factor=1 +// #pragma HLS LOOP_FLATTEN OFF +// systolic2: +// for (int i = 0; i < ROW; i++) { +// #pragma HLS UNROLL factor=16 +// systolic3: +// for (int j = 0; j < ROW; j++) { +// #pragma HLS UNROLL factor=16 +// data_t last = (k == 0) ? 0 : output[i][j]; +// data_t a_val = (i < ROW && k < COLUMN) ? logit[i][k] : 0; +// data_t b_val = (k < ROW && j < COLUMN) ? value_matrix[k][j] : 0; +// #pragma HLS BIND_OP variable=output op=mul impl=dsp latency=-1 +// output[i][j] = last + a_val * b_val; +// } +// } +// } +// } \ No newline at end of file diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.cpp new file mode 100644 index 000000000000..69ec6c7e7d90 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.cpp @@ -0,0 +1,199 @@ +#include "systolic.h" + +void systolic_array(data_t query_matrix[ROW][COLUMN], data_t key_matrix[ROW][COLUMN], + data_t value_matrix[ROW][COLUMN], data_t bias_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]) +{ + //#pragma HLS INTERFACE mode=axis port=query_matrix depth=50 + //#pragma HLS INTERFACE mode=axis port=key_matrix depth=50 + //#pragma HLS INTERFACE mode=axis port=value_matrix depth=50 + //#pragma HLS INTERFACE mode=axis port=output depth=50 + + //#pragma HLS INTERFACE s_axilite port=return bundle=control + + data_t logit[ROW][COLUMN]; + computeLogit(query_matrix, key_matrix, bias_matrix, logit); + computeAttention(logit, value_matrix, output); +} + +// Key weight stationary +void computeLogit(data_t query_matrix[ROW][COLUMN], data_t key_matrix[ROW][COLUMN], + data_t bias_matrix[ROW][COLUMN], data_t logit[ROW][COLUMN]) +{ +#pragma HLS INLINE + +#pragma HLS ARRAY_PARTITION variable=key_matrix dim=1 type=complete +#pragma HLS ARRAY_PARTITION variable=query_matrix dim=1 type=complete +#pragma HLS ARRAY_PARTITION variable=bias_matrix dim=1 type=complete +//#pragma HLS ARRAY_PARTITION variable=logit dim=1 type=complete + + data_t local_out[ROW][COLUMN]; + //data_t local_max[COLUMN]; + +//#pragma HLS ARRAY_PARTITION variable=local_out dim=2 type=complete +//#pragma HLS ARRAY_PARTITION variable=local_max dim=1 type=complete + + int maxf = ROW+COLUMN-2; + // Systolic array is TxH, iterations are F + systolic_f: + for (int f = 0; f < ROW + maxf; ++f) { +#pragma HLS PIPELINE OFF +#pragma HLS UNROLL factor=1 +#pragma HLS LOOP_FLATTEN OFF + + systolic_t_outer: + for (int t0 = ROW/SYSTOLIC_DIM; t0 > 0; --t0) { +#pragma HLS UNROLL factor=16 + systolic_h_outer: + for (int h0 = COLUMN/SYSTOLIC_DIM; h0 > 0; --h0) { +#pragma HLS UNROLL factor=16 + + systolic_t_inner: + for (int t = t0*SYSTOLIC_DIM-1; t > (t0-1)*SYSTOLIC_DIM-1; --t) { +#pragma HLS PIPELINE II=1 + systolic_h_inner: + for (int h = h0*SYSTOLIC_DIM-1; h > (h0-1)*SYSTOLIC_DIM-1; --h) { + bool active = (f-t-h >= 0 && f-t-h < ROW); + data_t query = (active) ? query_matrix[f-t-h][h] : (data_t) 0; + data_t prev_sum = (active) ? ((h == 0) ? bias_matrix[f-t][t] : local_out[t][h-1]) : (data_t) 0; + +#pragma HLS BIND_OP variable=local_out op=mul impl=dsp latency=-1 + local_out[t][h] = query * key_matrix[t][h] + prev_sum; + + int trow = t+ROW-1; + int findex = f-trow; + if (h == COLUMN-1 && f >= trow && findex <= COLUMN-1) { + // Write back + logit[findex][t] = local_out[t][COLUMN-1]; + // Update max + } + } + } + } + } + } +} + +// TODO: (IP) THIS STILL HAS HIGH FANOUT FOR INPUTS -> change to weight stationary +// TODO: Value weight stationary +void computeAttention(data_t logit[ROW][COLUMN], data_t value_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]) +{ +#pragma HLS INLINE + +#pragma HLS ARRAY_PARTITION variable=value_matrix dim=1 type=complete +#pragma HLS ARRAY_PARTITION variable=output dim=0 type=complete + +data_t local_out[ROW][COLUMN]; + +//#pragma HLS ARRAY_PARTITION variable=local_out dim=0 type=complete + +int maxk = ROW+COLUMN-2; +systolic1: + for (int k = 0; k < COLUMN + maxk; ++k) { +#pragma HLS PIPELINE off +#pragma HLS UNROLL factor=1 +#pragma HLS LOOP_FLATTEN OFF + + systolic2_outer: + for (int i0 = ROW/SYSTOLIC_DIM; i0 > 0; --i0) { +#pragma HLS UNROLL factor=16 + systolic3_outer: + for (int j0 = COLUMN/SYSTOLIC_DIM; j0 > 0; --j0) { +#pragma HLS UNROLL factor=16 + + systolic2_inner: + for (int i = i0*SYSTOLIC_DIM-1; i > (i0-1)*SYSTOLIC_DIM-1; --i) { +#pragma HLS PIPELINE II=1 + systolic3_inner: + for (int j = j0*SYSTOLIC_DIM-1; j > (j0-1)*SYSTOLIC_DIM-1; --j) { + + + bool active = (k-i-j >= 0 && k-i-j < ROW); + data_t a_val = (active) ? logit[i][k-i-j] : (data_t) 0; + data_t b_val = (active) ? value_matrix[k-i-j][j] : (data_t) 0; + data_t last = (active) ? ((j == 0) ? (data_t) 0 : local_out[i][j-1]) : (data_t) 0; + + +#pragma HLS BIND_OP variable=local_out op=mul impl=dsp latency=-1 + local_out[i][j] = last + a_val * b_val; + + int irow = i+ROW-1; + int kindex = k-irow; + if (j == COLUMN-1 && k >= irow && kindex <= COLUMN-1) { + // Write back + output[kindex][i] = local_out[i][COLUMN-1]; + } + } + } + } + } + } +} + +// Output stationary +static void computeAttentionOSTATIONARY(data_t logit[ROW][COLUMN], data_t value_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]) +{ + +#pragma HLS ARRAY_PARTITION variable=value_matrix dim=1 type=complete +#pragma HLS ARRAY_PARTITION variable=output dim=0 type=complete + +int maxk = ROW+COLUMN-2; +systolic1: + for (int k = 0; k < COLUMN + maxk; ++k) { +#pragma HLS PIPELINE off +#pragma HLS UNROLL factor=1 +#pragma HLS LOOP_FLATTEN OFF + + systolic2_outer: + for (int i0 = ROW/SYSTOLIC_DIM; i0 > 0; --i0) { +#pragma HLS UNROLL factor=16 + systolic3_outer: + for (int j0 = COLUMN/SYSTOLIC_DIM; j0 > 0; --j0) { +#pragma HLS UNROLL factor=16 + + systolic2_inner: + for (int i = i0*SYSTOLIC_DIM-1; i > (i0-1)*SYSTOLIC_DIM-1; --i) { +#pragma HLS PIPELINE II=1 + systolic3_inner: + for (int j = j0*SYSTOLIC_DIM-1; j > (j0-1)*SYSTOLIC_DIM-1; --j) { + + bool active = (k-i-j >= 0 && k-i-j < ROW); + data_t a_val = (active) ? logit[i][k-i-j] : (data_t) 0; + data_t b_val = (active) ? value_matrix[k-i-j][j] : (data_t) 0; + data_t last = (k == 0) ? (data_t) 0 : output[i][j]; +#pragma HLS BIND_OP variable=output op=mul impl=dsp latency=-1 + output[i][j] = last + a_val * b_val; + + } + } + } + } + } +} + +// Output stationary +static void computeAttentionORIGINAL(data_t logit[ROW][COLUMN], data_t value_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]) +{ + +#pragma HLS ARRAY_PARTITION variable=value_matrix dim=1 type=complete +#pragma HLS ARRAY_PARTITION variable=output dim=0 type=complete + +systolic1: + for (int k = 0; k < COLUMN; k++) { +#pragma HLS PIPELINE off +#pragma HLS UNROLL factor=1 +#pragma HLS LOOP_FLATTEN OFF + systolic2: + for (int i = 0; i < ROW; i++) { +#pragma HLS UNROLL factor=16 + systolic3: + for (int j = 0; j < ROW; j++) { +#pragma HLS UNROLL factor=16 + data_t last = (k == 0) ? 0 : output[i][j]; + data_t a_val = (i < ROW && k < COLUMN) ? logit[i][k] : 0; + data_t b_val = (k < ROW && j < COLUMN) ? value_matrix[k][j] : 0; +#pragma HLS BIND_OP variable=output op=mul impl=dsp latency=-1 + output[i][j] = last + a_val * b_val; + } + } + } +} diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.h b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.h new file mode 100644 index 000000000000..7ce5ec9dd800 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/test_systolic_array/systolic.h @@ -0,0 +1,23 @@ +#ifndef SYSTOLIC_H_ +#define SYSTOLIC_H_ + +#include +#include +#include + +#define ROW 64 +#define COLUMN 64 + +// Dimension of the inner "pseudo" SA for each actual PE +#define SYSTOLIC_DIM 16 + +typedef uint32_t data_t; + +void systolic_array(data_t query_matrix[ROW][COLUMN], data_t key_matrix[ROW][COLUMN], + data_t value_matrix[ROW][COLUMN], data_t bias_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]); +void computeLogit(data_t query_matrix[ROW][COLUMN], data_t key_matrix[ROW][COLUMN], + data_t bias_matrix[ROW][COLUMN], data_t logit[ROW][COLUMN]); +void computeAttention(data_t logit[ROW][COLUMN], data_t value_matrix[ROW][COLUMN], data_t output[ROW][COLUMN]); + + +#endif diff --git a/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/utils.cpp b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/utils.cpp new file mode 100644 index 000000000000..a430c5c3a007 --- /dev/null +++ b/tools/cgeist/Test/HLS/hlsfactory/Inputs/class_ece8893_2022_fall/FLAT-acceleration/source_code/HLS/utils.cpp @@ -0,0 +1,234 @@ +#include "flat.h" + +void Load_Query_from_DRAM_old(data_t query_buffer[BATCH_B][QUERY_LENGTH_F][NUM_HEAD_N][HEAD_DIM_H], data_t query[576][64][16][64], int idx) +{ + for (int b = 0; b < 64; ++b) + { +#pragma HLS pipeline off + for (int f = 0; f < 64; ++f) + { +#pragma HLS pipeline off + for (int n = 0; n < 16; ++n) + { +#pragma HLS pipeline + for (int h = 0; h < 64; ++h) + { +#pragma HLS pipeline + query_buffer[b][f][n][h] = query[idx * 64 + b][f][n][h]; + } + } + } + } +} + +void Load_Key_from_DRAM_old(data_t key_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t key[576][64][16][64], int idx) +{ + for (int b = 0; b < 64; ++b) + { +#pragma HLS pipeline off + for (int t = 0; t < 64; ++t) + { +#pragma HLS pipeline off + for (int n = 0; n < 16; ++n) + { +#pragma HLS pipeline + for (int h = 0; h < 64; ++h) + { +#pragma HLS pipeline + key_buffer[b][t][n][h] = key[idx * 64 + b][t][n][h]; + } + } + } + } +} + +void Load_Value_from_DRAM_old(data_t value_buffer[BATCH_B][KEY_LENGTH_T][NUM_HEAD_N][HEAD_DIM_H], data_t value[576][64][16][64], int idx) +{ + for (int b = 0; b < 64; ++b) + { +#pragma HLS pipeline off + for (int t = 0; t < 64; ++t) + { +#pragma HLS pipeline off + for (int n = 0; n < 16; ++n) + { +#pragma HLS pipeline + for (int h = 0; h < 64; ++h) + { +#pragma HLS pipeline + value_buffer[b][t][n][h] = value[idx * 64 + b][t][n][h]; + } + } + } + } +} + +void Load_Bias_from_DRAM_old(data_t bias_buffer[BATCH_B][NUM_HEAD_N][QUERY_LENGTH_F][HEAD_DIM_H], data_t bias[64][16][64][64]) +{ + for (int b = 0; b < 64; ++b) + { +#pragma HLS pipeline off + for (int n = 0; n < 16; ++n) + { +#pragma HLS pipeline off + for (int t = 0; t < 64; ++t) + { +#pragma HLS pipeline + for (int h = 0; h < 64; ++h) + { +#pragma HLS pipeline + bias_buffer[b][n][t][h] = bias[b][n][t][h]; + } + } + } + } + // <<"FINISH"<