Skip to content

Commit 02cbe1a

Browse files
committed
[L0 v2] Make L0 v2 implementation a seperate adapter
Initially, L0 v2 adapter was supposed to reside in a separate namespace but be a part of legacy L0 adapter (with runtime option to switch between executing on legacy or v2). However, this turns out to require a lot of changes in the legacy code to allow for function dispatching to legacy/v2 implementations of queue, event, etc. This approach allows us to keep the implementations separate while still resuing files when appropriate (e.g. for adapter.cpp or platform.cpp).
1 parent c5d2175 commit 02cbe1a

File tree

44 files changed

+2012
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2012
-140
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ option(UR_BUILD_ADAPTER_CUDA "Build the CUDA adapter" OFF)
5151
option(UR_BUILD_ADAPTER_HIP "Build the HIP adapter" OFF)
5252
option(UR_BUILD_ADAPTER_NATIVE_CPU "Build the Native-CPU adapter" OFF)
5353
option(UR_BUILD_ADAPTER_ALL "Build all currently supported adapters" OFF)
54+
option(UR_BUILD_ADAPTER_L0_V2 "Build the (experimental) Level-Zero v2 adapter" OFF)
5455
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
5556
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
5657
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)

source/adapters/level_zero/CMakeLists.txt

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ add_ur_adapter(${TARGET_NAME}
113113
${CMAKE_CURRENT_SOURCE_DIR}/queue_api.hpp
114114
${CMAKE_CURRENT_SOURCE_DIR}/queue.hpp
115115
${CMAKE_CURRENT_SOURCE_DIR}/sampler.hpp
116-
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
117-
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_factory.hpp
118-
${CMAKE_CURRENT_SOURCE_DIR}/v2/context.hpp
119-
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp
120116
${CMAKE_CURRENT_SOURCE_DIR}/ur_level_zero.cpp
121117
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
122118
${CMAKE_CURRENT_SOURCE_DIR}/context.cpp
@@ -136,9 +132,6 @@ add_ur_adapter(${TARGET_NAME}
136132
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
137133
${CMAKE_CURRENT_SOURCE_DIR}/image.cpp
138134
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
139-
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.cpp
140-
${CMAKE_CURRENT_SOURCE_DIR}/v2/context.cpp
141-
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.cpp
142135
)
143136

144137
if(NOT WIN32)
@@ -175,3 +168,80 @@ target_include_directories(${TARGET_NAME} PRIVATE
175168
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
176169
LevelZeroLoader-Headers
177170
)
171+
172+
if(UR_BUILD_ADAPTER_L0_V2)
173+
add_ur_adapter(ur_adapter_level_zero_v2
174+
SHARED
175+
# sources shared with legacy adapter
176+
${CMAKE_CURRENT_SOURCE_DIR}/adapter.hpp
177+
${CMAKE_CURRENT_SOURCE_DIR}/common.hpp
178+
${CMAKE_CURRENT_SOURCE_DIR}/device.hpp
179+
${CMAKE_CURRENT_SOURCE_DIR}/platform.hpp
180+
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp
181+
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
182+
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp
183+
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp
184+
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
185+
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
186+
# v2-only sources
187+
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp
188+
${CMAKE_CURRENT_SOURCE_DIR}/v2/context.hpp
189+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool_cache.hpp
190+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool.hpp
191+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_counter.hpp
192+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_normal.hpp
193+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider.hpp
194+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event.hpp
195+
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.hpp
196+
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
197+
${CMAKE_CURRENT_SOURCE_DIR}/v2/api.cpp
198+
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.cpp
199+
${CMAKE_CURRENT_SOURCE_DIR}/v2/context.cpp
200+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool_cache.cpp
201+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool.cpp
202+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_counter.cpp
203+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_normal.cpp
204+
${CMAKE_CURRENT_SOURCE_DIR}/v2/event.cpp
205+
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.cpp
206+
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.cpp
207+
)
208+
209+
# api.cpp contains NOT_SUPPORTED functions-only
210+
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/v2/api.cpp
211+
PROPERTIES APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-unused-parameter")
212+
213+
if(NOT WIN32)
214+
target_sources(ur_adapter_level_zero_v2
215+
PRIVATE
216+
${CMAKE_CURRENT_SOURCE_DIR}/adapter_lib_init_linux.cpp
217+
)
218+
endif()
219+
220+
# TODO: fix level_zero adapter conversion warnings
221+
target_compile_options(ur_adapter_level_zero_v2 PRIVATE
222+
$<$<CXX_COMPILER_ID:MSVC>:/wd4805 /wd4244>
223+
)
224+
225+
set_target_properties(ur_adapter_level_zero_v2 PROPERTIES
226+
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
227+
SOVERSION "${PROJECT_VERSION_MAJOR}"
228+
)
229+
230+
if (WIN32)
231+
# 0x800: Search for the DLL only in the System32 folder
232+
target_link_options(ur_adapter_level_zero_v2 PUBLIC /DEPENDENTLOADFLAG:0x800)
233+
endif()
234+
235+
target_link_libraries(ur_adapter_level_zero_v2 PRIVATE
236+
${PROJECT_NAME}::headers
237+
${PROJECT_NAME}::common
238+
${PROJECT_NAME}::umf
239+
LevelZeroLoader
240+
LevelZeroLoader-Headers
241+
)
242+
243+
target_include_directories(ur_adapter_level_zero_v2 PRIVATE
244+
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
245+
LevelZeroLoader-Headers
246+
)
247+
endif()

source/adapters/level_zero/context.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "queue.hpp"
1919
#include "ur_level_zero.hpp"
2020

21-
#include "v2/context.hpp"
22-
2321
UR_APIEXPORT ur_result_t UR_APICALL urContextCreate(
2422
uint32_t DeviceCount, ///< [in] the number of devices given in phDevices
2523
const ur_device_handle_t
@@ -38,7 +36,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate(
3836
ZE2UR_CALL(zeContextCreate, (Platform->ZeDriver, &ContextDesc, &ZeContext));
3937
try {
4038
ur_context_handle_t_ *Context =
41-
new v2::ur_context_handle_t_(ZeContext, DeviceCount, Devices, true);
39+
new ur_context_handle_t_(ZeContext, DeviceCount, Devices, true);
4240

4341
Context->initialize();
4442
*RetContext = reinterpret_cast<ur_context_handle_t>(Context);

source/adapters/level_zero/queue.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "ur_util.hpp"
2525
#include "ze_api.h"
2626

27-
#include "v2/queue_factory.hpp"
28-
2927
// Hard limit for the event completion batches.
3028
static const uint64_t CompletionBatchesMax = [] {
3129
// Default value chosen empirically to maximize the number of asynchronous
@@ -501,12 +499,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
501499

502500
UR_ASSERT(Context->isValidDevice(Device), UR_RESULT_ERROR_INVALID_DEVICE);
503501

504-
// optimized path for immediate, in-order command lists
505-
if (v2::shouldUseQueueV2(Device, Flags)) {
506-
*Queue = v2::createQueue(Context, Device, Props);
507-
return UR_RESULT_SUCCESS;
508-
}
509-
510502
// Create placeholder queues in the compute queue group.
511503
// Actual L0 queues will be created at first use.
512504
std::vector<ze_command_queue_handle_t> ZeComputeCommandQueues(

0 commit comments

Comments
 (0)