• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
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 #ifndef OHOS_HDI_NNR_NODE_FUNCTIONS_H
17 #define OHOS_HDI_NNR_NODE_FUNCTIONS_H
18 
19 #include <functional>
20 
21 #include "hdf_base.h"
22 #include "utils/hdf_log.h"
23 
24 #include "node_registry.h"
25 
26 namespace OHOS {
27 namespace HDI {
28 namespace Nnrt {
29 namespace V1_0 {
30 template<typename T>
ParsePrimitive(const std::vector<int8_t> & primitive,T & attr,std::function<bool (OHOS::MessageParcel &,T &)> parseFunc)31 int32_t ParsePrimitive(const std::vector<int8_t>& primitive, T& attr,
32     std::function<bool(OHOS::MessageParcel&, T&)> parseFunc)
33 {
34     if (primitive.empty()) {
35         HDF_LOGE("Primitive data is empty.");
36         return HDF_FAILURE;
37     }
38 
39     OHOS::MessageParcel parcelData;
40     bool ret = parcelData.WriteBuffer(primitive.data(), primitive.size());
41     if (!ret) {
42         HDF_LOGE("Write data to MessageParcel failed.");
43         return HDF_FAILURE;
44     }
45 
46     ret = parseFunc(parcelData, attr);
47     if (!ret) {
48         HDF_LOGE("Unmarshalling data failed.");
49         return HDF_FAILURE;
50     }
51     return HDF_SUCCESS;
52 }
53 
54 PrimUniquePtr GetAddPrimitive(const std::vector<int8_t>& primitive);
55 PrimUniquePtr GetAvgPoolPrimitive(const std::vector<int8_t>& primitive);
56 PrimUniquePtr GetConcatPrimitive(const std::vector<int8_t>& primitive);
57 PrimUniquePtr GetConv2dPrimitive(const std::vector<int8_t>& primitive);
58 PrimUniquePtr GetFullConnectionPrimitive(const std::vector<int8_t>& primitive);
59 PrimUniquePtr GetMaxPoolFusionPrimitive(const std::vector<int8_t>& primitive);
60 PrimUniquePtr GetMatMulFusionPrimitive(const std::vector<int8_t>& primitive);
61 PrimUniquePtr GetSoftmaxPrimitive(const std::vector<int8_t>& primitive);
62 PrimUniquePtr GetReshapePrimitive(const std::vector<int8_t>& primitive);
63 PrimUniquePtr GetScaleFusionPrimitive(const std::vector<int8_t>& primitive);
64 PrimUniquePtr GetActivationPrimitive(const std::vector<int8_t>& primitive);
65 PrimUniquePtr GetQuantDTypeCastPrimitive(const std::vector<int8_t>& primitive);
66 PrimUniquePtr GetMulFusionPrimitive(const std::vector<int8_t>& primitive);
67 } // namespace V1_0
68 } // namespace Nnrt
69 } // namespace HDI
70 } // namespace OHOS
71 #endif // OHOS_HDI_NNR_NODE_FUNCTIONS_H