[CIR][CUDA] Handle shared and local variables #1368
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CUDA shared variables are device-only, accessible from all threads in a block of some kernel. It's similar to
local
variables in OpenCL which all threads in a work-group can access. Hence they are realized asstatic
variables in addrspace(local).On the other hand, the local variables inside a kernel (without special attributes) are just regular variables, typically emitted by
CreateTempAlloca
. They are in the default address space.OG checks if the expected address space, denoted by the type, is the same as the actual address space indicated by attributes. If they aren't the same, a
addrspacecast
is emitted when a global variable is accessed. In CIR however,cir.get_global
alreadys carries that information in!cir.ptr
type, so we don't need a cast.