diff --git a/onnxruntime/test/onnx/microbenchmark/activation.cc b/onnxruntime/test/onnx/microbenchmark/activation.cc index bdec5a6310..f38cee6e98 100644 --- a/onnxruntime/test/onnx/microbenchmark/activation.cc +++ b/onnxruntime/test/onnx/microbenchmark/activation.cc @@ -1,5 +1,6 @@ #include "common.h" +#include "core/common/status.h" #include "core/session/ort_env.h" #include "core/graph/model.h" #include "core/graph/graph.h" @@ -15,6 +16,7 @@ #include #include +using namespace onnxruntime::common; using namespace onnxruntime; using namespace onnx; extern OrtEnv* env; @@ -380,7 +382,7 @@ static void BM_Powx(benchmark::State& state) { f.input2 = input2; f.output = output; for (auto _ : state) { - tp->ParallelFor(batch_size, TensorOpCost{2, 1, static_cast(cost)}, f); + concurrency::ThreadPool::TryParallelFor(tp.get(), batch_size, TensorOpCost{2, 1, static_cast(cost)}, f); } aligned_free(input1); aligned_free(input2); diff --git a/onnxruntime/test/onnx/microbenchmark/batchnorm.cc b/onnxruntime/test/onnx/microbenchmark/batchnorm.cc index 89df35a5e7..516664147d 100644 --- a/onnxruntime/test/onnx/microbenchmark/batchnorm.cc +++ b/onnxruntime/test/onnx/microbenchmark/batchnorm.cc @@ -1,8 +1,18 @@ #include "core/platform/threadpool.h" -#include "core/common/eigen_common_wrapper.h" #include "core/util/thread_utils.h" #include +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + +#include "core/common/eigen_common_wrapper.h" + +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + using namespace onnxruntime; #if 0 static void BM_BatchNormEigenTensor(benchmark::State& state) { @@ -99,4 +109,4 @@ BENCHMARK(BM_BatchNormEigenTensorSingleThread) ->Arg(16) ->Arg(64) ->UseRealTime() - ->Unit(benchmark::TimeUnit::kMicrosecond); \ No newline at end of file + ->Unit(benchmark::TimeUnit::kMicrosecond); diff --git a/onnxruntime/test/onnx/microbenchmark/eigen.cc b/onnxruntime/test/onnx/microbenchmark/eigen.cc index 206786dca5..26e8d773d8 100644 --- a/onnxruntime/test/onnx/microbenchmark/eigen.cc +++ b/onnxruntime/test/onnx/microbenchmark/eigen.cc @@ -4,6 +4,7 @@ #pragma GCC diagnostic ignored "-Wignored-attributes" #endif #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #elif defined(_MSC_VER) #pragma warning(push) #pragma warning(disable : 4267) diff --git a/onnxruntime/test/onnx/microbenchmark/gelu.cc b/onnxruntime/test/onnx/microbenchmark/gelu.cc index 23f9af6e9a..f2f39e429e 100644 --- a/onnxruntime/test/onnx/microbenchmark/gelu.cc +++ b/onnxruntime/test/onnx/microbenchmark/gelu.cc @@ -9,6 +9,7 @@ #include using namespace onnxruntime; +using namespace onnxruntime::concurrency; //naive implementation of Gelu static void BM_GeluSingleThreadPlainLoop(benchmark::State& state) { @@ -72,7 +73,7 @@ static void BM_GeluParallelFor(benchmark::State& state) { std::unique_ptr tp( concurrency::CreateThreadPool(&onnxruntime::Env::Default(), tpo, concurrency::ThreadPoolType::INTRA_OP)); for (auto _ : state) { - tp->ParallelFor(batch_size, cost, [data, output](ptrdiff_t first, ptrdiff_t last) { + ThreadPool::TryParallelFor(tp.get(), batch_size, cost, [data, output](ptrdiff_t first, ptrdiff_t last) { ptrdiff_t len = last - first; float* output_ptr = output + first; onnxruntime::ConstEigenVectorArrayMap xm(data + first, len); @@ -138,7 +139,8 @@ static void BM_ScaledTanhParallelFor(benchmark::State& state) { const float alpha_ = 0.3f; const float beta_ = 0.6f; for (auto _ : state) { - tp->ParallelFor(batch_size, cost, [alpha_, beta_, data, output](ptrdiff_t first, ptrdiff_t last) { + ThreadPool::TryParallelFor(tp.get(), batch_size, cost, + [alpha_, beta_, data, output](ptrdiff_t first, ptrdiff_t last) { ptrdiff_t len = last - first; float* output_ptr = output + first; onnxruntime::ConstEigenVectorArrayMap xm(data + first, len); @@ -207,7 +209,7 @@ static void BM_GeluBatchParallelFor(benchmark::State& state) { concurrency::CreateThreadPool(&onnxruntime::Env::Default(), tpo, concurrency::ThreadPoolType::INTRA_OP)); const int num_batches = 4; for (auto _ : state) { - tp->SimpleParallelFor(num_batches, [&](std::ptrdiff_t batch_index) { + ThreadPool::TrySimpleParallelFor(tp.get(), num_batches, [&](std::ptrdiff_t batch_index) { std::ptrdiff_t start, work_remaining; TestPartitionWork(batch_index, num_batches, batch_size, &start, &work_remaining); float* output_ptr = output + start; @@ -327,4 +329,4 @@ BENCHMARK(BM_GeluBatchParallelFor3) ->Arg(20000) ->Arg(40000) ->Arg(98304) - ->Arg(1572864); \ No newline at end of file + ->Arg(1572864); diff --git a/onnxruntime/test/onnx/microbenchmark/main.cc b/onnxruntime/test/onnx/microbenchmark/main.cc index 0a38dc89f4..70faa6f119 100644 --- a/onnxruntime/test/onnx/microbenchmark/main.cc +++ b/onnxruntime/test/onnx/microbenchmark/main.cc @@ -18,6 +18,7 @@ #include #include +#include #include const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION); @@ -43,7 +44,7 @@ static void BM_ResolveGraph(benchmark::State& state) { auto st = onnxruntime::Model::Load(ORT_TSTR("../models/opset8/test_tiny_yolov2/model.onnx"), model_copy, nullptr, *logger); if (!st.IsOK()) { - printf("Parse model failed: %s", st.ErrorMessage().c_str()); + ::std::cerr << "Parse model failed: " << st.ErrorMessage().c_str() << ::std::endl; abort(); } auto proto = model_copy->ToProto(); @@ -55,7 +56,7 @@ static void BM_ResolveGraph(benchmark::State& state) { state.ResumeTiming(); st = graph.Resolve(); if (!st.IsOK()) { - printf("Resolve graph failed: %s", st.ErrorMessage().c_str()); + ::std::cerr << "Resolve graph failed: " << st.ErrorMessage().c_str() << ::std::endl; abort(); } } @@ -67,7 +68,7 @@ BENCHMARK(BM_ResolveGraph); OrtStatus* onnx_status = (expr); \ if (onnx_status != NULL) { \ const char* msg = g_ort->GetErrorMessage(onnx_status); \ - fprintf(stderr, "%s\n", msg); \ + ::std::cerr << msg << ::std::endl; \ g_ort->ReleaseStatus(onnx_status); \ abort(); \ } \ diff --git a/onnxruntime/test/onnx/microbenchmark/tptest.cc b/onnxruntime/test/onnx/microbenchmark/tptest.cc index 21c1c7d999..b23d384437 100644 --- a/onnxruntime/test/onnx/microbenchmark/tptest.cc +++ b/onnxruntime/test/onnx/microbenchmark/tptest.cc @@ -10,9 +10,17 @@ using namespace onnxruntime; using namespace onnxruntime::concurrency; +// Thread pool configuration to test. +constexpr int NUM_THREADS = 8; +constexpr bool ALLOW_SPINNING = true; + static void BM_CreateThreadPool(benchmark::State& state) { for (auto _ : state) { - ThreadPool tp(&onnxruntime::Env::Default(), onnxruntime::ThreadOptions(), ORT_TSTR(""), 48, true); + ThreadPool tp(&onnxruntime::Env::Default(), + onnxruntime::ThreadOptions(), + ORT_TSTR(""), + NUM_THREADS, + ALLOW_SPINNING); } } BENCHMARK(BM_CreateThreadPool) @@ -42,10 +50,12 @@ static void BM_ThreadPoolParallelFor(benchmark::State& state) { const size_t len = state.range(0); const int cost = static_cast(state.range(1)); OrtThreadPoolParams tpo; - std::unique_ptr tp( - concurrency::CreateThreadPool(&onnxruntime::Env::Default(), tpo, ThreadPoolType::INTRA_OP)); + auto tp = onnxruntime::make_unique(&onnxruntime::Env::Default(), + onnxruntime::ThreadOptions(), + nullptr, + NUM_THREADS, ALLOW_SPINNING); for (auto _ : state) { - tp->ParallelFor(len, cost, SimpleForLoop); + ThreadPool::TryParallelFor(tp.get(), len, cost, SimpleForLoop); } } BENCHMARK(BM_ThreadPoolParallelFor) @@ -115,7 +125,7 @@ static void BM_SimpleScheduleWait(benchmark::State& state) { for (auto _ : state) { onnxruntime::Barrier barrier(static_cast(threads)); for (std::ptrdiff_t id = 0; id < threads; ++id) { - tp->Schedule([id, threads, len, &barrier]() { + ThreadPool::Schedule(tp.get(), [id, threads, len, &barrier]() { std::ptrdiff_t start, work_remaining; TestPartitionWork(id, threads, len, &start, &work_remaining); SimpleForLoop(start, start + work_remaining);