diff --git a/onnxruntime/core/framework/tunable.h b/onnxruntime/core/framework/tunable.h index 410dd9442c..21ab195b61 100644 --- a/onnxruntime/core/framework/tunable.h +++ b/onnxruntime/core/framework/tunable.h @@ -145,14 +145,14 @@ class TunableOp { private: static void WarmUp(Op& op, const ParamsT* param) { - const int num_iter = 4; + constexpr const int num_iter = 4; for (int i = 0; i < num_iter; i++) { ORT_THROW_IF_ERROR(op(param)); } } static double Profile(Op& op, const ParamsT* param) { - const int num_iter = 100; + constexpr const int num_iter = 100; TimerT timer{param->Stream()}; timer.Start(); for (int i = 0; i < num_iter; i++) { diff --git a/onnxruntime/test/framework/tunable_op_test.cc b/onnxruntime/test/framework/tunable_op_test.cc index f6512bcf03..8869e4ffbd 100644 --- a/onnxruntime/test/framework/tunable_op_test.cc +++ b/onnxruntime/test/framework/tunable_op_test.cc @@ -3,24 +3,11 @@ #include #include -#ifdef _WIN32 -#include -#endif #include #include "core/common/common.h" #include "core/framework/tunable.h" -#ifdef _WIN32 -#pragma comment(lib, "WinMM.lib") -#endif - -#ifdef ORT_NO_RTTI -#define GTEST_SKIP_IF_NO_RTTI() GTEST_SKIP() << "TunableOp needs RTTI to work correctly"; -#else -#define GTEST_SKIP_IF_NO_RTTI() -#endif - using namespace std::chrono_literals; namespace onnxruntime { @@ -64,20 +51,6 @@ using Op = ::onnxruntime::tunable::Op; template using TunableOp = ::onnxruntime::tunable::TunableOp; -struct SleepTimeResolutionGuard { - SleepTimeResolutionGuard() { -#ifdef _WIN32 - timeBeginPeriod(1); -#endif - } - - ~SleepTimeResolutionGuard() { -#ifdef _WIN32 - timeEndPeriod(1); -#endif - } -}; - } // namespace struct VecAddParams : ::onnxruntime::tunable::OpParams { @@ -115,8 +88,8 @@ Status VecAddFunc(const VecAddParams* params) { namespace wrapper { TEST(TunableOp, OpWrapsFunction) { - const int a = 7500000; - const int b = 42; + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParams params(&a, &b, &c, 1, 0); @@ -150,8 +123,8 @@ TEST(TunableOp, OpWrapsLambda) { } TEST(TunableOp, OpWrapsMoveOnlyLambda) { - const int a = 7500000; - const int b = 42; + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParams params(&a, &b, &c, 1, 0); @@ -175,8 +148,8 @@ class VecAddConstFunctor { }; TEST(TunableOp, OpWrapsConstFunctor) { - const int a = 7500000; - const int b = 42; + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParams params(&a, &b, &c, 1, 0); @@ -196,8 +169,8 @@ class VecAddMutableFunctor { }; TEST(TunableOp, OpWrapsMutableFunctor) { - const int a = 7500000; - const int b = 42; + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParams params(&a, &b, &c, 1, 0); @@ -220,8 +193,8 @@ class VecAddMoveOnlyFunctor { }; TEST(TunableOp, OpWrapsMoveOnlyFunctor) { - const int a = 7500000; - const int b = 42; + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParams params(&a, &b, &c, 1, 0); @@ -244,17 +217,18 @@ struct VecAddParamsRecordLastRun : public VecAddParams { Status SlowFull(const VecAddParamsRecordLastRun* params) { *(params->last_run) = "SlowFull"; - LaunchVecAddKernel(params->a, params->b, params->c, params->num_elem, params->beta); - SleepTimeResolutionGuard guard{}; + for (int i = 0; i < 1000000; i++) { + LaunchVecAddKernel(params->a, params->b, params->c, params->num_elem, params->beta); + } std::this_thread::sleep_for(5ms); return Status::OK(); } Status FastFull(const VecAddParamsRecordLastRun* params) { *(params->last_run) = "FastFull"; - LaunchVecAddKernel(params->a, params->b, params->c, params->num_elem, params->beta); - SleepTimeResolutionGuard guard{}; - std::this_thread::sleep_for(1ms); + for (int i = 0; i < 3000; i++) { + LaunchVecAddKernel(params->a, params->b, params->c, params->num_elem, params->beta); + } return Status::OK(); } @@ -274,10 +248,11 @@ class TunableVecAddSelectFast : public TunableOp { }; TEST(TunableOp, SelectFast) { - GTEST_SKIP_IF_NO_RTTI(); - - const int a = 7500000; - const int b = 42; +#ifdef ORT_NO_RTTI + GTEST_SKIP() << "TunableOp needs RTTI to work correctly"; +#else + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParamsRecordLastRun params(&a, &b, &c, 1, 0); std::string last_run; @@ -289,6 +264,7 @@ TEST(TunableOp, SelectFast) { auto status = op(¶ms); ASSERT_TRUE(status.IsOK()); ASSERT_EQ(last_run, "FastFull"); +#endif } class TunableVecAddSelectSupported : public TunableOp { @@ -300,10 +276,11 @@ class TunableVecAddSelectSupported : public TunableOp }; TEST(TunableOp, SelectSupported) { - GTEST_SKIP_IF_NO_RTTI(); - - const int a = 7500000; - const int b = 42; +#ifdef ORT_NO_RTTI + GTEST_SKIP() << "TunableOp needs RTTI to work correctly"; +#else + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParamsRecordLastRun params(&a, &b, &c, 1, 0); std::string last_run; @@ -315,6 +292,7 @@ TEST(TunableOp, SelectSupported) { auto status = op(¶ms); ASSERT_TRUE(status.IsOK()); ASSERT_EQ(last_run, "SlowFull"); +#endif } class TunableVecAddSelectFastestIfSupported : public TunableOp { @@ -329,10 +307,11 @@ class TunableVecAddSelectFastestIfSupported : public TunableOp { @@ -378,6 +360,7 @@ class TunableVecAddNotHandleInplaceUpdate : public TunableOp { } }; +#ifndef ORT_NO_RTTI class TunableVecAddHandleInplaceUpdate : public TunableOp { public: TunableVecAddHandleInplaceUpdate() { @@ -404,12 +387,14 @@ class TunableVecAddHandleInplaceUpdate : public TunableOp { bool is_proxy_params_used{false}; }; +#endif TEST(TunableOp, HandleInplaceUpdate) { - GTEST_SKIP_IF_NO_RTTI(); - - const int a = 7500000; - const int b = 42; +#ifdef ORT_NO_RTTI + GTEST_SKIP() << "TunableOp needs RTTI to work correctly"; +#else + constexpr const int a = 7500000; + constexpr const int b = 42; int c{}; VecAddParamsRecordLastRun params(&a, &b, &c, 1, 0); @@ -459,6 +444,7 @@ TEST(TunableOp, HandleInplaceUpdate) { ASSERT_EQ(c, 7504242); ASSERT_EQ(op.is_proxy_params_used, true); } +#endif } } // namespace tuning