| 1 |
//===- AMDGPUArch.cpp - list AMDGPU installed ----------*- C++ -*---------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// This file implements a tool for detecting name of AMDGPU installed in system. |
| 10 |
// This tool is used by AMDGPU OpenMP and HIP driver. |
| 11 |
// |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
#include "clang/Basic/Version.h" |
| 15 |
#include "llvm/Support/CommandLine.h" |
| 16 |
|
| 17 |
using namespace llvm; |
| 18 |
|
| 19 |
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden); |
| 20 |
|
| 21 |
// Mark all our options with this category. |
| 22 |
static cl::OptionCategory AMDGPUArchCategory("amdgpu-arch options"); |
| 23 |
|
| 24 |
static void PrintVersion(raw_ostream &OS) { |
| 25 |
OS << clang::getClangToolFullVersion("amdgpu-arch") << '\n'; |
| 26 |
} |
| 27 |
|
| 28 |
int printGPUsByHSA(); |
| 29 |
int printGPUsByHIP(); |
| 30 |
|
| 31 |
int main(int argc, char *argv[]) { |
| 32 |
cl::HideUnrelatedOptions(AMDGPUArchCategory); |
| 33 |
|
| 34 |
cl::SetVersionPrinter(PrintVersion); |
| 35 |
cl::ParseCommandLineOptions( |
| 36 |
argc, argv, |
| 37 |
"A tool to detect the presence of AMDGPU devices on the system. \n\n" |
| 38 |
"The tool will output each detected GPU architecture separated by a\n" |
| 39 |
"newline character. If multiple GPUs of the same architecture are found\n" |
| 40 |
"a string will be printed for each\n"); |
| 41 |
|
| 42 |
if (Help) { |
| 43 |
cl::PrintHelpMessage(); |
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
#ifndef _WIN32 |
| 48 |
if (!printGPUsByHSA()) |
| 49 |
return 0; |
| 50 |
#endif |
| 51 |
|
| 52 |
return printGPUsByHIP(); |
| 53 |
} |