32 vjson[
"prefix"] =
"cgrame_";
33 vjson[
"parameters"] = {};
36 vjson[
"parameters"].push_back(parameter.first);
38 vjson[
"interface"] = {};
39 vjson[
"interface"].push_back(
"CGRA_Clock");
40 vjson[
"interface"].push_back(
"CGRA_Reset");
41 vjson[
"interface"].push_back(
"CGRA_Enable");
43 for (
auto& port :
ports)
45 std::string portName = port.second->getName();
46 vjson[
"interface"].push_back(portName);
50 std::string moduleDefinition;
51 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
52 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
53 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
55 for (
auto& port :
ports)
58 std::string portTypeString = {};
61 portTypeString =
"input";
65 portTypeString =
"output";
69 portTypeString =
"output reg";
73 portTypeString =
"inout";
75 std::string portSizeString;
76 if (!(port.second->parameter).empty())
78 std::string portParameterName = port.second->parameter;
79 portSizeString =
"[" + portParameterName +
"-1:0]";
83 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
85 std::string portName = port.second->getName();
86 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
87 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
91 moduleDefinition += std::string(
SET_INDENT) +
"FPAdd FPAdder (\n";
98 moduleDefinition += std::string(
SET_INDENT) +
");\n";
100 vjson[
"definition"] = moduleDefinition;
131 return "FPMultiplier";
137 nlohmann::json vjson;
140 vjson[
"prefix"] =
"cgrame_";
141 vjson[
"parameters"] = {};
144 vjson[
"parameters"].push_back(parameter.first);
146 vjson[
"interface"] = {};
147 vjson[
"interface"].push_back(
"CGRA_Clock");
148 vjson[
"interface"].push_back(
"CGRA_Reset");
149 vjson[
"interface"].push_back(
"CGRA_Enable");
151 for (
auto& port :
ports)
153 std::string portName = port.second->getName();
154 vjson[
"interface"].push_back(portName);
158 std::string moduleDefinition;
159 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
160 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
161 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
163 for (
auto& port :
ports)
166 std::string portTypeString = {};
169 portTypeString =
"input";
173 portTypeString =
"output";
177 portTypeString =
"output reg";
181 portTypeString =
"inout";
183 std::string portSizeString;
184 if (!(port.second->parameter).empty())
186 std::string portParameterName = port.second->parameter;
187 portSizeString =
"[" + portParameterName +
"-1:0]";
191 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
193 std::string portName = port.second->getName();
194 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
195 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
199 moduleDefinition += std::string(
SET_INDENT) +
"FPMult FPMultiplier (\n";
206 moduleDefinition += std::string(
SET_INDENT) +
");\n";
208 vjson[
"definition"] = moduleDefinition;
245 nlohmann::json vjson;
248 vjson[
"prefix"] =
"cgrame_";
249 vjson[
"parameters"] = {};
252 vjson[
"parameters"].push_back(parameter.first);
254 vjson[
"interface"] = {};
255 vjson[
"interface"].push_back(
"CGRA_Clock");
256 vjson[
"interface"].push_back(
"CGRA_Reset");
257 vjson[
"interface"].push_back(
"CGRA_Enable");
259 for (
auto& port :
ports)
261 std::string portName = port.second->getName();
262 vjson[
"interface"].push_back(portName);
266 std::string moduleDefinition;
267 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
268 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
269 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
271 for (
auto& port :
ports)
274 std::string portTypeString = {};
277 portTypeString =
"input";
281 portTypeString =
"output";
285 portTypeString =
"output reg";
289 portTypeString =
"inout";
291 std::string portSizeString;
292 if (!(port.second->parameter).empty())
294 std::string portParameterName = port.second->parameter;
295 portSizeString =
"[" + portParameterName +
"-1:0]";
299 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
301 std::string portName = port.second->getName();
302 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
303 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
307 moduleDefinition += std::string(
SET_INDENT) +
"FPDiv FPDivider (\n";
314 moduleDefinition += std::string(
SET_INDENT) +
");\n";
316 vjson[
"definition"] = moduleDefinition;
352 nlohmann::json vjson;
355 vjson[
"prefix"] =
"cgrame_";
356 vjson[
"parameters"] = {};
359 vjson[
"parameters"].push_back(parameter.first);
361 vjson[
"interface"] = {};
362 vjson[
"interface"].push_back(
"CGRA_Clock");
363 vjson[
"interface"].push_back(
"CGRA_Reset");
364 vjson[
"interface"].push_back(
"CGRA_Enable");
366 for (
auto& port :
ports)
368 std::string portName = port.second->getName();
369 vjson[
"interface"].push_back(portName);
373 std::string moduleDefinition;
374 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
375 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
376 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
378 for (
auto& port :
ports)
381 std::string portTypeString = {};
384 portTypeString =
"input";
388 portTypeString =
"output";
392 portTypeString =
"output reg";
396 portTypeString =
"inout";
398 std::string portSizeString;
399 if (!(port.second->parameter).empty())
401 std::string portParameterName = port.second->parameter;
402 portSizeString =
"[" + portParameterName +
"-1:0]";
406 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
408 std::string portName = port.second->getName();
409 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
410 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
414 moduleDefinition += std::string(
SET_INDENT) +
"FPSqrt FPSqroot (\n";
420 moduleDefinition += std::string(
SET_INDENT) +
");\n";
422 vjson[
"definition"] = moduleDefinition;
454 nlohmann::json vjson;
457 vjson[
"prefix"] =
"cgrame_";
458 vjson[
"parameters"] = {};
461 vjson[
"parameters"].push_back(parameter.first);
463 vjson[
"interface"] = {};
464 vjson[
"interface"].push_back(
"CGRA_Clock");
465 vjson[
"interface"].push_back(
"CGRA_Reset");
466 vjson[
"interface"].push_back(
"CGRA_Enable");
468 for (
auto& port :
ports)
470 std::string portName = port.second->getName();
471 vjson[
"interface"].push_back(portName);
475 std::string moduleDefinition;
476 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
477 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
478 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
479 for (
auto& port :
ports)
482 std::string portTypeString = {};
485 portTypeString =
"input";
489 portTypeString =
"output";
493 portTypeString =
"output reg";
497 portTypeString =
"inout";
499 std::string portSizeString;
500 if (!(port.second->parameter).empty())
502 std::string portParameterName = port.second->parameter;
503 portSizeString =
"[" + portParameterName +
"-1:0]";
507 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
509 std::string portName = port.second->getName();
510 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
511 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
515 moduleDefinition += std::string(
SET_INDENT) +
"InputIEEE2FloPoCo FPInput (\n";
520 moduleDefinition += std::string(
SET_INDENT) +
");\n";
522 vjson[
"definition"] = moduleDefinition;
553 nlohmann::json vjson;
556 vjson[
"prefix"] =
"cgrame_";
557 vjson[
"parameters"] = {};
560 vjson[
"parameters"].push_back(parameter.first);
562 vjson[
"interface"] = {};
563 vjson[
"interface"].push_back(
"CGRA_Clock");
564 vjson[
"interface"].push_back(
"CGRA_Reset");
565 vjson[
"interface"].push_back(
"CGRA_Enable");
567 for (
auto& port :
ports)
569 std::string portName = port.second->getName();
570 vjson[
"interface"].push_back(portName);
574 std::string moduleDefinition;
575 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
576 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
577 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
578 for (
auto& port :
ports)
581 std::string portTypeString = {};
584 portTypeString =
"input";
588 portTypeString =
"output";
592 portTypeString =
"output reg";
596 portTypeString =
"inout";
598 std::string portSizeString;
599 if (!(port.second->parameter).empty())
601 std::string portParameterName = port.second->parameter;
602 portSizeString =
"[" + portParameterName +
"-1:0]";
606 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
608 std::string portName = port.second->getName();
609 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
610 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
614 moduleDefinition += std::string(
SET_INDENT) +
"OutputFloPoCo2IEEE FPOutput (\n";
619 moduleDefinition += std::string(
SET_INDENT) +
");\n";
621 vjson[
"definition"] = moduleDefinition;
641 :
Module(name, loc, size), supported_modes(std::move(supported_modes_))
661 return "OutputConvert2FP";
667 nlohmann::json vjson;
670 vjson[
"prefix"] =
"cgrame_";
671 vjson[
"parameters"] = {};
674 vjson[
"parameters"].push_back(parameter.first);
676 vjson[
"interface"] = {};
677 vjson[
"interface"].push_back(
"CGRA_Clock");
678 vjson[
"interface"].push_back(
"CGRA_Reset");
679 vjson[
"interface"].push_back(
"CGRA_Enable");
681 for (
auto& port :
ports)
683 std::string portName = port.second->getName();
684 vjson[
"interface"].push_back(portName);
688 std::string moduleDefinition;
689 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
690 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
691 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
692 for (
auto& port :
ports)
695 std::string portTypeString = {};
698 portTypeString =
"input";
702 portTypeString =
"output";
706 portTypeString =
"output reg";
710 portTypeString =
"inout";
712 std::string portSizeString;
713 if (!(port.second->parameter).empty())
715 std::string portParameterName = port.second->parameter;
716 portSizeString =
"[" + portParameterName +
"-1:0]";
720 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
722 std::string portName = port.second->getName();
723 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
724 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
728 moduleDefinition += std::string(
SET_INDENT) +
"wire [size+1:0] out_int2fp;\n";
729 moduleDefinition += std::string(
SET_INDENT) +
"reg [1:0] register;\n";
730 moduleDefinition +=
"\n";
732 moduleDefinition += std::string(
SET_INDENT) +
"Fix2FP int2fp(\n";
738 moduleDefinition += std::string(
SET_INDENT) +
");\n";
740 moduleDefinition += std::string(
SET_INDENT) +
"OutputFloPoCo2IEEE IEEE2FP(\n";
745 moduleDefinition += std::string(
SET_INDENT) +
");\n";
747 moduleDefinition += std::string(
SET_INDENT) +
"always@(posedge CGRA_Clock) begin\n";
752 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"else if (~stop_downstream) begin\n";
753 moduleDefinition += std::string(
SET_TRIPLE_INDENT) +
"register <= {valid_upstream, register[1:1]};\n";
755 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"else if (stop_downstream) begin\n";
759 moduleDefinition += std::string(
SET_INDENT) +
"end\n";
760 moduleDefinition +=
"\n";
761 moduleDefinition += std::string(
SET_INDENT) +
"always@(posedge CGRA_Clock) begin\n";
764 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"end else if (~register[0]) begin\n";
766 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"end else if (register[0]) begin\n";
769 moduleDefinition += std::string(
SET_INDENT) +
"end\n";
771 vjson[
"definition"] = moduleDefinition;
785 auto& result = *result_ptr;
787 for(
unsigned i = 0; i < II; i+= II)
796 result.link(datain_result, int2fp);
797 result.link(int2fp, dataout);
815 :
Module(name, loc, size), supported_modes(std::move(supported_modes_))
835 return "FPOutputConvert2Int";
841 nlohmann::json vjson;
844 vjson[
"prefix"] =
"cgrame_";
845 vjson[
"parameters"] = {};
848 vjson[
"parameters"].push_back(parameter.first);
850 vjson[
"interface"] = {};
851 vjson[
"interface"].push_back(
"CGRA_Clock");
852 vjson[
"interface"].push_back(
"CGRA_Reset");
853 vjson[
"interface"].push_back(
"CGRA_Enable");
855 for (
auto& port :
ports)
857 std::string portName = port.second->getName();
858 vjson[
"interface"].push_back(portName);
862 std::string moduleDefinition;
863 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Clock;\n";
864 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Reset;\n";
865 moduleDefinition += std::string(
SET_INDENT) +
"input CGRA_Enable;\n";
866 for (
auto& port :
ports)
869 std::string portTypeString = {};
872 portTypeString =
"input";
876 portTypeString =
"output";
880 portTypeString =
"output reg";
884 portTypeString =
"inout";
886 std::string portSizeString;
887 if (!(port.second->parameter).empty())
889 std::string portParameterName = port.second->parameter;
890 portSizeString =
"[" + portParameterName +
"-1:0]";
894 portSizeString =
"[" +
std::to_string(port.second->size - 1) +
":0]";
896 std::string portName = port.second->getName();
897 std::string portDeclaration = portTypeString +
" " + portSizeString +
" " + portName +
";\n";
898 moduleDefinition += std::string(
SET_INDENT) + portDeclaration;
902 moduleDefinition += std::string(
SET_INDENT) +
"wire [size+1:0] out_fp2int;\n";
903 moduleDefinition += std::string(
SET_INDENT) +
"reg [1:0] register;\n";
904 moduleDefinition +=
"\n";
905 moduleDefinition += std::string(
SET_INDENT) +
"InputIEEE2FloPoCo ieee2fp(\n";
910 moduleDefinition += std::string(
SET_INDENT) +
");\n";
911 moduleDefinition +=
"\n";
912 moduleDefinition += std::string(
SET_INDENT) +
"FP2Fix fp2int(\n";
918 moduleDefinition += std::string(
SET_INDENT) +
");\n";
920 moduleDefinition += std::string(
SET_INDENT) +
"always@(posedge CGRA_Clock) begin\n";
925 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"else if (~stop_downstream) begin\n";
926 moduleDefinition += std::string(
SET_TRIPLE_INDENT) +
"register <= {valid_upstream, register[1:1]};\n";
928 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"else if (stop_downstream) begin\n";
932 moduleDefinition += std::string(
SET_INDENT) +
"end\n";
933 moduleDefinition +=
"\n";
934 moduleDefinition += std::string(
SET_INDENT) +
"always@(posedge CGRA_Clock) begin\n";
937 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"end else if (~register[0]) begin\n";
939 moduleDefinition += std::string(
SET_DOUBLE_INDENT) +
"end else if (register[0]) begin\n";
942 moduleDefinition += std::string(
SET_INDENT) +
"end\n";
944 vjson[
"definition"] = moduleDefinition;
958 auto& result = *result_ptr;
960 for(
unsigned i = 0; i < II; i+= II)
969 result.link(datain_result, fp2int);
970 result.link(fp2int, dataout);
980 {
OpCode::FMUL, {
"op_multiply",
"multiply", {
"0"},
"mul_sel"}},
981 {
OpCode::FDIV, {
"op_divide",
"divide", {
"20"},
"div_sel"}},
982 {
OpCode::SQRT, {
"op_sqrt",
"sqrt", {
"17"},
"sqrt_sel"}},
991 NameToReturn.append(
"_");
997 FPUnit::FPUnit(std::string name,
Location loc, std::vector<OpGraphOpCode> supported_modes_,
unsigned size,
int II,
int latency)
998 :
Module(name, loc, size), pipeline_mode(II, latency), supported_modes(std::move(supported_modes_))
1001 std::cout << II <<
'\n';
1002 make_and_throw<cgrame_error>([&](
auto&& s) { s <<
"dont support an II other than 1 (given II=" << II <<
')'; });
1120 (void)mrrg_nodes_from_val_node;
1121 const auto bits_needed = std::lround(ceil(log2(
supported_modes.size())));
1127 for (
const auto& op_and_mrrg_nodes : mrrg_nodes_from_op_node) {
1128 for (
const auto& mrrg_node : op_and_mrrg_nodes.second) {
1129 opNodesByCycle[mrrg_node->cycle][op_and_mrrg_nodes.first].insert(mrrg_node);
1134 for (
auto & op_and_mrrg_nodes : opNodesByCycle) {
1135 if (op_and_mrrg_nodes.empty()) {
1137 }
else if (op_and_mrrg_nodes.size() == 1) {
1140 throw cgrame_error(
"couldn't find op in supported modes list");
1161 auto& result = *result_ptr;
1163 for(
unsigned i = 0; i < II; i+=
getII())
1171 result.link(in_a, fpunit);
1172 result.link(in_b, fpunit);
1176 for(
unsigned i = 0; i < II; i+=
getII())
1181 result.link(fpunit, out_next);