diff --git a/mlir/include/mlir/Dialect/CMakeLists.txt b/mlir/include/mlir/Dialect/CMakeLists.txt --- a/mlir/include/mlir/Dialect/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/CMakeLists.txt @@ -8,4 +8,5 @@ add_subdirectory(QuantOps) add_subdirectory(SPIRV) add_subdirectory(StandardOps) +add_subdirectory(Targets) add_subdirectory(VectorOps) diff --git a/mlir/include/mlir/Dialect/Targets/AVX512/AVX512Dialect.h b/mlir/include/mlir/Dialect/Targets/AVX512/AVX512Dialect.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Targets/AVX512/AVX512Dialect.h @@ -0,0 +1,35 @@ +//===- AVX512Dialect.h - MLIR Dialect for OpenMP ----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares the Target dialect for AVX512 in MLIR. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_TARGETS_AVX512_AVX512DIALECT_H_ +#define MLIR_DIALECT_TARGETS_AVX512_AVX512DIALECT_H_ + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + +namespace mlir { +namespace avx512 { + +#define GET_OP_CLASSES +#include "mlir/Dialect/Targets/AVX512/AVX512Ops.h.inc" + +class AVX512Dialect : public Dialect { +public: + explicit AVX512Dialect(MLIRContext *context); + + static StringRef getDialectNamespace() { return "avx512"; } +}; + +} // namespace avx512 +} // namespace mlir + +#endif // MLIR_DIALECT_TARGETS_AVX512_AVX512DIALECT_H_ diff --git a/mlir/include/mlir/Dialect/Targets/AVX512/AVX512Ops.td b/mlir/include/mlir/Dialect/Targets/AVX512/AVX512Ops.td new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Targets/AVX512/AVX512Ops.td @@ -0,0 +1,42 @@ +//===-- AVX512Ops.td - AVX512 dialect operation definitions *- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the basic operations for the AVX512 dialect. +// +//===----------------------------------------------------------------------===// + + +#ifndef AVX512_OPS +#define AVX512_OPS + +include "mlir/IR/OpBase.td" + +def AVX512_Dialect : Dialect { + let name = "avx512"; +} + +class AVX512_Op traits = []> : + Op {} + +def ExpP5ScaleOp : AVX512_Op<"exp_p5_scale", [NoSideEffect, + AllTypesMatch<["source", "result"]>]>, + // Supports either vector<16xf32> or vector<8xf64>. + Arguments<(ins VectorOfLengthAndType<[16], [F32]>:$source)>, + Results<(outs VectorOfLengthAndType<[16], [F32]>:$result)> { + let summary = "exp_p5_scale Op"; + let description = [{ + The exp_p5_scale constructs a degree-5 polynomial approximation for exp(t) + on [-log(2)/2, log(2)/2]. It corresponds to the XNNPack function + [xnn_math_f32_exp__avx512f_p5_scalef](https://github.com/google/XNNPACK/blob/master/src/math/exp-avx512f-p5-scalef.c). + }]; + // Fully specified by traits. + let verifier = ?; + let assemblyFormat = "$source attr-dict `:` type($source)"; +} + +#endif // AVX512_OPS diff --git a/mlir/include/mlir/Dialect/Targets/AVX512/CMakeLists.txt b/mlir/include/mlir/Dialect/Targets/AVX512/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Targets/AVX512/CMakeLists.txt @@ -0,0 +1 @@ +add_mlir_dialect(AVX512Ops AVX512Ops) diff --git a/mlir/include/mlir/Dialect/Targets/CMakeLists.txt b/mlir/include/mlir/Dialect/Targets/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Targets/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(AVX512) diff --git a/mlir/lib/Dialect/CMakeLists.txt b/mlir/lib/Dialect/CMakeLists.txt --- a/mlir/lib/Dialect/CMakeLists.txt +++ b/mlir/lib/Dialect/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory(SDBM) add_subdirectory(SPIRV) add_subdirectory(StandardOps) +add_subdirectory(Targets) add_subdirectory(VectorOps) add_llvm_library(MLIRDialect diff --git a/mlir/lib/Dialect/Targets/AVX512/AVX512Ops.cpp b/mlir/lib/Dialect/Targets/AVX512/AVX512Ops.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/Targets/AVX512/AVX512Ops.cpp @@ -0,0 +1,37 @@ +//===- AVX512Dialect.cpp - MLIR Dialect for AVX512 implementation ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements the AVX512 dialect and its operations. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/Targets/AVX512/AVX512Dialect.h" +#include "mlir/Dialect/VectorOps/VectorOps.h" +#include "mlir/IR/OpImplementation.h" +#include "mlir/IR/TypeUtilities.h" + +using namespace mlir; +using namespace mlir::avx512; + +AVX512Dialect::AVX512Dialect(MLIRContext *context) + : Dialect(getDialectNamespace(), context) { + addOperations< +#define GET_OP_LIST +#include "mlir/Dialect/Targets/AVX512/AVX512Ops.cpp.inc" + >(); +} + +namespace mlir { +namespace avx512 { +#define GET_OP_CLASSES +#include "mlir/Dialect/Targets/AVX512/AVX512Ops.cpp.inc" +} // namespace avx512 +} // namespace mlir + +// Static initialization for AVX512Ops dialect registration. +static DialectRegistration avx512Ops; diff --git a/mlir/lib/Dialect/Targets/AVX512/CMakeLists.txt b/mlir/lib/Dialect/Targets/AVX512/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/Targets/AVX512/CMakeLists.txt @@ -0,0 +1,8 @@ +add_llvm_library(MLIRAVX512Ops + AVX512Ops.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Targets/AVX512 + ) + +add_dependencies(MLIRAVX512Ops MLIRAVX512OpsIncGen) diff --git a/mlir/lib/Dialect/Targets/CMakeLists.txt b/mlir/lib/Dialect/Targets/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/Targets/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(AVX512) diff --git a/mlir/test/Dialect/Targets/AVX512/roundtrip.mlir b/mlir/test/Dialect/Targets/AVX512/roundtrip.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Dialect/Targets/AVX512/roundtrip.mlir @@ -0,0 +1,7 @@ +// RUN: mlir-opt -verify-diagnostics %s | mlir-opt | FileCheck %s + +func @avx512.exp_p5_scale(%a: vector<16xf32>) -> (vector<16xf32>) { + // CHECK: avx512.exp_p5_scale {{.*}}: vector<16xf32> + %0 = avx512.exp_p5_scale %a : vector<16xf32> + return %0: vector<16xf32> +} diff --git a/mlir/tools/mlir-opt/CMakeLists.txt b/mlir/tools/mlir-opt/CMakeLists.txt --- a/mlir/tools/mlir-opt/CMakeLists.txt +++ b/mlir/tools/mlir-opt/CMakeLists.txt @@ -22,6 +22,7 @@ MLIRAnalysis MLIRAffineOps MLIRAffineToStandard + MLIRAVX512Ops MLIRDialect MLIRLoopsToGPU MLIRLinalgToLLVM