Skip to content

Commit 050b56a

Browse files
committed
Replace binary entirely
1 parent 7085c29 commit 050b56a

File tree

5 files changed

+253
-299
lines changed

5 files changed

+253
-299
lines changed

offload/tools/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ endmacro()
1414

1515
add_subdirectory(deviceinfo)
1616
add_subdirectory(kernelreplay)
17-
add_subdirectory(liboffload-deviceinfo)

offload/tools/deviceinfo/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ add_openmp_tool(llvm-offload-device-info llvm-offload-device-info.cpp)
44

55
llvm_update_compile_flags(llvm-offload-device-info)
66

7-
target_include_directories(llvm-offload-device-info PRIVATE
8-
${LIBOMPTARGET_INCLUDE_DIR}
9-
)
107
target_link_libraries(llvm-offload-device-info PRIVATE
11-
omp
12-
omptarget
8+
LLVMOffload
139
)
Lines changed: 252 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,268 @@
1-
//===- llvm-offload-device-info.cpp - Device info as seen by LLVM/Offload -===//
1+
//===- llvm-liboffload-device-info.cpp - Print liboffload properties ------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This is a command line utility that, by using LLVM/Offload, and the device
10-
// plugins, list devices information as seen by the runtime.
9+
// This is a command line utility that, by using the new liboffload API, prints
10+
// all devices and properties
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "omptarget.h"
15-
#include <cstdio>
14+
#include <OffloadAPI.h>
15+
#include <iostream>
16+
#include <vector>
1617

17-
int main(int argc, char **argv) {
18-
__tgt_bin_desc EmptyDesc = {0, nullptr, nullptr, nullptr};
19-
__tgt_register_lib(&EmptyDesc);
20-
__tgt_init_all_rtls();
18+
#define OFFLOAD_ERR(X) \
19+
if (auto Err = X) { \
20+
return Err; \
21+
}
22+
23+
enum class PrintKind {
24+
NORMAL,
25+
FP_FLAGS,
26+
};
27+
28+
template <typename T, PrintKind PK = PrintKind::NORMAL>
29+
void doWrite(std::ostream &S, T &&Val) {
30+
S << Val;
31+
}
32+
33+
template <>
34+
void doWrite<ol_platform_backend_t>(std::ostream &S,
35+
ol_platform_backend_t &&Val) {
36+
switch (Val) {
37+
case OL_PLATFORM_BACKEND_UNKNOWN:
38+
S << "UNKNOWN";
39+
break;
40+
case OL_PLATFORM_BACKEND_CUDA:
41+
S << "CUDA";
42+
break;
43+
case OL_PLATFORM_BACKEND_AMDGPU:
44+
S << "AMDGPU";
45+
break;
46+
case OL_PLATFORM_BACKEND_HOST:
47+
S << "HOST";
48+
break;
49+
default:
50+
S << "<< INVALID >>";
51+
break;
52+
}
53+
}
54+
template <>
55+
void doWrite<ol_device_type_t>(std::ostream &S, ol_device_type_t &&Val) {
56+
switch (Val) {
57+
case OL_DEVICE_TYPE_GPU:
58+
S << "GPU";
59+
break;
60+
case OL_DEVICE_TYPE_CPU:
61+
S << "CPU";
62+
break;
63+
case OL_DEVICE_TYPE_HOST:
64+
S << "HOST";
65+
break;
66+
default:
67+
S << "<< INVALID >>";
68+
break;
69+
}
70+
}
71+
template <>
72+
void doWrite<ol_dimensions_t>(std::ostream &S, ol_dimensions_t &&Val) {
73+
S << "{x: " << Val.x << ", y: " << Val.y << ", z: " << Val.z << "}";
74+
}
75+
template <>
76+
void doWrite<ol_device_fp_capability_flags_t, PrintKind::FP_FLAGS>(
77+
std::ostream &S, ol_device_fp_capability_flags_t &&Val) {
78+
S << Val << " {";
79+
80+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT) {
81+
S << " CORRECTLY_ROUNDED_DIVIDE_SQRT";
82+
}
83+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST) {
84+
S << " ROUND_TO_NEAREST";
85+
}
86+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO) {
87+
S << " ROUND_TO_ZERO";
88+
}
89+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF) {
90+
S << " ROUND_TO_INF";
91+
}
92+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_INF_NAN) {
93+
S << " INF_NAN";
94+
}
95+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_DENORM) {
96+
S << " DENORM";
97+
}
98+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_FMA) {
99+
S << " FMA";
100+
}
101+
if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_SOFT_FLOAT) {
102+
S << " SOFT_FLOAT";
103+
}
104+
105+
S << " }";
106+
}
21107

