Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
2c7f6e6d
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2c7f6e6d
编写于
2月 16, 2022
作者:
王
王明冬
提交者:
GitHub
2月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[infrt] add infrt dialect ir. test=develop (#39455)
上级
c6478270
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
191 addition
and
4 deletion
+191
-4
paddle/infrt/CMakeLists.txt
paddle/infrt/CMakeLists.txt
+1
-1
paddle/infrt/dialect/CMakeLists.txt
paddle/infrt/dialect/CMakeLists.txt
+1
-1
paddle/infrt/dialect/infrt/CMakeLists.txt
paddle/infrt/dialect/infrt/CMakeLists.txt
+7
-0
paddle/infrt/dialect/infrt/infrt_dialect.cc
paddle/infrt/dialect/infrt/infrt_dialect.cc
+92
-0
paddle/infrt/dialect/infrt/infrt_dialect.h
paddle/infrt/dialect/infrt/infrt_dialect.h
+29
-0
paddle/infrt/dialect/infrt/infrt_ops.td
paddle/infrt/dialect/infrt/infrt_ops.td
+52
-0
paddle/infrt/dialect/init_infrt_dialects.cc
paddle/infrt/dialect/init_infrt_dialects.cc
+2
-0
paddle/infrt/dialect/pd_op_base.td
paddle/infrt/dialect/pd_op_base.td
+5
-1
paddle/infrt/dialect/pd_ops.cc
paddle/infrt/dialect/pd_ops.cc
+1
-0
paddle/infrt/tests/dialect/paddle_ops.mlir
paddle/infrt/tests/dialect/paddle_ops.mlir
+1
-1
未找到文件。
paddle/infrt/CMakeLists.txt
浏览文件 @
2c7f6e6d
...
...
@@ -107,6 +107,6 @@ endif()
cc_library
(
infrt SHARED SRCS
${
infrt_src
}
DEPS glog boost
${
mlir_libs
}
paddle_framework_proto infrt_naive
)
cc_library
(
infrt_static SRCS
${
infrt_src
}
DEPS glog boost
${
mlir_libs
}
paddle_framework_proto
)
add_dependencies
(
infrt
${
infrt_mlir_incs
}
)
add_dependencies
(
infrt
${
infrt_mlir_incs
}
mlir-headers
)
add_custom_target
(
test_infrt_exec DEPENDS
${
INFRT_TEST_TARGETS
}
)
paddle/infrt/dialect/CMakeLists.txt
浏览文件 @
2c7f6e6d
...
...
@@ -31,9 +31,9 @@ target_link_libraries(infrtopt infrt)
add_executable
(
print-ir print_ir.cc
)
target_link_libraries
(
print-ir infrt
${
mlir_libs
}
)
add_dependencies
(
print-ir pd_ops_inc
)
cc_test_tiny
(
test_infrt_mlir_loader SRCS mlir_loader_test.cc DEPS infrt
${
MLIR_IR_LIBS
}
)
add_subdirectory
(
infrt
)
add_subdirectory
(
tensorrt
)
if
(
INFRT_WITH_PTEN
)
...
...
paddle/infrt/dialect/infrt/CMakeLists.txt
0 → 100644
浏览文件 @
2c7f6e6d
core_gather_headers
()
gather_srcs
(
infrt_src SRCS
infrt_dialect.cc
)
add_mlir_dialect
(
infrt_ops Infrt
)
paddle/infrt/dialect/infrt/infrt_dialect.cc
0 → 100644
浏览文件 @
2c7f6e6d
// 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.
#include "paddle/infrt/dialect/infrt/infrt_dialect.h"
#include <mlir/IR/Builders.h>
#include <mlir/IR/BuiltinOps.h>
#include <mlir/IR/DialectImplementation.h>
#include "paddle/infrt/dialect/dense_tensor.h"
#include "paddle/infrt/dialect/infrt/infrt_opsDialect.cpp.inc"
#define GET_TYPEDEF_CLASSES
#include "paddle/infrt/dialect/infrt/infrt_opsTypes.cpp.inc"
#define GET_OP_CLASSES
#include "paddle/infrt/dialect/infrt/infrt_ops.cpp.inc"
namespace
infrt
{
void
InfrtDialect
::
initialize
()
{
addTypes
<
#define GET_TYPEDEF_LIST
#include "paddle/infrt/dialect/infrt/infrt_opsTypes.cpp.inc" // NOLINT
>
();
addOperations
<
#define GET_OP_LIST
#include "paddle/infrt/dialect/infrt/infrt_ops.cpp.inc" // NOLINT
>
();
}
/// Parse a type registered to this dialect.
mlir
::
Type
InfrtDialect
::
parseType
(
::
mlir
::
DialectAsmParser
&
parser
)
const
{
llvm
::
StringRef
keyword
;
if
(
parser
.
parseKeyword
(
&
keyword
))
return
nullptr
;
// parse TensorType, for example: !infrt.lod_tensor<3x64x3x3xf32,5>
// 5 is the lod_level
if
(
keyword
==
"lod_tensor"
)
{
// Parse the size and elementType.
llvm
::
SmallVector
<
int64_t
,
4
>
shape
;
mlir
::
Type
elementType
;
int32_t
lod_level
=
0
;
// parse "<"
if
(
parser
.
parseLess
())
return
nullptr
;
if
(
parser
.
parseDimensionList
(
shape
))
return
nullptr
;
// Parse the element type.
if
(
parser
.
parseType
(
elementType
))
return
nullptr
;
// parse ","
if
(
parser
.
parseComma
())
return
nullptr
;
// llvm::APInt lod_level;
if
(
parser
.
parseInteger
(
lod_level
))
return
nullptr
;
// parse ">"
if
(
parser
.
parseGreater
())
return
nullptr
;
return
LoDTensorType
::
get
(
parser
.
getContext
(),
shape
,
elementType
,
lod_level
);
}
// Todo: parse other type
return
mlir
::
Type
();
}
void
InfrtDialect
::
printType
(
::
mlir
::
Type
type
,
::
mlir
::
DialectAsmPrinter
&
os
)
const
{
// print TensorType, for example: !infrt.tensor<X86, CUDA, F32>
if
(
type
.
isa
<
infrt
::
LoDTensorType
>
())
{
auto
lodTensorType
=
type
.
cast
<
infrt
::
LoDTensorType
>
();
os
<<
"lod_tensor<"
;
auto
shape
=
lodTensorType
.
getShape
();
for
(
auto
dim
=
shape
.
begin
(),
e
=
shape
.
end
()
-
1
;
dim
!=
e
;
++
dim
)
os
<<
*
dim
<<
'x'
;
os
<<
shape
.
back
()
<<
'x'
<<
lodTensorType
.
getElementType
()
<<
", "
<<
lodTensorType
.
getLod_level
()
<<
">"
;
return
;
}
llvm_unreachable
(
"unknown infrt type."
);
}
}
// namespace infrt
paddle/infrt/dialect/infrt/infrt_dialect.h
0 → 100644
浏览文件 @
2c7f6e6d
// 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
//===----------------------------------------------------------------------===//
// Dialect
//===----------------------------------------------------------------------===//
#include <mlir/IR/BuiltinTypes.h>
#include <mlir/IR/Dialect.h>
#include <mlir/IR/OpDefinition.h>
#include <mlir/Interfaces/SideEffectInterfaces.h>
#include "paddle/infrt/dialect/infrt/infrt_opsDialect.h.inc"
#define GET_TYPEDEF_CLASSES
#include "paddle/infrt/dialect/infrt/infrt_opsTypes.h.inc"
#define GET_OP_CLASSES
#include "paddle/infrt/dialect/infrt/infrt_ops.h.inc"
paddle/infrt/dialect/infrt/infrt_ops.td
0 → 100644
浏览文件 @
2c7f6e6d
#ifndef Infrt_OpS
#define Infrt_OpS
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
def Infrt_Dialect : Dialect {
let summary =
"A dialect containing the Infrt Attributes, Operations, and Types";
let name = "Infrt";
let cppNamespace = "::infrt";
}
// Type definitions
// Base class for Infrt dialect types.
class Infrt_Type<string name, list<Trait> traits = [],
string baseCppClass = "::mlir::Type">
: TypeDef<Infrt_Dialect, name, traits, baseCppClass> {
}
def LoDTensor : Infrt_Type<"LoDTensor"> {
let summary = "infrt lod tensor";
let description = [{lod_tensor<3x64x3x3xf32, 3>}];
let parameters = (ins
ArrayRefParameter<"int64_t">:$shape,
"mlir::Type":$elementType,
"int32_t":$lod_level
);
}
// Op definition
class Infrt_Op<string mnemonic, list<OpTrait> traits = []> : Op<Infrt_Dialect, mnemonic, traits> {
// Each registered op needs to provide all of a printer, parser and verifier.
// let printer = [{ return infrt::print(p, *this); }];
// let verifier = [{ return infrt::verify(*this); }];
// let parser = [{ return infrt::parse$cppClass(parser, result); }];
}
// def InfRT_KernelOp : Infrt_Op<"kernel", [NoSideEffect]> {
// let summary = "kernel op";
// let description = [{
// kernel op!
// }];
// let arguments = (ins StrAttr:$name, PD_Tensor:$X, PD_Tensor:$Y, DefaultValuedAttr<F32Attr, "1.0">:$Alpha, DefaultValuedAttr<F32Attr, "1.0">:$Beta);
//
// let results = (outs PD_Tensor:$Out);
// }
#endif // Infrt_OpS
paddle/infrt/dialect/init_infrt_dialects.cc
浏览文件 @
2c7f6e6d
...
...
@@ -18,6 +18,7 @@
#include "paddle/infrt/dialect/basic_kernels.h"
#include "paddle/infrt/dialect/dense_tensor.h"
#include "paddle/infrt/dialect/infrt/infrt_dialect.h"
#include "paddle/infrt/dialect/infrt_base.h"
#include "paddle/infrt/dialect/pd_ops.h"
#include "paddle/infrt/dialect/pten/infrt_pten_tensor.h"
...
...
@@ -28,6 +29,7 @@ namespace infrt {
void
registerCinnDialects
(
mlir
::
DialectRegistry
&
registry
)
{
// NOLINT
registry
.
insert
<
ts
::
TensorShapeDialect
,
dialect
::
INFRTDialect
,
infrt
::
InfrtDialect
,
dt
::
DTDialect
,
mlir
::
pd
::
PaddleDialect
,
#ifdef INFRT_WITH_PTEN
...
...
paddle/infrt/dialect/pd_op_base.td
浏览文件 @
2c7f6e6d
...
...
@@ -6,6 +6,7 @@
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "paddle/infrt/dialect/infrt/infrt_ops.td"
def PD_Dialect : Dialect {
let name = "pd";
...
...
@@ -71,7 +72,10 @@ def PD_ElementType : Type<Or<[PD_Float.predicate,
PD_Int.predicate]>,
"pd.dtype">;
def PD_Tensor : TensorOf<[PD_ElementType]>;
// def PD_Tensor : TensorOf<[PD_ElementType]>;
def PD_Tensor1 : TensorOf<[PD_ElementType]>;
def PD_Tensor : AnyTypeOf<[PD_Tensor1, LoDTensor],"pd.ttype">;
def PD_Tensor_Array : VectorOf<[PD_Tensor]>;
...
...
paddle/infrt/dialect/pd_ops.cc
浏览文件 @
2c7f6e6d
...
...
@@ -16,6 +16,7 @@
#include <mlir/IR/Matchers.h>
#include <mlir/IR/PatternMatch.h>
#include "paddle/infrt/dialect/infrt/infrt_dialect.h"
#include "paddle/infrt/dialect/infrt_base.h"
#define GET_OP_CLASSES
...
...
paddle/infrt/tests/dialect/paddle_ops.mlir
浏览文件 @
2c7f6e6d
...
...
@@ -3,7 +3,7 @@
func @ops() {
%a = pd.feed() {name="input0"} : tensor<?xf32>
%b = pd.feed() {name="input1"}: tensor<?xf32>
%d = pd.feed() {name="input3"}: !Infrt.lod_tensor<3x4x9xf32, 0>
%c = "pd.matmul"(%a, %b) {transpose_x=true, transpose_y=false} : (tensor<?xf32>, tensor<?xf32>) -> tensor<?xf32>
infrt.return
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录