CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
96 lines
2.8 KiB
C++
96 lines
2.8 KiB
C++
//===- OffloadArch.cpp - list available GPUs ------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Basic/Version.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/Path.h"
|
|
|
|
using namespace llvm;
|
|
|
|
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);
|
|
|
|
// Mark all our options with this category.
|
|
static cl::OptionCategory OffloadArchCategory("offload-arch options");
|
|
|
|
extern cl::OptionCategory AMDGPUArchByHIPCategory;
|
|
|
|
enum VendorName {
|
|
all,
|
|
amdgpu,
|
|
nvptx,
|
|
intel,
|
|
};
|
|
|
|
static cl::opt<VendorName>
|
|
Only("only", cl::desc("Restrict to vendor:"), cl::cat(OffloadArchCategory),
|
|
cl::init(all),
|
|
cl::values(clEnumVal(all, "Print all GPUs (default)"),
|
|
clEnumVal(amdgpu, "Only print AMD GPUs"),
|
|
clEnumVal(nvptx, "Only print NVIDIA GPUs"),
|
|
clEnumVal(intel, "Only print Intel GPUs")));
|
|
|
|
cl::opt<bool> Verbose("verbose", cl::desc("Enable verbose output"),
|
|
cl::init(false), cl::cat(OffloadArchCategory));
|
|
|
|
static void PrintVersion(raw_ostream &OS) {
|
|
OS << clang::getClangToolFullVersion("offload-arch") << '\n';
|
|
}
|
|
|
|
int printGPUsByKFD();
|
|
int printGPUsByHIP();
|
|
int printGPUsByCUDA();
|
|
int printGPUsByLevelZero();
|
|
|
|
static int printAMD() {
|
|
#ifndef _WIN32
|
|
if (!printGPUsByKFD())
|
|
return 0;
|
|
#endif
|
|
|
|
return printGPUsByHIP();
|
|
}
|
|
|
|
static int printNVIDIA() { return printGPUsByCUDA(); }
|
|
static int printIntel() { return printGPUsByLevelZero(); }
|
|
|
|
const std::array<std::pair<VendorName, function_ref<int()>>, 3> VendorTable{
|
|
{{VendorName::amdgpu, printAMD},
|
|
{VendorName::nvptx, printNVIDIA},
|
|
{VendorName::intel, printIntel}}};
|
|
|
|
int main(int argc, char *argv[]) {
|
|
cl::HideUnrelatedOptions({&OffloadArchCategory, &AMDGPUArchByHIPCategory});
|
|
|
|
cl::SetVersionPrinter(PrintVersion);
|
|
cl::ParseCommandLineOptions(
|
|
argc, argv,
|
|
"A tool to detect the presence of offloading devices on the system. \n\n"
|
|
"The tool will output each detected GPU architecture separated by a\n"
|
|
"newline character. If multiple GPUs of the same architecture are found\n"
|
|
"a string will be printed for each\n");
|
|
|
|
if (Help) {
|
|
cl::PrintHelpMessage();
|
|
return 0;
|
|
}
|
|
|
|
// Support legacy binaries.
|
|
if (sys::path::stem(argv[0]).starts_with("amdgpu-arch"))
|
|
Only = VendorName::amdgpu;
|
|
if (sys::path::stem(argv[0]).starts_with("nvptx-arch"))
|
|
Only = VendorName::nvptx;
|
|
|
|
int Result = 1;
|
|
for (auto [Name, Func] : VendorTable) {
|
|
if (Only == VendorName::all || Only == Name)
|
|
Result &= Func();
|
|
}
|
|
|
|
return Result;
|
|
}
|