Skip to content

Commit e0c9905

Browse files
committed
EISW-163564 Add CMake option to conditionally disable TosaToTensor conversion
1 parent a3c101e commit e0c9905

File tree

10 files changed

+732
-32
lines changed

10 files changed

+732
-32
lines changed

mlir/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ if(MLIR_DIALECT_XEGPU_ENABLE)
200200
add_compile_definitions(MLIR_DIALECT_XEGPU_ENABLE)
201201
endif()
202202

203+
# TosaToTensor Conversion Option (Default OFF)
204+
option(MLIR_CONVERSION_TOSATOTENSOR_ENABLE
205+
"Enable TosaToTensor conversion"
206+
OFF)
207+
208+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
209+
add_compile_definitions(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
210+
endif()
211+
203212
add_subdirectory(include/mlir)
204213
add_subdirectory(lib)
205214
# C API needs all dialects for registration, but should be built before tests.

mlir/include/mlir/Conversion/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix Conversion)
66
add_public_tablegen_target(MLIRConversionPassIncGen)
77

88
add_mlir_doc(Passes ConversionPasses ./ -gen-pass-doc)
9+
10+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
11+
add_subdirectory(TosaToTensor)
12+
endif()

mlir/include/mlir/Conversion/Passes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
#include "mlir/Conversion/TosaToLinalg/TosaToLinalg.h"
7171
#include "mlir/Conversion/TosaToMLProgram/TosaToMLProgram.h"
7272
#include "mlir/Conversion/TosaToSCF/TosaToSCF.h"
73-
/* #include "mlir/Conversion/TosaToTensor/TosaToTensor.h" */
73+
#ifdef MLIR_CONVERSION_TOSATOTENSOR_ENABLE
74+
#include "mlir/Conversion/TosaToTensor/TosaToTensor.h"
75+
#endif
7476
#include "mlir/Conversion/UBToLLVM/UBToLLVM.h"
7577
#include "mlir/Conversion/UBToSPIRV/UBToSPIRV.h"
7678
#include "mlir/Conversion/VectorToArmSME/VectorToArmSME.h"

mlir/include/mlir/Conversion/Passes.td

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,19 +1215,20 @@ def TosaToSCF : Pass<"tosa-to-scf"> {
12151215
//===----------------------------------------------------------------------===//
12161216
// TosaToTensor
12171217
//===----------------------------------------------------------------------===//
1218+
#ifdef MLIR_CONVERSION_TOSATOTENSOR_ENABLE
1219+
def TosaToTensor : Pass<"tosa-to-tensor"> {
1220+
let summary = "Lower TOSA to the Tensor dialect";
1221+
let dependentDialects = [
1222+
"tensor::TensorDialect",
1223+
];
1224+
let description = [{
1225+
Pass that converts TOSA operations to the equivalent operations using the
1226+
operations in the Tensor dialect.
1227+
}];
12181228

1219-
// def TosaToTensor : Pass<"tosa-to-tensor"> {
1220-
// let summary = "Lower TOSA to the Tensor dialect";
1221-
// let dependentDialects = [
1222-
// "tensor::TensorDialect",
1223-
// ];
1224-
// let description = [{
1225-
// Pass that converts TOSA operations to the equivalent operations using the
1226-
// operations in the Tensor dialect.
1227-
// }];
1228-
//
1229-
// let constructor = "tosa::createTosaToTensor()";
1230-
//}
1229+
let constructor = "tosa::createTosaToTensor()";
1230+
}
1231+
#endif
12311232

12321233
//===----------------------------------------------------------------------===//
12331234
// UBToLLVM
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
2+
set(LLVM_TARGET_DEFINITIONS Passes.td)
3+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name TosaToTensor)
4+
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix TosaToTensor)
5+
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix TosaToTensor)
6+
add_public_tablegen_target(MLIRTosaToTensorPassIncGen)
7+
endif()

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ add_subdirectory(TosaToArith)
7878
add_subdirectory(TosaToLinalg)
7979
add_subdirectory(TosaToMLProgram)
8080
add_subdirectory(TosaToSCF)
81-
# FIXME(askrebko): cannot be compiled: no conversion between ShapedType and TensorType
82-
# add_subdirectory(TosaToTensor)
81+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
82+
add_subdirectory(TosaToTensor)
83+
endif()
8384
add_subdirectory(UBToLLVM)
8485
add_subdirectory(UBToSPIRV)
8586
add_subdirectory(VectorToArmSME)
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
add_mlir_conversion_library(MLIRTosaToTensor
2-
TosaToTensor.cpp
3-
TosaToTensorPass.cpp
1+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
2+
add_mlir_conversion_library(MLIRTosaToTensor
3+
TosaToTensor.cpp
4+
TosaToTensorPass.cpp
45

5-
ADDITIONAL_HEADER_DIRS
6-
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Tosa
7-
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
6+
ADDITIONAL_HEADER_DIRS
7+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Tosa
8+
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
89

9-
DEPENDS
10-
MLIRConversionPassIncGen
10+
DEPENDS
11+
MLIRConversionPassIncGen
1112

12-
LINK_LIBS PUBLIC
13-
MLIRTensorDialect
14-
MLIRTensorUtils
15-
MLIRIR
16-
MLIRPass
17-
MLIRTosaDialect
18-
MLIRTosaTransforms
19-
MLIRSupport
20-
)
13+
LINK_LIBS PUBLIC
14+
MLIRTensorDialect
15+
MLIRTensorUtils
16+
MLIRIR
17+
MLIRPass
18+
MLIRTosaDialect
19+
MLIRTosaTransforms
20+
MLIRSupport
21+
)
22+
endif()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// REQUIRES: tosa-to-tensor-enabled
2+
// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-tensor))" %s -verify-diagnostics
3+
4+
// CHECK-LABEL: @slice_resultType_unranked
5+
func.func @slice_resultType_unranked(%arg0: tensor<?xf32>) -> (tensor<*xf32>) {
6+
// expected-error@+1 {{failed to legalize operation 'tosa.slice'}}
7+
%0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 0>} : (tensor<?xf32>) -> (tensor<*xf32>)
8+
return %0 : tensor<*xf32>
9+
}

0 commit comments

Comments
 (0)