From 2cf38e9e33afa8caa2bd33d09273ad78852e3332 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:59:08 +0530 Subject: [PATCH 1/4] SWDEV-357695 - [catch2][dtest] hipGraphKernelNodeCopyAttributes API test (#90) Change-Id: I8a7494cbb056df8b2b6b0bf5810f67e4eed4db7b --- catch/unit/graph/CMakeLists.txt | 1 + .../graph/hipGraphKernelNodeCopyAttributes.cc | 165 ++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 catch/unit/graph/hipGraphKernelNodeCopyAttributes.cc diff --git a/catch/unit/graph/CMakeLists.txt b/catch/unit/graph/CMakeLists.txt index ee58c1672c..5a93f0c83e 100644 --- a/catch/unit/graph/CMakeLists.txt +++ b/catch/unit/graph/CMakeLists.txt @@ -104,6 +104,7 @@ set(TEST_SRC hipGraphDestroy.cc hipGraphExecDestroy.cc hipGraphUpload.cc + hipGraphKernelNodeCopyAttributes.cc ) hip_add_exe_to_target(NAME GraphsTest diff --git a/catch/unit/graph/hipGraphKernelNodeCopyAttributes.cc b/catch/unit/graph/hipGraphKernelNodeCopyAttributes.cc new file mode 100644 index 0000000000..7ebd9953ff --- /dev/null +++ b/catch/unit/graph/hipGraphKernelNodeCopyAttributes.cc @@ -0,0 +1,165 @@ +/* +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. +*/ + +#include +#include +#include + +/** + * Functional Test for API - hipGraphKernelNodeCopyAttributes + - Create graph with 2 kernel node. + Copy the attribute from 1st kernel node to 2nd kernel node. + */ + +TEST_CASE("Unit_hipGraphKernelNodeCopyAttributes_Functional") { + constexpr size_t N = 1024; + constexpr size_t Nbytes = N * sizeof(int); + constexpr auto blocksPerCU = 6; // to hide latency + constexpr auto threadsPerBlock = 256; + hipGraph_t graph; + hipGraphNode_t memcpyNode, kNode; + hipKernelNodeParams kNodeParams{}; + hipStream_t stream; + int *A_d, *B_d, *C_d; + int *A_h, *B_h, *C_h; + std::vector dependencies; + hipGraphExec_t graphExec; + size_t NElem{N}; + + HIP_CHECK(hipStreamCreate(&stream)); + HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false); + unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N); + + HIP_CHECK(hipGraphCreate(&graph, 0)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, nullptr, 0, A_d, A_h, + Nbytes, hipMemcpyHostToDevice)); + dependencies.push_back(memcpyNode); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, nullptr, 0, B_d, B_h, + Nbytes, hipMemcpyHostToDevice)); + dependencies.push_back(memcpyNode); + + void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast(&NElem)}; + kNodeParams.func = reinterpret_cast(HipTest::vectorADD); + kNodeParams.gridDim = dim3(blocks); + kNodeParams.blockDim = dim3(threadsPerBlock); + kNodeParams.sharedMemBytes = 0; + kNodeParams.kernelParams = reinterpret_cast(kernelArgs); + kNodeParams.extra = nullptr; + HIP_CHECK(hipGraphAddKernelNode(&kNode, graph, dependencies.data(), + dependencies.size(), &kNodeParams)); + dependencies.clear(); + dependencies.push_back(kNode); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, dependencies.data(), + dependencies.size(), C_h, C_d, + Nbytes, hipMemcpyDeviceToHost)); + + hipGraphNode_t kNode2; + + HIP_CHECK(hipGraphAddKernelNode(&kNode2, graph, nullptr, 0, &kNodeParams)); + HIP_CHECK(hipGraphKernelNodeCopyAttributes(kNode2, kNode)); + + // Instantiate and launch the graph + HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0)); + HIP_CHECK(hipGraphLaunch(graphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + // Verify graph execution result + HipTest::checkVectorADD(A_h, B_h, C_h, N); + + HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); + HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK(hipStreamDestroy(stream)); +} + +/** + Negative Test for API - hipGraphKernelNodeCopyAttributes + 1) Pass source kernel node as nullptr for copy attribute api + 2) Pass destination kernel node as nullptr for copy attribute api + 3) Pass source kernel node as Uninitialize for copy attribute api + 4) Pass dest kernel node as Uninitialize for copy attribute api + */ + +TEST_CASE("Unit_hipGraphKernelNodeCopyAttributes_Attribute_Negative") { + constexpr size_t N = 1024; + constexpr size_t Nbytes = N * sizeof(int); + constexpr auto blocksPerCU = 6; // to hide latency + constexpr auto threadsPerBlock = 256; + hipGraph_t graph; + hipGraphNode_t memcpyNode, kNode, kNode_2; + hipKernelNodeParams kNodeParams{}; + hipStream_t streamForGraph; + int *A_d, *B_d, *C_d; + int *A_h, *B_h, *C_h; + std::vector dependencies; + size_t NElem{N}; + hipError_t ret; + + HIP_CHECK(hipStreamCreate(&streamForGraph)); + HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false); + unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N); + + HIP_CHECK(hipGraphCreate(&graph, 0)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, nullptr, 0, A_d, A_h, + Nbytes, hipMemcpyHostToDevice)); + dependencies.push_back(memcpyNode); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, nullptr, 0, B_d, B_h, + Nbytes, hipMemcpyHostToDevice)); + dependencies.push_back(memcpyNode); + + void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast(&NElem)}; + kNodeParams.func = reinterpret_cast(HipTest::vectorADD); + kNodeParams.gridDim = dim3(blocks); + kNodeParams.blockDim = dim3(threadsPerBlock); + kNodeParams.sharedMemBytes = 0; + kNodeParams.kernelParams = reinterpret_cast(kernelArgs); + kNodeParams.extra = nullptr; + HIP_CHECK(hipGraphAddKernelNode(&kNode, graph, dependencies.data(), + dependencies.size(), &kNodeParams)); + dependencies.clear(); + dependencies.push_back(kNode); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyNode, graph, dependencies.data(), + dependencies.size(), C_h, C_d, + Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddKernelNode(&kNode_2, graph, nullptr, 0, &kNodeParams)); + + SECTION("Pass source kernel node as nullptr for copy attribute api") { + ret = hipGraphKernelNodeCopyAttributes(nullptr, kNode); + REQUIRE(hipErrorInvalidValue == ret); + } + SECTION("Pass destination kernel node as nullptr for copy attribute api") { + ret = hipGraphKernelNodeCopyAttributes(kNode_2, nullptr); + REQUIRE(hipErrorInvalidValue == ret); + } + SECTION("Pass source kernel node as Uninitialize for copy attribute api") { + hipGraphNode_t kNodeUninit{}; + ret = hipGraphKernelNodeCopyAttributes(kNodeUninit, kNode); + REQUIRE(hipErrorInvalidValue == ret); + } + SECTION("Pass dest kernel node as Uninitialize for copy attribute api") { + hipGraphNode_t kNodeUninit{}; + ret = hipGraphKernelNodeCopyAttributes(kNode_2, kNodeUninit); + REQUIRE(hipErrorInvalidValue == ret); + } + + HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK(hipStreamDestroy(streamForGraph)); +} + From 993eeb955fc1bb326895b2c5a7ee9dc1dd67abc9 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:59:35 +0530 Subject: [PATCH 2/4] SWDEV-373476 - [catch2][dtest] hipGraphNodeSetEnabled API test case added few more graph scenarios (#198) Change-Id: Iff3bb5b937117a89cb6dbe0229a27fe11bcaa6e0 --- catch/unit/graph/hipGraphNodeSetEnabled.cc | 241 +++++++++++++++++---- 1 file changed, 197 insertions(+), 44 deletions(-) diff --git a/catch/unit/graph/hipGraphNodeSetEnabled.cc b/catch/unit/graph/hipGraphNodeSetEnabled.cc index 15760ad17b..c8cd3751fb 100644 --- a/catch/unit/graph/hipGraphNodeSetEnabled.cc +++ b/catch/unit/graph/hipGraphNodeSetEnabled.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. +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 @@ -187,20 +187,22 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_Basic") { } /* Functional Test for API - hipGraphNodeSetEnabled - 9) Add a Kernel node(Vector_Square) with functonally to the graph and than + 9) Add a Kernel node(Vector_Square) with functonallty to the graph and than Disable kernel node and verify the result and - 10) Enable Kernel node and verify the result */ + 10) Enable Kernel node and verify the result + 11) Make ClonedGraph and disabled the kernel node in ClonedGraph and verify + 12) Enable the Kernel node in ClonedGraph and verify the result */ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_KernelNode") { constexpr size_t Nbytes = N * sizeof(int); constexpr auto blocksPerCU = 6; // to hide latency constexpr auto threadsPerBlock = 256; - hipGraph_t graph; + hipGraph_t graph, clonedGraph; hipStream_t stream; - hipGraphNode_t memcpy_A, memcpy_C, kNodeSquare; + hipGraphNode_t memcpy_A, memcpy_C, kNodeSquare, kNodeSquare_C; hipKernelNodeParams kNodeParams{}; int *A_d, *C_d, *A_h, *C_h; - hipGraphExec_t graphExec; + hipGraphExec_t graphExec, clonedGraphExec; size_t NElem{N}; unsigned int setEnable = 0, getEnable = 0; @@ -261,25 +263,69 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_KernelNode") { REQUIRE(true == verifyVectorSquare(A_h, C_h, N)); } + // Code for cloned graph operations + HIP_CHECK(hipGraphClone(&clonedGraph, graph)); + HIP_CHECK(hipGraphInstantiate(&clonedGraphExec, clonedGraph, + nullptr, nullptr, 0)); + HIP_CHECK(hipGraphNodeFindInClone(&kNodeSquare_C, kNodeSquare, clonedGraph)); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyVectorSquare(A_h, C_h, N)); + + SECTION("After disabled kernel node in ClonedGraph & verify the result") { + setEnable = 0; // for disabled a node + HIP_CHECK(hipGraphNodeSetEnabled(clonedGraphExec, + kNodeSquare_C, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(clonedGraphExec, + kNodeSquare_C, &getEnable)); + REQUIRE(setEnable == getEnable); + + HIP_CHECK(hipMemset(C_d, 0, Nbytes)); + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true != verifyVectorSquare(A_h, C_h, N)); + } + SECTION("Again enabled kernel node in ClonedGraph & verify the result") { + setEnable = 1; // for enabled a node + HIP_CHECK(hipGraphNodeSetEnabled(clonedGraphExec, + kNodeSquare_C, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(clonedGraphExec, + kNodeSquare_C, &getEnable)); + REQUIRE(setEnable == getEnable); + + HIP_CHECK(hipMemset(C_d, 0, Nbytes)); + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyVectorSquare(A_h, C_h, N)); + } + HipTest::freeArrays(A_d, nullptr, C_d, A_h, nullptr, C_h, false); HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphExecDestroy(clonedGraphExec)); + HIP_CHECK(hipGraphDestroy(clonedGraph)); HIP_CHECK(hipGraphDestroy(graph)); HIP_CHECK(hipStreamDestroy(stream)); } /* Functional Test for API - hipGraphNodeSetEnabled - 11) Add a MemSet node with functonally to the graph and than + 13) Add a MemSet node with functonally to the graph and than Disable MemSet node and verify the result and - 12) Enable MemSet node and verify the result */ + 14) Enable MemSet node and verify the result + 15) Make ClonedGraph and disabled the MemSet node in ClonedGraph and verify + 16) Enable the MemSet node in ClonedGraph and verify the result */ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemSet") { constexpr size_t Nbytes = N * sizeof(char); constexpr size_t val = 9; - hipGraph_t graph; - hipGraphExec_t graphExec; + hipGraph_t graph, clonedGraph; + hipGraphExec_t graphExec, clonedGraphExec; hipStream_t stream; - hipGraphNode_t memcpy_A, memcpy_AC, memcpy_C, memsetNode; - int setEnable; + hipGraphNode_t memcpy_A, memcpy_AC, memcpy_C, memsetNode, memsetNode_C; + unsigned int setEnable = 0, getEnable = 0; char *A_d, *C_d, *A_h, *B_h, *C_h; HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, &B_h, &C_h, N, false); @@ -313,15 +359,17 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemSet") { HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); - SECTION("Without disabling MemSet node and verify the execution result") { - HIP_CHECK(hipGraphLaunch(graphExec, stream)); - HIP_CHECK(hipStreamSynchronize(stream)); + // Verify the execution result - basic check 1st time + HIP_CHECK(hipGraphLaunch(graphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyArray(B_h, C_h, N)); - REQUIRE(true == verifyArray(B_h, C_h, N)); - } SECTION("After disabled MemSet node and verify the execution result") { - setEnable = 0; // for disabled + setEnable = 0; // for disabled a node HIP_CHECK(hipGraphNodeSetEnabled(graphExec, memsetNode, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(graphExec, memsetNode, &getEnable)); + REQUIRE(setEnable == getEnable); HIP_CHECK(hipGraphLaunch(graphExec, stream)); HIP_CHECK(hipStreamSynchronize(stream)); @@ -329,8 +377,10 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemSet") { REQUIRE(true == verifyArray(A_h, C_h, N)); } SECTION("Again enabled MemSet node and verify the execution result") { - setEnable = 1; // for enabled + setEnable = 1; // for enabled a node HIP_CHECK(hipGraphNodeSetEnabled(graphExec, memsetNode, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(graphExec, memsetNode, &getEnable)); + REQUIRE(setEnable == getEnable); HIP_CHECK(hipGraphLaunch(graphExec, stream)); HIP_CHECK(hipStreamSynchronize(stream)); @@ -338,29 +388,71 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemSet") { REQUIRE(true == verifyArray(B_h, C_h, N)); } + // Code for cloned graph operations + HIP_CHECK(hipGraphClone(&clonedGraph, graph)); + HIP_CHECK(hipGraphInstantiate(&clonedGraphExec, clonedGraph, + nullptr, nullptr, 0)); + HIP_CHECK(hipGraphNodeFindInClone(&memsetNode_C, memsetNode, clonedGraph)); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyArray(B_h, C_h, N)); + + SECTION("After disabled MemSet node and verify the execution result") { + setEnable = 0; // for disabled a node + HIP_CHECK(hipGraphNodeSetEnabled(clonedGraphExec, + memsetNode_C, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(clonedGraphExec, + memsetNode_C, &getEnable)); + REQUIRE(setEnable == getEnable); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyArray(A_h, C_h, N)); + } + SECTION("Again enabled MemSet node and verify the execution result") { + setEnable = 1; // for enabled a node + HIP_CHECK(hipGraphNodeSetEnabled(clonedGraphExec, + memsetNode_C, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(clonedGraphExec, + memsetNode_C, &getEnable)); + REQUIRE(setEnable == getEnable); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyArray(B_h, C_h, N)); + } + HipTest::freeArrays(A_d, nullptr, C_d, A_h, B_h, C_h, false); HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphExecDestroy(clonedGraphExec)); + HIP_CHECK(hipGraphDestroy(clonedGraph)); HIP_CHECK(hipGraphDestroy(graph)); HIP_CHECK(hipStreamDestroy(stream)); } /* Functional Test for API - hipGraphNodeSetEnabled - 13) Add a MemCpy node with functonally to the graph and than + 17) Add a MemCpy node with functonally to the graph and than Disable MemCpy node and verify the result and - 14) Enable MemCpy node and verify the result */ + 18) Enable MemCpy node and verify the result + 19) Make ClonedGraph and disabled the MemCpy node in ClonedGraph and verify + 20) Enable the MemCpy node in ClonedGraph and verify the result */ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemCpy") { constexpr size_t Nbytes = N * sizeof(int); constexpr auto blocksPerCU = 6; // to hide latency constexpr auto threadsPerBlock = 256; - hipGraph_t graph; + hipGraph_t graph, clonedGraph; hipStream_t stream; - hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kNodeSquare; + hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, kNodeSquare, memcpy_B_C; hipKernelNodeParams kNodeParams{}; int *A_d, *C_d, *A_h, *B_h, *C_h; - hipGraphExec_t graphExec; + hipGraphExec_t graphExec, clonedGraphExec; size_t NElem{N}; - int setEnable; + unsigned int setEnable = 0, getEnable = 0; HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, &B_h, &C_h, N, false); unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N); @@ -391,15 +483,17 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemCpy") { HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); - SECTION("Without disabling MemCpy node and verify the execution result") { - HIP_CHECK(hipGraphLaunch(graphExec, stream)); - HIP_CHECK(hipStreamSynchronize(stream)); + // Verify the execution result - basic check 1st time + HIP_CHECK(hipGraphLaunch(graphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyVectorSquare(B_h, C_h, N)); - REQUIRE(true == verifyVectorSquare(B_h, C_h, N)); - } SECTION("After disabled MemCpy node and verify the execution result") { - setEnable = 0; // for disabled + setEnable = 0; // for disabled a node HIP_CHECK(hipGraphNodeSetEnabled(graphExec, memcpy_B, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(graphExec, memcpy_B, &getEnable)); + REQUIRE(setEnable == getEnable); HIP_CHECK(hipGraphLaunch(graphExec, stream)); HIP_CHECK(hipStreamSynchronize(stream)); @@ -407,16 +501,55 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemCpy") { REQUIRE(true == verifyVectorSquare(A_h, C_h, N)); } SECTION("Again enabled MemCpy node and verify the execution result") { - setEnable = 1; // for enabled + setEnable = 1; // for enabled a node HIP_CHECK(hipGraphNodeSetEnabled(graphExec, memcpy_B, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(graphExec, memcpy_B, &getEnable)); + REQUIRE(setEnable == getEnable); HIP_CHECK(hipGraphLaunch(graphExec, stream)); HIP_CHECK(hipStreamSynchronize(stream)); REQUIRE(true == verifyVectorSquare(B_h, C_h, N)); } + + // Code for cloned graph operations + HIP_CHECK(hipGraphClone(&clonedGraph, graph)); + HIP_CHECK(hipGraphInstantiate(&clonedGraphExec, clonedGraph, + nullptr, nullptr, 0)); + HIP_CHECK(hipGraphNodeFindInClone(&memcpy_B_C, memcpy_B, clonedGraph)); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyVectorSquare(B_h, C_h, N)); + + SECTION("After disabled MemSet node and verify the execution result") { + setEnable = 0; // for disabled a node + HIP_CHECK(hipGraphNodeSetEnabled(clonedGraphExec, memcpy_B_C, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(clonedGraphExec, memcpy_B_C, &getEnable)); + REQUIRE(setEnable == getEnable); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyVectorSquare(A_h, C_h, N)); + } + SECTION("Again enabled MemSet node and verify the execution result") { + setEnable = 1; // for enabled a node + HIP_CHECK(hipGraphNodeSetEnabled(clonedGraphExec, memcpy_B_C, setEnable)); + HIP_CHECK(hipGraphNodeGetEnabled(clonedGraphExec, memcpy_B_C, &getEnable)); + REQUIRE(setEnable == getEnable); + + HIP_CHECK(hipGraphLaunch(clonedGraphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + REQUIRE(true == verifyVectorSquare(B_h, C_h, N)); + } + HipTest::freeArrays(A_d, nullptr, C_d, A_h, B_h, C_h, false); HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphExecDestroy(clonedGraphExec)); + HIP_CHECK(hipGraphDestroy(clonedGraph)); HIP_CHECK(hipGraphDestroy(graph)); HIP_CHECK(hipStreamDestroy(stream)); } @@ -432,20 +565,22 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Functional_MemCpy") { Negative Functional Test for API - hipGraphNodeSetEnabled 6) Pass hNode from different graph and verify 7) Create graphExec and then add one more new node to the graph verify - 8) Pass hNode a deleted node from same graph where exec was created - 9) Create graphExec and then delete the graph and verify a node - 10) Create graphExec and then delete the graphExec and verify a node + 8) Pass hNode as clonedGraph node and exec as graphExec + 9) Pass graphExec as clonedGraphExec and hNode as graph node + 10) Pass hNode a deleted node from same graph where exec was created + 11) Create graphExec and then delete the graph and verify a node + 12) Create graphExec and then delete the graphExec and verify a node */ TEST_CASE("Unit_hipGraphNodeSetEnabled_Negative_Functional") { constexpr size_t Nbytes = N * sizeof(int); constexpr auto blocksPerCU = 6; // to hide latency constexpr auto threadsPerBlock = 256; - hipGraph_t graph, graph2; - hipGraphNode_t memcpy_A, memcpy_B, memcpy_C, memcpy_A2, kNodeAdd; + hipGraph_t graph, graph2, clonedGraph; + hipGraphNode_t memcpy_A, memcpy_A_C, memcpy_B, memcpy_C, memcpy_A2, kNodeAdd; hipKernelNodeParams kNodeParams{}; int *A_d, *B_d, *C_d, *A_h, *B_h, *C_h; - hipGraphExec_t graphExec; + hipGraphExec_t graphExec, graphExec2, clonedGraphExec; size_t NElem{N}; unsigned int setEnable = 1; hipError_t ret; @@ -472,6 +607,12 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Negative_Functional") { HIP_CHECK(hipGraphAddDependencies(graph, &memcpy_B, &kNodeAdd, 1)); HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); + HIP_CHECK(hipGraphInstantiate(&graphExec2, graph, nullptr, nullptr, 0)); + + HIP_CHECK(hipGraphClone(&clonedGraph, graph)); + HIP_CHECK(hipGraphInstantiate(&clonedGraphExec, clonedGraph, + nullptr, nullptr, 0)); + HIP_CHECK(hipGraphNodeFindInClone(&memcpy_A_C, memcpy_A, clonedGraph)); HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d, Nbytes, hipMemcpyDeviceToHost)); @@ -511,21 +652,33 @@ TEST_CASE("Unit_hipGraphNodeSetEnabled_Negative_Functional") { ret = hipGraphNodeSetEnabled(graphExec, memcpy_C, setEnable); REQUIRE(hipErrorInvalidValue == ret); } + SECTION("Pass hNode as clonedGraph node and exec as graphExec") { + ret = hipGraphNodeSetEnabled(graphExec, memcpy_A_C, setEnable); + REQUIRE(hipErrorInvalidValue == ret); + } + SECTION("Pass graphExec as clonedGraphExec and hNode as graph node") { + ret = hipGraphNodeSetEnabled(clonedGraphExec, memcpy_A, setEnable); + REQUIRE(hipErrorInvalidValue == ret); + } SECTION("Pass hNode a deleted node from same graph where exec was created") { HIP_CHECK(hipGraphDestroyNode(memcpy_A)); ret = hipGraphNodeSetEnabled(graphExec, memcpy_A, setEnable); REQUIRE(hipErrorInvalidValue == ret); } - SECTION("Create graphExec and then delete the graph and verify a node") { - HIP_CHECK(hipGraphDestroy(graph)); - ret = hipGraphNodeSetEnabled(graphExec, memcpy_B, setEnable); - REQUIRE(hipErrorInvalidValue == ret); - } + HIP_CHECK(hipGraphExecDestroy(graphExec2)); SECTION("Create graphExec and then delete the graphExec and verify a node") { - HIP_CHECK(hipGraphExecDestroy(graphExec)); + ret = hipGraphNodeSetEnabled(graphExec2, memcpy_B, setEnable); + REQUIRE(hipErrorInvalidValue == ret); + } + HIP_CHECK(hipGraphDestroy(graph)); + SECTION("Create graphExec and then delete the graph and verify a node") { ret = hipGraphNodeSetEnabled(graphExec, memcpy_B, setEnable); REQUIRE(hipErrorInvalidValue == ret); } + HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); + HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphExecDestroy(clonedGraphExec)); + HIP_CHECK(hipGraphDestroy(clonedGraph)); HIP_CHECK(hipGraphDestroy(graph2)); } From 07260cf7e7f44a2588aaa5091c23daf6a8b7c2ad Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:00:08 +0530 Subject: [PATCH 3/4] SWDEV-373476 - [catch2][dtest] hipGraphNodeGetEnabled API test case added few more graph scenarios (#199) Change-Id: Ibd119135acb9e4fba97d320a93333604f176ee30 --- catch/unit/graph/hipGraphNodeGetEnabled.cc | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/catch/unit/graph/hipGraphNodeGetEnabled.cc b/catch/unit/graph/hipGraphNodeGetEnabled.cc index 9f9d8279a5..56b07c127b 100644 --- a/catch/unit/graph/hipGraphNodeGetEnabled.cc +++ b/catch/unit/graph/hipGraphNodeGetEnabled.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. +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 @@ -156,20 +156,22 @@ TEST_CASE("Unit_hipGraphNodeGetEnabled_Functional_Basic") { Negative Functional Test for API - hipGraphNodeGetEnabled 6) Pass hNode from different graph and verify 7) Create graphExec and then add one more new node to the graph verify - 8) Pass hNode a deleted node from same graph where exec was created - 9) Create graphExec and then delete the graph and verify a node - 10) Create graphExec and then delete the graphExec and verify a node + 8) Pass hNode as clonedGraph node and exec as graphExec + 9) Pass graphExec as clonedGraphExec and hNode as graph node + 10) Pass hNode a deleted node from same graph where exec was created + 11) Create graphExec and then delete the graph and verify a node + 12) Create graphExec and then delete the graphExec and verify a node */ TEST_CASE("Unit_hipGraphNodeGetEnabled_Negative_Functional") { constexpr size_t Nbytes = N * sizeof(int); constexpr auto blocksPerCU = 6; // to hide latency constexpr auto threadsPerBlock = 256; - hipGraph_t graph, graph2; - hipGraphNode_t memcpy_A, memcpy_B, memcpy_A2, memcpy_C, kNodeAdd; + hipGraph_t graph, graph2, clonedGraph; + hipGraphNode_t memcpy_A, memcpy_A_C, memcpy_B, memcpy_A2, memcpy_C, kNodeAdd; hipKernelNodeParams kNodeParams{}; int *A_d, *B_d, *C_d, *A_h, *B_h, *C_h; - hipGraphExec_t graphExec, graphExec2; + hipGraphExec_t graphExec, graphExec2, clonedGraphExec; size_t NElem{N}; unsigned int isEnabled; hipError_t ret; @@ -198,6 +200,11 @@ TEST_CASE("Unit_hipGraphNodeGetEnabled_Negative_Functional") { HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0)); HIP_CHECK(hipGraphInstantiate(&graphExec2, graph, NULL, NULL, 0)); + HIP_CHECK(hipGraphClone(&clonedGraph, graph)); + HIP_CHECK(hipGraphInstantiate(&clonedGraphExec, clonedGraph, + nullptr, nullptr, 0)); + HIP_CHECK(hipGraphNodeFindInClone(&memcpy_A_C, memcpy_A, clonedGraph)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_C, graph, nullptr, 0, C_h, C_d, Nbytes, hipMemcpyDeviceToHost)); HIP_CHECK(hipGraphAddDependencies(graph, &kNodeAdd, &memcpy_C, 1)); @@ -236,6 +243,14 @@ TEST_CASE("Unit_hipGraphNodeGetEnabled_Negative_Functional") { ret = hipGraphNodeGetEnabled(graphExec, memcpy_C, &isEnabled); REQUIRE(hipErrorInvalidValue == ret); } + SECTION("Pass hNode as clonedGraph node and exec as graphExec") { + ret = hipGraphNodeGetEnabled(graphExec, memcpy_A_C, &isEnabled); + REQUIRE(hipErrorInvalidValue == ret); + } + SECTION("Pass graphExec as clonedGraphExec and hNode as graph node") { + ret = hipGraphNodeGetEnabled(clonedGraphExec, memcpy_A, &isEnabled); + REQUIRE(hipErrorInvalidValue == ret); + } SECTION("Pass hNode a deleted node from same graph where exec was created") { HIP_CHECK(hipGraphDestroyNode(memcpy_A)); ret = hipGraphNodeGetEnabled(graphExec, memcpy_A, &isEnabled); @@ -253,5 +268,7 @@ TEST_CASE("Unit_hipGraphNodeGetEnabled_Negative_Functional") { } HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphExecDestroy(clonedGraphExec)); + HIP_CHECK(hipGraphDestroy(clonedGraph)); HIP_CHECK(hipGraphDestroy(graph2)); } From d3942fe73bace69498ea5629774671eafa915521 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:00:35 +0530 Subject: [PATCH 4/4] SWDEV-367689 - [catch2][dtest] UnifiedAddress attribute support for AMD (#204) Change-Id: Ie820e8d9fb59322fb66380bf676a66362adc0b65 --- catch/unit/device/hipGetDeviceAttribute.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/catch/unit/device/hipGetDeviceAttribute.cc b/catch/unit/device/hipGetDeviceAttribute.cc index 62b1aceed4..208f997e2b 100644 --- a/catch/unit/device/hipGetDeviceAttribute.cc +++ b/catch/unit/device/hipGetDeviceAttribute.cc @@ -1,16 +1,13 @@ /* -Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. - +Copyright (c) 2022 - 2023 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -232,8 +229,10 @@ TEST_CASE("Unit_hipGetDeviceAttribute_CheckAttrValues") { hipDeviceAttributeEccEnabled, props.ECCEnabled)); HIP_CHECK(test_hipDeviceGetAttribute(deviceId, - hipDeviceAttributeTexturePitchAlignment, - props.texturePitchAlignment)); + hipDeviceAttributeTexturePitchAlignment, + props.texturePitchAlignment)); + HIP_CHECK(test_hipDeviceGetAttribute(deviceId, + hipDeviceAttributeUnifiedAddressing, 1/*true*/)); } /** @@ -375,7 +374,7 @@ using AttributeToStringMap = std::array kCommonAttributes{{ +constexpr AttributeToStringMap<57> kCommonAttributes{{ {hipDeviceAttributeEccEnabled, "hipDeviceAttributeEccEnabled"}, {hipDeviceAttributeCanMapHostMemory, "hipDeviceAttributeCanMapHostMemory"}, {hipDeviceAttributeClockRate, "hipDeviceAttributeClockRate"}, @@ -436,12 +435,13 @@ constexpr AttributeToStringMap<56> kCommonAttributes{{ {hipDeviceAttributeTotalGlobalMem, "hipDeviceAttributeTotalGlobalMem"}, {hipDeviceAttributeWarpSize, "hipDeviceAttributeWarpSize"}, {hipDeviceAttributeMemoryPoolsSupported, "hipDeviceAttributeMemoryPoolsSupported"}, + {hipDeviceAttributeUnifiedAddressing, "hipDeviceAttributeUnifiedAddressing"}, {hipDeviceAttributeVirtualMemoryManagementSupported, "hipDeviceAttributeVirtualMemoryManagementSupported"} }}; #if HT_NVIDIA -constexpr AttributeToStringMap<34> kCudaOnlyAttributes{ +constexpr AttributeToStringMap<33> kCudaOnlyAttributes{ {{hipDeviceAttributeAccessPolicyMaxWindowSize, "hipDeviceAttributeAccessPolicyMaxWindowSize"}, {hipDeviceAttributeAsyncEngineCount, "hipDeviceAttributeAsyncEngineCount"}, {hipDeviceAttributeCanUseHostPointerForRegisteredMem, @@ -476,7 +476,6 @@ constexpr AttributeToStringMap<34> kCudaOnlyAttributes{ {hipDeviceAttributeStreamPrioritiesSupported, "hipDeviceAttributeStreamPrioritiesSupported"}, {hipDeviceAttributeSurfaceAlignment, "hipDeviceAttributeSurfaceAlignment"}, {hipDeviceAttributeTccDriver, "hipDeviceAttributeTccDriver"}, - {hipDeviceAttributeUnifiedAddressing, "hipDeviceAttributeUnifiedAddressing"}, {hipDeviceAttributeUuid, "hipDeviceAttributeUuid"}}}; #endif @@ -555,4 +554,4 @@ TEST_CASE("Print_Out_Attributes") { #endif std::flush(std::cout); -} \ No newline at end of file +}