Skip to content

Commit

Permalink
[L0 v2] implement support for sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed Feb 5, 2025
1 parent 0e6adfb commit a58306d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 71 deletions.
2 changes: 2 additions & 0 deletions source/adapters/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions source/adapters/level_zero/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<ze_sampler_desc_t> ZeSamplerDesc;
Expand Down Expand Up @@ -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));

Expand Down
46 changes: 0 additions & 46 deletions source/adapters/level_zero/v2/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
55 changes: 33 additions & 22 deletions source/adapters/level_zero/v2/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ur_shared_mutex> guard(hKernel->Mutex);
return hKernel->setArgValue(argIndex, argSize, pProperties, pArgValue);
Expand All @@ -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<ur_shared_mutex> guard(hKernel->Mutex);
return hKernel->setArgPointer(argIndex, pProperties, pArgValue);
Expand Down Expand Up @@ -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<ur_shared_mutex> guard(hKernel->Mutex);

Expand All @@ -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<ur_shared_mutex> guard(hKernel->Mutex);

Expand Down Expand Up @@ -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<ur_shared_mutex> 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

0 comments on commit a58306d

Please sign in to comment.