-
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
How to extract address space from raw pointers? #21
Comments
Interestingly, Intel is trying hard to hide what you are asking for: intel/llvm#348 Can you imagine an API that could be added to the standard? |
An easy solution that doesn't require an API change would be to correctly deduce the overloads, i.e. From the programmer's point of view it would be preferable to allow Admittedly I haven't given this much thought yet (I only encountered the problem on Wednesday), I'll try to think this through on the weekend. |
The weekend has passed... Apart from the solutions above the best I could come up with is something like template <typename Ptr>
struct pointer_traits
{
static_assert(is_raw_ptr_type(Ptr), "Ptr needs to be a raw pointer type");
using pointer_t = /* implementation-defined */ Ptr;
using address_space = /* implementation-defined */;
// maybe add other traits here
}; Since the compiler needs to figure out the address space on its own anyway (if I understand Section 6.8 correctly), it would fill out the This is basically the problem So my straight-forward resolution still is to remove the requirement to specify the address space for the |
The problem is that this address space resolution can be done in LLVM or even in the SPIR-V backend or whatever... So you might not have this information inside Clang as a type trait... :-(
|
I have to admit that my knowledge about compiler construction is a bit limited. But the backends will have to look up this information, too - why can't the frontend do the same?
While I can understand this intent with regard to new code I believe this is an oversight if we consider legacy code bases. If those have a raw pointer API the design of |
SYCL WG: there is an ongoing discussion internally. We will get back as soon as we have an update. |
related? |
Imagine a device-side function with the following signature:
I don't know if
vec
comes from global, local, constant or private memory. However, insidefoo
I'd like to do something tovec
which requires me to know the address space of the pointer, e.g. acl::sycl::atomic_fetch_add
. How do I tell themulti_ptr
/atomic
insidefoo
which address space is needed? Simply using aglobal_ptr
will break ifvec
actually resides in local memory. Usingmulti_ptr
will fail because the address space template parameter is missing. Creating anatomic
by passingvec
to its constructor will fail becausevec
isn't amulti_ptr
. Usingatomic_fetch_add
onvec
will fail becausevec
isn't anatomic
type.Some implementations (like ComputeCpp) internally use
__global
to annotate the pointer during device compilation. But even if there was a way to write something likevoid foo(__global int* vec)
(there isn't as far as I know, ComputeCpp complains if I do this) this would be a bad idea because the address space attributes are implementation-defined.Why do we need this? Sadly, there are libraries / frameworks out there that pass around raw pointers but where a SYCL backend is planned / worked on.
Edit: I also tried to overload
foo
withglobal_ptr
,local_ptr
etc. directly. This will fail because the call is ambigous.The text was updated successfully, but these errors were encountered: