From a58306d92a826c13bd5992850af47468b5fae6b1 Mon Sep 17 00:00:00 2001 From: Igor Chorazewicz Date: Fri, 3 Jan 2025 19:50:33 +0000 Subject: [PATCH] [L0 v2] implement support for sampler --- source/adapters/level_zero/CMakeLists.txt | 2 + source/adapters/level_zero/sampler.cpp | 11 +++-- source/adapters/level_zero/v2/api.cpp | 46 ------------------- source/adapters/level_zero/v2/kernel.cpp | 55 ++++++++++++++--------- 4 files changed, 43 insertions(+), 71 deletions(-) diff --git a/source/adapters/level_zero/CMakeLists.txt b/source/adapters/level_zero/CMakeLists.txt index 5bb5cf67fb..c4a05f6a1b 100644 --- a/source/adapters/level_zero/CMakeLists.txt +++ b/source/adapters/level_zero/CMakeLists.txt @@ -142,6 +142,8 @@ if(UR_BUILD_ADAPTER_L0_V2) ${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp ${CMAKE_CURRENT_SOURCE_DIR}/virtual_mem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sampler.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp # v2-only sources ${CMAKE_CURRENT_SOURCE_DIR}/v2/command_buffer.hpp ${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp diff --git a/source/adapters/level_zero/sampler.cpp b/source/adapters/level_zero/sampler.cpp index 8fdc23390e..f239dfed5c 100644 --- a/source/adapters/level_zero/sampler.cpp +++ b/source/adapters/level_zero/sampler.cpp @@ -10,7 +10,12 @@ #include "sampler.hpp" #include "logger/ur_logger.hpp" -#include "ur_level_zero.hpp" + +#ifdef UR_ADAPTER_LEVEL_ZERO_V2 +#include "v2/context.hpp" +#else +#include "context.hpp" +#endif namespace ur::level_zero { @@ -31,7 +36,7 @@ ur_result_t urSamplerCreate( // TODO: figure out if we instead need explicit copying for acessing // the sampler from other devices in the context. // - ur_device_handle_t Device = Context->Devices[0]; + ur_device_handle_t Device = Context->getDevices()[0]; ze_sampler_handle_t ZeSampler; ZeStruct ZeSamplerDesc; @@ -95,7 +100,7 @@ ur_result_t urSamplerCreate( } } - ZE2UR_CALL(zeSamplerCreate, (Context->ZeContext, Device->ZeDevice, + ZE2UR_CALL(zeSamplerCreate, (Context->getZeHandle(), Device->ZeDevice, &ZeSamplerDesc, // TODO: translate properties &ZeSampler)); diff --git a/source/adapters/level_zero/v2/api.cpp b/source/adapters/level_zero/v2/api.cpp index 88fde2cfac..c7bd97c32c 100644 --- a/source/adapters/level_zero/v2/api.cpp +++ b/source/adapters/level_zero/v2/api.cpp @@ -50,52 +50,6 @@ ur_result_t urMemImageGetInfo(ur_mem_handle_t hMemory, ur_image_info_t propName, return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } -ur_result_t urSamplerCreate(ur_context_handle_t hContext, - const ur_sampler_desc_t *pDesc, - ur_sampler_handle_t *phSampler) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ur_result_t urSamplerRetain(ur_sampler_handle_t hSampler) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ur_result_t urSamplerRelease(ur_sampler_handle_t hSampler) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ur_result_t urSamplerGetInfo(ur_sampler_handle_t hSampler, - ur_sampler_info_t propName, size_t propSize, - void *pPropValue, size_t *pPropSizeRet) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ur_result_t urSamplerGetNativeHandle(ur_sampler_handle_t hSampler, - ur_native_handle_t *phNativeSampler) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ur_result_t urSamplerCreateWithNativeHandle( - ur_native_handle_t hNativeSampler, ur_context_handle_t hContext, - const ur_sampler_native_properties_t *pProperties, - ur_sampler_handle_t *phSampler) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ur_result_t -urKernelSetArgSampler(ur_kernel_handle_t hKernel, uint32_t argIndex, - const ur_kernel_arg_sampler_properties_t *pProperties, - ur_sampler_handle_t hArgValue) { - logger::error("{} function not implemented!", __FUNCTION__); - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - ur_result_t urKernelSetSpecializationConstants( ur_kernel_handle_t hKernel, uint32_t count, const ur_specialization_constant_info_t *pSpecConstants) { diff --git a/source/adapters/level_zero/v2/kernel.cpp b/source/adapters/level_zero/v2/kernel.cpp index 5b415902d3..6261d2927b 100644 --- a/source/adapters/level_zero/v2/kernel.cpp +++ b/source/adapters/level_zero/v2/kernel.cpp @@ -20,6 +20,7 @@ #include "../helpers/kernel_helpers.hpp" #include "../platform.hpp" #include "../program.hpp" +#include "../sampler.hpp" #include "../ur_interface_loader.hpp" ur_single_device_kernel_t::ur_single_device_kernel_t(ur_device_handle_t hDevice, @@ -378,17 +379,15 @@ ur_result_t urKernelRelease( } ur_result_t urKernelSetArgValue( - /// [in] handle of the kernel object - ur_kernel_handle_t hKernel, - /// [in] argument index in range [0, num args - 1] - uint32_t argIndex, - /// [in] size of argument type - size_t argSize, - /// [in][optional] argument properties - const ur_kernel_arg_value_properties_t *pProperties, - /// [in] argument value represented as matching arg type. - const void *pArgValue) try { - TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgValue"); + ur_kernel_handle_t hKernel, ///< [in] handle of the kernel object + uint32_t argIndex, ///< [in] argument index in range [0, num args - 1] + size_t argSize, ///< [in] size of argument type + const ur_kernel_arg_value_properties_t + *pProperties, ///< [in][optional] argument properties + const void + *pArgValue ///< [in] argument value represented as matching arg type. + ) try { + TRACK_SCOPE_LATENCY("urKernelSetArgValue"); std::scoped_lock guard(hKernel->Mutex); return hKernel->setArgValue(argIndex, argSize, pProperties, pArgValue); @@ -397,15 +396,14 @@ ur_result_t urKernelSetArgValue( } ur_result_t urKernelSetArgPointer( - /// [in] handle of the kernel object - ur_kernel_handle_t hKernel, - /// [in] argument index in range [0, num args - 1] - uint32_t argIndex, - /// [in][optional] argument properties - const ur_kernel_arg_pointer_properties_t *pProperties, - /// [in] argument value represented as matching arg type. - const void *pArgValue) try { - TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgPointer"); + ur_kernel_handle_t hKernel, ///< [in] handle of the kernel object + uint32_t argIndex, ///< [in] argument index in range [0, num args - 1] + const ur_kernel_arg_pointer_properties_t + *pProperties, ///< [in][optional] argument properties + const void + *pArgValue ///< [in] argument value represented as matching arg type. + ) try { + TRACK_SCOPE_LATENCY("urKernelSetArgPointer"); std::scoped_lock guard(hKernel->Mutex); return hKernel->setArgPointer(argIndex, pProperties, pArgValue); @@ -434,7 +432,7 @@ ur_result_t urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex, const ur_kernel_arg_mem_obj_properties_t *pProperties, ur_mem_handle_t hArgValue) try { - TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgMemObj"); + TRACK_SCOPE_LATENCY("urKernelSetArgMemObj"); std::scoped_lock guard(hKernel->Mutex); @@ -450,7 +448,7 @@ ur_result_t urKernelSetArgLocal(ur_kernel_handle_t hKernel, uint32_t argIndex, size_t argSize, const ur_kernel_arg_local_properties_t *pProperties) try { - TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgLocal"); + TRACK_SCOPE_LATENCY("urKernelSetArgLocal"); std::scoped_lock guard(hKernel->Mutex); @@ -697,4 +695,17 @@ ur_result_t urKernelSuggestMaxCooperativeGroupCountExp( *pGroupCountRet = totalGroupCount; return UR_RESULT_SUCCESS; } + +ur_result_t +urKernelSetArgSampler(ur_kernel_handle_t hKernel, uint32_t argIndex, + const ur_kernel_arg_sampler_properties_t *pProperties, + ur_sampler_handle_t hArgValue) try { + TRACK_SCOPE_LATENCY("urKernelSetArgSampler"); + std::scoped_lock guard(hKernel->Mutex); + std::ignore = pProperties; + return hKernel->setArgValue(argIndex, sizeof(void *), nullptr, + &hArgValue->ZeSampler); +} catch (...) { + return exceptionToResult(std::current_exception()); +} } // namespace ur::level_zero