Skip to content

Commit eb869e1

Browse files
wip
1 parent 1bed0b6 commit eb869e1

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

src/iyokan_nt.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -518,20 +518,25 @@ Frontend::Frontend(const Snapshot& ss)
518518

519519
void Frontend::buildNetwork(NetworkBuilder& nb)
520520
{
521+
LOG_DBG_SCOPE("FRONTEND BUILD NETWORK");
522+
521523
const Blueprint& bp = blueprint();
522524
const TaskFinder& finder = nb.finder();
523525

524526
// [[file]]
527+
LOG_DBG << "BUILD NETWORK FROM FILE";
525528
for (auto&& file : bp.files())
526529
readNetworkFromFile(file, nb);
527530

528531
// [[builtin]] type = ram | type = mux-ram
532+
LOG_DBG << "BUILD BUILTIN RAM";
529533
for (auto&& ram : bp.builtinRAMs()) {
530534
// We ignore ram.type and always use mux-ram in plaintext mode.
531535
makeMUXRAM(ram, nb);
532536
}
533537

534538
// [[builtin]] type = rom | type = mux-rom
539+
LOG_DBG << "BUILD BUILTIN ROM";
535540
for (auto&& rom : bp.builtinROMs()) {
536541
// We ignore rom.type and always use mux-rom in plaintext mode.
537542
makeMUXROM(rom, nb);
@@ -547,6 +552,7 @@ void Frontend::buildNetwork(NetworkBuilder& nb)
547552
};
548553

549554
// [connect]
555+
LOG_DBG << "CONNECT";
550556
// We need to treat "... = @..." and "@... = ..." differently from
551557
// "..." = ...".
552558
// First, check if ports that are connected to or from "@..." exist.
@@ -561,13 +567,16 @@ void Frontend::buildNetwork(NetworkBuilder& nb)
561567
}
562568

563569
// Create the network from the builder
570+
LOG_DBG << "CREATE NETWORK FROM BUILDER";
564571
network_.emplace(nb.createNetwork());
565572

566573
// Check if network is valid
574+
LOG_DBG << "CHECK IF NETWORK IS VALID";
567575
if (!network_->checkIfValid())
568576
ERR_DIE("Network is not valid");
569577

570578
// Set priority to each task
579+
LOG_DBG << "PRIORITIZE TASKS IN NETWORK";
571580
switch (pr_.sched) {
572581
case SCHED::TOPO:
573582
prioritizeTaskByTopo(network_.value());
@@ -862,8 +871,8 @@ void make1bitRAMWithMUX(const std::string& nodeName,
862871

863872
} // namespace
864873

865-
/*
866-
// Iyokan-L1 JSON of MUX RAM pre-compiled (and optimized) by Yosys
874+
extern "C" {
875+
// Iyokan-L1 JSON of MUX RAM pre-compiled (and optimized) by Yosys
867876
extern char _binary_mux_ram_8_8_8_min_json_start[];
868877
extern char _binary_mux_ram_8_8_8_min_json_end[];
869878
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[];
873882
extern char _binary_mux_ram_9_16_16_min_json_start[];
874883
extern char _binary_mux_ram_9_16_16_min_json_end[];
875884
extern char _binary_mux_ram_9_16_16_min_json_size[];
876-
*/
885+
}
877886

878887
void makeMUXRAM(const blueprint::BuiltinRAM& ram, NetworkBuilder& nb)
879888
{
880889
assert(ram.inWdataWidth == ram.outRdataWidth);
881890

882-
/*
883-
#define USE_PRECOMPILED_BINARY(addrW, dataW) \
884-
if (inAddrWidth == addrW && dataWidth == dataW) { \
885-
std::stringstream ss{std::string{ \
886-
_binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_start, \
887-
_binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_end}}; \
888-
IyokanL1JSONReader::read(b, ss); \
889-
auto net = std::make_shared<typename NetworkBuilder::NetworkType>( \
890-
std::move(b)); \
891-
\
892-
error::Stack err; \
893-
net->checkValid(err); \
894-
assert(err.empty()); \
895-
\
896-
return net; \
891+
#define USE_PRECOMPILED_BINARY(addrW, dataW) \
892+
if (ram.inAddrWidth == addrW && ram.outRdataWidth == dataW) { \
893+
std::stringstream ss{std::string{ \
894+
_binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_start, \
895+
_binary_mux_ram_##addrW##_##dataW##_##dataW##_min_json_end}}; \
896+
readPrecompiledRAMNetworkFromFile(ram.name, ss, nb, dataW); \
897+
return; \
897898
}
898899
USE_PRECOMPILED_BINARY(8, 8);
899900
USE_PRECOMPILED_BINARY(8, 16);
900901
USE_PRECOMPILED_BINARY(9, 16);
901902
#undef USE_PRECOMPILED_BINARY
902-
*/
903903

904904
// Create inputs
905905
std::vector<UID> addrInputs;

src/iyokan_nt.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class WorkerInfo;
2424
class DataHolder;
2525
class Blueprint;
2626
namespace blueprint {
27-
class File;
28-
class BuiltinROM;
29-
class BuiltinRAM;
27+
struct File;
28+
struct BuiltinROM;
29+
struct BuiltinRAM;
3030
} // namespace blueprint
3131
} // namespace nt
3232
namespace cereal {
@@ -533,6 +533,9 @@ class Frontend {
533533
void run();
534534
};
535535

536+
void readPrecompiledRAMNetworkFromFile(const std::string& name,
537+
std::istream& is, nt::NetworkBuilder& nb,
538+
int ramDataWidth);
536539
void readNetworkFromFile(const blueprint::File& file, NetworkBuilder& nb);
537540
void makeMUXROM(const blueprint::BuiltinROM& rom, NetworkBuilder& nb);
538541
void makeMUXRAM(const blueprint::BuiltinRAM& ram, NetworkBuilder& nb);

src/iyokan_nt_plain.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,6 @@ class NetworkBuilder : public nt::NetworkBuilder {
341341
currentAllocator());
342342
uid2common_.emplace(uid, task);
343343

344-
// FIXME: We need to memorize this task to make a response packet.
345-
346344
return uid;
347345
}
348346
};

