mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 08:37:06 +08:00

* [backend] support bechmark mode for runtime and backend * [backend] support bechmark mode for runtime and backend * [pybind11] add benchmark methods pybind * [pybind11] add benchmark methods pybind * [Other] Update build scripts * [Other] Update cmake/summary.cmake * [Other] update build scripts * [Other] add ENABLE_BENCHMARK option -> setup.py * optimize backend time recording * optimize backend time recording * optimize trt backend time record * [backend] optimze backend_time recording for trt * [benchmark] remove redundant logs * fixed ov_backend confilct * [benchmark] fixed paddle_backend conflicts * [benchmark] fixed paddle_backend conflicts * [benchmark] fixed paddle_backend conflicts * [benchmark] remove use_gpu option from ort backend option * [benchmark] update benchmark_ppdet.py * [benchmark] update benchmark_ppcls.py * fixed lite backend conflicts * [Lite] fixed lite xpu * add benchmark macro * add RUNTIME_PROFILE_LOOP macros * add comments for RUNTIME_PROFILE macros * add comments for new apis * add comments for new apis * update benchmark_ppdet.py * afixed bugs * remove unused codes * optimize RUNTIME_PROFILE_LOOP macros * optimize RUNTIME_PROFILE_LOOP macros * add comments for benchmark option and result * add docs for benchmark namespace
86 lines
5.0 KiB
C++
86 lines
5.0 KiB
C++
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
#pragma once
|
|
#include "fastdeploy/core/config.h"
|
|
#include "fastdeploy/utils/utils.h"
|
|
#include "fastdeploy/utils/perf.h"
|
|
#include "fastdeploy/benchmark/option.h"
|
|
#include "fastdeploy/benchmark/results.h"
|
|
|
|
#ifdef ENABLE_BENCHMARK
|
|
#define __RUNTIME_PROFILE_LOOP_BEGIN(option, base_loop) \
|
|
int __p_loop = (base_loop); \
|
|
const bool __p_enable_profile = option.enable_profile; \
|
|
const bool __p_include_h2d_d2h = option.include_h2d_d2h; \
|
|
const int __p_repeats = option.repeats; \
|
|
const int __p_warmup = option.warmup; \
|
|
if (__p_enable_profile && (!__p_include_h2d_d2h)) { \
|
|
__p_loop = (__p_repeats) + (__p_warmup); \
|
|
FDINFO << option << std::endl; \
|
|
} \
|
|
TimeCounter __p_tc; \
|
|
bool __p_tc_start = false; \
|
|
for (int __p_i = 0; __p_i < __p_loop; ++__p_i) { \
|
|
if (__p_i >= (__p_warmup) && (!__p_tc_start)) { \
|
|
__p_tc.Start(); \
|
|
__p_tc_start = true; \
|
|
} \
|
|
|
|
#define __RUNTIME_PROFILE_LOOP_END(result) \
|
|
} \
|
|
if ((__p_enable_profile && (!__p_include_h2d_d2h))) { \
|
|
if (__p_tc_start) { \
|
|
__p_tc.End(); \
|
|
double __p_tc_duration = __p_tc.Duration(); \
|
|
result.time_of_runtime = \
|
|
__p_tc_duration / static_cast<double>(__p_repeats); \
|
|
} \
|
|
}
|
|
|
|
#define __RUNTIME_PROFILE_LOOP_H2D_D2H_BEGIN(option, base_loop) \
|
|
int __p_loop_h = (base_loop); \
|
|
const bool __p_enable_profile_h = option.enable_profile; \
|
|
const bool __p_include_h2d_d2h_h = option.include_h2d_d2h; \
|
|
const int __p_repeats_h = option.repeats; \
|
|
const int __p_warmup_h = option.warmup; \
|
|
if (__p_enable_profile_h && __p_include_h2d_d2h_h) { \
|
|
__p_loop_h = (__p_repeats_h) + (__p_warmup_h); \
|
|
FDINFO << option << std::endl; \
|
|
} \
|
|
TimeCounter __p_tc_h; \
|
|
bool __p_tc_start_h = false; \
|
|
for (int __p_i_h = 0; __p_i_h < __p_loop_h; ++__p_i_h) { \
|
|
if (__p_i_h >= (__p_warmup_h) && (!__p_tc_start_h)) { \
|
|
__p_tc_h.Start(); \
|
|
__p_tc_start_h = true; \
|
|
} \
|
|
|
|
#define __RUNTIME_PROFILE_LOOP_H2D_D2H_END(result) \
|
|
} \
|
|
if ((__p_enable_profile_h && __p_include_h2d_d2h_h)) { \
|
|
if (__p_tc_start_h) { \
|
|
__p_tc_h.End(); \
|
|
double __p_tc_duration_h = __p_tc_h.Duration(); \
|
|
result.time_of_runtime = \
|
|
__p_tc_duration_h / static_cast<double>(__p_repeats_h); \
|
|
} \
|
|
}
|
|
#else
|
|
#define __RUNTIME_PROFILE_LOOP_BEGIN(option, base_loop) \
|
|
for (int __p_i = 0; __p_i < (base_loop); ++ __p_i) {
|
|
#define __RUNTIME_PROFILE_LOOP_END(result) }
|
|
#define __RUNTIME_PROFILE_LOOP_H2D_D2H_BEGIN(option, base_loop) \
|
|
for (int __p_i_h = 0; __p_i_h < (base_loop); ++ __p_i_h) {
|
|
#define __RUNTIME_PROFILE_LOOP_H2D_D2H_END(result) }
|
|
#endif |