1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/lite/kernels/internal/reference/ceil.h"
17
18 #include "tensorflow/lite/c/common.h"
19 #include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
20 #include "tensorflow/lite/kernels/kernel_util.h"
21 #include "tensorflow/lite/micro/kernels/kernel_util.h"
22
23 namespace tflite {
24 namespace ops {
25 namespace micro {
26 namespace ceil {
27
28 constexpr int kInputTensor = 0;
29 constexpr int kOutputTensor = 0;
30
Prepare(TfLiteContext * context,TfLiteNode * node)31 TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
32 const TfLiteTensor* input = GetInput(context, node, kInputTensor);
33 TF_LITE_ENSURE(context, input != nullptr);
34 TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
35 TF_LITE_ENSURE(context, output != nullptr);
36 TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
37 TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
38 TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32);
39 TF_LITE_ENSURE_TYPES_EQ(context, output->type, input->type);
40 TF_LITE_ENSURE_EQ(context, output->bytes, input->bytes);
41 TF_LITE_ENSURE_EQ(context, output->dims->size, input->dims->size);
42 for (int i = 0; i < output->dims->size; ++i) {
43 TF_LITE_ENSURE_EQ(context, output->dims->data[i], input->dims->data[i]);
44 }
45 return kTfLiteOk;
46 }
47
Eval(TfLiteContext * context,TfLiteNode * node)48 TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
49 const TfLiteEvalTensor* input =
50 tflite::micro::GetEvalInput(context, node, kInputTensor);
51 TfLiteEvalTensor* output =
52 tflite::micro::GetEvalOutput(context, node, kOutputTensor);
53
54 reference_ops::Ceil(tflite::micro::GetTensorShape(input),
55 tflite::micro::GetTensorData<float>(input),
56 tflite::micro::GetTensorShape(output),
57 tflite::micro::GetTensorData<float>(output));
58
59 return kTfLiteOk;
60 }
61 } // namespace ceil
62
Register_CEIL()63 TfLiteRegistration Register_CEIL() {
64 return {/*init=*/nullptr,
65 /*free=*/nullptr,
66 /*prepare=*/ceil::Prepare,
67 /*invoke=*/ceil::Eval,
68 /*profiling_string=*/nullptr,
69 /*builtin_code=*/0,
70 /*custom_name=*/nullptr,
71 /*version=*/0};
72 }
73
74 } // namespace micro
75 } // namespace ops
76 } // namespace tflite
77