Skip to content

[SYCL] Fix malloc shared by throwing when usm_shared_allocations not supported #12700

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 16 commits into from
Feb 15, 2024

Conversation

lbushi25
Copy link
Contributor

@lbushi25 lbushi25 commented Feb 13, 2024

Final PR in the series of #12636.
Refer to it for a description.
After a discussion with @AlexeySachkov we've decided its best to not rewrite USM and syclcompat tests with buffers/accessors. For USM, the reason is obvious and for syclcompat you can reach out to Alexey. Therefore, these tests are handled using if statements or requring aspect to be supported.
Once this PR is merged, the behavior of malloc_shared will be to throw if the usm_shared_allocations is not supported which is conformant with the spec.

@lbushi25 lbushi25 marked this pull request as ready for review February 13, 2024 15:32
@lbushi25 lbushi25 requested review from a team as code owners February 13, 2024 15:32
@Alcpz
Copy link
Contributor

Alcpz commented Feb 14, 2024

Can you provide an explanation as to why these syclcompat tests are being skipped?
syclcompat/memory tests would need to be separated into different test suites, so it seems reasonable to disable until a refactor is done.
syclcompat/tests are using malloc_shared to simplify the tests a little bit, so I am wondering if there are more issues we need to be aware of in order to get these fixed.

@lbushi25
Copy link
Contributor Author

lbushi25 commented Feb 14, 2024

Can you provide an explanation as to why these syclcompat tests are being skipped? syclcompat/memory tests would need to be separated into different test suites, so it seems reasonable to disable until a refactor is done. syclcompat/tests are using malloc_shared to simplify the tests a little bit, so I am wondering if there are more issues we need to be aware of in order to get these fixed.

Here's what i propose, instead of skipping them with REQUIRES I could substitute malloc_shared with malloc_device instead which is supported by all devices that we run tests on. Going forward, people should just be mindful to avoid using malloc_shared to allocate memory unless they're prepared to handle exceptions that could be thrown from the call. Instead they can use buffers/accessors or use malloc_device.

@Alcpz
Copy link
Contributor

Alcpz commented Feb 14, 2024

Yes, that is perfectly reasonable. syclcompat/memory/* ones are slightly more complex than that, so those are fair to skip.

For the syclcompat/util/* tests, something akin to this should be enough:

diff --git a/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp b/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp
index c350049ff1d7..308da571cc29 100644
--- a/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp
+++ b/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp
@@ -104,14 +104,16 @@ void test_find_first_set() {
   sycl::queue q_ct1 = *dev_ct1.default_queue();
   int *test_result, host_test_result = 0;
 
-  test_result = sycl::malloc_shared<int>(sizeof(int), q_ct1);
+  test_result = sycl::malloc_device<int>(1, q_ct1);
   *test_result = 0;
+  int h_test_result;
 
   q_ct1.parallel_for(
       sycl::nd_range<3>(sycl::range<3>(1, 1, 1), sycl::range<3>(1, 1, 1)),
       [=](sycl::nd_item<3> item_ct1) { find_first_set_test(test_result); });
 
   dev_ct1.queues_wait_and_throw();
+  q_ct1.copy(&h_test_result, test_result, sizeof(int)).wait();
   find_first_set_test(&host_test_result);
   assert(*test_result == 0);
   assert(host_test_result == 0);

@lbushi25
Copy link
Contributor Author

Yes, that is perfectly reasonable. syclcompat/memory/* ones are slightly more complex than that, so those are fair to skip.

For the syclcompat/util/* tests, something akin to this should be enough:

diff --git a/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp b/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp
index c350049ff1d7..308da571cc29 100644
--- a/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp
+++ b/sycl/test-e2e/syclcompat/util/util_find_first_set.cpp
@@ -104,14 +104,16 @@ void test_find_first_set() {
   sycl::queue q_ct1 = *dev_ct1.default_queue();
   int *test_result, host_test_result = 0;
 
-  test_result = sycl::malloc_shared<int>(sizeof(int), q_ct1);
+  test_result = sycl::malloc_device<int>(1, q_ct1);
   *test_result = 0;
+  int h_test_result;
 
   q_ct1.parallel_for(
       sycl::nd_range<3>(sycl::range<3>(1, 1, 1), sycl::range<3>(1, 1, 1)),
       [=](sycl::nd_item<3> item_ct1) { find_first_set_test(test_result); });
 
   dev_ct1.queues_wait_and_throw();
+  q_ct1.copy(&h_test_result, test_result, sizeof(int)).wait();
   find_first_set_test(&host_test_result);
   assert(*test_result == 0);
   assert(host_test_result == 0);

Great, I will apply the suggested changes!

@lbushi25
Copy link
Contributor Author

@cperkinsintel ping

@lbushi25
Copy link
Contributor Author

@intel/llvm-gatekeepers ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants