@@ -112,6 +112,12 @@ class ReturnHelper {
112
112
// Controls PI level tracing prints.
113
113
static bool PrintPiTrace = false ;
114
114
115
+ static void PiTrace (std::string TraceString) {
116
+ if (PrintPiTrace) {
117
+ std::cout << TraceString << std::endl;
118
+ }
119
+ }
120
+
115
121
// Global variables used in PI_esimd_emulator
116
122
// Note we only create a simple pointer variables such that C++ RT won't
117
123
// deallocate them automatically at the end of the main program.
@@ -394,8 +400,8 @@ extern "C" {
394
400
pi_result piPlatformsGet (pi_uint32 NumEntries, pi_platform *Platforms,
395
401
pi_uint32 *NumPlatforms) {
396
402
static bool PiPlatformCachePopulated = false ;
397
- static const char *PiTrace = std::getenv (" SYCL_PI_TRACE" );
398
- static const int PiTraceValue = PiTrace ? std::stoi (PiTrace ) : 0 ;
403
+ static const char *PiTraceEnv = std::getenv (" SYCL_PI_TRACE" );
404
+ static const int PiTraceValue = PiTraceEnv ? std::stoi (PiTraceEnv ) : 0 ;
399
405
400
406
if (PiTraceValue == -1 ) { // Means print all PI traces
401
407
PrintPiTrace = true ;
@@ -408,11 +414,9 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
408
414
if (NumEntries == 0 ) {
409
415
// / Runtime queries number of Platforms
410
416
if (Platforms != nullptr ) {
411
- if (PrintPiTrace) {
412
- std::cerr << " Invalid Arguments for piPlatformsGet of esimd_emultor "
413
- " (Platforms!=nullptr) while querying number of platforms"
414
- << std::endl;
415
- }
417
+ PiTrace (" Invalid Arguments for piPlatformsGet of "
418
+ " esimd_emulator (Platforms!=nullptr) "
419
+ " while querying number of platforms" );
416
420
return PI_ERROR_INVALID_VALUE;
417
421
}
418
422
return PI_SUCCESS;
@@ -498,11 +502,8 @@ pi_result piDevicesGet(pi_platform Platform, pi_device_type DeviceType,
498
502
if (NumEntries == 0 ) {
499
503
// / Runtime queries number of devices
500
504
if (Devices != nullptr ) {
501
- if (PrintPiTrace) {
502
- std::cerr << " Invalid Arguments for piDevicesGet of esimd_emultor "
503
- " (Devices!=nullptr) while querying number of platforms"
504
- << std::endl;
505
- }
505
+ PiTrace (" Invalid Arguments for piDevicesGet of esimd_emultor "
506
+ " (Devices!=nullptr) while querying number of platforms" );
506
507
return PI_ERROR_INVALID_VALUE;
507
508
}
508
509
return PI_SUCCESS;
@@ -551,10 +552,9 @@ pi_result _pi_platform::populateDeviceCacheIfNeeded() {
551
552
// e.g. CM version 7.3 => Device version = 703
552
553
553
554
if (((Version / 10 ) % 10 ) != 0 ) {
554
- if (PrintPiTrace) {
555
- std::cerr << " CM_EMU Device version info is incorrect : " << Version
556
- << std::endl;
557
- }
555
+ PiTrace (" Invalid Arguments for piPlatformsGet of "
556
+ " esimd_emulator (Platforms!=nullptr) "
557
+ " while querying number of platforms" );
558
558
return PI_ERROR_INVALID_DEVICE;
559
559
}
560
560
@@ -906,21 +906,14 @@ pi_result piContextRelease(pi_context Context) {
906
906
bool _pi_context::checkSurfaceArgument (pi_mem_flags Flags, void *HostPtr) {
907
907
if (Flags & (PI_MEM_FLAGS_HOST_PTR_USE | PI_MEM_FLAGS_HOST_PTR_COPY)) {
908
908
if (HostPtr == nullptr ) {
909
- if (PrintPiTrace) {
910
- std::cerr << " HostPtr argument is required for "
911
- " PI_MEM_FLAGS_HOST_PTR_USE/COPY"
912
- << std::endl;
913
- }
909
+ PiTrace (" HostPtr argument is required for "
910
+ " PI_MEM_FLAGS_HOST_PTR_USE/COPY" );
914
911
return false ;
915
912
}
916
913
// COPY and USE are mutually exclusive
917
914
if ((Flags & (PI_MEM_FLAGS_HOST_PTR_USE | PI_MEM_FLAGS_HOST_PTR_COPY)) ==
918
915
(PI_MEM_FLAGS_HOST_PTR_USE | PI_MEM_FLAGS_HOST_PTR_COPY)) {
919
- if (PrintPiTrace) {
920
- std::cerr
921
- << " PI_MEM_FLAGS_HOST_PTR_USE and _COPY cannot be used together"
922
- << std::endl;
923
- }
916
+ PiTrace (" PI_MEM_FLAGS_HOST_PTR_USE and _COPY cannot be used together" );
924
917
return false ;
925
918
}
926
919
}
@@ -1010,10 +1003,7 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
1010
1003
ARG_UNUSED (properties);
1011
1004
1012
1005
if ((Flags & PI_MEM_FLAGS_ACCESS_RW) == 0 ) {
1013
- if (PrintPiTrace) {
1014
- std::cerr << " Invalid memory attribute for piMemBufferCreate"
1015
- << std::endl;
1016
- }
1006
+ PiTrace (" Invalid memory attribute for piMemBufferCreate" );
1017
1007
return PI_ERROR_INVALID_OPERATION;
1018
1008
}
1019
1009
@@ -1069,9 +1059,11 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
1069
1059
}
1070
1060
1071
1061
std::lock_guard<std::mutex> Lock{*PiESimdSurfaceMapLock};
1072
- assert (PiESimdSurfaceMap->find ((*RetMem)->SurfaceIndex ) ==
1073
- PiESimdSurfaceMap->end () &&
1074
- " Failure from CM-managed buffer creation" );
1062
+ if (PiESimdSurfaceMap->find ((*RetMem)->SurfaceIndex ) !=
1063
+ PiESimdSurfaceMap->end ()) {
1064
+ PiTrace (" Failure from CM-managed buffer creation" );
1065
+ return PI_ERROR_INVALID_MEM_OBJECT;
1066
+ }
1075
1067
1076
1068
(*PiESimdSurfaceMap)[(*RetMem)->SurfaceIndex ] = *RetMem;
1077
1069
@@ -1099,8 +1091,10 @@ pi_result piMemRelease(pi_mem Mem) {
1099
1091
// Removing Surface-map entry
1100
1092
std::lock_guard<std::mutex> Lock{*PiESimdSurfaceMapLock};
1101
1093
auto MapEntryIt = PiESimdSurfaceMap->find (Mem->SurfaceIndex );
1102
- assert (MapEntryIt != PiESimdSurfaceMap->end () &&
1103
- " Failure from Buffer/Image deletion" );
1094
+ if (MapEntryIt == PiESimdSurfaceMap->end ()) {
1095
+ PiTrace (" Failure from Buffer/Image deletion" );
1096
+ return PI_ERROR_INVALID_MEM_OBJECT;
1097
+ }
1104
1098
PiESimdSurfaceMap->erase (MapEntryIt);
1105
1099
delete Mem;
1106
1100
}
@@ -1122,8 +1116,8 @@ _pi_mem::~_pi_mem() {
1122
1116
Status = CmDevice->DestroySurface (SurfacePtr.RegularImgPtr );
1123
1117
}
1124
1118
1125
- assert (Status == cm_support::CM_SUCCESS &&
1126
- " Surface Deletion Failure from CM_EMU" );
1119
+ cl::sycl::detail::pi::assertion (Status == cm_support::CM_SUCCESS &&
1120
+ " Surface Deletion Failure from CM_EMU" );
1127
1121
1128
1122
for (auto mapit = Mappings.begin (); mapit != Mappings.end ();) {
1129
1123
mapit = Mappings.erase (mapit);
@@ -1160,9 +1154,7 @@ pi_result piMemImageCreate(pi_context Context, pi_mem_flags Flags,
1160
1154
const pi_image_desc *ImageDesc, void *HostPtr,
1161
1155
pi_mem *RetImage) {
1162
1156
if ((Flags & PI_MEM_FLAGS_ACCESS_RW) == 0 ) {
1163
- if (PrintPiTrace) {
1164
- std::cerr << " Invalid memory attribute for piMemImageCreate" << std::endl;
1165
- }
1157
+ PiTrace (" Invalid memory attribute for piMemImageCreate" );
1166
1158
return PI_ERROR_INVALID_OPERATION;
1167
1159
}
1168
1160
@@ -1265,9 +1257,11 @@ pi_result piMemImageCreate(pi_context Context, pi_mem_flags Flags,
1265
1257
}
1266
1258
1267
1259
std::lock_guard<std::mutex> Lock{*PiESimdSurfaceMapLock};
1268
- assert (PiESimdSurfaceMap->find ((*RetImage)->SurfaceIndex ) ==
1269
- PiESimdSurfaceMap->end () &&
1270
- " Failure from CM-managed image creation" );
1260
+ if (PiESimdSurfaceMap->find ((*RetImage)->SurfaceIndex ) !=
1261
+ PiESimdSurfaceMap->end ()) {
1262
+ PiTrace (" Failure from CM-managed image creation" );
1263
+ return PI_ERROR_INVALID_VALUE;
1264
+ }
1271
1265
1272
1266
(*PiESimdSurfaceMap)[(*RetImage)->SurfaceIndex ] = *RetImage;
1273
1267
@@ -1397,10 +1391,7 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,
1397
1391
ARG_UNUSED (ParamValue);
1398
1392
ARG_UNUSED (ParamValueSizeRet);
1399
1393
1400
- if (PrintPiTrace) {
1401
- std::cerr << " Warning : Profiling Not supported under PI_ESIMD_EMULATOR"
1402
- << std::endl;
1403
- }
1394
+ PiTrace (" Warning : Profiling Not supported under PI_ESIMD_EMULATOR" );
1404
1395
return PI_SUCCESS;
1405
1396
}
1406
1397
@@ -1503,12 +1494,15 @@ pi_result piEnqueueMemBufferRead(pi_queue Queue, pi_mem Src,
1503
1494
1504
1495
// / TODO : Support Blocked read, 'Queue' handling
1505
1496
if (BlockingRead) {
1506
- assert (false &&
1507
- " ESIMD_EMULATOR support for blocking piEnqueueMemBufferRead is NYI" );
1497
+ PiTrace (
1498
+ " ESIMD_EMULATOR support for blocking piEnqueueMemBufferRead is NYI" );
1499
+ return PI_ERROR_INVALID_OPERATION;
1508
1500
}
1509
1501
1510
- assert (Offset == 0 &&
1511
- " ESIMD_EMULATOR does not support buffer reading with offsets" );
1502
+ if (Offset != 0 ) {
1503
+ PiTrace (" ESIMD_EMULATOR does not support buffer reading with offsets" );
1504
+ return PI_ERROR_INVALID_ARG_VALUE;
1505
+ }
1512
1506
1513
1507
if (NumEventsInWaitList != 0 ) {
1514
1508
return PI_ERROR_INVALID_EVENT_WAIT_LIST;
@@ -1527,7 +1521,9 @@ pi_result piEnqueueMemBufferRead(pi_queue Queue, pi_mem Src,
1527
1521
// Surface. memcpy is used for BufferRead PI_API call.
1528
1522
memcpy (Dst, buf->MapHostPtr , Size);
1529
1523
} else {
1530
- assert (buf->SurfacePtr .tag == cm_surface_ptr_t ::TypeRegularBuffer);
1524
+ if (buf->SurfacePtr .tag != cm_surface_ptr_t ::TypeRegularBuffer) {
1525
+ return PI_ERROR_INVALID_MEM_OBJECT;
1526
+ }
1531
1527
int Status = buf->SurfacePtr .RegularBufPtr ->ReadSurface (
1532
1528
reinterpret_cast <unsigned char *>(Dst),
1533
1529
nullptr , // event
@@ -1620,10 +1616,7 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem MemObj,
1620
1616
// because mapping already exists.
1621
1617
if (!Res.second ) {
1622
1618
ret = PI_ERROR_INVALID_VALUE;
1623
- if (PrintPiTrace) {
1624
- std::cerr << " piEnqueueMemBufferMap: duplicate mapping detected"
1625
- << std::endl;
1626
- }
1619
+ PiTrace (" piEnqueueMemBufferMap: duplicate mapping detected" );
1627
1620
}
1628
1621
}
1629
1622
@@ -1657,9 +1650,7 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
1657
1650
auto It = MemObj->Mappings .find (MappedPtr);
1658
1651
if (It == MemObj->Mappings .end ()) {
1659
1652
ret = PI_ERROR_INVALID_VALUE;
1660
- if (PrintPiTrace) {
1661
- std::cerr << " piEnqueueMemUnmap: unknown memory mapping" << std::endl;
1662
- }
1653
+ PiTrace (" piEnqueueMemUnmap: unknown memory mapping" );
1663
1654
}
1664
1655
MemObj->Mappings .erase (It);
1665
1656
}
@@ -1688,16 +1679,22 @@ pi_result piEnqueueMemImageRead(pi_queue CommandQueue, pi_mem Image,
1688
1679
1689
1680
// / TODO : Support Blocked read, 'Queue' handling
1690
1681
if (BlockingRead) {
1691
- assert (false && " ESIMD_EMULATOR does not support Blocking Read" );
1682
+ PiTrace (" ESIMD_EMULATOR support for blocking piEnqueueMemImageRead is NYI" );
1683
+ return PI_ERROR_INVALID_OPERATION;
1692
1684
}
1693
1685
1694
1686
// SlicePitch is for 3D image while ESIMD_EMULATOR does not
1695
1687
// support. For 2D surfaces, SlicePitch must be 0.
1696
- assert ((SlicePitch == 0 ) && " ESIMD_EMULATOR does not support 3D-image" );
1688
+ if (SlicePitch != 0 ) {
1689
+ PiTrace (" ESIMD_EMULATOR does not support 3D-image" );
1690
+ return PI_ERROR_INVALID_ARG_VALUE;
1691
+ }
1697
1692
1698
1693
// CM_EMU does not support ReadSurface with offset
1699
- assert (Origin->x == 0 && Origin->y == 0 && Origin->z == 0 &&
1700
- " ESIMD_EMULATOR does not support 2D-image reading with offsets" );
1694
+ if (Origin->x != 0 || Origin->y != 0 || Origin->z != 0 ) {
1695
+ PiTrace (" ESIMD_EMULATOR does not support 2D-image reading with offsets" );
1696
+ return PI_ERROR_INVALID_ARG_VALUE;
1697
+ }
1701
1698
1702
1699
_pi_image *PiImg = static_cast <_pi_image *>(Image);
1703
1700
@@ -1714,7 +1711,9 @@ pi_result piEnqueueMemImageRead(pi_queue CommandQueue, pi_mem Image,
1714
1711
// Surface. memcpy is used for ImageRead PI_API call.
1715
1712
memcpy (Ptr, PiImg->MapHostPtr , Size);
1716
1713
} else {
1717
- assert (PiImg->SurfacePtr .tag == cm_surface_ptr_t ::TypeRegularImage);
1714
+ if (PiImg->SurfacePtr .tag != cm_surface_ptr_t ::TypeRegularImage) {
1715
+ return PI_ERROR_INVALID_MEM_OBJECT;
1716
+ }
1718
1717
int Status = PiImg->SurfacePtr .RegularImgPtr ->ReadSurface (
1719
1718
reinterpret_cast <unsigned char *>(Ptr),
1720
1719
nullptr , // event
@@ -1949,11 +1948,7 @@ pi_result piextDeviceSelectBinary(pi_device, pi_device_binary *,
1949
1948
// / TODO : Support multiple images and enable selection algorithm
1950
1949
// / for the images
1951
1950
if (RawImgSize != 1 ) {
1952
- if (PrintPiTrace) {
1953
- std::cerr
1954
- << " Only single device binary image is supported in ESIMD_EMULATOR"
1955
- << std::endl;
1956
- }
1951
+ PiTrace (" Only single device binary image is supported in ESIMD_EMULATOR" );
1957
1952
return PI_ERROR_INVALID_VALUE;
1958
1953
}
1959
1954
*ImgInd = 0 ;
0 commit comments