src/network_reader.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class IyokanL1JSONReader {
294294
public:
295295
template <class NetworkBuilder>
296296
static void read(const std::string& nodeName, std::istream& is,
297-
NetworkBuilder& builder)
297+
NetworkBuilder& builder, std::optional<int> ramDataWidth)
298298
{
299299
std::unordered_map<int, int> id2taskId;
300300
auto addId = [&](int id, int taskId) { id2taskId.emplace(id, taskId); };
@@ -355,18 +355,13 @@ class IyokanL1JSONReader {
355355
addId(id, builder.MUX());
356356
else {
357357
bool valid = false;
358-
/* FIXME
359-
// If builder.RAM() exists
360-
if constexpr (detail::hasMethodFuncRAM<NetworkBuilder>) {
361-
if (type == "RAM") {
362-
int addr = cell.at("ramAddress").get<double>(),
363-
bit = cell.at("ramBit").get<double>();
364-
addId(id, builder.RAM(addr, bit));
365-
valid = true;
366-
}
358+
if (type == "RAM" && ramDataWidth) {
359+
valid = true;
360+
int addr = cell.at("ramAddress").get<double>(),
361+
bit = cell.at("ramBit").get<double>();
362+
addId(id, builder.RAM(nodeName, "ramdata",
363+
addr * ramDataWidth.value() + bit));
367364
}
368-
*/
369-
370365
if (!valid)
371366
ERR_DIE("Invalid JSON of network. Invalid type: " << type);
372367
}
@@ -426,7 +421,12 @@ class IyokanL1JSONReader {
426421

427422
namespace nt {
428423

429-
/* readNetworkFromFile */
424+
void readPrecompiledRAMNetworkFromFile(const std::string& name,
425+
std::istream& is, nt::NetworkBuilder& nb,
426+
int ramDataWidth)
427+
{
428+
IyokanL1JSONReader::read(name, is, nb, ramDataWidth);
429+
}
430430

431431
void readNetworkFromFile(const blueprint::File& file, nt::NetworkBuilder& nb)
432432
{
@@ -440,7 +440,7 @@ void readNetworkFromFile(const blueprint::File& file, nt::NetworkBuilder& nb)
440440
<< "[[file]] of type 'iyokanl1-json' is deprecated. You don't need "
441441
"to use Iyokan-L1. Use Yosys JSON directly by specifying type "
442442
"'yosys-json'.";
443-
IyokanL1JSONReader::read(file.name, ifs, nb);
443+
IyokanL1JSONReader::read(file.name, ifs, nb, std::nullopt);
444444
break;
445445

446446
case blueprint::File::TYPE::YOSYS_JSON:

src/snapshot.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@ Snapshot::Snapshot(const RunParameter& pr,
1818

1919
Snapshot::Snapshot(const std::string& snapshotFile) : pr_(), alc_(nullptr)
2020
{
21+
LOG_DBG_SCOPE("READ SNAPSHOT");
22+
23+
LOG_DBG << "OPEN";
2124
std::ifstream ifs{snapshotFile};
2225
if (!ifs)
2326
ERR_DIE("Can't open a snapshot file to read from: " << snapshotFile);
2427
cereal::PortableBinaryInputArchive ar{ifs};
2528

2629
// Read header
30+
LOG_DBG << "READ HEADER";
2731
std::string header;
2832
ar(header);
2933
if (header != "IYSS") // IYokan SnapShot
3034
ERR_DIE(
3135
"Can't read the snapshot file; incorrect header: " << snapshotFile);
3236

3337
// Read run parameters
38+
LOG_DBG << "READ RUN PARAMS";
3439
ar(pr_.blueprintFile, pr_.inputFile, pr_.outputFile, pr_.numCPUWorkers,
3540
pr_.numCycles, pr_.currentCycle, pr_.sched);
3641

3742
// Read allocator
43+
LOG_DBG << "READ ALLOCATOR";
3844
alc_.reset(new Allocator(ar));
3945
}
4046

0 commit comments

Comments
 (0)