From dbbdfea95bf2c4c6f3af43bd287dd2e94b61e277 Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Wed, 2 Dec 2020 11:38:26 -0800 Subject: [PATCH] [MLIR:HLO] Generate enum decls for HLO and LHLO GPU dialects. - Split out enum definitions in hlo dialect into a separate .td file (similar to structs) and generate enum decl/defs for these enums. - Also split out the LHLO GPU enums into a separate .td file and generate enum decl/defs for these enums as well. - Remove unused dialect from ConvolutionAttributes and generate lhlo_gpu enums. - Add appropriate namespace for all the enums. PiperOrigin-RevId: 345277240 --- .../mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt | 5 + include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h | 1 + include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td | 6 +- .../mlir-hlo/Dialect/mhlo/IR/hlo_ops_base.td | 100 ++------------- .../Dialect/mhlo/IR/hlo_ops_base_enums.h | 29 +++++ .../Dialect/mhlo/IR/hlo_ops_base_enums.td | 119 ++++++++++++++++++ .../mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.h | 1 + .../mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.td | 20 +-- .../Dialect/mhlo/IR/lhlo_gpu_ops_enums.h | 29 +++++ .../Dialect/mhlo/IR/lhlo_gpu_ops_enums.td | 37 ++++++ .../Dialect/mhlo/IR/lhlo_gpu_ops_structs.td | 1 - include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td | 2 +- lib/Dialect/mhlo/IR/CMakeLists.txt | 2 + lib/Dialect/mhlo/IR/hlo_ops_base_enums.cc | 18 +++ lib/Dialect/mhlo/IR/lhlo_gpu_ops_enums.cc | 18 +++ 15 files changed, 274 insertions(+), 114 deletions(-) create mode 100644 include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h create mode 100644 include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.td create mode 100644 include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h create mode 100644 include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.td create mode 100644 lib/Dialect/mhlo/IR/hlo_ops_base_enums.cc create mode 100644 lib/Dialect/mhlo/IR/lhlo_gpu_ops_enums.cc diff --git a/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt b/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt index 3fa2b90..d64f7cc 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt +++ b/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt @@ -32,6 +32,8 @@ mlir_tablegen(hlo_ops.h.inc -gen-op-decls) mlir_tablegen(hlo_ops.cc.inc -gen-op-defs) mlir_tablegen(hlo_ops_base_structs.h.inc -gen-struct-attr-decls) mlir_tablegen(hlo_ops_base_structs.cc.inc -gen-struct-attr-defs) +mlir_tablegen(hlo_ops_base_enums.h.inc -gen-enum-decls) +mlir_tablegen(hlo_ops_base_enums.cc.inc -gen-enum-defs) add_public_tablegen_target(MLIRhlo_opsIncGen) set(LLVM_TARGET_DEFINITIONS lhlo_gpu_ops.td) @@ -40,6 +42,9 @@ mlir_tablegen(lhlo_gpu_ops.cc.inc -gen-op-defs) set(LLVM_TARGET_DEFINITIONS lhlo_gpu_ops_structs.td) mlir_tablegen(lhlo_gpu_ops_structs.h.inc -gen-struct-attr-decls) mlir_tablegen(lhlo_gpu_ops_structs.cc.inc -gen-struct-attr-defs) +set(LLVM_TARGET_DEFINITIONS lhlo_gpu_ops_enums.td) +mlir_tablegen(lhlo_gpu_ops_enums.h.inc -gen-enum-decls) +mlir_tablegen(lhlo_gpu_ops_enums.cc.inc -gen-enum-defs) add_public_tablegen_target(MLIRlhlo_gpu_opsIncGen) add_dependencies(mlir-headers MLIRlhlo_gpu_opsIncGen) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h index b354189..9bba3d3 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h @@ -34,6 +34,7 @@ limitations under the License. // clang-format off #include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_structs.h" +#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h" #include "mlir-hlo/Dialect/mhlo/IR/infer_fusibility_op_interface.h" // clang-format on diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td index dd6d3b3..cfe4da7 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td @@ -41,7 +41,9 @@ def HLO_OUTPUT_FUSION : StrEnumAttrCase<"kOutput">; def HLO_CUSTOM_FUSION : StrEnumAttrCase<"kCustom">; def HLO_FusionKindAttr : StrEnumAttr<"FusionKind", "fusion kind", [ HLO_LOOP_FUSION, HLO_INPUT_FUSION, HLO_OUTPUT_FUSION, HLO_CUSTOM_FUSION -]>; +]> { + let cppNamespace = "::mlir::mhlo"; +} //===----------------------------------------------------------------------===// // MHLO nullary op definitions. @@ -896,7 +898,7 @@ def HLO_ConvOp : HLO_Op<"convolution", [NoSideEffect]>, BASE_HLO_ConvOp { (ins HLO_Tensor:$lhs, HLO_Tensor:$rhs), - ConvolutionAttributes.attributes); + ConvolutionAttributes.attributes); let results = (outs HLO_Tensor); } diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base.td b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base.td index 572a2f9..9b1b126 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base.td @@ -23,6 +23,7 @@ def HLO_Dialect : Dialect { let cppNamespace = "::mlir::mhlo"; } +include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.td" include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_structs.td" def HLO_Pred : TypeAlias; @@ -692,77 +693,7 @@ class BASE_HLO_TupleOp { }]; } -//===----------------------------------------------------------------------===// -// Precision Config enum definitions. -//===----------------------------------------------------------------------===// -// These mirror the XLA PrecisionConfig proto enum. -def HLO_PRECISION_DEFAULT : StrEnumAttrCase<"DEFAULT">; -def HLO_PRECISION_HIGH : StrEnumAttrCase<"HIGH">; -def HLO_PRECISION_HIGHEST : StrEnumAttrCase<"HIGHEST">; - -def HLO_PrecisionAttr : StrEnumAttr<"Precision", - "XLA precision for an operand. Has backend specific meaning.", - [HLO_PRECISION_DEFAULT, HLO_PRECISION_HIGH, HLO_PRECISION_HIGHEST]>; - -// TODO(b/129153247) See if it's possible to also validate the size. -def HLO_PrecisionConfigAttr: - OptionalAttr< - TypedArrayAttrBase>; - - -//===----------------------------------------------------------------------===// -// Fast Fourier Transform Type enum definitions. -//===----------------------------------------------------------------------===// - -// These mirror the XLA FftType proto enum. -def HLO_FFT_TYPE_FFT : StrEnumAttrCase<"FFT">; -def HLO_FFT_TYPE_IFFT : StrEnumAttrCase<"IFFT">; -def HLO_FFT_TYPE_RFFT : StrEnumAttrCase<"RFFT">; -def HLO_FFT_TYPE_IRFFT : StrEnumAttrCase<"IRFFT">; - -def HLO_FftTypeAttr : StrEnumAttr<"FftType", - "XLA fast fourier transform type.", - [HLO_FFT_TYPE_FFT, HLO_FFT_TYPE_IFFT, - HLO_FFT_TYPE_RFFT, HLO_FFT_TYPE_IRFFT]>; - -//===----------------------------------------------------------------------===// -// Comparison op definitions. -//===----------------------------------------------------------------------===// - -// These mirror the XLA ComparisonDirection enum. -def HLO_COMPARISON_DIRECTION_EQ : StrEnumAttrCase<"EQ">; -def HLO_COMPARISON_DIRECTION_NE : StrEnumAttrCase<"NE">; -def HLO_COMPARISON_DIRECTION_GE : StrEnumAttrCase<"GE">; -def HLO_COMPARISON_DIRECTION_GT : StrEnumAttrCase<"GT">; -def HLO_COMPARISON_DIRECTION_LE : StrEnumAttrCase<"LE">; -def HLO_COMPARISON_DIRECTION_LT : StrEnumAttrCase<"LT">; - -def HLO_ComparisonDirectionAttr : StrEnumAttr<"ComparisonDirection", - "Which comparison operation to perform.", - [ - HLO_COMPARISON_DIRECTION_EQ, - HLO_COMPARISON_DIRECTION_NE, - HLO_COMPARISON_DIRECTION_GE, - HLO_COMPARISON_DIRECTION_GT, - HLO_COMPARISON_DIRECTION_LE, - HLO_COMPARISON_DIRECTION_LT - ]>; - -def HLO_DEFAULT_COMPARISON_TYPE : NativeCodeCall<"StringAttr()">; -def HLO_COMPARISON_TYPE_FLOAT : StrEnumAttrCase<"FLOAT">; -def HLO_COMPARISON_TYPE_FLOAT_TOTAL_ORDER : StrEnumAttrCase<"TOTALORDER">; -def HLO_COMPARISON_TYPE_SIGNED : StrEnumAttrCase<"SIGNED">; -def HLO_COMPARISON_TYPE_UNSIGNED : StrEnumAttrCase<"UNSIGNED">; - -def HLO_ComparisonTypeAttr : StrEnumAttr<"ComparisonType", - "Which comparison type to use.", - [ - HLO_COMPARISON_TYPE_FLOAT, - HLO_COMPARISON_TYPE_FLOAT_TOTAL_ORDER, - HLO_COMPARISON_TYPE_SIGNED, - HLO_COMPARISON_TYPE_UNSIGNED - ]>; class BASE_HLO_CompareOp { @@ -783,13 +714,6 @@ class BASE_HLO_CompareOp { // Quantize op definitions. //===----------------------------------------------------------------------===// -// These mirror the XLA ComparisonDirection enum. -def HLO_MIN_COMBINED : StrEnumAttrCase<"MIN_COMBINED">; - -def HLO_DequantizeModeAttr : StrEnumAttr<"DequantizeMode", - "Dequantization mode. Only MIN_COMBINED is supported.", - [HLO_MIN_COMBINED]>; - class BASE_HLO_DequantizeOp { string summary = "Dequantize operator"; @@ -1029,7 +953,12 @@ class BASE_HLO_ConcatenateOp { // Common convolution attributes //===----------------------------------------------------------------------===// -class ConvolutionAttributes { +// TODO(b/129153247) See if it's possible to also validate the size. +def HLO_PrecisionConfigAttr: + OptionalAttr< + TypedArrayAttrBase>; + +def ConvolutionAttributes { dag attributes = (ins // Default value: one for each of the spatial dimension. OptionalAttr:$window_strides, @@ -1270,21 +1199,6 @@ class BASE_HLO_TransposeOp { }]; } -// These mirror the XLA Transpose enum in Triangular Solve options. -def HLO_TRANSPOSE_INVALID : StrEnumAttrCase<"TRANSPOSE_INVALID">; -def HLO_NO_TRANSPOSE : StrEnumAttrCase<"NO_TRANSPOSE">; -def HLO_TRANSPOSE : StrEnumAttrCase<"TRANSPOSE">; -def HLO_ADJOINT : StrEnumAttrCase<"ADJOINT">; - -def HLO_TransposeAttr : StrEnumAttr<"Transpose", - "Transpose options", - [ - HLO_TRANSPOSE_INVALID, - HLO_NO_TRANSPOSE, - HLO_TRANSPOSE, - HLO_ADJOINT - ]>; - class BASE_HLO_TriangularSolveOp { string summary = "TriangularSolve operator"; diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h new file mode 100644 index 0000000..38414b4 --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h @@ -0,0 +1,29 @@ +/* Copyright 2020 The TensorFlow 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. +==============================================================================*/ + +// This file defines enums used in MHLO and LMHLO. +#ifndef TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_HLO_OPS_BASE_ENUMS_H_ +#define TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_HLO_OPS_BASE_ENUMS_H_ + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" + +// Order matters, this .inc header is not self-contained, and relies on the +// #includes above. + +#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h.inc" + +#endif // TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_HLO_OPS_BASE_ENUMS_H_ diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.td b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.td new file mode 100644 index 0000000..eb1830a --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.td @@ -0,0 +1,119 @@ +/* Copyright 2020 The TensorFlow 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. +==============================================================================*/ + +#ifndef HLO_OPS_BASE_ENUMS +#define HLO_OPS_BASE_ENUMS + +//===----------------------------------------------------------------------===// +// Precision Config enum definitions. +//===----------------------------------------------------------------------===// + +// These mirror the XLA PrecisionConfig proto enum. +def HLO_PRECISION_DEFAULT : StrEnumAttrCase<"DEFAULT">; +def HLO_PRECISION_HIGH : StrEnumAttrCase<"HIGH">; +def HLO_PRECISION_HIGHEST : StrEnumAttrCase<"HIGHEST">; + +def HLO_PrecisionAttr : StrEnumAttr<"Precision", + "XLA precision for an operand. Has backend specific meaning.", + [HLO_PRECISION_DEFAULT, HLO_PRECISION_HIGH, HLO_PRECISION_HIGHEST]> { + let cppNamespace = "::mlir::mhlo"; +} + +//===----------------------------------------------------------------------===// +// Fast Fourier Transform Type enum definitions. +//===----------------------------------------------------------------------===// + +// These mirror the XLA FftType proto enum. +def HLO_FFT_TYPE_FFT : StrEnumAttrCase<"FFT">; +def HLO_FFT_TYPE_IFFT : StrEnumAttrCase<"IFFT">; +def HLO_FFT_TYPE_RFFT : StrEnumAttrCase<"RFFT">; +def HLO_FFT_TYPE_IRFFT : StrEnumAttrCase<"IRFFT">; + +def HLO_FftTypeAttr : StrEnumAttr<"FftType", + "XLA fast fourier transform type.", + [HLO_FFT_TYPE_FFT, HLO_FFT_TYPE_IFFT, + HLO_FFT_TYPE_RFFT, HLO_FFT_TYPE_IRFFT]> { + let cppNamespace = "::mlir::mhlo"; +} + +//===----------------------------------------------------------------------===// +// Comparison op definitions. +//===----------------------------------------------------------------------===// + +// These mirror the XLA ComparisonDirection enum. +def HLO_COMPARISON_DIRECTION_EQ : StrEnumAttrCase<"EQ">; +def HLO_COMPARISON_DIRECTION_NE : StrEnumAttrCase<"NE">; +def HLO_COMPARISON_DIRECTION_GE : StrEnumAttrCase<"GE">; +def HLO_COMPARISON_DIRECTION_GT : StrEnumAttrCase<"GT">; +def HLO_COMPARISON_DIRECTION_LE : StrEnumAttrCase<"LE">; +def HLO_COMPARISON_DIRECTION_LT : StrEnumAttrCase<"LT">; + +def HLO_ComparisonDirectionAttr : StrEnumAttr<"ComparisonDirection", + "Which comparison operation to perform.", + [ + HLO_COMPARISON_DIRECTION_EQ, + HLO_COMPARISON_DIRECTION_NE, + HLO_COMPARISON_DIRECTION_GE, + HLO_COMPARISON_DIRECTION_GT, + HLO_COMPARISON_DIRECTION_LE, + HLO_COMPARISON_DIRECTION_LT + ]> { + let cppNamespace = "::mlir::mhlo"; +} + +def HLO_DEFAULT_COMPARISON_TYPE : NativeCodeCall<"StringAttr()">; +def HLO_COMPARISON_TYPE_FLOAT : StrEnumAttrCase<"FLOAT">; +def HLO_COMPARISON_TYPE_FLOAT_TOTAL_ORDER : StrEnumAttrCase<"TOTALORDER">; +def HLO_COMPARISON_TYPE_SIGNED : StrEnumAttrCase<"SIGNED">; +def HLO_COMPARISON_TYPE_UNSIGNED : StrEnumAttrCase<"UNSIGNED">; + +def HLO_ComparisonTypeAttr : StrEnumAttr<"ComparisonType", + "Which comparison type to use.", + [ + HLO_COMPARISON_TYPE_FLOAT, + HLO_COMPARISON_TYPE_FLOAT_TOTAL_ORDER, + HLO_COMPARISON_TYPE_SIGNED, + HLO_COMPARISON_TYPE_UNSIGNED + ]> { + let cppNamespace = "::mlir::mhlo"; +} + +// These mirror the XLA Dequantize mode string enum. +def HLO_MIN_COMBINED : StrEnumAttrCase<"MIN_COMBINED">; + +def HLO_DequantizeModeAttr : StrEnumAttr<"DequantizeMode", + "Dequantization mode. Only MIN_COMBINED is supported.", + [HLO_MIN_COMBINED]> { + let cppNamespace = "::mlir::mhlo"; +} + +// These mirror the XLA Transpose enum in Triangular Solve options. +def HLO_TRANSPOSE_INVALID : StrEnumAttrCase<"TRANSPOSE_INVALID">; +def HLO_NO_TRANSPOSE : StrEnumAttrCase<"NO_TRANSPOSE">; +def HLO_TRANSPOSE : StrEnumAttrCase<"TRANSPOSE">; +def HLO_ADJOINT : StrEnumAttrCase<"ADJOINT">; + +def HLO_TransposeAttr : StrEnumAttr<"Transpose", + "Transpose options", + [ + HLO_TRANSPOSE_INVALID, + HLO_NO_TRANSPOSE, + HLO_TRANSPOSE, + HLO_ADJOINT + ]> { + let cppNamespace = "::mlir::mhlo"; +} + +#endif // HLO_OPS_BASE_ENUMS diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.h b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.h index effa9ec..92b7f63 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.h +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.h @@ -22,6 +22,7 @@ limitations under the License. #include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.h" #include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_structs.h" #include "mlir-hlo/Dialect/mhlo/IR/infer_fusibility_op_interface.h" +#include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h" #include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_structs.h" #include "mlir/IR/Attributes.h" #include "mlir/IR/Dialect.h" diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.td index f4f2d85..21a25fb 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops.td @@ -23,9 +23,9 @@ include "mlir/IR/OpBase.td" include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir-hlo/Dialect/mhlo/IR/lhlo_ops_base.td" include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_base.td" +include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.td" include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_structs.td" - class LHLOGPU_Op traits = []> : Op], traits)>; @@ -92,30 +92,16 @@ def LHLOGPU_BatchNormTrainingOp : LHLOGPU_Op<"batch_norm_training">, // LMHLO ops representing convolution library functions. //===----------------------------------------------------------------------===// -def ActivationModeNone : StrEnumAttrCase<"None">; -def ActivationModeSigmoid : StrEnumAttrCase<"Sigmoid">; -def ActivationModeTanh : StrEnumAttrCase<"Relu">; -def ActivationModeRelu : StrEnumAttrCase<"Relu">; -def ActivationModeRelu6 : StrEnumAttrCase<"Relu6">; -def ActivationModeReluX : StrEnumAttrCase<"ReluX">; -def ActivationModeBandPass : StrEnumAttrCase<"BandPass">; - -def ActivationAttr : StrEnumAttr<"Activation", - "Activation applied with fused convolution", - [ActivationModeNone, ActivationModeSigmoid, ActivationModeTanh, - ActivationModeRelu, ActivationModeRelu6, ActivationModeReluX, - ActivationModeBandPass]>; - def GpuConvolutionAttributes { dag attributes = !con( - ConvolutionAttributes.attributes, + ConvolutionAttributes.attributes, (ins F64Attr:$result_scale), (ins ConvolutionBackendConfigAttr:$backend_config)); } def GpuFusedConvolutionAttributes { dag attributes = !con( - ConvolutionAttributes.attributes, + ConvolutionAttributes.attributes, (ins F64Attr:$result_scale, ActivationAttr:$activation_mode, F64Attr:$side_input_scale), diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h new file mode 100644 index 0000000..f8c996f --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h @@ -0,0 +1,29 @@ +/* Copyright 2020 The TensorFlow 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. + * ==============================================================================*/ + +// This file defines enums used in the LMHLO_GPU dialect. + +#ifndef TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_LHLO_GPU_OPS_ENUMS_H_ +#define TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_LHLO_GPU_OPS_ENUMS_H_ + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" + +// Order matters, this .inc header is not self-contained, and relies on the +// #includes above. +#include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h.inc" + +#endif // TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_LHLO_GPU_OPS_ENUMS_H_ diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.td b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.td new file mode 100644 index 0000000..15f9ed6 --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.td @@ -0,0 +1,37 @@ +/* Copyright 2020 The TensorFlow 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. +==============================================================================*/ + +#ifndef LHLO_GPU_OPS_ENUMS +#define LHLO_GPU_OPS_ENUMS + +include "mlir/IR/OpBase.td" + +def ActivationModeNone : StrEnumAttrCase<"None">; +def ActivationModeSigmoid : StrEnumAttrCase<"Sigmoid">; +def ActivationModeTanh : StrEnumAttrCase<"Tanh">; +def ActivationModeRelu : StrEnumAttrCase<"Relu">; +def ActivationModeRelu6 : StrEnumAttrCase<"Relu6">; +def ActivationModeReluX : StrEnumAttrCase<"ReluX">; +def ActivationModeBandPass : StrEnumAttrCase<"BandPass">; + +def ActivationAttr : StrEnumAttr<"Activation", + "Activation applied with fused convolution", + [ActivationModeNone, ActivationModeSigmoid, ActivationModeTanh, + ActivationModeRelu, ActivationModeRelu6, ActivationModeReluX, + ActivationModeBandPass]> { + let cppNamespace = "::mlir::lmhlo_gpu"; +} + +#endif // LHLO_GPU_OPS_ENUMS diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_structs.td b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_structs.td index 2236fc3..2bf93f7 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_structs.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_structs.td @@ -1,4 +1,3 @@ - /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td index 7d862ab..47b100a 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td @@ -415,7 +415,7 @@ def LHLO_ConvOp : LHLO_Op<"convolution", []>, BASE_HLO_ConvOp { Arg:$lhs, Arg:$rhs, Arg:$output), - ConvolutionAttributes.attributes); + ConvolutionAttributes.attributes); } def LHLO_CopyOp: LHLO_Op<"copy", [CopyOpInterface]>, BASE_HLO_CopyOp { diff --git a/lib/Dialect/mhlo/IR/CMakeLists.txt b/lib/Dialect/mhlo/IR/CMakeLists.txt index 7c0c11b..98983e7 100644 --- a/lib/Dialect/mhlo/IR/CMakeLists.txt +++ b/lib/Dialect/mhlo/IR/CMakeLists.txt @@ -44,6 +44,7 @@ add_mlir_library(MhloInferFusibilityOpInterface add_mlir_dialect_library(MhloDialect hlo_ops.cc hlo_ops_base_structs.cc + hlo_ops_base_enums.cc DEPENDS MLIRhlo_opsIncGen @@ -70,6 +71,7 @@ target_link_libraries(LmhloDialect PUBLIC MLIRIR) add_mlir_dialect_library(LmhloGPUDialect lhlo_gpu_ops.cc lhlo_gpu_ops_structs.cc + lhlo_gpu_ops_enums.cc DEPENDS MLIRlhlo_gpu_opsIncGen diff --git a/lib/Dialect/mhlo/IR/hlo_ops_base_enums.cc b/lib/Dialect/mhlo/IR/hlo_ops_base_enums.cc new file mode 100644 index 0000000..c71edf9 --- /dev/null +++ b/lib/Dialect/mhlo/IR/hlo_ops_base_enums.cc @@ -0,0 +1,18 @@ +/* Copyright 2020 The TensorFlow 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 "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.h" + +#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base_enums.cc.inc" diff --git a/lib/Dialect/mhlo/IR/lhlo_gpu_ops_enums.cc b/lib/Dialect/mhlo/IR/lhlo_gpu_ops_enums.cc new file mode 100644 index 0000000..23df0e9 --- /dev/null +++ b/lib/Dialect/mhlo/IR/lhlo_gpu_ops_enums.cc @@ -0,0 +1,18 @@ +/* Copyright 2020 The TensorFlow 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 "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.h" + +#include "mlir-hlo/Dialect/mhlo/IR/lhlo_gpu_ops_enums.cc.inc"