Skip to content

Commit

Permalink
add hooks for debugging; reduce optimizations for one model that requ…
Browse files Browse the repository at this point in the history
…ires it on gpu
  • Loading branch information
davidlange6 committed Sep 15, 2022
1 parent defc129 commit 28bcc71
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions PhysicsTools/ONNXRuntime/interface/ONNXSessionOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace cms::Ort {
// cpu -> Use CPU backend
// cuda -> Use cuda backend
// default -> Use best available
inline ::Ort::SessionOptions getSessionOptions(const std::string &param_backend ) {
inline ::Ort::SessionOptions getSessionOptions(const std::string &param_backend) {

auto backend = cms::Ort::Backend::cpu;
if ( param_backend == "cuda" )
backend = cms::Ort::Backend::cuda;
Expand All @@ -26,6 +26,7 @@ namespace cms::Ort {
backend = cms::Ort::Backend::cuda;
}
}

return ONNXRuntime::defaultSessionOptions(backend);
}
}
Expand Down
10 changes: 9 additions & 1 deletion PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
#include <memory>
#include <numeric>


namespace cms::Ort {

using namespace ::Ort;

#ifdef ONNXDebug
const Env ONNXRuntime::env_(ORT_LOGGING_LEVEL_INFO, "");
#else
const Env ONNXRuntime::env_(ORT_LOGGING_LEVEL_ERROR, "");
#endif

ONNXRuntime::ONNXRuntime(const std::string& model_path, const SessionOptions* session_options) {
// create session
Expand Down Expand Up @@ -80,10 +85,12 @@ namespace cms::Ort {
SessionOptions sess_opts;
sess_opts.SetIntraOpNumThreads(1);
if (backend == Backend::cuda) {
// https://www.onnxruntime.ai/docs/reference/execution-providers/CUDA-ExecutionProvider.html
OrtCUDAProviderOptions options;
sess_opts.AppendExecutionProvider_CUDA(options);
}
#ifdef ONNX_PROFILE
sess_opts.EnableProfiling("ONNXProf");
#endif
return sess_opts;
}

Expand Down Expand Up @@ -140,6 +147,7 @@ namespace cms::Ort {
}

// run

auto output_tensors = session_->Run(RunOptions{nullptr},
input_node_names_.data(),
input_tensors.data(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ void BoostedJetONNXJetTagsProducer::fillDescriptions(edm::ConfigurationDescripti
}

std::unique_ptr<ONNXRuntime> BoostedJetONNXJetTagsProducer::initializeGlobalCache(const edm::ParameterSet &iConfig) {
auto session_options = cms::Ort::getSessionOptions(iConfig.getParameter<std::string>("onnx_backend"));
std::string backend= iConfig.getParameter<std::string>("onnx_backend");

auto session_options = cms::Ort::getSessionOptions(backend);
// Sept 8, 2022 - on gpu, this model crashes with all optimizations on
if ( backend != "cpu" )
session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_BASIC);
return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath(),&session_options);
}

Expand Down

0 comments on commit 28bcc71

Please sign in to comment.