Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion babel.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern "C" int rvs_module_init(void* pMi) {

extern "C" int rvs_module_terminate(void) {
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
14 changes: 7 additions & 7 deletions gm.so/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ else()
set(ASAN_LIB_PATH "$ENV{LD_LIBRARY_PATH}")
endif()

if(DEFINED RVS_ROCMSMI)
if(NOT RVS_ROCMSMI EQUAL 1)
if(NOT EXISTS "${ROCM_SMI_LIB_DIR}/lib${ROCM_SMI_LIB}.so")
message("ERROR: rocm_smi library can't be found!...")
if(DEFINED RVS_AMDSMI)
if(NOT RVS_AMDSMI EQUAL 1)
if(NOT EXISTS "${AMD_SMI_LIB_DIR}/lib${AMD_SMI_LIB}.so")
message("ERROR: amd_smi library can't be found!...")
RETURN()
endif()
endif()
endif()

## define include directories
include_directories(./ ../ ${ROCM_SMI_INC_DIR} ${YAML_CPP_INCLUDE_DIR})
include_directories(./ ../ ${AMD_SMI_INC_DIR} ${YAML_CPP_INCLUDE_DIR})
# Add directories to look for library files to link
link_directories(${RVS_LIB_DIR} ${ROCM_SMI_LIB_DIR} ${ASAN_LIB_PATH} ${ROCM_SMI_LIB} ${HIPRAND_LIB_DIR} ${ROCRAND_LIB_DIR} ${HIPBLASLT_LIB_DIR})
link_directories(${RVS_LIB_DIR} ${AMD_SMI_LIB_DIR} ${ASAN_LIB_PATH} ${AMD_SMI_LIB} ${HIPRAND_LIB_DIR} ${ROCRAND_LIB_DIR} ${HIPBLASLT_LIB_DIR})
## additional libraries
set (PROJECT_LINK_LIBS rvslib libpthread.so libpci.so libm.so)

Expand All @@ -132,7 +132,7 @@ add_library( ${RVS_TARGET} SHARED ${SOURCES})
set_target_properties(${RVS_TARGET} PROPERTIES
SUFFIX .so.${LIB_VERSION_STRING}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
target_link_libraries(${RVS_TARGET} ${PROJECT_LINK_LIBS} ${ROCM_SMI_LIB})
target_link_libraries(${RVS_TARGET} ${PROJECT_LINK_LIBS} ${AMD_SMI_LIB})
add_dependencies(${RVS_TARGET} rvslib)

add_custom_command(TARGET ${RVS_TARGET} POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion gm.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern "C" int rvs_module_terminate(void) {
pworker = nullptr;
}
RVSTRACE_
amdsmi_shut_down();


return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion gpup.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extern "C" int rvs_module_init(void* pMi) {

extern "C" int rvs_module_terminate(void) {
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion gst.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern "C" int rvs_module_init(void* pMi) {

extern "C" int rvs_module_terminate(void) {
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion iet.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern "C" int rvs_module_init(void* pMi) {

extern "C" int rvs_module_terminate(void) {
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
120 changes: 119 additions & 1 deletion include/gpu_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <utility>
#include "amd_smi/amdsmi.h"

#define KFD_SYS_PATH_NODES "/sys/class/kfd/kfd/topology/nodes"
Expand All @@ -50,18 +52,91 @@ extern std::string gpu_get_platform_name (void);

namespace rvs {

/**
* @struct GpuInfo
* @brief Unified structure containing all GPU identifiers and properties
*
* This structure to replace the parallel arrays with a single cohesive data structure
* that keeps all GPU-related information together, improving maintainability.
* Older arrays if not updated in lockstep results in wrong behaviour
*/
struct GpuInfo {
uint16_t location_id; //GPU Location ID(location_id) from KFD topology
uint16_t gpu_id; //GPU ID from KFD
uint16_t gpu_idx; // GPU index in system
uint16_t device_id; // PCI Device ID
uint16_t node_id; // HSA Node ID
uint16_t domain_id; // PCI Domain ID
std::string pci_bdf; // PCI Bus:Device.Function string

GpuInfo()
: location_id(0), gpu_id(0), gpu_idx(0), device_id(0),
node_id(0), domain_id(0), pci_bdf("") {}

GpuInfo(uint16_t loc_id, uint16_t g_id, uint16_t idx,
uint16_t dev_id, uint16_t n_id, uint16_t dom_id,
const std::string& bdf)
: location_id(loc_id), gpu_id(g_id), gpu_idx(idx),
device_id(dev_id), node_id(n_id), domain_id(dom_id),
pci_bdf(bdf) {}

bool is_valid() const {
return gpu_id != 0;
}

std::pair<uint16_t, uint16_t> get_domain_location_pair() const {
return std::make_pair(domain_id, location_id);
}
};
/**
* Error codes for GPU lookup operations
*/
enum class GpuLookupError {
SUCCESS = 0, // Operation successful
NOT_FOUND = -1, // GPU identifier not found
NULL_POINTER = -2, // Null pointer passed as argument
UNINITIALIZED = -3, // GPU list not initialized
INDEX_OUT_OF_BOUNDS = -4, // Internal index corruption
INVALID_ARGUMENT = -5 // Invalid argument value
};

/**
* Convert error code to human-readable string
*/
inline const char* error_to_string(GpuLookupError err) {
switch (err) {
case GpuLookupError::SUCCESS:
return "Success";
case GpuLookupError::NOT_FOUND:
return "GPU identifier not found in system";
case GpuLookupError::NULL_POINTER:
return "Null pointer passed as argument";
case GpuLookupError::UNINITIALIZED:
return "GPU list not initialized - call Initialize() first";
case GpuLookupError::INDEX_OUT_OF_BOUNDS:
return "Internal index corruption detected";
case GpuLookupError::INVALID_ARGUMENT:
return "Invalid argument value";
default:
return "Unknown error";
}
}


/**
* @class gpulist
*
* @brief GPU cross-indexing utility class
*
* Used to quickly get GPU ID from location ID and vs. versa
*
* This class maintains a unified list of GPU information and provides
* fast lookups
*/
class gpulist {
public:
static int Initialize();

static int Shutdown();
static int location2gpu(const uint16_t LocationID, uint16_t* pGpuID);
static int gpu2location(const uint16_t GpuID, uint16_t* pLocationID);
static int node2gpu(const uint16_t NodeID, uint16_t* pGpuID);
Expand All @@ -77,7 +152,42 @@ class gpulist {
uint16_t* pGPUID);
static int node2bdf(const uint16_t NodeID, std::string& pPciBDF);
static std::string gpu_get_platform_name (void);
static const GpuInfo* get_gpu_info_by_gpu_id(uint16_t gpu_id);

static const GpuInfo* get_gpu_info_by_location(uint16_t location_id);

static const GpuInfo* get_gpu_info_by_node(uint16_t node_id);

//Get all GPU information
static const std::vector<GpuInfo>& get_all_gpu_info();
static bool is_valid_gpu_id(uint16_t gpu_id);

static size_t get_gpu_count();

static void clear();

protected:
/// Master list of all GPU information
static std::vector<GpuInfo> gpu_info_list;

static std::unordered_map<uint16_t, size_t> gpu_id_to_index;//get index in master list
static std::unordered_map<uint16_t, size_t> location_id_to_index;
static std::unordered_map<uint16_t, size_t> node_id_to_index;

static std::unordered_map<uint16_t, size_t> device_id_to_index;

struct PairHash {
template <class T1, class T2>
std::size_t operator()(const std::pair<T1, T2>& p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ (h2 << 1);
}
};

static std::unordered_map<std::pair<uint16_t, uint16_t>, size_t, PairHash>
domain_location_to_index;

//! Array of GPU location IDs
static std::vector<uint16_t> location_id;
//! Array of GPU IDs
Expand All @@ -93,6 +203,14 @@ class gpulist {
//! Array of PCI BDFs
static std::vector<std::string> pci_bdf;
static std::map<std::pair<uint16_t, uint16_t> , uint16_t> domain_loc_map;

private:
// checkers for sanity
static bool validate_output_pointer(const void* ptr, const char* func_name);

static bool check_initialized(const char* func_name);

static bool validate_index(size_t index, const char* func_name);
};

} // namespace rvs
Expand Down
2 changes: 1 addition & 1 deletion mem.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern "C" int rvs_module_init(void* pMi) {

extern "C" int rvs_module_terminate(void) {
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion pbqt.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extern "C" int rvs_module_init(void* pMi) {
extern "C" int rvs_module_terminate(void) {
rvs::hsa::Terminate();
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion pebb.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extern "C" int rvs_module_terminate(void) {
rvs::lp::Log("[module_terminate] pebb rvs_module_terminate() - entered",
rvs::logtrace);
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion peqt.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern "C" int rvs_module_init(void* pMi) {

extern "C" int rvs_module_terminate(void) {
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion perf.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern "C" int rvs_module_init(void* pMi) {
}

extern "C" int rvs_module_terminate(void) {
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion pesm.so/src/rvs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern "C" int rvs_module_terminate(void) {
rvs::logtrace);
}
cleanup_logs();
amdsmi_shut_down();

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions rvs/src/rvs_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <include/rvs.h>
#include <include/rvsinternal.h>
#include <include/rvsexec.h>
#include "include/gpu_util.h"
#include <map>
#include <mutex>

Expand Down Expand Up @@ -290,6 +291,7 @@ rvs_status_t rvs_terminate(void) {
if (RVS_STATE_INITIALIZED != rvs_state) {
return RVS_STATUS_INVALID_STATE;
}
rvs::gpulist::Shutdown();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's abstract these kind implementations from the RVS interface? And move it internally.

rvs_state = RVS_STATE_UNINITIALIZED;

return RVS_STATUS_SUCCESS;
Expand Down
Loading
Loading