This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Make generic aliases to OpenCL address spaces
Needs RevisionPublic

Authored by jhuber6 on Aug 1 2023, 10:42 AM.

Details

Summary

We provide these OpenCL attributes for specifying address spaces. These
more or less map directly to the versions described by the backend
documentation. However, when using these for more generic reasons, the
opencl keyword doesn't help since this is more tied to the backend.
This patch adds an alias to just call it addrspace_ instead of
opencl_.

Diff Detail

Event Timeline

jhuber6 created this revision.Aug 1 2023, 10:42 AM
jhuber6 requested review of this revision.Aug 1 2023, 10:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 10:42 AM

Are these attributes supposed to be used in other languages? Some of their names are meaningful only in OpenCL and could be confusing/ambiguous for other languages, e.g "global" and "local".

clang/include/clang/Basic/Attr.td
1349

typo

I don't really see the point of doing this. These introduce ambiguous terminology. The reason you need the attributes is basically for FFI to opencl code, so might as well make the specific meaning clearer with the opencl bit

jhuber6 added a comment.EditedAug 1 2023, 11:14 AM

I don't really see the point of doing this. These introduce ambiguous terminology. The reason you need the attributes is basically for FFI to opencl code, so might as well make the specific meaning clearer with the opencl bit

FFI isn't the reason you'd use these, it's for generic access to the actual backend. E.g. an addrspace(3) global is local memory, if it's external it's dynamic. Having these named is better than doing it via the numerical address space. I'd like to use these in the C++ / OpenMP codes instead of the numeric ones but I don't like needing to use opencl in the name. Similarly to how we have the OpenCL atomics that should be usable outside of OpenCL.

I don't really see the point of doing this. These introduce ambiguous terminology. The reason you need the attributes is basically for FFI to opencl code, so might as well make the specific meaning clearer with the opencl bit

FFI isn't the reason you'd use these, it's for generic access to the actual backend. E.g. an addrspace(3) global is local memory, if it's external it's dynamic. Having these named is better than doing it via the numerical address space. I'd like to use these in the C++ / OpenMP codes instead of the numeric ones but I don't like needing to use opencl in the name. Similarly to how we have the OpenCL atomics that should be usable outside of OpenCL.

I agree these attributes are useful in other languages, but "global" and "local" may need a more generic name suitable for all offloading languages. To me, "device" can be a good alternative to "global". even "shared" seems clearer than "local".

FFI isn't the reason you'd use these, it's for generic access to the actual backend. E.g. an addrspace(3) global is local memory, if it's external it's dynamic. Having these named is better than doing it via the numerical address space. I'd like to use these in the C++ / OpenMP codes instead of the numeric ones but I don't like needing to use opencl in the name. Similarly to how we have the OpenCL atomics that should be usable outside of OpenCL.

I agree these attributes are useful in other languages, but "global" and "local" may need a more generic name suitable for all offloading languages. To me, "device" can be a good alternative to "global". even "shared" seems clearer than "local".

Global is common in https://llvm.org/docs/AMDGPUUsage.html#address-spaces and https://llvm.org/docs/NVPTXUsage.html#address-spaces. The main problem is local vs shared and private vs local. Unsure which one we should prefer in this case. Generally I feel a lot of this OpenCL stuff should've been named commonly at the start considering you can use most of them outside of the actual OpenCL language just fine.

FFI isn't the reason you'd use these, it's for generic access to the actual backend. E.g. an addrspace(3) global is local memory, if it's external it's dynamic. Having these named is better than doing it via the numerical address space. I'd like to use these in the C++ / OpenMP codes instead of the numeric ones but I don't like needing to use opencl in the name. Similarly to how we have the OpenCL atomics that should be usable outside of OpenCL.

I agree these attributes are useful in other languages, but "global" and "local" may need a more generic name suitable for all offloading languages. To me, "device" can be a good alternative to "global". even "shared" seems clearer than "local".

Global is common in https://llvm.org/docs/AMDGPUUsage.html#address-spaces and https://llvm.org/docs/NVPTXUsage.html#address-spaces. The main problem is local vs shared and private vs local. Unsure which one we should prefer in this case. Generally I feel a lot of this OpenCL stuff should've been named commonly at the start considering you can use most of them outside of the actual OpenCL language just fine.

Why not to just use target address space and define it to some macro with desirable spelling?

I don't think renaming OpenCL address space to something else makes sense. It might make more sense to just introduced different model of address spaces completely. But if you use OpenCL ones then it makes sense to have adequate naming so its documentation and etc can be located.

Why not to just use target address space and define it to some macro with desirable spelling?

If you mean the numbered address spaces, that's the broken thing this is specifically trying to disallow. We probably shouldn't even allow you to use those numbers. The numbered versions are not treated equivalently, and don't have the same enforced semantic rules. For example constant disallows storing to it, but address_space(4) does. The lack of casting rules is also an issue

Why not to just use target address space and define it to some macro with desirable spelling?

I don't think renaming OpenCL address space to something else makes sense. It might make more sense to just introduced different model of address spaces completely. But if you use OpenCL ones then it makes sense to have adequate naming so its documentation and etc can be located.

My issue is that these address spaces aren't really OpenCL specific, they describe a larger concept than the OpenCL language itself and we'd like to use that without needing to invoke the opencl name, since it's unrelated in this context.

Why not to just use target address space and define it to some macro with desirable spelling?

I don't think renaming OpenCL address space to something else makes sense. It might make more sense to just introduced different model of address spaces completely. But if you use OpenCL ones then it makes sense to have adequate naming so its documentation and etc can be located.

My issue is that these address spaces aren't really OpenCL specific, they describe a larger concept than the OpenCL language itself and we'd like to use that without needing to invoke the opencl name, since it's unrelated in this context.

  1. AS is not language or backend specific. We have mostly converged and we want to have some neutral spelling for the common ones.
  2. This is not helping. Now the OpenCL attributes have a second spelling, but they are still OpenCL attributes (for the user due to the docs and for the developer in clang). We also are tied to OpenCL semantic of future versions.

Why not to just use target address space and define it to some macro with desirable spelling?

Macros seems to be good enough. If we really need clang attributes, we need new docs, and naming convention etc.

Macros seems to be good enough. If we really need clang attributes, we need new docs, and naming convention etc.

Yeah an alternative would be a new set of attributes, then we make the old ones OpenCL language specific. One problem is that this will probably be copy pasting everything a second time with no difference, but it might be fine. This is just the easy version. Also addrspace_ probably isn't the best name since there's other non-GPU targets that use address spaces. I just think that this GPU generic stuff should be moved out of OpenCL in whatever way is most convenient.

We also are tied to OpenCL semantic of future versions.

This is what I would like to avoid aliasing to OpenCL and then starting to change it in a way that is not conforming or documented. Maybe there is a need for something like an address space for the group of related languages or something like that and also a way to derive and specialise from the class instead of forking and copying/pasting.

There were a number of proposals for similar things in the past including improvement to the target specific address spaces https://reviews.llvm.org/D62574.

If what we currently have is not good enough for all purposes perhaps it would make sense to start an RFC describing the problems and the requirements and then working out the solution that works for all the use cases.

arsenm requested changes to this revision.Aug 9 2023, 12:07 PM

Probably should just wrap uses in macros for now

This revision now requires changes to proceed.Aug 9 2023, 12:07 PM

Probably should just wrap uses in macros for now

In clang? Or just have users deal with opencl_ on everything and rename it.