Skip to content

Commit bd721b2

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
refactor: Adding support for extending L0 context object
Related-To: NEO-13406 Signed-off-by: Chodor, Jaroslaw <[email protected]>
1 parent f852e2d commit bd721b2

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

level_zero/core/source/context/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2023-2024 Intel Corporation
2+
# Copyright (C) 2023-2025 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -13,4 +13,7 @@ target_sources(${L0_STATIC_LIB_NAME}
1313
${CMAKE_CURRENT_SOURCE_DIR}/context_imp.cpp
1414
${CMAKE_CURRENT_SOURCE_DIR}/context_imp.h
1515
${CMAKE_CURRENT_SOURCE_DIR}/context.h
16+
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/context_ext.cpp
1617
)
18+
19+
add_subdirectories()

level_zero/core/source/context/context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace L0 {
2828
struct DriverHandle;
2929
struct Image;
3030

31+
class ContextExt;
32+
3133
struct Context : _ze_context_handle_t {
3234
inline static ze_memory_type_t parseUSMType(InternalMemoryType memoryType) {
3335
switch (memoryType) {
@@ -178,6 +180,8 @@ struct Context : _ze_context_handle_t {
178180

179181
static Context *fromHandle(ze_context_handle_t handle) { return static_cast<Context *>(handle); }
180182
inline ze_context_handle_t toHandle() { return this; }
183+
184+
virtual ContextExt *getContextExt() = 0;
181185
};
182186

183187
} // namespace L0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
namespace L0 {
9+
10+
class ContextExt;
11+
struct DriverHandle;
12+
13+
ContextExt *createContextExt(DriverHandle *driverHandle) {
14+
return nullptr;
15+
}
16+
17+
void destroyContextExt(ContextExt *ctxExt) {
18+
return;
19+
}
20+
21+
} // namespace L0

level_zero/core/source/context/context_imp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ DriverHandle *ContextImp::getDriverHandle() {
6161

6262
ContextImp::ContextImp(DriverHandle *driverHandle) {
6363
this->driverHandle = static_cast<DriverHandleImp *>(driverHandle);
64+
this->contextExt = createContextExt(driverHandle);
65+
}
66+
67+
ContextImp::~ContextImp() {
68+
destroyContextExt(this->contextExt);
6469
}
6570

6671
ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,

level_zero/core/source/context/context_imp.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -22,9 +22,12 @@ struct DriverHandleImp;
2222
struct Device;
2323
struct IpcCounterBasedEventData;
2424

25+
ContextExt *createContextExt(DriverHandle *driverHandle);
26+
void destroyContextExt(ContextExt *ctxExt);
27+
2528
struct ContextImp : Context {
2629
ContextImp(DriverHandle *driverHandle);
27-
~ContextImp() override = default;
30+
~ContextImp() override;
2831
ze_result_t destroy() override;
2932
ze_result_t getStatus() override;
3033
DriverHandle *getDriverHandle() override;
@@ -187,6 +190,10 @@ struct ContextImp : Context {
187190
unsigned int elementSizeInBytes,
188191
size_t *rowPitch) override;
189192

193+
ContextExt *getContextExt() override {
194+
return contextExt;
195+
}
196+
190197
protected:
191198
ze_result_t getIpcMemHandlesImpl(const void *ptr, uint32_t *numIpcHandles, ze_ipc_mem_handle_t *pIpcHandles);
192199
void setIPCHandleData(NEO::GraphicsAllocation *graphicsAllocation, uint64_t handle, IpcMemoryData &ipcData, uint64_t ptrAddress, uint8_t type);
@@ -197,6 +204,7 @@ struct ContextImp : Context {
197204
std::vector<ze_device_handle_t> deviceHandles;
198205
DriverHandleImp *driverHandle = nullptr;
199206
uint32_t numDevices = 0;
207+
ContextExt *contextExt = nullptr;
200208
};
201209

202210
} // namespace L0

level_zero/core/source/memory_manager/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2023 Intel Corporation
2+
# Copyright (C) 2023-2025 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -9,3 +9,5 @@ target_sources(${L0_STATIC_LIB_NAME}
99
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
1010
${CMAKE_CURRENT_SOURCE_DIR}/compression_selector_l0.cpp
1111
)
12+
13+
add_subdirectories()

level_zero/core/test/unit_tests/fixtures/device_fixture.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ template <typename T>
5858
struct DeviceFixtureWithCustomMemoryManager : public DeviceFixture {
5959
void setUp() {
6060
auto executionEnvironment = NEO::MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u);
61-
auto memoryManager = new T(*executionEnvironment);
61+
memoryManager = new T(*executionEnvironment);
6262
executionEnvironment->memoryManager.reset(memoryManager);
6363
DeviceFixture::setupWithExecutionEnvironment(*executionEnvironment);
6464
}
6565

6666
void tearDown() {
6767
DeviceFixture::tearDown();
6868
}
69+
70+
T *memoryManager = nullptr;
6971
};
7072

7173
struct DriverHandleGetMemHandlePtrMock : public L0::DriverHandleImp {

0 commit comments

Comments
 (0)