Skip to content

Automated sync from github.com/tensorflow/tensorflow #3146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tensorflow/lite/core/c/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,8 @@ TfLiteRunStep TfLiteTensorGetShapeKnownStep(const TfLiteTensor* t) {
return kTfLiteRunStepUnknown;
}

// Returns a sentinel value to be used as the user_data field of a TfLiteNode
// when the kernel initialization fails.
void* TfLiteKernelInitFailed() { return reinterpret_cast<void*>(-1); }

} // extern "C"
9 changes: 9 additions & 0 deletions tensorflow/lite/core/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,11 @@ typedef struct TfLiteRegistration {
/// NOTE: if the data is already in the desired format, simply implement this
/// function to return `nullptr` and implement the free function to be a
/// no-op.
///
/// NOTE: For a Delegate kernel, returns `TfLiteKernelInitFailed()` if it
/// fails on the initialization. This eventually causes user's API call to
/// InterpreterBuilder::operator() or Interpreter::ModifyGraphWithDelegate()
/// to return an error.
void* (*init)(TfLiteContext* context, const char* buffer, size_t length);

/// The pointer `buffer` is the data previously returned by an init
Expand Down Expand Up @@ -1499,6 +1504,10 @@ TfLiteRunStep TfLiteTensorGetDataKnownStep(const TfLiteTensor* t);
/// operations.
TfLiteRunStep TfLiteTensorGetShapeKnownStep(const TfLiteTensor* t);

/// Returns a sentinel value to be used as the user_data field of a TfLiteNode
/// when the kernel initialization fails.
void* TfLiteKernelInitFailed();

/** @} */
// Ends `\addtogroup`, it's important for the doc generator that this doesn't
// include the CC code below.
Expand Down
1 change: 1 addition & 0 deletions tensorflow/lite/kernels/internal/portable_tensor_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ inline void BatchQuantizeFloats(const float* float_data_ptr, int n_batch,
tensor_utils::SymmetricQuantizeFloats(
float_data_ptr + offset, n_data, quantized_data_ptr + offset,
&unused_min, &unused_max, &scaling_factors[b]);
if (zero_points) zero_points[b] = 0;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include "tensorflow/lite/kernels/internal/common.h"
#include "tensorflow/lite/kernels/internal/compatibility.h"
#include "tensorflow/lite/kernels/internal/portable_tensor_utils.h"
#include "tensorflow/lite/kernels/internal/runtime_shape.h"
#include "tensorflow/lite/kernels/internal/types.h"

namespace tflite {
Expand Down
25 changes: 25 additions & 0 deletions tensorflow/lite/kernels/internal/reference/div.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ inline void Div(const ArithmeticParams& params,
DivElementwise(flat_size, params, input1_data, input2_data, output_data);
}

inline void Div(const ArithmeticParams& params,
const RuntimeShape& input1_shape, const int16_t* input1_data,
const RuntimeShape& input2_shape, const int16_t* input2_data,
const RuntimeShape& output_shape, int16_t* output_data) {
TFLITE_DCHECK_LE(params.quantized_activation_min,
params.quantized_activation_max);
const int flat_size =
MatchingElementsSize(input1_shape, input2_shape, output_shape);

DivElementwise(flat_size, params, input1_data, input2_data, output_data);
}

template <typename T, int N = 5>
inline void BroadcastDivSlowQuantized(
const ArithmeticParams& params, const RuntimeShape& unextended_input1_shape,
Expand Down Expand Up @@ -177,6 +189,19 @@ inline void BroadcastDivSlow(const ArithmeticParams& params,
input2_data, unextended_output_shape, output_data);
}

template <int N = 5>
inline void BroadcastDivSlow(const ArithmeticParams& params,
const RuntimeShape& unextended_input1_shape,
const int16_t* input1_data,
const RuntimeShape& unextended_input2_shape,
const int16_t* input2_data,
const RuntimeShape& unextended_output_shape,
int16_t* output_data) {
BroadcastDivSlowQuantized<int16_t, N>(
params, unextended_input1_shape, input1_data, unextended_input2_shape,
input2_data, unextended_output_shape, output_data);
}

// TODO(jiawen): We can implement BroadcastDiv on buffers of arbitrary
// dimensionality if the runtime code does a single loop over one dimension
// that handles broadcasting as the base case. The code generator would then
Expand Down
8 changes: 4 additions & 4 deletions tensorflow/lite/kernels/internal/reference/prelu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace tflite {
namespace reference_ops {

// Broadcast prelu to output_shape for quantized uint8_t/int8_t data.
template <typename T>
template <typename T, typename U>
inline void BroadcastPrelu4DSlow(
const PreluParams& params, const RuntimeShape& input_shape,
const T* input_data, const RuntimeShape& alpha_shape, const T* alpha_data,
const T* input_data, const RuntimeShape& alpha_shape, const U* alpha_data,
const RuntimeShape& output_shape, T* output_data) {
TFLITE_DCHECK_LE(input_shape.DimensionsCount(), 4);
TFLITE_DCHECK_LE(alpha_shape.DimensionsCount(), 4);
Expand Down Expand Up @@ -74,10 +74,10 @@ inline void BroadcastPrelu4DSlow(
}
}

template <typename T>
template <typename T, typename U>
inline void Prelu(const PreluParams& params, const RuntimeShape& input_shape,
const T* input_data, const RuntimeShape& alpha_shape,
const T* alpha_data, const RuntimeShape& output_shape,
const U* alpha_data, const RuntimeShape& output_shape,
T* output_data) {
const int32_t quantized_min = std::numeric_limits<T>::min();
const int32_t quantized_max = std::numeric_limits<T>::max();
Expand Down
Loading