Skip to content

Commit a53f89d

Browse files
authored
Merge pull request #1692 from aarongreig/aaron/platformCreateWithNativeAdapter
Add hAdapter parameter to urPlatformCreateWithNativeHandle
2 parents 6d053bc + fcecc00 commit a53f89d

File tree

19 files changed

+76
-53
lines changed

19 files changed

+76
-53
lines changed

include/ur_api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,13 +1188,16 @@ typedef struct ur_platform_native_properties_t {
11881188
/// - ::UR_RESULT_ERROR_UNINITIALIZED
11891189
/// - ::UR_RESULT_ERROR_DEVICE_LOST
11901190
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
1191+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
1192+
/// + `NULL == hAdapter`
11911193
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
11921194
/// + `NULL == phPlatform`
11931195
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
11941196
/// + If the adapter has no underlying equivalent handle.
11951197
UR_APIEXPORT ur_result_t UR_APICALL
11961198
urPlatformCreateWithNativeHandle(
11971199
ur_native_handle_t hNativePlatform, ///< [in][nocheck] the native handle of the platform.
1200+
ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter associated with the native backend.
11981201
const ur_platform_native_properties_t *pProperties, ///< [in][optional] pointer to native platform properties struct.
11991202
ur_platform_handle_t *phPlatform ///< [out] pointer to the handle of the platform object created.
12001203
);
@@ -9555,6 +9558,7 @@ typedef struct ur_platform_get_native_handle_params_t {
95559558
/// allowing the callback the ability to modify the parameter's value
95569559
typedef struct ur_platform_create_with_native_handle_params_t {
95579560
ur_native_handle_t *phNativePlatform;
9561+
ur_adapter_handle_t *phAdapter;
95589562
const ur_platform_native_properties_t **ppProperties;
95599563
ur_platform_handle_t **pphPlatform;
95609564
} ur_platform_create_with_native_handle_params_t;

include/ur_ddi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetNativeHandle_t)(
4949
/// @brief Function-pointer for urPlatformCreateWithNativeHandle
5050
typedef ur_result_t(UR_APICALL *ur_pfnPlatformCreateWithNativeHandle_t)(
5151
ur_native_handle_t,
52+
ur_adapter_handle_t,
5253
const ur_platform_native_properties_t *,
5354
ur_platform_handle_t *);
5455

include/ur_print.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10214,6 +10214,12 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1021410214
ur::details::printPtr(os,
1021510215
*(params->phNativePlatform));
1021610216

10217+
os << ", ";
10218+
os << ".hAdapter = ";
10219+
10220+
ur::details::printPtr(os,
10221+
*(params->phAdapter));
10222+
1021710223
os << ", ";
1021810224
os << ".pProperties = ";
1021910225

scripts/core/platform.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ params:
211211
- type: $x_native_handle_t
212212
name: hNativePlatform
213213
desc: "[in][nocheck] the native handle of the platform."
214+
- type: $x_adapter_handle_t
215+
name: hAdapter
216+
desc: "[in] handle of the adapter associated with the native backend."
214217
- type: const $x_platform_native_properties_t*
215218
name: pProperties
216219
desc: "[in][optional] pointer to native platform properties struct."

scripts/templates/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def get_adapter_handles(specs):
653653
objs = []
654654
for s in specs:
655655
for obj in s['objects']:
656-
if obj_traits.is_handle(obj) and not obj_traits.is_loader_only(obj):
656+
if obj_traits.is_handle(obj) and not (obj_traits.is_loader_only(obj) or 'native' in obj['name']):
657657
objs.append(obj)
658658

659659
return objs

scripts/templates/ldrddi.cpp.mako

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace ur_loader
132132
%else:
133133
<%param_replacements={}%>
134134
%for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)):
135-
%if not '_native_object_' in item['obj'] or th.make_func_name(n, tags, obj) == 'urPlatformCreateWithNativeHandle':
135+
%if not '_native_object_' in item['obj']:
136136
// extract platform's function pointer table
137137
auto dditable = reinterpret_cast<${item['obj']}*>( ${item['pointer']}${item['name']} )->dditable;
138138
auto ${th.make_pfn_name(n, tags, obj)} = dditable->${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
@@ -151,7 +151,7 @@ namespace ur_loader
151151
for( size_t i = ${item['range'][0]}; i < ${item['range'][1]}; ++i )
152152
${item['name']}Local[ i ] = reinterpret_cast<${item['obj']}*>( ${item['name']}[ i ] )->handle;
153153
%else:
154-
%if not '_native_object_' in item['obj'] or th.make_func_name(n, tags, obj) == 'urPlatformCreateWithNativeHandle':
154+
%if not '_native_object_' in item['obj']:
155155
// convert loader handle to platform handle
156156
%if item['optional']:
157157
${item['name']} = ( ${item['name']} ) ? reinterpret_cast<${item['obj']}*>( ${item['name']} )->handle : nullptr;
@@ -279,7 +279,7 @@ namespace ur_loader
279279
%if item['release']:
280280
// release loader handle
281281
${item['factory']}.release( ${item['name']} );
282-
%elif not '_native_object_' in item['obj'] or th.make_func_name(n, tags, obj) == 'urPlatformCreateWithNativeHandle':
282+
%elif not '_native_object_' in item['obj']:
283283
try
284284
{
285285
%if 'typename' in item:

source/adapters/cuda/platform.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
141141
}
142142

143143
UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
144-
ur_native_handle_t hNativePlatform,
145-
const ur_platform_native_properties_t *pProperties,
146-
ur_platform_handle_t *phPlatform) {
147-
std::ignore = hNativePlatform;
148-
std::ignore = pProperties;
149-
std::ignore = phPlatform;
144+
ur_native_handle_t, ur_adapter_handle_t,
145+
const ur_platform_native_properties_t *, ur_platform_handle_t *) {
146+
// There is no CUDA equivalent to ur_platform_handle_t
150147
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
151148
}
152149

source/adapters/hip/platform.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
135135
}
136136

137137
UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
138-
ur_native_handle_t hNativePlatform,
139-
const ur_platform_native_properties_t *pProperties,
140-
ur_platform_handle_t *phPlatform) {
141-
std::ignore = hNativePlatform;
142-
std::ignore = pProperties;
143-
std::ignore = phPlatform;
138+
ur_native_handle_t, ur_adapter_handle_t,
139+
const ur_platform_native_properties_t *, ur_platform_handle_t *) {
140+
// There is no HIP equivalent to ur_platform_handle_t
144141
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
145142
}
146143

source/adapters/level_zero/platform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
123123
UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
124124
ur_native_handle_t
125125
NativePlatform, ///< [in] the native handle of the platform.
126+
ur_adapter_handle_t,
126127
const ur_platform_native_properties_t
127128
*Properties, ///< [in][optional] pointer to native platform properties
128129
///< struct.

source/adapters/native_cpu/platform.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption(
9696
}
9797

9898
UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
99-
ur_native_handle_t hNativePlatform,
100-
const ur_platform_native_properties_t *pProperties,
101-
ur_platform_handle_t *phPlatform) {
102-
std::ignore = hNativePlatform;
103-
std::ignore = pProperties;
104-
std::ignore = phPlatform;
105-
99+
ur_native_handle_t, ur_adapter_handle_t,
100+
const ur_platform_native_properties_t *, ur_platform_handle_t *) {
106101
DIE_NO_IMPLEMENTATION;
107102
}
108103

0 commit comments

Comments
 (0)