//===- AMDGPUArch.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 AMDGPU installed in system // using HSA. This tool is used by AMDGPU OpenMP driver. // //===----------------------------------------------------------------------===// #include #include #include static hsa_status_t iterateAgentsCallback(hsa_agent_t Agent, void *Data) { hsa_device_type_t DeviceType; hsa_status_t Status = hsa_agent_get_info(Agent, HSA_AGENT_INFO_DEVICE, &DeviceType); // continue only if device type if GPU if (Status != HSA_STATUS_SUCCESS || DeviceType != HSA_DEVICE_TYPE_GPU) { return Status; } std::vector *GPUs = static_cast *>(Data); char GPUName[64]; Status = hsa_agent_get_info(Agent, HSA_AGENT_INFO_NAME, GPUName); if (Status != HSA_STATUS_SUCCESS) { return Status; } GPUs->push_back(GPUName); return HSA_STATUS_SUCCESS; } int main() { hsa_status_t Status = hsa_init(); if (Status != HSA_STATUS_SUCCESS) { return 1; } std::vector GPUs; Status = hsa_iterate_agents(iterateAgentsCallback, &GPUs); if (Status != HSA_STATUS_SUCCESS) { return 1; } for (const auto &GPU : GPUs) printf("%s\n", GPU.c_str()); if (GPUs.size() < 1) return 1; hsa_shut_down(); return 0; }