Skip to content

Commit b54b988

Browse files
committed
clean code
1 parent 7cac7c8 commit b54b988

File tree

2 files changed

+10
-175
lines changed

2 files changed

+10
-175
lines changed

source/adapters/level_zero/kernel.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -802,57 +802,3 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetSpecializationConstants(
802802
urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__);
803803
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
804804
}
805-
806-
UR_APIEXPORT ur_result_t UR_APICALL urGetKernelSuggestedLocalWorkSize(
807-
ur_queue_handle_t Queue, ur_kernel_handle_t Kernel, uint32_t workDim,
808-
const size_t *GlobalWorkOffset, const size_t *GlobalWorkSize,
809-
size_t *SuggestedLocalWorkSize) {
810-
std::ignore = workDim;
811-
std::ignore = GlobalWorkOffset;
812-
813-
uint32_t WG[3];
814-
auto Device = Queue->Device;
815-
816-
// We can't call to zeKernelSuggestGroupSize if 64-bit GlobalWorkSize
817-
// values do not fit to 32-bit that the API only supports currently.
818-
bool SuggestGroupSize = true;
819-
for (int I : {0, 1, 2}) {
820-
if (GlobalWorkSize[I] > UINT32_MAX) {
821-
SuggestGroupSize = false;
822-
}
823-
}
824-
825-
if (SuggestGroupSize) {
826-
ZE2UR_CALL(zeKernelSuggestGroupSize,
827-
(Kernel->ZeKernel, GlobalWorkSize[0], GlobalWorkSize[1],
828-
GlobalWorkSize[2], &WG[0], &WG[1], &WG[2]));
829-
} else {
830-
for (int I : {0, 1, 2}) {
831-
// Try to find a I-dimension WG size that the GlobalWorkSize[I] is
832-
// fully divisable with. Start with the max possible size in
833-
// each dimension.
834-
uint32_t GroupSize[] = {Device->ZeDeviceComputeProperties->maxGroupSizeX,
835-
Device->ZeDeviceComputeProperties->maxGroupSizeY,
836-
Device->ZeDeviceComputeProperties->maxGroupSizeZ};
837-
GroupSize[I] = (std::min)(size_t(GroupSize[I]), GlobalWorkSize[I]);
838-
while (GlobalWorkSize[I] % GroupSize[I]) {
839-
--GroupSize[I];
840-
}
841-
if (GlobalWorkSize[I] / GroupSize[I] > UINT32_MAX) {
842-
urPrint("urGetKernelSuggestedLocalWorkSize: can't find a WG size "
843-
"suitable for global work size > UINT32_MAX\n");
844-
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
845-
}
846-
WG[I] = GroupSize[I];
847-
}
848-
urPrint("urGetKernelSuggestedLocalWorkSize: using computed WG size = {%d, "
849-
"%d, %d}\n",
850-
WG[0], WG[1], WG[2]);
851-
}
852-
853-
SuggestedLocalWorkSize[0] = WG[0];
854-
SuggestedLocalWorkSize[1] = WG[1];
855-
SuggestedLocalWorkSize[2] = WG[2];
856-
857-
return UR_RESULT_SUCCESS;
858-
}

source/loader/ur_ldrddi.cpp

Lines changed: 10 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,6 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetNativeHandle(
352352
return result;
353353
}
354354

355-
try {
356-
// convert platform handle to loader handle
357-
*phNativePlatform = reinterpret_cast<ur_native_handle_t>(
358-
ur_native_factory.getInstance(*phNativePlatform, dditable));
359-
} catch (std::bad_alloc &) {
360-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
361-
}
362-
363355
return result;
364356
}
365357

@@ -718,14 +710,6 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGetNativeHandle(
718710
return result;
719711
}
720712

721-
try {
722-
// convert platform handle to loader handle
723-
*phNativeDevice = reinterpret_cast<ur_native_handle_t>(
724-
ur_native_factory.getInstance(*phNativeDevice, dditable));
725-
} catch (std::bad_alloc &) {
726-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
727-
}
728-
729713
return result;
730714
}
731715

@@ -744,17 +728,13 @@ __urdlllocal ur_result_t UR_APICALL urDeviceCreateWithNativeHandle(
744728

745729
// extract platform's function pointer table
746730
auto dditable =
747-
reinterpret_cast<ur_native_object_t *>(hNativeDevice)->dditable;
731+
reinterpret_cast<ur_platform_object_t *>(hPlatform)->dditable;
748732
auto pfnCreateWithNativeHandle =
749733
dditable->ur.Device.pfnCreateWithNativeHandle;
750734
if (nullptr == pfnCreateWithNativeHandle) {
751735
return UR_RESULT_ERROR_UNINITIALIZED;
752736
}
753737

754-
// convert loader handle to platform handle
755-
hNativeDevice =
756-
reinterpret_cast<ur_native_object_t *>(hNativeDevice)->handle;
757-
758738
// convert loader handle to platform handle
759739
hPlatform = reinterpret_cast<ur_platform_object_t *>(hPlatform)->handle;
760740

@@ -994,14 +974,6 @@ __urdlllocal ur_result_t UR_APICALL urContextGetNativeHandle(
994974
return result;
995975
}
996976

997-
try {
998-
// convert platform handle to loader handle
999-
*phNativeContext = reinterpret_cast<ur_native_handle_t>(
1000-
ur_native_factory.getInstance(*phNativeContext, dditable));
1001-
} catch (std::bad_alloc &) {
1002-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
1003-
}
1004-
1005977
return result;
1006978
}
1007979

@@ -1022,17 +994,13 @@ __urdlllocal ur_result_t UR_APICALL urContextCreateWithNativeHandle(
1022994

1023995
// extract platform's function pointer table
1024996
auto dditable =
1025-
reinterpret_cast<ur_native_object_t *>(hNativeContext)->dditable;
997+
reinterpret_cast<ur_device_object_t *>(*phDevices)->dditable;
1026998
auto pfnCreateWithNativeHandle =
1027999
dditable->ur.Context.pfnCreateWithNativeHandle;
10281000
if (nullptr == pfnCreateWithNativeHandle) {
10291001
return UR_RESULT_ERROR_UNINITIALIZED;
10301002
}
10311003

1032-
// convert loader handle to platform handle
1033-
hNativeContext =
1034-
reinterpret_cast<ur_native_object_t *>(hNativeContext)->handle;
1035-
10361004
// convert loader handles to platform handles
10371005
auto phDevicesLocal = std::vector<ur_device_handle_t>(numDevices);
10381006
for (size_t i = 0; i < numDevices; ++i) {
@@ -1285,14 +1253,6 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
12851253
return result;
12861254
}
12871255

1288-
try {
1289-
// convert platform handle to loader handle
1290-
*phNativeMem = reinterpret_cast<ur_native_handle_t>(
1291-
ur_native_factory.getInstance(*phNativeMem, dditable));
1292-
} catch (std::bad_alloc &) {
1293-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
1294-
}
1295-
12961256
return result;
12971257
}
12981258

