SWDEV-388493 - Use HSA APIs instead of rocminfo
- Recreation of github PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/217 - For Unit_hipGetDeviceAttribute_CheckFineGrainSupport test, get segment information using HSA APIs instead of rocminfo Change-Id: I20f4c8a6669684a2326a3ce61735c4fa10433f9d
This commit is contained in:
1 parent
1d9aadbf92
commit
f85b731a5c
2 files changed
+84
-63
No files matched your search
@@ -45,5 +45,13 @@ hip_add_exe_to_target(NAME DeviceTest
|
|||||||
TEST_SRC ${TEST_SRC}
|
TEST_SRC ${TEST_SRC}
|
||||||
TEST_TARGET_NAME build_tests
|
TEST_TARGET_NAME build_tests
|
||||||
COMPILE_OPTIONS -std=c++17)
|
COMPILE_OPTIONS -std=c++17)
|
||||||
|
# Add hsa-runtime dependencies for Unit_hipGetDeviceAttribute_CheckFineGrainSupport
|
||||||
|
if(UNIX)
|
||||||
|
if(HIP_PLATFORM STREQUAL "amd")
|
||||||
|
target_include_directories(DeviceTest PRIVATE ${ROCM_PATH}/include)
|
||||||
|
target_link_libraries(DeviceTest hsa-runtime64)
|
||||||
|
target_link_directories(DeviceTest PRIVATE ${ROCM_PATH}/lib)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
add_dependencies(build_tests getDeviceCount)
|
add_dependencies(build_tests getDeviceCount)
|
||||||
@@ -35,6 +35,21 @@ THE SOFTWARE.
|
|||||||
* Query for a specific device attribute.
|
* Query for a specific device attribute.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#if HT_AMD
|
||||||
|
#include "hsa/hsa_ext_amd.h"
|
||||||
|
#define HSA_CHECK(exp) { \
|
||||||
|
hsa_status_t status = (exp); \
|
||||||
|
if (status != HSA_STATUS_SUCCESS) { \
|
||||||
|
INFO("HSA Error Code: " << status \
|
||||||
|
<< "\n Str: " << #exp << "\n In File: " << __FILE__ \
|
||||||
|
<< "\n At line: " << __LINE__); \
|
||||||
|
REQUIRE(false); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#endif // HT_AMD
|
||||||
|
#endif // __linux__
|
||||||
|
|
||||||
static hipError_t test_hipDeviceGetAttribute(int deviceId,
|
static hipError_t test_hipDeviceGetAttribute(int deviceId,
|
||||||
hipDeviceAttribute_t attr,
|
hipDeviceAttribute_t attr,
|
||||||
int expectedValue = -1) {
|
int expectedValue = -1) {
|
||||||
@@ -257,28 +272,55 @@ TEST_CASE("Unit_hipGetDeviceAttribute_CheckAttrValues") {
|
|||||||
*/
|
*/
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#if HT_AMD
|
#if HT_AMD
|
||||||
#define COMMAND_LEN 256
|
|
||||||
#define BUFFER_LEN 512
|
|
||||||
|
|
||||||
static bool isRocmPathSet() {
|
typedef struct {
|
||||||
FILE *fpipe;
|
int device_index;
|
||||||
char const *command = "echo $ROCM_PATH";
|
int *fine_grained_val;
|
||||||
fpipe = popen(command, "r");
|
} MemoryPoolInfo;
|
||||||
|
|
||||||
if (fpipe == nullptr) {
|
|
||||||
printf("Unable to create command\n");
|
hsa_status_t IterateMemoryPoolCallback(hsa_amd_memory_pool_t pool, void* data) {
|
||||||
return false;
|
MemoryPoolInfo* memory_pool_info = reinterpret_cast<MemoryPoolInfo*>(data);
|
||||||
}
|
hsa_region_segment_t segment_type = (hsa_region_segment_t)0;
|
||||||
char command_op[BUFFER_LEN];
|
|
||||||
if (fgets(command_op, BUFFER_LEN, fpipe)) {
|
// Get segment information for this memory pool
|
||||||
size_t len = strlen(command_op);
|
HSA_CHECK(hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_SEGMENT, &segment_type));
|
||||||
if (len > 1) { // This is because fgets always adds newline character
|
|
||||||
pclose(fpipe);
|
// Check for global segment
|
||||||
return true;
|
if (segment_type == HSA_REGION_SEGMENT_GLOBAL) {
|
||||||
|
uint32_t global_flag = 0;
|
||||||
|
// Get global flags for this memory pool
|
||||||
|
HSA_CHECK(hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS,
|
||||||
|
&global_flag));
|
||||||
|
|
||||||
|
// If it is fine grained, then store the information
|
||||||
|
if ((global_flag & HSA_REGION_GLOBAL_FLAG_FINE_GRAINED) != 0) {
|
||||||
|
memory_pool_info->fine_grained_val[memory_pool_info->device_index] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pclose(fpipe);
|
return HSA_STATUS_SUCCESS;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
hsa_status_t IterateAgentCallback(hsa_agent_t agent, void* data) {
|
||||||
|
hsa_device_type_t dev_type = HSA_DEVICE_TYPE_CPU;
|
||||||
|
MemoryPoolInfo* memory_pool_info = reinterpret_cast<MemoryPoolInfo*>(data);
|
||||||
|
|
||||||
|
// Get device type for this agent
|
||||||
|
HSA_CHECK(hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &dev_type));
|
||||||
|
// If it is GPU device, then collect memory pool information
|
||||||
|
if (dev_type == HSA_DEVICE_TYPE_GPU) {
|
||||||
|
memory_pool_info->device_index++;
|
||||||
|
HSA_CHECK(hsa_amd_agent_iterate_memory_pools(agent, IterateMemoryPoolCallback,
|
||||||
|
memory_pool_info));
|
||||||
|
}
|
||||||
|
return HSA_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Fine-grained memory information from HSA
|
||||||
|
void HsaGetFineGrainInfo(MemoryPoolInfo* memory_pool_info)
|
||||||
|
{
|
||||||
|
HSA_CHECK(hsa_init());
|
||||||
|
HSA_CHECK(hsa_iterate_agents(IterateAgentCallback, memory_pool_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,48 +339,22 @@ static bool isRocmPathSet() {
|
|||||||
TEST_CASE("Unit_hipGetDeviceAttribute_CheckFineGrainSupport") {
|
TEST_CASE("Unit_hipGetDeviceAttribute_CheckFineGrainSupport") {
|
||||||
int deviceId;
|
int deviceId;
|
||||||
int deviceCount = 0;
|
int deviceCount = 0;
|
||||||
FILE *fpipe;
|
|
||||||
char command[COMMAND_LEN] = "";
|
|
||||||
const char *rocmpath = nullptr;
|
|
||||||
if (isRocmPathSet()) {
|
|
||||||
// For STG2 testing where /opt/rocm path is not present
|
|
||||||
rocmpath = "$ROCM_PATH/bin/rocminfo";
|
|
||||||
} else {
|
|
||||||
// Check if the rocminfo tool exists
|
|
||||||
rocmpath = "/opt/rocm/bin/rocminfo";
|
|
||||||
}
|
|
||||||
snprintf(command, COMMAND_LEN, "%s", rocmpath);
|
|
||||||
strncat(command, " | grep -i \"Segment:\\|Uuid:\"", COMMAND_LEN);
|
|
||||||
// Execute the rocminfo command and extract the segment info
|
|
||||||
fpipe = popen(command, "r");
|
|
||||||
if (fpipe == nullptr) {
|
|
||||||
printf("Unable to create command file\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HIP_CHECK(hipGetDeviceCount(&deviceCount));
|
HIP_CHECK(hipGetDeviceCount(&deviceCount));
|
||||||
assert(deviceCount > 0);
|
assert(deviceCount > 0);
|
||||||
int *fine_grained_val = new int[deviceCount];
|
|
||||||
assert(fine_grained_val != nullptr);
|
MemoryPoolInfo memory_pool_info = {-1, nullptr};
|
||||||
bool *gpuFound = new bool[deviceCount];
|
|
||||||
assert(gpuFound != nullptr);
|
memory_pool_info.fine_grained_val = new int[deviceCount];
|
||||||
|
assert(memory_pool_info.fine_grained_val != nullptr);
|
||||||
for (int i = 0; i < deviceCount; i++) {
|
for (int i = 0; i < deviceCount; i++) {
|
||||||
gpuFound[i] = false;
|
memory_pool_info.fine_grained_val[i] = 0; // Initialize to 0
|
||||||
fine_grained_val[i] = 0; // Initialize to 0
|
|
||||||
}
|
|
||||||
char command_op[BUFFER_LEN];
|
|
||||||
int count = -1;
|
|
||||||
// Extract each segment flags
|
|
||||||
while (fgets(command_op, BUFFER_LEN, fpipe) && (count + 1) < deviceCount) {
|
|
||||||
std::string rocminfo_line(command_op);
|
|
||||||
if ((std::string::npos != rocminfo_line.find("GPU-")) &&
|
|
||||||
(std::string::npos != rocminfo_line.find("Uuid:"))) {
|
|
||||||
count++;
|
|
||||||
gpuFound[count] = true;
|
|
||||||
} else if (count >= 0 && gpuFound[count] &&
|
|
||||||
(std::string::npos != rocminfo_line.find("FLAGS: FINE GRAINED"))) {
|
|
||||||
fine_grained_val[count] = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Fine-grained memory information from HSA
|
||||||
|
HsaGetFineGrainInfo(&memory_pool_info);
|
||||||
|
|
||||||
|
// Validate hipDeviceAttributeFineGrainSupport
|
||||||
for (int dev = 0; dev < deviceCount; dev++) {
|
for (int dev = 0; dev < deviceCount; dev++) {
|
||||||
HIP_CHECK(hipSetDevice(dev));
|
HIP_CHECK(hipSetDevice(dev));
|
||||||
HIP_CHECK(hipGetDevice(&deviceId));
|
HIP_CHECK(hipGetDevice(&deviceId));
|
||||||
@@ -347,15 +363,12 @@ TEST_CASE("Unit_hipGetDeviceAttribute_CheckFineGrainSupport") {
|
|||||||
int value = 0;
|
int value = 0;
|
||||||
HIP_CHECK(hipDeviceGetAttribute(&value,
|
HIP_CHECK(hipDeviceGetAttribute(&value,
|
||||||
hipDeviceAttributeFineGrainSupport, deviceId));
|
hipDeviceAttributeFineGrainSupport, deviceId));
|
||||||
REQUIRE(value == fine_grained_val[dev]);
|
REQUIRE(value == memory_pool_info.fine_grained_val[dev]);
|
||||||
}
|
}
|
||||||
// Validate hipDeviceAttributeFineGrainSupport
|
delete[] memory_pool_info.fine_grained_val;
|
||||||
delete[] fine_grained_val;
|
|
||||||
delete[] gpuFound;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif // HT_AMD
|
||||||
#endif
|
#endif // __linux__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Description
|
* Test Description
|
||||||
* ------------------------
|
* ------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user