Skip to content

Commit 857f467

Browse files
authored
Automated sync from github.com/tensorflow/tensorflow (#1843)
BUG=automated sync from upstream NO_CHECK_TFLITE_FILES=automated sync from upstream
1 parent ea36733 commit 857f467

File tree

7 files changed

+232
-25
lines changed

7 files changed

+232
-25
lines changed

tensorflow/lite/builtin_ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ typedef enum {
186186
kTfLiteBuiltinAtan2 = 156,
187187
kTfLiteBuiltinUnsortedSegmentMin = 157,
188188
kTfLiteBuiltinSign = 158,
189+
kTfLiteBuiltinBitcast = 159,
189190
} TfLiteBuiltinOperator;
190191

191192
#ifdef __cplusplus

tensorflow/lite/core/api/flatbuffer_conversions.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
885885
case BuiltinOperator_UNSORTED_SEGMENT_SUM:
886886
case BuiltinOperator_ATAN2:
887887
case BuiltinOperator_SIGN:
888+
case BuiltinOperator_BITCAST:
888889
case BuiltinOperator_WHERE:
889890
return kTfLiteOk;
890891
case BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES:

tensorflow/lite/kernels/internal/reference/mul.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ inline void Mul(const ArithmeticParams& params,
5656
const int flat_size =
5757
MatchingExtendedShapeFlatSize(input1_shape, input2_shape, output_shape);
5858
for (int i = 0; i < flat_size; ++i) {
59-
output_data[i] = ActivationFunctionWithMinMax(
59+
output_data[i] = ActivationFunctionWithMinMax<T>(
6060
input1_data[i] * input2_data[i], output_activation_min,
6161
output_activation_max);
6262
}
@@ -128,14 +128,18 @@ inline void BroadcastMul4DSlow(const ArithmeticParams& params,
128128
}
129129
}
130130

131-
template <typename T>
132-
void BroadcastMul4DSlow(const ArithmeticParams& params,
133-
const RuntimeShape& unextended_input1_shape,
134-
const T* input1_data,
135-
const RuntimeShape& unextended_input2_shape,
136-
const T* input2_data,
137-
const RuntimeShape& unextended_output_shape,
138-
T* output_data) {
131+
template <typename T,
132+
// For unquantized mul on small integers, explictly set to true.
133+
bool enable_for_short_integers = false>
134+
inline typename std::enable_if<
135+
!is_small_integer<T>::value || enable_for_short_integers, void>::type
136+
BroadcastMul4DSlow(const ArithmeticParams& params,
137+
const RuntimeShape& unextended_input1_shape,
138+
const T* input1_data,
139+
const RuntimeShape& unextended_input2_shape,
140+
const T* input2_data,
141+
const RuntimeShape& unextended_output_shape,
142+
T* output_data) {
139143
T output_activation_min;
140144
T output_activation_max;
141145
GetActivationParams(params, &output_activation_min, &output_activation_max);
@@ -167,7 +171,7 @@ void BroadcastMul4DSlow(const ArithmeticParams& params,
167171
for (int x = 0; x < output_shape.Dims(2); ++x) {
168172
for (int c = 0; c < output_shape.Dims(3); ++c) {
169173
output_data[Offset(output_shape, b, y, x, c)] =
170-
ActivationFunctionWithMinMax(
174+
ActivationFunctionWithMinMax<T>(
171175
input1_data[SubscriptToIndex(desc1, b, y, x, c)] *
172176
input2_data[SubscriptToIndex(desc2, b, y, x, c)],
173177
output_activation_min, output_activation_max);

tensorflow/lite/kernels/internal/types.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -1025,6 +1025,12 @@ inline void SetActivationParams(int32_t min, int32_t max, P* params) {
10251025
params->quantized_activation_max = max;
10261026
}
10271027

1028+
template <typename P>
1029+
inline void SetActivationParams(uint32_t min, uint32_t max, P* params) {
1030+
params->quantized_activation_min = min;
1031+
params->quantized_activation_max = max;
1032+
}
1033+
10281034
template <typename P>
10291035
inline void SetActivationParams(int16_t min, int16_t max, P* params) {
10301036
params->int16_activation_min = min;
@@ -1043,6 +1049,12 @@ inline void GetActivationParams(const P& params, int32_t* min, int32_t* max) {
10431049
*max = params.quantized_activation_max;
10441050
}
10451051

1052+
template <typename P>
1053+
inline void GetActivationParams(const P& params, uint32_t* min, uint32_t* max) {
1054+
*min = params.quantized_activation_min;
1055+
*max = params.quantized_activation_max;
1056+
}
1057+
10461058
template <typename P>
10471059
inline void GetActivationParams(const P& params, int16_t* min, int16_t* max) {
10481060
*min = params.int16_activation_min;

tensorflow/lite/python/schema_py_generated.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,70 @@ def Pack(self, builder):
937937
from flatbuffers.compat import import_numpy
938938
np = import_numpy()
939939

940+
class BitcastOptions(object):
941+
__slots__ = ['_tab']
942+
943+
@classmethod
944+
def GetRootAs(cls, buf, offset=0):
945+
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
946+
x = BitcastOptions()
947+
x.Init(buf, n + offset)
948+
return x
949+
950+
@classmethod
951+
def GetRootAsBitcastOptions(cls, buf, offset=0):
952+
"""This method is deprecated. Please switch to GetRootAs."""
953+
return cls.GetRootAs(buf, offset)
954+
@classmethod
955+
def BitcastOptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
956+
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed)
957+
958+
# BitcastOptions
959+
def Init(self, buf, pos):
960+
self._tab = flatbuffers.table.Table(buf, pos)
961+
962+
def BitcastOptionsStart(builder): builder.StartObject(0)
963+
def Start(builder):
964+
return BitcastOptionsStart(builder)
965+
def BitcastOptionsEnd(builder): return builder.EndObject()
966+
def End(builder):
967+
return BitcastOptionsEnd(builder)
968+
969+
class BitcastOptionsT(object):
970+
971+
# BitcastOptionsT
972+
def __init__(self):
973+
pass
974+
975+
@classmethod
976+
def InitFromBuf(cls, buf, pos):
977+
bitcastOptions = BitcastOptions()
978+
bitcastOptions.Init(buf, pos)
979+
return cls.InitFromObj(bitcastOptions)
980+
981+
@classmethod
982+
def InitFromObj(cls, bitcastOptions):
983+
x = BitcastOptionsT()
984+
x._UnPack(bitcastOptions)
985+
return x
986+
987+
# BitcastOptionsT
988+
def _UnPack(self, bitcastOptions):
989+
if bitcastOptions is None:
990+
return
991+
992+
# BitcastOptionsT
993+
def Pack(self, builder):
994+
BitcastOptionsStart(builder)
995+
bitcastOptions = BitcastOptionsEnd(builder)
996+
return bitcastOptions
997+
# automatically generated by the FlatBuffers compiler, do not modify
998+
999+
# namespace: tflite
1000+
1001+
from flatbuffers.compat import import_numpy
1002+
np = import_numpy()
1003+
9401004
class BroadcastToOptions(object):
9411005
__slots__ = ['_tab']
9421006

@@ -1394,6 +1458,7 @@ class BuiltinOperator(object):
13941458
ATAN2 = 156
13951459
UNSORTED_SEGMENT_MIN = 157
13961460
SIGN = 158
1461+
BITCAST = 159
13971462
# automatically generated by the FlatBuffers compiler, do not modify
13981463

13991464
# namespace: tflite
@@ -1523,6 +1588,7 @@ class BuiltinOptions(object):
15231588
UnsortedSegmentSumOptions = 121
15241589
ATan2Options = 122
15251590
SignOptions = 123
1591+
BitcastOptions = 124
15261592

15271593
def BuiltinOptionsCreator(unionType, table):
15281594
from flatbuffers.table import Table
@@ -1774,6 +1840,8 @@ def BuiltinOptionsCreator(unionType, table):
17741840
return ATan2OptionsT.InitFromBuf(table.Bytes, table.Pos)
17751841
if unionType == BuiltinOptions().SignOptions:
17761842
return SignOptionsT.InitFromBuf(table.Bytes, table.Pos)
1843+
if unionType == BuiltinOptions().BitcastOptions:
1844+
return BitcastOptionsT.InitFromBuf(table.Bytes, table.Pos)
17771845
return None
17781846
# automatically generated by the FlatBuffers compiler, do not modify
17791847

@@ -7454,7 +7522,7 @@ def __init__(self):
74547522
self.inputs = None # type: List[int]
74557523
self.outputs = None # type: List[int]
74567524
self.builtinOptionsType = 0 # type: int
7457-
self.builtinOptions = None # type: Union[None, Conv2DOptionsT, DepthwiseConv2DOptionsT, ConcatEmbeddingsOptionsT, LSHProjectionOptionsT, Pool2DOptionsT, SVDFOptionsT, RNNOptionsT, FullyConnectedOptionsT, SoftmaxOptionsT, ConcatenationOptionsT, AddOptionsT, L2NormOptionsT, LocalResponseNormalizationOptionsT, LSTMOptionsT, ResizeBilinearOptionsT, CallOptionsT, ReshapeOptionsT, SkipGramOptionsT, SpaceToDepthOptionsT, EmbeddingLookupSparseOptionsT, MulOptionsT, PadOptionsT, GatherOptionsT, BatchToSpaceNDOptionsT, SpaceToBatchNDOptionsT, TransposeOptionsT, ReducerOptionsT, SubOptionsT, DivOptionsT, SqueezeOptionsT, SequenceRNNOptionsT, StridedSliceOptionsT, ExpOptionsT, TopKV2OptionsT, SplitOptionsT, LogSoftmaxOptionsT, CastOptionsT, DequantizeOptionsT, MaximumMinimumOptionsT, ArgMaxOptionsT, LessOptionsT, NegOptionsT, PadV2OptionsT, GreaterOptionsT, GreaterEqualOptionsT, LessEqualOptionsT, SelectOptionsT, SliceOptionsT, TransposeConvOptionsT, SparseToDenseOptionsT, TileOptionsT, ExpandDimsOptionsT, EqualOptionsT, NotEqualOptionsT, ShapeOptionsT, PowOptionsT, ArgMinOptionsT, FakeQuantOptionsT, PackOptionsT, LogicalOrOptionsT, OneHotOptionsT, LogicalAndOptionsT, LogicalNotOptionsT, UnpackOptionsT, FloorDivOptionsT, SquareOptionsT, ZerosLikeOptionsT, FillOptionsT, BidirectionalSequenceLSTMOptionsT, BidirectionalSequenceRNNOptionsT, UnidirectionalSequenceLSTMOptionsT, FloorModOptionsT, RangeOptionsT, ResizeNearestNeighborOptionsT, LeakyReluOptionsT, SquaredDifferenceOptionsT, MirrorPadOptionsT, AbsOptionsT, SplitVOptionsT, UniqueOptionsT, ReverseV2OptionsT, AddNOptionsT, GatherNdOptionsT, CosOptionsT, WhereOptionsT, RankOptionsT, ReverseSequenceOptionsT, MatrixDiagOptionsT, QuantizeOptionsT, MatrixSetDiagOptionsT, HardSwishOptionsT, IfOptionsT, WhileOptionsT, DepthToSpaceOptionsT, NonMaxSuppressionV4OptionsT, NonMaxSuppressionV5OptionsT, ScatterNdOptionsT, SelectV2OptionsT, DensifyOptionsT, SegmentSumOptionsT, BatchMatMulOptionsT, CumsumOptionsT, CallOnceOptionsT, BroadcastToOptionsT, Rfft2dOptionsT, Conv3DOptionsT, HashtableOptionsT, HashtableFindOptionsT, HashtableImportOptionsT, HashtableSizeOptionsT, VarHandleOptionsT, ReadVariableOptionsT, AssignVariableOptionsT, RandomOptionsT, BucketizeOptionsT, GeluOptionsT, DynamicUpdateSliceOptionsT, UnsortedSegmentProdOptionsT, UnsortedSegmentMaxOptionsT, UnsortedSegmentMinOptionsT, UnsortedSegmentSumOptionsT, ATan2OptionsT, SignOptionsT]
7525+
self.builtinOptions = None # type: Union[None, Conv2DOptionsT, DepthwiseConv2DOptionsT, ConcatEmbeddingsOptionsT, LSHProjectionOptionsT, Pool2DOptionsT, SVDFOptionsT, RNNOptionsT, FullyConnectedOptionsT, SoftmaxOptionsT, ConcatenationOptionsT, AddOptionsT, L2NormOptionsT, LocalResponseNormalizationOptionsT, LSTMOptionsT, ResizeBilinearOptionsT, CallOptionsT, ReshapeOptionsT, SkipGramOptionsT, SpaceToDepthOptionsT, EmbeddingLookupSparseOptionsT, MulOptionsT, PadOptionsT, GatherOptionsT, BatchToSpaceNDOptionsT, SpaceToBatchNDOptionsT, TransposeOptionsT, ReducerOptionsT, SubOptionsT, DivOptionsT, SqueezeOptionsT, SequenceRNNOptionsT, StridedSliceOptionsT, ExpOptionsT, TopKV2OptionsT, SplitOptionsT, LogSoftmaxOptionsT, CastOptionsT, DequantizeOptionsT, MaximumMinimumOptionsT, ArgMaxOptionsT, LessOptionsT, NegOptionsT, PadV2OptionsT, GreaterOptionsT, GreaterEqualOptionsT, LessEqualOptionsT, SelectOptionsT, SliceOptionsT, TransposeConvOptionsT, SparseToDenseOptionsT, TileOptionsT, ExpandDimsOptionsT, EqualOptionsT, NotEqualOptionsT, ShapeOptionsT, PowOptionsT, ArgMinOptionsT, FakeQuantOptionsT, PackOptionsT, LogicalOrOptionsT, OneHotOptionsT, LogicalAndOptionsT, LogicalNotOptionsT, UnpackOptionsT, FloorDivOptionsT, SquareOptionsT, ZerosLikeOptionsT, FillOptionsT, BidirectionalSequenceLSTMOptionsT, BidirectionalSequenceRNNOptionsT, UnidirectionalSequenceLSTMOptionsT, FloorModOptionsT, RangeOptionsT, ResizeNearestNeighborOptionsT, LeakyReluOptionsT, SquaredDifferenceOptionsT, MirrorPadOptionsT, AbsOptionsT, SplitVOptionsT, UniqueOptionsT, ReverseV2OptionsT, AddNOptionsT, GatherNdOptionsT, CosOptionsT, WhereOptionsT, RankOptionsT, ReverseSequenceOptionsT, MatrixDiagOptionsT, QuantizeOptionsT, MatrixSetDiagOptionsT, HardSwishOptionsT, IfOptionsT, WhileOptionsT, DepthToSpaceOptionsT, NonMaxSuppressionV4OptionsT, NonMaxSuppressionV5OptionsT, ScatterNdOptionsT, SelectV2OptionsT, DensifyOptionsT, SegmentSumOptionsT, BatchMatMulOptionsT, CumsumOptionsT, CallOnceOptionsT, BroadcastToOptionsT, Rfft2dOptionsT, Conv3DOptionsT, HashtableOptionsT, HashtableFindOptionsT, HashtableImportOptionsT, HashtableSizeOptionsT, VarHandleOptionsT, ReadVariableOptionsT, AssignVariableOptionsT, RandomOptionsT, BucketizeOptionsT, GeluOptionsT, DynamicUpdateSliceOptionsT, UnsortedSegmentProdOptionsT, UnsortedSegmentMaxOptionsT, UnsortedSegmentMinOptionsT, UnsortedSegmentSumOptionsT, ATan2OptionsT, SignOptionsT, BitcastOptionsT]
74587526
self.customOptions = None # type: List[int]
74597527
self.customOptionsFormat = 0 # type: int
74607528
self.mutatingVariableInputs = None # type: List[bool]

tensorflow/lite/schema/schema.fbs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ enum BuiltinOperator : int32 {
413413
UNSORTED_SEGMENT_SUM = 155,
414414
ATAN2 = 156,
415415
UNSORTED_SEGMENT_MIN = 157,
416-
SIGN = 158
416+
SIGN = 158,
417+
BITCAST = 159
417418
}
418419
// LINT.ThenChange(nnapi_linter/linter.proto)
419420

@@ -541,7 +542,8 @@ union BuiltinOptions {
541542
UnsortedSegmentMinOptions,
542543
UnsortedSegmentSumOptions,
543544
ATan2Options,
544-
SignOptions
545+
SignOptions,
546+
BitcastOptions
545547
}
546548

547549
// LINT.IfChange
@@ -1178,6 +1180,9 @@ table UnsortedSegmentMinOptions{
11781180
table SignOptions {
11791181
}
11801182

1183+
table BitcastOptions {
1184+
}
1185+
11811186

11821187
// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a
11831188
// builtin, or a string if the operator is custom.

0 commit comments

Comments
 (0)