diff --git a/src/node.cc b/src/node.cc index b72cfcd5..7b5eba84 100644 --- a/src/node.cc +++ b/src/node.cc @@ -19,19 +19,20 @@ Node::Impl::Impl(const std::string& id_, const std::string& name_, const Halide: void Node::set_iport(const std::vector& ports) { size_t i = 0; - for (const auto& info : impl_->arginfos) { - if (info.dir == Halide::Internal::ArgInfoDirection::Output) { - continue; - } - - if (i >= ports.size()) { - log::error("Port {} is out of range", i); - throw std::runtime_error("Failed to validate input port"); - } + for (auto& port : ports) { + // TODO: Validation is better to be done lazily after BuildingBlock::configure + // + // if (info.dir == Halide::Internal::ArgInfoDirection::Output) { + // continue; + // } - auto& port(ports[i]); + // if (i >= ports.size()) { + // log::error("Port {} is out of range", i); + // throw std::runtime_error("Failed to validate input port"); + // } - port.impl_->succ_chans.insert({id(), info.name}); + // NOTE: Is succ_chans name OK to be just leave as it is? + port.impl_->succ_chans.insert({id(), "_ion_iport_" + i}); impl_->ports.push_back(port); @@ -40,11 +41,13 @@ void Node::set_iport(const std::vector& ports) { } Port Node::operator[](const std::string& name) { - if (std::find_if(impl_->arginfos.begin(), impl_->arginfos.end(), - [&](const Halide::Internal::AbstractGenerator::ArgInfo& info) { return info.name == name; }) == impl_->arginfos.end()) { - log::error("Port {} is not found", name); - throw std::runtime_error("Failed to find port"); - } + // TODO: Validation is better to be done lazily after BuildingBlock::configure + // + // if (std::find_if(impl_->arginfos.begin(), impl_->arginfos.end(), + // [&](const Halide::Internal::AbstractGenerator::ArgInfo& info) { return info.name == name; }) == impl_->arginfos.end()) { + // log::error("Port {} is not found", name); + // throw std::runtime_error("Failed to find port"); + // } auto it = std::find_if(impl_->ports.begin(), impl_->ports.end(), [&](const Port& p){ return (p.pred_name() == name && p.pred_id() == impl_->id) || p.has_succ({impl_->id, name}); }); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cb84f929..750790ee 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,6 +61,9 @@ endif() # Duplicate name test ion_jit_executable(dup-port-name SRCS dup-port-name.cc) +# BuildingBlock::configure +ion_jit_executable(configure SRCS configure.cc) + # Export test # TODO: Resolve defects in feature/win-debug branch on Windows environment # ion_jit_executable(export SRCS export.cc) diff --git a/test/configure.cc b/test/configure.cc new file mode 100644 index 00000000..8df16a4a --- /dev/null +++ b/test/configure.cc @@ -0,0 +1,78 @@ +#include + +using namespace ion; + +struct Test : BuildingBlock { + // This Building Block takes 1 input, 1 output and 1 parameter. + Input input{"input", Int(32), 1}; + Output output{"output", Int(32), 1}; + std::vector *> extra_scalar_inputs; + GeneratorParam num{"num", 0}; + + void configure() { + for (int32_t i=0; i("extra_scalar_input_" + std::to_string(i))); + } + } + + void generate() { + Halide::Var i; + Halide::Expr v = input(i); + for (int i=0; i input{size}; + input.fill(40); + + // No extra + { + Builder b; + b.set_target(get_host_target()); + Buffer output{size}; + b.add("test")(input)["output"].bind(output); + b.run(); + for (int i=0; i output{size}; + b.add("test")(input, &v, &v).set_param(Param("num", 2))["output"].bind(output); + b.compile("x"); + b.run(); + for (int i=0; i