ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
27namespace onert
28{
29namespace backend
30{
31namespace trix
32{
33
40data_type convertDataType(const ir::DataType type);
41
49template <typename T, std::enable_if_t<std::is_base_of<IPortableTensor, T>::value, bool> = true>
50void setDataInfo(const std::vector<T *> &tensors, tensors_data_info *info)
51{
52 info->num_info = static_cast<uint32_t>(tensors.size());
53
54 for (uint32_t idx = 0; idx < info->num_info; ++idx)
55 {
56 info->info[idx].layout = DATA_LAYOUT_NHWC;
57 info->info[idx].type = convertDataType(tensors[idx]->data_type());
58 }
59}
60
68template <typename T, std::enable_if_t<std::is_base_of<IPortableTensor, T>::value, bool> = true>
69void setBuffers(const std::vector<T *> &tensors, generic_buffers *buf)
70{
71 buf->num_buffers = static_cast<uint32_t>(tensors.size());
72
73 for (uint32_t idx = 0; idx < buf->num_buffers; ++idx)
74 {
75 buf->bufs[idx].addr = tensors[idx]->buffer();
76 buf->bufs[idx].size = static_cast<uint64_t>(tensors[idx]->total_size());
77 buf->bufs[idx].type = BUFFER_MAPPED;
78 }
79}
80
81} // namespace trix
82} // namespace backend
83} // namespace onert
84
85#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:69
data_type convertDataType(const ir::DataType type)
Convert type of data from onert type to npu type.
Definition Convert.cc:26
void setDataInfo(const std::vector< T * > &tensors, tensors_data_info *info)
Set the tensors_data_info object.
Definition Convert.h:50