mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
Make static analysis happy (#13655)
Just suppress some warning by changing code.
This commit is contained in:
parent
116079749e
commit
b731cf397d
2 changed files with 50 additions and 64 deletions
|
|
@ -145,14 +145,14 @@ class TunableOp {
|
|||
|
||||
private:
|
||||
static void WarmUp(Op<ParamsT>& 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<ParamsT>& 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++) {
|
||||
|
|
|
|||
|
|
@ -3,24 +3,11 @@
|
|||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <chrono>
|
||||
|
||||
#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<ParamsT>;
|
|||
template <typename ParamsT>
|
||||
using TunableOp = ::onnxruntime::tunable::TunableOp<ParamsT, Timer>;
|
||||
|
||||
struct SleepTimeResolutionGuard {
|
||||
SleepTimeResolutionGuard() {
|
||||
#ifdef _WIN32
|
||||
timeBeginPeriod(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
~SleepTimeResolutionGuard() {
|
||||
#ifdef _WIN32
|
||||
timeEndPeriod(1);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
struct VecAddParams : ::onnxruntime::tunable::OpParams<StreamT> {
|
||||
|
|
@ -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<VecAddParamsRecordLastRun> {
|
|||
};
|
||||
|
||||
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<VecAddParamsRecordLastRun> {
|
||||
|
|
@ -300,10 +276,11 @@ class TunableVecAddSelectSupported : public TunableOp<VecAddParamsRecordLastRun>
|
|||
};
|
||||
|
||||
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<VecAddParamsRecordLastRun> {
|
||||
|
|
@ -329,10 +307,11 @@ class TunableVecAddSelectFastestIfSupported : public TunableOp<VecAddParamsRecor
|
|||
};
|
||||
|
||||
TEST(TunableOp, SelectFastestIfSupported) {
|
||||
GTEST_SKIP_IF_NO_RTTI();
|
||||
|
||||
const int a[] = {0, 1, 2, 3};
|
||||
const int b[] = {42, 42, 42, 42};
|
||||
#ifdef ORT_NO_RTTI
|
||||
GTEST_SKIP() << "TunableOp needs RTTI to work correctly";
|
||||
#else
|
||||
constexpr const int a[] = {0, 1, 2, 3};
|
||||
constexpr const int b[] = {42, 42, 42, 42};
|
||||
int c[4] = {};
|
||||
VecAddParamsRecordLastRun params(a, b, c, 1, 0);
|
||||
std::string last_run;
|
||||
|
|
@ -349,13 +328,15 @@ TEST(TunableOp, SelectFastestIfSupported) {
|
|||
status = op(¶ms);
|
||||
ASSERT_TRUE(status.IsOK());
|
||||
ASSERT_EQ(last_run, "FastestNarrow");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(TunableOp, DisabledWithManualSelection) {
|
||||
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;
|
||||
|
|
@ -369,6 +350,7 @@ TEST(TunableOp, DisabledWithManualSelection) {
|
|||
ASSERT_EQ(status.Category(), common::StatusCategory::NONE);
|
||||
ASSERT_EQ(status.Code(), common::StatusCode::INVALID_ARGUMENT);
|
||||
ASSERT_THAT(status.ErrorMessage(), testing::HasSubstr("FastestNarrow only supports VecAdd 4 elements"));
|
||||
#endif
|
||||
}
|
||||
|
||||
class TunableVecAddNotHandleInplaceUpdate : public TunableOp<VecAddParams> {
|
||||
|
|
@ -378,6 +360,7 @@ class TunableVecAddNotHandleInplaceUpdate : public TunableOp<VecAddParams> {
|
|||
}
|
||||
};
|
||||
|
||||
#ifndef ORT_NO_RTTI
|
||||
class TunableVecAddHandleInplaceUpdate : public TunableOp<VecAddParams> {
|
||||
public:
|
||||
TunableVecAddHandleInplaceUpdate() {
|
||||
|
|
@ -404,12 +387,14 @@ class TunableVecAddHandleInplaceUpdate : public TunableOp<VecAddParams> {
|
|||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue