Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Nov 12, 2021
1 parent 1bed0b6 commit eb869e1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
38 changes: 19 additions & 19 deletions src/iyokan_nt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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());
Expand Down Expand Up @@ -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[];
Expand All @@ -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<typename NetworkBuilder::NetworkType>( \
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<UID> addrInputs;
Expand Down
9 changes: 6 additions & 3 deletions src/iyokan_nt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/iyokan_nt_plain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
28 changes: 14 additions & 14 deletions src/network_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class IyokanL1JSONReader {
public:
template <class NetworkBuilder>
static void read(const std::string& nodeName, std::istream& is,
NetworkBuilder& builder)
NetworkBuilder& builder, std::optional<int> ramDataWidth)
{
std::unordered_map<int, int> id2taskId;
auto addId = [&](int id, int taskId) { id2taskId.emplace(id, taskId); };
Expand Down Expand Up @@ -355,18 +355,13 @@ class IyokanL1JSONReader {
addId(id, builder.MUX());
else {
bool valid = false;
/* FIXME
// If builder.RAM() exists
if constexpr (detail::hasMethodFuncRAM<NetworkBuilder>) {
if (type == "RAM") {
int addr = cell.at("ramAddress").get<double>(),
bit = cell.at("ramBit").get<double>();
addId(id, builder.RAM(addr, bit));
valid = true;
}
if (type == "RAM" && ramDataWidth) {
valid = true;
int addr = cell.at("ramAddress").get<double>(),
bit = cell.at("ramBit").get<double>();
addId(id, builder.RAM(nodeName, "ramdata",
addr * ramDataWidth.value() + bit));
}
*/

if (!valid)
ERR_DIE("Invalid JSON of network. Invalid type: " << type);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,29 @@ 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
ERR_DIE(
"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));
}

Expand Down

0 comments on commit eb869e1

Please # to comment.