ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Overlay.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_OVERLAY_H__
18#define __NNCC_CORE_ADT_KERNEL_OVERLAY_H__
19
22
23#include <vector>
24
25namespace nncc
26{
27namespace core
28{
29namespace ADT
30{
31namespace kernel
32{
33
34template <typename T, typename InputIt> class Overlay final : public View<T>
35{
36public:
37 explicit Overlay(const Shape &shape, const Layout &layout, InputIt it)
38 : _impl{shape, layout}, _it{it}
39 {
40 // DO NOTHING
41 }
42
43public:
44 T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const override
45 {
46 return _impl.at(_it, nth, ch, row, col);
47 }
48
49public:
50 T &at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) override
51 {
52 return _impl.at(_it, nth, ch, row, col);
53 }
54
55public:
56 const Shape &shape(void) const override { return _impl.shape(); }
57
58private:
59 InputIt const _it;
60 ViewImpl<T> _impl;
61};
62
63template <typename T, typename LayoutImpl> struct OverlayFactory
64{
65 template <typename InputIt> static Overlay<T, InputIt> make(const Shape &shape, InputIt it)
66 {
67 return Overlay<T, InputIt>{shape, LayoutImpl{}, it};
68 }
69};
70
71template <typename T, typename LayoutImpl> Overlay<T, T *> make_overlay(const Shape &shape, T *base)
72{
73 return OverlayFactory<T, LayoutImpl>::make(shape, base);
74}
75
76} // namespace kernel
77} // namespace ADT
78} // namespace core
79} // namespace nncc
80
81#endif // __NNCC_CORE_ADT_KERNEL_OVERLAY_H__
T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const override
Definition Overlay.h:44
Overlay(const Shape &shape, const Layout &layout, InputIt it)
Definition Overlay.h:37
const Shape & shape(void) const override
Definition Overlay.h:56
T & at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) override
Definition Overlay.h:50
Overlay< T, T * > make_overlay(const Shape &shape, T *base)
Definition Overlay.h:71
static Overlay< T, InputIt > make(const Shape &shape, InputIt it)
Definition Overlay.h:65