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
ebac7d27
Commit
ebac7d27
authored
Oct 06, 2017
by
Scott Cyphers
Committed by
GitHub
Oct 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into jmenon/docker_fix
parents
697ff8b3
aa3d8338
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
67 changed files
with
1884 additions
and
1067 deletions
+1884
-1067
CMakeLists.txt
src/ngraph/CMakeLists.txt
+9
-2
dense_tensor_view_layout.cpp
src/ngraph/descriptor/layout/dense_tensor_view_layout.cpp
+1
-0
dense_tensor_view_layout.hpp
src/ngraph/descriptor/layout/dense_tensor_view_layout.hpp
+2
-2
tensor_view_layout.cpp
src/ngraph/descriptor/layout/tensor_view_layout.cpp
+33
-0
tensor_view_layout.hpp
src/ngraph/descriptor/layout/tensor_view_layout.hpp
+8
-9
tensor_view.cpp
src/ngraph/descriptor/tensor_view.cpp
+6
-9
tensor_view.hpp
src/ngraph/descriptor/tensor_view.hpp
+5
-7
value.hpp
src/ngraph/descriptor/value.hpp
+3
-2
function.hpp
src/ngraph/function.hpp
+0
-1
ngraph.hpp
src/ngraph/ngraph.hpp
+4
-1
backend.cpp
src/ngraph/runtime/backend.cpp
+34
-0
backend.hpp
src/ngraph/runtime/backend.hpp
+44
-33
call_frame.hpp
src/ngraph/runtime/call_frame.hpp
+7
-35
divide.hpp
src/ngraph/runtime/eigen/divide.hpp
+0
-54
dot.hpp
src/ngraph/runtime/eigen/dot.hpp
+0
-55
maximum.hpp
src/ngraph/runtime/eigen/maximum.hpp
+0
-53
utils.hpp
src/ngraph/runtime/eigen/utils.hpp
+0
-156
external_function.hpp
src/ngraph/runtime/external_function.hpp
+11
-27
manager.cpp
src/ngraph/runtime/manager.cpp
+34
-0
manager.hpp
src/ngraph/runtime/manager.hpp
+58
-0
call_frame.cpp
src/ngraph/runtime/ngvm/call_frame.cpp
+73
-0
call_frame.hpp
src/ngraph/runtime/ngvm/call_frame.hpp
+81
-0
abs.hpp
src/ngraph/runtime/ngvm/eigen/abs.hpp
+23
-20
add.hpp
src/ngraph/runtime/ngvm/eigen/add.hpp
+27
-24
broadcast_scalar.hpp
src/ngraph/runtime/ngvm/eigen/broadcast_scalar.hpp
+57
-0
broadcast_vector_colwise.hpp
src/ngraph/runtime/ngvm/eigen/broadcast_vector_colwise.hpp
+25
-24
broadcast_vector_rowwise.hpp
src/ngraph/runtime/ngvm/eigen/broadcast_vector_rowwise.hpp
+24
-21
call.hpp
src/ngraph/runtime/ngvm/eigen/call.hpp
+72
-0
concat_matrix.hpp
src/ngraph/runtime/ngvm/eigen/concat_matrix.hpp
+72
-0
concat_vector.hpp
src/ngraph/runtime/ngvm/eigen/concat_vector.hpp
+35
-34
constant.hpp
src/ngraph/runtime/ngvm/eigen/constant.hpp
+25
-25
convert.hpp
src/ngraph/runtime/ngvm/eigen/convert.hpp
+24
-21
copy.hpp
src/ngraph/runtime/ngvm/eigen/copy.hpp
+28
-24
divide.hpp
src/ngraph/runtime/ngvm/eigen/divide.hpp
+26
-23
dot.hpp
src/ngraph/runtime/ngvm/eigen/dot.hpp
+24
-30
equal.hpp
src/ngraph/runtime/ngvm/eigen/equal.hpp
+27
-29
greater_eq.hpp
src/ngraph/runtime/ngvm/eigen/greater_eq.hpp
+31
-30
greater_than.hpp
src/ngraph/runtime/ngvm/eigen/greater_than.hpp
+29
-21
less_eq.hpp
src/ngraph/runtime/ngvm/eigen/less_eq.hpp
+27
-23
less_than.hpp
src/ngraph/runtime/ngvm/eigen/less_than.hpp
+29
-24
log.hpp
src/ngraph/runtime/ngvm/eigen/log.hpp
+23
-20
matrix_mult.hpp
src/ngraph/runtime/ngvm/eigen/matrix_mult.hpp
+57
-0
matrix_vector_product.hpp
src/ngraph/runtime/ngvm/eigen/matrix_vector_product.hpp
+27
-24
maximum.hpp
src/ngraph/runtime/ngvm/eigen/maximum.hpp
+26
-24
multiply.hpp
src/ngraph/runtime/ngvm/eigen/multiply.hpp
+27
-22
negate.hpp
src/ngraph/runtime/ngvm/eigen/negate.hpp
+22
-21
not_equal.hpp
src/ngraph/runtime/ngvm/eigen/not_equal.hpp
+29
-24
return.hpp
src/ngraph/runtime/ngvm/eigen/return.hpp
+40
-0
scalar_tensor_product.hpp
src/ngraph/runtime/ngvm/eigen/scalar_tensor_product.hpp
+62
-0
select.hpp
src/ngraph/runtime/ngvm/eigen/select.hpp
+32
-32
subtract.hpp
src/ngraph/runtime/ngvm/eigen/subtract.hpp
+27
-22
utils.hpp
src/ngraph/runtime/ngvm/eigen/utils.hpp
+166
-0
external_function.cpp
src/ngraph/runtime/ngvm/external_function.cpp
+0
-0
external_function.hpp
src/ngraph/runtime/ngvm/external_function.hpp
+72
-0
instruction.hpp
src/ngraph/runtime/ngvm/instruction.hpp
+12
-21
ngvm_backend.cpp
src/ngraph/runtime/ngvm/ngvm_backend.cpp
+24
-0
ngvm_backend.hpp
src/ngraph/runtime/ngvm/ngvm_backend.hpp
+6
-9
ngvm_manager.cpp
src/ngraph/runtime/ngvm/ngvm_manager.cpp
+37
-0
ngvm_manager.hpp
src/ngraph/runtime/ngvm/ngvm_manager.hpp
+17
-12
parameterized_tensor_view.hpp
src/ngraph/runtime/parameterized_tensor_view.hpp
+43
-0
tensor_view.cpp
src/ngraph/runtime/tensor_view.cpp
+40
-0
tensor_view.hpp
src/ngraph/runtime/tensor_view.hpp
+23
-14
value.hpp
src/ngraph/runtime/value.hpp
+5
-0
element_type.cpp
src/ngraph/types/element_type.cpp
+0
-2
element_type.hpp
src/ngraph/types/element_type.hpp
+14
-0
execute.cpp
test/execute.cpp
+0
-0
tensor.cpp
test/tensor.cpp
+35
-1
No files found.
src/ngraph/CMakeLists.txt
View file @
ebac7d27
...
@@ -14,9 +14,11 @@
...
@@ -14,9 +14,11 @@
set
(
SRC
set
(
SRC
descriptor/input.cpp
descriptor/input.cpp
descriptor/layout/dense_tensor_view_layout.cpp
descriptor/layout/dense_tensor_view_layout.cpp
descriptor/layout/tensor_view_layout.cpp
descriptor/output.cpp
descriptor/output.cpp
descriptor/primary_tensor_view.cpp
descriptor/primary_tensor_view.cpp
descriptor/tensor.cpp
descriptor/tensor.cpp
descriptor/tensor_view.cpp
descriptor/tuple.cpp
descriptor/tuple.cpp
function.cpp
function.cpp
log.cpp
log.cpp
...
@@ -50,8 +52,13 @@ set (SRC
...
@@ -50,8 +52,13 @@ set (SRC
pass/propagate_types.cpp
pass/propagate_types.cpp
pass/topological_sort.cpp
pass/topological_sort.cpp
pass/visualize_tree.cpp
pass/visualize_tree.cpp
runtime/call_frame.cpp
runtime/backend.cpp
runtime/external_function.cpp
runtime/manager.cpp
runtime/ngvm/call_frame.cpp
runtime/ngvm/external_function.cpp
runtime/ngvm/ngvm_backend.cpp
runtime/ngvm/ngvm_manager.cpp
runtime/tensor_view.cpp
runtime/tuple.cpp
runtime/tuple.cpp
runtime/utils.cpp
runtime/utils.cpp
shape.cpp
shape.cpp
...
...
src/ngraph/descriptor/layout/dense_tensor_view_layout.cpp
View file @
ebac7d27
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/except.hpp"
#include "ngraph/except.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/types/element_type.hpp"
using
namespace
ngraph
::
descriptor
::
layout
;
using
namespace
ngraph
::
descriptor
::
layout
;
using
ngraph
::
Shape
;
using
ngraph
::
Shape
;
...
...
src/ngraph/descriptor/layout/dense_tensor_view_layout.hpp
View file @
ebac7d27
...
@@ -17,14 +17,14 @@
...
@@ -17,14 +17,14 @@
#include <cstddef>
#include <cstddef>
#include <vector>
#include <vector>
#include "ngraph/descriptor/buffer.hpp"
#include "ngraph/descriptor/layout/tensor_view_layout.hpp"
#include "ngraph/descriptor/layout/tensor_view_layout.hpp"
#include "ngraph/descriptor/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
descriptor
namespace
descriptor
{
{
class
TensorView
;
namespace
layout
namespace
layout
{
{
/// @brief The standard strided layout, used for row-major and column-major, their permutations and slices.
/// @brief The standard strided layout, used for row-major and column-major, their permutations and slices.
...
...
src/ngraph/descriptor/layout/tensor_view_layout.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/descriptor/layout/tensor_view_layout.hpp"
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/types/element_type.hpp"
using
namespace
ngraph
::
descriptor
::
layout
;
TensorViewLayout
::
TensorViewLayout
(
const
ngraph
::
descriptor
::
TensorView
&
tensor_view
)
:
m_tensor_view_type
(
tensor_view
.
get_tensor_view_type
())
{
}
const
ngraph
::
element
::
Type
&
TensorViewLayout
::
get_element_type
()
const
{
return
m_tensor_view_type
->
get_element_type
();
}
const
ngraph
::
Shape
&
TensorViewLayout
::
get_shape
()
const
{
return
m_tensor_view_type
->
get_shape
();
}
src/ngraph/descriptor/layout/tensor_view_layout.hpp
View file @
ebac7d27
...
@@ -23,6 +23,11 @@
...
@@ -23,6 +23,11 @@
namespace
ngraph
namespace
ngraph
{
{
namespace
element
{
class
Type
;
}
namespace
descriptor
namespace
descriptor
{
{
class
TensorView
;
class
TensorView
;
...
@@ -35,10 +40,7 @@ namespace ngraph
...
@@ -35,10 +40,7 @@ namespace ngraph
class
TensorViewLayout
class
TensorViewLayout
{
{
protected
:
protected
:
TensorViewLayout
(
const
ngraph
::
descriptor
::
TensorView
&
tensor_view
)
TensorViewLayout
(
const
ngraph
::
descriptor
::
TensorView
&
tensor_view
);
:
m_tensor_view_type
(
tensor_view
.
get_tensor_view_type
())
{
}
public
:
public
:
virtual
~
TensorViewLayout
()
{}
virtual
~
TensorViewLayout
()
{}
...
@@ -52,11 +54,8 @@ namespace ngraph
...
@@ -52,11 +54,8 @@ namespace ngraph
/// With non-linear buffers, this will need to be something other than size_t.
/// With non-linear buffers, this will need to be something other than size_t.
virtual
size_t
get_index_offset
(
const
std
::
vector
<
size_t
>&
indices
)
=
0
;
virtual
size_t
get_index_offset
(
const
std
::
vector
<
size_t
>&
indices
)
=
0
;
const
element
::
Type
&
get_element_type
()
const
const
element
::
Type
&
get_element_type
()
const
;
{
const
Shape
&
get_shape
()
const
;
return
m_tensor_view_type
->
get_element_type
();
}
const
Shape
&
get_shape
()
const
{
return
m_tensor_view_type
->
get_shape
();
}
/// Where this view is located in the buffer.
/// Where this view is located in the buffer.
const
BufferPos
&
get_buffer_pos
()
const
{
return
m_buffer_pos
;
}
const
BufferPos
&
get_buffer_pos
()
const
{
return
m_buffer_pos
;
}
BufferPos
&
get_buffer_pos
()
{
return
m_buffer_pos
;
}
BufferPos
&
get_buffer_pos
()
{
return
m_buffer_pos
;
}
...
...
src/ngraph/
runtime/tensor_view_index.h
pp
→
src/ngraph/
descriptor/tensor_view.c
pp
View file @
ebac7d27
...
@@ -12,14 +12,12 @@
...
@@ -12,14 +12,12 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#pragma once
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/types/type.hpp"
using
namespace
ngraph
::
descriptor
;
namespace
ngraph
std
::
shared_ptr
<
const
ngraph
::
ValueType
>
TensorView
::
get_value_type
()
const
{
{
namespace
runtime
return
m_tensor_view_type
;
{
}
using
TensorViewIndex
=
unordered_map
<
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>
,
size_t
>
;
}
}
\ No newline at end of file
src/ngraph/descriptor/tensor_view.hpp
View file @
ebac7d27
...
@@ -16,15 +16,13 @@
...
@@ -16,15 +16,13 @@
#include <memory>
#include <memory>
#include "ngraph/descriptor/tensor.hpp"
#include "ngraph/descriptor/value.hpp"
#include "ngraph/descriptor/value.hpp"
#include "ngraph/log.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/types/type.hpp"
namespace
ngraph
namespace
ngraph
{
{
class
Node
;
class
Node
;
class
TensorViewType
;
namespace
descriptor
namespace
descriptor
{
{
...
@@ -34,6 +32,9 @@ namespace ngraph
...
@@ -34,6 +32,9 @@ namespace ngraph
class
TensorViewLayout
;
class
TensorViewLayout
;
}
}
class
Tensor
;
class
TensorView
;
/// @brief Compile-time descriptor of a first-class value that is a view of a tensor.
/// @brief Compile-time descriptor of a first-class value that is a view of a tensor.
class
TensorView
:
public
Value
class
TensorView
:
public
Value
{
{
...
@@ -51,10 +52,7 @@ namespace ngraph
...
@@ -51,10 +52,7 @@ namespace ngraph
virtual
const
Tensor
&
get_tensor
()
const
=
0
;
virtual
const
Tensor
&
get_tensor
()
const
=
0
;
virtual
Tensor
&
get_tensor
()
=
0
;
virtual
Tensor
&
get_tensor
()
=
0
;
virtual
std
::
shared_ptr
<
const
ValueType
>
get_value_type
()
const
override
virtual
std
::
shared_ptr
<
const
ValueType
>
get_value_type
()
const
override
;
{
return
m_tensor_view_type
;
}
const
std
::
string
&
get_name
()
const
{
return
m_name
;
}
const
std
::
string
&
get_name
()
const
{
return
m_name
;
}
std
::
shared_ptr
<
const
TensorViewType
>
get_tensor_view_type
()
const
std
::
shared_ptr
<
const
TensorViewType
>
get_tensor_view_type
()
const
...
...
src/ngraph/descriptor/value.hpp
View file @
ebac7d27
...
@@ -15,11 +15,12 @@
...
@@ -15,11 +15,12 @@
#pragma once
#pragma once
#include <memory>
#include <memory>
#include <vector>
#include "ngraph/types/type.hpp"
namespace
ngraph
namespace
ngraph
{
{
class
ValueType
;
namespace
descriptor
namespace
descriptor
{
{
class
TensorView
;
class
TensorView
;
...
...
src/ngraph/function.hpp
View file @
ebac7d27
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
#include "ngraph/node.hpp"
#include "ngraph/node.hpp"
#include "ngraph/ops/op.hpp"
#include "ngraph/ops/op.hpp"
#include "ngraph/ops/parameter.hpp"
#include "ngraph/ops/parameter.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/types/type.hpp"
#include "ngraph/types/type.hpp"
namespace
ngraph
namespace
ngraph
...
...
src/ngraph/ngraph.hpp
View file @
ebac7d27
...
@@ -80,9 +80,12 @@
...
@@ -80,9 +80,12 @@
#include "ngraph/ops/select.hpp"
#include "ngraph/ops/select.hpp"
#include "ngraph/ops/subtract.hpp"
#include "ngraph/ops/subtract.hpp"
#include "ngraph/ops/tuple.hpp"
#include "ngraph/ops/tuple.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/manager.hpp"
#include "ngraph/runtime/ngvm/ngvm_backend.hpp"
#include "ngraph/runtime/ngvm/ngvm_manager.hpp"
#include "ngraph/runtime/parameterized_tensor_view.hpp"
#include "ngraph/runtime/parameterized_tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tuple.hpp"
#include "ngraph/runtime/tuple.hpp"
...
...
src/ngraph/runtime/backend.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <memory>
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tuple.hpp"
#include "ngraph/types/element_type.hpp"
using
namespace
ngraph
::
runtime
;
std
::
shared_ptr
<
TensorView
>
Backend
::
make_primary_tensor_view
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
)
{
return
element_type
.
make_primary_tensor_view
(
shape
);
}
std
::
shared_ptr
<
ngraph
::
runtime
::
Tuple
>
Backend
::
make_tuple
(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
elements
)
{
return
std
::
make_shared
<
ngraph
::
runtime
::
Tuple
>
(
elements
);
}
src/ngraph/runtime/
eigen/scalar_tensor_product
.hpp
→
src/ngraph/runtime/
backend
.hpp
View file @
ebac7d27
...
@@ -14,46 +14,57 @@
...
@@ -14,46 +14,57 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include <memory>
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/common.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
element
{
class
Type
;
}
namespace
runtime
namespace
runtime
{
{
namespace
eigen
class
ExternalFunction
;
class
CallFrame
;
class
TensorView
;
class
Tuple
;
class
Value
;
template
<
typename
ET
>
class
ParameterizedTensorView
;
/// @brief Interface to a generic backend.
///
/// Backends are responsible for function execution and value allocation.
class
Backend
{
{
public
:
virtual
~
Backend
()
{}
/// @brief Make a call frame that can support one concurrent call of an external function.
///
/// If more than one concurrent execution is needed, each execution will require its own call frame.
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
(
const
std
::
shared_ptr
<
ExternalFunction
>&
external_function
)
=
0
;
/// @brief Return a handle for a tensor on the backend device.
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>
make_primary_tensor_view
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
);
template
<
typename
ET
>
template
<
typename
ET
>
class
ScalarTensorProductInstruction
:
public
Instruction
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
ET
>>
make_parameterized_tensor_view
(
const
Shape
&
shape
)
{
{
public
:
return
std
::
dynamic_pointer_cast
<
ngraph
::
runtime
::
ParameterizedTensorView
<
ET
>>
(
ScalarTensorProductInstruction
(
const
TensorViewInfo
&
arg0
,
make_primary_tensor_view
(
ET
::
element_type
(),
shape
));
const
TensorViewInfo
&
arg1
,
}
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
/// @brief Construct a tuple handle from a sequence of values.
,
m_arg1
(
arg1
)
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
Tuple
>
,
m_out
(
out
)
make_tuple
(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
elements
);
{
};
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
// This is a bit hacky: regardless of the tensor rank we
// pull it out as a vector. This works because of the way
// fmt::V computes sizes---it lumps together any higher
// dimensions---while fmt::M ignores them.
EigenVector
<
ET
>
(
call_frame
,
m_out
)
=
call_frame
.
get_tensor_view_data
<
ET
>
(
m_arg0
.
get_index
())[
0
]
*
EigenVector
<
ET
>
(
call_frame
,
m_arg1
);
}
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
};
}
}
}
}
}
src/ngraph/runtime/call_frame.hpp
View file @
ebac7d27
...
@@ -25,51 +25,23 @@ namespace ngraph
...
@@ -25,51 +25,23 @@ namespace ngraph
namespace
runtime
namespace
runtime
{
{
class
PrimaryTensorView
;
class
PrimaryTensorView
;
class
Instruction
;
class
Value
;
// A VM for executing lightly-compiled graph functions.
// A VM for executing lightly-compiled graph functions.
class
CallFrame
class
CallFrame
{
{
public
:
public
:
CallFrame
(
virtual
~
CallFrame
()
{}
size_t
n_inputs
,
size_t
n_outputs
,
const
TensorViewPtrs
&
temps
,
size_t
initial_pc
,
const
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>&
instructions
);
/// @brief Invoke the function with values matching the signature of the function.
/// @brief Invoke the function with values matching the signature of the function.
///
///
/// Tuples will be expanded into their tensor views to build the call frame.
/// Tuples will be expanded into their tensor views to build the call frame.
void
operator
()(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
inputs
,
virtual
void
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
outputs
);
operator
()(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
inputs
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
outputs
)
=
0
;
/// @brief Invoke the function with tuples pre-expanded to their underlying tensor views.
/// @brief Invoke the function with tuples pre-expanded to their underlying tensor views.
void
tensor_call
(
const
TensorViewPtrs
&
inputs
,
const
TensorViewPtrs
&
outputs
);
virtual
void
tensor_call
(
const
TensorViewPtrs
&
inputs
,
const
TensorViewPtrs
&
outputs
)
=
0
;
void
set_return
()
{
m_return
=
true
;
}
std
::
shared_ptr
<
TensorView
>
get_tensor_view
(
size_t
i
)
{
return
m_tensor_views
[
i
];
}
template
<
typename
ET
>
ParameterizedTensorView
<
ET
>*
get_parameterized_tensor_view
(
size_t
i
)
{
return
m_tensor_views
[
i
]
->
get_parameterized_tensor_view
<
ET
>
();
}
template
<
typename
ET
>
typename
ET
::
type
*
get_tensor_view_data
(
size_t
i
)
{
return
&
get_parameterized_tensor_view
<
ET
>
(
i
)
->
get_vector
()[
0
];
}
protected
:
size_t
m_n_inputs
;
size_t
m_n_outputs
;
TensorViewPtrs
m_tensor_views
;
size_t
m_initial_pc
;
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>
m_instructions
;
size_t
m_pc
;
size_t
m_next_pc
;
bool
m_return
;
};
};
}
}
}
}
src/ngraph/runtime/eigen/divide.hpp
deleted
100644 → 0
View file @
697ff8b3
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
eigen
{
template
<
typename
ET
>
class
DivideInstruction
:
public
Instruction
{
public
:
DivideInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
/
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
}
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
};
}
}
}
src/ngraph/runtime/eigen/dot.hpp
deleted
100644 → 0
View file @
697ff8b3
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
eigen
{
template
<
typename
ET
>
class
DotInstruction
:
public
Instruction
{
public
:
DotInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
<<
EigenVector
<
ET
>
(
call_frame
,
m_arg0
)
.
dot
(
EigenVector
<
ET
>
(
call_frame
,
m_arg1
));
}
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
};
}
}
}
src/ngraph/runtime/eigen/maximum.hpp
deleted
100644 → 0
View file @
697ff8b3
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
eigen
{
template
<
typename
ET
>
class
MaximumInstruction
:
public
Instruction
{
public
:
MaximumInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
.
max
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
));
}
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
};
}
}
}
src/ngraph/runtime/eigen/utils.hpp
deleted
100644 → 0
View file @
697ff8b3
// ----------------------------------------------------------------------------
// 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 <Eigen/Dense>
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
namespace
ngraph
{
namespace
runtime
{
class
TensorViewInfo
;
class
CallFrame
;
namespace
eigen
{
using
DynamicStrides
=
Eigen
::
Stride
<
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
;
using
VectorStrides
=
Eigen
::
Stride
<
Eigen
::
Dynamic
,
1
>
;
template
<
typename
ET
>
using
DynamicArray
=
Eigen
::
Array
<
typename
ET
::
type
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
;
template
<
typename
ET
>
using
EigenArrayBase
=
Eigen
::
Map
<
DynamicArray
<
ET
>
,
0
,
DynamicStrides
>
;
template
<
typename
ET
>
using
DynamicMatrix
=
Eigen
::
Matrix
<
typename
ET
::
type
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>
;
template
<
typename
ET
>
using
EigenMatrixBase
=
Eigen
::
Map
<
DynamicMatrix
<
ET
>
,
0
,
DynamicStrides
>
;
template
<
typename
ET
>
using
DynamicVector
=
Eigen
::
Matrix
<
typename
ET
::
type
,
Eigen
::
Dynamic
,
1
>
;
template
<
typename
ET
>
using
EigenVectorBase
=
Eigen
::
Map
<
DynamicVector
<
ET
>
,
0
,
VectorStrides
>
;
namespace
fmt
{
/// @brief vector format for Eigen wrappers.
class
V
{
public
:
V
(
const
TensorViewInfo
&
tensor_view_info
)
:
l0
(
tensor_view_info
.
get_layout
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>
()
->
get_size
())
{
}
public
:
size_t
l0
;
size_t
l1
{
1
};
size_t
s0
{
1
};
size_t
s1
{
1
};
};
class
M
{
M
(
const
Shape
&
shape
,
const
Strides
&
strides
)
:
l0
(
shape
.
at
(
0
))
,
l1
(
shape
.
at
(
1
))
,
s0
(
strides
.
at
(
0
))
,
s1
(
strides
.
at
(
1
))
{
}
M
(
const
std
::
shared_ptr
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>&
layout
)
:
M
(
layout
->
get_shape
(),
layout
->
get_strides
())
{
}
public
:
M
(
const
TensorViewInfo
&
tensor_view_info
)
:
M
(
tensor_view_info
.
get_layout
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>
())
{
}
public
:
size_t
l0
;
size_t
l1
;
size_t
s0
;
size_t
s1
;
};
}
// ET element type
// FMT array format (fmt::V for vector, etc.)
// BASE select array/matrix
template
<
typename
ET
,
typename
FMT
,
typename
BASE
,
typename
STRIDES
=
DynamicStrides
>
class
EigenWrapper
:
public
BASE
{
using
base
=
BASE
;
public
:
EigenWrapper
(
typename
ET
::
type
*
t
,
const
FMT
&
fmt
)
:
base
(
t
,
fmt
.
l0
,
fmt
.
l1
,
STRIDES
(
fmt
.
s0
,
fmt
.
s1
))
{
}
EigenWrapper
(
typename
ET
::
type
*
t
,
const
std
::
shared_ptr
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>&
layout
)
:
base
(
t
,
layout
->
get_size
(),
1
,
DynamicStrides
(
1
,
1
))
{
}
EigenWrapper
(
CallFrame
&
call_frame
,
const
TensorViewInfo
&
tensor_view_info
)
:
EigenWrapper
(
call_frame
.
get_tensor_view_data
<
ET
>
(
tensor_view_info
.
get_index
()),
FMT
(
tensor_view_info
))
{
}
template
<
typename
U
>
EigenWrapper
&
operator
=
(
const
U
&
other
)
{
this
->
base
::
operator
=
(
other
);
return
*
this
;
}
};
template
<
typename
ET
,
typename
FMT
=
fmt
::
V
>
using
EigenArray1d
=
EigenWrapper
<
ET
,
FMT
,
EigenArrayBase
<
ET
>>
;
template
<
typename
ET
,
typename
FMT
=
fmt
::
M
>
using
EigenArray2d
=
EigenWrapper
<
ET
,
FMT
,
EigenArrayBase
<
ET
>>
;
template
<
typename
ET
,
typename
FMT
=
fmt
::
M
>
using
EigenMatrix
=
EigenWrapper
<
ET
,
FMT
,
EigenMatrixBase
<
ET
>>
;
template
<
typename
ET
,
typename
FMT
=
fmt
::
V
>
using
EigenVector
=
EigenWrapper
<
ET
,
FMT
,
EigenVectorBase
<
ET
>
,
VectorStrides
>
;
}
}
}
src/ngraph/runtime/external_function.hpp
View file @
ebac7d27
...
@@ -26,45 +26,29 @@ namespace ngraph
...
@@ -26,45 +26,29 @@ namespace ngraph
{
{
namespace
runtime
namespace
runtime
{
{
class
CallFrame
;
class
ExternalFunction
class
ExternalFunction
{
{
using
FunctionMap
=
protected
:
std
::
unordered_map
<
std
::
shared_ptr
<
Function
>
,
std
::
shared_ptr
<
ExternalFunction
>>
;
using
OpFunction
=
std
::
function
<
void
(
const
ngraph
::
Node
*
,
ExternalFunction
*
,
FunctionMap
&
,
const
std
::
vector
<
TensorViewInfo
>&
inputs
,
const
std
::
vector
<
TensorViewInfo
>&
outputs
)
>
;
using
OpMap
=
std
::
unordered_map
<
std
::
type_index
,
OpFunction
>
;
public
:
ExternalFunction
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
function
,
ExternalFunction
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
function
,
bool
release_function
=
true
);
bool
release_function
=
true
)
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
();
:
m_function
(
function
)
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
(
FunctionMap
&
function_map
);
,
m_release_function
(
release_function
)
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Instruction
>>>
,
m_is_compiled
(
false
)
get_instructions
()
{
{
return
m_instructions
;
}
}
// Release original function's resources
// Release original function's resources
void
release_function
()
{
m_function
=
nullptr
;
}
void
release_function
()
{
m_function
=
nullptr
;
}
p
rotected
:
p
ublic
:
v
oid
compile
();
v
irtual
~
ExternalFunction
()
{}
v
oid
compile
(
FunctionMap
&
function_map
)
;
v
irtual
std
::
shared_ptr
<
CallFrame
>
make_call_frame
()
=
0
;
protected
:
std
::
shared_ptr
<
ngraph
::
Function
>
m_function
;
std
::
shared_ptr
<
ngraph
::
Function
>
m_function
;
bool
m_release_function
;
bool
m_release_function
;
bool
m_is_compiled
;
bool
m_is_compiled
;
size_t
m_n_inputs
;
size_t
m_n_outputs
;
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Instruction
>>>
m_instructions
;
ngraph
::
descriptor
::
TensorViewPtrs
m_temp_views
;
static
OpMap
&
get_op_map
();
};
};
}
}
}
}
src/ngraph/runtime/manager.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/manager.hpp"
using
namespace
ngraph
::
runtime
;
Manager
::
FactoryMap
&
Manager
::
get_factory_map
()
{
static
FactoryMap
factory_map
;
return
factory_map
;
}
std
::
shared_ptr
<
Manager
>
Manager
::
get
(
const
std
::
string
&
name
)
{
return
get_factory_map
().
at
(
name
)(
name
);
}
Manager
::
Factory
Manager
::
register_factory
(
std
::
string
name
,
Factory
factory
)
{
get_factory_map
()[
name
]
=
factory
;
return
factory
;
}
src/ngraph/runtime/manager.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <functional>
#include <map>
#include <memory>
#include <string>
namespace
ngraph
{
class
Function
;
namespace
runtime
{
class
Backend
;
class
ExternalFunction
;
/// @brief Interface to a generic manager.
///
/// A manager provides access to compilation for a backend, and a means to obtain
/// a backed for execution and allocation.
class
Manager
{
public
:
virtual
~
Manager
()
{}
/// @brief Allocate a backend for this transformer.
///
/// Specific transformers may provide addtional methods for allocating customized backends.
virtual
std
::
shared_ptr
<
Backend
>
allocate_backend
()
=
0
;
/// @brief Convert a function to a form that can be run on a backend.
virtual
std
::
shared_ptr
<
ExternalFunction
>
compile
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
fun
)
=
0
;
using
Factory
=
std
::
function
<
std
::
shared_ptr
<
Manager
>
(
const
std
::
string
&
)
>
;
using
FactoryMap
=
std
::
map
<
std
::
string
,
Factory
>
;
static
FactoryMap
&
get_factory_map
();
static
std
::
shared_ptr
<
Manager
>
get
(
const
std
::
string
&
name
);
static
Factory
register_factory
(
std
::
string
name
,
Factory
factory
);
};
}
}
src/ngraph/runtime/ngvm/call_frame.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <algorithm>
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
using
namespace
std
;
using
namespace
ngraph
::
runtime
::
ngvm
;
CallFrame
::
CallFrame
(
size_t
n_inputs
,
size_t
n_outputs
,
const
TensorViewPtrs
&
temps
,
size_t
initial_pc
,
const
shared_ptr
<
vector
<
shared_ptr
<
Instruction
>>>&
instructions
)
:
m_n_inputs
(
n_inputs
)
,
m_n_outputs
(
n_outputs
)
,
m_tensor_views
(
n_inputs
+
n_outputs
+
temps
.
size
())
,
m_initial_pc
(
initial_pc
)
,
m_instructions
(
instructions
)
{
copy
(
temps
.
begin
(),
temps
.
end
(),
m_tensor_views
.
begin
()
+
m_n_inputs
+
m_n_outputs
);
}
void
CallFrame
::
tensor_call
(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>&
inputs
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>&
outputs
)
{
copy
(
inputs
.
begin
(),
inputs
.
end
(),
m_tensor_views
.
begin
());
copy
(
outputs
.
begin
(),
outputs
.
end
(),
m_tensor_views
.
begin
()
+
m_n_inputs
);
m_next_pc
=
m_initial_pc
;
m_return
=
false
;
while
(
!
m_return
)
{
m_pc
=
m_next_pc
;
m_next_pc
=
m_pc
+
1
;
m_instructions
->
at
(
m_pc
)
->
execute
(
*
this
);
}
// Don't hold onto inputs/outputs
fill_n
(
m_tensor_views
.
begin
(),
m_n_inputs
+
m_n_outputs
,
nullptr
);
}
void
CallFrame
::
operator
()(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
arguments
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
results
)
{
// TODO: Check types of args and result
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>
inputs
;
for
(
auto
argument
:
arguments
)
{
argument
->
collect_tensor_views
(
inputs
,
argument
);
}
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>
outputs
;
for
(
auto
result
:
results
)
{
result
->
collect_tensor_views
(
outputs
,
result
);
}
tensor_call
(
inputs
,
outputs
);
}
src/ngraph/runtime/ngvm/call_frame.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <vector>
#include "ngraph/function.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
class
PrimaryTensorView
;
namespace
ngvm
{
class
Instruction
;
// A VM for executing lightly-compiled graph functions.
class
CallFrame
:
public
ngraph
::
runtime
::
CallFrame
{
public
:
CallFrame
(
size_t
n_inputs
,
size_t
n_outputs
,
const
TensorViewPtrs
&
temps
,
size_t
initial_pc
,
const
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>&
instructions
);
/// @brief Invoke the function with values matching the signature of the function.
///
/// Tuples will be expanded into their tensor views to build the call frame.
void
operator
()(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
inputs
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>&
outputs
);
/// @brief Invoke the function with tuples pre-expanded to their underlying tensor views.
void
tensor_call
(
const
TensorViewPtrs
&
inputs
,
const
TensorViewPtrs
&
outputs
);
void
set_return
()
{
m_return
=
true
;
}
std
::
shared_ptr
<
TensorView
>
get_tensor_view
(
size_t
i
)
{
return
m_tensor_views
[
i
];
}
template
<
typename
ET
>
ParameterizedTensorView
<
ET
>*
get_parameterized_tensor_view
(
size_t
i
)
{
return
m_tensor_views
[
i
]
->
get_parameterized_tensor_view
<
ET
>
();
}
template
<
typename
ET
>
typename
ET
::
type
*
get_tensor_view_data
(
size_t
i
)
{
return
&
get_parameterized_tensor_view
<
ET
>
(
i
)
->
get_vector
()[
0
];
}
protected
:
size_t
m_n_inputs
;
size_t
m_n_outputs
;
TensorViewPtrs
m_tensor_views
;
size_t
m_initial_pc
;
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>
m_instructions
;
size_t
m_pc
;
size_t
m_next_pc
;
bool
m_return
;
};
}
}
}
src/ngraph/runtime/
eigen/convert
.hpp
→
src/ngraph/runtime/
ngvm/eigen/abs
.hpp
View file @
ebac7d27
...
@@ -14,9 +14,9 @@
...
@@ -14,9 +14,9 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
...
@@ -24,28 +24,31 @@ namespace ngraph
...
@@ -24,28 +24,31 @@ namespace ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ETI
,
typename
ETO
>
namespace
eigen
class
ConvertInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
ConvertInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
class
AbsInstruction
:
public
Instruction
:
m_arg
(
arg
)
,
m_out
(
out
)
{
{
}
public
:
AbsInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ETO
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ETI
>
(
call_frame
,
m_arg
).
template
cast
<
typename
ETO
::
type
>
(
);
Eigen
::
abs
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg
)
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/add.hpp
→
src/ngraph/runtime/
ngvm/
eigen/add.hpp
View file @
ebac7d27
...
@@ -14,41 +14,44 @@
...
@@ -14,41 +14,44 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
AddInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
AddInstruction
(
const
TensorViewInfo
&
arg0
,
class
AddInstruction
:
public
Instruction
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
AddInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
+
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
+
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/ngvm/eigen/broadcast_scalar.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
template
<
typename
ET
>
class
BroadcastScalarInstruction
:
public
Instruction
{
public
:
BroadcastScalarInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
// This is a bit hacky: regardless of the tensor rank we
// pull it out as a vector. This works because of the way
// fmt::V computes sizes---it lumps together any higher
// dimensions---while fmt::M ignores them.
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg
)(
0
,
0
);
}
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
};
}
}
}
}
src/ngraph/runtime/
eigen/equal
.hpp
→
src/ngraph/runtime/
ngvm/eigen/broadcast_vector_colwise
.hpp
View file @
ebac7d27
...
@@ -14,41 +14,42 @@
...
@@ -14,41 +14,42 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
EqualInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
EqualInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
class
BroadcastVectorColwiseInstruction
:
public
Instruction
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
BroadcastVectorColwiseInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenMatrix
<
ET
>
(
call_frame
,
m_out
).
colwise
()
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
==
EigenVector
<
ET
>
(
call_frame
,
m_arg
);
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
}
.
template
cast
<
char
>
();
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
}
;
}
;
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/broadcast_vector_rowwise.hpp
→
src/ngraph/runtime/
ngvm/
eigen/broadcast_vector_rowwise.hpp
View file @
ebac7d27
...
@@ -14,38 +14,41 @@
...
@@ -14,38 +14,41 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
BroadcastVectorRowwiseInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
BroadcastVectorRowwiseInstruction
(
const
TensorViewInfo
&
arg
,
class
BroadcastVectorRowwiseInstruction
:
public
Instruction
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
{
}
public
:
BroadcastVectorRowwiseInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenMatrix
<
ET
>
(
call_frame
,
m_out
).
rowwise
()
=
EigenMatrix
<
ET
>
(
call_frame
,
m_out
).
rowwise
()
=
EigenVector
<
ET
>
(
call_frame
,
m_arg
).
transpose
();
EigenVector
<
ET
>
(
call_frame
,
m_arg
).
transpose
();
}
}
protected
:
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/ngvm/eigen/call.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/external_function.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
class
CallInstruction
:
public
Instruction
{
public
:
CallInstruction
(
std
::
shared_ptr
<
ExternalFunction
>
ef
,
std
::
vector
<
TensorViewInfo
>
in
,
std
::
vector
<
TensorViewInfo
>
out
)
:
m_external_function
(
ef
)
,
m_in
(
in
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
std
::
shared_ptr
<
CallFrame
>
cf
=
std
::
dynamic_pointer_cast
<
CallFrame
>
(
m_external_function
->
make_call_frame
());
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>
inputs
;
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>
outputs
;
for
(
auto
in
:
m_in
)
{
inputs
.
push_back
(
call_frame
.
get_tensor_view
(
in
.
get_index
()));
}
for
(
auto
out
:
m_out
)
{
outputs
.
push_back
(
call_frame
.
get_tensor_view
(
out
.
get_index
()));
}
(
*
cf
)(
inputs
,
outputs
);
}
protected
:
std
::
shared_ptr
<
ExternalFunction
>
m_external_function
;
std
::
vector
<
TensorViewInfo
>
m_in
;
std
::
vector
<
TensorViewInfo
>
m_out
;
};
}
}
}
}
src/ngraph/runtime/ngvm/eigen/concat_matrix.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
template
<
typename
ET
>
class
ConcatMatrixInstruction
:
public
Instruction
{
public
:
ConcatMatrixInstruction
(
const
std
::
vector
<
TensorViewInfo
>&
args
,
size_t
axis
,
const
TensorViewInfo
&
out
)
:
m_args
(
args
)
,
m_axis
(
axis
)
,
m_out
(
out
)
{
size_t
concat_pos
[
2
]{
0
,
0
};
for
(
auto
arg
:
args
)
{
auto
&
arg_shape
=
arg
.
get_tensor_view_layout
()
->
get_shape
();
m_blocks
.
push_back
(
{
concat_pos
[
0
],
concat_pos
[
1
],
arg_shape
.
at
(
0
),
arg_shape
.
at
(
1
)});
concat_pos
[
axis
]
+=
arg_shape
.
at
(
axis
);
}
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenMatrix
<
ET
>
out
(
call_frame
,
m_out
);
for
(
size_t
i
=
0
;
i
<
m_args
.
size
();
i
++
)
{
auto
&
b
=
m_blocks
[
i
];
out
.
block
(
b
[
0
],
b
[
1
],
b
[
2
],
b
[
3
])
<<
EigenMatrix
<
ET
>
(
call_frame
,
m_args
.
at
(
i
));
}
}
protected
:
std
::
vector
<
TensorViewInfo
>
m_args
;
size_t
m_axis
;
TensorViewInfo
m_out
;
std
::
vector
<
std
::
vector
<
size_t
>>
m_blocks
;
};
}
}
}
}
src/ngraph/runtime/
eigen/concat_matrix
.hpp
→
src/ngraph/runtime/
ngvm/eigen/concat_vector
.hpp
View file @
ebac7d27
...
@@ -14,9 +14,11 @@
...
@@ -14,9 +14,11 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include <vector>
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
...
@@ -24,46 +26,45 @@ namespace ngraph
...
@@ -24,46 +26,45 @@ namespace ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
ConcatMatrixInstruction
:
public
Instruction
{
{
public
:
// Would be better to just generate a sequence of copy into slice of output instructions
ConcatMatrixInstruction
(
const
std
::
vector
<
TensorViewInfo
>&
args
,
template
<
typename
ET
>
size_t
axis
,
class
ConcatVectorInstruction
:
public
Instruction
const
TensorViewInfo
&
out
)
:
m_args
(
args
)
,
m_axis
(
axis
)
,
m_out
(
out
)
{
{
size_t
concat_pos
[
2
]{
0
,
0
};
public
:
for
(
auto
arg
:
args
)
ConcatVectorInstruction
(
const
std
::
vector
<
TensorViewInfo
>&
args
,
const
TensorViewInfo
&
out
)
:
m_args
(
args
)
,
m_out
(
out
)
{
{
auto
&
arg_shape
=
arg
.
get_tensor_view_layout
()
->
get_shape
();
for
(
auto
arg
:
args
)
m_blocks
.
push_back
(
{
{
concat_pos
[
0
],
concat_pos
[
1
],
arg_shape
.
at
(
0
),
arg_shape
.
at
(
1
)});
auto
&
arg_shape
=
arg
.
get_tensor_view_layout
()
->
get_shape
();
concat_pos
[
axis
]
+=
arg_shape
.
at
(
axis
);
m_sizes
.
push_back
(
arg_shape
.
at
(
0
));
}
}
}
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenMatrix
<
ET
>
out
(
call_frame
,
m_out
);
for
(
size_t
i
=
0
;
i
<
m_args
.
size
();
i
++
)
{
{
auto
&
b
=
m_blocks
[
i
];
EigenVector
<
ET
>
out
(
call_frame
,
m_out
);
out
.
block
(
b
[
0
],
b
[
1
],
b
[
2
],
b
[
3
])
size_t
concat_pos
=
0
;
<<
EigenMatrix
<
ET
>
(
call_frame
,
m_args
.
at
(
i
));
for
(
size_t
i
=
0
;
i
<
m_args
.
size
();
i
++
)
{
out
.
segment
(
concat_pos
,
m_sizes
[
i
])
<<
EigenVector
<
ET
>
(
call_frame
,
m_args
.
at
(
i
));
concat_pos
+=
m_sizes
[
i
];
}
}
}
}
protected
:
protected
:
std
::
vector
<
TensorViewInfo
>
m_args
;
std
::
vector
<
TensorViewInfo
>
m_args
;
size_t
m_axis
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
std
::
vector
<
size_t
>
m_sizes
;
std
::
vector
<
std
::
vector
<
size_t
>>
m_blocks
;
}
;
}
;
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/copy
.hpp
→
src/ngraph/runtime/
ngvm/eigen/constant
.hpp
View file @
ebac7d27
...
@@ -14,42 +14,42 @@
...
@@ -14,42 +14,42 @@
#pragma once
#pragma once
#include <cassert>
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
/// @brief Copies a tensor from in to out.
namespace
eigen
template
<
typename
ET
>
class
CopyInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
/// @param in Index of input tensor in call frame.
class
ConstantInstruction
:
public
Instruction
/// @param out Index of output tensor in call frame.
CopyInstruction
(
size_t
in
,
size_t
out
)
:
m_in
(
in
)
,
m_out
(
out
)
{
{
}
public
:
ConstantInstruction
(
const
std
::
vector
<
typename
ET
::
type
>
value
,
const
TensorViewInfo
&
out
)
:
m_value
(
value
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
call_frame
.
get_parameterized_tensor_view
<
ET
>
(
m_out
)
->
get_vector
()
=
call_frame
.
get_parameterized_tensor_view
<
ET
>
(
m_out
.
get_index
())
call_frame
.
get_parameterized_tensor_view
<
ET
>
(
m_in
)
->
get_vector
()
;
->
get_vector
()
=
m_value
;
}
}
protected
:
protected
:
size_t
m_in
;
const
std
::
vector
<
typename
ET
::
type
>
m_value
;
size_t
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/constan
t.hpp
→
src/ngraph/runtime/
ngvm/eigen/conver
t.hpp
View file @
ebac7d27
...
@@ -14,9 +14,9 @@
...
@@ -14,9 +14,9 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
...
@@ -24,29 +24,32 @@ namespace ngraph
...
@@ -24,29 +24,32 @@ namespace ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
ConstantInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ETI
,
typename
ETO
>
ConstantInstruction
(
const
std
::
vector
<
typename
ET
::
type
>
value
,
class
ConvertInstruction
:
public
Instruction
const
TensorViewInfo
&
out
)
:
m_value
(
value
)
,
m_out
(
out
)
{
{
}
public
:
ConvertInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
call_frame
.
get_parameterized_tensor_view
<
ET
>
(
m_out
.
get_index
())
->
get_vector
()
=
EigenArray1d
<
ETO
>
(
call_frame
,
m_out
)
=
m_value
;
EigenArray1d
<
ETI
>
(
call_frame
,
m_arg
)
}
.
template
cast
<
typename
ETO
::
type
>
();
}
protected
:
protected
:
const
std
::
vector
<
typename
ET
::
type
>
m_value
;
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/less_eq
.hpp
→
src/ngraph/runtime/
ngvm/eigen/copy
.hpp
View file @
ebac7d27
...
@@ -14,41 +14,45 @@
...
@@ -14,41 +14,45 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include <cassert>
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
LessEqInstruction
:
public
Instruction
{
{
public
:
/// @brief Copies a tensor from in to out.
LessEqInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
template
<
typename
ET
>
:
m_arg0
(
arg0
)
class
CopyInstruction
:
public
Instruction
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
/// @param in Index of input tensor in call frame.
/// @param out Index of output tensor in call frame.
CopyInstruction
(
size_t
in
,
size_t
out
)
:
m_in
(
in
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
call_frame
.
get_parameterized_tensor_view
<
ET
>
(
m_out
)
->
get_vector
()
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
<=
call_frame
.
get_parameterized_tensor_view
<
ET
>
(
m_in
)
->
get_vector
();
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
}
.
template
cast
<
char
>
();
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
size_t
m_in
;
TensorViewInfo
m_arg1
;
size_t
m_out
;
TensorViewInfo
m_out
;
}
;
}
;
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/matrix_mult
.hpp
→
src/ngraph/runtime/
ngvm/eigen/divide
.hpp
View file @
ebac7d27
...
@@ -14,41 +14,44 @@
...
@@ -14,41 +14,44 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
MatrixMultInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
MatrixMultInstruction
(
const
TensorViewInfo
&
arg0
,
class
DivideInstruction
:
public
Instruction
{
public
:
DivideInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
,
m_out
(
out
)
{
{
}
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenMatrix
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
/
EigenMatrix
<
ET
>
(
call_frame
,
m_arg0
)
*
EigenMatrix
<
ET
>
(
call_frame
,
m_arg1
);
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/concat_vector
.hpp
→
src/ngraph/runtime/
ngvm/eigen/dot
.hpp
View file @
ebac7d27
...
@@ -14,51 +14,45 @@
...
@@ -14,51 +14,45 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
// Would be better to just generate a sequence of copy into slice of output instructions
namespace
eigen
template
<
typename
ET
>
class
ConcatVectorInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
ConcatVectorInstruction
(
const
std
::
vector
<
TensorViewInfo
>&
args
,
class
DotInstruction
:
public
Instruction
const
TensorViewInfo
&
out
)
:
m_args
(
args
)
,
m_out
(
out
)
{
{
for
(
auto
arg
:
args
)
public
:
DotInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
auto
&
arg_shape
=
arg
.
get_tensor_view_layout
()
->
get_shape
();
m_sizes
.
push_back
(
arg_shape
.
at
(
0
));
}
}
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenVector
<
ET
>
out
(
call_frame
,
m_out
);
size_t
concat_pos
=
0
;
for
(
size_t
i
=
0
;
i
<
m_args
.
size
();
i
++
)
{
{
out
.
segment
(
concat_pos
,
m_sizes
[
i
]
)
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
<<
EigenVector
<
ET
>
(
call_frame
,
m_arg
s
.
at
(
i
));
<<
EigenVector
<
ET
>
(
call_frame
,
m_arg
0
)
concat_pos
+=
m_sizes
[
i
]
;
.
dot
(
EigenVector
<
ET
>
(
call_frame
,
m_arg1
))
;
}
}
}
protected
:
protected
:
std
::
vector
<
TensorViewInfo
>
m_args
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_out
;
TensorViewInfo
m_arg1
;
std
::
vector
<
size_t
>
m_sizes
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/select
.hpp
→
src/ngraph/runtime/
ngvm/eigen/equal
.hpp
View file @
ebac7d27
...
@@ -14,46 +14,44 @@
...
@@ -14,46 +14,44 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
SelectInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
SelectInstruction
(
TensorViewInfo
arg0
,
class
EqualInstruction
:
public
Instruction
TensorViewInfo
arg1
,
TensorViewInfo
arg2
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_arg2
(
arg2
)
,
m_out
(
out
)
{
{
}
public
:
EqualInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_arg0
)
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
==
.
select
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
),
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
EigenArray1d
<
ET
>
(
call_frame
,
m_arg2
)
);
.
template
cast
<
char
>
(
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg2
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
}
;
}
;
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/call
.hpp
→
src/ngraph/runtime/
ngvm/eigen/greater_eq
.hpp
View file @
ebac7d27
...
@@ -14,53 +14,54 @@
...
@@ -14,53 +14,54 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
class
CallInstruction
:
public
Instructio
n
namespace
eige
n
{
{
public
:
template
<
typename
TI
,
typename
TO
>
CallInstruction
(
std
::
shared_ptr
<
ExternalFunction
>
ef
,
void
greater_eq
(
TI
arg0
,
TI
arg1
,
TO
out
)
std
::
vector
<
TensorViewInfo
>
in
,
std
::
vector
<
TensorViewInfo
>
out
)
:
m_external_function
(
ef
)
,
m_in
(
in
)
,
m_out
(
out
)
{
{
auto
result_as_float
=
get_map_array
(
&*
arg0
)
<=
get_map_array
(
&*
arg1
);
auto
result_as_char
=
result_as_float
.
template
cast
<
char
>
();
set_map_array
(
&*
out
,
result_as_char
);
}
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
template
<
typename
ET
>
class
GreaterEqInstruction
:
public
Instruction
{
{
std
::
shared_ptr
<
CallFrame
>
cf
=
m_external_function
->
make_call_frame
();
public
:
GreaterEqInstruction
(
TensorViewInfo
arg0
,
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>
inputs
;
TensorViewInfo
arg1
,
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Value
>>
outputs
;
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
for
(
auto
in
:
m_in
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
inputs
.
push_back
(
call_frame
.
get_tensor_view
(
in
.
get_index
()));
}
}
for
(
auto
out
:
m_out
)
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
outputs
.
push_back
(
call_frame
.
get_tensor_view
(
out
.
get_index
()));
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
>=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
.
template
cast
<
char
>
();
}
}
(
*
cf
)(
inputs
,
outputs
);
}
protected
:
protected
:
std
::
shared_ptr
<
ExternalFunction
>
m_external_function
;
TensorViewInfo
m_arg0
;
std
::
vector
<
TensorViewInfo
>
m_in
;
TensorViewInfo
m_arg1
;
std
::
vector
<
TensorViewInfo
>
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/broadcast_vector_colwise
.hpp
→
src/ngraph/runtime/
ngvm/eigen/greater_than
.hpp
View file @
ebac7d27
...
@@ -14,38 +14,46 @@
...
@@ -14,38 +14,46 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
BroadcastVectorColwiseInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
BroadcastVectorColwiseInstruction
(
const
TensorViewInfo
&
arg
,
class
GreaterThanInstruction
:
public
Instruction
const
TensorViewInfo
&
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
{
}
public
:
GreaterThanInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenMatrix
<
ET
>
(
call_frame
,
m_out
).
colwise
()
=
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenVector
<
ET
>
(
call_frame
,
m_arg
);
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
>
}
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
.
template
cast
<
char
>
();
}
protected
:
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_out
;
TensorViewInfo
m_arg1
;
};
TensorViewInfo
m_out
;
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/broadcast_scalar
.hpp
→
src/ngraph/runtime/
ngvm/eigen/less_eq
.hpp
View file @
ebac7d27
...
@@ -14,40 +14,44 @@
...
@@ -14,40 +14,44 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
BroadcastScalarInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
BroadcastScalarInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
class
LessEqInstruction
:
public
Instruction
:
m_arg
(
arg
)
,
m_out
(
out
)
{
{
}
public
:
LessEqInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
// This is a bit hacky: regardless of the tensor rank we
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
// pull it out as a vector. This works because of the way
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
<=
// fmt::V computes sizes---it lumps together any higher
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
// dimensions---while fmt::M ignores them.
.
template
cast
<
char
>
();
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg
)(
0
,
0
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_out
;
TensorViewInfo
m_arg1
;
};
TensorViewInfo
m_out
;
};
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/less_than.hpp
→
src/ngraph/runtime/
ngvm/
eigen/less_than.hpp
View file @
ebac7d27
...
@@ -14,41 +14,46 @@
...
@@ -14,41 +14,46 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
LessThanInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
LessThanInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
class
LessThanInstruction
:
public
Instruction
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
LessThanInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
<
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
<
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
.
template
cast
<
char
>
();
.
template
cast
<
char
>
();
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/log.hpp
→
src/ngraph/runtime/
ngvm/
eigen/log.hpp
View file @
ebac7d27
...
@@ -14,37 +14,40 @@
...
@@ -14,37 +14,40 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
LogInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
LogInstruction
(
TensorViewInfo
arg
,
TensorViewInfo
out
)
class
LogInstruction
:
public
Instruction
:
m_arg
(
arg
)
,
m_out
(
out
)
{
{
}
public
:
LogInstruction
(
TensorViewInfo
arg
,
TensorViewInfo
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_out
)
=
Eigen
::
log
(
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_arg
));
Eigen
::
log
(
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_arg
));
}
}
protected
:
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/ngvm/eigen/matrix_mult.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
template
<
typename
ET
>
class
MatrixMultInstruction
:
public
Instruction
{
public
:
MatrixMultInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenMatrix
<
ET
>
(
call_frame
,
m_out
)
=
EigenMatrix
<
ET
>
(
call_frame
,
m_arg0
)
*
EigenMatrix
<
ET
>
(
call_frame
,
m_arg1
);
}
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
};
}
}
}
}
src/ngraph/runtime/eigen/matrix_vector_product.hpp
→
src/ngraph/runtime/
ngvm/
eigen/matrix_vector_product.hpp
View file @
ebac7d27
...
@@ -14,41 +14,44 @@
...
@@ -14,41 +14,44 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
MatrixVectorProductInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
MatrixVectorProductInstruction
(
const
TensorViewInfo
&
arg0
,
class
MatrixVectorProductInstruction
:
public
Instruction
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
MatrixVectorProductInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenVector
<
ET
>
(
call_frame
,
m_out
)
=
EigenVector
<
ET
>
(
call_frame
,
m_out
)
=
EigenMatrix
<
ET
>
(
call_frame
,
m_arg0
)
*
EigenMatrix
<
ET
>
(
call_frame
,
m_arg0
)
*
EigenVector
<
ET
>
(
call_frame
,
m_arg1
);
EigenVector
<
ET
>
(
call_frame
,
m_arg1
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/greater_than
.hpp
→
src/ngraph/runtime/
ngvm/eigen/maximum
.hpp
View file @
ebac7d27
...
@@ -14,41 +14,43 @@
...
@@ -14,41 +14,43 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
GreaterThanInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
GreaterThanInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
class
MaximumInstruction
:
public
Instruction
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
MaximumInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
>
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
.
max
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
));
.
template
cast
<
char
>
();
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/multiply.hpp
→
src/ngraph/runtime/
ngvm/
eigen/multiply.hpp
View file @
ebac7d27
...
@@ -14,38 +14,43 @@
...
@@ -14,38 +14,43 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
MultiplyInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
MultiplyInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
class
MultiplyInstruction
:
public
Instruction
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
MultiplyInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
*
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
*
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/
eigen/abs
.hpp
→
src/ngraph/runtime/
ngvm/eigen/negate
.hpp
View file @
ebac7d27
...
@@ -14,38 +14,39 @@
...
@@ -14,38 +14,39 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
AbsInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
AbsInstruction
(
const
TensorViewInfo
&
arg
,
const
TensorViewInfo
&
out
)
class
NegateInstruction
:
public
Instruction
:
m_arg
(
arg
)
,
m_out
(
out
)
{
{
}
public
:
NegateInstruction
(
TensorViewInfo
arg
,
TensorViewInfo
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
-
EigenArray1d
<
ET
>
(
call_frame
,
m_arg
);
Eigen
::
abs
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg
));
}
}
protected
:
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/not_equal.hpp
→
src/ngraph/runtime/
ngvm/
eigen/not_equal.hpp
View file @
ebac7d27
...
@@ -14,41 +14,46 @@
...
@@ -14,41 +14,46 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
NotEqualInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
NotEqualInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
class
NotEqualInstruction
:
public
Instruction
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
NotEqualInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
!=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
!=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
.
template
cast
<
char
>
();
.
template
cast
<
char
>
();
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/ngvm/eigen/return.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
class
ReturnInstruction
:
public
Instruction
{
public
:
ReturnInstruction
()
{}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
call_frame
.
set_return
();
}
};
}
}
}
}
src/ngraph/runtime/ngvm/eigen/scalar_tensor_product.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/ngvm/eigen/utils.hpp"
#include "ngraph/runtime/ngvm/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
namespace
eigen
{
template
<
typename
ET
>
class
ScalarTensorProductInstruction
:
public
Instruction
{
public
:
ScalarTensorProductInstruction
(
const
TensorViewInfo
&
arg0
,
const
TensorViewInfo
&
arg1
,
const
TensorViewInfo
&
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
// This is a bit hacky: regardless of the tensor rank we
// pull it out as a vector. This works because of the way
// fmt::V computes sizes---it lumps together any higher
// dimensions---while fmt::M ignores them.
EigenVector
<
ET
>
(
call_frame
,
m_out
)
=
call_frame
.
get_tensor_view_data
<
ET
>
(
m_arg0
.
get_index
())[
0
]
*
EigenVector
<
ET
>
(
call_frame
,
m_arg1
);
}
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
};
}
}
}
}
src/ngraph/runtime/
eigen/greater_eq
.hpp
→
src/ngraph/runtime/
ngvm/eigen/select
.hpp
View file @
ebac7d27
...
@@ -14,49 +14,49 @@
...
@@ -14,49 +14,49 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
TI
,
typename
TO
>
namespace
eigen
void
greater_eq
(
TI
arg0
,
TI
arg1
,
TO
out
)
{
{
auto
result_as_float
=
get_map_array
(
&*
arg0
)
<=
get_map_array
(
&*
arg1
);
template
<
typename
ET
>
auto
result_as_char
=
result_as_float
.
template
cast
<
char
>
();
class
SelectInstruction
:
public
Instruction
set_map_array
(
&*
out
,
result_as_char
);
}
template
<
typename
ET
>
class
GreaterEqInstruction
:
public
Instruction
{
public
:
GreaterEqInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
SelectInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
arg2
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_arg2
(
arg2
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
>=
EigenArray1d
<
element
::
Bool
>
(
call_frame
,
m_arg0
)
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
))
.
select
(
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
),
.
template
cast
<
char
>
(
);
EigenArray1d
<
ET
>
(
call_frame
,
m_arg2
)
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_arg2
;
};
TensorViewInfo
m_out
;
};
}
}
}
}
}
}
}
src/ngraph/runtime/eigen/subtract.hpp
→
src/ngraph/runtime/
ngvm/
eigen/subtract.hpp
View file @
ebac7d27
...
@@ -14,39 +14,44 @@
...
@@ -14,39 +14,44 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/
ngvm/
call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/
ngvm/
eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/
ngvm/
instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
namespace
eigen
class
SubtractInstruction
:
public
Instruction
{
{
public
:
template
<
typename
ET
>
SubtractInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
class
SubtractInstruction
:
public
Instruction
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
{
}
public
:
SubtractInstruction
(
TensorViewInfo
arg0
,
TensorViewInfo
arg1
,
TensorViewInfo
out
)
:
m_arg0
(
arg0
)
,
m_arg1
(
arg1
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
-
EigenArray1d
<
ET
>
(
call_frame
,
m_arg0
)
-
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
EigenArray1d
<
ET
>
(
call_frame
,
m_arg1
);
}
}
protected
:
protected
:
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg0
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_arg1
;
TensorViewInfo
m_out
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
}
}
}
src/ngraph/runtime/ngvm/eigen/utils.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <Eigen/Dense>
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/runtime/ngvm/call_frame.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
namespace
ngraph
{
namespace
runtime
{
class
TensorViewInfo
;
namespace
ngvm
{
class
CallFrame
;
namespace
eigen
{
using
DynamicStrides
=
Eigen
::
Stride
<
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
;
using
VectorStrides
=
Eigen
::
Stride
<
Eigen
::
Dynamic
,
1
>
;
template
<
typename
ET
>
using
DynamicArray
=
Eigen
::
Array
<
typename
ET
::
type
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
;
template
<
typename
ET
>
using
EigenArrayBase
=
Eigen
::
Map
<
DynamicArray
<
ET
>
,
0
,
DynamicStrides
>
;
template
<
typename
ET
>
using
DynamicMatrix
=
Eigen
::
Matrix
<
typename
ET
::
type
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>
;
template
<
typename
ET
>
using
EigenMatrixBase
=
Eigen
::
Map
<
DynamicMatrix
<
ET
>
,
0
,
DynamicStrides
>
;
template
<
typename
ET
>
using
DynamicVector
=
Eigen
::
Matrix
<
typename
ET
::
type
,
Eigen
::
Dynamic
,
1
>
;
template
<
typename
ET
>
using
EigenVectorBase
=
Eigen
::
Map
<
DynamicVector
<
ET
>
,
0
,
VectorStrides
>
;
namespace
fmt
{
/// @brief vector format for Eigen wrappers.
class
V
{
public
:
V
(
const
TensorViewInfo
&
tensor_view_info
)
:
l0
(
tensor_view_info
.
get_layout
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>
()
->
get_size
())
{
}
public
:
size_t
l0
;
size_t
l1
{
1
};
size_t
s0
{
1
};
size_t
s1
{
1
};
};
class
M
{
M
(
const
Shape
&
shape
,
const
Strides
&
strides
)
:
l0
(
shape
.
at
(
0
))
,
l1
(
shape
.
at
(
1
))
,
s0
(
strides
.
at
(
0
))
,
s1
(
strides
.
at
(
1
))
{
}
M
(
const
std
::
shared_ptr
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>&
layout
)
:
M
(
layout
->
get_shape
(),
layout
->
get_strides
())
{
}
public
:
M
(
const
TensorViewInfo
&
tensor_view_info
)
:
M
(
tensor_view_info
.
get_layout
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>
())
{
}
public
:
size_t
l0
;
size_t
l1
;
size_t
s0
;
size_t
s1
;
};
}
// ET element type
// FMT array format (fmt::V for vector, etc.)
// BASE select array/matrix
template
<
typename
ET
,
typename
FMT
,
typename
BASE
,
typename
STRIDES
=
DynamicStrides
>
class
EigenWrapper
:
public
BASE
{
using
base
=
BASE
;
public
:
EigenWrapper
(
typename
ET
::
type
*
t
,
const
FMT
&
fmt
)
:
base
(
t
,
fmt
.
l0
,
fmt
.
l1
,
STRIDES
(
fmt
.
s0
,
fmt
.
s1
))
{
}
EigenWrapper
(
typename
ET
::
type
*
t
,
const
std
::
shared_ptr
<
ngraph
::
descriptor
::
layout
::
DenseTensorViewLayout
>&
layout
)
:
base
(
t
,
layout
->
get_size
(),
1
,
DynamicStrides
(
1
,
1
))
{
}
EigenWrapper
(
CallFrame
&
call_frame
,
const
TensorViewInfo
&
tensor_view_info
)
:
EigenWrapper
(
call_frame
.
get_tensor_view_data
<
ET
>
(
tensor_view_info
.
get_index
()),
FMT
(
tensor_view_info
))
{
}
template
<
typename
U
>
EigenWrapper
&
operator
=
(
const
U
&
other
)
{
this
->
base
::
operator
=
(
other
);
return
*
this
;
}
};
template
<
typename
ET
,
typename
FMT
=
fmt
::
V
>
using
EigenArray1d
=
EigenWrapper
<
ET
,
FMT
,
EigenArrayBase
<
ET
>>
;
template
<
typename
ET
,
typename
FMT
=
fmt
::
M
>
using
EigenArray2d
=
EigenWrapper
<
ET
,
FMT
,
EigenArrayBase
<
ET
>>
;
template
<
typename
ET
,
typename
FMT
=
fmt
::
M
>
using
EigenMatrix
=
EigenWrapper
<
ET
,
FMT
,
EigenMatrixBase
<
ET
>>
;
template
<
typename
ET
,
typename
FMT
=
fmt
::
V
>
using
EigenVector
=
EigenWrapper
<
ET
,
FMT
,
EigenVectorBase
<
ET
>
,
VectorStrides
>
;
}
}
}
}
src/ngraph/runtime/external_function.cpp
→
src/ngraph/runtime/
ngvm/
external_function.cpp
View file @
ebac7d27
This diff is collapsed.
Click to expand it.
src/ngraph/runtime/ngvm/external_function.hpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <typeindex>
#include <typeinfo>
#include <unordered_map>
#include "ngraph/function.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
ngvm
{
class
Instruction
;
class
ExternalFunction
:
public
ngraph
::
runtime
::
ExternalFunction
{
using
FunctionMap
=
std
::
unordered_map
<
std
::
shared_ptr
<
Function
>
,
std
::
shared_ptr
<
ExternalFunction
>>
;
using
OpFunction
=
std
::
function
<
void
(
const
ngraph
::
Node
*
,
ExternalFunction
*
,
FunctionMap
&
,
const
std
::
vector
<
TensorViewInfo
>&
inputs
,
const
std
::
vector
<
TensorViewInfo
>&
outputs
)
>
;
using
OpMap
=
std
::
unordered_map
<
std
::
type_index
,
OpFunction
>
;
public
:
ExternalFunction
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
function
,
bool
release_function
=
true
);
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
();
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
(
FunctionMap
&
function_map
);
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>
get_instructions
()
{
return
m_instructions
;
}
// Release original function's resources
void
release_function
()
{
m_function
=
nullptr
;
}
protected
:
void
compile
();
void
compile
(
FunctionMap
&
function_map
);
size_t
m_n_inputs
;
size_t
m_n_outputs
;
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>
m_instructions
;
ngraph
::
descriptor
::
TensorViewPtrs
m_temp_views
;
static
OpMap
&
get_op_map
();
};
}
}
}
src/ngraph/runtime/
eigen/negate
.hpp
→
src/ngraph/runtime/
ngvm/instruction
.hpp
View file @
ebac7d27
...
@@ -14,35 +14,26 @@
...
@@ -14,35 +14,26 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include <memory>
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
template
<
typename
ET
>
class
CallFrame
;
class
NegateInstruction
:
public
Instruction
/// @brief An interpreter for an Op
///
/// The call_frame has a vector of instructions and calls execute on each instruction, passing it the call_frame.
/// Instructions get argument, result, and intermediate tensor views from the call frame. Instructions may also
/// set a flag in the call_frame to end execution, or adjust execution by modifying the position in the instruction vector.
class
Instruction
{
{
public
:
public
:
NegateInstruction
(
TensorViewInfo
arg
,
TensorViewInfo
out
)
virtual
~
Instruction
()
{}
:
m_arg
(
arg
)
virtual
void
execute
(
CallFrame
&
call_frame
)
const
=
0
;
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenArray1d
<
ET
>
(
call_frame
,
m_out
)
=
-
EigenArray1d
<
ET
>
(
call_frame
,
m_arg
);
}
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
};
};
}
}
}
}
...
...
src/ngraph/runtime/ngvm/ngvm_backend.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/ngvm/ngvm_backend.hpp"
#include "ngraph/runtime/external_function.hpp"
using
namespace
ngraph
::
runtime
::
ngvm
;
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
NGVMBackend
::
make_call_frame
(
const
std
::
shared_ptr
<
ExternalFunction
>&
external_function
)
{
return
external_function
->
make_call_frame
();
}
src/ngraph/runtime/
eigen/return
.hpp
→
src/ngraph/runtime/
ngvm/ngvm_backend
.hpp
View file @
ebac7d27
...
@@ -14,23 +14,20 @@
...
@@ -14,23 +14,20 @@
#pragma once
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/instruction.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
runtime
namespace
runtime
{
{
namespace
eigen
namespace
ngvm
{
{
class
ReturnInstruction
:
public
Instruction
/// @brief Transformer for the interpreted backend
class
NGVMBackend
:
public
Backend
{
{
public
:
public
:
ReturnInstruction
()
{}
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
(
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
const
std
::
shared_ptr
<
ngraph
::
runtime
::
ExternalFunction
>&
external_function
);
{
call_frame
.
set_return
();
}
};
};
}
}
}
}
...
...
src/ngraph/runtime/ngvm/ngvm_manager.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 <memory>
#include "ngraph/runtime/ngvm/external_function.hpp"
#include "ngraph/runtime/ngvm/ngvm_backend.hpp"
#include "ngraph/runtime/ngvm/ngvm_manager.hpp"
using
namespace
ngraph
::
runtime
::
ngvm
;
std
::
shared_ptr
<
ngraph
::
runtime
::
Backend
>
NGVMManager
::
allocate_backend
()
{
return
std
::
make_shared
<
NGVMBackend
>
();
}
std
::
shared_ptr
<
ngraph
::
runtime
::
ExternalFunction
>
NGVMManager
::
compile
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
fun
)
{
return
std
::
make_shared
<
ExternalFunction
>
(
fun
);
}
ngraph
::
runtime
::
Manager
::
Factory
NGVMManager
::
factory
=
ngraph
::
runtime
::
Manager
::
register_factory
(
"NGVM"
,
[](
const
std
::
string
&
name
)
->
std
::
shared_ptr
<
ngraph
::
runtime
::
Manager
>
{
return
std
::
make_shared
<
NGVMManager
>
();
});
src/ngraph/runtime/
instruction
.hpp
→
src/ngraph/runtime/
ngvm/ngvm_manager
.hpp
View file @
ebac7d27
...
@@ -16,24 +16,29 @@
...
@@ -16,24 +16,29 @@
#include <memory>
#include <memory>
#include "ngraph/runtime/
call_frame
.hpp"
#include "ngraph/runtime/
manager
.hpp"
namespace
ngraph
namespace
ngraph
{
{
class
Function
;
namespace
runtime
namespace
runtime
{
{
class
CallFrame
;
class
ExternalFunction
;
/// @brief An interpreter for an Op
namespace
ngvm
///
/// The call_frame has a vector of instructions and calls execute on each instruction, passing it the call_frame.
/// Instructions get argument, result, and intermediate tensor views from the call frame. Instructions may also
/// set a flag in the call_frame to end execution, or adjust execution by modifying the position in the instruction vector.
class
Instruction
{
{
public
:
/// @brief Transformer for the interpreted backend
virtual
~
Instruction
()
{}
class
NGVMManager
:
public
Manager
virtual
void
execute
(
CallFrame
&
call_frame
)
const
=
0
;
{
public
:
virtual
std
::
shared_ptr
<
Backend
>
allocate_backend
()
override
;
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
ExternalFunction
>
compile
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
fun
)
override
;
static
Factory
factory
;
};
};
};
}
}
}
}
src/ngraph/runtime/parameterized_tensor_view.hpp
View file @
ebac7d27
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#pragma once
#pragma once
#include <cstring>
#include <memory>
#include <memory>
#include <vector>
#include <vector>
...
@@ -61,6 +62,48 @@ namespace ngraph
...
@@ -61,6 +62,48 @@ namespace ngraph
// For getting the data out
// For getting the data out
storage_type
&
get_vector
()
{
return
m_vector
;
}
storage_type
&
get_vector
()
{
return
m_vector
;
}
virtual
void
write
(
const
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
override
{
size_t
elt_offset
=
tensor_offset
/
sizeof
(
typename
ET
::
type
);
if
(
elt_offset
*
sizeof
(
typename
ET
::
type
)
!=
tensor_offset
)
{
throw
ngraph_error
(
"Attempt to write to an address not aligned on an element"
);
}
size_t
elt_n
=
n
/
sizeof
(
typename
ET
::
type
);
if
(
elt_n
*
sizeof
(
typename
ET
::
type
)
!=
n
)
{
throw
ngraph_error
(
"Attemmpt to write a partial element"
);
}
size_t
elt_byte_size
=
sizeof
(
typename
ET
::
type
)
*
n
;
if
(
tensor_offset
+
n
>
elt_byte_size
)
{
throw
ngraph_error
(
"Attempt to write beyond the tensor"
);
}
std
::
memcpy
(
&
m_vector
[
elt_offset
],
p
,
n
);
}
virtual
void
read
(
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
const
override
{
size_t
elt_offset
=
tensor_offset
/
sizeof
(
typename
ET
::
type
);
if
(
elt_offset
*
sizeof
(
typename
ET
::
type
)
!=
tensor_offset
)
{
throw
ngraph_error
(
"Attempt to read from an address not aligned on an element"
);
}
size_t
elt_n
=
n
/
sizeof
(
typename
ET
::
type
);
if
(
elt_n
*
sizeof
(
typename
ET
::
type
)
!=
n
)
{
throw
ngraph_error
(
"Attemmpt to read a partial element"
);
}
size_t
elt_byte_size
=
sizeof
(
typename
ET
::
type
)
*
n
;
if
(
tensor_offset
+
n
>
elt_byte_size
)
{
throw
ngraph_error
(
"Attempt to read beyond the tensor"
);
}
std
::
memcpy
(
p
,
&
m_vector
[
elt_offset
],
n
);
}
protected
:
protected
:
storage_type
m_vector
;
storage_type
m_vector
;
};
};
...
...
src/ngraph/runtime/tensor_view.cpp
0 → 100644
View file @
ebac7d27
// ----------------------------------------------------------------------------
// 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 "ngraph/runtime/tensor_view.hpp"
#include "ngraph/common.hpp"
#include "ngraph/types/element_type.hpp"
using
namespace
ngraph
::
runtime
;
std
::
shared_ptr
<
const
ngraph
::
descriptor
::
TensorView
>
TensorView
::
get_tensor_view_descriptor
()
const
{
return
m_descriptor
;
}
std
::
shared_ptr
<
ngraph
::
descriptor
::
Value
>
TensorView
::
get_descriptor
()
const
{
return
m_descriptor
;
}
void
TensorView
::
collect_tensor_views
(
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
views
,
const
std
::
shared_ptr
<
Value
>&
value
)
const
{
views
.
push_back
(
std
::
static_pointer_cast
<
TensorView
>
(
value
));
}
const
ngraph
::
Shape
&
TensorView
::
get_shape
()
const
{
return
m_descriptor
->
get_tensor_view_type
()
->
get_shape
();
}
src/ngraph/runtime/tensor_view.hpp
View file @
ebac7d27
...
@@ -20,10 +20,14 @@
...
@@ -20,10 +20,14 @@
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/runtime/value.hpp"
#include "ngraph/runtime/value.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/types/element_type.hpp"
namespace
ngraph
namespace
ngraph
{
{
namespace
descriptor
{
class
Value
;
}
namespace
runtime
namespace
runtime
{
{
template
<
typename
ET
>
template
<
typename
ET
>
...
@@ -46,23 +50,28 @@ namespace ngraph
...
@@ -46,23 +50,28 @@ namespace ngraph
return
dynamic_cast
<
ParameterizedTensorView
<
ET
>*>
(
this
);
return
dynamic_cast
<
ParameterizedTensorView
<
ET
>*>
(
this
);
}
}
std
::
shared_ptr
<
const
ngraph
::
descriptor
::
TensorView
>
get_tensor_view_descriptor
()
const
std
::
shared_ptr
<
const
ngraph
::
descriptor
::
TensorView
>
{
get_tensor_view_descriptor
()
const
;
return
m_descriptor
;
}
virtual
std
::
shared_ptr
<
ngraph
::
descriptor
::
Value
>
get_descriptor
()
const
override
virtual
std
::
shared_ptr
<
ngraph
::
descriptor
::
Value
>
get_descriptor
()
const
override
;
{
return
m_descriptor
;
}
virtual
void
collect_tensor_views
(
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
views
,
virtual
void
collect_tensor_views
(
std
::
vector
<
std
::
shared_ptr
<
TensorView
>>&
views
,
const
std
::
shared_ptr
<
Value
>&
value
)
const
override
const
std
::
shared_ptr
<
Value
>&
value
)
const
override
;
{
views
.
push_back
(
std
::
static_pointer_cast
<
TensorView
>
(
value
));
const
ngraph
::
Shape
&
get_shape
()
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.
virtual
void
write
(
const
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
=
0
;
/// @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.
virtual
void
read
(
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
const
=
0
;
const
Shape
&
get_shape
()
{
return
m_descriptor
->
get_tensor_view_type
()
->
get_shape
();
}
protected
:
protected
:
std
::
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>
m_descriptor
;
std
::
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>
m_descriptor
;
};
};
...
...
src/ngraph/runtime/value.hpp
View file @
ebac7d27
...
@@ -21,6 +21,11 @@
...
@@ -21,6 +21,11 @@
namespace
ngraph
namespace
ngraph
{
{
namespace
descriptor
{
class
Value
;
}
namespace
runtime
namespace
runtime
{
{
class
TensorView
;
class
TensorView
;
...
...
src/ngraph/types/element_type.cpp
View file @
ebac7d27
...
@@ -21,8 +21,6 @@
...
@@ -21,8 +21,6 @@
using
namespace
ngraph
;
using
namespace
ngraph
;
std
::
map
<
std
::
string
,
ngraph
::
element
::
Type
>
ngraph
::
element
::
Type
::
m_element_list
;
ngraph
::
element
::
Type
::
Type
(
size_t
bitwidth
,
ngraph
::
element
::
Type
::
Type
(
size_t
bitwidth
,
bool
is_float
,
bool
is_float
,
bool
is_signed
,
bool
is_signed
,
...
...
src/ngraph/types/element_type.hpp
View file @
ebac7d27
...
@@ -19,10 +19,14 @@
...
@@ -19,10 +19,14 @@
#pragma once
#pragma once
#include <map>
#include <map>
#include <memory>
#include <string>
#include <string>
#include <type_traits>
#include <type_traits>
#include "ngraph/common.hpp"
#include "ngraph/except.hpp"
#include "ngraph/except.hpp"
#include "ngraph/runtime/parameterized_tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
namespace
ngraph
{
{
...
@@ -34,6 +38,7 @@ namespace ngraph
...
@@ -34,6 +38,7 @@ namespace ngraph
Type
&
operator
=
(
const
Type
&
)
=
delete
;
Type
&
operator
=
(
const
Type
&
)
=
delete
;
public
:
public
:
virtual
~
Type
()
{}
Type
(
size_t
bitwidth
,
bool
is_float
,
bool
is_signed
,
const
std
::
string
&
cname
);
Type
(
size_t
bitwidth
,
bool
is_float
,
bool
is_signed
,
const
std
::
string
&
cname
);
const
std
::
string
&
c_type_string
()
const
;
const
std
::
string
&
c_type_string
()
const
;
...
@@ -44,6 +49,9 @@ namespace ngraph
...
@@ -44,6 +49,9 @@ namespace ngraph
return
h
(
m_cname
);
return
h
(
m_cname
);
}
}
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>
make_primary_tensor_view
(
const
Shape
&
shape
)
const
=
0
;
bool
operator
==
(
const
Type
&
other
)
const
;
bool
operator
==
(
const
Type
&
other
)
const
;
bool
operator
!=
(
const
Type
&
other
)
const
{
return
!
(
*
this
==
other
);
}
bool
operator
!=
(
const
Type
&
other
)
const
{
return
!
(
*
this
==
other
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Type
&
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Type
&
);
...
@@ -102,6 +110,12 @@ namespace ngraph
...
@@ -102,6 +110,12 @@ namespace ngraph
static
TraitedType
<
T
>
t
;
static
TraitedType
<
T
>
t
;
return
t
;
return
t
;
}
}
virtual
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>
make_primary_tensor_view
(
const
ngraph
::
Shape
&
shape
)
const
override
{
return
std
::
make_shared
<
runtime
::
ParameterizedTensorView
<
TraitedType
<
T
>>>
(
shape
);
}
};
};
NGRAPH_DEFINE_TRAITED_TYPE_NAME
(
char
)
NGRAPH_DEFINE_TRAITED_TYPE_NAME
(
char
)
...
...
test/execute.cpp
View file @
ebac7d27
This diff is collapsed.
Click to expand it.
test/tensor.cpp
View file @
ebac7d27
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <
memory
>
#include <
algorithm
>
#include <memory>
#include <memory>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
...
@@ -83,3 +83,37 @@ TEST(tensor, size)
...
@@ -83,3 +83,37 @@ TEST(tensor, size)
EXPECT_EQ
(
1
*
4
,
output
.
size
());
EXPECT_EQ
(
1
*
4
,
output
.
size
());
}
}
}
}
template
<
typename
ET
>
void
test_read_write
(
const
std
::
vector
<
typename
ET
::
type
>&
x
)
{
using
T
=
typename
ET
::
type
;
auto
manager
=
ngraph
::
runtime
::
Manager
::
get
(
"NGVM"
);
auto
backend
=
manager
->
allocate_backend
();
auto
a
=
backend
->
make_primary_tensor_view
(
ET
::
element_type
(),
Shape
{
2
,
x
.
size
()});
auto
af
=
a
->
template
get_parameterized_tensor_view
<
ET
>
();
std
::
vector
<
T
>
result
(
2
*
x
.
size
());
a
->
write
(
&
x
[
0
],
0
,
x
.
size
()
*
sizeof
(
T
));
std
::
copy
(
x
.
begin
(),
x
.
end
(),
result
.
begin
());
a
->
write
(
&
x
[
0
],
x
.
size
()
*
sizeof
(
T
),
x
.
size
()
*
sizeof
(
T
));
std
::
copy
(
x
.
begin
(),
x
.
end
(),
result
.
begin
()
+
x
.
size
());
auto
&
af_vector
=
af
->
get_vector
();
ASSERT_EQ
(
af_vector
,
result
);
std
::
vector
<
T
>
result1
(
x
.
size
());
std
::
vector
<
T
>
result2
(
x
.
size
());
std
::
copy
(
result
.
begin
()
+
1
,
result
.
begin
()
+
1
+
x
.
size
(),
result1
.
begin
());
a
->
read
(
&
result2
[
0
],
sizeof
(
T
),
sizeof
(
T
)
*
x
.
size
());
ASSERT_EQ
(
result1
,
result2
);
}
TEST
(
tensor
,
read_write
)
{
test_read_write
<
element
::
Float32
>
({
1.0
,
3.0
,
5.0
});
test_read_write
<
element
::
Int64
>
({
-
1
,
2
,
4
});
}
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