ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Buffer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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 __NNCC_CORE_ADT_KERNEL_BUFFER_H__
18#define __NNCC_CORE_ADT_KERNEL_BUFFER_H__
19
22
23#include <vector>
24
25namespace nncc
26{
27namespace core
28{
29namespace ADT
30{
31namespace kernel
32{
33
34template <typename T> class Buffer final : public View<T>
35{
36public:
37 explicit Buffer(const Shape &shape, const Layout &layout) : _impl{shape, layout}
38 {
39 _buffer.resize(num_elements(shape));
40 }
41
42public:
43 T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const override
44 {
45 return _impl.at(_buffer.begin(), nth, ch, row, col);
46 }
47
48public:
49 T &at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) override
50 {
51 return _impl.at(_buffer.begin(), nth, ch, row, col);
52 }
53
54public:
55 const Shape &shape(void) const override { return _impl.shape(); }
56
57private:
58 std::vector<T> _buffer;
59 ViewImpl<T> _impl;
60};
61
62template <typename T, typename LayoutImpl> Buffer<T> make_buffer(const Shape &shape)
63{
64 return Buffer<T>{shape, LayoutImpl{}};
65}
66
67} // namespace kernel
68} // namespace ADT
69} // namespace core
70} // namespace nncc
71
72#endif // __NNCC_CORE_ADT_KERNEL_BUFFER_H__
T & at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) override
Definition Buffer.h:49
T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const override
Definition Buffer.h:43
const Shape & shape(void) const override
Definition Buffer.h:55
Buffer(const Shape &shape, const Layout &layout)
Definition Buffer.h:37