From 003707116bcabfa3cc456a4a64335b0ed69ecf37 Mon Sep 17 00:00:00 2001 From: Marko Arandjelovic Date: Wed, 14 Aug 2024 11:02:29 +0200 Subject: [PATCH] SWDEV-479213 - Add unit test for hipMemcpyHtoAAsync Change-Id: I698eb2f7b73db439c1082ef79e2e5b5462e8fd1e --- catch/unit/memory/CMakeLists.txt | 1 + catch/unit/memory/hipMemcpyHtoAAsync.cc | 83 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 catch/unit/memory/hipMemcpyHtoAAsync.cc diff --git a/catch/unit/memory/CMakeLists.txt b/catch/unit/memory/CMakeLists.txt index 1637403b0d..a963010d65 100644 --- a/catch/unit/memory/CMakeLists.txt +++ b/catch/unit/memory/CMakeLists.txt @@ -54,6 +54,7 @@ set(TEST_SRC hipMemcpyAtoHAsync.cc hipMemcpyAtoH_old.cc hipMemcpyHtoA.cc + hipMemcpyHtoAAsync.cc hipMemcpyAtoA.cc hipMemcpyHtoA_old.cc hipMemcpyAllApiNegative.cc diff --git a/catch/unit/memory/hipMemcpyHtoAAsync.cc b/catch/unit/memory/hipMemcpyHtoAAsync.cc new file mode 100644 index 0000000000..1f972c8f78 --- /dev/null +++ b/catch/unit/memory/hipMemcpyHtoAAsync.cc @@ -0,0 +1,83 @@ +/* +Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include + +#include + +#define N 32 + +TEMPLATE_TEST_CASE("Unit_hipMemcpyHtoAAsync_Basic", "", char, int, float) { + CHECK_IMAGE_SUPPORT + + hipArray_t dst_array = nullptr; + std::vector host_src(N); + std::vector host_dst(N); + size_t copy_size = N * sizeof(TestType); + size_t offset = GENERATE(0, N * sizeof(TestType) / 2); + + std::iota(host_src.begin(), host_src.end(), 0); + + auto channel_descriptor = hipCreateChannelDesc(); + HIP_CHECK(hipMallocArray(&dst_array, &channel_descriptor, copy_size)); + + HIP_CHECK(hipMemcpyHtoAAsync(dst_array, offset, host_src.data(), copy_size - offset, nullptr)); + + HIP_CHECK(hipStreamSynchronize(nullptr)); + + HIP_CHECK(hipMemcpyAtoH(host_dst.data(), dst_array, offset, copy_size - offset)); + + for (int i = 0; i < offset / sizeof(TestType); i++) { + if (host_src[i] != host_dst[i]) { + REQUIRE(false); + } + } + + HIP_CHECK(hipFreeArray(dst_array)); +} + +TEST_CASE("Unit_hipMemcpyHtoAAsync_Negative") { + CHECK_IMAGE_SUPPORT + + hipArray_t dst_array = nullptr; + std::vector host_src(N); + size_t copy_size = N * sizeof(int); + + std::iota(host_src.begin(), host_src.end(), 0); + + auto channel_descriptor = hipCreateChannelDesc(); + HIP_CHECK(hipMallocArray(&dst_array, &channel_descriptor, copy_size)); + + SECTION("dst array is null") { + HIP_CHECK_ERROR(hipMemcpyHtoAAsync(nullptr, 0, host_src.data(), copy_size, nullptr), + hipErrorInvalidValue); + } + + SECTION("src is nullptr") { + HIP_CHECK_ERROR(hipMemcpyHtoAAsync(dst_array, 0, nullptr, copy_size, nullptr), + hipErrorInvalidValue); + } + + SECTION("copy size is negative") { + HIP_CHECK_ERROR(hipMemcpyHtoAAsync(dst_array, 0, host_src.data(), -1, nullptr), + hipErrorInvalidValue); + } + + HIP_CHECK(hipFreeArray(dst_array)); +}