xref: /llvm-project/offload/tools/deviceinfo/llvm-offload-device-info.cpp (revision 7102592af740ed9f8b388c12dd2182039a58167d)
1*7102592aSJohannes Doerfert //===- llvm-offload-device-info.cpp - Device info as seen by LLVM/Offload -===//
2*7102592aSJohannes Doerfert //
3*7102592aSJohannes Doerfert // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*7102592aSJohannes Doerfert // See https://llvm.org/LICENSE.txt for license information.
5*7102592aSJohannes Doerfert // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*7102592aSJohannes Doerfert //
7*7102592aSJohannes Doerfert //===----------------------------------------------------------------------===//
8*7102592aSJohannes Doerfert //
9*7102592aSJohannes Doerfert // This is a command line utility that, by using LLVM/Offload, and the device
10*7102592aSJohannes Doerfert // plugins, list devices information as seen by the runtime.
11*7102592aSJohannes Doerfert //
12*7102592aSJohannes Doerfert //===----------------------------------------------------------------------===//
13*7102592aSJohannes Doerfert 
14*7102592aSJohannes Doerfert #include "omptarget.h"
15*7102592aSJohannes Doerfert #include <cstdio>
16*7102592aSJohannes Doerfert 
17*7102592aSJohannes Doerfert int main(int argc, char **argv) {
18*7102592aSJohannes Doerfert   __tgt_bin_desc EmptyDesc = {0, nullptr, nullptr, nullptr};
19*7102592aSJohannes Doerfert   __tgt_register_lib(&EmptyDesc);
20*7102592aSJohannes Doerfert   __tgt_init_all_rtls();
21*7102592aSJohannes Doerfert 
22*7102592aSJohannes Doerfert   printf("Found %d devices:\n", omp_get_num_devices());
23*7102592aSJohannes Doerfert   for (int Dev = 0; Dev < omp_get_num_devices(); Dev++) {
24*7102592aSJohannes Doerfert     printf("  Device %d:\n", Dev);
25*7102592aSJohannes Doerfert     if (!__tgt_print_device_info(Dev))
26*7102592aSJohannes Doerfert       printf("    print_device_info not implemented\n");
27*7102592aSJohannes Doerfert     printf("\n");
28*7102592aSJohannes Doerfert   }
29*7102592aSJohannes Doerfert 
30*7102592aSJohannes Doerfert   __tgt_unregister_lib(&EmptyDesc);
31*7102592aSJohannes Doerfert   return 0;
32*7102592aSJohannes Doerfert }
33