2022-09-23 12:35:27 +05:30
|
|
|
|
/*
|
|
|
|
|
|
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:
|
2023-06-28 06:04:52 +02:00
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
all copies or substantial portions of the Software.
|
2023-06-28 06:04:52 +02:00
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
2022-09-23 12:35:27 +05:30
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
2023-06-28 06:04:52 +02:00
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
2022-09-23 12:35:27 +05:30
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
2023-06-28 06:04:52 +02:00
|
|
|
|
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
|
2022-09-23 12:35:27 +05:30
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-28 06:04:52 +02:00
|
|
|
|
Test Case Scenarios of hipGraphHostNodeGetParams API:
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
Functional Scenarios:
|
2023-06-28 06:04:52 +02:00
|
|
|
|
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
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
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.
|
2023-06-28 06:04:52 +02:00
|
|
|
|
3) Pass uninitialized graph node
|
2022-09-23 12:35:27 +05:30
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <hip_test_checkers.hh>
|
2023-06-28 06:04:52 +02:00
|
|
|
|
#include <hip_test_common.hh>
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
#define SIZE 1024
|
|
|
|
|
|
|
2023-06-28 06:04:52 +02:00
|
|
|
|
static void callbackfunc(void* A_h) {
|
|
|
|
|
|
int* A = reinterpret_cast<int*>(A_h);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
for (int i = 0; i < SIZE; i++) {
|
|
|
|
|
|
A[i] = i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-28 06:04:52 +02:00
|
|
|
|
static void callbackfunc_setparams(void* B_h) {
|
|
|
|
|
|
int* B = reinterpret_cast<int*>(B_h);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
for (int i = 0; i < SIZE; i++) {
|
2023-06-28 06:04:52 +02:00
|
|
|
|
B[i] = i * i;
|
2022-09-23 12:35:27 +05:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2023-06-28 06:04:52 +02:00
|
|
|
|
This test case verifies the negative scenarios of
|
2022-09-23 12:35:27 +05:30
|
|
|
|
hipGraphHostNodeGetParams API
|
|
|
|
|
|
*/
|
|
|
|
|
|
TEST_CASE("Unit_hipGraphHostNodeGetParams_Negative") {
|
|
|
|
|
|
constexpr size_t N = 1024;
|
|
|
|
|
|
hipGraph_t graph;
|
|
|
|
|
|
int *A_d{nullptr}, *C_d{nullptr};
|
|
|
|
|
|
int *A_h{nullptr}, *C_h{nullptr};
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HipTest::initArrays<int>(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
HIP_CHECK(hipGraphCreate(&graph, 0));
|
|
|
|
|
|
|
|
|
|
|
|
hipGraphNode_t hostNode;
|
|
|
|
|
|
hipHostNodeParams hostParams = {0, 0};
|
|
|
|
|
|
hostParams.fn = callbackfunc;
|
|
|
|
|
|
hostParams.userData = A_h;
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams));
|
2022-09-23 12:35:27 +05:30
|
|
|
|
hipHostNodeParams GethostParams;
|
|
|
|
|
|
|
|
|
|
|
|
SECTION("Passing nullptr to graph node") {
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HIP_CHECK_ERROR(hipGraphHostNodeGetParams(nullptr, &GethostParams), hipErrorInvalidValue);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SECTION("Passing nullptr to hostParams") {
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HIP_CHECK_ERROR(hipGraphHostNodeGetParams(hostNode, nullptr), hipErrorInvalidValue);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-28 06:04:52 +02:00
|
|
|
|
#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);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
}
|
2023-06-28 06:04:52 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
HipTest::freeArrays<int>(A_d, nullptr, C_d, A_h, nullptr, C_h, false);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
HIP_CHECK(hipGraphDestroy(graph));
|
|
|
|
|
|
}
|
2023-06-28 06:04:52 +02:00
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
/*
|
2023-06-28 06:04:52 +02:00
|
|
|
|
This test case verifies hipGraphHostNodeGetParams API in cloned graph
|
2022-09-23 12:35:27 +05:30
|
|
|
|
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.
|
|
|
|
|
|
*/
|
2023-06-28 06:04:52 +02:00
|
|
|
|
TEST_CASE("Unit_hipGraphHostNodeGetParams_ClonedGraphWithHostNode") {
|
2022-09-23 12:35:27 +05:30
|
|
|
|
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};
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HipTest::initArrays<int>(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
HIP_CHECK(hipGraphCreate(&graph, 0));
|
2023-06-28 06:04:52 +02:00
|
|
|
|
hipGraphNode_t memcpyH2D_A, memcpyH2D_C, memcpyD2H_AC;
|
2022-09-23 12:35:27 +05:30
|
|
|
|
hipStream_t streamForGraph;
|
|
|
|
|
|
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
2023-06-28 06:04:52 +02:00
|
|
|
|
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));
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
hipGraph_t clonedgraph;
|
|
|
|
|
|
HIP_CHECK(hipGraphClone(&clonedgraph, graph));
|
|
|
|
|
|
|
|
|
|
|
|
hipGraphNode_t hostNode;
|
|
|
|
|
|
hipHostNodeParams hostParams = {0, 0};
|
|
|
|
|
|
hostParams.fn = callbackfunc;
|
|
|
|
|
|
hostParams.userData = A_h;
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HIP_CHECK(hipGraphAddHostNode(&hostNode, clonedgraph, nullptr, 0, &hostParams));
|
|
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
hipHostNodeParams sethostParams = {0, 0};
|
|
|
|
|
|
sethostParams.fn = callbackfunc_setparams;
|
|
|
|
|
|
sethostParams.userData = C_h;
|
|
|
|
|
|
HIP_CHECK(hipGraphHostNodeSetParams(hostNode, &sethostParams));
|
|
|
|
|
|
hipHostNodeParams gethostParams;
|
|
|
|
|
|
HIP_CHECK(hipGraphHostNodeGetParams(hostNode, &gethostParams));
|
2023-06-28 06:04:52 +02:00
|
|
|
|
REQUIRE(memcmp(&sethostParams, &gethostParams, sizeof(hipHostNodeParams)) == 0);
|
|
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
// Instantiate and launch the cloned graph
|
|
|
|
|
|
HIP_CHECK(hipGraphInstantiate(&graphExec, clonedgraph, nullptr, nullptr, 0));
|
|
|
|
|
|
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
|
|
|
|
|
HIP_CHECK(hipStreamSynchronize(streamForGraph));
|
|
|
|
|
|
|
|
|
|
|
|
// Verify execution result
|
|
|
|
|
|
for (size_t i = 0; i < N; i++) {
|
|
|
|
|
|
if (C_h[i] != static_cast<int>(i * i)) {
|
2023-06-28 06:04:52 +02:00
|
|
|
|
INFO("Validation failed i " << i << "C_h[i] " << C_h[i]);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
REQUIRE(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-28 06:04:52 +02:00
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
|
|
|
|
|
HIP_CHECK(hipGraphDestroy(graph));
|
|
|
|
|
|
HIP_CHECK(hipGraphDestroy(clonedgraph));
|
|
|
|
|
|
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
|
|
|
|
|
HipTest::freeArrays<int>(A_d, nullptr, C_d, A_h, nullptr, C_h, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2023-06-28 06:04:52 +02:00
|
|
|
|
This test case verifies the following scenarios
|
2022-09-23 12:35:27 +05:30
|
|
|
|
Create graph, Adds host node to the graph, updates it
|
|
|
|
|
|
with hipGraphHostNodeSetParams and gets the host node
|
|
|
|
|
|
params using hipGraphHostNodeGetParams API and validates
|
|
|
|
|
|
it
|
|
|
|
|
|
*/
|
|
|
|
|
|
void hipGraphHostNodeGetParams_func(bool setparams) {
|
|
|
|
|
|
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};
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HipTest::initArrays<int>(&A_d, nullptr, &C_d, &A_h, nullptr, &C_h, N, false);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
HIP_CHECK(hipGraphCreate(&graph, 0));
|
|
|
|
|
|
hipGraphNode_t memcpyH2D_A, memcpyD2H_AC, memcpyH2D_C;
|
|
|
|
|
|
hipStream_t streamForGraph;
|
|
|
|
|
|
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
2023-06-28 06:04:52 +02:00
|
|
|
|
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));
|
|
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
hipGraphNode_t hostNode;
|
|
|
|
|
|
hipHostNodeParams hostParams = {0, 0};
|
|
|
|
|
|
hostParams.fn = callbackfunc;
|
|
|
|
|
|
hostParams.userData = A_h;
|
2023-06-28 06:04:52 +02:00
|
|
|
|
HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams));
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
2023-06-28 06:04:52 +02:00
|
|
|
|
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));
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
if (setparams) {
|
|
|
|
|
|
hipHostNodeParams sethostParams = {0, 0};
|
|
|
|
|
|
sethostParams.fn = callbackfunc_setparams;
|
|
|
|
|
|
sethostParams.userData = C_h;
|
|
|
|
|
|
HIP_CHECK(hipGraphHostNodeSetParams(hostNode, &sethostParams));
|
|
|
|
|
|
|
|
|
|
|
|
hipHostNodeParams gethostParams;
|
|
|
|
|
|
HIP_CHECK(hipGraphHostNodeGetParams(hostNode, &gethostParams));
|
2023-06-28 06:04:52 +02:00
|
|
|
|
REQUIRE(memcmp(&sethostParams, &gethostParams, sizeof(hipHostNodeParams)) == 0);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
} else {
|
|
|
|
|
|
hipHostNodeParams gethostParams;
|
|
|
|
|
|
HIP_CHECK(hipGraphHostNodeGetParams(hostNode, &gethostParams));
|
2023-06-28 06:04:52 +02:00
|
|
|
|
REQUIRE(memcmp(&hostParams, &gethostParams, sizeof(hipHostNodeParams)) == 0);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
}
|
2023-06-28 06:04:52 +02:00
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
// 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<int>(i * i)) {
|
2023-06-28 06:04:52 +02:00
|
|
|
|
INFO("Validation failed i " << i << "C_h[i] " << C_h[i]);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
REQUIRE(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (size_t i = 0; i < N; i++) {
|
|
|
|
|
|
if (A_h[i] != static_cast<int>(i)) {
|
2023-06-28 06:04:52 +02:00
|
|
|
|
INFO("Validation failed i " << i << "C_h[i] " << C_h[i]);
|
2022-09-23 12:35:27 +05:30
|
|
|
|
REQUIRE(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HipTest::freeArrays<int>(A_d, nullptr, C_d, A_h, nullptr, C_h, false);
|
|
|
|
|
|
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
|
|
|
|
|
HIP_CHECK(hipGraphDestroy(graph));
|
|
|
|
|
|
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
|
|
|
|
|
}
|
2023-06-28 06:04:52 +02:00
|
|
|
|
|
2022-09-23 12:35:27 +05:30
|
|
|
|
/*
|
2023-06-28 06:04:52 +02:00
|
|
|
|
This test case verifies hipGraphHostNodeGetParams API by
|
2022-09-23 12:35:27 +05:30
|
|
|
|
adding host node to graph and gets the host params and
|
|
|
|
|
|
validates it
|
|
|
|
|
|
*/
|
2023-06-28 06:04:52 +02:00
|
|
|
|
TEST_CASE("Unit_hipGraphHostNodeGetParams_BasicFunc") { hipGraphHostNodeGetParams_func(false); }
|
2022-09-23 12:35:27 +05:30
|
|
|
|
|
|
|
|
|
|
/*
|
2023-06-28 06:04:52 +02:00
|
|
|
|
This test case verifies hipGraphHostNodeGetParams API by
|
2022-09-23 12:35:27 +05:30
|
|
|
|
adding host node to graph, updates host node params
|
|
|
|
|
|
using hipGraphHostNodeSetParams and gets the host params
|
|
|
|
|
|
validates it
|
|
|
|
|
|
*/
|
2023-06-28 06:04:52 +02:00
|
|
|
|
TEST_CASE("Unit_hipGraphHostNodeGetParams_SetParams") { hipGraphHostNodeGetParams_func(true); }
|