Skip to content

Commit 36ca9f1

Browse files
committed
Change ur_native_handle_t to be uintptr_t
1 parent 00ca0da commit 36ca9f1

37 files changed

+93
-86
lines changed

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ typedef struct ur_queue_handle_t_ *ur_queue_handle_t;
394394

395395
///////////////////////////////////////////////////////////////////////////////
396396
/// @brief Handle of a native object
397-
typedef struct ur_native_handle_t_ *ur_native_handle_t;
397+
typedef uintptr_t ur_native_handle_t;
398398

399399
///////////////////////////////////////////////////////////////////////////////
400400
/// @brief Handle of a Sampler object

include/ur_print.hpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10376,8 +10376,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1037610376

1037710377
os << ".hNativePlatform = ";
1037810378

10379-
ur::details::printPtr(os,
10380-
*(params->phNativePlatform));
10379+
ur::details::printPtr(os, reinterpret_cast<void *>(
10380+
*(params->phNativePlatform)));
1038110381

1038210382
os << ", ";
1038310383
os << ".hAdapter = ";
@@ -10573,8 +10573,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1057310573

1057410574
os << ".hNativeContext = ";
1057510575

10576-
ur::details::printPtr(os,
10577-
*(params->phNativeContext));
10576+
ur::details::printPtr(os, reinterpret_cast<void *>(
10577+
*(params->phNativeContext)));
1057810578

1057910579
os << ", ";
1058010580
os << ".numDevices = ";
@@ -10783,8 +10783,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1078310783

1078410784
os << ".hNativeEvent = ";
1078510785

10786-
ur::details::printPtr(os,
10787-
*(params->phNativeEvent));
10786+
ur::details::printPtr(os, reinterpret_cast<void *>(
10787+
*(params->phNativeEvent)));
1078810788

1078910789
os << ", ";
1079010790
os << ".hContext = ";
@@ -11377,8 +11377,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1137711377

1137811378
os << ".hNativeProgram = ";
1137911379

11380-
ur::details::printPtr(os,
11381-
*(params->phNativeProgram));
11380+
ur::details::printPtr(os, reinterpret_cast<void *>(
11381+
*(params->phNativeProgram)));
1138211382

1138311383
os << ", ";
1138411384
os << ".hContext = ";
@@ -11597,8 +11597,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1159711597

1159811598
os << ".hNativeKernel = ";
1159911599

11600-
ur::details::printPtr(os,
11601-
*(params->phNativeKernel));
11600+
ur::details::printPtr(os, reinterpret_cast<void *>(
11601+
*(params->phNativeKernel)));
1160211602

1160311603
os << ", ";
1160411604
os << ".hContext = ";
@@ -12046,8 +12046,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1204612046

1204712047
os << ".hNativeQueue = ";
1204812048

12049-
ur::details::printPtr(os,
12050-
*(params->phNativeQueue));
12049+
ur::details::printPtr(os, reinterpret_cast<void *>(
12050+
*(params->phNativeQueue)));
1205112051

1205212052
os << ", ";
1205312053
os << ".hContext = ";
@@ -12220,8 +12220,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1222012220

1222112221
os << ".hNativeSampler = ";
1222212222

12223-
ur::details::printPtr(os,
12224-
*(params->phNativeSampler));
12223+
ur::details::printPtr(os, reinterpret_cast<void *>(
12224+
*(params->phNativeSampler)));
1222512225

1222612226
os << ", ";
1222712227
os << ".hContext = ";
@@ -12424,8 +12424,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1242412424

1242512425
os << ".hNativeMem = ";
1242612426

12427-
ur::details::printPtr(os,
12428-
*(params->phNativeMem));
12427+
ur::details::printPtr(os, reinterpret_cast<void *>(
12428+
*(params->phNativeMem)));
1242912429

1243012430
os << ", ";
1243112431
os << ".hContext = ";
@@ -12456,8 +12456,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1245612456

1245712457
os << ".hNativeMem = ";
1245812458

12459-
ur::details::printPtr(os,
12460-
*(params->phNativeMem));
12459+
ur::details::printPtr(os, reinterpret_cast<void *>(
12460+
*(params->phNativeMem)));
1246112461

1246212462
os << ", ";
1246312463
os << ".hContext = ";
@@ -17206,8 +17206,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1720617206

1720717207
os << ".hNativeDevice = ";
1720817208

17209-
ur::details::printPtr(os,
17210-
*(params->phNativeDevice));
17209+
ur::details::printPtr(os, reinterpret_cast<void *>(
17210+
*(params->phNativeDevice)));
1721117211

1721217212
os << ", ";
1721317213
os << ".hPlatform = ";

