Skip to content

Commit 31b2940

Browse files
committed
[L0] Create v2::context
that inherits from the old context and extends it with v2 functionality. urContextCreate will now always create v2::context. All legacy functions will continue to operate as normal and the optimized code path can levarage additional features implemented in v2.
1 parent 9d3bce6 commit 31b2940

File tree

9 files changed

+75
-16
lines changed

9 files changed

+75
-16
lines changed

source/adapters/level_zero/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ add_ur_adapter(${TARGET_NAME}
115115
${CMAKE_CURRENT_SOURCE_DIR}/sampler.hpp
116116
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
117117
${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
118120
${CMAKE_CURRENT_SOURCE_DIR}/ur_level_zero.cpp
119121
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
120122
${CMAKE_CURRENT_SOURCE_DIR}/context.cpp
@@ -135,6 +137,8 @@ add_ur_adapter(${TARGET_NAME}
135137
${CMAKE_CURRENT_SOURCE_DIR}/image.cpp
136138
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
137139
${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
138142
)
139143

140144
if(NOT WIN32)

source/adapters/level_zero/context.cpp

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

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

4143
Context->initialize();
4244
*RetContext = reinterpret_cast<ur_context_handle_t>(Context);

source/adapters/level_zero/v2/command_list_cache.cpp

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

1111
#include "command_list_cache.hpp"
1212

13-
#include "context.hpp"
14-
#include "device.hpp"
13+
#include "../context.hpp"
14+
#include "../device.hpp"
1515

1616
bool v2::immediate_command_list_descriptor_t::operator==(
1717
const immediate_command_list_descriptor_t &rhs) const {

source/adapters/level_zero/v2/command_list_cache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <ur_api.h>
1616
#include <ze_api.h>
1717

18-
#include "common.hpp"
18+
#include "../common.hpp"
1919

2020
namespace v2 {
2121
namespace raii {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===--------- context.cpp - Level Zero Adapter --------------------------===//
2+
//
3+
// Copyright (C) 2024 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#include "context.hpp"
12+
13+
namespace v2 {
14+
15+
ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
16+
uint32_t numDevices,
17+
const ur_device_handle_t *phDevices,
18+
bool ownZeContext)
19+
: ::ur_context_handle_t_(hContext, numDevices, phDevices, ownZeContext),
20+
commandListCache(hContext) {}
21+
22+
} // namespace v2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===--------- context.hpp - Level Zero Adapter --------------------------===//
2+
//
3+
// Copyright (C) 2024 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#pragma once
12+
13+
#include "command_list_cache.hpp"
14+
15+
#include "../context.hpp"
16+
17+
namespace v2 {
18+
19+
struct ur_context_handle_t_;
20+
using ur_context_handle_t = ur_context_handle_t_ *;
21+
22+
struct ur_context_handle_t_ : public ::ur_context_handle_t_ {
23+
ur_context_handle_t_(ze_context_handle_t hContext, uint32_t numDevices,
24+
const ur_device_handle_t *phDevices, bool ownZeContext);
25+
26+
command_list_cache_t commandListCache;
27+
};
28+
29+
} // namespace v2

source/adapters/level_zero/v2/queue_factory.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,30 @@
1111
#pragma once
1212

1313
#include "../queue.hpp"
14+
#include "context.hpp"
1415

1516
#include "queue_immediate_in_order.hpp"
1617

1718
namespace v2 {
1819

19-
inline bool shouldUseQueueV2(ur_device_handle_t Device,
20-
ur_queue_flags_t Flags) {
21-
std::ignore = Device;
22-
std::ignore = Flags;
20+
inline bool shouldUseQueueV2(ur_device_handle_t hDevice,
21+
ur_queue_flags_t flags) {
22+
std::ignore = hDevice;
23+
std::ignore = flags;
2324

2425
const char *UrRet = std::getenv("UR_L0_USE_QUEUE_V2");
2526
return UrRet && std::stoi(UrRet);
2627
}
2728

28-
inline ur_queue_handle_t createQueue(ur_context_handle_t Context,
29-
ur_device_handle_t Device,
30-
ur_queue_flags_t Flags) {
31-
if (!shouldUseQueueV2(Device, Flags)) {
29+
inline ur_queue_handle_t createQueue(::ur_context_handle_t hContext,
30+
ur_device_handle_t hDevice,
31+
const ur_queue_properties_t *pProps) {
32+
if (!shouldUseQueueV2(hDevice, pProps ? pProps->flags : ur_queue_flags_t{})) {
3233
throw UR_RESULT_ERROR_INVALID_ARGUMENT;
3334
}
34-
3535
// TODO: For now, always use immediate, in-order
36-
return new ur_queue_immediate_in_order_t(Context, Device, Flags);
36+
return new ur_queue_immediate_in_order_t(
37+
static_cast<v2::ur_context_handle_t>(hContext), hDevice, pProps->flags);
3738
}
3839

3940
} // namespace v2

source/adapters/level_zero/v2/queue_immediate_in_order.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace v2 {
1414
ur_queue_immediate_in_order_t::ur_queue_immediate_in_order_t(
15-
ur_context_handle_t, ur_device_handle_t, ur_queue_flags_t) {}
15+
v2::ur_context_handle_t, ur_device_handle_t, ur_queue_flags_t) {}
1616

1717
ur_result_t
1818
ur_queue_immediate_in_order_t::queueGetInfo(ur_queue_info_t propName,

source/adapters/level_zero/v2/queue_immediate_in_order.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
#include "../common.hpp"
1313
#include "../queue.hpp"
14+
#include "context.hpp"
1415

1516
#include "ur/ur.hpp"
1617

1718
namespace v2 {
1819
struct ur_queue_immediate_in_order_t : _ur_object, public ur_queue_handle_t_ {
19-
ur_queue_immediate_in_order_t(ur_context_handle_t, ur_device_handle_t,
20+
ur_queue_immediate_in_order_t(v2::ur_context_handle_t, ur_device_handle_t,
2021
ur_queue_flags_t);
2122

2223
ur_result_t queueGetInfo(ur_queue_info_t propName, size_t propSize,

0 commit comments

Comments
 (0)