-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL][COMPAT][cuda] Add "ptr_to_integer" syclcompat functions. #14283
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9e77065
Added ptr_to_integer syclcompat functions.
JackAKirk 3dcd427
Add missing eof space.
JackAKirk e5e3183
Fix test.
JackAKirk a054077
Apply suggestions from code review
JackAKirk 5b8b643
Update sycl/doc/syclcompat/README.md
JackAKirk c2d2a50
Address review feedback.
JackAKirk 054e90e
include defs.hpp in memory.hpp
JackAKirk 054baf7
Use sycl 2020 exceptions.
JackAKirk ea085b3
Switch to templated function.
JackAKirk 0d2064a
Update docs to reflect change to ptr_to_int.
JackAKirk 18137d4
Move docs to correct location.
JackAKirk 7ea41d8
Address reviewer comments.
JackAKirk 888f0d5
Update format in readme.
JackAKirk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
sycl/test-e2e/syclcompat/memory/local_memory_ptr_to_integer.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // REQUIRES: cuda | ||
| // RUN: %{build} -Xsycl-target-backend --cuda-gpu-arch=sm_75 -o %t.out | ||
| // RUN: %{run} %t.out | ||
| #include <sycl/detail/core.hpp> | ||
| #include <syclcompat.hpp> | ||
Alcpz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <syclcompat/memory.hpp> | ||
|
|
||
| using namespace sycl; | ||
| #define NUM_ELEMENTS 64 | ||
|
|
||
| template <class T> void test(queue stream) { | ||
| half *res = malloc_shared<half>(NUM_ELEMENTS, stream); | ||
|
|
||
| for (int i = 0; i < NUM_ELEMENTS; ++i) { | ||
| res[i] = 0.5; | ||
| } | ||
|
|
||
| sycl::nd_range<1> global_range{sycl::range{32}, sycl::range{32}}; | ||
|
|
||
| stream | ||
| .submit([&](handler &h) { | ||
| h.parallel_for<T>(global_range, [=](nd_item<1> item) { | ||
| sycl::group work_group = item.get_group(); | ||
| int id = item.get_global_linear_id(); | ||
| half *data = syclcompat::local_mem<half[NUM_ELEMENTS]>(); | ||
|
|
||
| data[id * 2] = id; | ||
| data[id * 2 + 1] = id + 0.5; | ||
|
|
||
| T addr; | ||
| if constexpr (std::is_same_v<size_t, T>) { | ||
| addr = syclcompat::experimental::cvta_generic_to_shared( | ||
| reinterpret_cast<char *>(data) + (id % 8) * 16); | ||
| } else { // T == uint32_t | ||
| addr = syclcompat::experimental::nvvm_get_smem_pointer( | ||
| reinterpret_cast<char *>(data) + (id % 8) * 16); | ||
| } | ||
|
|
||
| uint32_t fragment; | ||
|
|
||
| #if defined(__NVPTX__) | ||
| asm volatile("ldmatrix.sync.aligned.m8n8.x1.shared.b16 {%0}, [%1];\n" | ||
| : "=r"(fragment) | ||
| : "r"(addr)); | ||
| #endif | ||
| sycl::group_barrier(work_group); | ||
|
|
||
| half *data_ptr = reinterpret_cast<half *>(&fragment); | ||
| res[id * 2] = data_ptr[0]; | ||
| res[id * 2 + 1] = data_ptr[1]; | ||
| }); | ||
| }) | ||
| .wait(); | ||
|
|
||
| for (int i = 0; i < NUM_ELEMENTS; i++) { | ||
| assert(res[i] == static_cast<half>(i / 2.0)); | ||
| } | ||
|
|
||
| free(res, stream); | ||
| }; | ||
|
|
||
| int main() { | ||
|
|
||
| queue stream{property::queue::in_order{}}; | ||
| test<size_t>(stream); | ||
| test<uint32_t>(stream); | ||
|
|
||
| std::cout << "PASS" << std::endl; | ||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.