// Copyright (c) 2022-2026 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: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // 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 // THE SOFTWARE. #include "benchmark_device_api.hpp" #include template class Gen, typename T, typename State, auto Dist, typename EngineType, typename... Args> void queue_device_bench(primbench::executor& executor, EngineType engine, size_t blocks, size_t threads, size_t dimensions, size_t offset, Args... args) { executor.queue, State, T, Dist>>(Gen(args...), engine, blocks, threads, dimensions, offset, args...); } template inline constexpr bool uses_64bit_int_v = std::is_same_v || std::is_same_v #ifdef __HIP__ || std::is_same_v || std::is_same_v #endif ; template struct engine_state { using State = StateType; static constexpr auto Engine = EngineVal; }; template void queue_device_permutations(primbench::executor& executor, size_t blocks, size_t threads, size_t dimensions, size_t offset, const std::vector& poisson_lambdas) { if constexpr(uses_64bit_int_v) { queue_device_bench( executor, Engine, blocks, threads, dimensions, offset); } else { queue_device_bench(executor, Engine, blocks, threads, dimensions, offset); } queue_device_bench(executor, Engine, blocks, threads, dimensions, offset); queue_device_bench(executor, Engine, blocks, threads, dimensions, offset); queue_device_bench(executor, Engine, blocks, threads, dimensions, offset); queue_device_bench(executor, Engine, blocks, threads, dimensions, offset); queue_device_bench(executor, Engine, blocks, threads, dimensions, offset); queue_device_bench( executor, Engine, blocks, threads, dimensions, offset); for(double lambda : poisson_lambdas) { queue_device_bench(executor, Engine, blocks, threads, dimensions, offset, lambda); queue_device_bench(executor, Engine, blocks, threads, dimensions, offset, lambda); } #ifdef __HIP__ queue_device_bench( executor, Engine, blocks, threads, dimensions, offset); #endif } template void queue_all_permutations(primbench::executor& executor, size_t blocks, size_t threads, size_t dimensions, size_t offset, const std::vector& poisson_lambdas) { (queue_device_permutations(executor, blocks, threads, dimensions, offset, poisson_lambdas), ...); } int main(int argc, char* argv[]) { primbench::settings settings; settings.size = 128 * primbench::MiB; // In items settings.min_gpu_ms_per_batch = 100; settings.hot = true; primbench::executor executor(argc, argv, settings); auto blocks = executor.get("blocks", 256, "Number of blocks"); auto threads = executor.get("threads", 256, "Threads per block"); auto dimensions = executor.get("dimensions", 1, "Number of quasi-random dimensions"); auto offset = executor.get("offset", 0, "Offset of generated pseudo-random values"); auto poisson_lambdas = executor.get>("lambda", {10.0}, "Space-separated list of Poisson lambdas"); queue_all_permutations< engine_state, engine_state, engine_state, engine_state, engine_state, engine_state, engine_state, engine_state #ifdef __HIP__ , engine_state, engine_state, engine_state, engine_state, engine_state, engine_state #endif >(executor, blocks, threads, dimensions, offset, poisson_lambdas); executor.run(); }