[v0.30] Add support for AMD GPUs

Adds very basic support for AMD (experimental). The only install
requirement is ROCm. Unlike NVIDIA, we don't need the CUDA equivalent
(HIP) to make gpufetch work, which reduces the installation
requirements quite significantly.

Major changes:

* CMakeLists:
  - Make CUDA not compiled by default (since we now may want to target
    AMD only)
  - Set build flags on gpufetch cmake target instead of doing
    "set(CMAKE_CXX_FLAGS". This fixes a warning coming from ROCm.
  - Assumes that the ROCm CMake files are installed (should be fixed
    later)

* hsa folder: AMD support is implemented via HSA (Heterogeneous System
  Architecture) calls. Therefore, HSA is added as a new backend to
  gpufetch. We only print basic stuff for now, so we may need more
  things in the future to give full support for AMD GPUs.

NOTE: This commit will probably break AUR packages since we used to
build CUDA by default, which is no longer the case. The AUR package
should be updated and use -DENABLE_CUDA_BACKEND or -DENABLE_HSA_BACKEND
as appropriate.
This commit is contained in:
Dr-Noob
2025-10-12 12:34:56 +02:00
parent 57caadf530
commit b29b17d14f
11 changed files with 344 additions and 21 deletions

View File

@@ -7,6 +7,7 @@
#include "master.hpp"
#include "args.hpp"
#include "../cuda/cuda.hpp"
#include "../hsa/hsa.hpp"
#include "../intel/intel.hpp"
#define MAX_GPUS 1000
@@ -35,6 +36,18 @@ struct gpu_list* get_gpu_list() {
list->num_gpus += idx;
#endif
#ifdef BACKEND_HSA
bool valid = true;
while(valid) {
list->gpus[idx] = get_gpu_info_hsa(devices, idx);
if(list->gpus[idx] != NULL) idx++;
else valid = false;
}
list->num_gpus += idx;
#endif
#ifdef BACKEND_INTEL
list->gpus[idx] = get_gpu_info_intel(devices);
if(list->gpus[idx] != NULL) list->num_gpus++;
@@ -51,6 +64,11 @@ bool print_gpus_list(struct gpu_list* list) {
print_gpu_cuda(list->gpus[i]);
#endif
}
else if(list->gpus[i]->vendor == GPU_VENDOR_AMD) {
#ifdef BACKEND_AMD
print_gpu_hsa(list->gpus[i]);
#endif
}
else if(list->gpus[i]->vendor == GPU_VENDOR_INTEL) {
#ifdef BACKEND_INTEL
print_gpu_intel(list->gpus[i]);
@@ -69,6 +87,13 @@ void print_enabled_backends() {
printf("%sOFF%s\n", C_FG_RED, C_RESET);
#endif
printf("- HSA backend: ");
#ifdef BACKEND_HSA
printf("%sON%s\n", C_FG_GREEN, C_RESET);
#else
printf("%sOFF%s\n", C_FG_RED, C_RESET);
#endif
printf("- Intel backend: ");
#ifdef BACKEND_INTEL
printf("%sON%s\n", C_FG_GREEN, C_RESET);