Skip to content

Commit edbc8b4

Browse files
committed
Automated SOFIEInference, removed profiler inference
1 parent c8e3635 commit edbc8b4

File tree

9 files changed

+89
-910
lines changed

9 files changed

+89
-910
lines changed

root/tmva/sofie/CMakeLists.txt

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ if(ROOT_tmva_FOUND AND ROOT_tmva-sofie_FOUND)
2626
set(CAPTURE_STR "BENCHMARK_CAPTURE(${FUNC_NAME}, @1,\t@2)@3")
2727
set(HEAD_COMMENT "Automatically configured by CMake")
2828
set(ALL_CAPTURES "")
29-
set(ONNX_MODEL_NAMES "")
3029
foreach(model ${ONNX_MODELS})
3130
get_filename_component(fname ${model} NAME)
3231
get_filename_component(fname_we ${model} NAME_WE)
@@ -46,27 +45,55 @@ if(ROOT_tmva_FOUND AND ROOT_tmva-sofie_FOUND)
4645
target_link_directories(ONNXRuntimeInference PRIVATE ${ONNXRuntime_LIBRARIES})
4746
target_include_directories(ONNXRuntimeInference PRIVATE ${ONNXRuntime_INCLUDE_DIR})
4847

48+
else()
49+
message(WARNING "ONNXRuntime not found")
4950
endif()
5051

51-
# Checking the SOFIE compiler
52-
if(NOT EXISTS ${ROOTSYS}/tmva/sofie/test/emitFromONNX)
53-
message(FATAL_ERROR "SOFIE compiler not found")
54-
endif()
52+
# Configuring SOFIEInference_Template.cxx.in
53+
set(FUNC_NAME "BM_SOFIE_Inference")
54+
set(CAPTURE_STR "BENCHMARK_CAPTURE(${FUNC_NAME}, @1,\t@2)@3")
55+
set(INCLUDES_STR "#include @1")
56+
set(FUNCS_STR "\t\t{ @1,\t{@2,\t@3} }")
57+
set(HEAD_COMMENT "Automatically configured by CMake")
58+
set(ALL_CAPTURES "")
59+
set(ALL_INCLUDES "")
60+
set(ALL_FUNCS "")
61+
set(COMPILED_MODELS_DIR ${ONNX_MODELS_DIR}/compiled)
62+
file(GLOB COMPILED_MODELS "${COMPILED_MODELS_DIR}/*.hxx")
63+
set(inc "")
64+
set(cap "")
65+
set(funcs "")
66+
foreach(model ${COMPILED_MODELS})
67+
get_filename_component(fname ${model} NAME)
68+
get_filename_component(fname_we ${model} NAME_WE)
69+
# Fixing the string for the include headers
70+
string(REPLACE "@1" "\"${COMPILED_MODELS_DIR}/${fname}\"" inc ${INCLUDES_STR})
71+
list(APPEND ALL_INCLUDES ${inc})
72+
# Fixing the string for the GBenchmark captures
73+
string(REPLACE "@1" ${fname_we} cap ${CAPTURE_STR})
74+
string(REPLACE "@2" "\"${fname_we}\"" cap ${cap})
75+
list(APPEND ALL_CAPTURES ${cap})
76+
# Fixing the string for the actual infer function that each capture will call
77+
string(REPLACE "@1" "\"${fname_we}\"" funcs ${FUNCS_STR})
78+
string(REPLACE "@2" "TMVA_SOFIE_${fname_we}::infer" funcs ${funcs})
79+
string(REPLACE "@3" "0" funcs ${funcs})
80+
list(APPEND ALL_FUNCS ${funcs})
81+
endforeach()
5582

83+
# Transforming list of strings into a single multi-line string
84+
string(REPLACE ";" "\n" BENCHMARK_CAPTURES "${ALL_CAPTURES}") # String[] -> String
85+
string(REPLACE "@3" ";" BENCHMARK_CAPTURES "${BENCHMARK_CAPTURES}") # Adding semicolon
86+
string(REPLACE ";" "\n" INCLUDE_HEADERS "${ALL_INCLUDES}") # String[] -> String
87+
string(REPLACE ";" ",\n" FUNC_TUPLES "${ALL_FUNCS}") # String[] -> String
88+
configure_file(SOFIEInference_Template.cxx.in SOFIEInference.cxx @ONLY)
89+
5690
# Benchmark for models emitted by SOFIE
5791
RB_ADD_GBENCHMARK(SOFIEInference
5892
SOFIEInference.cxx
5993
LABEL short
60-
LIBRARIES TMVA blas
94+
LIBRARIES TMVA openblas
6195
)
96+
target_include_directories(SOFIEInference PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
6297

63-
# Benchmark for models emitted by SOFIE (with RModelProfiler)
64-
# This should be useful in measuring profiler's overhead
65-
RB_ADD_GBENCHMARK(SOFIEInferenceProfiler
66-
SOFIEInferenceProfiler.cxx
67-
LABEL short
68-
LIBRARIES TMVA blas
69-
)
70-
7198
endif()
7299

root/tmva/sofie/SOFIEInference.cxx

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @HEAD_COMMENT@
2+
// Author: Federico Sossai (fsossai), 2021
3+
4+
#include <benchmark/benchmark.h>
5+
6+
#include <iostream>
7+
#include <vector>
8+
#include <functional>
9+
#include <unordered_map>
10+
11+
@INCLUDE_HEADERS@
12+
13+
using namespace std;
14+
15+
static void @FUNC_NAME@(benchmark::State& state, std::string model_name)
16+
{
17+
vector<float> input;
18+
19+
typedef function<vector<float>(float*)> infer_t;
20+
unordered_map<string, pair<infer_t, size_t>> all_infer_funcs{
21+
@FUNC_TUPLES@
22+
};
23+
24+
infer_t infer_func;
25+
size_t input_size;
26+
tie(infer_func, input_size) = all_infer_funcs[model_name];
27+
//input.resize(input_size);
28+
input.resize(10'000); // temporary remedy
29+
30+
for (auto _ : state) {
31+
infer_func(input.data());
32+
}
33+
}
34+
@BENCHMARK_CAPTURES@
35+
36+
BENCHMARK_MAIN();

root/tmva/sofie/input_models/compiled/Linear_16.hxx

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

root/tmva/sofie/input_models/compiled/Linear_16_prof.hxx

Lines changed: 0 additions & 280 deletions
This file was deleted.

root/tmva/sofie/input_models/compiled/Linear_32.hxx

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

root/tmva/sofie/input_models/compiled/Linear_32_prof.hxx

Lines changed: 0 additions & 280 deletions
This file was deleted.

root/tmva/sofie/input_models/compiled/Linear_64.hxx

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

root/tmva/sofie/input_models/compiled/Linear_64_prof.hxx

Lines changed: 0 additions & 280 deletions
This file was deleted.

0 commit comments

Comments
 (0)