Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_GRAPH_UTILS_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_UTILS_H__ |
| 26 | |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame^] | 27 | #include "arm_compute/core/PixelValue.h" |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/graph/ITensorAccessor.h" |
| 29 | #include "arm_compute/graph/Types.h" |
| 30 | |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame^] | 31 | #include <random> |
| 32 | |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace graph_utils |
| 36 | { |
| 37 | /** PPM writer class */ |
| 38 | class PPMWriter : public graph::ITensorAccessor |
| 39 | { |
| 40 | public: |
| 41 | /** Constructor |
| 42 | * |
| 43 | * @param[in] name PPM file name |
| 44 | * @param[in] maximum Maximum elements to access |
| 45 | */ |
| 46 | PPMWriter(std::string name, unsigned int maximum = 1); |
| 47 | /** Allows instances to move constructed */ |
| 48 | PPMWriter(PPMWriter &&) = default; |
| 49 | |
| 50 | // Inherited methods overriden: |
| 51 | bool access_tensor(ITensor &tensor) override; |
| 52 | |
| 53 | private: |
| 54 | const std::string _name; |
| 55 | unsigned int _iterator; |
| 56 | unsigned int _maximum; |
| 57 | }; |
| 58 | |
| 59 | /** Dummy accessor class */ |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame^] | 60 | class DummyAccessor final : public graph::ITensorAccessor |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 61 | { |
| 62 | public: |
| 63 | /** Constructor |
| 64 | * |
| 65 | * @param[in] maximum Maximum elements to write |
| 66 | */ |
| 67 | DummyAccessor(unsigned int maximum = 1); |
| 68 | /** Allows instances to move constructed */ |
| 69 | DummyAccessor(DummyAccessor &&) = default; |
| 70 | |
| 71 | // Inherited methods overriden: |
| 72 | bool access_tensor(ITensor &tensor) override; |
| 73 | |
| 74 | private: |
| 75 | unsigned int _iterator; |
| 76 | unsigned int _maximum; |
| 77 | }; |
| 78 | |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame^] | 79 | /** Random accessor class */ |
| 80 | class RandomAccessor final : public graph::ITensorAccessor |
| 81 | { |
| 82 | public: |
| 83 | /** Constructor |
| 84 | * |
| 85 | * @param[in] lower Lower bound value. |
| 86 | * @param[in] upper Upper bound value. |
| 87 | * @param[in] seed (Optional) Seed used to initialise the random number generator. |
| 88 | */ |
| 89 | RandomAccessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0); |
| 90 | /** Allows instances to move constructed */ |
| 91 | RandomAccessor(RandomAccessor &&) = default; |
| 92 | |
| 93 | // Inherited methods overriden: |
| 94 | bool access_tensor(ITensor &tensor) override; |
| 95 | |
| 96 | private: |
| 97 | template <typename T, typename D> |
| 98 | void fill(ITensor &tensor, D &&distribution); |
| 99 | PixelValue _lower; |
| 100 | PixelValue _upper; |
| 101 | std::random_device::result_type _seed; |
| 102 | }; |
| 103 | |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 104 | /** Numpy Binary loader class*/ |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame^] | 105 | class NumPyBinLoader final : public graph::ITensorAccessor |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 106 | { |
| 107 | public: |
| 108 | /** Default Constructor |
| 109 | * |
| 110 | * @param filename Binary file name |
| 111 | */ |
| 112 | NumPyBinLoader(std::string filename); |
| 113 | /** Allows instances to move constructed */ |
| 114 | NumPyBinLoader(NumPyBinLoader &&) = default; |
| 115 | |
| 116 | // Inherited methods overriden: |
| 117 | bool access_tensor(ITensor &tensor) override; |
| 118 | |
| 119 | private: |
| 120 | const std::string _filename; |
| 121 | }; |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame^] | 122 | } // namespace graph_utils |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 123 | } // namespace arm_compute |
| 124 | |
| 125 | #endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */ |