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

Custom Kernel outputs zeros? #819

Open
avik-pal opened this issue Feb 27, 2025 · 3 comments
Open

Custom Kernel outputs zeros? #819

avik-pal opened this issue Feb 27, 2025 · 3 comments

Comments

@avik-pal
Copy link
Collaborator

using Reactant, CUDA

Reactant.set_default_backend("cpu")

function square_kernel!(x, y)
    i = threadIdx().x
    x[i] = y[i] * y[i]
    # We don't yet auto lower this via polygeist
    # sync_threads()
    return nothing
end

function square!(x, y)
    @cuda blocks = 1 threads = length(x) square_kernel!(x, y)
    return nothing
end

function square(x)
    y = similar(x)
    square!(y, x)
    return y
end

x = Reactant.to_rarray(collect(1:1:64) ./ 64)

@code_hlo square(x)

@jit square(x)
64-element ConcretePJRTArray{Float64, 1, 1, Reactant.Sharding.ShardInfo{Reactant.Sharding.NoSharding, Nothing}}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 ⋮
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
@mofeing
Copy link
Collaborator

mofeing commented Mar 2, 2025

mmm just to discard synchronicity problems. does it change if you wait a couple of seconds before printing?

@avik-pal
Copy link
Collaborator Author

avik-pal commented Mar 2, 2025

no it doesnt

@mofeing
Copy link
Collaborator

mofeing commented Mar 2, 2025

mmm what happens if you initialize y with ones instead of similar? i suspect that side-effects are not properly tracked and it might be optimizing away the kernel

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

No branches or pull requests

2 participants