Skip to content

Commit cb4039e

Browse files
committed
created new unittest for virtual_mem_ext
1 parent 1d36e14 commit cb4039e

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

sycl/unittests/Extensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ add_sycl_unittest(ExtensionsTests OBJECT
2222

2323
add_subdirectory(CommandGraph)
2424
add_subdirectory(VirtualFunctions)
25+
add_subdirectory(VirtualMemory)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_sycl_unittest(VirtualMemoryExtensionTests OBJECT
2+
MultipleDevices.cpp
3+
)
4+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#include <sycl/sycl.hpp>
2+
3+
#include <sycl/ext/oneapi/virtual_mem/physical_mem.hpp>
4+
#include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp>
5+
6+
#include "ur_api.h"
7+
8+
#include <helpers/UrMock.hpp>
9+
10+
#include <gtest/gtest.h>
11+
12+
#include <array>
13+
14+
namespace syclext = sycl::ext::oneapi::experimental;
15+
16+
constexpr size_t NumberOfDevices = 3;
17+
18+
std::array<ur_device_handle_t, NumberOfDevices> GlobalDevicesHandle{
19+
mock::createDummyHandle<ur_device_handle_t>(),
20+
mock::createDummyHandle<ur_device_handle_t>(),
21+
mock::createDummyHandle<ur_device_handle_t>(),
22+
};
23+
24+
ur_result_t setup_urDeviceGet(void *pParams) {
25+
auto params = *static_cast<ur_device_get_params_t *>(pParams);
26+
if (*params.ppNumDevices)
27+
**params.ppNumDevices = 3;
28+
if (*params.pphDevices) {
29+
if (*params.pNumEntries > 0)
30+
(*params.pphDevices)[0] = GlobalDevicesHandle[0];
31+
if (*params.pNumEntries > 1)
32+
(*params.pphDevices)[1] = GlobalDevicesHandle[1];
33+
if (*params.pNumEntries > 2)
34+
(*params.pphDevices)[2] = GlobalDevicesHandle[2];
35+
}
36+
return UR_RESULT_SUCCESS;
37+
}
38+
ur_result_t setup_urDeviceGetInfo(void *pParams) {
39+
auto params = *static_cast<ur_device_get_info_params_t *>(pParams);
40+
switch (*params.ppropName){
41+
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT:{
42+
if (*params.ppPropValue) {
43+
if(*params.phDevice == GlobalDevicesHandle[0]){
44+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
45+
}
46+
}
47+
break;
48+
}
49+
default:{
50+
break;
51+
}
52+
}
53+
return UR_RESULT_SUCCESS;
54+
}
55+
56+
TEST(VirtualMemoryMultipleDevices, ThrowExceptionForGetMemGranularityContext) {
57+
58+
sycl::unittest::UrMock<> Mock;
59+
mock::getCallbacks().set_replace_callback("urDeviceGet",
60+
&setup_urDeviceGet);
61+
mock::getCallbacks().set_replace_callback("urDeviceGetInfo",
62+
&setup_urDeviceGetInfo);
63+
sycl::platform Platform = sycl::platform();
64+
sycl::context Context{Platform};
65+
66+
try {
67+
syclext::get_mem_granularity(Context, syclext::granularity_mode::recommended);
68+
} catch (sycl::exception &e) {
69+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
70+
EXPECT_STREQ(e.what(), "One or more devices in the context does not support aspect::ext_oneapi_virtual_mem.");
71+
}
72+
73+
try {
74+
syclext::get_mem_granularity(Context, syclext::granularity_mode::minimum);
75+
} catch (sycl::exception &e) {
76+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
77+
EXPECT_STREQ(e.what(), "One or more devices in the context does not support aspect::ext_oneapi_virtual_mem.");
78+
}
79+
}
80+
81+
TEST(VirtualMemoryMultipleDevices, ThrowExceptionForGetMemGranularityDevice) {
82+
83+
sycl::unittest::UrMock<> Mock;
84+
mock::getCallbacks().set_replace_callback("urDeviceGet",
85+
&setup_urDeviceGet);
86+
mock::getCallbacks().set_replace_callback("urDeviceGetInfo",
87+
&setup_urDeviceGetInfo);
88+
sycl::platform Platform = sycl::platform();
89+
sycl::context Context{Platform};
90+
91+
try {
92+
syclext::get_mem_granularity(Context.get_devices().front(), Context, syclext::granularity_mode::recommended);
93+
} catch (sycl::exception &e) {
94+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
95+
EXPECT_STREQ(e.what(), "Device does not support aspect::ext_oneapi_virtual_mem.");
96+
}
97+
98+
try {
99+
syclext::get_mem_granularity(Context.get_devices().front(), Context, syclext::granularity_mode::minimum);
100+
} catch (sycl::exception &e) {
101+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
102+
EXPECT_STREQ(e.what(), "Device does not support aspect::ext_oneapi_virtual_mem.");
103+
}
104+
}
105+
106+
107+
TEST(VirtualMemoryMultipleDevices, ReserveVirtualMemoryRange) {
108+
109+
sycl::unittest::UrMock<> Mock;
110+
mock::getCallbacks().set_replace_callback("urDeviceGet",
111+
&setup_urDeviceGet);
112+
mock::getCallbacks().set_replace_callback("urDeviceGetInfo",
113+
&setup_urDeviceGetInfo);
114+
sycl::platform Platform = sycl::platform();
115+
sycl::context Context{Platform};
116+
117+
try {
118+
syclext::reserve_virtual_mem(0, sizeof(int), Context);
119+
} catch (sycl::exception &e) {
120+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
121+
EXPECT_STREQ(e.what(), "One or more devices in the supplied context does not support "
122+
"aspect::ext_oneapi_virtual_mem.");
123+
}
124+
}
125+
126+
127+
TEST(VirtualMemoryMultipleDevices, ReservePhysicalMemory) {
128+
129+
sycl::unittest::UrMock<> Mock;
130+
mock::getCallbacks().set_replace_callback("urDeviceGet",
131+
&setup_urDeviceGet);
132+
mock::getCallbacks().set_replace_callback("urDeviceGetInfo",
133+
&setup_urDeviceGetInfo);
134+
sycl::platform Platform = sycl::platform();
135+
sycl::context Context{Platform};
136+
137+
try {
138+
syclext::physical_mem PhysicalMem{Context.get_devices().front(), Context, sizeof(int)};
139+
} catch (sycl::exception &e) {
140+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
141+
EXPECT_STREQ(e.what(), "Device does not support aspect::ext_oneapi_virtual_mem.");
142+
}
143+
}

0 commit comments

Comments
 (0)