From eb869e1f1946562046ce818b95e58f52d4ba6693 Mon Sep 17 00:00:00 2001 From: Ushitora Anqou Date: Fri, 12 Nov 2021 18:27:33 +0900 Subject: [PATCH] wip --- src/iyokan_nt.cpp | 38 +++++++++++++++++++------------------- src/iyokan_nt.hpp | 9 ++++++--- src/iyokan_nt_plain.cpp | 2 -- src/network_reader.cpp | 28 ++++++++++++++-------------- src/snapshot.cpp | 6 ++++++ 5 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/iyokan_nt.cpp b/src/iyokan_nt.cpp index be905bf..d57d1da 100644 --- a/src/iyokan_nt.cpp +++ b/src/iyokan_nt.cpp @@ -518,20 +518,25 @@ Frontend::Frontend(const Snapshot& ss) void Frontend::buildNetwork(NetworkBuilder& nb) { + LOG_DBG_SCOPE("FRONTEND BUILD NETWORK"); + const Blueprint& bp = blueprint(); const TaskFinder& finder = nb.finder(); // [[file]] + LOG_DBG << "BUILD NETWORK FROM FILE"; for (auto&& file : bp.files()) readNetworkFromFile(file, nb); // [[builtin]] type = ram | type = mux-ram + LOG_DBG << "BUILD BUILTIN RAM"; for (auto&& ram : bp.builtinRAMs()) { // We ignore ram.type and always use mux-ram in plaintext mode. makeMUXRAM(ram, nb); } // [[builtin]] type = rom | type = mux-rom + LOG_DBG << "BUILD BUILTIN ROM"; for (auto&& rom : bp.builtinROMs()) { // We ignore rom.type and always use mux-rom in plaintext mode. makeMUXROM(rom, nb); @@ -547,6 +552,7 @@ void Frontend::buildNetwork(NetworkBuilder& nb) }; // [connect] + LOG_DBG << "CONNECT"; // We need to treat "... = @..." and "@... = ..." differently from // "..." = ...". // First, check if ports that are connected to or from "@..." exist. @@ -561,13 +567,16 @@ void Frontend::buildNetwork(NetworkBuilder& nb) } // Create the network from the builder + LOG_DBG << "CREATE NETWORK FROM BUILDER"; network_.emplace(nb.createNetwork()); // Check if network is valid + LOG_DBG << "CHECK IF NETWORK IS VALID"; if (!network_->checkIfValid()) ERR_DIE("Network is not valid"); // Set priority to each task + LOG_DBG << "PRIORITIZE TASKS IN NETWORK"; switch (pr_.sched) { case SCHED::TOPO: prioritizeTaskByTopo(network_.value()); @@ -862,8 +871,8 @@ void make1bitRAMWithMUX(const std::string& nodeName, } // namespace -/* - // Iyokan-L1 JSON of MUX RAM pre-compiled (and optimized) by Yosys +extern "C" { +// Iyokan-L1 JSON of MUX RAM pre-compiled (and optimized) by Yosys extern char _binary_mux_ram_8_8_8_min_json_start[]; extern char _binary_mux_ram_8_8_8_min_json_end[]; extern char _binary_mux_ram_8_8_8_min_json_size[]; @@ -873,33 +882,24 @@ extern char _binary_mux_ram_8_16_16_min_json_size[]; extern char _binary_mux_ram_9_16_16_min_json_start[]; extern char _binary_mux_ram_9_16_16_min_json_end[]; extern char _binary_mux_ram_9_16_16_min_json_size[]; -*/ +} void makeMUXRAM(const blueprint::BuiltinRAM& ram, NetworkBuilder& nb) { assert(ram.inWdataWidth == ram.outRdataWidth); - /* -#define USE_PRECOMPILED_BINARY(addrW, dataW) \ - if (inAddrWidth == addrW && dataWidth == dataW) { \ - std::stringstream ss{std::string{ \ - _binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_start, \ - _binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_end}}; \ - IyokanL1JSONReader::read(b, ss); \ - auto net = std::make_shared( \ - std::move(b)); \ - \ - error::Stack err; \ - net->checkValid(err); \ - assert(err.empty()); \ - \ - return net; \ +#define USE_PRECOMPILED_BINARY(addrW, dataW) \ + if (ram.inAddrWidth == addrW && ram.outRdataWidth == dataW) { \ + std::stringstream ss{std::string{ \ + _binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_start, \ + _binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_end}}; \ + readPrecompiledRAMNetworkFromFile(ram.name, ss, nb, dataW); \ + return; \ } USE_PRECOMPILED_BINARY(8, 8); USE_PRECOMPILED_BINARY(8, 16); USE_PRECOMPILED_BINARY(9, 16); #undef USE_PRECOMPILED_BINARY -*/ // Create inputs std::vector addrInputs; diff --git a/src/iyokan_nt.hpp b/src/iyokan_nt.hpp index b614f83..56d4c14 100644 --- a/src/iyokan_nt.hpp +++ b/src/iyokan_nt.hpp @@ -24,9 +24,9 @@ class WorkerInfo; class DataHolder; class Blueprint; namespace blueprint { -class File; -class BuiltinROM; -class BuiltinRAM; +struct File; +struct BuiltinROM; +struct BuiltinRAM; } // namespace blueprint } // namespace nt namespace cereal { @@ -533,6 +533,9 @@ class Frontend { void run(); }; +void readPrecompiledRAMNetworkFromFile(const std::string& name, + std::istream& is, nt::NetworkBuilder& nb, + int ramDataWidth); void readNetworkFromFile(const blueprint::File& file, NetworkBuilder& nb); void makeMUXROM(const blueprint::BuiltinROM& rom, NetworkBuilder& nb); void makeMUXRAM(const blueprint::BuiltinRAM& ram, NetworkBuilder& nb); diff --git a/src/iyokan_nt_plain.cpp b/src/iyokan_nt_plain.cpp index e755e3c..9e7447b 100644 --- a/src/iyokan_nt_plain.cpp +++ b/src/iyokan_nt_plain.cpp @@ -341,8 +341,6 @@ class NetworkBuilder : public nt::NetworkBuilder { currentAllocator()); uid2common_.emplace(uid, task); - // FIXME: We need to memorize this task to make a response packet. - return uid; } }; diff --git a/src/network_reader.cpp b/src/network_reader.cpp index d885439..9b7818b 100644 --- a/src/network_reader.cpp +++ b/src/network_reader.cpp @@ -294,7 +294,7 @@ class IyokanL1JSONReader { public: template static void read(const std::string& nodeName, std::istream& is, - NetworkBuilder& builder) + NetworkBuilder& builder, std::optional ramDataWidth) { std::unordered_map id2taskId; auto addId = [&](int id, int taskId) { id2taskId.emplace(id, taskId); }; @@ -355,18 +355,13 @@ class IyokanL1JSONReader { addId(id, builder.MUX()); else { bool valid = false; - /* FIXME - // If builder.RAM() exists - if constexpr (detail::hasMethodFuncRAM) { - if (type == "RAM") { - int addr = cell.at("ramAddress").get(), - bit = cell.at("ramBit").get(); - addId(id, builder.RAM(addr, bit)); - valid = true; - } + if (type == "RAM" && ramDataWidth) { + valid = true; + int addr = cell.at("ramAddress").get(), + bit = cell.at("ramBit").get(); + addId(id, builder.RAM(nodeName, "ramdata", + addr * ramDataWidth.value() + bit)); } - */ - if (!valid) ERR_DIE("Invalid JSON of network. Invalid type: " << type); } @@ -426,7 +421,12 @@ class IyokanL1JSONReader { namespace nt { -/* readNetworkFromFile */ +void readPrecompiledRAMNetworkFromFile(const std::string& name, + std::istream& is, nt::NetworkBuilder& nb, + int ramDataWidth) +{ + IyokanL1JSONReader::read(name, is, nb, ramDataWidth); +} void readNetworkFromFile(const blueprint::File& file, nt::NetworkBuilder& nb) { @@ -440,7 +440,7 @@ void readNetworkFromFile(const blueprint::File& file, nt::NetworkBuilder& nb) << "[[file]] of type 'iyokanl1-json' is deprecated. You don't need " "to use Iyokan-L1. Use Yosys JSON directly by specifying type " "'yosys-json'."; - IyokanL1JSONReader::read(file.name, ifs, nb); + IyokanL1JSONReader::read(file.name, ifs, nb, std::nullopt); break; case blueprint::File::TYPE::YOSYS_JSON: diff --git a/src/snapshot.cpp b/src/snapshot.cpp index b07abb2..7341181 100644 --- a/src/snapshot.cpp +++ b/src/snapshot.cpp @@ -18,12 +18,16 @@ Snapshot::Snapshot(const RunParameter& pr, Snapshot::Snapshot(const std::string& snapshotFile) : pr_(), alc_(nullptr) { + LOG_DBG_SCOPE("READ SNAPSHOT"); + + LOG_DBG << "OPEN"; std::ifstream ifs{snapshotFile}; if (!ifs) ERR_DIE("Can't open a snapshot file to read from: " << snapshotFile); cereal::PortableBinaryInputArchive ar{ifs}; // Read header + LOG_DBG << "READ HEADER"; std::string header; ar(header); if (header != "IYSS") // IYokan SnapShot @@ -31,10 +35,12 @@ Snapshot::Snapshot(const std::string& snapshotFile) : pr_(), alc_(nullptr) "Can't read the snapshot file; incorrect header: " << snapshotFile); // Read run parameters + LOG_DBG << "READ RUN PARAMS"; ar(pr_.blueprintFile, pr_.inputFile, pr_.outputFile, pr_.numCPUWorkers, pr_.numCycles, pr_.currentCycle, pr_.sched); // Read allocator + LOG_DBG << "READ ALLOCATOR"; alc_.reset(new Allocator(ar)); }