blob: 21a61d73bf14c7b5c266e582c84a6e50dce09116 [file] [log] [blame]
Viet-Hoa Do3389f532023-07-05 17:36:40 +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
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010025#include "ckw/KernelWriter.h"
Viet-Hoa Do3389f532023-07-05 17:36:40 +010026#include "ckw/Error.h"
Gunes Bayir3c776062023-07-12 14:50:56 +010027#include "ckw/TileOperand.h"
Gunes Bayirab0b7502023-07-11 14:57:36 +010028#include "ckw/types/TargetArchitecture.h"
29#include "ckw/types/TargetLanguage.h"
Viet-Hoa Do3389f532023-07-05 17:36:40 +010030#include "src/cl/CLKernelWriter.h"
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010031#include "src/cl/CLTensorArgument.h"
32#include "src/cl/CLTile.h"
Viet-Hoa Do3389f532023-07-05 17:36:40 +010033
34namespace ckw
35{
36
Gunes Bayirab0b7502023-07-11 14:57:36 +010037KernelWriter::~KernelWriter() = default;
38
Viet-Hoa Do3389f532023-07-05 17:36:40 +010039std::unique_ptr<KernelWriter> KernelWriter::create_instance(TargetArchitecture architecture, TargetLanguage language)
40{
Gunes Bayirab0b7502023-07-11 14:57:36 +010041 CKW_UNUSED(architecture);
Viet-Hoa Do3389f532023-07-05 17:36:40 +010042 switch(language)
43 {
44 case TargetLanguage::OpenCL:
45 // Currently this is the oldest and the only supported GPU architecture.
46 CKW_ASSERT(architecture == TargetArchitecture::GpuArmMaliValhall);
47 return std::make_unique<CLKernelWriter>();
48
49 default:
50 CKW_THROW_MSG("Language not supported!");
51 }
52}
53
Gunes Bayirab0b7502023-07-11 14:57:36 +010054int32_t KernelWriter::id_space() const
55{
56 return _id_space;
57}
58
Gunes Bayirab0b7502023-07-11 14:57:36 +010059std::string KernelWriter::generate_full_name(const std::string &name) const
60{
61 return "G" + std::to_string(id_space()) + "__" + name;
62}
Viet-Hoa Do3389f532023-07-05 17:36:40 +010063
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010064TileOperand KernelWriter::create_tile_operand(ITile &tile)
65{
66 return TileOperand(tile);
67}
68
69ITile &KernelWriter::get_tile(const TileOperand &operand)
70{
71 return operand._tile;
72}
73
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010074TensorOperand KernelWriter::create_tensor_operand(ITensor &tensor)
75{
76 return TensorOperand(tensor);
77}
78
79ITensor &KernelWriter::get_tensor(const TensorOperand &operand)
80{
81 return operand._tensor;
82}
83
Gunes Bayir806b8e82023-08-23 23:28:31 +010084const std::vector<std::vector<std::string>> &KernelWriter::get_values(const ConstantData &data)
85{
86 return data.values();
87}
88
89DataType KernelWriter::get_data_type(const ConstantData &data)
90{
91 return data.data_type();
92}
93
Viet-Hoa Do3389f532023-07-05 17:36:40 +010094} // namespace ckw