Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/memory/hipDrvMemcpy2DUnaligned.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

314 lines
9.6 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip/hip_runtime_api.h>
#include <hip_test_common.hh>
#include "memcpy2d_tests_common.hh"
/**
* @addtogroup hipDrvMemcpy2DUnaligned hipDrvMemcpy2DUnaligned
* @{
* @ingroup MemoryTest
* `hipError_t hipDrvMemcpy2DUnaligned(const hip_Memcpy2D * pCopy)` -
* Copies memory for 2D arrays.
*/
/**
* Test Description
* ------------------------
* - Negative test cases for hipDrvMemcpy2DUnaligned api
* Test source
* ------------------------
* - unit/memory/hipDrvMemcpy2DUnaligned.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.0
*/
HIP_TEST_CASE(Unit_hipDrvMemcpy2DUnaligned_NegTst) {
// declare host and device arrays
int rows, cols;
rows = GENERATE(3, 4, 100);
cols = GENERATE(3, 4, 100);
int *srcD, *srcH;
int *dstD, *dstH;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&srcD), sizeof(int) * rows * cols));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&dstD), sizeof(int) * rows * cols));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&srcH), sizeof(int) * rows * cols));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&dstH), sizeof(int) * rows * cols));
// initialise array with corresponding index values
for (int i = 0; i < rows * cols; i++) {
srcH[i] = i;
}
HIP_CHECK(hipMemcpyHtoD(srcD, srcH, sizeof(int) * rows * cols));
hip_Memcpy2D pCopy;
SECTION(
"srcY(second argument) + non-zero WidthInBytes(15th argument)\
* Height(16th argument) points to unallocated memory") {
pCopy.srcXInBytes = 0;
pCopy.srcY = rows;
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.dstXInBytes = 0;
pCopy.dstY = 0;
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.srcDevice = srcD;
pCopy.dstDevice = dstD;
pCopy.WidthInBytes = sizeof(int);
pCopy.Height = 1;
pCopy.srcPitch = cols * sizeof(int);
pCopy.dstPitch = cols * sizeof(int);
HIP_CHECK_ERROR(hipDrvMemcpy2DUnaligned(&pCopy), hipErrorInvalidValue);
}
SECTION(
"srcHost(4th argument), srcDevice(5th argument), srcArray(6th\
argument) passed nullptr") {
pCopy.srcXInBytes = 0;
pCopy.srcY = 0;
pCopy.dstXInBytes = 0;
pCopy.dstY = 0;
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.dstDevice = dstD;
pCopy.WidthInBytes = sizeof(int) * cols;
pCopy.Height = rows;
pCopy.srcPitch = cols * sizeof(int);
pCopy.dstPitch = cols * sizeof(int);
SECTION("srcHost passed nullptr") {
pCopy.srcMemoryType = hipMemoryTypeHost;
pCopy.srcHost = nullptr;
}
SECTION("srcDevice passed nullptr") {
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.srcDevice = nullptr;
}
SECTION("srcArray passed nullptr") {
pCopy.srcMemoryType = hipMemoryTypeArray;
pCopy.srcArray = nullptr;
}
HIP_CHECK_ERROR(hipDrvMemcpy2DUnaligned(&pCopy), hipErrorInvalidValue);
}
SECTION(
"dstY(second argument) + non-zero WidthInBytes(15th argument)\
* Height(16th argument) points to unallocated memory") {
pCopy.srcXInBytes = 0;
pCopy.srcY = 0;
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.dstXInBytes = 0;
pCopy.dstY = rows;
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.srcDevice = srcD;
pCopy.dstDevice = dstD;
pCopy.WidthInBytes = sizeof(int);
pCopy.Height = 1;
pCopy.srcPitch = cols * sizeof(int);
pCopy.dstPitch = cols * sizeof(int);
HIP_CHECK_ERROR(hipDrvMemcpy2DUnaligned(&pCopy), hipErrorInvalidValue);
}
SECTION(
"dstHost(4th argument), dstDevice(5th argument), dstArray(6th\
argument) passed nullptr") {
pCopy.srcXInBytes = 0;
pCopy.srcY = 0;
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.srcDevice = srcD;
pCopy.dstXInBytes = 0;
pCopy.dstY = 0;
pCopy.WidthInBytes = sizeof(int) * cols;
pCopy.Height = rows;
pCopy.srcPitch = cols * sizeof(int);
pCopy.dstPitch = cols * sizeof(int);
SECTION("dstHost passed nullptr") {
pCopy.dstMemoryType = hipMemoryTypeHost;
pCopy.dstHost = nullptr;
}
SECTION("dstDevice passed nullptr") {
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.dstDevice = nullptr;
}
SECTION("dstArray passed nullptr") {
pCopy.dstMemoryType = hipMemoryTypeArray;
pCopy.dstArray = nullptr;
}
HIP_CHECK_ERROR(hipDrvMemcpy2DUnaligned(&pCopy), hipErrorInvalidValue);
}
SECTION(
"WidthInBytes * Height greater than allocated memory(both src \
and dst)") {
pCopy.srcXInBytes = 0;
pCopy.srcY = 0;
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.dstXInBytes = 0;
pCopy.dstY = 0;
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.srcDevice = srcD;
pCopy.dstDevice = dstD;
pCopy.WidthInBytes = sizeof(int) * cols;
pCopy.Height = rows + 1;
pCopy.srcPitch = cols * sizeof(int);
pCopy.dstPitch = cols * sizeof(int);
HIP_CHECK_ERROR(hipDrvMemcpy2DUnaligned(&pCopy), hipErrorInvalidValue);
}
HIP_CHECK(hipFree(srcH));
HIP_CHECK(hipFree(srcD));
HIP_CHECK(hipFree(dstD));
HIP_CHECK(hipFree(dstH));
}
/**
* Test Description
* ------------------------
* - Functional test cases for hipDrvMemcpy2DUnaligned api
* Test source
* ------------------------
* - unit/memory/hipDrvMemcpy2DUnaligned.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.0
*/
HIP_TEST_CASE(Unit_hipDrvMemcpy2DUnaligned_FuncTst) {
SECTION(
"Different types of memory transfers functional tests to check if\
copied array contains correct values") {
// declare host and device arrays
int rows, cols;
rows = GENERATE(3, 4, 100);
cols = GENERATE(3, 4, 100);
int *srcD, *srcH;
int *dstD, *dstH;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&srcD), sizeof(int) * rows * cols));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&dstD), sizeof(int) * rows * cols));
srcH = reinterpret_cast<int*>(malloc(sizeof(int) * rows * cols));
dstH = reinterpret_cast<int*>(malloc(sizeof(int) * rows * cols));
// initialise array with corresponding index values
for (int i = 0; i < rows * cols; i++) {
srcH[i] = i;
}
hip_Memcpy2D pCopy;
pCopy.srcXInBytes = 0;
pCopy.srcY = 0;
pCopy.dstXInBytes = 0;
pCopy.dstY = 0;
pCopy.WidthInBytes = sizeof(int) * cols;
pCopy.Height = rows;
pCopy.srcPitch = cols * sizeof(int);
pCopy.dstPitch = cols * sizeof(int);
SECTION("Device to Device") {
HIP_CHECK(hipMemcpyHtoD(srcD, srcH, sizeof(int) * rows * cols));
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.srcDevice = srcD;
pCopy.dstDevice = dstD;
HIP_CHECK(hipDrvMemcpy2DUnaligned(&pCopy));
HIP_CHECK(hipMemcpyDtoH(dstH, dstD, sizeof(int) * rows * cols));
}
SECTION("Device to Host") {
HIP_CHECK(hipMemcpyHtoD(srcD, srcH, sizeof(int) * rows * cols));
pCopy.srcMemoryType = hipMemoryTypeDevice;
pCopy.dstMemoryType = hipMemoryTypeHost;
pCopy.srcDevice = srcD;
pCopy.dstHost = dstH;
HIP_CHECK(hipDrvMemcpy2DUnaligned(&pCopy));
}
SECTION("Host to Device") {
pCopy.srcMemoryType = hipMemoryTypeHost;
pCopy.dstMemoryType = hipMemoryTypeDevice;
pCopy.srcHost = srcH;
pCopy.dstDevice = dstD;
HIP_CHECK(hipDrvMemcpy2DUnaligned(&pCopy));
HIP_CHECK(hipMemcpyDtoH(dstH, dstD, sizeof(int) * rows * cols));
}
SECTION("Host to Host") {
pCopy.srcMemoryType = hipMemoryTypeHost;
pCopy.dstMemoryType = hipMemoryTypeHost;
pCopy.srcHost = srcH;
pCopy.dstHost = dstH;
HIP_CHECK(hipDrvMemcpy2DUnaligned(&pCopy));
}
for (int i = 0; i < rows * cols; i++) {
REQUIRE(dstH[i] == i);
}
HIP_CHECK(hipFree(srcD));
HIP_CHECK(hipFree(dstD));
free(srcH);
free(dstH);
}
}
/**
* Test Description
* ------------------------
* - Basic test that copies and verifies copied data
* Test source
* ------------------------
* - unit/memory/hipDrvMemcpy2DUnaligned.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.0
*/
HIP_TEST_CASE(Unit_hipDrvMemcpy2DUnaligned_Positive_Basic) {
SECTION("Device to Device") {
SECTION("Peer access enabled") {
Memcpy2DDeviceToDeviceShell<false, true, true>(DrvMemcpy2DUnalignedAdapter());
}
}
SECTION("Host to Device") {
Memcpy2DHostToDeviceShell<false, true>(DrvMemcpy2DUnalignedAdapter());
}
SECTION("Device to Host") {
Memcpy2DDeviceToHostShell<false, true>(DrvMemcpy2DUnalignedAdapter());
}
}
/**
* Test Description
* ------------------------
* - Basic test that verifies synchronization behaviour
* Test source
* ------------------------
* - unit/memory/hipDrvMemcpy2DUnaligned.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.0
*/
HIP_TEST_CASE(Unit_hipDrvMemcpy2DUnaligned_Positive_Synchronization_Behavior) {
HIP_CHECK(hipDeviceSynchronize());
SECTION("Host to Device") { Memcpy2DHtoDSyncBehavior<true>(DrvMemcpy2DUnalignedAdapter(), true); }
SECTION("Device to Pinned Host") {
Memcpy2DDtoHPinnedSyncBehavior<true>(DrvMemcpy2DUnalignedAdapter(), true);
}
SECTION("Device to Pageable Host") {
Memcpy2DDtoHPageableSyncBehavior<true>(DrvMemcpy2DUnalignedAdapter(), true);
}
}
/**
* Test Description
* ------------------------
* - Basic test that copies and verifies copied data with zero width or height.
* Test source
* ------------------------
* - unit/memory/hipDrvMemcpy2DUnaligned.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.0
*/
HIP_TEST_CASE(Unit_hipDrvMemcpy2DUnaligned_Positive_Parameters) {
Memcpy2DZeroWidthHeight<false, true>(DrvMemcpy2DUnalignedAdapter());
}