Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
tensorflow
提交
e22197f3
T
tensorflow
项目概览
xxadev
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e22197f3
编写于
7月 16, 2019
作者:
H
Haoliang Zhang
提交者:
TensorFlower Gardener
7月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add GatherNd operator into tflite mlir converter.
PiperOrigin-RevId: 258463148
上级
c7504db1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
162 addition
and
0 deletion
+162
-0
tensorflow/compiler/mlir/lite/ir/tfl_ops.td
tensorflow/compiler/mlir/lite/ir/tfl_ops.td
+18
-0
tensorflow/compiler/mlir/lite/tests/legalize-tf.mlir
tensorflow/compiler/mlir/lite/tests/legalize-tf.mlir
+16
-0
tensorflow/compiler/mlir/lite/transforms/legalize_patterns.td
...orflow/compiler/mlir/lite/transforms/legalize_patterns.td
+3
-0
tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td
tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td
+125
-0
未找到文件。
tensorflow/compiler/mlir/lite/ir/tfl_ops.td
浏览文件 @
e22197f3
...
...
@@ -585,6 +585,24 @@ def TFL_GatherOp : TFL_Op<"gather", [
let hasOptions = 1;
}
def TFL_GatherNdOp : TFL_Op<"gather_nd", [NoSideEffect]> {
let summary = "Gather_nd operator";
let description = [{
Gather slices from `params` into a Tensor with shape specified by `indices`.
}];
// TODO: missing Uint8.
let arguments = (ins
TensorOf<[F32, I8, I64, I32]>:$params,
TFL_I32OrI64Tensor:$indices
);
let results = (outs
TensorOf<[F32, I8, I64, I32]>:$output
);
}
// Same type check of lhs and rhs is handled by the Broadcastable trait.
def TFL_LessEqualOp : TFL_Op<"less_equal", [Broadcastable, NoSideEffect]> {
let summary = "Less_equal operator";
...
...
tensorflow/compiler/mlir/lite/tests/legalize-tf.mlir
浏览文件 @
e22197f3
...
...
@@ -370,6 +370,22 @@ func @gatherHigherRankIndices(%arg0 : tensor<2x3x6xf32>, %arg1 : tensor<4x5xi32>
// CHECK: %0 = "tfl.gather"(%arg0, %arg1) {axis = 0 : i32} : (tensor<2x3x6xf32>, tensor<4x5xi32>) -> tensor<4x5x3x6xf32>
}
func @gatherNdVectorIndices(%arg0 : tensor<3x2x2xf32>, %arg1 : tensor<2xi32>) -> tensor<2xf32> {
%0 = "tf.GatherNd"(%arg0, %arg1) : (tensor<3x2x2xf32>, tensor<2xi32>) -> tensor<2xf32>
return %0 : tensor<2xf32>
// CHECK-LABEL:gatherNdVectorIndices
// CHECK: %0 = "tfl.gather_nd"(%arg0, %arg1) : (tensor<3x2x2xf32>, tensor<2xi32>) -> tensor<2xf32>
}
func @gatherNdHigherRankIndices(%arg0 : tensor<4x3x2xf32>, %arg1 : tensor<2x2xi32>) -> tensor<2x2xf32> {
%0 = "tf.GatherNd"(%arg0, %arg1) : (tensor<4x3x2xf32>, tensor<2x2xi32>) -> tensor<2x2xf32>
return %0 : tensor<2x2xf32>
// CHECK-LABEL:gatherNdHigherRankIndices
// CHECK: %0 = "tfl.gather_nd"(%arg0, %arg1) : (tensor<4x3x2xf32>, tensor<2x2xi32>) -> tensor<2x2xf32>
}
func @gatherV2VectorIndices(%arg0 : tensor<1x2x20xf32>, %arg1 : tensor<3x5xi32>) -> tensor<1x3x5x20xf32> {
%0 = constant dense<[1]> : tensor<1xi32>
%1 = "tf.GatherV2"(%arg0, %arg1, %0) : (tensor<1x2x20xf32>, tensor<3x5xi32>, tensor<1xi32>) -> tensor<1x3x5x20xf32>
...
...
tensorflow/compiler/mlir/lite/transforms/legalize_patterns.td
浏览文件 @
e22197f3
...
...
@@ -167,6 +167,9 @@ def : Pat<(TF_GreaterEqualOp $l, $r), (TFL_GreaterEqualOp $l, $r)>;
def : Pat<(TF_GatherOp $params, $indices, $ignored_validate_indices),
(TFL_GatherOp $params, $indices, ConstantAttr<I32Attr, "0">)>;
def : Pat<(TF_GatherNdOp $params, $indices),
(TFL_GatherNdOp $params, $indices)>;
def : Pat<(TF_GatherV2Op $params, $indices,
(ConstantOp ElementsAttr:$axis),
ConstantAttr<I64Attr, "0">:$batch_dims),
...
...
tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td
浏览文件 @
e22197f3
...
...
@@ -939,6 +939,131 @@ raising an error.
TF_DerivedOperandTypeAttr Tparams = TF_DerivedOperandTypeAttr<0>;
}
def TF_GatherNdOp : TF_Op<"GatherNd", [NoSideEffect]> {
let summary = [{
Gather slices from `params` into a Tensor with shape specified by `indices`.
}];
let description = [{
`indices` is an K-dimensional integer tensor, best thought of as a
(K-1)-dimensional tensor of indices into `params`, where each element defines a
slice of `params`:
output[\\(i_0, ..., i_{K-2}\\)] = params[indices[\\(i_0, ..., i_{K-2}\\)]]
Whereas in `tf.gather` `indices` defines slices into the first
dimension of `params`, in `tf.gather_nd`, `indices` defines slices into the
first `N` dimensions of `params`, where `N = indices.shape[-1]`.
The last dimension of `indices` can be at most the rank of
`params`:
indices.shape[-1] <= params.rank
The last dimension of `indices` corresponds to elements
(if `indices.shape[-1] == params.rank`) or slices
(if `indices.shape[-1] < params.rank`) along dimension `indices.shape[-1]`
of `params`. The output tensor has shape
indices.shape[:-1] + params.shape[indices.shape[-1]:]
Note that on CPU, if an out of bound index is found, an error is returned.
On GPU, if an out of bound index is found, a 0 is stored in the
corresponding output value.
Some examples below.
Simple indexing into a matrix:
```python
indices = [[0, 0], [1, 1]]
params = [['a', 'b'], ['c', 'd']]
output = ['a', 'd']
```
Slice indexing into a matrix:
```python
indices = [[1], [0]]
params = [['a', 'b'], ['c', 'd']]
output = [['c', 'd'], ['a', 'b']]
```
Indexing into a 3-tensor:
```python
indices = [[1]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[['a1', 'b1'], ['c1', 'd1']]]
indices = [[0, 1], [1, 0]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [['c0', 'd0'], ['a1', 'b1']]
indices = [[0, 0, 1], [1, 0, 1]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = ['b0', 'b1']
```
Batched indexing into a matrix:
```python
indices = [[[0, 0]], [[0, 1]]]
params = [['a', 'b'], ['c', 'd']]
output = [['a'], ['b']]
```
Batched slice indexing into a matrix:
```python
indices = [[[1]], [[0]]]
params = [['a', 'b'], ['c', 'd']]
output = [[['c', 'd']], [['a', 'b']]]
```
Batched indexing into a 3-tensor:
```python
indices = [[[1]], [[0]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[[['a1', 'b1'], ['c1', 'd1']]],
[[['a0', 'b0'], ['c0', 'd0']]]]
indices = [[[0, 1], [1, 0]], [[0, 0], [1, 1]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[['c0', 'd0'], ['a1', 'b1']],
[['a0', 'b0'], ['c1', 'd1']]]
indices = [[[0, 0, 1], [1, 0, 1]], [[0, 1, 1], [1, 1, 0]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [['b0', 'b1'], ['d0', 'c1']]
```
See also `tf.gather` and `tf.batch_gather`.
}];
let arguments = (ins
TF_Tensor:$params,
TF_I32OrI64Tensor:$indices
);
let results = (outs
TF_Tensor:$output
);
TF_DerivedOperandTypeAttr Tindices = TF_DerivedOperandTypeAttr<1>;
TF_DerivedOperandTypeAttr Tparams = TF_DerivedOperandTypeAttr<0>;
}
def TF_GatherV2Op : TF_Op<"GatherV2", [NoSideEffect]> {
let summary = [{
Gather slices from `params` axis `axis` according to `indices`.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录