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
zatwierdzone przez GitHub
rodzic 9fdc9a98b7
commit 04469c0cde
20 zmienionych plików z 603 dodań i 3195 usunięć
@@ -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.
* @}
*/
@@ -18,13 +18,14 @@ THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
// #define ENABLE_DEBUG 1
#include <hip_test_common.hh>
#define ARRAY_SIZE 16
@@ -33,7 +34,7 @@ typedef struct d_uint16 {
uint data[ARRAY_SIZE];
} d_uint16;
__global__ static void read_kernel(d_uint16 *src, ulong N, uint *dst) {
__global__ static void read_kernel(d_uint16* src, ulong N, uint* dst) {
size_t idx = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
@@ -59,8 +60,8 @@ static bool hipPerfDevMemReadSpeed_test() {
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount << " CUs \n");
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs\n", props.pciBusID, props.name,
props.multiProcessorCount);
const unsigned threadsPerBlock = 64;
const unsigned blocks = props.multiProcessorCount * 4;
@@ -70,7 +71,7 @@ static bool hipPerfDevMemReadSpeed_test() {
hSrc = new d_uint16[nBytes];
REQUIRE(hSrc != nullptr);
hDst = new uint;
hDst = new uint;
REQUIRE(hDst != nullptr);
hDst[0] = 0;
@@ -88,15 +89,15 @@ static bool hipPerfDevMemReadSpeed_test() {
HIP_CHECK(hipMemcpy(dSrc, hSrc, nBytes, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(dDst, hDst, sizeof(uint), hipMemcpyHostToDevice));
hipLaunchKernelGGL(read_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dSrc, N, dDst);
hipLaunchKernelGGL(read_kernel, dim3(blocks), dim3(threadsPerBlock), 0, stream, dSrc, N, dDst);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(hDst, dDst, sizeof(uint), hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
if (hDst[0] != (nBytes / sizeof(uint))) {
INFO("hipPerfDevMemReadSpeed - Data validation failed for warm up run!" <<
" expected " << nBytes / sizeof(uint) << " got " << hDst[0]);
DEBUG_PRINT(
"hipPerfDevMemReadSpeed - Data validation failed for warm up run! expected %u got %u\n",
nBytes / sizeof(uint), hDst[0]);
return false;
}
@@ -104,8 +105,7 @@ static bool hipPerfDevMemReadSpeed_test() {
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(read_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dSrc, N, dDst);
hipLaunchKernelGGL(read_kernel, dim3(blocks), dim3(threadsPerBlock), 0, stream, dSrc, N, dDst);
HIP_CHECK(hipGetLastError());
}
HIP_CHECK(hipDeviceSynchronize());
@@ -114,14 +114,14 @@ static bool hipPerfDevMemReadSpeed_test() {
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(nBytes * nIter * (1e-09))) /
all_kernel_time.count();
double perf = (static_cast<double>(nBytes * nIter * (1e-09))) / all_kernel_time.count();
INFO("hipPerfDevMemReadSpeed - info: average read speed of " <<
perf << " GB/s " << "achieved for memory size of " <<
nBytes / (1024 * 1024) << " MB");
CONSOLE_PRINT(
"hipPerfDevMemReadSpeed - average read speed of %.2f GB/s achieved for memory size of %u "
"MB\n",
perf, nBytes / (1024 * 1024));
delete [] hSrc;
delete[] hSrc;
delete hDst;
HIP_CHECK(hipFree(dSrc));
HIP_CHECK(hipFree(dDst));
@@ -130,30 +130,31 @@ static bool hipPerfDevMemReadSpeed_test() {
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfDevMemReadSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfDevMemReadSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfDevMemReadSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfDevMemReadSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfDevMemReadSpeed_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 == hipPerfDevMemReadSpeed_test());
}
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
@@ -18,12 +18,12 @@ THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
@@ -33,12 +33,12 @@ typedef struct d_uint16 {
uint data[ARRAY_SIZE];
} d_uint16;
__global__ void write_kernel(d_uint16 *dst, ulong N, d_uint16 pval) {
size_t idx = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for (size_t i = idx; i < N; i += stride) {
dst[i] = pval;
}
__global__ void write_kernel(d_uint16* dst, ulong N, d_uint16 pval) {
size_t idx = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for (size_t i = idx; i < N; i += stride) {
dst[i] = pval;
}
}
static bool hipPerfDevMemWriteSpeed_test() {
@@ -55,8 +55,8 @@ static bool hipPerfDevMemWriteSpeed_test() {
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount << " CUs \n");
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs\n", props.pciBusID, props.name,
props.multiProcessorCount);
const unsigned threadsPerBlock = 64;
const unsigned blocks = props.multiProcessorCount * 4;
@@ -65,7 +65,7 @@ static bool hipPerfDevMemWriteSpeed_test() {
pval.data[i] = inputData;
}
hDst = new d_uint16[nBytes];
hDst = new d_uint16[nBytes];
REQUIRE(hDst != nullptr);
for (size_t i = 0; i < N; i++) {
@@ -78,18 +78,18 @@ static bool hipPerfDevMemWriteSpeed_test() {
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipMalloc(&dDst, nBytes));
hipLaunchKernelGGL(write_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dDst, N, pval);
hipLaunchKernelGGL(write_kernel, dim3(blocks), dim3(threadsPerBlock), 0, stream, dDst, N, pval);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes , hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
for (uint i = 0; i < N; i++) {
for (uint j = 0; j < ARRAY_SIZE; j++) {
if (hDst[i].data[j] != inputData) {
INFO("hipPerfDevMemWriteSpeed - Data validation failed for warm up run!"
<< "at index i: " << i << " element j: " << j <<
"expected " << inputData << " but got " << hDst[i].data[j]);
DEBUG_PRINT(
"hipPerfDevMemWriteSpeed - Data validation failed for warm up run! at index i: %u "
"element j: %u expected 0x%x but got 0x%x\n",
i, j, inputData, hDst[i].data[j]);
return false;
}
}
@@ -99,8 +99,7 @@ static bool hipPerfDevMemWriteSpeed_test() {
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(write_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dDst, N, pval);
hipLaunchKernelGGL(write_kernel, dim3(blocks), dim3(threadsPerBlock), 0, stream, dDst, N, pval);
HIP_CHECK(hipGetLastError());
}
HIP_CHECK(hipDeviceSynchronize());
@@ -109,44 +108,45 @@ static bool hipPerfDevMemWriteSpeed_test() {
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(nBytes * nIter * (1e-09))) /
all_kernel_time.count();
double perf = (static_cast<double>(nBytes * nIter * (1e-09))) / all_kernel_time.count();
INFO("hipPerfDevMemReadSpeed - info: average write speed of " <<
perf << " GB/s " << "achieved for memory size of " <<
nBytes / (1024 * 1024) << " MB");
CONSOLE_PRINT(
"hipPerfDevMemWriteSpeed - average write speed of %.2f GB/s achieved for memory size of %u "
"MB\n",
perf, nBytes / (1024 * 1024));
delete [] hDst;
delete[] hDst;
HIP_CHECK(hipFree(dDst));
HIP_CHECK(hipStreamDestroy(stream));
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfDevMemWriteSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfDevMemWriteSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfDevMemWriteSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfDevMemWriteSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfDevMemWriteSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfDevMemWriteSpeed as"
"there is no device to test.");
SUCCEED(
"Skipped testcase hipPerfDevMemWriteSpeed as"
"there is no device to test.");
} else {
REQUIRE(true == hipPerfDevMemWriteSpeed_test());
}
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
@@ -18,28 +18,27 @@ THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <numaif.h>
#include <hip_test_common.hh>
// #define ENABLE_DEBUG 1
// To run it correctly, we must not export HIP_VISIBLE_DEVICES.
// And we must explicitly link libnuma because of numa api move_pages().
#define NUM_PAGES 4
char *h = nullptr;
char *d_h = nullptr;
char *m = nullptr;
char *d_m = nullptr;
char* h = nullptr;
char* d_h = nullptr;
char* m = nullptr;
char* d_m = nullptr;
int page_size = 1024;
const int mode[] = { MPOL_DEFAULT, MPOL_BIND, MPOL_PREFERRED, MPOL_INTERLEAVE };
const char* modeStr[] = { "MPOL_DEFAULT", "MPOL_BIND",
"MPOL_PREFERRED", "MPOL_INTERLEAVE" };
const int mode[] = {MPOL_DEFAULT, MPOL_BIND, MPOL_PREFERRED, MPOL_INTERLEAVE};
const char* modeStr[] = {"MPOL_DEFAULT", "MPOL_BIND", "MPOL_PREFERRED", "MPOL_INTERLEAVE"};
std::string exeCommand(const char* cmd) {
std::array<char, 128> buff;
@@ -55,23 +54,22 @@ std::string exeCommand(const char* cmd) {
}
int getCpuAgentCount() {
const char* cmd =
"cat /proc/cpuinfo | grep \"physical id\" | sort | uniq | wc -l";
const char* cmd = "cat /proc/cpuinfo | grep \"physical id\" | sort | uniq | wc -l";
int cpuAgentCount = std::atoi(exeCommand(cmd).c_str());
return cpuAgentCount;
}
bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
void *pages[NUM_PAGES];
void* pages[NUM_PAGES];
int status[NUM_PAGES];
int ret_code;
INFO("set cpu " << cpuId << ", gpu " << gpuId << ", numaMode "
<< numaMode << ", hostMallocflags " << hostMallocflags << "\n");
CONSOLE_PRINT("set cpu %d, gpu %d, numaMode %d, hostMallocflags %u\n", cpuId, gpuId, numaMode,
hostMallocflags);
if (cpuId >= 0) {
unsigned long nodeMask = 1 << cpuId; //NOLINT
unsigned long maxNode = sizeof(nodeMask) * 8; //NOLINT
unsigned long nodeMask = 1 << cpuId; // NOLINT
unsigned long maxNode = sizeof(nodeMask) * 8; // NOLINT
if (set_mempolicy(numaMode, numaMode == MPOL_DEFAULT ? NULL : &nodeMask,
numaMode == MPOL_DEFAULT ? 0 : maxNode) == -1) {
WARN("set_mempolicy() failed with err " << errno << "\n");
@@ -83,7 +81,7 @@ bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
HIP_CHECK(hipSetDevice(gpuId));
}
posix_memalign(reinterpret_cast<void**>(&m), page_size, page_size*NUM_PAGES);
posix_memalign(reinterpret_cast<void**>(&m), page_size, page_size * NUM_PAGES);
HIP_CHECK(hipHostRegister(m, page_size * NUM_PAGES, hipHostRegisterMapped));
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&d_m), m, 0));
@@ -94,15 +92,13 @@ bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
}
ret_code = move_pages(0, NUM_PAGES, pages, NULL, status, 0);
INFO("Memory (malloc) ret " << ret_code << " at " << m <<
" (dev " << d_m << "%p) is at node: ");
CONSOLE_PRINT("Memory (malloc) ret %d at %p (dev %p) is at node: ", ret_code, m, d_m);
for (int i = 0; i < NUM_PAGES; i++) {
INFO(status[i]); // Don't verify as it's out of our control
CONSOLE_PRINT("%d ", status[i]); // Don't verify as it's out of our control
}
INFO("\n");
CONSOLE_PRINT("\n");
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&h),
page_size*NUM_PAGES, hostMallocflags));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&h), page_size * NUM_PAGES, hostMallocflags));
pages[0] = h;
for (int i = 1; i < NUM_PAGES; i++) {
pages[i] = reinterpret_cast<char*>(pages[0]) + page_size;
@@ -111,16 +107,14 @@ bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
d_h = nullptr;
if (hostMallocflags & hipHostMallocMapped) {
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&d_h), h, 0));
INFO("Memory (hipHostMalloc) ret " << ret_code << " at " << h
<< " (dev " << d_h << ") is at node: ");
CONSOLE_PRINT("Memory (hipHostMalloc) ret %d at %p (dev %p) is at node: ", ret_code, h, d_h);
} else {
INFO("Memory (hipHostMalloc) ret " << ret_code << " at "
<< h << " is at node: ");
CONSOLE_PRINT("Memory (hipHostMalloc) ret %d at %p is at node: ", ret_code, h);
}
for (int i = 0; i < NUM_PAGES; i++) {
INFO(status[i]); // Always print it even if it's wrong. Verify later
CONSOLE_PRINT("%d ", status[i]); // Always print it even if it's wrong. Verify later
}
INFO("\n");
CONSOLE_PRINT("\n");
HIP_CHECK(hipHostFree(reinterpret_cast<void*>(h)));
HIP_CHECK(hipHostUnregister(m));
@@ -129,8 +123,7 @@ bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
if (cpuId >= 0 && (numaMode == MPOL_BIND || numaMode == MPOL_PREFERRED)) {
for (int i = 0; i < NUM_PAGES; i++) {
if (status[i] != cpuId) { // Now verify
WARN("Failed at " << i << " status[i] = " << status[i]
<< " cpuId " << cpuId << "\n");
WARN("Failed at " << i << " status[i] = " << status[i] << " cpuId " << cpuId << "\n");
return false;
}
}
@@ -138,12 +131,12 @@ bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
return true;
}
bool runTest(const int &cpuCount, const int &gpuCount,
unsigned int hostMallocflags, const std::string &str) {
INFO("Test- " << str.c_str() << "\n");
bool runTest(const int& cpuCount, const int& gpuCount, unsigned int hostMallocflags,
const std::string& str) {
CONSOLE_PRINT("Test- %s\n", str.c_str());
for (int m = 0; m < sizeof(mode) / sizeof(mode[0]); m++) {
INFO("Testing " << modeStr[m] << "\n");
CONSOLE_PRINT("Testing %s\n", modeStr[m]);
for (int i = 0; i < cpuCount; i++) {
for (int j = 0; j < gpuCount; j++) {
@@ -157,39 +150,40 @@ bool runTest(const int &cpuCount, const int &gpuCount,
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfHostNumaAlloc status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfHostNumaAlloc.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfHostNumaAlloc status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfHostNumaAlloc.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfHostNumaAlloc_test") {
int gpuCount = 0;
HIP_CHECK(hipGetDeviceCount(&gpuCount));
int cpuCount = getCpuAgentCount();
INFO("Cpu count " << cpuCount << ", Gpu count " << gpuCount << "\n");
CONSOLE_PRINT("Cpu count %d, Gpu count %d\n", cpuCount, gpuCount);
if (cpuCount < 0 || gpuCount < 0) {
SUCCEED("Skipped testcase hipPerfHostNumaAlloc as "
"there is no device to test.\n");
SUCCEED(
"Skipped testcase hipPerfHostNumaAlloc as "
"there is no device to test.\n");
return;
}
REQUIRE(true == runTest(cpuCount, gpuCount,
hipHostMallocDefault | hipHostMallocNumaUser,
"Testing hipHostMallocDefault | hipHostMallocNumaUser......"));
REQUIRE(true ==
runTest(cpuCount, gpuCount, hipHostMallocDefault | hipHostMallocNumaUser,
"Testing hipHostMallocDefault | hipHostMallocNumaUser......"));
REQUIRE(true == runTest(cpuCount, gpuCount,
hipHostMallocMapped | hipHostMallocNumaUser,
"Testing hipHostMallocMapped | hipHostMallocNumaUser......."));
REQUIRE(true ==
runTest(cpuCount, gpuCount, hipHostMallocMapped | hipHostMallocNumaUser,
"Testing hipHostMallocMapped | hipHostMallocNumaUser......."));
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
+82 -102
Wyświetl plik
@@ -18,20 +18,19 @@
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define SIMPLY_ASSIGN 0
#define USE_HIPTEST_SETNUMBLOCKS 0
template<class T>
__global__ void vec_fill(T *x, T coef, int N) {
template <class T> __global__ void vec_fill(T* x, T coef, int N) {
const int istart = threadIdx.x + blockIdx.x * blockDim.x;
const int ishift = blockDim.x * gridDim.x;
for (int i = istart; i < N; i += ishift) {
@@ -51,8 +50,7 @@ __device__ void print_log(int i, int value, int expected) {
printf("failed at %d: val=%d, expected=%d\n", i, value, expected);
}
template<class T>
__global__ void vec_verify(T *x, T coef, int N) {
template <class T> __global__ void vec_verify(T* x, T coef, int N) {
const int istart = threadIdx.x + blockIdx.x * blockDim.x;
const int ishift = blockDim.x * gridDim.x;
for (int i = istart; i < N; i += ishift) {
@@ -68,20 +66,17 @@ __global__ void vec_verify(T *x, T coef, int N) {
}
}
template<class T>
__global__ void daxpy(T *__restrict__ x, T *__restrict__ y,
const T coef, int Niter, int N) {
template <class T>
__global__ void daxpy(T* __restrict__ x, T* __restrict__ y, const T coef, int Niter, int N) {
const int istart = threadIdx.x + blockIdx.x * blockDim.x;
const int ishift = blockDim.x * gridDim.x;
for (int iter = 0; iter < Niter; ++iter) {
T iv = coef * iter;
for (int i = istart; i < N; i += ishift)
y[i] = iv * x[i] + y[i];
for (int i = istart; i < N; i += ishift) y[i] = iv * x[i] + y[i];
}
}
template<class T>
class hipPerfMemFill {
template <class T> class hipPerfMemFill {
private:
static constexpr int NUM_START = 27;
static constexpr int NUM_SIZE = 4;
@@ -96,26 +91,20 @@ class hipPerfMemFill {
public:
hipPerfMemFill() {
for (int i = 0; i < NUM_SIZE; i++) {
// 128M, 256M, 512M, 1024M
// 128M, 256M, 512M, 1024M
totalSizes_[i] = 1ull << (i + NUM_START);
}
}
~hipPerfMemFill() { }
~hipPerfMemFill() {}
bool supportLargeBar() {
return props_.isLargeBar != 0;
}
bool supportLargeBar() { return props_.isLargeBar != 0; }
bool supportManagedMemory() {
return props_.managedMemory != 0;
}
bool supportManagedMemory() { return props_.managedMemory != 0; }
const T getCoefficient(double val) {
return static_cast<T>(val);
}
const T getCoefficient(double val) { return static_cast<T>(val); }
void setHostBuffer(T *A, T val, size_t size) {
void setHostBuffer(T* A, T val, size_t size) {
size_t len = size / sizeof(T);
for (int i = 0; i < len; i++) {
A[i] = val;
@@ -138,33 +127,29 @@ class hipPerfMemFill {
HIP_CHECK(hipGetDeviceProperties(&props_, deviceId));
blocksPerCU_ = props_.multiProcessorCount * 4;
std::cout << "Info: running on device: id: " << deviceId << ", bus: 0x"
<< props_.pciBusID << " " << props_.name << " with "
<< props_.multiProcessorCount << " CUs, large bar: "
<< supportLargeBar() << ", managed memory: " << supportManagedMemory()
<< ", DeviceMallocFinegrained: " << supportDeviceMallocFinegrained()
<< std::endl;
std::cout << "Info: running on device: id: " << deviceId << ", bus: 0x" << props_.pciBusID
<< " " << props_.name << " with " << props_.multiProcessorCount
<< " CUs, large bar: " << supportLargeBar()
<< ", managed memory: " << supportManagedMemory()
<< ", DeviceMallocFinegrained: " << supportDeviceMallocFinegrained() << std::endl;
return true;
}
void log_host(const char* title, double GBytes, double sec) {
std::cout << title << " [" << std::setw(7) << GBytes << " GB]: cost "
<< std::setw(10) << sec << " s in bandwidth " << std::setw(10)
<< GBytes / sec << " [GB/s]" << std::endl;
std::cout << title << " [" << std::setw(7) << GBytes << " GB]: cost " << std::setw(10) << sec
<< " s in bandwidth " << std::setw(10) << GBytes / sec << " [GB/s]" << std::endl;
}
void log_kernel(const char* title, double GBytes, double sec,
double sec_hv, double sec_kv) {
std::cout << title << " [" << std::setw(7) << GBytes << " GB]: cost "
<< std::setw(10) << sec << " s in bandwidth " << std::setw(10)
<< GBytes / sec << " [GB/s]" << ", hostVerify cost "
<< std::setw(10) << sec_hv << " s in bandwidth " << std::setw(10)
<< GBytes / sec_hv << " [GB/s]" << ", kernelVerify cost "
<< std::setw(10) << sec_kv << " s in bandwidth " << std::setw(10)
<< GBytes / sec_kv << " [GB/s]" << std::endl;
void log_kernel(const char* title, double GBytes, double sec, double sec_hv, double sec_kv) {
std::cout << title << " [" << std::setw(7) << GBytes << " GB]: cost " << std::setw(10) << sec
<< " s in bandwidth " << std::setw(10) << GBytes / sec << " [GB/s]"
<< ", hostVerify cost " << std::setw(10) << sec_hv << " s in bandwidth "
<< std::setw(10) << GBytes / sec_hv << " [GB/s]" << ", kernelVerify cost "
<< std::setw(10) << sec_kv << " s in bandwidth " << std::setw(10) << GBytes / sec_kv
<< " [GB/s]" << std::endl;
}
void hostFill(size_t size, T *data, T coef, double *sec) {
void hostFill(size_t size, T* data, T coef, double* sec) {
size_t num = size / sizeof(T); // Size of elements
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < num; ++i) {
@@ -179,29 +164,29 @@ class hipPerfMemFill {
*sec = diff.count();
}
void kernelFill(size_t size, T *data, T coef, double *sec) {
void kernelFill(size_t size, T* data, T coef, double* sec) {
size_t num = size / sizeof(T); // Size of elements
unsigned blocks = setNumBlocks(num);
// kernel will be loaded first time
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_fill<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, 0, num);
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_fill<T>), dim3(blocks), dim3(threadsPerBlock_), 0, 0,
data, 0, num);
HIP_CHECK(hipDeviceSynchronize());
auto start = std::chrono::steady_clock::now();
for (int iter = 0; iter < NUM_ITER; ++iter) {
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_fill<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, coef, num);
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_fill<T>), dim3(blocks), dim3(threadsPerBlock_), 0, 0,
data, coef, num);
}
HIP_CHECK(hipDeviceSynchronize());
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start; // in second
*sec = diff.count() / NUM_ITER; // in second
*sec = diff.count() / NUM_ITER; // in second
}
void hostVerify(size_t size, T *data, T coef, double *sec) {
void hostVerify(size_t size, T* data, T coef, double* sec) {
size_t num = size / sizeof(T); // Size of elements
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < num; ++i) {
@@ -224,27 +209,27 @@ class hipPerfMemFill {
*sec = diff.count();
}
void kernelVerify(size_t size, T *data, T coef, double *sec) {
void kernelVerify(size_t size, T* data, T coef, double* sec) {
size_t num = size / sizeof(T); // Size of elements
unsigned blocks = setNumBlocks(num);
// kernel will be loaded first time
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_verify<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, coef, num);
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_verify<T>), dim3(blocks), dim3(threadsPerBlock_), 0, 0,
data, coef, num);
HIP_CHECK(hipDeviceSynchronize());
// Now all data verified. The following is to test bandwidth.
auto start = std::chrono::steady_clock::now();
for (int iter = 0; iter < NUM_ITER; ++iter) {
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_verify<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, coef, num);
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_verify<T>), dim3(blocks), dim3(threadsPerBlock_), 0, 0,
data, coef, num);
}
HIP_CHECK(hipDeviceSynchronize());
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start; // in second
*sec = diff.count() / NUM_ITER; // in second
*sec = diff.count() / NUM_ITER; // in second
}
bool testLargeBarDeviceMemoryHostFill(size_t size) {
@@ -254,7 +239,7 @@ class hipPerfMemFill {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
T* A;
HIP_CHECK(hipMalloc(&A, size));
double sec = 0;
hostFill(size, A, coef_, &sec); // Cpu can access device mem in LB
@@ -285,7 +270,7 @@ class hipPerfMemFill {
}
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
T* A;
HIP_CHECK(hipMallocManaged(&A, size));
double sec = 0;
hostFill(size, A, coef_, &sec); // Cpu can access HMM mem
@@ -301,7 +286,7 @@ class hipPerfMemFill {
}
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
T* A;
HIP_CHECK(hipMallocManaged(&A, size));
double sec = 0, sec_hv = 0, sec_kv = 0;
@@ -340,7 +325,7 @@ class hipPerfMemFill {
bool testHostMemoryHostFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
T* A;
HIP_CHECK(hipHostMalloc(&A, size, flags));
double sec = 0;
hostFill(size, A, coef_, &sec);
@@ -353,8 +338,8 @@ class hipPerfMemFill {
bool testHostMemoryKernelFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
HIP_CHECK(hipHostMalloc(reinterpret_cast<void **>(&A), size, flags));
T* A;
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A), size, flags));
double sec = 0, sec_hv = 0, sec_kv = 0;
kernelFill(size, A, coef_, &sec);
hostVerify(size, A, coef_, &sec_hv);
@@ -400,10 +385,11 @@ class hipPerfMemFill {
/* This function should be via device attribute query*/
bool supportDeviceMallocFinegrained() {
#ifdef __HIP_PLATFORM_AMD__
T *A = nullptr;
T* A = nullptr;
hipError_t err;
err = hipExtMallocWithFlags(reinterpret_cast<void**>(&A), sizeof(T),
hipDeviceMallocFinegrained);
err =
hipExtMallocWithFlags(reinterpret_cast<void**>(&A), sizeof(T), hipDeviceMallocFinegrained);
if (err || !A) {
return false;
}
@@ -415,7 +401,7 @@ class hipPerfMemFill {
}
unsigned int setNumBlocks(size_t size) {
size_t num = size/sizeof(T);
size_t num = size / sizeof(T);
#if USE_HIPTEST_SETNUMBLOCKS
return HipTest::setNumBlocks(blocksPerCU_, threadsPerBlock_, num);
@@ -428,12 +414,11 @@ class hipPerfMemFill {
bool testExtDeviceMemoryHostFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A = nullptr;
HIP_CHECK(hipExtMallocWithFlags(reinterpret_cast<void **>(&A),
size, flags));
T* A = nullptr;
HIP_CHECK(hipExtMallocWithFlags(reinterpret_cast<void**>(&A), size, flags));
if (!A) {
std::cout << "failed hipExtMallocWithFlags() with size =" <<
size << " flags="<< std::hex << flags << std::endl;
std::cout << "failed hipExtMallocWithFlags() with size =" << size << " flags=" << std::hex
<< flags << std::endl;
return false;
}
@@ -448,12 +433,11 @@ class hipPerfMemFill {
bool testExtDeviceMemoryKernelFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A = nullptr;
HIP_CHECK(hipExtMallocWithFlags(reinterpret_cast<void **>(&A),
size, flags));
T* A = nullptr;
HIP_CHECK(hipExtMallocWithFlags(reinterpret_cast<void**>(&A), size, flags));
if (!A) {
std::cout << "failed hipExtMallocWithFlags() with size =" <<
size << " flags=" << std::hex << flags << std::endl;
std::cout << "failed hipExtMallocWithFlags() with size =" << size << " flags=" << std::hex
<< flags << std::endl;
return false;
}
@@ -470,20 +454,16 @@ class hipPerfMemFill {
}
bool testExtDeviceMemory() {
std::cout << "Test fine grained device memory host filling"
<< std::endl;
std::cout << "Test fine grained device memory host filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testExtDeviceMemoryHostFill(totalSizes_[i],
hipDeviceMallocFinegrained)) {
if (!testExtDeviceMemoryHostFill(totalSizes_[i], hipDeviceMallocFinegrained)) {
return false;
}
}
std::cout << "Test fine grained device memory kernel filling"
<< std::endl;
std::cout << "Test fine grained device memory kernel filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testExtDeviceMemoryKernelFill(totalSizes_[i],
hipDeviceMallocFinegrained)) {
if (!testExtDeviceMemoryKernelFill(totalSizes_[i], hipDeviceMallocFinegrained)) {
return false;
}
}
@@ -521,16 +501,16 @@ class hipPerfMemFill {
};
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemFill status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemFill.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfMemFill status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemFill.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemFill_test") {
std::cout << "Test int" << std::endl;
@@ -545,6 +525,6 @@ TEST_CASE("Perf_hipPerfMemFill_test") {
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
@@ -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.
* @}
*/
+56 -61
Wyświetl plik
@@ -18,15 +18,15 @@
*/
/**
* @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.
*/
#include <hip_test_common.hh>
// #define ENABLE_DEBUG 1
#define NUM_SIZE 14
#define NUM_ITER 1000
// max BW number for DevicetoDeviceNoCU
@@ -35,7 +35,8 @@
class hipPerfMemcpy {
private:
size_t totalSizes_[NUM_SIZE];
void setHostBuffer(int *A, int val, size_t size);
void setHostBuffer(int* A, int val, size_t size);
public:
hipPerfMemcpy();
~hipPerfMemcpy() {}
@@ -53,7 +54,7 @@ hipPerfMemcpy::hipPerfMemcpy() {
}
}
void hipPerfMemcpy::setHostBuffer(int *A, int val, size_t size) {
void hipPerfMemcpy::setHostBuffer(int* A, int val, size_t size) {
size_t len = size / sizeof(int);
for (int i = 0; i < len; i++) {
A[i] = val;
@@ -61,36 +62,31 @@ void hipPerfMemcpy::setHostBuffer(int *A, int val, size_t size) {
}
void hipPerfMemcpy::TestResult(unsigned int numTests,
std::chrono::duration<double, std::micro> diff, hipMemcpyKind type)
{
std::chrono::duration<double, std::micro> diff, hipMemcpyKind type) {
// BW in GB/s
double perf = (static_cast<double>(totalSizes_[numTests] * NUM_ITER) *
static_cast<double>(1e-03)) / diff.count();
double perf =
(static_cast<double>(totalSizes_[numTests] * NUM_ITER) * static_cast<double>(1e-03)) /
diff.count();
const char *typestr = NULL;
const char* typestr = NULL;
if(type == hipMemcpyHostToDevice){
typestr = "Host to Device";
}
else if(type == hipMemcpyDeviceToHost){
typestr = "Device to Host";
}
else if(type == hipMemcpyDeviceToDevice){
typestr = "Device to Device";
perf *= 2.0;
}
else if(type == hipMemcpyDeviceToDeviceNoCU){
typestr = "Device to Device No CU";
perf *= 2.0;
if (type == hipMemcpyHostToDevice) {
typestr = "Host to Device";
} else if (type == hipMemcpyDeviceToHost) {
typestr = "Device to Host";
} else if (type == hipMemcpyDeviceToDevice) {
typestr = "Device to Device";
perf *= 2.0;
} else if (type == hipMemcpyDeviceToDeviceNoCU) {
typestr = "Device to Device No CU";
perf *= 2.0;
}
UNSCOPED_INFO("hipPerfMemcpy[" << numTests << "] " << typestr << " copy BW "
<< perf << " GB/s for memory size of " <<
totalSizes_[numTests] << " Bytes.");
if(totalSizes_[numTests] == 4194304 && type == hipMemcpyDeviceToDeviceNoCU)
REQUIRE(perf < NOCU_MAX_BW);
CONSOLE_PRINT("hipPerfMemcpy[%d] %s copy BW %.2f GB/s for memory size of %lu Bytes.\n", numTests,
typestr, perf, totalSizes_[numTests]);
if (totalSizes_[numTests] == 4194304 && type == hipMemcpyDeviceToDeviceNoCU)
REQUIRE(perf < NOCU_MAX_BW);
}
bool hipPerfMemcpy::run_h2d(unsigned int numTests) {
@@ -115,7 +111,7 @@ bool hipPerfMemcpy::run_h2d(unsigned int numTests) {
TestResult(numTests, diff, hipMemcpyHostToDevice);
HIP_CHECK(hipHostUnregister(A));
delete [] A;
delete[] A;
HIP_CHECK(hipFree(Ad));
return true;
@@ -143,7 +139,7 @@ bool hipPerfMemcpy::run_d2h(unsigned int numTests) {
TestResult(numTests, diff, hipMemcpyDeviceToHost);
HIP_CHECK(hipHostUnregister(A));
delete [] A;
delete[] A;
HIP_CHECK(hipFree(Ad));
return true;
@@ -186,8 +182,8 @@ bool hipPerfMemcpy::run_d2d_nocu(unsigned int numTests) {
auto all_start = std::chrono::steady_clock::now();
for (int j = 0; j < NUM_ITER; j++) {
HIP_CHECK(hipMemcpyAsync(Ad1, Ad2, totalSizes_[numTests], hipMemcpyDeviceToDeviceNoCU,
nullptr));
HIP_CHECK(
hipMemcpyAsync(Ad1, Ad2, totalSizes_[numTests], hipMemcpyDeviceToDeviceNoCU, nullptr));
}
HIP_CHECK(hipDeviceSynchronize());
@@ -204,16 +200,16 @@ bool hipPerfMemcpy::run_d2d_nocu(unsigned int numTests) {
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemcpy status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemcpy.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfMemcpy status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemcpy.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemcpy_test") {
int numDevices = 0;
@@ -227,35 +223,34 @@ TEST_CASE("Perf_hipPerfMemcpy_test") {
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
UNSCOPED_INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount << " CUs "
<< " and device id: " << deviceId);
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs and device id: %d\n", props.pciBusID,
props.name, props.multiProcessorCount, deviceId);
hipPerfMemcpy hipPerfMemcpy;
SECTION("Perf test Host Memory to Device Memory"){
SECTION("Perf test Host Memory to Device Memory") {
for (auto testCase = 0; testCase < NUM_SIZE; testCase++) {
REQUIRE(true == hipPerfMemcpy.run_h2d(testCase));
REQUIRE(true == hipPerfMemcpy.run_h2d(testCase));
}
}
SECTION("Perf test Device Memory to Host Memory"){
SECTION("Perf test Device Memory to Host Memory") {
for (auto testCase = 0; testCase < NUM_SIZE; testCase++) {
REQUIRE(true == hipPerfMemcpy.run_d2h(testCase));
REQUIRE(true == hipPerfMemcpy.run_d2h(testCase));
}
}
SECTION("Perf test Device Memory to Device Memory"){
SECTION("Perf test Device Memory to Device Memory") {
for (auto testCase = 0; testCase < NUM_SIZE; testCase++) {
REQUIRE(true == hipPerfMemcpy.run_d2d(testCase));
REQUIRE(true == hipPerfMemcpy.run_d2d(testCase));
}
}
SECTION("Perf test Device Memory to Device Memory No CU"){
SECTION("Perf test Device Memory to Device Memory No CU") {
for (auto testCase = 0; testCase < NUM_SIZE; testCase++) {
REQUIRE(true == hipPerfMemcpy.run_d2d_nocu(testCase));
REQUIRE(true == hipPerfMemcpy.run_d2d_nocu(testCase));
}
}
}
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
+87 -105
Wyświetl plik
@@ -18,30 +18,29 @@
*/
/**
* @addtogroup hipMemsetKernel hipMemsetKernel
* @{
* @ingroup perfMemoryTest
* `hipMemset(void* devPtr, int value, size_t count)` -
* Initializes or sets device memory to a value.
*/
* @addtogroup hipMemsetKernel hipMemsetKernel
* @{
* @ingroup perfMemoryTest
* `hipMemset(void* devPtr, int value, size_t count)` -
* Initializes or sets device memory to a value.
*/
// #define ENABLE_DEBUG 1
#include <hip_test_common.hh>
static unsigned int sizeList[] = {
256, 512, 1024, 2048, 4096, 8192,
256, 512, 1024, 2048, 4096, 8192,
};
static unsigned int eleNumList[] = {
0x100, 0x400, 0x1000, 0x4000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000,
0x200000, 0x400000, 0x800000, 0x1000000
};
static unsigned int eleNumList[] = {0x100, 0x400, 0x1000, 0x4000, 0x10000,
0x20000, 0x40000, 0x80000, 0x100000, 0x200000,
0x400000, 0x800000, 0x1000000};
typedef struct _dataType {
char memsetval = 0x42;
char memsetD8val = 0xDE;
int16_t memsetD16val = 0xDEAD;
int memsetD32val = 0xDEADBEEF;
}dataType;
} dataType;
#define NUM_ITER 1000
@@ -56,7 +55,7 @@ enum MemsetType {
class hipPerfMemset {
private:
uint64_t bufSize_;
uint64_t bufSize_;
unsigned int num_elements_;
unsigned int testNumEle_;
unsigned int _numSubTests = 0;
@@ -78,25 +77,19 @@ class hipPerfMemset {
bool open(int deviceID);
template<typename T>
template <typename T>
void run1D(unsigned int test, T memsetval, enum MemsetType type, bool async);
template<typename T>
template <typename T>
void run2D(unsigned int test, T memsetval, enum MemsetType type, bool async);
template<typename T>
template <typename T>
void run3D(unsigned int test, T memsetval, enum MemsetType type, bool async);
uint getNumTests() {
return _numSubTests;
}
uint getNumTests() { return _numSubTests; }
uint getNumTests2D() {
return _numSubTests2D;
}
uint getNumTests3D() {
return _numSubTests3D;
}
uint getNumTests2D() { return _numSubTests2D; }
uint getNumTests3D() { return _numSubTests3D; }
};
bool hipPerfMemset::open(int deviceId) {
@@ -109,15 +102,13 @@ bool hipPerfMemset::open(int deviceId) {
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " << props.name
<< " with " << props.multiProcessorCount << " CUs and device id: "
<< deviceId << "\n");
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs and device id: %d\n", props.pciBusID,
props.name, props.multiProcessorCount, deviceId);
return true;
}
template<typename T>
void hipPerfMemset::run1D(unsigned int test, T memsetval,
enum MemsetType type, bool async) {
template <typename T>
void hipPerfMemset::run1D(unsigned int test, T memsetval, enum MemsetType type, bool async) {
T *A_h, *A_d;
testNumEle_ = eleNumList[test % num_elements_];
@@ -126,17 +117,17 @@ void hipPerfMemset::run1D(unsigned int test, T memsetval,
HIP_CHECK(hipMalloc(&A_d, bufSize_));
A_h = reinterpret_cast<T*> (malloc(bufSize_));
A_h = reinterpret_cast<T*>(malloc(bufSize_));
hipStream_t stream;
HIP_CHECK(hipStreamCreateWithFlags(&stream, hipStreamNonBlocking));
// Warm-up
if (async) {
HIP_CHECK(hipMemsetAsync((void *)A_d, memsetval, bufSize_, stream));
HIP_CHECK(hipMemsetAsync((void*)A_d, memsetval, bufSize_, stream));
HIP_CHECK(hipStreamSynchronize(stream));
} else {
HIP_CHECK(hipMemset((void *)A_d, memsetval, bufSize_));
HIP_CHECK(hipMemset((void*)A_d, memsetval, bufSize_));
HIP_CHECK(hipDeviceSynchronize());
}
@@ -144,7 +135,7 @@ void hipPerfMemset::run1D(unsigned int test, T memsetval,
for (uint i = 0; i < NUM_ITER; i++) {
if (type == hipMemsetTypeDefault && !async) {
HIP_CHECK(hipMemset(reinterpret_cast<void *>(A_d), memsetval, bufSize_));
HIP_CHECK(hipMemset(reinterpret_cast<void*>(A_d), memsetval, bufSize_));
} else if (type == hipMemsetTypeDefault && async) {
HIP_CHECK(hipMemsetAsync(A_d, memsetval, bufSize_, stream));
} else if (type == hipMemsetTypeD8 && !async) {
@@ -152,13 +143,13 @@ void hipPerfMemset::run1D(unsigned int test, T memsetval,
} else if (type == hipMemsetTypeD8 && async) {
HIP_CHECK(hipMemsetD8Async((hipDeviceptr_t)A_d, memsetval, bufSize_, stream));
} else if (type == hipMemsetTypeD16 && !async) {
HIP_CHECK(hipMemsetD16((hipDeviceptr_t)A_d, memsetval, bufSize_/sizeof(T)));
HIP_CHECK(hipMemsetD16((hipDeviceptr_t)A_d, memsetval, bufSize_ / sizeof(T)));
} else if (type == hipMemsetTypeD16 && async) {
HIP_CHECK(hipMemsetD16Async((hipDeviceptr_t)A_d, memsetval, bufSize_/sizeof(T), stream));
HIP_CHECK(hipMemsetD16Async((hipDeviceptr_t)A_d, memsetval, bufSize_ / sizeof(T), stream));
} else if (type == hipMemsetTypeD32 && !async) {
HIP_CHECK(hipMemsetD32((hipDeviceptr_t)A_d, memsetval, bufSize_/sizeof(T)));
HIP_CHECK(hipMemsetD32((hipDeviceptr_t)A_d, memsetval, bufSize_ / sizeof(T)));
} else if (type == hipMemsetTypeD32 && async) {
HIP_CHECK(hipMemsetD32Async((hipDeviceptr_t)A_d, memsetval, bufSize_/sizeof(T), stream));
HIP_CHECK(hipMemsetD32Async((hipDeviceptr_t)A_d, memsetval, bufSize_ / sizeof(T), stream));
}
}
if (async) {
@@ -169,13 +160,12 @@ void hipPerfMemset::run1D(unsigned int test, T memsetval,
auto end = std::chrono::steady_clock::now();
HIP_CHECK(hipMemcpy(A_h, A_d, bufSize_, hipMemcpyDeviceToHost) );
HIP_CHECK(hipMemcpy(A_h, A_d, bufSize_, hipMemcpyDeviceToHost));
for (int i = 0; i < bufSize_ / sizeof(T); i++) {
if (A_h[i] != memsetval) {
INFO("mismatch at index " << i << " computed: " <<
static_cast<int> (A_h[i]) << ", memsetval: " <<
static_cast<int> (memsetval) << "\n");
DEBUG_PRINT("mismatch at index %d computed: %d, memsetval: %d\n", i, static_cast<int>(A_h[i]),
static_cast<int>(memsetval));
REQUIRE(false);
}
}
@@ -188,30 +178,27 @@ void hipPerfMemset::run1D(unsigned int test, T memsetval,
auto sec = diff.count();
auto perf = static_cast<double>((bufSize_ * NUM_ITER * (1e-09)) / sec);
std::cout << "[" << std::setw(2)
<< test << "] " << std::setw(5) << bufSize_/1024
<< " Kb " << std::setw(4) << " typeSize " << sizeof(T) << " : "
<< std::setw(7) << perf << " GB/s \n";
std::cout << "[" << std::setw(2) << test << "] " << std::setw(5) << bufSize_ / 1024 << " Kb "
<< std::setw(4) << " typeSize " << sizeof(T) << " : " << std::setw(7) << perf
<< " GB/s \n";
}
template<typename T>
void hipPerfMemset::run2D(unsigned int test, T memsetval,
enum MemsetType type, bool async) {
template <typename T>
void hipPerfMemset::run2D(unsigned int test, T memsetval, enum MemsetType type, bool async) {
bufSize_ = sizeList[test % num_sizes_];
size_t numH = bufSize_;
size_t numW = bufSize_;
size_t pitch_A;
size_t width = numW * sizeof(char);
size_t sizeElements = width * numH;
size_t elements = numW* numH;
size_t elements = numW * numH;
T * A_h, * A_d;
T *A_h, *A_d;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, numH));
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d), &pitch_A, width, numH));
A_h = reinterpret_cast<char*>(malloc(sizeElements));
for (size_t i=0; i < elements; i++) {
for (size_t i = 0; i < elements; i++) {
A_h[i] = 1;
}
@@ -244,14 +231,12 @@ void hipPerfMemset::run2D(unsigned int test, T memsetval,
auto end = std::chrono::steady_clock::now();
HIP_CHECK(hipMemcpy2D(A_h, width, A_d, pitch_A, numW, numH,
hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy2D(A_h, width, A_d, pitch_A, numW, numH, hipMemcpyDeviceToHost));
for (int i=0; i < elements; i++) {
for (int i = 0; i < elements; i++) {
if (A_h[i] != memsetval) {
INFO("mismatch at index " << i << " computed: " <<
static_cast<int> (A_h[i]) << ", memsetval: " <<
static_cast<int> (memsetval) << "\n");
DEBUG_PRINT("mismatch at index %d computed: %d, memsetval: %d\n", i, static_cast<int>(A_h[i]),
static_cast<int>(memsetval));
REQUIRE(false);
}
}
@@ -259,20 +244,19 @@ void hipPerfMemset::run2D(unsigned int test, T memsetval,
std::chrono::duration<double> diff = end - start;
auto sec = diff.count();
auto perf = static_cast<double>((sizeElements* NUM_ITER * (1e-09)) / sec);
auto perf = static_cast<double>((sizeElements * NUM_ITER * (1e-09)) / sec);
std::cout << "hipPerf2DMemset" << (async ? "Async" : " ") << "[" << test << "] "
<< " " << "(GB/s) for " << std::setw(5) << bufSize_
<< " x " << std::setw(5) << bufSize_ << " bytes : " << std::setw(7) << perf << "\n";
std::cout << "hipPerf2DMemset" << (async ? "Async" : " ") << "[" << test << "] " << " "
<< "(GB/s) for " << std::setw(5) << bufSize_ << " x " << std::setw(5) << bufSize_
<< " bytes : " << std::setw(7) << perf << "\n";
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(A_d));
free(A_h);
}
template<typename T>
void hipPerfMemset::run3D(unsigned int test, T memsetval,
enum MemsetType type, bool async) {
template <typename T>
void hipPerfMemset::run3D(unsigned int test, T memsetval, enum MemsetType type, bool async) {
bufSize_ = sizeList[test % num_sizes_];
size_t numH = bufSize_;
@@ -280,12 +264,12 @@ void hipPerfMemset::run3D(unsigned int test, T memsetval,
size_t depth = 10;
size_t width = numW * sizeof(char);
size_t sizeElements = width * numH * depth;
size_t elements = numW* numH* depth;
size_t elements = numW * numH * depth;
hipStream_t stream;
HIP_CHECK(hipStreamCreateWithFlags(&stream, hipStreamNonBlocking));
T *A_h;
T* A_h;
hipExtent extent = make_hipExtent(width, numH, depth);
hipPitchedPtr devPitchedPtr;
@@ -325,12 +309,12 @@ void hipPerfMemset::run3D(unsigned int test, T memsetval,
auto end = std::chrono::steady_clock::now();
hipMemcpy3DParms myparms ;
hipMemcpy3DParms myparms;
myparms.srcArray = nullptr;
myparms.dstArray = nullptr;
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.dstPtr = make_hipPitchedPtr(A_h, width , numW, numH);
myparms.dstPtr = make_hipPitchedPtr(A_h, width, numW, numH);
myparms.srcPtr = devPitchedPtr;
myparms.extent = extent;
@@ -338,11 +322,10 @@ void hipPerfMemset::run3D(unsigned int test, T memsetval,
HIP_CHECK(hipMemcpy3D(&myparms));
for (int i=0; i < elements; i++) {
for (int i = 0; i < elements; i++) {
if (A_h[i] != memsetval) {
INFO("mismatch at index " << i << " computed: " <<
static_cast<int> (A_h[i]) << ", memsetval: " <<
static_cast<int> (memsetval) << "\n");
DEBUG_PRINT("mismatch at index %d computed: %d, memsetval: %d\n", i, static_cast<int>(A_h[i]),
static_cast<int>(memsetval));
REQUIRE(false);
}
}
@@ -352,24 +335,23 @@ void hipPerfMemset::run3D(unsigned int test, T memsetval,
auto sec = diff.count();
auto perf = static_cast<double>((sizeElements * NUM_ITER * (1e-09)) / sec);
std::cout << "hipPerf3DMemset" << (async ? "Async" : " ") << "[" << test << "] " << " "
<< "(GB/s) for " << std::setw(5) << bufSize_ << " x " << std::setw(5)
<< bufSize_ << " x " << depth << " bytes : " << std::setw(7) << perf << "\n";
CONSOLE_PRINT("hipPerf3DMemset%s[%d] (GB/s) for %5lu x %5lu x %lu bytes : %7.2f\n",
(async ? "Async" : " "), test, bufSize_, bufSize_, depth, perf);
HIP_CHECK(hipFree(devPitchedPtr.ptr));
free(A_h);
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemset status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemset.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfMemset status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemset.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemset_test") {
hipPerfMemset hipPerfMemset;
@@ -385,44 +367,44 @@ TEST_CASE("Perf_hipPerfMemset_test") {
bool async = false;
for (uint i = 0; i < 2 ; i++) {
std::cout << "--------------------- 1D buffer -------------------\n";
for (uint i = 0; i < 2; i++) {
CONSOLE_PRINT("--------------------- 1D buffer -------------------\n");
for (auto testCase = 0; testCase < numTests; testCase++) {
if (testCase < sizeof(eleNumList) / sizeof(uint32_t)) {
std::cout << "hipMemsetD8" << (async ? "Async " : " ");
CONSOLE_PRINT("hipMemsetD8%s", (async ? "Async " : " "));
hipPerfMemset.run1D(testCase, pattern.memsetval, hipMemsetTypeD8, async);
} else if (testCase < 2 * sizeof(eleNumList) / sizeof(uint32_t)) {
std::cout << "hipMemsetD16" << (async ? "Async" : " ");
CONSOLE_PRINT("hipMemsetD16%s", (async ? "Async" : " "));
hipPerfMemset.run1D(testCase, pattern.memsetD16val, hipMemsetTypeD16, async);
} else if (testCase < 3 * sizeof(eleNumList) / sizeof(uint32_t)) {
std::cout << "hipMemsetD32" << (async ? "Async" : " ");
CONSOLE_PRINT("hipMemsetD32%s", (async ? "Async" : " "));
hipPerfMemset.run1D(testCase, pattern.memsetD32val, hipMemsetTypeD32, async);
} else {
std::cout << "hipMemset" << (async ? "Async " : " ");
CONSOLE_PRINT("hipMemset%s", (async ? "Async " : " "));
hipPerfMemset.run1D(testCase, pattern.memsetval, hipMemsetTypeDefault, async);
}
}
async = true;
}
INFO("\n");
std::cout << "------------------ 2D buffer arrays ---------------\n";
CONSOLE_PRINT("\n");
CONSOLE_PRINT("\n------------------ 2D buffer arrays ---------------\n");
async = false;
for (uint i = 0; i < 2; i++) {
INFO("\n");
CONSOLE_PRINT("\n");
for (uint test = 0; test < numTests2D; test++) {
hipPerfMemset.run2D(test, pattern.memsetval, hipMemsetTypeDefault, async);
}
async = true;
}
INFO("\n");
std::cout << "------------------ 3D buffer arrays ---------------\n";
CONSOLE_PRINT("\n");
CONSOLE_PRINT("\n------------------ 3D buffer arrays ---------------\n");
async = false;
for (uint i = 0; i < 2; i++) {
INFO("\n");
CONSOLE_PRINT("\n");
for (uint test = 0; test < numTests3D; test++) {
hipPerfMemset.run3D(test, pattern.memsetval, hipMemsetTypeDefault, async);
}
@@ -431,6 +413,6 @@ TEST_CASE("Perf_hipPerfMemset_test") {
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
+92 -104
Wyświetl plik
@@ -19,66 +19,69 @@
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
// #define ENABLE_DEBUG 1
#define NUM_TYPES 3
std::vector<std::string> types = {"float", "float2", "float4"};
std::vector<unsigned int> typeSizes = {4, 8, 16};
#define NUM_SIZES 12
std::vector<unsigned int> sizes = {1, 2, 4, 8, 16, 32,
64, 128, 256, 512, 1024, 2048};
std::vector<unsigned int> sizes = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
#define NUM_BUFS 6
#define MAX_BUFS (1 << (NUM_BUFS - 1))
#ifdef __HIP_PLATFORM_NVIDIA__
__host__ __device__ void operator+=(float2 &a, float2 b) { //NOLINT
a.x += b.x; a.y += b.y;
__host__ __device__ void operator+=(float2& a, float2 b) { // NOLINT
a.x += b.x;
a.y += b.y;
}
__host__ __device__ void operator+=(float4 &a, float4 b) { //NOLINT
a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
__host__ __device__ void operator+=(float4& a, float4 b) { // NOLINT
a.x += b.x;
a.y += b.y;
a.z += b.z;
a.w += b.w;
}
#endif
template <typename T>
__global__ void sampleRate(T * outBuffer, unsigned int inBufSize,
unsigned int writeIt, T **inBuffer, int numBufs) {
__global__ void sampleRate(T* outBuffer, unsigned int inBufSize, unsigned int writeIt, T** inBuffer,
int numBufs) {
uint gid = (blockIdx.x * blockDim.x + threadIdx.x);
uint inputIdx = gid % inBufSize;
T tmp;
memset(&tmp, 0, sizeof(T));
for (int i = 0; i < numBufs; i++) {
tmp += *(*(inBuffer+i)+inputIdx);
tmp += *(*(inBuffer + i) + inputIdx);
}
if (writeIt*(unsigned int)tmp.x) {
if (writeIt * (unsigned int)tmp.x) {
outBuffer[gid] = tmp;
}
}
template <typename T>
__global__ void sampleRateFloat(T * outBuffer, unsigned int inBufSize,
unsigned int writeIt, T ** inBuffer, int numBufs) {
__global__ void sampleRateFloat(T* outBuffer, unsigned int inBufSize, unsigned int writeIt,
T** inBuffer, int numBufs) {
uint gid = (blockIdx.x * blockDim.x + threadIdx.x);
uint inputIdx = gid % inBufSize;
T tmp = (T)0.0f;
for (int i = 0; i < numBufs; i++) {
tmp += *((*inBuffer+i)+inputIdx);
tmp += *((*inBuffer + i) + inputIdx);
}
if (writeIt*(unsigned int)tmp) {
if (writeIt * (unsigned int)tmp) {
outBuffer[gid] = tmp;
}
}
@@ -93,26 +96,23 @@ class hipPerfSampleRate {
void close(void);
// array of funtion pointers
typedef void (hipPerfSampleRate::*funPtr)(void * outBuffer, unsigned int
inBufSize, unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks);
typedef void (hipPerfSampleRate::*funPtr)(void* outBuffer, unsigned int inBufSize,
unsigned int writeIt, void** inBuffer, int numBufs,
int grids, int blocks);
// Wrappers
void float_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks);
void float_kernel(void* outBuffer, unsigned int inBufSize, unsigned int writeIt, void** inBuffer,
int numBufs, int grids, int blocks);
void float2_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks);
void float2_kernel(void* outBuffer, unsigned int inBufSize, unsigned int writeIt, void** inBuffer,
int numBufs, int grids, int blocks);
void float4_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks);
void float4_kernel(void* outBuffer, unsigned int inBufSize, unsigned int writeIt, void** inBuffer,
int numBufs, int grids, int blocks);
private:
void setData(void *ptr, unsigned int value);
void checkData(uint *ptr);
void setData(void* ptr, unsigned int value);
void checkData(uint* ptr);
unsigned int width_;
unsigned int bufSize_;
@@ -139,41 +139,36 @@ bool hipPerfSampleRate::open(void) {
hipDeviceProp_t props;
HIP_CHECK(hipSetDevice(deviceId));
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount <<
" CUs" << " and device id: " << deviceId << "\n");
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs and device id: %d\n", props.pciBusID,
props.name, props.multiProcessorCount, deviceId);
numCUs = props.multiProcessorCount;
return true;
}
// Wrappers for the kernel launches
void hipPerfSampleRate::float_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks) {
hipLaunchKernelGGL(sampleRateFloat<float>, dim3(grids, grids, grids),
dim3(blocks), 0, 0, reinterpret_cast<float*>(outBuffer),
inBufSize, writeIt, reinterpret_cast<float**>(inBuffer), numBufs);
void hipPerfSampleRate::float_kernel(void* outBuffer, unsigned int inBufSize, unsigned int writeIt,
void** inBuffer, int numBufs, int grids, int blocks) {
hipLaunchKernelGGL(sampleRateFloat<float>, dim3(grids, grids, grids), dim3(blocks), 0, 0,
reinterpret_cast<float*>(outBuffer), inBufSize, writeIt,
reinterpret_cast<float**>(inBuffer), numBufs);
}
void hipPerfSampleRate::float2_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int grids,
int blocks, int numBufs) {
hipLaunchKernelGGL(sampleRate<float2>, dim3(grids, grids, grids),
dim3(blocks), 0, 0, reinterpret_cast<float2 *>(outBuffer),
inBufSize, writeIt, reinterpret_cast<float2 **>(inBuffer), numBufs);
void hipPerfSampleRate::float2_kernel(void* outBuffer, unsigned int inBufSize, unsigned int writeIt,
void** inBuffer, int grids, int blocks, int numBufs) {
hipLaunchKernelGGL(sampleRate<float2>, dim3(grids, grids, grids), dim3(blocks), 0, 0,
reinterpret_cast<float2*>(outBuffer), inBufSize, writeIt,
reinterpret_cast<float2**>(inBuffer), numBufs);
}
void hipPerfSampleRate::float4_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int grids,
int blocks, int numBufs) {
hipLaunchKernelGGL(sampleRate<float4>, dim3(grids, grids, grids),
dim3(blocks), 0, 0, reinterpret_cast<float4 *>(outBuffer),
inBufSize, writeIt, reinterpret_cast<float4 **>(inBuffer), numBufs);
void hipPerfSampleRate::float4_kernel(void* outBuffer, unsigned int inBufSize, unsigned int writeIt,
void** inBuffer, int grids, int blocks, int numBufs) {
hipLaunchKernelGGL(sampleRate<float4>, dim3(grids, grids, grids), dim3(blocks), 0, 0,
reinterpret_cast<float4*>(outBuffer), inBufSize, writeIt,
reinterpret_cast<float4**>(inBuffer), numBufs);
}
void hipPerfSampleRate::run(unsigned int test) {
funPtr p[] = {&hipPerfSampleRate::float_kernel,
&hipPerfSampleRate::float2_kernel,
funPtr p[] = {&hipPerfSampleRate::float_kernel, &hipPerfSampleRate::float2_kernel,
&hipPerfSampleRate::float4_kernel};
// We compute a square domain
@@ -182,35 +177,30 @@ void hipPerfSampleRate::run(unsigned int test) {
bufSize_ = width_ * width_ * typeSizes[typeIdx_];
numBufs_ = (1 << (test / (NUM_SIZES * NUM_TYPES)));
void ** dPtr;
void * hOutPtr;
void * dOutPtr;
void ** hInPtr = new void *[numBufs_];
void ** dInPtr = new void *[numBufs_];
void** dPtr;
void* hOutPtr;
void* dOutPtr;
void** hInPtr = new void*[numBufs_];
void** dInPtr = new void*[numBufs_];
outBufSize_ =
sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * typeSizes[NUM_TYPES - 1];
outBufSize_ = sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * typeSizes[NUM_TYPES - 1];
// Allocate memory on the host and device
HIP_CHECK(hipHostMalloc(reinterpret_cast<void **>(&hOutPtr), outBufSize_,
hipHostMallocDefault));
setData(reinterpret_cast<void *>(hOutPtr), 0xdeadbeef);
HIP_CHECK(hipMalloc(reinterpret_cast<uint **>(&dOutPtr), outBufSize_));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&hOutPtr), outBufSize_, hipHostMallocDefault));
setData(reinterpret_cast<void*>(hOutPtr), 0xdeadbeef);
HIP_CHECK(hipMalloc(reinterpret_cast<uint**>(&dOutPtr), outBufSize_));
// Allocate 2D array in Device
HIP_CHECK(hipMalloc(reinterpret_cast<void **>(&dPtr),
numBufs_* sizeof(void *)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&dPtr), numBufs_ * sizeof(void*)));
for (uint i = 0; i < numBufs_; i++) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void **>(&hInPtr[i]), bufSize_,
hipHostMallocDefault));
HIP_CHECK(hipMalloc(reinterpret_cast<uint **>(&dInPtr[i]), bufSize_));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&hInPtr[i]), bufSize_, hipHostMallocDefault));
HIP_CHECK(hipMalloc(reinterpret_cast<uint**>(&dInPtr[i]), bufSize_));
setData(hInPtr[i], 0x3f800000);
}
// Populate array of pointers with array addresses
HIP_CHECK(hipMemcpy(dPtr, dInPtr, numBufs_* sizeof(void *),
hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(dPtr, dInPtr, numBufs_ * sizeof(void*), hipMemcpyHostToDevice));
// Copy memory from host to device
for (uint i = 0; i < numBufs_; i++) {
@@ -241,20 +231,19 @@ void hipPerfSampleRate::run(unsigned int test) {
// Time the kernel execution
auto all_start = std::chrono::steady_clock::now();
for (uint i = 0; i < maxIter; i++) {
(this->*p[idx]) (reinterpret_cast<void *>(dOutPtr), sizeDW, writeIt,
dPtr, numBufs_, grids, blocks);
(this->*p[idx])(reinterpret_cast<void*>(dOutPtr), sizeDW, writeIt, dPtr, numBufs_, grids,
blocks);
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> all_kernel_time = all_end - all_start;
double perf = (static_cast<double>(outBufSize_ * numBufs_ *
maxIter * (1e-09))) / all_kernel_time.count();
double perf =
(static_cast<double>(outBufSize_ * numBufs_ * maxIter * (1e-09))) / all_kernel_time.count();
INFO("Domain " << sizes[NUM_SIZES - 1] << "x"<< sizes[NUM_SIZES - 1]
<< " bufs " << numBufs_ << " " << types[typeIdx_] << " " << width_
<< "x" <<width_<< " (GB/s) " << perf << "\n");
CONSOLE_PRINT("Domain %u x %u bufs %u %s %u x %u (GB/s) %f\n", sizes[NUM_SIZES - 1],
sizes[NUM_SIZES - 1], numBufs_, types[typeIdx_].c_str(), width_, width_, perf);
HIP_CHECK(hipFree(dOutPtr));
@@ -265,52 +254,51 @@ void hipPerfSampleRate::run(unsigned int test) {
}
HIP_CHECK(hipHostFree(hOutPtr));
HIP_CHECK(hipFree(dPtr));
delete [] hInPtr;
delete [] dInPtr;
delete[] hInPtr;
delete[] dInPtr;
}
void hipPerfSampleRate::setData(void *ptr, unsigned int value) {
unsigned int *ptr2 = (unsigned int *)ptr;
void hipPerfSampleRate::setData(void* ptr, unsigned int value) {
unsigned int* ptr2 = (unsigned int*)ptr;
for (unsigned int i = 0; i < bufSize_ / sizeof(unsigned int); i++) {
ptr2[i] = value;
}
}
void hipPerfSampleRate::checkData(uint *ptr) {
void hipPerfSampleRate::checkData(uint* ptr) {
for (unsigned int i = 0; i < outBufSize_ / sizeof(float); i++) {
if (ptr[i] != static_cast<float>(numBufs_)) {
INFO("Data validation failed at "<< i << " Got "<< ptr[i]
<< ", expected " << (float)numBufs_ << "\n");
DEBUG_PRINT("Data validation failed at %u Got %u, expected %f\n", i, ptr[i], (float)numBufs_);
REQUIRE(false);
}
}
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfSampleRate status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfSampleRate.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfSampleRate status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfSampleRate.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfSampleRate_test") {
hipPerfSampleRate sampleTypes;
REQUIRE(true == sampleTypes.open());
for (unsigned int testCase = 0; testCase < 216 ; testCase+=36) {
for (unsigned int testCase = 0; testCase < 216; testCase += 36) {
sampleTypes.run(testCase);
}
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/
@@ -18,19 +18,19 @@
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
// #define ENABLE_DEBUG 1
#define sharedMemSize1 2048
#define sharedMemSize2 256
__global__ void sharedMemReadSpeed1(float *outBuf, ulong N) {
__global__ void sharedMemReadSpeed1(float* outBuf, ulong N) {
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
size_t lid = threadIdx.x;
__shared__ float local[sharedMemSize1];
@@ -84,7 +84,7 @@ __global__ void sharedMemReadSpeed1(float *outBuf, ulong N) {
}
}
__global__ void sharedMemReadSpeed2(float *outBuf, ulong N) {
__global__ void sharedMemReadSpeed2(float* outBuf, ulong N) {
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
size_t lid = threadIdx.x;
__shared__ float local[sharedMemSize2];
@@ -116,8 +116,8 @@ __global__ void sharedMemReadSpeed2(float *outBuf, ulong N) {
}
static bool hipPerfSharedMemReadSpeed_test() {
float *dDst;
float *hDst;
float* dDst;
float* hDst;
hipStream_t stream;
constexpr uint numSizes = 4;
constexpr uint Sizes[numSizes] = {262144, 1048576, 4194304, 16777216};
@@ -132,8 +132,8 @@ static bool hipPerfSharedMemReadSpeed_test() {
HIP_CHECK(hipSetDevice(device));
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, device));
INFO("info: running on bus " << "0x" << props.pciBusID << " " << props.name
<< " with " << props.multiProcessorCount << " CUs \n");
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs\n", props.pciBusID, props.name,
props.multiProcessorCount);
HIP_CHECK(hipStreamCreate(&stream));
@@ -149,8 +149,8 @@ static bool hipPerfSharedMemReadSpeed_test() {
HIP_CHECK(hipMalloc(&dDst, nBytes));
HIP_CHECK(hipMemcpy(dDst, hDst, nBytes, hipMemcpyHostToDevice));
hipLaunchKernelGGL(sharedMemReadSpeed1, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
hipLaunchKernelGGL(sharedMemReadSpeed1, dim3(blocks), dim3(threadsPerBlock), 0, stream, dDst,
N);
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
@@ -160,8 +160,7 @@ static bool hipPerfSharedMemReadSpeed_test() {
tmp = 0;
}
if (hDst[i] != tmp) {
INFO("info: Data validation failed for warm up run! \n");
INFO("info: expected " << tmp << " got " << hDst[i] << " \n");
DEBUG_PRINT("Data validation failed for warm up run! expected %d got %f\n", tmp, hDst[i]);
return false;
}
tmp += threadsPerBlock / 2;
@@ -169,8 +168,8 @@ static bool hipPerfSharedMemReadSpeed_test() {
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(sharedMemReadSpeed1, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
hipLaunchKernelGGL(sharedMemReadSpeed1, dim3(blocks), dim3(threadsPerBlock), 0, stream, dDst,
N);
}
HIP_CHECK(hipDeviceSynchronize());
@@ -178,15 +177,14 @@ static bool hipPerfSharedMemReadSpeed_test() {
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(blocks * threadsPerBlock)
* (numReads1 * sizeof(float) + sharedMemSizeBytes1 / 64)
* nIter * (1e-09)) / all_kernel_time.count();
double perf = (static_cast<double>(blocks * threadsPerBlock) *
(numReads1 * sizeof(float) + sharedMemSizeBytes1 / 64) * nIter * (1e-09)) /
all_kernel_time.count();
INFO("info: read speed = " << std::setw(8) << perf << " GB/s for " <<
sharedMemSizeBytes1 / 1024 << " KB shared memory with " <<
std::setw(8) << blocks * threadsPerBlock << " threads, "
<< std::setw(4) << numReads1 <<
" reads in sharedMemReadSpeed1 kernel \n");
CONSOLE_PRINT(
"info: read speed = %.2f GB/s for %d KB shared memory with %d threads, %d reads in "
"sharedMemReadSpeed1 kernel\n",
perf, sharedMemSizeBytes1 / 1024, blocks * threadsPerBlock, numReads1);
delete[] hDst;
HIP_CHECK(hipFree(dDst));
@@ -204,15 +202,15 @@ static bool hipPerfSharedMemReadSpeed_test() {
HIP_CHECK(hipMalloc(&dDst, nBytes));
HIP_CHECK(hipMemcpy(dDst, hDst, nBytes, hipMemcpyHostToDevice));
hipLaunchKernelGGL(sharedMemReadSpeed2, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
hipLaunchKernelGGL(sharedMemReadSpeed2, dim3(blocks), dim3(threadsPerBlock), 0, stream, dDst,
N);
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(sharedMemReadSpeed2, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
hipLaunchKernelGGL(sharedMemReadSpeed2, dim3(blocks), dim3(threadsPerBlock), 0, stream, dDst,
N);
}
HIP_CHECK(hipDeviceSynchronize());
@@ -220,15 +218,14 @@ static bool hipPerfSharedMemReadSpeed_test() {
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(blocks * threadsPerBlock)
* (numReads2 * sizeof(float) + sharedMemSizeBytes2 / 64)
* nIter * (1e-09)) / all_kernel_time.count();
double perf = (static_cast<double>(blocks * threadsPerBlock) *
(numReads2 * sizeof(float) + sharedMemSizeBytes2 / 64) * nIter * (1e-09)) /
all_kernel_time.count();
INFO("info: read speed = " << std::setw(8) << perf << " GB/s for "
<< sharedMemSizeBytes2 / 1024 << " KB shared memory with "
<< std::setw(8) << blocks * threadsPerBlock << " threads, "
<< std::setw(4) << numReads2 <<
" reads in sharedMemReadSpeed2 kernel \n");
CONSOLE_PRINT(
"info: read speed = %.2f GB/s for %d KB shared memory with %d threads, %d reads in "
"sharedMemReadSpeed2 kernel\n",
perf, sharedMemSizeBytes2 / 1024, blocks * threadsPerBlock, numReads2);
delete[] hDst;
HIP_CHECK(hipFree(dDst));
@@ -238,30 +235,31 @@ static bool hipPerfSharedMemReadSpeed_test() {
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfSharedMemReadSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfSharedMemReadSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
* Test Description
* ------------------------
*  - Verify hipPerfSharedMemReadSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfSharedMemReadSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfSharedMemReadSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfSharedMemReadSpeed as"
"there is no device to test.\n");
SUCCEED(
"Skipped testcase hipPerfSharedMemReadSpeed as"
"there is no device to test.\n");
} else {
REQUIRE(true == hipPerfSharedMemReadSpeed_test());
}
}
/**
* End doxygen group perfMemoryTest.
* @}
*/
* End doxygen group perfMemoryTest.
* @}
*/