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

Function EvalSum

tensorflow/lite/kernels/reduce.cc:569–632  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567}
568
569TfLiteStatus EvalSum(TfLiteContext* context, TfLiteNode* node) {
570 OpContext op_context(context, node);
571 gemmlowp::ScopedProfilingLabel label("Sum");
572 const auto& input = op_context.input;
573 const auto& output = op_context.output;
574 const bool same_scale =
575 (input->params.scale == output->params.scale &&
576 input->params.zero_point == output->params.zero_point);
577 const bool eight_bit_quantized =
578 input->type == kTfLiteUInt8 || input->type == kTfLiteInt8;
579 const bool need_rescale = (eight_bit_quantized && !same_scale);
580 if (need_rescale) {
581 // Rescaling 8bit reduce sum.
582 int num_axis = static_cast<int>(NumElements(op_context.axis));
583 TfLiteTensor* temp_index = GetTemporary(context, node, /*index=*/0);
584 TfLiteTensor* resolved_axis = GetTemporary(context, node, /*index=*/1);
585 TfLiteTensor* temp_sum = GetTemporary(context, node, /*index=*/2);
586 // Resize the output tensor if the output tensor is dynamic.
587 if (IsDynamicTensor(op_context.output)) {
588 TF_LITE_ENSURE_OK(context,
589 ResizeTempAxis(context, &op_context, resolved_axis));
590 TF_LITE_ENSURE_OK(context, ResizeOutputTensor(context, &op_context));
591 TF_LITE_ENSURE_OK(context, ResizeTempSum(context, &op_context, temp_sum));
592 }
593 if (input->type == kTfLiteUInt8) {
594 TF_LITE_ENSURE(
595 context,
596 reference_ops::QuantizedMeanOrSum<>(
597 GetTensorData<uint8_t>(op_context.input),
598 op_context.input->params.zero_point,
599 op_context.input->params.scale, op_context.input->dims->data,
600 op_context.input->dims->size,
601 GetTensorData<uint8_t>(op_context.output),
602 op_context.output->params.zero_point,
603 op_context.output->params.scale, op_context.output->dims->data,
604 op_context.output->dims->size,
605 GetTensorData<int>(op_context.axis), num_axis,
606 op_context.params->keep_dims, GetTensorData<int>(temp_index),
607 GetTensorData<int>(resolved_axis), GetTensorData<int32>(temp_sum),
608 /*compute_sum=*/true));
609 }
610 if (input->type == kTfLiteInt8) {
611 TF_LITE_ENSURE(
612 context,
613 reference_ops::QuantizedMeanOrSum<>(
614 GetTensorData<int8_t>(op_context.input),
615 op_context.input->params.zero_point,
616 op_context.input->params.scale, op_context.input->dims->data,
617 op_context.input->dims->size,
618 GetTensorData<int8_t>(op_context.output),
619 op_context.output->params.zero_point,
620 op_context.output->params.scale, op_context.output->dims->data,
621 op_context.output->dims->size,
622 GetTensorData<int>(op_context.axis), num_axis,
623 op_context.params->keep_dims, GetTensorData<int>(temp_index),
624 GetTensorData<int>(resolved_axis), GetTensorData<int32>(temp_sum),
625 /*compute_sum=*/true));
626 }

Callers

nothing calls this directly

Calls 6

GetTemporaryFunction · 0.85
IsDynamicTensorFunction · 0.85
ResizeTempAxisFunction · 0.85
ResizeTempSumFunction · 0.85
NumElementsFunction · 0.70
ResizeOutputTensorFunction · 0.70

Tested by

no test coverage detected