24.02.1
ITensorV2.h
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
#ifndef SRC_COMMON_ITENSOR_H_
25
#define SRC_COMMON_ITENSOR_H_
26
27
#include "
src/common/IContext.h
"
28
#include "
src/common/utils/Validate.h
"
29
30
struct
AclTensor_
31
{
32
arm_compute::detail::Header
header
{
arm_compute::detail::ObjectType::Tensor
,
nullptr
};
33
34
protected
:
35
AclTensor_
() =
default
;
36
~
AclTensor_
() =
default
;
37
};
38
39
namespace
arm_compute
40
{
41
// Forward declaration
42
class
ITensor;
43
44
/** Base class specifying the tensor interface */
45
class
ITensorV2
:
public
AclTensor_
46
{
47
public
:
48
/** Explict Operator Constructor
49
*
50
* @param[in] ctx Context to be used by the operator
51
*/
52
explicit
ITensorV2
(
IContext
*ctx) :
AclTensor_
()
53
{
54
ARM_COMPUTE_ASSERT_NOT_NULLPTR
(ctx);
55
this->
header
.
ctx
= ctx;
56
this->
header
.
ctx
->
inc_ref
();
57
}
58
/** Destructor */
59
virtual
~ITensorV2
()
60
{
61
this->
header
.
ctx
->
dec_ref
();
62
this->
header
.
type
=
detail::ObjectType::Invalid
;
63
};
64
/** Checks if a queue is valid
65
*
66
* @return True if successful otherwise false
67
*/
68
bool
is_valid
()
const
69
{
70
return
this->
header
.
type
==
detail::ObjectType::Tensor
;
71
};
72
/** Map tensor to a host pointer
73
*
74
* @return A pointer to the underlying backing memory if successful else nullptr
75
*/
76
virtual
void
*
map
() = 0;
77
/** Unmap tensor
78
*
79
* @return AclStatus A status cod
80
*/
81
virtual
StatusCode
unmap
() = 0;
82
/** Import external memory handle
83
*
84
* @param[in] handle Memory to import
85
* @param[in] type Type of imported memory
86
*
87
* @return Status code
88
*/
89
virtual
StatusCode
import
(
void
*handle,
ImportMemoryType
type
) = 0;
90
/** Get the legacy tensor object
91
*
92
* @return The legacy underlying tensor object
93
*/
94
virtual
arm_compute::ITensor
*
tensor
()
const
= 0;
95
/** Get the size of the tensor in byte
96
*
97
* @note The size isn't based on allocated memory, but based on information in its descriptor (dimensions, data type, etc.).
98
*
99
* @return The size of the tensor in byte
100
*/
101
size_t
get_size
()
const
;
102
/** Get the descriptor of this tensor
103
*
104
* @return The descriptor describing the characteristics of this tensor
105
*/
106
AclTensorDescriptor
get_descriptor
()
const
;
107
};
108
109
/** Extract internal representation of a Tensor
110
*
111
* @param[in] tensor Opaque tensor pointer
112
*
113
* @return The internal representation as an ITensor
114
*/
115
inline
ITensorV2
*
get_internal
(
AclTensor
tensor
)
116
{
117
return
static_cast<
ITensorV2
*
>
(
tensor
);
118
}
119
120
namespace
detail
121
{
122
/** Check if an internal tensor is valid
123
*
124
* @param[in] tensor Internal tensor to check
125
*
126
* @return A status code
127
*/
128
inline
StatusCode
validate_internal_tensor
(
const
ITensorV2
*
tensor
)
129
{
130
if
(
tensor
==
nullptr
|| !
tensor
->is_valid())
131
{
132
ARM_COMPUTE_LOG_ERROR_ACL
(
"[ITensorV2]: Invalid tensor object"
);
133
return
StatusCode::InvalidArgument
;
134
}
135
return
StatusCode::Success
;
136
}
137
}
// namespace detail
138
}
// namespace arm_compute
139
#endif
/* SRC_COMMON_ITENSOR_H_ */
arm_compute::ITensorV2
Base class specifying the tensor interface.
Definition:
ITensorV2.h:45
type
decltype(strategy::transforms) typedef type
Definition:
gemm_interleaved.hpp:261
ARM_COMPUTE_LOG_ERROR_ACL
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Definition:
Log.h:32
arm_compute::StatusCode::Success
@ Success
arm_compute::ITensor
Interface for CPU tensor.
Definition:
ITensor.h:36
arm_compute::IContext
Context interface.
Definition:
IContext.h:51
arm_compute::IContext::inc_ref
void inc_ref() const
Increment context refcount.
Definition:
IContext.h:71
arm_compute::detail::ObjectType::Invalid
@ Invalid
arm_compute::StatusCode
StatusCode
Definition:
Types.h:32
Validate.h
arm_compute::ITensorV2::unmap
virtual StatusCode unmap()=0
Unmap tensor.
ARM_COMPUTE_ASSERT_NOT_NULLPTR
#define ARM_COMPUTE_ASSERT_NOT_NULLPTR(ptr)
Definition:
Validate.h:38
arm_compute::ImportMemoryType
ImportMemoryType
Definition:
Types.h:57
arm_compute::ITensorV2::get_size
size_t get_size() const
Get the size of the tensor in byte.
Definition:
ITensorV2.cpp:32
arm_compute::ITensorV2::map
virtual void * map()=0
Map tensor to a host pointer.
arm_compute::StatusCode::InvalidArgument
@ InvalidArgument
arm_compute::detail::ObjectType::Tensor
@ Tensor
arm_compute::detail::Header::ctx
IContext * ctx
Definition:
Object.h:60
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition:
ClWorkloadRuntime.cpp:67
arm_compute::detail::Header
Definition:
Object.h:48
IContext.h
arm_compute::ITensorV2::ITensorV2
ITensorV2(IContext *ctx)
Explict Operator Constructor.
Definition:
ITensorV2.h:52
AclTensor_
Definition:
ITensorV2.h:30
arm_compute::detail::Header::type
ObjectType type
Definition:
Object.h:59
AclTensorDescriptor
Definition:
AclTypes.h:192
arm_compute::ITensorV2::is_valid
bool is_valid() const
Checks if a queue is valid.
Definition:
ITensorV2.h:68
arm_compute
Copyright (c) 2017-2024 Arm Limited.
Definition:
introduction.dox:24
arm_compute::detail::validate_internal_tensor
StatusCode validate_internal_tensor(const ITensorV2 *tensor)
Check if an internal tensor is valid.
Definition:
ITensorV2.h:128
arm_compute::get_internal
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition:
IContext.h:127
arm_compute::ITensorV2::~ITensorV2
virtual ~ITensorV2()
Destructor.
Definition:
ITensorV2.h:59
arm_compute::IContext::dec_ref
void dec_ref() const
Decrement context refcount.
Definition:
IContext.h:76
AclTensor_::header
arm_compute::detail::Header header
Definition:
ITensorV2.h:32
arm_compute::ITensorV2::tensor
virtual arm_compute::ITensor * tensor() const =0
Get the legacy tensor object.
arm_compute::ITensorV2::get_descriptor
AclTensorDescriptor get_descriptor() const
Get the descriptor of this tensor.
Definition:
ITensorV2.cpp:37
src
common
ITensorV2.h
Generated on Mon Mar 18 2024 11:31:56 for Compute Library by
1.8.17