blob: 347ae5b5456050fbf971d0a182500df7666a4a08 [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 Do3389f532023-07-05 17:36:40 +010025#include "ckw/Error.h"
Gunes Bayir3c776062023-07-12 14:50:56 +010026#include "ckw/TileOperand.h"
Gunes Bayirab0b7502023-07-11 14:57:36 +010027#include "ckw/KernelWriter.h"
28#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"
31
Gunes Bayirab0b7502023-07-11 14:57:36 +010032#include <iterator>
Viet-Hoa Do3389f532023-07-05 17:36:40 +010033namespace ckw
34{
35
Gunes Bayirab0b7502023-07-11 14:57:36 +010036KernelWriter::~KernelWriter() = default;
37
Viet-Hoa Do3389f532023-07-05 17:36:40 +010038std::unique_ptr<KernelWriter> KernelWriter::create_instance(TargetArchitecture architecture, TargetLanguage language)
39{
Gunes Bayirab0b7502023-07-11 14:57:36 +010040 CKW_UNUSED(architecture);
Viet-Hoa Do3389f532023-07-05 17:36:40 +010041 switch(language)
42 {
43 case TargetLanguage::OpenCL:
44 // Currently this is the oldest and the only supported GPU architecture.
45 CKW_ASSERT(architecture == TargetArchitecture::GpuArmMaliValhall);
46 return std::make_unique<CLKernelWriter>();
47
48 default:
49 CKW_THROW_MSG("Language not supported!");
50 }
51}
52
Gunes Bayirab0b7502023-07-11 14:57:36 +010053int32_t KernelWriter::id_space() const
54{
55 return _id_space;
56}
57
Gunes Bayir3c776062023-07-12 14:50:56 +010058TileOperand &KernelWriter::add_operand(std::unique_ptr<TileOperand> &operand_ptr)
Gunes Bayirab0b7502023-07-11 14:57:36 +010059{
60 auto it = _operands.insert(std::move(operand_ptr));
61 return *it.first->get();
62}
63
64std::string KernelWriter::generate_full_name(const std::string &name) const
65{
66 return "G" + std::to_string(id_space()) + "__" + name;
67}
Viet-Hoa Do3389f532023-07-05 17:36:40 +010068
69} // namespace ckw