Skip to content

Commit 895f5c6

Browse files
committed
Fix formatting and modify queue_api template
1 parent 7da53d8 commit 895f5c6

File tree

7 files changed

+74
-82
lines changed

7 files changed

+74
-82
lines changed

scripts/templates/queue_api.hpp.mako

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ from templates import helper as th
2424
#pragma once
2525

2626
#include <ur_api.h>
27+
#include <ze_api.h>
2728

2829
struct ur_queue_handle_t_ {
2930
virtual ~ur_queue_handle_t_();
@@ -33,4 +34,11 @@ struct ur_queue_handle_t_ {
3334
%for obj in th.get_queue_related_functions(specs, n, tags):
3435
virtual ${x}_result_t ${th.transform_queue_related_function_name(n, tags, obj, format=["type"])} = 0;
3536
%endfor
37+
38+
virtual ur_result_t
39+
enqueueNativeCommandExp(ur_exp_enqueue_native_command_function_t, void *,
40+
uint32_t, const ur_mem_handle_t *,
41+
const ur_exp_enqueue_native_command_properties_t *,
42+
uint32_t, const ur_event_handle_t *,
43+
ur_event_handle_t *) = 0;
3644
};

source/adapters/level_zero/v2/command_buffer.cpp

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

1111
#include "command_buffer.hpp"
1212
#include "../helpers/kernel_helpers.hpp"
13-
#include "logger/ur_logger.hpp"
1413
#include "../ur_interface_loader.hpp"
14+
#include "logger/ur_logger.hpp"
1515

1616
namespace {
1717

@@ -27,10 +27,9 @@ void checkImmediateAppendSupport(ur_context_handle_t context) {
2727
"zeCommandListImmediateAppendCommandListsExp entrypoint.");
2828
std::abort();
2929
}
30-
3130
}
3231

33-
}
32+
} // namespace
3433

