Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #include "GeneratedTestHarness.h" |
| 18 | #include "TestHarness.h" |
| 19 | |
| 20 | #include <android/hardware/neuralnetworks/1.0/types.h> |
| 21 | |
| 22 | #include <cstring> |
| 23 | #include <map> |
| 24 | #include <vector> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace neuralnetworks { |
| 29 | |
| 30 | using ::android::hardware::neuralnetworks::V1_0::RequestArgument; |
| 31 | using ::test_helper::for_each; |
| 32 | using ::test_helper::MixedTyped; |
| 33 | |
| 34 | template <typename T> |
| 35 | void copy_back_(std::map<int, std::vector<T>>* dst, const std::vector<RequestArgument>& ra, |
| 36 | char* src) { |
| 37 | for_each<T>(*dst, [&ra, src](int index, std::vector<T>& m) { |
| 38 | ASSERT_EQ(m.size(), ra[index].location.length / sizeof(T)); |
| 39 | char* begin = src + ra[index].location.offset; |
| 40 | memcpy(m.data(), begin, ra[index].location.length); |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | void copy_back(MixedTyped* dst, const std::vector<RequestArgument>& ra, char* src) { |
| 45 | copy_back_(&dst->float32Operands, ra, src); |
| 46 | copy_back_(&dst->int32Operands, ra, src); |
| 47 | copy_back_(&dst->quant8AsymmOperands, ra, src); |
| 48 | copy_back_(&dst->quant16SymmOperands, ra, src); |
| 49 | copy_back_(&dst->float16Operands, ra, src); |
| 50 | copy_back_(&dst->bool8Operands, ra, src); |
| 51 | copy_back_(&dst->quant8ChannelOperands, ra, src); |
| 52 | copy_back_(&dst->quant16AsymmOperands, ra, src); |
| 53 | copy_back_(&dst->quant8SymmOperands, ra, src); |
| 54 | static_assert(9 == MixedTyped::kNumTypes, |
| 55 | "Number of types in MixedTyped changed, but copy_back function wasn't updated"); |
| 56 | } |
| 57 | |
| 58 | } // namespace neuralnetworks |
| 59 | } // namespace hardware |
| 60 | } // namespace android |