Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/memory/hipMemcpy3DPeer.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

219 lines
7.5 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
/*@addtogroup hipMemcpy3DPeer hipMemcpy3DPeer* @{
*@ingroup MemoryTest* `hipError_t hipMemcpy3DPeer(hipMemcpy3DPeerParms* p)` -
*Performs 3D memory copies between devices.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the 3D peer to peer device copy.
* 1. Allocate device memory for two Arrays (array_1, array_2).
* 2. Fill the source array with some data with hipMemcpy3D.
* 3. Transfer data between two peer devices with hipMemcpy3DPeer.
* 4. Verify the data on host.
* Test source
* ------------------------
* - catch/unit/memory/hipMemcpy3DPeer.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 7.1
*/
HIP_TEST_CASE(Unit_hipMemcpy3DPeer_BasicFunctional) {
CHECK_IMAGE_SUPPORT
constexpr int numW = 16;
constexpr int numH = 16;
constexpr int depth = 4;
size_t volume = numW * numH * depth;
hipExtent extent = make_hipExtent(numW, numH, depth);
const auto device_count = HipTest::getDeviceCount();
if (device_count <= 1) {
HIP_SKIP_TEST(HipTest::SkipReason::kFewerThanTwoGpus);
}
const auto src_device = GENERATE_COPY(range(0, device_count));
const auto dst_device = GENERATE_COPY(range(0, device_count));
if (src_device == dst_device) {
INFO("Src device: " << src_device << ", Dst device: " << dst_device);
HIP_SKIP_TEST(HipTest::SkipReason::kMemcpyPeerSameSrcDstDevice);
}
HIP_CHECK(hipSetDevice(src_device));
int can_access_peer = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&can_access_peer, src_device, dst_device));
if (!can_access_peer) {
HIP_SKIP_TEST(HipTest::SkipReason::kPeerAccessUnavailable);
}
// Array-1 Memory allocation
hipChannelFormatDesc channelDesc_1 = hipCreateChannelDesc<char>();
hipArray_t array_1;
HIP_CHECK(hipMalloc3DArray(&array_1, &channelDesc_1, extent, 0));
// Set the array memory
std::vector<char>tmpHost(volume, 0xb);
hipMemcpy3DParms fillParms{};
fillParms.srcPos = make_hipPos(0, 0, 0);
fillParms.dstPos = make_hipPos(0, 0, 0);
fillParms.srcPtr = make_hipPitchedPtr(tmpHost.data(), numW, numW, numH);
fillParms.dstArray = array_1;
fillParms.extent = extent;
fillParms.kind = hipMemcpyHostToDevice;
HIP_CHECK(hipMemcpy3D(&fillParms));
// Array-2 Memory allocation
HIP_CHECK(hipSetDevice(dst_device));
hipChannelFormatDesc channelDesc_2 = hipCreateChannelDesc<char>();
hipArray_t array_2;
HIP_CHECK(hipMalloc3DArray(&array_2, &channelDesc_2, extent, 0));
HIP_CHECK(hipSetDevice(src_device));
// Copy data to peer-peer device
hipMemcpy3DPeerParms peerCopyParams{};
peerCopyParams.dstArray = array_2;
peerCopyParams.dstDevice = dst_device;
peerCopyParams.dstPos = make_hipPos(0, 0, 0);
peerCopyParams.dstPtr = make_hipPitchedPtr(0, 0, 0, 0);
peerCopyParams.srcArray = array_1;
peerCopyParams.srcDevice = src_device;
peerCopyParams.srcPos = make_hipPos(0, 0, 0);
peerCopyParams.srcPtr = make_hipPitchedPtr(0, 0, 0, 0);
peerCopyParams.extent = extent;
HIP_CHECK(hipMemcpy3DPeer(&peerCopyParams));
// Copy data from Device Array- host ptr
std::vector<char>hostBuf(volume, 0xa);
hipMemcpy3DParms copyParms{};
copyParms.srcArray = array_2;
copyParms.dstPtr = make_hipPitchedPtr(hostBuf.data(), numW, numW, numH);
copyParms.extent = extent;
copyParms.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipMemcpy3D(&copyParms));
// Validation
for (size_t i = 0; i < volume; i++) {
INFO("Array FAILURE at Index: "<< i << "\nval : " <<hostBuf[i]);
REQUIRE(hostBuf[i] == 0xb);
}
HIP_CHECK(hipFreeArray(array_1));
HIP_CHECK(hipFreeArray(array_2));
}
/**
* Test Description
* ------------------------
* - Test case verifies the negative cases of hipMemcpy3DPeer.
* 1. Memcpy3DPeer Params struct as nullptr.
* 2. Max Destination/Source device id.
* 3. Neg Source/Destination device id
* 4. Source/Destination Array as Null.
* 5. Max value of extent
* 6. Passing width > max width size in extent
* 7. Passing height > max height size in extent
* 8. Passing depth > max depth size in extent
* Test source
* ------------------------
* - catch/unit/memory/hipMemcpy3DPeer.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 7.1
*/
HIP_TEST_CASE(Unit_hipMemcpy3DPeer_NegativeTsts) {
CHECK_IMAGE_SUPPORT
constexpr int numW = 16;
constexpr int numH = 16;
constexpr int depth = 4;
hipExtent extent = make_hipExtent(numW, numH, depth);
const auto device_count = HipTest::getDeviceCount();
const auto src_device = GENERATE_COPY(range(0, device_count));
const auto dst_device = GENERATE_COPY(range(0, device_count));
HIP_CHECK(hipSetDevice(src_device));
// Array-2 Memory allocation
hipArray_t array_1;
hipChannelFormatDesc channelDesc_1 = hipCreateChannelDesc<char>();
HIP_CHECK(hipMalloc3DArray(&array_1, &channelDesc_1, extent, 0));
// Array-2 Memory allocation
HIP_CHECK(hipSetDevice(dst_device));
hipArray_t array_2;
hipChannelFormatDesc channelDesc_2 = hipCreateChannelDesc<char>();
HIP_CHECK(hipMalloc3DArray(&array_2, &channelDesc_2, extent, 0));
hipMemcpy3DPeerParms peerCopyParams{};
peerCopyParams.dstArray = array_2;
peerCopyParams.dstPos = make_hipPos(0, 0, 0);
peerCopyParams.dstPtr = make_hipPitchedPtr(0, 0, 0, 0);
peerCopyParams.srcArray = array_1;
peerCopyParams.srcPos = make_hipPos(0, 0, 0);
peerCopyParams.srcPtr = make_hipPitchedPtr(0, 0, 0, 0);
peerCopyParams.extent = extent;
SECTION("Max Destination device id") {
peerCopyParams.dstDevice = device_count + 1;
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidDevice);
}
SECTION("Max Source device id") {
peerCopyParams.srcDevice = device_count + 1;
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidDevice);
}
SECTION("Neg Source device id") {
peerCopyParams.srcDevice = -1;
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidDevice);
}
SECTION("Neg Destination device id") {
peerCopyParams.dstDevice = -1;
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidDevice);
}
SECTION("Source Array as Null") {
peerCopyParams.srcArray = nullptr;
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidValue);
}
SECTION("Destination Array as Null") {
peerCopyParams.dstArray = nullptr;
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidValue);
}
SECTION("Passing Max value to extent") {
peerCopyParams.extent =
make_hipExtent(std::numeric_limits<int>::max(), std::numeric_limits<int>::max(),
std::numeric_limits<int>::max());
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidValue);
}
SECTION("Passing width > max width size in extent") {
peerCopyParams.extent = make_hipExtent(numW + 1, numH, depth);
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidValue);
}
SECTION("Passing height > max height size in extent") {
peerCopyParams.extent = make_hipExtent(numW, numH + 1, depth);
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidValue);
}
SECTION("Passing depth > max depth size in extent") {
peerCopyParams.extent = make_hipExtent(numW, numH, depth + 1);
HIP_CHECK_ERROR(hipMemcpy3DPeer(&peerCopyParams), hipErrorInvalidValue);
}
SECTION("Memcpy3DPeer Params struct as nullptr") {
HIP_CHECK_ERROR(hipMemcpy3D(nullptr), hipErrorInvalidValue);
}
HIP_CHECK(hipFreeArray(array_1));
HIP_CHECK(hipFreeArray(array_2));
}
/**
* End doxygen group MemoryTest.
* @}
*/