Skip to content

Commit 69268a3

Browse files
author
Hugh Delaney
committed
Add CUDA testing
1 parent 7839346 commit 69268a3

File tree

5 files changed

+106
-11
lines changed

5 files changed

+106
-11
lines changed

test/conformance/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ if(UR_DPCXX)
142142
add_subdirectory(enqueue)
143143
add_subdirectory(integration)
144144
add_subdirectory(exp_command_buffer)
145+
add_subdirectory(exp_enqueue_native)
145146
add_subdirectory(exp_usm_p2p)
146147
add_subdirectory(exp_launch_properties)
147148
add_subdirectory(memory-migrate)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See LICENSE.TXT
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
if (UR_BUILD_ADAPTER_CUDA)
7+
add_conformance_test_with_kernels_environment(
8+
exp_enqueue_native_cuda
9+
enqueue_native_cuda.cpp
10+
)
11+
target_include_directories(test-exp_enqueue_native_cuda PRIVATE
12+
${PROJECT_SOURCE_DIR}/source
13+
${PROJECT_SOURCE_DIR}/source/adapters/cuda
14+
)
15+
target_link_libraries(test-exp_enqueue_native_cuda PRIVATE cudadrv)
16+
endif()
17+
18+
# TODO: Add more tests for different triples
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include <cuda.h>
7+
#include <uur/fixtures.h>
8+
#include <vector>
9+
10+
using T = uint32_t;
11+
12+
struct urCudaEnqueueNativeCommandTest : uur::urQueueTest {
13+
void SetUp() {
14+
UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTest::SetUp());
15+
16+
host_vec = std::vector<T>(global_size, 0);
17+
ASSERT_EQ(host_vec.size(), global_size);
18+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
19+
allocation_size, &device_ptr));
20+
ASSERT_NE(device_ptr, nullptr);
21+
}
22+
static constexpr T val = 42;
23+
static constexpr uint32_t global_size = 1e7;
24+
std::vector<T> host_vec;
25+
void *device_ptr = nullptr;
26+
static constexpr size_t allocation_size = sizeof(val) * global_size;
27+
};
28+
29+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaEnqueueNativeCommandTest);
30+
31+
struct InteropData1 {
32+
void *fill_ptr;
33+
};
34+
35+
// Fill a device ptr with the pattern val
36+
void interop_func_1(ur_queue_handle_t hQueue, void *data) {
37+
CUstream stream;
38+
ASSERT_SUCCESS(
39+
urQueueGetNativeHandle(hQueue, nullptr, (ur_native_handle_t *)&stream));
40+
InteropData1 *func_data = reinterpret_cast<InteropData1 *>(data);
41+
42+
ASSERT_EQ(cuMemsetD32Async((CUdeviceptr)func_data->fill_ptr,
43+
urCudaEnqueueNativeCommandTest::val,
44+
urCudaEnqueueNativeCommandTest::global_size,
45+
stream),
46+
CUDA_SUCCESS);
47+
}
48+
49+
struct InteropData2 {
50+
void *from, *to;
51+
};
52+
53+
// Read from device ptr to host ptr
54+
void interop_func_2(ur_queue_handle_t hQueue, void *data) {
55+
CUstream stream;
56+
ASSERT_SUCCESS(
57+
urQueueGetNativeHandle(hQueue, nullptr, (ur_native_handle_t *)&stream));
58+
InteropData2 *func_data = reinterpret_cast<InteropData2 *>(data);
59+
60+
ASSERT_EQ(cuMemcpyDtoHAsync(func_data->to, (CUdeviceptr)func_data->from,
61+
urCudaEnqueueNativeCommandTest::allocation_size,
62+
stream),
63+
CUDA_SUCCESS);
64+
}
65+
66+
TEST_P(urCudaEnqueueNativeCommandTest, Success) {
67+
InteropData1 data_1{device_ptr};
68+
ur_event_handle_t event_1;
69+
ASSERT_SUCCESS(urEnqueueNativeCommandExp(queue, &interop_func_1, &data_1,
70+
nullptr, 0, nullptr, &event_1));
71+
}
72+
73+
TEST_P(urCudaEnqueueNativeCommandTest, Dependencies) {
74+
ur_event_handle_t event_1, event_2;
75+
76+
InteropData1 data_1{device_ptr};
77+
ASSERT_SUCCESS(urEnqueueNativeCommandExp(queue, &interop_func_1, &data_1,
78+
nullptr, 0, nullptr, &event_1));
79+
80+
InteropData2 data_2{device_ptr, host_vec.data()};
81+
ASSERT_SUCCESS(urEnqueueNativeCommandExp(queue, &interop_func_2, &data_2,
82+
nullptr, 1, &event_1, &event_2));
83+
urQueueFinish(queue);
84+
for (auto &i : host_vec) {
85+
ASSERT_EQ(i, val);
86+
}
87+
}

test/conformance/exp_enqueue_native/exp_enqueue_native_cuda_adapter_cuda.match

Whitespace-only changes.

test/conformance/exp_enqueue_native/urEnqueueNative.cpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)