// Test under-development. Calls async mem-copy API, experiment with functionality. #include "hip_runtime.h" #include "test_common.h" unsigned p_streams = 2; void simpleNegTest() { printf ("testing: %s\n",__func__); hipError_t e; float *A_malloc, *A_pinned, *A_d; size_t Nbytes = N*sizeof(float); A_malloc = (float*)malloc(Nbytes); HIPCHECK(hipMallocHost(&A_pinned, Nbytes)); HIPCHECK(hipMalloc(&A_d, Nbytes)); // Can't use default with async copy e = hipMemcpyAsync(A_pinned, A_d, Nbytes, hipMemcpyDefault, NULL); HIPASSERT (e==hipErrorInvalidMemcpyDirection); // TODO HIPASSERT (e!= hipSuccess); // Not sure what happens here, the memory must be pinned. e = hipMemcpyAsync(A_malloc, A_d, Nbytes, hipMemcpyHostToDevice, NULL); printf (" async memcpy of A_malloc to A_d. Result=%d\n", e); //HIPASSERT (e==hipErrorInvalidValue); } //--- //Send many async copies to the same stream. //This requires runtime to keep track of many outstanding commands, and in the case of HCC requires growing/tracking the signal pool: template void test_manyCopies(int nElements, int numCopies) { size_t Nbytes = nElements*sizeof(T); size_t eachCopyElements = nElements / numCopies; size_t eachCopyBytes = eachCopyElements * sizeof(T); printf ("-----------------------------------------------------------------------------------------------\n"); printf ("testing: %s Nbytes=%zu (%6.1f MB) numCopies=%d eachCopyElements=%zu eachCopyBytes=%zu\n", __func__, Nbytes, (double)(Nbytes)/1024.0/1024.0, numCopies, eachCopyElements, eachCopyBytes); T *A_d; T *A_h1, *A_h2; HIPCHECK(hipMallocHost(&A_h1, Nbytes)); HIPCHECK(hipMallocHost(&A_h2, Nbytes)); HIPCHECK(hipMalloc(&A_d, Nbytes)); for (int i=0; i (i); } hipStream_t stream; HIPCHECK (hipStreamCreate(&stream)); //stream=0; // fixme TODO for (int i=0; i= argc || !HipTest::parseUInt(argv[i], &p_streams)) { failed("Bad streams argument"); } } else { failed("Bad argument '%s'", arg); } }; }; int main(int argc, char *argv[]) { HipTest::parseStandardArguments(argc, argv, true); parseMyArguments(argc, argv); printf ("info: set device to %d\n", p_gpuDevice); HIPCHECK(hipSetDevice(p_gpuDevice)); if (p_tests & 0x1) { simpleNegTest(); } if (p_tests & 0x2) { test_manyCopies(1024, 16); test_manyCopies(1024, 4); test_manyCopies(1024*4, 64); } if (p_tests & 0x4) { test_chunkedAsyncExample(p_streams, true, true, true); // Easy sync version test_chunkedAsyncExample(p_streams, false, true, true); // Easy sync version test_chunkedAsyncExample(p_streams, false, false, true); // Some async test_chunkedAsyncExample(p_streams, false, false, false); // All async } passed(); }