SWDEV-294470 - [dtest] Catch2 unit tests for hipMemset2d, hipMemset2d Mthread, hipMemset3d files. (#2347)

Change-Id: Ia503f9dd12b8c576dee17c3fcbb018eeac305a7e

Co-authored-by: Maneesh Gupta <maneesh.gupta@amd.com>
This commit is contained in:
sumanthtg
2021-09-17 11:54:39 +05:30
committed by GitHub
parent 8763c8c2ad
commit b537d94974
5 changed files with 531 additions and 1 deletions
+37 -1
View File
@@ -23,10 +23,46 @@ THE SOFTWARE.
#pragma once
#include "hip_test_common.hh"
#ifdef __linux__
#include <sys/sysinfo.h>
#endif
namespace HipTest {
static inline int getGeviceCount() {
int dev = 0;
HIPCHECK(hipGetDeviceCount(&dev));
HIP_CHECK(hipGetDeviceCount(&dev));
return dev;
}
// Get Free Memory from the system
static size_t getMemoryAmount() {
#ifdef __linux__
struct sysinfo info{};
sysinfo(&info);
return info.freeram / (1024 * 1024); // MB
#elif defined(_WIN32)
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
return (statex.ullAvailPhys / (1024 * 1024)); // MB
#endif
}
static size_t getHostThreadCount(const size_t memPerThread,
const size_t maxThreads) {
if (memPerThread == 0) return 0;
auto memAmount = getMemoryAmount();
const auto processor_count = std::thread::hardware_concurrency();
if (processor_count == 0 || memAmount == 0) return 0;
size_t thread_count = 0;
if ((processor_count * memPerThread) < memAmount)
thread_count = processor_count;
else
thread_count = reinterpret_cast<size_t>(memAmount / memPerThread);
if (maxThreads > 0) {
return (thread_count > maxThreads) ? maxThreads : thread_count;
}
return thread_count;
}
} // namespace HipTest