Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan backend bug in casting boolean #8064

Closed
immortalsalomon opened this issue Feb 5, 2024 · 4 comments
Closed

Vulkan backend bug in casting boolean #8064

immortalsalomon opened this issue Feb 5, 2024 · 4 comments
Assignees
Labels

Comments

@immortalsalomon
Copy link

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:

SpvId true_value_id = builder.declare_constant(target_type, &true_data);

SpvId false_value_id = builder.declare_constant(target_type, &false_data);

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 :)

@derek-gerstmann
Copy link
Contributor

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

@immortalsalomon
Copy link
Author

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.

@derek-gerstmann
Copy link
Contributor

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

Thanks again!

@abadams abadams added the bug label Feb 9, 2024
@derek-gerstmann
Copy link
Contributor

Fixed in #8067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants