Rakesh Roy committed 2024-02-23 20:42:03 +05:30
commit 96df1fde80
117 files changed
+15062 -3874

No files matched your search

+8
View File
@@ -32,6 +32,7 @@ set(TEST_SRC
hipGraph.cc
hipSimpleGraphWithKernel.cc
hipGraphAddMemcpyNode.cc
hipGraphAddMemcpyNode_old.cc
hipGraphClone.cc
hipGraphInstantiateWithFlags.cc
hipGraphAddHostNode.cc
@@ -54,6 +55,7 @@ set(TEST_SRC
hipGraphAddMemcpyNode1D.cc
hipGraphAddChildGraphNode.cc
hipGraphNodeGetType.cc
hipGraphExecMemcpyNodeSetParams1D_old.cc
hipGraphExecMemcpyNodeSetParams1D.cc
hipGraphGetEdges.cc
hipGraphGetEdges_old.cc
@@ -71,7 +73,10 @@ set(TEST_SRC
hipGraphEventRecordNodeSetEvent.cc
hipGraphEventWaitNodeGetEvent.cc
hipGraphExecMemcpyNodeSetParams.cc
hipGraphExecMemcpyNodeSetParams_old.cc
hipStreamBeginCapture.cc
hipGraphAddMemcpyNode1D_old.cc
hipGraphAddMemcpyNode1D.cc
hipStreamBeginCapture_old.cc
hipStreamIsCapturing.cc
hipStreamIsCapturing_old.cc)
@@ -98,13 +103,16 @@ set(TEST_SRC
hipGraphAddMemsetNode.cc
hipGraphAddKernelNode.cc
hipGraphMemcpyNodeGetParams.cc
hipGraphMemcpyNodeGetParams_old.cc
hipGraphMemcpyNodeSetParams.cc
hipGraphMemcpyNodeSetParams_old.cc
hipGraphKernelNodeGetParams.cc
hipGraphKernelNodeSetParams.cc
hipGraphExecKernelNodeSetParams.cc
hipGraphLaunch.cc
hipGraphLaunch_old.cc
hipGraphMemcpyNodeSetParams1D.cc
hipGraphMemcpyNodeSetParams1D_old.cc
hipGraphExecMemcpyNodeSetParamsToSymbol_old.cc
hipGraphExecMemcpyNodeSetParamsToSymbol.cc
hipGraphNodeGetDependentNodes.cc
+243 -532
View File
@@ -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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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, &params),
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);
}
+152 -210
View File
@@ -6,237 +6,179 @@ 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 :
Functional -
1) Add 1D 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) Allocate memory on default device(Dev 0), Perform memcpy operation for 1D arrays on Peer device(Dev 1) and
verify the results.
3) Create two host pointers, copy the data between them by the api hipGraphAddMemcpyNode1D with data transfer
kind hipMemcpyHostToHost. Validate the output.
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 destination ptr is nullptr, api expected to return error code.
7) When source ptr is nullptr, api expected to return error code.
8) If count is more than allocated size for source and destination ptr, error code is returned.
9) If count is less than or equal to allocated size of source and destination ptr, api should return success.
*/
#include <functional>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <vector>
#include <numeric>
static void validateMemcpyNode1DArray(bool peerAccess) {
constexpr int SIZE{32};
int harray1D[SIZE]{};
int harray1Dres[SIZE]{};
hipGraph_t graph;
hipArray_t devArray1, devArray2;
hipGraphNode_t memcpyH2D, memcpyD2H, memcpyD2D;
constexpr int numBytes{SIZE * sizeof(int)};
hipStream_t streamForGraph;
hipGraphExec_t graphExec;
HIP_CHECK(hipSetDevice(0));
HIP_CHECK(hipStreamCreate(&streamForGraph));
HIP_CHECK(hipMalloc(&devArray1, numBytes));
HIP_CHECK(hipMalloc(&devArray2, numBytes));
// Initialize 1D object
for (int i = 0; i < SIZE; i++) {
harray1D[i] = i + 1;
}
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 (harray1D -> devArray1)
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph, nullptr, 0,
devArray1, harray1D, numBytes, hipMemcpyHostToDevice));
// Device to Device (devArray1 -> devArray2)
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2D, graph, &memcpyH2D, 1,
devArray2, devArray1, numBytes, hipMemcpyDeviceToDevice));
// Device to host (devArray2 -> harray1Dres)
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph, &memcpyD2D, 1,
harray1Dres, devArray2, numBytes, hipMemcpyDeviceToHost));
// 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 < SIZE; 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(hipFree(devArray1));
HIP_CHECK(hipFree(devArray2));
}
#include <hip_test_defgroups.hh>
#include <memcpy1d_tests_common.hh>
#include "graph_tests_common.hh"
/**
* Functional Tests adds memcpy 1D nodes of types H2D, D2D and D2H to graph
* and verifies execution sequence by launching graph.
*
* For Default device test: Memory allocations and memory operations
* are performed from device(0).
* For Peer device test: Memory allocations happen on device(0) and memcpy operations
* are performed from device(1).
* @addtogroup hipGraphAddMemcpyNode1D hipGraphAddMemcpyNode1D
* @{
* @ingroup GraphTest
* `hipGraphAddMemcpyNode1D(hipGraphNode_t *pGraphNode, hipGraph_t graph, const hipGraphNode_t
* *pDependencies, size_t numDependencies, void *dst, const void *src, size_t count, hipMemcpyKind
* kind)` - Creates a 1D memcpy node and adds it to a graph
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_Functional") {
SECTION("Memcpy with 1D array on default device") {
validateMemcpyNode1DArray(false);
}
SECTION("Memcpy with 1D array on peer device") {
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;
}
validateMemcpyNode1DArray(true);
}
}
/**
* Negative Test for API hipGraphAddMemcpyNode1D
* Test Description
* ------------------------
* - Verify basic API behavior. A Memcpy1D 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/hipGraphAddMemcpyNode1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
int *A_d, *A_h;
hipGraph_t graph;
hipGraphNode_t memcpyNode{};
hipError_t ret;
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_Positive_Basic") {
constexpr auto f = [](void* dst, void* src, size_t count, hipMemcpyKind direction) {
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t node = nullptr;
HIP_CHECK(hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dst, src, count, direction));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graph_exec, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipMalloc(&A_h, Nbytes));
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
return hipSuccess;
};
#if HT_NVIDIA
MemcpyWithDirectionCommonTests<false>(f);
#else
using namespace std::placeholders;
SECTION("Device to host") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToHost));
}
SECTION("Device to host with default kind") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Host to device") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToDevice));
}
SECTION("Host to device with default kind") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
// Disabled on AMD due to defect - EXSWHTEC-209
#if 0
SECTION("Host to host") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToHost));
}
SECTION("Host to host with default kind") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
SECTION("Device to device") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
}
SECTION("Device to device with default kind") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
}
#endif
}
/**
* 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/hipGraphAddMemcpyNode1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_Negative_Parameters") {
using namespace std::placeholders;
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t node = nullptr;
int src[2] = {}, dst[2] = {};
SECTION("Pass pGraphNode as nullptr") {
ret = hipGraphAddMemcpyNode1D(nullptr, graph,
nullptr, 0, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
GraphAddNodeCommonNegativeTests(
std::bind(hipGraphAddMemcpyNode1D, _1, _2, _3, _4, dst, src, sizeof(dst), hipMemcpyDefault),
graph);
MemcpyWithDirectionCommonNegativeTests(
std::bind(hipGraphAddMemcpyNode1D, &node, graph, nullptr, 0, _1, _2, _3, _4), dst, src,
sizeof(dst), hipMemcpyDefault);
// Disabled on AMD due to defect - EXSWHTEC-211
#if HT_NVIDIA
SECTION("count == 0") {
HIP_CHECK_ERROR(
hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dst, src, 0, hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass graph as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, nullptr,
nullptr, 0, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
#endif
SECTION("count larger than dst allocation size") {
LinearAllocGuard<int> dev_dst(LinearAllocs::hipMalloc, sizeof(int));
HIP_CHECK_ERROR(hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dev_dst.ptr(), src,
sizeof(src), hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass pDependencies as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
SECTION("count larger than src allocation size") {
LinearAllocGuard<int> dev_src(LinearAllocs::hipMalloc, sizeof(int));
HIP_CHECK_ERROR(hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dst, dev_src.ptr(),
sizeof(dst), hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass numDependencies is max and pDependencies is not valid ptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, INT_MAX, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pDependencies as nullptr, but numDependencies is non-zero") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 9, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass destination ptr as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, nullptr, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass source ptr as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, nullptr, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass count as more than allocated size for source ptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, A_h, Nbytes+10, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass count as less than allocated size for destination ptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, A_h, Nbytes-10, hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
}
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(A_h));
HIP_CHECK(hipGraphDestroy(graph));
}
/*
* Create two host pointers, copy the data between them by the api
* hipGraphAddMemcpyNode1D with data transfer kind hipMemcpyHostToHost.
* Validate the output.
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_HostToHost") {
constexpr size_t size = 1024;
size_t numBytes{size * sizeof(int)};
// Host Vectors
std::vector<int> A_h(size);
std::vector<int> B_h(size);
// 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));
// Host to Host
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2H, graph, nullptr, 0,
B_h.data(), A_h.data(), numBytes, hipMemcpyHostToHost));
// 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(std::equal(A_h.begin(), A_h.end(), B_h.begin(), B_h.end()));
}
@@ -0,0 +1,242 @@
/*
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
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
Testcase Scenarios :
Functional -
1) Add 1D 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) Allocate memory on default device(Dev 0), Perform memcpy operation for 1D arrays on Peer device(Dev 1) and
verify the results.
3) Create two host pointers, copy the data between them by the api hipGraphAddMemcpyNode1D with data transfer
kind hipMemcpyHostToHost. Validate the output.
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 destination ptr is nullptr, api expected to return error code.
7) When source ptr is nullptr, api expected to return error code.
8) If count is more than allocated size for source and destination ptr, error code is returned.
9) If count is less than or equal to allocated size of source and destination ptr, api should return success.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <vector>
#include <numeric>
static void validateMemcpyNode1DArray(bool peerAccess) {
constexpr int SIZE{32};
int harray1D[SIZE]{};
int harray1Dres[SIZE]{};
hipGraph_t graph;
hipArray_t devArray1, devArray2;
hipGraphNode_t memcpyH2D, memcpyD2H, memcpyD2D;
constexpr int numBytes{SIZE * sizeof(int)};
hipStream_t streamForGraph;
hipGraphExec_t graphExec;
HIP_CHECK(hipSetDevice(0));
HIP_CHECK(hipStreamCreate(&streamForGraph));
HIP_CHECK(hipMalloc(&devArray1, numBytes));
HIP_CHECK(hipMalloc(&devArray2, numBytes));
// Initialize 1D object
for (int i = 0; i < SIZE; i++) {
harray1D[i] = i + 1;
}
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 (harray1D -> devArray1)
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph, nullptr, 0,
devArray1, harray1D, numBytes, hipMemcpyHostToDevice));
// Device to Device (devArray1 -> devArray2)
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2D, graph, &memcpyH2D, 1,
devArray2, devArray1, numBytes, hipMemcpyDeviceToDevice));
// Device to host (devArray2 -> harray1Dres)
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph, &memcpyD2D, 1,
harray1Dres, devArray2, numBytes, hipMemcpyDeviceToHost));
// 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 < SIZE; 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(hipFree(devArray1));
HIP_CHECK(hipFree(devArray2));
}
/**
* Functional Tests adds memcpy 1D nodes of types H2D, D2D and D2H to graph
* and verifies execution sequence by launching graph.
*
* For Default device test: Memory allocations and memory operations
* are performed from device(0).
* For Peer device test: Memory allocations happen on device(0) and memcpy operations
* are performed from device(1).
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_Functional") {
SECTION("Memcpy with 1D array on default device") {
validateMemcpyNode1DArray(false);
}
SECTION("Memcpy with 1D array on peer device") {
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;
}
validateMemcpyNode1DArray(true);
}
}
/**
* Negative Test for API hipGraphAddMemcpyNode1D
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
int *A_d, *A_h;
hipGraph_t graph;
hipGraphNode_t memcpyNode{};
hipError_t ret;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipMalloc(&A_h, Nbytes));
HIP_CHECK(hipGraphCreate(&graph, 0));
SECTION("Pass pGraphNode as nullptr") {
ret = hipGraphAddMemcpyNode1D(nullptr, graph,
nullptr, 0, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass graph as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, nullptr,
nullptr, 0, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pDependencies as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass numDependencies is max and pDependencies is not valid ptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, INT_MAX, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pDependencies as nullptr, but numDependencies is non-zero") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 9, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass destination ptr as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, nullptr, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass source ptr as nullptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, nullptr, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass count as more than allocated size for source ptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, A_h, Nbytes+10, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass count as less than allocated size for destination ptr") {
ret = hipGraphAddMemcpyNode1D(&memcpyNode, graph,
nullptr, 0, A_d, A_h, Nbytes-10, hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
}
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(A_h));
HIP_CHECK(hipGraphDestroy(graph));
}
/*
* Create two host pointers, copy the data between them by the api
* hipGraphAddMemcpyNode1D with data transfer kind hipMemcpyHostToHost.
* Validate the output.
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode1D_HostToHost") {
constexpr size_t size = 1024;
size_t numBytes{size * sizeof(int)};
// Host Vectors
std::vector<int> A_h(size);
std::vector<int> B_h(size);
// 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));
// Host to Host
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2H, graph, nullptr, 0,
B_h.data(), A_h.data(), numBytes, hipMemcpyHostToHost));
// 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(std::equal(A_h.begin(), A_h.end(), B_h.begin(), B_h.end()));
}
@@ -0,0 +1,576 @@
/*
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
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
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 <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <vector>
#include <numeric>
#define ZSIZE 32
#define YSIZE 32
#define XSIZE 32
/* Test verifies hipGraphAddMemcpyNode API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphAddMemcpyNode_Negative") {
CHECK_IMAGE_SUPPORT
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;
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));
HIP_CHECK(hipGraphCreate(&graph, 0));
// 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;
}
}
}
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;
}
}
}
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));
// 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));
}
/**
* 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_CASE("Unit_hipGraphAddMemcpyNode_BasicFunctional") {
CHECK_IMAGE_SUPPORT
SECTION("Memcpy with 3D array on default device") {
validateMemcpyNode3DArray();
}
SECTION("Memcpy with 2D array on default device") {
validateMemcpyNode2DArray();
}
SECTION("Memcpy with 1D array on default device") {
validateMemcpyNode1DArray();
}
}
/**
* 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);
}
@@ -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
@@ -17,247 +20,248 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
Testcase Scenarios :
Functional-
1) Instantiate a graph with memcpy node, obtain executable graph and update the hipMemcpy3DParms node params with set. Make sure they are taking effect.
Negative-
1) Pass hGraphExec as nullptr and verify api returns error code.
2) Pass node as nullptr and verify api returns error code.
3) Pass pNodeParams as nullptr and verify api returns error code.
4) Pass pNodeParams as empty structure object and verify api returns error code.
5) 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.
6) 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.
7) Passing different element size for hipMemcpy3DParms::srcArray and hipMemcpy3DParms::dstArray is expected to return error code.
8) Pass node of different graph and verify api returns error code.
*/
#include <functional>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_defgroups.hh>
#include <memcpy1d_tests_common.hh>
#include <memcpy3d_tests_common.hh>
/* Test verifies hipGraphExecMemcpyNodeSetParams API Negative scenarios.
#include "graph_tests_common.hh"
/**
* @addtogroup hipGraphExecMemcpyNodeSetParams hipGraphExecMemcpyNodeSetParams
* @{
* @ingroup GraphTest
* `hipGraphExecMemcpyNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node, hipMemcpy3DParms
* *pNodeParams)` - Sets the parameters for a memcpy node in the given graphExec
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams_Negative") {
CHECK_IMAGE_SUPPORT
constexpr int width{10}, height{10}, depth{10};
hipArray_t devArray, devArray2;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
hipError_t ret;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
/**
* Test Description
* ------------------------
* - Verify that node parameters get updated correctly by creating a node with valid but
* incorrect parameters, and the setting them to the correct values in the executable graph. The
* executable graph is run and the results of the memcpy 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/hipGraphExecMemcpyNodeSetParams.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams_Positive_Basic") {
constexpr auto f = [](void* dst, void* src, size_t count, hipMemcpyKind direction) {
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t node = nullptr;
const auto offset_src = reinterpret_cast<uint8_t*>(src) + 1;
const auto offset_dst = reinterpret_cast<uint8_t*>(dst) + 1;
auto params =
GetMemcpy3DParms(make_hipPitchedPtr(offset_dst, 0, count - 1, 0), make_hipPos(0, 0, 0),
make_hipPitchedPtr(offset_src, 0, count - 1, 0), make_hipPos(0, 0, 0),
make_hipExtent(count - 1, 1, 1), direction);
HIP_CHECK(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, &params));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
params = GetMemcpy3DParms(make_hipPitchedPtr(dst, 0, count, 0), make_hipPos(0, 0, 0),
make_hipPitchedPtr(src, 0, count, 0), make_hipPos(0, 0, 0),
make_hipExtent(count, 1, 1), direction);
HIP_CHECK(hipGraphExecMemcpyNodeSetParams(graph_exec, node, &params));
HIP_CHECK(hipGraphLaunch(graph_exec, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
return hipSuccess;
};
#if HT_NVIDIA
MemcpyWithDirectionCommonTests<false>(f);
#else
using namespace std::placeholders;
SECTION("Device to host") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToHost));
}
SECTION("Host to device") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToDevice));
}
SECTION("Device to device") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
HIP_CHECK(hipMalloc3DArray(&devArray2, &channelDesc, make_hipExtent(width+1,
height+1, depth+1), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipGraphNode_t memcpyNode;
hipGraphExec_t graphExec;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
// Instantiate the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
SECTION("Pass hGraphExec as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams(nullptr, memcpyNode, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass node as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams(graphExec, nullptr, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pNodeParams as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pNodeParams as empty structure object") {
hipMemcpy3DParms temp{};
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("API expects atleast one memcpy src pointer to be set") {
hipMemcpy3DParms temp;
memset(&temp, 0x0, sizeof(hipMemcpy3DParms));
temp.srcPos = make_hipPos(0, 0, 0);
temp.dstPos = make_hipPos(0, 0, 0);
temp.extent = make_hipExtent(width , height, depth);
temp.dstArray = devArray;
temp.kind = hipMemcpyHostToDevice;
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("API expects atleast one memcpy dst pointer to be set") {
hipMemcpy3DParms temp;
memset(&temp, 0x0, sizeof(hipMemcpy3DParms));
temp.srcPos = make_hipPos(0, 0, 0);
temp.dstPos = make_hipPos(0, 0, 0);
temp.extent = make_hipExtent(width , height, depth);
temp.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
temp.kind = hipMemcpyHostToDevice;
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Passing different element size for hipMemcpy3DParms::srcArray"
"and hipMemcpy3DParms::dstArray") {
hipMemcpy3DParms temp;
memset(&temp, 0x0, sizeof(hipMemcpy3DParms));
temp.srcPos = make_hipPos(0, 0, 0);
temp.dstPos = make_hipPos(0, 0, 0);
temp.extent = make_hipExtent(width , height, depth);
temp.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
temp.kind = hipMemcpyHostToDevice;
temp.srcArray = devArray;
temp.dstArray = devArray2;
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Check with other graph node") {
hipGraph_t graph1;
hipGraphNode_t memcpyNode1;
HIP_CHECK(hipGraphCreate(&graph1, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode1, graph1, NULL, 0, &myparms));
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode1, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
HIP_CHECK(hipGraphDestroy(graph1));
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipFreeArray(devArray));
HIP_CHECK(hipFreeArray(devArray2));
free(hData);
}
/* Test verifies hipGraphExecMemcpyNodeSetParams API Functional scenarios.
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams_Functional") {
CHECK_IMAGE_SUPPORT
constexpr int XSIZE = 1024;
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(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));
// 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 the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
int harray1Dupdate[XSIZE]{};
hipArray_t devArray3;
HIP_CHECK(hipMalloc3DArray(&devArray3, &channelDesc,
make_hipExtent(width, 0, 0), hipArrayDefault));
// D2H updated with different pointer harray1Dres -> harray1Dupdate
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(harray1Dupdate, width * sizeof(int),
width, 1);
myparams.srcArray = devArray2;
myparams.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &myparams));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
// Validate result
for (int i = 0; i < XSIZE; i++) {
if (harray1D[i] != harray1Dupdate[i]) {
INFO("harray1D: " << harray1D[i] << " harray1Dupdate: " <<
harray1Dupdate[i] << " mismatch at : " << i);
REQUIRE(false);
SECTION("Device to device with default kind") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipFreeArray(devArray1));
HIP_CHECK(hipFreeArray(devArray2));
// Disabled on AMD due to defect - EXSWHTEC-209
#if 0
SECTION("Host to host") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToHost));
}
SECTION("Host to host with default kind") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
// Disabled on AMD due to defect - EXSWHTEC-210
#if 0
SECTION("Device to host with default kind") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Host to device with default kind") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
#endif
}
/**
* Test Description
* ------------------------
* - Verify API behaviour with invalid arguments:
* -# pGraphExec is nullptr
* -# 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_hipGraphExecMemcpyNodeSetParams_Negative_Parameters") {
using namespace std::placeholders;
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
int src[2] = {}, dst[2] = {};
auto params = GetMemcpy3DParms(make_hipPitchedPtr(dst, 0, sizeof(dst), 0), make_hipPos(0, 0, 0),
make_hipPitchedPtr(src, 0, sizeof(src), 0), make_hipPos(0, 0, 0),
make_hipExtent(sizeof(dst), 1, 1), hipMemcpyDefault);
hipGraphNode_t node = nullptr;
HIP_CHECK(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, &params));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
SECTION("pGraphExec == nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(nullptr, node, &params), hipErrorInvalidValue);
}
SECTION("node == nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, nullptr, &params),
hipErrorInvalidValue);
}
auto f = [&](void* dst, void* src, size_t count, hipMemcpyKind kind) {
auto params = GetMemcpy3DParms(make_hipPitchedPtr(dst, 0, sizeof(dst), 0), make_hipPos(0, 0, 0),
make_hipPitchedPtr(src, 0, sizeof(src), 0), make_hipPos(0, 0, 0),
make_hipExtent(count, 1, 1), kind);
return hipGraphExecMemcpyNodeSetParams(graph_exec, node, &params);
};
MemcpyWithDirectionCommonNegativeTests(f, dst, src, sizeof(dst), hipMemcpyDefault);
SECTION("count == 0") {
HIP_CHECK_ERROR(
hipGraphExecMemcpyNodeSetParams1D(graph_exec, node, dst, src, 0, hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("count larger than dst allocation size") {
LinearAllocGuard<int> dev_dst(LinearAllocs::hipMalloc, sizeof(int));
params.dstPtr = make_hipPitchedPtr(dev_dst.ptr(), 0, sizeof(int), 0);
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, node, &params),
hipErrorInvalidValue);
}
SECTION("count larger than src allocation size") {
LinearAllocGuard<int> dev_src(LinearAllocs::hipMalloc, sizeof(int));
params.dstPtr = make_hipPitchedPtr(dev_src.ptr(), 0, sizeof(int), 0);
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, node, &params),
hipErrorInvalidValue);
}
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
}
/**
* Test Description
* ------------------------
* - Verify that memcpy direction cannot be altered in an executable graph. The test is run for
* all memcpy directions with appropriate memory allocations.
* Test source
* ------------------------
* - unit/graph/hipGraphExecMemcpyNodeSetParams.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams_Negative_Changing_Memcpy_Direction") {
int host;
LinearAllocGuard<int> dev(LinearAllocs::hipMalloc, sizeof(int));
const auto [dir, src, dst] =
GENERATE_REF(std::make_tuple(hipMemcpyHostToHost, &host, &host),
std::make_tuple(hipMemcpyHostToDevice, &host, dev.ptr()),
std::make_tuple(hipMemcpyDeviceToHost, dev.ptr(), &host),
std::make_tuple(hipMemcpyDeviceToDevice, dev.ptr(), dev.ptr()));
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
auto params = GetMemcpy3DParms(make_hipPitchedPtr(dst, 0, sizeof(int), 0), make_hipPos(0, 0, 0),
make_hipPitchedPtr(src, 0, sizeof(int), 0), make_hipPos(0, 0, 0),
make_hipExtent(sizeof(int), 1, 1), dir);
hipGraphNode_t node = nullptr;
HIP_CHECK(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, &params));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
const auto set_dir = GENERATE(hipMemcpyHostToHost, hipMemcpyHostToDevice, hipMemcpyDeviceToHost,
hipMemcpyDeviceToDevice, hipMemcpyDefault);
if (dir == set_dir) {
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
return;
}
params.kind = set_dir;
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, node, &params), hipErrorInvalidValue);
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
}
@@ -6,8 +6,10 @@ 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
@@ -17,182 +19,235 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Testcase Scenarios :
Functional-
1) Instantiate a graph with memcpy node, obtain executable graph and update the
node params with set exec api call. Make sure they are taking effect.
Negative-
1) Pass hGraphExec as nullptr and check if api returns error.
2) Pass GraphNode as nullptr and check if api returns error.
3) Pass destination ptr is nullptr, api expected to return error code.
4) Pass source ptr is nullptr, api expected to return error code.
5) Pass count as zero, api expected to return error code.
6) Pass same pointer as source ptr and destination ptr, api expected to return error code.
7) Pass overlap memory address as source ptr and destination ptr, api expected to return error code.
7) Pass overlap memory as source ptr and destination ptr where source ptr is ahead of destination ptr, api expected to return error code.
8) Pass overlap memory as source ptr and destination ptr where destination ptr is ahead of source ptr, api expected to return error code.
9) If count is more than allocated size for source and destination ptr, api should return error code.
10) If count is less than allocated size for source and destination ptr, api should return error code.
11) Change the hipMemcpyKind from H2D to D2H but allocate pointer memory for H2D, api should return error code.
*/
#include <functional>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
#include <hip_test_defgroups.hh>
#include <memcpy1d_tests_common.hh>
/* Test verifies hipGraphExecMemcpyNodeSetParams1D API Negative scenarios.
#include "graph_tests_common.hh"
/**
* @addtogroup hipGraphExecMemcpyNodeSetParams1D hipGraphExecMemcpyNodeSetParams1D
* @{
* @ingroup GraphTest
* `hipGraphExecMemcpyNodeSetParams1D(hipGraphExec_t hGraphExec, hipGraphNode_t node, void *dst,
* const void *src, size_t count, hipMemcpyKind kind)` - Sets the parameters for a memcpy node in
* the given graphExec to perform a 1-dimensional copy
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
int *A_d;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
int *A_h = reinterpret_cast<int*>(malloc(Nbytes));
REQUIRE(A_h != nullptr);
memset(A_h, 0, Nbytes);
/**
* Test Description
* ------------------------
* - Verify that node parameters get updated correctly by creating a node with valid but
* incorrect parameters, and the setting them to the correct values in the executable graph. The
* executable graph is run and the results of the memcpy 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/hipGraphExecMemcpyNodeSetParams1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Positive_Basic") {
constexpr auto f = [](void* dst, void* src, size_t count, hipMemcpyKind direction) {
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t node = nullptr;
const auto offset_src = reinterpret_cast<uint8_t*>(src) + 1;
const auto offset_dst = reinterpret_cast<uint8_t*>(dst) + 1;
HIP_CHECK(hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, offset_dst, offset_src, count - 1,
direction));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphExecMemcpyNodeSetParams1D(graph_exec, node, dst, src, count, direction));
HIP_CHECK(hipGraphLaunch(graph_exec, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
hipError_t ret;
hipGraphNode_t memcpyH2D;
hipGraph_t graph;
hipGraphExec_t graphExec;
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
return hipSuccess;
};
#if HT_NVIDIA
MemcpyWithDirectionCommonTests<false>(f);
#else
using namespace std::placeholders;
SECTION("Device to host") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToHost));
}
SECTION("Host to device") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToDevice));
}
SECTION("Device to device") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
}
SECTION("Device to device with default kind") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
}
// Disabled on AMD due to defect - EXSWHTEC-209
#if 0
SECTION("Host to host") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToHost));
}
SECTION("Host to host with default kind") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
// Disabled on AMD due to defect - EXSWHTEC-210
#if 0
SECTION("Device to host with default kind") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Host to device with default kind") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
#endif
}
/**
* Test Description
* ------------------------
* - Verify API behaviour with invalid arguments:
* -# pGraphExec is nullptr
* -# 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/hipGraphAddMemcpyNode1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Negative_Parameters") {
using namespace std::placeholders;
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
// Instantiate the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
SECTION("Pass hGraphExec as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(nullptr, memcpyH2D, A_d, A_h,
Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
int src[2] = {}, dst[2] = {};
hipGraphNode_t node = nullptr;
HIP_CHECK(
hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dst, src, sizeof(dst), hipMemcpyDefault));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
SECTION("pGraphExec == nullptr") {
HIP_CHECK_ERROR(
hipGraphExecMemcpyNodeSetParams1D(nullptr, node, dst, src, sizeof(dst), hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass GraphNode as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, nullptr, A_d, A_h,
Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("node == nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graph_exec, nullptr, dst, src, sizeof(dst),
hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass destination ptr is nullptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, nullptr, A_h,
Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
MemcpyWithDirectionCommonNegativeTests(
std::bind(hipGraphExecMemcpyNodeSetParams1D, graph_exec, node, _1, _2, _3, _4), dst, src,
sizeof(dst), hipMemcpyDefault);
SECTION("count == 0") {
HIP_CHECK_ERROR(
hipGraphExecMemcpyNodeSetParams1D(graph_exec, node, dst, src, 0, hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass source ptr is nullptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, nullptr,
Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("count larger than dst allocation size") {
LinearAllocGuard<int> dev_dst(LinearAllocs::hipMalloc, sizeof(int));
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graph_exec, node, dev_dst.ptr(), src,
sizeof(src), hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass count as zero") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, A_h,
0, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("count larger than src allocation size") {
LinearAllocGuard<int> dev_src(LinearAllocs::hipMalloc, sizeof(int));
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graph_exec, node, dst, dev_src.ptr(),
sizeof(dst), hipMemcpyDefault),
hipErrorInvalidValue);
}
SECTION("Pass same pointer as source ptr and destination ptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, A_d,
Nbytes, hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass overlap memory where destination ptr is ahead of source ptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, A_d-5,
Nbytes, hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass overlap memory where source ptr is ahead of destination ptr") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d+5, A_d,
Nbytes, hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Copy more than allocated memory") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, A_h,
Nbytes+8, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Copy less than allocated memory") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, A_h,
Nbytes-8, hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
}
SECTION("Change the hipMemcpyKind from H2D to D2H") {
ret = hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d, A_h,
Nbytes, hipMemcpyDeviceToHost);
REQUIRE(hipSuccess != ret);
}
HIP_CHECK(hipFree(A_d));
free(A_h);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
}
/* Test verifies hipGraphExecMemcpyNodeSetParams1D API Functional scenarios.
/**
* Test Description
* ------------------------
* - Verify that memcpy direction cannot be altered in an executable graph. The test is run for
* all memcpy directions with appropriate memory allocations.
* Test source
* ------------------------
* - unit/graph/hipGraphExecMemcpyNodeSetParams1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Negative_Changing_Memcpy_Direction") {
int host;
LinearAllocGuard<int> dev(LinearAllocs::hipMalloc, sizeof(int));
int *hData = reinterpret_cast<int*>(malloc(Nbytes));
REQUIRE(hData != nullptr);
memset(hData, 0, Nbytes);
hipGraphNode_t memcpyH2D_A, memcpyH2D_B, memcpyD2H_C;
hipGraphNode_t kernel_vecAdd;
hipKernelNodeParams kernelNodeParams{};
hipGraph_t graph;
hipGraphExec_t graphExec;
hipStream_t streamForGraph;
HIP_CHECK(hipStreamCreate(&streamForGraph));
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
const auto [dir, src, dst] =
GENERATE_REF(std::make_tuple(hipMemcpyHostToHost, &host, &host),
std::make_tuple(hipMemcpyHostToDevice, &host, dev.ptr()),
std::make_tuple(hipMemcpyDeviceToHost, dev.ptr(), &host),
std::make_tuple(hipMemcpyDeviceToDevice, dev.ptr(), dev.ptr()));
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
hipGraphNode_t node = nullptr;
HIP_CHECK(hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dst, src, sizeof(int), dir));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
const auto set_dir = GENERATE(hipMemcpyHostToHost, hipMemcpyHostToDevice, hipMemcpyDeviceToHost,
hipMemcpyDeviceToDevice, hipMemcpyDefault);
if (dir == set_dir) {
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
return;
}
void* kernelArgs2[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kernelNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks);
kernelNodeParams.blockDim = dim3(threadsPerBlock);
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs2);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kernelNodeParams));
HIP_CHECK_ERROR(
hipGraphExecMemcpyNodeSetParams1D(graph_exec, node, dst, src, sizeof(int), set_dir),
hipErrorInvalidValue);
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpyD2H_C, 1));
// Instantiate the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyD2H_C, hData,
C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
// Verify graph execution result
HipTest::checkVectorADD(A_h, B_h, hData, N);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
free(hData);
}
@@ -0,0 +1,201 @@
/*
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.
*/
/*
Testcase Scenarios :
Functional-
1) Instantiate a graph with memcpy node, obtain executable graph and update the
node params with set exec api call. Make sure they are taking effect.
Negative-
1) Pass hGraphExec as nullptr and check if api returns error.
2) Pass GraphNode as nullptr and check if api returns error.
3) Pass destination ptr is nullptr, api expected to return error code.
4) Pass source ptr is nullptr, api expected to return error code.
5) Pass count as zero, api expected to return error code.
6) Pass same pointer as source ptr and destination ptr, api expected to return error code.
7) Pass overlap memory address as source ptr and destination ptr, api expected to return error code.
7) Pass overlap memory as source ptr and destination ptr where source ptr is ahead of destination ptr, api expected to return error code.
8) Pass overlap memory as source ptr and destination ptr where destination ptr is ahead of source ptr, api expected to return error code.
9) If count is more than allocated size for source and destination ptr, api should return error code.
10) If count is less than allocated size for source and destination ptr, api should return error code.
11) Change the hipMemcpyKind from H2D to D2H but allocate pointer memory for H2D, api should return error code.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
#include <memcpy1d_tests_common.hh>
/* Test verifies hipGraphExecMemcpyNodeSetParams1D API Functional scenarios.
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
int *hData = reinterpret_cast<int*>(malloc(Nbytes));
REQUIRE(hData != nullptr);
memset(hData, 0, Nbytes);
hipGraphNode_t memcpyH2D_A, memcpyH2D_B, memcpyD2H_C;
hipGraphNode_t kernel_vecAdd;
hipKernelNodeParams kernelNodeParams{};
hipGraph_t graph;
hipGraphExec_t graphExec;
hipStream_t streamForGraph;
HIP_CHECK(hipStreamCreate(&streamForGraph));
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs2[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kernelNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks);
kernelNodeParams.blockDim = dim3(threadsPerBlock);
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs2);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kernelNodeParams));
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpyD2H_C, 1));
// Instantiate the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyD2H_C, hData,
C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
// Verify graph execution result
HipTest::checkVectorADD(A_h, B_h, hData, N);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipGraphDestroy(graph));
free(hData);
}
/* Test verifies hipGraphExecMemcpyNodeSetParams1D API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams1D_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
LinearAllocGuard<int> A_d(LinearAllocs::hipMalloc, Nbytes);
LinearAllocGuard<int> A_h(LinearAllocs::malloc, Nbytes);
memset(A_h.ptr(), 0, Nbytes);
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t memcpyH2D;
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph, nullptr, 0, A_d.ptr(), A_h.ptr(),
Nbytes, hipMemcpyHostToDevice));
// Instantiate the graph
hipGraphExec_t graphExec;
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
SECTION("Pass hGraphExec as nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(nullptr, memcpyH2D, A_d.ptr(),
A_h.ptr(), Nbytes,
hipMemcpyHostToDevice),
hipErrorInvalidValue);
}
SECTION("Pass GraphNode as nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, nullptr, A_d.ptr(),
A_h.ptr(), Nbytes,
hipMemcpyHostToDevice),
hipErrorInvalidValue);
}
SECTION("Pass destination ptr is nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D,
nullptr, A_h.ptr(), Nbytes,
hipMemcpyHostToDevice),
hipErrorInvalidValue);
}
SECTION("Pass source ptr is nullptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d.ptr(),
nullptr, Nbytes,
hipMemcpyHostToDevice),
hipErrorInvalidValue);
}
SECTION("Pass count as zero") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d.ptr(),
A_h.ptr(), 0,
hipMemcpyHostToDevice),
hipErrorInvalidValue);
}
SECTION("Pass same pointer as source ptr and destination ptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d.ptr(),
A_d.ptr(), Nbytes,
hipMemcpyDeviceToDevice),
hipErrorInvalidValue);
}
SECTION("Pass overlap memory where destination ptr is ahead of source ptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d.ptr(),
A_d.ptr() - 5, Nbytes,
hipMemcpyDeviceToDevice),
hipErrorInvalidValue);
}
SECTION("Pass overlap memory where source ptr is ahead of destination ptr") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D,
A_d.ptr() + 5, A_d.ptr(), Nbytes,
hipMemcpyDeviceToDevice),
hipErrorInvalidValue);
}
SECTION("Copy more than allocated memory") {
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams1D(graphExec, memcpyH2D, A_d.ptr(),
A_h.ptr(), Nbytes + 8,
hipMemcpyHostToDevice),
hipErrorInvalidValue);
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
}
@@ -0,0 +1,263 @@
/*
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.
*/
/**
Testcase Scenarios :
Functional-
1) Instantiate a graph with memcpy node, obtain executable graph and update the hipMemcpy3DParms node params with set. Make sure they are taking effect.
Negative-
1) Pass hGraphExec as nullptr and verify api returns error code.
2) Pass node as nullptr and verify api returns error code.
3) Pass pNodeParams as nullptr and verify api returns error code.
4) Pass pNodeParams as empty structure object and verify api returns error code.
5) 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.
6) 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.
7) Passing different element size for hipMemcpy3DParms::srcArray and hipMemcpy3DParms::dstArray is expected to return error code.
8) Pass node of different graph and verify api returns error code.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
/* Test verifies hipGraphExecMemcpyNodeSetParams API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams_Negative") {
CHECK_IMAGE_SUPPORT
constexpr int width{10}, height{10}, depth{10};
hipArray_t devArray, devArray2;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
hipError_t ret;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
HIP_CHECK(hipMalloc3DArray(&devArray2, &channelDesc, make_hipExtent(width+1,
height+1, depth+1), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipGraphNode_t memcpyNode;
hipGraphExec_t graphExec;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
// Instantiate the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
SECTION("Pass hGraphExec as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams(nullptr, memcpyNode, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass node as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams(graphExec, nullptr, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pNodeParams as nullptr") {
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass pNodeParams as empty structure object") {
hipMemcpy3DParms temp{};
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("API expects atleast one memcpy src pointer to be set") {
hipMemcpy3DParms temp;
memset(&temp, 0x0, sizeof(hipMemcpy3DParms));
temp.srcPos = make_hipPos(0, 0, 0);
temp.dstPos = make_hipPos(0, 0, 0);
temp.extent = make_hipExtent(width , height, depth);
temp.dstArray = devArray;
temp.kind = hipMemcpyHostToDevice;
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("API expects atleast one memcpy dst pointer to be set") {
hipMemcpy3DParms temp;
memset(&temp, 0x0, sizeof(hipMemcpy3DParms));
temp.srcPos = make_hipPos(0, 0, 0);
temp.dstPos = make_hipPos(0, 0, 0);
temp.extent = make_hipExtent(width , height, depth);
temp.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
temp.kind = hipMemcpyHostToDevice;
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Passing different element size for hipMemcpy3DParms::srcArray"
"and hipMemcpy3DParms::dstArray") {
hipMemcpy3DParms temp;
memset(&temp, 0x0, sizeof(hipMemcpy3DParms));
temp.srcPos = make_hipPos(0, 0, 0);
temp.dstPos = make_hipPos(0, 0, 0);
temp.extent = make_hipExtent(width , height, depth);
temp.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
temp.kind = hipMemcpyHostToDevice;
temp.srcArray = devArray;
temp.dstArray = devArray2;
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &temp);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Check with other graph node") {
hipGraph_t graph1;
hipGraphNode_t memcpyNode1;
HIP_CHECK(hipGraphCreate(&graph1, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode1, graph1, NULL, 0, &myparms));
ret = hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode1, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
HIP_CHECK(hipGraphDestroy(graph1));
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipFreeArray(devArray));
HIP_CHECK(hipFreeArray(devArray2));
free(hData);
}
/* Test verifies hipGraphExecMemcpyNodeSetParams API Functional scenarios.
*/
TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParams_Functional") {
CHECK_IMAGE_SUPPORT
constexpr int XSIZE = 1024;
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(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));
// 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 the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
int harray1Dupdate[XSIZE]{};
hipArray_t devArray3;
HIP_CHECK(hipMalloc3DArray(&devArray3, &channelDesc,
make_hipExtent(width, 0, 0), hipArrayDefault));
// D2H updated with different pointer harray1Dres -> harray1Dupdate
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(harray1Dupdate, width * sizeof(int),
width, 1);
myparams.srcArray = devArray2;
myparams.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphExecMemcpyNodeSetParams(graphExec, memcpyNode, &myparams));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
// Validate result
for (int i = 0; i < XSIZE; i++) {
if (harray1D[i] != harray1Dupdate[i]) {
INFO("harray1D: " << harray1D[i] << " harray1Dupdate: " <<
harray1Dupdate[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));
}
@@ -1,13 +1,16 @@
/*
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 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
@@ -18,178 +21,66 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
/**
* @addtogroup hipGraphKernelNodeGetAttribute hipGraphKernelNodeGetAttribute
* @{
* @ingroup GraphTest
* `hipGraphKernelNodeGetAttribute(hipGraphNode_t hNode,
* hipKernelNodeAttrID attr, hipKernelNodeAttrValue* value_out )` -
* Queries node attribute.
*/
#define THREADS_PER_BLOCK 512
/**
* Test Description
* ------------------------
*  - Functional Test for API - hipGraphKernelNodeGetAttribute
* 1) GetKernelAttribute for ID hipKernelNodeAttributeCooperative
* 2) GetKernelAttribute for ID hipKernelNodeAttributeAccessPolicyWindow
* Test source
* ------------------------
*  - unit/graph/hipGraphKernelNodeGetAttribute.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipGraphKernelNodeGetAttribute_Negative_Parameters") {
constexpr int N = 1024;
TEST_CASE("Unit_hipGraphKernelNodeGetAttribute_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
hipGraph_t graph;
hipGraphExec_t graphExec;
hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kernel_vecAdd;
hipKernelNodeParams kNodeParams{};
hipStream_t stream;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
HIP_CHECK(hipMalloc(&A_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&B_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&C_d, sizeof(int) * N));
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(blocks);
kNodeParams.blockDim = dim3(threadsPerBlock);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kNodeParams));
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpy_C, 1));
hipKernelNodeAttrValue value_out;
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
SECTION("GetKernelAttribute for hipKernelNodeAttributeCooperative") {
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeCooperative, &value_out));
}
SECTION("GetKernelAttribute for hipKernelNodeAttributeAccessPolicyWindow") {
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
}
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify graph execution result
HipTest::checkVectorADD<int>(A_h, B_h, C_h, N);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Test Description
* ------------------------
*  - Negative Test for API - hipGraphKernelNodeGetAttribute
* 1) Pass kernel node as nullptr for Get attribute api & verify
* 2) Pass KernelNodeAttrID as negative value for Get attribute api & verify
* 3) Pass KernelNodeAttrID as INT_MAX value for Get attribute api & verify
* 4) Pass KernelNodeAttrValue as nullptr for Get attribute api & verify
* Test source
* ------------------------
*  - unit/graph/hipGraphKernelNodeGetAttribute.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipGraphKernelNodeGetAttribute_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
hipGraph_t graph;
hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kernel_vecAdd;
hipKernelNodeParams kNodeParams{};
hipStream_t stream;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
hipError_t ret;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(blocks);
kNodeParams.blockDim = dim3(threadsPerBlock);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kNodeParams));
hipKernelNodeParams node_params{};
node_params.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
node_params.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
node_params.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
hipKernelNodeAttrValue value_out;
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
size_t N_elem{N};
void* kernel_params[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&N_elem)};
node_params.kernelParams = reinterpret_cast<void**>(kernel_params);
SECTION("Pass kernel node as nullptr for Get attribute api") {
ret = hipGraphKernelNodeGetAttribute(nullptr,
hipKernelNodeAttributeAccessPolicyWindow, &value_out);
REQUIRE(hipErrorInvalidValue == ret);
hipGraphNode_t graph_node;
HIP_CHECK(hipGraphAddKernelNode(&graph_node, graph, nullptr, 0, &node_params));
hipKernelNodeAttrValue node_attribute;
SECTION("node == nullptr") {
HIP_CHECK_ERROR(hipGraphKernelNodeGetAttribute(
nullptr, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("Pass KernelNodeAttrID as negative value for Get attribute api") {
ret = hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttrID(-1), &value_out);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("node is not a kernel node") {
hipGraphNode_t empty_node;
HIP_CHECK(hipGraphAddEmptyNode(&empty_node, graph, nullptr, 0));
HIP_CHECK_ERROR(hipGraphKernelNodeGetAttribute(
empty_node, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("Pass KernelNodeAttrID as INT_MAX value for Get attribute api") {
ret = hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttrID(INT_MAX), &value_out);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("invalid attribute") {
HIP_CHECK_ERROR(hipGraphKernelNodeGetAttribute(graph_node, static_cast<hipKernelNodeAttrID>(-1),
&node_attribute),
hipErrorInvalidValue);
}
#if HT_AMD // getting SIGSEGV error in Cuda Setup
SECTION("Pass KernelNodeAttrValue as nullptr for Get attribute api") {
ret = hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
#if HT_AMD // segfaults on NVIDIA
SECTION("value == nullptr") {
HIP_CHECK_ERROR(hipGraphKernelNodeGetAttribute(
graph_node, hipKernelNodeAttributeAccessPolicyWindow, nullptr),
hipErrorInvalidValue);
}
#endif
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(B_d));
HIP_CHECK(hipFree(C_d));
}
+179 -315
View File
@@ -1,13 +1,16 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 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
@@ -18,353 +21,214 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
/**
* @addtogroup hipGraphKernelNodeSetAttribute hipGraphKernelNodeSetAttribute
* @{
* @ingroup GraphTest
* `hipGraphKernelNodeSetAttribute(hipGraphNode_t hNode,
* hipKernelNodeAttrID attr, const hipKernelNodeAttrValue* value )` -
* Sets node attribute.
*/
#define THREADS_PER_BLOCK 512
/**
* Test Description
* ------------------------
*  - Functional Test for API - hipGraphKernelNodeSetAttribute
* 1) Check hipGraphKernelNodeSetAttribute for AccessPolicyWindow attributes
* 2) Check hipGraphKernelNodeSetAttribute for cooperative attributes
* 3) Check hipGraphKernelNodeSetAttribute for window cooperative attributes
* Test source
* ------------------------
*  - unit/graph/hipGraphKernelNodeGetAttribute.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
namespace {
constexpr std::array<hipAccessProperty, 3> kAccessProperties{
hipAccessPropertyNormal, hipAccessPropertyStreaming, hipAccessPropertyPersisting};
} // anonymous namespace
static bool validateKernelNodeAttrValue(hipKernelNodeAttrValue in,
hipKernelNodeAttrValue out) {
if ((in.accessPolicyWindow.base_ptr != out.accessPolicyWindow.base_ptr) ||
(in.accessPolicyWindow.hitProp != out.accessPolicyWindow.hitProp) ||
(in.accessPolicyWindow.hitRatio != out.accessPolicyWindow.hitRatio) ||
(in.accessPolicyWindow.missProp != out.accessPolicyWindow.missProp) ||
(in.accessPolicyWindow.num_bytes != out.accessPolicyWindow.num_bytes) ||
(in.cooperative != out.cooperative)) {
return false;
}
return true;
static bool CompareAccessPolicyWindow(const hipKernelNodeAttrValue& lhs,
const hipKernelNodeAttrValue& rhs) {
return lhs.accessPolicyWindow.base_ptr == rhs.accessPolicyWindow.base_ptr &&
lhs.accessPolicyWindow.num_bytes == rhs.accessPolicyWindow.num_bytes &&
lhs.accessPolicyWindow.hitRatio == rhs.accessPolicyWindow.hitRatio &&
lhs.accessPolicyWindow.hitProp == rhs.accessPolicyWindow.hitProp &&
lhs.accessPolicyWindow.missProp == rhs.accessPolicyWindow.missProp;
}
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
hipGraph_t graph;
hipGraphExec_t graphExec;
hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kernel_vecAdd;
hipKernelNodeParams kNodeParams{};
hipStream_t stream;
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Positive_AccessPolicyWindow") {
constexpr int N = 1024;
const auto hit_prop = GENERATE(from_range(begin(kAccessProperties), end(kAccessProperties)));
const auto miss_prop = GENERATE(from_range(begin(kAccessProperties), end(kAccessProperties) - 1));
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipMalloc(&A_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&B_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&C_d, sizeof(int) * N));
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(blocks);
kNodeParams.blockDim = dim3(threadsPerBlock);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kNodeParams));
hipKernelNodeParams node_params{};
node_params.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
node_params.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
node_params.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpy_C, 1));
size_t N_elem{N};
void* kernel_params[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&N_elem)};
node_params.kernelParams = reinterpret_cast<void**>(kernel_params);
hipKernelNodeAttrValue value_in, value_out;
hipGraphNode_t graph_node;
HIP_CHECK(hipGraphAddKernelNode(&graph_node, graph, nullptr, 0, &node_params));
SECTION("Check hipGraphKernelNodeSetAttribute for AccessPolicyWindow") {
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
int max_window_size;
HIP_CHECK(
hipDeviceGetAttribute(&max_window_size, hipDeviceAttributeAccessPolicyMaxWindowSize, 0));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
hipKernelNodeAttrValue node_attribute_1;
node_attribute_1.accessPolicyWindow.base_ptr = reinterpret_cast<void*>(A_d);
node_attribute_1.accessPolicyWindow.num_bytes =
std::min<unsigned long>(static_cast<unsigned long>(max_window_size), sizeof(int) * N);
node_attribute_1.accessPolicyWindow.hitRatio = 0.6;
node_attribute_1.accessPolicyWindow.hitProp = hit_prop;
node_attribute_1.accessPolicyWindow.missProp = miss_prop;
value_in.accessPolicyWindow.hitRatio = 0.8;
value_in.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
value_in.accessPolicyWindow.missProp = hipAccessPropertyStreaming;
HIP_CHECK(hipGraphKernelNodeSetAttribute(graph_node, hipKernelNodeAttributeAccessPolicyWindow,
&node_attribute_1));
HIP_CHECK(hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
hipKernelNodeAttrValue node_attribute_2;
HIP_CHECK(hipGraphKernelNodeGetAttribute(graph_node, hipKernelNodeAttributeAccessPolicyWindow,
&node_attribute_2));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
REQUIRE(true == validateKernelNodeAttrValue(value_in, value_out));
}
SECTION("Check hipGraphKernelNodeSetAttribute for cooperative") {
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
REQUIRE(CompareAccessPolicyWindow(node_attribute_1, node_attribute_2));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
value_in.cooperative = 2;
HIP_CHECK(hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
REQUIRE(true == validateKernelNodeAttrValue(value_in, value_out));
}
SECTION("Check hipGraphKernelNodeSetAttribute for window and cooperative") {
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
value_in.cooperative = 8;
value_in.accessPolicyWindow.hitRatio = 0.1;
value_in.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
value_in.accessPolicyWindow.missProp = hipAccessPropertyNormal;
HIP_CHECK(hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
REQUIRE(true == validateKernelNodeAttrValue(value_in, value_out));
}
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify graph execution result
HipTest::checkVectorADD<int>(A_h, B_h, C_h, N);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(B_d));
HIP_CHECK(hipFree(C_d));
}
/**
* Test Description
* ------------------------
*  - Negative/argument Test for API - hipGraphKernelNodeSetAttribute
* 1) Pass kernel node as nullptr for Set attribute api and verify
* 2) Pass KernelNodeAttrID as invalid value for Set attribute api and verify
* 3) Pass KernelNodeAttrID as INT_MAX value for Get attribute api and verify
* 4) Pass KernelNodeAttrValue as nullptr for Set attribute api and verify
* 5) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value missProp as hipAccessPropertyPersisting
* 6) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value hitProp as hipAccessPropertyPersisting
* 7) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as 1.4
* 8) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as 0
* 9) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as 1
* 10) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as -1.8
* 11) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as -0.6
* 12) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass accessPolicyWindow.num_bytes as 1024 & hitRatio as 0.6
* 13) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
* and pass accessPolicyWindow.num_bytes as 1 GB & hitRatio as -0.6
* 14) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.num_bytes as 1 MB
* 15) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value base_ptr as nullptr
* Test source
* ------------------------
*  - unit/graph/hipGraphKernelNodeSetAttribute.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Positive_Cooperative") {
constexpr int N = 1024;
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
hipGraph_t graph;
hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kernel_vecAdd;
hipKernelNodeParams kNodeParams{};
hipStream_t stream;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
hipError_t ret;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipMalloc(&A_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&B_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&C_d, sizeof(int) * N));
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(blocks);
kNodeParams.blockDim = dim3(threadsPerBlock);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kNodeParams));
hipKernelNodeParams node_params{};
node_params.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
node_params.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
node_params.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
hipKernelNodeAttrValue value_in, value_out;
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
memcpy(&value_out, &value_in, sizeof(hipKernelNodeAttrValue));
size_t N_elem{N};
void* kernel_params[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&N_elem)};
node_params.kernelParams = reinterpret_cast<void**>(kernel_params);
SECTION("Pass kernel node as nullptr for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(nullptr,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
hipGraphNode_t graph_node;
HIP_CHECK(hipGraphAddKernelNode(&graph_node, graph, nullptr, 0, &node_params));
hipKernelNodeAttrValue node_attribute_1;
node_attribute_1.cooperative = 2;
HIP_CHECK(hipGraphKernelNodeSetAttribute(graph_node, hipKernelNodeAttributeCooperative,
&node_attribute_1));
hipKernelNodeAttrValue node_attribute_2;
HIP_CHECK(hipGraphKernelNodeGetAttribute(graph_node, hipKernelNodeAttributeCooperative,
&node_attribute_2));
REQUIRE(node_attribute_1.cooperative == node_attribute_2.cooperative);
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(B_d));
HIP_CHECK(hipFree(C_d));
}
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Negative_Parameters") {
constexpr int N = 1024;
int *A_d, *B_d, *C_d;
HIP_CHECK(hipMalloc(&A_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&B_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&C_d, sizeof(int) * N));
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipKernelNodeParams node_params{};
node_params.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
node_params.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
node_params.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
size_t N_elem{N};
void* kernel_params[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&N_elem)};
node_params.kernelParams = reinterpret_cast<void**>(kernel_params);
hipGraphNode_t graph_node;
HIP_CHECK(hipGraphAddKernelNode(&graph_node, graph, nullptr, 0, &node_params));
int max_window_size;
HIP_CHECK(
hipDeviceGetAttribute(&max_window_size, hipDeviceAttributeAccessPolicyMaxWindowSize, 0));
hipKernelNodeAttrValue node_attribute;
node_attribute.accessPolicyWindow.base_ptr = reinterpret_cast<void*>(A_d);
node_attribute.accessPolicyWindow.num_bytes =
std::min<unsigned long>(static_cast<unsigned long>(max_window_size), sizeof(int) * N);
node_attribute.accessPolicyWindow.hitRatio = 0.6;
node_attribute.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
node_attribute.accessPolicyWindow.missProp = hipAccessPropertyStreaming;
SECTION("node == nullptr") {
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
nullptr, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("Pass KernelNodeAttrID as invalid value for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttrID(-1), &value_in);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("node is not a kernel node") {
hipGraphNode_t empty_node;
HIP_CHECK(hipGraphAddEmptyNode(&empty_node, graph, nullptr, 0));
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
empty_node, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("Pass KernelNodeAttrID as INT_MAX value for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttrID(INT_MAX), &value_in);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("invalid attribute") {
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(graph_node, static_cast<hipKernelNodeAttrID>(-1),
&node_attribute),
hipErrorInvalidValue);
}
#if HT_AMD // getting SIGSEGV error in Cuda Setup
SECTION("Pass KernelNodeAttrValue as nullptr for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
#if HT_AMD // segfaults on NVIDIA
SECTION("value == nullptr") {
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
graph_node, hipKernelNodeAttributeAccessPolicyWindow, nullptr),
hipErrorInvalidValue);
}
#endif
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value missProp as hipAccessPropertyPersisting") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.missProp = hipAccessPropertyPersisting;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value hitProp as hipAccessPropertyPersisting") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as 1.4") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = 1.4;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as 0") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = 0;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as 1") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = 1;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as -1.8") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = -1.8;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as -0.6") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = -0.6;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" & pass accessPolicyWindow.num_bytes as 1024 & hitRatio as 0.6") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.num_bytes = 1024;
value_in.accessPolicyWindow.hitRatio = 0.6;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" & pass accessPolicyWindow.num_bytes as 1 GB & hitRatio as -0.6") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.num_bytes = 1024 * 1024 * 1024;
value_in.accessPolicyWindow.hitRatio = -0.6;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.num_bytes as 1 MB") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.num_bytes = 1024 * 1024;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value base_ptr as nullptr") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.base_ptr = nullptr;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
SECTION("accessPolicyWindow.num_bytes > accessPolicyMaxWindowSize") {
node_attribute.accessPolicyWindow.num_bytes = max_window_size + 1;
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
graph_node, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("accessPolicyWindow.hitRatio < 0") {
node_attribute.accessPolicyWindow.hitRatio = -0.6;
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
graph_node, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("accessPolicyWindow.hitRatio > 1.0") {
node_attribute.accessPolicyWindow.hitRatio = 1.1;
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
graph_node, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
SECTION("accessPolicyWindow.missProp == hipAccessPropertyPersisting") {
node_attribute.accessPolicyWindow.missProp = hipAccessPropertyPersisting;
HIP_CHECK_ERROR(hipGraphKernelNodeSetAttribute(
graph_node, hipKernelNodeAttributeAccessPolicyWindow, &node_attribute),
hipErrorInvalidValue);
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(B_d));
HIP_CHECK(hipFree(C_d));
}
@@ -0,0 +1,370 @@
/*
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 WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
/**
* @addtogroup hipGraphKernelNodeSetAttribute hipGraphKernelNodeSetAttribute
* @{
* @ingroup GraphTest
* `hipGraphKernelNodeSetAttribute(hipGraphNode_t hNode,
* hipKernelNodeAttrID attr, const hipKernelNodeAttrValue* value )` -
* Sets node attribute.
*/
/**
* Test Description
* ------------------------
*  - Functional Test for API - hipGraphKernelNodeSetAttribute
* 1) Check hipGraphKernelNodeSetAttribute for AccessPolicyWindow attributes
* 2) Check hipGraphKernelNodeSetAttribute for cooperative attributes
* 3) Check hipGraphKernelNodeSetAttribute for window cooperative attributes
* Test source
* ------------------------
*  - unit/graph/hipGraphKernelNodeGetAttribute.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
static bool validateKernelNodeAttrValue(hipKernelNodeAttrValue in,
hipKernelNodeAttrValue out) {
if ((in.accessPolicyWindow.base_ptr != out.accessPolicyWindow.base_ptr) ||
(in.accessPolicyWindow.hitProp != out.accessPolicyWindow.hitProp) ||
(in.accessPolicyWindow.hitRatio != out.accessPolicyWindow.hitRatio) ||
(in.accessPolicyWindow.missProp != out.accessPolicyWindow.missProp) ||
(in.accessPolicyWindow.num_bytes != out.accessPolicyWindow.num_bytes) ||
(in.cooperative != out.cooperative)) {
return false;
}
return true;
}
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
hipGraph_t graph;
hipGraphExec_t graphExec;
hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kernel_vecAdd;
hipKernelNodeParams kNodeParams{};
hipStream_t stream;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(blocks);
kNodeParams.blockDim = dim3(threadsPerBlock);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kNodeParams));
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpy_C, 1));
hipKernelNodeAttrValue value_in, value_out;
SECTION("Check hipGraphKernelNodeSetAttribute for AccessPolicyWindow") {
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
value_in.accessPolicyWindow.hitRatio = 0.8;
value_in.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
value_in.accessPolicyWindow.missProp = hipAccessPropertyStreaming;
HIP_CHECK(hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
REQUIRE(true == validateKernelNodeAttrValue(value_in, value_out));
}
SECTION("Check hipGraphKernelNodeSetAttribute for cooperative") {
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
value_in.cooperative = 2;
HIP_CHECK(hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
REQUIRE(true == validateKernelNodeAttrValue(value_in, value_out));
}
SECTION("Check hipGraphKernelNodeSetAttribute for window and cooperative") {
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
value_in.cooperative = 8;
value_in.accessPolicyWindow.hitRatio = 0.1;
value_in.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
value_in.accessPolicyWindow.missProp = hipAccessPropertyNormal;
HIP_CHECK(hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_out));
REQUIRE(true == validateKernelNodeAttrValue(value_in, value_out));
}
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify graph execution result
HipTest::checkVectorADD<int>(A_h, B_h, C_h, N);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Test Description
* ------------------------
*  - Negative/argument Test for API - hipGraphKernelNodeSetAttribute
* 1) Pass kernel node as nullptr for Set attribute api and verify
* 2) Pass KernelNodeAttrID as invalid value for Set attribute api and verify
* 3) Pass KernelNodeAttrID as INT_MAX value for Get attribute api and verify
* 4) Pass KernelNodeAttrValue as nullptr for Set attribute api and verify
* 5) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value missProp as hipAccessPropertyPersisting
* 6) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value hitProp as hipAccessPropertyPersisting
* 7) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as 1.4
* 8) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as 0
* 9) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as 1
* 10) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as -1.8
* 11) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.hitRatio as -0.6
* 12) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass accessPolicyWindow.num_bytes as 1024 & hitRatio as 0.6
* 13) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
* and pass accessPolicyWindow.num_bytes as 1 GB & hitRatio as -0.6
* 14) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value accessPolicyWindow.num_bytes as 1 MB
* 15) Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow
* and pass value base_ptr as nullptr
* Test source
* ------------------------
*  - unit/graph/hipGraphKernelNodeSetAttribute.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipGraphKernelNodeSetAttribute_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
hipGraph_t graph;
hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kernel_vecAdd;
hipKernelNodeParams kNodeParams{};
hipStream_t stream;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
hipError_t ret;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(blocks);
kNodeParams.blockDim = dim3(threadsPerBlock);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kNodeParams));
hipKernelNodeAttrValue value_in, value_out;
memset(&value_in, 0, sizeof(hipKernelNodeAttrValue));
memset(&value_out, 0, sizeof(hipKernelNodeAttrValue));
HIP_CHECK(hipGraphKernelNodeGetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in));
memcpy(&value_out, &value_in, sizeof(hipKernelNodeAttrValue));
SECTION("Pass kernel node as nullptr for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(nullptr,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as invalid value for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttrID(-1), &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as INT_MAX value for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttrID(INT_MAX), &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
#if HT_AMD // getting SIGSEGV error in Cuda Setup
SECTION("Pass KernelNodeAttrValue as nullptr for Set attribute api") {
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
#endif
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value missProp as hipAccessPropertyPersisting") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.missProp = hipAccessPropertyPersisting;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value hitProp as hipAccessPropertyPersisting") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitProp = hipAccessPropertyPersisting;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as 1.4") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = 1.4;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as 0") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = 0;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as 1") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = 1;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as -1.8") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = -1.8;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.hitRatio as -0.6") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.hitRatio = -0.6;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" & pass accessPolicyWindow.num_bytes as 1024 & hitRatio as 0.6") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.num_bytes = 1024;
value_in.accessPolicyWindow.hitRatio = 0.6;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" & pass accessPolicyWindow.num_bytes as 1 GB & hitRatio as -0.6") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.num_bytes = 1024 * 1024 * 1024;
value_in.accessPolicyWindow.hitRatio = -0.6;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value accessPolicyWindow.num_bytes as 1 MB") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.num_bytes = 1024 * 1024;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass KernelNodeAttrID as hipKernelNodeAttributeAccessPolicyWindow"
" and pass value base_ptr as nullptr") {
memcpy(&value_in, &value_out, sizeof(hipKernelNodeAttrValue));
value_in.accessPolicyWindow.base_ptr = nullptr;
ret = hipGraphKernelNodeSetAttribute(kernel_vecAdd,
hipKernelNodeAttributeAccessPolicyWindow, &value_in);
REQUIRE(hipSuccess == ret);
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
+58 -206
View File
@@ -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
@@ -17,220 +20,69 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
Testcase Scenarios :
Negative -
1) Pass node as nullptr and verify api returns error code.
2) Pass un-initialize node and verify api returns error code.
3) Pass pNodeParams as nullptr and verify api returns error code.
Functional -
1) Create a graph, add Memcpy node to graph with desired node params.
Verify api fetches the node params mentioned while adding Memcpy node.
2) Set Memcpy node params with hipGraphMemcpyNodeSetParams,
now get the params and verify both are same.
*/
#include <hip_test_defgroups.hh>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <resource_guards.hh>
#define SIZE 10
#define UPDATESIZE 8
/* Test verifies hipGraphMemcpyNodeGetParams API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeGetParams_Negative") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipError_t ret;
hipGraphNode_t memcpyNode;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
SECTION("Pass node as nullptr") {
ret = hipGraphMemcpyNodeGetParams(nullptr, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass un-initilize node") {
hipGraphNode_t memcpyNode_uninit{};
ret = hipGraphMemcpyNodeGetParams(memcpyNode_uninit, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass GetNodeParams as nullptr") {
ret = hipGraphMemcpyNodeGetParams(memcpyNode, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
HIP_CHECK(hipFreeArray(devArray));
free(hData);
HIP_CHECK(hipGraphDestroy(graph));
}
/* Test verifies hipGraphMemcpyNodeGetParams API Functional scenarios.
/**
* @addtogroup hipGraphMemcpyNodeGetParams hipGraphMemcpyNodeGetParams
* @{
* @ingroup GraphTest
* `hipGraphMemcpyNodeGetParams(hipGraphNode_t node, hipMemcpy3DParms *pNodeParams)` -
* Gets a memcpy node's parameters
* ________________________
* Test cases from other APIs:
* - @ref Unit_hipGraphMemcpyNodeSetParams_Positive_Basic
*/
static bool compareHipPos(hipPos hPos1, hipPos hPos2) {
if ((hPos1.x == hPos2.x) && (hPos1.y == hPos2.y) && (hPos1.z == hPos2.z))
return true;
else
return false;
}
static bool compareHipExtent(hipExtent hExt1, hipExtent hExt2) {
if ((hExt1.width == hExt2.width) && (hExt1.height == hExt2.height) &&
(hExt1.depth == hExt2.depth))
return true;
else
return false;
}
static bool compareHipPitchedPtr(hipPitchedPtr hpPtr1, hipPitchedPtr hpPtr2) {
if ((reinterpret_cast<int *>(hpPtr1.ptr) ==
reinterpret_cast<int *>(hpPtr2.ptr))
&& (hpPtr1.pitch == hpPtr2.pitch)
#if HT_AMD
&& (hpPtr1.xsize == hpPtr2.xsize)
/* xsize check below is disabled on nvidia as xsize value
* is not being updated properly due to issue with CUDA api */
#endif
&& (hpPtr1.ysize == hpPtr2.ysize))
return true;
else
return false;
}
/**
* Test Description
* ------------------------
* - Verify API behaviour with invalid arguments:
* -# node is nullptr
* -# pNodeParams is nullptr
* -# node is destroyed
* Test source
* ------------------------
* - unit/graph/hipGraphMemcpyNodeGetParams.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphMemcpyNodeGetParams_Negative_Parameters") {
constexpr hipExtent extent{128 * sizeof(int), 128, 8};
static bool memcpyNodeCompare(hipMemcpy3DParms *mNode1,
hipMemcpy3DParms *mNode2) {
if (mNode1->srcArray != mNode2->srcArray)
return false;
if (!compareHipPos(mNode1->srcPos, mNode2->srcPos))
return false;
if (!compareHipPitchedPtr(mNode1->srcPtr, mNode2->srcPtr))
return false;
if (mNode1->dstArray != mNode2->dstArray)
return false;
if (!compareHipPos(mNode1->dstPos, mNode2->dstPos))
return false;
if (!compareHipPitchedPtr(mNode1->dstPtr, mNode2->dstPtr))
return false;
if (!compareHipExtent(mNode1->extent, mNode2->extent))
return false;
if (mNode1->kind != mNode2->kind)
return false;
return true;
}
LinearAllocGuard3D<int> src_alloc(extent);
LinearAllocGuard3D<int> dst_alloc(extent);
TEST_CASE("Unit_hipGraphMemcpyNodeGetParams_Functional") {
CHECK_IMAGE_SUPPORT
hipMemcpy3DParms params = {};
params.srcPtr = src_alloc.pitched_ptr();
params.srcPos = make_hipPos(0, 0, 0);
params.dstPtr = dst_alloc.pitched_ptr();
params.dstPos = make_hipPos(0, 0, 0);
params.extent = extent;
params.kind = hipMemcpyDeviceToDevice;
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph = nullptr;
hipGraphNode_t node = nullptr;
hipGraph_t graph;
hipGraphNode_t memcpyNode;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
SECTION("Get Memcpy Param and verify.") {
hipMemcpy3DParms m3DGetParams;
REQUIRE(hipSuccess == hipGraphMemcpyNodeGetParams(memcpyNode,
&m3DGetParams));
// Validating the result
REQUIRE(true == memcpyNodeCompare(&myparms, &m3DGetParams));
SECTION("node == nullptr") {
HIP_CHECK_ERROR(hipGraphMemcpyNodeGetParams(nullptr, &params), hipErrorInvalidValue);
}
SECTION("Set memcpy params and Get param and verify.") {
hipMemcpy3DParms myparms1, m3DGetParams1;
constexpr int width1{UPDATESIZE}, height1{UPDATESIZE}, depth1{UPDATESIZE};
hipArray_t devArray1;
hipChannelFormatKind formatKind1 = hipChannelFormatKindSigned;
int* hData1;
uint32_t size1 = width1 * height1 * depth1 * sizeof(int);
hData1 = reinterpret_cast<int*>(malloc(size1));
REQUIRE(hData1 != nullptr);
memset(hData1, 0, size1);
for (int i = 0; i < depth1; i++) {
for (int j = 0; j < height1; j++) {
for (int k = 0; k < width1; k++) {
hData1[i*width1*height1 + j*width1 + k] = i*width1*height1 +
j*width1 + k;
}
}
}
hipChannelFormatDesc channelDesc1 = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind1);
HIP_CHECK(hipMalloc3DArray(&devArray1, &channelDesc1,
make_hipExtent(width1, height1, depth1), hipArrayDefault));
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.extent = make_hipExtent(width1 , height1, depth1);
myparms1.srcPtr = make_hipPitchedPtr(hData1, width1 * sizeof(int),
width1, height1);
myparms1.dstArray = devArray1;
myparms1.kind = hipMemcpyHostToDevice;
REQUIRE(hipSuccess == hipGraphMemcpyNodeSetParams(memcpyNode, &myparms1));
REQUIRE(hipSuccess == hipGraphMemcpyNodeGetParams(memcpyNode,
&m3DGetParams1));
REQUIRE(true == memcpyNodeCompare(&myparms1, &m3DGetParams1));
HIP_CHECK(hipFreeArray(devArray1));
free(hData1);
SECTION("pNodeParams == nullptr") {
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, &params));
HIP_CHECK_ERROR(hipGraphMemcpyNodeGetParams(node, nullptr), hipErrorInvalidValue);
HIP_CHECK(hipGraphDestroy(graph));
}
HIP_CHECK(hipFreeArray(devArray));
free(hData);
HIP_CHECK(hipGraphDestroy(graph));
}
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-208
SECTION("Node is destroyed") {
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, &params));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK_ERROR(hipGraphMemcpyNodeGetParams(node, &params), hipErrorInvalidValue);
}
#endif
}
@@ -0,0 +1,236 @@
/*
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.
*/
/**
Testcase Scenarios :
Negative -
1) Pass node as nullptr and verify api returns error code.
2) Pass un-initialize node and verify api returns error code.
3) Pass pNodeParams as nullptr and verify api returns error code.
Functional -
1) Create a graph, add Memcpy node to graph with desired node params.
Verify api fetches the node params mentioned while adding Memcpy node.
2) Set Memcpy node params with hipGraphMemcpyNodeSetParams,
now get the params and verify both are same.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#define SIZE 10
#define UPDATESIZE 8
/* Test verifies hipGraphMemcpyNodeGetParams API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeGetParams_Negative") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipError_t ret;
hipGraphNode_t memcpyNode;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
SECTION("Pass node as nullptr") {
ret = hipGraphMemcpyNodeGetParams(nullptr, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass un-initilize node") {
hipGraphNode_t memcpyNode_uninit{};
ret = hipGraphMemcpyNodeGetParams(memcpyNode_uninit, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass GetNodeParams as nullptr") {
ret = hipGraphMemcpyNodeGetParams(memcpyNode, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
HIP_CHECK(hipFreeArray(devArray));
free(hData);
HIP_CHECK(hipGraphDestroy(graph));
}
/* Test verifies hipGraphMemcpyNodeGetParams API Functional scenarios.
*/
static bool compareHipPos(hipPos hPos1, hipPos hPos2) {
if ((hPos1.x == hPos2.x) && (hPos1.y == hPos2.y) && (hPos1.z == hPos2.z))
return true;
else
return false;
}
static bool compareHipExtent(hipExtent hExt1, hipExtent hExt2) {
if ((hExt1.width == hExt2.width) && (hExt1.height == hExt2.height) &&
(hExt1.depth == hExt2.depth))
return true;
else
return false;
}
static bool compareHipPitchedPtr(hipPitchedPtr hpPtr1, hipPitchedPtr hpPtr2) {
if ((reinterpret_cast<int *>(hpPtr1.ptr) ==
reinterpret_cast<int *>(hpPtr2.ptr))
&& (hpPtr1.pitch == hpPtr2.pitch)
#if HT_AMD
&& (hpPtr1.xsize == hpPtr2.xsize)
/* xsize check below is disabled on nvidia as xsize value
* is not being updated properly due to issue with CUDA api */
#endif
&& (hpPtr1.ysize == hpPtr2.ysize))
return true;
else
return false;
}
static bool memcpyNodeCompare(hipMemcpy3DParms *mNode1,
hipMemcpy3DParms *mNode2) {
if (mNode1->srcArray != mNode2->srcArray)
return false;
if (!compareHipPos(mNode1->srcPos, mNode2->srcPos))
return false;
if (!compareHipPitchedPtr(mNode1->srcPtr, mNode2->srcPtr))
return false;
if (mNode1->dstArray != mNode2->dstArray)
return false;
if (!compareHipPos(mNode1->dstPos, mNode2->dstPos))
return false;
if (!compareHipPitchedPtr(mNode1->dstPtr, mNode2->dstPtr))
return false;
if (!compareHipExtent(mNode1->extent, mNode2->extent))
return false;
if (mNode1->kind != mNode2->kind)
return false;
return true;
}
TEST_CASE("Unit_hipGraphMemcpyNodeGetParams_Functional") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipGraphNode_t memcpyNode;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
SECTION("Get Memcpy Param and verify.") {
hipMemcpy3DParms m3DGetParams;
REQUIRE(hipSuccess == hipGraphMemcpyNodeGetParams(memcpyNode,
&m3DGetParams));
// Validating the result
REQUIRE(true == memcpyNodeCompare(&myparms, &m3DGetParams));
}
SECTION("Set memcpy params and Get param and verify.") {
hipMemcpy3DParms myparms1, m3DGetParams1;
constexpr int width1{UPDATESIZE}, height1{UPDATESIZE}, depth1{UPDATESIZE};
hipArray_t devArray1;
hipChannelFormatKind formatKind1 = hipChannelFormatKindSigned;
int* hData1;
uint32_t size1 = width1 * height1 * depth1 * sizeof(int);
hData1 = reinterpret_cast<int*>(malloc(size1));
REQUIRE(hData1 != nullptr);
memset(hData1, 0, size1);
for (int i = 0; i < depth1; i++) {
for (int j = 0; j < height1; j++) {
for (int k = 0; k < width1; k++) {
hData1[i*width1*height1 + j*width1 + k] = i*width1*height1 +
j*width1 + k;
}
}
}
hipChannelFormatDesc channelDesc1 = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind1);
HIP_CHECK(hipMalloc3DArray(&devArray1, &channelDesc1,
make_hipExtent(width1, height1, depth1), hipArrayDefault));
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.extent = make_hipExtent(width1 , height1, depth1);
myparms1.srcPtr = make_hipPitchedPtr(hData1, width1 * sizeof(int),
width1, height1);
myparms1.dstArray = devArray1;
myparms1.kind = hipMemcpyHostToDevice;
REQUIRE(hipSuccess == hipGraphMemcpyNodeSetParams(memcpyNode, &myparms1));
REQUIRE(hipSuccess == hipGraphMemcpyNodeGetParams(memcpyNode,
&m3DGetParams1));
REQUIRE(true == memcpyNodeCompare(&myparms1, &m3DGetParams1));
HIP_CHECK(hipFreeArray(devArray1));
free(hData1);
}
HIP_CHECK(hipFreeArray(devArray));
free(hData);
HIP_CHECK(hipGraphDestroy(graph));
}
+248 -184
View File
@@ -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
@@ -17,203 +20,264 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
Testcase Scenarios :
Negative -
1) Pass node as nullptr and verify api returns error code.
2) Pass un-initialize node and verify api returns error code.
3) Pass pNodeParams as nullptr and verify api returns error code.
Functional -
1) Add Memcpy node to graph, update the Memcpy node params with set and
launch the graph and check updated params are taking effect.
2) Add Memcpy node to graph, launch graph, then update the Memcpy node params
with set and launch the graph and check updated params are taking effect.
*/
#include <functional>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_defgroups.hh>
#include <memcpy3d_tests_common.hh>
#define SIZE 10
#include "graph_tests_common.hh"
/* Test verifies hipGraphMemcpyNodeSetParams API Negative scenarios.
/**
* @addtogroup hipGraphMemcpyNodeSetParams hipGraphMemcpyNodeSetParams
* @{
* @ingroup GraphTest
* `hipGraphMemcpyNodeSetParams (hipGraphNode_t node, const hipMemcpy3DParms *pNodeParams)` - Sets a
* memcpy node's parameters
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams_Negative") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
/**
* Test Description
* ------------------------
* - Verify that node parameters get updated correctly by creating a node with valid but
* incorrect parameters, and the setting them to the correct values after which the graph is
* executed and the results of the memcpy 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/hipGraphMemcpyNodeSetParams.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams_Positive_Basic") {
constexpr bool async = false;
SECTION("Device to host") {
Memcpy3DDeviceToHostShell<async>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Device to host with default kind") {
Memcpy3DDeviceToHostShell<async>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Host to device") {
Memcpy3DHostToDeviceShell<async>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Host to device with default kind") {
Memcpy3DHostToDeviceShell<async>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Host to host") { Memcpy3DHostToHostShell<async>(Memcpy3DWrapper<async, true, true>); }
SECTION("Host to host with default kind") {
Memcpy3DHostToHostShell<async>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Device to device") {
SECTION("Peer access enabled") {
Memcpy3DDeviceToDeviceShell<async, true>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Peer access disabled") {
Memcpy3DDeviceToDeviceShell<async, false>(Memcpy3DWrapper<async, true, true>);
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipError_t ret;
hipGraphNode_t memcpyNode;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
SECTION("Pass node as nullptr") {
ret = hipGraphMemcpyNodeSetParams(nullptr, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass un-initialize node") {
hipGraphNode_t memcpyNode_uninit{};
ret = hipGraphMemcpyNodeSetParams(memcpyNode_uninit, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass SetNodeParams as nullptr") {
ret = hipGraphMemcpyNodeSetParams(memcpyNode, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
HIP_CHECK(hipFreeArray(devArray));
free(hData);
HIP_CHECK(hipGraphDestroy(graph));
}
/* Test verifies hipGraphMemcpyNodeSetParams API Functional scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams_Functional") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms, myparms1;
uint32_t size = width * height * depth * sizeof(int);
int *hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
memset(hData, 0, size);
int *hDataTemp = reinterpret_cast<int*>(malloc(size));
REQUIRE(hDataTemp != nullptr);
memset(hDataTemp, 0, size);
int *hOutputData = reinterpret_cast<int *>(malloc(size));
REQUIRE(hOutputData != nullptr);
memset(hOutputData, 0, size);
int *hOutputData1 = reinterpret_cast<int *>(malloc(size));
REQUIRE(hOutputData1 != nullptr);
memset(hOutputData1, 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;
}
SECTION("Device to device with default kind") {
SECTION("Peer access enabled") {
Memcpy3DDeviceToDeviceShell<async, true>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Peer access disabled") {
Memcpy3DDeviceToDeviceShell<async, false>(Memcpy3DWrapper<async, true, true>);
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
// Host to Device
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipGraphNode_t memcpyNode;
std::vector<hipGraphNode_t> dependencies;
hipStream_t streamForGraph;
hipGraphExec_t graphExec;
HIP_CHECK(hipStreamCreate(&streamForGraph));
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
dependencies.push_back(memcpyNode);
// Device to host
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.dstPtr = make_hipPitchedPtr(hDataTemp, width * sizeof(int),
width, height);
myparms1.srcArray = devArray;
myparms1.extent = make_hipExtent(width, height, depth);
myparms1.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
dependencies.size(), &myparms1));
SECTION("Update the memcpyNode and check") {
// Device to host with updated host ptr hDataTemp -> hOutputData
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.dstPtr = make_hipPitchedPtr(hOutputData, width * sizeof(int),
width, height);
myparms1.srcArray = devArray;
myparms1.extent = make_hipExtent(width, height, depth);
myparms1.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphMemcpyNodeSetParams(memcpyNode, &myparms1));
// 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);
SECTION("Array from/to Host") {
Memcpy3DArrayHostShell<async>(Memcpy3DWrapper<async, true, true>);
}
SECTION("Update the memcpyNode again and check") {
// Device to host with updated host ptr hOutputData -> hOutputData1
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.dstPtr = make_hipPitchedPtr(hOutputData1, width * sizeof(int),
width, height);
myparms1.srcArray = devArray;
myparms1.extent = make_hipExtent(width, height, depth);
myparms1.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
dependencies.size(), &myparms1));
HIP_CHECK(hipGraphMemcpyNodeSetParams(memcpyNode, &myparms1));
// 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, hOutputData1, width, height, depth);
#if HT_NVIDIA // Disabled on AMD due to defect - EXSWHTEC-220
SECTION("Array from/to Device") {
Memcpy3DArrayDeviceShell<async>(Memcpy3DWrapper<async, true, true>);
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipFreeArray(devArray));
free(hData);
free(hDataTemp);
free(hOutputData);
free(hOutputData1);
#endif
}
/**
* 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_hipGraphMemcpyNodeSetParams_Negative_Parameters") {
using namespace std::placeholders;
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;
SECTION("node == nullptr") {
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent, kind);
HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(nullptr, &params), hipErrorInvalidValue);
}
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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), 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(hipGraphMemcpyNodeSetParams(node, &params), hipErrorInvalidValue);
}
SECTION("Invalid MemcpyKind") {
auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent,
static_cast<hipMemcpyKind>(-1));
HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, &params), 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("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);
}
}
+149 -136
View File
@@ -6,8 +6,10 @@ 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
@@ -17,169 +19,180 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
Testcase Scenarios :
Functional-
1) Create a graph, add Memcpy node to graph, update the Memcpy node params with set and make sure they are taking effect.
Negative-
1) Pass pGraphNode as nullptr and check if api returns error.
2) Pass destination ptr is nullptr, api expected to return error code.
3) Pass source ptr is nullptr, api expected to return error code.
4) Pass count as zero, api expected to return error code.
5) Pass same pointer as source ptr and destination ptr, api expected to return error code.
6) Pass overlap memory as source ptr and destination ptr where source ptr is ahead of destination ptr, api expected to return error code.
7) Pass overlap memory as source ptr and destination ptr where destination ptr is ahead of source ptr, api expected to return error code.
8) If count is more than allocated size for source and destination ptr, api should return error code.
9) If count is less than allocated size for source and destination ptr, api should return error code.
*/
#include <functional>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
#include <hip_test_defgroups.hh>
#include <memcpy1d_tests_common.hh>
/* Test verifies hipGraphMemcpyNodeSetParams1D API Negative scenarios.
#include "graph_tests_common.hh"
static inline hipMemcpyKind ReverseMemcpyDirection(const hipMemcpyKind direction) {
switch (direction) {
case hipMemcpyHostToDevice:
return hipMemcpyDeviceToHost;
case hipMemcpyDeviceToHost:
return hipMemcpyHostToDevice;
default:
return direction;
}
};
/**
* @addtogroup hipGraphMemcpyNodeSetParams1D hipGraphMemcpyNodeSetParams1D
* @{
* @ingroup GraphTest
* `hipGraphMemcpyNodeSetParams1D(hipGraphNode_t node, void *dst, const void *src, size_t count,
* hipMemcpyKind kind)` - Sets a memcpy node's parameters to perform a 1-dimensional copy
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams1D_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
int *A_d, *A_h;
hipGraphNode_t memcpyNode{};
hipError_t ret;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipMalloc(&A_h, Nbytes));
/**
* Test Description
* ------------------------
* - Verify that node parameters get updated correctly by creating a node with valid but
* incorrect parameters, and the setting them to the correct values after which the graph is
* executed and the results of the memcpy 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/hipGraphMemcpyNodeSetParams1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams1D_Positive_Basic") {
constexpr auto f = [](void* dst, void* src, size_t count, hipMemcpyKind direction) {
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t node = nullptr;
HIP_CHECK(hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, src, dst, count / 2,
ReverseMemcpyDirection(direction)));
HIP_CHECK(hipGraphMemcpyNodeSetParams1D(node, dst, src, count, direction));
hipGraphExec_t graph_exec = nullptr;
HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graph_exec, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphExecDestroy(graph_exec));
HIP_CHECK(hipGraphDestroy(graph));
SECTION("Pass pGraphNode as nullptr") {
ret = hipGraphMemcpyNodeSetParams1D(nullptr, A_d, A_h, Nbytes,
hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
return hipSuccess;
};
#if HT_NVIDIA
MemcpyWithDirectionCommonTests<false>(f);
#else
using namespace std::placeholders;
SECTION("Device to host") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToHost));
}
SECTION("Pass destination ptr is nullptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, nullptr, A_h, Nbytes,
hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("Host to device") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToDevice));
}
SECTION("Pass source ptr is nullptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, nullptr, Nbytes,
hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("Device to device") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice));
}
}
SECTION("Pass count as zero") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, 0,
hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
SECTION("Device to device with default kind") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<false, true>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<false, false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
}
#if HT_AMD
SECTION("Pass same pointer as source ptr and destination ptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_d, Nbytes,
hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
// Disabled on AMD due to defect - EXSWHTEC-209
#if 0
SECTION("Host to host") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyHostToHost));
}
SECTION("Host to host with default kind") {
MemcpyHostToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
SECTION("Pass overlap memory where destination ptr is ahead of source ptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_d-5, Nbytes,
hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass overlap memory where source ptr is ahead of destination ptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d+5, A_d, Nbytes-5,
hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Copy more than allocated memory") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, Nbytes+8,
hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Copy less than allocated memory") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, Nbytes-8,
hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
}
SECTION("Change the kind from H2D to D2H") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, Nbytes,
hipMemcpyDeviceToHost);
REQUIRE(hipSuccess == ret);
// Disabled on AMD due to defect - EXSWHTEC-210
#if 0
SECTION("Device to host with default kind") {
MemcpyDeviceToHostShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(A_h));
HIP_CHECK(hipGraphDestroy(graph));
SECTION("Host to device with default kind") {
MemcpyHostToDeviceShell<false>(std::bind(f, _1, _2, _3, hipMemcpyDefault));
}
#endif
#endif
}
/* Test verifies hipGraphMemcpyNodeSetParams1D API Functional scenarios.
/**
* Test Description
* ------------------------
* - Verify API behaviour with invalid arguments:
* -# node is nullptr
* -# 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/hipGraphMemcpyNodeSetParams1D.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams1D_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
int *hData = reinterpret_cast<int*>(malloc(Nbytes));
REQUIRE(hData != nullptr);
memset(hData, 0, Nbytes);
hipGraphNode_t memcpyH2D_A, memcpyH2D_B, memcpyD2H_C;
hipGraphNode_t kernel_vecAdd;
hipKernelNodeParams kernelNodeParams{};
hipGraph_t graph;
hipGraphExec_t graphExec;
hipStream_t streamForGraph;
HIP_CHECK(hipStreamCreate(&streamForGraph));
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams1D_Negative_Parameters") {
using namespace std::placeholders;
hipGraph_t graph = nullptr;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
int src[2] = {}, dst[2] = {};
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
hipGraphNode_t node = nullptr;
HIP_CHECK(
hipGraphAddMemcpyNode1D(&node, graph, nullptr, 0, dst, src, sizeof(dst), hipMemcpyDefault));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0, C_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphMemcpyNodeSetParams1D(memcpyD2H_C, hData, C_d, Nbytes,
hipMemcpyDeviceToHost));
SECTION("node == nullptr") {
HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams1D(nullptr, dst, src, sizeof(dst), hipMemcpyDefault),
hipErrorInvalidValue);
}
void* kernelArgs2[] = {&A_d, &B_d, &C_d, reinterpret_cast<void *>(&NElem)};
kernelNodeParams.func = reinterpret_cast<void *>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks);
kernelNodeParams.blockDim = dim3(threadsPerBlock);
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs2);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0,
&kernelNodeParams));
MemcpyWithDirectionCommonNegativeTests(
std::bind(hipGraphMemcpyNodeSetParams1D, node, _1, _2, _3, _4), dst, src, sizeof(dst),
hipMemcpyDefault);
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpyD2H_C, 1));
SECTION("count == 0") {
HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams1D(node, dst, src, 0, hipMemcpyDefault),
hipErrorInvalidValue);
}
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
SECTION("count larger than dst allocation size") {
LinearAllocGuard<int> dev_dst(LinearAllocs::hipMalloc, sizeof(int));
HIP_CHECK_ERROR(
hipGraphMemcpyNodeSetParams1D(node, dev_dst.ptr(), src, sizeof(src), hipMemcpyDefault),
hipErrorInvalidValue);
}
// Verify graph execution result
HipTest::checkVectorADD(A_h, B_h, hData, N);
SECTION("count larger than src allocation size") {
LinearAllocGuard<int> dev_src(LinearAllocs::hipMalloc, sizeof(int));
HIP_CHECK_ERROR(
hipGraphMemcpyNodeSetParams1D(node, dst, dev_src.ptr(), sizeof(dst), hipMemcpyDefault),
hipErrorInvalidValue);
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipGraphDestroy(graph));
free(hData);
}
@@ -0,0 +1,172 @@
/*
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.
*/
/**
Testcase Scenarios :
Functional-
1) Create a graph, add Memcpy node to graph, update the Memcpy node params with set and make sure
they are taking effect. Negative- 1) Pass pGraphNode as nullptr and check if api returns error. 2)
Pass destination ptr is nullptr, api expected to return error code. 3) Pass source ptr is nullptr,
api expected to return error code. 4) Pass count as zero, api expected to return error code. 5) Pass
same pointer as source ptr and destination ptr, api expected to return error code. 6) Pass overlap
memory as source ptr and destination ptr where source ptr is ahead of destination ptr, api expected
to return error code. 7) Pass overlap memory as source ptr and destination ptr where destination ptr
is ahead of source ptr, api expected to return error code. 8) If count is more than allocated size
for source and destination ptr, api should return error code. 9) If count is less than allocated
size for source and destination ptr, api should return error code.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
/* Test verifies hipGraphMemcpyNodeSetParams1D API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams1D_Negative") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
int *A_d, *A_h;
hipGraphNode_t memcpyNode{};
hipError_t ret;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipMalloc(&A_h, Nbytes));
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, nullptr, 0, A_d, A_h, Nbytes,
hipMemcpyHostToDevice));
SECTION("Pass pGraphNode as nullptr") {
ret = hipGraphMemcpyNodeSetParams1D(nullptr, A_d, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass destination ptr is nullptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, nullptr, A_h, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass source ptr is nullptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, nullptr, Nbytes, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass count as zero") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, 0, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
#if HT_AMD
SECTION("Pass same pointer as source ptr and destination ptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_d, Nbytes, hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
#endif
SECTION("Pass overlap memory where destination ptr is ahead of source ptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_d - 5, Nbytes, hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass overlap memory where source ptr is ahead of destination ptr") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d + 5, A_d, Nbytes - 5,
hipMemcpyDeviceToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Copy more than allocated memory") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, Nbytes + 8, hipMemcpyHostToDevice);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Copy less than allocated memory") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, Nbytes - 8, hipMemcpyHostToDevice);
REQUIRE(hipSuccess == ret);
}
SECTION("Change the kind from H2D to D2H") {
ret = hipGraphMemcpyNodeSetParams1D(memcpyNode, A_d, A_h, Nbytes, hipMemcpyDeviceToHost);
REQUIRE(hipSuccess == ret);
}
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(A_h));
HIP_CHECK(hipGraphDestroy(graph));
}
/* Test verifies hipGraphMemcpyNodeSetParams1D API Functional scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams1D_Functional") {
constexpr size_t N = 1024;
constexpr size_t Nbytes = N * sizeof(int);
constexpr auto blocksPerCU = 6; // to hide latency
constexpr auto threadsPerBlock = 256;
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
size_t NElem{N};
int* hData = reinterpret_cast<int*>(malloc(Nbytes));
REQUIRE(hData != nullptr);
memset(hData, 0, Nbytes);
hipGraphNode_t memcpyH2D_A, memcpyH2D_B, memcpyD2H_C;
hipGraphNode_t kernel_vecAdd;
hipKernelNodeParams kernelNodeParams{};
hipGraph_t graph;
hipGraphExec_t graphExec;
hipStream_t streamForGraph;
HIP_CHECK(hipStreamCreate(&streamForGraph));
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, 0, B_d, B_h, Nbytes,
hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0, C_h, C_d, Nbytes,
hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphMemcpyNodeSetParams1D(memcpyD2H_C, hData, C_d, Nbytes, hipMemcpyDeviceToHost));
void* kernelArgs2[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&NElem)};
kernelNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kernelNodeParams.gridDim = dim3(blocks);
kernelNodeParams.blockDim = dim3(threadsPerBlock);
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs2);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0, &kernelNodeParams));
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &kernel_vecAdd, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpyD2H_C, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
// Verify graph execution result
HipTest::checkVectorADD(A_h, B_h, hData, N);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipGraphDestroy(graph));
free(hData);
}
@@ -0,0 +1,219 @@
/*
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.
*/
/**
Testcase Scenarios :
Negative -
1) Pass node as nullptr and verify api returns error code.
2) Pass un-initialize node and verify api returns error code.
3) Pass pNodeParams as nullptr and verify api returns error code.
Functional -
1) Add Memcpy node to graph, update the Memcpy node params with set and
launch the graph and check updated params are taking effect.
2) Add Memcpy node to graph, launch graph, then update the Memcpy node params
with set and launch the graph and check updated params are taking effect.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#define SIZE 10
/* Test verifies hipGraphMemcpyNodeSetParams API Negative scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams_Negative") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms;
int* hData;
uint32_t size = width * height * depth * sizeof(int);
hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipError_t ret;
hipGraphNode_t memcpyNode;
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
SECTION("Pass node as nullptr") {
ret = hipGraphMemcpyNodeSetParams(nullptr, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass un-initialize node") {
hipGraphNode_t memcpyNode_uninit{};
ret = hipGraphMemcpyNodeSetParams(memcpyNode_uninit, &myparms);
REQUIRE(hipErrorInvalidValue == ret);
}
SECTION("Pass SetNodeParams as nullptr") {
ret = hipGraphMemcpyNodeSetParams(memcpyNode, nullptr);
REQUIRE(hipErrorInvalidValue == ret);
}
HIP_CHECK(hipFreeArray(devArray));
free(hData);
HIP_CHECK(hipGraphDestroy(graph));
}
/* Test verifies hipGraphMemcpyNodeSetParams API Functional scenarios.
*/
TEST_CASE("Unit_hipGraphMemcpyNodeSetParams_Functional") {
CHECK_IMAGE_SUPPORT
constexpr int width{SIZE}, height{SIZE}, depth{SIZE};
hipArray_t devArray;
hipChannelFormatKind formatKind = hipChannelFormatKindSigned;
hipMemcpy3DParms myparms, myparms1;
uint32_t size = width * height * depth * sizeof(int);
int *hData = reinterpret_cast<int*>(malloc(size));
REQUIRE(hData != nullptr);
memset(hData, 0, size);
int *hDataTemp = reinterpret_cast<int*>(malloc(size));
REQUIRE(hDataTemp != nullptr);
memset(hDataTemp, 0, size);
int *hOutputData = reinterpret_cast<int *>(malloc(size));
REQUIRE(hOutputData != nullptr);
memset(hOutputData, 0, size);
int *hOutputData1 = reinterpret_cast<int *>(malloc(size));
REQUIRE(hOutputData1 != nullptr);
memset(hOutputData1, 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;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(int)*8,
0, 0, 0, formatKind);
HIP_CHECK(hipMalloc3DArray(&devArray, &channelDesc, make_hipExtent(width,
height, depth), hipArrayDefault));
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
// Host to Device
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.extent = make_hipExtent(width , height, depth);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(int),
width, height);
myparms.dstArray = devArray;
myparms.kind = hipMemcpyHostToDevice;
hipGraph_t graph;
hipGraphNode_t memcpyNode;
std::vector<hipGraphNode_t> dependencies;
hipStream_t streamForGraph;
hipGraphExec_t graphExec;
HIP_CHECK(hipStreamCreate(&streamForGraph));
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, NULL, 0, &myparms));
dependencies.push_back(memcpyNode);
// Device to host
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.dstPtr = make_hipPitchedPtr(hDataTemp, width * sizeof(int),
width, height);
myparms1.srcArray = devArray;
myparms1.extent = make_hipExtent(width, height, depth);
myparms1.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
dependencies.size(), &myparms1));
SECTION("Update the memcpyNode and check") {
// Device to host with updated host ptr hDataTemp -> hOutputData
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.dstPtr = make_hipPitchedPtr(hOutputData, width * sizeof(int),
width, height);
myparms1.srcArray = devArray;
myparms1.extent = make_hipExtent(width, height, depth);
myparms1.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphMemcpyNodeSetParams(memcpyNode, &myparms1));
// 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);
}
SECTION("Update the memcpyNode again and check") {
// Device to host with updated host ptr hOutputData -> hOutputData1
memset(&myparms1, 0x0, sizeof(hipMemcpy3DParms));
myparms1.srcPos = make_hipPos(0, 0, 0);
myparms1.dstPos = make_hipPos(0, 0, 0);
myparms1.dstPtr = make_hipPitchedPtr(hOutputData1, width * sizeof(int),
width, height);
myparms1.srcArray = devArray;
myparms1.extent = make_hipExtent(width, height, depth);
myparms1.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, dependencies.data(),
dependencies.size(), &myparms1));
HIP_CHECK(hipGraphMemcpyNodeSetParams(memcpyNode, &myparms1));
// 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, hOutputData1, width, height, depth);
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipFreeArray(devArray));
free(hData);
free(hDataTemp);
free(hOutputData);
free(hOutputData1);
}