@@ -1310,17 +1270,13 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle(
13101270
ur_result_t result = UR_RESULT_SUCCESS;
13111271

13121272
// extract platform's function pointer table
1313-
auto dditable =
1314-
reinterpret_cast<ur_native_object_t *>(hNativeMem)->dditable;
1273+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
13151274
auto pfnBufferCreateWithNativeHandle =
13161275
dditable->ur.Mem.pfnBufferCreateWithNativeHandle;
13171276
if (nullptr == pfnBufferCreateWithNativeHandle) {
13181277
return UR_RESULT_ERROR_UNINITIALIZED;
13191278
}
13201279

1321-
// convert loader handle to platform handle
1322-
hNativeMem = reinterpret_cast<ur_native_object_t *>(hNativeMem)->handle;
1323-
13241280
// convert loader handle to platform handle
13251281
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
13261282

@@ -1360,17 +1316,13 @@ __urdlllocal ur_result_t UR_APICALL urMemImageCreateWithNativeHandle(
13601316
ur_result_t result = UR_RESULT_SUCCESS;
13611317

13621318
// extract platform's function pointer table
1363-
auto dditable =
1364-
reinterpret_cast<ur_native_object_t *>(hNativeMem)->dditable;
1319+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
13651320
auto pfnImageCreateWithNativeHandle =
13661321
dditable->ur.Mem.pfnImageCreateWithNativeHandle;
13671322
if (nullptr == pfnImageCreateWithNativeHandle) {
13681323
return UR_RESULT_ERROR_UNINITIALIZED;
13691324
}
13701325

1371-
// convert loader handle to platform handle
1372-
hNativeMem = reinterpret_cast<ur_native_object_t *>(hNativeMem)->handle;
1373-
13741326
// convert loader handle to platform handle
13751327
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
13761328

@@ -1672,14 +1624,6 @@ __urdlllocal ur_result_t UR_APICALL urSamplerGetNativeHandle(
16721624
return result;
16731625
}
16741626

1675-
try {
1676-
// convert platform handle to loader handle
1677-
*phNativeSampler = reinterpret_cast<ur_native_handle_t>(
1678-
ur_native_factory.getInstance(*phNativeSampler, dditable));
1679-
} catch (std::bad_alloc &) {
1680-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
1681-
}
1682-
16831627
return result;
16841628
}
16851629

@@ -1697,18 +1641,13 @@ __urdlllocal ur_result_t UR_APICALL urSamplerCreateWithNativeHandle(
16971641
ur_result_t result = UR_RESULT_SUCCESS;
16981642

16991643
// extract platform's function pointer table
1700-
auto dditable =
1701-
reinterpret_cast<ur_native_object_t *>(hNativeSampler)->dditable;
1644+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
17021645
auto pfnCreateWithNativeHandle =
17031646
dditable->ur.Sampler.pfnCreateWithNativeHandle;
17041647
if (nullptr == pfnCreateWithNativeHandle) {
17051648
return UR_RESULT_ERROR_UNINITIALIZED;
17061649
}
17071650

1708-
// convert loader handle to platform handle
1709-
hNativeSampler =
1710-
reinterpret_cast<ur_native_object_t *>(hNativeSampler)->handle;
1711-
17121651
// convert loader handle to platform handle
17131652
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
17141653

@@ -2871,14 +2810,6 @@ __urdlllocal ur_result_t UR_APICALL urProgramGetNativeHandle(
28712810
return result;
28722811
}
28732812

2874-
try {
2875-
// convert platform handle to loader handle
2876-
*phNativeProgram = reinterpret_cast<ur_native_handle_t>(
2877-
ur_native_factory.getInstance(*phNativeProgram, dditable));
2878-
} catch (std::bad_alloc &) {
2879-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
2880-
}
2881-
28822813
return result;
28832814
}
28842815

@@ -2896,18 +2827,13 @@ __urdlllocal ur_result_t UR_APICALL urProgramCreateWithNativeHandle(
28962827
ur_result_t result = UR_RESULT_SUCCESS;
28972828

28982829
// extract platform's function pointer table
2899-
auto dditable =
2900-
reinterpret_cast<ur_native_object_t *>(hNativeProgram)->dditable;
2830+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
29012831
auto pfnCreateWithNativeHandle =
29022832
dditable->ur.Program.pfnCreateWithNativeHandle;
29032833
if (nullptr == pfnCreateWithNativeHandle) {
29042834
return UR_RESULT_ERROR_UNINITIALIZED;
29052835
}
29062836

2907-
// convert loader handle to platform handle
2908-
hNativeProgram =
2909-
reinterpret_cast<ur_native_object_t *>(hNativeProgram)->handle;
2910-
29112837
// convert loader handle to platform handle
29122838
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
29132839

@@ -3400,14 +3326,6 @@ __urdlllocal ur_result_t UR_APICALL urKernelGetNativeHandle(
34003326
return result;
34013327
}
34023328

3403-
try {
3404-
// convert platform handle to loader handle
3405-
*phNativeKernel = reinterpret_cast<ur_native_handle_t>(
3406-
ur_native_factory.getInstance(*phNativeKernel, dditable));
3407-
} catch (std::bad_alloc &) {
3408-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
3409-
}
3410-
34113329
return result;
34123330
}
34133331

@@ -3427,18 +3345,13 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
34273345
ur_result_t result = UR_RESULT_SUCCESS;
34283346

34293347
// extract platform's function pointer table
3430-
auto dditable =
3431-
reinterpret_cast<ur_native_object_t *>(hNativeKernel)->dditable;
3348+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
34323349
auto pfnCreateWithNativeHandle =
34333350
dditable->ur.Kernel.pfnCreateWithNativeHandle;
34343351
if (nullptr == pfnCreateWithNativeHandle) {
34353352
return UR_RESULT_ERROR_UNINITIALIZED;
34363353
}
34373354

3438-
// convert loader handle to platform handle
3439-
hNativeKernel =
3440-
reinterpret_cast<ur_native_object_t *>(hNativeKernel)->handle;
3441-
34423355
// convert loader handle to platform handle
34433356
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
34443357

@@ -3668,14 +3581,6 @@ __urdlllocal ur_result_t UR_APICALL urQueueGetNativeHandle(
36683581
return result;
36693582
}
36703583

3671-
try {
3672-
// convert platform handle to loader handle
3673-
*phNativeQueue = reinterpret_cast<ur_native_handle_t>(
3674-
ur_native_factory.getInstance(*phNativeQueue, dditable));
3675-
} catch (std::bad_alloc &) {
3676-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
3677-
}
3678-
36793584
return result;
36803585
}
36813586

