From c56876cc19b67cb42d7c6849ae229a0ca82caada Mon Sep 17 00:00:00 2001 From: Aaron Enye Shi Date: Wed, 24 Jul 2019 03:49:20 -0400 Subject: [PATCH] Fix hipMemcpy-size test running out of Host Mem (#1224) * Fix hipMemcpy-size test running out of Host Mem The hipMemcpy-size uses a maxElem calculated from the total GPU mem /8. Then it will allocate 4 times that amount of host memory. This tests begins failing when there is not enough host memory, such as on systems with 32GB GPU mem, and 16GB RAM. This fixes the test if not enough host memory is available on the system. * Add windows support to hipMemcpy-size fix * avoid linking extra libs for windows * HIPMemcpy-size Remove freeCPU including swap --- .../tests/src/runtimeApi/memory/hipMemcpy.cpp | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/hipamd/tests/src/runtimeApi/memory/hipMemcpy.cpp b/hipamd/tests/src/runtimeApi/memory/hipMemcpy.cpp index c8ee170336..208f263ab5 100644 --- a/hipamd/tests/src/runtimeApi/memory/hipMemcpy.cpp +++ b/hipamd/tests/src/runtimeApi/memory/hipMemcpy.cpp @@ -34,6 +34,13 @@ THE SOFTWARE. #include "hip/hip_runtime.h" #include "test_common.h" +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#else +#include "sys/types.h" +#include "sys/sysinfo.h" +#endif void printSep() { printf( @@ -280,6 +287,26 @@ void memcpytest2_for_type(size_t numElements) { } } +#ifdef _WIN32 +void memcpytest2_get_host_memory(size_t& free, size_t& total) { + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + free = status.ullAvailPhys; + total = status.ullTotalPhys; +} +#else +struct sysinfo memInfo; +void memcpytest2_get_host_memory(size_t& free, size_t& total) { + sysinfo(&memInfo); + long long freePhysMem=memInfo.freeram; + freePhysMem *= memInfo.mem_unit; + free = freePhysMem; + long long totalPhysMem=memInfo.totalram; + totalPhysMem *= memInfo.mem_unit; + total = totalPhysMem; +} +#endif //--- // Try many different sizes to memory copy. @@ -291,12 +318,20 @@ void memcpytest2_sizes(size_t maxElem = 0) { int deviceId; HIPCHECK(hipGetDevice(&deviceId)); - size_t free, total; + size_t free, total, freeCPU, totalCPU; HIPCHECK(hipMemGetInfo(&free, &total)); + memcpytest2_get_host_memory(freeCPU, totalCPU); if (maxElem == 0) { - maxElem = free / sizeof(T) / 8; + // Use lesser maxElem if not enough host memory available + size_t maxElemGPU = free / sizeof(T) / 8; + size_t maxElemCPU = freeCPU / sizeof(T) / 8; + maxElem = maxElemGPU < maxElemCPU ? maxElemGPU : maxElemCPU; } + printf( + " Host: free=%zu (%4.2fMB) total=%zu (%4.2fMB)\n", + freeCPU, (float)(freeCPU / 1024.0 / 1024.0), + totalCPU, (float)(totalCPU / 1024.0 / 1024.0)); printf( " device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",