Skip to content

[SYCL][UR][L0 v2] use counter based provider for immediate queue #19824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
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