Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
b64f611e
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b64f611e
编写于
3月 28, 2022
作者:
S
Shang Zhizhou
提交者:
GitHub
3月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Infrt]add enum from nvinfer namespace to trt lower pattern (#40799)
* add enum from nvinfer namespace to trt lower pattern * update
上级
37f914c8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
66 deletion
+36
-66
paddle/infrt/backends/tensorrt/trt_engine.cc
paddle/infrt/backends/tensorrt/trt_engine.cc
+4
-0
paddle/infrt/dialect/tensorrt/pd_lower_to_trt.td
paddle/infrt/dialect/tensorrt/pd_lower_to_trt.td
+6
-6
paddle/infrt/dialect/tensorrt/trt_op_base.td
paddle/infrt/dialect/tensorrt/trt_op_base.td
+0
-51
paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc
paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc
+26
-0
paddle/infrt/dialect/tensorrt/trt_ops.td
paddle/infrt/dialect/tensorrt/trt_ops.td
+0
-9
未找到文件。
paddle/infrt/backends/tensorrt/trt_engine.cc
浏览文件 @
b64f611e
...
...
@@ -210,12 +210,16 @@ bool TrtEngine::SetupNetworkAndConfig(const BuildOptions& build,
case
PrecisionConstraints
::
kNONE
:
// It's the default for TensorRT.
break
;
#if IS_TRT_VERSION_GE(8200)
case
PrecisionConstraints
::
kOBEY
:
config
.
setFlag
(
BuilderFlag
::
kOBEY_PRECISION_CONSTRAINTS
);
break
;
case
PrecisionConstraints
::
kPREFER
:
config
.
setFlag
(
BuilderFlag
::
kPREFER_PRECISION_CONSTRAINTS
);
break
;
#endif // IS_TRT_VERSION_GE(8200)
default:
break
;
}
// TODO(TRT): DLA config.
...
...
paddle/infrt/dialect/tensorrt/pd_lower_to_trt.td
浏览文件 @
b64f611e
...
...
@@ -6,23 +6,23 @@ include "paddle/infrt/dialect/infrt/ir/infrt_base.td"
include "paddle/infrt/dialect/pd/ir/pd_ops.td"
include "paddle/infrt/dialect/tensorrt/trt_ops.td"
class TRT_createNvinferEnumAttr<string enum_type, string enum_value> : NativeCodeCall<
"infrt::trt::createNvinferEnumAttr<STRING_TO_ENUM_TYPE(" # enum_type # ")>($_builder, STRING_TO_ENUM_VALUE(" # enum_type # "::" # enum_value # "))">;
def PD2TRT_Matmul_Lower : Pat<
(PD_MatmulOp $X, $Y, $transpose_X, $transpose_Y, ConstantAttr<F32Attr, "1.0">),
(TRT_MatrixMultiplyOp $X, $transpose_X, $Y, $transpose_Y)>;
//TO DO(shangzhizhou):replace '"INFRT_createI32Attr<"0">' to enum nvinfer1::ElementWiseOperation::kSUM
def PD2TRT_ElementwiseAdd_Lower : Pat<
(PD_Elementwise_addOp $X, $Y, ConstantAttr<SI32Attr, "-1">),
(TRT_ElementWiseOp $X, $Y, (
INFRT_createSI32Attr<"0">)/*kSUM*/
)>;
(TRT_ElementWiseOp $X, $Y, (
TRT_createNvinferEnumAttr<"nvinfer1::ElementWiseOperation", "kSUM">)
)>;
//TO DO(shangzhizhou):replace '"INFRT_createI32Attr<"0">' to enum nvinfer1::ActivationType::kRELU
def PD2TRT_Relu_Lower : Pat<
(PD_ReluOp $X),
(TRT_ActivationOp $X, (
INFRT_createSI32Attr<"0">)/*kRELU*/
, (INFRT_createF32Attr<"0.0">), (INFRT_createF32Attr<"0.0">))>;
(TRT_ActivationOp $X, (
TRT_createNvinferEnumAttr<"nvinfer1::ActivationType", "kRELU">)
, (INFRT_createF32Attr<"0.0">), (INFRT_createF32Attr<"0.0">))>;
//TO DO(shangzhizhou):replace '"INFRT_createI32Attr<"0">' to enum nvinfer1::ActivationType::kCLIP
def PD2TRT_Relu6_Lower : Pat<
(PD_Relu6Op $X, $threshold),
(TRT_ActivationOp $X, (
INFRT_createSI32Attr<"8">)/*kCLIP*/
, (INFRT_createF32Attr<"0.0">), $threshold)>;
(TRT_ActivationOp $X, (
TRT_createNvinferEnumAttr<"nvinfer1::ActivationType", "kCLIP">)
, (INFRT_createF32Attr<"0.0">), $threshold)>;
#endif // PD_LOWER_TO_TRT
paddle/infrt/dialect/tensorrt/trt_op_base.td
浏览文件 @
b64f611e
...
...
@@ -22,59 +22,8 @@ def TRT_Dialect : Dialect {
class TRT_Op<string mnemonic, list<OpTrait> traits = []> :
Op<TRT_Dialect, mnemonic, traits>;
class TRT_PaddleAttr <string name, string description> :
Attr<CPred<"$_self.isa<mlir::trt::" # name # "Attr>()">,
"PaddlePaddle " # description # " attribute">;
def TRT_EngineType :
Type<CPred<"$_self.isa<::infrt::trt::EngineType>()">, "!trt.engine">,
BuildableType<"getType<::infrt::trt::EngineType>()">;
//===----------------------------------------------------------------------===//
// PaddlePaddle type definitions
//===----------------------------------------------------------------------===//
def TRT_TRTDialectType : Type<CPred<"$_self.isa<mlir::trt::TRTType>()">, "PaddlePaddle type">;
class TRT_PaddleType <string name, string description> :
Type<CPred<"$_self.isa<mlir::trt::" # name #"Type>()">,
"Paddle " # description # " type">,
BuildableType<"getType<mlir::trt::" # name # "Type>()">;
//===----------------------------------------------------------------------===//
// Integer types
def TRT_Bool : AnyTypeOf<[I<1>], "bool">;
def TRT_Int8 : AnyTypeOf<[I8], "8-bit integer">;
def TRT_Int16 : AnyTypeOf<[I16], "16-bit integer">;
def TRT_Int32 : AnyTypeOf<[I32], "32-bit integer">;
def TRT_Int64 : AnyTypeOf<[I64], "64-bit integer">;
def TRT_UInt8 : AnyTypeOf<[UI<8>], "8-bit unsigned integer">;
def TRT_UInt16 : AnyTypeOf<[UI<16>], "16-bit unsigned integer">;
def TRT_UInt32 : AnyTypeOf<[UI<32>], "32-bit unsigned integer">;
def TRT_UInt64 : AnyTypeOf<[UI<64>], "64-bit unsigned integer">;
def TRT_SInt : AnyTypeOf<[TRT_Int8, TRT_Int16, TRT_Int32, TRT_Int64], "signed integer">;
def TRT_UInt : AnyTypeOf<[TRT_UInt8, TRT_UInt16, TRT_UInt32, TRT_UInt64], "unsigned integer">;
def TRT_Int : AnyTypeOf<[TRT_SInt, TRT_UInt], "integer">;
// Float types
def TRT_Float16 : AnyTypeOf<[F16], "16-bit float">;
def TRT_Float32 : AnyTypeOf<[F32], "32-bit float">;
def TRT_Float64 : AnyTypeOf<[F64], "64-bit float">;
def TRT_Float : AnyTypeOf<[TRT_Float16, TRT_Float32, TRT_Float64], "floating-point">;
// Tensor types
def TRT_ElementType : Type<Or<[TRT_Float.predicate,
TRT_Bool.predicate,
TRT_Int.predicate]>,
"trt.dtype">;
def TRT_Tensor : TensorOf<[TRT_ElementType]>;
#endif // TRT_OP_BASE
paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc
浏览文件 @
b64f611e
...
...
@@ -27,6 +27,32 @@
namespace
infrt
{
namespace
trt
{
#ifdef INFRT_WITH_TRT
#define STRING_TO_ENUM_TYPE(enum_type) enum_type
#define STRING_TO_ENUM_VALUE(enum_value) enum_value
#include <NvInfer.h>
#else // INFRT_WITH_TRT
#define STRING_TO_ENUM_TYPE(enum_type) std::string
#define STRING_TO_ENUM_VALUE(enum_value) #enum_value
#endif // INFRT_WITH_TRT
template
<
typename
T
>
::
mlir
::
IntegerAttr
createNvinferEnumAttr
(
::
mlir
::
PatternRewriter
&
rewriter
,
T
enum_value
)
{
return
rewriter
.
getSI32IntegerAttr
((
int32_t
)
enum_value
);
}
template
<
>
::
mlir
::
IntegerAttr
createNvinferEnumAttr
<
std
::
string
>
(
::
mlir
::
PatternRewriter
&
rewriter
,
std
::
string
enum_value
)
{
(
void
)
enum_value
;
return
rewriter
.
getSI32IntegerAttr
(
-
1
);
}
#include "paddle/infrt/dialect/tensorrt/pd_lower_to_trt.cpp.inc" // NOLINT
struct
PD2TRT_GraphLower
:
public
::
mlir
::
RewritePattern
{
...
...
paddle/infrt/dialect/tensorrt/trt_ops.td
浏览文件 @
b64f611e
...
...
@@ -20,15 +20,6 @@ def TRT_CreateEngineOp : TRT_Op<"create_engine", [SingleBlockImplicitTerminator<
let results = (outs TRT_EngineType:$engine);
}
def TRT_ExecuteOp : TRT_Op<"execute", [NoSideEffect]> {
let summary = "trt execute Op";
let description = [{
Describe a tensorrt runtime.
}];
let arguments = (ins TRT_EngineType:$engine, Variadic<DenseTensor>:$inputs);
let results = (outs Variadic<DenseTensor>:$output);
}
def TRT_EngineComputeOp : TRT_Op<"compute", [NoSideEffect]> {
let summary = "trt compute engine";
let description = [{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录