blob: 4cbbee21ee107d3ad902fe2aede0b27f213e7997 [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"
29#include "src/ITensor.h"
30#include <memory>
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010031#include <string>
32#include <vector>
33
34namespace ckw
35{
36// Forward declarations
37class TensorInfo;
38
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010039class ITensorComponent;
40class CLTensorComponent;
41class CLTensorStorage;
42
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010043/** OpenCL specific tensor argument
44 * Internally, the object keeps track of the components and storages used to minimize the number
45 * of kernel arguments required. Therefore, if we create this object but we do not access any components
46 * or storages, the storages() and components() method will return an empty list.
47*/
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010048class CLTensorArgument : public ITensor
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010049{
50public:
51 /** Constructor
52 *
53 * @param[in] name Tensor name
54 * @param[in] info Tensor info
55 * @param[in] return_dims_by_value Flag to return the dimensions by value whenever it is possible.
56 * True, if the dimensions should be returned as value instead as variable.
57 */
58 CLTensorArgument(const std::string &name, const TensorInfo &info, bool return_dims_by_value);
59
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010060 /** Destructor. */
61 ~CLTensorArgument();
62
63 /** Get a tensor component of the given type.
64 *
65 * This function is for internal use as it returns a reference to @ref CLTensorComponent object.
66 * It provides rich functionalities and doesn't require unnecessary casting
67 * unlike @ref CLTensorComponent::component which is for the public API and only returns
68 * a reference to a generic @ref ITile object.
69 */
70 CLTensorComponent& cl_component(TensorComponentType component_type);
71
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010072 // Inherited method overridden
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010073 TensorStorageVariable &storage(TensorStorageType x) override;
74 ITile &component(TensorComponentType x) override;
75 std::vector<TensorStorageVariable> storages() const override;
76 std::vector<const ITensorComponent *> components() const override;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010077
78private:
79 std::string create_storage_name(TensorStorageType x) const;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010080
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010081 bool _return_dims_by_value{ false };
82 std::vector<TensorStorageVariable> _storages_used{};
83 std::vector<std::unique_ptr<CLTensorComponent>> _components_used{};
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010084};
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010085
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010086} // namespace ckw
87
88#endif // CKW_SRC_CL_CLTENSORARGUMENT_H