MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / SigmoidPrepare

Function SigmoidPrepare

tensorflow/lite/kernels/activations.cc:354–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352
353template <KernelType kernel_type>
354TfLiteStatus SigmoidPrepare(TfLiteContext* context, TfLiteNode* node) {
355 OpData* data = reinterpret_cast<OpData*>(node->user_data);
356
357 TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
358 TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
359 const TfLiteTensor* input = GetInput(context, node, 0);
360 TfLiteTensor* output = GetOutput(context, node, 0);
361 TF_LITE_ENSURE_EQ(context, input->type, output->type);
362
363 if (kernel_type == kFixedPointOptimized) {
364 if (input->type == kTfLiteUInt8 || input->type == kTfLiteInt8) {
365 if (input->type == kTfLiteUInt8) {
366 TF_LITE_ENSURE_EQ(context, output->params.zero_point,
367 std::numeric_limits<uint8_t>::min());
368 }
369 if (input->type == kTfLiteInt8) {
370 TF_LITE_ENSURE_EQ(context, output->params.zero_point,
371 std::numeric_limits<int8_t>::min());
372 }
373 TF_LITE_ENSURE(context, output->params.scale == 1. / 256);
374
375 static constexpr int kInputIntegerBits = 4;
376
377 const double input_real_multiplier =
378 input->params.scale *
379 static_cast<double>(1 << (15 - kInputIntegerBits));
380
381 const double q =
382 std::frexp(input_real_multiplier, &data->input_left_shift);
383 auto q_fixed = static_cast<int32_t>(TfLiteRound(q * (1ll << 15)));
384 data->input_multiplier = static_cast<int16_t>(q_fixed);
385
386 int16_t input_range_radius =
387 CalculateInputRadius(kInputIntegerBits, data->input_left_shift, 15);
388 data->input_range_radius = input_range_radius;
389 }
390 }
391
392 if (kernel_type == kGenericOptimized || kernel_type == kReference) {
393 if (input->type == kTfLiteUInt8) {
394 TF_LITE_ENSURE(context, output->params.scale == 1. / 256);
395 PopulateLookupTable<uint8_t>(data, input, output, [](float value) {
396 return 1.0f / (1.0f + std::exp(-value));
397 });
398 } else if (input->type == kTfLiteInt8) {
399 TF_LITE_ENSURE(context, output->params.scale == 1. / 256);
400 PopulateLookupTable<int8_t>(data, input, output, [](float value) {
401 return 1.0f / (1.0f + std::exp(-value));
402 });
403 }
404 }
405
406 if (input->type == kTfLiteInt16) {
407 static constexpr int kInputIntegerBits = 3;
408 static constexpr int kOutputFractionalBits = 15;
409
410 // See comments in TanhPrepare about requiring zero_point==0
411 // and a power-of-two ("POT") scale.

Callers

nothing calls this directly

Calls 11

NumInputsFunction · 0.85
GetInputFunction · 0.85
GetOutputFunction · 0.85
TfLiteRoundFunction · 0.85
CalculateInputRadiusFunction · 0.85
CheckedLog2Function · 0.85
TfLiteIntArrayCopyFunction · 0.85
ResizeTensorMethod · 0.80
NumOutputsFunction · 0.70
minFunction · 0.50
expFunction · 0.50

Tested by

no test coverage detected