/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /* * Test Scenarios: * 1. Perform host and Pinned host Memory * 2. Perform bytecount 0 validation for hipMemcpyAtoH API * 3. Allocate Memory from one GPU device and call hipMemcpyAtoH from Peer * GPU device * 4. Perform hipMemcpyAtoH Negative Scenarios */ #include #include static constexpr auto NUM_W{10}; static constexpr auto NUM_H{1}; static constexpr auto copy_bytes{2}; /* This testcase performs the basic and pinned host memory scenarios of hipMemcpyAtoH API Memory is allocated in GPU-0 and the API is triggered from GPU-1 Input: "A_d" initialized with "hData" Pi value Output:"B_h" host variable output of hipMemcpyAtoH API is then validated with "hData" */ #if HT_AMD HIP_TEMPLATE_TEST_CASE(Unit_hipMemcpyAtoH_multiDevice_PeerDeviceContext, char, int, float) { CHECK_IMAGE_SUPPORT int numDevices = 0; HIP_CHECK(hipGetDeviceCount(&numDevices)); if (numDevices > 1) { int peerAccess = 0; HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0)); if (!peerAccess) { HIP_SKIP_TEST(HipTest::SkipReason::kPeerAccessUnavailable); } else { HIP_CHECK(hipSetDevice(0)); hipArray_t A_d; TestType *hData{nullptr}, *B_h{nullptr}; size_t width{NUM_W * sizeof(TestType)}; // Initialization of data HipTest::initArrays(nullptr, nullptr, nullptr, &hData, &B_h, nullptr, NUM_W); HipTest::setDefaultData(NUM_W, hData, B_h, nullptr); hipChannelFormatDesc desc = hipCreateChannelDesc(); HIP_CHECK(hipMallocArray(&A_d, &desc, NUM_W, NUM_H, hipArrayDefault)); HIP_CHECK(hipMemcpy2DToArray(A_d, 0, 0, hData, width, width, NUM_H, hipMemcpyHostToDevice)); HIP_CHECK(hipDeviceSynchronize()); // Changing the device context HIP_CHECK(hipSetDevice(1)); // Performing API call REQUIRE(hipMemcpyAtoH(B_h, A_d, 0, copy_bytes * sizeof(TestType)) == hipSuccess); // Validating the result REQUIRE(HipTest::checkArray(B_h, hData, copy_bytes, NUM_H) == true); // DeAllocating the memory HIP_CHECK(hipFreeArray(A_d)); REQUIRE(HipTest::freeArrays(nullptr, nullptr, nullptr, hData, B_h, nullptr, false) == true); } } else { HIP_SKIP_TEST(HipTest::SkipReason::kFewerThanTwoGpus); } } #endif