未验证 提交 c4f30c51 编写于 作者: Y Yuanle Liu 提交者: GitHub

add PADDLE_WITH_TENSORRT to EnableTensorRtEngine (#49091)

上级 a0576250
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "paddle/fluid/inference/utils/table_printer.h" #include "paddle/fluid/inference/utils/table_printer.h"
#include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h"
#include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/errors.h"
#include "paddle/phi/backends/cpu/cpu_info.h" #include "paddle/phi/backends/cpu/cpu_info.h"
#include "paddle/utils/string/split.h" #include "paddle/utils/string/split.h"
...@@ -101,10 +102,10 @@ void AnalysisConfig::EnableUseGpu(uint64_t memory_pool_init_size_mb, ...@@ -101,10 +102,10 @@ void AnalysisConfig::EnableUseGpu(uint64_t memory_pool_init_size_mb,
precision_mode == Precision::kBf16) { precision_mode == Precision::kBf16) {
enable_gpu_mixed_ = true; enable_gpu_mixed_ = true;
} else { } else {
LOG(ERROR) PADDLE_THROW(platform::errors::InvalidArgument(
<< "The Paddle-GPU inference currently only supports " "The Paddle-GPU inference currently only supports "
"float32/float16/bfloat16 precision. Please check the parameters " "float32/float16/bfloat16 precision. Please check the parameters "
"you specified in EnableUseGpu or enable_use_gpu function."; "you specified in EnableUseGpu or enable_use_gpu function."));
} }
#else #else
LOG(ERROR) << "Please use PaddlePaddle with GPU version."; LOG(ERROR) << "Please use PaddlePaddle with GPU version.";
...@@ -696,7 +697,7 @@ void AnalysisConfig::EnableTensorRtEngine( ...@@ -696,7 +697,7 @@ void AnalysisConfig::EnableTensorRtEngine(
AnalysisConfig::Precision precision_mode, AnalysisConfig::Precision precision_mode,
bool use_static, bool use_static,
bool use_calib_mode) { bool use_calib_mode) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #ifdef PADDLE_WITH_TENSORRT
if (!use_gpu()) { if (!use_gpu()) {
LOG(ERROR) << "To use TensorRT engine, please call EnableUseGpu() first"; LOG(ERROR) << "To use TensorRT engine, please call EnableUseGpu() first";
return; return;
...@@ -712,8 +713,8 @@ void AnalysisConfig::EnableTensorRtEngine( ...@@ -712,8 +713,8 @@ void AnalysisConfig::EnableTensorRtEngine(
Update(); Update();
#else #else
LOG(ERROR) PADDLE_THROW(platform::errors::PreconditionNotMet(
<< "To use TensorRT engine, please compile inference lib with GPU first."; "To use Paddle-TensorRT, please compile with TENSORRT first."));
#endif #endif
} }
...@@ -1249,7 +1250,7 @@ std::string AnalysisConfig::Summary() { ...@@ -1249,7 +1250,7 @@ std::string AnalysisConfig::Summary() {
os.InsertRow({"use_gpu", use_gpu_ ? "true" : "false"}); os.InsertRow({"use_gpu", use_gpu_ ? "true" : "false"});
if (use_gpu_) { if (use_gpu_) {
os.InsertRow({"gpu_device_id", std::to_string(gpu_device_id_)}); os.InsertRow({"gpu_device_id", std::to_string(gpu_device_id_)});
os.InsertRow({"enable_gpu_mixed_", std::to_string(enable_gpu_mixed_)}); os.InsertRow({"enable_gpu_mixed", std::to_string(enable_gpu_mixed_)});
os.InsertRow({"memory_pool_init_size", os.InsertRow({"memory_pool_init_size",
std::to_string(memory_pool_init_size_mb_) + "MB"}); std::to_string(memory_pool_init_size_mb_) + "MB"});
os.InsertRow( os.InsertRow(
......
...@@ -87,7 +87,9 @@ TEST(paddle_inference_api, UpdateDllFlag) { ...@@ -87,7 +87,9 @@ TEST(paddle_inference_api, UpdateDllFlag) {
TEST(paddle_inference_api, AnalysisConfigCopyCtor) { TEST(paddle_inference_api, AnalysisConfigCopyCtor) {
AnalysisConfig cfg1; AnalysisConfig cfg1;
cfg1.EnableUseGpu(10); cfg1.EnableUseGpu(10);
#ifdef PADDLE_WITH_TENSORRT
cfg1.EnableTensorRtEngine(); cfg1.EnableTensorRtEngine();
#endif
std::string delete_pass("skip_layernorm_fuse_pass"); std::string delete_pass("skip_layernorm_fuse_pass");
cfg1.pass_builder()->DeletePass(delete_pass); cfg1.pass_builder()->DeletePass(delete_pass);
AnalysisConfig cfg2(cfg1); AnalysisConfig cfg2(cfg1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册