FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
uTensor/src/uTensor/core/memoryManagementInterface.cpp at develop · uTensor/uTensor · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
uTensor
/
uTensor
Public
Notifications
You must be signed in to change notification settings
Fork
250
Star
1.9k
Code
Issues
51
Pull requests
5
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
uTensor
/
src
/
uTensor
/
core
/
memoryManagementInterface.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
141 lines (127 loc) · 3.47 KB
Breadcrumbs
uTensor
/
src
/
uTensor
/
core
/
memoryManagementInterface.cpp
Copy path
File metadata and controls
141 lines (127 loc) · 3.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#
include
"
memoryManagementInterface.hpp
"
#
include
"
uTensor/core/uTensor_util.hpp
"
namespace
uTensor
{
Handle::Handle
(
const
Handle& that) {}
void
* Handle::
operator
new
(
size_t
sz) {
return
nullptr
; }
void
Handle::
operator
delete
(
void
* p) {}
Handle::Handle
() : _ptr(
nullptr
) {}
Handle::Handle
(
void
* p) : _ptr(p) {}
void
* Handle::
operator
*() {
return
_ptr; }
bool
Handle::
operator
!()
const
{
return
_ptr ==
nullptr
; }
Handle::
operator
bool
()
const
{
return
_ptr !=
nullptr
; }
void
*
operator
*(
const
Handle& that) {
return
that.
_ptr
; }
/*
* Handle Reference Stuff
*/
HandleReference::HandleReference
() : _ref(
nullptr
) {}
HandleReference::HandleReference
(Handle* ref) : _ref(ref) {}
HandleReference::HandleReference
(
const
Handle& ref)
: _ref(
const_cast
<Handle*>(&ref)) {}
HandleReference::HandleReference
(
const
HandleReference& that) {
_ref = that.
_ref
;
}
HandleReference::HandleReference
(HandleReference&& that) {
_ref = that.
_ref
;
that.
_ref
=
nullptr
;
}
HandleReference& HandleReference::
operator
=(Handle* ref) {
_ref = ref;
return
*
this
;
}
HandleReference& HandleReference::
operator
=(
const
HandleReference& that) {
_ref = that.
_ref
;
return
*
this
;
}
HandleReference& HandleReference::
operator
=(HandleReference&& that) {
if
(
this
!= &that) {
_ref = that.
_ref
;
that.
_ref
=
nullptr
;
}
return
*
this
;
}
//
Delegate functions
//
return the data directly (looks pointer like)
void
* HandleReference::
operator
*() {
if
(_ref) {
//
Hue hue pointer like
return
**_ref;
}
return
nullptr
;
}
//
Allow users to check if handle is not valid
bool
HandleReference::
operator
!()
const
{
if
(_ref) {
return
!((
bool
)_ref);
}
return
true
;
}
HandleReference::
operator
bool
()
const
{
if
(_ref) {
return
((
bool
)_ref);
}
return
true
;
}
void
AllocatorInterface::update_hndl
(Handle* h,
void
* new_ptr) {
h->
_ptr
= new_ptr;
}
void
AllocatorInterface::bind
(
void
* ptr, Handle* hndl) {
if
(!
_has_handle
(hndl)) {
DEBUG
(
"
Allocator does not contain reference to handle
"
);
}
if
(
is_bound
(ptr, hndl)) {
ERR_EXIT
(
"
Cannot rebind Handles without unbinding
"
);
}
//
To be safe, make sure handle has a pointer
update_hndl
(hndl, ptr);
_bind
(ptr, hndl);
}
void
AllocatorInterface::unbind
(
void
* ptr, Handle* hndl) {
if
(!
is_bound
(ptr, hndl)) {
ERR_EXIT
(
"
Cannot unbind unbound Handles
"
);
}
_unbind
(ptr, hndl);
update_hndl
(hndl,
nullptr
);
}
bool
AllocatorInterface::is_bound
(
void
* ptr, Handle* hndl) {
return
_is_bound
(ptr, hndl);
}
void
*
AllocatorInterface::allocate
(
size_t
sz) {
if
(sz >
static_cast
<
size_t
>(
1
<<
31
)) {
//
TODO ERROR invalid allocation size
uTensor_printf
(
"
[ERROR] Attempted to allocator > 2**32 bytes
\n
"
);
return
nullptr
;
}
return
_allocate
(sz);
}
void
AllocatorInterface::deallocate
(
void
* ptr) {
_deallocate
(ptr);
ptr =
nullptr
;
}
void
AllocatorInterface::unbind_and_deallocate
(Handle* hndl){
void
*
ptr_t
= hndl->
_ptr
;
if
(hndl->
_ptr
) {
if
(
this
->
is_bound
(hndl->
_ptr
, hndl)) {
this
->
unbind
(hndl->
_ptr
, hndl);
}
else
{
ERR_EXIT
(
"
Cannot unbind unbound Handles
"
);
}
this
->
deallocate
(
ptr_t
);
}
}
bool
bind
(Handle& hndl, AllocatorInterface& allocator) {
if
(!hndl) {
return
false
;
}
allocator.
bind
(*hndl, &hndl);
return
true
;
}
bool
unbind
(Handle& hndl, AllocatorInterface& allocator) {
if
(!hndl) {
return
false
;
}
allocator.
unbind
(*hndl, &hndl);
return
true
;
}
bool
is_bound
(Handle& hndl, AllocatorInterface& allocator) {
return
allocator.
is_bound
(*hndl, &hndl);
}
};
//
namespace uTensor
Back
|
FazBrowse Home
|
New Git URL