scripts/templates/api.h.mako

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ ${th.make_func_name(n, tags, obj)}(
121121
);
122122
## HANDLE #####################################################################
123123
%elif re.match(r"handle", obj['type']):
124-
%if 'alias' in obj:
124+
%if th.type_traits.is_native_handle(obj['name']):
125+
typedef uintptr_t ${th.subt(n, tags, obj['name'])};
126+
%elif 'alias' in obj:
125127
typedef ${th.subt(n, tags, obj['alias'])} ${th.subt(n, tags, obj['name'])};
126128
%else:
127129
typedef struct ${th.subt(n, tags, obj['name'])}_ *${th.subt(n, tags, obj['name'])};

scripts/templates/helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def get_handle(item, meta):
109109
"""
110110
class type_traits:
111111
RE_HANDLE = r"(.*)handle_t"
112+
RE_NATIVE_HANDLE = r"(.*)native_handle_t"
112113
RE_IPC = r"(.*)ipc(.*)handle_t"
113114
RE_POINTER = r"(.*\w+)\*+"
114115
RE_PPOINTER = r"(.*\w+)\*{2,}"
@@ -128,6 +129,13 @@ def is_handle(cls, name):
128129
except:
129130
return False
130131

132+
@classmethod
133+
def is_native_handle(cls, name):
134+
try:
135+
return True if re.match(cls.RE_NATIVE_HANDLE, name) else False
136+
except:
137+
return False
138+
131139
@classmethod
132140
def is_pointer_to_pointer(cls, name):
133141
try:

scripts/templates/print.hpp.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ from templates import helper as th
3636
${x}::details::printPtr(os, ${caller.body()});
3737
%elif loop and th.type_traits.is_pointer_to_pointer(itype):
3838
${x}::details::printPtr(os, ${caller.body()});
39+
%elif th.type_traits.is_native_handle(itype):
40+
${x}::details::printPtr(os, reinterpret_cast<void*>(${caller.body()}));
3941
%elif th.type_traits.is_handle(itype):
4042
${x}::details::printPtr(os, ${caller.body()});
4143
%elif iname and iname.startswith("pfn"):

source/adapters/cuda/device.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle(
11851185
ur_device_handle_t *phDevice) {
11861186
std::ignore = pProperties;
11871187

1188-
// We can't cast between ur_native_handle_t and CUdevice, so memcpy the bits
1189-
// instead
1190-
CUdevice CuDevice = 0;
1191-
memcpy(&CuDevice, &hNativeDevice, sizeof(CUdevice));
1188+
CUdevice CuDevice = static_cast<CUdevice>(hNativeDevice);
11921189

11931190
auto IsDevice = [=](std::unique_ptr<ur_device_handle_t_> &Dev) {
11941191
return Dev->get() == CuDevice;

source/adapters/cuda/memory.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
132132
ur_native_handle_t *phNativeMem) {
133133
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
134134
try {
135-
*phNativeMem = reinterpret_cast<ur_native_handle_t>(
136-
std::get<BufferMem>(hMem->Mem).getPtr(Device));
135+
*phNativeMem = std::get<BufferMem>(hMem->Mem).getPtr(Device);
137136
} catch (ur_result_t Err) {
138137
return Err;
139138
} catch (...) {

source/adapters/hip/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(ur_platform_handle_t hPlatform,
980980
/// \return UR_RESULT_SUCCESS
981981
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetNativeHandle(
982982
ur_device_handle_t hDevice, ur_native_handle_t *phNativeHandle) {
983-
*phNativeHandle = reinterpret_cast<ur_native_handle_t>(hDevice->get());
983+
*phNativeHandle = hDevice->get();
984984
return UR_RESULT_SUCCESS;
985985
}
986986

source/adapters/level_zero/event.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
926926

927927
// we dont have urEventCreate, so use this check for now to know that
928928
// the call comes from urEventCreate()
929-
if (NativeEvent == nullptr) {
929+
if (reinterpret_cast<ze_event_handle_t>(NativeEvent) == nullptr) {
930930
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
931931

932932
(*Event)->RefCountExternal++;

source/adapters/opencl/queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
167167

168168
*phQueue = reinterpret_cast<ur_queue_handle_t>(hNativeQueue);
169169
cl_int RetErr =
170-
clRetainCommandQueue(cl_adapter::cast<cl_command_queue>(hNativeQueue));
170+
clRetainCommandQueue(cl_adapter::cast<cl_command_queue>(*phQueue));
171171
CL_RETURN_ON_FAILURE(RetErr);
172172
return UR_RESULT_SUCCESS;
173173
}

0 commit comments

Comments
 (0)