Skip to content

Commit c36a0b6

Browse files
authored
Merge pull request #2365 from aarongreig/aaron/addAdapterPlatformQuery
Add query to retrieve adapter handle from platform.
2 parents 501057c + c67d128 commit c36a0b6

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
@@ -1093,6 +1093,8 @@ typedef enum ur_platform_info_t {
10931093
///< info needs to be dynamically queried.
10941094
UR_PLATFORM_INFO_BACKEND = 6, ///< [::ur_platform_backend_t] The backend of the platform. Identifies the
10951095
///< native backend adapter implementing this platform.
1096+
UR_PLATFORM_INFO_ADAPTER = 7, ///< [::ur_adapter_handle_t] The adapter handle associated with the
1097+
///< platform.
10961098
/// @cond
10971099
UR_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
10981100
/// @endcond
@@ -1118,7 +1120,7 @@ typedef enum ur_platform_info_t {
11181120
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
11191121
/// + `NULL == hPlatform`
11201122
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
1121-
/// + `::UR_PLATFORM_INFO_BACKEND < propName`
1123+
/// + `::UR_PLATFORM_INFO_ADAPTER < propName`
11221124
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
11231125
/// + If `propName` is not supported by the adapter.
11241126
/// - ::UR_RESULT_ERROR_INVALID_SIZE

include/ur_print.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_platform_info_t value)
20742074
case UR_PLATFORM_INFO_BACKEND:
20752075
os << "UR_PLATFORM_INFO_BACKEND";
20762076
break;
2077+
case UR_PLATFORM_INFO_ADAPTER:
2078+
os << "UR_PLATFORM_INFO_ADAPTER";
2079+
break;
20772080
default:
20782081
os << "unknown enumerator";
20792082
break;
@@ -2127,6 +2130,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_platform_in
21272130

21282131
os << ")";
21292132
} break;
2133+
case UR_PLATFORM_INFO_ADAPTER: {
2134+
const ur_adapter_handle_t *tptr = (const ur_adapter_handle_t *)ptr;
2135+
if (sizeof(ur_adapter_handle_t) > size) {
2136+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_adapter_handle_t) << ")";
2137+
return UR_RESULT_ERROR_INVALID_SIZE;
2138+
}
2139+
os << (const void *)(tptr) << " (";
2140+
2141+
ur::details::printPtr(os,
2142+
*tptr);
2143+
2144+
os << ")";
2145+
} break;
21302146
default:
21312147
os << "unknown enumerator";
21322148
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)