Skip to content

Commit f49f72e

Browse files
authored
Merge pull request #2675 from martygrant/martin/enqueue-cts-spec-gap
Improvements to align CTS and Spec for Enqueue
2 parents 16c8579 + 86eb6b5 commit f49f72e

18 files changed

+462
-191
lines changed

include/ur_api.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8295,8 +8295,6 @@ typedef enum ur_usm_migration_flag_t {
82958295
/// address space and return a pointer to the mapped region
82968296
///
82978297
/// @details
8298-
/// - Input parameter blockingMap indicates if the map is blocking or
8299-
/// non-blocking.
83008298
/// - Currently, no direct support in Level Zero. Implemented as a shared
83018299
/// allocation followed by copying on discrete GPU
83028300
/// - TODO: add a driver function in Level Zero?
@@ -8569,7 +8567,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
85698567
/// @details
85708568
/// - Not all memory advice hints may be supported for all devices or
85718569
/// allocation types. If a memory advice hint is not supported, it will be
8572-
/// ignored.
8570+
/// ignored. Some adapters may return ::UR_RESULT_ERROR_ADAPTER_SPECIFIC,
8571+
/// more information can be retrieved by using urAdapterGetLastError.
85738572
///
85748573
/// @returns
85758574
/// - ::UR_RESULT_SUCCESS

scripts/core/enqueue.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ class: $xEnqueue
863863
name: MemBufferMap
864864
ordinal: "0"
865865
details:
866-
- "Input parameter blockingMap indicates if the map is blocking or non-blocking."
867866
- "Currently, no direct support in Level Zero. Implemented as a shared allocation followed by copying on discrete GPU"
868867
- "TODO: add a driver function in Level Zero?"
869868
analogue:
@@ -1180,7 +1179,7 @@ class: $xEnqueue
11801179
name: USMAdvise
11811180
ordinal: "0"
11821181
details:
1183-
- "Not all memory advice hints may be supported for all devices or allocation types. If a memory advice hint is not supported, it will be ignored."
1182+
- "Not all memory advice hints may be supported for all devices or allocation types. If a memory advice hint is not supported, it will be ignored. Some adapters may return $X_RESULT_ERROR_ADAPTER_SPECIFIC, more information can be retrieved by using urAdapterGetLastError."
11841183
params:
11851184
- type: $x_queue_handle_t
11861185
name: hQueue

source/loader/ur_libapi.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5951,8 +5951,6 @@ ur_result_t UR_APICALL urEnqueueMemImageCopy(
59515951
/// address space and return a pointer to the mapped region
59525952
///
59535953
/// @details
5954-
/// - Input parameter blockingMap indicates if the map is blocking or
5955-
/// non-blocking.
59565954
/// - Currently, no direct support in Level Zero. Implemented as a shared
59575955
/// allocation followed by copying on discrete GPU
59585956
/// - TODO: add a driver function in Level Zero?
@@ -6272,7 +6270,8 @@ ur_result_t UR_APICALL urEnqueueUSMPrefetch(
62726270
/// @details
62736271
/// - Not all memory advice hints may be supported for all devices or
62746272
/// allocation types. If a memory advice hint is not supported, it will be
6275-
/// ignored.
6273+
/// ignored. Some adapters may return ::UR_RESULT_ERROR_ADAPTER_SPECIFIC,
6274+
/// more information can be retrieved by using urAdapterGetLastError.
62766275
///
62776276
/// @returns
62786277
/// - ::UR_RESULT_SUCCESS

source/ur_api.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,8 +5218,6 @@ ur_result_t UR_APICALL urEnqueueMemImageCopy(
52185218
/// address space and return a pointer to the mapped region
52195219
///
52205220
/// @details
5221-
/// - Input parameter blockingMap indicates if the map is blocking or
5222-
/// non-blocking.
52235221
/// - Currently, no direct support in Level Zero. Implemented as a shared
52245222
/// allocation followed by copying on discrete GPU
52255223
/// - TODO: add a driver function in Level Zero?
@@ -5507,7 +5505,8 @@ ur_result_t UR_APICALL urEnqueueUSMPrefetch(
55075505
/// @details
55085506
/// - Not all memory advice hints may be supported for all devices or
55095507
/// allocation types. If a memory advice hint is not supported, it will be
5510-
/// ignored.
5508+
/// ignored. Some adapters may return ::UR_RESULT_ERROR_ADAPTER_SPECIFIC,
5509+
/// more information can be retrieved by using urAdapterGetLastError.
55115510
///
55125511
/// @returns
55135512
/// - ::UR_RESULT_SUCCESS

test/conformance/enqueue/urEnqueueDeviceGlobalVariableRead.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#include <uur/fixtures.h>
77

8-
using urEnqueueDeviceGetGlobalVariableReadTest = uur::urGlobalVariableTest;
9-
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueDeviceGetGlobalVariableReadTest);
8+
using urEnqueueDeviceGetGlobalVariableReadWithParamTest =
9+
uur::urGlobalVariableWithParamTest<uur::BoolTestParam>;
10+
11+
UUR_DEVICE_TEST_SUITE_WITH_PARAM(
12+
urEnqueueDeviceGetGlobalVariableReadWithParamTest,
13+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("Blocking")),
14+
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
1015

11-
TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, Success) {
16+
TEST_P(urEnqueueDeviceGetGlobalVariableReadWithParamTest, Success) {
17+
bool is_blocking = getParam().value;
1218

1319
ASSERT_SUCCESS(urEnqueueDeviceGlobalVariableWrite(
1420
queue, program, global_var.name.c_str(), true, sizeof(global_var.value),
@@ -26,13 +32,20 @@ TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, Success) {
2632

2733
// read global var back to host
2834
ASSERT_SUCCESS(urEnqueueDeviceGlobalVariableRead(
29-
queue, program, global_var.name.c_str(), true, sizeof(global_var.value),
30-
0, &global_var.value, 0, nullptr, nullptr));
35+
queue, program, global_var.name.c_str(), is_blocking,
36+
sizeof(global_var.value), 0, &global_var.value, 0, nullptr, nullptr));
37+
38+
if (!is_blocking) {
39+
ASSERT_SUCCESS(urQueueFinish(queue));
40+
}
3141

3242
// kernel should increment value
3343
ASSERT_EQ(global_var.value, 1);
3444
}
3545

46+
using urEnqueueDeviceGetGlobalVariableReadTest = uur::urGlobalVariableTest;
47+
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueDeviceGetGlobalVariableReadTest);
48+
3649
TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidNullHandleQueue) {
3750
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
3851
nullptr, program, global_var.name.c_str(), true,

test/conformance/enqueue/urEnqueueDeviceGlobalVariableWrite.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#include <uur/fixtures.h>
77

8+
using urEnqueueDeviceGetGlobalVariableWriteWithParamTest =
9+
uur::urGlobalVariableWithParamTest<uur::BoolTestParam>;
10+
11+
UUR_DEVICE_TEST_SUITE_WITH_PARAM(
12+
urEnqueueDeviceGetGlobalVariableWriteWithParamTest,
13+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("Blocking")),
14+
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
15+
16+
TEST_P(urEnqueueDeviceGetGlobalVariableWriteWithParamTest, Success) {
17+
bool is_blocking = getParam().value;
18+
global_var.value = 42;
19+
20+
ASSERT_SUCCESS(urEnqueueDeviceGlobalVariableWrite(
21+
queue, program, global_var.name.c_str(), is_blocking,
22+
sizeof(global_var.value), 0, &global_var.value, 0, nullptr, nullptr));
23+
24+
if (!is_blocking) {
25+
ASSERT_SUCCESS(urQueueFinish(queue));
26+
}
27+
28+
size_t global_offset = 0;
29+
size_t n_dimensions = 1;
30+
size_t global_size = 1;
31+
32+
// execute the kernel
33+
ASSERT_SUCCESS(urEnqueueKernelLaunch(queue, kernel, n_dimensions,
34+
&global_offset, &global_size, nullptr, 0,
35+
nullptr, nullptr));
36+
ASSERT_SUCCESS(urQueueFinish(queue));
37+
38+
// read global var back to host
39+
int return_value = 0;
40+
ASSERT_SUCCESS(urEnqueueDeviceGlobalVariableRead(
41+
queue, program, global_var.name.c_str(), true, sizeof(return_value), 0,
42+
&return_value, 0, nullptr, nullptr));
43+
44+
// kernel should return global_var.value + 1
45+
ASSERT_EQ(return_value, global_var.value + 1);
46+
}
47+
848
using urEnqueueDeviceGetGlobalVariableWriteTest = uur::urGlobalVariableTest;
949
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueDeviceGetGlobalVariableWriteTest);
1050

test/conformance/enqueue/urEnqueueKernelLaunch.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ TEST_P(urEnqueueKernelLaunchTest, InvalidNullHandleQueue) {
8585
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
8686
}
8787

88+
TEST_P(urEnqueueKernelLaunchTest, InvalidNullPointer) {
89+
ASSERT_EQ_RESULT(urEnqueueKernelLaunch(queue, kernel, n_dimensions, nullptr,
90+
&global_size, nullptr, 0, nullptr,
91+
nullptr),
92+
UR_RESULT_ERROR_INVALID_NULL_POINTER);
93+
94+
ASSERT_EQ_RESULT(urEnqueueKernelLaunch(queue, kernel, n_dimensions,
95+
&global_offset, nullptr, nullptr, 0,
96+
nullptr, nullptr),
97+
UR_RESULT_ERROR_INVALID_NULL_POINTER);
98+
}
99+
88100
TEST_P(urEnqueueKernelLaunchTest, InvalidNullHandleKernel) {
89101
ASSERT_EQ_RESULT(urEnqueueKernelLaunch(queue, nullptr, n_dimensions,
90102
&global_offset, &global_size, nullptr,

test/conformance/enqueue/urEnqueueMemBufferCopyRect.cpp

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,17 @@ struct urEnqueueMemBufferCopyRectTest : uur::urQueueTest {
177177
ur_mem_handle_t src_buffer = nullptr;
178178
ur_mem_handle_t dst_buffer = nullptr;
179179
std::vector<uint32_t> input;
180+
ur_rect_region_t src_region{size, 1, 1};
181+
ur_rect_offset_t src_origin{0, 0, 0};
182+
ur_rect_offset_t dst_origin{0, 0, 0};
183+
size_t src_row_pitch = size;
184+
size_t src_slice_pitch = size;
185+
const size_t dst_row_pitch = size;
186+
size_t dst_slice_pitch = size;
180187
};
181188
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueMemBufferCopyRectTest);
182189

183190
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleQueue) {
184-
ur_rect_region_t src_region{size, 1, 1};
185-
ur_rect_offset_t src_origin{0, 0, 0};
186-
ur_rect_offset_t dst_origin{0, 0, 0};
187191
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
188192
urEnqueueMemBufferCopyRect(nullptr, src_buffer, dst_buffer,
189193
src_origin, dst_origin,
@@ -192,9 +196,6 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleQueue) {
192196
}
193197

194198
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferSrc) {
195-
ur_rect_region_t src_region{size, 1, 1};
196-
ur_rect_offset_t src_origin{0, 0, 0};
197-
ur_rect_offset_t dst_origin{0, 0, 0};
198199
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
199200
urEnqueueMemBufferCopyRect(queue, nullptr, dst_buffer,
200201
src_origin, dst_origin,
@@ -203,9 +204,6 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferSrc) {
203204
}
204205

205206
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferDst) {
206-
ur_rect_region_t src_region{size, 1, 1};
207-
ur_rect_offset_t src_origin{0, 0, 0};
208-
ur_rect_offset_t dst_origin{0, 0, 0};
209207
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
210208
urEnqueueMemBufferCopyRect(queue, src_buffer, nullptr,
211209
src_origin, dst_origin,
@@ -216,9 +214,6 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferDst) {
216214
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullPtrEventWaitList) {
217215
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
218216

219-
ur_rect_region_t src_region{size, 1, 1};
220-
ur_rect_offset_t src_origin{0, 0, 0};
221-
ur_rect_offset_t dst_origin{0, 0, 0};
222217
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
223218
queue, src_buffer, dst_buffer, src_origin, dst_origin,
224219
src_region, size, size, size, size, 1, nullptr, nullptr),
@@ -242,6 +237,79 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullPtrEventWaitList) {
242237

243238
ASSERT_SUCCESS(urEventRelease(validEvent));
244239
}
240+
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidSize) {
241+
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
242+
243+
// region.width == 0 || region.height == 0 || region.width == 0
244+
src_region.width = 0;
245+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
246+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
247+
src_region, src_row_pitch, src_slice_pitch,
248+
dst_row_pitch, dst_slice_pitch, 0, nullptr, nullptr),
249+
UR_RESULT_ERROR_INVALID_SIZE);
250+
251+
// srcRowPitch != 0 && srcRowPitch < region.width
252+
src_region.width = src_row_pitch + 1;
253+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
254+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
255+
src_region, src_row_pitch, src_slice_pitch,
256+
dst_row_pitch, dst_slice_pitch, 0, nullptr, nullptr),
257+
UR_RESULT_ERROR_INVALID_SIZE);
258+
259+
// dstRowPitch != 0 && dstRowPitch < region.width
260+
src_region.width = dst_row_pitch + 1;
261+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
262+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
263+
src_region, src_row_pitch, src_slice_pitch,
264+
dst_row_pitch, dst_slice_pitch, 0, nullptr, nullptr),
265+
UR_RESULT_ERROR_INVALID_SIZE);
266+
267+
// srcSlicePitch != 0 && srcSlicePitch < region.height * (srcRowPitch != 0 ?
268+
// srcRowPitch : region.width)
269+
src_region.width = size;
270+
src_row_pitch = 16;
271+
src_slice_pitch = (src_region.height * src_row_pitch) - 1;
272+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
273+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
274+
src_region, src_row_pitch, src_slice_pitch,
275+
dst_row_pitch, dst_slice_pitch, 0, nullptr, nullptr),
276+
UR_RESULT_ERROR_INVALID_SIZE);
277+
278+
// srcSlicePitch != 0 && srcSlicePitch % (srcRowPitch != 0 ? srcRowPitch :
279+
// region.width) != 0
280+
src_slice_pitch = size + 1;
281+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
282+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
283+
src_region, src_row_pitch, src_slice_pitch,
284+
dst_row_pitch, dst_slice_pitch, 0, nullptr, nullptr),
285+
UR_RESULT_ERROR_INVALID_SIZE);
286+
287+
// dstSlicePitch != 0 && dstSlicePitch < region.height * (dstRowPitch != 0 ?
288+
// dstRowPitch : region.width)
289+
src_slice_pitch = size;
290+
dst_slice_pitch = (src_region.height * src_slice_pitch) - 1;
291+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
292+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
293+
src_region, src_row_pitch, src_slice_pitch,
294+
dst_row_pitch, dst_slice_pitch, 0, nullptr, nullptr),
295+
UR_RESULT_ERROR_INVALID_SIZE);
296+
297+
// If the combination of srcOrigin, region, srcRowPitch, and srcSlicePitch
298+
// results in an out-of-bounds access.
299+
src_origin = {std::numeric_limits<uint64_t>::max(), 1, 1};
300+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
301+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
302+
src_region, size, size, size, size, 0, nullptr, nullptr),
303+
UR_RESULT_ERROR_INVALID_SIZE);
304+
305+
// If the combination of dstOrigin, region, dstRowPitch, and dstSlicePitch
306+
// results in an out-of-bounds access.
307+
dst_origin = {std::numeric_limits<uint64_t>::max(), 1, 1};
308+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
309+
queue, src_buffer, dst_buffer, src_origin, dst_origin,
310+
src_region, size, size, size, size, 0, nullptr, nullptr),
311+
UR_RESULT_ERROR_INVALID_SIZE);
312+
}
245313

246314
using urEnqueueMemBufferCopyRectMultiDeviceTest =
247315
uur::urMultiDeviceMemBufferQueueTest;
@@ -281,17 +349,3 @@ TEST_P(urEnqueueMemBufferCopyRectMultiDeviceTest, CopyRectReadDifferentQueues) {
281349

282350
EXPECT_SUCCESS(urMemRelease(dst_buffer));
283351
}
284-
285-
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidSize) {
286-
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
287-
288-
// out-of-bounds access with potential overflow
289-
ur_rect_region_t src_region{size, 1, 1};
290-
ur_rect_offset_t src_origin{std::numeric_limits<uint64_t>::max(), 1, 1};
291-
ur_rect_offset_t dst_origin{0, 0, 0};
292-
293-
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(
294-
queue, src_buffer, dst_buffer, src_origin, dst_origin,
295-
src_region, size, size, size, size, 0, nullptr, nullptr),
296-
UR_RESULT_ERROR_INVALID_SIZE);
297-
}

0 commit comments

Comments
 (0)