EXSWHTEC-217 - Implement new and update existing tests for the hipGraph*MemcpyNode family of APIs #48
Change-Id: Iae7ac9c855ba6e3288257e99e49f8b16cebb1bac
[ROCm/hip-tests commit: cefbaed5cf]
This commit is contained in:
committed by
Rakesh Roy
parent
25263b8553
commit
4194470cd6
@@ -1,576 +1,287 @@
|
||||
/*
|
||||
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Testcase Scenarios : Negative
|
||||
1) Pass pGraphNode as nullptr and check if api returns error.
|
||||
2) When graph is un-initialized argument(skipping graph creation),
|
||||
api should return error code.
|
||||
3) Passing pDependencies as nullptr, api should return success.
|
||||
4) When numDependencies is max(size_t) and pDependencies is not valid ptr,
|
||||
api expected to return error code.
|
||||
5) When pDependencies is nullptr, but numDependencies is non-zero,
|
||||
api expected to return error.
|
||||
6) When pCopyParams is nullptr, api expected to return error code.
|
||||
7) API expects atleast one memcpy src pointer to be set.
|
||||
When hipMemcpy3DParms::srcArray and hipMemcpy3DParms::srcPtr.ptr both
|
||||
are nullptr, api expected to return error code.
|
||||
8) API expects atleast one memcpy dst pointer to be set.
|
||||
When hipMemcpy3DParms::dstArray and hipMemcpy3DParms::dstPtr.ptr both
|
||||
are nullptr, api expected to return error code.
|
||||
9) Passing different element size for hipMemcpy3DParms::srcArray and
|
||||
hipMemcpy3DParms::dstArray is expected to return error code.
|
||||
|
||||
Testcase Scenarios : Functional
|
||||
1) Add memcpy node to graph and verify memcpy operation is success for all
|
||||
memcpy kinds(H2D, D2H and D2D).
|
||||
Memcpy nodes are added and assigned to default device.
|
||||
2) Perform memcpy operation for 1D, 2D and 3D arrays on default device and
|
||||
verify the results.
|
||||
3) Add memcpy node to graph and verify memcpy operation is success for all
|
||||
memcpy kinds(H2D, D2H and D2D).
|
||||
Memcpy nodes are added and assigned to Peer device.
|
||||
4) Perform memcpy operation for 1D, 2D and 3D arrays on Peer device and
|
||||
verify the results.
|
||||
5) Create two host pointers, copy the data between them by the api
|
||||
hipGraphAddMemcpyNode with data transfer kind hipMemcpyHostToHost.
|
||||
Validate the output.
|
||||
*/
|
||||
#include <functional>
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_checkers.hh>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <hip_test_defgroups.hh>
|
||||
#include <memcpy3d_tests_common.hh>
|
||||
|
||||
#define ZSIZE 32
|
||||
#define YSIZE 32
|
||||
#define XSIZE 32
|
||||
#include "graph_tests_common.hh"
|
||||
|
||||
/* Test verifies hipGraphAddMemcpyNode API Negative scenarios.
|
||||
/**
|
||||
* @addtogroup hipGraphAddMemcpyNode hipGraphAddMemcpyNode
|
||||
* @{
|
||||
* @ingroup GraphTest
|
||||
* `hipGraphAddMemcpyNode(hipGraphNode_t *pGraphNode, hipGraph_t graph, const
|
||||
* hipGraphNode_t *pDependencies, size_t numDependencies, const hipMemcpy3DParms
|
||||
* *pCopyParams)` - Creates a memcpy node and adds it to a graph
|
||||
*/
|
||||
|
||||
TEST_CASE("Unit_hipGraphAddMemcpyNode_Negative") {
|
||||
CHECK_IMAGE_SUPPORT
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Verify basic API behavior. A Memcpy node is created with parameters set according to the
|
||||
* test run, after which the graph is run and the memcpy results are verified.
|
||||
* The test is run for all possible memcpy directions, with both the corresponding memcpy
|
||||
* kind and hipMemcpyDefault, as well as half page and full page allocation sizes.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/graph/hipGraphAddMemcpyNode.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipGraphAddMemcpyNode_Positive_Basic") {
|
||||
constexpr bool async = false;
|
||||
|
||||
constexpr int width{10}, height{10}, depth{10};
|
||||
hipArray_t devArray1;
|
||||
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
|
||||
hipMemcpy3DParms myparams;
|
||||
uint32_t size = width * height * depth * sizeof(int);
|
||||
hipGraph_t graph;
|
||||
hipGraphNode_t memcpyNode;
|
||||
hipStream_t streamForGraph;
|
||||
hipError_t ret;
|
||||
SECTION("Device to host") { Memcpy3DDeviceToHostShell<async>(Memcpy3DWrapper<async, true>); }
|
||||
|
||||
int *hData = reinterpret_cast<int*>(malloc(size));
|
||||
int *hOutputData = reinterpret_cast<int *>(malloc(size));
|
||||
SECTION("Device to host with default kind") {
|
||||
Memcpy3DDeviceToHostShell<async>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
|
||||
REQUIRE(hData != nullptr);
|
||||
REQUIRE(hOutputData != nullptr);
|
||||
memset(hData, 0, size);
|
||||
memset(hOutputData, 0, size);
|
||||
SECTION("Host to device") { Memcpy3DHostToDeviceShell<async>(Memcpy3DWrapper<async, true>); }
|
||||
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
SECTION("Host to device with default kind") {
|
||||
Memcpy3DHostToDeviceShell<async>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
|
||||
// Initialize host buffer
|
||||
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;
|
||||
}
|
||||
SECTION("Host to host") { Memcpy3DHostToHostShell<async>(Memcpy3DWrapper<async, true>); }
|
||||
|
||||
SECTION("Host to host with default kind") {
|
||||
Memcpy3DHostToHostShell<async>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
|
||||
SECTION("Device to device") {
|
||||
SECTION("Peer access enabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, true>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
SECTION("Peer access disabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, false>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
}
|
||||
|
||||
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
|
||||
0, 0, 0, formatKind);
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray1, &channelDesc,
|
||||
make_hipExtent(width, height, depth), hipArrayDefault));
|
||||
|
||||
// Host to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width , height, depth);
|
||||
myparams.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
|
||||
width, height);
|
||||
myparams.dstArray = devArray1;
|
||||
myparams.kind = hipMemcpyHostToDevice;
|
||||
|
||||
SECTION("Pass pGraphNode as nullptr") {
|
||||
ret = hipGraphAddMemcpyNode(nullptr, graph, nullptr, 0, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("When graph is nullptr") {
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, nullptr, nullptr, 0, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("Passing pDependencies as nullptr") {
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams);
|
||||
REQUIRE(hipSuccess == ret);
|
||||
}
|
||||
SECTION("When numDependencies is max and pDependencies is not valid ptr") {
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph,
|
||||
nullptr, INT_MAX, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("When pDependencies is nullptr, but numDependencies is non-zero") {
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 11, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("Pass pCopyParams as nullptr") {
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, nullptr);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("API expects atleast one memcpy src pointer to be set") {
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width , height, depth);
|
||||
myparams.dstArray = devArray1;
|
||||
myparams.kind = hipMemcpyHostToDevice;
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("API expects atleast one memcpy dst pointer to be set") {
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width , height, depth);
|
||||
myparams.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
|
||||
width, height);
|
||||
myparams.kind = hipMemcpyHostToDevice;
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
}
|
||||
SECTION("Passing different element size for hipMemcpy3DParms::srcArray"
|
||||
"and hipMemcpy3DParms::dstArray") {
|
||||
myparams.srcArray = devArray1;
|
||||
hipArray_t devArray2;
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray2, &channelDesc,
|
||||
make_hipExtent(width+1, height+1, depth+1), hipArrayDefault));
|
||||
myparams.dstArray = devArray2;
|
||||
ret = hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams);
|
||||
REQUIRE(hipErrorInvalidValue == ret);
|
||||
HIP_CHECK(hipFreeArray(devArray2));
|
||||
}
|
||||
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
HIP_CHECK(hipFreeArray(devArray1));
|
||||
free(hData);
|
||||
free(hOutputData);
|
||||
}
|
||||
|
||||
static void validateMemcpyNode3DArray(bool peerAccess = false) {
|
||||
constexpr int width{10}, height{10}, depth{10};
|
||||
hipArray_t devArray1, devArray2;
|
||||
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
|
||||
hipMemcpy3DParms myparams;
|
||||
uint32_t size = width * height * depth * sizeof(int);
|
||||
hipGraph_t graph;
|
||||
hipGraphNode_t memcpyNode;
|
||||
std::vector<hipGraphNode_t> dependencies;
|
||||
hipStream_t streamForGraph;
|
||||
hipGraphExec_t graphExec;
|
||||
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
int *hData = reinterpret_cast<int*>(malloc(size));
|
||||
int *hOutputData = reinterpret_cast<int *>(malloc(size));
|
||||
|
||||
REQUIRE(hData != nullptr);
|
||||
REQUIRE(hOutputData != nullptr);
|
||||
memset(hData, 0, size);
|
||||
memset(hOutputData, 0, size);
|
||||
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
|
||||
// Initialize host buffer
|
||||
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;
|
||||
}
|
||||
SECTION("Device to device with default kind") {
|
||||
SECTION("Peer access enabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, true>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
SECTION("Peer access disabled") {
|
||||
Memcpy3DDeviceToDeviceShell<async, false>(Memcpy3DWrapper<async, true>);
|
||||
}
|
||||
}
|
||||
|
||||
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
|
||||
0, 0, 0, formatKind);
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray1, &channelDesc,
|
||||
make_hipExtent(width, height, depth), hipArrayDefault));
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray2, &channelDesc,
|
||||
make_hipExtent(width, height, depth), hipArrayDefault));
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
SECTION("Array from/to Host") { Memcpy3DArrayHostShell<async>(Memcpy3DWrapper<async, true>); }
|
||||
|
||||
// For peer access test, Memory is allocated on device(0)
|
||||
// while memcpy nodes are allocated and assigned to peer device(1)
|
||||
if (peerAccess) {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
|
||||
// Host to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width , height, depth);
|
||||
myparams.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
|
||||
width, height);
|
||||
myparams.dstArray = devArray1;
|
||||
myparams.kind = hipMemcpyHostToDevice;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams));
|
||||
dependencies.push_back(memcpyNode);
|
||||
|
||||
// Device to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.srcArray = devArray1;
|
||||
myparams.dstArray = devArray2;
|
||||
myparams.extent = make_hipExtent(width, height, depth);
|
||||
myparams.kind = hipMemcpyDeviceToDevice;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
|
||||
dependencies.size(), &myparams));
|
||||
dependencies.clear();
|
||||
dependencies.push_back(memcpyNode);
|
||||
|
||||
// Device to host
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPtr = make_hipPitchedPtr(hOutputData, width * sizeof(int),
|
||||
width, height);
|
||||
myparams.srcArray = devArray2;
|
||||
myparams.extent = make_hipExtent(width, height, depth);
|
||||
myparams.kind = hipMemcpyDeviceToHost;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
|
||||
dependencies.size(), &myparams));
|
||||
|
||||
// Instantiate and launch the graph
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph));
|
||||
|
||||
// Check result
|
||||
HipTest::checkArray(hData, hOutputData, width, height, depth);
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
HIP_CHECK(hipFreeArray(devArray1));
|
||||
HIP_CHECK(hipFreeArray(devArray2));
|
||||
free(hData);
|
||||
free(hOutputData);
|
||||
}
|
||||
|
||||
static void validateMemcpyNode2DArray(bool peerAccess = false) {
|
||||
int harray2D[YSIZE][XSIZE]{};
|
||||
int harray2Dres[YSIZE][XSIZE]{};
|
||||
constexpr int width{XSIZE}, height{YSIZE};
|
||||
hipArray_t devArray1, devArray2;
|
||||
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
|
||||
hipMemcpy3DParms myparams;
|
||||
hipGraph_t graph;
|
||||
hipGraphNode_t memcpyNode;
|
||||
std::vector<hipGraphNode_t> dependencies;
|
||||
hipStream_t streamForGraph;
|
||||
hipGraphExec_t graphExec;
|
||||
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
// Initialize 2D object
|
||||
for (int i = 0; i < YSIZE; i++) {
|
||||
for (int j = 0; j < XSIZE; j++) {
|
||||
harray2D[i][j] = i + j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
|
||||
0, 0, 0, formatKind);
|
||||
// Allocate 2D device array by passing depth(0)
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray1, &channelDesc,
|
||||
make_hipExtent(width, height, 0), hipArrayDefault));
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray2, &channelDesc,
|
||||
make_hipExtent(width, height, 0), hipArrayDefault));
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
|
||||
// For peer access test, Memory is allocated on device(0)
|
||||
// while memcpy nodes are allocated and assigned to peer device(1)
|
||||
if (peerAccess) {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
|
||||
// Host to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width, height, 1);
|
||||
myparams.srcPtr = make_hipPitchedPtr(harray2D, width * sizeof(int),
|
||||
width, height);
|
||||
myparams.dstArray = devArray1;
|
||||
myparams.kind = hipMemcpyHostToDevice;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams));
|
||||
dependencies.push_back(memcpyNode);
|
||||
|
||||
// Device to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.srcArray = devArray1;
|
||||
myparams.dstArray = devArray2;
|
||||
myparams.extent = make_hipExtent(width, height, 1);
|
||||
myparams.kind = hipMemcpyDeviceToDevice;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
|
||||
dependencies.size(), &myparams));
|
||||
dependencies.clear();
|
||||
dependencies.push_back(memcpyNode);
|
||||
|
||||
// Device to host
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width, height, 1);
|
||||
myparams.dstPtr = make_hipPitchedPtr(harray2Dres, width * sizeof(int),
|
||||
width, height);
|
||||
myparams.srcArray = devArray2;
|
||||
myparams.kind = hipMemcpyDeviceToHost;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
|
||||
dependencies.size(), &myparams));
|
||||
|
||||
// Instantiate and launch the graph
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph));
|
||||
|
||||
// Validate result
|
||||
for (int i = 0; i < YSIZE; i++) {
|
||||
for (int j = 0; j < XSIZE; j++) {
|
||||
if (harray2D[i][j] != harray2Dres[i][j]) {
|
||||
INFO("harray2D: " << harray2D[i][j] << "harray2Dres: "
|
||||
<< harray2Dres[i][j] << " mismatch at (i,j) : " << i << j);
|
||||
REQUIRE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
HIP_CHECK(hipFreeArray(devArray1));
|
||||
HIP_CHECK(hipFreeArray(devArray2));
|
||||
}
|
||||
|
||||
static void validateMemcpyNode1DArray(bool peerAccess = false) {
|
||||
int harray1D[XSIZE]{};
|
||||
int harray1Dres[XSIZE]{};
|
||||
constexpr int width{XSIZE};
|
||||
hipArray_t devArray1, devArray2;
|
||||
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
|
||||
hipMemcpy3DParms myparams;
|
||||
hipGraph_t graph;
|
||||
hipGraphNode_t memcpyNode;
|
||||
std::vector<hipGraphNode_t> dependencies;
|
||||
hipStream_t streamForGraph;
|
||||
hipGraphExec_t graphExec;
|
||||
|
||||
HIP_CHECK(hipSetDevice(0));
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
// Initialize 1D object
|
||||
for (int i = 0; i < XSIZE; i++) {
|
||||
harray1D[i] = i + 1;
|
||||
}
|
||||
|
||||
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
|
||||
0, 0, 0, formatKind);
|
||||
// Allocate 1D device array by passing depth(0), height(0)
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray1, &channelDesc,
|
||||
make_hipExtent(width, 0, 0), hipArrayDefault));
|
||||
HIP_CHECK(hipMalloc3DArray(&devArray2, &channelDesc,
|
||||
make_hipExtent(width, 0, 0), hipArrayDefault));
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
|
||||
// For peer access test, Memory is allocated on device(0)
|
||||
// while memcpy nodes are allocated and assigned to peer device(1)
|
||||
if (peerAccess) {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
}
|
||||
|
||||
// Host to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width, 1, 1);
|
||||
myparams.srcPtr = make_hipPitchedPtr(harray1D, width * sizeof(int),
|
||||
width, 1);
|
||||
myparams.dstArray = devArray1;
|
||||
myparams.kind = hipMemcpyHostToDevice;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams));
|
||||
dependencies.push_back(memcpyNode);
|
||||
|
||||
// Device to Device
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.srcArray = devArray1;
|
||||
myparams.dstArray = devArray2;
|
||||
myparams.extent = make_hipExtent(width, 1, 1);
|
||||
myparams.kind = hipMemcpyDeviceToDevice;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
|
||||
dependencies.size(), &myparams));
|
||||
dependencies.clear();
|
||||
dependencies.push_back(memcpyNode);
|
||||
|
||||
// Device to host
|
||||
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
|
||||
myparams.srcPos = make_hipPos(0, 0, 0);
|
||||
myparams.dstPos = make_hipPos(0, 0, 0);
|
||||
myparams.extent = make_hipExtent(width, 1, 1);
|
||||
myparams.dstPtr = make_hipPitchedPtr(harray1Dres, width * sizeof(int),
|
||||
width, 1);
|
||||
myparams.srcArray = devArray2;
|
||||
myparams.kind = hipMemcpyDeviceToHost;
|
||||
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
|
||||
dependencies.size(), &myparams));
|
||||
|
||||
// Instantiate and launch the graph
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph));
|
||||
|
||||
// Validate result
|
||||
for (int i = 0; i < XSIZE; i++) {
|
||||
if (harray1D[i] != harray1Dres[i]) {
|
||||
INFO("harray1D: " << harray1D[i] << " harray1Dres: " << harray1Dres[i]
|
||||
<< " mismatch at : " << i);
|
||||
REQUIRE(false);
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
HIP_CHECK(hipFreeArray(devArray1));
|
||||
HIP_CHECK(hipFreeArray(devArray2));
|
||||
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-220
|
||||
SECTION("Array from/to Device") { Memcpy3DArrayDeviceShell<async>(Memcpy3DWrapper<async, true>); }
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Functional Tests adds memcpy nodes of types H2D, D2D and D2H to graph
|
||||
* and verifies execution sequence by launching graph on default device.
|
||||
* Tests also verify memcpy node addition with 1D, 2D and 3D objects.
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Verify API behaviour with invalid arguments:
|
||||
* -# node is nullptr
|
||||
* -# graph is nullptr
|
||||
* -# pDependencies is nullptr when numDependencies is not zero
|
||||
* -# A node in pDependencies originates from a different graph
|
||||
* -# numDependencies is invalid
|
||||
* -# A node is duplicated in pDependencies
|
||||
* -# dst is nullptr
|
||||
* -# src is nullptr
|
||||
* -# kind is an invalid enum value
|
||||
* -# count is zero
|
||||
* -# count is larger than dst allocation size
|
||||
* -# count is larger than src allocation size
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/graph/hipGraphAddMemcpyNode.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipGraphAddMemcpyNode_BasicFunctional") {
|
||||
CHECK_IMAGE_SUPPORT
|
||||
TEST_CASE("Unit_hipGraphAddMemcpyNode_Negative_Parameters") {
|
||||
using namespace std::placeholders;
|
||||
|
||||
SECTION("Memcpy with 3D array on default device") {
|
||||
validateMemcpyNode3DArray();
|
||||
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) {
|
||||
hipGraph_t graph = nullptr;
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
hipGraphNode_t node = nullptr;
|
||||
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent, kind);
|
||||
GraphAddNodeCommonNegativeTests(std::bind(hipGraphAddMemcpyNode, _1, _2, _3, _4, ¶ms),
|
||||
graph);
|
||||
|
||||
SECTION("dst_ptr.ptr == nullptr") {
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.ptr = nullptr;
|
||||
auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_ptr.ptr == nullptr") {
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.ptr = nullptr;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_ptr.pitch < width") {
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.pitch = extent.width - 1;
|
||||
auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidPitchValue);
|
||||
}
|
||||
|
||||
SECTION("src_ptr.pitch < width") {
|
||||
hipPitchedPtr invalid_ptr = src_ptr;
|
||||
invalid_ptr.pitch = extent.width - 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidPitchValue);
|
||||
}
|
||||
|
||||
SECTION("dst_ptr.pitch > max pitch") {
|
||||
int attr = 0;
|
||||
HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0));
|
||||
hipPitchedPtr invalid_ptr = dst_ptr;
|
||||
invalid_ptr.pitch = attr;
|
||||
auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
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;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("extent.width + dst_pos.x > dst_ptr.pitch") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.x = dst_ptr.pitch - extent.width + 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("extent.width + src_pos.x > src_ptr.pitch") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.x = src_ptr.pitch - extent.width + 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_pos.y out of bounds") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.y = 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_pos.y out of bounds") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.y = 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("dst_pos.z out of bounds") {
|
||||
hipPos invalid_pos = dst_pos;
|
||||
invalid_pos.z = 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("src_pos.z out of bounds") {
|
||||
hipPos invalid_pos = src_pos;
|
||||
invalid_pos.z = 1;
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind);
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("Invalid MemcpyKind") {
|
||||
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent,
|
||||
static_cast<hipMemcpyKind>(-1));
|
||||
HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms),
|
||||
hipErrorInvalidMemcpyDirection);
|
||||
}
|
||||
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
};
|
||||
|
||||
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("Memcpy with 2D array on default device") {
|
||||
validateMemcpyNode2DArray();
|
||||
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("Memcpy with 1D array on default device") {
|
||||
validateMemcpyNode1DArray();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Peer access tests adds and assigns memcpy nodes of types H2D, D2D and D2H
|
||||
* to peer device. Memory allocations happen on device(0) and memcpy operations
|
||||
* are performed from device(1).
|
||||
* Tests also verify memcpy node addition with 1D, 2D and 3D objects.
|
||||
*/
|
||||
TEST_CASE("Unit_hipGraphAddMemcpyNode_PeerAccessFunctional") {
|
||||
CHECK_IMAGE_SUPPORT
|
||||
|
||||
int numDevices{}, peerAccess{};
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
if (numDevices > 1) {
|
||||
HIP_CHECK(hipDeviceCanAccessPeer(&peerAccess, 1, 0));
|
||||
}
|
||||
|
||||
if (!peerAccess) {
|
||||
WARN("Skipping test as peer device access is not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
SECTION("Memcpy with 3D array on peer device") {
|
||||
validateMemcpyNode3DArray(true);
|
||||
}
|
||||
|
||||
SECTION("Memcpy with 2D array on peer device") {
|
||||
validateMemcpyNode2DArray(true);
|
||||
}
|
||||
|
||||
SECTION("Memcpy with 1D array on peer device") {
|
||||
validateMemcpyNode1DArray(true);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Create two host pointers, copy the data between them by the api
|
||||
* hipGraphAddMemcpyNode with data transfer kind hipMemcpyHostToHost.
|
||||
* Validate the output.
|
||||
*/
|
||||
TEST_CASE("Unit_hipGraphAddMemcpyNode_HostToHost") {
|
||||
constexpr size_t size = 1024;
|
||||
size_t numW = size * sizeof(int);
|
||||
// Host Vectors
|
||||
std::vector<int> A_h(numW);
|
||||
std::vector<int> B_h(numW);
|
||||
// Initialization
|
||||
std::iota(A_h.begin(), A_h.end(), 0);
|
||||
std::fill_n(B_h.begin(), size, 0);
|
||||
|
||||
hipGraph_t graph;
|
||||
hipStream_t streamForGraph;
|
||||
hipGraphExec_t graphExec;
|
||||
hipGraphNode_t memcpyH2H;
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
|
||||
hipMemcpy3DParms myparms{};
|
||||
myparms.srcPos = make_hipPos(0, 0, 0);
|
||||
myparms.dstPos = make_hipPos(0, 0, 0);
|
||||
myparms.srcPtr = make_hipPitchedPtr(A_h.data(), numW, numW, 1);
|
||||
myparms.dstPtr = make_hipPitchedPtr(B_h.data(), numW, numW, 1);
|
||||
myparms.extent = make_hipExtent(numW, 1, 1);
|
||||
myparms.kind = hipMemcpyHostToHost;
|
||||
|
||||
// Host to Host
|
||||
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyH2H, graph, nullptr,
|
||||
0, &myparms));
|
||||
|
||||
// Instantiate and launch the graph
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph));
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
|
||||
// Validation
|
||||
REQUIRE(memcmp(A_h.data(), B_h.data(), numW) == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user