diff --git a/include/ion/port.h b/include/ion/port.h index 9d6e9ce0..66a4c0f5 100644 --- a/include/ion/port.h +++ b/include/ion/port.h @@ -53,6 +53,7 @@ class Port { private: struct Impl { + std::string id; Channel pred_chan; std::set succ_chans; @@ -62,20 +63,8 @@ class Port { std::unordered_map params; std::unordered_map instances; - Impl() {} - - Impl(const std::string& pid, const std::string& pn, const Halide::Type& t, int32_t d) - : pred_chan{pid, pn}, succ_chans{}, type(t), dimensions(d) - { - params[0] = Halide::Internal::Parameter(type, dimensions != 0, dimensions, argument_name(pid, pn, 0)); - } - - Impl(const Channel& chan, const Halide::Type& t, int32_t d) - : pred_chan(chan), succ_chans{chan}, type(t), dimensions(d) - { - params[0] = Halide::Internal::Parameter(type, dimensions != 0, dimensions, argument_name(std::get<0>(chan), std::get<1>(chan), 0)); - } - + Impl(); + Impl(const std::string& pid, const std::string& pn, const Halide::Type& t, int32_t d); }; public: @@ -125,6 +114,7 @@ class Port { } // Getter + const std::string& id() const { return impl_->id; } const Channel& pred_chan() const { return impl_->pred_chan; } const std::string& pred_id() const { return std::get<0>(impl_->pred_chan); } const std::string& pred_name() const { return std::get<1>(impl_->pred_chan); } @@ -133,7 +123,6 @@ class Port { int32_t dimensions() const { return impl_->dimensions; } int32_t size() const { return static_cast(impl_->params.size()); } int32_t index() const { return index_; } - uintptr_t impl_ptr() const { return reinterpret_cast(impl_.get()); } // Setter void set_index(int index) { index_ = index; } @@ -198,17 +187,7 @@ class Port { } } - static std::tuple, bool> find_impl(uintptr_t ptr) { - static std::unordered_map> impls; - static std::mutex mutex; - std::scoped_lock lock(mutex); - bool found = true; - if (!impls.count(ptr)) { - impls[ptr] = std::make_shared(); - found = false; - } - return std::make_tuple(impls[ptr], found); - } + static std::tuple, bool> find_impl(const std::string& id); private: /** @@ -217,12 +196,7 @@ class Port { * pid and pn is stored in both pred and succ, * then it will determined through pipeline build process. */ -#if 1 Port(const std::string& pid, const std::string& pn) : impl_(new Impl(pid, pn, Halide::Type(), 0)), index_(-1) {} -#else - Port(const std::string& pid, const std::string& pn) : impl_(new Impl(Channel{pid, pn}, Halide::Type(), 0)), index_(-1) {} -#endif - std::vector as_argument() const { std::vector args; diff --git a/src/port.cc b/src/port.cc index 26ab7e44..a90a1506 100644 --- a/src/port.cc +++ b/src/port.cc @@ -1,9 +1,21 @@ #include "ion/port.h" +#include "uuid/sole.hpp" #include "log.h" namespace ion { +Port::Impl::Impl() + : id(sole::uuid4().str()), pred_chan{"", ""}, succ_chans{}, type(), dimensions(-1) +{ +} + +Port::Impl::Impl(const std::string& pid, const std::string& pn, const Halide::Type& t, int32_t d) + : id(sole::uuid4().str()), pred_chan{pid, pn}, succ_chans{}, type(t), dimensions(d) +{ + params[0] = Halide::Internal::Parameter(type, dimensions != 0, dimensions, argument_name(pid, pn, 0)); +} + void Port::determine_succ(const std::string& nid, const std::string& old_pn, const std::string& new_pn) { auto it = std::find(impl_->succ_chans.begin(), impl_->succ_chans.end(), Channel{nid, old_pn}); if (it == impl_->succ_chans.end()) { @@ -16,5 +28,17 @@ void Port::determine_succ(const std::string& nid, const std::string& old_pn, con impl_->succ_chans.insert(Channel{nid, new_pn}); } +std::tuple, bool> Port::find_impl(const std::string& id) { + static std::unordered_map> impls; + static std::mutex mutex; + std::scoped_lock lock(mutex); + bool found = true; + if (!impls.count(id)) { + impls[id] = std::make_shared(); + found = false; + } + log::debug("Port {} is {}found", id, found ? "" : "not "); + return std::make_tuple(impls[id], found); +} } // namespace ion diff --git a/src/serializer.h b/src/serializer.h index 8e0c8921..c1f42967 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -42,17 +42,17 @@ static void from_json(const json& j, ion::Param& v) { template<> struct adl_serializer { static void to_json(json& j, const ion::Port& v) { + j["id"] = v.id(); j["pred_chan"] = v.pred_chan(); j["succ_chans"] = v.succ_chans(); j["type"] = static_cast(v.type()); j["dimensions"] = v.dimensions(); j["size"] = v.size(); - j["impl_ptr"] = v.impl_ptr(); j["index"] = v.index(); } static void from_json(const json& j, ion::Port& v) { - auto [impl, found] = ion::Port::find_impl(j["impl_ptr"].get()); + auto [impl, found] = ion::Port::find_impl(j["id"].get()); if (!found) { impl->pred_chan = j["pred_chan"].get(); impl->succ_chans = j["succ_chans"].get>(); diff --git a/test/inverted_dep.cc b/test/inverted_dep.cc index 51764db1..fe76a7e2 100644 --- a/test/inverted_dep.cc +++ b/test/inverted_dep.cc @@ -17,22 +17,22 @@ int main() { "nodes": [ { - "id": "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "id": "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "name": "test_consumer", "params": [], "ports": [ { "dimensions": 0, - "impl_ptr": 93824992939168, + "id": "2792b187-a42f-4c02-9399-25fc3acddd8e", "index": -1, "pred_chan": [ - "51917e77-d626-47ff-b1be-37957a7d0706", + "c4fcbdba-7da4-4149-80ab-4ad5da37b435", "output" ], "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "input" ] ], @@ -44,7 +44,7 @@ int main() }, { "dimensions": 0, - "impl_ptr": 93824992925424, + "id": "b44a2f84-b7a2-40a4-9fbf-ed80078b6123", "index": -1, "pred_chan": [ "", @@ -53,7 +53,7 @@ int main() "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "min0" ] ], @@ -65,7 +65,7 @@ int main() }, { "dimensions": 0, - "impl_ptr": 93824992925968, + "id": "2f9ab162-f72a-42c8-8b92-2cbcf5ce71f7", "index": -1, "pred_chan": [ "", @@ -74,7 +74,7 @@ int main() "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "extent0" ] ], @@ -86,7 +86,7 @@ int main() }, { "dimensions": 0, - "impl_ptr": 93824992926512, + "id": "ba2f373c-2dd7-436f-b816-0ca59ca83037", "index": -1, "pred_chan": [ "", @@ -95,7 +95,7 @@ int main() "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "min1" ] ], @@ -107,7 +107,7 @@ int main() }, { "dimensions": 0, - "impl_ptr": 93824992927056, + "id": "537fd4b2-eef1-4c69-a04f-bd09adf3c93f", "index": -1, "pred_chan": [ "", @@ -116,7 +116,7 @@ int main() "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "extent1" ] ], @@ -128,7 +128,7 @@ int main() }, { "dimensions": 0, - "impl_ptr": 93824992927664, + "id": "80f24262-a521-43b7-8063-3b410fb5c509", "index": -1, "pred_chan": [ "", @@ -137,7 +137,7 @@ int main() "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "v" ] ], @@ -151,7 +151,7 @@ int main() "target": "host-profile" }, { - "id": "51917e77-d626-47ff-b1be-37957a7d0706", + "id": "c4fcbdba-7da4-4149-80ab-4ad5da37b435", "name": "test_producer", "params": [ { @@ -162,16 +162,16 @@ int main() "ports": [ { "dimensions": 0, - "impl_ptr": 93824992939168, + "id": "2792b187-a42f-4c02-9399-25fc3acddd8e", "index": -1, "pred_chan": [ - "51917e77-d626-47ff-b1be-37957a7d0706", + "c4fcbdba-7da4-4149-80ab-4ad5da37b435", "output" ], "size": 1, "succ_chans": [ [ - "827bd8eb-b51c-4f0a-b94d-58dd3c521464", + "3de72ac3-d7e4-4de1-b73e-49856f8b5fc7", "input" ] ],