/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /** * @addtogroup hipHccModuleLaunchKernel hipHccModuleLaunchKernel * @{ * @ingroup KernelTest * `HIP_PUBLIC_API hipError_t hipHccModuleLaunchKernel (hipFunction_t f, * uint32_t globalWorkSizeX, * uint32_t globalWorkSizeY, * uint32_t globalWorkSizeZ, * uint32_t localWorkSizeX, * uint32_t localWorkSizeY, * uint32_t localWorkSizeZ, * size_t sharedMemBytes, * hipStream_t hStream, * void ** kernelParams, * void ** extra, * hipEvent_t startEvent, * hipEvent_t stopEvent )` - * This HIP API is deprecated, please use hipExtModuleLaunchKernel() instead. * Launches kernel with parameters and shared memory on stream with arguments * passed to kernel params or extra arguments. */ #include #include "hip/hip_ext.h" #define fileName "copyKernel.code" #define kernel_name "copy_ker" /** * Test Description * ------------------------ * - Basic functional testcase to verify kernel launch * Test source * ------------------------ * - catch\unit\module\hipHccModuleLaunchKernel.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.7 */ HIP_TEST_CASE(Unit_hipHccModuleLaunchKernel_basic) { size_t width = GENERATE(3, 4, 100); size_t widthInBytes = width * sizeof(int); int *A_d, *B_d; int* A_h = reinterpret_cast(malloc(widthInBytes)); int* B_h = reinterpret_cast(malloc(widthInBytes)); for (int i = 0; i < width; i++) { A_h[i] = i; } HIP_CHECK(hipMalloc(reinterpret_cast(&A_d), widthInBytes)); HIP_CHECK(hipMalloc(reinterpret_cast(&B_d), widthInBytes)); void* kernelArgs[3] = {&A_d, &B_d, &widthInBytes}; HIP_CHECK(hipMemcpyHtoD((hipDeviceptr_t)A_d, A_h, widthInBytes)); hipModule_t module; HIP_CHECK(hipModuleLoad(&module, fileName)); hipFunction_t kernelFunc; HIP_CHECK(hipModuleGetFunction(&kernelFunc, module, kernel_name)); HIP_CHECK(hipHccModuleLaunchKernel(kernelFunc, width, 1, 1, width, 1, 1, 0, 0, kernelArgs, nullptr, nullptr, nullptr)); HIP_CHECK(hipMemcpyDtoH(B_h, (hipDeviceptr_t)B_d, widthInBytes)); for (int i = 0; i < width; i++) { REQUIRE(A_h[i] == B_h[i]); } HIP_CHECK(hipModuleUnload(module)); HIP_CHECK(hipFree(A_d)); HIP_CHECK(hipFree(B_d)); free(A_h); free(B_h); } /** * Test Description * ------------------------ * - Negative testcases * Test source * ------------------------ * - catch\unit\module\hipHccModuleLaunchKernel.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.7 */ HIP_TEST_CASE(Unit_hipHccModuleLaunchKernel_NegTst) { size_t width = GENERATE(3, 4, 100); size_t widthInBytes = width * sizeof(int); int *A_d, *B_d; HIP_CHECK(hipMalloc(reinterpret_cast(&A_d), widthInBytes)); HIP_CHECK(hipMalloc(reinterpret_cast(&B_d), widthInBytes)); void* kernelArgs[3] = {&A_d, &B_d, &widthInBytes}; hipModule_t module; HIP_CHECK(hipModuleLoad(&module, fileName)); hipFunction_t kernelFunc; HIP_CHECK(hipModuleGetFunction(&kernelFunc, module, kernel_name)); SECTION("nullptr to f(first argument)") { HIP_CHECK_ERROR(hipHccModuleLaunchKernel(nullptr, width, 1, 1, width, 1, 1, 0, 0, kernelArgs, nullptr, nullptr, nullptr), hipErrorInvalidHandle); } SECTION("-1 to localWorkSizeX(fifth argument)") { HIP_CHECK_ERROR(hipHccModuleLaunchKernel(kernelFunc, width, 1, 1, -1, 1, 1, 0, 0, kernelArgs, nullptr, nullptr, nullptr), hipErrorInvalidConfiguration); } SECTION("-1 to localWorkSizeY(sixth argument)") { HIP_CHECK_ERROR(hipHccModuleLaunchKernel(kernelFunc, width, 1, 1, width, -1, 1, 0, 0, kernelArgs, nullptr, nullptr, nullptr), hipErrorInvalidConfiguration); } SECTION("-1 to localWorkSizeZ(seventh argument)") { HIP_CHECK_ERROR(hipHccModuleLaunchKernel(kernelFunc, width, 1, 1, width, 1, -1, 0, 0, kernelArgs, nullptr, nullptr, nullptr), hipErrorInvalidConfiguration); } SECTION("-1 to sharedMemBytes(eighth argument)") { HIP_CHECK_ERROR(hipHccModuleLaunchKernel(kernelFunc, width, 1, 1, width, 1, 1, -1, 0, kernelArgs, nullptr, nullptr, nullptr), hipErrorInvalidValue); } SECTION("nullptr to kernelParams(10th argument)") { HIP_CHECK_ERROR(hipHccModuleLaunchKernel(kernelFunc, width, 1, 1, width, 1, 1, 0, 0, nullptr, nullptr, nullptr, nullptr), hipErrorInvalidValue); } HIP_CHECK(hipModuleUnload(module)); HIP_CHECK(hipFree(A_d)); HIP_CHECK(hipFree(B_d)); }