Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
d2e16992
Commit
d2e16992
authored
9 years ago
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5767 from dtmoodie:cpu_mat_memory_allocator
parents
bb4b4acc
237f33d4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
10 deletions
+29
-10
mat.hpp
modules/core/include/opencv2/core/mat.hpp
+2
-0
matrix.cpp
modules/core/src/matrix.cpp
+19
-2
ocl.cpp
modules/core/src/ocl.cpp
+3
-3
umatrix.cpp
modules/core/src/umatrix.cpp
+5
-5
No files found.
modules/core/include/opencv2/core/mat.hpp
View file @
d2e16992
...
...
@@ -1895,6 +1895,8 @@ public:
MatAllocator
*
allocator
;
//! and the standard allocator
static
MatAllocator
*
getStdAllocator
();
static
MatAllocator
*
getDefaultAllocator
();
static
void
setDefaultAllocator
(
MatAllocator
*
allocator
);
//! interaction with UMat
UMatData
*
u
;
...
...
This diff is collapsed.
Click to expand it.
modules/core/src/matrix.cpp
View file @
d2e16992
...
...
@@ -218,7 +218,24 @@ public:
delete
u
;
}
};
namespace
{
MatAllocator
*
g_matAllocator
=
NULL
;
}
MatAllocator
*
Mat
::
getDefaultAllocator
()
{
if
(
g_matAllocator
==
NULL
)
{
g_matAllocator
=
getStdAllocator
();
}
return
g_matAllocator
;
}
void
Mat
::
setDefaultAllocator
(
MatAllocator
*
allocator
)
{
g_matAllocator
=
allocator
;
}
MatAllocator
*
Mat
::
getStdAllocator
()
{
CV_SINGLETON_LAZY_INIT
(
MatAllocator
,
new
StdMatAllocator
())
...
...
@@ -388,7 +405,7 @@ void Mat::create(int d, const int* _sizes, int _type)
if
(
total
()
>
0
)
{
MatAllocator
*
a
=
allocator
,
*
a0
=
get
Std
Allocator
();
MatAllocator
*
a
=
allocator
,
*
a0
=
get
Default
Allocator
();
#ifdef HAVE_TGPU
if
(
!
a
||
a
==
tegra
::
getAllocator
()
)
a
=
tegra
::
getAllocator
(
d
,
_sizes
,
_type
);
...
...
@@ -426,7 +443,7 @@ void Mat::copySize(const Mat& m)
void
Mat
::
deallocate
()
{
if
(
u
)
(
u
->
currAllocator
?
u
->
currAllocator
:
allocator
?
allocator
:
get
Std
Allocator
())
->
unmap
(
u
);
(
u
->
currAllocator
?
u
->
currAllocator
:
allocator
?
allocator
:
get
Default
Allocator
())
->
unmap
(
u
);
u
=
NULL
;
}
...
...
This diff is collapsed.
Click to expand it.
modules/core/src/ocl.cpp
View file @
d2e16992
...
...
@@ -4292,7 +4292,7 @@ public:
bufferPoolSVM
.
setMaxReservedSize
(
poolSize
);
#endif
matStdAllocator
=
Mat
::
get
Std
Allocator
();
matStdAllocator
=
Mat
::
get
Default
Allocator
();
}
UMatData
*
defaultAllocate
(
int
dims
,
const
int
*
sizes
,
int
type
,
void
*
data
,
size_t
*
step
,
...
...
@@ -4918,7 +4918,7 @@ public:
if
(
u
->
data
&&
!
u
->
hostCopyObsolete
()
)
{
Mat
::
get
Std
Allocator
()
->
download
(
u
,
dstptr
,
dims
,
sz
,
srcofs
,
srcstep
,
dststep
);
Mat
::
get
Default
Allocator
()
->
download
(
u
,
dstptr
,
dims
,
sz
,
srcofs
,
srcstep
,
dststep
);
return
;
}
CV_Assert
(
u
->
handle
!=
0
);
...
...
@@ -5042,7 +5042,7 @@ public:
// 2. we overwrite part of the matrix, but the GPU copy is out-of-date
if
(
u
->
data
&&
(
u
->
hostCopyObsolete
()
<
u
->
deviceCopyObsolete
()
||
total
==
u
->
size
))
{
Mat
::
get
Std
Allocator
()
->
upload
(
u
,
srcptr
,
dims
,
sz
,
dstofs
,
dststep
,
srcstep
);
Mat
::
get
Default
Allocator
()
->
upload
(
u
,
srcptr
,
dims
,
sz
,
dstofs
,
dststep
,
srcstep
);
u
->
markHostCopyObsolete
(
false
);
u
->
markDeviceCopyObsolete
(
true
);
return
;
...
...
This diff is collapsed.
Click to expand it.
modules/core/src/umatrix.cpp
View file @
d2e16992
...
...
@@ -94,7 +94,7 @@ UMatData::~UMatData()
// simulate Mat::deallocate
if
(
u
->
mapcount
!=
0
)
{
(
u
->
currAllocator
?
u
->
currAllocator
:
/* TODO allocator ? allocator :*/
Mat
::
get
Std
Allocator
())
->
unmap
(
u
);
(
u
->
currAllocator
?
u
->
currAllocator
:
/* TODO allocator ? allocator :*/
Mat
::
get
Default
Allocator
())
->
unmap
(
u
);
}
else
{
...
...
@@ -144,7 +144,7 @@ MatAllocator* UMat::getStdAllocator()
if
(
ocl
::
haveOpenCL
()
&&
ocl
::
useOpenCL
()
)
return
ocl
::
getOpenCLAllocator
();
#endif
return
Mat
::
get
Std
Allocator
();
return
Mat
::
get
Default
Allocator
();
}
void
swap
(
UMat
&
a
,
UMat
&
b
)
...
...
@@ -286,7 +286,7 @@ UMat Mat::getUMat(int accessFlags, UMatUsageFlags usageFlags) const
accessFlags
|=
ACCESS_RW
;
UMatData
*
new_u
=
NULL
;
{
MatAllocator
*
a
=
allocator
,
*
a0
=
get
Std
Allocator
();
MatAllocator
*
a
=
allocator
,
*
a0
=
get
Default
Allocator
();
if
(
!
a
)
a
=
a0
;
new_u
=
a
->
allocate
(
dims
,
size
.
p
,
type
(),
data
,
step
.
p
,
accessFlags
,
usageFlags
);
...
...
@@ -302,7 +302,7 @@ UMat Mat::getUMat(int accessFlags, UMatUsageFlags usageFlags) const
}
if
(
!
allocated
)
{
allocated
=
get
Std
Allocator
()
->
allocate
(
new_u
,
accessFlags
,
usageFlags
);
allocated
=
get
Default
Allocator
()
->
allocate
(
new_u
,
accessFlags
,
usageFlags
);
CV_Assert
(
allocated
);
}
if
(
u
!=
NULL
)
...
...
@@ -358,7 +358,7 @@ void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlag
if
(
!
a
)
{
a
=
a0
;
a0
=
Mat
::
get
Std
Allocator
();
a0
=
Mat
::
get
Default
Allocator
();
}
try
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment