/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include "kernel_launch_common.hh" #include /** * @addtogroup kernelLaunch kernel launch * @{ * @ingroup PerformanceTestKernelLaunch * Contains performance tests for kernel launch overhead benchmarking. */ template class ExtLaunchKernelBenchmark : public KernelLaunchBenchmark, timer_type> { public: constexpr void LaunchKernel() { if constexpr (kernel_type == KernelType::kNull) { error_ = hipExtLaunchKernel(reinterpret_cast(NullKernel), 1, 1, nullptr, 0, nullptr, events_[0], events_[1], 0u); } else if constexpr (kernel_type == KernelType::kSmall) { error_ = hipExtLaunchKernel(reinterpret_cast(KernelWithSmallArgs), 1, 1, small_kernel_args_, 0, nullptr, events_[0], events_[1], 0u); } else if constexpr (kernel_type == KernelType::kMedium) { error_ = hipExtLaunchKernel(reinterpret_cast(KernelWithMediumArgs), 1, 1, medium_kernel_args_, 0, nullptr, events_[0], events_[1], 0u); } else if constexpr (kernel_type == KernelType::kLarge) { error_ = hipExtLaunchKernel(reinterpret_cast(KernelWithLargeArgs), 1, 1, large_kernel_args_, 0, nullptr, events_[0], events_[1], 0u); } else ; } hipError_t GetError() { return error_; } private: EventsGuard events_{2}; hipError_t error_; char* out_ = nullptr; void* small_kernel_args_[2] = {&small_kernel_args, &out_}; void* medium_kernel_args_[2] = {&medium_kernel_args, &out_}; void* large_kernel_args_[2] = {&large_kernel_args, &out_}; }; template static void RunBenchmark(bool sync) { ExtLaunchKernelBenchmark benchmark; benchmark.AddSectionName(GetSynchronizationSectionName(sync)); benchmark.AddSectionName(GetKernelTypeSectionName()); benchmark.AddSectionName(GetTimerTypeSectionName()); benchmark.Run(sync); HIP_CHECK(benchmark.GetError()); } /** * Test Description * ------------------------ * - Calls an empty kernel using hipExtLaunchKernel: * -# With different timing methods: * - CPU-based * - Event-based * -# With different synchronization behavior: * - Using a stream synchronization between each iteration * - Without any synchronization between iterations * -# With different kernel argument sizes * Test source * ------------------------ * - performance/api/kernelLaunch/hipExtLaunchKernel.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Performance_hipExtLaunchKernel) { bool sync = GENERATE(true, false); SECTION("null kernel") { SECTION("cpu-based timing") { RunBenchmark(sync); } SECTION("event-based timing") { RunBenchmark(sync); } } SECTION("small kernel") { SECTION("cpu-based timing") { RunBenchmark(sync); } SECTION("event-based timing") { RunBenchmark(sync); } } SECTION("medium kernel") { SECTION("cpu-based timing") { RunBenchmark(sync); } SECTION("event-based timing") { RunBenchmark(sync); } } SECTION("large kernel") { SECTION("cpu-based timing") { RunBenchmark(sync); } SECTION("event-based timing") { RunBenchmark(sync); } } } /** * End doxygen group kernelLaunch. * @} */