From cfddeb6d999278ef90c28f6bb5ea2235b7d4a9f9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 4 Mar 2022 18:46:58 -0800 Subject: [PATCH] Integrate llvm-project and bump dependencies. (#8464) * Integrate llvm-project and bump dependencies. * llvm-project: 7c65d2288bfd03ca3c3e829c7746b5e4e495357f * mlir-hlo: a2c37922d79b4204e690c4815f92363de1ae0739 * tensorflow: e4c2068ee960f1f3a886af89a17c74b9b2c477c8 -Update StandardToSPIRV uses -Update linalg ext test due to new folding patterns --- integrations/tensorflow/WORKSPACE | 2 +- .../test/iree_linalgext/convert_to_loops.mlir | 30 +++++++------------ iree/compiler/Codegen/SPIRV/BUILD | 4 ++- iree/compiler/Codegen/SPIRV/CMakeLists.txt | 4 ++- .../Codegen/SPIRV/ConvertToSPIRVPass.cpp | 6 ++-- iree/tools/BUILD | 2 +- iree/tools/CMakeLists.txt | 2 +- iree/tools/init_mlir_passes.h | 3 +- .../test/iree_linalgext/convert_to_loops.mlir | 30 +++++++------------ third_party/llvm-project | 2 +- third_party/mlir-hlo | 2 +- 11 files changed, 39 insertions(+), 48 deletions(-) diff --git a/integrations/tensorflow/WORKSPACE b/integrations/tensorflow/WORKSPACE index 5a94c3651072..3de05c5ec075 100644 --- a/integrations/tensorflow/WORKSPACE +++ b/integrations/tensorflow/WORKSPACE @@ -7,7 +7,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -TENSORFLOW_COMMIT = "fddb6c72caa6a63ec86263a4d4230812c861cd10" +TENSORFLOW_COMMIT = "e4c2068ee960f1f3a886af89a17c74b9b2c477c8" git_repository( name = "org_tensorflow", diff --git a/integrations/tensorflow/iree-dialects/test/iree_linalgext/convert_to_loops.mlir b/integrations/tensorflow/iree-dialects/test/iree_linalgext/convert_to_loops.mlir index 0480823747e0..f4871a838af2 100644 --- a/integrations/tensorflow/iree-dialects/test/iree_linalgext/convert_to_loops.mlir +++ b/integrations/tensorflow/iree-dialects/test/iree_linalgext/convert_to_loops.mlir @@ -378,20 +378,16 @@ func @fft_1D(%real: memref<16xf32>, %imag: memref<16xf32>) { // CHECK-SAME: %[[IMAG:[a-zA-Z0-9]+]] // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index +// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index // CHECK-DAG: %[[C16:.+]] = arith.constant 16 : index -// CHECK-DAG: %[[SCALE:.+]] = arith.constant -6.28318548 : f32 -// CHECK-DAG: %[[NODE_RNG:.+]] = arith.shli %[[C1]], %[[C1]] : index -// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[NODE_RNG]] -// CHECK-DAG: %[[M:.+]] = arith.shli %[[C1]], %[[C1]] : index -// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[M]], %[[C1]] : index +// CHECK-DAG: %[[COEFF:.+]] = arith.constant -3.14159274 : f32 +// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[C2]] +// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[C2]], %[[C1]] : index // CHECK: %[[L_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[K]]] [%[[HM]]] [1] // CHECK: %[[L_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[K]]] [%[[HM]]] [1] // CHECK: %[[R_OFFSET:.+]] = arith.addi %[[K]], %[[HM]] : index // CHECK: %[[R_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[R_OFFSET]]] [%[[HM]]] [1] // CHECK: %[[R_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[R_OFFSET]]] [%[[HM]]] [1] -// CHECK: %[[M_I32:.+]] = arith.index_cast %[[M]] : index to i32 -// CHECK: %[[M_F32:.+]] = arith.sitofp %[[M_I32]] : i32 to f32 -// CHECK: %[[COEFF:.+]] = arith.divf %[[SCALE]], %[[M_F32]] // CHECK: linalg.generic // CHECK-SAME: indexing_maps = [#[[MAP1]], #[[MAP1]], #[[MAP1]], #[[MAP1]]] // CHECK-SAME: iterator_types = ["parallel"] @@ -402,7 +398,7 @@ func @fft_1D(%real: memref<16xf32>, %imag: memref<16xf32>) { // CHECK: %[[J_IDX:.+]] = linalg.index 0 : index // CHECK: %[[J_I32:.+]] = arith.index_cast %[[J_IDX]] : index to i32 // CHECK: %[[J_F32:.+]] = arith.sitofp %[[J_I32]] : i32 to f32 -// CHECK: %[[EXP_COEF:.+]] = arith.mulf %[[COEFF]], %[[J_F32]] : f32 +// CHECK: %[[EXP_COEF:.+]] = arith.mulf %[[J_F32]], %[[COEFF]] : f32 // CHECK: %[[W_REAL:.+]] = math.cos %[[EXP_COEF]] // CHECK: %[[W_IMAG:.+]] = math.sin %[[EXP_COEF]] // @@ -436,18 +432,16 @@ func @fft_2D(%real: memref, %imag: memref) { } // CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1)[s0] -> (d0 * 16 + s0 + d1)> // CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0, d1) -> (d0, d1)> -// CHECK: func @fft_2D +// CHECK: func @fft_2D( // CHECK-SAME: %[[REAL:[a-zA-Z0-9]+]] // CHECK-SAME: %[[IMAG:[a-zA-Z0-9]+]] // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index -// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index +// CHECK-DAG: %[[C4:.+]] = arith.constant 4 : index // CHECK-DAG: %[[D0:.+]] = memref.dim %[[REAL]], %[[C0]] : memref -// CHECK-DAG: %[[NODE_RNG:.+]] = arith.shli %[[C1]], %[[C2]] : index // CHECK: scf.for %[[I:.+]] = %[[C0]] to %[[D0]] step %[[C1]] -// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[NODE_RNG]] -// CHECK-DAG: %[[M:.+]] = arith.shli %[[C1]], %[[C2]] : index -// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[M]], %[[C1]] : index +// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[C4]] +// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[C4]], %[[C1]] : index // CHECK: %[[L_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[L_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[R_OFFSET:.+]] = arith.addi %[[K]], %[[HM]] : index @@ -483,11 +477,9 @@ func @fft_2D_coef_buf(%real: memref, %imag: memref, // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index // CHECK-DAG: %[[D0:.+]] = memref.dim %[[REAL]], %[[C0]] : memref -// CHECK-DAG: %[[NODE_RNG:.+]] = arith.shli %[[C1]], %[[C1]] : index // CHECK: scf.for %[[I:.+]] = %[[C0]] to %[[D0]] step %[[C1]] -// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[NODE_RNG]] -// CHECK-DAG: %[[M:.+]] = arith.shli %[[C1]], %[[C1]] : index -// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[M]], %[[C1]] : index +// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[C2]] +// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[C2]], %[[C1]] : index // CHECK: %[[L_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[L_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[R_OFFSET:.+]] = arith.addi %[[K]], %[[HM]] : index diff --git a/iree/compiler/Codegen/SPIRV/BUILD b/iree/compiler/Codegen/SPIRV/BUILD index 5f89cfa94b5a..bc8043f26515 100644 --- a/iree/compiler/Codegen/SPIRV/BUILD +++ b/iree/compiler/Codegen/SPIRV/BUILD @@ -57,8 +57,10 @@ cc_library( "@llvm-project//mlir:ArithmeticToSPIRV", "@llvm-project//mlir:ArithmeticTransforms", "@llvm-project//mlir:BufferizationDialect", + "@llvm-project//mlir:ControlFlowToSPIRV", "@llvm-project//mlir:DialectUtils", "@llvm-project//mlir:FuncDialect", + "@llvm-project//mlir:FuncToSPIRV", "@llvm-project//mlir:FuncTransforms", "@llvm-project//mlir:GPUDialect", "@llvm-project//mlir:GPUToSPIRV", @@ -79,8 +81,8 @@ cc_library( "@llvm-project//mlir:SPIRVDialect", "@llvm-project//mlir:SPIRVTransforms", "@llvm-project//mlir:SideEffectInterfaces", - "@llvm-project//mlir:StandardToSPIRV", "@llvm-project//mlir:Support", + "@llvm-project//mlir:TensorToSPIRV", "@llvm-project//mlir:TosaDialect", "@llvm-project//mlir:TosaToStandard", "@llvm-project//mlir:Transforms", diff --git a/iree/compiler/Codegen/SPIRV/CMakeLists.txt b/iree/compiler/Codegen/SPIRV/CMakeLists.txt index e2d3e4269ca1..a164446c5da8 100644 --- a/iree/compiler/Codegen/SPIRV/CMakeLists.txt +++ b/iree/compiler/Codegen/SPIRV/CMakeLists.txt @@ -47,7 +47,9 @@ iree_cc_library( MLIRArithmeticToSPIRV MLIRArithmeticTransforms MLIRBufferization + MLIRControlFlowToSPIRV MLIRFunc + MLIRFuncToSPIRV MLIRFuncTransforms MLIRGPUOps MLIRGPUToSPIRV @@ -68,8 +70,8 @@ iree_cc_library( MLIRSPIRVConversion MLIRSPIRVTransforms MLIRSideEffectInterfaces - MLIRStandardToSPIRV MLIRSupport + MLIRTensorToSPIRV MLIRTosa MLIRTosaToStandard MLIRTransforms diff --git a/iree/compiler/Codegen/SPIRV/ConvertToSPIRVPass.cpp b/iree/compiler/Codegen/SPIRV/ConvertToSPIRVPass.cpp index 4c430a4755f8..aec35ee8e159 100644 --- a/iree/compiler/Codegen/SPIRV/ConvertToSPIRVPass.cpp +++ b/iree/compiler/Codegen/SPIRV/ConvertToSPIRVPass.cpp @@ -27,11 +27,13 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Support/FormatVariadic.h" #include "mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h" +#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h" +#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h" #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h" #include "mlir/Conversion/MathToSPIRV/MathToSPIRV.h" #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h" #include "mlir/Conversion/SCFToSPIRV/SCFToSPIRV.h" -#include "mlir/Conversion/StandardToSPIRV/StandardToSPIRV.h" +#include "mlir/Conversion/TensorToSPIRV/TensorToSPIRV.h" #include "mlir/Conversion/TosaToStandard/TosaToStandard.h" #include "mlir/Conversion/VectorToSPIRV/VectorToSPIRV.h" #include "mlir/Dialect/Bufferization/IR/Bufferization.h" @@ -348,7 +350,7 @@ void ConvertToSPIRVPass::runOnOperation() { // Pull in standard/math patterns to convert arithmetic ops and others. arith::populateArithmeticToSPIRVPatterns(typeConverter, patterns); - populateStandardToSPIRVPatterns(typeConverter, patterns); + populateFuncToSPIRVPatterns(typeConverter, patterns); populateMathToSPIRVPatterns(typeConverter, patterns); // Pull in standard patterns to convert tensor operations to SPIR-V. These are diff --git a/iree/tools/BUILD b/iree/tools/BUILD index 01da9a301fe5..ba96d3f3652a 100644 --- a/iree/tools/BUILD +++ b/iree/tools/BUILD @@ -145,6 +145,7 @@ cc_library( "@llvm-project//mlir:ConversionPasses", "@llvm-project//mlir:EmitC", "@llvm-project//mlir:FuncDialect", + "@llvm-project//mlir:FuncToSPIRV", "@llvm-project//mlir:GPUDialect", "@llvm-project//mlir:GPUToSPIRV", "@llvm-project//mlir:GPUTransforms", @@ -164,7 +165,6 @@ cc_library( "@llvm-project//mlir:SPIRVDialect", "@llvm-project//mlir:SPIRVTransforms", "@llvm-project//mlir:Shape", - "@llvm-project//mlir:StandardToSPIRV", "@llvm-project//mlir:TensorInferTypeOpInterfaceImpl", "@llvm-project//mlir:Transforms", "@llvm-project//mlir:VectorOps", diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt index 63b778cd1caa..a2b3c0386d4d 100644 --- a/iree/tools/CMakeLists.txt +++ b/iree/tools/CMakeLists.txt @@ -288,7 +288,7 @@ if(${IREE_BUILD_COMPILER}) MLIRSPIRVTransforms MLIRShape MLIRFunc - MLIRStandardToSPIRV + MLIRFuncToSPIRV MLIRTensorInferTypeOpInterfaceImpl MLIRTosa MLIRTosaTransforms diff --git a/iree/tools/init_mlir_passes.h b/iree/tools/init_mlir_passes.h index 1569d68c7022..f880846502d5 100644 --- a/iree/tools/init_mlir_passes.h +++ b/iree/tools/init_mlir_passes.h @@ -82,7 +82,8 @@ inline void registerMlirPasses() { // SPIR-V spirv::registerSPIRVLowerABIAttributesPass(); registerConvertGPUToSPIRVPass(); - registerConvertStandardToSPIRVPass(); + registerConvertControlFlowToSPIRVPass(); + registerConvertFuncToSPIRVPass(); registerConvertLinalgToSPIRVPass(); // TOSA. diff --git a/llvm-external-projects/iree-dialects/test/iree_linalgext/convert_to_loops.mlir b/llvm-external-projects/iree-dialects/test/iree_linalgext/convert_to_loops.mlir index 0480823747e0..f4871a838af2 100644 --- a/llvm-external-projects/iree-dialects/test/iree_linalgext/convert_to_loops.mlir +++ b/llvm-external-projects/iree-dialects/test/iree_linalgext/convert_to_loops.mlir @@ -378,20 +378,16 @@ func @fft_1D(%real: memref<16xf32>, %imag: memref<16xf32>) { // CHECK-SAME: %[[IMAG:[a-zA-Z0-9]+]] // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index +// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index // CHECK-DAG: %[[C16:.+]] = arith.constant 16 : index -// CHECK-DAG: %[[SCALE:.+]] = arith.constant -6.28318548 : f32 -// CHECK-DAG: %[[NODE_RNG:.+]] = arith.shli %[[C1]], %[[C1]] : index -// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[NODE_RNG]] -// CHECK-DAG: %[[M:.+]] = arith.shli %[[C1]], %[[C1]] : index -// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[M]], %[[C1]] : index +// CHECK-DAG: %[[COEFF:.+]] = arith.constant -3.14159274 : f32 +// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[C2]] +// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[C2]], %[[C1]] : index // CHECK: %[[L_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[K]]] [%[[HM]]] [1] // CHECK: %[[L_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[K]]] [%[[HM]]] [1] // CHECK: %[[R_OFFSET:.+]] = arith.addi %[[K]], %[[HM]] : index // CHECK: %[[R_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[R_OFFSET]]] [%[[HM]]] [1] // CHECK: %[[R_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[R_OFFSET]]] [%[[HM]]] [1] -// CHECK: %[[M_I32:.+]] = arith.index_cast %[[M]] : index to i32 -// CHECK: %[[M_F32:.+]] = arith.sitofp %[[M_I32]] : i32 to f32 -// CHECK: %[[COEFF:.+]] = arith.divf %[[SCALE]], %[[M_F32]] // CHECK: linalg.generic // CHECK-SAME: indexing_maps = [#[[MAP1]], #[[MAP1]], #[[MAP1]], #[[MAP1]]] // CHECK-SAME: iterator_types = ["parallel"] @@ -402,7 +398,7 @@ func @fft_1D(%real: memref<16xf32>, %imag: memref<16xf32>) { // CHECK: %[[J_IDX:.+]] = linalg.index 0 : index // CHECK: %[[J_I32:.+]] = arith.index_cast %[[J_IDX]] : index to i32 // CHECK: %[[J_F32:.+]] = arith.sitofp %[[J_I32]] : i32 to f32 -// CHECK: %[[EXP_COEF:.+]] = arith.mulf %[[COEFF]], %[[J_F32]] : f32 +// CHECK: %[[EXP_COEF:.+]] = arith.mulf %[[J_F32]], %[[COEFF]] : f32 // CHECK: %[[W_REAL:.+]] = math.cos %[[EXP_COEF]] // CHECK: %[[W_IMAG:.+]] = math.sin %[[EXP_COEF]] // @@ -436,18 +432,16 @@ func @fft_2D(%real: memref, %imag: memref) { } // CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1)[s0] -> (d0 * 16 + s0 + d1)> // CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0, d1) -> (d0, d1)> -// CHECK: func @fft_2D +// CHECK: func @fft_2D( // CHECK-SAME: %[[REAL:[a-zA-Z0-9]+]] // CHECK-SAME: %[[IMAG:[a-zA-Z0-9]+]] // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index -// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index +// CHECK-DAG: %[[C4:.+]] = arith.constant 4 : index // CHECK-DAG: %[[D0:.+]] = memref.dim %[[REAL]], %[[C0]] : memref -// CHECK-DAG: %[[NODE_RNG:.+]] = arith.shli %[[C1]], %[[C2]] : index // CHECK: scf.for %[[I:.+]] = %[[C0]] to %[[D0]] step %[[C1]] -// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[NODE_RNG]] -// CHECK-DAG: %[[M:.+]] = arith.shli %[[C1]], %[[C2]] : index -// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[M]], %[[C1]] : index +// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[C4]] +// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[C4]], %[[C1]] : index // CHECK: %[[L_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[L_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[R_OFFSET:.+]] = arith.addi %[[K]], %[[HM]] : index @@ -483,11 +477,9 @@ func @fft_2D_coef_buf(%real: memref, %imag: memref, // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index // CHECK-DAG: %[[D0:.+]] = memref.dim %[[REAL]], %[[C0]] : memref -// CHECK-DAG: %[[NODE_RNG:.+]] = arith.shli %[[C1]], %[[C1]] : index // CHECK: scf.for %[[I:.+]] = %[[C0]] to %[[D0]] step %[[C1]] -// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[NODE_RNG]] -// CHECK-DAG: %[[M:.+]] = arith.shli %[[C1]], %[[C1]] : index -// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[M]], %[[C1]] : index +// CHECK: scf.for %[[K:.+]] = %[[C0]] to %[[C16]] step %[[C2]] +// CHECK-DAG: %[[HM:.+]] = arith.shrsi %[[C2]], %[[C1]] : index // CHECK: %[[L_REAL_SLICE:.+]] = memref.subview %[[REAL]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[L_IMAG_SLICE:.+]] = memref.subview %[[IMAG]][%[[I]], %[[K]]] [1, %[[HM]]] [1, 1] // CHECK: %[[R_OFFSET:.+]] = arith.addi %[[K]], %[[HM]] : index diff --git a/third_party/llvm-project b/third_party/llvm-project index eb27da7dec67..7c65d2288bfd 160000 --- a/third_party/llvm-project +++ b/third_party/llvm-project @@ -1 +1 @@ -Subproject commit eb27da7dec67f1a36505b589b786ba1a499c274a +Subproject commit 7c65d2288bfd03ca3c3e829c7746b5e4e495357f diff --git a/third_party/mlir-hlo b/third_party/mlir-hlo index 397198ab5352..a2c37922d79b 160000 --- a/third_party/mlir-hlo +++ b/third_party/mlir-hlo @@ -1 +1 @@ -Subproject commit 397198ab53521856c05a044432c923286ab02480 +Subproject commit a2c37922d79b4204e690c4815f92363de1ae0739