/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /* Testcase Scenarios : Unit_hipMemcpy2DToArray_Positive_Default - Test basic memcpy between host/device and 2D array with hipMemcpy2DToArray api Unit_hipMemcpy2DToArray_Positive_Synchronization_Behavior - Test synchronization behavior for hipMemcpy2DToArray api Unit_hipMemcpy2DToArray_Positive_ZeroWidthHeight - Test that no data is copied when width/height is set to 0 Unit_hipMemcpy2DToArray_Negative_Parameters - Test unsuccessful execution of hipMemcpy2DToArray api when parameters are invalid */ #include "array_memcpy_tests_common.hh" #include #include #include #include HIP_TEST_CASE(Unit_hipMemcpy2DToArray_Positive_Default) { CHECK_IMAGE_SUPPORT using namespace std::placeholders; const auto width = GENERATE(16, 32, 48); const auto height = GENERATE(1, 16, 32, 48); SECTION("Host to Array") { Memcpy2DHosttoAShell(std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyHostToDevice), width, height); } SECTION("Host to Array with default kind") { Memcpy2DHosttoAShell(std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyDefault), width, height); } #if HT_NVIDIA // EXSWHTEC-120 SECTION("Device to Array") { SECTION("Peer access disabled") { Memcpy2DDevicetoAShell( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyDeviceToDevice), width, height); } SECTION("Peer access enabled") { Memcpy2DDevicetoAShell( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyDeviceToDevice), width, height); } } SECTION("Device to Array with default kind") { SECTION("Peer access disabled") { Memcpy2DDevicetoAShell( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyDefault), width, height); } SECTION("Peer access enabled") { Memcpy2DDevicetoAShell( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyDefault), width, height); } } #endif } HIP_TEST_CASE(Unit_hipMemcpy2DToArray_Positive_Synchronization_Behavior) { CHECK_IMAGE_SUPPORT using namespace std::placeholders; HIP_CHECK(hipDeviceSynchronize()); SECTION("Host to Array") { const auto width = GENERATE(16, 32, 48); const auto height = GENERATE(16, 32, 48); MemcpyHtoASyncBehavior(std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, width * sizeof(int), width * sizeof(int), height, hipMemcpyHostToDevice), width, height, true); } #if HT_NVIDIA // EXSWHTEC-214 SECTION("Device to Array") { const auto width = GENERATE(16, 32, 48); const auto height = GENERATE(16, 32, 48); MemcpyDtoASyncBehavior(std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), height, hipMemcpyDeviceToDevice), width, height, false); } #endif } HIP_TEST_CASE(Unit_hipMemcpy2DToArray_Positive_ZeroWidthHeight) { CHECK_IMAGE_SUPPORT using namespace std::placeholders; const auto width = 16; const auto height = 16; SECTION("Array to host") { SECTION("Height is 0") { Memcpy2DToArrayZeroWidthHeight( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), 0, hipMemcpyHostToDevice), width, height); } SECTION("Width is 0") { Memcpy2DToArrayZeroWidthHeight( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, 0, height, hipMemcpyHostToDevice), width, height); } } SECTION("Array to device") { SECTION("Height is 0") { Memcpy2DToArrayZeroWidthHeight( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, width * sizeof(int), 0, hipMemcpyDeviceToDevice), width, height); } SECTION("Width is 0") { Memcpy2DToArrayZeroWidthHeight( std::bind(hipMemcpy2DToArray, _1, 0, 0, _2, _3, 0, height, hipMemcpyDeviceToDevice), width, height); } } } HIP_TEST_CASE(Unit_hipMemcpy2DToArray_Negative_Parameters) { CHECK_IMAGE_SUPPORT using namespace std::placeholders; const auto width = 32; const auto height = 32; const auto allocation_size = 2 * width * height * sizeof(int); const unsigned int flag = hipArrayDefault; ArrayAllocGuard array_alloc(make_hipExtent(width, height, 0), flag); LinearAllocGuard2D device_alloc(width, height); LinearAllocGuard host_alloc(LinearAllocs::hipHostMalloc, allocation_size); SECTION("Host to Array") { SECTION("dst == nullptr") { HIP_CHECK_ERROR(hipMemcpy2DToArray(nullptr, 0, 0, host_alloc.ptr(), 2 * width * sizeof(int), width * sizeof(int), height, hipMemcpyHostToDevice), hipErrorInvalidHandle); } SECTION("src == nullptr") { HIP_CHECK_ERROR(hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, nullptr, 2 * width * sizeof(int), width * sizeof(int), height, hipMemcpyHostToDevice), hipErrorInvalidValue); } #if HT_NVIDIA // EXSWHTEC-119 SECTION("spitch < width") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, host_alloc.ptr(), width * sizeof(int) - 10, width * sizeof(int), height, hipMemcpyHostToDevice), hipErrorInvalidPitchValue); } SECTION("Offset + width/height overflows") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 1, 0, host_alloc.ptr(), 2 * width * sizeof(int), width * sizeof(int), height, hipMemcpyHostToDevice), hipErrorInvalidValue); HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 1, host_alloc.ptr(), 2 * width * sizeof(int), width * sizeof(int), height, hipMemcpyHostToDevice), hipErrorInvalidValue); } SECTION("Width/height overflows") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, host_alloc.ptr(), 2 * width * sizeof(int), width * sizeof(int) + 1, height, hipMemcpyHostToDevice), hipErrorInvalidValue); HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, host_alloc.ptr(), 2 * width * sizeof(int), width * sizeof(int), height + 1, hipMemcpyHostToDevice), hipErrorInvalidValue); } SECTION("Memcpy kind is invalid") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, host_alloc.ptr(), 2 * width * sizeof(int), width * sizeof(int), height, static_cast(-1)), hipErrorInvalidMemcpyDirection); } #endif } SECTION("Device to Array") { SECTION("dst == nullptr") { HIP_CHECK_ERROR(hipMemcpy2DToArray(nullptr, 0, 0, device_alloc.ptr(), device_alloc.pitch(), width * sizeof(int), height, hipMemcpyDeviceToDevice), hipErrorInvalidHandle); } SECTION("src == nullptr") { HIP_CHECK_ERROR(hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, nullptr, device_alloc.pitch(), width * sizeof(int), height, hipMemcpyDeviceToDevice), hipErrorInvalidValue); } #if HT_NVIDIA // EXSWHTEC-119 SECTION("spitch < width") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, device_alloc.ptr(), width * sizeof(int) - 10, width * sizeof(int), height, hipMemcpyDeviceToDevice), hipErrorInvalidPitchValue); } SECTION("Offset + width/height overflows") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 1, 0, device_alloc.ptr(), device_alloc.pitch(), width * sizeof(int), height, hipMemcpyDeviceToDevice), hipErrorInvalidValue); HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 1, device_alloc.ptr(), device_alloc.pitch(), width * sizeof(int), height, hipMemcpyDeviceToDevice), hipErrorInvalidValue); } SECTION("Width/height overflows") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, device_alloc.ptr(), device_alloc.pitch(), width * sizeof(int) + 1, height, hipMemcpyDeviceToDevice), hipErrorInvalidValue); HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, device_alloc.ptr(), device_alloc.pitch(), width * sizeof(int), height + 1, hipMemcpyDeviceToDevice), hipErrorInvalidValue); } SECTION("Memcpy kind is invalid") { HIP_CHECK_ERROR( hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, device_alloc.ptr(), device_alloc.pitch(), width * sizeof(int), height, static_cast(-1)), hipErrorInvalidMemcpyDirection); } #endif } } HIP_TEST_CASE(Unit_hipMemcpy2DToArray_Capture) { CHECK_IMAGE_SUPPORT const auto width = 16; const auto height = 16; const auto size = width * height * sizeof(int); ArrayAllocGuard array_alloc(make_hipExtent(width, height, 0), hipArrayDefault); LinearAllocGuard host_alloc(LinearAllocs::hipHostMalloc, size); hipError_t memcpy_err = hipSuccess; BEGIN_CAPTURE_SYNC(memcpy_err, false); HIP_CHECK_ERROR(hipMemcpy2DToArray(array_alloc.ptr(), 0, 0, host_alloc.ptr(), width * sizeof(int), width * sizeof(int), height, hipMemcpyHostToDevice), memcpy_err); END_CAPTURE_SYNC(memcpy_err); }