Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/graph/hipGraphKernelNodeGetParams.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

140 lines
4.9 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
/**
Test Case Scenarios :
Negative -
1) Pass node as nullptr and verify api returns error code.
2) Pass pNodeParams as nullptr and verify api returns error code.
Functional -
1) Create a graph, add kernel node to graph with desired kernel node params.
Verify api fetches the node params mentioned while adding kernel node.
2) Set kernel node params with hipGraphKernelNodeSetParams,
now get the params and verify both are same.
*/
#include <hip_test_common.hh>
#include <hip_test_kernels.hh>
#define THREADS_PER_BLOCK 512
/* Test verifies hipGraphKernelNodeGetParams API Negative scenarios.
*/
HIP_TEST_CASE(Unit_hipGraphKernelNodeGetParams_Negative) {
constexpr int N = 1024;
size_t NElem{N};
int *A_d, *B_d, *C_d;
hipGraph_t graph;
hipGraphNode_t kNode;
hipKernelNodeParams kNodeParams{};
HIP_CHECK(hipMalloc(&A_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&B_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&C_d, sizeof(int) * N));
HIP_CHECK(hipGraphCreate(&graph, 0));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&NElem)};
kNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
kNodeParams.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
HIP_CHECK(hipGraphAddKernelNode(&kNode, graph, nullptr, 0, &kNodeParams));
SECTION("Pass node as nullptr") {
HIP_CHECK_ERROR(hipGraphKernelNodeGetParams(nullptr, &kNodeParams), hipErrorInvalidValue);
}
SECTION("Pass kNodeParams as nullptr") {
HIP_CHECK_ERROR(hipGraphKernelNodeGetParams(kNode, nullptr), hipErrorInvalidValue);
}
#if HT_NVIDIA // segfaults on AMD
SECTION("node is not a kernel node") {
hipGraphNode_t empty_node;
HIP_CHECK(hipGraphAddEmptyNode(&empty_node, graph, nullptr, 0));
HIP_CHECK_ERROR(hipGraphKernelNodeGetParams(empty_node, &kNodeParams), hipErrorInvalidValue);
}
#endif
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(B_d));
HIP_CHECK(hipFree(C_d));
HIP_CHECK(hipGraphDestroy(graph));
}
static bool dim3_compare(dim3 node1, dim3 node2) {
if ((node1.x == node2.x) && (node1.y == node2.y) && (node1.z == node2.z))
return true;
else
return false;
}
static bool kernelParam_compare(void** p1, void** p2) {
for (int i = 0; i < 4; i++) {
if (*reinterpret_cast<int*>(p1[i]) != *reinterpret_cast<int*>(p2[i])) return false;
}
return true;
}
static bool node_compare(hipKernelNodeParams* kNode1, hipKernelNodeParams* kNode2) {
if (!dim3_compare(kNode1->blockDim, kNode2->blockDim)) return false;
if (kNode1->extra != kNode2->extra) return false;
if (kNode1->func != kNode2->func) return false;
if (!dim3_compare(kNode1->gridDim, kNode2->gridDim)) return false;
if (!kernelParam_compare(kNode1->kernelParams, kNode2->kernelParams)) return false;
if (kNode1->sharedMemBytes != kNode2->sharedMemBytes) return false;
return true;
}
/* Test verifies hipGraphKernelNodeGetParams API Functional scenarios.
*/
HIP_TEST_CASE(Unit_hipGraphKernelNodeGetParams_Functional) {
constexpr int N = 1024;
size_t NElem{N};
int *A_d, *B_d, *C_d;
hipGraph_t graph;
hipGraphNode_t kNode;
hipKernelNodeParams kNodeParams{};
HIP_CHECK(hipMalloc(&A_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&B_d, sizeof(int) * N));
HIP_CHECK(hipMalloc(&C_d, sizeof(int) * N));
HIP_CHECK(hipGraphCreate(&graph, 0));
void* kernelArgs[] = {&A_d, &B_d, &C_d, reinterpret_cast<void*>(&NElem)};
kNodeParams.func = reinterpret_cast<void*>(HipTest::vectorADD<int>);
kNodeParams.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
kNodeParams.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
HIP_CHECK(hipGraphAddKernelNode(&kNode, graph, nullptr, 0, &kNodeParams));
SECTION("Get Kernel Param and verify.") {
hipKernelNodeParams kNodeGetParams;
HIP_CHECK(hipGraphKernelNodeGetParams(kNode, &kNodeGetParams));
REQUIRE(node_compare(&kNodeParams, &kNodeGetParams));
}
SECTION("Set kernel node params then Get Kernel Param and verify.") {
hipKernelNodeParams kNodeParams1;
kNodeParams1.func = reinterpret_cast<void*>(HipTest::vectorADDReverse<int>);
kNodeParams1.gridDim = dim3(N / THREADS_PER_BLOCK, 1, 1);
kNodeParams1.blockDim = dim3(THREADS_PER_BLOCK, 1, 1);
kNodeParams1.sharedMemBytes = 0;
kNodeParams1.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams1.extra = nullptr;
HIP_CHECK(hipGraphKernelNodeSetParams(kNode, &kNodeParams1));
hipKernelNodeParams kNodeGetParams1;
HIP_CHECK(hipGraphKernelNodeGetParams(kNode, &kNodeGetParams1));
REQUIRE(node_compare(&kNodeParams1, &kNodeGetParams1));
}
HIP_CHECK(hipFree(A_d));
HIP_CHECK(hipFree(B_d));
HIP_CHECK(hipFree(C_d));
HIP_CHECK(hipGraphDestroy(graph));
}