Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1188,13 +1188,16 @@ typedef struct ur_platform_native_properties_t {
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hAdapter`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phPlatform`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
UR_APIEXPORT ur_result_t UR_APICALL
urPlatformCreateWithNativeHandle(
ur_native_handle_t hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *phPlatform ///< [out] pointer to the handle of the platform object created.
);
Expand Down Expand Up @@ -9552,6 +9555,7 @@ typedef struct ur_platform_get_native_handle_params_t {
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_platform_create_with_native_handle_params_t {
ur_native_handle_t *phNativePlatform;
ur_adapter_handle_t *phAdapter;
const ur_platform_native_properties_t **ppProperties;
ur_platform_handle_t **pphPlatform;
} ur_platform_create_with_native_handle_params_t;
Expand Down
1 change: 1 addition & 0 deletions include/ur_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetNativeHandle_t)(
/// @brief Function-pointer for urPlatformCreateWithNativeHandle
typedef ur_result_t(UR_APICALL *ur_pfnPlatformCreateWithNativeHandle_t)(
ur_native_handle_t,
ur_adapter_handle_t,
const ur_platform_native_properties_t *,
ur_platform_handle_t *);

Expand Down
6 changes: 6 additions & 0 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10214,6 +10214,12 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
ur::details::printPtr(os,
*(params->phNativePlatform));

os << ", ";
os << ".hAdapter = ";

ur::details::printPtr(os,
*(params->phAdapter));

os << ", ";
os << ".pProperties = ";

Expand Down
3 changes: 3 additions & 0 deletions scripts/core/platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ params:
- type: $x_native_handle_t
name: hNativePlatform
desc: "[in][nocheck] the native handle of the platform."
- type: $x_adapter_handle_t
name: hAdapter
desc: "[in] handle of the adapter associated with the native backend."
- type: const $x_platform_native_properties_t*
name: pProperties
desc: "[in][optional] pointer to native platform properties struct."
Expand Down
2 changes: 1 addition & 1 deletion scripts/templates/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def get_adapter_handles(specs):
objs = []
for s in specs:
for obj in s['objects']:
if obj_traits.is_handle(obj) and not obj_traits.is_loader_only(obj):
if obj_traits.is_handle(obj) and not (obj_traits.is_loader_only(obj) or 'native' in obj['name']):
objs.append(obj)

return objs
Expand Down
6 changes: 3 additions & 3 deletions scripts/templates/ldrddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace ur_loader
%else:
<%param_replacements={}%>
%for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)):
%if not '_native_object_' in item['obj'] or th.make_func_name(n, tags, obj) == 'urPlatformCreateWithNativeHandle':
%if not '_native_object_' in item['obj']:
// extract platform's function pointer table
auto dditable = reinterpret_cast<${item['obj']}*>( ${item['pointer']}${item['name']} )->dditable;
auto ${th.make_pfn_name(n, tags, obj)} = dditable->${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
Expand All @@ -151,7 +151,7 @@ namespace ur_loader
for( size_t i = ${item['range'][0]}; i < ${item['range'][1]}; ++i )
${item['name']}Local[ i ] = reinterpret_cast<${item['obj']}*>( ${item['name']}[ i ] )->handle;
%else:
%if not '_native_object_' in item['obj'] or th.make_func_name(n, tags, obj) == 'urPlatformCreateWithNativeHandle':
%if not '_native_object_' in item['obj']:
// convert loader handle to platform handle
%if item['optional']:
${item['name']} = ( ${item['name']} ) ? reinterpret_cast<${item['obj']}*>( ${item['name']} )->handle : nullptr;
Expand Down Expand Up @@ -279,7 +279,7 @@ namespace ur_loader
%if item['release']:
// release loader handle
${item['factory']}.release( ${item['name']} );
%elif not '_native_object_' in item['obj'] or th.make_func_name(n, tags, obj) == 'urPlatformCreateWithNativeHandle':
%elif not '_native_object_' in item['obj']:
try
{
%if 'typename' in item:
Expand Down
9 changes: 3 additions & 6 deletions source/adapters/cuda/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
}

UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t hNativePlatform,
const ur_platform_native_properties_t *pProperties,
ur_platform_handle_t *phPlatform) {
std::ignore = hNativePlatform;
std::ignore = pProperties;
std::ignore = phPlatform;
ur_native_handle_t, ur_adapter_handle_t,
const ur_platform_native_properties_t *, ur_platform_handle_t *) {
// There is no CUDA equivalent to ur_platform_handle_t
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down
9 changes: 3 additions & 6 deletions source/adapters/hip/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
}

UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t hNativePlatform,
const ur_platform_native_properties_t *pProperties,
ur_platform_handle_t *phPlatform) {
std::ignore = hNativePlatform;
std::ignore = pProperties;
std::ignore = phPlatform;
ur_native_handle_t, ur_adapter_handle_t,
const ur_platform_native_properties_t *, ur_platform_handle_t *) {
// There is no HIP equivalent to ur_platform_handle_t
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
NativePlatform, ///< [in] the native handle of the platform.
ur_adapter_handle_t,
const ur_platform_native_properties_t
*Properties, ///< [in][optional] pointer to native platform properties
///< struct.
Expand Down
9 changes: 2 additions & 7 deletions source/adapters/native_cpu/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption(
}

UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t hNativePlatform,
const ur_platform_native_properties_t *pProperties,
ur_platform_handle_t *phPlatform) {
std::ignore = hNativePlatform;
std::ignore = pProperties;
std::ignore = phPlatform;

ur_native_handle_t, ur_adapter_handle_t,
const ur_platform_native_properties_t *, ur_platform_handle_t *) {
DIE_NO_IMPLEMENTATION;
}

Expand Down
6 changes: 4 additions & 2 deletions source/adapters/null/ur_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetNativeHandle(
__urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t
hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *
pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *
Expand All @@ -274,8 +276,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
auto pfnCreateWithNativeHandle =
d_context.urDdiTable.Platform.pfnCreateWithNativeHandle;
if (nullptr != pfnCreateWithNativeHandle) {
result =
pfnCreateWithNativeHandle(hNativePlatform, pProperties, phPlatform);
result = pfnCreateWithNativeHandle(hNativePlatform, hAdapter,
pProperties, phPlatform);
} else {
// generic implementation
*phPlatform = reinterpret_cast<ur_platform_handle_t>(d_context.get());
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/opencl/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle(
}

UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t hNativePlatform, const ur_platform_native_properties_t *,
ur_platform_handle_t *phPlatform) {
ur_native_handle_t hNativePlatform, ur_adapter_handle_t,
const ur_platform_native_properties_t *, ur_platform_handle_t *phPlatform) {
*phPlatform = reinterpret_cast<ur_platform_handle_t>(hNativePlatform);
return UR_RESULT_SUCCESS;
}
Expand Down
8 changes: 5 additions & 3 deletions source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetNativeHandle(
__urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t
hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *
pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *
Expand All @@ -365,15 +367,15 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
}

ur_platform_create_with_native_handle_params_t params = {
&hNativePlatform, &pProperties, &phPlatform};
&hNativePlatform, &hAdapter, &pProperties, &phPlatform};
uint64_t instance =
context.notify_begin(UR_FUNCTION_PLATFORM_CREATE_WITH_NATIVE_HANDLE,
"urPlatformCreateWithNativeHandle", &params);

context.logger.info("---> urPlatformCreateWithNativeHandle");

ur_result_t result =
pfnCreateWithNativeHandle(hNativePlatform, pProperties, phPlatform);
ur_result_t result = pfnCreateWithNativeHandle(hNativePlatform, hAdapter,
pProperties, phPlatform);

context.notify_end(UR_FUNCTION_PLATFORM_CREATE_WITH_NATIVE_HANDLE,
"urPlatformCreateWithNativeHandle", &params, &result,
Expand Down
15 changes: 13 additions & 2 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetNativeHandle(
__urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t
hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *
pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *
Expand All @@ -360,13 +362,22 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
}

if (context.enableParameterValidation) {
if (NULL == hAdapter) {
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
}

if (NULL == phPlatform) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}
}

ur_result_t result =
pfnCreateWithNativeHandle(hNativePlatform, pProperties, phPlatform);
if (context.enableLifetimeValidation &&
!refCountContext.isReferenceValid(hAdapter)) {
refCountContext.logInvalidReference(hAdapter);
}

ur_result_t result = pfnCreateWithNativeHandle(hNativePlatform, hAdapter,
pProperties, phPlatform);

