Skip to content

Commit 23cf4cd

Browse files
Vedant2005goyalvgvassilev
authored andcommitted
Added benchmark to compare tapenade and clad performance during disk offloading and the tapenade is fetched only at the build time
1 parent 9ed0b9e commit 23cf4cd

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

benchmark/CMakeLists.txt

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,37 @@ CB_ADD_GBENCHMARK(ArrayExpressionTemplates ArrayExpressionTemplates.cpp)
77
if (CLAD_ENABLE_ENZYME_BACKEND)
88
CB_ADD_GBENCHMARK(EnzymeCladComparison EnzymeCladComparison.cpp)
99
endif(CLAD_ENABLE_ENZYME_BACKEND)
10+
11+
include(FetchContent)
12+
FetchContent_Declare(
13+
tapenade_kit
14+
GIT_REPOSITORY https://gitlab.inria.fr/tapenade/tapenade.git
15+
16+
# We use a commit hash from the 'develop' branch because
17+
# the 'disk offloading' feature is not yet available in the stable release of tapenade.
18+
GIT_TAG 6f8cb04a4168cac5f6242cdeb65f6816c413f4ee
19+
20+
GIT_SHALLOW TRUE
21+
GIT_PROGRESS TRUE
22+
)
23+
FetchContent_MakeAvailable(tapenade_kit)
24+
25+
# Build the support library for the stack from the fetched source
26+
add_library(tapenade_support STATIC ${tapenade_kit_SOURCE_DIR}/ADFirstAidKit/adStack.c)
27+
target_include_directories(tapenade_support PUBLIC ${tapenade_kit_SOURCE_DIR}/ADFirstAidKit)
28+
29+
target_compile_definitions(tapenade_support PRIVATE
30+
ADSTACK_MAX_SPACES=1
31+
ADSTACK_BLOCK_SIZE=4194304
32+
)
33+
1034
CB_ADD_GBENCHMARK(VectorModeComparison VectorModeComparison.cpp)
11-
CB_ADD_GBENCHMARK(MemoryComplexity MemoryComplexity.cpp)
35+
CB_ADD_GBENCHMARK(MemoryComplexity_tapenade MemoryComplexity.cpp)
1236
CB_ADD_GBENCHMARK(Multithreading Multithreading.cpp)
13-
CB_ADD_GBENCHMARK(Hessians Hessians.cpp)
14-
15-
set (CLAD_BENCHMARK_DEPS clad)
16-
get_property(_benchmark_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
1737

18-
foreach (name ${_benchmark_names})
19-
get_test_property(${name} LABELS _labels)
20-
if (_labels MATCHES ".*benchmark.*")
21-
get_test_property(${name} DEPENDS _deps)
22-
list(APPEND CLAD_BENCHMARK_DEPS ${_deps})
23-
endif()
24-
endforeach()
38+
target_link_libraries(MemoryComplexity_tapenade PRIVATE tapenade_support)
2539

2640
add_custom_target(benchmark-clad COMMAND ${CMAKE_CTEST_COMMAND} -V
2741
DEPENDS ${CLAD_BENCHMARK_DEPS} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
2842

29-
set_target_properties(benchmark-clad PROPERTIES FOLDER "Clad benchmarks")
43+
set_target_properties(benchmark-clad PROPERTIES FOLDER "Clad benchmarks")

benchmark/MemoryComplexity.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include "clad/Differentiator/Tape.h"
55
#include <cstddef>
66
#include <cstdint>
7+
8+
extern "C" {
9+
void pushReal8(double x);
10+
void popReal8(double* x);
11+
}
712
namespace {
813
struct MemoryManager : public benchmark::MemoryManager {
914
size_t cur_num_allocs = 0;
@@ -185,4 +190,44 @@ static void BM_CrashTest_Clad_Offload(benchmark::State& state) {
185190
}
186191
BENCHMARK(BM_CrashTest_Clad_Offload)->Iterations(1);
187192

193+
// Tapenade Comparison Benchmarks
194+
struct Tapenade {
195+
void push(double val) { pushReal8(val); }
196+
void pop(double* val) { popReal8(val); }
197+
};
198+
struct CladDisk {
199+
clad::tape_impl<double, 64, 1024, /*is_multithread=*/false,
200+
/*DiskOffload=*/true>
201+
tape;
202+
203+
void push(double val) { tape.emplace_back(val); }
204+
void pop(double* val) {
205+
*val = tape.back();
206+
tape.pop_back();
207+
}
208+
};
209+
template <typename Strategy> static void BM_PushPop(benchmark::State& state) {
210+
int64_t n = state.range(0);
211+
Strategy s; // Instantiate the specific strategy (Clad or Tapenade)
212+
213+
for (auto _ : state) {
214+
for (int64_t i = 0; i < n; ++i)
215+
s.push(1.0);
216+
for (int64_t i = 0; i < n; ++i) {
217+
double val;
218+
s.pop(&val);
219+
benchmark::DoNotOptimize(val);
220+
}
221+
}
222+
}
223+
BENCHMARK_TEMPLATE(BM_PushPop, Tapenade)
224+
->RangeMultiplier(4)
225+
->Range(1024, 262144)
226+
->Name("BM_PushPop/TapenadeStack");
227+
228+
BENCHMARK_TEMPLATE(BM_PushPop, CladDisk)
229+
->RangeMultiplier(4)
230+
->Range(1024, 262144)
231+
->Name("BM_PushPop/CladDiskStack");
232+
188233
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)