================ @@ -0,0 +1,74 @@ +//===- AMDGPUArchByKFD.cpp - list AMDGPU installed ------*- C++ -*---------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file implements a tool for detecting name of AMD GPUs installed in +// system using the Linux sysfs interface for the AMD KFD driver. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/LineIterator.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include <memory> +#include <string> + +using namespace llvm; + +constexpr const char *KFD_SYSFS_NODE_PATH = + "/sys/devices/virtual/kfd/kfd/topology/nodes"; + +constexpr static long getMajor(long Ver) { return (Ver / 10000) % 100; } +constexpr static long getMinor(long Ver) { return (Ver / 100) % 100; } +constexpr static long getStep(long Ver) { return Ver % 100; } + +int printGPUsByKFD() { + SmallVector<std::pair<long, long>> Devices; + std::error_code EC; + for (sys::fs::directory_iterator Begin(KFD_SYSFS_NODE_PATH, EC), End; + Begin != End; Begin.increment(EC)) { + if (EC) + return 1; ---------------- arsenm wrote:
Should print some errors when this fails https://github.com/llvm/llvm-project/pull/116651 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits