This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add basic wrappers for the backend address spaces
ClosedPublic

Authored by jhuber6 on Jul 31 2023, 12:39 PM.

Details

Summary

The GPU makes use of different address spaces. We generally work with
global memory, thread private memory, and thread shared memory. This
patch simply adds a few preliminary wrappers to map these concepts to
the numerical values the backend uses. Obviously casts between these
will need to be checked by the user.

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 31 2023, 12:39 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 31 2023, 12:39 PM
jhuber6 requested review of this revision.Jul 31 2023, 12:39 PM
arsenm added inline comments.Jul 31 2023, 12:50 PM
libc/src/__support/GPU/amdgpu/utils.h
25–28

I don't really condone using the numbered address spaces to access these, they don't quite work the same way

jhuber6 added inline comments.Jul 31 2023, 12:52 PM
libc/src/__support/GPU/amdgpu/utils.h
25–28

They directly map LLVM ones to the ones documented in the backend. Since this is regular C++ we don't have any other option.

arsenm added inline comments.Jul 31 2023, 1:49 PM
libc/src/__support/GPU/amdgpu/utils.h
25–28

Doesn't declaring as the opencl langAses work? I think those have attributes

jhuber6 added inline comments.Jul 31 2023, 2:03 PM
libc/src/__support/GPU/amdgpu/utils.h
25–28

That doesn't work for NVPTX it seems, https://godbolt.org/z/7515T83nE.

arsenm added inline comments.Jul 31 2023, 2:05 PM
libc/src/__support/GPU/amdgpu/utils.h
25–28

This looks correct to me when you account for the stack-is-flat hack PTX uses

jhuber6 added inline comments.Jul 31 2023, 2:06 PM
libc/src/__support/GPU/amdgpu/utils.h
25–28

Ah, you're right it seems it understands constant and friends.

jhuber6 updated this revision to Diff 545800.Jul 31 2023, 2:09 PM

Changing to use opencl attrs

arsenm accepted this revision.Jul 31 2023, 5:07 PM

It's not great but it's more sound than the numbers. I think the other builtin openmp and hip headers should do the same for the ocml interfacing

This revision is now accepted and ready to land.Jul 31 2023, 5:07 PM
This revision was automatically updated to reflect the committed changes.