Skip to content

Commit 0a6e827

Browse files
committed
[L0 v2] Implement v2 kernel
Key differences vs the original implementation: - std::unordered_map replaced with std::vector - L0 handles' lifetime managed by raii wrappers - subdevices do not have a separate entry in the map/vector, instead, lookup is always done using root device handle - removed indirect access support
1 parent f97c784 commit 0a6e827

File tree

14 files changed

+505
-342
lines changed

14 files changed

+505
-342
lines changed

source/adapters/level_zero/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,15 @@ if(UR_BUILD_ADAPTER_L0_V2)
179179
${CMAKE_CURRENT_SOURCE_DIR}/common.hpp
180180
${CMAKE_CURRENT_SOURCE_DIR}/device.hpp
181181
${CMAKE_CURRENT_SOURCE_DIR}/platform.hpp
182+
${CMAKE_CURRENT_SOURCE_DIR}/program.hpp
183+
${CMAKE_CURRENT_SOURCE_DIR}/helpers/kernel_helpers.hpp
182184
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp
183185
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
184186
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp
185187
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp
186188
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
189+
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
190+
${CMAKE_CURRENT_SOURCE_DIR}/helpers/kernel_helpers.cpp
187191
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
188192
# v2-only sources
189193
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp
@@ -194,6 +198,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
194198
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_normal.hpp
195199
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider.hpp
196200
${CMAKE_CURRENT_SOURCE_DIR}/v2/event.hpp
201+
${CMAKE_CURRENT_SOURCE_DIR}/v2/kernel.hpp
197202
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.hpp
198203
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
199204
${CMAKE_CURRENT_SOURCE_DIR}/v2/api.cpp
@@ -204,6 +209,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
204209
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_counter.cpp
205210
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_normal.cpp
206211
${CMAKE_CURRENT_SOURCE_DIR}/v2/event.cpp
212+
${CMAKE_CURRENT_SOURCE_DIR}/v2/kernel.cpp
207213
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.cpp
208214
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_create.cpp
209215
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.cpp
@@ -220,6 +226,8 @@ if(UR_BUILD_ADAPTER_L0_V2)
220226
)
221227
endif()
222228

