fixstars / ion-kit

Modernized graph-based data processing framework
MIT License
7 stars 6 forks source link

Improve output buffer binding #2

Closed iitaku closed 3 years ago

iitaku commented 3 years ago

It determines output functions based on the function name (builder.cc:236-251). It is not a stable way to realize it.

iitaku commented 3 years ago

e.g. Current implementation cannot bind output properly if BB implementation substitute output by own name.(In this case, Halide::GeneratorOutput<Halide::Func> output{"output", Halide::type_of<int32_t>(), 2}; is substituted by Func output_{static_cast<std::string>(gc_prefix)+"output"}

class IncSelf : public ion::BuildingBlock<IncSelf> {
public:
    GeneratorParam<std::string> gc_title{"gc_title", "IncSelf"};
    GeneratorParam<std::string> gc_description{"gc_description", "IncSelf"};
    GeneratorParam<std::string> gc_tags{"gc_tags", "test"};
    GeneratorParam<std::string> gc_inference{"gc_inference", R"((function(v){ return { output: v.input }}))"};
    GeneratorParam<std::string> gc_mandatory{"gc_mandatory", ""};
    GeneratorParam<std::string> gc_strategy{"gc_strategy", "self"};
    GeneratorParam<std::string> gc_prefix{"gc_prefix", ""};

    Halide::GeneratorParam<int32_t> v{"v", 0};
    Halide::GeneratorInput<Halide::Func> input{"input", Halide::type_of<int32_t>(), 2};
    Halide::GeneratorOutput<Halide::Func> output{"output", Halide::type_of<int32_t>(), 2};

    void generate() {
        Func output_(static_cast<std::string>(gc_prefix)+"output");
        output_(x, y) = input(x, y) + v;
        output = output_;
    }

    void schedule() {
        output.compute_root();
        auto t = get_target();
        if (t.has_gpu_feature()) {
            Halide::Var xo, yo, xi, yi;
            output.gpu_tile(x, y, xo, yo, xi, yi, 16, 16);
        } else {
            output.parallel(y);
        }
    }

private:
    Halide::Var x, y;
};