Skip to content

Commit 4078649

Browse files
committed
[L0 v2] Rename ur_event to ur_event_handle_t and fix compilation
1 parent ce9433d commit 4078649

15 files changed

+143
-85
lines changed

source/adapters/level_zero/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ if(UR_BUILD_ADAPTER_L0_V2)
207207
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.cpp
208208
)
209209

210-
# api.cpp contains NOT_SUPPORTED functions-only
211-
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/v2/api.cpp
212-
PROPERTIES APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-unused-parameter")
213-
214210
if(NOT WIN32)
211+
# api.cpp contains NOT_SUPPORTED functions-only
212+
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/v2/api.cpp
213+
PROPERTIES APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-unused-parameter")
214+
215215
target_sources(ur_adapter_level_zero_v2
216216
PRIVATE
217217
${CMAKE_CURRENT_SOURCE_DIR}/adapter_lib_init_linux.cpp

source/adapters/level_zero/v2/api.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,16 +538,6 @@ ur_result_t UR_APICALL urEventWait(uint32_t numEvents,
538538
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
539539
}
540540

541-
ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) {
542-
logger::error("{} function not implemented!", __FUNCTION__);
543-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
544-
}
545-
546-
ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) {
547-
logger::error("{} function not implemented!", __FUNCTION__);
548-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
549-
}
550-
551541
ur_result_t UR_APICALL urEventGetNativeHandle(
552542
ur_event_handle_t hEvent, ur_native_handle_t *phNativeEvent) {
553543
logger::error("{} function not implemented!", __FUNCTION__);

source/adapters/level_zero/v2/event.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,49 @@
77
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
//
99
//===----------------------------------------------------------------------===//
10+
11+
#include <ze_api.h>
12+
1013
#include "event.hpp"
14+
#include "event_pool.hpp"
1115
#include "event_provider.hpp"
12-
#include "ze_api.h"
1316

14-
namespace v2 {
15-
void ur_event::reset() {
17+
ur_event_handle_t_::ur_event_handle_t_(v2::event_allocation eventAllocation,
18+
v2::event_pool *pool)
19+
: type(eventAllocation.type), zeEvent(std::move(eventAllocation.borrow)),
20+
pool(pool) {}
21+
22+
void ur_event_handle_t_::reset() {
1623
// consider make an abstraction for regular/counter based
1724
// events if there's more of this type of conditions
18-
if (type == event_type::EVENT_REGULAR) {
25+
if (type == v2::event_type::EVENT_REGULAR) {
1926
zeEventHostReset(zeEvent.get());
2027
}
2128
}
2229

23-
ze_event_handle_t ur_event::getZeEvent() { return zeEvent.get(); }
30+
ze_event_handle_t ur_event_handle_t_::getZeEvent() const {
31+
return zeEvent.get();
32+
}
33+
34+
ur_result_t ur_event_handle_t_::retain() {
35+
RefCount.increment();
36+
return UR_RESULT_SUCCESS;
37+
}
38+
39+
ur_result_t ur_event_handle_t_::release() {
40+
if (!RefCount.decrementAndTest())
41+
return UR_RESULT_SUCCESS;
42+
43+
pool->free(this);
44+
RefCount.increment();
45+
46+
return UR_RESULT_SUCCESS;
47+
}
2448

25-
ur_event::ur_event(event_allocation eventAllocation)
26-
: type(eventAllocation.type), zeEvent(std::move(eventAllocation.borrow)) {}
49+
UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) {
50+
return hEvent->retain();
51+
}
2752

28-
} // namespace v2
53+
UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) {
54+
return hEvent->release();
55+
}

source/adapters/level_zero/v2/event.hpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@
1515
#include <ur_api.h>
1616
#include <ze_api.h>
1717

18+
#include "common.hpp"
1819
#include "event_provider.hpp"
1920

2021
namespace v2 {
22+
class event_pool;
23+
}
2124

22-
class ur_event {
25+
struct ur_event_handle_t_;
26+
using ur_event_handle_t = ur_event_handle_t_ *;
27+
28+
struct ur_event_handle_t_ : _ur_object {
2329
public:
24-
ur_event(event_allocation eventAllocation);
30+
ur_event_handle_t_(v2::event_allocation eventAllocation,
31+
v2::event_pool *pool);
2532

2633
void reset();
27-
ze_event_handle_t getZeEvent();
34+
ze_event_handle_t getZeEvent() const;
35+
36+
ur_result_t retain();
37+
ur_result_t release();
2838

2939
private:
30-
event_type type;
31-
event_borrowed zeEvent;
40+
v2::event_type type;
41+
v2::raii::cache_borrowed_event zeEvent;
42+
v2::event_pool *pool;
3243
};
33-
34-
} // namespace v2

source/adapters/level_zero/v2/event_pool.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace v2 {
1414

1515
static constexpr size_t EVENTS_BURST = 64;
1616

17-
ur_event *event_pool::allocate() {
17+
ur_event_handle_t_ *event_pool::allocate() {
1818
if (freelist.empty()) {
1919
auto start = events.size();
2020
auto end = start + EVENTS_BURST;
2121
for (; start < end; ++start) {
22-
events.emplace_back(provider->allocate());
22+
events.emplace_back(provider->allocate(), this);
2323
freelist.push_back(&events.at(start));
2424
}
2525
}
@@ -30,9 +30,11 @@ ur_event *event_pool::allocate() {
3030
return event;
3131
}
3232

33-
void event_pool::free(ur_event *event) {
33+
void event_pool::free(ur_event_handle_t_ *event) {
3434
event->reset();
3535
freelist.push_back(event);
3636
}
3737

38+
event_provider *event_pool::getProvider() { return provider.get(); }
39+
3840
} // namespace v2

source/adapters/level_zero/v2/event_pool.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ class event_pool {
3939

4040
DeviceId Id() { return provider->device()->Id; };
4141

42-
ur_event *allocate();
43-
void free(ur_event *event);
42+
ur_event_handle_t_ *allocate();
43+
void free(ur_event_handle_t_ *event);
44+
45+
event_provider *getProvider();
4446

4547
private:
4648
std::unique_ptr<event_provider> provider;
4749

48-
std::deque<ur_event> events;
49-
std::vector<ur_event *> freelist;
50+
std::deque<ur_event_handle_t_> events;
51+
std::vector<ur_event_handle_t_ *> freelist;
5052
};
5153

5254
} // namespace v2

source/adapters/level_zero/v2/event_pool_cache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ event_pool_cache::event_pool_cache(size_t max_devices,
2121

2222
event_pool_cache::~event_pool_cache() {}
2323

24-
event_pool_borrowed event_pool_cache::borrow(DeviceId id) {
24+
raii::cache_borrowed_event_pool event_pool_cache::borrow(DeviceId id) {
2525
std::unique_lock<ur_mutex> Lock(mutex);
2626

2727
if (id >= pools.size()) {
@@ -36,7 +36,7 @@ event_pool_borrowed event_pool_cache::borrow(DeviceId id) {
3636
auto pool = vec.back().release();
3737
vec.pop_back();
3838

39-
return event_pool_borrowed(pool, [this](event_pool *pool) {
39+
return raii::cache_borrowed_event_pool(pool, [this](event_pool *pool) {
4040
std::unique_lock<ur_mutex> Lock(mutex);
4141
pools[pool->Id()].emplace_back(pool);
4242
});

source/adapters/level_zero/v2/event_pool_cache.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
namespace v2 {
2727

28-
using event_pool_borrowed =
28+
namespace raii {
29+
using cache_borrowed_event_pool =
2930
std::unique_ptr<event_pool, std::function<void(event_pool *)>>;
31+
} // namespace raii
3032

3133
class event_pool_cache {
3234
public:
@@ -36,7 +38,7 @@ class event_pool_cache {
3638
event_pool_cache(size_t max_devices, ProviderCreateFunc);
3739
~event_pool_cache();
3840

39-
event_pool_borrowed borrow(DeviceId);
41+
raii::cache_borrowed_event_pool borrow(DeviceId);
4042

4143
private:
4244
ur_mutex mutex;

source/adapters/level_zero/v2/event_provider.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ namespace v2 {
2323

2424
enum event_type { EVENT_REGULAR, EVENT_COUNTER };
2525

26-
using event_borrowed =
27-
std::unique_ptr<_ze_event_handle_t, std::function<void(ze_event_handle_t)>>;
26+
class event_provider;
27+
28+
namespace raii {
29+
using cache_borrowed_event =
30+
std::unique_ptr<_ze_event_handle_t,
31+
std::function<void(::ze_event_handle_t)>>;
32+
} // namespace raii
2833

2934
struct event_allocation {
3035
event_type type;
31-
event_borrowed borrow;
36+
raii::cache_borrowed_event borrow;
3237
};
3338

3439
class event_provider {

source/adapters/level_zero/v2/event_provider_counter.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
//
99
//===----------------------------------------------------------------------===//
10+
#include <ur_api.h>
11+
#include <ze_api.h>
12+
13+
#include "context.hpp"
14+
#include "event_provider.hpp"
1015
#include "event_provider_counter.hpp"
11-
#include "../context.hpp"
16+
#include "loader/ze_loader.h"
17+
1218
#include "../device.hpp"
1319
#include "../platform.hpp"
14-
#include "event_provider.hpp"
15-
#include "loader/ze_loader.h"
16-
#include "ur_api.h"
17-
#include "ze_api.h"
1820

1921
namespace v2 {
2022

@@ -27,7 +29,7 @@ provider_counter::provider_counter(ur_platform_handle_t platform,
2729
(void **)&this->eventCreateFunc));
2830
ZE2UR_CALL_THROWS(
2931
zelLoaderTranslateHandle,
30-
(ZEL_HANDLE_CONTEXT, context->ZeContext, (void **)&translatedContext));
32+
(ZEL_HANDLE_CONTEXT, context->hContext, (void **)&translatedContext));
3133
ZE2UR_CALL_THROWS(
3234
zelLoaderTranslateHandle,
3335
(ZEL_HANDLE_DEVICE, device->ZeDevice, (void **)&translatedDevice));
@@ -52,9 +54,10 @@ event_allocation provider_counter::allocate() {
5254
freelist.pop_back();
5355

5456
return {event_type::EVENT_COUNTER,
55-
event_borrowed(event.release(), [this](ze_event_handle_t handle) {
56-
freelist.push_back(handle);
57-
})};
57+
raii::cache_borrowed_event(event.release(),
58+
[this](ze_event_handle_t handle) {
59+
freelist.push_back(handle);
60+
})};
5861
}
5962

6063
ur_device_handle_t provider_counter::device() { return urDevice; }

0 commit comments

Comments
 (0)