Skip to content

[CIR][CUDA] Handle shared and local variables #1368

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

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

AdUhTkJm
Copy link
Contributor

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 as static 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.

@bcardosolopes bcardosolopes merged commit b510e50 into llvm:main Feb 19, 2025
6 checks passed
lanza pushed a commit that referenced this pull request Mar 18, 2025
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 as
`static` 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.
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

Successfully merging this pull request may close these issues.

2 participants