Skip to content
Closed
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
56 changes: 56 additions & 0 deletions rocrtst/common/base_rocr_utils.cc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <algorithm>
#include "common/base_rocr.h"
#include "common/helper_funcs.h"
#include "common/os.h"
Expand Down Expand Up @@ -512,6 +513,61 @@ hsa_status_t AllocAndSetKernArgs(BaseRocR* test, void* args, size_t arg_size) {
return HSA_STATUS_SUCCESS;
}

// Returns the first “gfx…” string for this GPU agent.
// gfx_id – will get “gfx940”, “gfx1201” etc
// return – true = found, false = nothing usable
bool GetISAGfxString(const hsa_agent_t agent, std::string& gfx_id) {
// Iterate over every ISA for this agent
hsa_status_t status = hsa_agent_iterate_isas(
agent,
/* Callback lambda - invoked once per ISA*/
[](hsa_isa_t isa, void* data) -> hsa_status_t {
std::string* result = static_cast<std::string*>(data);

// Ask how long the ISA name is..
uint32_t len = 0;
if (hsa_isa_get_info_alt(isa, HSA_ISA_INFO_NAME_LENGTH, &len) != HSA_STATUS_SUCCESS)
return HSA_STATUS_SUCCESS;

std::string name(len + 1, '\0');
// Read full name..
if (hsa_isa_get_info_alt(isa, HSA_ISA_INFO_NAME, &name[0]) != HSA_STATUS_SUCCESS) {
std::cout << " hsa_isa_get_info_alt(HSA_ISA_INFO_NAME) failed" << std::endl;
return HSA_STATUS_SUCCESS; // continue iterating
}

name.resize(len);

// Skip any "*-generic” entry

if (name.rfind("generic") != std::string::npos) return HSA_STATUS_SUCCESS;
// Found the ISA name - save and stop iterating
*result = std::move(name);
return HSA_STATUS_INFO_BREAK;
},
&gfx_id);

// If the walk itself failed, give up
if (status != HSA_STATUS_INFO_BREAK && status != HSA_STATUS_SUCCESS) return false;

// Nothing stored.. Also give up..
if (gfx_id.empty()) return false;

// Extract the "gfx.." part
std::size_t pos = gfx_id.rfind("gfx");
if (pos == std::string::npos) return false; // no gfx or GFX found in the string

gfx_id.erase(0, pos); // keep only the "gfxXYZ" part

// Keep letters/digits after “gfx”; stop at first separator
auto it_end = std::find_if_not(gfx_id.begin() + 3, gfx_id.end(), [](char c) {
return std::isalnum(static_cast<unsigned char>(c));
});
gfx_id.erase(it_end, gfx_id.end());

return !gfx_id.empty(); // true if something like “gfx940”
}

#undef RET_IF_HSA_UTILS_ERR

} // namespace rocrtst
12 changes: 12 additions & 0 deletions rocrtst/common/base_rocr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,17 @@ hsa_status_t SetPoolsTypical(BaseRocR* test);
/// \returns HSA_STATUS_OK if not errors
hsa_status_t hsa_memory_fill_workaround_gen(void* ptr, uint32_t value,
size_t count, hsa_agent_t dst_ag, hsa_agent_t src_ag, BaseRocR* test);


/// Helper function that iterates through hsa_agent_iterate_isas, selects the first ISA
/// that does not contain “-generic”, chops the prefix up to the substring
/// “gfx”, then truncates the token to `[0-9a-z]` characters that
/// belong to the gfx ID (e.g. gfx940, gfx1200).
/// \param[in] agent HSA agent whose ISA list will be scanned.
/// \param[out] gfx_id On success, receives the gfx name
/// \returns true – success, gfx_id is filled
/// false – no ISA could be found or parsed
///
bool GetISAGfxString(hsa_agent_t agent, std::string& gfx_id);
} // namespace rocrtst
#endif // ROCRTST_COMMON_BASE_ROCR_UTILS_H_
41 changes: 34 additions & 7 deletions rocrtst/suites/negative/memory_allocate_negative_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@

static const uint32_t kNumBufferElements = 256;





#define RET_IF_HSA_ERR(err) { \
if ((err) != HSA_STATUS_SUCCESS) { \
const char* msg = 0; \
Expand Down Expand Up @@ -328,6 +324,7 @@ hsa_status_t CallbackSystemErrorHandling(const hsa_amd_event_t* event, void* dat
void MemoryAllocateNegativeTest::FreeQueueRingBufferTest(void) {
hsa_status_t err;

// Prepare a blank AQL dispatch packet and point it to empty_kernel
memset(&aql(), 0, sizeof(hsa_kernel_dispatch_packet_t));
set_kernel_file_name("dispatch_time_kernels.hsaco");
set_kernel_name("empty_kernel");
Expand All @@ -346,16 +343,46 @@ void MemoryAllocateNegativeTest::FreeQueueRingBufferTest(void) {
err = hsa_iterate_agents(rocrtst::IterateGPUAgents, &gpus);
ASSERT_EQ(err, HSA_STATUS_SUCCESS);

for (unsigned int i = 0; i < gpus.size(); ++i) {
FreeQueueRingBufferTest(gpus[i]);
bool found_gpu = false;
for (hsa_agent_t gpuAgent : gpus) {
std::string gfx;
if (!rocrtst::GetISAGfxString(gpuAgent, gfx)) {
std::cout << "[FreeQueueRingBufferTest] Could not derive ISA for agent – skipping.."
<< std::endl;
continue;
}

// The first three characters after "gfx" are digits.Convert them to int
// int ver = std::stoi(gfx.substr(3));
std::size_t p = 3;
while (p < gfx.size() && std::isdigit(static_cast<unsigned char>(gfx[p]))) ++p;
int ver = std::stoi(gfx.substr(3, p - 3)); // e.g. “940”, “1201”

// Skip everything older than gfx94x
if (ver < 940) {
if (verbosity() > 0) {
std::cout << " Test not applicable for GPU: " << gfx << ". Skipping.\n"
<< kSubTestSeparator << std::endl;
}
continue; // next GPU
}

// We found the gfx94x+ GPU. Run the negative test now.
found_gpu = true;

FreeQueueRingBufferTest(gpuAgent);
}

if (verbosity() > 0) {
std::cout << "subtest Passed" << std::endl;
if (found_gpu)
std::cout << "subtest Passed\n"; // atleast on GPU was tested
else
std::cout << "subtest Skipped – no GPU found\n";
std::cout << kSubTestSeparator << std::endl;
}
}


void MemoryAllocateNegativeTest::FreeQueueRingBufferTest(hsa_agent_t gpuAgent) {
hsa_status_t err;

Expand Down
6 changes: 1 addition & 5 deletions rocrtst/suites/test_common/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,7 @@ TEST(rocrtstNeg, Memory_Negative_Tests) {
RunCustomTestProlog(&mt);
mt.ZeroMemoryAllocateTest();
mt.MaxMemoryAllocateTest();

// Disabled temporarily - Renable this test only
// on recent GPUs - gfx94x+
// mt.FreeQueueRingBufferTest();

mt.FreeQueueRingBufferTest();
RunCustomTestEpilog(&mt);
}

Expand Down
Loading