return result;
}
Expand Down
13 changes: 6 additions & 7 deletions source/loader/ur_ldrddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ur_event_factory_t ur_event_factory;
ur_program_factory_t ur_program_factory;
ur_kernel_factory_t ur_kernel_factory;
ur_queue_factory_t ur_queue_factory;
ur_native_factory_t ur_native_factory;
ur_sampler_factory_t ur_sampler_factory;
ur_mem_factory_t ur_mem_factory;
ur_physical_mem_factory_t ur_physical_mem_factory;
Expand Down Expand Up @@ -364,6 +363,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetNativeHandle(
__urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t
hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *
pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *
Expand All @@ -372,21 +373,19 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_result_t result = UR_RESULT_SUCCESS;

// extract platform's function pointer table
auto dditable =
reinterpret_cast<ur_native_object_t *>(hNativePlatform)->dditable;
auto dditable = reinterpret_cast<ur_adapter_object_t *>(hAdapter)->dditable;
auto pfnCreateWithNativeHandle =
dditable->ur.Platform.pfnCreateWithNativeHandle;
if (nullptr == pfnCreateWithNativeHandle) {
return UR_RESULT_ERROR_UNINITIALIZED;
}

// convert loader handle to platform handle
hNativePlatform =
reinterpret_cast<ur_native_object_t *>(hNativePlatform)->handle;
hAdapter = reinterpret_cast<ur_adapter_object_t *>(hAdapter)->handle;

// forward to device-platform
result =
pfnCreateWithNativeHandle(hNativePlatform, pProperties, phPlatform);
result = pfnCreateWithNativeHandle(hNativePlatform, hAdapter, pProperties,
phPlatform);

if (UR_RESULT_SUCCESS != result) {
return result;
Expand Down
4 changes: 0 additions & 4 deletions source/loader/ur_ldrddi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ using ur_queue_object_t = object_t<ur_queue_handle_t>;
using ur_queue_factory_t =
singleton_factory_t<ur_queue_object_t, ur_queue_handle_t>;

using ur_native_object_t = object_t<ur_native_handle_t>;
using ur_native_factory_t =
singleton_factory_t<ur_native_object_t, ur_native_handle_t>;

using ur_sampler_object_t = object_t<ur_sampler_handle_t>;
using ur_sampler_factory_t =
singleton_factory_t<ur_sampler_object_t, ur_sampler_handle_t>;
Expand Down
7 changes: 6 additions & 1 deletion source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,17 @@ ur_result_t UR_APICALL urPlatformGetNativeHandle(
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hAdapter`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phPlatform`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t
hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *
pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *
Expand All @@ -671,7 +675,8 @@ ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
return UR_RESULT_ERROR_UNINITIALIZED;
}

return pfnCreateWithNativeHandle(hNativePlatform, pProperties, phPlatform);
return pfnCreateWithNativeHandle(hNativePlatform, hAdapter, pProperties,
phPlatform);
} catch (...) {
return exceptionToResult(std::current_exception());
}
Expand Down
4 changes: 4 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,17 @@ ur_result_t UR_APICALL urPlatformGetNativeHandle(
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hAdapter`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phPlatform`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
ur_native_handle_t
hNativePlatform, ///< [in][nocheck] the native handle of the platform.
ur_adapter_handle_t
hAdapter, ///< [in] handle of the adapter associated with the native backend.
const ur_platform_native_properties_t *
pProperties, ///< [in][optional] pointer to native platform properties struct.
ur_platform_handle_t *
Expand Down
18 changes: 9 additions & 9 deletions test/conformance/platform/urPlatformCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ TEST_F(urPlatformCreateWithNativeHandleTest, Success) {
// We can however convert the native_handle back into a unified-runtime
// handle and perform some query on it to verify that it works.
ur_platform_handle_t plat = nullptr;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformCreateWithNativeHandle(native_handle, nullptr, &plat));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urPlatformCreateWithNativeHandle(
native_handle, adapters[0], nullptr, &plat));
ASSERT_NE(plat, nullptr);

std::string input_platform_name = uur::GetPlatformName(platform);
Expand All @@ -45,8 +45,8 @@ TEST_F(urPlatformCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
ur_platform_native_properties_t props = {
UR_STRUCTURE_TYPE_PLATFORM_NATIVE_PROPERTIES, nullptr, true};
ur_platform_handle_t plat = nullptr;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformCreateWithNativeHandle(native_handle, &props, &plat));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urPlatformCreateWithNativeHandle(
native_handle, adapters[0], &props, &plat));
ASSERT_NE(plat, nullptr);

std::string input_platform_name = uur::GetPlatformName(platform);
Expand All @@ -70,8 +70,8 @@ TEST_F(urPlatformCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {
ur_platform_native_properties_t props = {
UR_STRUCTURE_TYPE_PLATFORM_NATIVE_PROPERTIES, nullptr, false};
ur_platform_handle_t plat = nullptr;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformCreateWithNativeHandle(native_handle, &props, &plat));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urPlatformCreateWithNativeHandle(
native_handle, adapters[0], &props, &plat));
ASSERT_NE(plat, nullptr);

std::string input_platform_name = uur::GetPlatformName(platform);
Expand All @@ -84,8 +84,8 @@ TEST_F(urPlatformCreateWithNativeHandleTest, InvalidNullPointerPlatform) {
for (auto platform : platforms) {
ur_native_handle_t native_handle = nullptr;
ASSERT_SUCCESS(urPlatformGetNativeHandle(platform, &native_handle));
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_POINTER,
urPlatformCreateWithNativeHandle(native_handle, nullptr, nullptr));
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urPlatformCreateWithNativeHandle(
native_handle, adapters[0], nullptr, nullptr));
}
}