From 1a4276bfedfa1eb1d533e919eeaa569a7fbba6d3 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: Wed, 28 Jun 2023 06:04:52 +0200 Subject: [PATCH] EXSWHTEC-191 - Implement additional tests for Host Graph Node APIs (#9) - Tidy up hipGraphAddHostNode tests - Tidy up hipGraphHostNodeGetParams tests - Tidy up hipGraphHostNodeSetParams tests - Tidy up hipGraphExecHostNodeSetParams tests. - Disable failing test sections on AMD. [ROCm/hip-tests commit: 9f5bb4219ac7c07b6b97da78dd34d7b4804344d0] --- .../catch/unit/graph/hipGraphAddHostNode.cc | 208 ++++++------- .../graph/hipGraphExecHostNodeSetParams.cc | 284 +++++++++--------- .../unit/graph/hipGraphHostNodeGetParams.cc | 166 +++++----- .../unit/graph/hipGraphHostNodeSetParams.cc | 126 ++++---- 4 files changed, 365 insertions(+), 419 deletions(-) diff --git a/projects/hip-tests/catch/unit/graph/hipGraphAddHostNode.cc b/projects/hip-tests/catch/unit/graph/hipGraphAddHostNode.cc index 9da6e3b223..971ac187cb 100644 --- a/projects/hip-tests/catch/unit/graph/hipGraphAddHostNode.cc +++ b/projects/hip-tests/catch/unit/graph/hipGraphAddHostNode.cc @@ -6,23 +6,25 @@ 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 of hipGraphAddHostNode API: +Test Case Scenarios of hipGraphAddHostNode API: Functional: 1. Creates graph, Adds HostNode which updates the variable and validates the result -2. Create graph, Add Graphnodes and clones the graph. Add Hostnode to the cloned graph +2. Create graph, Add Graph nodes and clones the graph. Add Host node to the cloned graph and validate the result 3. Creates graph which performs the square of number in the kernel function and the result is validated in the callback function of hipGraphAddHostNode API @@ -35,22 +37,22 @@ Negative: 4) Pass hipHostNodeParams::hipHostFn_t as nullptr and verify api doesn't crash, returns error code. */ -#include #include +#include #define SIZE 1024 -static int *B_h; -static int *D_h; +static int* B_h; +static int* D_h; -static void callbackfunc(void *A_h) { - int *A = reinterpret_cast(A_h); +static void callbackfunc(void* A_h) { + int* A = reinterpret_cast(A_h); for (int i = 0; i < SIZE; i++) { A[i] = i; } } -static void __global__ vector_square(int *B_d, int *D_d) { +static void __global__ vector_square(int* B_d, int* D_d) { for (int i = 0; i < SIZE; i++) { D_d[i] = B_d[i] * B_d[i]; } @@ -60,7 +62,7 @@ static void vectorsquare_callback(void* ptr) { // of type void (*)(void*). This test is designed to // work with global variables, hence the workaround to // print this *ptr value to avoid type mismatch errors. - int *A = reinterpret_cast(ptr); + int* A = reinterpret_cast(ptr); for (int i = 0; i < SIZE; i++) { if (D_h[i] != B_h[i] * B_h[i]) { @@ -70,8 +72,9 @@ static void vectorsquare_callback(void* ptr) { } } } + /* -This testcase verifies the negative scenarios of +This test case verifies the negative scenarios of hipGraphAddHostNode API */ TEST_CASE("Unit_hipGraphAddHostNode_Negative") { @@ -79,101 +82,96 @@ TEST_CASE("Unit_hipGraphAddHostNode_Negative") { hipGraph_t graph; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); hipGraphNode_t hostNode; hipHostNodeParams hostParams = {0, 0}; + std::vector dependencies; hostParams.fn = callbackfunc; hostParams.userData = A_h; SECTION("Passing nullptr to graph node") { - REQUIRE(hipGraphAddHostNode(nullptr, graph, - nullptr, - 0, &hostParams) == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphAddHostNode(nullptr, graph, nullptr, 0, &hostParams), + hipErrorInvalidValue); } SECTION("Passing nullptr to graph") { - REQUIRE(hipGraphAddHostNode(&hostNode, nullptr, - nullptr, - 0, &hostParams) == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphAddHostNode(&hostNode, nullptr, nullptr, 0, &hostParams), + hipErrorInvalidValue); } -#if HT_NVIDIA - SECTION("Passing nullptr to host params") { - REQUIRE(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, nullptr) == hipErrorInvalidValue); + SECTION("Pass invalid numDependencies") { + HIP_CHECK_ERROR(hipGraphAddHostNode(&hostNode, graph, nullptr, 11, &hostParams), + hipErrorInvalidValue); + } + + SECTION("Pass invalid numDependencies and valid list for dependencies") { + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); + dependencies.push_back(hostNode); + HIP_CHECK_ERROR(hipGraphAddHostNode(&hostNode, graph, dependencies.data(), + dependencies.size() + 1, &hostParams), + hipErrorInvalidValue); + } + + SECTION("Passing nullptr to host params") { + HIP_CHECK_ERROR(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, nullptr), + hipErrorInvalidValue); } -#endif SECTION("Passing nullptr to host func") { hostParams.fn = nullptr; - REQUIRE(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams) == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams), + hipErrorInvalidValue); } + HipTest::freeArrays(A_d, nullptr, C_d, A_h, nullptr, C_h, false); HIP_CHECK(hipGraphDestroy(graph)); } + /* -This testcase verifies hipGraphAddHostNode API in cloned graph +This test case verifies hipGraphAddHostNode API in cloned graph Creates graph, Add graph nodes and clone the graph Add HostNode to the cloned graph and validate the result */ -TEST_CASE("Unit_hipGraphAddHostNode_ClonedGraphwithHostNode") { +TEST_CASE("Unit_hipGraphAddHostNode_ClonedGraphWithHostNode") { constexpr size_t N = 1024; constexpr size_t Nbytes = N * sizeof(int); hipGraph_t graph; hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); - hipGraphNode_t memcpyH2D_A, memcpyH2D_C, - memcpyD2H_AC; - hipGraphNode_t cloned_memcpyH2D_A, cloned_memcpyH2D_C, - cloned_memcpyD2H_AC; + hipGraphNode_t memcpyH2D_A, memcpyH2D_C, memcpyD2H_AC; + hipGraphNode_t cloned_memcpyH2D_A, cloned_memcpyH2D_C, cloned_memcpyD2H_AC; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); hipGraph_t clonedgraph; HIP_CHECK(hipGraphClone(&clonedgraph, graph)); - HIP_CHECK(hipGraphNodeFindInClone(&cloned_memcpyH2D_A, memcpyH2D_A, - clonedgraph)); - HIP_CHECK(hipGraphNodeFindInClone(&cloned_memcpyH2D_C, memcpyH2D_C, - clonedgraph)); - HIP_CHECK(hipGraphNodeFindInClone(&cloned_memcpyD2H_AC, memcpyD2H_AC, - clonedgraph)); + HIP_CHECK(hipGraphNodeFindInClone(&cloned_memcpyH2D_A, memcpyH2D_A, clonedgraph)); + HIP_CHECK(hipGraphNodeFindInClone(&cloned_memcpyH2D_C, memcpyH2D_C, clonedgraph)); + HIP_CHECK(hipGraphNodeFindInClone(&cloned_memcpyD2H_AC, memcpyD2H_AC, clonedgraph)); hipGraphNode_t hostNode; hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, nullptr, 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(clonedgraph, &cloned_memcpyH2D_A, - &cloned_memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(clonedgraph, &cloned_memcpyH2D_C, - &cloned_memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(clonedgraph, &cloned_memcpyD2H_AC, - &hostNode, 1)); + HIP_CHECK(hipGraphAddDependencies(clonedgraph, &cloned_memcpyH2D_A, &cloned_memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(clonedgraph, &cloned_memcpyH2D_C, &cloned_memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(clonedgraph, &cloned_memcpyD2H_AC, &hostNode, 1)); // Instantiate and launch the cloned graph HIP_CHECK(hipGraphInstantiate(&graphExec, clonedgraph, nullptr, nullptr, 0)); @@ -183,7 +181,7 @@ TEST_CASE("Unit_hipGraphAddHostNode_ClonedGraphwithHostNode") { // Verify execution result for (size_t i = 0; i < N; i++) { if (A_h[i] != static_cast(i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } @@ -196,9 +194,9 @@ TEST_CASE("Unit_hipGraphAddHostNode_ClonedGraphwithHostNode") { } /* -This testcase verifies the square of number by +This test case verifies the square of number by creating graph, Add kernel node which does the square -of number and the result is validated byhipGrahAddHostNode API +of number and the result is validated by hipGraphAddHostNode API */ TEST_CASE("Unit_hipGraphAddHostNode_VectorSquare") { constexpr size_t N = 1024; @@ -206,9 +204,9 @@ TEST_CASE("Unit_hipGraphAddHostNode_VectorSquare") { hipGraph_t graph; hipGraphExec_t graphExec; int *A_d{nullptr}, *A_h{nullptr}, *B_d{nullptr}, *D_d{nullptr}; - int *param = reinterpret_cast(sizeof(int));; - HipTest::initArrays(&A_d, &B_d, &D_d, - &A_h, &B_h, &D_h, N, false); + int* param = reinterpret_cast(sizeof(int)); + + HipTest::initArrays(&A_d, &B_d, &D_d, &A_h, &B_h, &D_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); hipGraphNode_t memcpyH2D_B, memcpyH2D_D, memcpyD2H_D, kernel_vecAdd; hipKernelNodeParams kernelNodeParams{}; @@ -219,37 +217,27 @@ TEST_CASE("Unit_hipGraphAddHostNode_VectorSquare") { hostParams.fn = vectorsquare_callback; hostParams.userData = param; - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, - 0, B_d, B_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_D, graph, nullptr, - 0, D_d, D_h, - Nbytes, hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, 0, B_d, B_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_D, graph, nullptr, 0, D_d, D_h, Nbytes, + hipMemcpyHostToDevice)); void* kernelArgs2[] = {&B_d, &D_d}; - kernelNodeParams.func = reinterpret_cast(vector_square); + kernelNodeParams.func = reinterpret_cast(vector_square); kernelNodeParams.gridDim = dim3(1); kernelNodeParams.blockDim = dim3(1); kernelNodeParams.sharedMemBytes = 0; kernelNodeParams.kernelParams = reinterpret_cast(kernelArgs2); kernelNodeParams.extra = nullptr; - HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0, - &kernelNodeParams)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_D, graph, nullptr, - 0, D_h, D_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddKernelNode(&kernel_vecAdd, graph, nullptr, 0, &kernelNodeParams)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_D, graph, nullptr, 0, D_h, D_d, Nbytes, + hipMemcpyDeviceToHost)); - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &kernel_vecAdd, - 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_D, &kernel_vecAdd, - 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, - &memcpyD2H_D, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_D, - &hostNode, 1)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &kernel_vecAdd, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_D, &kernel_vecAdd, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecAdd, &memcpyD2H_D, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_D, &hostNode, 1)); // Instantiate and launch the graph HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); @@ -261,8 +249,9 @@ TEST_CASE("Unit_hipGraphAddHostNode_VectorSquare") { HIP_CHECK(hipGraphDestroy(graph)); HIP_CHECK(hipStreamDestroy(streamForGraph)); } + /* -This testcase verifies the following scenario +This test case verifies the following scenario Create graph, calls the host function and updates the parameters in the callback function and validates it. @@ -274,36 +263,27 @@ TEST_CASE("Unit_hipGraphAddHostNode_BasicFunc") { hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); hipGraphNode_t memcpyH2D_A, memcpyD2H_AC, memcpyH2D_C; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); hipGraphNode_t hostNode; hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, - &hostNode, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, &hostNode, 1)); // Instantiate and launch the graph HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); @@ -313,7 +293,7 @@ TEST_CASE("Unit_hipGraphAddHostNode_BasicFunc") { // Verify execution result for (size_t i = 0; i < N; i++) { if (A_h[i] != static_cast(i)) { - INFO("Validation failed i " << i << "A_h[i] "<< A_h[i]); + INFO("Validation failed i " << i << "A_h[i] " << A_h[i]); REQUIRE(false); } } diff --git a/projects/hip-tests/catch/unit/graph/hipGraphExecHostNodeSetParams.cc b/projects/hip-tests/catch/unit/graph/hipGraphExecHostNodeSetParams.cc index 6f07b23269..6341e73e02 100644 --- a/projects/hip-tests/catch/unit/graph/hipGraphExecHostNodeSetParams.cc +++ b/projects/hip-tests/catch/unit/graph/hipGraphExecHostNodeSetParams.cc @@ -6,164 +6,173 @@ 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 of hipGraphExecHostNodeSetParams API: +Test Case Scenarios of hipGraphExecHostNodeSetParams API: Functional: 1. Creates graph, Adds HostNode, update hostNode params using hipGraphExecHostNodeSetParams API and validates the result -2. Create graph, Add Graphnodes and clones the graph. Add Hostnode to the cloned graph, update +2. Create graph, Add Graph nodes and clones the graph. Add Host node to the cloned graph, update hostNode params using hipGraphExecHostNodeSetParams API and validate the result Negative: -1) Pass hGraphExec as nullptr and verify api doen't crash, returns error code. -2) Pass node as nullptr and verify api doen't crash, returns error code. +1) Pass hGraphExec as nullptr and verify api doesn't crash, returns error code. +2) Pass node as nullptr and verify api doesn't crash, returns error code. 3) Pass pNodeParams as nullptr and verify api doesn't crash, returns error code. 3) Pass hipHostNodeParams::hipHostFn_t as nullptr and verify api doesn't crash, returns error code. -4) Pass unintialized host params and verify api doesn't crash, returns error code. -5) Pass unintialized graph and verify api doesn't crash, returns error code. -6) Pass nullptr to hostfunc and verify api doesn't crash, returns error code. +4) Pass uninitialized host params and verify api doesn't crash, returns error code. +5) Pass uninitialized graph and verify api doesn't crash, returns error code. +6) Pass nullptr to host func and verify api doesn't crash, returns error code. */ -#include #include +#include #define SIZE 1024 -void callbackfunc(void *A_h) { - int *A = reinterpret_cast(A_h); +void callbackfunc(void* A_h) { + int* A = reinterpret_cast(A_h); for (int i = 0; i < SIZE; i++) { - A[i] = i; + A[i] = i; } } -void callbackfunc_setparams(void *B_h) { - int *B = reinterpret_cast(B_h); +void callbackfunc_setparams(void* B_h) { + int* B = reinterpret_cast(B_h); for (int i = 0; i < SIZE; i++) { - B[i] = i * i; + B[i] = i * i; } } /* -This testcase verifies the negative scenarios of +This test case verifies the negative scenarios of hipGraphExecHostNodeSetParams API */ TEST_CASE("Unit_hipGraphExecHostNodeSetParams_Negative") { -constexpr size_t N = 1024; - constexpr size_t Nbytes = N * sizeof(int); - hipGraph_t graph; - hipGraphExec_t graphExec; - int *A_d{nullptr}, *C_d{nullptr}; - int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); - - HIP_CHECK(hipGraphCreate(&graph, 0)); - hipGraphNode_t memcpyH2D_A, memcpyD2H_AC, memcpyH2D_C; - hipStream_t streamForGraph; - HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); - hipGraphNode_t hostNode; - hipHostNodeParams hostParams = {0, 0}; - hostParams.fn = callbackfunc; - hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); - - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, - &hostNode, 1)); - - hipHostNodeParams sethostParams = {0, 0}; - sethostParams.fn = callbackfunc_setparams; - sethostParams.userData = C_h; - - // Instantiate and launch the graph - HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); -#if HT_NVIDIA - SECTION("Passing nullptr to graphExec") { - REQUIRE(hipGraphExecHostNodeSetParams(nullptr, hostNode, &sethostParams) - == hipErrorInvalidValue); - } - - SECTION("Passing nullptr to hostParams") { - REQUIRE(hipGraphExecHostNodeSetParams(graphExec, hostNode, nullptr) - == hipErrorInvalidValue); - } -#endif - SECTION("Passing nullptr to graph") { - REQUIRE(hipGraphExecHostNodeSetParams(graphExec, nullptr, &sethostParams) - == hipErrorInvalidValue); - } - - SECTION("Passing nullptr to host func") { - sethostParams.fn = nullptr; - REQUIRE(hipGraphExecHostNodeSetParams(graphExec, hostNode, &sethostParams) - == hipErrorInvalidValue); - } - - - SECTION("Passing unintialized hostParams") { - hipHostNodeParams unintParams = {0, 0}; - REQUIRE(hipGraphExecHostNodeSetParams(graphExec, hostNode, &unintParams) - == hipErrorInvalidValue); - } - HIP_CHECK(hipGraphDestroy(graph)); -} -/* -This testcase verifies hipGraphExecHostNodeSetParams API in cloned graph -Creates graph, Add graph nodes and clone the graph -Add HostNode to the cloned graph,update the host params using -hipGraphExecHostNodeSetParams API and validates the result -*/ -TEST_CASE("Unit_hipGraphExecHostNodeSetParams_ClonedGraphwithHostNode") { constexpr size_t N = 1024; constexpr size_t Nbytes = N * sizeof(int); hipGraph_t graph; hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); - hipGraphNode_t memcpyH2D_A, memcpyH2D_C, - memcpyD2H_AC; + hipGraphNode_t memcpyH2D_A, memcpyD2H_AC, memcpyH2D_C; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); + + hipGraphNode_t hostNode; + hipHostNodeParams hostParams = {0, 0}; + hostParams.fn = callbackfunc; + hostParams.userData = A_h; + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); + + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, &hostNode, 1)); + + hipHostNodeParams sethostParams = {0, 0}; + sethostParams.fn = callbackfunc_setparams; + sethostParams.userData = C_h; + + hipGraphNode_t empty_node; + HIP_CHECK(hipGraphAddEmptyNode(&empty_node, graph, &hostNode, 1)); + + // Instantiate and launch the graph + HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); + + SECTION("Passing nullptr to graphExec") { + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(nullptr, hostNode, &sethostParams), + hipErrorInvalidValue); + } + + SECTION("Passing nullptr to hostParams") { + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(graphExec, hostNode, nullptr), + hipErrorInvalidValue); + } + + SECTION("Passing nullptr to graph") { + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(graphExec, nullptr, &sethostParams), + hipErrorInvalidValue); + } + + SECTION("Passing nullptr to host func") { + sethostParams.fn = nullptr; + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(graphExec, hostNode, &sethostParams), + hipErrorInvalidValue); + } + + SECTION("Passing uninitialized hostParams") { + hipHostNodeParams unintParams = {0, 0}; + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(graphExec, hostNode, &unintParams), + hipErrorInvalidValue); + } + +#if HT_NVIDIA // segfaults on AMD + SECTION("node is not a host node") { + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(graphExec, empty_node, &sethostParams), + hipErrorInvalidValue); + } +#endif + + SECTION("node is not instantiated") { + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); + HIP_CHECK_ERROR(hipGraphExecHostNodeSetParams(graphExec, hostNode, &sethostParams), + hipErrorInvalidValue); + } + + HipTest::freeArrays(A_d, nullptr, C_d, A_h, nullptr, C_h, false); + HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK(hipStreamDestroy(streamForGraph)); +} + +/* +This test case verifies hipGraphExecHostNodeSetParams API in cloned graph +Creates graph, Add graph nodes and clone the graph +Add HostNode to the cloned graph,update the host params using +hipGraphExecHostNodeSetParams API and validates the result +*/ +TEST_CASE("Unit_hipGraphExecHostNodeSetParams_ClonedGraphWithHostNode") { + constexpr size_t N = 1024; + constexpr size_t Nbytes = N * sizeof(int); + hipGraph_t graph; + hipGraphExec_t graphExec; + int *A_d{nullptr}, *C_d{nullptr}; + int *A_h{nullptr}, *C_h{nullptr}; + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); + + HIP_CHECK(hipGraphCreate(&graph, 0)); + hipGraphNode_t memcpyH2D_A, memcpyH2D_C, memcpyD2H_AC; + hipStream_t streamForGraph; + HIP_CHECK(hipStreamCreate(&streamForGraph)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); hipGraph_t clonedgraph; HIP_CHECK(hipGraphClone(&clonedgraph, graph)); @@ -172,20 +181,15 @@ TEST_CASE("Unit_hipGraphExecHostNodeSetParams_ClonedGraphwithHostNode") { hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, nullptr, 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); hipHostNodeParams sethostParams = {0, 0}; sethostParams.fn = callbackfunc_setparams; sethostParams.userData = C_h; - // Instantiate and launch the cloned graph HIP_CHECK(hipGraphInstantiate(&graphExec, clonedgraph, nullptr, nullptr, 0)); HIP_CHECK(hipGraphExecHostNodeSetParams(graphExec, hostNode, &sethostParams)); @@ -195,7 +199,7 @@ TEST_CASE("Unit_hipGraphExecHostNodeSetParams_ClonedGraphwithHostNode") { // Verify execution result for (size_t i = 0; i < N; i++) { if (C_h[i] != static_cast(i * i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } @@ -207,7 +211,7 @@ TEST_CASE("Unit_hipGraphExecHostNodeSetParams_ClonedGraphwithHostNode") { } /* -This testcase verifies the following scenario +This test case verifies the following scenario Create graph, Adds host node to the graph, updates the host params using hipGraphExecHostNodeSetParams API and validates the result @@ -219,36 +223,28 @@ TEST_CASE("Unit_hipGraphExecHostNodeSetParams_BasicFunc") { hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); hipGraphNode_t memcpyH2D_A, memcpyD2H_AC, memcpyH2D_C; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); + hipGraphNode_t hostNode; hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, - &hostNode, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, &hostNode, 1)); hipHostNodeParams sethostParams = {0, 0}; sethostParams.fn = callbackfunc_setparams; @@ -263,8 +259,8 @@ TEST_CASE("Unit_hipGraphExecHostNodeSetParams_BasicFunc") { // Verify execution result for (size_t i = 0; i < N; i++) { - if (C_h[i] != static_cast(i * i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + if (C_h[i] != static_cast(i * i)) { + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } diff --git a/projects/hip-tests/catch/unit/graph/hipGraphHostNodeGetParams.cc b/projects/hip-tests/catch/unit/graph/hipGraphHostNodeGetParams.cc index a1c769ea47..ffb04cc174 100644 --- a/projects/hip-tests/catch/unit/graph/hipGraphHostNodeGetParams.cc +++ b/projects/hip-tests/catch/unit/graph/hipGraphHostNodeGetParams.cc @@ -6,55 +6,57 @@ 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 of hipGraphHostNodeGetParams API: +Test Case Scenarios of hipGraphHostNodeGetParams API: Functional Scenarios: -1) Create a graph, add Host node to graph with desired node params. Verify api fetches the node params - which were mentioned while adding the host node. -2) Set host node params with hipGraphHostNodeSetParams, now get the params and verify both are same. -3) Create graph, Add Graphnodes and clones the graph. Add Hostnode to the cloned graph, update - hostNode params using hipGraphHostNodeSetParams API now get the params and verify both are same +1) Create a graph, add Host node to graph with desired node params. Verify api fetches the node +params which were mentioned while adding the host node. 2) Set host node params with +hipGraphHostNodeSetParams, now get the params and verify both are same. 3) Create graph, Add Graph +nodes and clones the graph. Add Host node to the cloned graph, update hostNode params using +hipGraphHostNodeSetParams API now get the params and verify both are same Negative Scenarios: 1) Pass pGraphNode as nullptr and verify api doesn’t crash, returns error code. 2) Pass pNodeParams as nullptr and verify api doesn’t crash, returns error code. -3) Pass unintialized graph node +3) Pass uninitialized graph node */ -#include #include +#include #define SIZE 1024 -static void callbackfunc(void *A_h) { - int *A = reinterpret_cast(A_h); +static void callbackfunc(void* A_h) { + int* A = reinterpret_cast(A_h); for (int i = 0; i < SIZE; i++) { A[i] = i; } } -static void callbackfunc_setparams(void *B_h) { - int *B = reinterpret_cast(B_h); +static void callbackfunc_setparams(void* B_h) { + int* B = reinterpret_cast(B_h); for (int i = 0; i < SIZE; i++) { - B[i] = i * i; + B[i] = i * i; } } /* -This testcase verifies the negative scenarios of +This test case verifies the negative scenarios of hipGraphHostNodeGetParams API */ TEST_CASE("Unit_hipGraphHostNodeGetParams_Negative") { @@ -62,8 +64,7 @@ TEST_CASE("Unit_hipGraphHostNodeGetParams_Negative") { hipGraph_t graph; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); @@ -71,63 +72,57 @@ TEST_CASE("Unit_hipGraphHostNodeGetParams_Negative") { hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); hipHostNodeParams GethostParams; SECTION("Passing nullptr to graph node") { - REQUIRE(hipGraphHostNodeGetParams(nullptr, &GethostParams) - == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphHostNodeGetParams(nullptr, &GethostParams), hipErrorInvalidValue); } SECTION("Passing nullptr to hostParams") { - REQUIRE(hipGraphHostNodeGetParams(hostNode, nullptr) - == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphHostNodeGetParams(hostNode, nullptr), hipErrorInvalidValue); } - SECTION("Passing unintialized graphNode") { - hipGraphNode_t unint_graphnode{nullptr}; - REQUIRE(hipGraphHostNodeGetParams(unint_graphnode, &GethostParams) - == hipErrorInvalidValue); +#if HT_NVIDIA // segfaults on AMD + SECTION("node is not a host node") { + hipGraphNode_t empty_node; + HIP_CHECK(hipGraphAddEmptyNode(&empty_node, graph, nullptr, 0)); + HIP_CHECK_ERROR(hipGraphHostNodeGetParams(empty_node, &GethostParams), hipErrorInvalidValue); } +#endif + + HipTest::freeArrays(A_d, nullptr, C_d, A_h, nullptr, C_h, false); HIP_CHECK(hipGraphDestroy(graph)); } + /* -This testcase verifies hipGraphHostNodeGetParams API in cloned graph +This test case verifies hipGraphHostNodeGetParams API in cloned graph Creates graph, Add graph nodes and clone the graph Add HostNode to the cloned graph, update hostNode using hipGraphHostNodeSetParams, then get the host node params using hipGraphHostNodeGetParams API and compare it. */ -TEST_CASE("Unit_hipGraphHostNodeGetParams_ClonedGraphwithHostNode") { +TEST_CASE("Unit_hipGraphHostNodeGetParams_ClonedGraphWithHostNode") { constexpr size_t N = 1024; constexpr size_t Nbytes = N * sizeof(int); hipGraph_t graph; hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); - hipGraphNode_t memcpyH2D_A, memcpyH2D_C, - memcpyD2H_AC; + hipGraphNode_t memcpyH2D_A, memcpyH2D_C, memcpyD2H_AC; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); hipGraph_t clonedgraph; HIP_CHECK(hipGraphClone(&clonedgraph, graph)); @@ -136,17 +131,16 @@ TEST_CASE("Unit_hipGraphHostNodeGetParams_ClonedGraphwithHostNode") { hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, nullptr, 0, &hostParams)); + hipHostNodeParams sethostParams = {0, 0}; sethostParams.fn = callbackfunc_setparams; sethostParams.userData = C_h; HIP_CHECK(hipGraphHostNodeSetParams(hostNode, &sethostParams)); hipHostNodeParams gethostParams; HIP_CHECK(hipGraphHostNodeGetParams(hostNode, &gethostParams)); - REQUIRE(memcmp(&sethostParams, &gethostParams, sizeof(hipHostNodeParams)) - == 0); + REQUIRE(memcmp(&sethostParams, &gethostParams, sizeof(hipHostNodeParams)) == 0); + // Instantiate and launch the cloned graph HIP_CHECK(hipGraphInstantiate(&graphExec, clonedgraph, nullptr, nullptr, 0)); HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph)); @@ -155,10 +149,11 @@ TEST_CASE("Unit_hipGraphHostNodeGetParams_ClonedGraphwithHostNode") { // Verify execution result for (size_t i = 0; i < N; i++) { if (C_h[i] != static_cast(i * i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } + HIP_CHECK(hipGraphExecDestroy(graphExec)); HIP_CHECK(hipGraphDestroy(graph)); HIP_CHECK(hipGraphDestroy(clonedgraph)); @@ -167,7 +162,7 @@ TEST_CASE("Unit_hipGraphHostNodeGetParams_ClonedGraphwithHostNode") { } /* -This testcase verifies the following scenarios +This test case verifies the following scenarios Create graph, Adds host node to the graph, updates it with hipGraphHostNodeSetParams and gets the host node params using hipGraphHostNodeGetParams API and validates @@ -180,36 +175,28 @@ void hipGraphHostNodeGetParams_func(bool setparams) { hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); hipGraphNode_t memcpyH2D_A, memcpyD2H_AC, memcpyH2D_C; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, - 0, A_d, A_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); + hipGraphNode_t hostNode; hipHostNodeParams hostParams = {0, 0}; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, - &hostNode, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, &hostNode, 1)); if (setparams) { hipHostNodeParams sethostParams = {0, 0}; @@ -219,32 +206,30 @@ void hipGraphHostNodeGetParams_func(bool setparams) { hipHostNodeParams gethostParams; HIP_CHECK(hipGraphHostNodeGetParams(hostNode, &gethostParams)); - REQUIRE(memcmp(&sethostParams, &gethostParams, sizeof(hipHostNodeParams)) - == 0); + REQUIRE(memcmp(&sethostParams, &gethostParams, sizeof(hipHostNodeParams)) == 0); } else { hipHostNodeParams gethostParams; HIP_CHECK(hipGraphHostNodeGetParams(hostNode, &gethostParams)); - REQUIRE(memcmp(&hostParams, &gethostParams, sizeof(hipHostNodeParams)) - == 0); + REQUIRE(memcmp(&hostParams, &gethostParams, sizeof(hipHostNodeParams)) == 0); } + // Instantiate and launch the graph HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph)); HIP_CHECK(hipStreamSynchronize(streamForGraph)); // Verify execution result - if (setparams) { for (size_t i = 0; i < N; i++) { if (C_h[i] != static_cast(i * i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } } else { for (size_t i = 0; i < N; i++) { if (A_h[i] != static_cast(i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } @@ -255,21 +240,18 @@ void hipGraphHostNodeGetParams_func(bool setparams) { HIP_CHECK(hipGraphDestroy(graph)); HIP_CHECK(hipStreamDestroy(streamForGraph)); } + /* -This testcase verifies hipGraphHostNodeGetParams API by +This test case verifies hipGraphHostNodeGetParams API by adding host node to graph and gets the host params and validates it */ -TEST_CASE("Unit_hipGraphHostNodeGetParams_BasicFunc") { - hipGraphHostNodeGetParams_func(false); -} +TEST_CASE("Unit_hipGraphHostNodeGetParams_BasicFunc") { hipGraphHostNodeGetParams_func(false); } /* -This testcase verifies hipGraphHostNodeGetParams API by +This test case verifies hipGraphHostNodeGetParams API by adding host node to graph, updates host node params using hipGraphHostNodeSetParams and gets the host params validates it */ -TEST_CASE("Unit_hipGraphHostNodeGetParams_SetParams") { - hipGraphHostNodeGetParams_func(true); -} +TEST_CASE("Unit_hipGraphHostNodeGetParams_SetParams") { hipGraphHostNodeGetParams_func(true); } diff --git a/projects/hip-tests/catch/unit/graph/hipGraphHostNodeSetParams.cc b/projects/hip-tests/catch/unit/graph/hipGraphHostNodeSetParams.cc index a2899198cd..d9b275b375 100644 --- a/projects/hip-tests/catch/unit/graph/hipGraphHostNodeSetParams.cc +++ b/projects/hip-tests/catch/unit/graph/hipGraphHostNodeSetParams.cc @@ -6,24 +6,26 @@ 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 of hipGraphHostNodeSetParams API: +Test Case Scenarios of hipGraphHostNodeSetParams API: Functional: 1. Creates graph, Adds HostNode, update hostNode params using hipGraphHostNodeSetParams API and validates the result -2. Create graph, Add Graphnodes and clones the graph. Add Hostnode to the cloned graph, update +2. Create graph, Add Graph nodes and clones the graph. Add Host node to the cloned graph, update hostNode params using hipGraphHostNodeSetParams API and validate the result Negative: @@ -31,30 +33,30 @@ Negative: 1) Pass pGraphNode as nullptr and verify api doesn’t crash, returns error code. 2) Pass pNodeParams as nullptr and verify api doesn’t crash, returns error code. 3) Pass hipHostNodeParams::hipHostFn_t as nullptr and verify api doesn't crash, returns error code. -4) Pass unintialized host params +4) Pass uninitialized host params */ -#include #include +#include #define SIZE 1024 -static void callbackfunc(void *A_h) { - int *A = reinterpret_cast(A_h); +static void callbackfunc(void* A_h) { + int* A = reinterpret_cast(A_h); for (int i = 0; i < SIZE; i++) { - A[i] = i; + A[i] = i; } } -static void callbackfunc_setparams(void *B_h) { - int *B = reinterpret_cast(B_h); +static void callbackfunc_setparams(void* B_h) { + int* B = reinterpret_cast(B_h); for (int i = 0; i < SIZE; i++) { - B[i] = i * i; + B[i] = i * i; } } /* -This testcase verifies the negative scenarios of +This test case verifies the negative scenarios of hipGraphHostNodeSetParams API */ TEST_CASE("Unit_hipGraphHostNodeSetParams_Negative") { @@ -62,8 +64,7 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_Negative") { hipGraph_t graph; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); @@ -71,65 +72,63 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_Negative") { hipHostNodeParams hostParams; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); -#if HT_NVIDIA + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); + SECTION("Passing nullptr to graph node") { - REQUIRE(hipGraphHostNodeSetParams(nullptr, &hostParams) - == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphHostNodeSetParams(nullptr, &hostParams), hipErrorInvalidValue); } SECTION("Passing nullptr to hostParams") { - REQUIRE(hipGraphHostNodeSetParams(hostNode, nullptr) - == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphHostNodeSetParams(hostNode, nullptr), hipErrorInvalidValue); } -#endif SECTION("Passing nullptr to host func") { hostParams.fn = nullptr; - REQUIRE(hipGraphHostNodeSetParams(hostNode, &hostParams) - == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphHostNodeSetParams(hostNode, &hostParams), hipErrorInvalidValue); } - - SECTION("Passing unintialized hostParams") { + SECTION("Passing uninitialized hostParams") { hipHostNodeParams unintParams = {0, 0}; - REQUIRE(hipGraphHostNodeSetParams(hostNode, &unintParams) - == hipErrorInvalidValue); + HIP_CHECK_ERROR(hipGraphHostNodeSetParams(hostNode, &unintParams), hipErrorInvalidValue); } + +#if HT_NVIDIA // segfaults on AMD + SECTION("node is not a host node") { + hipGraphNode_t empty_node; + HIP_CHECK(hipGraphAddEmptyNode(&empty_node, graph, nullptr, 0)); + HIP_CHECK_ERROR(hipGraphHostNodeSetParams(empty_node, &hostParams), hipErrorInvalidValue); + } +#endif + + HipTest::freeArrays(A_d, nullptr, C_d, A_h, nullptr, C_h, false); HIP_CHECK(hipGraphDestroy(graph)); } + /* -This testcase verifies hipGraphHostNodeSetParams API in cloned graph +This test case verifies hipGraphHostNodeSetParams API in cloned graph Creates graph, Add graph nodes and clone the graph Add HostNode to the cloned graph,update the host params using hipGraphHostNodeSetParams API and validates the result */ -TEST_CASE("Unit_hipGraphHostNodeSetParams_ClonedGraphwithHostNode") { +TEST_CASE("Unit_hipGraphHostNodeSetParams_ClonedGraphWithHostNode") { constexpr size_t N = 1024; constexpr size_t Nbytes = N * sizeof(int); hipGraph_t graph; hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); - hipGraphNode_t memcpyH2D_C, - memcpyD2H_AC; + hipGraphNode_t memcpyH2D_C, memcpyD2H_AC; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); hipGraph_t clonedgraph; HIP_CHECK(hipGraphClone(&clonedgraph, graph)); @@ -138,17 +137,13 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_ClonedGraphwithHostNode") { hipHostNodeParams hostParams; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, - nullptr, - 0, &hostParams)); - + HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, nullptr, 0, &hostParams)); hipHostNodeParams sethostParams; sethostParams.fn = callbackfunc_setparams; sethostParams.userData = C_h; HIP_CHECK(hipGraphHostNodeSetParams(hostNode, &sethostParams)); - // Instantiate and launch the cloned graph HIP_CHECK(hipGraphInstantiate(&graphExec, clonedgraph, nullptr, nullptr, 0)); HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph)); @@ -157,7 +152,7 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_ClonedGraphwithHostNode") { // Verify execution result for (size_t i = 0; i < N; i++) { if (C_h[i] != static_cast(i * i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } } @@ -169,7 +164,7 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_ClonedGraphwithHostNode") { } /* -This testcase verifies the following scenario +This test case verifies the following scenario Create graph, Adds host node to the graph, updates the host params using hipGraphHostNodeSetParams API and validates the result @@ -181,31 +176,24 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_BasicFunc") { hipGraphExec_t graphExec; int *A_d{nullptr}, *C_d{nullptr}; int *A_h{nullptr}, *C_h{nullptr}; - HipTest::initArrays(&A_d, nullptr, &C_d, - &A_h, nullptr, &C_h, N, false); + HipTest::initArrays(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false); HIP_CHECK(hipGraphCreate(&graph, 0)); hipGraphNode_t memcpyD2H_AC, memcpyH2D_C; hipStream_t streamForGraph; HIP_CHECK(hipStreamCreate(&streamForGraph)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, - 0, C_d, C_h, - Nbytes, hipMemcpyHostToDevice)); - HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, - 0, A_h, C_d, - Nbytes, hipMemcpyDeviceToHost)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h, Nbytes, + hipMemcpyHostToDevice)); + HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d, Nbytes, + hipMemcpyDeviceToHost)); hipGraphNode_t hostNode; hipHostNodeParams hostParams; hostParams.fn = callbackfunc; hostParams.userData = A_h; - HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, - nullptr, - 0, &hostParams)); + HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, - &memcpyD2H_AC, 1)); - HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, - &hostNode, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1)); + HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, &hostNode, 1)); hipHostNodeParams sethostParams; sethostParams.fn = callbackfunc_setparams; @@ -220,7 +208,7 @@ TEST_CASE("Unit_hipGraphHostNodeSetParams_BasicFunc") { // Verify execution result for (size_t i = 0; i < N; i++) { if (C_h[i] != static_cast(i * i)) { - INFO("Validation failed i " << i << "C_h[i] "<< C_h[i]); + INFO("Validation failed i " << i << "C_h[i] " << C_h[i]); REQUIRE(false); } }