Skip to content

Commit b52e1c9

Browse files
committed
Add preliminary implementation of tests via syclos side
1 parent 28410c6 commit b52e1c9

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed

sycl/cmake/modules/FetchUnifiedRuntime.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ if(SYCL_UR_USE_FETCH_CONTENT)
121121
# Author: Maosu Zhao <maosu.zhao@intel.com>
122122
# Date: Thu Oct 17 16:31:21 2024 +0800
123123
# [DeviceSanitizer] Refactor the code to manage shadow memory (#2127)
124-
set(UNIFIED_RUNTIME_TAG 644eef9f8dfcc3931fd2883f24eace60ca98b3ed)
124+
set(UNIFIED_RUNTIME_TAG ca43f937d91c53e04ebad69a02dbffdb1bc2f78e)
125125

126126
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
127127
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need

sycl/test-e2e/USM/prefetch_exp.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ int main() {
3030
for (int i = 0; i < count; i++)
3131
src[i] = i;
3232

33-
// Test host to device prefetch_exp(handler &CGH, ..)
3433
{
34+
// Test host to device handler::ext_oneapi_prefetch_exp
3535
event init_prefetch = q.submit(
3636
[&](handler &cgh) { cgh.ext_oneapi_prefetch_exp(src, sizeof(float) * count); });
3737

@@ -41,12 +41,27 @@ int main() {
4141
for (int i = 0; i < count; i++)
4242
dest[i] = 2 * src[i];
4343
});
44-
}
44+
});
4545
q.wait_and_throw();
4646

4747
for (int i = 0; i < count; i++) {
4848
assert(dest[i] == i * 2);
4949
}
50+
51+
// Test device to host handler::ext_oneapi_prefetch_exp
52+
q.submit([&](handler &cgh) {
53+
cgh.single_task<class quadruple_dest>([=]() {
54+
for (int i = 0; i < count; i++)
55+
dest[i] = 4 * src[i];
56+
});
57+
});
58+
event init_prefetch_back = q.submit(
59+
[&](handler &cgh) { cgh.ext_oneapi_prefetch_exp(dest, sizeof(float) * count, sycl::ext::oneapi::experimental::migration_direction::DEVICE_TO_HOST); });
60+
q.wait_and_throw();
61+
62+
for (int i = 0; i < count; i++) {
63+
assert(dest[i] == i * 4);
64+
}
5065
}
5166

5267
// Test queue::prefetch
@@ -55,7 +70,7 @@ int main() {
5570

5671
q.submit([&](handler &cgh) {
5772
cgh.depends_on(init_prefetch);
58-
cgh.single_task<class double_dest3>([=]() {
73+
cgh.single_task<class triple_dest>([=]() {
5974
for (int i = 0; i < count; i++)
6075
dest[i] = 3 * src[i];
6176
});
@@ -65,6 +80,19 @@ int main() {
6580
for (int i = 0; i < count; i++) {
6681
assert(dest[i] == i * 3);
6782
}
83+
84+
q.submit([&](handler &cgh) {
85+
cgh.single_task<class sixtuple_dest>([=]() {
86+
for (int i = 0; i < count; i++)
87+
dest[i] = 6 * src[i];
88+
});
89+
});
90+
event init_prefetch_back = q.ext_oneapi_prefetch_exp(src, sizeof(float) * count, sycl::ext::oneapi::experimental::migration_direction::DEVICE_TO_HOST);
91+
q.wait_and_throw();
92+
93+
for (int i = 0; i < count; i++) {
94+
assert(dest[i] == i * 6);
95+
}
6896
}
6997
free(src, q);
7098
free(dest, q);

sycl/unittests/Extensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_sycl_unittest(ExtensionsTests OBJECT
1616
KernelProperties.cpp
1717
NoDeviceIPVersion.cpp
1818
GetLastEvent.cpp
19+
USMPrefetchExp.cpp
1920
)
2021

2122
add_subdirectory(CommandGraph)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <helpers/UrMock.hpp>
2+
#include <sycl/detail/core.hpp>
3+
#include <sycl/usm.hpp>
4+
#include <sycl/ext/oneapi/experimental/USM/prefetch_exp.hpp>
5+
6+
#include <gtest/gtest.h>
7+
8+
static constexpr int N = 8;
9+
static ur_usm_migration_flags_t urUSMPrefetchDirection = -1;
10+
11+
// TODO: FIGURE OUT WHEN COMMANDBUF GETS CALLED AND IMPLEMENT COMMANDBUF TESTING
12+
13+
ur_result_t redefinedEnqueueUSMPrefetch(void *pParams) {
14+
auto params = *static_cast<ur_enqueue_usm_prefetch_params_t *>(pParams);
15+
urUSMPrefetchDirection = *(params.pflags);
16+
return UR_RESULT_SUCCESS;
17+
}
18+
19+
TEST(USMPrefetchExp, CheckURCall) {
20+
using namespace sycl;
21+
unittest::UrMock<> Mock;
22+
mock::getCallbacks().set_replace_callback("urEnqueueUSMPrefetch",
23+
&redefinedEnqueueUSMPrefetch);
24+
queue q;
25+
int *mem = (int*) malloc_shared(sizeof(int) * N, q.get_device(), q.get_context());
26+
27+
// Check handler calls:
28+
q.submit([&](handler &cgh) { cgh.ext_oneapi_prefetch_exp(mem, sizeof(int) * N); });
29+
q.wait_and_throw();
30+
EXPECT_EQ(urUSMPrefetchDirection, UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE);
31+
32+
q.submit([&](handler &cgh) { cgh.ext_oneapi_prefetch_exp(mem, sizeof(int) * N, sycl::ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE); });
33+
q.wait_and_throw();
34+
EXPECT_EQ(urUSMPrefetchDirection, UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE);
35+
36+
q.submit([&](handler &cgh) { cgh.ext_oneapi_prefetch_exp(mem, sizeof(int) * N, sycl::ext::oneapi::experimental::migration_direction::DEVICE_TO_HOST); });
37+
q.wait_and_throw();
38+
EXPECT_EQ(urUSMPrefetchDirection, UR_USM_MIGRATION_FLAG_DEVICE_TO_HOST);
39+
40+
// Check queue calls:
41+
q.ext_oneapi_prefetch_exp(mem, sizeof(int) * N);
42+
q.wait_and_throw();
43+
EXPECT_EQ(urUSMPrefetchDirection, UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE);
44+
45+
q.ext_oneapi_prefetch_exp(mem, sizeof(int) * N, sycl::ext::oneapi::experimental::migration_direction::HOST_TO_DEVICE);
46+
q.wait_and_throw();
47+
EXPECT_EQ(urUSMPrefetchDirection, UR_USM_MIGRATION_FLAG_HOST_TO_DEVICE);
48+
49+
q.ext_oneapi_prefetch_exp(mem, sizeof(int) * N, sycl::ext::oneapi::experimental::migration_direction::DEVICE_TO_HOST);
50+
q.wait_and_throw();
51+
EXPECT_EQ(urUSMPrefetchDirection, UR_USM_MIGRATION_FLAG_DEVICE_TO_HOST);
52+
53+
// TODO: not sure what else to test for, check event? I don't think there's any other
54+
// parameters to validate....
55+
}

0 commit comments

Comments
 (0)