Compute Library
 21.11
TensorPack.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "src/common/TensorPack.h"
25 #include "src/common/ITensorV2.h"
27 
28 namespace arm_compute
29 {
31  : AclTensorPack_(), _pack()
32 {
34  this->header.ctx = ctx;
35  this->header.ctx->inc_ref();
36 }
37 
39 {
40  this->header.ctx->dec_ref();
42 }
43 
44 AclStatus TensorPack::add_tensor(ITensorV2 *tensor, int32_t slot_id)
45 {
46  _pack.add_tensor(slot_id, tensor->tensor());
47  return AclStatus::AclSuccess;
48 }
49 
50 size_t TensorPack::size() const
51 {
52  return _pack.size();
53 }
54 
55 bool TensorPack::empty() const
56 {
57  return _pack.empty();
58 }
59 
61 {
63 }
64 
66 {
67  return _pack.get_tensor(slot_id);
68 }
69 
71 {
72  return _pack;
73 }
74 } // namespace arm_compute
TensorPack(IContext *ctx)
Constructor.
Definition: TensorPack.cpp:30
AclStatus add_tensor(ITensorV2 *tensor, int32_t slot_id)
Add tensor to the pack.
Definition: TensorPack.cpp:44
Base class specifying the tensor interface.
Definition: ITensorV2.h:45
arm_compute::ITensor * get_tensor(int32_t slot_id)
Get tensor of a given id from the pac.
Definition: TensorPack.cpp:65
bool empty() const
Checks if pack is empty.
Definition: ITensorPack.cpp:80
bool is_valid() const
Checks if an object is valid.
Definition: TensorPack.cpp:60
bool empty() const
Checks if pack is empty.
Definition: TensorPack.cpp:55
Context interface.
Definition: IContext.h:50
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
void dec_ref() const
Decrement context refcount.
Definition: IContext.h:76
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
arm_compute::detail::Header header
Definition: TensorPack.h:32
~TensorPack()
Destructor.
Definition: TensorPack.cpp:38
size_t size() const
Pack size accessor.
Definition: ITensorPack.cpp:75
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:64
arm_compute::ITensorPack & get_tensor_pack()
Get legacy tensor pack.
Definition: TensorPack.cpp:70
size_t size() const
Pack size accessor.
Definition: TensorPack.cpp:50
Tensor packing service.
Definition: ITensorPack.h:39
void inc_ref() const
Increment context refcount.
Definition: IContext.h:71
#define ARM_COMPUTE_ASSERT_NOT_NULLPTR(ptr)
Definition: Validate.h:38
virtual arm_compute::ITensor * tensor() const =0
Get the legacy tensor object.
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39
AclStatus
Definition: AclTypes.h:49