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

[BUG] Kernel if short circuiting #520

Open
ped02 opened this issue Feb 11, 2025 · 2 comments
Open

[BUG] Kernel if short circuiting #520

ped02 opened this issue Feb 11, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ped02
Copy link

ped02 commented Feb 11, 2025

Bug Description

Prior to warp v1.5 (tested with v1.4.0), the condition if reset and reset[tid] is able to run when reset is None. After upgrading to v1.5, the kernel cause Warp CUDA Error 700: an illegal memory access was encountered. Not sure if upgrading was supposed to report illegal memory access or causing illegal memory access.

import warp as wp

@wp.kernel
def test_kernel(
    reset: wp.array(dtype=bool),
    # outputs
    buffer: wp.array(dtype=int)
):

    tid = wp.tid()

    ## Works only before v1.5
    if reset and reset[tid]:
        buffer[tid] = tid

    ## Solution for > v1.5
    # if reset:
    #     if reset[tid]:
    #         buffer[tid] = tid


def main():

    reset = wp.array([True, True, False, True, False, False])

    buffer = wp.empty(reset.shape, dtype=int)

    wp.launch(
        test_kernel,
        dim=buffer.shape,
        inputs = [
            # reset
            None
        ],
        outputs = [
            buffer
        ]
    )

    print(f'{buffer.numpy()=}')

if __name__ == '__main__':
    main()

System Information
CUDA Version: 12.5
OS Ubuntu 22.04
Python Version: 3.10.12

System Information

No response

@ped02 ped02 added the bug Something isn't working label Feb 11, 2025
@Hantao-Ye
Copy link

As they mentioned in the documentation, short-curcuit evaluation is not supported in kernels and user functions.

@shi-eric
Copy link
Contributor

A git bisect indicates that the behavior change started in 3f31e2c#diff-a7be079c872d39bb82545a63383217ea48bc14d5d708f0a99b025d55f039f1a4 but it's unclear to us why the CUDA Error 700 starts getting reported.

@Hantao-Ye is correct that we don't support short-circuit evaluation right now, so in v1.4.0 and in v1.5.0 we're loading from a malformed address:

        var_0 = builtin_tid1d();
        // if reset and reset[tid]:                                                               <L 13>
        var_1 = wp::address(var_reset, var_0);
        var_2 = wp::load(var_1);
        var_3 = var_reset && var_2;
        if (var_3) {
            // buffer[tid] = tid                                                                  <L 14>
            wp::array_store(var_buffer, var_0, var_0);
        }

It's best to use the solution you identified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants