From 731a2a58d331490b32457c8ee5ea5e94dbff4db3 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Tue, 16 Feb 2016 01:58:24 -0600 Subject: [PATCH] Add comments to tests --- hipamd/tests/src/hipMemcpy.cpp | 25 ++++++++++---- hipamd/tests/src/hipPointerAttrib.cpp | 48 +++++++++++++++++++++------ 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/hipamd/tests/src/hipMemcpy.cpp b/hipamd/tests/src/hipMemcpy.cpp index 3502b81e9d..97a372304a 100644 --- a/hipamd/tests/src/hipMemcpy.cpp +++ b/hipamd/tests/src/hipMemcpy.cpp @@ -28,7 +28,9 @@ void printSep() printf ("======================================================================================\n"); } +//--- // Test simple H2D copies and back. +// Designed to stress a small number of simple smoke tests void simpleTest1() { printf ("test: %s\n", __func__); @@ -61,8 +63,16 @@ void simpleTest1() } -// Test many different kinds of memory copies: - +//--- +// Test many different kinds of memory copies. +// THe subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result. +// +// IN: numElements controls the number of elements used for allocations. +// IN: usePinnedHost : If true, allocate host with hipMallocHost and is pinned ; else allocate host memory with malloc. +// IN: useHostToHost : If true, add an extra host-to-host copy. +// IN: useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced. +// IN: useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use explicit memcpy direction. +// template void memcpytest2(size_t numElements, bool usePinnedHost, bool useHostToHost, bool useDeviceToDevice, bool useMemkindDefault) { @@ -134,18 +144,15 @@ void memcpytest2(size_t numElements, bool usePinnedHost, bool useHostToHost, boo } +//--- +//Try all the 16 possible combinations to memcpytest2 - usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault template void memcpytest2_loop(size_t numElements) { printSep(); for (int usePinnedHost =0; usePinnedHost<=1; usePinnedHost++) { -#define USE_HOST_2_HOST -#ifdef USE_HOST_2_HOST for (int useHostToHost =0; useHostToHost<=1; useHostToHost++) { // TODO -#else - for (int useHostToHost =0; useHostToHost<=0; useHostToHost++) { // TODO -#endif for (int useDeviceToDevice =0; useDeviceToDevice<=1; useDeviceToDevice++) { for (int useMemkindDefault =0; useMemkindDefault<=1; useMemkindDefault++) { memcpytest2(numElements, usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault); @@ -156,6 +163,8 @@ void memcpytest2_loop(size_t numElements) } +//--- +//Try many different sizes to memory copy. template void memcpytest2_sizes(size_t maxElem=0, size_t offset=0) { @@ -184,6 +193,8 @@ void memcpytest2_sizes(size_t maxElem=0, size_t offset=0) } +//--- +//Create multiple threads to stress multi-thread locking behavior in the allocation/deallocation/tracking logic: template void multiThread_1(bool serialize, bool usePinnedHost) { diff --git a/hipamd/tests/src/hipPointerAttrib.cpp b/hipamd/tests/src/hipPointerAttrib.cpp index 1418997274..586b2af5b5 100644 --- a/hipamd/tests/src/hipPointerAttrib.cpp +++ b/hipamd/tests/src/hipPointerAttrib.cpp @@ -27,7 +27,9 @@ THE SOFTWARE. #include "test_common.h" #ifdef __HIP_PLATFORM_HCC__ -#include "hcc_detail/AM.h" +//#include "hcc_detail/AM.h" +#include "hc_am.hpp" + #endif size_t Nbytes = 0; @@ -97,8 +99,8 @@ inline int zrand(int max) //================================================================================================= // Functins to run tests //================================================================================================= -// -//Run through a couple simple cases to test lookups and hostd pointer arithmetic: +//-- +//Run through a couple simple cases to test lookups and host pointer arithmetic: void testSimple() { printf ("\n"); @@ -188,7 +190,10 @@ void testSimple() HIPASSERT(e == hipErrorInvalidValue); // OS-allocated pointers should return hipErrorInvalidValue. } - +//--- +//Reset the memory tracker (remove allocations from all known devices): +//This frees any memory allocated through the runtime. +//The routine will not release any void resetTracker () { if (p_verbose & 0x1) { @@ -214,7 +219,8 @@ struct SuperPointerAttribute { }; - +//--- +//Support function to check result against a reference: void checkPointer(SuperPointerAttribute &ref, int major, int minor, void *pointer) { hipPointerAttribute_t attribs; @@ -236,6 +242,12 @@ void checkPointer(SuperPointerAttribute &ref, int major, int minor, void *pointe } +//--- +//Test that allocates memory across all 4 devices withing the specified size range (minSize...maxSize). +//Then does lookups to make sure the info reported by the tracker matches expecations +//Then deallocates it all. +// +//Multiple threads can call this funtion and in fact we do this in the testMultiThreaded_1 test. void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) { printf (" clusterAllocs numAllocs=%d size=%lu..%lu\n", numAllocs, minSize, maxSize); @@ -313,9 +325,6 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) } - - - #ifdef __HIP_PLATFORM_HCC__ if (p_verbose & 0x2) { printf ("Tracker after cleanup:\n"); @@ -325,6 +334,10 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) } +//--- +// Multi-threaded test with many simul allocs. +// IN : serialize will force the test to run in serial fashion. +// Seems like this does not hit MT corner cases in the tracker very often - testMultiThreaded_2 below seems more effective. void testMultiThreaded_1(bool serialize=false) { printf ("\n===========================================================================\n"); @@ -356,8 +369,8 @@ void testMultiThreaded_1(bool serialize=false) ///================================================================================================ - -// Add pointers to tracker very quickly. +//--- +//Repeatedly query a single entry: void thread_query(void *ptr, const hipPointerAttribute_t *refAttrib) { int count = 0; @@ -376,6 +389,9 @@ void thread_query(void *ptr, const hipPointerAttribute_t *refAttrib) } +#ifdef __HIP_PLATFORM_HCC__ +//--- +// Add pointers to tracker very quickly, then remove them quickly: enum Dir {Up, Down}; void thread_noise_generator(int iters, size_t numBuffers, Dir addDir, Dir removeDir) { @@ -412,6 +428,13 @@ void thread_noise_generator(int iters, size_t numBuffers, Dir addDir, Dir remove } +//--- +//Multi-thread test that is effective at catching locking errors in the alloc/dealloc/tracker. +//The query thread repeately requests information on the same block of memory. +//Meanwhile, the thread_noise_generator registers a large number of blocks, and +//then unregisters them. This causes a large amount of rebalancing in the tree +//structure and will generate errors unless the locks in the tracker are preventing reading +//while writing. void testMultiThreaded_2() { std::atomic inflight(2); @@ -445,6 +468,8 @@ void testMultiThreaded_2() hipSetDevice(0); hipDeviceReset(); } +#endif + int main(int argc, char *argv[]) @@ -483,11 +508,14 @@ int main(int argc, char *argv[]) testMultiThreaded_1(false); } + +#ifdef __HIP_PLATFORM_HCC__ if (p_tests & 0x10) { srand(0x400); testMultiThreaded_2(); resetTracker(); } +#endif printf ("\n"); passed();