Skip to content

Commit

Permalink
Port Atomic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Feb 8, 2023
1 parent 6ab2791 commit eb18f1d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 118 deletions.
11 changes: 5 additions & 6 deletions core/perf_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ IF(KOKKOS_ENABLE_TESTS)

KOKKOS_INCLUDE_DIRECTORIES(REQUIRED_DURING_INSTALLATION_TESTING ${CMAKE_CURRENT_SOURCE_DIR})

KOKKOS_ADD_EXECUTABLE_AND_TEST(
PerformanceTest_Atomic
SOURCES test_atomic.cpp
CATEGORIES PERFORMANCE
)

IF(NOT Kokkos_ENABLE_OPENMPTARGET)
# FIXME OPENMPTARGET needs tasking
KOKKOS_ADD_EXECUTABLE_AND_TEST(
Expand Down Expand Up @@ -193,3 +187,8 @@ IF(NOT KOKKOS_CXX_COMPILER_ID STREQUAL NVHPC)
SOURCES test_mempool.cpp
)
ENDIF()

KOKKOS_ADD_BENCHMARK(
PerformanceTest_Atomic
SOURCES test_atomic.cpp
)
6 changes: 0 additions & 6 deletions core/perf_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ TARGETS =

#

OBJ_ATOMICS = test_atomic.o
TARGETS += KokkosCore_PerformanceTest_Atomics
TEST_TARGETS += test-atomic

#

OBJ_TASKDAG = test_taskdag.o
TARGETS += KokkosCore_PerformanceTest_TaskDAG
TEST_TARGETS += test-taskdag
Expand Down
140 changes: 34 additions & 106 deletions core/perf_test/test_atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,14 @@
#include <cstring>
#include <cstdlib>

#include <benchmark/benchmark.h>
#include "Benchmark_Context.hpp"

#include <Kokkos_Core.hpp>
#include <Kokkos_Timer.hpp>

using exec_space = Kokkos::DefaultExecutionSpace;

#define RESET 0
#define BRIGHT 1
#define DIM 2
#define UNDERLINE 3
#define BLINK 4
#define REVERSE 7
#define HIDDEN 8

#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define GREY 7
#define WHITE 8

void textcolor(int attr, int fg, int bg) {
char command[40];

/* Command is the control command to the terminal */
snprintf(command, 40, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
printf("%s", command);
}
void textcolor_standard() { textcolor(RESET, BLACK, WHITE); }

template <class T, class DEVICE_TYPE>
struct ZeroFunctor {
using execution_space = DEVICE_TYPE;
Expand Down Expand Up @@ -370,7 +346,9 @@ T LoopVariantNonAtomic(int loop, int test) {
}

template <class T>
void Loop(int loop, int test, const char* type_name) {
void Loop(benchmark::State& state, int test) {
int loop = state.range(0);

LoopVariant<T>(loop, test);

Kokkos::Timer timer;
Expand All @@ -388,86 +366,36 @@ void Loop(int loop, int test, const char* type_name) {
time *= 1e6 / loop;
timeNonAtomic *= 1e6 / loop;
timeSerial *= 1e6 / loop;
// textcolor_standard();
bool passed = true;
if (resSerial != res) passed = false;
// if(!passed) textcolor(RESET,BLACK,YELLOW);
printf(
"%s Test %i %s --- Loop: %i Value (S,A,NA): %e %e %e Time: %7.4e %7.4e "
"%7.4e Size of Type %i)",
type_name, test, passed ? "PASSED" : "FAILED", loop, 1.0 * resSerial,
1.0 * res, 1.0 * resNonAtomic, timeSerial, time, timeNonAtomic,
(int)sizeof(T));
// if(!passed) textcolor_standard();
printf("\n");
}

template <class T>
void Test(int loop, int test, const char* type_name) {
if (test == -1) {
Loop<T>(loop, 1, type_name);
Loop<T>(loop, 2, type_name);
Loop<T>(loop, 3, type_name);

} else
Loop<T>(loop, test, type_name);
}
bool passed = (resSerial == res);

int main(int argc, char* argv[]) {
int type = -1;
int loop = 100000;
int test = -1;

for (int i = 0; i < argc; i++) {
if ((strcmp(argv[i], "--test") == 0)) {
test = std::stoi(argv[++i]);
continue;
}
if ((strcmp(argv[i], "--type") == 0)) {
type = std::stoi(argv[++i]);
continue;
}
if ((strcmp(argv[i], "-l") == 0) || (strcmp(argv[i], "--loop") == 0)) {
loop = std::stoi(argv[++i]);
continue;
}
}
state.counters["Passed"] = benchmark::Counter(passed);
state.counters["Value serial"] = benchmark::Counter(resSerial);
state.counters["Value atomic"] = benchmark::Counter(res);
state.counters["Value non-atomic"] = benchmark::Counter(resNonAtomic);
state.counters["Time serial"] = benchmark::Counter(timeSerial);
state.counters["Time atomic"] = benchmark::Counter(time);
state.counters["Time non-atomic"] = benchmark::Counter(timeNonAtomic);
state.counters["Size of type"] = benchmark::Counter(sizeof(T));
}

Kokkos::initialize(argc, argv);

printf("Using %s\n", Kokkos::atomic_query_version());
bool all_tests = false;
if (type == -1) all_tests = true;
while (type < 100) {
if (type == 1) {
Test<int>(loop, test, "int ");
}
if (type == 2) {
Test<long int>(loop, test, "long int ");
}
if (type == 3) {
Test<long long int>(loop, test, "long long int ");
}
if (type == 4) {
Test<unsigned int>(loop, test, "unsigned int ");
}
if (type == 5) {
Test<unsigned long int>(loop, test, "unsigned long int ");
}
if (type == 6) {
Test<unsigned long long int>(loop, test, "unsigned long long int ");
}
if (type == 10) {
// Test<float>(loop,test,"float ");
}
if (type == 11) {
Test<double>(loop, test, "double ");
}
if (!all_tests)
type = 100;
else
type++;
template <class T>
static void Test_Atomic(benchmark::State& state) {
for (auto _ : state) {
Loop<T>(state, 1);
Loop<T>(state, 2);
Loop<T>(state, 3);
}

Kokkos::finalize();
}

static constexpr int LOOP = 100'000;

BENCHMARK(Test_Atomic<int>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<long int>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<long long int>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<unsigned int>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<unsigned long int>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<unsigned long long int>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<float>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<double>)->Arg(LOOP)->Iterations(10);
BENCHMARK(Test_Atomic<int>)->Arg(LOOP)->Iterations(10);

0 comments on commit eb18f1d

Please sign in to comment.