blob: 35df51422ecf4963808884e0b92e0db538da3359 [file] [log] [blame]
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +01001/*
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 Do0b23e0e2023-07-25 14:00:46 +010027#include "ckw/types/TensorComponentType.h"
28#include "ckw/types/TensorStorageType.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010030#include "src/ITensor.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010031
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010032#include <memory>
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010033#include <string>
34#include <vector>
35
36namespace ckw
37{
38// Forward declarations
39class TensorInfo;
40
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010041class ITensorComponent;
42class CLTensorComponent;
43class CLTensorStorage;
44
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010045/** OpenCL specific tensor argument
46 * Internally, the object keeps track of the components and storages used to minimize the number
47 * of kernel arguments required. Therefore, if we create this object but we do not access any components
48 * or storages, the storages() and components() method will return an empty list.
49*/
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010050class CLTensorArgument : public ITensor
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010051{
52public:
53 /** Constructor
54 *
55 * @param[in] name Tensor name
56 * @param[in] info Tensor info
57 * @param[in] return_dims_by_value Flag to return the dimensions by value whenever it is possible.
58 * True, if the dimensions should be returned as value instead as variable.
59 */
60 CLTensorArgument(const std::string &name, const TensorInfo &info, bool return_dims_by_value);
61
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010062 /** Destructor. */
63 ~CLTensorArgument();
64
65 /** Get a tensor component of the given type.
66 *
67 * This function is for internal use as it returns a reference to @ref CLTensorComponent object.
68 * It provides rich functionalities and doesn't require unnecessary casting
69 * unlike @ref CLTensorComponent::component which is for the public API and only returns
70 * a reference to a generic @ref ITile object.
71 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 CLTensorComponent &cl_component(TensorComponentType component_type);
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010073
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010074 // Inherited method overridden
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010075 TensorStorageVariable &storage(TensorStorageType x) override;
76 ITile &component(TensorComponentType x) override;
77 std::vector<TensorStorageVariable> storages() const override;
78 std::vector<const ITensorComponent *> components() const override;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010079
80private:
81 std::string create_storage_name(TensorStorageType x) const;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010082
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010083 bool _return_dims_by_value{false};
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010084 std::vector<TensorStorageVariable> _storages_used{};
85 std::vector<std::unique_ptr<CLTensorComponent>> _components_used{};
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010086};
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010087
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010088} // namespace ckw
89
90#endif // CKW_SRC_CL_CLTENSORARGUMENT_H