From 09f4fc418862e53ef016e7350898e042a25800c6 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Sat, 9 Apr 2016 04:47:07 -0500 Subject: [PATCH] Improve P2P test. Add option to select which device does the copy. [ROCm/hip commit: 466ab79f1600907c6b10795732c04c4ce280ca74] --- .../hip/tests/src/hipPeerToPeer_simple.cpp | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/projects/hip/tests/src/hipPeerToPeer_simple.cpp b/projects/hip/tests/src/hipPeerToPeer_simple.cpp index ca2501438d..aa305f92fa 100644 --- a/projects/hip/tests/src/hipPeerToPeer_simple.cpp +++ b/projects/hip/tests/src/hipPeerToPeer_simple.cpp @@ -26,11 +26,26 @@ THE SOFTWARE. #include "hip_runtime.h" #include "test_common.h" +bool p_memcpyWithPeer = false; + +void parseMyArguments(int argc, char *argv[]) +{ + int more_argc = HipTest::parseStandardArguments(argc, argv, false); + // parse args for this test: + for (int i = 1; i < more_argc; i++) { + const char *arg = argv[i]; + + if (!strcmp(arg, "--memcpyWithPeer")) { + p_memcpyWithPeer = true; + } else { + failed("Bad argument '%s'", arg); + } + }; +}; int main(int argc, char *argv[]) { - - HipTest::parseStandardArguments(argc, argv, true); + parseMyArguments(argc, argv); int deviceCnt; @@ -58,27 +73,31 @@ int main(int argc, char *argv[]) char *A_h; A_h = (char*)malloc(Nbytes); - HIPCHECK (hipSetDevice(peerDevice)); - HIPCHECK (hipMalloc(&A_d1, Nbytes) ); + // allocate and initialize memory on device0 HIPCHECK (hipSetDevice(p_gpuDevice)); HIPCHECK (hipMalloc(&A_d0, Nbytes) ); - - - // Set memory on first device. - HIPCHECK (hipSetDevice(p_gpuDevice)); HIPCHECK ( hipMemset(A_d0, memsetval, Nbytes) ); + // allocate and initialize memory on peer device + HIPCHECK (hipSetDevice(peerDevice)); + HIPCHECK (hipMalloc(&A_d1, Nbytes) ); + HIPCHECK ( hipMemset(A_d1, 0x13, Nbytes) ); + + + // Device0 push to device1, using P2P: - HIPCHECK ( hipMemcpy(A_d1, A_d0, Nbytes, hipMemcpyDefault)); + HIPCHECK (hipSetDevice(p_memcpyWithPeer ? peerDevice : p_gpuDevice)); + HIPCHECK (hipMemcpy(A_d1, A_d0, Nbytes, hipMemcpyDefault)); // Copy data back to host: - HIPCHECK ( hipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost)); + HIPCHECK (hipSetDevice(peerDevice)); + HIPCHECK (hipMemcpy(A_h, A_d1, Nbytes, hipMemcpyDeviceToHost)); // Check host data: for (int i=0; i