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
b2232e6f
Unverified
Commit
b2232e6f
authored
Jan 21, 2018
by
Robert Kimball
Committed by
GitHub
Jan 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move cpu tensor view to runtime dir and change cpu and interpreter to use it (#399)
parent
ad6b0f07
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
84 additions
and
242 deletions
+84
-242
CMakeLists.txt
src/ngraph/CMakeLists.txt
+1
-2
cpu_backend.cpp
src/ngraph/runtime/cpu/cpu_backend.cpp
+2
-2
cpu_backend.hpp
src/ngraph/runtime/cpu/cpu_backend.hpp
+0
-2
cpu_call_frame.cpp
src/ngraph/runtime/cpu/cpu_call_frame.cpp
+5
-5
cpu_external_function.cpp
src/ngraph/runtime/cpu/cpu_external_function.cpp
+2
-1
gpu_backend.cpp
src/ngraph/runtime/gpu/gpu_backend.cpp
+2
-1
gpu_call_frame.cpp
src/ngraph/runtime/gpu/gpu_call_frame.cpp
+4
-4
host_tensor_view.cpp
src/ngraph/runtime/host_tensor_view.cpp
+13
-17
host_tensor_view.hpp
src/ngraph/runtime/host_tensor_view.hpp
+8
-7
int_backend.cpp
src/ngraph/runtime/interpreter/int_backend.cpp
+2
-2
int_backend.hpp
src/ngraph/runtime/interpreter/int_backend.hpp
+0
-2
int_call_frame.cpp
src/ngraph/runtime/interpreter/int_call_frame.cpp
+19
-21
int_call_frame.hpp
src/ngraph/runtime/interpreter/int_call_frame.hpp
+26
-27
int_tensor_view.cpp
src/ngraph/runtime/interpreter/int_tensor_view.cpp
+0
-89
int_tensor_view.hpp
src/ngraph/runtime/interpreter/int_tensor_view.hpp
+0
-60
No files found.
src/ngraph/CMakeLists.txt
View file @
b2232e6f
...
@@ -88,12 +88,12 @@ set (SRC
...
@@ -88,12 +88,12 @@ set (SRC
pass/visualize_tree.cpp
pass/visualize_tree.cpp
pattern/matcher.cpp
pattern/matcher.cpp
runtime/aligned_buffer.cpp
runtime/aligned_buffer.cpp
runtime/host_tensor_view.cpp
runtime/interpreter/int_backend.cpp
runtime/interpreter/int_backend.cpp
runtime/interpreter/int_call_frame.cpp
runtime/interpreter/int_call_frame.cpp
runtime/interpreter/int_external_function.cpp
runtime/interpreter/int_external_function.cpp
runtime/interpreter/int_kernels.cpp
runtime/interpreter/int_kernels.cpp
runtime/interpreter/int_manager.cpp
runtime/interpreter/int_manager.cpp
runtime/interpreter/int_tensor_view.cpp
runtime/manager.cpp
runtime/manager.cpp
runtime/tensor_view.cpp
runtime/tensor_view.cpp
serializer.cpp
serializer.cpp
...
@@ -168,7 +168,6 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND
...
@@ -168,7 +168,6 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND
runtime/cpu/cpu_kernel_utils.cpp
runtime/cpu/cpu_kernel_utils.cpp
runtime/cpu/cpu_emitter.cpp
runtime/cpu/cpu_emitter.cpp
runtime/cpu/cpu_external_function.cpp
runtime/cpu/cpu_external_function.cpp
runtime/cpu/cpu_tensor_view.cpp
runtime/cpu/cpu_tensor_view_wrapper.cpp
runtime/cpu/cpu_tensor_view_wrapper.cpp
)
)
# LLVM binary builds are typically built without RTTI
# LLVM binary builds are typically built without RTTI
...
...
src/ngraph/runtime/cpu/cpu_backend.cpp
View file @
b2232e6f
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/log.hpp"
#include "ngraph/log.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/host_tensor_view.hpp"
using
namespace
ngraph
;
using
namespace
ngraph
;
using
namespace
std
;
using
namespace
std
;
...
@@ -30,6 +30,6 @@ std::shared_ptr<ngraph::runtime::TensorView>
...
@@ -30,6 +30,6 @@ std::shared_ptr<ngraph::runtime::TensorView>
runtime
::
cpu
::
CPU_Backend
::
make_primary_tensor_view
(
const
ngraph
::
element
::
Type
&
element_type
,
runtime
::
cpu
::
CPU_Backend
::
make_primary_tensor_view
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
)
const
Shape
&
shape
)
{
{
auto
rc
=
make_shared
<
runtime
::
cpu
::
CPU_
TensorView
>
(
element_type
,
shape
);
auto
rc
=
make_shared
<
runtime
::
Host
TensorView
>
(
element_type
,
shape
);
return
dynamic_pointer_cast
<
runtime
::
TensorView
>
(
rc
);
return
dynamic_pointer_cast
<
runtime
::
TensorView
>
(
rc
);
}
}
src/ngraph/runtime/cpu/cpu_backend.hpp
View file @
b2232e6f
...
@@ -22,8 +22,6 @@ namespace ngraph
...
@@ -22,8 +22,6 @@ namespace ngraph
{
{
namespace
cpu
namespace
cpu
{
{
static
size_t
alignment
=
64
;
class
CPU_Backend
:
public
runtime
::
Backend
class
CPU_Backend
:
public
runtime
::
Backend
{
{
public
:
public
:
...
...
src/ngraph/runtime/cpu/cpu_call_frame.cpp
View file @
b2232e6f
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/
cpu/cpu
_tensor_view.hpp"
#include "ngraph/runtime/
host
_tensor_view.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
ngraph
;
using
namespace
ngraph
;
...
@@ -36,14 +36,14 @@ void runtime::cpu::CPU_CallFrame::tensor_call(
...
@@ -36,14 +36,14 @@ void runtime::cpu::CPU_CallFrame::tensor_call(
vector
<
void
*>
outputs
;
vector
<
void
*>
outputs
;
for
(
size_t
i
=
0
;
i
<
input_tvs
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
input_tvs
.
size
();
i
++
)
{
{
shared_ptr
<
runtime
::
cpu
::
CPU_
TensorView
>
tv
=
shared_ptr
<
runtime
::
Host
TensorView
>
tv
=
static_pointer_cast
<
runtime
::
cpu
::
CPU_
TensorView
>
(
input_tvs
[
i
]);
static_pointer_cast
<
runtime
::
Host
TensorView
>
(
input_tvs
[
i
]);
inputs
.
push_back
(
tv
->
get_data_ptr
());
inputs
.
push_back
(
tv
->
get_data_ptr
());
}
}
for
(
size_t
i
=
0
;
i
<
output_tvs
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
output_tvs
.
size
();
i
++
)
{
{
shared_ptr
<
runtime
::
cpu
::
CPU_
TensorView
>
tv
=
shared_ptr
<
runtime
::
Host
TensorView
>
tv
=
static_pointer_cast
<
runtime
::
cpu
::
CPU_
TensorView
>
(
output_tvs
[
i
]);
static_pointer_cast
<
runtime
::
Host
TensorView
>
(
output_tvs
[
i
]);
outputs
.
push_back
(
tv
->
get_data_ptr
());
outputs
.
push_back
(
tv
->
get_data_ptr
());
}
}
...
...
src/ngraph/runtime/cpu/cpu_external_function.cpp
View file @
b2232e6f
...
@@ -92,6 +92,7 @@
...
@@ -92,6 +92,7 @@
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_emitter.hpp"
#include "ngraph/runtime/cpu/cpu_emitter.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/host_tensor_view.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
ngraph
;
using
namespace
ngraph
;
...
@@ -499,7 +500,7 @@ using namespace ngraph::runtime;
...
@@ -499,7 +500,7 @@ using namespace ngraph::runtime;
writer
<<
"// Memory pool size is "
<<
temp_pool_size
<<
" bytes
\n
"
;
writer
<<
"// Memory pool size is "
<<
temp_pool_size
<<
" bytes
\n
"
;
writer
<<
"// Worst case size is "
<<
worst_case_tmp_size
<<
" bytes
\n
"
;
writer
<<
"// Worst case size is "
<<
worst_case_tmp_size
<<
" bytes
\n
"
;
writer
<<
"ngraph::runtime::AlignedBuffer memory_handler("
<<
temp_pool_size
<<
", "
writer
<<
"ngraph::runtime::AlignedBuffer memory_handler("
<<
temp_pool_size
<<
", "
<<
ngraph
::
runtime
::
cpu
::
alignment
<<
");
\n
"
;
<<
ngraph
::
runtime
::
alignment
<<
");
\n
"
;
writer
<<
"size_t pool_base_ptr = (size_t)memory_handler.get_ptr();
\n
"
;
writer
<<
"size_t pool_base_ptr = (size_t)memory_handler.get_ptr();
\n
"
;
writer
<<
"
\n
"
;
writer
<<
"
\n
"
;
...
...
src/ngraph/runtime/gpu/gpu_backend.cpp
View file @
b2232e6f
...
@@ -30,5 +30,6 @@ std::shared_ptr<ngraph::runtime::TensorView>
...
@@ -30,5 +30,6 @@ std::shared_ptr<ngraph::runtime::TensorView>
runtime
::
gpu
::
GPU_Backend
::
make_device_tensor
(
const
ngraph
::
element
::
Type
&
element_type
,
runtime
::
gpu
::
GPU_Backend
::
make_device_tensor
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
)
const
Shape
&
shape
)
{
{
return
make_shared
<
runtime
::
TensorView
>
(
element_type
,
shape
);
auto
rc
=
make_shared
<
runtime
::
HostTensorView
>
(
element_type
,
shape
);
return
dynamic_pointer_cast
<
runtime
::
TensorView
>
(
rc
);
}
}
src/ngraph/runtime/gpu/gpu_call_frame.cpp
View file @
b2232e6f
...
@@ -41,14 +41,14 @@ void runtime::gpu::GPU_CallFrame::tensor_call(
...
@@ -41,14 +41,14 @@ void runtime::gpu::GPU_CallFrame::tensor_call(
for
(
size_t
i
=
0
;
i
<
input_tvs
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
input_tvs
.
size
();
i
++
)
{
{
shared_ptr
<
runtime
::
cpu
::
CPU_
TensorView
>
tv
=
shared_ptr
<
runtime
::
Host
TensorView
>
tv
=
static_pointer_cast
<
runtime
::
cpu
::
CPU_
TensorView
>
(
input_tvs
[
i
]);
static_pointer_cast
<
runtime
::
Host
TensorView
>
(
input_tvs
[
i
]);
inputs
.
push_back
(
tv
->
get_data_ptr
());
inputs
.
push_back
(
tv
->
get_data_ptr
());
}
}
for
(
size_t
i
=
0
;
i
<
output_tvs
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
output_tvs
.
size
();
i
++
)
{
{
shared_ptr
<
runtime
::
cpu
::
CPU_
TensorView
>
tv
=
shared_ptr
<
runtime
::
Host
TensorView
>
tv
=
static_pointer_cast
<
runtime
::
cpu
::
CPU_
TensorView
>
(
output_tvs
[
i
]);
static_pointer_cast
<
runtime
::
Host
TensorView
>
(
output_tvs
[
i
]);
outputs
.
push_back
(
tv
->
get_data_ptr
());
outputs
.
push_back
(
tv
->
get_data_ptr
());
}
}
...
...
src/ngraph/runtime/
cpu/cpu
_tensor_view.cpp
→
src/ngraph/runtime/
host
_tensor_view.cpp
View file @
b2232e6f
...
@@ -17,20 +17,16 @@
...
@@ -17,20 +17,16 @@
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/descriptor/primary_tensor_view.hpp"
#include "ngraph/descriptor/primary_tensor_view.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/runtime/host_tensor_view.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
using
namespace
ngraph
;
using
namespace
ngraph
;
using
namespace
std
;
using
namespace
std
;
runtime
::
cpu
::
CPU_TensorView
::
CPU_TensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
runtime
::
HostTensorView
::
HostTensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
)
const
Shape
&
shape
,
const
string
&
name
)
:
runtime
::
TensorView
(
std
::
make_shared
<
ngraph
::
descriptor
::
PrimaryTensorView
>
(
:
runtime
::
TensorView
(
std
::
make_shared
<
ngraph
::
descriptor
::
PrimaryTensorView
>
(
std
::
make_shared
<
ngraph
::
TensorViewType
>
(
element_type
,
shape
),
std
::
make_shared
<
ngraph
::
TensorViewType
>
(
element_type
,
shape
),
name
,
true
,
true
,
false
))
"external"
,
true
,
true
,
false
))
,
m_allocated_buffer_pool
(
nullptr
)
,
m_allocated_buffer_pool
(
nullptr
)
,
m_aligned_buffer_pool
(
nullptr
)
,
m_aligned_buffer_pool
(
nullptr
)
...
@@ -41,7 +37,7 @@ runtime::cpu::CPU_TensorView::CPU_TensorView(const ngraph::element::Type& elemen
...
@@ -41,7 +37,7 @@ runtime::cpu::CPU_TensorView::CPU_TensorView(const ngraph::element::Type& elemen
m_buffer_size
=
m_descriptor
->
get_tensor_view_layout
()
->
get_size
()
*
element_type
.
size
();
m_buffer_size
=
m_descriptor
->
get_tensor_view_layout
()
->
get_size
()
*
element_type
.
size
();
if
(
m_buffer_size
>
0
)
if
(
m_buffer_size
>
0
)
{
{
size_t
allocation_size
=
m_buffer_size
+
runtime
::
cpu
::
alignment
;
size_t
allocation_size
=
m_buffer_size
+
runtime
::
alignment
;
m_allocated_buffer_pool
=
static_cast
<
char
*>
(
malloc
(
allocation_size
));
m_allocated_buffer_pool
=
static_cast
<
char
*>
(
malloc
(
allocation_size
));
m_aligned_buffer_pool
=
m_allocated_buffer_pool
;
m_aligned_buffer_pool
=
m_allocated_buffer_pool
;
size_t
mod
=
size_t
(
m_aligned_buffer_pool
)
%
alignment
;
size_t
mod
=
size_t
(
m_aligned_buffer_pool
)
%
alignment
;
...
@@ -52,7 +48,7 @@ runtime::cpu::CPU_TensorView::CPU_TensorView(const ngraph::element::Type& elemen
...
@@ -52,7 +48,7 @@ runtime::cpu::CPU_TensorView::CPU_TensorView(const ngraph::element::Type& elemen
}
}
}
}
runtime
::
cpu
::
CPU_TensorView
::~
CPU_
TensorView
()
runtime
::
HostTensorView
::~
Host
TensorView
()
{
{
if
(
m_allocated_buffer_pool
!=
nullptr
)
if
(
m_allocated_buffer_pool
!=
nullptr
)
{
{
...
@@ -60,17 +56,17 @@ runtime::cpu::CPU_TensorView::~CPU_TensorView()
...
@@ -60,17 +56,17 @@ runtime::cpu::CPU_TensorView::~CPU_TensorView()
}
}
}
}
char
*
runtime
::
cpu
::
CPU_
TensorView
::
get_data_ptr
()
char
*
runtime
::
Host
TensorView
::
get_data_ptr
()
{
{
return
m_aligned_buffer_pool
;
return
m_aligned_buffer_pool
;
}
}
const
char
*
runtime
::
cpu
::
CPU_
TensorView
::
get_data_ptr
()
const
const
char
*
runtime
::
Host
TensorView
::
get_data_ptr
()
const
{
{
return
m_aligned_buffer_pool
;
return
m_aligned_buffer_pool
;
}
}
void
runtime
::
cpu
::
CPU_
TensorView
::
write
(
const
void
*
source
,
size_t
tensor_offset
,
size_t
n
)
void
runtime
::
Host
TensorView
::
write
(
const
void
*
source
,
size_t
tensor_offset
,
size_t
n
)
{
{
if
(
tensor_offset
+
n
>
m_buffer_size
)
if
(
tensor_offset
+
n
>
m_buffer_size
)
{
{
...
@@ -80,7 +76,7 @@ void runtime::cpu::CPU_TensorView::write(const void* source, size_t tensor_offse
...
@@ -80,7 +76,7 @@ void runtime::cpu::CPU_TensorView::write(const void* source, size_t tensor_offse
memcpy
(
&
target
[
tensor_offset
],
source
,
n
);
memcpy
(
&
target
[
tensor_offset
],
source
,
n
);
}
}
void
runtime
::
cpu
::
CPU_
TensorView
::
read
(
void
*
target
,
size_t
tensor_offset
,
size_t
n
)
const
void
runtime
::
Host
TensorView
::
read
(
void
*
target
,
size_t
tensor_offset
,
size_t
n
)
const
{
{
if
(
tensor_offset
+
n
>
m_buffer_size
)
if
(
tensor_offset
+
n
>
m_buffer_size
)
{
{
...
@@ -90,12 +86,12 @@ void runtime::cpu::CPU_TensorView::read(void* target, size_t tensor_offset, size
...
@@ -90,12 +86,12 @@ void runtime::cpu::CPU_TensorView::read(void* target, size_t tensor_offset, size
memcpy
(
target
,
&
source
[
tensor_offset
],
n
);
memcpy
(
target
,
&
source
[
tensor_offset
],
n
);
}
}
size_t
runtime
::
cpu
::
CPU_
TensorView
::
get_size
()
const
size_t
runtime
::
Host
TensorView
::
get_size
()
const
{
{
return
get_tensor_view_layout
()
->
get_size
();
return
get_tensor_view_layout
()
->
get_size
();
}
}
const
element
::
Type
&
runtime
::
cpu
::
CPU_
TensorView
::
get_element_type
()
const
const
element
::
Type
&
runtime
::
Host
TensorView
::
get_element_type
()
const
{
{
return
get_tensor_view_layout
()
->
get_element_type
();
return
get_tensor_view_layout
()
->
get_element_type
();
}
}
src/ngraph/runtime/
cpu/cpu
_tensor_view.hpp
→
src/ngraph/runtime/
host
_tensor_view.hpp
View file @
b2232e6f
...
@@ -23,18 +23,19 @@ namespace ngraph
...
@@ -23,18 +23,19 @@ namespace ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
cpu
static
size_t
alignment
=
64
;
{
class
CPU_TensorView
;
class
HostTensorView
;
}
}
}
}
}
class
ngraph
::
runtime
::
cpu
::
CPU_
TensorView
:
public
ngraph
::
runtime
::
TensorView
class
ngraph
::
runtime
::
Host
TensorView
:
public
ngraph
::
runtime
::
TensorView
{
{
public
:
public
:
CPU_TensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
);
HostTensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
virtual
~
CPU_TensorView
();
const
Shape
&
shape
,
const
std
::
string
&
name
=
"external"
);
virtual
~
HostTensorView
();
char
*
get_data_ptr
();
char
*
get_data_ptr
();
const
char
*
get_data_ptr
()
const
;
const
char
*
get_data_ptr
()
const
;
...
...
src/ngraph/runtime/interpreter/int_backend.cpp
View file @
b2232e6f
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#include "ngraph/runtime/interpreter/int_backend.hpp"
#include "ngraph/runtime/interpreter/int_backend.hpp"
#include "ngraph/log.hpp"
#include "ngraph/log.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/
interpreter/in
t_tensor_view.hpp"
#include "ngraph/runtime/
hos
t_tensor_view.hpp"
using
namespace
ngraph
;
using
namespace
ngraph
;
using
namespace
std
;
using
namespace
std
;
...
@@ -30,6 +30,6 @@ shared_ptr<runtime::TensorView>
...
@@ -30,6 +30,6 @@ shared_ptr<runtime::TensorView>
runtime
::
interpreter
::
INT_Backend
::
make_primary_tensor_view
(
const
element
::
Type
&
element_type
,
runtime
::
interpreter
::
INT_Backend
::
make_primary_tensor_view
(
const
element
::
Type
&
element_type
,
const
Shape
&
shape
)
const
Shape
&
shape
)
{
{
auto
rc
=
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
element_type
,
shape
,
"external"
);
auto
rc
=
make_shared
<
runtime
::
Host
TensorView
>
(
element_type
,
shape
,
"external"
);
return
static_pointer_cast
<
runtime
::
TensorView
>
(
rc
);
return
static_pointer_cast
<
runtime
::
TensorView
>
(
rc
);
}
}
src/ngraph/runtime/interpreter/int_backend.hpp
View file @
b2232e6f
...
@@ -22,8 +22,6 @@ namespace ngraph
...
@@ -22,8 +22,6 @@ namespace ngraph
{
{
namespace
interpreter
namespace
interpreter
{
{
static
size_t
alignment
=
64
;
class
INT_Backend
:
public
runtime
::
Backend
class
INT_Backend
:
public
runtime
::
Backend
{
{
public
:
public
:
...
...
src/ngraph/runtime/interpreter/int_call_frame.cpp
View file @
b2232e6f
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
#include <cstdlib>
#include <cstdlib>
#include <iomanip>
#include <iomanip>
#include "ngraph/runtime/host_tensor_view.hpp"
#include "ngraph/runtime/interpreter/int_call_frame.hpp"
#include "ngraph/runtime/interpreter/int_call_frame.hpp"
#include "ngraph/runtime/interpreter/int_tensor_view.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
ngraph
;
using
namespace
ngraph
;
...
@@ -33,15 +33,14 @@ runtime::interpreter::INT_CallFrame::INT_CallFrame(shared_ptr<ExternalFunction>
...
@@ -33,15 +33,14 @@ runtime::interpreter::INT_CallFrame::INT_CallFrame(shared_ptr<ExternalFunction>
void
runtime
::
interpreter
::
INT_CallFrame
::
call
(
void
runtime
::
interpreter
::
INT_CallFrame
::
call
(
std
::
shared_ptr
<
Function
>
function
,
std
::
shared_ptr
<
Function
>
function
,
const
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
input_tvs
,
const
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>&
input_tvs
,
const
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
output_tvs
)
const
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>&
output_tvs
)
{
{
if
(
m_nan_check
)
if
(
m_nan_check
)
{
{
perform_nan_check
(
input_tvs
);
perform_nan_check
(
input_tvs
);
}
}
unordered_map
<
descriptor
::
TensorView
*
,
shared_ptr
<
runtime
::
interpreter
::
INT_TensorView
>>
unordered_map
<
descriptor
::
TensorView
*
,
shared_ptr
<
runtime
::
HostTensorView
>>
tensor_map
;
tensor_map
;
size_t
arg_index
=
0
;
size_t
arg_index
=
0
;
for
(
shared_ptr
<
op
::
Parameter
>
param
:
function
->
get_parameters
())
for
(
shared_ptr
<
op
::
Parameter
>
param
:
function
->
get_parameters
())
...
@@ -95,8 +94,8 @@ void runtime::interpreter::INT_CallFrame::call(
...
@@ -95,8 +94,8 @@ void runtime::interpreter::INT_CallFrame::call(
continue
;
continue
;
}
}
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>
inputs
;
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>
inputs
;
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>
outputs
;
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>
outputs
;
for
(
const
descriptor
::
Input
&
input
:
op
->
get_inputs
())
for
(
const
descriptor
::
Input
&
input
:
op
->
get_inputs
())
{
{
descriptor
::
TensorView
*
tv
=
input
.
get_output
().
get_tensor_view
().
get
();
descriptor
::
TensorView
*
tv
=
input
.
get_output
().
get_tensor_view
().
get
();
...
@@ -107,15 +106,14 @@ void runtime::interpreter::INT_CallFrame::call(
...
@@ -107,15 +106,14 @@ void runtime::interpreter::INT_CallFrame::call(
{
{
descriptor
::
TensorView
*
tv
=
op
->
get_output_tensor_view
(
i
).
get
();
descriptor
::
TensorView
*
tv
=
op
->
get_output_tensor_view
(
i
).
get
();
string
name
=
tv
->
get_tensor
().
get_name
();
string
name
=
tv
->
get_tensor
().
get_name
();
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>
itv
;
shared_ptr
<
runtime
::
Host
TensorView
>
itv
;
if
(
!
contains_key
(
tensor_map
,
tv
))
if
(
!
contains_key
(
tensor_map
,
tv
))
{
{
// The output tensor is not in the tensor map so create a new tensor
// The output tensor is not in the tensor map so create a new tensor
const
Shape
&
shape
=
op
->
get_output_shape
(
i
);
const
Shape
&
shape
=
op
->
get_output_shape
(
i
);
const
element
::
Type
&
element_type
=
op
->
get_output_element_type
(
i
);
const
element
::
Type
&
element_type
=
op
->
get_output_element_type
(
i
);
string
tensor_name
=
op
->
get_output_tensor
(
i
).
get_name
();
string
tensor_name
=
op
->
get_output_tensor
(
i
).
get_name
();
itv
=
make_shared
<
runtime
::
interpreter
::
INT_TensorView
>
(
itv
=
make_shared
<
runtime
::
HostTensorView
>
(
element_type
,
shape
,
tensor_name
);
element_type
,
shape
,
tensor_name
);
tensor_map
.
insert
({
tv
,
itv
});
tensor_map
.
insert
({
tv
,
itv
});
}
}
else
else
...
@@ -179,7 +177,7 @@ void runtime::interpreter::INT_CallFrame::call(
...
@@ -179,7 +177,7 @@ void runtime::interpreter::INT_CallFrame::call(
void
runtime
::
interpreter
::
INT_CallFrame
::
handle_output_alias
(
void
runtime
::
interpreter
::
INT_CallFrame
::
handle_output_alias
(
const
Node
&
node
,
const
Node
&
node
,
const
unordered_map
<
descriptor
::
TensorView
*
,
vector
<
size_t
>>&
output_alias_map
,
const
unordered_map
<
descriptor
::
TensorView
*
,
vector
<
size_t
>>&
output_alias_map
,
const
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
output_tvs
)
const
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>&
output_tvs
)
{
{
for
(
size_t
i
=
0
;
i
<
node
.
get_output_size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
node
.
get_output_size
();
++
i
)
{
{
...
@@ -205,8 +203,8 @@ void runtime::interpreter::INT_CallFrame::generate_calls(
...
@@ -205,8 +203,8 @@ void runtime::interpreter::INT_CallFrame::generate_calls(
const
element
::
Type
&
base_type
,
const
element
::
Type
&
base_type
,
const
element
::
Type
&
secondary_type
,
const
element
::
Type
&
secondary_type
,
ngraph
::
Node
&
op
,
ngraph
::
Node
&
op
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
out
)
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
out
)
{
{
if
(
base_type
==
element
::
boolean
)
if
(
base_type
==
element
::
boolean
)
{
{
...
@@ -261,8 +259,8 @@ void runtime::interpreter::INT_CallFrame::generate_calls(
...
@@ -261,8 +259,8 @@ void runtime::interpreter::INT_CallFrame::generate_calls(
}
}
void
runtime
::
interpreter
::
INT_CallFrame
::
tensor_call
(
void
runtime
::
interpreter
::
INT_CallFrame
::
tensor_call
(
const
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
input_tvs
,
const
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>&
input_tvs
,
const
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
output_tvs
)
const
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>&
output_tvs
)
{
{
call
(
m_function
,
input_tvs
,
output_tvs
);
call
(
m_function
,
input_tvs
,
output_tvs
);
}
}
...
@@ -271,15 +269,15 @@ void runtime::interpreter::INT_CallFrame::tensor_call(
...
@@ -271,15 +269,15 @@ void runtime::interpreter::INT_CallFrame::tensor_call(
const
vector
<
shared_ptr
<
runtime
::
TensorView
>>&
input_tvs
,
const
vector
<
shared_ptr
<
runtime
::
TensorView
>>&
input_tvs
,
const
vector
<
shared_ptr
<
runtime
::
TensorView
>>&
output_tvs
)
const
vector
<
shared_ptr
<
runtime
::
TensorView
>>&
output_tvs
)
{
{
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>
args
;
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>
args
;
vector
<
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>
out
;
vector
<
shared_ptr
<
runtime
::
Host
TensorView
>>
out
;
for
(
auto
tv
:
input_tvs
)
for
(
auto
tv
:
input_tvs
)
{
{
args
.
push_back
(
static_pointer_cast
<
runtime
::
interpreter
::
INT_
TensorView
>
(
tv
));
args
.
push_back
(
static_pointer_cast
<
runtime
::
Host
TensorView
>
(
tv
));
}
}
for
(
auto
tv
:
output_tvs
)
for
(
auto
tv
:
output_tvs
)
{
{
out
.
push_back
(
static_pointer_cast
<
runtime
::
interpreter
::
INT_
TensorView
>
(
tv
));
out
.
push_back
(
static_pointer_cast
<
runtime
::
Host
TensorView
>
(
tv
));
}
}
tensor_call
(
args
,
out
);
tensor_call
(
args
,
out
);
}
}
...
@@ -317,10 +315,10 @@ vector<runtime::PerformanceCounter>
...
@@ -317,10 +315,10 @@ vector<runtime::PerformanceCounter>
}
}
void
runtime
::
interpreter
::
INT_CallFrame
::
perform_nan_check
(
void
runtime
::
interpreter
::
INT_CallFrame
::
perform_nan_check
(
const
vector
<
shared_ptr
<
INT_
TensorView
>>&
tvs
,
const
Node
*
op
)
const
vector
<
shared_ptr
<
Host
TensorView
>>&
tvs
,
const
Node
*
op
)
{
{
size_t
arg_number
=
1
;
size_t
arg_number
=
1
;
for
(
shared_ptr
<
INT_
TensorView
>
tv
:
tvs
)
for
(
shared_ptr
<
Host
TensorView
>
tv
:
tvs
)
{
{
const
element
::
Type
&
type
=
tv
->
get_tensor
().
get_element_type
();
const
element
::
Type
&
type
=
tv
->
get_tensor
().
get_element_type
();
if
(
type
==
element
::
f32
)
if
(
type
==
element
::
f32
)
...
...
src/ngraph/runtime/interpreter/int_call_frame.hpp
View file @
b2232e6f
...
@@ -39,8 +39,7 @@
...
@@ -39,8 +39,7 @@
#include "ngraph/ops/slice.hpp"
#include "ngraph/ops/slice.hpp"
#include "ngraph/ops/sum.hpp"
#include "ngraph/ops/sum.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/interpreter/int_tensor_view.hpp"
#include "ngraph/runtime/host_tensor_view.hpp"
#include "ngraph/runtime/interpreter/int_tensor_view.hpp"
#include "ngraph/runtime/kernel/abs.hpp"
#include "ngraph/runtime/kernel/abs.hpp"
#include "ngraph/runtime/kernel/acos.hpp"
#include "ngraph/runtime/kernel/acos.hpp"
#include "ngraph/runtime/kernel/add.hpp"
#include "ngraph/runtime/kernel/add.hpp"
...
@@ -130,17 +129,17 @@ private:
...
@@ -130,17 +129,17 @@ private:
/// tensor views.
/// tensor views.
void
tensor_call
(
const
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
inputs
,
void
tensor_call
(
const
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
inputs
,
const
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
outputs
)
override
;
const
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
outputs
)
override
;
void
tensor_call
(
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
inputs
,
void
tensor_call
(
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
inputs
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
outputs
);
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
outputs
);
void
call
(
std
::
shared_ptr
<
Function
>
function
,
void
call
(
std
::
shared_ptr
<
Function
>
function
,
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
input_tvs
,
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
Host
TensorView
>>&
input_tvs
,
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
output_tvs
);
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
Host
TensorView
>>&
output_tvs
);
void
handle_output_alias
(
void
handle_output_alias
(
const
Node
&
node
,
const
Node
&
node
,
const
std
::
unordered_map
<
descriptor
::
TensorView
*
,
std
::
vector
<
size_t
>>&
output_alias_map
,
const
std
::
unordered_map
<
descriptor
::
TensorView
*
,
std
::
vector
<
size_t
>>&
output_alias_map
,
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
interpreter
::
INT_
TensorView
>>&
output_tvs
);
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
Host
TensorView
>>&
output_tvs
);
static
void
perform_nan_check
(
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
,
static
void
perform_nan_check
(
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
,
const
Node
*
op
=
nullptr
);
const
Node
*
op
=
nullptr
);
std
::
shared_ptr
<
ExternalFunction
>
m_external_function
;
std
::
shared_ptr
<
ExternalFunction
>
m_external_function
;
...
@@ -152,14 +151,14 @@ private:
...
@@ -152,14 +151,14 @@ private:
void
generate_calls
(
const
element
::
Type
&
base_type
,
void
generate_calls
(
const
element
::
Type
&
base_type
,
const
element
::
Type
&
secondary_type
,
const
element
::
Type
&
secondary_type
,
ngraph
::
Node
&
op
,
ngraph
::
Node
&
op
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
out
);
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
out
);
template
<
typename
BASE
>
template
<
typename
BASE
>
void
generate_calls
(
const
element
::
Type
&
type
,
void
generate_calls
(
const
element
::
Type
&
type
,
ngraph
::
Node
&
op
,
ngraph
::
Node
&
op
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
out
)
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
out
)
{
{
if
(
type
==
element
::
boolean
)
if
(
type
==
element
::
boolean
)
{
{
...
@@ -215,8 +214,8 @@ private:
...
@@ -215,8 +214,8 @@ private:
template
<
typename
T
,
typename
S
>
template
<
typename
T
,
typename
S
>
void
op_engine
(
ngraph
::
Node
&
node
,
void
op_engine
(
ngraph
::
Node
&
node
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
args
,
const
std
::
vector
<
std
::
shared_ptr
<
INT_
TensorView
>>&
out
)
const
std
::
vector
<
std
::
shared_ptr
<
Host
TensorView
>>&
out
)
{
{
std
::
string
node_op
=
node
.
description
();
std
::
string
node_op
=
node
.
description
();
if
(
node_op
==
"Abs"
)
if
(
node_op
==
"Abs"
)
...
@@ -286,7 +285,7 @@ private:
...
@@ -286,7 +285,7 @@ private:
const
op
::
Concat
*
concat
=
static_cast
<
const
op
::
Concat
*>
(
&
node
);
const
op
::
Concat
*
concat
=
static_cast
<
const
op
::
Concat
*>
(
&
node
);
std
::
vector
<
T
*>
in_args
;
std
::
vector
<
T
*>
in_args
;
std
::
vector
<
Shape
>
in_shapes
;
std
::
vector
<
Shape
>
in_shapes
;
for
(
std
::
shared_ptr
<
INT_
TensorView
>
arg
:
args
)
for
(
std
::
shared_ptr
<
Host
TensorView
>
arg
:
args
)
{
{
in_args
.
push_back
(
reinterpret_cast
<
T
*>
(
arg
->
get_data_ptr
()));
in_args
.
push_back
(
reinterpret_cast
<
T
*>
(
arg
->
get_data_ptr
()));
in_shapes
.
push_back
(
arg
->
get_shape
());
in_shapes
.
push_back
(
arg
->
get_shape
());
...
@@ -504,11 +503,11 @@ private:
...
@@ -504,11 +503,11 @@ private:
std
::
shared_ptr
<
ngraph
::
Function
>
reduction_function
=
reduce
->
get_functions
()[
0
];
std
::
shared_ptr
<
ngraph
::
Function
>
reduction_function
=
reduce
->
get_functions
()[
0
];
std
::
function
<
T
(
T
,
T
)
>
f
=
[
this
,
&
node
,
reduction_function
](
T
x
,
T
y
)
->
T
{
std
::
function
<
T
(
T
,
T
)
>
f
=
[
this
,
&
node
,
reduction_function
](
T
x
,
T
y
)
->
T
{
auto
tx
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tx
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"reduce_temp_x"
);
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"reduce_temp_x"
);
auto
ty
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
ty
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"reduce_temp_y"
);
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"reduce_temp_y"
);
auto
tr
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tr
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_output_element_type
(
0
),
Shape
{},
"reduce_temp_r"
);
node
.
get_output_element_type
(
0
),
Shape
{},
"reduce_temp_r"
);
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
...
@@ -532,11 +531,11 @@ private:
...
@@ -532,11 +531,11 @@ private:
reduce_window
->
get_functions
()[
0
];
reduce_window
->
get_functions
()[
0
];
std
::
function
<
T
(
T
,
T
)
>
f
=
[
this
,
&
node
,
reduction_function
](
T
x
,
T
y
)
->
T
{
std
::
function
<
T
(
T
,
T
)
>
f
=
[
this
,
&
node
,
reduction_function
](
T
x
,
T
y
)
->
T
{
auto
tx
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tx
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"reduce_window_temp_x"
);
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"reduce_window_temp_x"
);
auto
ty
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
ty
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"reduce_window_temp_y"
);
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"reduce_window_temp_y"
);
auto
tr
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tr
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_output_element_type
(
0
),
Shape
{},
"reduce_window_temp_r"
);
node
.
get_output_element_type
(
0
),
Shape
{},
"reduce_window_temp_r"
);
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
...
@@ -604,11 +603,11 @@ private:
...
@@ -604,11 +603,11 @@ private:
select_and_scatter
->
get_functions
()[
0
];
select_and_scatter
->
get_functions
()[
0
];
std
::
function
<
bool
(
T
,
T
)
>
f_selection
=
[
this
,
&
node
,
selection_function
](
T
x
,
std
::
function
<
bool
(
T
,
T
)
>
f_selection
=
[
this
,
&
node
,
selection_function
](
T
x
,
T
y
)
->
bool
{
T
y
)
->
bool
{
auto
tx
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tx
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"selection_temp_x"
);
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"selection_temp_x"
);
auto
ty
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
ty
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"selection_temp_y"
);
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"selection_temp_y"
);
auto
tr
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tr
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
element
::
boolean
,
Shape
{},
"selection_temp_r"
);
element
::
boolean
,
Shape
{},
"selection_temp_r"
);
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
...
@@ -619,11 +618,11 @@ private:
...
@@ -619,11 +618,11 @@ private:
std
::
shared_ptr
<
ngraph
::
Function
>
scatter_function
=
std
::
shared_ptr
<
ngraph
::
Function
>
scatter_function
=
select_and_scatter
->
get_functions
()[
1
];
select_and_scatter
->
get_functions
()[
1
];
std
::
function
<
T
(
T
,
T
)
>
f_scatter
=
[
this
,
&
node
,
scatter_function
](
T
x
,
T
y
)
->
T
{
std
::
function
<
T
(
T
,
T
)
>
f_scatter
=
[
this
,
&
node
,
scatter_function
](
T
x
,
T
y
)
->
T
{
auto
tx
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tx
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"scatter_temp_x"
);
node
.
get_inputs
().
at
(
0
).
get_element_type
(),
Shape
{},
"scatter_temp_x"
);
auto
ty
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
ty
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"scatter_temp_y"
);
node
.
get_inputs
().
at
(
1
).
get_element_type
(),
Shape
{},
"scatter_temp_y"
);
auto
tr
=
std
::
make_shared
<
runtime
::
interpreter
::
INT_
TensorView
>
(
auto
tr
=
std
::
make_shared
<
runtime
::
Host
TensorView
>
(
node
.
get_output_element_type
(
0
),
Shape
{},
"scatter_temp_r"
);
node
.
get_output_element_type
(
0
),
Shape
{},
"scatter_temp_r"
);
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
tx
->
get_data_ptr
()))
=
x
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
*
(
reinterpret_cast
<
T
*>
(
ty
->
get_data_ptr
()))
=
y
;
...
...
src/ngraph/runtime/interpreter/int_tensor_view.cpp
deleted
100644 → 0
View file @
ad6b0f07
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include <cstring>
#include <memory>
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/descriptor/primary_tensor_view.hpp"
#include "ngraph/log.hpp"
#include "ngraph/runtime/interpreter/int_backend.hpp"
#include "ngraph/runtime/interpreter/int_tensor_view.hpp"
using
namespace
ngraph
;
using
namespace
std
;
runtime
::
interpreter
::
INT_TensorView
::
INT_TensorView
(
const
element
::
Type
&
element_type
,
const
Shape
&
shape
,
const
string
&
name
)
:
runtime
::
TensorView
(
std
::
make_shared
<
descriptor
::
PrimaryTensorView
>
(
std
::
make_shared
<
TensorViewType
>
(
element_type
,
shape
),
name
,
true
,
true
,
false
))
,
m_allocated_buffer_pool
(
nullptr
)
,
m_aligned_buffer_pool
(
nullptr
)
{
m_descriptor
->
set_tensor_view_layout
(
std
::
make_shared
<
descriptor
::
layout
::
DenseTensorViewLayout
>
(
*
m_descriptor
));
m_buffer_size
=
m_descriptor
->
get_tensor_view_layout
()
->
get_size
()
*
element_type
.
size
();
if
(
m_buffer_size
>
0
)
{
size_t
allocation_size
=
m_buffer_size
+
runtime
::
interpreter
::
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
::
interpreter
::
INT_TensorView
::~
INT_TensorView
()
{
if
(
m_allocated_buffer_pool
!=
nullptr
)
{
free
(
m_allocated_buffer_pool
);
}
}
char
*
runtime
::
interpreter
::
INT_TensorView
::
get_data_ptr
()
{
return
m_aligned_buffer_pool
;
}
const
char
*
runtime
::
interpreter
::
INT_TensorView
::
get_data_ptr
()
const
{
return
m_aligned_buffer_pool
;
}
void
runtime
::
interpreter
::
INT_TensorView
::
write
(
const
void
*
source
,
size_t
tensor_offset
,
size_t
n
)
{
if
(
tensor_offset
+
n
>
m_buffer_size
)
{
throw
out_of_range
(
"write access past end of tensor"
);
}
char
*
target
=
get_data_ptr
();
memcpy
(
&
target
[
tensor_offset
],
source
,
n
);
}
void
runtime
::
interpreter
::
INT_TensorView
::
read
(
void
*
target
,
size_t
tensor_offset
,
size_t
n
)
const
{
if
(
tensor_offset
+
n
>
m_buffer_size
)
{
throw
out_of_range
(
"read access past end of tensor"
);
}
const
char
*
source
=
get_data_ptr
();
memcpy
(
target
,
&
source
[
tensor_offset
],
n
);
}
src/ngraph/runtime/interpreter/int_tensor_view.hpp
deleted
100644 → 0
View file @
ad6b0f07
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#pragma once
#include <memory>
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/types/element_type.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
interpreter
{
class
INT_TensorView
;
}
}
}
class
ngraph
::
runtime
::
interpreter
::
INT_TensorView
:
public
ngraph
::
runtime
::
TensorView
{
public
:
INT_TensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
,
const
std
::
string
&
name
);
virtual
~
INT_TensorView
();
char
*
get_data_ptr
();
const
char
*
get_data_ptr
()
const
;
/// @brief Write bytes directly into the tensor
/// @param p Pointer to source of data
/// @param tensor_offset Offset into tensor storage to begin writing. Must be element-aligned.
/// @param n Number of bytes to write, must be integral number of elements.
void
write
(
const
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
override
;
/// @brief Read bytes directly from the tensor
/// @param p Pointer to destination for data
/// @param tensor_offset Offset into tensor storage to begin reading. Must be element-aligned.
/// @param n Number of bytes to read, must be integral number of elements.
void
read
(
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
const
override
;
private
:
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