1 /**
2 * Copyright 2020 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 "src/runtime/kernel/arm/fp32/shape_fp32.h"
18 #include "schema/model_generated.h"
19 #include "src/kernel_registry.h"
20 #include "include/errorcode.h"
21 #include "src/common/log_adapter.h"
22
23 using mindspore::lite::KernelRegistrar;
24 using mindspore::lite::RET_ERROR;
25 using mindspore::lite::RET_OK;
26 using mindspore::schema::PrimitiveType_Shape;
27
28 namespace mindspore::kernel {
Init()29 int ShapeCPUKernel::Init() {
30 CHECK_LESS_RETURN(in_tensors_.size(), 1);
31 CHECK_LESS_RETURN(out_tensors_.size(), 1);
32 return RET_OK;
33 }
34
ReSize()35 int ShapeCPUKernel::ReSize() { return RET_OK; }
36
Run()37 int ShapeCPUKernel::Run() {
38 auto out_tensor = out_tensors_.front();
39 auto in_tensor = in_tensors_.front();
40 if (in_tensor == nullptr || out_tensor == nullptr) {
41 MS_LOG(ERROR) << "null pointer dereferencing.";
42 return RET_ERROR;
43 }
44 if (in_tensor->MutableData() == nullptr || out_tensor->MutableData() == nullptr) {
45 MS_LOG(ERROR) << "null pointer dereferencing.";
46 return RET_ERROR;
47 }
48
49 for (size_t i = 0; i < in_tensor->shape().size(); i++) {
50 reinterpret_cast<int *>(out_tensor->MutableData())[i] = in_tensor->shape().at(i);
51 }
52
53 return RET_OK;
54 }
55
56 REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Shape, LiteKernelCreator<ShapeCPUKernel>)
57 REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Shape, LiteKernelCreator<ShapeCPUKernel>)
58 REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Shape, LiteKernelCreator<ShapeCPUKernel>)
59 REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Shape, LiteKernelCreator<ShapeCPUKernel>)
60 REG_KERNEL(kCPU, kNumberTypeInt64, PrimitiveType_Shape, LiteKernelCreator<ShapeCPUKernel>)
61 } // namespace mindspore::kernel
62