Search code examples
c++c++17halide

No output from Halide generator


I am trying to follow the tutorial for creating a Halide generator and the executable that is created doesn't produce a halide library when I run it using Windows + MSVC.

I have a simple generator test file:

#include "Halide.h"

using namespace Halide;

class TestGen: public Halide::Generator<TestGen>
{
public:
    Input<Buffer<uint8_t, 2>> input{"input"};
    Input<uint8_t> offset{"offset"};

    Output<Buffer<uint8_t, 2>> output{"output"};

    Var x{"x"},y{"y"};

    void generate()
    {
        output(x,y) = input(x, y) + offset;
        output(x,y) = Halide::min(output(x, y), 255.f);

        output.vectorize(x, 16).parallel(y);
    }
};

HALIDE_REGISTER_GENERATOR(TestGen, test_gen);

And I compile this along with GenGen.cpp to create the executable called TestGen.exe. But when I run this executable with .\TestGen.exe -g test_gen -o . target=host it doesn't generate any output library or header and there is no error message (although I don't know if there is error handling).

I have made sure to set the environment variable for LD_LIBRARY_PATH and DYLD_LIBRARY_PATH to point to the folder containing my halide.lib and halide.dll. So I am not sure what I am doing wrong

Edit: I've just tried adding a print line to the GenGen.cpp file before the generate line to see if it is running at all and it doesn't print it out. Maybe something about the generator build is silently failing?


Solution

  • There is an error in your update definition where you are using a float where you should have an int. You should have seen the following error when running TestGen.exe:

    Unhandled exception: Error: In update definition 0 of Func "output":
    Tuple element 0 of update definition has type float32, 
    but pure definition has type uint8
    

    To fix this, you can change

    output(x,y) = Halide::min(output(x, y), 255.f);
    

    to

    output(x,y) = Halide::min(output(x, y), 255);
    

    Note that even after this change, you will get a warning about scheduling:

    Warning: Update definition 0 of function output has not been scheduled,
    even though some other definitions have been. You may have forgotten to
    schedule it. If this was intentional, call output.update(0).unscheduled()
    to suppress this warning.
    

    which you can choose to deal with as you like.

    I am not sure why you did not see the original warning or the output from your print statement. It sounds like you might have a problem with your terminal environment or are redirect your output elsewhere.