Skip to content

Commit 6d8abb9

Browse files
[SYCL][ESIMD][EMU] Queue/Event handling change for esimd_cpu (#4201)
* [SYCL][ESIMD][EMU] Queue/Event handling change for esimd_cpu - Including esimd_cpu in work-around for revised queue::wait() logic same as level-zero, introduced in PR#4044 - Returning 'false' from ExecCGCommand:: producesPiEvent() predicate for esimd_cpu as no effective event is created during esimd_cpu kernel execution - Support only in-order queue for pi_esimd_cpu - Event creation is imported from pi_cuda.cpp - Special handling for esimd_cpu in ExecCGCommand::producesPiEvent() (commands.cpp) is removed
1 parent 6c077a0 commit 6d8abb9

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

sycl/plugins/esimd_cpu/pi_esimd_cpu.cpp

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ extern "C" {
351351
std::cerr << "Warning : Not Implemented : " << __FUNCTION__ \
352352
<< " - File : " << __FILE__; \
353353
std::cerr << " / Line : " << __LINE__ << std::endl; \
354-
}
354+
} \
355+
return PI_SUCCESS;
355356

356357
pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
357358
pi_uint32 *NumPlatforms) {
@@ -684,6 +685,12 @@ pi_result piContextRelease(pi_context Context) {
684685

685686
pi_result piQueueCreate(pi_context Context, pi_device Device,
686687
pi_queue_properties Properties, pi_queue *Queue) {
688+
if (Properties & PI_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) {
689+
// TODO : Support Out-of-order Queue
690+
*Queue = nullptr;
691+
return PI_INVALID_QUEUE_PROPERTIES;
692+
}
693+
687694
cm_support::CmQueue *CmQueue;
688695

689696
int Result = Context->Device->CmDevicePtr->CreateQueue(CmQueue);
@@ -729,7 +736,10 @@ pi_result piQueueRelease(pi_queue Queue) {
729736
}
730737

731738
pi_result piQueueFinish(pi_queue) {
732-
DIE_NO_IMPLEMENTATION;
739+
// No-op as enqueued commands with ESIMD_CPU plugin are blocking
740+
// ones that do not return until their completion - kernel execution
741+
// and memory read.
742+
CONTINUE_NO_IMPLEMENTATION;
733743
}
734744

735745
pi_result piextQueueGetNativeHandle(pi_queue, pi_native_handle *) {
@@ -1190,6 +1200,12 @@ pi_result piEnqueueMemBufferRead(pi_queue Queue, pi_mem Src,
11901200

11911201
_pi_buffer *buf = static_cast<_pi_buffer *>(Src);
11921202

1203+
std::unique_ptr<_pi_event> RetEv{nullptr};
1204+
if (Event) {
1205+
RetEv = std::unique_ptr<_pi_event>(new _pi_event());
1206+
RetEv->IsDummyEvent = true;
1207+
}
1208+
11931209
int Status =
11941210
buf->CmBufferPtr->ReadSurface(reinterpret_cast<unsigned char *>(Dst),
11951211
nullptr, // event
@@ -1200,18 +1216,7 @@ pi_result piEnqueueMemBufferRead(pi_queue Queue, pi_mem Src,
12001216
}
12011217

12021218
if (Event) {
1203-
try {
1204-
*Event = new _pi_event();
1205-
} catch (const std::bad_alloc &) {
1206-
return PI_OUT_OF_HOST_MEMORY;
1207-
} catch (...) {
1208-
return PI_ERROR_UNKNOWN;
1209-
}
1210-
1211-
// At this point, CM already completed buffer-read (ReadSurface)
1212-
// operation. Therefore, 'event' corresponding to this operation
1213-
// is marked as dummy one and ignored during events-waiting.
1214-
(*Event)->IsDummyEvent = true;
1219+
*Event = RetEv.release();
12151220
}
12161221

12171222
return PI_SUCCESS;
@@ -1286,6 +1291,14 @@ pi_result piEnqueueMemImageRead(pi_queue CommandQueue, pi_mem Image,
12861291
assert(false && "ESIMD_CPU does not support Blocking Read");
12871292
}
12881293
_pi_image *PiImg = static_cast<_pi_image *>(Image);
1294+
1295+
std::unique_ptr<_pi_event> RetEv{nullptr};
1296+
1297+
if (Event) {
1298+
RetEv = std::unique_ptr<_pi_event>(new _pi_event());
1299+
RetEv->IsDummyEvent = true;
1300+
}
1301+
12891302
int Status =
12901303
PiImg->CmSurfacePtr->ReadSurface(reinterpret_cast<unsigned char *>(Ptr),
12911304
nullptr, // event
@@ -1295,18 +1308,7 @@ pi_result piEnqueueMemImageRead(pi_queue CommandQueue, pi_mem Image,
12951308
}
12961309

12971310
if (Event) {
1298-
try {
1299-
*Event = new _pi_event();
1300-
} catch (const std::bad_alloc &) {
1301-
return PI_OUT_OF_HOST_MEMORY;
1302-
} catch (...) {
1303-
return PI_ERROR_UNKNOWN;
1304-
}
1305-
1306-
// At this point, CM already completed image-read (ReadSurface)
1307-
// operation. Therefore, 'event' corresponding to this operation
1308-
// is marked as dummy one and ignored during events-waiting.
1309-
(*Event)->IsDummyEvent = true;
1311+
*Event = RetEv.release();
13101312
}
13111313
return PI_SUCCESS;
13121314
}
@@ -1360,25 +1362,39 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
13601362
}
13611363
}
13621364

1365+
std::unique_ptr<_pi_event> RetEv{nullptr};
1366+
1367+
if (Event) {
1368+
RetEv = std::unique_ptr<_pi_event>(new _pi_event());
1369+
RetEv->IsDummyEvent = true;
1370+
}
1371+
13631372
switch (WorkDim) {
13641373
case 1:
13651374
InvokeImpl<1>::invoke(Kernel, GlobalWorkOffset, GlobalWorkSize,
13661375
LocalWorkSize);
1367-
return PI_SUCCESS;
1376+
break;
13681377

13691378
case 2:
13701379
InvokeImpl<2>::invoke(Kernel, GlobalWorkOffset, GlobalWorkSize,
13711380
LocalWorkSize);
1372-
return PI_SUCCESS;
1381+
break;
13731382

13741383
case 3:
13751384
InvokeImpl<3>::invoke(Kernel, GlobalWorkOffset, GlobalWorkSize,
13761385
LocalWorkSize);
1377-
return PI_SUCCESS;
1386+
break;
13781387

13791388
default:
13801389
DIE_NO_IMPLEMENTATION;
1390+
break;
13811391
}
1392+
1393+
if (Event) {
1394+
*Event = RetEv.release();
1395+
}
1396+
1397+
return PI_SUCCESS;
13821398
}
13831399

13841400
pi_result piextKernelCreateWithNativeHandle(pi_native_handle, pi_context, bool,

0 commit comments

Comments
 (0)