Skip to content

Commit 3f15fca

Browse files
authored
add tests for clGetSVMPointerInfoKHR with a non-USVM pointer (#2280)
Note, this PR is setup to merge to the `cl_khr_unified_svm` branch. Querying a non-USVM pointer should return default values and should not return an error. This is the next item on the `cl_khr_unified_svm` test plan.
1 parent debc466 commit 3f15fca

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

test_conformance/SVM/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(${MODULE_NAME}_SOURCES
1919
test_unified_svm_consistency.cpp
2020
test_unified_svm_capabilities.cpp
2121
test_unified_svm_apis.cpp
22+
test_unified_svm_api_query_defaults.cpp
2223
)
2324

2425
set_gnulike_module_compile_flags("-Wno-sometimes-uninitialized -Wno-sign-compare")
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
// Copyright (c) 2025 The Khronos Group Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#include "unified_svm_fixture.h"
18+
#include <cinttypes>
19+
#include <memory>
20+
21+
struct UnifiedSVMAPIQueryDefaults : UnifiedSVMBase
22+
{
23+
UnifiedSVMAPIQueryDefaults(cl_context context, cl_device_id device,
24+
cl_command_queue queue, int num_elements)
25+
: UnifiedSVMBase(context, device, queue, num_elements)
26+
{}
27+
28+
cl_int test_query_defaults(cl_device_id queryDevice)
29+
{
30+
cl_int err = CL_SUCCESS;
31+
const void* query_ptr = &err; // a random non-USVM pointer
32+
33+
cl_uint typeIndexQuery = 0;
34+
err = clGetSVMPointerInfoKHR(
35+
context, queryDevice, query_ptr, CL_SVM_INFO_TYPE_INDEX_KHR,
36+
sizeof(typeIndexQuery), &typeIndexQuery, nullptr);
37+
test_error(err,
38+
"clGetSVMPointerInfoKHR for CL_SVM_INFO_TYPE_INDEX_KHR");
39+
test_assert_error_ret(typeIndexQuery == CL_UINT_MAX,
40+
"type index is not the default",
41+
CL_INVALID_VALUE);
42+
43+
cl_svm_capabilities_khr capabilitiesQuery = ~0;
44+
err = clGetSVMPointerInfoKHR(
45+
context, queryDevice, query_ptr, CL_SVM_INFO_CAPABILITIES_KHR,
46+
sizeof(capabilitiesQuery), &capabilitiesQuery, nullptr);
47+
test_error(err,
48+
"clGetSVMPointerInfoKHR for CL_SVM_INFO_CAPABILITIES_KHR");
49+
test_assert_error_ret(capabilitiesQuery == 0,
50+
"capabilities are not the default",
51+
CL_INVALID_VALUE);
52+
53+
cl_svm_alloc_access_flags_khr accessFlagsQuery = ~0;
54+
err = clGetSVMPointerInfoKHR(
55+
context, queryDevice, query_ptr, CL_SVM_INFO_ACCESS_FLAGS_KHR,
56+
sizeof(accessFlagsQuery), &accessFlagsQuery, nullptr);
57+
test_error(err,
58+
"clGetSVMPointerInfoKHR for CL_SVM_INFO_ACCESS_FLAGS_KHR");
59+
test_assert_error_ret(accessFlagsQuery == 0,
60+
"access flags are not the default",
61+
CL_INVALID_VALUE);
62+
63+
void* basePtrQuery = &err;
64+
err = clGetSVMPointerInfoKHR(
65+
context, queryDevice, query_ptr, CL_SVM_INFO_BASE_PTR_KHR,
66+
sizeof(basePtrQuery), &basePtrQuery, nullptr);
67+
test_error(err, "clGetSVMPointerInfoKHR for CL_SVM_INFO_BASE_PTR_KHR");
68+
test_assert_error_ret(basePtrQuery == nullptr,
69+
"base pointer is not the default",
70+
CL_INVALID_VALUE);
71+
72+
size_t sizeQuery = ~0;
73+
err = clGetSVMPointerInfoKHR(context, queryDevice, query_ptr,
74+
CL_SVM_INFO_SIZE_KHR, sizeof(sizeQuery),
75+
&sizeQuery, nullptr);
76+
test_error(err, "clGetSVMPointerInfoKHR for CL_SVM_INFO_SIZE_KHR");
77+
test_assert_error_ret(sizeQuery == 0, "size is not the default",
78+
CL_INVALID_VALUE);
79+
80+
cl_device_id associatedDeviceQuery = device;
81+
err = clGetSVMPointerInfoKHR(context, queryDevice, query_ptr,
82+
CL_SVM_INFO_ASSOCIATED_DEVICE_HANDLE_KHR,
83+
sizeof(associatedDeviceQuery),
84+
&associatedDeviceQuery, nullptr);
85+
test_error(err,
86+
"clGetSVMPointerInfoKHR for "
87+
"CL_SVM_INFO_ASSOCIATED_DEVICE_HANDLE_KHR");
88+
test_assert_error_ret(associatedDeviceQuery == nullptr,
89+
"associated device handle is not the default",
90+
CL_INVALID_VALUE);
91+
92+
return CL_SUCCESS;
93+
}
94+
95+
cl_int run() override
96+
{
97+
cl_int err;
98+
99+
log_info(" testing query defaults with no device\n");
100+
err = test_query_defaults(nullptr);
101+
test_error(err, "query defaults failed");
102+
103+
log_info(" testing query defaults with a device\n");
104+
err = test_query_defaults(device);
105+
test_error(err, "query defaults failed");
106+
107+
return CL_SUCCESS;
108+
}
109+
};
110+
111+
REGISTER_TEST(unified_svm_api_query_defaults)
112+
{
113+
REQUIRE_EXTENSION("cl_khr_unified_svm");
114+
115+
cl_int err;
116+
117+
clContextWrapper contextWrapper;
118+
clCommandQueueWrapper queueWrapper;
119+
120+
// For now: create a new context and queue.
121+
// If we switch to a new test executable and run the tests without
122+
// forceNoContextCreation then this can be removed, and we can just use the
123+
// context and the queue from the harness.
124+
if (context == nullptr)
125+
{
126+
contextWrapper =
127+
clCreateContext(nullptr, 1, &device, nullptr, nullptr, &err);
128+
test_error(err, "clCreateContext failed");
129+
context = contextWrapper;
130+
}
131+
132+
if (queue == nullptr)
133+
{
134+
queueWrapper = clCreateCommandQueue(context, device, 0, &err);
135+
test_error(err, "clCreateCommandQueue failed");
136+
queue = queueWrapper;
137+
}
138+
139+
UnifiedSVMAPIQueryDefaults Test(context, device, queue, num_elements);
140+
err = Test.setup();
141+
test_error(err, "test setup failed");
142+
143+
err = Test.run();
144+
test_error(err, "test failed");
145+
146+
return TEST_PASS;
147+
}

0 commit comments

Comments
 (0)