Skip to content

Commit

Permalink
Merge branch 'r2.13-rocm-enhanced-upate-llvm' into r2.13-rocm-enhance…
Browse files Browse the repository at this point in the history
…d-bitcodes-3
  • Loading branch information
ScXfjiang committed Nov 25, 2024
2 parents 16c671a + 0c08ddf commit 831b45a
Show file tree
Hide file tree
Showing 159 changed files with 10,874 additions and 5,135 deletions.
2 changes: 1 addition & 1 deletion build_rocm_python3
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ done
shift "$((OPTIND-1))"

# First positional argument (if any) specifies the ROCM_INSTALL_DIR
ROCM_INSTALL_DIR=/opt/rocm-6.0.0
ROCM_INSTALL_DIR=$(realpath /opt/rocm)
if [[ -n $1 ]]; then
ROCM_INSTALL_DIR=$1
fi
Expand Down
18 changes: 9 additions & 9 deletions tensorflow/compiler/mlir/lite/ir/tfl_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,9 @@ mlir::LogicalResult CustomOp::verify() {

LogicalResult CustomTfOp::inferReturnTypes(
MLIRContext*, std::optional<Location> location, ValueRange operands,
DictionaryAttr attr, RegionRange ranges,
DictionaryAttr attr, OpaqueProperties, RegionRange ranges,
SmallVectorImpl<Type>& inferredReturnTypes) {
CustomTfOpAdaptor op(operands, attr, ranges);
CustomTfOpAdaptor op(operands, attr, {}, ranges);

if (op.getRegions().empty()) return success();
auto* real_op = &op.getBody().front().front();
Expand Down Expand Up @@ -1233,7 +1233,7 @@ static LogicalResult ComputeConvWindowedOutputSize(

LogicalResult Conv2DOp::inferReturnTypes(
MLIRContext*, std::optional<Location> location, ValueRange operands,
DictionaryAttr attr, RegionRange,
DictionaryAttr attr, OpaqueProperties, RegionRange,
SmallVectorImpl<Type>& inferredReturnTypes) {
Conv2DOpAdaptor op(operands, attr);

Expand Down Expand Up @@ -1914,7 +1914,7 @@ mlir::LogicalResult ReshapeOp::verify() {

LogicalResult ReshapeOp::inferReturnTypes(
MLIRContext* context, std::optional<Location> location, ValueRange operands,
DictionaryAttr attr, RegionRange,
DictionaryAttr attr, OpaqueProperties, RegionRange,
SmallVectorImpl<Type>& inferredReturnTypes) {
ReshapeOpAdaptor op(operands, attr);
const Value input = op.getInput();
Expand Down Expand Up @@ -2291,7 +2291,7 @@ void FakeQuantOp::getCanonicalizationPatterns(RewritePatternSet& results,

LogicalResult UnpackOp::inferReturnTypes(
MLIRContext* context, std::optional<Location> loc, ValueRange operands,
DictionaryAttr attributes, RegionRange regions,
DictionaryAttr attributes, OpaqueProperties, RegionRange regions,
SmallVectorImpl<Type>& inferredReturnTypes) {
UnpackOpAdaptor op(operands, attributes);
// TODO(jpienaar): Refactor verify
Expand Down Expand Up @@ -2652,7 +2652,7 @@ mlir::LogicalResult UnidirectionalSequenceLSTMOp::verify() {

LogicalResult UnidirectionalSequenceLSTMOp::inferReturnTypes(
MLIRContext*, std::optional<Location>, ValueRange operands,
DictionaryAttr attr, RegionRange,
DictionaryAttr attr, OpaqueProperties, RegionRange,
SmallVectorImpl<Type>& inferredReturnTypes) {
Value input = operands[0];
auto input_type = input.getType().dyn_cast_or_null<RankedTensorType>();
Expand Down Expand Up @@ -3713,9 +3713,9 @@ struct WhileResultOperandsMatchAndImplicitCapture

// Replace with new While with matching operands and results.
Operation* op = while_op.getOperation();
Operation* new_op = rewriter.insert(
Operation::create(op->getLoc(), op->getName(), types, new_operands,
op->getAttrs(), {}, /*numRegions=*/2));
Operation* new_op = rewriter.insert(Operation::create(
op->getLoc(), op->getName(), types, new_operands, op->getAttrs(),
op->getPropertiesStorage(), {}, /*numRegions=*/2));

for (int i = 0; i < 2; ++i) new_op->getRegion(i).takeBody(op->getRegion(i));
int new_index = 0;
Expand Down
5 changes: 5 additions & 0 deletions tensorflow/compiler/mlir/lite/tests/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ func.func @unpackQuantized(%arg0: tensor<2x3x!quant.uniform<u8:f32, 0.02>>) -> t
// -----

func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// expected-error @+2 {{failed to infer returned types}}
// expected-error @+1 {{output count should match 'num' attribute}}
%0:3 = "tfl.unpack"(%arg0) {axis = 1 : i32, num = 2 : i32} : (tensor<2x3xi32>) -> (tensor<2xi32>, tensor<2xi32>, tensor<2xi32>)
func.return %0#0 : tensor<2xi32>
Expand All @@ -1461,6 +1462,7 @@ func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// -----

func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// expected-error @+2 {{failed to infer returned types}}
// expected-error @+1 {{attribute 'axis' should be in range [-rank, rank), got axis = 2, and rank = 2}}
%0:3 = "tfl.unpack"(%arg0) {axis = 2 : i32, num = 3 : i32} : (tensor<2x3xi32>) -> (tensor<2xi32>, tensor<2xi32>, tensor<2xi32>)
func.return %0#0 : tensor<2xi32>
Expand All @@ -1469,6 +1471,7 @@ func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// -----

func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// expected-error @+2 {{failed to infer returned types}}
// expected-error @+1 {{attribute 'axis' should be in range [-rank, rank), got axis = -3, and rank = 2}}
%0:3 = "tfl.unpack"(%arg0) {axis = -3 : i32, num = 3 : i32} : (tensor<2x3xi32>) -> (tensor<2xi32>, tensor<2xi32>, tensor<2xi32>)
func.return %0#0 : tensor<2xi32>
Expand All @@ -1477,6 +1480,7 @@ func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// -----

func.func @unpack(%arg0: tensor<i32>) -> tensor<2xi32> {
// expected-error @+2 {{failed to infer returned types}}
// expected-error @+1 {{input should be of rank larger than 0}}
%0:3 = "tfl.unpack"(%arg0) {axis = 0 : i32, num = 3 : i32} : (tensor<i32>) -> (tensor<2xi32>, tensor<2xi32>, tensor<2xi32>)
func.return %0#0 : tensor<2xi32>
Expand All @@ -1485,6 +1489,7 @@ func.func @unpack(%arg0: tensor<i32>) -> tensor<2xi32> {
// -----

func.func @unpack(%arg0: tensor<2x3xi32>) -> tensor<2xi32> {
// expected-error @+2 {{failed to infer returned types}}
// expected-error @+1 {{op inferred type(s) 'tensor<2xi32>', 'tensor<2xi32>', 'tensor<2xi32>' are incompatible with return type(s) of operation 'tensor<2xi32>', 'tensor<2x1xi32>', 'tensor<2xi32>'}}
%0:3 = "tfl.unpack"(%arg0) {axis = 1 : i32, num = 3 : i32} : (tensor<2x3xi32>) -> (tensor<2xi32>, tensor<2x1xi32>, tensor<2xi32>)
func.return %0#0 : tensor<2xi32>
Expand Down
1 change: 1 addition & 0 deletions tensorflow/compiler/mlir/lite/tests/shape-inference.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func.func @testConv2dShapeInferenceDynamic(%arg0: tensor<1x?x?x128xf32>, %arg1:

module attributes {tf.versions = {producer = 888 : i32}} {
func.func @testConv2dShapeInvalidRanks(%arg0: tensor<1x112x80xf32>, %arg1: tensor<128x3x3x128xf32>, %arg2: tensor<128xf32>) -> tensor<1x?x?x128xf32> {
// expected-error @+2 {{'tfl.conv_2d' op failed to infer returned types}}
// expected-error @+1 {{Invalid ranks}}
%0 = "tfl.conv_2d"(%arg0, %arg1, %arg2) {dilation_h_factor = 2 : i32, dilation_w_factor = 2 : i32, fused_activation_function = "NONE", padding = "VALID", stride_h = 1 : i32, stride_w = 1 : i32} : (tensor<1x112x80xf32>, tensor<128x3x3x128xf32>, tensor<128xf32>) -> tensor<1x?x?x128xf32>
func.return %0 : tensor<1x?x?x128xf32>
Expand Down
14 changes: 10 additions & 4 deletions tensorflow/compiler/mlir/python/mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ void ExperimentalWriteBytecode(const std::string& filename,
mlir::stablehlo::registerAllDialects(registry);
mlir::MLIRContext context(registry);
mlir::OwningOpRef<mlir::ModuleOp> module;
mlir::StatusScopedDiagnosticHandler diagnostic_handler(&context);
{
mlir::StatusScopedDiagnosticHandler diagnostic_handler(&context);
module = mlir::parseSourceString<mlir::ModuleOp>(mlir_txt, &context);
if (!module) {
tsl::Set_TF_Status_from_Status(status,
Expand All @@ -394,7 +394,10 @@ void ExperimentalWriteBytecode(const std::string& filename,
return;
}
outputFile->keep();
mlir::writeBytecodeToFile(*module, outputFile->os(), writer_config);
if (failed(mlir::writeBytecodeToFile(*module, outputFile->os(),
writer_config))) {
tsl::Set_TF_Status_from_Status(status, diagnostic_handler.ConsumeStatus());
}
}

void ExperimentalTFLiteToTosaBytecode(
Expand All @@ -407,6 +410,7 @@ void ExperimentalTFLiteToTosaBytecode(
registry.insert<mlir::tosa::TosaDialect>();
mlir::MLIRContext context(registry);
mlir::OwningOpRef<mlir::ModuleOp> module;
mlir::StatusScopedDiagnosticHandler diagnostic_handler(&context);
{
mlir::Location loc = mlir::UnknownLoc::get(&context);
std::string error;
Expand All @@ -418,7 +422,6 @@ void ExperimentalTFLiteToTosaBytecode(
return;
}

mlir::StatusScopedDiagnosticHandler diagnostic_handler(&context);
auto buffer_view =
std::string_view(buffer->getBufferStart(), buffer->getBufferSize());
module = tflite::FlatBufferToMlir(
Expand Down Expand Up @@ -449,7 +452,10 @@ void ExperimentalTFLiteToTosaBytecode(
return;
}
outputFile->keep();
mlir::writeBytecodeToFile(*module, outputFile->os(), writer_config);
if (failed(mlir::writeBytecodeToFile(*module, outputFile->os(),
writer_config))) {
tsl::Set_TF_Status_from_Status(status, diagnostic_handler.ConsumeStatus());
}
}

} // namespace tensorflow
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func.func private @conv(%input: tensor<1x3x4x3xf32> {tf._user_specified_name = "
func.return %dq_res : tensor<*xf32>
}

// CHECK-DAG: [[bias:%.+]] = "arith.constant"() {value = dense<[7.11401462, 7.05456924]> : tensor<2xf32>} : () -> tensor<2xf32>
// CHECK-DAG: [[weight:%.+]] = "arith.constant"() {value = dense_resource<__elided__> : tensor<2x3x3x2xf32>} : () -> tensor<2x3x3x2x!quant.uniform<i8:f32, 0.074855112561992565:-1>>
// CHECK-DAG: [[bias:%.+]] = "arith.constant"() <{value = dense<[7.11401462, 7.05456924]> : tensor<2xf32>}> : () -> tensor<2xf32>
// CHECK-DAG: [[weight:%.+]] = "arith.constant"() <{value = dense_resource<__elided__> : tensor<2x3x3x2xf32>}> : () -> tensor<2x3x3x2x!quant.uniform<i8:f32, 0.074855112561992565:-1>>
// CHECK: [[q_input:%.+]] = "quantfork.qcast"(%arg0) : (tensor<1x3x4x3xf32>) -> tensor<1x3x4x3x!quant.uniform<i8:f32, 0.58810077742034317:-128>>
// CHECK-NEXT: [[q_bias:%.+]] = "quantfork.qcast"([[bias]]) : (tensor<2xf32>) -> tensor<2x!quant.uniform<i32:f32, 0.044022349891595126>>
// CHECK-NEXT: [[conv:%.+]] = "tf.PartitionedCall"([[q_input]], [[weight]], [[q_bias]]) {_tfl_quant_trait = "fully_quantizable", config = "", config_proto = "", executor_type = "", f = @[[composite_fn:composite_conv2d_with_bias_and_relu6_fn.*]]} : (tensor<1x3x4x3x!quant.uniform<i8:f32, 0.58810077742034317:-128>>, tensor<2x3x3x2x!quant.uniform<i8:f32, 0.074855112561992565:-1>>, tensor<2x!quant.uniform<i32:f32, 0.044022349891595126>>) -> tensor<*x!quant.uniform<i8:f32, 0.023529411764705882:-128>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module {
return %0 : tensor<*xf32>
}

// CHECK: %[[cst:.*]] = "arith.constant"() {value = dense<0.000000e+00> : tensor<2x1024xf32>} : () -> tensor<2x1024xf32>
// CHECK: %[[cst:.*]] = "arith.constant"() <{value = dense<0.000000e+00> : tensor<2x1024xf32>}> : () -> tensor<2x1024xf32>
// CHECK: %[[q_cst:.*]] = "quantfork.qcast"(%[[cst]]) : (tensor<2x1024xf32>) -> tensor<2x1024x!quant.uniform<i8<-127:127>:f32, 3.9370078740157481E-9>>
// CHECK: %[[out:.*]] = "tf.PartitionedCall"(%arg0, %[[q_cst]]) {_tfl_quant_trait = "fully_quantizable", config = "", config_proto = "", executor_type = "", f = @composite_matmul_fn} : (tensor<1x2x2x3xf32>, tensor<2x1024x!quant.uniform<i8<-127:127>:f32, 3.9370078740157481E-9>>) -> tensor<*xf32>
// CHECK: "func.return"(%[[out]]) : (tensor<*xf32>) -> ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func.func private @conv(%input: tensor<1x3x4x3xf32> {tf._user_specified_name = "
func.return %dq_res : tensor<*xf32>
}

// CHECK-DAG: [[bias:%.+]] = "arith.constant"() {value = dense<[7.11401462, 7.05456924]> : tensor<2xf32>} : () -> tensor<2xf32>
// CHECK-DAG: [[weight:%.+]] = "arith.constant"() {value = dense_resource<__elided__> : tensor<2x3x3x2xf32>} : () -> tensor<2x3x3x2x!quant.uniform<i8:f32, 0.074855112561992565:-1>>
// CHECK-DAG: [[bias:%.+]] = "arith.constant"() <{value = dense<[7.11401462, 7.05456924]> : tensor<2xf32>}> : () -> tensor<2xf32>
// CHECK-DAG: [[weight:%.+]] = "arith.constant"() <{value = dense_resource<__elided__> : tensor<2x3x3x2xf32>}> : () -> tensor<2x3x3x2x!quant.uniform<i8:f32, 0.074855112561992565:-1>>
// CHECK: [[q_input:%.+]] = "quantfork.qcast"(%arg0) : (tensor<1x3x4x3xf32>) -> tensor<1x3x4x3x!quant.uniform<i8:f32, 0.58810077742034317:-128>>
// CHECK-NEXT: [[q_bias:%.+]] = "quantfork.qcast"([[bias]]) : (tensor<2xf32>) -> tensor<2x!quant.uniform<i32:f32, 0.044022349891595126>>
// CHECK-NEXT: [[conv:%.+]] = "tf.PartitionedCall"([[q_input]], [[weight]], [[q_bias]]) {_tfl_quant_trait = "fully_quantizable", config = "", config_proto = "", executor_type = "", f = @[[composite_fn:composite_conv2d_with_bias_and_relu6_fn.*]]} : (tensor<1x3x4x3x!quant.uniform<i8:f32, 0.58810077742034317:-128>>, tensor<2x3x3x2x!quant.uniform<i8:f32, 0.074855112561992565:-1>>, tensor<2x!quant.uniform<i32:f32, 0.044022349891595126>>) -> tensor<*x!quant.uniform<i8:f32, 0.023529411764705882:-128>>
Expand Down
2 changes: 2 additions & 0 deletions tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td
Original file line number Diff line number Diff line change
Expand Up @@ -11187,6 +11187,8 @@ underlying graph, and executes each of the partitioned subgraphs as a function.

// Returns the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getFAttr(); }
// Sets the callee from the callable.
void setCalleeFromCallable(CallInterfaceCallable callee);

// returns the callee of this operation.
func::FuncOp func() {
Expand Down
18 changes: 9 additions & 9 deletions tensorflow/compiler/mlir/tensorflow/ir/tf_op_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ ResourceHandleValueAndId GetResourceHandleValueAndIdBase(
// and have at least one operand, result type can be inferred using the first
// operand's type.

#define INFER_RETURN_TYPE_COMPONENTS_FROM_OPERANDS(Op) \
LogicalResult Op::inferReturnTypeComponents( \
MLIRContext* context, std::optional<Location> location, \
ValueShapeRange operands, DictionaryAttr attributes, \
RegionRange regions, \
SmallVectorImpl<ShapedTypeComponents>& inferredReturnShapes) { \
return inferReturnTypeComponentsFromOperands(context, location, operands, \
attributes, regions, \
inferredReturnShapes); \
#define INFER_RETURN_TYPE_COMPONENTS_FROM_OPERANDS(Op) \
LogicalResult Op::inferReturnTypeComponents( \
MLIRContext* context, std::optional<Location> location, \
ValueShapeRange operands, DictionaryAttr attributes, \
OpaqueProperties properties, RegionRange regions, \
SmallVectorImpl<ShapedTypeComponents>& inferredReturnShapes) { \
return inferReturnTypeComponentsFromOperands( \
context, location, operands, attributes, properties, regions, \
inferredReturnShapes); \
}

#include "tensorflow/compiler/mlir/tensorflow/ir/tf_op_interfaces.h.inc"
Expand Down
6 changes: 6 additions & 0 deletions tensorflow/compiler/mlir/tensorflow/ir/tf_ops.td
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ def TF_LegacyCallOp : TF_Op<"LegacyCall",

// Returns the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getFAttr(); }
// Sets the callee from the callable
void setCalleeFromCallable(::mlir::CallInterfaceCallable callee);

// Returns the resolved callee function of this operation.
// Prefer passing in SymbolTableCollection to reduce lookup costs by
Expand Down Expand Up @@ -570,6 +572,8 @@ underlying graph, and executes each of the partitioned subgraphs as a function.

// Returns the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getFAttr(); }
// Sets the callee from the callable
void setCalleeFromCallable(::mlir::CallInterfaceCallable callee);

// Returns the resolved callee function of this operation.
// Prefer passing in SymbolTableCollection to reduce lookup costs by
Expand Down Expand Up @@ -1009,6 +1013,8 @@ def TF_TPUPartitionedCallOp : TF_Op<"TPUPartitionedCall",

// Returns the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getFAttr(); }
// Sets the callee from the callable.
void setCalleeFromCallable(CallInterfaceCallable callee);

// Returns the resolved callee function of this operation.
// Prefer passing in SymbolTableCollection to reduce lookup costs by
Expand Down
18 changes: 15 additions & 3 deletions tensorflow/compiler/mlir/tensorflow/ir/tf_ops_a_m.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ void ConstOp::build(OpBuilder& builder, OperationState& result, Type type,

LogicalResult ConstOp::inferReturnTypes(
MLIRContext* context, std::optional<Location> location, ValueRange operands,
DictionaryAttr attributes, RegionRange regions,
DictionaryAttr attributes, OpaqueProperties, RegionRange regions,
SmallVectorImpl<Type>& inferredReturnTypes) {
auto value = attributes.get("value");
if (!value) return emitOptionalError(location, "missing attribute 'value'");
Expand Down Expand Up @@ -1936,7 +1936,8 @@ static LogicalResult inferConvReturnTypeComponents(

LogicalResult Conv2DOp::inferReturnTypeComponents(
MLIRContext* context, std::optional<Location> location,
ValueShapeRange operands, DictionaryAttr attributes, RegionRange regions,
ValueShapeRange operands, DictionaryAttr attributes, OpaqueProperties,
RegionRange regions,
SmallVectorImpl<ShapedTypeComponents>& inferredReturnShapes) {
Conv2DOpAdaptor op(operands.getValues(), attributes);
ArrayRef<Attribute> explicit_padding;
Expand Down Expand Up @@ -2134,7 +2135,8 @@ StringRef Conv2DBackpropInputOp::GetOptimalLayout(

LogicalResult Conv3DOp::inferReturnTypeComponents(
MLIRContext* context, std::optional<Location> location,
ValueShapeRange operands, DictionaryAttr attributes, RegionRange regions,
ValueShapeRange operands, DictionaryAttr attributes, OpaqueProperties,
RegionRange regions,
SmallVectorImpl<ShapedTypeComponents>& inferredReturnShapes) {
Conv3DOpAdaptor op(operands.getValues(), attributes);
ArrayRef<Attribute> explicit_padding;
Expand Down Expand Up @@ -3212,6 +3214,16 @@ LogicalResult LegacyCallOp::verifySymbolUses(
return success();
}

void LegacyCallOp::setCalleeFromCallable(mlir::CallInterfaceCallable callee) {
// Direct call.
if (SymbolRefAttr fAttr = getFAttr()) {
SymbolRefAttr calleeAttr = callee.get<SymbolRefAttr>();
return setFAttr(cast<FlatSymbolRefAttr>(calleeAttr));
}
// Indirect call, callee Value is the first operand.
return setOperand(0, callee.get<Value>());
}

//===----------------------------------------------------------------------===//
// LogOp
//===----------------------------------------------------------------------===//
Expand Down
Loading

0 comments on commit 831b45a

Please sign in to comment.