/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /* * Test Scenarios: * 1. Perform simple and pinned host memory of hipMemcpyHtoA API * 2. Allocate Memory from one GPU device and call hipMemcpyHtoA from Peer * GPU device * 3. Perform hipMemcpyHtoA Negative Scenarios * 4. Perform bytecount 0 validation for hipMemcpyHtoA API */ #include #include static constexpr auto NUM_W{10}; static constexpr auto NUM_H{1}; static constexpr auto copy_bytes{2}; /* This testcase performs the peer device context scenario of hipMemcpyHtoA API Memory is allocated in GPU-0 and the API is triggered from GPU-1 Input: "B_h" which is initialized with 1.6 Output: "A_d" output of hipMemcpyHtoA is copied to "hData" host variable validated the result with "B_h" */ #if HT_AMD HIP_TEMPLATE_TEST_CASE(Unit_hipMemcpyHtoA_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)); // Changing the device context HIP_CHECK(hipSetDevice(1)); // Performing API call HIP_CHECK(hipMemcpyHtoA(A_d, 0, B_h, copy_bytes * sizeof(TestType))); HIP_CHECK(hipMemcpy2DFromArray(hData, sizeof(TestType) * NUM_W, A_d, 0, 0, sizeof(TestType) * NUM_W, 1, hipMemcpyDeviceToHost)); // 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