Skip to content

Commit fa6bf97

Browse files
authored
Merge pull request #1856 from aarongreig/aaron/fixContextCreateWithNative
Make urContextCreateWithNativeHandle work for SYCL use with loader
2 parents a1295ba + 863c761 commit fa6bf97

File tree

22 files changed

+172
-115
lines changed

22 files changed

+172
-115
lines changed

include/ur_api.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,16 +2401,19 @@ typedef struct ur_context_native_properties_t {
24012401
/// - ::UR_RESULT_ERROR_UNINITIALIZED
24022402
/// - ::UR_RESULT_ERROR_DEVICE_LOST
24032403
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
2404+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
2405+
/// + `NULL == hAdapter`
24042406
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
2405-
/// + `NULL == phDevices`
24062407
/// + `NULL == phContext`
24072408
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
24082409
/// + If the adapter has no underlying equivalent handle.
24092410
UR_APIEXPORT ur_result_t UR_APICALL
24102411
urContextCreateWithNativeHandle(
24112412
ur_native_handle_t hNativeContext, ///< [in][nocheck] the native handle of the context.
2413+
ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter that owns the native handle
24122414
uint32_t numDevices, ///< [in] number of devices associated with the context
2413-
const ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] list of devices associated with the context
2415+
const ur_device_handle_t *phDevices, ///< [in][optional][range(0, numDevices)] list of devices associated with
2416+
///< the context
24142417
const ur_context_native_properties_t *pProperties, ///< [in][optional] pointer to native context properties struct
24152418
ur_context_handle_t *phContext ///< [out] pointer to the handle of the context object created.
24162419
);
@@ -5627,7 +5630,6 @@ typedef struct ur_queue_native_properties_t {
56275630
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
56285631
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
56295632
/// + `NULL == hContext`
5630-
/// + `NULL == hDevice`
56315633
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
56325634
/// + `NULL == phQueue`
56335635
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
@@ -5636,7 +5638,7 @@ UR_APIEXPORT ur_result_t UR_APICALL
56365638
urQueueCreateWithNativeHandle(
56375639
ur_native_handle_t hNativeQueue, ///< [in][nocheck] the native handle of the queue.
56385640
ur_context_handle_t hContext, ///< [in] handle of the context object
5639-
ur_device_handle_t hDevice, ///< [in] handle of the device object
5641+
ur_device_handle_t hDevice, ///< [in][optional] handle of the device object
56405642
const ur_queue_native_properties_t *pProperties, ///< [in][optional] pointer to native queue properties struct
56415643
ur_queue_handle_t *phQueue ///< [out] pointer to the handle of the queue object created.
56425644
);
@@ -9824,6 +9826,7 @@ typedef struct ur_context_get_native_handle_params_t {
98249826
/// allowing the callback the ability to modify the parameter's value
98259827
typedef struct ur_context_create_with_native_handle_params_t {
98269828
ur_native_handle_t *phNativeContext;
9829+
ur_adapter_handle_t *phAdapter;
98279830
uint32_t *pnumDevices;
98289831
const ur_device_handle_t **pphDevices;
98299832
const ur_context_native_properties_t **ppProperties;

include/ur_ddi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ typedef ur_result_t(UR_APICALL *ur_pfnContextGetNativeHandle_t)(
135135
/// @brief Function-pointer for urContextCreateWithNativeHandle
136136
typedef ur_result_t(UR_APICALL *ur_pfnContextCreateWithNativeHandle_t)(
137137
ur_native_handle_t,
138+
ur_adapter_handle_t,
138139
uint32_t,
139140
const ur_device_handle_t *,
140141
const ur_context_native_properties_t *,

include/ur_print.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10668,6 +10668,12 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1066810668
ur::details::printPtr(os, reinterpret_cast<void *>(
1066910669
*(params->phNativeContext)));
1067010670

10671+
os << ", ";
10672+
os << ".hAdapter = ";
10673+
10674+
ur::details::printPtr(os,
10675+
*(params->phAdapter));
10676+
1067110677
os << ", ";
1067210678
os << ".numDevices = ";
1067310679

scripts/core/context.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,15 @@ params:
228228
name: hNativeContext
229229
desc: |
230230
[in][nocheck] the native handle of the context.
231+
- type: $x_adapter_handle_t
232+
name: hAdapter
233+
desc: "[in] handle of the adapter that owns the native handle"
231234
- type: uint32_t
232235
name: numDevices
233236
desc: "[in] number of devices associated with the context"
234237
- type: "const $x_device_handle_t*"
235238
name: phDevices
236-
desc: "[in][range(0, numDevices)] list of devices associated with the context"
239+
desc: "[in][optional][range(0, numDevices)] list of devices associated with the context"
237240
- type: "const $x_context_native_properties_t*"
238241
name: pProperties
239242
desc: "[in][optional] pointer to native context properties struct"

scripts/core/queue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ params:
286286
desc: "[in] handle of the context object"
287287
- type: $x_device_handle_t
288288
name: hDevice
289-
desc: "[in] handle of the device object"
289+
desc: "[in][optional] handle of the device object"
290290
- type: "const $x_queue_native_properties_t*"
291291
name: pProperties
292292
desc: "[in][optional] pointer to native queue properties struct"

source/adapters/cuda/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
143143

144144
UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
145145
[[maybe_unused]] ur_native_handle_t hNativeContext,
146+
[[maybe_unused]] ur_adapter_handle_t hAdapter,
146147
[[maybe_unused]] uint32_t numDevices,
147148
[[maybe_unused]] const ur_device_handle_t *phDevices,
148149
[[maybe_unused]] const ur_context_native_properties_t *pProperties,

source/adapters/hip/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
122122

123123
UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
124124
[[maybe_unused]] ur_native_handle_t hNativeContext,
125+
[[maybe_unused]] ur_adapter_handle_t hAdapter,
125126
[[maybe_unused]] uint32_t numDevices,
126127
[[maybe_unused]] const ur_device_handle_t *phDevices,
127128
[[maybe_unused]] const ur_context_native_properties_t *pProperties,

source/adapters/level_zero/context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
147147
UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
148148
ur_native_handle_t
149149
NativeContext, ///< [in] the native handle of the context.
150-
uint32_t NumDevices, const ur_device_handle_t *Devices,
150+
ur_adapter_handle_t, uint32_t NumDevices, const ur_device_handle_t *Devices,
151151
const ur_context_native_properties_t *Properties,
152152
ur_context_handle_t
153153
*Context ///< [out] pointer to the handle of the context object created.

source/adapters/mock/ur_mockddi.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,10 +1264,13 @@ __urdlllocal ur_result_t UR_APICALL urContextGetNativeHandle(
12641264
/// @brief Intercept function for urContextCreateWithNativeHandle
12651265
__urdlllocal ur_result_t UR_APICALL urContextCreateWithNativeHandle(
12661266
ur_native_handle_t
1267-
hNativeContext, ///< [in][nocheck] the native handle of the context.
1267+
hNativeContext, ///< [in][nocheck] the native handle of the context.
1268+
ur_adapter_handle_t
1269+
hAdapter, ///< [in] handle of the adapter that owns the native handle
12681270
uint32_t numDevices, ///< [in] number of devices associated with the context
12691271
const ur_device_handle_t *
1270-
phDevices, ///< [in][range(0, numDevices)] list of devices associated with the context
1272+
phDevices, ///< [in][optional][range(0, numDevices)] list of devices associated with
1273+
///< the context
12711274
const ur_context_native_properties_t *
12721275
pProperties, ///< [in][optional] pointer to native context properties struct
12731276
ur_context_handle_t *
@@ -1276,7 +1279,8 @@ __urdlllocal ur_result_t UR_APICALL urContextCreateWithNativeHandle(
12761279
ur_result_t result = UR_RESULT_SUCCESS;
12771280

12781281
ur_context_create_with_native_handle_params_t params = {
1279-
&hNativeContext, &numDevices, &phDevices, &pProperties, &phContext};
1282+
&hNativeContext, &hAdapter, &numDevices,
1283+
&phDevices, &pProperties, &phContext};
12801284

12811285
auto beforeCallback = reinterpret_cast<ur_mock_callback_t>(
12821286
mock::getCallbacks().get_before_callback(
@@ -4841,7 +4845,7 @@ __urdlllocal ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
48414845
ur_native_handle_t
48424846
hNativeQueue, ///< [in][nocheck] the native handle of the queue.
48434847
ur_context_handle_t hContext, ///< [in] handle of the context object
4844-
ur_device_handle_t hDevice, ///< [in] handle of the device object
4848+
ur_device_handle_t hDevice, ///< [in][optional] handle of the device object
48454849
const ur_queue_native_properties_t *
48464850
pProperties, ///< [in][optional] pointer to native queue properties struct
48474851
ur_queue_handle_t

source/adapters/native_cpu/context.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
7979
}
8080

8181
UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
82-
ur_native_handle_t hNativeContext, uint32_t numDevices,
83-
const ur_device_handle_t *phDevices,
82+
ur_native_handle_t hNativeContext, ur_adapter_handle_t hAdapter,
83+
uint32_t numDevices, const ur_device_handle_t *phDevices,
8484
const ur_context_native_properties_t *pProperties,
8585
ur_context_handle_t *phContext) {
8686
std::ignore = hNativeContext;
87+
std::ignore = hAdapter;
8788
std::ignore = numDevices;
8889
std::ignore = phDevices;
8990
std::ignore = pProperties;

0 commit comments

Comments
 (0)