blob: a79cf340bb810b6282c10d52567179f6ae0debfc [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
Gunes Bayir2b9fa592024-01-17 16:07:03 +000030#include "src/cl/CLTensorComponent.h"
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010031#include "src/ITensor.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010032
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010033#include <memory>
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010034#include <string>
35#include <vector>
36
37namespace ckw
38{
39// Forward declarations
40class TensorInfo;
41
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010042class ITensorComponent;
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010043
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010044/** 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 Do0b23e0e2023-07-25 14:00:46 +010049class CLTensorArgument : public ITensor
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010050{
51public:
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 Do0b23e0e2023-07-25 14:00:46 +010061 /** 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 Thomasmathibalanafd38f02023-09-27 17:46:17 +010071 CLTensorComponent &cl_component(TensorComponentType component_type);
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010072
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010073 // Inherited method overridden
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010074 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 Iodiceebfdb5a2023-07-07 11:25:57 +010078
79private:
80 std::string create_storage_name(TensorStorageType x) const;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010081
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082 bool _return_dims_by_value{false};
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010083 std::vector<TensorStorageVariable> _storages_used{};
84 std::vector<std::unique_ptr<CLTensorComponent>> _components_used{};
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010085};
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010086
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010087} // namespace ckw
88
89#endif // CKW_SRC_CL_CLTENSORARGUMENT_H