Skip to content

Commit c67d128

Browse files
committed
Add query to retrieve adapter handle from platform.
1 parent 0c60db6 commit c67d128

File tree

17 files changed

+115
-9
lines changed

17 files changed

+115
-9
lines changed

include/ur_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,8 @@ typedef enum ur_platform_info_t {
10871087
///< info needs to be dynamically queried.
10881088
UR_PLATFORM_INFO_BACKEND = 6, ///< [::ur_platform_backend_t] The backend of the platform. Identifies the
10891089
///< native backend adapter implementing this platform.
1090+
UR_PLATFORM_INFO_ADAPTER = 7, ///< [::ur_adapter_handle_t] The adapter handle associated with the
1091+
///< platform.
10901092
/// @cond
10911093
UR_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
10921094
/// @endcond
@@ -1112,7 +1114,7 @@ typedef enum ur_platform_info_t {
11121114
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
11131115
/// + `NULL == hPlatform`
11141116
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
1115-
/// + `::UR_PLATFORM_INFO_BACKEND < propName`
1117+
/// + `::UR_PLATFORM_INFO_ADAPTER < propName`
11161118
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
11171119
/// + If `propName` is not supported by the adapter.
11181120
/// - ::UR_RESULT_ERROR_INVALID_SIZE

include/ur_print.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_platform_info_t value)
20242024
case UR_PLATFORM_INFO_BACKEND:
20252025
os << "UR_PLATFORM_INFO_BACKEND";
20262026
break;
2027+
case UR_PLATFORM_INFO_ADAPTER:
2028+
os << "UR_PLATFORM_INFO_ADAPTER";
2029+
break;
20272030
default:
20282031
os << "unknown enumerator";
20292032
break;
@@ -2077,6 +2080,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_platform_in
20772080

20782081
os << ")";
20792082
} break;
2083+
case UR_PLATFORM_INFO_ADAPTER: {
2084+
const ur_adapter_handle_t *tptr = (const ur_adapter_handle_t *)ptr;
2085+
if (sizeof(ur_adapter_handle_t) > size) {
2086+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_adapter_handle_t) << ")";
2087+
return UR_RESULT_ERROR_INVALID_SIZE;
2088+
}
2089+
os << (const void *)(tptr) << " (";
2090+
2091+
ur::details::printPtr(os,
2092+
*tptr);
2093+
2094+
os << ")";
2095+
} break;
20802096
default:
20812097
os << "unknown enumerator";
20822098
return UR_RESULT_ERROR_INVALID_ENUMERATION;

scripts/core/platform.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ etors:
7777
- name: BACKEND
7878
value: "6"
7979
desc: "[$x_platform_backend_t] The backend of the platform. Identifies the native backend adapter implementing this platform."
80-
80+
- name: ADAPTER
81+
value: "7"
82+
desc: "[$x_adapter_handle_t] The adapter handle associated with the platform."
8183
--- #--------------------------------------------------------------------------
8284
type: function
8385
desc: "Retrieves various information about platform"

source/adapters/cuda/platform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "platform.hpp"
12+
#include "adapter.hpp"
1213
#include "common.hpp"
1314
#include "context.hpp"
1415
#include "device.hpp"
@@ -41,6 +42,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo(
4142
case UR_PLATFORM_INFO_BACKEND: {
4243
return ReturnValue(UR_PLATFORM_BACKEND_CUDA);
4344
}
45+
case UR_PLATFORM_INFO_ADAPTER: {
46+
return ReturnValue(&adapter);
47+
}
4448
default:
4549
return UR_RESULT_ERROR_INVALID_ENUMERATION;
4650
}

source/adapters/hip/platform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "platform.hpp"
12+
#include "adapter.hpp"
1213
#include "context.hpp"
1314

1415
UR_APIEXPORT ur_result_t UR_APICALL
@@ -34,6 +35,9 @@ urPlatformGetInfo(ur_platform_handle_t, ur_platform_info_t propName,
3435
case UR_PLATFORM_INFO_EXTENSIONS: {
3536
return ReturnValue("");
3637
}
38+
case UR_PLATFORM_INFO_ADAPTER: {
39+
return ReturnValue(&adapter);
40+
}
3741
default:
3842
return UR_RESULT_ERROR_INVALID_ENUMERATION;
3943
}

source/adapters/level_zero/platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ ur_result_t urPlatformGetInfo(
9595
return ReturnValue(Platform->ZeDriverApiVersion.c_str());
9696
case UR_PLATFORM_INFO_BACKEND:
9797
return ReturnValue(UR_PLATFORM_BACKEND_LEVEL_ZERO);
98+
case UR_PLATFORM_INFO_ADAPTER:
99+
return ReturnValue(GlobalAdapter);
98100
default:
99101
logger::debug("urPlatformGetInfo: unrecognized ParamName");
100102
return UR_RESULT_ERROR_INVALID_VALUE;

source/adapters/native_cpu/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(TARGET_NAME ur_adapter_native_cpu)
99

1010
add_ur_adapter(${TARGET_NAME}
1111
SHARED
12+
${CMAKE_CURRENT_SOURCE_DIR}/adapter.hpp
1213
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp
1314
${CMAKE_CURRENT_SOURCE_DIR}/command_buffer.cpp
1415
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp

source/adapters/native_cpu/adapter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99
//===----------------------------------------------------------------------===//
1010

11+
#include "adapter.hpp"
1112
#include "common.hpp"
1213
#include "ur_api.h"
1314

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===---------------- adapter.hpp - Native CPU Adapter --------------------===//
2+
//
3+
// Copyright (C) 2024 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
struct ur_adapter_handle_t_;
12+
13+
extern ur_adapter_handle_t_ Adapter;

source/adapters/native_cpu/platform.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "platform.hpp"
12+
#include "adapter.hpp"
1213
#include "common.hpp"
1314

1415
#include "ur/ur.hpp"
@@ -75,9 +76,9 @@ urPlatformGetInfo(ur_platform_handle_t hPlatform, ur_platform_info_t propName,
7576
return ReturnValue("");
7677

7778
case UR_PLATFORM_INFO_BACKEND:
78-
// TODO(alcpz): PR with this enum value at
79-
// https://github.com/oneapi-src/unified-runtime
8079
return ReturnValue(UR_PLATFORM_BACKEND_NATIVE_CPU);
80+
case UR_PLATFORM_INFO_ADAPTER:
81+
return ReturnValue(&Adapter);
8182
default:
8283
DIE_NO_IMPLEMENTATION;
8384
}

0 commit comments

Comments
 (0)