1 /**
2 * Copyright 2023 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "nnacl/kernel/size.h"
18 #include "nnacl/kernel/default_kernel_base.h"
19 #include "nnacl/tensor_c_utils.h"
20
SizeCompute(KernelBase * self)21 int SizeCompute(KernelBase *self) {
22 TensorC *in_tensor = self->in_[FIRST_INPUT];
23 NNACL_CHECK_NULL_RETURN_ERR(in_tensor);
24 TensorC *out_tensor = self->out_[OUTPUT_INDEX];
25 NNACL_CHECK_NULL_RETURN_ERR(out_tensor);
26 int *out_data = (int *)out_tensor->data_;
27 NNACL_CHECK_NULL_RETURN_ERR(out_data);
28 out_data[Index0] = GetElementNum(in_tensor);
29 return NNACL_OK;
30 }
31
CreateSize(OpParameter * param,int data_type)32 KernelBase *CreateSize(OpParameter *param, int data_type) {
33 SizeStruct *size = (SizeStruct *)malloc(sizeof(SizeStruct));
34 NNACL_CHECK_NULL_RETURN_NULL(size);
35 size->base_.Release = DefaultRelease;
36 size->base_.Prepare = DefaultPrepare1In1Out;
37 size->base_.Resize = DefaultResize;
38 size->base_.Compute = SizeCompute;
39 return (KernelBase *)size;
40 }
41
42 REG_KERNEL_CREATOR(PrimType_Size, kNumberTypeInt32, CreateSize)
43 REG_KERNEL_CREATOR(PrimType_Size, kNumberTypeFloat32, CreateSize)
44 REG_KERNEL_CREATOR(PrimType_Size, kNumberTypeFloat16, CreateSize)
45