diff --git a/test/conformance/CMakeLists.txt b/test/conformance/CMakeLists.txt index 5c14d3e34a..fe6eb43f9b 100644 --- a/test/conformance/CMakeLists.txt +++ b/test/conformance/CMakeLists.txt @@ -45,6 +45,7 @@ function(add_conformance_test_with_platform_environment name) endfunction() add_subdirectory(testing) +add_subdirectory(adapters) add_subdirectory(platform) add_subdirectory(device) diff --git a/test/conformance/adapters/CMakeLists.txt b/test/conformance/adapters/CMakeLists.txt new file mode 100644 index 0000000000..c49bdfd412 --- /dev/null +++ b/test/conformance/adapters/CMakeLists.txt @@ -0,0 +1,3 @@ +if(UR_BUILD_ADAPTER_CUDA) + add_subdirectory(cuda) +endif() diff --git a/test/conformance/adapters/cuda/CMakeLists.txt b/test/conformance/adapters/cuda/CMakeLists.txt new file mode 100644 index 0000000000..bed37d8070 --- /dev/null +++ b/test/conformance/adapters/cuda/CMakeLists.txt @@ -0,0 +1,15 @@ + +add_conformance_test_with_devices_environment(adapter-cuda + cuda_fixtures.h + cuda_urContextGetNativeHandle.cpp + cuda_urDeviceGetNativeHandle.cpp + cuda_urDeviceCreateWithNativeHandle.cpp + cuda_urEventGetNativeHandle.cpp + cuda_urEventCreateWithNativeHandle.cpp +) +target_link_libraries(test-adapter-cuda PRIVATE cudadrv) + +set_tests_properties(adapter-cuda PROPERTIES + LABELS "conformance:cuda" + ENVIRONMENT "UR_ADAPTERS_FORCE_LOAD=\"$\"" + ) diff --git a/test/conformance/adapters/cuda/cuda_fixtures.h b/test/conformance/adapters/cuda/cuda_fixtures.h new file mode 100644 index 0000000000..2624abc434 --- /dev/null +++ b/test/conformance/adapters/cuda/cuda_fixtures.h @@ -0,0 +1,38 @@ +#ifndef UR_TEST_CONFORMANCE_ADAPTERS_CUDA_FIXTURES_H_INCLUDED +#define UR_TEST_CONFORMANCE_ADAPTERS_CUDA_FIXTURES_H_INCLUDED +#include +#include + +namespace uur { +struct ResultCuda { + + constexpr ResultCuda(CUresult result) noexcept : value(result) {} + + inline bool operator==(const ResultCuda &rhs) const noexcept { + return rhs.value == value; + } + + CUresult value; +}; +} // namespace uur + +#ifndef ASSERT_EQ_RESULT_CUDA +#define ASSERT_EQ_RESULT_CUDA(EXPECTED, ACTUAL) \ + ASSERT_EQ(uur::ResultCuda(EXPECTED), uur::ResultCuda(ACTUAL)) +#endif // ASSERT_EQ_RESULT_CUDA + +#ifndef ASSERT_SUCCESS_CUDA +#define ASSERT_SUCCESS_CUDA(ACTUAL) ASSERT_EQ_RESULT_CUDA(CUDA_SUCCESS, ACTUAL) +#endif // ASSERT_SUCCESS_CUDA + +#ifndef EXPECT_EQ_RESULT_CUDA +#define EXPECT_EQ_RESULT_CUDA(EXPECTED, ACTUAL) \ + EXPECT_EQ_RESULT_CUDA(uur::ResultCuda(EXPECTED), uur::ResultCuda(ACTUAL)) +#endif // EXPECT_EQ_RESULT_CUDA + +#ifndef EXPECT_SUCCESS_CUDA +#define EXPECT_SUCCESS_CUDA(ACTUAL) \ + EXPECT_EQ_RESULT_CUDA(UR_RESULT_SUCCESS, ACTUAL) +#endif // EXPECT_EQ_RESULT_CUDA + +#endif // UR_TEST_CONFORMANCE_ADAPTERS_CUDA_FIXTURES_H_INCLUDED diff --git a/test/conformance/adapters/cuda/cuda_urContextGetNativeHandle.cpp b/test/conformance/adapters/cuda/cuda_urContextGetNativeHandle.cpp new file mode 100644 index 0000000000..b9d199516d --- /dev/null +++ b/test/conformance/adapters/cuda/cuda_urContextGetNativeHandle.cpp @@ -0,0 +1,13 @@ +#include "cuda_fixtures.h" + +using urCudaContextGetNativeHandle = uur::urContextTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaContextGetNativeHandle); + +TEST_P(urCudaContextGetNativeHandle, Success) { + ur_native_handle_t native_context = nullptr; + ASSERT_SUCCESS(urContextGetNativeHandle(context, &native_context)); + CUcontext cuda_context = reinterpret_cast(native_context); + + unsigned int cudaVersion; + ASSERT_SUCCESS_CUDA(cuCtxGetApiVersion(cuda_context, &cudaVersion)); +} diff --git a/test/conformance/adapters/cuda/cuda_urDeviceCreateWithNativeHandle.cpp b/test/conformance/adapters/cuda/cuda_urDeviceCreateWithNativeHandle.cpp new file mode 100644 index 0000000000..89fddfaf83 --- /dev/null +++ b/test/conformance/adapters/cuda/cuda_urDeviceCreateWithNativeHandle.cpp @@ -0,0 +1,18 @@ +#include "cuda_fixtures.h" + +using urCudaDeviceCreateWithNativeHandle = uur::urPlatformTest; + +TEST_F(urCudaDeviceCreateWithNativeHandle, Success) { + // get a device from cuda + int nCudaDevices; + ASSERT_SUCCESS_CUDA(cuDeviceGetCount(&nCudaDevices)); + ASSERT_GT(nCudaDevices, 0); + CUdevice cudaDevice; + ASSERT_SUCCESS_CUDA(cuDeviceGet(&cudaDevice, 0)); + + ur_native_handle_t nativeCuda = + reinterpret_cast(cudaDevice); + ur_device_handle_t urDevice; + ASSERT_SUCCESS(urDeviceCreateWithNativeHandle(nativeCuda, platform, nullptr, + &urDevice)); +} diff --git a/test/conformance/adapters/cuda/cuda_urDeviceGetNativeHandle.cpp b/test/conformance/adapters/cuda/cuda_urDeviceGetNativeHandle.cpp new file mode 100644 index 0000000000..cfedae68ad --- /dev/null +++ b/test/conformance/adapters/cuda/cuda_urDeviceGetNativeHandle.cpp @@ -0,0 +1,15 @@ +#include "cuda_fixtures.h" + +using urCudaGetDeviceNativeHandle = uur::urDeviceTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaGetDeviceNativeHandle); + +TEST_P(urCudaGetDeviceNativeHandle, Success) { + ur_native_handle_t native_handle; + ASSERT_SUCCESS(urDeviceGetNativeHandle(device, &native_handle)); + + CUdevice cuda_device = *reinterpret_cast(&native_handle); + + char cuda_device_name[256]; + ASSERT_SUCCESS_CUDA(cuDeviceGetName(cuda_device_name, + sizeof(cuda_device_name), cuda_device)); +} diff --git a/test/conformance/adapters/cuda/cuda_urEventCreateWithNativeHandle.cpp b/test/conformance/adapters/cuda/cuda_urEventCreateWithNativeHandle.cpp new file mode 100644 index 0000000000..d85b83902f --- /dev/null +++ b/test/conformance/adapters/cuda/cuda_urEventCreateWithNativeHandle.cpp @@ -0,0 +1,19 @@ +#include "cuda_fixtures.h" + +using urCudaEventCreateWithNativeHandleTest = uur::urQueueTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaEventCreateWithNativeHandleTest); + +TEST_P(urCudaEventCreateWithNativeHandleTest, Success) { + + CUevent cuda_event; + ASSERT_SUCCESS_CUDA(cuEventCreate(&cuda_event, CU_EVENT_DEFAULT)); + + ur_native_handle_t native_event = + reinterpret_cast(cuda_event); + + ur_event_handle_t event = nullptr; + ASSERT_SUCCESS( + urEventCreateWithNativeHandle(native_event, context, nullptr, &event)); + + ASSERT_SUCCESS(urEventRelease(event)); +} diff --git a/test/conformance/adapters/cuda/cuda_urEventGetNativeHandle.cpp b/test/conformance/adapters/cuda/cuda_urEventGetNativeHandle.cpp new file mode 100644 index 0000000000..484b2e88c6 --- /dev/null +++ b/test/conformance/adapters/cuda/cuda_urEventGetNativeHandle.cpp @@ -0,0 +1,25 @@ +#include "cuda_fixtures.h" + +using urCudaEventGetNativeHandleTest = uur::urQueueTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaEventGetNativeHandleTest); + +TEST_P(urCudaEventGetNativeHandleTest, Success) { + constexpr size_t buffer_size = 1024; + ur_mem_handle_t mem = nullptr; + ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, + buffer_size, nullptr, &mem)); + + ur_event_handle_t event = nullptr; + uint8_t pattern = 6; + ASSERT_SUCCESS(urEnqueueMemBufferFill(queue, mem, &pattern, sizeof(pattern), + 0, buffer_size, 0, nullptr, &event)); + + ur_native_handle_t native_event = nullptr; + ASSERT_SUCCESS(urEventGetNativeHandle(event, &native_event)); + CUevent cuda_event = reinterpret_cast(native_event); + + ASSERT_SUCCESS_CUDA(cuEventSynchronize(cuda_event)); + + ASSERT_SUCCESS(urEventRelease(event)); + ASSERT_SUCCESS(urMemRelease(mem)); +}