ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Convert.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ONERT_BACKEND_TRIX_CONVERT_H__
18#define __ONERT_BACKEND_TRIX_CONVERT_H__
19
21#include <ir/DataType.h>
22#include <ir/Layout.h>
23
24#include <libnpuhost.h>
25#include <type_traits>
26
28{
29
36data_type convertDataType(const ir::DataType type);
37
45template <typename T, std::enable_if_t<std::is_base_of_v<IPortableTensor, T>, bool> = true>
46void setDataInfo(const std::vector<T *> &tensors, tensors_data_info *info)
47{
48 info->num_info = static_cast<uint32_t>(tensors.size());
49
50 for (uint32_t idx = 0; idx < info->num_info; ++idx)
51 {
52 info->info[idx].layout = DATA_LAYOUT_NHWC;
53 info->info[idx].type = convertDataType(tensors[idx]->data_type());
54 }
55}
56
64template <typename T, std::enable_if_t<std::is_base_of_v<IPortableTensor, T>, bool> = true>
65void setBuffers(const std::vector<T *> &tensors, generic_buffers *buf)
66{
67 buf->num_buffers = static_cast<uint32_t>(tensors.size());
68
69 for (uint32_t idx = 0; idx < buf->num_buffers; ++idx)
70 {
71 buf->bufs[idx].addr = tensors[idx]->buffer();
72 buf->bufs[idx].size = static_cast<uint64_t>(tensors[idx]->total_size());
73 buf->bufs[idx].type = BUFFER_MAPPED;
74 }
75}
76
77} // namespace onert::backend::trix
78
79#endif // __ONERT_BACKEND_TRIX_CONVERT_H__
volatile const char info[]
void setBuffers(const std::vector< T * > &tensors, generic_buffers *buf)
Set the generic_buffers object.
Definition Convert.h:65
data_type convertDataType(const ir::DataType type)
Convert type of data from onert type to npu type.
Definition Convert.cc:22
void setDataInfo(const std::vector< T * > &tensors, tensors_data_info *info)
Set the tensors_data_info object.
Definition Convert.h:46