Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions libs/librrgraph/src/io/rr_graph.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
attribute should be the name of a xs:simpleType that defines an
xs:restriction / xs:enumeration. This will be demonstrated later.
-->

<xs:complexType name="channel">
<xs:attribute name="chan_width_max" type="xs:int" use="required"/>
<xs:attribute name="x_min" type="xs:int" use="required"/>
Expand Down Expand Up @@ -375,6 +376,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
9 changes: 9 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 @@ -85,6 +86,13 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder,
rr_graph_builder->set_tileable(true);
}

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_LOG("Schema file ID: 0x%016lx\n", schema_file_id);
#endif

RrGraphSerializer reader(
graph_type,
base_cost_type,
Expand All @@ -108,6 +116,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
18 changes: 18 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,17 @@ 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 the schema file ID is not 0. If it is 0, it means capnproto is not enabled.
// Thus, we cannot check the schema file ID mismatch.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment moment is incomplete. Don’t you also allow older rr graphs with no schema to come in? Might also want the to explain that we’re checking the file is compatible when can, but alllowing it to be read if we can’t determine its schema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the comment to the following:

// 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 +1761,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 +2198,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
9 changes: 9 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 @@ -39,6 +40,13 @@ void write_rr_graph(RRGraphBuilder* rr_graph_builder,
const char* echo_file_name,
bool is_flat) {

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_LOG("Schema file ID: 0x%016lx\n", schema_file_id);
#endif

RrGraphSerializer reader(
/*graph_type=*/e_graph_type(),
/*base_cost_type=*/e_base_cost_type(),
Expand All @@ -62,6 +70,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
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;
}