/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include "min_max_common.hh" #include /** * @addtogroup unsafeAtomicMax unsafeAtomicMax * @{ * @ingroup AtomicsTest * `unsafeAtomicMax(TestType* address, TestType* val)` - * calculates maximum between address and val, returns old value. */ // Helper function to run unsafeAtomicMax tests for same address (single kernel) template static void runUnsafeAtomicMaxSameAddressTest() { for (auto current = 0; current < cmd_options.iterations; ++current) { DYNAMIC_SECTION("Same address " << current) { MinMax::SingleDeviceSingleKernelTest( 1, sizeof(TestType)); } } } // Helper function to run unsafeAtomicMax tests for adjacent addresses (single kernel) template static void runUnsafeAtomicMaxAdjacentAddressesTest() { int warp_size = 0; HIP_CHECK(hipDeviceGetAttribute(&warp_size, hipDeviceAttributeWarpSize, 0)); for (auto current = 0; current < cmd_options.iterations; ++current) { DYNAMIC_SECTION("Adjacent address " << current) { MinMax::SingleDeviceSingleKernelTest( warp_size, sizeof(TestType)); } } } // Helper function to run unsafeAtomicMax tests for scattered addresses (single kernel) template static void runUnsafeAtomicMaxScatteredAddressesTest() { int warp_size = 0; HIP_CHECK(hipDeviceGetAttribute(&warp_size, hipDeviceAttributeWarpSize, 0)); const auto cache_line_size = 128u; for (auto current = 0; current < cmd_options.iterations; ++current) { DYNAMIC_SECTION("Scattered address " << current) { MinMax::SingleDeviceSingleKernelTest( warp_size, cache_line_size); } } } // Helper function to run unsafeAtomicMax tests for same address (multi kernel) template static void runUnsafeAtomicMaxMultiKernelSameAddressTest() { for (auto current = 0; current < cmd_options.iterations; ++current) { DYNAMIC_SECTION("Same address " << current) { MinMax::SingleDeviceMultipleKernelTest( 2, 1, sizeof(TestType)); } } } // Helper function to run unsafeAtomicMax tests for adjacent addresses (multi kernel) template static void runUnsafeAtomicMaxMultiKernelAdjacentAddressesTest() { int warp_size = 0; HIP_CHECK(hipDeviceGetAttribute(&warp_size, hipDeviceAttributeWarpSize, 0)); for (auto current = 0; current < cmd_options.iterations; ++current) { DYNAMIC_SECTION("Adjacent address " << current) { MinMax::SingleDeviceMultipleKernelTest( 2, warp_size, sizeof(TestType)); } } } // Helper function to run unsafeAtomicMax tests for scattered addresses (multi kernel) template static void runUnsafeAtomicMaxMultiKernelScatteredAddressesTest() { int warp_size = 0; HIP_CHECK(hipDeviceGetAttribute(&warp_size, hipDeviceAttributeWarpSize, 0)); const auto cache_line_size = 128u; for (auto current = 0; current < cmd_options.iterations; ++current) { DYNAMIC_SECTION("Scattered address " << current) { MinMax::SingleDeviceMultipleKernelTest( 2, warp_size, cache_line_size); } } } /** * Test Description * ------------------------ * - Performs unsafeAtomicMax from multiple threads on the same address. * - Uses only one device and launches one kernel. * Test source * ------------------------ * - unit/atomics/unsafeAtomicMax.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Unit_unsafeAtomicMax_Positive_SameAddress) { SECTION("float") { runUnsafeAtomicMaxSameAddressTest(); } SECTION("double") { runUnsafeAtomicMaxSameAddressTest(); } } /** * Test Description * ------------------------ * - Performs unsafeAtomicMax from multiple threads on adjacent addresses. * - Uses only one device and launches one kernel. * Test source * ------------------------ * - unit/atomics/unsafeAtomicMax.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Unit_unsafeAtomicMax_Positive_Adjacent_Addresses) { SECTION("float") { runUnsafeAtomicMaxAdjacentAddressesTest(); } SECTION("double") { runUnsafeAtomicMaxAdjacentAddressesTest(); } } /** * Test Description * ------------------------ * - Performs unsafeAtomicMax from multiple threads on the scattered addresses. * - Uses only one device and launches one kernel. * Test source * ------------------------ * - unit/atomics/unsafeAtomicMax.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Unit_unsafeAtomicMax_Positive_Scattered_Addresses) { SECTION("float") { runUnsafeAtomicMaxScatteredAddressesTest(); } SECTION("double") { runUnsafeAtomicMaxScatteredAddressesTest(); } } /** * Test Description * ------------------------ * - Performs unsafeAtomicMax from multiple threads on the same address. * - Uses only one device and launches multiple kernels. * Test source * ------------------------ * - unit/atomics/unsafeAtomicMax.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Unit_unsafeAtomicMax_Positive_Multi_Kernel_Same_Address) { SECTION("float") { runUnsafeAtomicMaxMultiKernelSameAddressTest(); } SECTION("double") { runUnsafeAtomicMaxMultiKernelSameAddressTest(); } } /** * Test Description * ------------------------ * - Performs unsafeAtomicMax from multiple threads on adjacent addresses. * - Uses only one device and launches multiple kernels. * Test source * ------------------------ * - unit/atomics/unsafeAtomicMax.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Unit_unsafeAtomicMax_Positive_Multi_Kernel_Adjacent_Addresses) { SECTION("float") { runUnsafeAtomicMaxMultiKernelAdjacentAddressesTest(); } SECTION("double") { runUnsafeAtomicMaxMultiKernelAdjacentAddressesTest(); } } /** * Test Description * ------------------------ * - Performs unsafeAtomicMax from multiple threads on the scattered addresses. * - Uses only one device and launches multiple kernels. * Test source * ------------------------ * - unit/atomics/unsafeAtomicMax.cc * Test requirements * ------------------------ * - HIP_VERSION >= 5.2 */ HIP_TEST_CASE(Unit_unsafeAtomicMax_Positive_Multi_Kernel_Scattered_Addresses) { SECTION("float") { runUnsafeAtomicMaxMultiKernelScatteredAddressesTest(); } SECTION("double") { runUnsafeAtomicMaxMultiKernelScatteredAddressesTest(); } } /** * End doxygen group AtomicsTest. * @} */