-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add shorthand aliases for address spaces #633
base: main
Are you sure you want to change the base?
Conversation
Working with address spaces (e.g., when using address space casts) was previously very verbose. Defining shorthands allows long values like sycl::access::address_space::global_space to be replaced by much shorter values like sycl::global_space.
To kickstart the bikeshedding... @AerialMantis had suggested that we adopt different names here, that would be more aligned with names like One way we could split the difference between namespace sycl {
namespace access {
enum class address_space : int {
global_space,
local_space,
private_space,
generic_space
};
} // namespace access
using addrspace = access::address_space;
static constexpr addrspace addrspace_global = addrspace::global_space;
static constexpr addrspace addrspace_local = addrspace::local_space;
static constexpr addrspace addrspace_private = addrspace::private_space;
static constexpr addrspace addrspace_generic = addrspace::generic_space;
} // namespace sycl ...which would give us a shorthand of Setting a precedent for use of |
I Agree with Gordon, I would like to keep the consistency of our mangling. I personally have no problem with But I have no problem with (even if I'm still confused between |
I agree that having too many ways to do the same thing is bad. The only reason I'm suggesting to make an exception here is simply to avoid breakage between SYCL 2020 and SYCL-Next. Between SYCL 1.2.1 and SYCL 2020 we renamed |
Agree! Should we deprecate it now, so we can remove it in SYCL Next? |
We should talk about this in a WG meeting. I don't think we can deprecate things if we go the alias route. Adding I believe our options are:
|
There also a 4th option, which I'll throw out:
This would allow us to deprecate and eventually remove Many of the uses of |
I am thinking to
|
I do like that these are much shorter, but I think that "as" might be too short. Like you pointed out, it's very easy to read it as the English word "as" instead of as an initialism. Also, because we don't have any precedent for this elsewhere in SYCL, a new developer probably won't be able to guess what it means without looking at the specification. |
Any reasonable developer not using punch cards will move the mouse on the word and the explanation on what is the meaning of |
This is true during development, but the first time somebody sees these shorthands might be in a printed book, on a website, or some sort of training presentation. That's the main reason I'm leaning towards readable names, even if they're longer.
I couldn't find a good real usage showing all the address-space functionality together, so I wrote something I think is fairly representative. Original Proposalvoid increment(sycl::multi_ptr<float, sycl::generic_space> generic_ptr) {
auto global_ptr = sycl::static_address_cast<sycl::global_space>(generic_ptr);
sycl::atomic_ref<float,
sycl::memory_order::relaxed,
sycl::memory_scope::device,
sycl::global_space>(*global_ptr)++;
} Gordon's Proposalvoid increment(sycl::multi_ptr<float, sycl::address_space_generic> generic_ptr) {
auto global_ptr = sycl::static_address_cast<sycl::address_space_global>(generic_ptr);
sycl::atomic_ref<float,
sycl::memory_order::relaxed,
sycl::memory_scope::device,
sycl::address_space_global>(*global_ptr)++;
} John's Modified Proposalvoid increment(sycl::multi_ptr<float, sycl::addrspace_generic> generic_ptr) {
auto global_ptr = sycl::static_addrspace_cast<sycl::addrspace_global>(generic_ptr);
sycl::atomic_ref<float,
sycl::memory_order::relaxed,
sycl::memory_scope::device,
sycl::addrspace_global>(*global_ptr)++;
} Note that my modified proposal is to rename Ronan's Proposalvoid increment(sycl::multi_ptr<float, sycl::generic_as> generic_ptr) {
auto global_ptr = sycl::static_as_cast<sycl::global_as>(generic_ptr);
sycl::atomic_ref<float,
sycl::memory_order::relaxed,
sycl::memory_scope::device,
sycl::global_as>(*global_ptr)++;
} I know you didn't actually suggest |
The SYCL WG decided that it was better to align with other enum variables (e.g., memory_order_relaxed) by putting the name of the enum at the beginning. Adopting addrspace as an alias for the address_space enum enables this alignment while also reducing verbosity.
I've updated the PR to reflect the discussion in today's WG meeting. |
constexpr inline addrspace addrspace_global = addrspace::global_space; | ||
constexpr inline addrspace addrspace_local = addrspace::local_space; | ||
constexpr inline addrspace addrspace_private = addrspace::private_space; | ||
constexpr inline addrspace addrspace_generic = addrspace::generic_space; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is no longer constrained by namespace hierarchy, why not following English like
constexpr inline addrspace generic_addrspace = addrspace::generic_space;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AerialMantis' suggestion was that we should always use enum_value
, because that's the precedent elsewhere (e.g., memory_order_relaxed
, memory_scope_device
).
Working with address spaces (e.g., when using address space casts) was previously very verbose. Defining shorthands allows long values like
sycl::access::address_space::global_space
to be replaced by much shorter values likesycl::global_space
.