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:
@@ -18,13 +18,13 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hipMemcpy hipMemcpy
|
||||
* @{
|
||||
* @ingroup perfMemoryTest
|
||||
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
|
||||
* Copies data between host and device.
|
||||
*/
|
||||
|
||||
* @addtogroup hipMemcpy hipMemcpy
|
||||
* @{
|
||||
* @ingroup perfMemoryTest
|
||||
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
|
||||
* Copies data between host and device.
|
||||
*/
|
||||
// #define ENABLE_DEBUG 1
|
||||
#include <time.h>
|
||||
#include <hip_test_common.hh>
|
||||
|
||||
@@ -38,7 +38,7 @@ void valSet(int* A, int val, size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
void setup(size_t *size, int *num, int **pA, const size_t totalGlobalMem) {
|
||||
void setup(size_t* size, int* num, int** pA, const size_t totalGlobalMem) {
|
||||
for (int i = 0; i < *num; i++) {
|
||||
size[i] = 1 << (i + 6);
|
||||
if ((NUM_ITER + 1) * size[i] > totalGlobalMem) {
|
||||
@@ -50,39 +50,39 @@ void setup(size_t *size, int *num, int **pA, const size_t totalGlobalMem) {
|
||||
valSet(*pA, 1, size[*num - 1]);
|
||||
}
|
||||
|
||||
void testInit(size_t size, int *A) {
|
||||
int *Ad;
|
||||
void testInit(size_t size, int* A) {
|
||||
int* Ad;
|
||||
|
||||
clock_t start = clock();
|
||||
HIP_CHECK(hipMalloc(&Ad, size)); // hip::init() will be called
|
||||
HIP_CHECK(hipMalloc(&Ad, size)); // hip::init() will be called
|
||||
clock_t end = clock();
|
||||
double uS = (end - start) * 1000000. / CLOCKS_PER_SEC;
|
||||
INFO("Initial: hipMalloc(" << size << ") cost " << uS << "us" << "\n");
|
||||
CONSOLE_PRINT("Initial: hipMalloc(%zu) cost %.2fus\n", size, uS);
|
||||
|
||||
start = clock();
|
||||
HIP_CHECK(hipMemcpy(Ad, A, size, hipMemcpyHostToDevice));
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
end = clock();
|
||||
uS = (end - start) * 1000000. / CLOCKS_PER_SEC;
|
||||
INFO("hipMemcpy(" << size << ") cost " << uS << "us" << "\n");
|
||||
CONSOLE_PRINT("hipMemcpy(%zu) cost %.2fus\n", size, uS);
|
||||
|
||||
start = clock();
|
||||
HIP_CHECK(hipFree(Ad));
|
||||
end = clock();
|
||||
uS = (end - start) * 1000000. / CLOCKS_PER_SEC;
|
||||
INFO("hipFree(" << size << ") cost " << uS << "us" << "\n");
|
||||
CONSOLE_PRINT("hipFree(%zu) cost %.2fus\n", size, uS);
|
||||
}
|
||||
|
||||
static bool hipPerfMemMallocCpyFree_test() {
|
||||
double uS;
|
||||
clock_t start, end;
|
||||
size_t size[NUM_SIZE] = { 0 };
|
||||
int *Ad[NUM_ITER] = { nullptr };
|
||||
int *A;
|
||||
size_t size[NUM_SIZE] = {0};
|
||||
int* Ad[NUM_ITER] = {nullptr};
|
||||
int* A;
|
||||
hipDeviceProp_t props;
|
||||
memset(&props, 0, sizeof(props));
|
||||
HIP_CHECK(hipGetDeviceProperties(&props, 0));
|
||||
INFO("totalGlobalMem: " << props.totalGlobalMem << "\n");
|
||||
CONSOLE_PRINT("totalGlobalMem: %zu\n", props.totalGlobalMem);
|
||||
|
||||
int num = NUM_SIZE;
|
||||
setup(size, &num, &A, props.totalGlobalMem);
|
||||
@@ -91,59 +91,60 @@ static bool hipPerfMemMallocCpyFree_test() {
|
||||
for (int i = 0; i < num; i++) {
|
||||
start = clock();
|
||||
for (int j = 0; j < NUM_ITER; j++) {
|
||||
HIP_CHECK(hipMalloc(&Ad[j], size[i]));
|
||||
HIP_CHECK(hipMalloc(&Ad[j], size[i]));
|
||||
}
|
||||
end = clock();
|
||||
uS = (end - start) * 1000000. / (NUM_ITER * CLOCKS_PER_SEC);
|
||||
INFO("hipMalloc(" << size[i] << ") cost " << uS << "us" << "\n");
|
||||
CONSOLE_PRINT("hipMalloc(%zu) cost %.2fus\n", size[i], uS);
|
||||
|
||||
start = clock();
|
||||
for (int j = 0; j < NUM_ITER; j++) {
|
||||
HIP_CHECK(hipMemcpy(Ad[j], A, size[i], hipMemcpyHostToDevice));
|
||||
HIP_CHECK(hipMemcpy(Ad[j], A, size[i], hipMemcpyHostToDevice));
|
||||
}
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
end = clock();
|
||||
uS = (end - start) * 1000000. / (NUM_ITER * CLOCKS_PER_SEC);
|
||||
INFO("hipMemcpy(" << size[i] << ") cost " << uS << "us" << "\n");
|
||||
CONSOLE_PRINT("hipMemcpy(%zu) cost %.2fus\n", size[i], uS);
|
||||
|
||||
start = clock();
|
||||
for (int j = 0; j < NUM_ITER; j++) {
|
||||
HIP_CHECK(hipFree(Ad[j]));
|
||||
Ad[j] = nullptr;
|
||||
HIP_CHECK(hipFree(Ad[j]));
|
||||
Ad[j] = nullptr;
|
||||
}
|
||||
end = clock();
|
||||
double uS = (end - start) * 1000000. / (NUM_ITER * CLOCKS_PER_SEC);
|
||||
INFO("hipFree(" << size[i] << ") cost " << uS << "us" << "\n");
|
||||
CONSOLE_PRINT("hipFree(%zu) cost %.2fus\n", size[i], uS);
|
||||
}
|
||||
free(A);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Verify hipPerfMemMallocCpyFree status.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - perftests/memory/hipPerfMemMallocCpyFree.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
*/
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Verify hipPerfMemMallocCpyFree status.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - perftests/memory/hipPerfMemMallocCpyFree.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
*/
|
||||
|
||||
TEST_CASE("Perf_hipPerfMemMallocCpyFree_test") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
|
||||
if (numDevices <= 0) {
|
||||
SUCCEED("Skipped testcase hipPerfDevMemReadSpeed as"
|
||||
"there is no device to test.");
|
||||
SUCCEED(
|
||||
"Skipped testcase hipPerfDevMemReadSpeed as"
|
||||
"there is no device to test.");
|
||||
} else {
|
||||
REQUIRE(true == hipPerfMemMallocCpyFree_test());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End doxygen group perfMemoryTest.
|
||||
* @}
|
||||
*/
|
||||
* End doxygen group perfMemoryTest.
|
||||
* @}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user