/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include "kernel_launch_common.hh" #include #include /** * @addtogroup kernelLaunch kernel launch * @{ * @ingroup PerformanceTestKernelLaunch * Contains performance tests for kernel launch overhead benchmarking. */ template class LaunchCooperativeKernelBenchmark : public KernelLaunchBenchmark, timer_type> { public: constexpr void LaunchKernel() { if constexpr (kernel_type == KernelType::kNull) { error_ = hipLaunchCooperativeKernel(reinterpret_cast(NullKernel), dim3{1, 1, 1}, dim3{1, 1, 1}, nullptr, 0, nullptr); } else if constexpr (kernel_type == KernelType::kSmall) { error_ = hipLaunchCooperativeKernel(reinterpret_cast(KernelWithSmallArgs), dim3{1, 1, 1}, dim3{1, 1, 1}, small_kernel_args_, 0, nullptr); } else if constexpr (kernel_type == KernelType::kMedium) { error_ = hipLaunchCooperativeKernel(reinterpret_cast(KernelWithMediumArgs), dim3{1, 1, 1}, dim3{1, 1, 1}, medium_kernel_args_, 0, nullptr); } else if constexpr (kernel_type == KernelType::kLarge) { error_ = hipLaunchCooperativeKernel(reinterpret_cast(KernelWithLargeArgs), dim3{1, 1, 1}, dim3{1, 1, 1}, large_kernel_args_, 0, nullptr); } else ; } hipError_t GetError() { return error_; } private: 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) { LaunchCooperativeKernelBenchmark 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 hipLaunchCooperativeKernel: * -# 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/hipLaunchCooperativeKernel.cc * Test requirements * ------------------------ * - Device supports CooperativeLaunch * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Performance_hipLaunchCooperativeKernel) { if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HIP_SKIP_TEST(HipTest::SkipReason::kCooperativeLaunchUnsupported); } 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. * @} */