Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few benchmarks #512

Merged
merged 2 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions onnxruntime/test/onnx/microbenchmark/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <core/graph/model.h>
#include <core/graph/graph.h>
#include <core/framework/kernel_def_builder.h>
#include <core/session/onnxruntime_c_api.h>
#include <unordered_map>

using namespace onnxruntime;
Expand Down Expand Up @@ -48,18 +49,24 @@ static void BM_ResolveGraph(benchmark::State& state) {
}

BENCHMARK(BM_ResolveGraph);
#define ORT_ABORT_ON_ERROR(expr) \
do { \
OrtStatus* onnx_status = (expr); \
if (onnx_status != NULL) { \
const char* msg = OrtGetErrorMessage(onnx_status); \
fprintf(stderr, "%s\n", msg); \
OrtReleaseStatus(onnx_status); \
abort(); \
} \
} while (0);

OrtEnv* env = nullptr;

int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return -1;
std::string default_logger_id{"Default"};
logging::LoggingManager default_logging_manager{std::unique_ptr<logging::ISink>{new logging::CLogSink{}},
logging::Severity::kWARNING, false,
logging::LoggingManager::InstanceType::Default,
&default_logger_id};

std::unique_ptr<Environment> env;
auto status = Environment::Create(env);
ORT_ABORT_ON_ERROR(OrtCreateEnv(ORT_LOGGING_LEVEL_WARNING, "test", &env));
::benchmark::RunSpecifiedBenchmarks();
OrtReleaseEnv(env);
return 0;
}
44 changes: 44 additions & 0 deletions onnxruntime/test/onnx/microbenchmark/modeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <benchmark/benchmark.h>
#include <core/graph/model.h>
#include <core/session/onnxruntime_c_api.h>
#include "providers.h"

static void BM_LoadModel(benchmark::State& state) {
for (auto _ : state) {
Expand All @@ -16,3 +18,45 @@ static void BM_LoadModel(benchmark::State& state) {
}

BENCHMARK(BM_LoadModel);

extern OrtEnv* env;

#define ORT_BREAK_ON_ERROR(expr) \
do { \
OrtStatus* onnx_status = (expr); \
if (onnx_status != NULL) { \
state.SkipWithError(OrtGetErrorMessage(onnx_status)); \
OrtReleaseStatus(onnx_status); \
} \
} while (0);

#ifdef USE_CUDA
static void BM_CreateSession_WithGPU(benchmark::State& state) {
const char* model_path = "../models/opset8/test_bvlc_alexnet/model.onnx";
OrtSessionOptions* session_option = OrtCreateSessionOptions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do session_options requires releasing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jignparm , I fixed it, could you please review it again?

ORT_BREAK_ON_ERROR(OrtSessionOptionsAppendExecutionProvider_CUDA(session_option, 0));
for (auto _ : state) {
OrtSession* session;
ORT_BREAK_ON_ERROR(OrtCreateSession(env, model_path, session_option, &session));
state.PauseTiming();
OrtReleaseSession(session);
state.ResumeTiming();
}
OrtReleaseSessionOptions(session_option);
}
BENCHMARK(BM_CreateSession_WithGPU);
#endif

static void BM_CreateSession(benchmark::State& state) {
const char* model_path = "../models/opset8/test_bvlc_alexnet/model.onnx";
OrtSessionOptions* session_option = OrtCreateSessionOptions();
for (auto _ : state) {
OrtSession* session;
ORT_BREAK_ON_ERROR(OrtCreateSession(env, model_path, session_option, &session));
state.PauseTiming();
OrtReleaseSession(session);
state.ResumeTiming();
}
OrtReleaseSessionOptions(session_option);
}
BENCHMARK(BM_CreateSession);