Skip to content

Variable live-time counter intuitive on the CPU #13

@vchuravy

Description

@vchuravy

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions