From 4149cabeec527fa171a45a10ab21ba7fd1374a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=98=8E=E5=86=AC?= <78149749+winter-wang@users.noreply.github.com> Date: Tue, 1 Mar 2022 10:00:01 +0800 Subject: [PATCH] add type constrait for DenseTensor (#39967) --- paddle/infrt/dialect/infrt/infrt_ops_base.td | 6 ++++++ paddle/infrt/dialect/init_infrt_dialects.cc | 4 ++-- paddle/infrt/dialect/phi/CMakeLists.txt | 11 +---------- paddle/infrt/dialect/phi/ir/CMakeLists.txt | 9 +++++++++ paddle/infrt/dialect/phi/{ => ir}/infrt_phi_base.td | 0 .../infrt/dialect/phi/{ => ir}/infrt_phi_kernel.td | 2 +- .../infrt/dialect/phi/{ => ir}/infrt_phi_tensor.cc | 10 +++++----- paddle/infrt/dialect/phi/{ => ir}/infrt_phi_tensor.h | 8 ++++---- .../infrt/dialect/phi/{ => ir}/infrt_phi_tensor.td | 2 +- paddle/infrt/dialect/phi/{ => ir}/phi_base.cc | 12 ++++++------ paddle/infrt/dialect/phi/{ => ir}/phi_base.h | 8 +++++--- 11 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 paddle/infrt/dialect/phi/ir/CMakeLists.txt rename paddle/infrt/dialect/phi/{ => ir}/infrt_phi_base.td (100%) rename paddle/infrt/dialect/phi/{ => ir}/infrt_phi_kernel.td (92%) rename paddle/infrt/dialect/phi/{ => ir}/infrt_phi_tensor.cc (71%) rename paddle/infrt/dialect/phi/{ => ir}/infrt_phi_tensor.h (83%) rename paddle/infrt/dialect/phi/{ => ir}/infrt_phi_tensor.td (97%) rename paddle/infrt/dialect/phi/{ => ir}/phi_base.cc (84%) rename paddle/infrt/dialect/phi/{ => ir}/phi_base.h (84%) diff --git a/paddle/infrt/dialect/infrt/infrt_ops_base.td b/paddle/infrt/dialect/infrt/infrt_ops_base.td index 81d3d028a6..978b126d75 100644 --- a/paddle/infrt/dialect/infrt/infrt_ops_base.td +++ b/paddle/infrt/dialect/infrt/infrt_ops_base.td @@ -40,6 +40,12 @@ def DenseTensor : Infrt_Type<"DenseTensor"> { ); } +// Type Constrait for concrete DenseTensor type. +class DenseTensor : + Type, + "!infrt.DenseTensor<"#target#","#precision#","#layout#">", + "::infrt::DenseTensorType">; + // Base class for infrt dialect attributes. class Infrt_Attr traits = [], string baseCppClass = "::mlir::Attribute"> diff --git a/paddle/infrt/dialect/init_infrt_dialects.cc b/paddle/infrt/dialect/init_infrt_dialects.cc index b5b8de7a20..c5c81b4b0f 100644 --- a/paddle/infrt/dialect/init_infrt_dialects.cc +++ b/paddle/infrt/dialect/init_infrt_dialects.cc @@ -21,8 +21,8 @@ #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/phi/infrt_phi_tensor.h" -#include "paddle/infrt/dialect/phi/phi_base.h" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensor.h" +#include "paddle/infrt/dialect/phi/ir/phi_base.h" #include "paddle/infrt/dialect/tensor_shape.h" namespace infrt { diff --git a/paddle/infrt/dialect/phi/CMakeLists.txt b/paddle/infrt/dialect/phi/CMakeLists.txt index 626b02c1f7..d477b6b9bd 100644 --- a/paddle/infrt/dialect/phi/CMakeLists.txt +++ b/paddle/infrt/dialect/phi/CMakeLists.txt @@ -2,16 +2,7 @@ if (NOT INFRT_WITH_PHI) return() endif() -#mlir_tablegen_on(infrt_phi_base DIALECT phi) -add_mlir_dialect(infrt_phi_base phi) -add_mlir_dialect(infrt_phi_tensor phi_dt) -add_mlir_dialect(infrt_phi_kernel phi_kernel) -#mlir_tablegen_on(infrt_phi_tensor) - -gather_srcs(infrt_src SRCS - phi_base.cc infrt_phi_tensor.cc - infrt_phi_tensor.cc) - +add_subdirectory(ir) add_subdirectory(pass) add_executable(phi-exec phi_exec.cc) diff --git a/paddle/infrt/dialect/phi/ir/CMakeLists.txt b/paddle/infrt/dialect/phi/ir/CMakeLists.txt new file mode 100644 index 0000000000..8c1d75629d --- /dev/null +++ b/paddle/infrt/dialect/phi/ir/CMakeLists.txt @@ -0,0 +1,9 @@ +#mlir_tablegen_on(infrt_phi_base DIALECT phi) +add_mlir_dialect(infrt_phi_base phi) +add_mlir_dialect(infrt_phi_tensor phi_dt) +add_mlir_dialect(infrt_phi_kernel phi_kernel) +#mlir_tablegen_on(infrt_phi_tensor) + +gather_srcs(infrt_src SRCS + phi_base.cc + infrt_phi_tensor.cc) diff --git a/paddle/infrt/dialect/phi/infrt_phi_base.td b/paddle/infrt/dialect/phi/ir/infrt_phi_base.td similarity index 100% rename from paddle/infrt/dialect/phi/infrt_phi_base.td rename to paddle/infrt/dialect/phi/ir/infrt_phi_base.td diff --git a/paddle/infrt/dialect/phi/infrt_phi_kernel.td b/paddle/infrt/dialect/phi/ir/infrt_phi_kernel.td similarity index 92% rename from paddle/infrt/dialect/phi/infrt_phi_kernel.td rename to paddle/infrt/dialect/phi/ir/infrt_phi_kernel.td index 879994907c..37bf0b5ef2 100644 --- a/paddle/infrt/dialect/phi/infrt_phi_kernel.td +++ b/paddle/infrt/dialect/phi/ir/infrt_phi_kernel.td @@ -4,7 +4,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/IR/OpBase.td" include "paddle/infrt/dialect/infrt_base.td" -include "paddle/infrt/dialect/phi/infrt_phi_base.td" +include "paddle/infrt/dialect/phi/ir/infrt_phi_base.td" def PHI_KernelDialect : Dialect { let name = "phi_kernel"; diff --git a/paddle/infrt/dialect/phi/infrt_phi_tensor.cc b/paddle/infrt/dialect/phi/ir/infrt_phi_tensor.cc similarity index 71% rename from paddle/infrt/dialect/phi/infrt_phi_tensor.cc rename to paddle/infrt/dialect/phi/ir/infrt_phi_tensor.cc index 9df1a47031..64780294be 100644 --- a/paddle/infrt/dialect/phi/infrt_phi_tensor.cc +++ b/paddle/infrt/dialect/phi/ir/infrt_phi_tensor.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/infrt/dialect/phi/infrt_phi_tensor.h" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensor.h" #include -#include "paddle/infrt/dialect/phi/infrt_phi_tensorDialect.cpp.inc" -#include "paddle/infrt/dialect/phi/infrt_phi_tensorTypes.cpp.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensorDialect.cpp.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensorTypes.cpp.inc" namespace infrt { namespace phi { @@ -25,7 +25,7 @@ namespace phi { void PHIDenseTensorDialect::initialize() { #define GET_OP_LIST addOperations< -#include "paddle/infrt/dialect/phi/infrt_phi_tensor.cpp.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensor.cpp.inc" >(); } @@ -33,4 +33,4 @@ void PHIDenseTensorDialect::initialize() { } // namespace infrt #define GET_OP_CLASSES -#include "paddle/infrt/dialect/phi/infrt_phi_tensor.cpp.inc" // NOLINT +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensor.cpp.inc" // NOLINT diff --git a/paddle/infrt/dialect/phi/infrt_phi_tensor.h b/paddle/infrt/dialect/phi/ir/infrt_phi_tensor.h similarity index 83% rename from paddle/infrt/dialect/phi/infrt_phi_tensor.h rename to paddle/infrt/dialect/phi/ir/infrt_phi_tensor.h index 2780f97591..9a92558daa 100644 --- a/paddle/infrt/dialect/phi/infrt_phi_tensor.h +++ b/paddle/infrt/dialect/phi/ir/infrt_phi_tensor.h @@ -29,11 +29,11 @@ #include #include -#include "paddle/infrt/dialect/phi/infrt_phi_tensorDialect.h.inc" -#include "paddle/infrt/dialect/phi/infrt_phi_tensorTypes.h.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensorDialect.h.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensorTypes.h.inc" #include "paddle/infrt/dialect/dense_tensor.h" -#include "paddle/infrt/dialect/phi/phi_base.h" +#include "paddle/infrt/dialect/phi/ir/phi_base.h" // NOLINT #define GET_OP_CLASSES -#include "paddle/infrt/dialect/phi/infrt_phi_tensor.h.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_tensor.h.inc" diff --git a/paddle/infrt/dialect/phi/infrt_phi_tensor.td b/paddle/infrt/dialect/phi/ir/infrt_phi_tensor.td similarity index 97% rename from paddle/infrt/dialect/phi/infrt_phi_tensor.td rename to paddle/infrt/dialect/phi/ir/infrt_phi_tensor.td index b7b3b061fd..dc3a4b340d 100644 --- a/paddle/infrt/dialect/phi/infrt_phi_tensor.td +++ b/paddle/infrt/dialect/phi/ir/infrt_phi_tensor.td @@ -2,7 +2,7 @@ #else #define PHI_TENSOR -include "paddle/infrt/dialect/phi/infrt_phi_base.td" +include "paddle/infrt/dialect/phi/ir/infrt_phi_base.td" include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/IR/OpBase.td" include "paddle/infrt/dialect/infrt_base.td" diff --git a/paddle/infrt/dialect/phi/phi_base.cc b/paddle/infrt/dialect/phi/ir/phi_base.cc similarity index 84% rename from paddle/infrt/dialect/phi/phi_base.cc rename to paddle/infrt/dialect/phi/ir/phi_base.cc index a1caa40f63..7a6b3f3f0a 100644 --- a/paddle/infrt/dialect/phi/phi_base.cc +++ b/paddle/infrt/dialect/phi/ir/phi_base.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/infrt/dialect/phi/phi_base.h" +#include "paddle/infrt/dialect/phi/ir/phi_base.h" #include #include @@ -21,8 +21,8 @@ #include #include #include "paddle/infrt/common/global.h" -#include "paddle/infrt/dialect/phi/infrt_phi_base.cpp.inc" -#include "paddle/infrt/dialect/phi/infrt_phi_baseDialect.cpp.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_base.cpp.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_baseDialect.cpp.inc" namespace infrt { namespace phi { @@ -51,11 +51,11 @@ void PHIDialect::printType(::mlir::Type type, void PHIDialect::initialize() { addOperations< #define GET_OP_LIST -#include "paddle/infrt/dialect/phi/infrt_phi_base.cpp.inc" // NOLINT +#include "paddle/infrt/dialect/phi/ir/infrt_phi_base.cpp.inc" // NOLINT >(); addTypes< #define GET_TYPEDEF_LIST -#include "paddle/infrt/dialect/phi/infrt_phi_baseTypes.cpp.inc" // NOLINT +#include "paddle/infrt/dialect/phi/ir/infrt_phi_baseTypes.cpp.inc" // NOLINT >(); } @@ -81,4 +81,4 @@ mlir::Type PHIDialect::parseType(mlir::DialectAsmParser& parser) const { } // namespace infrt #define GET_TYPEDEF_CLASSES -#include "paddle/infrt/dialect/phi/infrt_phi_baseTypes.cpp.inc" // NOLINT +#include "paddle/infrt/dialect/phi/ir/infrt_phi_baseTypes.cpp.inc" // NOLINT diff --git a/paddle/infrt/dialect/phi/phi_base.h b/paddle/infrt/dialect/phi/ir/phi_base.h similarity index 84% rename from paddle/infrt/dialect/phi/phi_base.h rename to paddle/infrt/dialect/phi/ir/phi_base.h index 11174290f9..a08d8229fc 100644 --- a/paddle/infrt/dialect/phi/phi_base.h +++ b/paddle/infrt/dialect/phi/ir/phi_base.h @@ -19,11 +19,13 @@ #include -#include "paddle/infrt/dialect/phi/infrt_phi_base.h.inc" -#include "paddle/infrt/dialect/phi/infrt_phi_baseDialect.h.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_baseDialect.h.inc" #define GET_TYPEDEF_CLASSES -#include "paddle/infrt/dialect/phi/infrt_phi_baseTypes.h.inc" +#include "paddle/infrt/dialect/phi/ir/infrt_phi_baseTypes.h.inc" + +#define GET_OP_CLASSES +#include "paddle/infrt/dialect/phi/ir/infrt_phi_base.h.inc" namespace mlir { namespace OpTrait { -- GitLab