EXSWHTEC-102 - Implement tests for hipMemcpyParam2D APIs #54

Change-Id: Ieac4d5000915b80f579c8e5f72d8d072bde63ab9


[ROCm/hip-tests commit: 9a3fd8ec41]
Этот коммит содержится в:
Mirza Halilčević
2023-12-28 19:33:58 +01:00
коммит произвёл Rakesh Roy
родитель 836505f7b3
Коммит 25263b8553
6 изменённых файлов: 1333 добавлений и 705 удалений
+2
Просмотреть файл
@@ -38,7 +38,9 @@ set(TEST_SRC
hipMemcpy3DAsync.cc
hipMemcpy3DAsync_old.cc
hipMemcpyParam2D.cc
hipMemcpyParam2D_old.cc
hipMemcpyParam2DAsync.cc
hipMemcpyParam2DAsync_old.cc
hipMemcpy2D.cc
hipMemcpy2D_old.cc
hipMemcpy2DAsync.cc
+160 -302
Просмотреть файл
@@ -1,337 +1,195 @@
/*
Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2022 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 WARRANNTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
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.
*/
/*
This testfile verifies the following scenarios of hipMemcpyParam2D API
1. Negative Scenarios
2. Extent Validation Scenarios
3. D2D copy for different datatypes
4. H2D and D2H copy for different datatypes
*/
#include "memcpy2d_tests_common.hh"
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip/hip_runtime_api.h>
#include <resource_guards.hh>
#include <utils.hh>
static constexpr size_t NUM_W{10};
static constexpr size_t NUM_H{10};
/*
* This testcase verifies D2D functionality of hipMemcpyParam2D API
* Input: Intializing "A_d" device variable with "C_h" host variable
* Output: "A_d" device variable to "E_d" device variable
*
* Validating the result by copying "E_d" to "A_h" and checking
* it with the initalized data "C_h".
*
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2D_multiDevice-D2D", "[hipMemcpyParam2D]", char, float, int,
double, long double) {
CHECK_IMAGE_SUPPORT
TEST_CASE("Unit_hipMemcpyParam2D_Positive_Basic") {
constexpr bool async = false;
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Initialize and Allocating Memory
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr}, *A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
SECTION("Device to Host") { Memcpy2DDeviceToHostShell<async>(MemcpyParam2DAdapter<async>()); }
#endif
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
HIP_CHECK(hipSetDevice(1));
char *E_d;
size_t pitch_E;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_d),
&pitch_E, width, NUM_H));
// Initalizing A_d with C_h
HIP_CHECK(hipMemcpy2D(A_d, pitch_A, C_h, width,
NUM_W * sizeof(TestType), NUM_H, hipMemcpyHostToDevice));
// Device to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = E_d;
desc.dstDevice = hipDeviceptr_t(E_d);
desc.dstPitch = pitch_E;
desc.WidthInBytes = NUM_W * sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
// Copying E_d to A_h
HIP_CHECK(hipMemcpy2D(A_h, width, E_d, pitch_E,
NUM_W * sizeof(TestType), NUM_H,
hipMemcpyDeviceToHost));
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
SECTION("Device to Device") {
SECTION("Peer access disabled") {
Memcpy2DDeviceToDeviceShell<async, false>(MemcpyParam2DAdapter<async>());
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies H2D & D2H functionality of hipMemcpyParam2D API
* H2D case:
* Input: "C_h" host variable initialized with default data
* Output: "A_d" device variable
*
* D2H case:
* Input: "A_d" device variable from the previous output
* OutPut: "A_h" variable
*
* Validating the result by comparing "A_h" to "C_h"
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2D_multiDevice-H2D-D2H", "[hipMemcpyParam2D]", char, float,
int, double, long double) {
CHECK_IMAGE_SUPPORT
// 1 refers to pinned host memory and 0 refers
// to unpinned memory
auto memory_type = GENERATE(0, 1);
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
HIP_CHECK(hipSetDevice(0));
// Initialize and Allocating Memory
TestType* A_h{nullptr}, *C_h{nullptr},
*A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
// Based on memory type (pinned/unpinned) allocating memory
if (memory_type) {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, true);
} else {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
SECTION("Peer access enabled") {
Memcpy2DDeviceToDeviceShell<async, true>(MemcpyParam2DAdapter<async>());
}
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
// Host to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = C_h;
desc.srcDevice = hipDeviceptr_t(C_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(A_d);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
}
// Device to Host
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
SECTION("Host to Device") { Memcpy2DHostToDeviceShell<async>(MemcpyParam2DAdapter<async>()); }
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
SECTION("Host to Host") { Memcpy2DHostToHostShell<async>(MemcpyParam2DAdapter<async>()); }
#endif
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
if (memory_type) {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, true);
} else {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
TEST_CASE("Unit_hipMemcpyParam2D_Positive_Synchronization_Behavior") {
HIP_CHECK(hipDeviceSynchronize());
SECTION("Host to Device") { Memcpy2DHtoDSyncBehavior(MemcpyParam2DAdapter<>(), true); }
SECTION("Device to Pageable Host") {
Memcpy2DDtoHPageableSyncBehavior(MemcpyParam2DAdapter<>(), true);
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
SECTION("Device to Pinned Host") {
Memcpy2DDtoHPinnedSyncBehavior(MemcpyParam2DAdapter<>(), true);
}
#endif
SECTION("Device to Device") {
#if HT_NVIDIA
Memcpy2DDtoDSyncBehavior(MemcpyParam2DAdapter<>(), false);
#else
Memcpy2DDtoDSyncBehavior(MemcpyParam2DAdapter<>(), true);
#endif
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-232
SECTION("Host to Host") { Memcpy2DHtoHSyncBehavior(MemcpyParam2DAdapter<>(), true); }
#endif
}
TEST_CASE("Unit_hipMemcpyParam2D_Positive_Parameters") {
constexpr bool async = false;
Memcpy2DZeroWidthHeight<async>(MemcpyParam2DAdapter<async>());
}
TEST_CASE("Unit_hipMemcpyParam2D_Positive_Array") {
constexpr bool async = false;
SECTION("Array from/to Host") {
MemcpyParam2DArrayHostShell<async>(MemcpyParam2DAdapter<async>());
}
SECTION("Array from/to Device") {
MemcpyParam2DArrayDeviceShell<async>(MemcpyParam2DAdapter<async>());
}
}
TEST_CASE("Unit_hipMemcpyParam2D_Negative_Parameters") {
constexpr size_t cols = 128;
constexpr size_t rows = 128;
constexpr auto NegativeTests = [](void* dst, size_t dpitch, void* src, size_t spitch,
size_t width, size_t height, hipMemcpyKind kind) {
SECTION("dst == nullptr") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>()(static_cast<void*>(nullptr), dpitch, src, spitch,
width, height, kind),
hipErrorInvalidValue);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies the extent validation scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2D_ExtentValidation") {
CHECK_IMAGE_SUPPORT
// Allocating memory and Initializing the data
HIP_CHECK(hipSetDevice(0));
char* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(char)};
constexpr auto memsetval{100};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&B_h, nullptr, nullptr,
width*NUM_H, false);
HipTest::setDefaultData<char>(NUM_W*NUM_H, A_h, nullptr, C_h);
HipTest::setDefaultData<char>(NUM_W*NUM_H, B_h, nullptr, nullptr);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
SECTION("src == nullptr") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>()(dst, dpitch, static_cast<void*>(nullptr), spitch,
width, height, kind),
hipErrorInvalidValue);
}
// Device to Host
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("dstPitch < WithInBytes") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>()(dst, width - 1, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
SECTION("Destination Pitch is 0") {
desc.dstPitch = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
SECTION("srcPitch < WidthInBytes") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>()(dst, dpitch, src, width - 1, width, height, kind),
hipErrorInvalidValue);
}
SECTION("dstPitch > max pitch") {
int attr = 0;
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>()(dst, static_cast<size_t>(attr) + 1, src, spitch,
width, height, kind),
hipErrorInvalidValue);
}
SECTION("srcPitch > max pitch") {
int attr = 0;
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>()(dst, dpitch, src, static_cast<size_t>(attr) + 1,
width, height, kind),
hipErrorInvalidValue);
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-237
SECTION("WidthInBytes + srcXInBytes > srcPitch") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>(make_hipExtent(spitch - width + 1, 0, 0))(
dst, dpitch, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
SECTION("WidthInBytes + dstXInBytes > dstPitch") {
HIP_CHECK_ERROR(
MemcpyParam2DAdapter<>(make_hipExtent(0, 0, 0), make_hipExtent(dpitch - width + 1, 0, 0))(
dst, dpitch, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
SECTION("srcY out of bounds") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>(make_hipExtent(0, 1, 0))(dst, dpitch, src, spitch,
width, height, kind),
hipErrorInvalidValue);
}
SECTION("dstY out of bounds") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<>(make_hipExtent(0, 0, 0), make_hipExtent(0, 1, 0))(
dst, dpitch, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
#endif
};
SECTION("Host to Device") {
LinearAllocGuard2D<int> device_alloc(cols, rows);
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, device_alloc.pitch() * rows);
NegativeTests(device_alloc.ptr(), device_alloc.pitch(), host_alloc.ptr(), device_alloc.pitch(),
device_alloc.width(), device_alloc.height(), hipMemcpyHostToDevice);
}
SECTION("Source Pitch is 0") {
desc.srcPitch = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
SECTION("Device to Host") {
LinearAllocGuard2D<int> device_alloc(cols, rows);
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, device_alloc.pitch() * rows);
NegativeTests(host_alloc.ptr(), device_alloc.pitch(), device_alloc.ptr(), device_alloc.pitch(),
device_alloc.width(), device_alloc.height(), hipMemcpyDeviceToHost);
}
SECTION("Height is 0") {
desc.Height = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
SECTION("Host to Host") {
LinearAllocGuard<int> src_alloc(LinearAllocs::hipHostMalloc, cols * rows * sizeof(int));
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipHostMalloc, cols * rows * sizeof(int));
NegativeTests(dst_alloc.ptr(), cols * sizeof(int), src_alloc.ptr(), cols * sizeof(int),
cols * sizeof(int), rows, hipMemcpyHostToHost);
}
SECTION("Width is 0") {
desc.WidthInBytes = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
SECTION("Device to Device") {
LinearAllocGuard2D<int> src_alloc(cols, rows);
LinearAllocGuard2D<int> dst_alloc(cols, rows);
NegativeTests(dst_alloc.ptr(), dst_alloc.pitch(), src_alloc.ptr(), src_alloc.pitch(),
dst_alloc.width(), dst_alloc.height(), hipMemcpyDeviceToDevice);
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
HipTest::freeArrays<char>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
/*
* This testcase verifies the negative scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2D_Negative") {
CHECK_IMAGE_SUPPORT
HIP_CHECK(hipSetDevice(0));
// Allocating and Initializing the data
float* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(float)};
constexpr auto memsetval{100};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<float>(nullptr, nullptr, nullptr,
&A_h, &B_h, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<float>(NUM_W*NUM_H, A_h, B_h, C_h);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Null Pointer to Source Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
SECTION("Null Pointer to Destination Device Pointer") {
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = A_h;
desc.srcDevice = hipDeviceptr_t(A_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(nullptr);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
SECTION("Null Pointer to both Src & Dst Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
desc.dstDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
SECTION("Width > src/dest pitches") {
desc.WidthInBytes = pitch_A+1;
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
HipTest::freeArrays<float>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
}
+182 -403
Просмотреть файл
@@ -1,441 +1,220 @@
/*
Copyright (c) 2022 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 WARRANNTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
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.
*/
/*
This testfile verifies the following scenarios of hipMemcpyParam2DAsync API
1. Negative Scenarios
2. Extent Validation Scenarios
3. D2D copy for different datatypes
4. H2D and D2H copy for different datatypes
5. Device context change scenario where memory allocated in one GPU
stream created in another GPU
*/
#include "memcpy2d_tests_common.hh"
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip/hip_runtime_api.h>
#include <resource_guards.hh>
#include <utils.hh>
static constexpr size_t NUM_W{10};
static constexpr size_t NUM_H{10};
/*
* This testcase verifies D2D functionality of hipMemcpyParam2DAsync API
* Where Memory is allocated in GPU-0 and stream is created in GPU-1
*
* Input: Intializing "A_d" device variable with "C_h" host variable
* Output: "A_d" device variable to "E_d" device variable
*
* Validating the result by copying "E_d" to "A_h" and checking
* it with the initalized data "C_h".
*
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2DAsync_multiDevice-StreamOnDiffDevice",
"[hipMemcpyParam2DAsync]", char, float, int, double, long double) {
CHECK_IMAGE_SUPPORT
TEST_CASE("Unit_hipMemcpyParam2DAsync_Positive_Basic") {
using namespace std::placeholders;
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Allocating and Initializing the data
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr}, *A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
TestType *E_d{nullptr};
size_t pitch_E;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_d),
&pitch_E, width, NUM_H));
constexpr bool async = true;
// Initalizing A_d with C_h
HIP_CHECK(hipSetDevice(1));
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
const auto stream_type = GENERATE(Streams::nullstream, Streams::perThread, Streams::created);
const StreamGuard stream_guard(stream_type);
const hipStream_t stream = stream_guard.stream();
HIP_CHECK(hipMemcpy2DAsync(A_d, pitch_A, C_h, width,
NUM_W*sizeof(TestType), NUM_H,
hipMemcpyHostToDevice, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Device to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = E_d;
desc.dstDevice = hipDeviceptr_t(E_d);
desc.dstPitch = pitch_E;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Copying the result E_d to A_h host variable
HIP_CHECK(hipMemcpy2D(A_h, width, E_d, pitch_E,
NUM_W*sizeof(TestType), NUM_H,
hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(E_d));
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
SECTION("Device to Host") {
Memcpy2DDeviceToHostShell<async>(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, stream), stream);
}
#endif
SECTION("Device to Device") {
SECTION("Peer access disabled") {
Memcpy2DDeviceToDeviceShell<async, false>(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, stream), stream);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies D2D functionality of hipMemcpyParam2DAsync API
* Input: Intializing "A_d" device variable with "C_h" host variable
* Output: "A_d" device variable to "E_d" device variable
*
* Validating the result by copying "E_d" to "A_h" and checking
* it with the initalized data "C_h".
*
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2DAsync_multiDevice-D2D", "[hipMemcpyParam2DAsync]", char,
int, float, double, long double) {
CHECK_IMAGE_SUPPORT
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Allocating and Initializing the data
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr}, *A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
HIP_CHECK(hipSetDevice(1));
TestType *E_d;
size_t pitch_E;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_d),
&pitch_E, width, NUM_H));
// Initializing A_d with C_h
HIP_CHECK(hipMemcpy2D(A_d, pitch_A, C_h, width,
NUM_W*sizeof(TestType), NUM_H, hipMemcpyHostToDevice));
// Device to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = E_d;
desc.dstDevice = hipDeviceptr_t(E_d);
desc.dstPitch = pitch_E;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Copying the result E_d to A_h host variable
HIP_CHECK(hipMemcpy2D(A_h, width, E_d, pitch_E,
NUM_W*sizeof(TestType), NUM_H, hipMemcpyDeviceToHost));
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
SECTION("Peer access enabled") {
Memcpy2DDeviceToDeviceShell<async, true>(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, stream), stream);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
SECTION("Host to Device") {
Memcpy2DHostToDeviceShell<async>(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, stream), stream);
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
SECTION("Host to Host") {
Memcpy2DHostToHostShell<async>(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, stream), stream);
}
#endif
}
TEST_CASE("Unit_hipMemcpyParam2DAsync_Positive_Synchronization_Behavior") {
using namespace std::placeholders;
constexpr bool async = true;
HIP_CHECK(hipDeviceSynchronize());
SECTION("Host to Device") {
Memcpy2DHtoDSyncBehavior(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, nullptr), false);
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-233
SECTION("Device to Pageable Host") {
Memcpy2DDtoHPageableSyncBehavior(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, nullptr), true);
}
#endif
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
SECTION("Device to Pinned Host") {
Memcpy2DDtoHPinnedSyncBehavior(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, nullptr), false);
}
#endif
SECTION("Device to Device") {
Memcpy2DDtoDSyncBehavior(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, nullptr), false);
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-233
SECTION("Host to Host") {
Memcpy2DHtoHSyncBehavior(
std::bind(MemcpyParam2DAdapter<async>(), _1, _2, _3, _4, _5, _6, _7, nullptr), true);
}
#endif
}
TEST_CASE("Unit_hipMemcpyParam2DAsync_Positive_Parameters") {
constexpr bool async = true;
Memcpy2DZeroWidthHeight<async>(MemcpyParam2DAdapter<async>());
}
TEST_CASE("Unit_hipMemcpyParam2DAsync_Positive_Array") {
constexpr bool async = true;
SECTION("Array from/to Host") {
MemcpyParam2DArrayHostShell<async>(MemcpyParam2DAdapter<async>());
}
SECTION("Array from/to Device") {
MemcpyParam2DArrayDeviceShell<async>(MemcpyParam2DAdapter<async>());
}
}
/*
* This testcase verifies H2D & D2H functionality of hipMemcpyParam2DAsync API
* H2D case:
* Input: "C_h" host variable initialized with default data
* Output: "A_d" device variable
*
* D2H case:
* Input: "A_d" device variable from the previous output
* OutPut: "A_h" variable
*
* Validating the result by comparing "A_h" to "C_h"
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2DAsync_multiDevice-H2D-D2H", "[hipMemcpyParam2DAsync]",
char, int, float, double, long double) {
CHECK_IMAGE_SUPPORT
TEST_CASE("Unit_hipMemcpyParam2DAsync_Negative_Parameters") {
constexpr bool async = true;
// 1 refers to pinned host memory and 0 refers
// to unpinned memory
auto memory_type = GENERATE(0, 1);
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Allocating and Initializing the data
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr},
*A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
hipStream_t stream;
constexpr size_t cols = 128;
constexpr size_t rows = 128;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
// Based on memory type (pinned/unpinned) allocating memory
if (memory_type) {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, true);
} else {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
constexpr auto NegativeTests = [](void* dst, size_t dpitch, void* src, size_t spitch,
size_t width, size_t height, hipMemcpyKind kind) {
SECTION("dst == nullptr") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>()(static_cast<void*>(nullptr), dpitch, src,
spitch, width, height, kind),
hipErrorInvalidValue);
}
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
// Host to Device
hip_Memcpy2D desc = {};
HIP_CHECK(hipStreamCreate(&stream));
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = C_h;
desc.srcDevice = hipDeviceptr_t(C_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(A_d);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Device to Host
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
if (memory_type) {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, true);
} else {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
SECTION("src == nullptr") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>()(dst, dpitch, static_cast<void*>(nullptr),
spitch, width, height, kind),
hipErrorInvalidValue);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies the extent validation scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2DAsync_ExtentValidation") {
CHECK_IMAGE_SUPPORT
SECTION("dstPitch < WidthInBytes") {
HIP_CHECK_ERROR(
MemcpyParam2DAdapter<async>()(dst, width - 1, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
SECTION("srcPitch < WidthInBytes") {
HIP_CHECK_ERROR(
MemcpyParam2DAdapter<async>()(dst, dpitch, src, width - 1, width, height, kind),
hipErrorInvalidValue);
}
SECTION("dpitch > max pitch") {
int attr = 0;
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>()(dst, static_cast<size_t>(attr) + 1, src, spitch,
width, height, kind),
hipErrorInvalidValue);
}
SECTION("spitch > max pitch") {
int attr = 0;
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>()(dst, dpitch, src, static_cast<size_t>(attr) + 1,
width, height, kind),
hipErrorInvalidValue);
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-237
SECTION("WidthInBytes + srcXInBytes > srcPitch") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>(make_hipExtent(spitch - width + 1, 0, 0))(
dst, dpitch, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
SECTION("WidthInBytes + dstXInBytes > dstPitch") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>(make_hipExtent(0, 0, 0),
make_hipExtent(dpitch - width + 1, 0, 0))(
dst, dpitch, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
SECTION("srcY out of bounds") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>(make_hipExtent(0, 1, 0))(dst, dpitch, src, spitch,
width, height, kind),
hipErrorInvalidValue);
}
SECTION("dstY out of bounds") {
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>(make_hipExtent(0, 0, 0), make_hipExtent(0, 1, 0))(
dst, dpitch, src, spitch, width, height, kind),
hipErrorInvalidValue);
}
#endif
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-235
SECTION("Invalid stream") {
StreamGuard stream_guard(Streams::created);
HIP_CHECK(hipStreamDestroy(stream_guard.stream()));
HIP_CHECK_ERROR(MemcpyParam2DAdapter<async>()(dst, dpitch, src, spitch, width, height, kind,
stream_guard.stream()),
hipErrorContextIsDestroyed);
}
#endif
};
HIP_CHECK(hipSetDevice(0));
char* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(char)};
constexpr auto memsetval{100};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
// Allocating and Initializing the data
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&B_h, nullptr, nullptr,
width*NUM_H, false);
HipTest::setDefaultData<char>(NUM_W*NUM_H, A_h, nullptr, C_h);
HipTest::setDefaultData<char>(NUM_W*NUM_H, B_h, nullptr, nullptr);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
// Device to Host
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Destination Pitch is 0") {
desc.dstPitch = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
SECTION("Host to device") {
LinearAllocGuard2D<int> device_alloc(cols, rows);
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, device_alloc.pitch() * rows);
NegativeTests(device_alloc.ptr(), device_alloc.pitch(), host_alloc.ptr(), device_alloc.pitch(),
device_alloc.width(), device_alloc.height(), hipMemcpyHostToDevice);
}
SECTION("Source Pitch is 0") {
desc.srcPitch = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
SECTION("Device to host") {
LinearAllocGuard2D<int> device_alloc(cols, rows);
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, device_alloc.pitch() * rows);
NegativeTests(host_alloc.ptr(), device_alloc.pitch(), device_alloc.ptr(), device_alloc.pitch(),
device_alloc.width(), device_alloc.height(), hipMemcpyDeviceToHost);
}
SECTION("Height is 0") {
desc.Height = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
SECTION("Host to host") {
LinearAllocGuard<int> src_alloc(LinearAllocs::hipHostMalloc, cols * rows * sizeof(int));
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipHostMalloc, cols * rows * sizeof(int));
NegativeTests(dst_alloc.ptr(), cols * sizeof(int), src_alloc.ptr(), cols * sizeof(int),
cols * sizeof(int), rows, hipMemcpyHostToHost);
}
SECTION("Width is 0") {
desc.Height = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
SECTION("Device to device") {
LinearAllocGuard2D<int> src_alloc(cols, rows);
LinearAllocGuard2D<int> dst_alloc(cols, rows);
NegativeTests(dst_alloc.ptr(), dst_alloc.pitch(), src_alloc.ptr(), src_alloc.pitch(),
dst_alloc.width(), dst_alloc.height(), hipMemcpyDeviceToDevice);
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<char>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
/*
* This testcase verifies the negative scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2DAsync_Negative") {
CHECK_IMAGE_SUPPORT
HIP_CHECK(hipSetDevice(0));
float* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(float)};
constexpr auto memsetval{100};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
// Allocating and Initializing the data
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<float>(nullptr, nullptr, nullptr,
&A_h, &B_h, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<float>(NUM_W*NUM_H, A_h, B_h, C_h);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
// Device to Host
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Null Pointer to Source Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
SECTION("Null Pointer to Destination Device Pointer") {
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = A_h;
desc.srcDevice = hipDeviceptr_t(A_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(nullptr);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
SECTION("Null Pointer to both Src & Dst Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
desc.dstDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
SECTION("Width > src/dest pitches") {
desc.WidthInBytes = pitch_A+1;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<float>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
}
+441
Просмотреть файл
@@ -0,0 +1,441 @@
/*
Copyright (c) 2022 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 WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS 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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
This testfile verifies the following scenarios of hipMemcpyParam2DAsync API
1. Negative Scenarios
2. Extent Validation Scenarios
3. D2D copy for different datatypes
4. H2D and D2H copy for different datatypes
5. Device context change scenario where memory allocated in one GPU
stream created in another GPU
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
static constexpr size_t NUM_W{10};
static constexpr size_t NUM_H{10};
/*
* This testcase verifies D2D functionality of hipMemcpyParam2DAsync API
* Where Memory is allocated in GPU-0 and stream is created in GPU-1
*
* Input: Intializing "A_d" device variable with "C_h" host variable
* Output: "A_d" device variable to "E_d" device variable
*
* Validating the result by copying "E_d" to "A_h" and checking
* it with the initalized data "C_h".
*
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2DAsync_multiDevice-StreamOnDiffDevice",
"[hipMemcpyParam2DAsync]", char, float, int, double, long double) {
CHECK_IMAGE_SUPPORT
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Allocating and Initializing the data
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr}, *A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
TestType *E_d{nullptr};
size_t pitch_E;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_d),
&pitch_E, width, NUM_H));
// Initalizing A_d with C_h
HIP_CHECK(hipSetDevice(1));
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipMemcpy2DAsync(A_d, pitch_A, C_h, width,
NUM_W*sizeof(TestType), NUM_H,
hipMemcpyHostToDevice, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Device to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = E_d;
desc.dstDevice = hipDeviceptr_t(E_d);
desc.dstPitch = pitch_E;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Copying the result E_d to A_h host variable
HIP_CHECK(hipMemcpy2D(A_h, width, E_d, pitch_E,
NUM_W*sizeof(TestType), NUM_H,
hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(E_d));
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies D2D functionality of hipMemcpyParam2DAsync API
* Input: Intializing "A_d" device variable with "C_h" host variable
* Output: "A_d" device variable to "E_d" device variable
*
* Validating the result by copying "E_d" to "A_h" and checking
* it with the initalized data "C_h".
*
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2DAsync_multiDevice-D2D", "[hipMemcpyParam2DAsync]", char,
int, float, double, long double) {
CHECK_IMAGE_SUPPORT
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Allocating and Initializing the data
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr}, *A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
HIP_CHECK(hipSetDevice(1));
TestType *E_d;
size_t pitch_E;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_d),
&pitch_E, width, NUM_H));
// Initializing A_d with C_h
HIP_CHECK(hipMemcpy2D(A_d, pitch_A, C_h, width,
NUM_W*sizeof(TestType), NUM_H, hipMemcpyHostToDevice));
// Device to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = E_d;
desc.dstDevice = hipDeviceptr_t(E_d);
desc.dstPitch = pitch_E;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Copying the result E_d to A_h host variable
HIP_CHECK(hipMemcpy2D(A_h, width, E_d, pitch_E,
NUM_W*sizeof(TestType), NUM_H, hipMemcpyDeviceToHost));
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies H2D & D2H functionality of hipMemcpyParam2DAsync API
* H2D case:
* Input: "C_h" host variable initialized with default data
* Output: "A_d" device variable
*
* D2H case:
* Input: "A_d" device variable from the previous output
* OutPut: "A_h" variable
*
* Validating the result by comparing "A_h" to "C_h"
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2DAsync_multiDevice-H2D-D2H", "[hipMemcpyParam2DAsync]",
char, int, float, double, long double) {
CHECK_IMAGE_SUPPORT
// 1 refers to pinned host memory and 0 refers
// to unpinned memory
auto memory_type = GENERATE(0, 1);
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Allocating and Initializing the data
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr},
*A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
hipStream_t stream;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
// Based on memory type (pinned/unpinned) allocating memory
if (memory_type) {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, true);
} else {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
}
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
// Host to Device
hip_Memcpy2D desc = {};
HIP_CHECK(hipStreamCreate(&stream));
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = C_h;
desc.srcDevice = hipDeviceptr_t(C_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(A_d);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Device to Host
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
if (memory_type) {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, true);
} else {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies the extent validation scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2DAsync_ExtentValidation") {
CHECK_IMAGE_SUPPORT
HIP_CHECK(hipSetDevice(0));
char* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(char)};
constexpr auto memsetval{100};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
// Allocating and Initializing the data
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&B_h, nullptr, nullptr,
width*NUM_H, false);
HipTest::setDefaultData<char>(NUM_W*NUM_H, A_h, nullptr, C_h);
HipTest::setDefaultData<char>(NUM_W*NUM_H, B_h, nullptr, nullptr);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
// Device to Host
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Destination Pitch is 0") {
desc.dstPitch = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
}
SECTION("Source Pitch is 0") {
desc.srcPitch = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
}
SECTION("Height is 0") {
desc.Height = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
}
SECTION("Width is 0") {
desc.Height = 0;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) == hipSuccess);
HIP_CHECK(hipStreamSynchronize(stream));
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<char>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
/*
* This testcase verifies the negative scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2DAsync_Negative") {
CHECK_IMAGE_SUPPORT
HIP_CHECK(hipSetDevice(0));
float* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(float)};
constexpr auto memsetval{100};
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
// Allocating and Initializing the data
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<float>(nullptr, nullptr, nullptr,
&A_h, &B_h, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<float>(NUM_W*NUM_H, A_h, B_h, C_h);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
// Device to Host
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Null Pointer to Source Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
SECTION("Null Pointer to Destination Device Pointer") {
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = A_h;
desc.srcDevice = hipDeviceptr_t(A_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(nullptr);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
SECTION("Null Pointer to both Src & Dst Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
desc.dstDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
SECTION("Width > src/dest pitches") {
desc.WidthInBytes = pitch_A+1;
REQUIRE(hipMemcpyParam2DAsync(&desc, stream) != hipSuccess);
}
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipStreamDestroy(stream));
HipTest::freeArrays<float>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
+337
Просмотреть файл
@@ -0,0 +1,337 @@
/*
Copyright (c) 2021 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 WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS 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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
This testfile verifies the following scenarios of hipMemcpyParam2D API
1. Negative Scenarios
2. Extent Validation Scenarios
3. D2D copy for different datatypes
4. H2D and D2H copy for different datatypes
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
static constexpr size_t NUM_W{10};
static constexpr size_t NUM_H{10};
/*
* This testcase verifies D2D functionality of hipMemcpyParam2D API
* Input: Intializing "A_d" device variable with "C_h" host variable
* Output: "A_d" device variable to "E_d" device variable
*
* Validating the result by copying "E_d" to "A_h" and checking
* it with the initalized data "C_h".
*
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2D_multiDevice-D2D", "[hipMemcpyParam2D]", char, float, int,
double, long double) {
CHECK_IMAGE_SUPPORT
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
// Initialize and Allocating Memory
HIP_CHECK(hipSetDevice(0));
TestType* A_h{nullptr}, *C_h{nullptr}, *A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
HIP_CHECK(hipSetDevice(1));
char *E_d;
size_t pitch_E;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_d),
&pitch_E, width, NUM_H));
// Initalizing A_d with C_h
HIP_CHECK(hipMemcpy2D(A_d, pitch_A, C_h, width,
NUM_W * sizeof(TestType), NUM_H, hipMemcpyHostToDevice));
// Device to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = E_d;
desc.dstDevice = hipDeviceptr_t(E_d);
desc.dstPitch = pitch_E;
desc.WidthInBytes = NUM_W * sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
// Copying E_d to A_h
HIP_CHECK(hipMemcpy2D(A_h, width, E_d, pitch_E,
NUM_W * sizeof(TestType), NUM_H,
hipMemcpyDeviceToHost));
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the memory
HIP_CHECK(hipFree(A_d));
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies H2D & D2H functionality of hipMemcpyParam2D API
* H2D case:
* Input: "C_h" host variable initialized with default data
* Output: "A_d" device variable
*
* D2H case:
* Input: "A_d" device variable from the previous output
* OutPut: "A_h" variable
*
* Validating the result by comparing "A_h" to "C_h"
*/
TEMPLATE_TEST_CASE("Unit_hipMemcpyParam2D_multiDevice-H2D-D2H", "[hipMemcpyParam2D]", char, float,
int, double, long double) {
CHECK_IMAGE_SUPPORT
// 1 refers to pinned host memory and 0 refers
// to unpinned memory
auto memory_type = GENERATE(0, 1);
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices > 1) {
HIP_CHECK(hipSetDevice(0));
// Initialize and Allocating Memory
TestType* A_h{nullptr}, *C_h{nullptr},
*A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(TestType)};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
// Based on memory type (pinned/unpinned) allocating memory
if (memory_type) {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, true);
} else {
HipTest::initArrays<TestType>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
}
HipTest::setDefaultData<TestType>(NUM_W*NUM_H, A_h, nullptr, C_h);
int peerAccess = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
if (!peerAccess) {
SUCCEED("Skipped the test as there is no peer access");
} else {
// Host to Device
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = C_h;
desc.srcDevice = hipDeviceptr_t(C_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(A_d);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
// Device to Host
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W*sizeof(TestType);
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
// Validating the result
REQUIRE(HipTest::checkArray<TestType>(A_h, C_h, NUM_W, NUM_H) == true);
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
if (memory_type) {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, true);
} else {
HipTest::freeArrays<TestType>(nullptr, nullptr, nullptr,
A_h, nullptr, C_h, false);
}
}
} else {
SUCCEED("skipping the testcases as numDevices < 2");
}
}
/*
* This testcase verifies the extent validation scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2D_ExtentValidation") {
CHECK_IMAGE_SUPPORT
// Allocating memory and Initializing the data
HIP_CHECK(hipSetDevice(0));
char* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(char)};
constexpr auto memsetval{100};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&A_h, nullptr, &C_h,
width*NUM_H, false);
HipTest::initArrays<char>(nullptr, nullptr, nullptr,
&B_h, nullptr, nullptr,
width*NUM_H, false);
HipTest::setDefaultData<char>(NUM_W*NUM_H, A_h, nullptr, C_h);
HipTest::setDefaultData<char>(NUM_W*NUM_H, B_h, nullptr, nullptr);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
// Device to Host
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Destination Pitch is 0") {
desc.dstPitch = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
}
SECTION("Source Pitch is 0") {
desc.srcPitch = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
}
SECTION("Height is 0") {
desc.Height = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
}
SECTION("Width is 0") {
desc.WidthInBytes = 0;
REQUIRE(hipMemcpyParam2D(&desc) == hipSuccess);
REQUIRE(HipTest::checkArray<char>(A_h, B_h, NUM_W, NUM_H) == true);
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
HipTest::freeArrays<char>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
/*
* This testcase verifies the negative scenarios
*/
TEST_CASE("Unit_hipMemcpyParam2D_Negative") {
CHECK_IMAGE_SUPPORT
HIP_CHECK(hipSetDevice(0));
// Allocating and Initializing the data
float* A_h{nullptr}, *B_h{nullptr}, *C_h{nullptr},
* A_d{nullptr};
size_t pitch_A;
size_t width{NUM_W * sizeof(float)};
constexpr auto memsetval{100};
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, NUM_H));
HipTest::initArrays<float>(nullptr, nullptr, nullptr,
&A_h, &B_h, &C_h,
width*NUM_H, false);
HipTest::setDefaultData<float>(NUM_W*NUM_H, A_h, B_h, C_h);
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, NUM_W, NUM_H));
hip_Memcpy2D desc = {};
desc.srcMemoryType = hipMemoryTypeDevice;
desc.srcHost = A_d;
desc.srcDevice = hipDeviceptr_t(A_d);
desc.srcPitch = pitch_A;
desc.dstMemoryType = hipMemoryTypeHost;
desc.dstHost = A_h;
desc.dstDevice = hipDeviceptr_t(A_h);
desc.dstPitch = width;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
SECTION("Null Pointer to Source Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
SECTION("Null Pointer to Destination Device Pointer") {
memset(&desc, 0x0, sizeof(hip_Memcpy2D));
desc.srcMemoryType = hipMemoryTypeHost;
desc.srcHost = A_h;
desc.srcDevice = hipDeviceptr_t(A_h);
desc.srcPitch = width;
desc.dstMemoryType = hipMemoryTypeDevice;
desc.dstHost = A_d;
desc.dstDevice = hipDeviceptr_t(nullptr);
desc.dstPitch = pitch_A;
desc.WidthInBytes = NUM_W;
desc.Height = NUM_H;
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
SECTION("Null Pointer to both Src & Dst Device Pointer") {
desc.srcDevice = hipDeviceptr_t(nullptr);
desc.dstDevice = hipDeviceptr_t(nullptr);
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
SECTION("Width > src/dest pitches") {
desc.WidthInBytes = pitch_A+1;
REQUIRE(hipMemcpyParam2D(&desc) != hipSuccess);
}
// DeAllocating the Memory
HIP_CHECK(hipFree(A_d));
HipTest::freeArrays<float>(nullptr, nullptr, nullptr,
A_h, B_h, C_h, false);
}
+211
Просмотреть файл
@@ -22,10 +22,13 @@ THE SOFTWARE.
#pragma once
#include <variant>
#include <hip_test_common.hh>
#include <hip/hip_runtime_api.h>
#include <utils.hh>
#include <resource_guards.hh>
#include <hip/driver_types.h>
template <bool should_synchronize, typename F>
void Memcpy2DDeviceToHostShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
@@ -322,4 +325,212 @@ void Memcpy2DZeroWidthHeight(F memcpy_func, const hipStream_t stream = nullptr)
}
ArrayFindIfNot(dst_alloc.ptr(), static_cast<uint8_t>(42), alloc_size);
}
}
constexpr auto MemTypeHost() {
#if HT_AMD
return hipMemoryTypeHost;
#else
return CU_MEMORYTYPE_HOST;
#endif
}
constexpr auto MemTypeDevice() {
#if HT_AMD
return hipMemoryTypeDevice;
#else
return CU_MEMORYTYPE_DEVICE;
#endif
}
constexpr auto MemTypeArray() {
#if HT_AMD
return hipMemoryTypeArray;
#else
return CU_MEMORYTYPE_ARRAY;
#endif
}
constexpr auto MemTypeUnified() {
#if HT_AMD
return hipMemoryTypeUnified;
#else
return CU_MEMORYTYPE_UNIFIED;
#endif
}
using PtrVariant = std::variant<void*, hipArray_t>;
template <bool async = false>
constexpr auto MemcpyParam2DAdapter(const hipExtent src_offset = {0, 0, 0},
const hipExtent dst_offset = {0, 0, 0}) {
return [=](PtrVariant dst, size_t dpitch, PtrVariant src, size_t spitch, size_t width,
size_t height, hipMemcpyKind kind, hipStream_t stream = nullptr) {
hip_Memcpy2D parms = {};
if (std::holds_alternative<hipArray_t>(dst)) {
parms.dstMemoryType = MemTypeArray();
parms.dstArray = std::get<hipArray_t>(dst);
} else {
parms.dstPitch = dpitch;
auto ptr = std::get<void*>(dst);
switch (kind) {
case hipMemcpyDeviceToHost:
case hipMemcpyHostToHost:
parms.dstMemoryType = MemTypeHost();
parms.dstHost = ptr;
break;
case hipMemcpyDeviceToDevice:
case hipMemcpyHostToDevice:
parms.dstMemoryType = MemTypeDevice();
parms.dstDevice = reinterpret_cast<hipDeviceptr_t>(ptr);
break;
case hipMemcpyDefault:
parms.dstMemoryType = MemTypeUnified();
parms.dstDevice = reinterpret_cast<hipDeviceptr_t>(ptr);
break;
default:
assert(false);
}
}
if (std::holds_alternative<hipArray_t>(src)) {
parms.srcMemoryType = MemTypeArray();
parms.srcArray = std::get<hipArray_t>(src);
} else {
parms.srcPitch = spitch;
auto ptr = std::get<void*>(src);
switch (kind) {
case hipMemcpyDeviceToHost:
case hipMemcpyDeviceToDevice:
parms.srcMemoryType = MemTypeDevice();
parms.srcDevice = reinterpret_cast<hipDeviceptr_t>(ptr);
break;
case hipMemcpyHostToDevice:
case hipMemcpyHostToHost:
parms.srcMemoryType = MemTypeHost();
parms.srcHost = ptr;
break;
case hipMemcpyDefault:
parms.srcMemoryType = MemTypeUnified();
parms.srcDevice = reinterpret_cast<hipDeviceptr_t>(ptr);
break;
default:
assert(false);
}
}
parms.WidthInBytes = width;
parms.Height = height;
parms.srcXInBytes = src_offset.width;
parms.srcY = src_offset.height;
parms.dstXInBytes = dst_offset.width;
parms.dstY = dst_offset.height;
if constexpr (async) {
return hipMemcpyParam2DAsync(&parms, stream);
} else {
return hipMemcpyParam2D(&parms);
}
};
}
template <bool should_synchronize, typename F>
void MemcpyParam2DArrayHostShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
constexpr hipExtent extent{127 * sizeof(int), 128, 1};
LinearAllocGuard<int> src_host(LinearAllocs::hipHostMalloc,
extent.width * extent.height * extent.depth);
LinearAllocGuard<int> dst_host(LinearAllocs::hipHostMalloc,
extent.width * extent.height * extent.depth);
DrvArrayAllocGuard<int> src_array(extent);
DrvArrayAllocGuard<int> dst_array(extent);
const auto f = [](size_t x, size_t y, size_t z) {
constexpr auto width_logical = extent.width / sizeof(int);
return z * width_logical * extent.height + y * width_logical + x;
};
PitchedMemorySet(src_host.ptr(), extent.width, extent.width / sizeof(int), extent.height,
extent.depth, f);
// Host -> Array
HIP_CHECK(memcpy_func(src_array.ptr(), 0, src_host.ptr(), extent.width, extent.width,
extent.height, hipMemcpyHostToDevice, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
// Array -> Array
HIP_CHECK(memcpy_func(dst_array.ptr(), 0, src_array.ptr(), 0, extent.width, extent.height,
hipMemcpyDeviceToDevice, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
// Array -> Host
HIP_CHECK(memcpy_func(dst_host.ptr(), extent.width, dst_array.ptr(), 0, extent.width,
extent.height, hipMemcpyDeviceToHost, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
PitchedMemoryVerify(dst_host.ptr(), extent.width, extent.width / sizeof(int), extent.height,
extent.depth, f);
}
template <bool should_synchronize, typename F>
void MemcpyParam2DArrayDeviceShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
constexpr hipExtent extent{127 * sizeof(int), 128, 1};
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc,
extent.width * extent.height * extent.depth);
DrvArrayAllocGuard<int> src_array(extent);
DrvArrayAllocGuard<int> dst_array(extent);
LinearAllocGuard3D<int> src_device(extent);
LinearAllocGuard3D<int> dst_device(extent);
const dim3 threads_per_block(32, 32);
const dim3 blocks(src_device.width_logical() / threads_per_block.x + 1,
src_device.height() / threads_per_block.y + 1, src_device.depth());
Iota<<<blocks, threads_per_block>>>(src_device.ptr(), src_device.pitch(),
src_device.width_logical(), src_device.height(),
src_device.depth());
HIP_CHECK(hipGetLastError());
// Device -> Array
HIP_CHECK(memcpy_func(src_array.ptr(), 0, src_device.ptr(), src_device.pitch(), extent.width,
extent.height, hipMemcpyDeviceToDevice, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
// Array -> Array
HIP_CHECK(memcpy_func(dst_array.ptr(), 0, src_array.ptr(), 0, extent.width, extent.height,
hipMemcpyDeviceToDevice, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
// Array -> Device
HIP_CHECK(memcpy_func(dst_device.ptr(), dst_device.pitch(), dst_array.ptr(), 0, extent.width,
extent.height, hipMemcpyDeviceToDevice, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
HIP_CHECK(memcpy_func(host_alloc.ptr(), extent.width, dst_device.ptr(), dst_device.pitch(),
extent.width, extent.height, hipMemcpyDeviceToHost, kernel_stream));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}
const auto f = [](size_t x, size_t y, size_t z) {
constexpr auto width_logical = extent.width / sizeof(int);
return z * width_logical * extent.height + y * width_logical + x;
};
PitchedMemoryVerify(host_alloc.ptr(), extent.width, extent.width / sizeof(int), extent.height,
extent.depth, f);
}