Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 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 CKW_SRC_CL_CLTENSORARGUMENT_H |
| 25 | #define CKW_SRC_CL_CLTENSORARGUMENT_H |
| 26 | |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 27 | #include "ckw/types/TensorComponentType.h" |
| 28 | #include "ckw/types/TensorStorageType.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 30 | #include "src/cl/CLTensorComponent.h" |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 31 | #include "src/ITensor.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 33 | #include <memory> |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 34 | #include <string> |
| 35 | #include <vector> |
| 36 | |
| 37 | namespace ckw |
| 38 | { |
| 39 | // Forward declarations |
| 40 | class TensorInfo; |
| 41 | |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 42 | class ITensorComponent; |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 43 | |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 44 | /** OpenCL specific tensor argument |
| 45 | * Internally, the object keeps track of the components and storages used to minimize the number |
| 46 | * of kernel arguments required. Therefore, if we create this object but we do not access any components |
| 47 | * or storages, the storages() and components() method will return an empty list. |
| 48 | */ |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 49 | class CLTensorArgument : public ITensor |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | /** Constructor |
| 53 | * |
| 54 | * @param[in] name Tensor name |
| 55 | * @param[in] info Tensor info |
| 56 | * @param[in] return_dims_by_value Flag to return the dimensions by value whenever it is possible. |
| 57 | * True, if the dimensions should be returned as value instead as variable. |
| 58 | */ |
| 59 | CLTensorArgument(const std::string &name, const TensorInfo &info, bool return_dims_by_value); |
| 60 | |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 61 | /** Destructor. */ |
| 62 | ~CLTensorArgument(); |
| 63 | |
| 64 | /** Get a tensor component of the given type. |
| 65 | * |
| 66 | * This function is for internal use as it returns a reference to @ref CLTensorComponent object. |
| 67 | * It provides rich functionalities and doesn't require unnecessary casting |
| 68 | * unlike @ref CLTensorComponent::component which is for the public API and only returns |
| 69 | * a reference to a generic @ref ITile object. |
| 70 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 71 | CLTensorComponent &cl_component(TensorComponentType component_type); |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 72 | |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 73 | // Inherited method overridden |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 74 | TensorStorageVariable &storage(TensorStorageType x) override; |
| 75 | ITile &component(TensorComponentType x) override; |
| 76 | std::vector<TensorStorageVariable> storages() const override; |
| 77 | std::vector<const ITensorComponent *> components() const override; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | std::string create_storage_name(TensorStorageType x) const; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 81 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | bool _return_dims_by_value{false}; |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 83 | std::vector<TensorStorageVariable> _storages_used{}; |
| 84 | std::vector<std::unique_ptr<CLTensorComponent>> _components_used{}; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 85 | }; |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 86 | |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 87 | } // namespace ckw |
| 88 | |
| 89 | #endif // CKW_SRC_CL_CLTENSORARGUMENT_H |