Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / backend / IPortableTensor.h
1 /*
2  * Copyright (c) 2020 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_I_PORTABLE_TENSOR_H__
18 #define __ONERT_BACKEND_I_PORTABLE_TENSOR_H__
19
20 #include "backend/ITensor.h"
21
22 namespace onert
23 {
24 namespace backend
25 {
26
27 /**
28  * @brief A tensor class that is portable for other backends
29  *
30  * Backends that use derivatives of this interface can reuse each other's tensors without copying.
31  * Here's criterion to be a portable tensor:
32  *   - it must not have any paddings
33  *   - No special operations on @c access method
34  *     - e.g. CL memory must map/unmap to use it from CPU, the memory so it cannot be portable
35  */
36 class IPortableTensor : public ITensor
37 {
38 public:
39   virtual ~IPortableTensor() = default;
40   virtual bool is_sparse() const { return false; }
41   virtual const uint16_t *w1_segments() const { return nullptr; }
42   virtual const uint16_t *w1_indices() const { return nullptr; }
43
44 public:
45   bool has_padding() const final { return false; }
46   void access(const std::function<void(ITensor &tensor)> &fn) final { fn(*this); }
47 };
48
49 } // namespace backend
50 } // namespace onert
51
52 #endif // __ONERT_BACKEND_I_PORTABLE_TENSOR_H__