From bffe0bd7ac38df594fa47e611d1fe98f3fcd080b Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Fri, 18 Mar 2016 03:09:52 -0500 Subject: [PATCH] Supported --aliged mode. Add results check for H2D and D2H. [ROCm/hip-tests commit: 97493d20988b7d3c435a5ceebee53a67977b9881] --- .../hipBusBandwidth/hipBusBandwidth.cpp | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/projects/hip-tests/samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp b/projects/hip-tests/samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp index a43bee77e1..6e875667f9 100644 --- a/projects/hip-tests/samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp +++ b/projects/hip-tests/samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp @@ -13,6 +13,7 @@ int p_iterations = 10; int p_device = 0; int p_detailed = 0; bool p_async = 0; +bool p_alignedhost = 1; bool p_h2d = true; bool p_d2h = true; @@ -120,7 +121,11 @@ void RunBenchmark_H2D(ResultDatabase &resultDB) } else { - hostMem = new float[numMaxFloats]; + if (p_alignedhost) { + hostMem = (float*)aligned_alloc(64, numMaxFloats*sizeof(float)); + } else { + hostMem = new float[numMaxFloats]; + } } for (int i = 0; i < numMaxFloats; i++) @@ -189,6 +194,21 @@ void RunBenchmark_H2D(ResultDatabase &resultDB) } } + // Check. First reset the host memory, then copy-back result. Then compare against original ref value. + for (int i = 0; i < numMaxFloats; i++) + { + hostMem[i] = 0; + } + hipMemcpy(hostMem, device, numMaxFloats*sizeof(float), hipMemcpyDeviceToHost); + for (int i = 0; i < numMaxFloats; i++) + { + float ref = i % 77; + if (ref != hostMem[i]) { + printf ("error: H2D. i=%d reference:%6.f != copyback:%6.2f\n", i, ref, hostMem[i]); + } + } + + // Cleanup hipFree((void*)device); CHECK_HIP_ERROR(); @@ -199,7 +219,11 @@ void RunBenchmark_H2D(ResultDatabase &resultDB) } else { - delete[] hostMem; + if (p_alignedhost) { + delete[] hostMem; + } else { + free(hostMem); + } } hipEventDestroy(start); hipEventDestroy(stop); @@ -254,15 +278,15 @@ void RunBenchmark_D2H(ResultDatabase &resultDB) hipMalloc((void**)&device, sizeof(float) * numMaxFloats); while (hipGetLastError() != hipSuccess) { - // drop the size and try again - if (p_verbose) std::cout << " - dropping size allocating device mem\n"; - --nSizes; - if (nSizes < 1) - { - std::cerr << "Error: Couldn't allocated any device buffer\n"; - return; - } - numMaxFloats = 1024 * (sizes[nSizes-1]) / 4; + // drop the size and try again + if (p_verbose) std::cout << " - dropping size allocating device mem\n"; + --nSizes; + if (nSizes < 1) + { + std::cerr << "Error: Couldn't allocated any device buffer\n"; + return; + } + numMaxFloats = 1024 * (sizes[nSizes-1]) / 4; hipMalloc((void**)&device, sizeof(float) * numMaxFloats); } @@ -316,6 +340,16 @@ void RunBenchmark_D2H(ResultDatabase &resultDB) //resultDB.AddResult("ReadbackLatencyEstimate", "2-4kb", "ms", times[1]-(times[2]-times[1])/1.); } + + // Check. First reset the host memory, then copy-back result. Then compare against original ref value. + for (int i = 0; i < numMaxFloats; i++) + { + float ref = i % 77; + if (ref != hostMem2[i]) { + printf ("error: D2H. i=%d reference:%6.f != copyback:%6.2f\n", i, ref, hostMem2[i]); + } + } + // Cleanup hipFree((void*)device); CHECK_HIP_ERROR();