Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
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
ngraph
Commits
efc53f25
Commit
efc53f25
authored
Nov 15, 2017
by
Robert Kimball
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new memory handler for generated code
parent
a68f0715
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
53 deletions
+33
-53
external_function.cpp
src/ngraph/runtime/cpu/external_function.cpp
+11
-43
tensor_view.cpp
src/ngraph/runtime/cpu/tensor_view.cpp
+20
-8
tensor_view.hpp
src/ngraph/runtime/cpu/tensor_view.hpp
+2
-2
No files found.
src/ngraph/runtime/cpu/external_function.cpp
View file @
efc53f25
...
...
@@ -74,6 +74,7 @@
#include "ngraph/pass/memory_layout.hpp"
#include "ngraph/pass/topological_sort.hpp"
#include "ngraph/runtime/cpu/call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/runtime/cpu/emitter.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/utils.hpp"
...
...
@@ -93,25 +94,6 @@ static StaticInitializers s_static_initializers;
using
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
;
extern
"C"
void
allocate_aligned_buffer
(
size_t
size
,
size_t
alignment
,
char
**
allocated
,
char
**
aligned_ptr
)
{
size_t
allocation_size
=
size
+
alignment
;
*
allocated
=
static_cast
<
char
*>
(
malloc
(
allocation_size
));
*
aligned_ptr
=
*
allocated
;
size_t
mod
=
size_t
(
*
aligned_ptr
)
%
alignment
;
if
(
mod
!=
0
)
{
(
*
aligned_ptr
)
+=
(
alignment
-
mod
);
}
}
extern
"C"
void
free_aligned_buffer
(
void
*
allocated
)
{
free
(
allocated
);
}
#define TI(x) type_index(typeid(x))
static
const
OpMap
dispatcher
{
...
...
@@ -211,28 +193,18 @@ void ExternalFunction::compile()
#include "ngraph/runtime/cpu/cpu_kernels.hpp"
#include "ngraph/runtime/cpu/eigen_utils.hpp"
#include "ngraph/runtime/cpu/memory_handler.hpp"
using namespace ngraph::runtime::cpu::eigen;
extern "C" void allocate_aligned_buffer(
size_t size,
size_t alignment,
char** allocated,
char** aligned_ptr);
extern "C" void free_aligned_buffer(void* allocated);
)"
;
TU
<<
"// Declare a
ny functions that are not main
\n
"
;
TU
<<
"// Declare a
ll functions
\n
"
;
for
(
shared_ptr
<
Function
>
f
:
pass_manager
.
get_state
().
get_functions
())
{
if
(
f
!=
m_function
)
{
TU
<<
"extern
\"
C
\"
void "
<<
f
->
get_name
()
<<
"(
\n
"
;
TU
<<
" const std::vector<void*>& inputs,
\n
"
;
TU
<<
" const std::vector<void*>& outputs);
\n
"
;
}
TU
<<
"extern
\"
C
\"
void "
<<
f
->
get_name
()
<<
"(
\n
"
;
TU
<<
" const std::vector<void*>& inputs,
\n
"
;
TU
<<
" const std::vector<void*>& outputs);
\n
"
;
}
TU
<<
"
\n
"
;
...
...
@@ -244,12 +216,10 @@ extern "C" void free_aligned_buffer(void* allocated);
TU
<<
"{
\n
"
;
TU
.
indent
++
;
TU
<<
"// Allocate the memory pool
\n
"
;
size_t
temp_pool_size
=
pass_manager
.
get_state
().
get_temporary_pool_size
();
TU
<<
"char* allocated_buffer_pool;
\n
"
;
TU
<<
"char* aligned_buffer_pool;
\n
"
;
TU
<<
"allocate_aligned_buffer("
<<
temp_pool_size
<<
", 64"
<<
", &allocated_buffer_pool, &aligned_buffer_pool);
\n
"
;
TU
<<
"// Allocate the memory pool
\n
"
;
TU
<<
"ngraph::runtime::cpu::MemoryHandler memory_handler("
<<
temp_pool_size
<<
", "
<<
ngraph
::
runtime
::
cpu
::
alignment
<<
");
\n
"
;
TU
<<
"
\n
"
;
TU
<<
"// Define temporary tensors
\n
"
;
...
...
@@ -258,8 +228,8 @@ extern "C" void free_aligned_buffer(void* allocated);
for
(
descriptor
::
Tensor
*
tensor
:
node
->
liveness_new_list
)
{
TU
<<
tensor
->
get_element_type
()
<<
"* "
<<
tensor
->
get_name
()
<<
" = ("
<<
tensor
->
get_element_type
()
<<
"*)(
aligned_buffer_pool +
"
<<
tensor
->
get_pool_offset
()
<<
");
\n
"
;
<<
tensor
->
get_element_type
()
<<
"*)(
memory_handler.get_ptr(
"
<<
tensor
->
get_pool_offset
()
<<
")
)
;
\n
"
;
}
}
TU
<<
"
\n
"
;
...
...
@@ -321,8 +291,6 @@ extern "C" void free_aligned_buffer(void* allocated);
handler
->
second
(
&
emitter
,
node
.
get
(),
this
,
in
,
out
);
}
TU
<<
"
\n
free_aligned_buffer(allocated_buffer_pool);
\n
"
;
TU
.
indent
--
;
// End TU
...
...
src/ngraph/runtime/cpu/tensor_view.cpp
View file @
efc53f25
...
...
@@ -20,35 +20,47 @@
using
namespace
ngraph
;
using
namespace
std
;
extern
"C"
void
allocate_aligned_buffer
(
size_t
size
,
size_t
alignment
,
char
**
allocated
,
char
**
aligned_ptr
);
extern
"C"
void
free_aligned_buffer
(
void
*
allocated
);
runtime
::
cpu
::
CPUTensorView
::
CPUTensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
)
:
runtime
::
TensorView
(
std
::
make_shared
<
ngraph
::
descriptor
::
PrimaryTensorView
>
(
std
::
make_shared
<
ngraph
::
TensorViewType
>
(
element_type
,
shape
),
"external"
,
true
,
true
))
,
m_allocated_buffer_pool
(
nullptr
)
,
m_aligned_buffer_pool
(
nullptr
)
{
m_descriptor
->
set_tensor_view_layout
(
std
::
make_shared
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>
(
*
m_descriptor
));
m_buffer_size
=
m_descriptor
->
get_tensor_view_layout
()
->
get_size
()
*
element_type
.
size
();
allocate_aligned_buffer
(
m_buffer_size
,
runtime
::
cpu
::
alignment
,
&
m_allocated
,
&
m_buffer
);
if
(
m_buffer_size
>
0
)
{
size_t
allocation_size
=
m_buffer_size
+
runtime
::
cpu
::
alignment
;
m_allocated_buffer_pool
=
static_cast
<
char
*>
(
malloc
(
allocation_size
));
m_aligned_buffer_pool
=
m_allocated_buffer_pool
;
size_t
mod
=
size_t
(
m_aligned_buffer_pool
)
%
alignment
;
if
(
mod
!=
0
)
{
m_aligned_buffer_pool
+=
(
alignment
-
mod
);
}
}
}
runtime
::
cpu
::
CPUTensorView
::~
CPUTensorView
()
{
free_aligned_buffer
(
m_allocated
);
if
(
m_allocated_buffer_pool
!=
nullptr
)
{
free
(
m_allocated_buffer_pool
);
}
}
char
*
runtime
::
cpu
::
CPUTensorView
::
get_data_ptr
()
{
return
m_
buffer
;
return
m_
aligned_buffer_pool
;
}
const
char
*
runtime
::
cpu
::
CPUTensorView
::
get_data_ptr
()
const
{
return
m_
buffer
;
return
m_
aligned_buffer_pool
;
}
void
runtime
::
cpu
::
CPUTensorView
::
write
(
const
void
*
source
,
size_t
tensor_offset
,
size_t
n
)
...
...
src/ngraph/runtime/cpu/tensor_view.hpp
View file @
efc53f25
...
...
@@ -52,7 +52,7 @@ public:
void
read
(
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
const
override
;
private
:
char
*
m_allocated
;
char
*
m_
buffer
;
char
*
m_allocated
_buffer_pool
;
char
*
m_
aligned_buffer_pool
;
size_t
m_buffer_size
;
};
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