Halide
Halide copied to clipboard
Vulkan backend bug in casting boolean
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 :)
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
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.
Perfect! Thanks so much! I added a test case to our correctness tests.
Thanks again!
Fixed in https://github.com/halide/Halide/pull/8067