SWDEV-490555 - [catch2][dtest] Additional tests for hipMemcpyDtoA and hipMemcpy2DArrayToArray

Change-Id: Icd0e4c35cc0cf60f2e943c4f4da39de23a8c1e5b


[ROCm/hip-tests commit: 92b717da81]
This commit is contained in:
Rambabu Swargam
2024-12-09 14:57:16 +05:30
والد 8d1a7f5041
کامیت 6c7ed09ca0
2فایلهای تغییر یافته به همراه134 افزوده شده و 0 حذف شده
@@ -96,6 +96,22 @@ TEST_CASE("Unit_hipMemcpy2DArrayToArray_Negative") {
hipErrorInvalidValue);
}
SECTION("Invalid source and destination arrays") {
HIP_CHECK_ERROR(hipMemcpy2DArrayToArray(nullptr, 0, 0,
nullptr, 0, 0,
width, height,
hipMemcpyDeviceToDevice),
hipErrorInvalidResourceHandle);
}
SECTION("Invalid copy direction") {
HIP_CHECK_ERROR(hipMemcpy2DArrayToArray(d_dst_arr, 0, 0,
d_src_arr, 0, 0,
width, height,
static_cast<hipMemcpyKind>(-100)),
hipErrorInvalidMemcpyDirection);
}
HIP_CHECK(hipFreeArray(d_src_arr));
HIP_CHECK(hipFreeArray(d_dst_arr));
}
@@ -136,3 +152,65 @@ TEST_CASE("Unit_hipMemcpy2DArrayToArray_Positive") {
HIP_CHECK(hipFreeArray(d_src_arr));
HIP_CHECK(hipFreeArray(d_dst_arr));
}
/**
* Test Description
* ------------------------
* - Test case to validate basic functionality of hipMemcpy2DArrayToArray,
* Step 1 : Take two host arrays srcHost, dstHost(fill with value)
* Step 2 : Fill srcHost with valid value and dstHost with 0
* Step 3 : Take srcArray and dstArray
* Step 4 : Copy data from srcHost to srcArray
* Step 5 : Copy data from srcArray to dstArray
* Step 6 : Copy data from dstArray to dstHost
* Step 7 : Validate dstHost, it should contain valid value
* Test source
* ------------------------
* - catch/unit/memory/hipMemcpy2DArrayToArray.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_hipMemcpy2DArrayToArray_BasicPositive") {
CHECK_IMAGE_SUPPORT
const size_t width = 1024;
const size_t height = 1024;
const int N = width * height;
std::vector<char> srcHost(N), dstHost(N);
for (int i = 0; i < N; i++) {
srcHost[i] = 'A'; dstHost[i] = 'Z';
}
hipChannelFormatDesc desc = hipCreateChannelDesc<char>();
unsigned int flags = hipArrayDefault;
hipArray_t srcArray = nullptr;
HIP_CHECK(hipMallocArray(&srcArray, &desc, width, height, flags));
REQUIRE(srcArray != nullptr);
hipArray_t dstArray = nullptr;
HIP_CHECK(hipMallocArray(&dstArray, &desc, width, height, flags));
REQUIRE(dstArray != nullptr);
HIP_CHECK(hipMemcpy2DToArray(srcArray, 0, 0, srcHost.data(), width,
width, height,
hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy2DArrayToArray(dstArray, 0, 0,
srcArray, 0, 0,
width, height,
hipMemcpyDeviceToDevice));
HIP_CHECK(hipMemcpy2DFromArray(dstHost.data(), width, dstArray,
0, 0, width, height,
hipMemcpyDeviceToHost));
for (int i = 0; i < N; i++) {
REQUIRE(dstHost[i] == 'A');
}
HIP_CHECK(hipFreeArray(srcArray));
HIP_CHECK(hipFreeArray(dstArray));
}
@@ -77,3 +77,59 @@ TEST_CASE("Unit_hipMemcpyDtoA_Negative") {
HIP_CHECK(hipFreeArray(dst_array));
}
/**
* Test Description
* ------------------------
* - Test case to validate basic functionality of hipMemcpyDtoA,
* Step 1 : Take two host arrays srcHost, dstHost(fill with value)
* Step 2 : Fill srcHost with valid value and dstHost with 0
* Step 3 : Take srcDevice and copy data from srcHost to srcDevice
* Step 4 : Take the array and copy data from srcDevice to array
* Step 5 : Copy data from array to dstHost
* Step 6 : Validate dstHost, it should contain valid value
* Test source
* ------------------------
* - catch/unit/memory/hipMemcpyDtoA.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_hipMemcpyDtoA_BasicPositive") {
CHECK_IMAGE_SUPPORT
const size_t width = 1024;
const size_t height = 1;
const int size = width * height;
const int sizeBytes = size * sizeof(int);
const int value = 200;
std::vector<int> srcHost(size), dstHost(size);
for (int i = 0; i < size; i++) {
srcHost[i] = value; dstHost[i] = 0;
}
int* srcDevice = nullptr;
HIP_CHECK(hipMalloc(&srcDevice, sizeBytes));
REQUIRE(srcDevice != nullptr);
HIP_CHECK(hipMemcpy(srcDevice, srcHost.data(), sizeBytes,
hipMemcpyHostToDevice));
hipChannelFormatDesc desc = hipCreateChannelDesc<int>();
unsigned int flags = hipArrayDefault;
hipArray_t array = nullptr;
HIP_CHECK(hipMallocArray(&array, &desc, width, height, flags));
REQUIRE(array != nullptr);
HIP_CHECK(hipMemcpyDtoA(array, 0,
reinterpret_cast<hipDeviceptr_t>(srcDevice),
sizeBytes));
HIP_CHECK(hipMemcpyAtoH(dstHost.data(), array, 0, sizeBytes));
for (int i = 0; i < size; i++) {
REQUIRE(dstHost[i] == value);
}
HIP_CHECK(hipFree(srcDevice));
HIP_CHECK(hipFreeArray(array));
}