Elffuss BraidHub

kikocis/ncnn public

master · 65.6 KiBRawPermalink
1/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16// This is the operation definition file for TensorFlow.
17//
18// This file contains TensorFlow ops whose definitions are amended to fix
19// issues or provide more information. In this file you have full control
20// of the op definition; all changes will be retained with subsequent
21// refreshes.
22//
23// This file includes another file, `tf_generated_ops.td`, which contains
24// all ops whose definitions are generated from TensorFlow codebase.
25// Changes made there are not respected.
26
27#ifndef TF_OPS
28#define TF_OPS
29
30include "tf_generated_ops.td"
31include "tf_op_base.td"
32include "mlir/Interfaces/CallInterfaces.td"
33include "mlir/Interfaces/ControlFlowInterfaces.td"
34include "mlir/Interfaces/LoopLikeInterface.td"
35include "mlir/Interfaces/SideEffectInterfaces.td"
36include "mlir/IR/OpBase.td"
37include "mlir/IR/SymbolInterfaces.td"
38
39class TF_TensorListInitOp<string mnemonic> : TF_Op<mnemonic, [NoSideEffect]> {
40 let results = (outs
41 TF_VariantTensor:$handle
42 );
43
44 TF_DerivedOperandTypeAttr shape_type = TF_DerivedOperandTypeAttr<0>;
45
46 let verifier = [{
47 // This is required to populate derived attributes during export in a
48 // meaningful way. Else during export to GraphDef element_type() query
49 // will result in out of bounds access/assert.
50 if (handle_dtype().getSubtypes().size() != 1) {
51 return emitOpError(
52 "must have exactly one subtype in the result variant type");
53 }
54
55 return Verify(*this);
56 }];
57
58 DerivedTypeAttr element_dtype = DerivedTypeAttr<
59 "return getElementTypeOrSelf(element_type());">;
60
61 let extraClassDeclaration = [{
62 // Returns type of the TensorList element produced by this op.
63 TensorType element_type() { return handle_dtype().getSubtypes()[0]; }
64
65 // Returns data type of the result handle. Returned type contains type of
66 // the TensorList element as a subtype.
67 VariantType handle_dtype() {
68 return getElementTypeOrSelf(handle().getType()).cast<TF::VariantType>();
69 }
70 }];
71}
72
73def TF_CaseOp : TF_Op<"Case", []> {
74 let summary = [{
75An n-way switch statement which calls a single branch function.
76 }];
77
78 let description = [{
79An n-way switch statement, implementing the following:
80 ```
81 switch (branch_index) {
82 case 0:
83 output = branches[0](input);
84 break;
85 case 1:
86 output = branches[1](input);
87 break;
88 ...
89 case [[nbranches-1]]:
90 default:
91 output = branches[nbranches-1](input);
92 break;
93 }
94 ```
95 }];
96
97 let arguments = (ins
98 I32Tensor:$branch_index,
99 Variadic<TF_Tensor>:$input,
100
101 Confined<SymbolRefArrayAttr, [ArrayMinCount<1>]>:$branches,
102
103 // Used to map StatelessCase and Case op defined in TensorFlow to a common
104 // op.
105 BoolAttr:$is_stateless
106 );
107
108 let results = (outs
109 Variadic<TF_Tensor>:$output
110 );
111
112 TF_DerivedOperandTypeListAttr Tin = TF_DerivedOperandTypeListAttr<1>;
113 TF_DerivedResultTypeListAttr Tout = TF_DerivedResultTypeListAttr<0>;
114 TF_DerivedResultShapeListAttr output_shapes = TF_DerivedResultShapeListAttr<0>;
115
116 let verifier = [{
117 return Verify(*this);
118 }];
119
120
121 let extraClassDeclaration = [{
122 int num_branches() { return branches().size(); }
123
124 // Gets function corresponding branch # `index`.
125 FuncOp branch_function(int index) {
126 auto flat_sym_ref = branches()[index].cast<FlatSymbolRefAttr>();
127 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, flat_sym_ref);
128 }
129
130 // Gets all branch functions.
131 void get_branch_functions(SmallVectorImpl<FuncOp> &functions) {
132 functions.reserve(num_branches());
133 for (int idx : llvm::seq<int>(0, num_branches()))
134 functions.push_back(branch_function(idx));
135 }
136 }];
137}
138
139def TF_CaseRegionOp : TF_Op<"CaseRegion",
140 [SingleBlockImplicitTerminator<"YieldOp">, NoRegionArguments]> {
141 let summary = [{
142An n-way switch statement which calls a single branch function.
143 }];
144
145 let description = [{
146An n-way switch statement, implementing the following:
147 ```
148 switch (branch_index) {
149 case 0:
150 output = branches[0](input);
151 break;
152 case 1:
153 output = branches[1](input);
154 break;
155 ...
156 case [[nbranches-1]]:
157 default:
158 output = branches[nbranches-1](input);
159 break;
160 }
161 ```
162 }];
163
164 let arguments = (ins
165 I32Tensor:$branch_index,
166
167 // Used to map StatelessCase and Case op defined in TensorFlow to a common
168 // op.
169 BoolAttr:$is_stateless
170 );
171
172 let results = (outs
173 Variadic<TF_Tensor>:$output
174 );
175
176 let regions = (region VariadicRegion<SizedRegion<1>>:$branches);
177
178 let verifier = [{
179 return Verify(*this);
180 }];
181
182}
183
184// In MLIR, the TensorFlow tensor value is represented as an ElementsAttr, with
185// its type encoding the tensor's shape and data type.
186def TF_ConstOp : TF_Op<"Const", [ConstantLike, NoSideEffect]> {
187 let summary = "Constant tensor op";
188
189 let arguments = (ins
190 ElementsAttr:$value
191 );
192
193 let results = (outs
194 TF_Tensor:$output
195 );
196
197 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
198
199 let builders = [
200 OpBuilder<(ins "Attribute":$value)>,
201 OpBuilder<(ins "Type":$type, "Attribute":$value)>,
202 ];
203}
204
205def TF_CollectivePermuteOp : TF_Op<"CollectivePermute", []> {
206 let summary = "An Op to permute tensors across replicated TPU instances.";
207
208 let description = [{
209Each instance supplies its own input.
210
211For example, suppose there are 4 TPU instances: `[A, B, C, D]`. Passing
212source_target_pairs=`[[0,1],[1,2],[2,3],[3,0]]` gets the outputs:
213`[D, A, B, C]`.
214 }];
215
216 let arguments = (ins
217 TensorOf<[TF_Bfloat16, TF_Float16, TF_Float32, TF_Float64, TF_Int16, TF_Int32, TF_Int64, TF_Int8, TF_Complex128, TF_Complex64, TF_Qint32, TF_Qint8, TF_Quint8, TF_Uint16, TF_Uint32, TF_Uint64, TF_Uint8]>:$input,
218 I32Tensor:$source_target_pairs
219 );
220
221 let results = (outs
222 TensorOf<[TF_Bfloat16, TF_Float16, TF_Float32, TF_Float64, TF_Int16, TF_Int32, TF_Int64, TF_Int8, TF_Complex128, TF_Complex64, TF_Qint32, TF_Qint8, TF_Quint8, TF_Uint16, TF_Uint32, TF_Uint64, TF_Uint8]>:$output
223 );
224
225 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
226}
227
228def TF_XlaAllReduceOp : TF_Op<"XlaAllReduce", [NoSideEffect, TF_AllTypesMatch<["input", "output"]>]> {
229 let summary = "An Op to reduce inputs across replicated TPU instances.";
230
231 let arguments = (ins
232 TensorOf<[TF_Bfloat16, TF_Float16, TF_Float32, TF_Int32, TF_Uint32]>:$input,
233 TF_Int32Tensor:$group_assignment,
234 TF_AnyStrAttrOf<["Min", "Max", "Mul", "Add", "Mean"]>:$reduce_op
235 );
236
237 let results = (outs
238 TensorOf<[TF_Bfloat16, TF_Float16, TF_Float32, TF_Int32, TF_Uint32]>:$output
239 );
240
241 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
242}
243
244def TF_EmptyTensorListOp : TF_TensorListInitOp<"EmptyTensorList"> {
245 let summary = "Creates and returns an empty tensor list.";
246
247 let description = [{
248All list elements must be tensors of dtype element_dtype and shape compatible
249with element_shape.
250
251handle: an empty tensor list.
252element_dtype: the type of elements in the list.
253element_shape: a shape compatible with that of elements in the list.
254 }];
255
256 let arguments = (ins
257 TF_I32OrI64Tensor:$element_shape,
258 TF_Int32Tensor:$max_num_elements
259 );
260}
261
262// TODO(fengliuai): The tf.Identity is side-effect free and it doesn't change
263// the status of the system during the execution. However it shouldn't be folded
264// in general if it used to serve for caching and some other invariant checks,
265// so we removed the side-effect free property in the op definition. This is a
266// hack, and we should fix it if we have a better way to model it.
267def TF_IdentityOp : TF_Op<"Identity", [TF_OperandsSameAsResultsTypeOrRef]> {
268 let summary = "Identity op";
269
270 let description = [{
271Returns a tensor with the same shape and contents as input.
272 }];
273
274 let arguments = (ins
275 TF_Tensor:$input
276 );
277
278 let results = (outs
279 TF_Tensor:$output
280 );
281
282 TF_DerivedResultTypeAttr T = TF_DerivedResultTypeAttr<0>;
283}
284
285def TF_IfOp : TF_Op<"If", []> {
286 let summary = "output = cond ? then_branch(input) : else_branch(input)";
287
288 let description = [{
289output = cond ? then_branch(input) : else_branch(input)
290
291cond: A Tensor. If the tensor is a scalar of non-boolean type, the
292 scalar is converted to a boolean according to the
293 following rule: if the scalar is a numerical value, non-zero means
294 True and zero means False; if the scalar is a string, non-empty
295 means True and empty means False. If the tensor is not a scalar,
296 being empty means False and being non-empty means True.
297input: A list of input tensors.
298then_branch: A function that takes 'inputs' and returns a list of
299 tensors, whose types are the same as what else_branch returns.
300else_branch: A function that takes 'inputs' and returns a list of
301 tensors. whose types are the same as what then_branch returns.
302 }];
303
304 let arguments = (ins
305 TF_Tensor:$cond,
306 Variadic<TF_Tensor>:$input,
307
308 FlatSymbolRefAttr:$then_branch,
309 FlatSymbolRefAttr:$else_branch,
310
311 // Used to map StatelessIf and If op defined in TensorFlow to a common op.
312 BoolAttr:$is_stateless
313 );
314
315 let results = (outs
316 Variadic<TF_Tensor>:$output
317 );
318
319 TF_DerivedOperandTypeAttr Tcond = TF_DerivedOperandTypeAttr<0>;
320 TF_DerivedOperandTypeListAttr Tin = TF_DerivedOperandTypeListAttr<1>;
321 TF_DerivedResultTypeListAttr Tout = TF_DerivedResultTypeListAttr<0>;
322 TF_DerivedResultShapeListAttr output_shapes = TF_DerivedResultShapeListAttr<0>;
323
324 let extraClassDeclaration = [{
325 // Get the then branch function.
326 FuncOp then_function() {
327 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, then_branch());
328 }
329
330 // Get the else branch function.
331 FuncOp else_function() {
332 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, else_branch());
333 }
334 }];
335}
336
337def TF_YieldOp : TF_Op<"Yield",
338 [NoSideEffect, ReturnLike, Terminator,
339 ParentOneOf<["CaseRegionOp", "IfRegionOp", "WhileRegionOp"]>]> {
340 let summary = "Yield operation";
341
342 let description = [{
343 The "yield" operation represents a return operation within the conditional
344 and body of structured control flow (e.g., if and while). The operation
345 takes a variable number of operands and produces no results. The number and
346 types of inputs must match the signature of the operation that contains the
347 region.
348 }];
349
350 let arguments = (ins Variadic<AnyType>:$operands);
351}
352
353def TF_IfRegionOp : TF_Op<"IfRegion",
354 [SingleBlockImplicitTerminator<"YieldOp">, NoRegionArguments]> {
355 let summary = "output = cond ? then_branch output : else_branch output";
356
357 let description = [{
358"output = cond ? then_branch output : else_branch output"
359
360cond: A Tensor. If the tensor is a scalar of non-boolean type, the
361 scalar is converted to a boolean according to the
362 following rule: if the scalar is a numerical value, non-zero means
363 True and zero means False; if the scalar is a string, non-empty
364 means True and empty means False. If the tensor is not a scalar,
365 being empty means False and being non-empty means True.
366then_branch: A region that computes the outputs of the op if cond = true.
367 It returns a list of tensors using tf.yield (as the terminator). The
368 types of these returned tensors is same as that of the else_branch
369else_branch: A region that computes the outputs of the op if cond = false.
370 It returns a list of tensors using tf.yield (as the terminator). The
371 types of these returned tensors is same as that of the then_branch
372 }];
373
374 let arguments = (ins
375 0DTensorOf<[I1]>:$cond,
376
377 // Used to map StatelessIf and If op defined in TensorFlow to a common op.
378 BoolAttr:$is_stateless,
379 // Used to maintain function name when round-tripping
380 // between functional and regional control flow. This can be removed if
381 // the runtime does not require globally unique then/else branch function names.
382 OptionalAttr<StrAttr>:$_then_func_name,
383 OptionalAttr<StrAttr>:$_else_func_name
384 );
385
386 let results = (outs
387 Variadic<TF_Tensor>:$output
388 );
389
390 let regions = (region SizedRegion<1>:$then_branch, SizedRegion<1>:$else_branch);
391
392 let verifier = [{
393 return Verify(*this);
394 }];
395
396 let builders = [
397 OpBuilder<(ins "TypeRange":$resultTypes, "ValueRange":$operands,
398 "llvm::ArrayRef<::mlir::NamedAttribute>":$attributes,
399 "unsigned":$numRegions),
400 [{
401 assert(numRegions == 2u && "mismatched number of regions");
402 build($_builder, $_state, resultTypes, operands, attributes);
403 }]>];
404}
405
406def TF_LegacyCallOp : TF_Op<"LegacyCall",
407 [CallOpInterface, NoSideEffect]> {
408 let summary =
409 "returns `f(inputs)`, where `f` is a function.";
410
411 let description = [{
412 The LegacyCall operation represents a direct call to a function that is
413 within the same symbol scope as the call and is mapped to a GraphDef node
414 with the function name as the op name. Unlike a PartitionedCall which
415 represents asynchronously executing a function across multiple devices, a
416 LegacyCall ignores specification for ops in the attached function and
417 instead executes it on the device assigned to this op.
418 }];
419
420 let arguments = (ins
421 Variadic<TF_Tensor>:$args,
422
423 FlatSymbolRefAttr:$f,
424 DefaultValuedAttr<BoolAttr, "false">:$_disable_call_shape_inference
425 );
426
427 let results = (outs
428 Variadic<TF_Tensor>:$output
429 );
430
431 let extraClassDeclaration = [{
432 // Gets the argument operands to the called function.
433 operand_range getArgOperands() { return args(); }
434
435 // Returns the callee of this operation.
436 CallInterfaceCallable getCallableForCallee() { return fAttr(); }
437
438 // returns the callee of this operation.
439 FuncOp func() {
440 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, f());
441 }
442 }];
443}
444
445def TF_ParseExampleOp : TF_Op<"ParseExample",
446 [NoSideEffect,
447 AttrSizedResultSegments,
448 AttrSizedOperandSegments]> {
449
450 let summary =
451 "Transforms a vector of tf.Example protos (as strings) into typed tensors.";
452
453 let arguments = (ins
454 TF_StrTensor:$serialized,
455 TF_StrTensor:$names,
456 Variadic<TF_StrTensor>:$sparse_keys,
457 Variadic<TF_StrTensor>:$dense_keys,
458 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$dense_defaults,
459
460 TF_ShapeAttrArray:$dense_shapes,
461 I32ElementsAttr:$result_segment_sizes,
462 I32ElementsAttr:$operand_segment_sizes
463 );
464
465 let results = (outs
466 Variadic<TF_Int64Tensor>:$sparse_indices, // len(sparse_types)
467 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$sparse_values, // len(sparse_types)
468 Variadic<TF_Int64Tensor>:$sparse_shapes, // len(sparse_types)
469 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$dense_values // len(Tdense)
470 );
471
472 TF_DerivedOperandSizeAttr Nsparse = TF_DerivedOperandSizeAttr<2>;
473 TF_DerivedOperandSizeAttr Ndense = TF_DerivedOperandSizeAttr<3>;
474 TF_DerivedOperandTypeListAttr Tdense = TF_DerivedOperandTypeListAttr<4>;
475 TF_DerivedResultTypeListAttr sparse_types = TF_DerivedResultTypeListAttr<1>;
476
477 let verifier = ?;
478}
479
480def TF_ParseExampleV2Op : TF_Op<"ParseExampleV2",
481 [NoSideEffect,
482 AttrSizedResultSegments]> {
483
484 let summary =
485 "Transforms a vector of tf.Example protos (as strings) into typed tensors.";
486
487 let arguments = (ins
488 TF_StrTensor:$serialized,
489 TF_StrTensor:$names,
490 TF_StrTensor:$sparse_keys,
491 TF_StrTensor:$dense_keys,
492 TF_StrTensor:$ragged_keys,
493 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$dense_defaults,
494
495 Confined<I64Attr, [IntMinValue<0>]>:$num_sparse,
496 TF_ShapeAttrArray:$dense_shapes,
497 I32ElementsAttr:$result_segment_sizes
498 );
499
500 let results = (outs
501 Variadic<TF_Int64Tensor>:$sparse_indices, // len(sparse_types)
502 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$sparse_values, // len(sparse_types)
503 Variadic<TF_Int64Tensor>:$sparse_shapes, // len(sparse_types)
504 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$dense_values, // len(Tdense)
505 Variadic<TensorOf<[TF_Float32, TF_Int64, TF_Str]>>:$ragged_values, // len(ragged_value_types)
506 // = len(ragged_split_types)
507 Variadic<TensorOf<[TF_Int32, TF_Int64]>>:$ragged_row_splits // len(ragged_split_types)
508 // = len(ragged_value_types)
509 );
510
511 // The Verify(ParseExampleV2Op) function validates that the lengths and types
512 // of these attrs are compatible.
513 TF_DerivedOperandTypeListAttr Tdense = TF_DerivedOperandTypeListAttr<5>;
514 TF_DerivedResultTypeListAttr sparse_types = TF_DerivedResultTypeListAttr<1>;
515 TF_DerivedResultTypeListAttr ragged_value_types =
516 TF_DerivedResultTypeListAttr<4>;
517 TF_DerivedResultTypeListAttr ragged_split_types =
518 TF_DerivedResultTypeListAttr<5>;
519
520 let verifier = [{
521 return Verify(*this);
522 }];
523}
524
525def TF_PartitionedCallOp : TF_Op<"PartitionedCall",
526 [CallOpInterface, NoSideEffect]> {
527 let summary =
528 "returns `f(inputs)`, where `f`'s body is placed and partitioned.";
529
530 let description = [{
531Asynchronously executes a function, potentially across multiple devices but
532within a single process. The kernel places and partitions a given function's
533underlying graph, and executes each of the partitioned subgraphs as a function.
534 }];
535
536 let arguments = (ins
537 Variadic<TF_Tensor>:$args,
538
539 SymbolRefAttr:$f,
540 StrAttr:$config,
541 StrAttr:$config_proto,
542 StrAttr:$executor_type
543 );
544
545 let results = (outs
546 Variadic<TF_Tensor>:$output
547 );
548
549 TF_DerivedOperandTypeListAttr Tin = TF_DerivedOperandTypeListAttr<0>;
550 TF_DerivedResultTypeListAttr Tout = TF_DerivedResultTypeListAttr<0>;
551
552 let extraClassDeclaration = [{
553 // Gets the argument operands to the called function.
554 operand_range getArgOperands() { return args(); }
555
556 // Returns the callee of this operation.
557 CallInterfaceCallable getCallableForCallee() { return fAttr(); }
558
559 // returns the callee of this operation.
560 FuncOp func() {
561 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, f());
562 }
563 }];
564
565 let verifier = [{ return VerifyPartitionedCall(*this); }];
566}
567
568def TF_PlaceholderOp : TF_Op<"Placeholder", [NoSideEffect]> {
569 let summary = "Placeholder op";
570
571 let description = [{
572Inserts a placeholder for a tensor that will be always fed.
573 }];
574
575 let arguments = (ins
576 );
577
578 let results = (outs
579 TF_Tensor:$output
580 );
581
582 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
583}
584
585def TF_PlaceholderWithDefaultOp : TF_Op<"PlaceholderWithDefault", [NoSideEffect]> {
586 let summary = "Placeholder op";
587
588 let description = [{
589 A placeholder op that passes through input when its output is not fed.
590 }];
591
592 let arguments = (ins
593 TF_Tensor:$input
594 );
595
596 let results = (outs
597 TF_Tensor:$output
598 );
599
600 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
601 DerivedAttr shape = TF_DerivedResultShapeAttr;
602}
603
604def TF_StatefulPartitionedCallOp : TF_Op<"StatefulPartitionedCall",
605 [CallOpInterface]> {
606 let summary =
607 "returns `f(inputs)`, where `f`'s body is placed and partitioned.";
608
609 let description = [{
610Asynchronously executes a function, potentially across multiple devices but
611within a single process. The kernel places and partitions a given function's
612underlying graph, and executes each of the partitioned subgraphs as a function.
613 }];
614
615 let arguments = (ins
616 Variadic<TF_Tensor>:$args,
617
618 FlatSymbolRefAttr:$f,
619 StrAttr:$config,
620 StrAttr:$config_proto,
621 StrAttr:$executor_type
622 );
623
624 let results = (outs
625 Variadic<TF_Tensor>:$output
626 );
627
628 TF_DerivedOperandTypeListAttr Tin = TF_DerivedOperandTypeListAttr<0>;
629 TF_DerivedResultTypeListAttr Tout = TF_DerivedResultTypeListAttr<0>;
630
631 let extraClassDeclaration = [{
632 // Gets the argument operands to the called function.
633 operand_range getArgOperands() { return args(); }
634
635 // Returns the callee of this operation.
636 CallInterfaceCallable getCallableForCallee() { return fAttr(); }
637
638 // returns the callee of this operation.
639 FuncOp func() {
640 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, f());
641 }
642 }];
643
644 let verifier = [{ return VerifyPartitionedCall(*this); }];
645}
646
647def TF_WhileOp : TF_Op<"While", []> {
648 let summary = [{
649output = input; While (Cond(output)) { output = Body(output) }
650 }];
651
652 let description = [{
653output = input; While (Cond(output)) { output = Body(output) }
654
655input: A list of input tensors whose types are T.
656output: A list of output tensors whose types are T.
657cond: A function that takes 'input' and returns a tensor. If the tensor is
658 a scalar of non-boolean, the scalar is converted to a boolean
659 according to the following rule: if the scalar is a numerical
660 value, non-zero means True and zero means False; if the scalar is
661 a string, non-empty means True and empty means False. If the
662 tensor is not a scalar, non-emptiness means True and False
663 otherwise.
664body: A function that takes a list of tensors and returns another
665 list of tensors. Both lists have the same types as specified
666 by T.
667 }];
668
669 let arguments = (ins
670 Variadic<TF_Tensor>:$input,
671
672 FlatSymbolRefAttr:$cond,
673 FlatSymbolRefAttr:$body,
674 DefaultValuedAttr<I64Attr, "10">:$parallel_iterations,
675
676 // Used to map StatelessWhile and While op defined in TensorFlow to a common
677 // op.
678 BoolAttr:$is_stateless,
679
680 // In TensorFlow, While has a special behavior where if `output_shapes`
681 // attribute is not empty, those shapes are used in its shape function
682 // as result shapes instead of propagating operand shapes as result shapes.
683 // This allows for different result shapes from operand shapes. While these
684 // shapes are imported and set as a part of the result type, there is no
685 // indicator differentiating between having no output shapes compared to
686 // having all unranked shapes. Thus this attribute is set to determine
687 // which shape function behavior to use for this op, specifically
688 // propagating operand shapes as result shapes when this attribute is not
689 // set, or preserving result shapes as is when this attribute is set.
690 UnitAttr:$shape_invariant
691 );
692
693 let results = (outs
694 Variadic<TF_Tensor>:$output
695 );
696
697 TF_DerivedOperandTypeListAttr T = TF_DerivedOperandTypeListAttr<0>;
698 TF_DerivedResultShapeListAttr output_shapes = TF_DerivedResultShapeListAttr<0>;
699
700 let extraClassDeclaration = [{
701 // Get the condition function.
702 FuncOp cond_function() {
703 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, cond());
704 }
705
706 // Get the body function.
707 FuncOp body_function() {
708 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, body());
709 }
710 }];
711}
712
713def TF_WhileRegionOp : TF_Op<"WhileRegion",
714 [DeclareOpInterfaceMethods<LoopLikeOpInterface>,
715 SingleBlockImplicitTerminator<"YieldOp">]> {
716 let summary = "while operation";
717 let description = [{
718 The tf.WhileRegion op represents a while loop using 2 regions and a set of
719 iteration variables. The iteration variables maintained by this Op have the
720 same types as the inputs. The Op executes a while loop described by the
721 following pseudo code:
722
723 ```
724 func WhileRegionOp(inputs) {
725 iteration_vars = inputs;
726 while (cond(iteration_vars)) {
727 iteration_vars = body(iteration_vars);
728 }
729 return iteration_vars;
730 }
731 ```
732
733 `cond` is the condition region and `body` is the body region. Both these
734 regions accept the current value of the iteration variables as inputs. The
735 condition region returns a tensor<i1> which, if false, will exit the loop.
736 The body region computes new values of the iteration variables. The iteration
737 variables are initialized to the Op input, and the results of the
738 tf.WhileRegion op are the final values of the iteration variables.
739
740 This implies that the operand and result types for tf.WhileRegion should be
741 the same. Note that the condition and body regions can implicitly capture
742 loop invariant values directly. In canonical form, iteration variables that
743 pass through the loop body unmodified are converted to implicitly captured
744 references to their values outside the loop.
745 }];
746
747 let arguments = (ins
748 Variadic<AnyTensor>:$input,
749
750 DefaultValuedAttr<I64Attr, "10">:$parallel_iterations,
751
752 // Used to map StatelessWhile and While op defined in TensorFlow to a common
753 // op.
754 BoolAttr:$is_stateless,
755
756 // In TensorFlow, While has a special behavior where if `output_shapes`
757 // attribute is not empty, those shapes are used in its shape function
758 // as result shapes instead of propagating operand shapes as result shapes.
759 // This allows for different result shapes from operand shapes. While these
760 // shapes are imported and set as a part of the result type, there is no
761 // indicator differentiating between having no output shapes compared to
762 // having all unranked shapes. Thus this attribute is set to determine
763 // which shape function behavior to use for this op, specifically
764 // propagating operand shapes as result shapes when this attribute is not
765 // set, or preserving result shapes as is when this attribute is set.
766 UnitAttr:$shape_invariant
767 );
768 let results = (outs Variadic<AnyTensor>:$output);
769
770 let regions = (region SizedRegion<1>:$cond, SizedRegion<1>:$body);
771
772 let verifier = [{ return Verify(*this); }];
773}
774
775def TF_TensorListReserveOp : TF_TensorListInitOp<"TensorListReserve"> {
776 let summary = "List of the given size with empty elements.";
777
778 let description = [{
779element_shape: the shape of the future elements of the list
780num_elements: the number of elements to reserve
781handle: the output list
782element_dtype: the desired type of elements in the list.
783 }];
784
785 let arguments = (ins
786 TF_I32OrI64Tensor:$element_shape,
787 TF_Int32Tensor:$num_elements
788 );
789}
790
791// This operation when auto-generated is marked as NoSideEffect because it isn't
792// stateful in TensorFlow. However it is kept alive through control dependency,
793// and does not have any output. When placed in an island it wouldn't be kept
794// alive in any way and the canonicalizer would just always fold it away.
795def TF_TPUReplicateMetadataOp : TF_Op<"TPUReplicateMetadata", []> {
796 let summary = [{
797Metadata indicating how the TPU computation should be replicated.
798 }];
799
800 let description = [{
801This operation holds the metadata common to operations of a `tpu.replicate()` computation subgraph.
802 }];
803
804 let arguments = (ins
805 Confined<I64Attr, [IntMinValue<0>]>:$num_replicas,
806 DefaultValuedAttr<I64Attr, "1">:$num_cores_per_replica,
807 StrAttr:$topology,
808 DefaultValuedAttr<BoolAttr, "true">:$use_tpu,
809 DefaultValuedAttr<I64ArrayAttr, "{}">:$device_assignment,
810 DefaultValuedAttr<I64ArrayAttr, "{}">:$computation_shape,
811 DefaultValuedAttr<StrArrayAttr, "{}">:$host_compute_core,
812 DefaultValuedAttr<StrArrayAttr, "{}">:$padding_map,
813 DefaultValuedAttr<StrAttr, "STEP_MARK_AT_ENTRY">:$step_marker_location,
814 DefaultValuedAttr<BoolAttr, "false">:$allow_soft_placement,
815 DefaultValuedAttr<BoolAttr, "false">:$use_spmd_for_xla_partitioning
816 );
817
818 let results = (outs);
819}
820
821def TF_VarHandleOp : TF_Op<"VarHandleOp", []> {
822 let summary = "Creates a handle to a Variable resource from its name.";
823
824 let description = [{
825container: the container this variable is placed in.
826shared_name: the name by which this variable is referred to.
827dtype and shape: attributes representing the data type and shape held in the
828 variable.
829
830Example:
831 resource_variable_ops.var_handle_op(
832 dtype=dtypes.int32, shape=[8, 16], container="foo", shared_name="bar")
833 returns a handle for a variable with name "bar" in container "foo", and the
834 variable holds a tensor of shape [8, 16] and dtype int32.
835 }];
836
837 let arguments = (ins
838 DefaultValuedAttr<StrAttr, "">:$container,
839 DefaultValuedAttr<StrAttr, "">:$shared_name
840 );
841
842 let results = (outs
843 Res<TF_ResourceTensor, "", [TF_VariableAlloc]>:$resource
844 );
845}
846
847def TF_EnqueueTPUEmbeddingBatchOp : TF_Op<"EnqueueTPUEmbeddingBatch", [TF_TPUEmbeddingSideEffect]> {
848 let summary = [{
849An op that enqueues a list of input batch tensors to TPUEmbedding.
850 }];
851
852 let arguments = (ins
853 Variadic<TF_StrTensor>:$batch,
854 TF_StrTensor:$mode_override,
855
856 DefaultValuedAttr<I64Attr, "-1">:$device_ordinal,
857 DefaultValuedAttr<StrArrayAttr, "{}">:$combiners
858 );
859
860 let results = (outs);
861
862 TF_DerivedOperandSizeAttr N = TF_DerivedOperandSizeAttr<0>;
863}
864
865// Multiple variadic operands with different sizes are not supported by the
866// dialect generator, so we manually added the op.
867def TF_SendTPUEmbeddingGradientsOp : TF_Op<"SendTPUEmbeddingGradients", [AttrSizedOperandSegments, TF_TPUEmbeddingSideEffect]> {
868 let summary = "Performs gradient updates of embedding tables.";
869
870 let description = [{
871inputs: A TensorList of gradients with which to update embedding tables.
872 This argument has the same length and shapes as the return value of
873 RecvTPUEmbeddingActivations, but contains gradients of the model's loss
874 with respect to the embedding activations. The embedding tables are updated
875 from these gradients via the optimizer specified in the TPU embedding
876 configuration given to tpu.initialize_system.
877learning_rates: A TensorList of float32 scalars, one for each dynamic learning
878 rate tag: see the comments in
879 //third_party/tensorflow/core/protobuf/tpu/optimization_parameters.proto.
880 Multiple tables can share the same dynamic learning rate tag as specified
881 in the configuration. If the learning rates for all tables are constant,
882 this list should be empty.
883config: Serialized TPUEmbeddingConfiguration proto.
884 }];
885
886 let arguments = (ins
887 Variadic<TF_Tensor>:$inputs,
888 Variadic<TF_Tensor>:$learning_rates,
889 StrAttr:$config
890 );
891
892 TF_DerivedOperandSizeAttr N = TF_DerivedOperandSizeAttr<0>;
893 TF_DerivedOperandSizeAttr NN = TF_DerivedOperandSizeAttr<1>;
894}
895
896// Multiple variadic operands with different sizes are not supported by the
897// dialect generator, so we manually added the op.
898def TF__SendTPUEmbeddingGradientsOp : TF_Op<"_SendTPUEmbeddingGradients", [AttrSizedOperandSegments, TF_TPUEmbeddingSideEffect]> {
899 let summary = "Performs gradient updates of embedding tables.";
900
901 let description = [{
902The gradients argument is a TensorList having the same length and shapes as the
903return value of _RecvTPUEmbeddingActivations, but contains gradients of the
904model's loss with respect to the embedding activations. The embedding tables are
905updated from these gradients via the optimizer specified in the
906TPUEmbeddingConfiguration proto given to tpu.initialize_system.
907
908gradients: A TensorList of gradients with which to update embedding tables.
909learning_rates: A TensorList of learning rates used for updating the embedding
910 tables via the optimizer. The length of the TensorList must be equal to the
911 number of dynamic learning rate tags specified in the
912 TPUEmbeddingConfiguration proto.
913deduplication_data: A Tensor with type=DT_VARIANT containing the deduplication
914 data. The tensor is an XLA nested tuple containing N elements. Each
915 element of the nested tuple is a tuple of rank 1 tensors. Each tensor either
916 contains indices (DT_INT32) for embedding lookup or weights (DT_FLOAT) to
917 apply to the output of the embedding lookup operation.
918config: Serialized TPUEmbeddingConfiguration proto.
919 }];
920
921 let arguments = (ins
922 Variadic<TF_Tensor>:$gradients,
923 Variadic<TF_Tensor>:$learning_rates,
924 TF_VariantTensor:$deduplication_data,
925 StrAttr:$config
926 );
927
928 TF_DerivedOperandSizeAttr NumTables = TF_DerivedOperandSizeAttr<0>;
929 TF_DerivedOperandSizeAttr NumLearningRateTags = TF_DerivedOperandSizeAttr<1>;
930}
931
932// Updated the op description text from the auto-generated op definition.
933def TF__RecvTPUEmbeddingDeduplicationDataOp : TF_Op<"_RecvTPUEmbeddingDeduplicationData", []> {
934 let summary = [{
935Receives deduplication data (indices and weights).
936 }];
937
938 let description = [{
939The deduplication data is a Tensor with type=DT_VARIANT. The tensor itself is an
940XLA nested tuple containing N elements. Each element of the nested tuple is a
941tuple of rank 1 tensors. Each tensor either contains indices (DT_INT32) for
942embedding lookup or weights (DT_FLOAT) to apply to the output of the embedding
943lookup operation.
944 }];
945
946 let arguments = (ins
947 StrAttr:$config
948 );
949
950 let results = (outs
951 TF_VariantTensor:$output
952 );
953}
954
955def TF_XlaShardingOp : TF_Op<"XlaSharding", [NoSideEffect]> {
956 let summary = [{
957An op which shards the input based on the given sharding attribute.
958 }];
959
960 let arguments = (ins
961 TF_Tensor:$input,
962
963 DefaultValuedAttr<StrAttr, "">:$sharding,
964 OptionalAttr<StrAttr>:$_XlaSharding
965 );
966
967 let results = (outs
968 TF_Tensor:$output
969 );
970
971 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
972}
973
974def TF_InfeedDequeueTupleOp : TF_Op<"InfeedDequeueTuple", []> {
975 let summary = "Fetches multiple values from infeed as an XLA tuple.";
976
977 let arguments = (ins
978 OptionalAttr<StrAttr>:$_XlaSharding
979 );
980
981 let results = (outs
982 Variadic<TF_Tensor>:$outputs
983 );
984
985 TF_DerivedResultShapeListAttr shapes = TF_DerivedResultShapeListAttr<0>;
986 TF_DerivedResultTypeListAttr dtypes = TF_DerivedResultTypeListAttr<0>;
987}
988
989def TF_StringFormatOp : TF_Op<"StringFormat", [NoSideEffect]> {
990 let summary = "Formats a string template using a list of tensors.";
991
992 let description = [{
993Formats a string template using a list of tensors, pretty-printing tensor summaries.
994 }];
995
996 let arguments = (ins
997 Variadic<TF_Tensor>:$inputs,
998
999 DefaultValuedAttr<StrAttr, "%s">:$strtemplate,
1000 DefaultValuedAttr<StrAttr, "%s">:$placeholder,
1001 DefaultValuedAttr<I64Attr, "3">:$summarize
1002 );
1003
1004 let results = (outs
1005 TF_StrTensor:$output
1006 );
1007
1008 TF_DerivedOperandTypeListAttr T = TF_DerivedOperandTypeListAttr<0>;
1009}
1010
1011//===----------------------------------------------------------------------===//
1012// tf.data ops
1013//===----------------------------------------------------------------------===//
1014
1015def TF_BatchDatasetV2Op : TF_Op<"BatchDatasetV2", [NoSideEffect]> {
1016 let summary = [{
1017Creates a dataset that batches `batch_size` elements from `input_dataset`.
1018 }];
1019
1020 let arguments = (ins
1021 TF_VariantTensor:$input_dataset,
1022 TF_Int64Tensor:$batch_size,
1023 TF_BoolTensor:$drop_remainder,
1024
1025 DefaultValuedAttr<BoolAttr, "false">:$parallel_copy,
1026 Confined<TypeArrayAttr, [ArrayMinCount<1>]>:$output_types,
1027 Confined<TF_ShapeAttrArray, [ArrayMinCount<1>]>:$output_shapes
1028 );
1029
1030 let results = (outs
1031 TF_VariantTensor:$handle
1032 );
1033}
1034
1035def TF_MapDatasetOp : TF_Op<"MapDataset", [NoSideEffect]> {
1036 let summary = [{
1037 Creates a dataset that applies `f` to the outputs of `input_dataset`.
1038 }];
1039
1040 let arguments = (ins
1041 TF_VariantTensor:$input_dataset,
1042 Variadic<TF_Tensor>:$other_arguments,
1043
1044 SymbolRefAttr:$f,
1045 Confined<TypeArrayAttr, [ArrayMinCount<1>]>:$output_types,
1046 Confined<TF_ShapeAttrArray, [ArrayMinCount<1>]>:$output_shapes,
1047 DefaultValuedAttr<BoolAttr, "true">:$use_inter_op_parallelism,
1048 DefaultValuedAttr<BoolAttr, "false">:$preserve_cardinality
1049 );
1050
1051 let results = (outs
1052 TF_VariantTensor:$handle
1053 );
1054
1055 TF_DerivedOperandTypeListAttr Targuments = TF_DerivedOperandTypeListAttr<1>;
1056}
1057
1058def TF_MapAndBatchDatasetOp : TF_Op<"MapAndBatchDataset", [NoSideEffect]> {
1059 let summary = "Creates a dataset that fuses mapping with batching.";
1060
1061 let description = [{
1062Creates a dataset that applies `f` to the outputs of `input_dataset` and then
1063batches `batch_size` of them.
1064
1065Unlike a "MapDataset", which applies `f` sequentially, this dataset invokes up
1066to `batch_size * num_parallel_batches` copies of `f` in parallel.
1067 }];
1068
1069 let arguments = (ins
1070 TF_VariantTensor:$input_dataset,
1071 Variadic<TF_Tensor>:$other_arguments,
1072 TF_Int64Tensor:$batch_size,
1073 TF_Int64Tensor:$num_parallel_calls,
1074 TF_BoolTensor:$drop_remainder,
1075
1076 SymbolRefAttr:$f,
1077 Confined<TypeArrayAttr, [ArrayMinCount<1>]>:$output_types,
1078 Confined<TF_ShapeAttrArray, [ArrayMinCount<1>]>:$output_shapes,
1079 DefaultValuedAttr<BoolAttr, "false">:$preserve_cardinality
1080 );
1081
1082 let results = (outs
1083 TF_VariantTensor:$handle
1084 );
1085
1086 TF_DerivedOperandTypeListAttr Targuments = TF_DerivedOperandTypeListAttr<1>;
1087}
1088
1089def TF_ParallelMapDatasetOp : TF_Op<"ParallelMapDataset", [NoSideEffect]> {
1090 let summary = [{
1091 Creates a dataset that applies `f` to the outputs of `input_dataset`.
1092 }];
1093
1094 let description = [{
1095 Unlike a "MapDataset", which applies `f` sequentially, this dataset invokes
1096 up to `num_parallel_calls` copies of `f` in parallel.
1097 }];
1098
1099 let arguments = (ins
1100 TF_VariantTensor:$input_dataset,
1101 Variadic<TF_Tensor>:$other_arguments,
1102 TF_Int32Tensor:$num_parallel_calls,
1103
1104 SymbolRefAttr:$f,
1105 Confined<TypeArrayAttr, [ArrayMinCount<1>]>:$output_types,
1106 Confined<TF_ShapeAttrArray, [ArrayMinCount<1>]>:$output_shapes,
1107 DefaultValuedAttr<BoolAttr, "true">:$use_inter_op_parallelism,
1108 DefaultValuedAttr<BoolAttr, "false">:$sloppy,
1109 DefaultValuedAttr<BoolAttr, "false">:$preserve_cardinality
1110 );
1111
1112 let results = (outs
1113 TF_VariantTensor:$handle
1114 );
1115
1116 TF_DerivedOperandTypeListAttr Targuments = TF_DerivedOperandTypeListAttr<1>;
1117}
1118
1119def TF_TensorSliceDatasetOp : TF_Op<"TensorSliceDataset", []> {
1120 let summary = [{
1121 Creates a dataset that emits each dim-0 slice of `components` once.
1122 }];
1123
1124 let arguments = (ins
1125 Variadic<TF_Tensor>:$components,
1126 Confined<TF_ShapeAttrArray, [ArrayMinCount<1>]>:$output_shapes
1127 );
1128
1129 let results = (outs
1130 TF_VariantTensor:$handle
1131 );
1132
1133 TF_DerivedOperandTypeListAttr Toutput_types = TF_DerivedOperandTypeListAttr<0>;
1134}
1135
1136def TF_ToBoolOp : TF_Op<"ToBool", [NoSideEffect]> {
1137 let summary = "Converts a tensor to a scalar predicate.";
1138
1139 let description = [{
1140Converts a tensor to a scalar predicate with the following rules:
1141
1142- For 0D tensors, truthiness is determined by comparing against a "zero"
1143 value. For numerical types it is the obvious zero. For strings it is the
1144 empty string.
1145
1146- For >0D tensors, truthiness is determined by looking at the number of
1147 elements. If has zero elements, then the result is false. Otherwise the
1148 result is true.
1149
1150This matches the behavior of If and While for determining if a tensor counts
1151as true/false for a branch condition.
1152 }];
1153
1154 let arguments = (ins
1155 TF_Tensor:$input
1156 );
1157
1158 let results = (outs
1159 0DTensorOf<[I1]>:$output
1160 );
1161
1162 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1163
1164 let builders = [
1165 OpBuilder<(ins "Value":$value),
1166 [{
1167 build($_builder, $_state, RankedTensorType::get({}, $_builder.getI1Type()),
1168 value);
1169 }]>];
1170}
1171
1172def TF_BesselI0eOp : TF_Op<"BesselI0e", [NoSideEffect, SameOperandsAndResultType]> {
1173 let summary = "Computes the Bessel i0e function of `x` element-wise.";
1174
1175 let description = [{
1176Exponentially scaled modified Bessel function of order 0 defined as
1177`bessel_i0e(x) = exp(-abs(x)) bessel_i0(x)`.
1178
1179This function is faster and numerically stabler than `bessel_i0(x)`.
1180 }];
1181
1182 let arguments = (ins
1183 TF_FloatTensor:$x
1184 );
1185
1186 let results = (outs
1187 TF_FloatTensor:$y
1188 );
1189
1190 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1191}
1192
1193def TF_BesselI1eOp : TF_Op<"BesselI1e", [NoSideEffect, SameOperandsAndResultType]> {
1194 let summary = "Computes the Bessel i1e function of `x` element-wise.";
1195
1196 let description = [{
1197Exponentially scaled modified Bessel function of order 0 defined as
1198`bessel_i1e(x) = exp(-abs(x)) bessel_i1(x)`.
1199
1200This function is faster and numerically stabler than `bessel_i1(x)`.
1201 }];
1202
1203 let arguments = (ins
1204 TF_FloatTensor:$x
1205 );
1206
1207 let results = (outs
1208 TF_FloatTensor:$y
1209 );
1210
1211 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1212}
1213
1214def TF_TPUPartitionedCallOp : TF_Op<"TPUPartitionedCall", [CallOpInterface]> {
1215 let summary = "Calls a function placed on a specified TPU device.";
1216
1217 let arguments = (ins
1218 Variadic<TF_Tensor>:$args,
1219 TF_Int32Tensor:$device_ordinal,
1220
1221 SymbolRefAttr:$f,
1222 DefaultValuedAttr<I64Attr, "0">:$autotuner_thresh
1223 );
1224
1225 let results = (outs
1226 Variadic<TF_Tensor>:$output
1227 );
1228
1229 TF_DerivedOperandTypeListAttr Tin = TF_DerivedOperandTypeListAttr<0>;
1230 TF_DerivedResultTypeListAttr Tout = TF_DerivedResultTypeListAttr<0>;
1231
1232 let extraClassDeclaration = [{
1233 // Gets the argument operands to the called function.
1234 operand_range getArgOperands() { return args(); }
1235
1236 // Returns the callee of this operation.
1237 CallInterfaceCallable getCallableForCallee() { return fAttr(); }
1238
1239 // returns the callee of this operation.
1240 FuncOp func() {
1241 return SymbolTable::lookupNearestSymbolFrom<FuncOp>(*this, f());
1242 }
1243 }];
1244
1245 let verifier = [{ return VerifyPartitionedCall(*this); }];
1246}
1247
1248def TF_BatchFunctionOp : TF_Op<"BatchFunction", [AttrSizedOperandSegments]> {
1249 let summary = [{
1250Batches all the inputs tensors to the computation done by the function.
1251 }];
1252
1253 let description = [{
1254So, for example, in the following code
1255
1256 ```python
1257
1258 # This input will be captured.
1259 y = tf.placeholder_with_default(1.0, shape=[])
1260
1261 @tf.Defun(tf.float32)
1262 def computation(a):
1263 return tf.matmul(a, a) + y
1264
1265 b = gen_batch_ops.batch_function(
1266 f=computation
1267 in_tensors=[a],
1268 captured_tensors=computation.captured_inputs,
1269 Tout=[o.type for o in computation.definition.signature.output_arg],
1270 num_batch_threads=1,
1271 max_batch_size=10,
1272 batch_timeout_micros=100000, # 100ms
1273 allowed_batch_sizes=[3, 10],
1274 batching_queue="")
1275 ```
1276
1277If more than one session.run call is simultaneously trying to compute `b`
1278the values of `a` will be gathered, non-deterministically concatenated
1279along the first axis, and only one thread will run the computation.
1280
1281Assumes that all arguments of the function are Tensors which will be batched
1282along their first dimension.
1283
1284Arguments that are captured, are not batched. The session.run call which does
1285the concatenation, will use the values of the captured tensors available to it.
1286Therefore, typical uses of captured tensors should involve values which remain
1287unchanged across session.run calls. Inference is a good example of this.
1288
1289SparseTensor is not supported. The return value of the decorated function
1290must be a Tensor or a list/tuple of Tensors.
1291 }];
1292
1293 let arguments = (ins
1294 Variadic<TF_Tensor>:$in_tensors,
1295 Variadic<TF_Tensor>:$captured_tensors,
1296
1297 SymbolRefAttr:$f,
1298 I64Attr:$num_batch_threads,
1299 I64Attr:$max_batch_size,
1300 I64Attr:$batch_timeout_micros,
1301 DefaultValuedAttr<I64Attr, "10">:$max_enqueued_batches,
1302 DefaultValuedAttr<I64ArrayAttr, "{}">:$allowed_batch_sizes,
1303 StrAttr:$container,
1304 StrAttr:$shared_name,
1305 StrAttr:$batching_queue,
1306 DefaultValuedAttr<BoolAttr, "false">:$enable_large_batch_splitting,
1307 I32ElementsAttr:$operand_segment_sizes
1308 );
1309
1310 let results = (outs
1311 Variadic<TF_Tensor>:$out_tensors
1312 );
1313
1314 TF_DerivedOperandTypeListAttr Tin = TF_DerivedOperandTypeListAttr<0>;
1315 TF_DerivedOperandTypeListAttr Tcaptured = TF_DerivedOperandTypeListAttr<1>;
1316 TF_DerivedResultTypeListAttr Tout = TF_DerivedResultTypeListAttr<0>;
1317}
1318
1319def TF_AddV2Op : TF_Op<"AddV2", [Commutative, NoSideEffect, ResultsBroadcastableShape, TF_CwiseBinary, TF_LayoutAgnostic, TF_SameOperandsAndResultElementTypeResolveRef]>,
1320 WithBroadcastableBinOpBuilder {
1321 let summary = "Returns x + y element-wise.";
1322
1323 let description = [{
1324*NOTE*: `Add` supports broadcasting. `AddN` does not. More about broadcasting
1325[here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
1326 }];
1327
1328 let arguments = (ins
1329 TensorOf<[TF_Float, TF_SInt, TF_Complex, TF_Uint8, TF_Uint16, TF_Uint32, TF_Uint64]>:$x,
1330 TensorOf<[TF_Float, TF_SInt, TF_Complex, TF_Uint8, TF_Uint16, TF_Uint32, TF_Uint64]>:$y
1331 );
1332
1333 let results = (outs
1334 TensorOf<[TF_Float, TF_SInt, TF_Complex, TF_Uint8, TF_Uint16, TF_Uint32, TF_Uint64]>:$z
1335 );
1336
1337 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1338}
1339
1340def TF_DivNoNanOp : TF_Op<"DivNoNan", [NoSideEffect, ResultsBroadcastableShape, TF_SameOperandsAndResultElementTypeResolveRef]>,
1341 WithBroadcastableBinOpBuilder {
1342 let summary = "Returns 0 if the denominator is zero.";
1343
1344 let description = [{
1345*NOTE*: `DivNoNan` supports broadcasting. More about broadcasting
1346[here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
1347 }];
1348
1349 let arguments = (ins
1350 TensorOf<[TF_Float16, TF_Float32, TF_Float64, TF_Complex]>:$x,
1351 TensorOf<[TF_Float16, TF_Float32, TF_Float64, TF_Complex]>:$y
1352 );
1353
1354 let results = (outs
1355 TensorOf<[TF_Float16, TF_Float32, TF_Float64, TF_Complex]>:$z
1356 );
1357
1358 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1359}
1360
1361def TF_MaximumOp : TF_Op<"Maximum", [NoSideEffect, ResultsBroadcastableShape, TF_SameOperandsAndResultElementTypeResolveRef]>,
1362 WithBroadcastableBinOpBuilder {
1363 let summary = "Returns the max of x and y (i.e. x > y ? x : y) element-wise.";
1364
1365 let description = [{
1366*NOTE*: `Maximum` supports broadcasting. More about broadcasting
1367[here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
1368 }];
1369
1370 let arguments = (ins
1371 TensorOf<[TF_Float, TF_Int16, TF_Int32, TF_Int64, TF_Uint8]>:$x,
1372 TensorOf<[TF_Float, TF_Int16, TF_Int32, TF_Int64, TF_Uint8]>:$y
1373 );
1374
1375 let results = (outs
1376 TensorOf<[TF_Float, TF_Int16, TF_Int32, TF_Int64, TF_Uint8]>:$z
1377 );
1378
1379 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1380}
1381
1382def TF_RealDivOp : TF_Op<"RealDiv", [NoSideEffect, ResultsBroadcastableShape, TF_CwiseBinary]>,
1383 WithBroadcastableBinOpBuilder {
1384 let summary = "Returns x / y element-wise for real types.";
1385
1386 let description = [{
1387If `x` and `y` are reals, this will return the floating-point division.
1388
1389*NOTE*: `Div` supports broadcasting. More about broadcasting
1390[here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
1391 }];
1392
1393 let arguments = (ins
1394 TensorOf<[TF_Float, TF_SInt, TF_Complex, TF_Uint16, TF_Uint8]>:$x,
1395 TensorOf<[TF_Float, TF_SInt, TF_Complex, TF_Uint16, TF_Uint8]>:$y
1396 );
1397
1398 let results = (outs
1399 TensorOf<[TF_Float, TF_SInt, TF_Complex, TF_Uint16, TF_Uint8]>:$z
1400 );
1401
1402 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1403}
1404
1405def TF_AddOp : TF_Op<"Add", [NoSideEffect, ResultsBroadcastableShape, TF_LayoutAgnostic, TF_SameOperandsAndResultElementTypeResolveRef]>,
1406 WithBroadcastableBinOpBuilder {
1407 let summary = "Returns x + y element-wise.";
1408
1409 let description = [{
1410*NOTE*: `Add` supports broadcasting. `AddN` does not. More about broadcasting
1411[here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
1412
1413Given two input tensors, the `tf.add` operation computes the sum for every element in the tensor.
1414
1415Both input and output have a range `(-inf, inf)`.
1416 }];
1417
1418 let arguments = (ins
1419 TensorOf<[TF_NumberNotQuantizedOrStr]>:$x,
1420 TensorOf<[TF_NumberNotQuantizedOrStr]>:$y
1421 );
1422
1423 let results = (outs
1424 TensorOf<[TF_NumberNotQuantizedOrStr]>:$z
1425 );
1426
1427 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1428}
1429
1430def TF_StatefulStandardNormalV2Op : TF_Op<"StatefulStandardNormalV2", []> {
1431 let summary = "Outputs random values from a normal distribution.";
1432
1433 let description = [{
1434The generated values will have mean 0 and standard deviation 1.
1435 }];
1436
1437 let arguments = (ins
1438 Arg<TF_ResourceTensor, "", [TF_VariableRead,TF_VariableWrite]>:$resource,
1439 TF_Int64Tensor:$algorithm,
1440 TF_I32OrI64Tensor:$shape
1441 );
1442
1443 let results = (outs
1444 TF_FloatTensor:$output
1445 );
1446
1447 TF_DerivedOperandTypeAttr shape_dtype = TF_DerivedOperandTypeAttr<2>;
1448 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
1449}
1450
1451def TF_StatefulTruncatedNormalOp : TF_Op<"StatefulTruncatedNormal", []> {
1452 let summary = "Outputs random values from a truncated normal distribution.";
1453
1454 let description = [{
1455The generated values follow a normal distribution with mean 0 and standard
1456deviation 1, except that values whose magnitude is more than 2 standard
1457deviations from the mean are dropped and re-picked.
1458 }];
1459
1460 let arguments = (ins
1461 Arg<TF_ResourceTensor, "", [TF_VariableRead,TF_VariableWrite]>:$resource,
1462 TF_Int64Tensor:$algorithm,
1463 TF_I32OrI64Tensor:$shape
1464 );
1465
1466 let results = (outs
1467 TF_FloatTensor:$output
1468 );
1469
1470 TF_DerivedOperandTypeAttr shape_dtype = TF_DerivedOperandTypeAttr<2>;
1471 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
1472}
1473
1474def TF_StatefulUniformOp : TF_Op<"StatefulUniform", []> {
1475 let summary = "Outputs random values from a uniform distribution.";
1476
1477 let description = [{
1478The generated values follow a uniform distribution in the range `[0, 1)`. The
1479lower bound 0 is included in the range, while the upper bound 1 is excluded.
1480 }];
1481
1482 let arguments = (ins
1483 Arg<TF_ResourceTensor, "", [TF_VariableRead,TF_VariableWrite]>:$resource,
1484 TF_Int64Tensor:$algorithm,
1485 TF_I32OrI64Tensor:$shape
1486 );
1487
1488 let results = (outs
1489 TF_FloatTensor:$output
1490 );
1491
1492 TF_DerivedOperandTypeAttr shape_dtype = TF_DerivedOperandTypeAttr<2>;
1493 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
1494}
1495
1496def TF_StatefulUniformFullIntOp : TF_Op<"StatefulUniformFullInt", []> {
1497 let summary = "Outputs random integers from a uniform distribution.";
1498
1499 let description = [{
1500The generated values are uniform integers covering the whole range of `dtype`.
1501 }];
1502
1503 let arguments = (ins
1504 Arg<TF_ResourceTensor, "", [TF_VariableRead,TF_VariableWrite]>:$resource,
1505 TF_Int64Tensor:$algorithm,
1506 TF_I32OrI64Tensor:$shape
1507 );
1508
1509 let results = (outs
1510 TensorOf<[TF_Int32, TF_Int64, TF_Uint32, TF_Uint64]>:$output
1511 );
1512
1513 TF_DerivedOperandTypeAttr shape_dtype = TF_DerivedOperandTypeAttr<2>;
1514 TF_DerivedResultTypeAttr dtype = TF_DerivedResultTypeAttr<0>;
1515}
1516
1517// TODO(lyandy): Investigate supported dtypes (`minval`, `maxval`, `output`) for
1518// `tf.StatefulUniformInt`. tf2xla kernels support i32, i64, ui32, and ui64
1519// while TensorFlow CPU/GPU kernels only support i32 and i64.
1520def TF_StatefulUniformIntOp : TF_Op<"StatefulUniformInt", []> {
1521 let summary = "Outputs random integers from a uniform distribution.";
1522
1523 let description = [{
1524The generated values are uniform integers in the range `[minval, maxval)`.
1525The lower bound `minval` is included in the range, while the upper bound
1526`maxval` is excluded.
1527
1528The random integers are slightly biased unless `maxval - minval` is an exact
1529power of two. The bias is small for values of `maxval - minval` significantly
1530smaller than the range of the output (either `2^32` or `2^64`).
1531 }];
1532
1533 let arguments = (ins
1534 Arg<TF_ResourceTensor, "", [TF_VariableRead,TF_VariableWrite]>:$resource,
1535 TF_Int64Tensor:$algorithm,
1536 TF_I32OrI64Tensor:$shape,
1537 TensorOf<[TF_Int32, TF_Int64, TF_Uint32, TF_Uint64]>:$minval,
1538 TensorOf<[TF_Int32, TF_Int64, TF_Uint32, TF_Uint64]>:$maxval
1539 );
1540
1541 let results = (outs
1542 TensorOf<[TF_Int32, TF_Int64, TF_Uint32, TF_Uint64]>:$output
1543 );
1544
1545 TF_DerivedOperandTypeAttr shape_dtype = TF_DerivedOperandTypeAttr<2>;
1546 TF_DerivedOperandTypeAttr dtype = TF_DerivedOperandTypeAttr<3>;
1547}
1548
1549def TF_CloseSummaryWriterOp : TF_Op<"CloseSummaryWriter", []> {
1550 let summary = "Flushes and closes the summary writer.";
1551
1552 let description = [{
1553Also removes it from the resource manager. To reopen, use another
1554CreateSummaryFileWriter op.
1555
1556writer: A handle to the summary writer resource.
1557 }];
1558
1559 let arguments = (ins
1560 Arg<TF_ResourceTensor, "", [TF_SummaryFree]>:$writer
1561 );
1562
1563 let results = (outs);
1564}
1565
1566// TODO(b/168035831): Model db_uri read/write.
1567def TF_CreateSummaryDbWriterOp : TF_Op<"CreateSummaryDbWriter", []> {
1568 let summary = "Creates summary database writer accessible by given resource handle.";
1569
1570 let description = [{
1571This can be used to write tensors from the execution graph directly
1572to a database. Only SQLite is supported right now. This function
1573will create the schema if it doesn't exist. Entries in the Users,
1574Experiments, and Runs tables will be created automatically if they
1575don't already exist.
1576
1577writer: Handle to SummaryWriter resource to overwrite.
1578db_uri: For example "file:/tmp/foo.sqlite".
1579experiment_name: Can't contain ASCII control characters or <>. Case
1580 sensitive. If empty, then the Run will not be associated with any
1581 Experiment.
1582run_name: Can't contain ASCII control characters or <>. Case sensitive.
1583 If empty, then each Tag will not be associated with any Run.
1584user_name: Must be valid as both a DNS label and Linux username. If
1585 empty, then the Experiment will not be associated with any User.
1586 }];
1587
1588 let arguments = (ins
1589 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1590 TF_StrTensor:$db_uri,
1591 TF_StrTensor:$experiment_name,
1592 TF_StrTensor:$run_name,
1593 TF_StrTensor:$user_name
1594 );
1595
1596 let results = (outs);
1597}
1598
1599// TODO(b/168035831): Model logdir read/write.
1600def TF_CreateSummaryFileWriterOp : TF_Op<"CreateSummaryFileWriter", []> {
1601 let summary = "Creates a summary file writer accessible by the given resource handle.";
1602
1603 let description = [{
1604writer: A handle to the summary writer resource
1605logdir: Directory where the event file will be written.
1606max_queue: Size of the queue of pending events and summaries.
1607flush_millis: How often, in milliseconds, to flush the pending events and
1608 summaries to disk.
1609filename_suffix: Every event file's name is suffixed with this suffix.
1610 }];
1611
1612 let arguments = (ins
1613 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1614 TF_StrTensor:$logdir,
1615 TF_Int32Tensor:$max_queue,
1616 TF_Int32Tensor:$flush_millis,
1617 TF_StrTensor:$filename_suffix
1618 );
1619
1620 let results = (outs);
1621}
1622
1623def TF_FlushSummaryWriterOp : TF_Op<"FlushSummaryWriter", []> {
1624 let summary = "Flushes the writer's unwritten events.";
1625
1626 let description = [{
1627writer: A handle to the summary writer resource.
1628 }];
1629
1630 let arguments = (ins
1631 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer
1632 );
1633
1634 let results = (outs);
1635}
1636
1637def TF_ImportEventOp : TF_Op<"ImportEvent", []> {
1638 let summary = "Outputs a `tf.Event` protocol buffer.";
1639
1640 let description = [{
1641When CreateSummaryDbWriter is being used, this op can be useful for
1642importing data from event logs.
1643
1644writer: A handle to a summary writer.
1645event: A string containing a binary-encoded tf.Event proto.
1646 }];
1647
1648 let arguments = (ins
1649 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1650 TF_StrTensor:$event
1651 );
1652
1653 let results = (outs);
1654}
1655
1656def TF_SummaryWriterOp : TF_Op<"SummaryWriter", []> {
1657 let summary = "Returns a handle to be used to access a summary writer.";
1658
1659 let description = [{
1660The summary writer is an in-graph resource which can be used by ops to write
1661summaries to event files.
1662
1663writer: the summary writer resource. Scalar handle.
1664 }];
1665
1666 let arguments = (ins
1667 StrAttr:$shared_name,
1668 StrAttr:$container
1669 );
1670
1671 let results = (outs
1672 Res<TF_ResourceTensor, "", [TF_SummaryAlloc]>:$writer
1673 );
1674}
1675
1676def TF_WriteAudioSummaryOp : TF_Op<"WriteAudioSummary", []> {
1677 let summary = "Writes a `Summary` protocol buffer with audio.";
1678
1679 let description = [{
1680The summary has up to `max_outputs` summary values containing audio. The
1681audio is built from `tensor` which must be 3-D with shape `[batch_size,
1682frames, channels]` or 2-D with shape `[batch_size, frames]`. The values are
1683assumed to be in the range of `[-1.0, 1.0]` with a sample rate of `sample_rate`.
1684
1685The `tag` argument is a scalar `Tensor` of type `string`. It is used to
1686build the `tag` of the summary values:
1687
1688* If `max_outputs` is 1, the summary value tag is '*tag*/audio'.
1689* If `max_outputs` is greater than 1, the summary value tags are
1690 generated sequentially as '*tag*/audio/0', '*tag*/audio/1', etc.
1691
1692writer: A handle to a summary writer.
1693step: The step to write the summary for.
1694tag: Scalar. Used to build the `tag` attribute of the summary values.
1695tensor: 2-D of shape `[batch_size, frames]`.
1696sample_rate: The sample rate of the signal in hertz.
1697max_outputs: Max number of batch elements to generate audio for.
1698 }];
1699
1700 let arguments = (ins
1701 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1702 TF_Int64Tensor:$step,
1703 TF_StrTensor:$tag,
1704 TF_Float32Tensor:$tensor,
1705 TF_Float32Tensor:$sample_rate,
1706
1707 Confined<DefaultValuedAttr<I64Attr, "3">, [IntMinValue<1>]>:$max_outputs
1708 );
1709
1710 let results = (outs);
1711}
1712
1713def TF_WriteGraphSummaryOp : TF_Op<"WriteGraphSummary", []> {
1714 let summary = "Writes a `GraphDef` protocol buffer to a `SummaryWriter`.";
1715
1716 let description = [{
1717writer: Handle of `SummaryWriter`.
1718step: The step to write the summary for.
1719tensor: A scalar string of the serialized tf.GraphDef proto.
1720 }];
1721
1722 let arguments = (ins
1723 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1724 TF_Int64Tensor:$step,
1725 TF_StrTensor:$tensor
1726 );
1727
1728 let results = (outs);
1729}
1730
1731def TF_WriteHistogramSummaryOp : TF_Op<"WriteHistogramSummary", []> {
1732 let summary = "Writes a histogram summary.";
1733
1734 let description = [{
1735The generated
1736[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
1737has one summary value containing a histogram for `values`.
1738
1739This op reports an `InvalidArgument` error if any value is not finite.
1740
1741writer: A handle to a summary writer.
1742step: The step to write the summary for.
1743tag: Scalar. Tag to use for the `Summary.Value`.
1744values: Any shape. Values to use to build the histogram.
1745 }];
1746
1747 let arguments = (ins
1748 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1749 TF_Int64Tensor:$step,
1750 TF_StrTensor:$tag,
1751 TF_IntOrFpTensor:$values
1752 );
1753
1754 let results = (outs);
1755
1756 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<3>;
1757}
1758
1759def TF_WriteImageSummaryOp : TF_Op<"WriteImageSummary", []> {
1760 let summary = "Writes a `Summary` protocol buffer with images.";
1761
1762 let description = [{
1763The summary has up to `max_images` summary values containing images. The
1764images are built from `tensor` which must be 4-D with shape `[batch_size,
1765height, width, channels]` and where `channels` can be:
1766
1767* 1: `tensor` is interpreted as Grayscale.
1768* 3: `tensor` is interpreted as RGB.
1769* 4: `tensor` is interpreted as RGBA.
1770
1771The images have the same number of channels as the input tensor. For float
1772input, the values are normalized one image at a time to fit in the range
1773`[0, 255]`. `uint8` values are unchanged. The op uses two different
1774normalization algorithms:
1775
1776* If the input values are all positive, they are rescaled so the largest one
1777 is 255.
1778
1779* If any input value is negative, the values are shifted so input value 0.0
1780 is at 127. They are then rescaled so that either the smallest value is 0,
1781 or the largest one is 255.
1782
1783The `tag` argument is a scalar `Tensor` of type `string`. It is used to
1784build the `tag` of the summary values:
1785
1786* If `max_images` is 1, the summary value tag is '*tag*/image'.
1787* If `max_images` is greater than 1, the summary value tags are
1788 generated sequentially as '*tag*/image/0', '*tag*/image/1', etc.
1789
1790The `bad_color` argument is the color to use in the generated images for
1791non-finite input values. It is a `unit8` 1-D tensor of length `channels`.
1792Each element must be in the range `[0, 255]` (It represents the value of a
1793pixel in the output image). Non-finite values in the input tensor are
1794replaced by this tensor in the output image. The default value is the color
1795red.
1796
1797writer: A handle to a summary writer.
1798step: The step to write the summary for.
1799tag: Scalar. Used to build the `tag` attribute of the summary values.
1800tensor: 4-D of shape `[batch_size, height, width, channels]` where
1801 `channels` is 1, 3, or 4.
1802max_images: Max number of batch elements to generate images for.
1803bad_color: Color to use for pixels with non-finite values.
1804 }];
1805
1806 let arguments = (ins
1807 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1808 TF_Int64Tensor:$step,
1809 TF_StrTensor:$tag,
1810 TensorOf<[TF_Float16, TF_Float32, TF_Uint8]>:$tensor,
1811 TF_Uint8Tensor:$bad_color,
1812
1813 Confined<DefaultValuedAttr<I64Attr, "3">, [IntMinValue<1>]>:$max_images
1814 );
1815
1816 let results = (outs);
1817
1818 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<3>;
1819}
1820
1821def TF_WriteRawProtoSummaryOp : TF_Op<"WriteRawProtoSummary", []> {
1822 let summary = "Writes a `Summary` protocol buffer with serialized string `Summary` protocol buffers.";
1823
1824 let description = [{
1825writer: A handle to a summary writer.
1826step: The step to write the summary for.
1827tensor: A tensor holding one or more serialized `Summary` protobufs to write.
1828 }];
1829
1830 let arguments = (ins
1831 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1832 TF_Int64Tensor:$step,
1833 TF_StrTensor:$tensor
1834 );
1835
1836 let results = (outs);
1837}
1838
1839def TF_WriteScalarSummaryOp : TF_Op<"WriteScalarSummary", []> {
1840 let summary = "Writes a `Summary` protocol buffer with scalar values.";
1841
1842 let description = [{
1843The input `tag` and `value` must have the scalars.
1844
1845writer: A handle to a summary writer.
1846step: The step to write the summary for.
1847tag: Tag for the summary.
1848value: Value for the summary.
1849 }];
1850
1851 let arguments = (ins
1852 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1853 TF_Int64Tensor:$step,
1854 TF_StrTensor:$tag,
1855 TF_IntOrFpTensor:$value
1856 );
1857
1858 let results = (outs);
1859
1860 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<3>;
1861}
1862
1863def TF_WriteSummaryOp : TF_Op<"WriteSummary", []> {
1864 let summary = "Outputs a `Summary` protocol buffer with a tensor.";
1865
1866 let description = [{
1867writer: A handle to a summary writer.
1868step: The step to write the summary for.
1869tensor: A tensor to serialize.
1870tag: The summary's tag.
1871summary_metadata: Serialized SummaryMetadata protocol buffer containing
1872 plugin-related metadata for this summary.
1873 }];
1874
1875 let arguments = (ins
1876 Arg<TF_ResourceTensor, "", [TF_SummaryWrite]>:$writer,
1877 TF_Int64Tensor:$step,
1878 TF_Tensor:$tensor,
1879 TF_StrTensor:$tag,
1880 TF_StrTensor:$summary_metadata
1881 );
1882
1883 let results = (outs);
1884
1885 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<2>;
1886}
1887
1888def TF_InitializeTableFromDatasetOp : TF_Op<"InitializeTableFromDataset", []> {
1889 let summary = "";
1890
1891 let arguments = (ins
1892 Arg<TF_ResourceTensor, "", [TF_LookupTableWrite]>:$table_handle,
1893 TF_VariantTensor:$dataset
1894 );
1895
1896 let results = (outs);
1897}
1898
1899// TODO(b/168035831): Model filename read.
1900def TF_InitializeTableFromTextFileV2Op : TF_Op<"InitializeTableFromTextFileV2", []> {
1901 let summary = "Initializes a table from a text file.";
1902
1903 let description = [{
1904It inserts one key-value pair into the table for each line of the file.
1905The key and value is extracted from the whole line content, elements from the
1906split line based on `delimiter` or the line number (starting from zero).
1907Where to extract the key and value from a line is specified by `key_index` and
1908`value_index`.
1909
1910- A value of -1 means use the line number(starting from zero), expects `int64`.
1911- A value of -2 means use the whole line content, expects `string`.
1912- A value >= 0 means use the index (starting at zero) of the split line based
1913 on `delimiter`.
1914 }];
1915
1916 let arguments = (ins
1917 Arg<TF_ResourceTensor, "", [TF_LookupTableWrite]>:$table_handle,
1918 TF_StrTensor:$filename,
1919
1920 Confined<I64Attr, [IntMinValue<-2>]>:$key_index,
1921 Confined<I64Attr, [IntMinValue<-2>]>:$value_index,
1922 Confined<DefaultValuedAttr<I64Attr, "-1">, [IntMinValue<-1>]>:$vocab_size,
1923 DefaultValuedAttr<StrAttr, "\t">:$delimiter
1924 );
1925
1926 let results = (outs);
1927}
1928
1929// TODO(b/168035831): Model filename read.
1930def TF_CacheDatasetV2Op : TF_Op<"CacheDatasetV2", []> {
1931 let summary = "";
1932
1933 let arguments = (ins
1934 TF_VariantTensor:$input_dataset,
1935 TF_StrTensor:$filename,
1936 Arg<TF_ResourceTensor, "", [TF_DatasetMemoryCacheRead, TF_DatasetMemoryCacheWrite]>:$cache,
1937
1938 Confined<TypeArrayAttr, [ArrayMinCount<1>]>:$output_types,
1939 Confined<TF_ShapeAttrArray, [ArrayMinCount<1>]>:$output_shapes
1940 );
1941
1942 let results = (outs
1943 TF_VariantTensor:$handle
1944 );
1945}
1946
1947def TF__TPUDeviceOrdinalPlaceholderOp : TF_Op<"_TPUDeviceOrdinalPlaceholder", []> {
1948 let summary = [{
1949Placeholder device ordinal that represents device ordinal of a replicated op.
1950 }];
1951
1952 let description = [{
1953This op can be used when certain rewrite passes materialize ops that require a
1954device ordinal of a replicated op but replication logic has been abstracted away
1955using tf_device.replicate op. Subsequent rewrite passes must replace this op with
1956a constant output that represents the correct device ordinal of the replicated
1957operations inside a TPU host.
1958 }];
1959
1960 let arguments = (ins);
1961
1962 let results = (outs
1963 TF_Int64Tensor:$device_ordinal
1964 );
1965}
1966
1967def TF_AssignOp : TF_Op<"Assign", []> {
1968 let summary = "Update 'ref' by assigning 'value' to it.";
1969
1970 let description = [{
1971This operation outputs "ref" after the assignment is done.
1972This makes it easier to chain operations that need to use the reset value.
1973
1974This is a side-effecting operation because it will change the value of its
1975argument "ref" in addition to returning the results.
1976 }];
1977
1978 let arguments = (ins
1979 TF_Tensor:$ref,
1980 TF_Tensor:$value,
1981
1982 DefaultValuedAttr<BoolAttr, "true">:$validate_shape,
1983 DefaultValuedAttr<BoolAttr, "true">:$use_locking
1984 );
1985
1986 let results = (outs
1987 TF_Tensor:$output_ref
1988 );
1989
1990 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
1991}
1992
1993def TF_TPUPartitionedInputOp : TF_Op<"TPUPartitionedInput", [NoSideEffect]> {
1994 let summary = [{
1995An op that groups a list of partitioned inputs together. This op
1996 }];
1997
1998 let arguments = (ins
1999 Variadic<TF_Tensor>:$inputs,
2000
2001 DefaultValuedAttr<I64Attr, "0">:$partition_dim,
2002 OptionalAttr<StrAttr>:$_XlaSharding
2003 );
2004
2005 let results = (outs
2006 TF_Tensor:$output
2007 );
2008
2009 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
2010 TF_DerivedOperandSizeAttr N = TF_DerivedOperandSizeAttr<0>;
2011}
2012
2013def TF_TPUPartitionedOutputOp : TF_Op<"TPUPartitionedOutput", [NoSideEffect]> {
2014 let summary = [{
2015An op that demultiplexes a tensor to be sharded by XLA to a list of partitioned
2016 }];
2017
2018 let description = [{
2019outputs outside the XLA computation.
2020 }];
2021
2022 let arguments = (ins
2023 TF_Tensor:$inputs,
2024
2025 DefaultValuedAttr<I64Attr, "0">:$partition_dim,
2026 OptionalAttr<StrAttr>:$_XlaSharding
2027 );
2028
2029 let results = (outs
2030 Variadic<TF_Tensor>:$output
2031 );
2032
2033 TF_DerivedOperandTypeAttr T = TF_DerivedOperandTypeAttr<0>;
2034 TF_DerivedResultSizeAttr num_splits = TF_DerivedResultSizeAttr<0>;
2035}
2036
2037#endif // TF_OPS