Skip to content

Commit c718012

Browse files
committed
[L0 v2] implement support for sampler
1 parent dd1a3e1 commit c718012

File tree

4 files changed

+43
-71
lines changed

4 files changed

+43
-71
lines changed

source/adapters/level_zero/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ if(UR_BUILD_ADAPTER_L0_V2)
142142
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
143143
${CMAKE_CURRENT_SOURCE_DIR}/virtual_mem.cpp
144144
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
145+
${CMAKE_CURRENT_SOURCE_DIR}/sampler.hpp
146+
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
145147
# v2-only sources
146148
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_buffer.hpp
147149
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp

source/adapters/level_zero/sampler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
#include "sampler.hpp"
1212
#include "logger/ur_logger.hpp"
13-
#include "ur_level_zero.hpp"
13+
14+
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
15+
#include "v2/context.hpp"
16+
#else
17+
#include "context.hpp"
18+
#endif
1419

1520
namespace ur::level_zero {
1621

@@ -31,7 +36,7 @@ ur_result_t urSamplerCreate(
3136
// TODO: figure out if we instead need explicit copying for acessing
3237
// the sampler from other devices in the context.
3338
//
34-
ur_device_handle_t Device = Context->Devices[0];
39+
ur_device_handle_t Device = Context->getDevices()[0];
3540

3641
ze_sampler_handle_t ZeSampler;
3742
ZeStruct<ze_sampler_desc_t> ZeSamplerDesc;
@@ -95,7 +100,7 @@ ur_result_t urSamplerCreate(
95100
}
96101
}
97102

98-
ZE2UR_CALL(zeSamplerCreate, (Context->ZeContext, Device->ZeDevice,
103+
ZE2UR_CALL(zeSamplerCreate, (Context->getZeHandle(), Device->ZeDevice,
99104
&ZeSamplerDesc, // TODO: translate properties
100105
&ZeSampler));
101106

source/adapters/level_zero/v2/api.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,52 +50,6 @@ ur_result_t urMemImageGetInfo(ur_mem_handle_t hMemory, ur_image_info_t propName,
5050
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
5151
}
5252

53-
ur_result_t urSamplerCreate(ur_context_handle_t hContext,
54-
const ur_sampler_desc_t *pDesc,
55-
ur_sampler_handle_t *phSampler) {
56-
logger::error("{} function not implemented!", __FUNCTION__);
57-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
58-
}
59-
60-
ur_result_t urSamplerRetain(ur_sampler_handle_t hSampler) {
61-
logger::error("{} function not implemented!", __FUNCTION__);
62-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
63-
}
64-
65-
ur_result_t urSamplerRelease(ur_sampler_handle_t hSampler) {
66-
logger::error("{} function not implemented!", __FUNCTION__);
67-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
68-
}
69-
70-
ur_result_t urSamplerGetInfo(ur_sampler_handle_t hSampler,
71-
ur_sampler_info_t propName, size_t propSize,
72-
void *pPropValue, size_t *pPropSizeRet) {
73-
logger::error("{} function not implemented!", __FUNCTION__);
74-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
75-
}
76-
77-
ur_result_t urSamplerGetNativeHandle(ur_sampler_handle_t hSampler,
78-
ur_native_handle_t *phNativeSampler) {
79-
logger::error("{} function not implemented!", __FUNCTION__);
80-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
81-
}
82-
83-
ur_result_t urSamplerCreateWithNativeHandle(
84-
ur_native_handle_t hNativeSampler, ur_context_handle_t hContext,
85-
const ur_sampler_native_properties_t *pProperties,
86-
ur_sampler_handle_t *phSampler) {
87-
logger::error("{} function not implemented!", __FUNCTION__);
88-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
89-
}
90-
91-
ur_result_t
92-
urKernelSetArgSampler(ur_kernel_handle_t hKernel, uint32_t argIndex,
93-
const ur_kernel_arg_sampler_properties_t *pProperties,
94-
ur_sampler_handle_t hArgValue) {
95-
logger::error("{} function not implemented!", __FUNCTION__);
96-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
97-
}
98-
9953
ur_result_t urKernelSetSpecializationConstants(
10054
ur_kernel_handle_t hKernel, uint32_t count,
10155
const ur_specialization_constant_info_t *pSpecConstants) {

source/adapters/level_zero/v2/kernel.cpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "../helpers/kernel_helpers.hpp"
2121
#include "../platform.hpp"
2222
#include "../program.hpp"
23+
#include "../sampler.hpp"
2324
#include "../ur_interface_loader.hpp"
2425

2526
ur_single_device_kernel_t::ur_single_device_kernel_t(ur_device_handle_t hDevice,
@@ -378,17 +379,15 @@ ur_result_t urKernelRelease(
378379
}
379380

380381
ur_result_t urKernelSetArgValue(
381-
/// [in] handle of the kernel object
382-
ur_kernel_handle_t hKernel,
383-
/// [in] argument index in range [0, num args - 1]
384-
uint32_t argIndex,
385-
/// [in] size of argument type
386-
size_t argSize,
387-
/// [in][optional] argument properties
388-
const ur_kernel_arg_value_properties_t *pProperties,
389-
/// [in] argument value represented as matching arg type.
390-
const void *pArgValue) try {
391-
TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgValue");
382+
ur_kernel_handle_t hKernel, ///< [in] handle of the kernel object
383+
uint32_t argIndex, ///< [in] argument index in range [0, num args - 1]
384+
size_t argSize, ///< [in] size of argument type
385+
const ur_kernel_arg_value_properties_t
386+
*pProperties, ///< [in][optional] argument properties
387+
const void
388+
*pArgValue ///< [in] argument value represented as matching arg type.
389+
) try {
390+
TRACK_SCOPE_LATENCY("urKernelSetArgValue");
392391

393392
std::scoped_lock<ur_shared_mutex> guard(hKernel->Mutex);
394393
return hKernel->setArgValue(argIndex, argSize, pProperties, pArgValue);
@@ -397,15 +396,14 @@ ur_result_t urKernelSetArgValue(
397396
}
398397

399398
ur_result_t urKernelSetArgPointer(
400-
/// [in] handle of the kernel object
401-
ur_kernel_handle_t hKernel,
402-
/// [in] argument index in range [0, num args - 1]
403-
uint32_t argIndex,
404-
/// [in][optional] argument properties
405-
const ur_kernel_arg_pointer_properties_t *pProperties,
406-
/// [in] argument value represented as matching arg type.
407-
const void *pArgValue) try {
408-
TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgPointer");
399+
ur_kernel_handle_t hKernel, ///< [in] handle of the kernel object
400+
uint32_t argIndex, ///< [in] argument index in range [0, num args - 1]
401+
const ur_kernel_arg_pointer_properties_t
402+
*pProperties, ///< [in][optional] argument properties
403+
const void
404+
*pArgValue ///< [in] argument value represented as matching arg type.
405+
) try {
406+
TRACK_SCOPE_LATENCY("urKernelSetArgPointer");
409407

410408
std::scoped_lock<ur_shared_mutex> guard(hKernel->Mutex);
411409
return hKernel->setArgPointer(argIndex, pProperties, pArgValue);
@@ -434,7 +432,7 @@ ur_result_t
434432
urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
435433
const ur_kernel_arg_mem_obj_properties_t *pProperties,
436434
ur_mem_handle_t hArgValue) try {
437-
TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgMemObj");
435+
TRACK_SCOPE_LATENCY("urKernelSetArgMemObj");
438436

439437
std::scoped_lock<ur_shared_mutex> guard(hKernel->Mutex);
440438

@@ -450,7 +448,7 @@ ur_result_t
450448
urKernelSetArgLocal(ur_kernel_handle_t hKernel, uint32_t argIndex,
451449
size_t argSize,
452450
const ur_kernel_arg_local_properties_t *pProperties) try {
453-
TRACK_SCOPE_LATENCY("ur_kernel_handle_t_::setArgLocal");
451+
TRACK_SCOPE_LATENCY("urKernelSetArgLocal");
454452

455453
std::scoped_lock<ur_shared_mutex> guard(hKernel->Mutex);
456454

@@ -697,4 +695,17 @@ ur_result_t urKernelSuggestMaxCooperativeGroupCountExp(
697695
*pGroupCountRet = totalGroupCount;
698696
return UR_RESULT_SUCCESS;
699697
}
698+
699+
ur_result_t
700+
urKernelSetArgSampler(ur_kernel_handle_t hKernel, uint32_t argIndex,
701+
const ur_kernel_arg_sampler_properties_t *pProperties,
702+
ur_sampler_handle_t hArgValue) try {
703+
TRACK_SCOPE_LATENCY("urKernelSetArgSampler");
704+
std::scoped_lock<ur_shared_mutex> guard(hKernel->Mutex);
705+
std::ignore = pProperties;
706+
return hKernel->setArgValue(argIndex, sizeof(void *), nullptr,
707+
&hArgValue->ZeSampler);
708+
} catch (...) {
709+
return exceptionToResult(std::current_exception());
710+
}
700711
} // namespace ur::level_zero

0 commit comments

Comments
 (0)