SWDEV-546485 Port and clean up for all tests in catch/perftests/memory folder. (#558)

* SWDEV-546485 Port and clean up for hipPerfBufferCopyRectSpeed

* SWDEV-546485 Port and clean up for hipPerfDevMemReadSpeed

* SWDEV-546485 Port and clean up for hipPerfDevMemWriteSpeed

* SWDEV-546485 Port and clean up for hipPerfHostNumaAlloc

* SWDEV-546485 Port and clean up for hipPerfMemcpy

* SWDEV-546485 Port and clean up for hipPerfMemMallocCpyFree

* SWDEV-546485 Port and clean up for hipPerfMemset

* SWDEV-546485 Port and clean up for hipPerfSampleRate

* SWDEV-546485 Port and clean up for hipPerfSharedMemReadSpeed

* SWDEV-546485 Ported and fixed up segfault for hipPerfMemFill

* SWDEV-545485 Returning to unedited stage
This commit is contained in:
Naeisseh, Hadi
2025-08-15 16:09:19 -04:00
committed by GitHub
parent 9fdc9a98b7
commit 04469c0cde
20 changed files with 603 additions and 3195 deletions
@@ -18,30 +18,31 @@ THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpy2DAsync hipMemcpy2DAsync
* @{
* @ingroup perfMemoryTest
* `hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t spitch,
* size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream = 0)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpy2DAsync hipMemcpy2DAsync
* @{
* @ingroup perfMemoryTest
* `hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t spitch,
* size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream = 0)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
// #define ENABLE_DEBUG 1
#define NUM_SIZES 8
// 4KB, 8KB, 64KB, 256KB, 1 MB, 4MB, 16 MB, 16MB+10
static const unsigned int Sizes[NUM_SIZES] =
{4096, 8192, 65536, 262144, 1048576, 4194304, 16777216, 16777216+10};
static const unsigned int Sizes[NUM_SIZES] = {4096, 8192, 65536, 262144,
1048576, 4194304, 16777216, 16777216 + 10};
static const unsigned int Iterations[2] = {1, 1000};
#define BUF_TYPES 4
// 16 ways to combine 4 different buffer types
#define NUM_SUBTESTS (BUF_TYPES*BUF_TYPES)
#define NUM_SUBTESTS (BUF_TYPES * BUF_TYPES)
static void setData(void *ptr, unsigned int size, char value) {
char *ptr2 = reinterpret_cast<char *>(ptr);
for (unsigned int i = 0; i < size ; i++) {
static void setData(void* ptr, unsigned int size, char value) {
char* ptr2 = reinterpret_cast<char*>(ptr);
for (unsigned int i = 0; i < size; i++) {
ptr2[i] = value;
}
}
@@ -52,17 +53,17 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
bool hostMalloc[2] = {false};
bool hostRegister[2] = {false};
bool unpinnedMalloc[2] = {false};
void *memptr[2] = {NULL};
void *alignedmemptr[2] = {NULL};
void *srcBuffer = NULL;
void *dstBuffer = NULL;
void* memptr[2] = {NULL};
void* alignedmemptr[2] = {NULL};
void* srcBuffer = NULL;
void* dstBuffer = NULL;
int numTests = (p_tests == -1) ? (NUM_SIZES*NUM_SUBTESTS*2 - 1) : p_tests;
int numTests = (p_tests == -1) ? (NUM_SIZES * NUM_SUBTESTS * 2 - 1) : p_tests;
int test = (p_tests == -1) ? 0 : p_tests;
for ( ; test <= numTests ; test++ ) {
for (; test <= numTests; test++) {
unsigned int srcTest = (test / NUM_SIZES) % BUF_TYPES;
unsigned int dstTest = (test / (NUM_SIZES*BUF_TYPES)) % BUF_TYPES;
unsigned int dstTest = (test / (NUM_SIZES * BUF_TYPES)) % BUF_TYPES;
bufSize_ = Sizes[test % NUM_SIZES];
hostMalloc[0] = hostMalloc[1] = false;
hostRegister[0] = hostRegister[1] = false;
@@ -92,8 +93,7 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
numIter = Iterations[test / (NUM_SIZES * NUM_SUBTESTS)];
if (hostMalloc[0]) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&srcBuffer),
bufSize_, 0));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&srcBuffer), bufSize_, 0));
setData(srcBuffer, bufSize_, 0xd0);
} else if (hostRegister[0]) {
memptr[0] = malloc(bufSize_ + 4096);
@@ -112,8 +112,7 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
}
if (hostMalloc[1]) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&dstBuffer),
bufSize_, 0));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&dstBuffer), bufSize_, 0));
} else if (hostRegister[1]) {
memptr[1] = malloc(bufSize_ + 4096);
alignedmemptr[1] = reinterpret_cast<void*>(memptr[0]);
@@ -128,15 +127,14 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
}
// warm up
HIP_CHECK(hipMemcpy2D(dstBuffer, width, srcBuffer,
width, width, width, hipMemcpyDefault));
HIP_CHECK(hipMemcpy2D(dstBuffer, width, srcBuffer, width, width, width, hipMemcpyDefault));
// measure performance based on host time
auto all_start = std::chrono::steady_clock::now();
for (unsigned int i = 0; i < numIter; i++) {
HIP_CHECK(hipMemcpy2DAsync(dstBuffer, width, srcBuffer,
width, width, width, hipMemcpyDefault, NULL));
HIP_CHECK(hipMemcpy2DAsync(dstBuffer, width, srcBuffer, width, width, width, hipMemcpyDefault,
NULL));
}
HIP_CHECK(hipDeviceSynchronize());
@@ -144,11 +142,11 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
std::chrono::duration<double> elapsed_secs = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(bufSize_ * numIter) *
static_cast<double>(1e-09)) / elapsed_secs.count();
double perf = (static_cast<double>(bufSize_ * numIter) * static_cast<double>(1e-09)) /
elapsed_secs.count();
const char *strSrc = NULL;
const char *strDst = NULL;
const char* strSrc = NULL;
const char* strDst = NULL;
if (hostMalloc[0])
strSrc = "hHM";
else if (hostRegister[0])
@@ -170,15 +168,14 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
// Double results when src and dst are both on device
if ((!hostMalloc[0] && !hostRegister[0] && !unpinnedMalloc[0]) &&
(!hostMalloc[1] && !hostRegister[1] && !unpinnedMalloc[1]))
perf *= 2.0;
perf *= 2.0;
// Double results when src and dst are both in sysmem
if ((hostMalloc[0] || hostRegister[0] || unpinnedMalloc[0]) &&
(hostMalloc[1] || hostRegister[1] || unpinnedMalloc[1]))
perf *= 2.0;
perf *= 2.0;
INFO("hipPerfBufferCopyRectSpeed[" << test << "]\t( " << bufSize_ <<
")\ts:" << strSrc << " d:" << strDst << "\ti:" << numIter <<
"\t(GB/s) perf\t" << (float)perf);
CONSOLE_PRINT("hipPerfBufferCopyRectSpeed[%d]\t( %u )\ts:%s d:%s\ti:%u\t(GB/s) perf\t%.2f\n",
test, bufSize_, strSrc, strDst, numIter, (float)perf);
// Free src
if (hostMalloc[0]) {
@@ -208,40 +205,42 @@ static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfBufferCopy status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfBufferCopyRectSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfBufferCopy status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfBufferCopyRectSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfBufferCopyRectSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfBufferCopyRectSpeed"
"as there is no device to test.");
SUCCEED(
"Skipped testcase hipPerfBufferCopyRectSpeed"
"as there is no device to test.");
} else {
int deviceId = 0;
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("hipPerfBufferCopyRectSpeed - info: Set device to " << deviceId
<< " : " << props.name << "Legend: unp - unpinned(malloc),"
" hM - hipMalloc(device)\n hHR - hipHostRegister(pinned),"
" hHM - hipHostMalloc(prePinned)\n");
CONSOLE_PRINT(
"hipPerfBufferCopyRectSpeed - info: Set device to %d : %s Legend: unp - unpinned(malloc), "
"hM - hipMalloc(device)\n hHR - hipHostRegister(pinned), hHM - "
"hipHostMalloc(prePinned)\n",
deviceId, props.name);
REQUIRE(true == hipPerfBufferCopyRectSpeed_test(1));
}
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/