Skip to content

Commit 07d446f

Browse files
committed
Add query to retrieve adapter handle from platform.
1 parent 50f66ae commit 07d446f

File tree

16 files changed

+126
-17
lines changed

16 files changed

+126
-17
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: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_platform_info_t value)
20202020
case UR_PLATFORM_INFO_BACKEND:
20212021
os << "UR_PLATFORM_INFO_BACKEND";
20222022
break;
2023+
case UR_PLATFORM_INFO_ADAPTER:
2024+
os << "UR_PLATFORM_INFO_ADAPTER";
2025+
break;
20232026
default:
20242027
os << "unknown enumerator";
20252028
break;
@@ -2073,6 +2076,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_platform_in
20732076

20742077
os << ")";
20752078
} break;
2079+
case UR_PLATFORM_INFO_ADAPTER: {
2080+
const ur_adapter_handle_t *tptr = (const ur_adapter_handle_t *)ptr;
2081+
if (sizeof(ur_adapter_handle_t) > size) {
2082+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_adapter_handle_t) << ")";
2083+
return UR_RESULT_ERROR_INVALID_SIZE;
2084+
}
2085+
os << (const void *)(tptr) << " (";
2086+
2087+
ur::details::printPtr(os,
2088+
*tptr);
2089+
2090+
os << ")";
2091+
} break;
20762092
default:
20772093
os << "unknown enumerator";
20782094
return UR_RESULT_ERROR_INVALID_ENUMERATION;
@@ -15107,16 +15123,20 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1510715123
os << *(params->pnumEventsInWaitList);
1510815124

1510915125
os << ", ";
15110-
os << ".phEventWaitList = {";
15111-
for (size_t i = 0; *(params->pphEventWaitList) != NULL && i < *params->pnumEventsInWaitList; ++i) {
15112-
if (i != 0) {
15113-
os << ", ";
15114-
}
15126+
os << ".phEventWaitList = ";
15127+
ur::details::printPtr(os, reinterpret_cast<const void *>(*(params->pphEventWaitList)));
15128+
if (*(params->pphEventWaitList) != NULL) {
15129+
os << " {";
15130+
for (size_t i = 0; i < *params->pnumEventsInWaitList; ++i) {
15131+
if (i != 0) {
15132+
os << ", ";
15133+
}
1511515134

15116-
ur::details::printPtr(os,
15117-
(*(params->pphEventWaitList))[i]);
15135+
ur::details::printPtr(os,
15136+
(*(params->pphEventWaitList))[i]);
15137+
}
15138+
os << "}";
1511815139
}
15119-
os << "}";
1512015140

1512115141
os << ", ";
1512215142
os << ".phEvent = ";

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/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
}

source/adapters/opencl/platform.cpp

Lines changed: 3 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

1314
ur_result_t cl_adapter::getPlatformVersion(cl_platform_id Plat,
1415
oclv::OpenCLVersion &Version) {
@@ -57,6 +58,8 @@ urPlatformGetInfo(ur_platform_handle_t hPlatform, ur_platform_info_t propName,
5758
switch (static_cast<uint32_t>(propName)) {
5859
case UR_PLATFORM_INFO_BACKEND:
5960
return ReturnValue(UR_PLATFORM_BACKEND_OPENCL);
61+
case UR_PLATFORM_INFO_ADAPTER:
62+
return ReturnValue(ur::cl::getAdapter());
6063
case UR_PLATFORM_INFO_NAME:
6164
case UR_PLATFORM_INFO_VENDOR_NAME:
6265
case UR_PLATFORM_INFO_VERSION:

0 commit comments

Comments
 (0)