Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devops/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"root": "{DEPS_ROOT}/opencl/runtime/linux/oclcpu"
}
}
}
}
13 changes: 12 additions & 1 deletion unified-runtime/cmake/FetchLevelZero.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ if(NOT LEVEL_ZERO_LIB_NAME AND NOT LEVEL_ZERO_LIBRARY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat-extra-semi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
endif()
set(BUILD_STATIC ON)

set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
# Remember to update the pkg_check_modules minimum version above when updating the
Expand All @@ -60,6 +59,11 @@ if(NOT LEVEL_ZERO_LIB_NAME AND NOT LEVEL_ZERO_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY_BAK "${CMAKE_MSVC_RUNTIME_LIBRARY}")
# UMF has not yet been able to build as static
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")

# Force building validation layer by setting BUILD_STATIC to OFF
# This must be set before FetchContent to override Level Zero's default
set(BUILD_STATIC OFF CACHE BOOL "Build Level Zero as dynamic library to enable validation layer" FORCE)

message(STATUS "Level Zero Adapter: Will fetch Level Zero Loader from ${UR_LEVEL_ZERO_LOADER_REPO}")
include(FetchContent)
FetchContent_Declare(level-zero-loader
Expand All @@ -72,6 +76,13 @@ if(NOT LEVEL_ZERO_LIB_NAME AND NOT LEVEL_ZERO_LIBRARY)
FetchContent_MakeAvailable(level-zero-loader)
FetchContent_GetProperties(level-zero-loader)

# Ensure validation layer is built as part of the default target
# This is needed for leak debugging with UR_L0_LEAKS_DEBUG=1
if(TARGET ze_validation_layer)
add_dependencies(ze_loader ze_validation_layer)
message(STATUS "Level Zero validation layer will be built with loader")
endif()

# Restore original flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}")
set(CMAKE_MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY_BAK}")
Expand Down
11 changes: 7 additions & 4 deletions unified-runtime/source/adapters/level_zero/v2/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
phDevices[0]->Platform->ZeMutableCmdListExt.Supported}),
eventPoolCacheImmediate(
this, phDevices[0]->Platform->getNumDevices(),
[context = this](DeviceId /* deviceId*/, v2::event_flags_t flags)
-> std::unique_ptr<v2::event_provider> {
[context = this, platform = phDevices[0]->Platform](
DeviceId deviceId,
v2::event_flags_t flags) -> std::unique_ptr<v2::event_provider> {
auto device = platform->getDeviceById(deviceId);

// TODO: just use per-context id?
return std::make_unique<v2::provider_normal>(
context, v2::QUEUE_IMMEDIATE, flags);
return std::make_unique<v2::provider_counter>(
platform, context, v2::QUEUE_IMMEDIATE, device, flags);
}),
eventPoolCacheRegular(this, phDevices[0]->Platform->getNumDevices(),
[context = this, platform = phDevices[0]->Platform](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ enum event_flag_t {
};
static constexpr size_t EVENT_FLAGS_USED_BITS = 2;

enum queue_type {
QUEUE_REGULAR,
QUEUE_IMMEDIATE,
};

class event_provider;

namespace raii {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ namespace v2 {

provider_counter::provider_counter(ur_platform_handle_t platform,
ur_context_handle_t context,
ur_device_handle_t device) {
queue_type queueType,
ur_device_handle_t device,
event_flags_t flags)
: queueType(queueType), flags(flags) {
assert(flags & EVENT_FLAGS_COUNTER);

ZE2UR_CALL_THROWS(zeDriverGetExtensionFunctionAddress,
(platform->ZeDriver, "zexCounterBasedEventCreate",
(platform->ZeDriver, "zexCounterBasedEventCreate2",
(void **)&this->eventCreateFunc));
ZE2UR_CALL_THROWS(zelLoaderTranslateHandle,
(ZEL_HANDLE_CONTEXT, context->getZeHandle(),
Expand All @@ -34,17 +39,35 @@ provider_counter::provider_counter(ur_platform_handle_t platform,
(ZEL_HANDLE_DEVICE, device->ZeDevice, (void **)&translatedDevice));
}

static zex_counter_based_event_exp_flags_t createZeFlags(queue_type queueType,
event_flags_t flags) {
zex_counter_based_event_exp_flags_t zeFlags =
ZEX_COUNTER_BASED_EVENT_FLAG_HOST_VISIBLE;
if (flags & EVENT_FLAGS_PROFILING_ENABLED) {
zeFlags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
}

if (queueType == QUEUE_IMMEDIATE) {
zeFlags |= ZEX_COUNTER_BASED_EVENT_FLAG_IMMEDIATE;
} else {
zeFlags |= ZEX_COUNTER_BASED_EVENT_FLAG_NON_IMMEDIATE;
}

return zeFlags;
}

raii::cache_borrowed_event provider_counter::allocate() {
if (freelist.empty()) {
ZeStruct<ze_event_desc_t> desc;
desc.index = 0;
desc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
desc.wait = 0;
zex_counter_based_event_desc_t desc = {};
desc.stype = ZEX_STRUCTURE_COUNTER_BASED_EVENT_DESC;
desc.flags = createZeFlags(queueType, flags);
desc.signalScope = ZE_EVENT_SCOPE_FLAG_HOST;

ze_event_handle_t handle;

// TODO: allocate host and device buffers to use here
ZE2UR_CALL_THROWS(eventCreateFunc, (translatedContext, translatedDevice,
nullptr, nullptr, 0, &desc, &handle));
ZE2UR_CALL_THROWS(eventCreateFunc,
(translatedContext, translatedDevice, &desc, &handle));

freelist.emplace_back(handle);
}
Expand All @@ -57,8 +80,6 @@ raii::cache_borrowed_event provider_counter::allocate() {
[this](ze_event_handle_t handle) { freelist.push_back(handle); });
}

event_flags_t provider_counter::eventFlags() const {
return EVENT_FLAGS_COUNTER;
}
event_flags_t provider_counter::eventFlags() const { return flags; }

} // namespace v2
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@

#include "../device.hpp"

#include <level_zero/driver_experimental/zex_event.h>
#include <level_zero/ze_intel_gpu.h>

namespace v2 {

typedef ze_result_t (*zexCounterBasedEventCreate)(
ze_context_handle_t hContext, ze_device_handle_t hDevice,
uint64_t *deviceAddress, uint64_t *hostAddress, uint64_t completionValue,
const ze_event_desc_t *desc, ze_event_handle_t *phEvent);
const zex_counter_based_event_desc_t *desc, ze_event_handle_t *phEvent);

class provider_counter : public event_provider {
public:
provider_counter(ur_platform_handle_t platform, ur_context_handle_t,
ur_device_handle_t);
queue_type, ur_device_handle_t, event_flags_t);

raii::cache_borrowed_event allocate() override;
event_flags_t eventFlags() const override;

private:
queue_type queueType;
event_flags_t flags;

ze_context_handle_t translatedContext;
ze_device_handle_t translatedDevice;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
#include "event_provider.hpp"
#include "event_provider_normal.hpp"

#include "../common/latency_tracker.hpp"

#include "../common.hpp"
#include "../common/latency_tracker.hpp"

namespace v2 {
static constexpr int EVENTS_BURST = 64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@

#include "common.hpp"
#include "event.hpp"
#include "event_provider.hpp"

#include "../device.hpp"
#include "../ur_interface_loader.hpp"

namespace v2 {

enum queue_type {
QUEUE_REGULAR,
QUEUE_IMMEDIATE,
};

class provider_pool {
public:
provider_pool(ur_context_handle_t, queue_type, event_flags_t flags);
Expand Down
Loading