Skip to content

Commit 7a4babb

Browse files
committed
benches ready to be done
1 parent b78b11c commit 7a4babb

6 files changed

Lines changed: 67 additions & 15 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ RUN apt-get update && \
1212
build-essential \
1313
cmake \
1414
gdb \
15+
libpapi-dev papi-tools \
1516
gfortran && \
1617
rm -rf /var/lib/apt/lists/*
1718

benches/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
find_library(PAPI_LIB papi)
2+
3+
if(NOT PAPI_LIB)
4+
message(WARNING "⚠️ PAPI library not found, benchmarks will be skipped")
5+
return()
6+
endif()
7+
18
FetchContent_Declare(
29
nanobench
310
GIT_REPOSITORY https://github.com/martinus/nanobench.git
411
GIT_TAG v4.1.0
512
GIT_SHALLOW TRUE
613
)
714

8-
915
FetchContent_MakeAvailable(nanobench)
1016

1117
add_library(bench_options bench_options.c)
1218

1319
add_library(bench_wrapper bench_wrapper.cpp)
14-
target_link_libraries(bench_wrapper PUBLIC bench_options PRIVATE nanobench)
20+
target_link_libraries(bench_wrapper PUBLIC bench_options PRIVATE nanobench ${PAPI_LIB})
1521

1622
foreach(bench_name
1723
bench_transform_states

benches/bench_wrapper.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#include "nanobench.h"
1+
#include <iostream>
2+
#include <papi.h>
23
#include "bench_options.h"
4+
#include "nanobench.h"
35

46
extern "C" void run_benchmark(BenchOptions *options)
57
{
@@ -8,10 +10,45 @@ extern "C" void run_benchmark(BenchOptions *options)
810
b.title(options->name)
911
.warmup(options->warmup)
1012
.epochs(options->epochs)
11-
.relative(options->num_functions > 1);
13+
.relative(options->num_functions > 1)
14+
.minEpochIterations(30);
15+
16+
if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
17+
{
18+
std::cerr << "Error inicializando PAPI\n";
19+
}
1220

1321
for (int i = 0; i < options->num_functions; ++i)
1422
{
23+
#define EVENTS_LEN 4
24+
int EventSet = PAPI_NULL;
25+
long long values[EVENTS_LEN] = {0};
26+
27+
PAPI_create_eventset(&EventSet);
28+
PAPI_add_named_event(EventSet, "MEM_LOAD_RETIRED:L1_HIT");
29+
PAPI_add_named_event(EventSet, "MEM_LOAD_RETIRED:L1_MISS");
30+
PAPI_add_named_event(EventSet, "MEM_LOAD_RETIRED:L2_HIT");
31+
PAPI_add_named_event(EventSet, "MEM_LOAD_RETIRED:L2_MISS");
32+
33+
if (PAPI_start(EventSet) != PAPI_OK)
34+
{
35+
std::cerr << "Error starting counters PAPI\n";
36+
}
37+
1538
b.run([&] { ((void (*)(void)) options->functions[i])(); });
39+
40+
if (PAPI_stop(EventSet, values) != PAPI_OK)
41+
{
42+
std::cerr << "Error stopping counters PAPI\n";
43+
}
44+
45+
PAPI_cleanup_eventset(EventSet);
46+
PAPI_destroy_eventset(&EventSet);
47+
48+
std::cout << "#### Cache analysis for " << options->name << " ###\n"
49+
<< "L1 cache misses: " << values[0] << ", L2 cache misses: " << values[1] << "\n"
50+
<< "L1 cache hits: " << values[2] << ", L2 cache hits: " << values[3] << "\n";
1651
}
52+
53+
PAPI_shutdown();
1754
}

scripts/bench.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if [ ! -d ./build-serial/benches ]; then
55
exit 1
66
fi
77

8+
bash scripts/init_venv.sh
9+
810
ISOLATED_CPUS_LIST="0-11"
911

1012
(

scripts/init_venv.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
if [ -d ".venv" ]; then
4+
exit 0
5+
fi
6+
7+
if ! python3 -m venv .venv; then
8+
echo "Error creating python virtual environment. Install python3-venv."
9+
exit 1
10+
fi
11+
12+
source .venv/bin/activate
13+
pip install --upgrade pip
14+
pip install matplotlib
15+
pip install pyperf

scripts/test.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,10 @@ execute_variant() {
4747
)
4848
fi
4949

50-
# .venv/bin/python plot.py "$CLI_TEST_DIR/data/output/cuqdyn-results.txt"
50+
.venv/bin/python plot.py "$CLI_TEST_DIR/data/output/cuqdyn-results.txt"
5151
}
5252

53-
# if [ ! -d ".venv" ]; then
54-
# if ! python3 -m venv .venv; then
55-
# echo "Error creating python virtual environment. Install python3-venv."
56-
# exit 1
57-
# fi
58-
# source .venv/bin/activate
59-
# pip install --upgrade pip
60-
# fi
61-
#
62-
# pip install matplotlib
53+
bash scripts/init_venv.sh
6354

6455
variants=(
6556
"serial"

0 commit comments

Comments
 (0)