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

Variable live-time counter intuitive on the CPU #13

Closed
vchuravy opened this issue Feb 13, 2020 · 1 comment
Closed

Variable live-time counter intuitive on the CPU #13

vchuravy opened this issue Feb 13, 2020 · 1 comment
Assignees
Milestone

Comments

@vchuravy
Copy link
Member

I just found myself writing a kernel like this:

@kernel function localmem(A)
    I = @index(Global, Linear)
    i = @index(Local, Linear)
    N = groupsize()
    lmem = @localmem Int (N,) # Ok iff groupsize is static 
    lmem[i] = i
    @synchronize
    A[I] = lmem[N - i + 1]
end

This works as expected on the GPU, but on the CPU there is counter-intuitive variable scoping going on. The first weird part is that after the @synchronize the lifetime of N has ended.

And so I thought I could just re-introduce the variable...

@kernel function localmem(A)
    I = @index(Global, Linear)
    i = @index(Local, Linear)
    N = groupsize()
    lmem = @localmem Int (N,) # Ok iff groupsize is static 
    lmem[i] = i
    @synchronize
    N = groupsize()
    A[I] = lmem[N - i + 1]
end

But it turns out that I made @localmem special, and its live-time begins in an outside scope, which of course is now also missing N.

I will have to think about how to fix this. But most likely this means that we need a "non-divergent value" or a group constant value. In return we might be able to get rid of @private, and do the right thing automatically for all divergent values.

@vchuravy vchuravy self-assigned this Feb 13, 2020
@vchuravy vchuravy added this to the 0.1.0 milestone Feb 21, 2020
@vchuravy
Copy link
Member Author

Needs better docs, but #34 and #35 introduces @uniform to mitigate this issue.

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

1 participant