From cefbaed5cf253ff47d4df5a6c673395483615e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirza=20Halil=C4=8Devi=C4=87?= <109971222+mirza-halilcevic@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:34:33 +0100 Subject: [PATCH] EXSWHTEC-217 - Implement new and update existing tests for the hipGraph*MemcpyNode family of APIs #48 Change-Id: Iae7ac9c855ba6e3288257e99e49f8b16cebb1bac --- catch/hipTestMain/config/config_amd_linux | 1 + catch/hipTestMain/config/config_amd_windows | 1 + catch/include/memcpy1d_tests_common.hh | 6 +- catch/include/memcpy3d_tests_common.hh | 1 + catch/unit/graph/CMakeLists.txt | 4 + catch/unit/graph/hipGraphAddMemcpyNode.cc | 775 ++++++------------ catch/unit/graph/hipGraphAddMemcpyNode_old.cc | 576 +++++++++++++ .../graph/hipGraphExecMemcpyNodeSetParams.cc | 470 +++++------ .../hipGraphExecMemcpyNodeSetParams_old.cc | 263 ++++++ .../unit/graph/hipGraphMemcpyNodeGetParams.cc | 264 ++---- .../graph/hipGraphMemcpyNodeGetParams_old.cc | 236 ++++++ .../unit/graph/hipGraphMemcpyNodeSetParams.cc | 432 +++++----- .../graph/hipGraphMemcpyNodeSetParams_old.cc | 219 +++++ 13 files changed, 2090 insertions(+), 1158 deletions(-) create mode 100644 catch/unit/graph/hipGraphAddMemcpyNode_old.cc create mode 100644 catch/unit/graph/hipGraphExecMemcpyNodeSetParams_old.cc create mode 100644 catch/unit/graph/hipGraphMemcpyNodeGetParams_old.cc create mode 100644 catch/unit/graph/hipGraphMemcpyNodeSetParams_old.cc diff --git a/catch/hipTestMain/config/config_amd_linux b/catch/hipTestMain/config/config_amd_linux index d24f21a772..8d89762cf3 100644 --- a/catch/hipTestMain/config/config_amd_linux +++ b/catch/hipTestMain/config/config_amd_linux @@ -127,6 +127,7 @@ "Unit_deviceAllocation_InOneThread_AccessInAllThreads", "=== Patch which removes the typetraits implementation from std namespace in hiprtc is reverted ===", "Unit_hiprtc_stdheaders", + "Unit_hipGraphAddMemcpyNode_Negative_Parameters", "Unit_hipMemAddressFree_negative", "Unit_hipMemAddressReserve_AlignmentTest", "Unit_hipMemAddressReserve_Negative", diff --git a/catch/hipTestMain/config/config_amd_windows b/catch/hipTestMain/config/config_amd_windows index 9a780a8730..623b25dfba 100644 --- a/catch/hipTestMain/config/config_amd_windows +++ b/catch/hipTestMain/config/config_amd_windows @@ -219,6 +219,7 @@ "=== Patch which removes the typetraits implementation from std namespace in hiprtc is reverted ===", "Unit_hiprtc_stdheaders", "Unit_hipMemAddressReserve_AlignmentTest", + "Unit_hipGraphAddMemcpyNode_Negative_Parameters", "Unit_hipMemCreate_ChkWithKerLaunch", "Unit_hipMemCreate_MapNonContiguousChunks", "Unit_hipMemMap_MapPartialPhysicalMem", diff --git a/catch/include/memcpy1d_tests_common.hh b/catch/include/memcpy1d_tests_common.hh index d357d992cb..ec8f991fa7 100644 --- a/catch/include/memcpy1d_tests_common.hh +++ b/catch/include/memcpy1d_tests_common.hh @@ -141,6 +141,7 @@ void MemcpyDeviceToDeviceShell(F memcpy_func, const hipStream_t kernel_stream = int can_access_peer = 0; HIP_CHECK(hipDeviceCanAccessPeer(&can_access_peer, src_device, dst_device)); if (!can_access_peer) { + INFO("Peer access cannot be enabled between devices " << src_device << " " << dst_device); return; } HIP_CHECK(hipDeviceEnablePeerAccess(dst_device, 0)); @@ -168,8 +169,8 @@ void MemcpyDeviceToDeviceShell(F memcpy_func, const hipStream_t kernel_stream = HIP_CHECK( hipMemcpy(result.host_ptr(), dst_allocation.ptr(), allocation_size, hipMemcpyDeviceToHost)); if constexpr (enable_peer_access) { - // If we've gotten this far, EnablePeerAccess must have succeeded, so we only need to check this - // condition + // If we've gotten this far, EnablePeerAccess must have succeeded, so we + // only need to check this condition HIP_CHECK(hipDeviceDisablePeerAccess(dst_device)); } @@ -237,7 +238,6 @@ void MemcpySyncBehaviorCheck(F memcpy_func, const bool should_sync, LaunchDelayKernel(std::chrono::milliseconds{100}, kernel_stream); HIP_CHECK(memcpy_func()); if (should_sync) { - HIP_CHECK(hipStreamSynchronize(kernel_stream)); HIP_CHECK(hipStreamQuery(kernel_stream)); } else { HIP_CHECK_ERROR(hipStreamQuery(kernel_stream), hipErrorNotReady); diff --git a/catch/include/memcpy3d_tests_common.hh b/catch/include/memcpy3d_tests_common.hh index 4978a264ac..84d0fc517b 100644 --- a/catch/include/memcpy3d_tests_common.hh +++ b/catch/include/memcpy3d_tests_common.hh @@ -23,6 +23,7 @@ THE SOFTWARE. #pragma once #pragma clang diagnostic ignored "-Wmissing-field-initializers" #pragma clang diagnostic ignored "-Wunused-lambda-capture" + #include #include diff --git a/catch/unit/graph/CMakeLists.txt b/catch/unit/graph/CMakeLists.txt index 2d0a3c50ff..cef5d2f5b7 100644 --- a/catch/unit/graph/CMakeLists.txt +++ b/catch/unit/graph/CMakeLists.txt @@ -32,6 +32,7 @@ set(TEST_SRC hipGraph.cc hipSimpleGraphWithKernel.cc hipGraphAddMemcpyNode.cc + hipGraphAddMemcpyNode_old.cc hipGraphClone.cc hipGraphInstantiateWithFlags.cc hipGraphAddHostNode.cc @@ -72,6 +73,7 @@ set(TEST_SRC hipGraphEventRecordNodeSetEvent.cc hipGraphEventWaitNodeGetEvent.cc hipGraphExecMemcpyNodeSetParams.cc + hipGraphExecMemcpyNodeSetParams_old.cc hipStreamBeginCapture.cc hipGraphAddMemcpyNode1D_old.cc hipGraphAddMemcpyNode1D.cc @@ -101,7 +103,9 @@ set(TEST_SRC hipGraphAddMemsetNode.cc hipGraphAddKernelNode.cc hipGraphMemcpyNodeGetParams.cc + hipGraphMemcpyNodeGetParams_old.cc hipGraphMemcpyNodeSetParams.cc + hipGraphMemcpyNodeSetParams_old.cc hipGraphKernelNodeGetParams.cc hipGraphKernelNodeSetParams.cc hipGraphExecKernelNodeSetParams.cc diff --git a/catch/unit/graph/hipGraphAddMemcpyNode.cc b/catch/unit/graph/hipGraphAddMemcpyNode.cc index 6b8e34bed8..57b5d3f0b6 100644 --- a/catch/unit/graph/hipGraphAddMemcpyNode.cc +++ b/catch/unit/graph/hipGraphAddMemcpyNode.cc @@ -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 #include -#include -#include -#include +#include +#include -#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(Memcpy3DWrapper); } - int *hData = reinterpret_cast(malloc(size)); - int *hOutputData = reinterpret_cast(malloc(size)); + SECTION("Device to host with default kind") { + Memcpy3DDeviceToHostShell(Memcpy3DWrapper); + } - REQUIRE(hData != nullptr); - REQUIRE(hOutputData != nullptr); - memset(hData, 0, size); - memset(hOutputData, 0, size); + SECTION("Host to device") { Memcpy3DHostToDeviceShell(Memcpy3DWrapper); } - HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphCreate(&graph, 0)); + SECTION("Host to device with default kind") { + Memcpy3DHostToDeviceShell(Memcpy3DWrapper); + } - // 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(Memcpy3DWrapper); } + + SECTION("Host to host with default kind") { + Memcpy3DHostToHostShell(Memcpy3DWrapper); + } + + SECTION("Device to device") { + SECTION("Peer access enabled") { + Memcpy3DDeviceToDeviceShell(Memcpy3DWrapper); + } + SECTION("Peer access disabled") { + Memcpy3DDeviceToDeviceShell(Memcpy3DWrapper); } } - 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 dependencies; - hipStream_t streamForGraph; - hipGraphExec_t graphExec; - - HIP_CHECK(hipSetDevice(0)); - int *hData = reinterpret_cast(malloc(size)); - int *hOutputData = reinterpret_cast(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(Memcpy3DWrapper); + } + SECTION("Peer access disabled") { + Memcpy3DDeviceToDeviceShell(Memcpy3DWrapper); } } - 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(Memcpy3DWrapper); } - // 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 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 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(Memcpy3DWrapper); } +#endif } /** - * Basic Functional Tests adds memcpy nodes of types H2D, D2D and D2H to graph - * and verifies execution sequence by launching graph on default device. - * Tests also verify memcpy node addition with 1D, 2D and 3D objects. + * Test Description + * ------------------------ + * - Verify API behaviour with invalid arguments: + * -# node is nullptr + * -# graph is nullptr + * -# pDependencies is nullptr when numDependencies is not zero + * -# A node in pDependencies originates from a different graph + * -# numDependencies is invalid + * -# A node is duplicated in pDependencies + * -# dst is nullptr + * -# src is nullptr + * -# kind is an invalid enum value + * -# count is zero + * -# count is larger than dst allocation size + * -# count is larger than src allocation size + * Test source + * ------------------------ + * - unit/graph/hipGraphAddMemcpyNode.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 */ -TEST_CASE("Unit_hipGraphAddMemcpyNode_BasicFunctional") { - CHECK_IMAGE_SUPPORT +TEST_CASE("Unit_hipGraphAddMemcpyNode_Negative_Parameters") { + using namespace std::placeholders; - SECTION("Memcpy with 3D array on default device") { - validateMemcpyNode3DArray(); + constexpr hipExtent extent{128 * sizeof(int), 128, 8}; + + constexpr auto NegativeTests = [](hipPitchedPtr dst_ptr, hipPos dst_pos, hipPitchedPtr src_ptr, + hipPos src_pos, hipExtent extent, hipMemcpyKind kind) { + hipGraph_t graph = nullptr; + HIP_CHECK(hipGraphCreate(&graph, 0)); + hipGraphNode_t node = nullptr; + + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent, kind); + GraphAddNodeCommonNegativeTests(std::bind(hipGraphAddMemcpyNode, _1, _2, _3, _4, ¶ms), + graph); + + SECTION("dst_ptr.ptr == nullptr") { + hipPitchedPtr invalid_ptr = dst_ptr; + invalid_ptr.ptr = nullptr; + auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("src_ptr.ptr == nullptr") { + hipPitchedPtr invalid_ptr = src_ptr; + invalid_ptr.ptr = nullptr; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("dst_ptr.pitch < width") { + hipPitchedPtr invalid_ptr = dst_ptr; + invalid_ptr.pitch = extent.width - 1; + auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidPitchValue); + } + + SECTION("src_ptr.pitch < width") { + hipPitchedPtr invalid_ptr = src_ptr; + invalid_ptr.pitch = extent.width - 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidPitchValue); + } + + SECTION("dst_ptr.pitch > max pitch") { + int attr = 0; + HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0)); + hipPitchedPtr invalid_ptr = dst_ptr; + invalid_ptr.pitch = attr; + auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("src_ptr.pitch > max pitch") { + int attr = 0; + HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0)); + hipPitchedPtr invalid_ptr = src_ptr; + invalid_ptr.pitch = attr; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("extent.width + dst_pos.x > dst_ptr.pitch") { + hipPos invalid_pos = dst_pos; + invalid_pos.x = dst_ptr.pitch - extent.width + 1; + auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("extent.width + src_pos.x > src_ptr.pitch") { + hipPos invalid_pos = src_pos; + invalid_pos.x = src_ptr.pitch - extent.width + 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("dst_pos.y out of bounds") { + hipPos invalid_pos = dst_pos; + invalid_pos.y = 1; + auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("src_pos.y out of bounds") { + hipPos invalid_pos = src_pos; + invalid_pos.y = 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("dst_pos.z out of bounds") { + hipPos invalid_pos = dst_pos; + invalid_pos.z = 1; + auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("src_pos.z out of bounds") { + hipPos invalid_pos = src_pos; + invalid_pos.z = 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidValue); + } + + SECTION("Invalid MemcpyKind") { + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent, + static_cast(-1)); + HIP_CHECK_ERROR(hipGraphAddMemcpyNode(&node, graph, nullptr, 0, ¶ms), + hipErrorInvalidMemcpyDirection); + } + + HIP_CHECK(hipGraphDestroy(graph)); + }; + + SECTION("Host to Device") { + LinearAllocGuard3D device_alloc(extent); + LinearAllocGuard 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 device_alloc(extent); + LinearAllocGuard 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 src_alloc(LinearAllocs::hipHostMalloc, + extent.width * extent.height * extent.depth); + LinearAllocGuard 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 src_alloc(extent); + LinearAllocGuard3D 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 A_h(numW); - std::vector 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); -} diff --git a/catch/unit/graph/hipGraphAddMemcpyNode_old.cc b/catch/unit/graph/hipGraphAddMemcpyNode_old.cc new file mode 100644 index 0000000000..6b8e34bed8 --- /dev/null +++ b/catch/unit/graph/hipGraphAddMemcpyNode_old.cc @@ -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 +#include +#include +#include + +#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(malloc(size)); + int *hOutputData = reinterpret_cast(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 dependencies; + hipStream_t streamForGraph; + hipGraphExec_t graphExec; + + HIP_CHECK(hipSetDevice(0)); + int *hData = reinterpret_cast(malloc(size)); + int *hOutputData = reinterpret_cast(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 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 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 A_h(numW); + std::vector 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); +} diff --git a/catch/unit/graph/hipGraphExecMemcpyNodeSetParams.cc b/catch/unit/graph/hipGraphExecMemcpyNodeSetParams.cc index 3fe07bae58..7520d88d03 100644 --- a/catch/unit/graph/hipGraphExecMemcpyNodeSetParams.cc +++ b/catch/unit/graph/hipGraphExecMemcpyNodeSetParams.cc @@ -1,13 +1,16 @@ /* Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -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 #include -#include +#include +#include +#include -/* 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(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(src) + 1; + const auto offset_dst = reinterpret_cast(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, ¶ms)); + 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, ¶ms)); + 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(f); +#else + using namespace std::placeholders; + + SECTION("Device to host") { + MemcpyDeviceToHostShell(std::bind(f, _1, _2, _3, hipMemcpyDeviceToHost)); + } + + SECTION("Host to device") { + MemcpyHostToDeviceShell(std::bind(f, _1, _2, _3, hipMemcpyHostToDevice)); + } + + SECTION("Device to device") { + SECTION("Peer access enabled") { + MemcpyDeviceToDeviceShell(std::bind(f, _1, _2, _3, hipMemcpyDeviceToDevice)); + } + SECTION("Peer access disabled") { + MemcpyDeviceToDeviceShell(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 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(std::bind(f, _1, _2, _3, hipMemcpyDefault)); + } + SECTION("Peer access disabled") { + MemcpyDeviceToDeviceShell(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(std::bind(f, _1, _2, _3, hipMemcpyHostToHost)); + } + + SECTION("Host to host with default kind") { + MemcpyHostToHostShell(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(std::bind(f, _1, _2, _3, hipMemcpyDefault)); + } + + SECTION("Host to device with default kind") { + MemcpyHostToDeviceShell(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, ¶ms)); + + hipGraphExec_t graph_exec = nullptr; + HIP_CHECK(hipGraphInstantiate(&graph_exec, graph, nullptr, nullptr, 0)); + + SECTION("pGraphExec == nullptr") { + HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(nullptr, node, ¶ms), hipErrorInvalidValue); + } + + SECTION("node == nullptr") { + HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, nullptr, ¶ms), + hipErrorInvalidValue); + } + + auto f = [&](void* dst, void* src, size_t count, hipMemcpyKind kind) { + auto 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(sizeof(dst), 1, 1), kind); + return hipGraphExecMemcpyNodeSetParams(graph_exec, node, ¶ms); + }; + 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 dev_dst(LinearAllocs::hipMalloc, sizeof(int)); + params.dstPtr = make_hipPitchedPtr(dev_dst.ptr(), 0, sizeof(int), 0); + HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, node, ¶ms), + hipErrorInvalidValue); + } + + SECTION("count larger than src allocation size") { + LinearAllocGuard dev_src(LinearAllocs::hipMalloc, sizeof(int)); + params.dstPtr = make_hipPitchedPtr(dev_src.ptr(), 0, sizeof(int), 0); + HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParams(graph_exec, node, ¶ms), + 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 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, ¶ms)); + + 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, ¶ms), hipErrorInvalidValue); + + HIP_CHECK(hipGraphExecDestroy(graph_exec)); + HIP_CHECK(hipGraphDestroy(graph)); +} \ No newline at end of file diff --git a/catch/unit/graph/hipGraphExecMemcpyNodeSetParams_old.cc b/catch/unit/graph/hipGraphExecMemcpyNodeSetParams_old.cc new file mode 100644 index 0000000000..3fe07bae58 --- /dev/null +++ b/catch/unit/graph/hipGraphExecMemcpyNodeSetParams_old.cc @@ -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 +#include + +/* 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(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 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)); +} diff --git a/catch/unit/graph/hipGraphMemcpyNodeGetParams.cc b/catch/unit/graph/hipGraphMemcpyNodeGetParams.cc index 34a9ff7d48..752aae29c5 100644 --- a/catch/unit/graph/hipGraphMemcpyNodeGetParams.cc +++ b/catch/unit/graph/hipGraphMemcpyNodeGetParams.cc @@ -1,13 +1,16 @@ /* Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -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 #include -#include +#include -#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(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(hpPtr1.ptr) == - reinterpret_cast(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 src_alloc(extent); + LinearAllocGuard3D 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(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, ¶ms), 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(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, ¶ms)); + 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, ¶ms)); + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK_ERROR(hipGraphMemcpyNodeGetParams(node, ¶ms), hipErrorInvalidValue); + } +#endif +} \ No newline at end of file diff --git a/catch/unit/graph/hipGraphMemcpyNodeGetParams_old.cc b/catch/unit/graph/hipGraphMemcpyNodeGetParams_old.cc new file mode 100644 index 0000000000..34a9ff7d48 --- /dev/null +++ b/catch/unit/graph/hipGraphMemcpyNodeGetParams_old.cc @@ -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 +#include + +#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(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(hpPtr1.ptr) == + reinterpret_cast(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(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(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)); +} diff --git a/catch/unit/graph/hipGraphMemcpyNodeSetParams.cc b/catch/unit/graph/hipGraphMemcpyNodeSetParams.cc index 2942729960..d56596164f 100644 --- a/catch/unit/graph/hipGraphMemcpyNodeSetParams.cc +++ b/catch/unit/graph/hipGraphMemcpyNodeSetParams.cc @@ -1,13 +1,16 @@ /* Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -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 #include -#include +#include +#include -#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(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(Memcpy3DWrapper); + } + + SECTION("Device to host with default kind") { + Memcpy3DDeviceToHostShell(Memcpy3DWrapper); + } + + SECTION("Host to device") { + Memcpy3DHostToDeviceShell(Memcpy3DWrapper); + } + + SECTION("Host to device with default kind") { + Memcpy3DHostToDeviceShell(Memcpy3DWrapper); + } + + SECTION("Host to host") { Memcpy3DHostToHostShell(Memcpy3DWrapper); } + + SECTION("Host to host with default kind") { + Memcpy3DHostToHostShell(Memcpy3DWrapper); + } + + SECTION("Device to device") { + SECTION("Peer access enabled") { + Memcpy3DDeviceToDeviceShell(Memcpy3DWrapper); + } + SECTION("Peer access disabled") { + Memcpy3DDeviceToDeviceShell(Memcpy3DWrapper); } } - 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(malloc(size)); - REQUIRE(hData != nullptr); - memset(hData, 0, size); - int *hDataTemp = reinterpret_cast(malloc(size)); - REQUIRE(hDataTemp != nullptr); - memset(hDataTemp, 0, size); - int *hOutputData = reinterpret_cast(malloc(size)); - REQUIRE(hOutputData != nullptr); - memset(hOutputData, 0, size); - int *hOutputData1 = reinterpret_cast(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(Memcpy3DWrapper); + } + SECTION("Peer access disabled") { + Memcpy3DDeviceToDeviceShell(Memcpy3DWrapper); } } - 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 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(Memcpy3DWrapper); } - 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(Memcpy3DWrapper); } - 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, ¶ms), 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, ¶ms), hipErrorInvalidValue); + } + + SECTION("src_ptr.ptr == nullptr") { + hipPitchedPtr invalid_ptr = src_ptr; + invalid_ptr.ptr = nullptr; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("dst_ptr.pitch < width") { + hipPitchedPtr invalid_ptr = dst_ptr; + invalid_ptr.pitch = extent.width - 1; + auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidPitchValue); + } + + SECTION("src_ptr.pitch < width") { + hipPitchedPtr invalid_ptr = src_ptr; + invalid_ptr.pitch = extent.width - 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidPitchValue); + } + + SECTION("dst_ptr.pitch > max pitch") { + int attr = 0; + HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0)); + hipPitchedPtr invalid_ptr = dst_ptr; + invalid_ptr.pitch = attr; + auto params = GetMemcpy3DParms(invalid_ptr, dst_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("src_ptr.pitch > max pitch") { + int attr = 0; + HIP_CHECK(hipDeviceGetAttribute(&attr, hipDeviceAttributeMaxPitch, 0)); + hipPitchedPtr invalid_ptr = src_ptr; + invalid_ptr.pitch = attr; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, invalid_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("extent.width + dst_pos.x > dst_ptr.pitch") { + hipPos invalid_pos = dst_pos; + invalid_pos.x = dst_ptr.pitch - extent.width + 1; + auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("extent.width + src_pos.x > src_ptr.pitch") { + hipPos invalid_pos = src_pos; + invalid_pos.x = src_ptr.pitch - extent.width + 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("dst_pos.y out of bounds") { + hipPos invalid_pos = dst_pos; + invalid_pos.y = 1; + auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("src_pos.y out of bounds") { + hipPos invalid_pos = src_pos; + invalid_pos.y = 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("dst_pos.z out of bounds") { + hipPos invalid_pos = dst_pos; + invalid_pos.z = 1; + auto params = GetMemcpy3DParms(dst_ptr, invalid_pos, src_ptr, src_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("src_pos.z out of bounds") { + hipPos invalid_pos = src_pos; + invalid_pos.z = 1; + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, invalid_pos, extent, kind); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidValue); + } + + SECTION("Invalid MemcpyKind") { + auto params = GetMemcpy3DParms(dst_ptr, dst_pos, src_ptr, src_pos, extent, + static_cast(-1)); + HIP_CHECK_ERROR(hipGraphMemcpyNodeSetParams(node, ¶ms), hipErrorInvalidMemcpyDirection); + } + + HIP_CHECK(hipGraphDestroy(graph)); + }; + + SECTION("Host to Device") { + LinearAllocGuard3D device_alloc(extent); + LinearAllocGuard 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 device_alloc(extent); + LinearAllocGuard 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 src_alloc(LinearAllocs::hipHostMalloc, + extent.width * extent.height * extent.depth); + LinearAllocGuard 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 src_alloc(extent); + LinearAllocGuard3D dst_alloc(extent); + NegativeTests(dst_alloc.pitched_ptr(), make_hipPos(0, 0, 0), src_alloc.pitched_ptr(), + make_hipPos(0, 0, 0), extent, hipMemcpyDeviceToDevice); + } +} \ No newline at end of file diff --git a/catch/unit/graph/hipGraphMemcpyNodeSetParams_old.cc b/catch/unit/graph/hipGraphMemcpyNodeSetParams_old.cc new file mode 100644 index 0000000000..2942729960 --- /dev/null +++ b/catch/unit/graph/hipGraphMemcpyNodeSetParams_old.cc @@ -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 +#include + +#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(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(malloc(size)); + REQUIRE(hData != nullptr); + memset(hData, 0, size); + int *hDataTemp = reinterpret_cast(malloc(size)); + REQUIRE(hDataTemp != nullptr); + memset(hDataTemp, 0, size); + int *hOutputData = reinterpret_cast(malloc(size)); + REQUIRE(hOutputData != nullptr); + memset(hOutputData, 0, size); + int *hOutputData1 = reinterpret_cast(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 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); +}