22-
printf("Found %d devices:\n", omp_get_num_devices());
23-
for (int Dev = 0; Dev < omp_get_num_devices(); Dev++) {
24-
printf(" Device %d:\n", Dev);
25-
if (!__tgt_print_device_info(Dev))
26-
printf(" print_device_info not implemented\n");
27-
printf("\n");
108+
template <typename T>
109+
ol_result_t printPlatformValue(std::ostream &S, ol_platform_handle_t Plat,
110+
ol_platform_info_t Info, const char *Desc) {
111+
S << Desc << ": ";
112+
113+
if constexpr (std::is_pointer_v<T>) {
114+
std::vector<uint8_t> Val;
115+
size_t Size;
116+
OFFLOAD_ERR(olGetPlatformInfoSize(Plat, Info, &Size));
117+
Val.resize(Size);
118+
OFFLOAD_ERR(olGetPlatformInfo(Plat, Info, sizeof(Val), Val.data()));
119+
doWrite(S, reinterpret_cast<T>(Val.data()));
120+
} else {
121+
T Val;
122+
OFFLOAD_ERR(olGetPlatformInfo(Plat, Info, sizeof(Val), &Val));
123+
doWrite(S, std::move(Val));
124+
}
125+
S << "\n";
126+
return OL_SUCCESS;
127+
}
128+
129+
template <typename T, PrintKind PK = PrintKind::NORMAL>
130+
ol_result_t printDeviceValue(std::ostream &S, ol_device_handle_t Dev,
131+
ol_device_info_t Info, const char *Desc,
132+
const char *Units = "") {
133+
S << Desc << ": ";
134+
135+
if constexpr (std::is_pointer_v<T>) {
136+
std::vector<uint8_t> Val;
137+
size_t Size;
138+
OFFLOAD_ERR(olGetDeviceInfoSize(Dev, Info, &Size));
139+
Val.resize(Size);
140+
OFFLOAD_ERR(olGetDeviceInfo(Dev, Info, sizeof(Val), Val.data()));
141+
doWrite<T, PK>(S, reinterpret_cast<T>(Val.data()));
142+
} else {
143+
T Val;
144+
OFFLOAD_ERR(olGetDeviceInfo(Dev, Info, sizeof(Val), &Val));
145+
doWrite<T, PK>(S, std::move(Val));
146+
}
147+
S << Units << "\n";
148+
return OL_SUCCESS;
149+
}
150+
151+
ol_result_t printDevice(std::ostream &S, ol_device_handle_t D) {
152+
ol_platform_handle_t Platform;
153+
OFFLOAD_ERR(
154+
olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform), &Platform));
155+
156+
std::vector<char> Name;
157+
size_t NameSize;
158+
OFFLOAD_ERR(olGetDeviceInfoSize(D, OL_DEVICE_INFO_PRODUCT_NAME, &NameSize))
159+
Name.resize(NameSize);
160+
OFFLOAD_ERR(
161+
olGetDeviceInfo(D, OL_DEVICE_INFO_PRODUCT_NAME, NameSize, Name.data()));
162+
S << "[" << Name.data() << "]\n";
163+
164+
OFFLOAD_ERR(printPlatformValue<const char *>(
165+
S, Platform, OL_PLATFORM_INFO_NAME, "Platform Name"));
166+
OFFLOAD_ERR(printPlatformValue<const char *>(
167+
S, Platform, OL_PLATFORM_INFO_VENDOR_NAME, "Platform Vendor Name"));
168+
OFFLOAD_ERR(printPlatformValue<const char *>(
169+
S, Platform, OL_PLATFORM_INFO_VERSION, "Platform Version"));
170+
OFFLOAD_ERR(printPlatformValue<ol_platform_backend_t>(
171+
S, Platform, OL_PLATFORM_INFO_BACKEND, "Platform Backend"));
172+
173+
OFFLOAD_ERR(
174+
printDeviceValue<const char *>(S, D, OL_DEVICE_INFO_NAME, "Name"));
175+
OFFLOAD_ERR(
176+
printDeviceValue<ol_device_type_t>(S, D, OL_DEVICE_INFO_TYPE, "Type"));
177+
OFFLOAD_ERR(printDeviceValue<const char *>(
178+
S, D, OL_DEVICE_INFO_DRIVER_VERSION, "Driver Version"));
179+
OFFLOAD_ERR(printDeviceValue<uint32_t>(
180+
S, D, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE, "Max Work Group Size"));
181+
OFFLOAD_ERR(printDeviceValue<ol_dimensions_t>(
182+
S, D, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE_PER_DIMENSION,
183+
"Max Work Group Size Per Dimension"));
184+
OFFLOAD_ERR(
185+
printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_VENDOR_ID, "Vendor ID"));
186+
OFFLOAD_ERR(printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_NUM_COMPUTE_UNITS,
187+
"Num Compute Units"));
188+
OFFLOAD_ERR(printDeviceValue<uint32_t>(
189+
S, D, OL_DEVICE_INFO_MAX_CLOCK_FREQUENCY, "Max Clock Frequency", "MHz"));
190+
OFFLOAD_ERR(printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_MEMORY_CLOCK_RATE,
191+
"Memory Clock Rate", "MHz"));
192+
OFFLOAD_ERR(printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_ADDRESS_BITS,
193+
"Address Bits"));
194+
OFFLOAD_ERR(printDeviceValue<uint64_t>(
195+
S, D, OL_DEVICE_INFO_MAX_MEM_ALLOC_SIZE, "Max Mem Allocation Size", "B"));
196+
OFFLOAD_ERR(printDeviceValue<uint64_t>(S, D, OL_DEVICE_INFO_GLOBAL_MEM_SIZE,
197+
"Global Mem Size", "B"));
198+
OFFLOAD_ERR(
199+
(printDeviceValue<ol_device_fp_capability_flags_t, PrintKind::FP_FLAGS>(
200+
S, D, OL_DEVICE_INFO_SINGLE_FP_CONFIG,
201+
"Single Precision Floating Point Capability")));
202+
OFFLOAD_ERR(
203+
(printDeviceValue<ol_device_fp_capability_flags_t, PrintKind::FP_FLAGS>(
204+
S, D, OL_DEVICE_INFO_DOUBLE_FP_CONFIG,
205+
"Double Precision Floating Point Capability")));
206+
OFFLOAD_ERR(
207+
(printDeviceValue<ol_device_fp_capability_flags_t, PrintKind::FP_FLAGS>(
208+
S, D, OL_DEVICE_INFO_HALF_FP_CONFIG,
209+
"Half Precision Floating Point Capability")));
210+
OFFLOAD_ERR(
211+
printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_CHAR,
212+
"Native Vector Width For Char"));
213+
OFFLOAD_ERR(
214+
printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_SHORT,
215+
"Native Vector Width For Short"));
216+
OFFLOAD_ERR(printDeviceValue<uint32_t>(S, D,
217+
OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_INT,
218+
"Native Vector Width For Int"));
219+
OFFLOAD_ERR(
220+
printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_LONG,
221+
"Native Vector Width For Long"));
222+
OFFLOAD_ERR(
223+
printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_FLOAT,
224+
"Native Vector Width For Float"));
225+
OFFLOAD_ERR(printDeviceValue<uint32_t>(
226+
S, D, OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_DOUBLE,
227+
"Native Vector Width For Double"));
228+
OFFLOAD_ERR(
229+
printDeviceValue<uint32_t>(S, D, OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF,
230+
"Native Vector Width For Half"));
231+
232+
return OL_SUCCESS;
233+
}
234+
235+
ol_result_t printRoot(std::ostream &S) {
236+
OFFLOAD_ERR(olInit());
237+
S << "Liboffload Version: " << OL_VERSION_MAJOR << "." << OL_VERSION_MINOR
238+
<< "." << OL_VERSION_PATCH << "\n";
239+
240+
std::vector<ol_device_handle_t> Devices;
241+
OFFLOAD_ERR(olIterateDevices(
242+
[](ol_device_handle_t Device, void *UserData) {
243+
reinterpret_cast<decltype(Devices) *>(UserData)->push_back(Device);
244+
return true;
245+
},
246+
&Devices));
247+
248+
S << "Num Devices: " << Devices.size() << "\n";
249+
250+
for (auto &D : Devices) {
251+
S << "\n";
252+
OFFLOAD_ERR(printDevice(S, D));
28253
}
29254

30-
__tgt_unregister_lib(&EmptyDesc);
255+
OFFLOAD_ERR(olShutDown());
256+
return OL_SUCCESS;
257+
}
258+
259+
int main(int argc, char **argv) {
260+
auto Err = printRoot(std::cout);
261+
262+
if (Err) {
263+
std::cerr << "[Liboffload error " << Err->Code << "]: " << Err->Details
264+
<< "\n";
265+
return 1;
266+
}
31267
return 0;
32268
}

offload/tools/liboffload-deviceinfo/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)