/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /* This testcase verifies the hipMemcpyDtoD basic scenario 1. H2D-KernelLaunch-D2H scenario */ #include #include #include static constexpr auto NUM_ELM{1024}; /* This testcase verifies hipMemcpyDtoD API 1.Initializes device variables 2.Launches kernel and performs the sum of device variables 3.Copies the result to host variable and validates the result. 4.Sets the peer device 5.D2D copy from GPU-0 to GPU-1 6.Kernel Launch 7.DtoH copy and validating the result */ HIP_TEMPLATE_TEST_CASE(Unit_hipMemcpyDtoD_Basic, int, float, double) { size_t Nbytes = NUM_ELM * sizeof(TestType); int numDevices = 0; TestType *A_d{nullptr}, *B_d{nullptr}, *C_d{nullptr}, *X_d{nullptr}, *Y_d{nullptr}, *Z_d{nullptr}; TestType *A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr}; HIP_CHECK(hipGetDeviceCount(&numDevices)); if (numDevices < 2) { HIP_SKIP_TEST(HipTest::SkipReason::kFewerThanTwoGpus); } int canAccessPeer = 0; HIP_CHECK(hipDeviceCanAccessPeer(&canAccessPeer, 0, 1)); HIP_CHECK(hipSetDevice(0)); if (!canAccessPeer) { HIP_SKIP_TEST(HipTest::SkipReason::kPeerAccessUnavailable); } HIP_CHECK(hipDeviceEnablePeerAccess(1, 0)); HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, NUM_ELM, false); HIP_CHECK(hipSetDevice(1)); HIP_CHECK(hipMalloc(&X_d, Nbytes)); HIP_CHECK(hipMalloc(&Y_d, Nbytes)); HIP_CHECK(hipMalloc(&Z_d, Nbytes)); HIP_CHECK(hipSetDevice(0)); HIP_CHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice)); hipLaunchKernelGGL(HipTest::vectorADD, dim3(1), NUM_ELM, 0, 0, static_cast(A_d), static_cast(B_d), C_d, NUM_ELM); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost)); HIP_CHECK(hipDeviceSynchronize()); HipTest::checkVectorADD(A_h, B_h, C_h, NUM_ELM); HIP_CHECK(hipSetDevice(1)); hipError_t memcpy_err = hipSuccess; BEGIN_CAPTURE_SYNC(memcpy_err, false); HIP_CHECK_ERROR(hipMemcpyDtoD((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes), memcpy_err); HIP_CHECK_ERROR(hipMemcpyDtoD((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes), memcpy_err); END_CAPTURE_SYNC(memcpy_err); if (memcpy_err == hipSuccess) { hipLaunchKernelGGL(HipTest::vectorADD, dim3(1), NUM_ELM, 0, 0, static_cast(X_d), static_cast(Y_d), Z_d, NUM_ELM); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipMemcpyDtoH(C_h, (hipDeviceptr_t)Z_d, Nbytes)); HIP_CHECK(hipDeviceSynchronize()); HipTest::checkVectorADD(A_h, B_h, C_h, NUM_ELM); } HIP_CHECK(hipFree(X_d)); HIP_CHECK(hipFree(Y_d)); HIP_CHECK(hipFree(Z_d)); (void)hipGetLastError(); HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); }