[clang] [amdgpu-arch] Replace use of HSA with reading sysfs directly (PR #116651)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 18 08:47:29 PST 2024
================
@@ -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;
+
+ long Node = 0;
+ if (sys::path::stem(Begin->path()).consumeInteger(10, Node))
+ return 1;
+
+ SmallVector<char> Path(Begin->path().begin(), Begin->path().end());
+ sys::path::append(Path, "properties");
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
+ MemoryBuffer::getFileOrSTDIN(Path);
+ if (std::error_code EC = BufferOrErr.getError())
+ return 1;
+
+ long GFXVersion = 0;
+ for (line_iterator Lines(**BufferOrErr, false); !Lines.is_at_end();
+ ++Lines) {
+ if (Lines->starts_with("gfx_target_version")) {
+ if (Lines->drop_front(sizeof("gfx_target_version"))
----------------
arsenm wrote:
consume_front
https://github.com/llvm/llvm-project/pull/116651
More information about the cfe-commits
mailing list