Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixstars-iizuka committed Dec 28, 2023
1 parent f25673c commit edd5f26
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
14 changes: 11 additions & 3 deletions include/ion/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ class Node {
Halide::Target target;
std::vector<Param> params;
std::vector<Port> ports;
Halide::Internal::AbstractGeneratorPtr bb;

Impl(): id(), name(), target(), params(), ports() {}
Impl(): id(), name(), target(), params(), ports(), bb() {}

Impl(const std::string& id_, const std::string& name_, const Halide::Target& target_)
: id(id_), name(name_), target(target_), params(), ports() {
: id(id_), name(name_), target(target_), params(), ports(), bb(Halide::Internal::GeneratorRegistry::create(name_, Halide::GeneratorContext(target_))) {
}
};

public:
friend class Builder;
friend class nlohmann::adl_serializer<Node>;

Node() : impl_(new Impl) {};

Expand Down Expand Up @@ -94,7 +96,13 @@ class Node {
return *it;
} else {
// This is output port, bind myself and create new Port instance
return Port(name, impl_->id);
auto arginfos(impl_->bb->arginfos());
auto it = std::find_if(arginfos.begin(), arginfos.end(), [&name](const Halide::Internal::AbstractGenerator::ArgInfo& info){ return info.name == name; });
if (it == arginfos.end()) {
throw std::runtime_error("Unknown output port");
}
// TODO: Treat nicely tuple-valued input and output
return Port(name, it->types.front(), it->dimensions, impl_->id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/ion/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Port {
/**
* This port is bound with some node.
*/
Port(const std::string& n, const std::string& nid) : impl_(new Impl(n, Halide::Type(), 0, nid)), index_(-1) {}
Port(const std::string& n, Halide::Type t, int32_t d, const std::string& nid) : impl_(new Impl(n, t, d, nid)), index_(-1) {}

std::vector<Halide::Argument> as_argument() const {
std::vector<Halide::Argument> args;
Expand Down
1 change: 1 addition & 0 deletions src/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Builder::~Builder()

Node Builder::add(const std::string& k)
{
// TODO: Validate bb is existing
Node n(sole::uuid4().str(), k, target_);
nodes_.push_back(n);
return n;
Expand Down
21 changes: 11 additions & 10 deletions src/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ template <>
class adl_serializer<ion::Node> {
public:
static void to_json(json& j, const ion::Node& v) {
j["id"] = v.id();
j["name"] = v.name();
j["target"] = v.target().to_string();
j["params"] = v.params();
j["ports"] = v.ports();
j["id"] = v.impl_->id;
j["name"] = v.impl_->name;
j["target"] = v.impl_->target.to_string();
j["params"] = v.impl_->params;
j["ports"] = v.impl_->ports;
}

static void from_json(const json& j, ion::Node& v) {
v.id() = j["id"].get<std::string>();
v.name() = j["name"].get<std::string>();
v.target() = Halide::Target(j["target"].get<std::string>());
v.params() = j["params"].get<std::vector<ion::Param>>();
v.ports() = j["ports"].get<std::vector<ion::Port>>();
v.impl_->id = j["id"].get<std::string>();
v.impl_->name = j["name"].get<std::string>();
v.impl_->target = Halide::Target(j["target"].get<std::string>());
v.impl_->params = j["params"].get<std::vector<ion::Param>>();
v.impl_->ports = j["ports"].get<std::vector<ion::Port>>();
v.impl_->bb = Halide::Internal::GeneratorRegistry::create(v.impl_->name, Halide::GeneratorContext(v.impl_->target));
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions test/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int main()
if (ret != 0)
return ret;

// ret = ion_builder_with_bb_module(b, "./libion-bb-test.so");
// if (ret != 0)
// return ret;
ret = ion_builder_with_bb_module(b, "ion-bb-test");
if (ret != 0)
return ret;

ion_node_t n0;
ret = ion_builder_add_node(b, "test_producer", &n0);
Expand Down
1 change: 0 additions & 1 deletion test/inverted_dep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ int main()
}

Halide::Type t = Halide::type_of<int32_t>();
Port min0{"min0", t}, extent0{"extent0", t}, min1{"min1", t}, extent1{"extent1", t}, v{"v", t};

Builder b;

Expand Down

0 comments on commit edd5f26

Please sign in to comment.