Skip to content

Commit

Permalink
find_first_of: Implement autotuning
Browse files Browse the repository at this point in the history
  • Loading branch information
ex-rzr committed Sep 9, 2024
1 parent 6f4560b commit fd07e9e
Show file tree
Hide file tree
Showing 10 changed files with 659 additions and 186 deletions.
4 changes: 4 additions & 0 deletions benchmark/ConfigAutotuneSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,9 @@ DataType;BlockSize;" PARENT_SCOPE)
set(list_across_names "KeyType;ValueType;BlockSize;TilesPerBlock" PARENT_SCOPE)
set(list_across "${LIMITED_TUNING_TYPES};${TUNING_TYPES};128 192 256 384 512;1 2" PARENT_SCOPE)
set(output_pattern_suffix "@KeyType@_@ValueType@_@BlockSize@_@TilesPerBlock@" PARENT_SCOPE)
elseif(file STREQUAL "benchmark_device_find_first_of")
set(list_across_names "DataType;BlockSize" PARENT_SCOPE)
set(list_across "${LIMITED_TUNING_TYPES};32 64 128 256 512 1024" PARENT_SCOPE)
set(output_pattern_suffix "@DataType@_@BlockSize@" PARENT_SCOPE)
endif()
endfunction()
37 changes: 31 additions & 6 deletions benchmark/benchmark_device_find_first_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "benchmark_device_find_first_of.hpp"
#include "benchmark_device_find_first_of.parallel.hpp"
#include "benchmark_utils.hpp"

// CmdParser
Expand All @@ -35,8 +35,8 @@
#include <cstddef>
#include <string>

#ifndef DEFAULT_N
const size_t DEFAULT_N = 1024 * 1024 * 32;
#ifndef DEFAULT_BYTES
constexpr size_t DEFAULT_BYTES = size_t{1} << 27; // 128 MiB
#endif

#define CREATE_BENCHMARK_FIND_FIRST_OF(TYPE, KEYS_SIZE, FIRST_OCCURENCE) \
Expand All @@ -55,23 +55,35 @@ const size_t DEFAULT_N = 1024 * 1024 * 32;

#define CREATE_BENCHMARK(TYPE) \
{ \
CREATE_BENCHMARK0(TYPE, 1) \
CREATE_BENCHMARK0(TYPE, 10) \
CREATE_BENCHMARK0(TYPE, 128) \
CREATE_BENCHMARK0(TYPE, 1024) \
CREATE_BENCHMARK0(TYPE, 100) \
CREATE_BENCHMARK0(TYPE, 1000) \
CREATE_BENCHMARK0(TYPE, 10000) \
}
// clang-format on

int main(int argc, char* argv[])
{
cli::Parser parser(argc, argv);
parser.set_optional<size_t>("size", "size", DEFAULT_N, "number of values");
parser.set_optional<size_t>("size", "size", DEFAULT_BYTES, "number of bytes");
parser.set_optional<int>("trials", "trials", -1, "number of iterations");
parser.set_optional<std::string>("name_format",
"name_format",
"human",
"either: json,human,txt");
parser.set_optional<std::string>("seed", "seed", "random", get_seed_message());
#ifdef BENCHMARK_CONFIG_TUNING
// optionally run an evenly split subset of benchmarks, when making multiple program invocations
parser.set_optional<int>("parallel_instance",
"parallel_instance",
0,
"parallel instance index");
parser.set_optional<int>("parallel_instances",
"parallel_instances",
1,
"total parallel instances");
#endif
parser.run_and_exit_if_error();

// Parse argv
Expand All @@ -92,16 +104,29 @@ int main(int argc, char* argv[])

// Add benchmarks
std::vector<benchmark::internal::Benchmark*> benchmarks{};
#ifdef BENCHMARK_CONFIG_TUNING
const int parallel_instance = parser.get<int>("parallel_instance");
const int parallel_instances = parser.get<int>("parallel_instances");
config_autotune_register::register_benchmark_subset(benchmarks,
parallel_instance,
parallel_instances,
size,
seed,
stream);
#else // BENCHMARK_CONFIG_TUNING
CREATE_BENCHMARK(int8_t)
CREATE_BENCHMARK(int16_t)
CREATE_BENCHMARK(int32_t)
CREATE_BENCHMARK(float)
CREATE_BENCHMARK(int64_t)
CREATE_BENCHMARK(double)

using custom_int2 = custom_type<int, int>;
using custom_longlong_double = custom_type<long long, double>;

CREATE_BENCHMARK(custom_int2)
CREATE_BENCHMARK(custom_longlong_double)
#endif // BENCHMARK_CONFIG_TUNING

// Use manual timing
for(auto& b : benchmarks)
Expand Down
176 changes: 0 additions & 176 deletions benchmark/benchmark_device_find_first_of.hpp

This file was deleted.

30 changes: 30 additions & 0 deletions benchmark/benchmark_device_find_first_of.parallel.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// MIT License
//
// Copyright (c) 2024 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_find_first_of.parallel.hpp"
#include "benchmark_utils.hpp"

namespace
{
auto benchmarks = config_autotune_register::create_bulk(
device_find_first_of_benchmark_generator<@DataType@, @BlockSize@>::create);
} // namespace
Loading

0 comments on commit fd07e9e

Please sign in to comment.