-
Notifications
You must be signed in to change notification settings - Fork 741
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
[SYCL] Add global_device and global_host address spaces #1704
Conversation
host_device? You meant to say
Do we really need to separate all three types of allocation or just two is enough?
This is inaccurate statement. Even if we preserve the host code it won't be possible to disambiguate the allocation type w/o additional annotations if allocation is done in separate translation unit. Tagging @GarveyJoe. |
This makes |
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.
global_device and host_device which are a subset of a global address space.
Agree with @Naghasan, I don't see the logic which makes them subset of global address space and allows conversions. Is this intention?
in global memory on device. It is supposed to be used only in SYCL headers and | ||
not in the actual OpenCL/SYCL user code. It helps distinguishing USM pointers |
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.
It is strange that attributes named OpenCLAddressSpace...
can appear only in SYCL headers. I like the idea with usm*
naming.
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.
@bader @Fznamznon : I don't know enough about the address spaces, so I hope that you and @Naghasan can make sure you review that part for me.
This patch introduces 2 new address spaces in OpenCL: usm_device and usm_host which are a subset of a global address space. We want to give the user a way to tell the compiler the allocation type of a USM pointer for optimization purposes. While it is usually easy for our compiler to distinguish loads or stores that access local memory from those that access global memory, distinguishing USM pointers that access host memory from those that access device memory or even distinguishing USM pointers that access host memory from accessors that access global memory is currently impossible. This is because all host code has been stripped out before we reach the backend and both accessors and USM pointers are presenting in LLVM IR as pointers in the global address space in the kernel's arguments. Being able to distinguish between these types of pointers at compile time is valuable because it allows us to instantiate simpler load-store units to perform memory transactions. Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Thanks for the early feedback!
It indeed seems to be a better naming, will rename.
@Naghasan is right,
I was planning to add this functionality in a different PR, but since current implementation makes the commit message be misleading (and I don't really want to change the part, where new address spaces are claimed to be a subset of
Good catch, thanks! Some thought about possibility to break existing SYCL code designs for different targets and design notes. There will be an extension in SPIR-V added that will bring SPIR-V representation of the address spaces (most likely new storage classes). In my POC I've also made a patch in clang driver, that denies support of this extension for all devices but FPGA (aka only for AOT compilation for FPGA this extension will be added to be supported, until adoption by other devices' backends). So in response for the new address spaces in SPIR-V we would see CrossWorkgroup storage class and in reversed translation we would see in LLVM IR addrspace(1) as for just
Thanks Erich! |
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
91fdae5
to
c1df2e1
Compare
Addressed the comments |
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.
Other than the one change, I think this is OK. I want @Naghasan's approval first though, the details of the address space aren't as familiar to me as they seem to be to him.
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
One argument in favor of global_device/global_host instead of usm_device/usm_host is that we'd also like accessor pointers to be in the *_device address space. Thus it could be misleading if we prefix it with "usm" when pointers in that AS aren't always allocated through USM mechanisms. |
I'm not sure I follow this use case. @GarveyJoe, could you elaborate on that or provide a short code snippet, please? |
One motivation for adding these new address spaces is to (in a subsequent change) automatically have the frontend put all pointers that come from accessors into the device address space. This will allow backends that can exploit this information to perform additional optimization. Without this information, backends must assume that all accessor-derived pointers can point into host memory as they are in the global address space. |
I'm definitely missing something. According to my understanding, the problem we are trying to solve by adding new attributes is to generate more efficient FPGA code for memory access to allocations other than "allocation on the host in USM mode". This justifies the need for
|
@bader and I synched up offline. I think the part he was missing was that we are currently putting USM pointers in global and consequently they can't be distinguished from accessors. |
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
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.
Looking through the code, it seems OK, but I don't know enough about how we use address spaces to approve this commit. @Fznamznon and @bader will have to do that I believe.
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.
I'm a bit confused. It seems those address spaces are not only for USM, but there is still some USM namings.
The code overall looks ok, but it would be great if @Naghasan take a looks as well.
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
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.
Small nit, otherwise LGTM
Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
@Naghasan, could you take a look at updates, please? |
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.
Sorry for the late feedback.
LGTM, to avoid mangling breakage (and assert/crash) it may be good to query if it is supported by the target in Sema (so store a flag in TargetInfo and querry when parsing the address space). But maybe this can be done later.
SYCL NVPTX is not going through SPIR-V, so the round trip is not going to protect it.
Thanks! @MrSidims, please, update the description, so I can used it as commit message for squashed commit. |
Done |
This patch introduces 2 new address spaces in OpenCL: global_device
and global_host which are a subset of a global address space.
We want to give the user a way to tell the compiler the allocation
type of a USM pointer for optimization purposes. While it is usually
easy for our compiler to distinguish loads or stores that access local
memory from those that access global memory, distinguishing USM pointers
that access host memory from those that access device memory or even
distinguishing USM pointers that access host memory from accessors that
access global memory is currently impossible. This is because all
host code has been stripped out before we reach the backend and both
accessors and USM pointers are presenting in LLVM IR as pointers in the
global address space in the kernel's arguments. Being able to distinguish
between these types of pointers at compile time is valuable because it allows
us to instantiate simpler load-store units to perform memory transactions.
Signed-off-by: Dmitry Sidorov dmitry.sidorov@intel.com