Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
469e717a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
469e717a
编写于
8月 07, 2020
作者:
Z
zlsh80826
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add nvinfer_plugin dyloader
上级
68c6160e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
10 deletion
+58
-10
paddle/fluid/platform/dynload/tensorrt.cc
paddle/fluid/platform/dynload/tensorrt.cc
+27
-10
paddle/fluid/platform/dynload/tensorrt.h
paddle/fluid/platform/dynload/tensorrt.h
+31
-0
未找到文件。
paddle/fluid/platform/dynload/tensorrt.cc
浏览文件 @
469e717a
...
@@ -22,19 +22,15 @@ namespace dynload {
...
@@ -22,19 +22,15 @@ namespace dynload {
std
::
once_flag
tensorrt_dso_flag
;
std
::
once_flag
tensorrt_dso_flag
;
void
*
tensorrt_dso_handle
;
void
*
tensorrt_dso_handle
;
std
::
once_flag
tensorrt_plugin_dso_flag
;
void
*
tensorrt_plugin_dso_handle
;
#define DEFINE_WRAP(__name) DynLoad__##__name __name
#define DEFINE_WRAP(__name) DynLoad__##__name __name
TENSORRT_RAND_ROUTINE_EACH
(
DEFINE_WRAP
);
TENSORRT_RAND_ROUTINE_EACH
(
DEFINE_WRAP
);
TENSORRT_PLUGIN_RAND_ROUTINE_EACH
(
DEFINE_WRAP
);
void
*
GetTensorRtHandle
()
{
void
*
GetDsoHandle
(
const
std
::
string
&
dso_name
)
{
#if defined(__APPLE__) || defined(__OSX__)
std
::
string
dso_name
=
"libnvinfer.dylib"
;
#elif defined(_WIN32)
std
::
string
dso_name
=
"nvinfer.dll"
;
#else
std
::
string
dso_name
=
"libnvinfer.so"
;
#endif
#if !defined(_WIN32)
#if !defined(_WIN32)
int
dynload_flags
=
RTLD_LAZY
|
RTLD_LOCAL
;
int
dynload_flags
=
RTLD_LAZY
|
RTLD_LOCAL
;
#else
#else
...
@@ -65,10 +61,31 @@ void* GetTensorRtHandle() {
...
@@ -65,10 +61,31 @@ void* GetTensorRtHandle() {
#endif // !_WIN32
#endif // !_WIN32
std
::
cerr
<<
string
::
Sprintf
(
error_msg
,
dso_name
,
errorno
);
std
::
cerr
<<
string
::
Sprintf
(
error_msg
,
dso_name
,
errorno
);
}
}
return
dso_handle
;
return
dso_handle
;
}
}
void
*
GetTensorRtHandle
()
{
#if defined(__APPLE__) || defined(__OSX__)
std
::
string
dso_name
=
"libnvinfer.dylib"
;
#elif defined(_WIN32)
std
::
string
dso_name
=
"nvinfer.dll"
;
#else
std
::
string
dso_name
=
"libnvinfer.so"
;
#endif
return
GetDsoHandle
(
dso_name
);
}
void
*
GetTensorRtPluginHandle
()
{
#if defined(__APPLE__) || defined(__OSX__)
std
::
string
dso_name
=
"libnvinfer_plugin.dylib"
;
#elif defined(_WIN32)
std
::
string
dso_name
=
"nvinfer_plugin.dll"
;
#else
std
::
string
dso_name
=
"libnvinfer_plugin.so"
;
#endif
return
GetDsoHandle
(
dso_name
);
}
}
// namespace dynload
}
// namespace dynload
}
// namespace platform
}
// namespace platform
}
// namespace paddle
}
// namespace paddle
paddle/fluid/platform/dynload/tensorrt.h
浏览文件 @
469e717a
...
@@ -14,6 +14,7 @@ limitations under the License. */
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#pragma once
#include <NvInfer.h>
#include <NvInfer.h>
#include <NvInferPlugin.h>
#if !defined(_WIN32)
#if !defined(_WIN32)
#include <dlfcn.h>
#include <dlfcn.h>
#endif
#endif
...
@@ -28,10 +29,14 @@ namespace platform {
...
@@ -28,10 +29,14 @@ namespace platform {
namespace
dynload
{
namespace
dynload
{
void
*
GetTensorRtHandle
();
void
*
GetTensorRtHandle
();
void
*
GetTensorRtPluginHandle
();
extern
std
::
once_flag
tensorrt_dso_flag
;
extern
std
::
once_flag
tensorrt_dso_flag
;
extern
void
*
tensorrt_dso_handle
;
extern
void
*
tensorrt_dso_handle
;
extern
std
::
once_flag
tensorrt_plugin_dso_flag
;
extern
void
*
tensorrt_plugin_dso_handle
;
#define DECLARE_DYNAMIC_LOAD_TENSORRT_WRAP(__name) \
#define DECLARE_DYNAMIC_LOAD_TENSORRT_WRAP(__name) \
struct DynLoad__##__name { \
struct DynLoad__##__name { \
template <typename... Args> \
template <typename... Args> \
...
@@ -52,12 +57,38 @@ extern void* tensorrt_dso_handle;
...
@@ -52,12 +57,38 @@ extern void* tensorrt_dso_handle;
}; \
}; \
extern DynLoad__##__name __name
extern DynLoad__##__name __name
#define DECLARE_DYNAMIC_LOAD_TENSORRT_PLUGIN_WRAP(__name) \
struct DynLoad__##__name { \
template <typename... Args> \
auto operator()(Args... args) -> DECLARE_TYPE(__name, args...) { \
using tensorrt_plugin_func = decltype(&::__name); \
std::call_once(tensorrt_plugin_dso_flag, []() { \
tensorrt_plugin_dso_handle = \
paddle::platform::dynload::GetTensorRtPluginHandle(); \
PADDLE_ENFORCE_NOT_NULL( \
tensorrt_plugin_dso_handle, \
platform::errors::Unavailable("Load tensorrt plugin %s failed", \
#__name)); \
}); \
static void* p_##__name = dlsym(tensorrt_plugin_dso_handle, #__name); \
PADDLE_ENFORCE_NOT_NULL(p_##__name, \
platform::errors::Unavailable( \
"Load tensorrt plugin %s failed", #__name)); \
return reinterpret_cast<tensorrt_plugin_func>(p_##__name)(args...); \
} \
}; \
extern DynLoad__##__name __name
#define TENSORRT_RAND_ROUTINE_EACH(__macro) \
#define TENSORRT_RAND_ROUTINE_EACH(__macro) \
__macro(createInferBuilder_INTERNAL); \
__macro(createInferBuilder_INTERNAL); \
__macro(createInferRuntime_INTERNAL); \
__macro(createInferRuntime_INTERNAL); \
__macro(getPluginRegistry);
__macro(getPluginRegistry);
#define TENSORRT_PLUGIN_RAND_ROUTINE_EACH(__macro) \
__macro(initLibNvInferPlugins);
TENSORRT_RAND_ROUTINE_EACH
(
DECLARE_DYNAMIC_LOAD_TENSORRT_WRAP
)
TENSORRT_RAND_ROUTINE_EACH
(
DECLARE_DYNAMIC_LOAD_TENSORRT_WRAP
)
TENSORRT_PLUGIN_RAND_ROUTINE_EACH
(
DECLARE_DYNAMIC_LOAD_TENSORRT_PLUGIN_WRAP
)
}
// namespace dynload
}
// namespace dynload
}
// namespace platform
}
// namespace platform
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录