Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
119c5c9c
Commit
119c5c9c
authored
Dec 03, 2019
by
Tianqi Chen
Committed by
ziheng
Dec 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MEMORY] Fix gcc 4.8 compact (#4461)
parent
8a61313e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
include/tvm/runtime/memory.h
+9
-5
No files found.
include/tvm/runtime/memory.h
View file @
119c5c9c
...
...
@@ -149,7 +149,11 @@ class SimpleObjAllocator :
template
<
typename
ArrayType
,
typename
ElemType
>
class
ArrayHandler
{
public
:
using
StorageType
=
typename
std
::
aligned_union
<
sizeof
(
ArrayType
),
ArrayType
,
ElemType
>::
type
;
using
StorageType
=
typename
std
::
aligned_storage
<
sizeof
(
ArrayType
),
alignof
(
ArrayType
)
>::
type
;
// for now only support elements that aligns with array header.
static_assert
(
alignof
(
ArrayType
)
%
alignof
(
ElemType
)
==
0
&&
sizeof
(
ArrayType
)
%
alignof
(
ElemType
)
==
0
,
"element alignment constraint"
);
template
<
typename
...
Args
>
static
ArrayType
*
New
(
SimpleObjAllocator
*
,
size_t
num_elems
,
Args
&&
...
args
)
{
...
...
@@ -160,15 +164,15 @@ class SimpleObjAllocator :
// In the case of an object pool, an allocator needs to create
// a special chunk memory that hides reference to the allocator
// and call allocator's release function in the deleter.
// NOTE2: Use inplace new to allocate
// This is used to get rid of warning when deleting a virtual
// class with non-virtual destructor.
// We are fine here as we captured the right deleter during construction.
// This is also the right way to get storage type for an object pool.
size_t
factor
=
sizeof
(
ArrayType
)
/
sizeof
(
ElemType
);
num_elems
=
(
num_elems
+
factor
-
1
)
/
factor
;
StorageType
*
data
=
new
StorageType
[
num_elems
+
1
];
size_t
unit
=
sizeof
(
StorageType
);
size_t
requested_size
=
num_elems
*
sizeof
(
ElemType
)
+
sizeof
(
ArrayType
);
size_t
num_storage_slots
=
(
requested_size
+
unit
-
1
)
/
unit
;
StorageType
*
data
=
new
StorageType
[
num_storage_slots
];
new
(
data
)
ArrayType
(
std
::
forward
<
Args
>
(
args
)...);
return
reinterpret_cast
<
ArrayType
*>
(
data
);
}
...
...
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