Skip to content

Commit

Permalink
[tmva][sofie] Apply fixes for new SOFIE in 6.32
Browse files Browse the repository at this point in the history
Do not use empty path when creating Session classes

Improve tests by adding possibility to pass location of input files
  • Loading branch information
lmoneta committed Jun 11, 2024
1 parent 0f948b0 commit 2c342a8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
4 changes: 2 additions & 2 deletions root/tmva/sofie/EmitFromONNX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ int main(int argc, char *argv[]){
RModelParser_ONNX parser;
std::cout << "Parsing file " << argv[1] << std::endl;
RModel model = parser.Parse(argv[1]);
model.Generate();
model.Generate(Options::kDefault, 1);
model.PrintRequiredInputTensors();
model.OutputGenerated(outname);

return 0;
}
28 changes: 27 additions & 1 deletion root/tmva/sofie/ONNXRuntimeInference_Template.cxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <random>
#include <chrono>
#include <fstream>
#include <filesystem>

using namespace std;

Expand Down Expand Up @@ -168,4 +169,29 @@ static void @FUNC_NAME@(benchmark::State& state, string model_path)
}
@BENCHMARK_CAPTURES@

BENCHMARK_MAIN();
//BENCHMARK_MAIN();

// define main to pass some convenient command line parameters
int main(int argc, char **argv) {

// Parse command line arguments
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg == "-v") {
//std::cout << "---running in verbose mode" << std::endl;
//verbose = true;
} else if ((arg == "-d" || arg == "--dir") && argc > i+1) {
std::string pathDir = argv[i+1];
std::filesystem::path path(pathDir);
std::filesystem::current_path(path);
i++;
}
}

std::cout << "running benchmark from current directory " << std::filesystem::current_path() << std::endl;

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();

return 0;
}
34 changes: 31 additions & 3 deletions root/tmva/sofie/SOFIEInference.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <memory>
#include <functional>
#include <random>
#include <filesystem>

#include "Linear_event.hxx"
#include "Linear_16.hxx"
Expand Down Expand Up @@ -60,7 +61,8 @@ void BM_SOFIE_Inference(benchmark::State &state)
std::generate(input.begin(), input.end(), []() { return distribution(generator); });
}
float *input_ptr = input.data();
S s("");
// construct session (no need to pass filename, use default value)
S s;

double totDuration = 0;
int ntimes = 0;
Expand Down Expand Up @@ -143,7 +145,8 @@ void BM_SOFIE_Inference_3(benchmark::State &state)
input3 = vector<float>(input3.size(),3.);
}

S s("");
// create session with default filename
S s{};

//std::cout << "init done - do benchmark \n";

Expand Down Expand Up @@ -199,5 +202,30 @@ BENCHMARK_TEMPLATE(BM_SOFIE_Inference, TMVA_SOFIE_RNN_d10_L20_h8_B1::Session)->N
BENCHMARK_TEMPLATE(BM_SOFIE_Inference, TMVA_SOFIE_GRU_d10_L20_h8_B1::Session)->Name("GRU_d10_L20_h8_B1")->Args({3 * 5, 1})->Unit(benchmark::kMillisecond);
BENCHMARK_TEMPLATE(BM_SOFIE_Inference, TMVA_SOFIE_LSTM_d10_L20_h8_B1::Session)->Name("LSTM_d10_L20_h8_B1")->Args({1 * 1, 1})->Unit(benchmark::kMillisecond);

// default main
//BENCHMARK_MAIN();

// define main to pass some convenient command line parameters
int main(int argc, char **argv) {

// Parse command line arguments
for (Int_t i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg == "-v") {
std::cout << "---running in verbose mode" << std::endl;
verbose = true;
} else if ((arg == "-d" || arg == "--dir") && argc > i+1) {
std::string pathDir = argv[i+1];
std::filesystem::path path(pathDir);
std::filesystem::current_path(path);
i++;
}
}

std::cout << "running benchmark from current directory " << std::filesystem::current_path() << std::endl;

BENCHMARK_MAIN();
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();

return 0;
}

0 comments on commit 2c342a8

Please sign in to comment.