-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ python graph API and strongly typed ID #252
Conversation
@xinyuli1204 Basically looks good. Now we have three different id (Node, Port and now Graph is added) and it has same type (std::string) even if these are not compatible each other. Can you think about introducing strongly typed alias for each id? ref: https://stackoverflow.com/questions/34287842/strongly-typed-using-and-typedef |
include/ion/c_ion.h
Outdated
int ion_graph_add_node(ion_graph_t, const char*, ion_node_t *); | ||
int ion_graph_destroy(ion_graph_t); | ||
int ion_graph_run(ion_graph_t); | ||
int ion_graph_create_with_multiple(ion_graph_t *, ion_graph_t obj1, ion_graph_t obj2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm considering more straitforward naming. e.g. ion_graph_create_from_2
? Do you have any better idea?
include/ion/node.h
Outdated
|
||
|
||
template<typename... Args> | ||
std::vector<Port> create_ports_vector(Args... args) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please clarify necessity of the wrapper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion, this is unnecessary and I delete it
@iitaku done |
include/ion/node.h
Outdated
Impl(const std::string& id_, const std::string& name_, const Halide::Target& target_); | ||
Impl(const std::string& id_, const std::string& name_, const Halide::Target& target_, const GraphID &graph_id_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First argument is better to be NodeID, not std::string
include/ion/node.h
Outdated
@@ -126,6 +131,40 @@ class Node { | |||
{ | |||
} | |||
|
|||
Node(const std::string& id, const std::string& name, const Halide::Target& target, const GraphID& graph_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above (NodeID)
include/ion/port.h
Outdated
@@ -64,12 +65,12 @@ class Port { | |||
std::unordered_map<uint32_t, const void *> instances; | |||
|
|||
Impl(); | |||
Impl(const std::string& pid, const std::string& pn, const Halide::Type& t, int32_t d); | |||
Impl(const std::string& pid, const std::string& pn, const Halide::Type& t, int32_t d, const GraphID &gid ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PortID instead of std::string
src/port.cc
Outdated
{ | ||
params[0] = Halide::Internal::Parameter(type, dimensions != 0, dimensions, argument_name(pid, pn, 0)); | ||
params[0] = Halide::Internal::Parameter(type, dimensions != 0, dimensions, argument_name(pid, pn, 0, gid.value())); | ||
} | ||
|
||
void Port::determine_succ(const std::string& nid, const std::string& old_pn, const std::string& new_pn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeID instead of std::string
include/ion/port.h
Outdated
bool has_pred() const { return !std::get<0>(impl_->pred_chan).empty(); } | ||
bool has_pred_by_nid(const std::string& nid) const { return !std::get<0>(impl_->pred_chan).empty(); } | ||
bool has_pred() const { return !std::get<0>(impl_->pred_chan).value().empty(); } | ||
bool has_pred_by_nid(const std::string& nid) const { return !to_string(std::get<0>(impl_->pred_chan)).empty(); } | ||
bool has_succ() const { return !impl_->succ_chans.empty(); } | ||
bool has_succ(const Channel& c) const { return impl_->succ_chans.count(c); } | ||
bool has_succ_by_nid(const std::string& nid) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeID instead of std::string
include/ion/node.h
Outdated
{ | ||
} | ||
|
||
Port get_iport(Port arg) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably make_iport
is less confusing for this internal API.
include/ion/port.h
Outdated
@@ -78,58 +79,87 @@ class Port { | |||
* @arg k: The key of the port which should be matched with BuildingBlock Input/Output name. | |||
* @arg t: The type of the value. | |||
*/ | |||
Port(const std::string& n, Halide::Type t) : impl_(new Impl("", n, t, 0)), index_(-1) {} | |||
Port(const std::string& n, Halide::Type t) : impl_(new Impl("", n, t, 0, GraphID(""))), index_(-1) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is GraphID("")
and GraphID()
identical? Let's use either one if there is no meaning for these two use
include/ion/port.h
Outdated
@@ -220,7 +250,7 @@ class Port { | |||
args.push_back(Halide::Var::implicit(i)); | |||
args_expr.push_back(Halide::Var::implicit(i)); | |||
} | |||
Halide::Func f(param.type(), param.dimensions(), argument_name(pred_id(), pred_name(), i) + "_im"); | |||
Halide::Func f(param.type(), param.dimensions(), argument_name(pred_id(), pred_name(), i, graph_id_to_string()) + "_im"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can pass GraphID to argument_name
directly
include/ion/port_map.h
Outdated
@@ -16,7 +16,7 @@ class PortMap { | |||
template<typename T> | |||
[[deprecated("Port::bind can be used instead of PortMap.")]] | |||
void set(Port port, T v) { | |||
auto& buf(scalar_buffer_[argument_name(port.pred_id(), port.pred_name(), port.index())]); | |||
auto& buf(scalar_buffer_[argument_name(port.pred_id_to_string(), port.pred_name(), port.index(), port.graph_id_to_string())]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument name takes NodeID and GraphID, not string
@iitaku can I ask something about pred_chan in port.h?
pred_chan{pid, pn}, why it takes pid instead? I wonder if port should init like this
and is PortId really needed? I didn't find it is used in other place but we can keep it as well |
@xinyuli1204 It's correct. PortID is not used at this moment, but if it has no downside, let's leave it as it is for the future. |
In short words,
argument_name now becomes
std::string s = "_" + node_id + "_" + name + std::to_string(index) + "_" + graph_id;