Halide icon indicating copy to clipboard operation
Halide copied to clipboard

Vulkan backend bug in casting boolean

Open immortalsalomon opened this issue 1 year ago • 3 comments

Hi all, I think I found a bug in the Vulkan backend regarding casting from booleans to other types.

The affected file is CodeGen_Vulkan_Dev (https://github.com/halide/Halide/blob/main/src/CodeGen_Vulkan_Dev.cpp) at lines: https://github.com/halide/Halide/blob/e2448fe535db057b18f7ca16d1c878cd045902e9/src/CodeGen_Vulkan_Dev.cpp#L593 https://github.com/halide/Halide/blob/e2448fe535db057b18f7ca16d1c878cd045902e9/src/CodeGen_Vulkan_Dev.cpp#L594

To the declare_constant() method is passed the address of the std::vector object instead of the address of the first element contained by the std::vector. The possible solution I found in line with the code already present is the following (already tested):

    SpvId true_value_id = builder.declare_constant(target_type, &true_data[0]);
    SpvId false_value_id = builder.declare_constant(target_type, &false_data[0]);

Have a nice day :)

immortalsalomon avatar Feb 05 '24 10:02 immortalsalomon

Thanks very much for the bug report!

Oh geez, ... yes ... those calls are clearly wrong! I'll submit a fix ASAP.

Do you happen to have a snippet of Halide IR that triggered this so I can add a unit test? @immortalsalomon

derek-gerstmann avatar Feb 05 '24 22:02 derek-gerstmann

I can share a simplified version of what generated the problem.

Halide::Buffer<uint8_t> input = load_image("images/rgb.png");
 
// Upper bound = min + extent - 1
RDom r(-1, 3, -1, 3);

Halide::Func isPixelValid;
isPixelValid(x, y) = cast(UInt(8), input(x, y) >= 60);

// Counts valid points in the neighborhood.
Halide::Func countNeighbourhoodValidPoints;
countNeighbourhoodValidPoints(x, y) = sum(
        isPixelValid(x + r.x, y + r.y),
        "dSumValidPoints"
        );

Thank you for developing the Vulkan backend.

immortalsalomon avatar Feb 06 '24 06:02 immortalsalomon

Perfect! Thanks so much! I added a test case to our correctness tests.

Thanks again!

derek-gerstmann avatar Feb 06 '24 20:02 derek-gerstmann

Fixed in https://github.com/halide/Halide/pull/8067

derek-gerstmann avatar Mar 01 '24 17:03 derek-gerstmann