Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions libs/librrgraph/src/io/gen/rr_graph_uxsdcxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* https://github.com/duck2/uxsdcxx
* Modify only if your build process doesn't involve regenerating this file.
*
* Cmdline: uxsdcxx/uxsdcxx.py /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* Input file: /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* md5sum of input file: 040903603053940a1b24392c38663b59
* Cmdline: uxsdcxx/uxsdcxx.py /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* Input file: /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* md5sum of input file: e14523c72a5db9cc83592d3baaf45780
*/

#include <functional>
Expand Down Expand Up @@ -188,6 +188,8 @@ template <class T, typename Context>
inline void write_rr_graph_xml(T &in, Context &context, std::ostream &os){
in.start_write();
os << "<rr_graph";
if((bool)in.get_rr_graph_schema_file_id(context))
os << " schema_file_id=\"" << in.get_rr_graph_schema_file_id(context) << "\"";
if((bool)in.get_rr_graph_tool_comment(context))
os << " tool_comment=\"" << in.get_rr_graph_tool_comment(context) << "\"";
if((bool)in.get_rr_graph_tool_name(context))
Expand Down Expand Up @@ -308,8 +310,8 @@ enum class gtok_t_rr_edges {EDGE};
constexpr const char *gtok_lookup_t_rr_edges[] = {"edge"};
enum class gtok_t_rr_graph {CHANNELS, SWITCHES, SEGMENTS, BLOCK_TYPES, GRID, RR_NODES, RR_EDGES};
constexpr const char *gtok_lookup_t_rr_graph[] = {"channels", "switches", "segments", "block_types", "grid", "rr_nodes", "rr_edges"};
enum class atok_t_rr_graph {TOOL_COMMENT, TOOL_NAME, TOOL_VERSION};
constexpr const char *atok_lookup_t_rr_graph[] = {"tool_comment", "tool_name", "tool_version"};
enum class atok_t_rr_graph {SCHEMA_FILE_ID, TOOL_COMMENT, TOOL_NAME, TOOL_VERSION};
constexpr const char *atok_lookup_t_rr_graph[] = {"schema_file_id", "tool_comment", "tool_name", "tool_version"};


/* Internal lexers. These convert the PugiXML node names to input tokens. */
Expand Down Expand Up @@ -1607,6 +1609,29 @@ inline atok_t_rr_graph lex_attr_t_rr_graph(const char *in, const std::function<v
default: break;
}
break;
case 14:
switch(*((triehash_uu64*)&in[0])){
case onechar('s', 0, 64) | onechar('c', 8, 64) | onechar('h', 16, 64) | onechar('e', 24, 64) | onechar('m', 32, 64) | onechar('a', 40, 64) | onechar('_', 48, 64) | onechar('f', 56, 64):
switch(*((triehash_uu32*)&in[8])){
case onechar('i', 0, 32) | onechar('l', 8, 32) | onechar('e', 16, 32) | onechar('_', 24, 32):
switch(in[12]){
case onechar('i', 0, 8):
switch(in[13]){
case onechar('d', 0, 8):
return atok_t_rr_graph::SCHEMA_FILE_ID;
break;
default: break;
}
break;
default: break;
}
break;
default: break;
}
break;
default: break;
}
break;
default: break;
}
noreturn_report(report_error, ("Found unrecognized attribute " + std::string(in) + " of <rr_graph>.").c_str());
Expand Down Expand Up @@ -2251,6 +2276,14 @@ inline enum_loc_side lex_enum_loc_side(const char *in, bool throw_on_invalid, co


/* Internal loading functions, which validate and load a PugiXML DOM tree into memory. */
inline unsigned long load_unsigned_long(const char *in, const std::function<void(const char *)> * report_error){
unsigned long out;
out = std::strtoull(in, NULL, 10);
if(errno != 0)
noreturn_report(report_error, ("Invalid value `" + std::string(in) + "` when loading into a unsigned long.").c_str());
return out;
}

inline int load_int(const char *in, const std::function<void(const char *)> * report_error){
int out;
out = std::strtol(in, NULL, 10);
Expand Down Expand Up @@ -3879,6 +3912,9 @@ inline void load_rr_graph(const pugi::xml_node &root, T &out, Context &context,
for(pugi::xml_attribute attr = root.first_attribute(); attr; attr = attr.next_attribute()){
atok_t_rr_graph in = lex_attr_t_rr_graph(attr.name(), report_error);
switch(in){
case atok_t_rr_graph::SCHEMA_FILE_ID:
out.set_rr_graph_schema_file_id(load_unsigned_long(attr.value(), report_error), context);
break;
case atok_t_rr_graph::TOOL_COMMENT:
out.set_rr_graph_tool_comment(attr.value(), context);
break;
Expand Down
9 changes: 6 additions & 3 deletions libs/librrgraph/src/io/gen/rr_graph_uxsdcxx_capnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* https://github.com/duck2/uxsdcxx
* Modify only if your build process doesn't involve regenerating this file.
*
* Cmdline: uxsdcxx/uxsdcap.py /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* Input file: /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* md5sum of input file: 040903603053940a1b24392c38663b59
* Cmdline: uxsdcxx/uxsdcap.py /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* Input file: /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* md5sum of input file: e14523c72a5db9cc83592d3baaf45780
*/

#include <functional>
Expand Down Expand Up @@ -434,6 +434,8 @@ inline void load_rr_graph_capnp(T &out, kj::ArrayPtr<const ::capnp::word> data,
template <class T, typename Context>
inline void write_rr_graph_capnp(T &in, Context &context, ucap::RrGraph::Builder &root) {
in.start_write();
if((bool)in.get_rr_graph_schema_file_id(context))
root.setSchemaFileId(in.get_rr_graph_schema_file_id(context));
if((bool)in.get_rr_graph_tool_comment(context))
root.setToolComment(in.get_rr_graph_tool_comment(context));
if((bool)in.get_rr_graph_tool_name(context))
Expand Down Expand Up @@ -946,6 +948,7 @@ inline void load_rr_graph_capnp_type(const ucap::RrGraph::Reader &root, T &out,
(void)report_error;
(void)stack;

out.set_rr_graph_schema_file_id(root.getSchemaFileId(), context);
out.set_rr_graph_tool_comment(root.getToolComment().cStr(), context);
out.set_rr_graph_tool_name(root.getToolName().cStr(), context);
out.set_rr_graph_tool_version(root.getToolVersion().cStr(), context);
Expand Down
9 changes: 6 additions & 3 deletions libs/librrgraph/src/io/gen/rr_graph_uxsdcxx_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* https://github.com/duck2/uxsdcxx
* Modify only if your build process doesn't involve regenerating this file.
*
* Cmdline: uxsdcxx/uxsdcxx.py /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* Input file: /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* md5sum of input file: 040903603053940a1b24392c38663b59
* Cmdline: uxsdcxx/uxsdcxx.py /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* Input file: /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
* md5sum of input file: e14523c72a5db9cc83592d3baaf45780
*/

#include <functional>
Expand Down Expand Up @@ -536,8 +536,11 @@ class RrGraphBase {
* <xs:attribute name="tool_name" type="xs:string" />
* <xs:attribute name="tool_version" type="xs:string" />
* <xs:attribute name="tool_comment" type="xs:string" />
* <xs:attribute name="schema_file_id" type="xs:unsignedLong" />
* </xs:complexType>
*/
virtual inline unsigned long get_rr_graph_schema_file_id(typename ContextTypes::RrGraphReadContext &ctx) = 0;
virtual inline void set_rr_graph_schema_file_id(unsigned long schema_file_id, typename ContextTypes::RrGraphWriteContext &ctx) = 0;
virtual inline const char * get_rr_graph_tool_comment(typename ContextTypes::RrGraphReadContext &ctx) = 0;
virtual inline void set_rr_graph_tool_comment(const char * tool_comment, typename ContextTypes::RrGraphWriteContext &ctx) = 0;
virtual inline const char * get_rr_graph_tool_name(typename ContextTypes::RrGraphReadContext &ctx) = 0;
Expand Down
2 changes: 2 additions & 0 deletions libs/librrgraph/src/io/rr_graph.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@
<xs:attribute name="tool_name" type="xs:string"/>
<xs:attribute name="tool_version" type="xs:string"/>
<xs:attribute name="tool_comment" type="xs:string"/>

<xs:attribute name="schema_file_id" type="xs:unsignedLong"/>
</xs:complexType>
</xs:element>

Expand Down
17 changes: 17 additions & 0 deletions libs/librrgraph/src/io/rr_graph_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pugixml_util.hpp"

#ifdef VTR_ENABLE_CAPNPROTO
# include <capnp/schema.h>
# include "rr_graph_uxsdcxx_capnp.h"
# include "mmap_file.h"
#endif
Expand Down Expand Up @@ -72,6 +73,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
bool do_check_rr_graph,
bool echo_enabled,
const char* echo_file_name,
const int route_verbosity,
bool is_flat) {
vtr::ScopedStartFinishTimer timer("Loading routing resource graph");

Expand All @@ -85,6 +87,20 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
rr_graph_builder->set_tileable(true);
}

// If Cap'n Proto is enabled, a unique ID is assigned to the schema used to serialize the RR graph.
// This ID is used to verify that the schema used to serialize the RR graph matches the
// schema being used to deserialize it.
// If Cap'n Proto is not enabled, the schema ID is 0 and no schema ID check is performed.
unsigned long schema_file_id = 0;
#ifdef VTR_ENABLE_CAPNPROTO
::capnp::Schema schema = ::capnp::Schema::from<ucap::RrGraph>();
schema_file_id = schema.getProto().getScopeId();
VTR_LOGV(route_verbosity > 1, "Schema file ID: 0x%016lx\n", schema_file_id);
#else
// Suppress the warning about unused variable 'route_verbosity'
(void)route_verbosity;
#endif

RrGraphSerializer reader(
graph_type,
base_cost_type,
Expand All @@ -108,6 +124,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
&rr_graph_builder->rr_node_metadata(),
&rr_graph_builder->rr_edge_metadata(),
&arch->strings,
schema_file_id,
is_flat);

if (vtr::check_file_name_extension(read_rr_graph_name, ".xml")) {
Expand Down
1 change: 1 addition & 0 deletions libs/librrgraph/src/io/rr_graph_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
bool do_check_rr_graph,
bool echo_enabled,
const char* echo_file_name,
const int route_verbosity,
bool is_flat);

/**
Expand Down
21 changes: 21 additions & 0 deletions libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
MetadataStorage<int>* rr_node_metadata,
MetadataStorage<std::tuple<int, int, short>>* rr_edge_metadata,
vtr::string_internment* strings,
unsigned long schema_file_id,
bool is_flat)
: chan_width_(chan_width)
, rr_nodes_(rr_nodes)
Expand All @@ -319,6 +320,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
, strings_(strings)
, empty_(strings_->intern_string(""))
, report_error_(nullptr)
, schema_file_id_(schema_file_id)
, is_flat_(is_flat) {
// Initialize internal data
init_side_map();
Expand Down Expand Up @@ -1727,6 +1729,20 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
* <xs:attribute name="tool_comment" type="xs:string" />
* </xs:complexType>
*/
inline void set_rr_graph_schema_file_id(unsigned long schema_file_id, void*& /*ctx*/) final {
// Only check if schema_file_id_ (set when initializing the class) is not 0.
// If it is 0, it means Cap'n Proto is not enabled, so we cannot check for a schema file ID mismatch.
// This function is only called when the RR graph file being read contains a schema file ID.
// If it does not, this function is not called, and the RR graph can be read without performing
// the schema file ID check.
if (schema_file_id_ != 0) {
if (schema_file_id != schema_file_id_) {
report_error(
"Schema file ID mismatch: Expected ID 0x%016lx, but got ID 0x%016lx",
schema_file_id_, schema_file_id);
}
}
}
inline void set_rr_graph_tool_comment(const char* tool_comment, void*& /*ctx*/) final {
std::string correct_string = "Generated from arch file ";
correct_string += get_arch_file_name();
Expand All @@ -1748,6 +1764,10 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
}
}

inline unsigned long get_rr_graph_schema_file_id(void*& /*ctx*/) final {
return schema_file_id_;
}

inline const char* get_rr_graph_tool_comment(void*& /*ctx*/) final {
temp_string_.assign("Generated from arch file ");
temp_string_ += get_arch_file_name();
Expand Down Expand Up @@ -2181,6 +2201,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
vtr::string_internment* strings_;
vtr::interned_string empty_;
const std::function<void(const char*)>* report_error_;
unsigned long schema_file_id_;
bool is_flat_;

// Temporary data to check grid block types
Expand Down
17 changes: 17 additions & 0 deletions libs/librrgraph/src/io/rr_graph_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "rr_graph_uxsdcxx_serializer.h"
#include "rr_graph_uxsdcxx.h"
#ifdef VTR_ENABLE_CAPNPROTO
# include <capnp/schema.h>
# include "serdes_utils.h"
# include "rr_graph_uxsdcxx_capnp.h"
#endif
Expand All @@ -37,8 +38,23 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
const char* file_name,
bool echo_enabled,
const char* echo_file_name,
const int route_verbosity,
bool is_flat) {

// If Cap'n Proto is enabled, a unique ID is assigned to the schema used to serialize the RR graph.
// This ID is used to verify that the schema used to serialize the RR graph matches the
// schema being used to deserialize it.
// If Cap'n Proto is not enabled, the schema ID is 0 and no schema ID check is performed.
unsigned long schema_file_id = 0;
#ifdef VTR_ENABLE_CAPNPROTO
::capnp::Schema schema = ::capnp::Schema::from<ucap::RrGraph>();
schema_file_id = schema.getProto().getScopeId();
VTR_LOGV(route_verbosity > 1, "Schema file ID: 0x%016lx\n", schema_file_id);
#else
// Suppress the warning about unused variable 'route_verbosity'
(void)route_verbosity;
#endif

RrGraphSerializer reader(
/*graph_type=*/e_graph_type(),
/*base_cost_type=*/e_base_cost_type(),
Expand All @@ -62,6 +78,7 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
&rr_graph_builder->rr_node_metadata(),
&rr_graph_builder->rr_edge_metadata(),
&arch->strings,
schema_file_id,
is_flat);

if (vtr::check_file_name_extension(file_name, ".xml")) {
Expand Down
1 change: 1 addition & 0 deletions libs/librrgraph/src/io/rr_graph_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
const char* file_name,
bool echo_enabled,
const char* echo_file_name,
const int route_verbosity,
bool is_flat);
29 changes: 15 additions & 14 deletions libs/libvtrcapnproto/gen/rr_graph_uxsdcxx.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# https://github.com/duck2/uxsdcxx
# Modify only if your build process doesn't involve regenerating this file.
#
# Cmdline: uxsdcxx/uxsdcap.py /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
# Input file: /home/soheil/vtr/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
# md5sum of input file: 040903603053940a1b24392c38663b59
# Cmdline: uxsdcxx/uxsdcap.py /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
# Input file: /dsoft/amohaghegh/vtr-verilog-to-routing/libs/librrgraph/src/io/rr_graph.xsd
# md5sum of input file: e14523c72a5db9cc83592d3baaf45780

@0xe7650575a8718aa2;
@0xef4b0a4204785218;
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("ucap");

Expand Down Expand Up @@ -235,14 +235,15 @@ struct RrEdges {
}

struct RrGraph {
toolComment @0 :Text;
toolName @1 :Text;
toolVersion @2 :Text;
channels @3 :Channels;
switches @4 :Switches;
segments @5 :Segments;
blockTypes @6 :BlockTypes;
grid @7 :GridLocs;
rrNodes @8 :RrNodes;
rrEdges @9 :RrEdges;
schemaFileId @0 :UInt64;
toolComment @1 :Text;
toolName @2 :Text;
toolVersion @3 :Text;
channels @4 :Channels;
switches @5 :Switches;
segments @6 :Segments;
blockTypes @7 :BlockTypes;
grid @8 :GridLocs;
rrNodes @9 :RrNodes;
rrEdges @10 :RrEdges;
}
1 change: 1 addition & 0 deletions utils/fasm/test/test_fasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ TEST_CASE("fasm_integration_test", "[fasm]") {
kRrGraphFile,
echo_enabled,
echo_file_name,
vpr_setup.RouterOpts.route_verbosity,
is_flat);
vpr_free_all(arch, vpr_setup);
}
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/route/rr_graph_generation/rr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ void create_rr_graph(e_graph_type graph_type,
router_opts.do_check_rr_graph,
echo_enabled,
echo_file_name,
router_opts.route_verbosity,
is_flat);
if (router_opts.reorder_rr_graph_nodes_algorithm != DONT_REORDER) {
mutable_device_ctx.rr_graph_builder.reorder_nodes(router_opts.reorder_rr_graph_nodes_algorithm,
Expand Down Expand Up @@ -586,6 +587,7 @@ void create_rr_graph(e_graph_type graph_type,
det_routing_arch.write_rr_graph_filename.c_str(),
echo_enabled,
echo_file_name,
router_opts.route_verbosity,
is_flat);
}
}
Expand Down
3 changes: 3 additions & 0 deletions vpr/test/test_vpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ TEST_CASE("read_rr_graph_metadata", "[vpr]") {
kRrGraphFile,
echo_enabled,
echo_file_name,
vpr_setup.RouterOpts.route_verbosity,
false);
vpr_free_all(arch, vpr_setup);
}
Expand Down Expand Up @@ -290,6 +291,7 @@ TEST_CASE("read_rr_edge_override", "[vpr]") {
rr_graph_filename.c_str(),
echo_enabled,
echo_file_name,
vpr_setup.RouterOpts.route_verbosity,
false);

vpr_free_all(arch, vpr_setup);
Expand Down Expand Up @@ -334,6 +336,7 @@ TEST_CASE("read_rr_edge_override", "[vpr]") {
overridden_rr_graph_filename.c_str(),
echo_enabled,
echo_file_name,
vpr_setup.RouterOpts.route_verbosity,
false);

vpr_free_all(arch, vpr_setup);
Expand Down