From 55409e43a3f69a4e67e7f30558d12ba8c198a438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Mestre?= Date: Fri, 27 Oct 2023 17:46:52 +0100 Subject: [PATCH 1/9] [OpenCL] Fix memory leak --- source/adapters/opencl/adapter.cpp | 16 ++++++++++------ source/adapters/opencl/common.hpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source/adapters/opencl/adapter.cpp b/source/adapters/opencl/adapter.cpp index 10713b9ff9..65c5676bf9 100644 --- a/source/adapters/opencl/adapter.cpp +++ b/source/adapters/opencl/adapter.cpp @@ -12,21 +12,17 @@ struct ur_adapter_handle_t_ { std::atomic RefCount = 0; + std::mutex Mutex; }; ur_adapter_handle_t_ adapter{}; UR_APIEXPORT ur_result_t UR_APICALL urInit(ur_device_init_flags_t, ur_loader_config_handle_t) { - cl_ext::ExtFuncPtrCache = new cl_ext::ExtFuncPtrCacheT(); return UR_RESULT_SUCCESS; } UR_APIEXPORT ur_result_t UR_APICALL urTearDown(void *) { - if (cl_ext::ExtFuncPtrCache) { - delete cl_ext::ExtFuncPtrCache; - cl_ext::ExtFuncPtrCache = nullptr; - } return UR_RESULT_SUCCESS; } @@ -34,6 +30,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet(uint32_t NumEntries, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) { if (NumEntries > 0 && phAdapters) { + std::lock_guard Lock{adapter.Mutex}; + if (adapter.RefCount++ == 0) { + cl_ext::ExtFuncPtrCache = std::make_unique(); + } + *phAdapters = &adapter; } @@ -50,7 +51,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) { } UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) { - --adapter.RefCount; + std::lock_guard Lock{adapter.Mutex}; + if (--adapter.RefCount == 0) { + cl_ext::ExtFuncPtrCache.reset(); + } return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/common.hpp b/source/adapters/opencl/common.hpp index f78710d0df..95105b552d 100644 --- a/source/adapters/opencl/common.hpp +++ b/source/adapters/opencl/common.hpp @@ -260,7 +260,7 @@ struct ExtFuncPtrCacheT { // piTeardown to avoid issues with static destruction order (a user application // might have static objects that indirectly access this cache in their // destructor). -inline ExtFuncPtrCacheT *ExtFuncPtrCache; +inline std::unique_ptr ExtFuncPtrCache; // USM helper function to get an extension function pointer template From f2a365caacd045b919c2b4f7686837e3bc0d27bd Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Tue, 17 Oct 2023 15:14:57 +0100 Subject: [PATCH 2/9] [OpenCL] Add version check for urProgramSetSpecializationConstants --- source/adapters/opencl/enqueue.cpp | 8 ++--- source/adapters/opencl/program.cpp | 58 ++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/source/adapters/opencl/enqueue.cpp b/source/adapters/opencl/enqueue.cpp index 29c5ad672e..5f41878182 100644 --- a/source/adapters/opencl/enqueue.cpp +++ b/source/adapters/opencl/enqueue.cpp @@ -350,9 +350,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( return mapCLErrorToUR(CLErr); } - clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr; + cl_ext::clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr; ur_result_t RetVal = - cl_ext::getExtFuncFromContext( + cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clEnqueueReadHostPipeINTELCache, cl_ext::EnqueueReadHostPipeName, &FuncPtr); @@ -382,9 +382,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( return mapCLErrorToUR(CLErr); } - clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr; + cl_ext::clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr; ur_result_t RetVal = - cl_ext::getExtFuncFromContext( + cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clEnqueueWriteHostPipeINTELCache, cl_ext::EnqueueWriteHostPipeName, &FuncPtr); diff --git a/source/adapters/opencl/program.cpp b/source/adapters/opencl/program.cpp index 0beca23dab..7f46b52cfa 100644 --- a/source/adapters/opencl/program.cpp +++ b/source/adapters/opencl/program.cpp @@ -316,20 +316,58 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstants( CL_RETURN_ON_FAILURE(clGetProgramInfo(CLProg, CL_PROGRAM_CONTEXT, sizeof(Ctx), &Ctx, &RetSize)); - cl_ext::clSetProgramSpecializationConstant_fn F = nullptr; - const ur_result_t URResult = cl_ext::getExtFuncFromContext( - Ctx, cl_ext::ExtFuncPtrCache->clSetProgramSpecializationConstantCache, - cl_ext::SetProgramSpecializationConstantName, &F); + std::unique_ptr> DevicesInCtx; + cl_adapter::getDevicesFromContext(cl_adapter::cast(Ctx), + DevicesInCtx); - if (URResult != UR_RESULT_SUCCESS) { - return URResult; - } + cl_platform_id CurPlatform; + clGetDeviceInfo((*DevicesInCtx)[0], CL_DEVICE_PLATFORM, + sizeof(cl_platform_id), &CurPlatform, nullptr); + + oclv::OpenCLVersion PlatVer; + cl_adapter::getPlatformVersion(CurPlatform, PlatVer); + + bool UseExtensionLookup = false; + if (PlatVer < oclv::V2_2) { + UseExtensionLookup = true; + } else { + for (cl_device_id Dev : *DevicesInCtx) { + oclv::OpenCLVersion DevVer; - for (uint32_t i = 0; i < count; ++i) { - CL_RETURN_ON_FAILURE(F(CLProg, pSpecConstants[i].id, pSpecConstants[i].size, - pSpecConstants[i].pValue)); + cl_adapter::getDeviceVersion(Dev, DevVer); + + if (DevVer < oclv::V2_2) { + UseExtensionLookup = true; + break; + } + } } + if (UseExtensionLookup == false) { + for (uint32_t i = 0; i < count; ++i) { + CL_RETURN_ON_FAILURE(clSetProgramSpecializationConstant( + CLProg, pSpecConstants[i].id, pSpecConstants[i].size, + pSpecConstants[i].pValue)); + } + } else { + cl_ext::clSetProgramSpecializationConstant_fn + SetProgramSpecializationConstant = nullptr; + const ur_result_t URResult = cl_ext::getExtFuncFromContext< + decltype(SetProgramSpecializationConstant)>( + Ctx, cl_ext::ExtFuncPtrCache->clSetProgramSpecializationConstantCache, + cl_ext::SetProgramSpecializationConstantName, + &SetProgramSpecializationConstant); + + if (URResult != UR_RESULT_SUCCESS) { + return URResult; + } + + for (uint32_t i = 0; i < count; ++i) { + CL_RETURN_ON_FAILURE(SetProgramSpecializationConstant( + CLProg, pSpecConstants[i].id, pSpecConstants[i].size, + pSpecConstants[i].pValue)); + } + } return UR_RESULT_SUCCESS; } From 93bdb8181ed0ef535cc10971eb240b61193e87b5 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 31 Oct 2023 17:40:36 +0000 Subject: [PATCH 3/9] [CUDA][HIP] Move adapter specific testing out of CTS This patch moves the `test-adapter-cuda` and `test-adapter-hip` test suites out of the `test/conformance` directory. The goal of this move is to ensure that all adapters will be tested with the same set and number of conformance tests, making conformance pass rates directly comparable between adapters. Up to now the CUDA and HIP adapters have included additional unit tests of internals which skews pass rates. --- .github/workflows/cmake.yml | 4 ++ source/adapters/cuda/CMakeLists.txt | 2 - source/adapters/hip/CMakeLists.txt | 2 - test/CMakeLists.txt | 1 + test/adapters/CMakeLists.txt | 46 +++++++++++++++++++ test/adapters/cuda/CMakeLists.txt | 27 +++++++++++ .../adapters/cuda/context_tests.cpp | 0 .../adapters/cuda/fixtures.h | 0 .../adapters/cuda/kernel_tests.cpp | 0 .../adapters/cuda/memory_tests.cpp | 0 .../cuda/urContextGetNativeHandle.cpp | 0 .../cuda/urDeviceCreateWithNativeHandle.cpp | 0 .../adapters/cuda/urDeviceGetNativeHandle.cpp | 0 .../cuda/urEventCreateWithNativeHandle.cpp | 0 .../adapters/cuda/urEventGetNativeHandle.cpp | 0 test/adapters/hip/CMakeLists.txt | 29 ++++++++++++ .../{conformance => }/adapters/hip/fixtures.h | 0 .../adapters/hip/test_context.cpp | 0 .../adapters/hip/urContextGetNativeHandle.cpp | 0 .../adapters/hip/urDeviceGetNativeHandle.cpp | 0 .../adapters/hip/urEventGetNativeHandle.cpp | 0 test/conformance/CMakeLists.txt | 39 +++++++--------- test/conformance/adapters/CMakeLists.txt | 12 ----- test/conformance/adapters/cuda/CMakeLists.txt | 24 ---------- test/conformance/adapters/hip/CMakeLists.txt | 26 ----------- 25 files changed, 123 insertions(+), 89 deletions(-) create mode 100644 test/adapters/CMakeLists.txt create mode 100644 test/adapters/cuda/CMakeLists.txt rename test/{conformance => }/adapters/cuda/context_tests.cpp (100%) rename test/{conformance => }/adapters/cuda/fixtures.h (100%) rename test/{conformance => }/adapters/cuda/kernel_tests.cpp (100%) rename test/{conformance => }/adapters/cuda/memory_tests.cpp (100%) rename test/{conformance => }/adapters/cuda/urContextGetNativeHandle.cpp (100%) rename test/{conformance => }/adapters/cuda/urDeviceCreateWithNativeHandle.cpp (100%) rename test/{conformance => }/adapters/cuda/urDeviceGetNativeHandle.cpp (100%) rename test/{conformance => }/adapters/cuda/urEventCreateWithNativeHandle.cpp (100%) rename test/{conformance => }/adapters/cuda/urEventGetNativeHandle.cpp (100%) create mode 100644 test/adapters/hip/CMakeLists.txt rename test/{conformance => }/adapters/hip/fixtures.h (100%) rename test/{conformance => }/adapters/hip/test_context.cpp (100%) rename test/{conformance => }/adapters/hip/urContextGetNativeHandle.cpp (100%) rename test/{conformance => }/adapters/hip/urDeviceGetNativeHandle.cpp (100%) rename test/{conformance => }/adapters/hip/urEventGetNativeHandle.cpp (100%) delete mode 100644 test/conformance/adapters/CMakeLists.txt delete mode 100644 test/conformance/adapters/cuda/CMakeLists.txt delete mode 100644 test/conformance/adapters/hip/CMakeLists.txt diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9edbd459d7..0a2684462d 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -203,6 +203,10 @@ jobs: run: LD_LIBRARY_PATH=${{github.workspace}}/dpcpp_compiler/lib cmake --build ${{github.workspace}}/build -j $(nproc) + - name: Test adapter specific + working-directory: ${{github.workspace}}/build + run: ctest -C ${{matrix.build_type}} --output-on-failure -L "adapter-specific" --timeout 180 + # Temporarily disabling platform test for L0, because of hang # See issue: #824 - name: Test L0 adapter diff --git a/source/adapters/cuda/CMakeLists.txt b/source/adapters/cuda/CMakeLists.txt index 0b44ae0777..4a8c1d1f59 100644 --- a/source/adapters/cuda/CMakeLists.txt +++ b/source/adapters/cuda/CMakeLists.txt @@ -3,8 +3,6 @@ # See LICENSE.TXT # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set(CUDA_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "CUDA adapter directory") - set(TARGET_NAME ur_adapter_cuda) add_ur_adapter(${TARGET_NAME} diff --git a/source/adapters/hip/CMakeLists.txt b/source/adapters/hip/CMakeLists.txt index 4595bfbf84..7de1b5f501 100644 --- a/source/adapters/hip/CMakeLists.txt +++ b/source/adapters/hip/CMakeLists.txt @@ -3,8 +3,6 @@ # See LICENSE.TXT # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set(HIP_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "HIP adapter directory") - set(TARGET_NAME ur_adapter_hip) # Set default UR HIP platform to AMD diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1d7e84f0c3..49e13eb869 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,7 @@ enable_testing() add_subdirectory(python) add_subdirectory(loader) +add_subdirectory(adapters) add_subdirectory(conformance) add_subdirectory(unified_malloc_framework) add_subdirectory(usm) diff --git a/test/adapters/CMakeLists.txt b/test/adapters/CMakeLists.txt new file mode 100644 index 0000000000..d87d774ede --- /dev/null +++ b/test/adapters/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright (C) 2023 Intel Corporation +# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +# See LICENSE.TXT +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +function(add_adapter_test name) + cmake_parse_arguments(args + "" # options + "FIXTURE" # one value keywords + "SOURCES;ENVIRONMENT" # multi value keywords + ${ARGN}) + + set(target test-adapter-${name}) + add_ur_executable(${target} ${args_SOURCES} + ${PROJECT_SOURCE_DIR}/test/conformance/source/environment.cpp + ${PROJECT_SOURCE_DIR}/test/conformance/source/main.cpp + ) + + set(fixtures "PLATFORM;DEVICES;KERNELS") + if(NOT args_FIXTURE IN_LIST fixtures) + message(FATAL_ERROR + "FIXTURE must be one of: ${fixtures}. Found: ${args_FIXTURE}") + endif() + + target_compile_definitions(${target} PRIVATE + ${args_FIXTURE}_ENVIRONMENT) + target_link_libraries(${target} PRIVATE + ${PROJECT_NAME}::loader + ${PROJECT_NAME}::headers + ${PROJECT_NAME}::testing + ${PROJECT_NAME}::common + GTest::gtest) + + add_test(NAME ${target} COMMAND $) + set_tests_properties(${target} PROPERTIES + LABELS "adapter-specific;${name}" + ENVIRONMENT "${args_ENVIRONMENT}") +endfunction() + +if(UR_BUILD_ADAPTER_CUDA) + add_subdirectory(cuda) +endif() + +if(UR_BUILD_ADAPTER_HIP) + add_subdirectory(hip) +endif() diff --git a/test/adapters/cuda/CMakeLists.txt b/test/adapters/cuda/CMakeLists.txt new file mode 100644 index 0000000000..fbc15b47e8 --- /dev/null +++ b/test/adapters/cuda/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright (C) 2023 Intel Corporation +# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +# See LICENSE.TXT +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +add_adapter_test(cuda + FIXTURE DEVICES + SOURCES + fixtures.h + context_tests.cpp + urContextGetNativeHandle.cpp + urDeviceGetNativeHandle.cpp + urDeviceCreateWithNativeHandle.cpp + urEventGetNativeHandle.cpp + urEventCreateWithNativeHandle.cpp + kernel_tests.cpp + memory_tests.cpp + ENVIRONMENT + "UR_ADAPTERS_FORCE_LOAD=\"$\"" +) + +target_include_directories(test-adapter-cuda PRIVATE + ${PROJECT_SOURCE_DIR}/source + ${PROJECT_SOURCE_DIR}/source/adapters/cuda +) + +target_link_libraries(test-adapter-cuda PRIVATE cudadrv) diff --git a/test/conformance/adapters/cuda/context_tests.cpp b/test/adapters/cuda/context_tests.cpp similarity index 100% rename from test/conformance/adapters/cuda/context_tests.cpp rename to test/adapters/cuda/context_tests.cpp diff --git a/test/conformance/adapters/cuda/fixtures.h b/test/adapters/cuda/fixtures.h similarity index 100% rename from test/conformance/adapters/cuda/fixtures.h rename to test/adapters/cuda/fixtures.h diff --git a/test/conformance/adapters/cuda/kernel_tests.cpp b/test/adapters/cuda/kernel_tests.cpp similarity index 100% rename from test/conformance/adapters/cuda/kernel_tests.cpp rename to test/adapters/cuda/kernel_tests.cpp diff --git a/test/conformance/adapters/cuda/memory_tests.cpp b/test/adapters/cuda/memory_tests.cpp similarity index 100% rename from test/conformance/adapters/cuda/memory_tests.cpp rename to test/adapters/cuda/memory_tests.cpp diff --git a/test/conformance/adapters/cuda/urContextGetNativeHandle.cpp b/test/adapters/cuda/urContextGetNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/cuda/urContextGetNativeHandle.cpp rename to test/adapters/cuda/urContextGetNativeHandle.cpp diff --git a/test/conformance/adapters/cuda/urDeviceCreateWithNativeHandle.cpp b/test/adapters/cuda/urDeviceCreateWithNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/cuda/urDeviceCreateWithNativeHandle.cpp rename to test/adapters/cuda/urDeviceCreateWithNativeHandle.cpp diff --git a/test/conformance/adapters/cuda/urDeviceGetNativeHandle.cpp b/test/adapters/cuda/urDeviceGetNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/cuda/urDeviceGetNativeHandle.cpp rename to test/adapters/cuda/urDeviceGetNativeHandle.cpp diff --git a/test/conformance/adapters/cuda/urEventCreateWithNativeHandle.cpp b/test/adapters/cuda/urEventCreateWithNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/cuda/urEventCreateWithNativeHandle.cpp rename to test/adapters/cuda/urEventCreateWithNativeHandle.cpp diff --git a/test/conformance/adapters/cuda/urEventGetNativeHandle.cpp b/test/adapters/cuda/urEventGetNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/cuda/urEventGetNativeHandle.cpp rename to test/adapters/cuda/urEventGetNativeHandle.cpp diff --git a/test/adapters/hip/CMakeLists.txt b/test/adapters/hip/CMakeLists.txt new file mode 100644 index 0000000000..3496f71bd0 --- /dev/null +++ b/test/adapters/hip/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (C) 2023 Intel Corporation +# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +# See LICENSE.TXT +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +add_adapter_test(hip + FIXTURE DEVICES + SOURCES + fixtures.h + urContextGetNativeHandle.cpp + urDeviceGetNativeHandle.cpp + urEventGetNativeHandle.cpp + test_context.cpp + ENVIRONMENT + "UR_ADAPTERS_FORCE_LOAD=\"$\"" +) + +target_include_directories(test-adapter-hip PRIVATE + ${PROJECT_SOURCE_DIR}/source + ${PROJECT_SOURCE_DIR}/source/adapters/hip +) + +get_target_property(HIP_COMPILE_DEFINITIONS + ur_adapter_hip COMPILE_DEFINITIONS) +target_compile_definitions(test-adapter-hip PRIVATE + ${HIP_COMPILE_DEFINITIONS} +) + +target_link_libraries(test-adapter-hip PRIVATE rocmdrv) diff --git a/test/conformance/adapters/hip/fixtures.h b/test/adapters/hip/fixtures.h similarity index 100% rename from test/conformance/adapters/hip/fixtures.h rename to test/adapters/hip/fixtures.h diff --git a/test/conformance/adapters/hip/test_context.cpp b/test/adapters/hip/test_context.cpp similarity index 100% rename from test/conformance/adapters/hip/test_context.cpp rename to test/adapters/hip/test_context.cpp diff --git a/test/conformance/adapters/hip/urContextGetNativeHandle.cpp b/test/adapters/hip/urContextGetNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/hip/urContextGetNativeHandle.cpp rename to test/adapters/hip/urContextGetNativeHandle.cpp diff --git a/test/conformance/adapters/hip/urDeviceGetNativeHandle.cpp b/test/adapters/hip/urDeviceGetNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/hip/urDeviceGetNativeHandle.cpp rename to test/adapters/hip/urDeviceGetNativeHandle.cpp diff --git a/test/conformance/adapters/hip/urEventGetNativeHandle.cpp b/test/adapters/hip/urEventGetNativeHandle.cpp similarity index 100% rename from test/conformance/adapters/hip/urEventGetNativeHandle.cpp rename to test/adapters/hip/urEventGetNativeHandle.cpp diff --git a/test/conformance/CMakeLists.txt b/test/conformance/CMakeLists.txt index e90b74f4cd..9a273470eb 100644 --- a/test/conformance/CMakeLists.txt +++ b/test/conformance/CMakeLists.txt @@ -39,28 +39,22 @@ function(add_conformance_test name) ${PROJECT_NAME}::common GTest::gtest_main) - if(USE_LOCAL_TEST_CONFIGURATION) - add_test(NAME ${name} - COMMAND ${TEST_TARGET_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - else() - if(UR_BUILD_ADAPTER_CUDA) - add_test_adapter(${name} adapter_cuda) - endif() - if(UR_BUILD_ADAPTER_HIP) - add_test_adapter(${name} adapter_hip) - endif() - if(UR_BUILD_ADAPTER_L0) - add_test_adapter(${name} adapter_level_zero) - endif() - if(UR_BUILD_ADAPTER_OPENCL) - add_test_adapter(${name} adapter_opencl) - endif() - - if(NOT (UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP - OR UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_OPENCL)) - add_test_adapter(${name} adapter_null) - endif() + if(UR_BUILD_ADAPTER_CUDA) + add_test_adapter(${name} adapter_cuda) + endif() + if(UR_BUILD_ADAPTER_HIP) + add_test_adapter(${name} adapter_hip) + endif() + if(UR_BUILD_ADAPTER_L0) + add_test_adapter(${name} adapter_level_zero) + endif() + if(UR_BUILD_ADAPTER_OPENCL) + add_test_adapter(${name} adapter_opencl) + endif() + + if(NOT (UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP + OR UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_OPENCL)) + add_test_adapter(${name} adapter_null) endif() endfunction() @@ -83,7 +77,6 @@ function(add_conformance_test_with_platform_environment name) endfunction() add_subdirectory(testing) -add_subdirectory(adapters) add_subdirectory(runtime) add_subdirectory(platform) diff --git a/test/conformance/adapters/CMakeLists.txt b/test/conformance/adapters/CMakeLists.txt deleted file mode 100644 index 84e61864c9..0000000000 --- a/test/conformance/adapters/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (C) 2023 Intel Corporation -# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. -# See LICENSE.TXT -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -if(UR_BUILD_ADAPTER_CUDA) - add_subdirectory(cuda) -endif() - -if(UR_BUILD_ADAPTER_HIP) - add_subdirectory(hip) -endif() diff --git a/test/conformance/adapters/cuda/CMakeLists.txt b/test/conformance/adapters/cuda/CMakeLists.txt deleted file mode 100644 index 8b060686cf..0000000000 --- a/test/conformance/adapters/cuda/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2023 Intel Corporation -# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. -# See LICENSE.TXT -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set(USE_LOCAL_TEST_CONFIGURATION ON) -add_conformance_test_with_devices_environment(adapter-cuda - fixtures.h - context_tests.cpp - urContextGetNativeHandle.cpp - urDeviceGetNativeHandle.cpp - urDeviceCreateWithNativeHandle.cpp - urEventGetNativeHandle.cpp - urEventCreateWithNativeHandle.cpp - kernel_tests.cpp - memory_tests.cpp -) -target_link_libraries(test-adapter-cuda PRIVATE cudadrv ur_adapter_cuda) -target_include_directories(test-adapter-cuda PRIVATE ${CUDA_DIR} "${CUDA_DIR}/../../" ) - -set_tests_properties(adapter-cuda PROPERTIES - LABELS "conformance:cuda" - ENVIRONMENT "UR_ADAPTERS_FORCE_LOAD=\"$\"" - ) diff --git a/test/conformance/adapters/hip/CMakeLists.txt b/test/conformance/adapters/hip/CMakeLists.txt deleted file mode 100644 index 1e40639d21..0000000000 --- a/test/conformance/adapters/hip/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2023 Intel Corporation -# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. -# See LICENSE.TXT -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set(USE_LOCAL_TEST_CONFIGURATION ON) -add_conformance_test_with_devices_environment(adapter-hip - fixtures.h - urContextGetNativeHandle.cpp - urDeviceGetNativeHandle.cpp - urEventGetNativeHandle.cpp - test_context.cpp -) -target_link_libraries(test-adapter-hip PRIVATE rocmdrv) -target_include_directories(test-adapter-hip PRIVATE ${HIP_DIR} "${HIP_DIR}/../../") - -if(UR_HIP_PLATFORM STREQUAL "AMD") - target_compile_definitions(test-adapter-hip PRIVATE __HIP_PLATFORM_AMD__) -else() - target_compile_definitions(test-adapter-hip PRIVATE __HIP_PLATFORM_NVIDIA__) -endif() - -set_tests_properties(adapter-hip PROPERTIES - LABELS "conformance:hip" - ENVIRONMENT "UR_ADAPTERS_FORCE_LOAD=\"$\"" -) From c55dc2af42b5c2dd03b0c54f90ab001d1b6b8285 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 6 Oct 2023 12:58:14 +0100 Subject: [PATCH 4/9] Resolved conflicts --- source/adapters/cuda/device.cpp | 8 ++------ source/adapters/cuda/device.hpp | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index 76984ca744..a4877236ae 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -501,12 +501,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, return ReturnValue( static_cast(hDevice->getMaxChosenLocalMem())); } else { - int LocalMemSize = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &LocalMemSize, CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK, - hDevice->get())); - detail::ur::assertion(LocalMemSize >= 0); - return ReturnValue(static_cast(LocalMemSize)); + return ReturnValue( + static_cast(hDevice->getMaxCapacityLocalMem())); } } case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT: { diff --git a/source/adapters/cuda/device.hpp b/source/adapters/cuda/device.hpp index 919f813e4e..5ad70672e9 100644 --- a/source/adapters/cuda/device.hpp +++ b/source/adapters/cuda/device.hpp @@ -45,6 +45,9 @@ struct ur_device_handle_t_ { UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxRegsPerBlock, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK, cuDevice)); + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxCapacityLocalMem, + CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN, cuDevice)); // Set local mem max size if env var is present static const char *LocalMemSizePtrUR = @@ -56,9 +59,6 @@ struct ur_device_handle_t_ { : (LocalMemSizePtrPI ? LocalMemSizePtrPI : nullptr); if (LocalMemSizePtr) { - cuDeviceGetAttribute( - &MaxCapacityLocalMem, - CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN, cuDevice); MaxChosenLocalMem = std::atoi(LocalMemSizePtr); MaxLocalMemSizeChosen = true; } From c86b8412f02a8787a9e1fc84c9a187864c6b9606 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 3 Nov 2023 11:20:31 +0000 Subject: [PATCH 5/9] Moved conflicted changes to setKernelParams --- source/adapters/cuda/enqueue.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/source/adapters/cuda/enqueue.cpp b/source/adapters/cuda/enqueue.cpp index 6e6515908e..117261ed11 100644 --- a/source/adapters/cuda/enqueue.cpp +++ b/source/adapters/cuda/enqueue.cpp @@ -284,12 +284,18 @@ setKernelParams(const ur_context_handle_t Context, CudaImplicitOffset); } - if (Context->getDevice()->maxLocalMemSizeChosen()) { + auto Device = Context->getDevice(); + if (LocalSize > static_cast(Device->getMaxCapacityLocalMem())) { + setErrorMessage("Too much local memory allocated for device", + UR_RESULT_ERROR_ADAPTER_SPECIFIC); + return UR_RESULT_ERROR_ADAPTER_SPECIFIC; + } + + if (Device->maxLocalMemSizeChosen()) { // Set up local memory requirements for kernel. - auto Device = Context->getDevice(); if (Device->getMaxChosenLocalMem() < 0) { bool EnvVarHasURPrefix = - std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr; + (std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr); setErrorMessage(EnvVarHasURPrefix ? "Invalid value specified for " "UR_CUDA_MAX_LOCAL_MEM_SIZE" : "Invalid value specified for " @@ -297,14 +303,9 @@ setKernelParams(const ur_context_handle_t Context, UR_RESULT_ERROR_ADAPTER_SPECIFIC); return UR_RESULT_ERROR_ADAPTER_SPECIFIC; } - if (LocalSize > static_cast(Device->getMaxCapacityLocalMem())) { - setErrorMessage("Too much local memory allocated for device", - UR_RESULT_ERROR_ADAPTER_SPECIFIC); - return UR_RESULT_ERROR_ADAPTER_SPECIFIC; - } if (LocalSize > static_cast(Device->getMaxChosenLocalMem())) { bool EnvVarHasURPrefix = - std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr; + (std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr); setErrorMessage( EnvVarHasURPrefix ? "Local memory for kernel exceeds the amount requested using " @@ -319,6 +320,10 @@ setKernelParams(const ur_context_handle_t Context, UR_CHECK_ERROR(cuFuncSetAttribute( CuFunc, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, Device->getMaxChosenLocalMem())); + + } else { + UR_CHECK_ERROR(cuFuncSetAttribute( + CuFunc, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, LocalSize)); } } catch (ur_result_t Err) { From 17cb185da3e344d515f79463b4e261d2cc09384c Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 3 Nov 2023 11:54:13 +0000 Subject: [PATCH 6/9] Removed unnecessary bracket change --- source/adapters/cuda/enqueue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/adapters/cuda/enqueue.cpp b/source/adapters/cuda/enqueue.cpp index 117261ed11..40361339bd 100644 --- a/source/adapters/cuda/enqueue.cpp +++ b/source/adapters/cuda/enqueue.cpp @@ -295,7 +295,7 @@ setKernelParams(const ur_context_handle_t Context, // Set up local memory requirements for kernel. if (Device->getMaxChosenLocalMem() < 0) { bool EnvVarHasURPrefix = - (std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr); + std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr; setErrorMessage(EnvVarHasURPrefix ? "Invalid value specified for " "UR_CUDA_MAX_LOCAL_MEM_SIZE" : "Invalid value specified for " @@ -305,7 +305,7 @@ setKernelParams(const ur_context_handle_t Context, } if (LocalSize > static_cast(Device->getMaxChosenLocalMem())) { bool EnvVarHasURPrefix = - (std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr); + std::getenv("UR_CUDA_MAX_LOCAL_MEM_SIZE") != nullptr; setErrorMessage( EnvVarHasURPrefix ? "Local memory for kernel exceeds the amount requested using " From d5a46915477f6d9eb9f0ac292fe6f94195850316 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 3 Nov 2023 12:19:44 +0000 Subject: [PATCH 7/9] Changed the error message --- source/adapters/cuda/enqueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adapters/cuda/enqueue.cpp b/source/adapters/cuda/enqueue.cpp index 40361339bd..5761f24e0a 100644 --- a/source/adapters/cuda/enqueue.cpp +++ b/source/adapters/cuda/enqueue.cpp @@ -286,7 +286,7 @@ setKernelParams(const ur_context_handle_t Context, auto Device = Context->getDevice(); if (LocalSize > static_cast(Device->getMaxCapacityLocalMem())) { - setErrorMessage("Too much local memory allocated for device", + setErrorMessage("Excessive allocation of local memory on the device", UR_RESULT_ERROR_ADAPTER_SPECIFIC); return UR_RESULT_ERROR_ADAPTER_SPECIFIC; } From bdcb6622c0ea3d129cac75dc1d9470438c2ffa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stolarczuk?= Date: Fri, 3 Nov 2023 19:35:24 +0100 Subject: [PATCH 8/9] Fail codegen example configuration if no dependcies We rather want to fail CMake configuration than silently move on, to find out about missing example, after the build. Codegen example is only build "on demand", when UR_BUILD_EXAMPLE_CODEGEN is set. --- examples/codegen/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/codegen/CMakeLists.txt b/examples/codegen/CMakeLists.txt index ddaabcc34f..4896d3a721 100644 --- a/examples/codegen/CMakeLists.txt +++ b/examples/codegen/CMakeLists.txt @@ -43,5 +43,5 @@ if(LLVM_FOUND AND PkgConfig_FOUND AND LLVMSPIRVLib_FOUND) ) endif() else() - message(STATUS "The environment did not satisfy dependency requirements (LLVM, PkgConfig, LLVMSPIRVLib) for codegen example (skipping target).") + message(FATAL_ERROR "The environment did not satisfy dependency requirements (LLVM, PkgConfig, LLVMSPIRVLib) for codegen example (skipping target).") endif() From ff7a4d8ceba41d37cd787df5ac99de57bc4b69ef Mon Sep 17 00:00:00 2001 From: pbalcer Date: Fri, 3 Nov 2023 11:29:55 +0100 Subject: [PATCH 9/9] automatically generate linker version script for adapter libraries --- scripts/generate_code.py | 21 +++++++++++++++++++++ scripts/templates/adapter.def.in.mako | 11 +++++++++++ scripts/templates/adapter.map.in.mako | 14 ++++++++++++++ source/adapters/adapter.def.in | 6 +++--- source/adapters/adapter.map.in | 6 +++--- 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 scripts/templates/adapter.def.in.mako create mode 100644 scripts/templates/adapter.map.in.mako diff --git a/scripts/generate_code.py b/scripts/generate_code.py index a6436f2a0a..9c427c3780 100644 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -315,6 +315,25 @@ def _mako_info_hpp(path, namespace, tags, version, specs, meta): specs=specs, meta=meta) +""" +Entry-point: + generates linker version scripts +""" +def _mako_linker_scripts(path, ext, namespace, tags, version, specs, meta): + name = "adapter" + filename = f"{name}.{ext}.in" + fin = os.path.join(templates_dir, f"{filename}.mako") + fout = os.path.join(path, filename) + print("Generating %s..." % fout) + return util.makoWrite( + fin, fout, + name=name, + ver=version, + namespace=namespace, + tags=tags, + specs=specs, + meta=meta) + """ Entry-point: generates lib code @@ -349,6 +368,8 @@ def generate_adapters(path, section, namespace, tags, version, specs, meta): loc = 0 loc += _mako_null_adapter_cpp(dstpath, namespace, tags, version, specs, meta) + loc += _mako_linker_scripts(dstpath, "map", namespace, tags, version, specs, meta) + loc += _mako_linker_scripts(dstpath, "def", namespace, tags, version, specs, meta) print("Generated %s lines of code.\n"%loc) """ diff --git a/scripts/templates/adapter.def.in.mako b/scripts/templates/adapter.def.in.mako new file mode 100644 index 0000000000..7304682440 --- /dev/null +++ b/scripts/templates/adapter.def.in.mako @@ -0,0 +1,11 @@ +<%! +import re +from templates import helper as th +%><% + n=namespace +%>\ +LIBRARY @TARGET_LIBNAME@ +EXPORTS +%for tbl in th.get_pfntables(specs, meta, n, tags): + ${tbl['export']['name']} +%endfor diff --git a/scripts/templates/adapter.map.in.mako b/scripts/templates/adapter.map.in.mako new file mode 100644 index 0000000000..d03871f867 --- /dev/null +++ b/scripts/templates/adapter.map.in.mako @@ -0,0 +1,14 @@ +<%! +import re +from templates import helper as th +%><% + n=namespace +%>\ +@TARGET_LIBNAME@ { + global: +%for tbl in th.get_pfntables(specs, meta, n, tags): + ${tbl['export']['name']}; +%endfor + local: + *; +}; diff --git a/source/adapters/adapter.def.in b/source/adapters/adapter.def.in index bfe14a6a03..de0b4fa8ee 100644 --- a/source/adapters/adapter.def.in +++ b/source/adapters/adapter.def.in @@ -1,12 +1,11 @@ LIBRARY @TARGET_LIBNAME@ EXPORTS + urGetGlobalProcAddrTable urGetBindlessImagesExpProcAddrTable urGetCommandBufferExpProcAddrTable urGetContextProcAddrTable - urGetDeviceProcAddrTable urGetEnqueueProcAddrTable urGetEventProcAddrTable - urGetGlobalProcAddrTable urGetKernelProcAddrTable urGetMemProcAddrTable urGetPhysicalMemProcAddrTable @@ -14,7 +13,8 @@ EXPORTS urGetProgramProcAddrTable urGetQueueProcAddrTable urGetSamplerProcAddrTable + urGetUSMProcAddrTable urGetUSMExpProcAddrTable urGetUsmP2PExpProcAddrTable - urGetUSMProcAddrTable urGetVirtualMemProcAddrTable + urGetDeviceProcAddrTable diff --git a/source/adapters/adapter.map.in b/source/adapters/adapter.map.in index cbb5c6c4cb..4379e1f7de 100644 --- a/source/adapters/adapter.map.in +++ b/source/adapters/adapter.map.in @@ -1,12 +1,11 @@ @TARGET_LIBNAME@ { global: + urGetGlobalProcAddrTable; urGetBindlessImagesExpProcAddrTable; urGetCommandBufferExpProcAddrTable; urGetContextProcAddrTable; - urGetDeviceProcAddrTable; urGetEnqueueProcAddrTable; urGetEventProcAddrTable; - urGetGlobalProcAddrTable; urGetKernelProcAddrTable; urGetMemProcAddrTable; urGetPhysicalMemProcAddrTable; @@ -14,10 +13,11 @@ urGetProgramProcAddrTable; urGetQueueProcAddrTable; urGetSamplerProcAddrTable; + urGetUSMProcAddrTable; urGetUSMExpProcAddrTable; urGetUsmP2PExpProcAddrTable; - urGetUSMProcAddrTable; urGetVirtualMemProcAddrTable; + urGetDeviceProcAddrTable; local: *; };