@@ -3694,17 +3599,13 @@ __urdlllocal ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
36943599
ur_result_t result = UR_RESULT_SUCCESS;
36953600

36963601
// extract platform's function pointer table
3697-
auto dditable =
3698-
reinterpret_cast<ur_native_object_t *>(hNativeQueue)->dditable;
3602+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
36993603
auto pfnCreateWithNativeHandle =
37003604
dditable->ur.Queue.pfnCreateWithNativeHandle;
37013605
if (nullptr == pfnCreateWithNativeHandle) {
37023606
return UR_RESULT_ERROR_UNINITIALIZED;
37033607
}
37043608

3705-
// convert loader handle to platform handle
3706-
hNativeQueue = reinterpret_cast<ur_native_object_t *>(hNativeQueue)->handle;
3707-
37083609
// convert loader handle to platform handle
37093610
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
37103611

@@ -3985,14 +3886,6 @@ __urdlllocal ur_result_t UR_APICALL urEventGetNativeHandle(
39853886
return result;
39863887
}
39873888

3988-
try {
3989-
// convert platform handle to loader handle
3990-
*phNativeEvent = reinterpret_cast<ur_native_handle_t>(
3991-
ur_native_factory.getInstance(*phNativeEvent, dditable));
3992-
} catch (std::bad_alloc &) {
3993-
result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
3994-
}
3995-
39963889
return result;
39973890
}
39983891

@@ -4010,17 +3903,13 @@ __urdlllocal ur_result_t UR_APICALL urEventCreateWithNativeHandle(
40103903
ur_result_t result = UR_RESULT_SUCCESS;
40113904

40123905
// extract platform's function pointer table
4013-
auto dditable =
4014-
reinterpret_cast<ur_native_object_t *>(hNativeEvent)->dditable;
3906+
auto dditable = reinterpret_cast<ur_context_object_t *>(hContext)->dditable;
40153907
auto pfnCreateWithNativeHandle =
40163908
dditable->ur.Event.pfnCreateWithNativeHandle;
40173909
if (nullptr == pfnCreateWithNativeHandle) {
40183910
return UR_RESULT_ERROR_UNINITIALIZED;
40193911
}
40203912

4021-
// convert loader handle to platform handle
4022-
hNativeEvent = reinterpret_cast<ur_native_object_t *>(hNativeEvent)->handle;
4023-
40243913
// convert loader handle to platform handle
40253914
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
40263915

@@ -9099,4 +8988,4 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetDeviceProcAddrTable(
90998988

91008989
#if defined(__cplusplus)
91018990
}
9102-
#endif
8991+
#endif

0 commit comments

Comments
 (0)