1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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 #ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_CONVERSIONS_H
18 #define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_CONVERSIONS_H
19 
20 #include <android/hardware/neuralnetworks/1.0/types.h>
21 #include <nnapi/Result.h>
22 #include <nnapi/Types.h>
23 #include <nnapi/hal/CommonUtils.h>
24 
25 namespace android::nn {
26 
27 GeneralResult<OperandType> unvalidatedConvert(const hal::V1_0::OperandType& operandType);
28 GeneralResult<OperationType> unvalidatedConvert(const hal::V1_0::OperationType& operationType);
29 GeneralResult<Operand::LifeTime> unvalidatedConvert(const hal::V1_0::OperandLifeTime& lifetime);
30 GeneralResult<DeviceStatus> unvalidatedConvert(const hal::V1_0::DeviceStatus& deviceStatus);
31 GeneralResult<Capabilities::PerformanceInfo> unvalidatedConvert(
32         const hal::V1_0::PerformanceInfo& performanceInfo);
33 GeneralResult<Capabilities> unvalidatedConvert(const hal::V1_0::Capabilities& capabilities);
34 GeneralResult<DataLocation> unvalidatedConvert(const hal::V1_0::DataLocation& location);
35 GeneralResult<Operand> unvalidatedConvert(const hal::V1_0::Operand& operand);
36 GeneralResult<Operation> unvalidatedConvert(const hal::V1_0::Operation& operation);
37 GeneralResult<Model::OperandValues> unvalidatedConvert(
38         const hardware::hidl_vec<uint8_t>& operandValues);
39 GeneralResult<SharedHandle> unvalidatedConvert(const hardware::hidl_handle& handle);
40 GeneralResult<SharedMemory> unvalidatedConvert(const hardware::hidl_memory& memory);
41 GeneralResult<Model> unvalidatedConvert(const hal::V1_0::Model& model);
42 GeneralResult<Request::Argument> unvalidatedConvert(
43         const hal::V1_0::RequestArgument& requestArgument);
44 GeneralResult<Request> unvalidatedConvert(const hal::V1_0::Request& request);
45 GeneralResult<ErrorStatus> unvalidatedConvert(const hal::V1_0::ErrorStatus& status);
46 
47 GeneralResult<DeviceStatus> convert(const hal::V1_0::DeviceStatus& deviceStatus);
48 GeneralResult<Capabilities> convert(const hal::V1_0::Capabilities& capabilities);
49 GeneralResult<Model> convert(const hal::V1_0::Model& model);
50 GeneralResult<Request> convert(const hal::V1_0::Request& request);
51 GeneralResult<ErrorStatus> convert(const hal::V1_0::ErrorStatus& status);
52 
53 }  // namespace android::nn
54 
55 namespace android::hardware::neuralnetworks::V1_0::utils {
56 
57 nn::GeneralResult<OperandType> unvalidatedConvert(const nn::OperandType& operandType);
58 nn::GeneralResult<OperationType> unvalidatedConvert(const nn::OperationType& operationType);
59 nn::GeneralResult<OperandLifeTime> unvalidatedConvert(const nn::Operand::LifeTime& lifetime);
60 nn::GeneralResult<DeviceStatus> unvalidatedConvert(const nn::DeviceStatus& deviceStatus);
61 nn::GeneralResult<PerformanceInfo> unvalidatedConvert(
62         const nn::Capabilities::PerformanceInfo& performanceInfo);
63 nn::GeneralResult<Capabilities> unvalidatedConvert(const nn::Capabilities& capabilities);
64 nn::GeneralResult<DataLocation> unvalidatedConvert(const nn::DataLocation& location);
65 nn::GeneralResult<Operand> unvalidatedConvert(const nn::Operand& operand);
66 nn::GeneralResult<Operation> unvalidatedConvert(const nn::Operation& operation);
67 nn::GeneralResult<hidl_vec<uint8_t>> unvalidatedConvert(
68         const nn::Model::OperandValues& operandValues);
69 nn::GeneralResult<hidl_handle> unvalidatedConvert(const nn::SharedHandle& handle);
70 nn::GeneralResult<hidl_memory> unvalidatedConvert(const nn::SharedMemory& memory);
71 nn::GeneralResult<Model> unvalidatedConvert(const nn::Model& model);
72 nn::GeneralResult<RequestArgument> unvalidatedConvert(const nn::Request::Argument& requestArgument);
73 nn::GeneralResult<hidl_memory> unvalidatedConvert(const nn::Request::MemoryPool& memoryPool);
74 nn::GeneralResult<Request> unvalidatedConvert(const nn::Request& request);
75 nn::GeneralResult<ErrorStatus> unvalidatedConvert(const nn::ErrorStatus& status);
76 
77 nn::GeneralResult<DeviceStatus> convert(const nn::DeviceStatus& deviceStatus);
78 nn::GeneralResult<Capabilities> convert(const nn::Capabilities& capabilities);
79 nn::GeneralResult<Model> convert(const nn::Model& model);
80 nn::GeneralResult<Request> convert(const nn::Request& request);
81 nn::GeneralResult<ErrorStatus> convert(const nn::ErrorStatus& status);
82 
83 }  // namespace android::hardware::neuralnetworks::V1_0::utils
84 
85 #endif  // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_CONVERSIONS_H
86