3534
std::pair<ze_event_handle_t *, uint32_t>
3635
ur_exp_command_buffer_handle_t_::getWaitListView(
@@ -46,8 +45,8 @@ ur_exp_command_buffer_handle_t_::getWaitListView(
4645

4746
ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
4847
ur_context_handle_t context, ur_device_handle_t device,
49-
ze_command_list_handle_t commandList,
50-
const ur_exp_command_buffer_desc_t *desc)
48+
ze_command_list_handle_t commandList,
49+
const ur_exp_command_buffer_desc_t *desc)
5150
: context(context), device(device), zeCommandList(commandList),
5251
isUpdatable(desc ? desc->isUpdatable : false) {
5352
UR_CALL_THROWS(ur::level_zero::urContextRetain(context));
@@ -77,15 +76,14 @@ namespace ur::level_zero {
7776
* @return UR_RESULT_SUCCESS or an error code on failure
7877
*/
7978
ur_result_t createMainCommandList(ur_context_handle_t context,
80-
ur_device_handle_t device,
81-
bool isUpdatable,
79+
ur_device_handle_t device, bool isUpdatable,
8280
ze_command_list_handle_t &commandList) {
8381

84-
8582
using queue_group_type = ur_device_handle_t_::queue_group_info_t::type;
86-
// that should be call to queue getZeOrdinal,
83+
// that should be call to queue getZeOrdinal,
8784
// but queue is not available while constructing buffer
88-
uint32_t queueGroupOrdinal = device->QueueGroup[queue_group_type::Compute].ZeOrdinal;
85+
uint32_t queueGroupOrdinal =
86+
device->QueueGroup[queue_group_type::Compute].ZeOrdinal;
8987

9088
ZeStruct<ze_command_list_desc_t> zeCommandListDesc;
9189
zeCommandListDesc.commandQueueGroupOrdinal = queueGroupOrdinal;
@@ -116,7 +114,7 @@ urCommandBufferCreateExp(ur_context_handle_t context, ur_device_handle_t device,
116114
UR_ASSERT(context->getPlatform()->ZeMutableCmdListExt.Supported,
117115
UR_RESULT_ERROR_UNSUPPORTED_FEATURE);
118116
}
119-
117+
120118
ze_command_list_handle_t zeCommandList = nullptr;
121119
UR_CALL(createMainCommandList(context, device, isUpdatable, zeCommandList));
122120
*commandBuffer = new ur_exp_command_buffer_handle_t_(
@@ -152,7 +150,7 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
152150
}
153151

154152
ur_result_t
155-
urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
153+
urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
156154
try {
157155
UR_ASSERT(hCommandBuffer, UR_RESULT_ERROR_INVALID_NULL_POINTER);
158156
UR_ASSERT(!hCommandBuffer->isFinalized, UR_RESULT_ERROR_INVALID_OPERATION);
@@ -180,33 +178,34 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
180178
uint32_t numEventsInWaitList, const ur_event_handle_t *eventWaitList,
181179
ur_exp_command_buffer_sync_point_t *retSyncPoint, ur_event_handle_t *event,
182180
ur_exp_command_buffer_command_handle_t *command) {
183-
//Need to know semantics
184-
// - should they be checked before kernel execution or before kernel appending to list
185-
// if latter then it is easy fix, if former then TODO
181+
// Need to know semantics
182+
// - should they be checked before kernel execution or before kernel
183+
// appending to list if latter then it is easy fix, if former then TODO
186184
std::ignore = numEventsInWaitList;
187185
std::ignore = eventWaitList;
188186
std::ignore = event;
189187

190-
//sync mechanic can be ignored, because all lists are in-order
188+
// sync mechanic can be ignored, because all lists are in-order
191189
std::ignore = numSyncPointsInWaitList;
192190
std::ignore = syncPointWaitList;
193191
std::ignore = retSyncPoint;
194192

195-
//TODO
193+
// TODO
196194
std::ignore = numKernelAlternatives;
197195
std::ignore = kernelAlternatives;
198196
std::ignore = command;
199197
try {
200198
UR_ASSERT(hKernel, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
201-
UR_ASSERT(hKernel->getProgramHandle(), UR_RESULT_ERROR_INVALID_NULL_POINTER);
199+
UR_ASSERT(hKernel->getProgramHandle(),
200+
UR_RESULT_ERROR_INVALID_NULL_POINTER);
202201

203202
UR_ASSERT(workDim > 0, UR_RESULT_ERROR_INVALID_WORK_DIMENSION);
204203
UR_ASSERT(workDim < 4, UR_RESULT_ERROR_INVALID_WORK_DIMENSION);
205204

206205
ze_kernel_handle_t hZeKernel = hKernel->getZeHandle(commandBuffer->device);
207206

208-
std::scoped_lock<ur_shared_mutex, ur_shared_mutex> lock(commandBuffer->Mutex,
209-
hKernel->Mutex);
207+
std::scoped_lock<ur_shared_mutex, ur_shared_mutex> lock(
208+
commandBuffer->Mutex, hKernel->Mutex);
210209

211210
ze_group_count_t zeThreadGroupDimensions{1, 1, 1};
212211
uint32_t wg[3]{};
@@ -219,18 +218,19 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
219218
bool memoryMigrated = false;
220219
auto memoryMigrate = [&](void *src, void *dst, size_t size) {
221220
ZE2UR_CALL_THROWS(zeCommandListAppendMemoryCopy,
222-
(commandBuffer->zeCommandList.get(), dst, src, size, nullptr,
223-
waitList.second, waitList.first));
221+
(commandBuffer->zeCommandList.get(), dst, src, size,
222+
nullptr, waitList.second, waitList.first));
224223
memoryMigrated = true;
225224
};
226225

227-
UR_CALL(hKernel->prepareForSubmission(commandBuffer->context, commandBuffer->device, pGlobalWorkOffset,
228-
workDim, wg[0], wg[1], wg[2],
229-
memoryMigrate));
226+
UR_CALL(hKernel->prepareForSubmission(
227+
commandBuffer->context, commandBuffer->device, pGlobalWorkOffset,
228+
workDim, wg[0], wg[1], wg[2], memoryMigrate));
230229

231230
ZE2UR_CALL(zeCommandListAppendLaunchKernel,
232-
(commandBuffer->zeCommandList.get(), hZeKernel, &zeThreadGroupDimensions,
233-
nullptr, waitList.second, waitList.first));
231+
(commandBuffer->zeCommandList.get(), hZeKernel,
232+
&zeThreadGroupDimensions, nullptr, waitList.second,
233+
waitList.first));
234234
} catch (...) {
235235
return exceptionToResult(std::current_exception());
236236
}
@@ -243,8 +243,9 @@ ur_result_t urCommandBufferEnqueueExp(
243243
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
244244
ur_event_handle_t *phEvent) {
245245
try {
246-
return hQueue->enqueueCommandBuffer(
247-
hCommandBuffer->zeCommandList.get(), phEvent, numEventsInWaitList, phEventWaitList);
246+
return hQueue->enqueueCommandBuffer(hCommandBuffer->zeCommandList.get(),
247+
phEvent, numEventsInWaitList,
248+
phEventWaitList);
248249
} catch (...) {
249250
return exceptionToResult(std::current_exception());
250251
}

source/adapters/level_zero/v2/command_buffer.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
//===----------------------------------------------------------------------===//
1010
#pragma once
1111

12+
#include <unordered_set>
1213
#include <ur/ur.hpp>
1314
#include <ur_api.h>
1415
#include <ze_api.h>
1516
#include <zes_api.h>
16-
#include <unordered_set>
1717

1818
#include "common.hpp"
1919

@@ -27,13 +27,12 @@ struct command_buffer_profiling_t {
2727
};
2828

2929
struct ur_exp_command_buffer_handle_t_ : public _ur_object {
30-
ur_exp_command_buffer_handle_t_(
31-
ur_context_handle_t context, ur_device_handle_t device,
32-
ze_command_list_handle_t commandList,
33-
const ur_exp_command_buffer_desc_t *desc
34-
);
30+
ur_exp_command_buffer_handle_t_(ur_context_handle_t context,
31+
ur_device_handle_t device,
32+
ze_command_list_handle_t commandList,
33+
const ur_exp_command_buffer_desc_t *desc);
3534
ur_event_handle_t getSignalEvent(ur_event_handle_t *hUserEvent,
36-
ur_command_t commandType);
35+
ur_command_t commandType);
3736

3837
std::pair<ze_event_handle_t *, uint32_t>
3938
getWaitListView(const ur_event_handle_t *phWaitEvents,

source/adapters/level_zero/v2/queue_api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*
1111
*/
1212

13+
// This file was generated basing on scripts/templates/queue_api.cpp.mako
14+
1315
#include "queue_api.hpp"
1416
#include "ur_util.hpp"
1517

source/adapters/level_zero/v2/queue_api.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*
1111
*/
1212

13+
// This file was generated basing on scripts/templates/queue_api.hpp.mako
14+
1315
#pragma once
1416

1517
#include <ur_api.h>
16-
17-
#include "../common.hpp"
18-
18+
#include <ze_api.h>
1919

2020
struct ur_queue_handle_t_ {
2121
virtual ~ur_queue_handle_t_();
@@ -154,14 +154,14 @@ struct ur_queue_handle_t_ {
154154
enqueueEventsWaitWithBarrierExt(const ur_exp_enqueue_ext_properties_t *,
155155
uint32_t, const ur_event_handle_t *,
156156
ur_event_handle_t *) = 0;
157-
virtual ur_result_t
158-
enqueueCommandBuffer(ze_command_list_handle_t, ur_event_handle_t *,
159-
uint32_t, const ur_event_handle_t *) = 0;
160-
161157
virtual ur_result_t
162158
enqueueNativeCommandExp(ur_exp_enqueue_native_command_function_t, void *,
163159
uint32_t, const ur_mem_handle_t *,
164160
const ur_exp_enqueue_native_command_properties_t *,
165161
uint32_t, const ur_event_handle_t *,
166162
ur_event_handle_t *) = 0;
163+
164+
virtual ur_result_t enqueueCommandBuffer(ze_command_list_handle_t,
165+
ur_event_handle_t *, uint32_t,
166+
const ur_event_handle_t *) = 0;
167167
};

source/adapters/level_zero/v2/queue_immediate_in_order.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,13 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueGenericCopyUnlocked(
380380
return UR_RESULT_SUCCESS;
381381
}
382382

383-
384383
ur_result_t ur_queue_immediate_in_order_t::enqueueGenericCommandListsExp(
385-
uint32_t numCommandLists,
386-
ze_command_list_handle_t *phCommandLists,
387-
ur_event_handle_t *phEvent,
388-
uint32_t numEventsInWaitList,
389-
const ur_event_handle_t *phEventWaitList,
390-
ur_command_t callerCommand
391-
) {
392-
393-
std::scoped_lock<ur_shared_mutex> Lock(this->Mutex);
394-
auto signalEvent =
395-
getSignalEvent(phEvent, callerCommand);
384+
uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists,
385+
ur_event_handle_t *phEvent, uint32_t numEventsInWaitList,
386+
const ur_event_handle_t *phEventWaitList, ur_command_t callerCommand) {
396387

388+
std::scoped_lock<ur_shared_mutex> Lock(this->Mutex);
389+
auto signalEvent = getSignalEvent(phEvent, callerCommand);
397390

398391
auto [pWaitEvents, numWaitEvents] =
399392
getWaitListView(phEventWaitList, numEventsInWaitList);
@@ -404,8 +397,8 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueGenericCommandListsExp(
404397
(handler.commandList.get(), numCommandLists, phCommandLists,
405398
zeSignalEvent, numWaitEvents, pWaitEvents));
406399

407-
return UR_RESULT_SUCCESS;
408-
}
400+
return UR_RESULT_SUCCESS;
401+
}
409402

410403
ur_result_t ur_queue_immediate_in_order_t::enqueueMemBufferRead(
411404
ur_mem_handle_t hBuffer, bool blockingRead, size_t offset, size_t size,
@@ -1129,18 +1122,13 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueTimestampRecordingExp(
11291122
}
11301123

11311124
ur_result_t ur_queue_immediate_in_order_t::enqueueCommandBuffer(
1132-
ze_command_list_handle_t commandBufferCommandList,
1133-
ur_event_handle_t *phEvent,
1134-
uint32_t numEventsInWaitList,
1135-
const ur_event_handle_t *phEventWaitList
1136-
) {
1137-
return enqueueGenericCommandListsExp(1,
1138-
&commandBufferCommandList,
1139-
phEvent,
1140-
numEventsInWaitList,
1141-
phEventWaitList,
1142-
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP);
1143-
}
1125+
ze_command_list_handle_t commandBufferCommandList,
1126+
ur_event_handle_t *phEvent, uint32_t numEventsInWaitList,
1127+
const ur_event_handle_t *phEventWaitList) {
1128+
return enqueueGenericCommandListsExp(1, &commandBufferCommandList, phEvent,
1129+
numEventsInWaitList, phEventWaitList,
1130+
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP);
1131+
}
11441132
ur_result_t ur_queue_immediate_in_order_t::enqueueKernelLaunchCustomExp(
11451133
ur_kernel_handle_t hKernel, uint32_t workDim,
11461134
const size_t *pGlobalWorkOffset, const size_t *pGlobalWorkSize,

source/adapters/level_zero/v2/queue_immediate_in_order.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ struct ur_queue_immediate_in_order_t : _ur_object, public ur_queue_handle_t_ {
7878
ur_command_t commandType);
7979

8080
ur_result_t enqueueGenericCommandListsExp(
81-
uint32_t numCommandLists,
82-
ze_command_list_handle_t *phCommandLists,
83-
ur_event_handle_t *phEvent,
84-
uint32_t numEventsInWaitList,
85-
const ur_event_handle_t *phEventWaitList,
86-
ur_command_t callerCommand
87-
);
81+
uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists,
82+
ur_event_handle_t *phEvent, uint32_t numEventsInWaitList,
83+
const ur_event_handle_t *phEventWaitList, ur_command_t callerCommand);
8884

8985
ur_result_t
9086
enqueueEventsWaitWithBarrierImpl(uint32_t numEventsInWaitList,
@@ -282,12 +278,10 @@ struct ur_queue_immediate_in_order_t : _ur_object, public ur_queue_handle_t_ {
282278
const ur_exp_launch_property_t *launchPropList,
283279
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
284280
ur_event_handle_t *phEvent) override;
285-
ur_result_t enqueueCommandBuffer(
286-
ze_command_list_handle_t commandBufferCommandList,
287-
ur_event_handle_t *phEvent,
288-
uint32_t numEventsInWaitList,
289-
const ur_event_handle_t *phEventWaitList
290-
) override;
281+
ur_result_t
282+
enqueueCommandBuffer(ze_command_list_handle_t commandBufferCommandList,
283+
ur_event_handle_t *phEvent, uint32_t numEventsInWaitList,
284+
const ur_event_handle_t *phEventWaitList) override;
291285
ur_result_t
292286
enqueueNativeCommandExp(ur_exp_enqueue_native_command_function_t, void *,
293287
uint32_t, const ur_mem_handle_t *,

0 commit comments

Comments
 (0)