229+
target_compile_definitions(ur_adapter_level_zero_v2 PUBLIC UR_ADAPTER_LEVEL_ZERO_V2)
230+
223231
# TODO: fix level_zero adapter conversion warnings
224232
target_compile_options(ur_adapter_level_zero_v2 PRIVATE
225233
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244>

source/adapters/level_zero/command_buffer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "common.hpp"
1818

1919
#include "context.hpp"
20+
#include "kernel.hpp"
2021
#include "queue.hpp"
2122

2223
struct command_buffer_profiling_t {

source/adapters/level_zero/context.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,12 @@ bool ur_context_handle_t_::isValidDevice(ur_device_handle_t Device) const {
829829
}
830830
return false;
831831
}
832+
833+
const std::vector<ur_device_handle_t> &
834+
ur_context_handle_t_::getDevices() const {
835+
return Devices;
836+
}
837+
838+
ze_context_handle_t ur_context_handle_t_::getZeHandle() const {
839+
return ZeContext;
840+
}

source/adapters/level_zero/context.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ struct ur_context_handle_t_ : _ur_object {
193193
// Return the Platform, which is the same for all devices in the context
194194
ur_platform_handle_t getPlatform() const;
195195

196+
// Get vector of devices from this context
197+
const std::vector<ur_device_handle_t> &getDevices() const;
198+
196199
// Get index of the free slot in the available pool. If there is no available
197200
// pool then create new one. The HostVisible parameter tells if we need a
198201
// slot for a host-visible event. The ProfilingEnabled tells is we need a
@@ -303,6 +306,9 @@ struct ur_context_handle_t_ : _ur_object {
303306
// For that the Device or its root devices need to be in the context.
304307
bool isValidDevice(ur_device_handle_t Device) const;
305308

309+
// Get handle to the L0 context
310+
ze_context_handle_t getZeHandle() const;
311+
306312
private:
307313
// Get the cache of events for a provided scope and profiling mode.
308314
auto getEventCache(bool HostVisible, bool WithProfiling,

source/adapters/level_zero/helpers/kernel_helpers.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
#include "logger/ur_logger.hpp"
1313

1414
#include "../common.hpp"
15-
#include "../context.hpp"
1615
#include "../device.hpp"
1716

17+
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
18+
#include "../context.hpp"
19+
#else
20+
#include "../v2/context.hpp"
21+
#endif
22+
1823
ur_result_t getSuggestedLocalWorkSize(ur_device_handle_t hDevice,
1924
ze_kernel_handle_t hZeKernel,
2025
size_t GlobalWorkSize3D[3],

source/adapters/level_zero/platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ ur_result_t ur_platform_handle_t_::populateDeviceCacheIfNeeded() {
503503
return UR_RESULT_SUCCESS;
504504
}
505505

506+
size_t ur_platform_handle_t_::getNumDevices() { return URDevicesCache.size(); }
507+
506508
ur_device_handle_t ur_platform_handle_t_::getDeviceById(DeviceId id) {
507509
for (auto &dev : URDevicesCache) {
508510
if (dev->Id == id) {

source/adapters/level_zero/platform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ struct ur_platform_handle_t_ : public _ur_platform {
5656
// Check the device cache and load it if necessary.
5757
ur_result_t populateDeviceCacheIfNeeded();
5858

59+
size_t getNumDevices();
60+
5961
ur_device_handle_t getDeviceById(DeviceId);
6062

6163
// Return the PI device from cache that represents given native device.

source/adapters/level_zero/program.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "program.hpp"
12+
#include "device.hpp"
1213
#include "logger/ur_logger.hpp"
13-
#include "ur_level_zero.hpp"
14+
15+
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
16+
#include "context.hpp"
17+
#else
18+
#include "v2/context.hpp"
19+
#endif
1420

1521
extern "C" {
1622
// Check to see if a Level Zero module has any unresolved symbols.
@@ -115,8 +121,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
115121
const char *Options ///< [in][optional] pointer to build options
116122
///< null-terminated string.
117123
) {
118-
return urProgramBuildExp(Program, Context->Devices.size(),
119-
Context->Devices.data(), Options);
124+
std::vector<ur_device_handle_t> Devices = Context->getDevices();
125+
return urProgramBuildExp(Program, Devices.size(), Devices.data(), Options);
120126
}
121127

122128
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
@@ -174,7 +180,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
174180

175181
for (uint32_t i = 0; i < numDevices; i++) {
176182
ze_device_handle_t ZeDevice = phDevices[i]->ZeDevice;
177-
ze_context_handle_t ZeContext = hProgram->Context->ZeContext;
183+
ze_context_handle_t ZeContext = hProgram->Context->getZeHandle();
178184
ze_module_handle_t ZeModuleHandle = nullptr;
179185
ze_module_build_log_handle_t ZeBuildLog{};
180186

@@ -266,7 +272,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile(
266272
// ze-opt-greater-than-4GB-buffer-required to disable
267273
// stateful optimizations and be able to use larger than
268274
// 4GB allocations on these kernels.
269-
if (Context->Devices[0]->useRelaxedAllocationLimits()) {
275+
if (Context->getDevices()[0]->useRelaxedAllocationLimits()) {
270276
Program->BuildFlags += " -ze-opt-greater-than-4GB-buffer-required";
271277
}
272278
}
@@ -285,9 +291,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(
285291
ur_program_handle_t
286292
*Program ///< [out] pointer to handle of program object created.
287293
) {
288-
return urProgramLinkExp(Context, Context->Devices.size(),
289-
Context->Devices.data(), Count, Programs, Options,
290-
Program);
294+
std::vector<ur_device_handle_t> Devices = Context->getDevices();
295+
return urProgramLinkExp(Context, Devices.size(), Devices.data(), Count,
296+
Programs, Options, Program);
291297
}
292298

293299
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
@@ -426,7 +432,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
426432

427433
// Call the Level Zero API to compile, link, and create the module.
428434
ze_device_handle_t ZeDevice = phDevices[i]->ZeDevice;
429-
ze_context_handle_t ZeContext = hContext->ZeContext;
435+
ze_context_handle_t ZeContext = hContext->getZeHandle();
430436
ze_module_handle_t ZeModule = nullptr;
431437
ze_module_build_log_handle_t ZeBuildLog = nullptr;
432438
ze_result_t ZeResult =
@@ -652,7 +658,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetInfo(
652658
for (auto &ZeModulePair : Program->ZeModuleMap) {
653659
auto It = Program->ZeModuleMap.find(ZeModulePair.first);
654660
if (It != Program->ZeModuleMap.end()) {
655-
for (auto &Device : Program->Context->Devices) {
661+
for (auto &Device : Program->Context->getDevices()) {
656662
if (Device->ZeDevice == ZeModulePair.first) {
657663
devices.push_back(Device);
658664
}
@@ -661,7 +667,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetInfo(
661667
}
662668
return ReturnValue(devices.data(), devices.size());
663669
} else {
664-
return ReturnValue(Program->Context->Devices[0]);
670+
return ReturnValue(Program->Context->getDevices()[0]);
665671
}
666672
case UR_PROGRAM_INFO_BINARY_SIZES: {
667673
std::shared_lock<ur_shared_mutex> Guard(Program->Mutex);

source/adapters/level_zero/v2/api.cpp

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -294,124 +294,6 @@ urPhysicalMemRelease(ur_physical_mem_handle_t hPhysicalMem) {
294294
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
295295
}
296296

297-
ur_result_t UR_APICALL
298-
urProgramCreateWithIL(ur_context_handle_t hContext, const void *pIL,
299-
size_t length, const ur_program_properties_t *pProperties,
300-
ur_program_handle_t *phProgram) {
301-
logger::error("{} function not implemented!", __FUNCTION__);
302-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
303-
}
304-
305-
ur_result_t UR_APICALL urProgramCreateWithBinary(
306-
ur_context_handle_t hContext, ur_device_handle_t hDevice, size_t size,
307-
const uint8_t *pBinary, const ur_program_properties_t *pProperties,
308-
ur_program_handle_t *phProgram) {
309-
logger::error("{} function not implemented!", __FUNCTION__);
310-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
311-
}
312-
313-
ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t hContext,
314-
ur_program_handle_t hProgram,
315-
const char *pOptions) {
316-
logger::error("{} function not implemented!", __FUNCTION__);
317-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
318-
}
319-
320-
ur_result_t UR_APICALL urProgramCompile(ur_context_handle_t hContext,
321-
ur_program_handle_t hProgram,
322-
const char *pOptions) {
323-
logger::error("{} function not implemented!", __FUNCTION__);
324-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
325-
}
326-
327-
ur_result_t UR_APICALL urProgramLink(ur_context_handle_t hContext,
328-
uint32_t count,
329-
const ur_program_handle_t *phPrograms,
330-
const char *pOptions,
331-
ur_program_handle_t *phProgram) {
332-
logger::error("{} function not implemented!", __FUNCTION__);
333-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
334-
}
335-
336-
ur_result_t UR_APICALL urProgramRetain(ur_program_handle_t hProgram) {
337-
logger::error("{} function not implemented!", __FUNCTION__);
338-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
339-
}
340-
341-
ur_result_t UR_APICALL urProgramRelease(ur_program_handle_t hProgram) {
342-
logger::error("{} function not implemented!", __FUNCTION__);
343-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
344-
}
345-
346-
ur_result_t UR_APICALL urProgramGetFunctionPointer(ur_device_handle_t hDevice,
347-
ur_program_handle_t hProgram,
348-
const char *pFunctionName,
349-
void **ppFunctionPointer) {
350-
logger::error("{} function not implemented!", __FUNCTION__);
351-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
352-
}
353-
354-
ur_result_t UR_APICALL urProgramGetGlobalVariablePointer(
355-
ur_device_handle_t hDevice, ur_program_handle_t hProgram,
356-
const char *pGlobalVariableName, size_t *pGlobalVariableSizeRet,
357-
void **ppGlobalVariablePointerRet) {
358-
logger::error("{} function not implemented!", __FUNCTION__);
359-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
360-
}
361-
362-
ur_result_t UR_APICALL urProgramGetInfo(ur_program_handle_t hProgram,
363-
ur_program_info_t propName,
364-
size_t propSize, void *pPropValue,
365-
size_t *pPropSizeRet) {
366-
logger::error("{} function not implemented!", __FUNCTION__);
367-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
368-
}
369-
370-
ur_result_t UR_APICALL urProgramGetBuildInfo(ur_program_handle_t hProgram,
371-
ur_device_handle_t hDevice,
372-
ur_program_build_info_t propName,
373-
size_t propSize, void *pPropValue,
374-
size_t *pPropSizeRet) {
375-
logger::error("{} function not implemented!", __FUNCTION__);
376-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
377-
}
378-
379-
ur_result_t UR_APICALL urProgramSetSpecializationConstants(
380-
ur_program_handle_t hProgram, uint32_t count,
381-
const ur_specialization_constant_info_t *pSpecConstants) {
382-
logger::error("{} function not implemented!", __FUNCTION__);
383-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
384-
}
385-
386-
ur_result_t UR_APICALL urProgramGetNativeHandle(
387-
ur_program_handle_t hProgram, ur_native_handle_t *phNativeProgram) {
388-
logger::error("{} function not implemented!", __FUNCTION__);
389-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
390-
}
391-
392-
ur_result_t UR_APICALL urProgramCreateWithNativeHandle(
393-
ur_native_handle_t hNativeProgram, ur_context_handle_t hContext,
394-
const ur_program_native_properties_t *pProperties,
395-
ur_program_handle_t *phProgram) {
396-
logger::error("{} function not implemented!", __FUNCTION__);
397-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
398-
}
399-
400-
ur_result_t UR_APICALL urKernelCreate(ur_program_handle_t hProgram,
401-
const char *pKernelName,
402-
ur_kernel_handle_t *phKernel) {
403-
logger::error("{} function not implemented!", __FUNCTION__);
404-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
405-
}
406-
407-
ur_result_t UR_APICALL urKernelSetArgValue(
408-
ur_kernel_handle_t hKernel, uint32_t argIndex, size_t argSize,
409-
const ur_kernel_arg_value_properties_t *pProperties,
410-
const void *pArgValue) {
411-
logger::error("{} function not implemented!", __FUNCTION__);
412-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
413-
}
414-
415297
ur_result_t UR_APICALL urKernelSetArgLocal(
416298
ur_kernel_handle_t hKernel, uint32_t argIndex, size_t argSize,
417299
const ur_kernel_arg_local_properties_t *pProperties) {
@@ -444,16 +326,6 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
444326
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
445327
}
446328

447-
ur_result_t UR_APICALL urKernelRetain(ur_kernel_handle_t hKernel) {
448-
logger::error("{} function not implemented!", __FUNCTION__);
449-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
450-
}
451-
452-
ur_result_t UR_APICALL urKernelRelease(ur_kernel_handle_t hKernel) {
453-
logger::error("{} function not implemented!", __FUNCTION__);
454-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
455-
}
456-
457329
ur_result_t UR_APICALL
458330
urKernelSetArgPointer(ur_kernel_handle_t hKernel, uint32_t argIndex,
459331
const ur_kernel_arg_pointer_properties_t *pProperties,
@@ -888,33 +760,6 @@ ur_result_t UR_APICALL urKernelSuggestMaxCooperativeGroupCountExp(
888760
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
889761
}
890762

891-
ur_result_t UR_APICALL urProgramBuildExp(ur_program_handle_t hProgram,
892-
uint32_t numDevices,
893-
ur_device_handle_t *phDevices,
894-
const char *pOptions) {
895-
logger::error("{} function not implemented!", __FUNCTION__);
896-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
897-
}
898-
899-
ur_result_t UR_APICALL urProgramCompileExp(ur_program_handle_t hProgram,
900-
uint32_t numDevices,
901-
ur_device_handle_t *phDevices,
902-
const char *pOptions) {
903-
logger::error("{} function not implemented!", __FUNCTION__);
904-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
905-
}
906-
907-
ur_result_t UR_APICALL urProgramLinkExp(ur_context_handle_t hContext,
908-
uint32_t numDevices,
909-
ur_device_handle_t *phDevices,
910-
uint32_t count,
911-
const ur_program_handle_t *phPrograms,
912-
const char *pOptions,
913-
ur_program_handle_t *phProgram) {
914-
logger::error("{} function not implemented!", __FUNCTION__);
915-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
916-
}
917-
918763
ur_result_t UR_APICALL urUSMImportExp(ur_context_handle_t hContext, void *pMem,
919764
size_t size) {
920765
logger::error("{} function not implemented!", __FUNCTION__);

0 commit comments

Comments
 (0)