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
1f00711d
Commit
1f00711d
authored
Feb 27, 2019
by
pruthvi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed compiler errors
parent
d227de8e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
15 deletions
+65
-15
aligned_buffer.cpp
src/ngraph/runtime/aligned_buffer.cpp
+2
-0
cpu_mkl_allocator.cpp
src/ngraph/runtime/cpu/cpu_mkl_allocator.cpp
+46
-7
cpu_mkl_allocator.hpp
src/ngraph/runtime/cpu/cpu_mkl_allocator.hpp
+17
-8
No files found.
src/ngraph/runtime/aligned_buffer.cpp
View file @
1f00711d
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include <memory>
#include <memory>
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/cpu/cpu_mkl_allocator.hpp"
#include "ngraph/util.hpp"
#include "ngraph/util.hpp"
using
namespace
ngraph
;
using
namespace
ngraph
;
...
@@ -31,6 +32,7 @@ runtime::AlignedBuffer::AlignedBuffer()
...
@@ -31,6 +32,7 @@ runtime::AlignedBuffer::AlignedBuffer()
runtime
::
AlignedBuffer
::
AlignedBuffer
(
size_t
byte_size
,
size_t
alignment
)
runtime
::
AlignedBuffer
::
AlignedBuffer
(
size_t
byte_size
,
size_t
alignment
)
{
{
m_byte_size
=
byte_size
;
m_byte_size
=
byte_size
;
auto
cpu_allocator
=
ngraph
::
runtime
::
cpu
::
GetCPUAllocator
();
if
(
m_byte_size
>
0
)
if
(
m_byte_size
>
0
)
{
{
size_t
allocation_size
=
m_byte_size
+
alignment
;
size_t
allocation_size
=
m_byte_size
+
alignment
;
...
...
src/ngraph/runtime/cpu/cpu_mkl_allocator.cpp
View file @
1f00711d
...
@@ -15,16 +15,55 @@
...
@@ -15,16 +15,55 @@
//*****************************************************************************
//*****************************************************************************
#include "ngraph/runtime/cpu/cpu_mkl_allocator.hpp"
#include "ngraph/runtime/cpu/cpu_mkl_allocator.hpp"
#include <string>
#include "ngraph/except.hpp"
ngraph
::
runtime
::
cpu
::
CPUAllocator
::
CPUAllocator
()
ngraph
::
runtime
::
cpu
::
CPUAllocator
::
CPUAllocator
(
AllocateFunc
allocator
,
:
m_buffer
(
nullptr
)
DestroyFunc
deallocator
,
,
m_byte_size
(
0
)
size_t
alignment
)
:
m_framework_allocator
(
allocator
)
,
m_framework_deallocator
(
deallocator
)
,
m_alignment
(
alignment
)
{
{
mkl
::
i_malloc
=
MallocHook
;
mkl
::
i_free
=
FreeHook
;
}
}
ngraph
::
runtime
::
cpu
::
CPUAllocator
::
CPUAllocator
(
size_t
size
)
void
*
ngraph
::
runtime
::
cpu
::
CPUAllocator
::
cpu_malloc
(
size_t
size
)
{
{
m_byte_size
=
size
;
void
*
ptr
;
mkl
::
i_malloc
=
MallocHook
;
if
(
m_framework_allocator
!=
nullptr
)
mkl
::
i_free
=
FreeHook
;
{
ptr
=
m_framework_allocator
(
nullptr
,
m_alignment
,
size
);
}
else
{
ptr
=
malloc
(
size
);
}
// check for exception
if
(
size
!=
0
&&
!
ptr
)
{
throw
ngraph_error
(
"malloc failed to allocate memory of size "
+
std
::
to_string
(
size
));
throw
std
::
bad_alloc
();
}
return
ptr
;
}
void
ngraph
::
runtime
::
cpu
::
CPUAllocator
::
cpu_free
(
void
*
ptr
)
{
if
(
m_framework_deallocator
&&
ptr
)
{
m_framework_deallocator
(
nullptr
,
ptr
);
}
else
if
(
ptr
)
{
free
(
ptr
);
}
}
ngraph
::
runtime
::
cpu
::
CPUAllocator
&
ngraph
::
runtime
::
cpu
::
GetCPUAllocator
()
{
static
ngraph
::
runtime
::
cpu
::
CPUAllocator
cpu_allocator
(
nullptr
,
nullptr
,
4096
);
return
cpu_allocator
;
}
}
src/ngraph/runtime/cpu/cpu_mkl_allocator.hpp
View file @
1f00711d
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
#include "ngraph/util.hpp"
#include "ngraph/util.hpp"
using
namespace
ngraph
;
using
namespace
ngraph
;
using
AllocateFunc
=
void
*
(
*
)(
void
*
,
size_t
,
size_t
);
using
DestroyFunc
=
void
(
*
)(
void
*
,
void
*
);
namespace
mkl
namespace
mkl
{
{
...
@@ -45,6 +47,7 @@ namespace ngraph
...
@@ -45,6 +47,7 @@ namespace ngraph
namespace
cpu
namespace
cpu
{
{
class
CPUAllocator
;
class
CPUAllocator
;
extern
CPUAllocator
&
GetCPUAllocator
();
}
}
}
}
}
}
...
@@ -52,18 +55,24 @@ namespace ngraph
...
@@ -52,18 +55,24 @@ namespace ngraph
class
ngraph
::
runtime
::
cpu
::
CPUAllocator
class
ngraph
::
runtime
::
cpu
::
CPUAllocator
{
{
public
:
public
:
CPUAllocator
(
size_t
size
);
CPUAllocator
(
AllocateFunc
allocator
,
DestroyFunc
deallocator
,
size_t
alignment
);
CPUAllocator
();
//~CPUAllocator();
~
CPUAllocator
();
void
*
cpu_malloc
(
size_t
size
);
void
cpu_free
(
void
*
ptr
);
private
:
private
:
void
*
m_buffer
;
AllocateFunc
m_framework_allocator
;
size_t
m_byte_size
;
DestroyFunc
m_framework_deallocator
;
size_t
m_alignment
;
static
inline
void
*
MallocHook
(
size_t
size
)
static
inline
void
*
MallocHook
(
size_t
size
)
{
{
void
*
ptr
=
static_cast
<
void
*>
(
ngraph_malloc
(
size
));
ngraph
::
runtime
::
cpu
::
GetCPUAllocator
().
cpu_malloc
(
size
);
return
ptr
;
}
static
inline
void
FreeHook
(
void
*
ptr
)
{
ngraph
::
runtime
::
cpu
::
GetCPUAllocator
().
cpu_free
(
ptr
);
}
}
static
inline
void
FreeHook
(
void
*
ptr
)
{
ngraph_free
(
ptr
);
}
};
};
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