EXSWHTEC-103 - Implement tests for hipDrvMemcpy3D APIs (#56)
- Implement basic behavior checks in all copy directions
- Implement synchronization behavior checks for expected behavior based on cuda docs
- Implement positive tests for zero sized width and/or height copies, where no copy is expected to happen
- Implement negative parameter tests
- Implement all of the above for hipDrvMemcpy3D and hipDrvMemcpy3DAsync.
- Disable failing tests on AMD.
- Fix copyright disclaimer.
- Add defect issue numbers.
[ROCm/hip-tests commit: c695f1b146]
Esse commit está contido em:
@@ -23,6 +23,9 @@
|
||||
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ClonedGrph",
|
||||
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ChldNode",
|
||||
"Unit_hipMemGetAddressRange_Negative",
|
||||
"NOTE: The following 2 tests are disabled due to defect - EXSWHTEC-238",
|
||||
"Unit_hipDrvMemcpy3D_Positive_Array",
|
||||
"Unit_hipDrvMemcpy3DAsync_Positive_Array",
|
||||
"Unit_hipMemRangeGetAttribute_Positive_AccessedBy_Basic",
|
||||
"Unit_hipMemRangeGetAttribute_Positive_AccessedBy_Partial_Range",
|
||||
"Unit_hipMemRangeGetAttributes_Negative_Parameters",
|
||||
|
||||
@@ -109,6 +109,9 @@
|
||||
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ClonedGrph",
|
||||
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ChldNode",
|
||||
"Unit_hipMemGetAddressRange_Negative",
|
||||
"NOTE: The following 2 tests are disabled due to defect - EXSWHTEC-238",
|
||||
"Unit_hipDrvMemcpy3D_Positive_Array",
|
||||
"Unit_hipDrvMemcpy3DAsync_Positive_Array",
|
||||
"Unit_hipMemGetAddressRange_Positive",
|
||||
"Note: devicelib hangs and failures",
|
||||
"Unit_deviceAllocation_Malloc_PerThread_PrimitiveDataType",
|
||||
|
||||
@@ -582,4 +582,219 @@ void Memcpy3DZeroWidthHeightDepth(F memcpy_func, const hipStream_t stream = null
|
||||
}
|
||||
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 DrvPtrVariant = std::variant<hipPitchedPtr, hiparray>;
|
||||
|
||||
template <bool async = false>
|
||||
hipError_t DrvMemcpy3DWrapper(DrvPtrVariant dst_ptr, hipPos dst_pos, DrvPtrVariant src_ptr,
|
||||
hipPos src_pos, hipExtent extent, hipMemcpyKind kind,
|
||||
hipStream_t stream = nullptr) {
|
||||
HIP_MEMCPY3D parms = {0};
|
||||
|
||||
if (std::holds_alternative<hiparray>(dst_ptr)) {
|
||||
parms.dstMemoryType = MemTypeArray();
|
||||
parms.dstArray = std::get<hiparray>(dst_ptr);
|
||||
} else {
|
||||
auto ptr = std::get<hipPitchedPtr>(dst_ptr);
|
||||
parms.dstPitch = ptr.pitch;
|
||||
switch (kind) {
|
||||
case hipMemcpyDeviceToHost:
|
||||
case hipMemcpyHostToHost:
|
||||
parms.dstMemoryType = MemTypeHost();
|
||||
parms.dstHost = ptr.ptr;
|
||||
break;
|
||||
case hipMemcpyDeviceToDevice:
|
||||
case hipMemcpyHostToDevice:
|
||||
parms.dstMemoryType = MemTypeDevice();
|
||||
parms.dstDevice = reinterpret_cast<hipDeviceptr_t>(ptr.ptr);
|
||||
break;
|
||||
case hipMemcpyDefault:
|
||||
parms.dstMemoryType = MemTypeUnified();
|
||||
parms.dstDevice = reinterpret_cast<hipDeviceptr_t>(ptr.ptr);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (std::holds_alternative<hiparray>(src_ptr)) {
|
||||
parms.srcMemoryType = MemTypeArray();
|
||||
parms.srcArray = std::get<hiparray>(src_ptr);
|
||||
} else {
|
||||
auto ptr = std::get<hipPitchedPtr>(src_ptr);
|
||||
parms.srcPitch = ptr.pitch;
|
||||
switch (kind) {
|
||||
case hipMemcpyDeviceToHost:
|
||||
case hipMemcpyDeviceToDevice:
|
||||
parms.srcMemoryType = MemTypeDevice();
|
||||
parms.srcDevice = reinterpret_cast<hipDeviceptr_t>(ptr.ptr);
|
||||
break;
|
||||
case hipMemcpyHostToDevice:
|
||||
case hipMemcpyHostToHost:
|
||||
parms.srcMemoryType = MemTypeHost();
|
||||
parms.srcHost = ptr.ptr;
|
||||
break;
|
||||
case hipMemcpyDefault:
|
||||
parms.srcMemoryType = MemTypeUnified();
|
||||
parms.srcDevice = reinterpret_cast<hipDeviceptr_t>(ptr.ptr);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
parms.WidthInBytes = extent.width;
|
||||
parms.Height = extent.height;
|
||||
parms.Depth = extent.depth;
|
||||
parms.srcXInBytes = src_pos.x;
|
||||
parms.srcY = src_pos.y;
|
||||
parms.srcZ = src_pos.z;
|
||||
parms.dstXInBytes = dst_pos.x;
|
||||
parms.dstY = dst_pos.y;
|
||||
parms.dstZ = dst_pos.z;
|
||||
|
||||
if constexpr (async) {
|
||||
return hipDrvMemcpy3DAsync(&parms, stream);
|
||||
} else {
|
||||
return hipDrvMemcpy3D(&parms);
|
||||
}
|
||||
}
|
||||
|
||||
template <bool should_synchronize, typename F>
|
||||
void DrvMemcpy3DArrayHostShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
|
||||
constexpr hipExtent extent{127 * sizeof(int), 128, 8};
|
||||
|
||||
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 = [extent](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(), make_hipPos(0, 0, 0),
|
||||
make_hipPitchedPtr(src_host.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyHostToDevice, kernel_stream));
|
||||
if constexpr (should_synchronize) {
|
||||
HIP_CHECK(hipStreamSynchronize(kernel_stream));
|
||||
}
|
||||
|
||||
// Array -> Array
|
||||
HIP_CHECK(memcpy_func(dst_array.ptr(), make_hipPos(0, 0, 0), src_array.ptr(),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice, kernel_stream));
|
||||
if constexpr (should_synchronize) {
|
||||
HIP_CHECK(hipStreamSynchronize(kernel_stream));
|
||||
}
|
||||
|
||||
// Array -> Host
|
||||
HIP_CHECK(
|
||||
memcpy_func(make_hipPitchedPtr(dst_host.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0), dst_array.ptr(), make_hipPos(0, 0, 0), extent,
|
||||
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 DrvMemcpy3DArrayDeviceShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
|
||||
constexpr hipExtent extent{127 * sizeof(int), 128, 8};
|
||||
|
||||
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(), make_hipPos(0, 0, 0), src_device.pitched_ptr(),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice, kernel_stream));
|
||||
if constexpr (should_synchronize) {
|
||||
HIP_CHECK(hipStreamSynchronize(kernel_stream));
|
||||
}
|
||||
|
||||
// Array -> Array
|
||||
HIP_CHECK(memcpy_func(dst_array.ptr(), make_hipPos(0, 0, 0), src_array.ptr(),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice, kernel_stream));
|
||||
if constexpr (should_synchronize) {
|
||||
HIP_CHECK(hipStreamSynchronize(kernel_stream));
|
||||
}
|
||||
|
||||
// Array -> Device
|
||||
HIP_CHECK(memcpy_func(dst_device.pitched_ptr(), make_hipPos(0, 0, 0), dst_array.ptr(),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice, kernel_stream));
|
||||
if constexpr (should_synchronize) {
|
||||
HIP_CHECK(hipStreamSynchronize(kernel_stream));
|
||||
}
|
||||
|
||||
HIP_CHECK(
|
||||
memcpy_func(make_hipPitchedPtr(host_alloc.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0), dst_device.pitched_ptr(), make_hipPos(0, 0, 0),
|
||||
dst_device.extent(), hipMemcpyDeviceToHost, kernel_stream));
|
||||
if constexpr (should_synchronize) {
|
||||
HIP_CHECK(hipStreamSynchronize(kernel_stream));
|
||||
}
|
||||
|
||||
const auto f = [extent](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);
|
||||
}
|
||||
@@ -92,7 +92,9 @@ set(TEST_SRC
|
||||
hipArrayCreate.cc
|
||||
hipArray3DCreate.cc
|
||||
hipDrvMemcpy3D.cc
|
||||
hipDrvMemcpy3D_old.cc
|
||||
hipDrvMemcpy3DAsync.cc
|
||||
hipDrvMemcpy3DAsync_old.cc
|
||||
hipPointerGetAttribute.cc
|
||||
hipDrvPtrGetAttributes.cc
|
||||
hipMemPrefetchAsync.cc
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
/*
|
||||
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 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
|
||||
@@ -16,558 +19,209 @@ 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.
|
||||
*/
|
||||
/*
|
||||
* Test Scenarios
|
||||
* 1. Verifying hipDrvMemcpy3D API for H2A,A2A,A2H scenarios
|
||||
* 2. Verifying hipDrvMemcpy3D API for H2D,D2D,D2H scenarios
|
||||
* 3. Verifying Negative Scenarios
|
||||
* 4. Verifying Extent validation scenarios by passing 0
|
||||
* 5. Verifying hipDrvMemcpy3D API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3D from peer GPU for
|
||||
* H2D,D2D,D2H scenarios
|
||||
* 6. Verifying hipDrvMemcpy3D API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3D from peer GPU for
|
||||
* H2A,A2A,A2H scenarios
|
||||
*
|
||||
* Scenarios 3 is temporarily suspended on AMD
|
||||
* Scenario 5&6 are not supported in CUDA platform
|
||||
*/
|
||||
|
||||
#include "hip_test_common.hh"
|
||||
#include "hip_test_checkers.hh"
|
||||
#include <memcpy1d_tests_common.hh>
|
||||
#include <memcpy3d_tests_common.hh>
|
||||
|
||||
template<typename T>
|
||||
class DrvMemcpy3D {
|
||||
int width, height, depth;
|
||||
unsigned int size;
|
||||
hipArray_Format formatKind;
|
||||
hiparray arr, arr1;
|
||||
size_t pitch_D, pitch_E;
|
||||
HIP_MEMCPY3D myparms;
|
||||
hipDeviceptr_t D_m, E_m;
|
||||
T* hData{nullptr};
|
||||
public:
|
||||
DrvMemcpy3D(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format);
|
||||
DrvMemcpy3D() = delete;
|
||||
void AllocateMemory();
|
||||
void SetDefaultData();
|
||||
void HostArray_DrvMemcpy3D(bool device_context_change = false);
|
||||
void HostDevice_DrvMemcpy3D(bool device_context_change = false);
|
||||
void Extent_Validation();
|
||||
void NegativeTests();
|
||||
void DeAllocateMemory();
|
||||
};
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <resource_guards.hh>
|
||||
#include <utils.hh>
|
||||
|
||||
/* Intializes class variables */
|
||||
template <typename T>
|
||||
DrvMemcpy3D<T>::DrvMemcpy3D(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format) {
|
||||
width = l_width;
|
||||
height = l_height;
|
||||
depth = l_depth;
|
||||
formatKind = l_format;
|
||||
}
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Positive_Basic") {
|
||||
constexpr bool async = false;
|
||||
|
||||
/* Allocating Memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::AllocateMemory() {
|
||||
size = width * height * depth * sizeof(T);
|
||||
hData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hData, 0, size);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int k = 0; k < width; k++) {
|
||||
hData[i*width*height + j*width +k] = i*width*height + j*width + k;
|
||||
}
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
|
||||
SECTION("Device to Host") { Memcpy3DDeviceToHostShell<async>(DrvMemcpy3DWrapper<>); }
|
||||
#endif
|
||||
|
||||
SECTION("Device to Device") {
|
||||
SECTION("Peer access disabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, false>(DrvMemcpy3DWrapper<>);
|
||||
}
|
||||
SECTION("Peer access enabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, true>(DrvMemcpy3DWrapper<>);
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&D_m),
|
||||
&pitch_D, width*sizeof(T), height));
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_m),
|
||||
&pitch_E, width*sizeof(T), height));
|
||||
HIP_ARRAY3D_DESCRIPTOR *desc;
|
||||
desc = reinterpret_cast<HIP_ARRAY3D_DESCRIPTOR*>
|
||||
(malloc(sizeof(HIP_ARRAY3D_DESCRIPTOR)));
|
||||
desc->Format = formatKind;
|
||||
desc->NumChannels = 1;
|
||||
desc->Width = width;
|
||||
desc->Height = height;
|
||||
desc->Depth = depth;
|
||||
desc->Flags = hipArrayDefault;
|
||||
HIP_CHECK(hipArray3DCreate(&arr, desc));
|
||||
HIP_CHECK(hipArray3DCreate(&arr1, desc));
|
||||
|
||||
SECTION("Host to Device") { Memcpy3DHostToDeviceShell<async>(DrvMemcpy3DWrapper<>); }
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
|
||||
SECTION("Host to Host") { Memcpy3DHostToHostShell<async>(DrvMemcpy3DWrapper<>); }
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Setting the default data */
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::SetDefaultData() {
|
||||
memset(&myparms, 0x0, sizeof(HIP_MEMCPY3D));
|
||||
myparms.srcXInBytes = 0;
|
||||
myparms.srcY = 0;
|
||||
myparms.srcZ = 0;
|
||||
myparms.srcLOD = 0;
|
||||
myparms.dstXInBytes = 0;
|
||||
myparms.dstY = 0;
|
||||
myparms.dstZ = 0;
|
||||
myparms.dstLOD = 0;
|
||||
myparms.WidthInBytes = width*sizeof(T);
|
||||
myparms.Height = height;
|
||||
myparms.Depth = depth;
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Positive_Synchronization_Behavior") {
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
|
||||
SECTION("Host to Device") { Memcpy3DHtoDSyncBehavior(DrvMemcpy3DWrapper<>, true); }
|
||||
|
||||
SECTION("Device to Pageable Host") {
|
||||
Memcpy3DDtoHPageableSyncBehavior(DrvMemcpy3DWrapper<>, true);
|
||||
}
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
|
||||
SECTION("Device to Pinned Host") { Memcpy3DDtoHPinnedSyncBehavior(DrvMemcpy3DWrapper<>, true); }
|
||||
#endif
|
||||
|
||||
SECTION("Device to Device") {
|
||||
#if HT_NVIDIA
|
||||
Memcpy3DDtoDSyncBehavior(DrvMemcpy3DWrapper<>, false);
|
||||
#else
|
||||
Memcpy3DDtoDSyncBehavior(DrvMemcpy3DWrapper<>, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-232
|
||||
SECTION("Host to Host") { Memcpy3DHtoHSyncBehavior(DrvMemcpy3DWrapper<>, true); }
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
This function verifies the negative scenarios of
|
||||
hipDrvMemcpy3D API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::NegativeTests() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
AllocateMemory();
|
||||
SetDefaultData();
|
||||
int deviceId;
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
unsigned int MaxPitch;
|
||||
HIP_CHECK(hipDeviceGetAttribute(reinterpret_cast<int *>(&MaxPitch),
|
||||
hipDeviceAttributeMaxPitch, deviceId));
|
||||
myparms.srcHost = hData;
|
||||
myparms.dstArray = arr;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
|
||||
SECTION("Passing nullptr to Source Host") {
|
||||
myparms.srcHost = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing both dst host and device") {
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.WidthInBytes = pitch_D;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing max value to WidthInBytes") {
|
||||
myparms.WidthInBytes = std::numeric_limits<int>::max();
|
||||
myparms.Height = std::numeric_limits<int>::max();
|
||||
myparms.Depth = std::numeric_limits<int>::max();
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing width > max width size") {
|
||||
myparms.WidthInBytes = width*sizeof(T) + 1;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing height > max height size") {
|
||||
myparms.Height = height + 1;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing depth > max depth size") {
|
||||
myparms.Depth = depth + 1;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + srcXinBytes is out of bound") {
|
||||
myparms.srcXInBytes = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + dstXinBytes is out of bound") {
|
||||
myparms.dstXInBytes = pitch_D;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("srcY + height is out of bound") {
|
||||
myparms.srcY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dstY + height out of bounds") {
|
||||
myparms.dstY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("src pitch greater than Max allowed pitch") {
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = D_m;
|
||||
myparms.srcHost = nullptr;
|
||||
myparms.srcPitch = MaxPitch;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = width*sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dst pitch greater than Max allowed pitch") {
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = MaxPitch+1;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst device") {
|
||||
myparms.dstDevice = hipDeviceptr_t(nullptr);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst array") {
|
||||
myparms.dstArray = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to hipDrvMemcpy3D") {
|
||||
REQUIRE(hipDrvMemcpy3D(nullptr) != hipSuccess);
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Positive_Parameters") {
|
||||
constexpr bool async = false;
|
||||
Memcpy3DZeroWidthHeightDepth<async>(DrvMemcpy3DWrapper<async>);
|
||||
}
|
||||
/*
|
||||
This function verifies the Extent validation scenarios of
|
||||
hipDrvMemcpy3D API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::Extent_Validation() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
// Allocating the memory
|
||||
AllocateMemory();
|
||||
|
||||
// Setting default data
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
|
||||
SECTION("WidthInBytes is 0") {
|
||||
myparms.WidthInBytes = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
}
|
||||
|
||||
SECTION("Height is 0") {
|
||||
myparms.Height = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
}
|
||||
|
||||
SECTION("Depth is 0") {
|
||||
myparms.Depth = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
// Disabled on AMD due to defect - EXSWHTEC-238
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Positive_Array") {
|
||||
constexpr bool async = false;
|
||||
SECTION("Array from/to Host") { DrvMemcpy3DArrayHostShell<async>(DrvMemcpy3DWrapper<async>); }
|
||||
SECTION("Array from/to Device") { DrvMemcpy3DArrayDeviceShell<async>(DrvMemcpy3DWrapper<async>); }
|
||||
}
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3D API
|
||||
1. Host to Device copy
|
||||
2. Device to Device
|
||||
3. Device to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3D API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::HostDevice_DrvMemcpy3D(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Negative_Parameters") {
|
||||
constexpr hipExtent extent{128 * sizeof(int), 128, 8};
|
||||
|
||||
constexpr auto NegativeTests = [](hipPitchedPtr dst_ptr, hipPos dst_pos, hipPitchedPtr src_ptr,
|
||||
hipPos src_pos, hipExtent extent, hipMemcpyKind kind) {
|
||||
SECTION("dst_ptr.ptr == nullptr") {
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.ptr = nullptr;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
|
||||
// Device to Device
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(D_m);
|
||||
myparms.srcPitch = pitch_D;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(E_m);
|
||||
myparms.dstPitch = pitch_E;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
|
||||
// Device to host
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(E_m);
|
||||
myparms.srcPitch = pitch_E;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3D API
|
||||
1. Host to Array copy
|
||||
2. Array to Array
|
||||
3. Array to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3D API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::HostArray_DrvMemcpy3D(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
SECTION("src_ptr.ptr == nullptr") {
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.ptr = nullptr;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstArray = arr;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
// Array to Array
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcArray = arr;
|
||||
myparms.dstArray = arr1;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
SetDefaultData();
|
||||
// Device to host
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcArray = arr1;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
/* DeAllocating the memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::DeAllocateMemory() {
|
||||
HIP_CHECK(hipArrayDestroy(arr));
|
||||
HIP_CHECK(hipArrayDestroy(arr1));
|
||||
free(hData);
|
||||
}
|
||||
|
||||
/* Verifying hipDrvMemcpy3D API Host to Array for different datatypes */
|
||||
TEMPLATE_TEST_CASE("Unit_hipDrvMemcpy3D_MultipleDataTypes", "",
|
||||
uint8_t, int, float) {
|
||||
for (int i = 1; i < 25; i++) {
|
||||
if (std::is_same<TestType, float>::value) {
|
||||
DrvMemcpy3D<TestType> memcpy3d_float(i, i, i, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_float.HostArray_DrvMemcpy3D();
|
||||
} else if (std::is_same<TestType, uint8_t>::value) {
|
||||
DrvMemcpy3D<TestType> memcpy3d_intx(i, i, i, HIP_AD_FORMAT_UNSIGNED_INT8);
|
||||
memcpy3d_intx.HostArray_DrvMemcpy3D();
|
||||
} else if (std::is_same<TestType, int>::value) {
|
||||
DrvMemcpy3D<TestType> memcpy3d_inty(i, i, i, HIP_AD_FORMAT_SIGNED_INT32);
|
||||
memcpy3d_inty.HostArray_DrvMemcpy3D();
|
||||
SECTION("dst_ptr.pitch < width") {
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.pitch = extent.width - 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This testcase verifies H2D copy of hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_HosttoDevice") {
|
||||
DrvMemcpy3D<float> memcpy3d_D2H_float(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_D2H_float.HostDevice_DrvMemcpy3D();
|
||||
}
|
||||
SECTION("src_ptr.pitch < width") {
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.pitch = extent.width - 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
/* This testcase verifies negative scenarios of hipDrvMemcpy3D API */
|
||||
#if HT_NVIDIA
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Negative") {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.NegativeTests();
|
||||
}
|
||||
SECTION("dst_ptr.pitch > max pitch") {
|
||||
int attr = 0;
|
||||
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.pitch = attr;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_ptr.pitch > max pitch") {
|
||||
int attr = 0;
|
||||
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.pitch = attr;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-237
|
||||
SECTION("extent.width + dst_pos.x > dst_ptr.pitch") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.x = dst_ptr.pitch - extent.width + 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("extent.width + src_pos.x > src_ptr.pitch") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.x = src_ptr.pitch - extent.width + 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_pos.y out of bounds") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.y = 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_pos.y out of bounds") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.y = 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_pos.z out of bounds") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.z = 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_pos.z out of bounds") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.z = 1;
|
||||
HIP_CHECK_ERROR(DrvMemcpy3DWrapper(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This testcase verifies extent validation scenarios of hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_ExtentValidation") {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.Extent_Validation();
|
||||
}
|
||||
|
||||
#if HT_AMD
|
||||
/* This testcase verifies H2D copy in device context
|
||||
change scenario for hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_H2DDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostDevice_DrvMemcpy3D(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
SECTION("Host to Device") {
|
||||
LinearAllocGuard3D<int> device_alloc(extent);
|
||||
LinearAllocGuard<int> host_alloc(
|
||||
LinearAllocs::hipHostMalloc,
|
||||
device_alloc.pitch() * device_alloc.height() * device_alloc.depth());
|
||||
NegativeTests(device_alloc.pitched_ptr(), make_hipPos(0, 0, 0),
|
||||
make_hipPitchedPtr(host_alloc.ptr(), device_alloc.pitch(), device_alloc.width(),
|
||||
device_alloc.height()),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyHostToDevice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* This testcase verifies Host to Array copy in device context
|
||||
change scenario for hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Host2ArrayDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostArray_DrvMemcpy3D(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
SECTION("Device to Host") {
|
||||
LinearAllocGuard3D<int> device_alloc(extent);
|
||||
LinearAllocGuard<int> host_alloc(
|
||||
LinearAllocs::hipHostMalloc,
|
||||
device_alloc.pitch() * device_alloc.height() * device_alloc.depth());
|
||||
NegativeTests(make_hipPitchedPtr(host_alloc.ptr(), device_alloc.pitch(), device_alloc.width(),
|
||||
device_alloc.height()),
|
||||
make_hipPos(0, 0, 0), device_alloc.pitched_ptr(), make_hipPos(0, 0, 0), extent,
|
||||
hipMemcpyDeviceToHost);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("Host to Host") {
|
||||
LinearAllocGuard<int> src_alloc(LinearAllocs::hipHostMalloc,
|
||||
extent.width * extent.height * extent.depth);
|
||||
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipHostMalloc,
|
||||
extent.width * extent.height * extent.depth);
|
||||
NegativeTests(make_hipPitchedPtr(dst_alloc.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0),
|
||||
make_hipPitchedPtr(src_alloc.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyHostToHost);
|
||||
}
|
||||
|
||||
SECTION("Device to Device") {
|
||||
LinearAllocGuard3D<int> src_alloc(extent);
|
||||
LinearAllocGuard3D<int> dst_alloc(extent);
|
||||
NegativeTests(dst_alloc.pitched_ptr(), make_hipPos(0, 0, 0), src_alloc.pitched_ptr(),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
/*
|
||||
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 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
|
||||
@@ -16,579 +19,236 @@ 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.
|
||||
*/
|
||||
/*
|
||||
* Test Scenarios
|
||||
* 1. Verifying hipDrvMemcpy3DAsync API for H2A,A2A,A2H scenarios
|
||||
* 2. Verifying hipDrvMemcpy3DAsync API for H2D,D2D,D2H scenarios
|
||||
* 3. Verifying Negative Scenarios
|
||||
* 4. Verifying Extent validation scenarios by passing 0
|
||||
* 5. Verifying hipDrvMemcpy3DAsync API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3DAsync from peer GPU for
|
||||
* H2D,D2D,D2H scenarios
|
||||
* 6. Verifying hipDrvMemcpy3DAsync API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3DAsync from peer GPU for
|
||||
* H2A,A2A,A2H scenarios
|
||||
*
|
||||
* Scenarios 3 is temporarily excluded in AMD platform
|
||||
* Scenario 5&6 are excluded in CUDA platform
|
||||
*/
|
||||
|
||||
#include "hip_test_common.hh"
|
||||
#include "hip_test_checkers.hh"
|
||||
#include <memcpy1d_tests_common.hh>
|
||||
#include <memcpy3d_tests_common.hh>
|
||||
|
||||
template<typename T>
|
||||
class DrvMemcpy3DAsync {
|
||||
int width, height, depth;
|
||||
unsigned int size;
|
||||
hipArray_Format formatKind;
|
||||
hiparray arr, arr1;
|
||||
hipStream_t stream;
|
||||
size_t pitch_D, pitch_E;
|
||||
HIP_MEMCPY3D myparms;
|
||||
hipDeviceptr_t D_m, E_m;
|
||||
T* hData{nullptr};
|
||||
public:
|
||||
DrvMemcpy3DAsync(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format);
|
||||
DrvMemcpy3DAsync() = delete;
|
||||
void AllocateMemory();
|
||||
void SetDefaultData();
|
||||
void HostArray_DrvMemcpy3DAsync(bool device_context_change = false);
|
||||
void HostDevice_DrvMemcpy3DAsync(bool device_context_change = false);
|
||||
void Extent_Validation();
|
||||
void NegativeTests();
|
||||
void DeAllocateMemory();
|
||||
};
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <resource_guards.hh>
|
||||
#include <utils.hh>
|
||||
|
||||
/* Intializes class variables */
|
||||
template <typename T>
|
||||
DrvMemcpy3DAsync<T>::DrvMemcpy3DAsync(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format) {
|
||||
width = l_width;
|
||||
height = l_height;
|
||||
depth = l_depth;
|
||||
formatKind = l_format;
|
||||
}
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Positive_Basic") {
|
||||
constexpr bool async = true;
|
||||
|
||||
/* Allocating Memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::AllocateMemory() {
|
||||
size = width * height * depth * sizeof(T);
|
||||
hData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hData, 0, size);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int k = 0; k < width; k++) {
|
||||
hData[i*width*height + j*width +k] = i*width*height + j*width + k;
|
||||
}
|
||||
const auto stream_type = GENERATE(Streams::nullstream, Streams::perThread, Streams::created);
|
||||
const StreamGuard stream_guard(stream_type);
|
||||
const hipStream_t stream = stream_guard.stream();
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
|
||||
SECTION("Device to Host") { Memcpy3DDeviceToHostShell<async>(DrvMemcpy3DWrapper<async>, stream); }
|
||||
#endif
|
||||
|
||||
SECTION("Device to Device") {
|
||||
SECTION("Peer access disabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, false>(DrvMemcpy3DWrapper<async>, stream);
|
||||
}
|
||||
SECTION("Peer access enabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, true>(DrvMemcpy3DWrapper<async>, stream);
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&D_m),
|
||||
&pitch_D, width*sizeof(T), height));
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_m),
|
||||
&pitch_E, width*sizeof(T), height));
|
||||
HIP_ARRAY3D_DESCRIPTOR *desc;
|
||||
desc = reinterpret_cast<HIP_ARRAY3D_DESCRIPTOR*>
|
||||
(malloc(sizeof(HIP_ARRAY3D_DESCRIPTOR)));
|
||||
desc->Format = formatKind;
|
||||
desc->NumChannels = 1;
|
||||
desc->Width = width;
|
||||
desc->Height = height;
|
||||
desc->Depth = depth;
|
||||
desc->Flags = hipArrayDefault;
|
||||
HIP_CHECK(hipArray3DCreate(&arr, desc));
|
||||
HIP_CHECK(hipArray3DCreate(&arr1, desc));
|
||||
|
||||
SECTION("Host to Device") { Memcpy3DHostToDeviceShell<async>(DrvMemcpy3DWrapper<async>, stream); }
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
|
||||
SECTION("Host to Host") { Memcpy3DHostToHostShell<async>(DrvMemcpy3DWrapper<async>, stream); }
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Setting the default data */
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::SetDefaultData() {
|
||||
memset(&myparms, 0x0, sizeof(HIP_MEMCPY3D));
|
||||
myparms.srcXInBytes = 0;
|
||||
myparms.srcY = 0;
|
||||
myparms.srcZ = 0;
|
||||
myparms.srcLOD = 0;
|
||||
myparms.dstXInBytes = 0;
|
||||
myparms.dstY = 0;
|
||||
myparms.dstZ = 0;
|
||||
myparms.dstLOD = 0;
|
||||
myparms.WidthInBytes = width*sizeof(T);
|
||||
myparms.Height = height;
|
||||
myparms.Depth = depth;
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Positive_Synchronization_Behavior") {
|
||||
constexpr bool async = true;
|
||||
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
|
||||
SECTION("Host to Device") { Memcpy3DHtoDSyncBehavior(DrvMemcpy3DWrapper<async>, false); }
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-233
|
||||
SECTION("Device to Pageable Host") {
|
||||
Memcpy3DDtoHPageableSyncBehavior(DrvMemcpy3DWrapper<async>, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-236
|
||||
SECTION("Device to Pinned Host") {
|
||||
Memcpy3DDtoHPinnedSyncBehavior(DrvMemcpy3DWrapper<async>, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("Device to Device") { Memcpy3DDtoDSyncBehavior(DrvMemcpy3DWrapper<async>, false); }
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-233
|
||||
SECTION("Host to Host") { Memcpy3DHtoHSyncBehavior(DrvMemcpy3DWrapper<async>, true); }
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
This function verifies the negative scenarios of
|
||||
hipDrvMemcpy3DAsync API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::NegativeTests() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
AllocateMemory();
|
||||
SetDefaultData();
|
||||
int deviceId;
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
unsigned int MaxPitch;
|
||||
HIP_CHECK(hipDeviceGetAttribute(reinterpret_cast<int *>(&MaxPitch),
|
||||
hipDeviceAttributeMaxPitch, deviceId));
|
||||
myparms.srcHost = hData;
|
||||
myparms.dstArray = arr;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
|
||||
SECTION("Passing nullptr to Source Host") {
|
||||
myparms.srcHost = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing both dst host and device") {
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.WidthInBytes = pitch_D;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing max value to WidthInBytes") {
|
||||
myparms.WidthInBytes = std::numeric_limits<int>::max();
|
||||
myparms.Height = std::numeric_limits<int>::max();
|
||||
myparms.Depth = std::numeric_limits<int>::max();
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing width > max width size") {
|
||||
myparms.WidthInBytes = width*sizeof(T) + 1;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing height > max height size") {
|
||||
myparms.Height = height + 1;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing depth > max depth size") {
|
||||
myparms.Depth = depth + 1;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + srcXinBytes is out of bound") {
|
||||
myparms.srcXInBytes = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + dstXinBytes is out of bound") {
|
||||
myparms.dstXInBytes = pitch_D;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("srcY + height is out of bound") {
|
||||
myparms.srcY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dstY + height out of bounds") {
|
||||
myparms.dstY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("src pitch greater than Max allowed pitch") {
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = D_m;
|
||||
myparms.srcHost = nullptr;
|
||||
myparms.srcPitch = MaxPitch;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = width*sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dst pitch greater than Max allowed pitch") {
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = MaxPitch+1;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst device") {
|
||||
myparms.dstDevice = hipDeviceptr_t(nullptr);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst array") {
|
||||
myparms.dstArray = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to hipDrvMemcpy3DAsync") {
|
||||
REQUIRE(hipDrvMemcpy3DAsync(nullptr, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Positive_Parameters") {
|
||||
constexpr bool async = true;
|
||||
Memcpy3DZeroWidthHeightDepth<async>(DrvMemcpy3DWrapper<async>);
|
||||
}
|
||||
/*
|
||||
This function verifies the Extent validation scenarios of
|
||||
hipDrvMemcpy3DAsync API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::Extent_Validation() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
// Allocating the memory
|
||||
AllocateMemory();
|
||||
|
||||
// Setting default data
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
|
||||
SECTION("WidthInBytes is 0") {
|
||||
myparms.WidthInBytes = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
|
||||
SECTION("Height is 0") {
|
||||
myparms.Height = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
|
||||
SECTION("Depth is 0") {
|
||||
myparms.Depth = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
// Disabled on AMD due to defect - EXSWHTEC-238
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Positive_Array") {
|
||||
constexpr bool async = true;
|
||||
SECTION("Array from/to Host") { DrvMemcpy3DArrayHostShell<async>(DrvMemcpy3DWrapper<async>); }
|
||||
SECTION("Array from/to Device") { DrvMemcpy3DArrayDeviceShell<async>(DrvMemcpy3DWrapper<async>); }
|
||||
}
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3DAsync API
|
||||
1. Host to Device copy
|
||||
2. Device to Device
|
||||
3. Device to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3DAsync API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::HostDevice_DrvMemcpy3DAsync
|
||||
(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Negative_Parameters") {
|
||||
constexpr bool async = true;
|
||||
constexpr hipExtent extent{128 * sizeof(int), 128, 8};
|
||||
|
||||
constexpr auto NegativeTests = [](hipPitchedPtr dst_ptr, hipPos dst_pos, hipPitchedPtr src_ptr,
|
||||
hipPos src_pos, hipExtent extent, hipMemcpyKind kind) {
|
||||
SECTION("dst_ptr.ptr == nullptr") {
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.ptr = nullptr;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
|
||||
// Device to Device
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(D_m);
|
||||
myparms.srcPitch = pitch_D;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(E_m);
|
||||
myparms.dstPitch = pitch_E;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
|
||||
// Device to host
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(E_m);
|
||||
myparms.srcPitch = pitch_E;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3DAsync API
|
||||
1. Host to Array copy
|
||||
2. Array to Array
|
||||
3. Array to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3DAsync API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::HostArray_DrvMemcpy3DAsync
|
||||
(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
SECTION("src_ptr.ptr == nullptr") {
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.ptr = nullptr;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstArray = arr;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Array to Array
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcArray = arr;
|
||||
myparms.dstArray = arr1;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
SetDefaultData();
|
||||
// Device to host
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcArray = arr1;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
|
||||
/* DeAllocating the memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::DeAllocateMemory() {
|
||||
HIP_CHECK(hipArrayDestroy(arr));
|
||||
HIP_CHECK(hipArrayDestroy(arr1));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
free(hData);
|
||||
}
|
||||
|
||||
/* Verifying hipDrvMemcpy3DAsync API Host to Array for different datatypes */
|
||||
TEMPLATE_TEST_CASE("Unit_hipDrvMemcpy3DAsync_MultipleDataTypes", "",
|
||||
uint8_t, int, float) {
|
||||
for (int i = 1; i < 25; i++) {
|
||||
if (std::is_same<TestType, float>::value) {
|
||||
DrvMemcpy3DAsync<TestType> memcpy3d_float(i, i, i,
|
||||
HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_float.HostArray_DrvMemcpy3DAsync();
|
||||
} else if (std::is_same<TestType, uint8_t>::value) {
|
||||
DrvMemcpy3DAsync<TestType> memcpy3d_intx(i, i, i,
|
||||
HIP_AD_FORMAT_UNSIGNED_INT8);
|
||||
memcpy3d_intx.HostArray_DrvMemcpy3DAsync();
|
||||
} else if (std::is_same<TestType, int>::value) {
|
||||
DrvMemcpy3DAsync<TestType> memcpy3d_inty(i, i, i,
|
||||
HIP_AD_FORMAT_SIGNED_INT32);
|
||||
memcpy3d_inty.HostArray_DrvMemcpy3DAsync();
|
||||
SECTION("dst_ptr.pitch < width") {
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.pitch = extent.width - 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This testcase verifies H2D copy of hipDrvMemcpy3DAsync API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_HosttoDevice") {
|
||||
DrvMemcpy3DAsync<float> memcpy3d_D2H_float(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_D2H_float.HostDevice_DrvMemcpy3DAsync();
|
||||
}
|
||||
SECTION("src_ptr.pitch < width") {
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.pitch = extent.width - 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
/* This testcase verifies negative scenarios of hipDrvMemcpy3DAsync API */
|
||||
#if HT_NVIDIA
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Negative") {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.NegativeTests();
|
||||
}
|
||||
SECTION("dst_ptr.pitch > max pitch") {
|
||||
int attr = 0;
|
||||
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.pitch = attr;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_ptr.pitch > max pitch") {
|
||||
int attr = 0;
|
||||
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.pitch = attr;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-237
|
||||
SECTION("extent.width + dst_pos.x > dst_ptr.pitch") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.x = dst_ptr.pitch - extent.width + 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("extent.width + src_pos.x > src_ptr.pitch") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.x = src_ptr.pitch - extent.width + 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_pos.y out of bounds") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.y = 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_pos.y out of bounds") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.y = 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_pos.z out of bounds") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.z = 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_pos.z out of bounds") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.z = 1;
|
||||
HIP_CHECK_ERROR(
|
||||
DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This testcase verifies extent validation scenarios of
|
||||
hipDrvMemcpy3DAsync API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_ExtentValidation") {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.Extent_Validation();
|
||||
}
|
||||
|
||||
/* This testcase verifies H2D copy in device context
|
||||
change scenario for hipDrvMemcpy3DAsync API */
|
||||
#if HT_AMD
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_H2DDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostDevice_DrvMemcpy3DAsync(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* This testcase verifies Host to Array copy in device context
|
||||
change scenario for hipDrvMemcpy3DAsync API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Host2ArrayDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 10, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostArray_DrvMemcpy3DAsync(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
}
|
||||
}
|
||||
#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(DrvMemcpy3DWrapper<async>(dst_ptr, dst_pos, src_ptr, src_pos, extent, kind,
|
||||
stream_guard.stream()),
|
||||
hipErrorContextIsDestroyed);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
SECTION("Host to Device") {
|
||||
LinearAllocGuard3D<int> device_alloc(extent);
|
||||
LinearAllocGuard<int> host_alloc(
|
||||
LinearAllocs::hipHostMalloc,
|
||||
device_alloc.pitch() * device_alloc.height() * device_alloc.depth());
|
||||
NegativeTests(device_alloc.pitched_ptr(), make_hipPos(0, 0, 0),
|
||||
make_hipPitchedPtr(host_alloc.ptr(), device_alloc.pitch(), device_alloc.width(),
|
||||
device_alloc.height()),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
SECTION("Device to Host") {
|
||||
LinearAllocGuard3D<int> device_alloc(extent);
|
||||
LinearAllocGuard<int> host_alloc(
|
||||
LinearAllocs::hipHostMalloc,
|
||||
device_alloc.pitch() * device_alloc.height() * device_alloc.depth());
|
||||
NegativeTests(make_hipPitchedPtr(host_alloc.ptr(), device_alloc.pitch(), device_alloc.width(),
|
||||
device_alloc.height()),
|
||||
make_hipPos(0, 0, 0), device_alloc.pitched_ptr(), make_hipPos(0, 0, 0), extent,
|
||||
hipMemcpyDeviceToHost);
|
||||
}
|
||||
|
||||
SECTION("Host to Host") {
|
||||
LinearAllocGuard<int> src_alloc(LinearAllocs::hipHostMalloc,
|
||||
extent.width * extent.height * extent.depth);
|
||||
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipHostMalloc,
|
||||
extent.width * extent.height * extent.depth);
|
||||
NegativeTests(make_hipPitchedPtr(dst_alloc.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0),
|
||||
make_hipPitchedPtr(src_alloc.ptr(), extent.width, extent.width, extent.height),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyHostToHost);
|
||||
}
|
||||
|
||||
SECTION("Device to Device") {
|
||||
LinearAllocGuard3D<int> src_alloc(extent);
|
||||
LinearAllocGuard3D<int> dst_alloc(extent);
|
||||
NegativeTests(dst_alloc.pitched_ptr(), make_hipPos(0, 0, 0), src_alloc.pitched_ptr(),
|
||||
make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
/*
|
||||
* Test Scenarios
|
||||
* 1. Verifying hipDrvMemcpy3DAsync API for H2A,A2A,A2H scenarios
|
||||
* 2. Verifying hipDrvMemcpy3DAsync API for H2D,D2D,D2H scenarios
|
||||
* 3. Verifying Negative Scenarios
|
||||
* 4. Verifying Extent validation scenarios by passing 0
|
||||
* 5. Verifying hipDrvMemcpy3DAsync API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3DAsync from peer GPU for
|
||||
* H2D,D2D,D2H scenarios
|
||||
* 6. Verifying hipDrvMemcpy3DAsync API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3DAsync from peer GPU for
|
||||
* H2A,A2A,A2H scenarios
|
||||
*
|
||||
* Scenarios 3 is temporarily excluded in AMD platform
|
||||
* Scenario 5&6 are excluded in CUDA platform
|
||||
*/
|
||||
|
||||
#include "hip_test_common.hh"
|
||||
#include "hip_test_checkers.hh"
|
||||
|
||||
template<typename T>
|
||||
class DrvMemcpy3DAsync {
|
||||
int width, height, depth;
|
||||
unsigned int size;
|
||||
hipArray_Format formatKind;
|
||||
hiparray arr, arr1;
|
||||
hipStream_t stream;
|
||||
size_t pitch_D, pitch_E;
|
||||
HIP_MEMCPY3D myparms;
|
||||
hipDeviceptr_t D_m, E_m;
|
||||
T* hData{nullptr};
|
||||
public:
|
||||
DrvMemcpy3DAsync(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format);
|
||||
DrvMemcpy3DAsync() = delete;
|
||||
void AllocateMemory();
|
||||
void SetDefaultData();
|
||||
void HostArray_DrvMemcpy3DAsync(bool device_context_change = false);
|
||||
void HostDevice_DrvMemcpy3DAsync(bool device_context_change = false);
|
||||
void Extent_Validation();
|
||||
void NegativeTests();
|
||||
void DeAllocateMemory();
|
||||
};
|
||||
|
||||
/* Intializes class variables */
|
||||
template <typename T>
|
||||
DrvMemcpy3DAsync<T>::DrvMemcpy3DAsync(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format) {
|
||||
width = l_width;
|
||||
height = l_height;
|
||||
depth = l_depth;
|
||||
formatKind = l_format;
|
||||
}
|
||||
|
||||
/* Allocating Memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::AllocateMemory() {
|
||||
size = width * height * depth * sizeof(T);
|
||||
hData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hData, 0, size);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int k = 0; k < width; k++) {
|
||||
hData[i*width*height + j*width +k] = i*width*height + j*width + k;
|
||||
}
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&D_m),
|
||||
&pitch_D, width*sizeof(T), height));
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_m),
|
||||
&pitch_E, width*sizeof(T), height));
|
||||
HIP_ARRAY3D_DESCRIPTOR *desc;
|
||||
desc = reinterpret_cast<HIP_ARRAY3D_DESCRIPTOR*>
|
||||
(malloc(sizeof(HIP_ARRAY3D_DESCRIPTOR)));
|
||||
desc->Format = formatKind;
|
||||
desc->NumChannels = 1;
|
||||
desc->Width = width;
|
||||
desc->Height = height;
|
||||
desc->Depth = depth;
|
||||
desc->Flags = hipArrayDefault;
|
||||
HIP_CHECK(hipArray3DCreate(&arr, desc));
|
||||
HIP_CHECK(hipArray3DCreate(&arr1, desc));
|
||||
}
|
||||
|
||||
/* Setting the default data */
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::SetDefaultData() {
|
||||
memset(&myparms, 0x0, sizeof(HIP_MEMCPY3D));
|
||||
myparms.srcXInBytes = 0;
|
||||
myparms.srcY = 0;
|
||||
myparms.srcZ = 0;
|
||||
myparms.srcLOD = 0;
|
||||
myparms.dstXInBytes = 0;
|
||||
myparms.dstY = 0;
|
||||
myparms.dstZ = 0;
|
||||
myparms.dstLOD = 0;
|
||||
myparms.WidthInBytes = width*sizeof(T);
|
||||
myparms.Height = height;
|
||||
myparms.Depth = depth;
|
||||
}
|
||||
|
||||
/*
|
||||
This function verifies the negative scenarios of
|
||||
hipDrvMemcpy3DAsync API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::NegativeTests() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
AllocateMemory();
|
||||
SetDefaultData();
|
||||
int deviceId;
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
unsigned int MaxPitch;
|
||||
HIP_CHECK(hipDeviceGetAttribute(reinterpret_cast<int *>(&MaxPitch),
|
||||
hipDeviceAttributeMaxPitch, deviceId));
|
||||
myparms.srcHost = hData;
|
||||
myparms.dstArray = arr;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
|
||||
SECTION("Passing nullptr to Source Host") {
|
||||
myparms.srcHost = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing both dst host and device") {
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.WidthInBytes = pitch_D;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing max value to WidthInBytes") {
|
||||
myparms.WidthInBytes = std::numeric_limits<int>::max();
|
||||
myparms.Height = std::numeric_limits<int>::max();
|
||||
myparms.Depth = std::numeric_limits<int>::max();
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing width > max width size") {
|
||||
myparms.WidthInBytes = width*sizeof(T) + 1;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing height > max height size") {
|
||||
myparms.Height = height + 1;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing depth > max depth size") {
|
||||
myparms.Depth = depth + 1;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + srcXinBytes is out of bound") {
|
||||
myparms.srcXInBytes = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + dstXinBytes is out of bound") {
|
||||
myparms.dstXInBytes = pitch_D;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("srcY + height is out of bound") {
|
||||
myparms.srcY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dstY + height out of bounds") {
|
||||
myparms.dstY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("src pitch greater than Max allowed pitch") {
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = D_m;
|
||||
myparms.srcHost = nullptr;
|
||||
myparms.srcPitch = MaxPitch;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = width*sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dst pitch greater than Max allowed pitch") {
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = MaxPitch+1;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst device") {
|
||||
myparms.dstDevice = hipDeviceptr_t(nullptr);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst array") {
|
||||
myparms.dstArray = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3DAsync(&myparms, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to hipDrvMemcpy3DAsync") {
|
||||
REQUIRE(hipDrvMemcpy3DAsync(nullptr, stream) != hipSuccess);
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
}
|
||||
/*
|
||||
This function verifies the Extent validation scenarios of
|
||||
hipDrvMemcpy3DAsync API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::Extent_Validation() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
// Allocating the memory
|
||||
AllocateMemory();
|
||||
|
||||
// Setting default data
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
|
||||
SECTION("WidthInBytes is 0") {
|
||||
myparms.WidthInBytes = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
|
||||
SECTION("Height is 0") {
|
||||
myparms.Height = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
|
||||
SECTION("Depth is 0") {
|
||||
myparms.Depth = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
}
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3DAsync API
|
||||
1. Host to Device copy
|
||||
2. Device to Device
|
||||
3. Device to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3DAsync API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::HostDevice_DrvMemcpy3DAsync
|
||||
(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
|
||||
// Device to Device
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(D_m);
|
||||
myparms.srcPitch = pitch_D;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(E_m);
|
||||
myparms.dstPitch = pitch_E;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
|
||||
// Device to host
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(E_m);
|
||||
myparms.srcPitch = pitch_E;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3DAsync API
|
||||
1. Host to Array copy
|
||||
2. Array to Array
|
||||
3. Array to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3DAsync API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::HostArray_DrvMemcpy3DAsync
|
||||
(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstArray = arr;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Array to Array
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcArray = arr;
|
||||
myparms.dstArray = arr1;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
SetDefaultData();
|
||||
// Device to host
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcArray = arr1;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3DAsync(&myparms, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
|
||||
/* DeAllocating the memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3DAsync<T>::DeAllocateMemory() {
|
||||
HIP_CHECK(hipArrayDestroy(arr));
|
||||
HIP_CHECK(hipArrayDestroy(arr1));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
free(hData);
|
||||
}
|
||||
|
||||
/* Verifying hipDrvMemcpy3DAsync API Host to Array for different datatypes */
|
||||
TEMPLATE_TEST_CASE("Unit_hipDrvMemcpy3DAsync_MultipleDataTypes", "",
|
||||
uint8_t, int, float) {
|
||||
for (int i = 1; i < 25; i++) {
|
||||
if (std::is_same<TestType, float>::value) {
|
||||
DrvMemcpy3DAsync<TestType> memcpy3d_float(i, i, i,
|
||||
HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_float.HostArray_DrvMemcpy3DAsync();
|
||||
} else if (std::is_same<TestType, uint8_t>::value) {
|
||||
DrvMemcpy3DAsync<TestType> memcpy3d_intx(i, i, i,
|
||||
HIP_AD_FORMAT_UNSIGNED_INT8);
|
||||
memcpy3d_intx.HostArray_DrvMemcpy3DAsync();
|
||||
} else if (std::is_same<TestType, int>::value) {
|
||||
DrvMemcpy3DAsync<TestType> memcpy3d_inty(i, i, i,
|
||||
HIP_AD_FORMAT_SIGNED_INT32);
|
||||
memcpy3d_inty.HostArray_DrvMemcpy3DAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This testcase verifies H2D copy of hipDrvMemcpy3DAsync API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_HosttoDevice") {
|
||||
DrvMemcpy3DAsync<float> memcpy3d_D2H_float(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_D2H_float.HostDevice_DrvMemcpy3DAsync();
|
||||
}
|
||||
|
||||
/* This testcase verifies negative scenarios of hipDrvMemcpy3DAsync API */
|
||||
#if HT_NVIDIA
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Negative") {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.NegativeTests();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This testcase verifies extent validation scenarios of
|
||||
hipDrvMemcpy3DAsync API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_ExtentValidation") {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.Extent_Validation();
|
||||
}
|
||||
|
||||
/* This testcase verifies H2D copy in device context
|
||||
change scenario for hipDrvMemcpy3DAsync API */
|
||||
#if HT_AMD
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_H2DDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostDevice_DrvMemcpy3DAsync(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* This testcase verifies Host to Array copy in device context
|
||||
change scenario for hipDrvMemcpy3DAsync API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3DAsync_Host2ArrayDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3DAsync<float> memcpy3d(10, 10, 10, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostArray_DrvMemcpy3DAsync(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,573 @@
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
/*
|
||||
* Test Scenarios
|
||||
* 1. Verifying hipDrvMemcpy3D API for H2A,A2A,A2H scenarios
|
||||
* 2. Verifying hipDrvMemcpy3D API for H2D,D2D,D2H scenarios
|
||||
* 3. Verifying Negative Scenarios
|
||||
* 4. Verifying Extent validation scenarios by passing 0
|
||||
* 5. Verifying hipDrvMemcpy3D API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3D from peer GPU for
|
||||
* H2D,D2D,D2H scenarios
|
||||
* 6. Verifying hipDrvMemcpy3D API by allocating Memory in
|
||||
* one GPU and trigger hipDrvMemcpy3D from peer GPU for
|
||||
* H2A,A2A,A2H scenarios
|
||||
*
|
||||
* Scenarios 3 is temporarily suspended on AMD
|
||||
* Scenario 5&6 are not supported in CUDA platform
|
||||
*/
|
||||
|
||||
#include "hip_test_common.hh"
|
||||
#include "hip_test_checkers.hh"
|
||||
|
||||
template<typename T>
|
||||
class DrvMemcpy3D {
|
||||
int width, height, depth;
|
||||
unsigned int size;
|
||||
hipArray_Format formatKind;
|
||||
hiparray arr, arr1;
|
||||
size_t pitch_D, pitch_E;
|
||||
HIP_MEMCPY3D myparms;
|
||||
hipDeviceptr_t D_m, E_m;
|
||||
T* hData{nullptr};
|
||||
public:
|
||||
DrvMemcpy3D(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format);
|
||||
DrvMemcpy3D() = delete;
|
||||
void AllocateMemory();
|
||||
void SetDefaultData();
|
||||
void HostArray_DrvMemcpy3D(bool device_context_change = false);
|
||||
void HostDevice_DrvMemcpy3D(bool device_context_change = false);
|
||||
void Extent_Validation();
|
||||
void NegativeTests();
|
||||
void DeAllocateMemory();
|
||||
};
|
||||
|
||||
/* Intializes class variables */
|
||||
template <typename T>
|
||||
DrvMemcpy3D<T>::DrvMemcpy3D(int l_width, int l_height, int l_depth,
|
||||
hipArray_Format l_format) {
|
||||
width = l_width;
|
||||
height = l_height;
|
||||
depth = l_depth;
|
||||
formatKind = l_format;
|
||||
}
|
||||
|
||||
/* Allocating Memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::AllocateMemory() {
|
||||
size = width * height * depth * sizeof(T);
|
||||
hData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hData, 0, size);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int k = 0; k < width; k++) {
|
||||
hData[i*width*height + j*width +k] = i*width*height + j*width + k;
|
||||
}
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&D_m),
|
||||
&pitch_D, width*sizeof(T), height));
|
||||
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&E_m),
|
||||
&pitch_E, width*sizeof(T), height));
|
||||
HIP_ARRAY3D_DESCRIPTOR *desc;
|
||||
desc = reinterpret_cast<HIP_ARRAY3D_DESCRIPTOR*>
|
||||
(malloc(sizeof(HIP_ARRAY3D_DESCRIPTOR)));
|
||||
desc->Format = formatKind;
|
||||
desc->NumChannels = 1;
|
||||
desc->Width = width;
|
||||
desc->Height = height;
|
||||
desc->Depth = depth;
|
||||
desc->Flags = hipArrayDefault;
|
||||
HIP_CHECK(hipArray3DCreate(&arr, desc));
|
||||
HIP_CHECK(hipArray3DCreate(&arr1, desc));
|
||||
}
|
||||
|
||||
/* Setting the default data */
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::SetDefaultData() {
|
||||
memset(&myparms, 0x0, sizeof(HIP_MEMCPY3D));
|
||||
myparms.srcXInBytes = 0;
|
||||
myparms.srcY = 0;
|
||||
myparms.srcZ = 0;
|
||||
myparms.srcLOD = 0;
|
||||
myparms.dstXInBytes = 0;
|
||||
myparms.dstY = 0;
|
||||
myparms.dstZ = 0;
|
||||
myparms.dstLOD = 0;
|
||||
myparms.WidthInBytes = width*sizeof(T);
|
||||
myparms.Height = height;
|
||||
myparms.Depth = depth;
|
||||
}
|
||||
|
||||
/*
|
||||
This function verifies the negative scenarios of
|
||||
hipDrvMemcpy3D API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::NegativeTests() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
AllocateMemory();
|
||||
SetDefaultData();
|
||||
int deviceId;
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
unsigned int MaxPitch;
|
||||
HIP_CHECK(hipDeviceGetAttribute(reinterpret_cast<int *>(&MaxPitch),
|
||||
hipDeviceAttributeMaxPitch, deviceId));
|
||||
myparms.srcHost = hData;
|
||||
myparms.dstArray = arr;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
|
||||
SECTION("Passing nullptr to Source Host") {
|
||||
myparms.srcHost = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing both dst host and device") {
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.WidthInBytes = pitch_D;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing max value to WidthInBytes") {
|
||||
myparms.WidthInBytes = std::numeric_limits<int>::max();
|
||||
myparms.Height = std::numeric_limits<int>::max();
|
||||
myparms.Depth = std::numeric_limits<int>::max();
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing width > max width size") {
|
||||
myparms.WidthInBytes = width*sizeof(T) + 1;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing height > max height size") {
|
||||
myparms.Height = height + 1;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Passing depth > max depth size") {
|
||||
myparms.Depth = depth + 1;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + srcXinBytes is out of bound") {
|
||||
myparms.srcXInBytes = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("widthinbytes + dstXinBytes is out of bound") {
|
||||
myparms.dstXInBytes = pitch_D;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("srcY + height is out of bound") {
|
||||
myparms.srcY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dstY + height out of bounds") {
|
||||
myparms.dstY = 1;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("src pitch greater than Max allowed pitch") {
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = D_m;
|
||||
myparms.srcHost = nullptr;
|
||||
myparms.srcPitch = MaxPitch;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hData;
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = width*sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("dst pitch greater than Max allowed pitch") {
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = MaxPitch+1;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst device") {
|
||||
myparms.dstDevice = hipDeviceptr_t(nullptr);
|
||||
myparms.dstArray = nullptr;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
#if HT_NVIDIA
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to src/dst array") {
|
||||
myparms.dstArray = nullptr;
|
||||
REQUIRE(hipDrvMemcpy3D(&myparms) != hipSuccess);
|
||||
}
|
||||
|
||||
SECTION("Nullptr to hipDrvMemcpy3D") {
|
||||
REQUIRE(hipDrvMemcpy3D(nullptr) != hipSuccess);
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
}
|
||||
/*
|
||||
This function verifies the Extent validation scenarios of
|
||||
hipDrvMemcpy3D API
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::Extent_Validation() {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
// Allocating the memory
|
||||
AllocateMemory();
|
||||
|
||||
// Setting default data
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = D_m;
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
|
||||
SECTION("WidthInBytes is 0") {
|
||||
myparms.WidthInBytes = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
}
|
||||
|
||||
SECTION("Height is 0") {
|
||||
myparms.Height = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
}
|
||||
|
||||
SECTION("Depth is 0") {
|
||||
myparms.Depth = 0;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
}
|
||||
|
||||
DeAllocateMemory();
|
||||
}
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3D API
|
||||
1. Host to Device copy
|
||||
2. Device to Device
|
||||
3. Device to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3D API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::HostDevice_DrvMemcpy3D(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(D_m);
|
||||
myparms.dstPitch = pitch_D;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
|
||||
// Device to Device
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeDevice;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(D_m);
|
||||
myparms.srcPitch = pitch_D;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstDevice = hipDeviceptr_t(E_m);
|
||||
myparms.dstPitch = pitch_E;
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
|
||||
// Device to host
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_DEVICE;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeDevice;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcDevice = hipDeviceptr_t(E_m);
|
||||
myparms.srcPitch = pitch_E;
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
|
||||
/*
|
||||
This Function verifies following functionalities of hipDrvMemcpy3D API
|
||||
1. Host to Array copy
|
||||
2. Array to Array
|
||||
3. Array to Host
|
||||
In the end validates the results.
|
||||
|
||||
This functionality is verified in 2 scenarios
|
||||
1. Basic scenario on same GPU device
|
||||
2. Device context change scenario where memory is allocated in 1 GPU
|
||||
and hipDrvMemcpy3D API is trigerred from another GPU
|
||||
*/
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::HostArray_DrvMemcpy3D(bool device_context_change) {
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
bool skip_test = false;
|
||||
int peerAccess = 0;
|
||||
AllocateMemory();
|
||||
if (device_context_change) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 0, 1));
|
||||
if (!peerAccess) {
|
||||
WARN("skipped the testcase as no peer access");
|
||||
skip_test = true;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
}
|
||||
if (!skip_test) {
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_HOST;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeHost;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcHost = hData;
|
||||
myparms.srcPitch = width * sizeof(T);
|
||||
myparms.srcHeight = height;
|
||||
myparms.dstArray = arr;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
// Array to Array
|
||||
SetDefaultData();
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeArray;
|
||||
#endif
|
||||
myparms.srcArray = arr;
|
||||
myparms.dstArray = arr1;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
T *hOutputData = reinterpret_cast<T*>(malloc(size));
|
||||
memset(hOutputData, 0, size);
|
||||
SetDefaultData();
|
||||
// Device to host
|
||||
#if HT_NVIDIA
|
||||
myparms.srcMemoryType = CU_MEMORYTYPE_ARRAY;
|
||||
myparms.dstMemoryType = CU_MEMORYTYPE_HOST;
|
||||
#else
|
||||
myparms.srcMemoryType = hipMemoryTypeArray;
|
||||
myparms.dstMemoryType = hipMemoryTypeHost;
|
||||
#endif
|
||||
myparms.srcArray = arr1;
|
||||
myparms.dstHost = hOutputData;
|
||||
myparms.dstPitch = width * sizeof(T);
|
||||
myparms.dstHeight = height;
|
||||
HIP_CHECK(hipDrvMemcpy3D(&myparms));
|
||||
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
free(hOutputData);
|
||||
}
|
||||
DeAllocateMemory();
|
||||
}
|
||||
/* DeAllocating the memory */
|
||||
template <typename T>
|
||||
void DrvMemcpy3D<T>::DeAllocateMemory() {
|
||||
HIP_CHECK(hipArrayDestroy(arr));
|
||||
HIP_CHECK(hipArrayDestroy(arr1));
|
||||
free(hData);
|
||||
}
|
||||
|
||||
/* Verifying hipDrvMemcpy3D API Host to Array for different datatypes */
|
||||
TEMPLATE_TEST_CASE("Unit_hipDrvMemcpy3D_MultipleDataTypes", "",
|
||||
uint8_t, int, float) {
|
||||
for (int i = 1; i < 25; i++) {
|
||||
if (std::is_same<TestType, float>::value) {
|
||||
DrvMemcpy3D<TestType> memcpy3d_float(i, i, i, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_float.HostArray_DrvMemcpy3D();
|
||||
} else if (std::is_same<TestType, uint8_t>::value) {
|
||||
DrvMemcpy3D<TestType> memcpy3d_intx(i, i, i, HIP_AD_FORMAT_UNSIGNED_INT8);
|
||||
memcpy3d_intx.HostArray_DrvMemcpy3D();
|
||||
} else if (std::is_same<TestType, int>::value) {
|
||||
DrvMemcpy3D<TestType> memcpy3d_inty(i, i, i, HIP_AD_FORMAT_SIGNED_INT32);
|
||||
memcpy3d_inty.HostArray_DrvMemcpy3D();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This testcase verifies H2D copy of hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_HosttoDevice") {
|
||||
DrvMemcpy3D<float> memcpy3d_D2H_float(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d_D2H_float.HostDevice_DrvMemcpy3D();
|
||||
}
|
||||
|
||||
/* This testcase verifies negative scenarios of hipDrvMemcpy3D API */
|
||||
#if HT_NVIDIA
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Negative") {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.NegativeTests();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This testcase verifies extent validation scenarios of hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_ExtentValidation") {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.Extent_Validation();
|
||||
}
|
||||
|
||||
#if HT_AMD
|
||||
/* This testcase verifies H2D copy in device context
|
||||
change scenario for hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_H2DDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostDevice_DrvMemcpy3D(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* This testcase verifies Host to Array copy in device context
|
||||
change scenario for hipDrvMemcpy3D API */
|
||||
TEST_CASE("Unit_hipDrvMemcpy3D_Host2ArrayDeviceContextChange") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
DrvMemcpy3D<float> memcpy3d(10, 10, 1, HIP_AD_FORMAT_FLOAT);
|
||||
memcpy3d.HostArray_DrvMemcpy3D(true);
|
||||
} else {
|
||||
SUCCEED("skipped testcase as Device count is < 2");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Referência em uma Nova Issue
Bloquear um usuário