Skip to content

Commit 63a801e

Browse files
author
Jaime Arteaga
committed
Context implementation (3/N)
Add object creators. Change-Id: Ic656a1bd3735bce1d995c407011ef7c26eab848e Signed-off: Jaime Arteaga <[email protected]>
1 parent a6d4cb1 commit 63a801e

File tree

14 files changed

+427
-0
lines changed

14 files changed

+427
-0
lines changed

level_zero/api/core/ze_cmdlist.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "level_zero/core/source/cmdlist/cmdlist.h"
9+
#include "level_zero/core/source/context/context.h"
910
#include <level_zero/ze_api.h>
1011

1112
#include "third_party/level_zero/ze_api_ext.h"
@@ -20,6 +21,15 @@ zeCommandListCreate(
2021
return L0::Device::fromHandle(hDevice)->createCommandList(desc, phCommandList);
2122
}
2223

24+
ZE_APIEXPORT ze_result_t ZE_APICALL
25+
zeCommandListCreateExt(
26+
ze_context_handle_t hContext,
27+
ze_device_handle_t hDevice,
28+
const ze_command_list_desc_t *desc,
29+
ze_command_list_handle_t *phCommandList) {
30+
return L0::Context::fromHandle(hContext)->createCommandList(hDevice, desc, phCommandList);
31+
}
32+
2333
__zedllexport ze_result_t __zecall
2434
zeCommandListCreateImmediate(
2535
ze_device_handle_t hDevice,
@@ -28,6 +38,15 @@ zeCommandListCreateImmediate(
2838
return L0::Device::fromHandle(hDevice)->createCommandListImmediate(altdesc, phCommandList);
2939
}
3040

41+
ZE_APIEXPORT ze_result_t ZE_APICALL
42+
zeCommandListCreateImmediateExt(
43+
ze_context_handle_t hContext,
44+
ze_device_handle_t hDevice,
45+
const ze_command_queue_desc_t *altdesc,
46+
ze_command_list_handle_t *phCommandList) {
47+
return L0::Context::fromHandle(hContext)->createCommandListImmediate(hDevice, altdesc, phCommandList);
48+
}
49+
3150
__zedllexport ze_result_t __zecall
3251
zeCommandListDestroy(
3352
ze_command_list_handle_t hCommandList) {

level_zero/api/core/ze_cmdqueue.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "level_zero/core/source/cmdqueue/cmdqueue.h"
9+
#include "level_zero/core/source/context/context.h"
910
#include <level_zero/ze_api.h>
1011

1112
extern "C" {
@@ -18,6 +19,15 @@ zeCommandQueueCreate(
1819
return L0::Device::fromHandle(hDevice)->createCommandQueue(desc, phCommandQueue);
1920
}
2021

22+
ZE_APIEXPORT ze_result_t ZE_APICALL
23+
zeCommandQueueCreateExt(
24+
ze_context_handle_t hContext,
25+
ze_device_handle_t hDevice,
26+
const ze_command_queue_desc_t *desc,
27+
ze_command_queue_handle_t *phCommandQueue) {
28+
return L0::Context::fromHandle(hContext)->createCommandQueue(hDevice, desc, phCommandQueue);
29+
}
30+
2131
__zedllexport ze_result_t __zecall
2232
zeCommandQueueDestroy(
2333
ze_command_queue_handle_t hCommandQueue) {

level_zero/api/core/ze_module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ zeModuleCreate(
2121
return L0::Device::fromHandle(hDevice)->createModule(desc, phModule, phBuildLog);
2222
}
2323

24+
ZE_APIEXPORT ze_result_t ZE_APICALL
25+
zeModuleCreateExt(
26+
ze_context_handle_t hContext,
27+
ze_device_handle_t hDevice,
28+
const ze_module_desc_t *desc,
29+
ze_module_handle_t *phModule,
30+
ze_module_build_log_handle_t *phBuildLog) {
31+
return L0::Context::fromHandle(hContext)->createModule(hDevice, desc, phModule, phBuildLog);
32+
}
33+
2434
__zedllexport ze_result_t __zecall
2535
zeModuleDestroy(
2636
ze_module_handle_t hModule) {

level_zero/api/core/ze_sampler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

8+
#include "level_zero/core/source/context/context.h"
89
#include "level_zero/core/source/sampler/sampler.h"
910
#include <level_zero/ze_api.h>
1011

@@ -18,6 +19,15 @@ zeSamplerCreate(
1819
return L0::Device::fromHandle(hDevice)->createSampler(desc, phSampler);
1920
}
2021

22+
ZE_APIEXPORT ze_result_t ZE_APICALL
23+
zeSamplerCreateExt(
24+
ze_context_handle_t hContext,
25+
ze_device_handle_t hDevice,
26+
const ze_sampler_desc_t *desc,
27+
ze_sampler_handle_t *phSampler) {
28+
return L0::Context::fromHandle(hContext)->createSampler(hDevice, desc, phSampler);
29+
}
30+
2131
__zedllexport ze_result_t __zecall
2232
zeSamplerDestroy(
2333
ze_sampler_handle_t hSampler) {

level_zero/core/source/context/context.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ struct Context : _ze_context_handle_t {
5252
virtual ze_result_t getMemAllocProperties(const void *ptr,
5353
ze_memory_allocation_properties_t *pMemAllocProperties,
5454
ze_device_handle_t *phDevice) = 0;
55+
virtual ze_result_t createModule(ze_device_handle_t hDevice,
56+
const ze_module_desc_t *desc,
57+
ze_module_handle_t *phModule,
58+
ze_module_build_log_handle_t *phBuildLog) = 0;
59+
virtual ze_result_t createSampler(ze_device_handle_t hDevice,
60+
const ze_sampler_desc_t *pDesc,
61+
ze_sampler_handle_t *phSampler) = 0;
62+
virtual ze_result_t createCommandQueue(ze_device_handle_t hDevice,
63+
const ze_command_queue_desc_t *desc,
64+
ze_command_queue_handle_t *commandQueue) = 0;
65+
virtual ze_result_t createCommandList(ze_device_handle_t hDevice,
66+
const ze_command_list_desc_t *desc,
67+
ze_command_list_handle_t *commandList) = 0;
68+
virtual ze_result_t createCommandListImmediate(ze_device_handle_t hDevice,
69+
const ze_command_queue_desc_t *desc,
70+
ze_command_list_handle_t *commandList) = 0;
5571

5672
static Context *fromHandle(ze_context_handle_t handle) { return static_cast<Context *>(handle); }
5773
inline ze_context_handle_t toHandle() { return this; }

level_zero/core/source/context/context_imp.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "level_zero/core/source/context/context_imp.h"
99

10+
#include "level_zero/core/source/device/device.h"
11+
1012
namespace L0 {
1113

1214
ze_result_t ContextImp::destroy() {
@@ -111,4 +113,35 @@ ze_result_t ContextImp::getMemAllocProperties(const void *ptr,
111113
phDevice);
112114
}
113115

116+
ze_result_t ContextImp::createModule(ze_device_handle_t hDevice,
117+
const ze_module_desc_t *desc,
118+
ze_module_handle_t *phModule,
119+
ze_module_build_log_handle_t *phBuildLog) {
120+
return L0::Device::fromHandle(hDevice)->createModule(desc, phModule, phBuildLog);
121+
}
122+
123+
ze_result_t ContextImp::createSampler(ze_device_handle_t hDevice,
124+
const ze_sampler_desc_t *pDesc,
125+
ze_sampler_handle_t *phSampler) {
126+
return L0::Device::fromHandle(hDevice)->createSampler(pDesc, phSampler);
127+
}
128+
129+
ze_result_t ContextImp::createCommandQueue(ze_device_handle_t hDevice,
130+
const ze_command_queue_desc_t *desc,
131+
ze_command_queue_handle_t *commandQueue) {
132+
return L0::Device::fromHandle(hDevice)->createCommandQueue(desc, commandQueue);
133+
}
134+
135+
ze_result_t ContextImp::createCommandList(ze_device_handle_t hDevice,
136+
const ze_command_list_desc_t *desc,
137+
ze_command_list_handle_t *commandList) {
138+
return L0::Device::fromHandle(hDevice)->createCommandList(desc, commandList);
139+
}
140+
141+
ze_result_t ContextImp::createCommandListImmediate(ze_device_handle_t hDevice,
142+
const ze_command_queue_desc_t *desc,
143+
ze_command_list_handle_t *commandList) {
144+
return L0::Device::fromHandle(hDevice)->createCommandListImmediate(desc, commandList);
145+
}
146+
114147
} // namespace L0

level_zero/core/source/context/context_imp.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ struct ContextImp : Context {
4646
ze_result_t getMemAllocProperties(const void *ptr,
4747
ze_memory_allocation_properties_t *pMemAllocProperties,
4848
ze_device_handle_t *phDevice) override;
49+
ze_result_t createModule(ze_device_handle_t hDevice,
50+
const ze_module_desc_t *desc,
51+
ze_module_handle_t *phModule,
52+
ze_module_build_log_handle_t *phBuildLog) override;
53+
ze_result_t createSampler(ze_device_handle_t hDevice,
54+
const ze_sampler_desc_t *pDesc,
55+
ze_sampler_handle_t *phSampler) override;
56+
ze_result_t createCommandQueue(ze_device_handle_t hDevice,
57+
const ze_command_queue_desc_t *desc,
58+
ze_command_queue_handle_t *commandQueue) override;
59+
ze_result_t createCommandList(ze_device_handle_t hDevice,
60+
const ze_command_list_desc_t *desc,
61+
ze_command_list_handle_t *commandList) override;
62+
ze_result_t createCommandListImmediate(ze_device_handle_t hDevice,
63+
const ze_command_queue_desc_t *desc,
64+
ze_command_list_handle_t *commandList) override;
4965

5066
protected:
5167
DriverHandle *driverHandle = nullptr;

level_zero/core/source/module/module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include "level_zero/core/source/cmdlist/cmdlist.h"
11+
#include "level_zero/core/source/context/context.h"
1112
#include "level_zero/core/source/kernel/kernel.h"
1213
#include "level_zero/core/source/module/module_build_log.h"
1314
#include <level_zero/ze_api.h>

level_zero/core/test/unit_tests/mocks/mock_context.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,37 @@ struct Mock<Context> : public Context {
9393
ze_ipc_memory_flags_t flags,
9494
void **ptr),
9595
(override));
96+
MOCK_METHOD(ze_result_t,
97+
createModule,
98+
(ze_device_handle_t hDevice,
99+
const ze_module_desc_t *desc,
100+
ze_module_handle_t *phModule,
101+
ze_module_build_log_handle_t *phBuildLog),
102+
(override));
103+
MOCK_METHOD(ze_result_t,
104+
createSampler,
105+
(ze_device_handle_t hDevice,
106+
const ze_sampler_desc_t *pDesc,
107+
ze_sampler_handle_t *phSampler),
108+
(override));
109+
MOCK_METHOD(ze_result_t,
110+
createCommandQueue,
111+
(ze_device_handle_t hDevice,
112+
const ze_command_queue_desc_t *desc,
113+
ze_command_queue_handle_t *commandQueue),
114+
(override));
115+
MOCK_METHOD(ze_result_t,
116+
createCommandList,
117+
(ze_device_handle_t hDevice,
118+
const ze_command_list_desc_t *desc,
119+
ze_command_list_handle_t *commandList),
120+
(override));
121+
MOCK_METHOD(ze_result_t,
122+
createCommandListImmediate,
123+
(ze_device_handle_t hDevice,
124+
const ze_command_queue_desc_t *desc,
125+
ze_command_list_handle_t *commandList),
126+
(override));
96127
};
97128

98129
} // namespace ult

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "test.h"
1515

1616
#include "level_zero/core/source/builtin/builtin_functions_lib_impl.h"
17+
#include "level_zero/core/source/context/context.h"
1718
#include "level_zero/core/source/driver/driver_handle_imp.h"
1819
#include "level_zero/core/source/image/image_hw.h"
1920
#include "level_zero/core/source/kernel/kernel_imp.h"
@@ -25,6 +26,31 @@
2526

2627
namespace L0 {
2728
namespace ult {
29+
30+
using ContextCommandListCreate = Test<ContextFixture>;
31+
32+
TEST_F(ContextCommandListCreate, whenCreatingCommandListFromContextThenSuccessIsReturned) {
33+
ze_command_list_desc_t desc = {};
34+
ze_command_list_handle_t hCommandList = {};
35+
36+
ze_result_t result = context->createCommandList(device, &desc, &hCommandList);
37+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
38+
39+
L0::CommandList *commandList = L0::CommandList::fromHandle(hCommandList);
40+
commandList->destroy();
41+
}
42+
43+
TEST_F(ContextCommandListCreate, whenCreatingCommandListImmediateFromContextThenSuccessIsReturned) {
44+
ze_command_queue_desc_t desc = {};
45+
ze_command_list_handle_t hCommandList = {};
46+
47+
ze_result_t result = context->createCommandListImmediate(device, &desc, &hCommandList);
48+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
49+
50+
L0::CommandList *commandList = L0::CommandList::fromHandle(hCommandList);
51+
commandList->destroy();
52+
}
53+
2854
using CommandListCreate = Test<DeviceFixture>;
2955

3056
TEST(zeCommandListCreateImmediate, redirectsToObject) {

0 commit comments

Comments
 (0)