Skip to content

Commit 2507bd8

Browse files
committed
Generalize AsyncTest to work with buffers too
1 parent 4720439 commit 2507bd8

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

sycl/test-e2e/syclcompat/memory/memory_async.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
// RUN: %{build} -o %t.out
3434
// RUN: %{run} %t.out
35+
// RUN: %{build} -DCOMPAT_USM_LEVEL_NONE -o %t.out
36+
// RUN: %{run} %t.out
3537
// Tests for the sycl::events returned from syclcompat::*Async API calls
3638

3739
#include <stdio.h>
@@ -187,6 +189,11 @@ void test_combine_events() {
187189
}
188190

189191
int main() {
192+
#ifdef COMPAT_USM_LEVEL_NONE
193+
std::cout << "Running COMPAT_USM_LEVEL_NONE tests" << std::endl;
194+
#else
195+
std::cout << "Running USM tests" << std::endl;
196+
#endif
190197
test_free_async();
191198

192199
test_memcpy_async1();

sycl/test-e2e/syclcompat/memory/memory_fixt.hpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,39 @@ class AsyncTest {
3737
AsyncTest()
3838
: q_{syclcompat::get_default_queue()}, grid_{NUM_WG}, thread_{WG_SIZE},
3939
size_{WG_SIZE * NUM_WG} {
40-
d_A_ = sycl::malloc_device<float>(size_, q_);
41-
d_B_ = sycl::malloc_device<float>(size_, q_);
42-
d_C_ = sycl::malloc_device<float>(size_, q_);
40+
d_A_ = syclcompat::malloc<float>(size_, q_);
41+
d_B_ = syclcompat::malloc<float>(size_, q_);
42+
d_C_ = syclcompat::malloc<float>(size_, q_);
4343
}
4444

4545
~AsyncTest() {
46-
sycl::free(d_A_, q_);
47-
sycl::free(d_B_, q_);
48-
sycl::free(d_C_, q_);
46+
syclcompat::free(d_A_, q_);
47+
syclcompat::free(d_B_, q_);
48+
syclcompat::free(d_C_, q_);
4949
}
5050
sycl::event launch_kernel() {
5151
auto &dd_A = d_A_;
5252
auto &dd_B = d_B_;
5353
auto &dd_C = d_C_;
54+
#ifdef COMPAT_USM_LEVEL_NONE
55+
syclcompat::buffer_t buffer_A = syclcompat::get_buffer(d_A_);
56+
syclcompat::buffer_t buffer_B = syclcompat::get_buffer(d_B_);
57+
syclcompat::buffer_t buffer_C = syclcompat::get_buffer(d_C_);
58+
#endif
5459
return q_.submit([&](sycl::handler &cgh) {
60+
#ifdef COMPAT_USM_LEVEL_NONE
61+
auto A = buffer_A.get_access<sycl::access::mode::read_write>(cgh);
62+
auto B = buffer_B.get_access<sycl::access::mode::read_write>(cgh);
63+
auto C = buffer_C.get_access<sycl::access::mode::read_write>(cgh);
64+
#else
65+
auto A = dd_A;
66+
auto B = dd_B;
67+
auto C = dd_C;
68+
#endif
5569
cgh.parallel_for(size_, [=](sycl::id<1> id) {
56-
dd_A[id] = static_cast<float>(id) + 1.0f;
57-
dd_B[id] = static_cast<float>(id) + 1.0f;
58-
dd_C[id] = dd_A[id] + dd_B[id];
70+
A[id] = static_cast<float>(id) + 1.0f;
71+
B[id] = static_cast<float>(id) + 1.0f;
72+
C[id] = A[id] + B[id];
5973
});
6074
});
6175
}

0 commit comments

Comments
 (0)