chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
@@ -0,0 +1,25 @@
load("//tensorflow/compiler/mlir/tfr:build_defs.bzl", "gen_op_bindings")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
default_visibility = [
":friends",
],
licenses = ["notice"],
)
package_group(
name = "friends",
packages = [
"//tensorflow/compiler/mlir/...",
],
)
filegroup(
name = "decomposition_lib",
srcs = ["decomposition_lib.mlir"],
)
gen_op_bindings(name = "composite")
gen_op_bindings(name = "test")
@@ -0,0 +1,36 @@
/* 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 "tensorflow/core/framework/op.h"
namespace tensorflow {
REGISTER_OP("MyAddN")
.Input("inputs: N * T")
.Output("sum: T")
.Attr("N: int >= 1")
.Attr("T: {numbertype, variant}")
.SetIsCommutative()
.SetIsAggregate();
REGISTER_OP("MyBiasedDense")
.Input("input: T")
.Input("weight: T")
.Input("bias: T")
.Output("out: T")
.Attr("T: {float, int8}")
.Attr("act: {'', 'relu', 'relu6'} = ''");
} // namespace tensorflow
@@ -0,0 +1,129 @@
// Copyright 2026 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.
// ==============================================================================
// A test resource file which contains some pre-defined internal tfr.functions
// for decomposition and external tfr.functions for raising the decomposition
// result to the ops in the TF dialect.
//
// All the tfr.func functions are supposed to be translated from the Python
// function with tf.composite annotation.
// All the external tfr.func functions modeles the op signature defined by
// OpDefs.
tfr.func @tf__my_add_n(%values: !tfr.tensor_list,
%n: i64 {tfr.name="N"}) -> !tfr.tensor {
%index = arith.constant 0 : index
%cst = arith.constant 1 : i64
%eq = arith.cmpi eq, %n, %cst : i64
%v1 = tfr.get_element %values[%index] : (!tfr.tensor_list, index) -> !tfr.tensor
%res = scf.if %eq -> !tfr.tensor {
scf.yield %v1 : !tfr.tensor
} else {
%step = arith.index_cast %cst : i64 to index
%end = arith.index_cast %n : i64 to index
%reduce = scf.for %i = %step to %end step %step iter_args(%reduce_iter=%v1) -> !tfr.tensor {
%v = tfr.get_element %values[%i] : (!tfr.tensor_list, index) -> !tfr.tensor
%reduce_next = tfr.call @tf__add(%reduce_iter, %v) : (!tfr.tensor, !tfr.tensor) -> !tfr.tensor
scf.yield %reduce_next : !tfr.tensor
}
scf.yield %reduce : !tfr.tensor
}
tfr.return %res : !tfr.tensor
}
tfr.func @tf__my_add_n_(!tfr.tensor_list<N,T>, i64 {tfr.name="N"}) -> !tfr.tensor attributes {N,T}
// Translated from tf.compose Python function.
tfr.func @tf__my_biased_dense(%input: !tfr.tensor, %weight: !tfr.tensor,
%bias: !tfr.tensor,
%act: !tfr.attr{tfr.name="act", tfr.default=""}) -> !tfr.tensor {
%dot = tfr.call @tf__mat_mul(%input, %weight) : (!tfr.tensor, !tfr.tensor) -> !tfr.tensor
%add = tfr.call @tf__add(%dot, %bias) : (!tfr.tensor, !tfr.tensor) -> !tfr.tensor
%relu = tfr.constant "relu" -> !tfr.attr
%relu6 = tfr.constant "relu6" -> !tfr.attr
%is_relu = tfr.equal %act, %relu -> i1
%res = scf.if %is_relu -> !tfr.tensor {
%applied_relu = tfr.call @tf__relu(%add) : (!tfr.tensor) -> !tfr.tensor
scf.yield %applied_relu : !tfr.tensor
} else {
%is_relu6 = tfr.equal %act, %relu6 -> i1
%res1 = scf.if %is_relu6 -> !tfr.tensor {
%applied_relu6 = tfr.call @tf__relu6(%add) : (!tfr.tensor) -> !tfr.tensor
scf.yield %applied_relu6 : !tfr.tensor
} else {
scf.yield %add : !tfr.tensor
}
scf.yield %res1 : !tfr.tensor
}
tfr.return %res : !tfr.tensor
}
tfr.func @tf__my_biased_dense_(!tfr.tensor<T>, !tfr.tensor<T>, !tfr.tensor<T>,
!tfr.attr{tfr.name="act", tfr.default=""}) -> !tfr.tensor attributes {T}
// This is a wong decomposition and used to verify that tf.Elu isn't decomposed
// since its kernel has been registered.
tfr.func @tf__elu_(%input: !tfr.tensor) -> !tfr.tensor {
tfr.return %input : !tfr.tensor
}
// Translated from:
//
// REGISTER_OP("Add")
// .Input("x: T")
// .Input("y: T")
// .Output("z: T")
// .Attr(
// "T: {bfloat16, half, float, double, uint8, int8, int16, int32, int64, "
// "complex64, complex128, string}")
tfr.func @tf__add_(!tfr.tensor<T>, !tfr.tensor<T>)
-> !tfr.tensor<T> attributes{T}
// Translated from:
//
// REGISTER_OP("MatMul")
// .Input("a: T")
// .Input("b: T")
// .Output("product: T")
// .Attr("transpose_a: bool = false")
// .Attr("transpose_b: bool = false")
// .Attr("T: {bfloat16, half, float, double, int32, int64, complex64, complex128}")
// T is a derived attribute.
// transpose_a and transpose_b is materialized attributes.
tfr.func @tf__mat_mul_(!tfr.tensor<T>, !tfr.tensor<T>,
i1 {tfr.name="transpose_a", tfr.default=false},
i1 {tfr.name="transpose_b", tfr.default=false})
-> !tfr.tensor<T> attributes{T}
// Translated from:
//
// REGISTER_OP("Relu")
// .Input("features: T")
// .Output("activations: T")
// .Attr("T: {realnumbertype, qint8}")
// T is a derived attribute.
tfr.func @tf__relu_(!tfr.tensor<T>) -> !tfr.tensor<T> attributes{T}
// Translated from:
//
// REGISTER_OP("Relu6")
// .Input("features: T")
// .Output("activations: T")
// .Attr("T: {realnumbertype}")
// T is a derived attribute.
tfr.func @tf__relu6_(!tfr.tensor<T>) -> !tfr.tensor<T> attributes{T}
@@ -0,0 +1,85 @@
/* 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 "tensorflow/core/framework/op.h"
namespace tensorflow {
REGISTER_OP("TestNoOp");
REGISTER_OP("TestIdentityOp")
.Input("input: T")
.Output("output: T")
.Attr("T: numbertype");
REGISTER_OP("TestIdentityNOp")
.Input("input: N * T")
.Output("output: N * T")
.Attr("N: int >= 1")
.Attr("T: numbertype");
REGISTER_OP("TestInputNOp")
.Input("input: N * T")
.Output("output: T")
.Attr("N: int >= 1")
.Attr("T: numbertype");
REGISTER_OP("TestOutputNOp")
.Input("input: T")
.Output("output: N * T")
.Attr("N: int >= 1")
.Attr("T: numbertype");
REGISTER_OP("TestTwoInputsOp")
.Input("lhs: T")
.Input("rhs: T")
.Output("output: T")
.Attr("T: numbertype")
.Attr("pred: bool = false");
REGISTER_OP("TestComplexTFOp")
.Input("lhs: T")
.Input("rhs: Tlen")
.Output("output: N * T")
.Attr("N: int >= 1")
.Attr("T: numbertype")
.Attr("Tlen: {int32, int64} = DT_INT64");
REGISTER_OP("TestNumAttrsOp")
.Attr("x1: int = -10")
.Attr("y1: int = 1")
.Attr("x2: float = 0.0")
.Attr("y2: float = -3.0");
REGISTER_OP("TestNonNumAttrsOp")
.Attr("z: shape")
.Attr("x: string = 'hello'")
.Attr("y: type = DT_FLOAT");
REGISTER_OP("TestThreeInputsOp")
.Input("x: T")
.Input("y: T")
.Input("z: T")
.Output("output: T")
.Attr("T: numbertype")
.Attr("act: {'x', 'y', 'z'} = 'z'");
REGISTER_OP("TestTwoOutputsOp")
.Input("input: T")
.Output("output1: T")
.Output("output2: T")
.Attr("T: numbertype");
} // namespace tensorflow