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
da8d8a2b
Commit
da8d8a2b
authored
Sep 22, 2017
by
Scott Cyphers
Committed by
GitHub
Sep 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove eigen dependencies. (#140)
parent
3691c577
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
268 additions
and
238 deletions
+268
-238
clang_4_0_flags.cmake
cmake/clang_4_0_flags.cmake
+1
-0
CMakeLists.txt
src/ngraph/CMakeLists.txt
+1
-2
ngraph.hpp
src/ngraph/ngraph.hpp
+2
-7
constant.hpp
src/ngraph/ops/constant.hpp
+4
-4
call_frame.cpp
src/ngraph/runtime/call_frame.cpp
+7
-6
call_frame.hpp
src/ngraph/runtime/call_frame.hpp
+14
-6
add.hpp
src/ngraph/runtime/eigen/add.hpp
+17
-7
multiply.hpp
src/ngraph/runtime/eigen/multiply.hpp
+18
-6
tensor_view.hpp
src/ngraph/runtime/eigen/tensor_view.hpp
+0
-101
utils.hpp
src/ngraph/runtime/eigen/utils.hpp
+61
-0
external_function.cpp
src/ngraph/runtime/external_function.cpp
+5
-4
external_function.hpp
src/ngraph/runtime/external_function.hpp
+32
-35
tensor_view.hpp
src/ngraph/runtime/tensor_view.hpp
+55
-4
utils.hpp
src/ngraph/runtime/utils.hpp
+15
-19
execute.cpp
test/execute.cpp
+8
-8
runtime.cpp
test/runtime.cpp
+28
-28
shape.cpp
test/shape.cpp
+0
-1
No files found.
cmake/clang_4_0_flags.cmake
View file @
da8d8a2b
...
...
@@ -47,3 +47,4 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables") # Not ready for this
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++11-compat-deprecated-writable-strings")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-double-promotion"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-undefined-func-template"
)
src/ngraph/CMakeLists.txt
View file @
da8d8a2b
...
...
@@ -32,8 +32,7 @@ set (SRC
pass/tree_pass.cpp
pass/visualize_tree.cpp
runtime/call_frame.cpp
runtime/eigen/external_function.cpp
runtime/eigen/tensor_view.cpp
runtime/external_function.cpp
shape.cpp
visualize.cpp
ops/binary_elementwise_arithmetic.cpp
...
...
src/ngraph/ngraph.hpp
View file @
da8d8a2b
...
...
@@ -26,7 +26,6 @@
#include "ngraph/descriptor/tensor.hpp"
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/descriptor/tensor_view_layout.hpp"
#include "ngraph/types/element_type.hpp"
#include "ngraph/except.hpp"
#include "ngraph/function.hpp"
#include "ngraph/node.hpp"
...
...
@@ -55,14 +54,10 @@
#include "ngraph/ops/remainder.hpp"
#include "ngraph/ops/subtract.hpp"
#include "ngraph/ops/tuple.hpp"
#include "ngraph/runtime/eigen/add.hpp"
#include "ngraph/runtime/eigen/external_function.hpp"
#include "ngraph/runtime/eigen/multiply.hpp"
#include "ngraph/runtime/eigen/return.hpp"
#include "ngraph/runtime/eigen/tensor_view.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/function.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/types/element_type.hpp"
#include "ngraph/types/type.hpp"
src/ngraph/ops/constant.hpp
View file @
da8d8a2b
...
...
@@ -17,7 +17,7 @@
#include <sstream>
#include "ngraph/types/element_type.hpp"
#include "ngraph/runtime/
eigen/tensor_view
.hpp"
#include "ngraph/runtime/
utils
.hpp"
namespace
ngraph
{
...
...
@@ -101,7 +101,7 @@ namespace ngraph
TensorConstant
(
const
Shape
&
shape
)
:
TensorConstantBase
(
std
::
make_shared
<
TensorViewType
>
(
T
::
element_type
(),
shape
))
,
m_value
(
std
::
make_shared
<
ngraph
::
runtime
::
eigen
::
PrimaryTensorView
<
T
>
>
(
shape
))
,
m_value
(
ngraph
::
runtime
::
make_tensor
<
T
>
(
shape
))
{
}
...
...
@@ -113,10 +113,10 @@ namespace ngraph
return
ss
.
str
();
}
typename
std
::
shared_ptr
<
ngraph
::
runtime
::
eigen
::
Primary
TensorView
<
T
>>
get_value
()
const
{
return
m_value
;
}
typename
std
::
shared_ptr
<
ngraph
::
runtime
::
Parameterized
TensorView
<
T
>>
get_value
()
const
{
return
m_value
;
}
protected
:
std
::
shared_ptr
<
ngraph
::
runtime
::
eigen
::
Primary
TensorView
<
T
>>
m_value
;
std
::
shared_ptr
<
ngraph
::
runtime
::
Parameterized
TensorView
<
T
>>
m_value
;
};
using
Float32TensorConstant
=
TensorConstant
<
element
::
Float32
>
;
...
...
src/ngraph/runtime/call_frame.cpp
View file @
da8d8a2b
...
...
@@ -20,11 +20,11 @@ using namespace std;
using
namespace
ngraph
;
using
namespace
ngraph
::
runtime
;
CallFrame
::
CallFrame
(
size_t
n_inputs
,
size_t
n_outputs
,
const
PTVs
&
temps
,
size_t
initial_pc
,
const
shared_ptr
<
vector
<
shared_ptr
<
Instruction
>>>&
instructions
)
CallFrame
::
CallFrame
(
size_t
n_inputs
,
size_t
n_outputs
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>&
temps
,
size_t
initial_pc
,
const
shared_ptr
<
vector
<
shared_ptr
<
Instruction
>>>&
instructions
)
:
m_n_inputs
(
n_inputs
)
,
m_n_outputs
(
n_outputs
)
...
...
@@ -35,7 +35,8 @@ CallFrame::CallFrame(size_t n_inputs
copy
(
temps
.
begin
(),
temps
.
end
(),
m_tensors
.
begin
()
+
m_n_inputs
+
m_n_outputs
);
}
void
CallFrame
::
operator
()(
const
PTVs
&
inputs
,
const
PTVs
&
outputs
)
void
CallFrame
::
operator
()(
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_tensors
.
begin
());
copy
(
outputs
.
begin
(),
outputs
.
end
(),
m_tensors
.
begin
()
+
m_n_inputs
);
...
...
src/ngraph/runtime/call_frame.hpp
View file @
da8d8a2b
...
...
@@ -17,9 +17,9 @@
#include <memory>
#include <vector>
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/function.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
...
...
@@ -34,18 +34,26 @@ namespace ngraph
CallFrame
(
size_t
n_inputs
,
size_t
n_outputs
,
const
PTVs
&
temps
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>&
temps
,
size_t
initial_pc
,
const
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>&
instructions
);
void
operator
()(
const
PTVs
&
inputs
,
const
PTVs
&
outpus
);
void
set_return
()
{
m_return
=
true
;
}
std
::
shared_ptr
<
PrimaryTensorView
>
get_tensor
(
size_t
i
)
{
return
m_tensors
[
i
];
}
void
operator
()(
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>&
inputs
,
const
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>&
outpus
);
void
set_return
()
{
m_return
=
true
;
}
std
::
shared_ptr
<
TensorView
>
get_tensor
(
size_t
i
)
{
return
m_tensors
[
i
];
}
template
<
typename
ET
>
ParameterizedTensorView
<
ET
>*
get_parameterized_tensor
(
size_t
i
)
{
return
m_tensors
[
i
]
->
get_parameterized_tensor
<
ET
>
();
}
protected
:
size_t
m_n_inputs
;
size_t
m_n_outputs
;
PTVs
m_tensors
;
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>
m_tensors
;
size_t
m_initial_pc
;
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
Instruction
>>>
m_instructions
;
size_t
m_pc
;
...
...
src/ngraph/runtime/eigen/add.hpp
View file @
da8d8a2b
...
...
@@ -15,8 +15,9 @@
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/eigen/
tensor_view
.hpp"
#include "ngraph/runtime/eigen/
utils
.hpp"
#include "ngraph/runtime/instruction.hpp"
#include "ngraph/runtime/tensor_view.hpp"
namespace
ngraph
{
...
...
@@ -24,6 +25,18 @@ namespace ngraph
{
namespace
eigen
{
template
<
typename
T
>
void
add
(
T
*
arg0
,
T
*
arg1
,
T
*
out
)
{
set_map
(
out
,
get_map
(
arg0
)
+
get_map
(
arg1
));
}
template
<
typename
T
>
void
add
(
std
::
shared_ptr
<
T
>&
arg0
,
std
::
shared_ptr
<
T
>&
arg1
,
std
::
shared_ptr
<
T
>&
out
)
{
add
(
&*
arg0
,
&*
arg1
,
&*
out
);
}
template
<
typename
ET
>
class
AddInstruction
:
public
Instruction
{
...
...
@@ -37,12 +50,9 @@ namespace ngraph
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
dynamic_cast
<
PrimaryTensorView
<
ET
>*>
(
&*
call_frame
.
get_tensor
(
m_out
))
->
get_map
()
=
dynamic_cast
<
PrimaryTensorView
<
ET
>*>
(
&*
call_frame
.
get_tensor
(
m_arg0
))
->
get_map
()
+
dynamic_cast
<
PrimaryTensorView
<
ET
>*>
(
&*
call_frame
.
get_tensor
(
m_arg1
))
->
get_map
();
add
(
call_frame
.
get_parameterized_tensor
<
ET
>
(
m_arg0
),
call_frame
.
get_parameterized_tensor
<
ET
>
(
m_arg1
),
call_frame
.
get_parameterized_tensor
<
ET
>
(
m_out
));
}
protected
:
...
...
src/ngraph/runtime/eigen/multiply.hpp
View file @
da8d8a2b
...
...
@@ -15,6 +15,7 @@
#pragma once
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/eigen/utils.hpp"
#include "ngraph/runtime/instruction.hpp"
namespace
ngraph
...
...
@@ -23,6 +24,20 @@ namespace ngraph
{
namespace
eigen
{
template
<
typename
T
>
void
multiply
(
T
*
arg0
,
T
*
arg1
,
T
*
out
)
{
set_map
(
out
,
get_map
(
arg0
)
*
get_map
(
arg1
));
}
template
<
typename
T
>
void
multiply
(
std
::
shared_ptr
<
T
>&
arg0
,
std
::
shared_ptr
<
T
>&
arg1
,
std
::
shared_ptr
<
T
>&
out
)
{
multiply
(
&*
arg0
,
&*
arg1
,
&*
out
);
}
template
<
typename
ET
>
class
MultiplyInstruction
:
public
Instruction
{
...
...
@@ -36,12 +51,9 @@ namespace ngraph
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
dynamic_cast
<
PrimaryTensorView
<
ET
>*>
(
&*
call_frame
.
get_tensor
(
m_out
))
->
get_map
()
=
dynamic_cast
<
PrimaryTensorView
<
ET
>*>
(
&*
call_frame
.
get_tensor
(
m_arg0
))
->
get_map
()
*
dynamic_cast
<
PrimaryTensorView
<
ET
>*>
(
&*
call_frame
.
get_tensor
(
m_arg1
))
->
get_map
();
multiply
(
call_frame
.
get_parameterized_tensor
<
ET
>
(
m_arg0
),
call_frame
.
get_parameterized_tensor
<
ET
>
(
m_arg1
),
call_frame
.
get_parameterized_tensor
<
ET
>
(
m_out
));
}
protected
:
...
...
src/ngraph/runtime/eigen/tensor_view.hpp
deleted
100644 → 0
View file @
3691c577
// ----------------------------------------------------------------------------
// 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 <vector>
#include "Eigen/Dense"
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/shape.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
eigen
{
std
::
shared_ptr
<
ngraph
::
runtime
::
PrimaryTensorView
>
make_tensor_view
(
std
::
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>
);
template
<
typename
ET
>
class
PrimaryTensorView
:
public
ngraph
::
runtime
::
PrimaryTensorView
{
public
:
// Standard definitions from vector
using
value_type
=
typename
ET
::
type
;
using
storage_type
=
std
::
vector
<
value_type
>
;
using
size_type
=
typename
storage_type
::
size_type
;
using
difference_type
=
typename
storage_type
::
difference_type
;
using
reference
=
typename
storage_type
::
reference
;
using
const_reference
=
typename
storage_type
::
const_reference
;
using
pointer
=
typename
storage_type
::
pointer
;
using
const_pointer
=
typename
storage_type
::
const_pointer
;
using
iterator
=
typename
storage_type
::
iterator
;
using
const_iterator
=
typename
storage_type
::
const_iterator
;
using
reverse_iterator
=
typename
storage_type
::
reverse_iterator
;
using
const_reverse_iterator
=
typename
storage_type
::
const_reverse_iterator
;
// Mapping vector to eigen
using
eigen_type
=
Eigen
::
Array
<
value_type
,
Eigen
::
Dynamic
,
1
>
;
using
eigen_map
=
Eigen
::
Map
<
eigen_type
>
;
PrimaryTensorView
(
const
ngraph
::
Shape
&
shape
)
:
m_shape
(
shape
)
,
m_size
(
ngraph
::
shape_size
(
shape
))
,
m_strides
(
ngraph
::
row_major_strides
(
m_shape
))
,
m_vector
(
m_size
,
0
)
,
m_map
(
&
m_vector
[
0
],
m_size
,
1
)
{
}
template
<
typename
T
>
PrimaryTensorView
&
operator
=
(
const
T
&
value
)
{
m_vector
=
value
;
return
*
this
;
}
// For getting the data out
const
storage_type
&
get_vector
()
{
return
m_vector
;
}
eigen_map
&
get_map
()
{
return
m_map
;
}
const
eigen_map
&
get_map
()
const
{
return
m_map
;
}
const
Shape
&
get_shape
()
const
{
return
m_shape
;
}
protected
:
ngraph
::
Shape
m_shape
;
size_t
m_size
;
ngraph
::
Strides
m_strides
;
storage_type
m_vector
;
eigen_map
m_map
;
};
template
<
typename
ET
>
void
add
(
const
PrimaryTensorView
<
ET
>&
arg0
,
const
PrimaryTensorView
<
ET
>&
arg1
,
PrimaryTensorView
<
ET
>&
out
)
{
out
.
get_map
()
=
arg0
.
get_map
()
+
arg1
.
get_map
();
}
template
<
typename
ET
>
void
multiply
(
const
PrimaryTensorView
<
ET
>&
arg0
,
const
PrimaryTensorView
<
ET
>&
arg1
,
PrimaryTensorView
<
ET
>&
out
)
{
out
.
get_map
()
=
arg0
.
get_map
()
*
arg1
.
get_map
();
}
}
}
}
src/ngraph/runtime/eigen/utils.hpp
0 → 100644
View file @
da8d8a2b
// ----------------------------------------------------------------------------
// 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>
namespace
ngraph
{
namespace
runtime
{
namespace
eigen
{
template
<
typename
T
,
typename
U
>
void
set_map
(
std
::
shared_ptr
<
T
>&
t
,
const
U
&
u
)
{
auto
&
v
=
t
->
get_vector
();
Eigen
::
Map
<
Eigen
::
Array
<
typename
T
::
value_type
,
Eigen
::
Dynamic
,
1
>>
(
&
v
[
0
],
v
.
size
(),
1
)
=
u
;
}
template
<
typename
T
,
typename
U
>
void
set_map
(
T
*
t
,
const
U
&
u
)
{
auto
&
v
=
t
->
get_vector
();
Eigen
::
Map
<
Eigen
::
Array
<
typename
T
::
value_type
,
Eigen
::
Dynamic
,
1
>>
(
&
v
[
0
],
v
.
size
(),
1
)
=
u
;
}
template
<
typename
T
>
Eigen
::
Map
<
Eigen
::
Array
<
typename
T
::
value_type
,
Eigen
::
Dynamic
,
1
>>
get_map
(
std
::
shared_ptr
<
T
>&
arg
)
{
auto
&
v
=
arg
->
get_vector
();
return
Eigen
::
Map
<
Eigen
::
Array
<
typename
T
::
value_type
,
Eigen
::
Dynamic
,
1
>>
(
&
v
[
0
],
v
.
size
(),
1
);
}
template
<
typename
T
>
Eigen
::
Map
<
Eigen
::
Array
<
typename
T
::
value_type
,
Eigen
::
Dynamic
,
1
>>
get_map
(
T
*
arg
)
{
auto
&
v
=
arg
->
get_vector
();
return
Eigen
::
Map
<
Eigen
::
Array
<
typename
T
::
value_type
,
Eigen
::
Dynamic
,
1
>>
(
&
v
[
0
],
v
.
size
(),
1
);
}
}
}
}
src/ngraph/runtime/e
igen/e
xternal_function.cpp
→
src/ngraph/runtime/external_function.cpp
View file @
da8d8a2b
...
...
@@ -26,12 +26,13 @@
#include "ngraph/ops/multiply.hpp"
#include "ngraph/pass/topological_sort.hpp"
#include "ngraph/runtime/eigen/add.hpp"
#include "ngraph/runtime/e
igen/e
xternal_function.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/eigen/multiply.hpp"
#include "ngraph/runtime/eigen/return.hpp"
#include "ngraph/runtime/utils.hpp"
using
namespace
std
;
using
namespace
ngraph
::
runtime
::
eigen
;
using
namespace
ngraph
::
runtime
;
ExternalFunction
::
ExternalFunction
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
function
,
bool
release_function
)
...
...
@@ -186,10 +187,10 @@ shared_ptr<ngraph::runtime::CallFrame> ExternalFunction::make_call_frame()
{
compile
();
}
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Primary
TensorView
>>
temps
;
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
TensorView
>>
temps
;
for
(
auto
tv
:
m_temp_views
)
{
temps
.
push_back
(
ngraph
::
runtime
::
eigen
::
make_tensor_view
(
tv
));
temps
.
push_back
(
ngraph
::
runtime
::
make_tensor
<
ngraph
::
element
::
Float32
>
(
tv
->
get_tensor_view_type
()
->
get_shape
()
));
}
return
make_shared
<
ngraph
::
runtime
::
CallFrame
>
(
m_n_inputs
,
m_n_outputs
,
temps
,
0
,
m_instructions
);
...
...
src/ngraph/runtime/e
igen/e
xternal_function.hpp
→
src/ngraph/runtime/external_function.hpp
View file @
da8d8a2b
...
...
@@ -25,42 +25,39 @@ namespace ngraph
{
namespace
runtime
{
namespace
eige
n
class
ExternalFunctio
n
{
class
ExternalFunction
public
:
ExternalFunction
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
function
,
bool
release_function
=
true
);
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
();
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Instruction
>>>
get_instructions
()
{
public
:
ExternalFunction
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
function
,
bool
release_function
=
true
);
std
::
shared_ptr
<
ngraph
::
runtime
::
CallFrame
>
make_call_frame
();
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
Instruction
>>>
get_instructions
()
{
return
m_instructions
;
}
// Release original function's resources
void
release_function
()
{
m_function
=
nullptr
;
}
protected
:
void
compile
();
std
::
shared_ptr
<
ngraph
::
Function
>
m_function
;
bool
m_release_function
;
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
;
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>>
m_temp_views
;
static
std
::
unordered_map
<
std
::
type_index
,
std
::
function
<
void
(
ngraph
::
Node
*
,
ExternalFunction
*
,
const
std
::
vector
<
size_t
>&
inputs
,
const
std
::
vector
<
size_t
>&
outputs
)
>>&
get_op_map
();
};
}
return
m_instructions
;
}
// Release original function's resources
void
release_function
()
{
m_function
=
nullptr
;
}
protected
:
void
compile
();
std
::
shared_ptr
<
ngraph
::
Function
>
m_function
;
bool
m_release_function
;
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
;
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>>
m_temp_views
;
static
std
::
unordered_map
<
std
::
type_index
,
std
::
function
<
void
(
ngraph
::
Node
*
,
ExternalFunction
*
,
const
std
::
vector
<
size_t
>&
inputs
,
const
std
::
vector
<
size_t
>&
outputs
)
>>&
get_op_map
();
};
}
}
src/ngraph/runtime/tensor_view.hpp
View file @
da8d8a2b
...
...
@@ -14,17 +14,68 @@
#pragma once
#include <memory>
#include <vector>
#include "ngraph/shape.hpp"
#include "ngraph/types/element_type.hpp"
namespace
ngraph
{
namespace
runtime
{
// Actual tensor views are parameterized on element type
class
PrimaryTensorView
template
<
typename
ET
>
class
ParameterizedTensorView
;
class
TensorView
{
public
:
virtual
~
PrimaryTensorView
()
{}
virtual
~
TensorView
()
{}
template
<
typename
ET
>
ParameterizedTensorView
<
ET
>*
get_parameterized_tensor
()
{
return
dynamic_cast
<
ParameterizedTensorView
<
ET
>*>
(
this
);
}
};
using
PTVs
=
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
PrimaryTensorView
>>
;
template
<
typename
ET
>
class
ParameterizedTensorView
:
public
ngraph
::
runtime
::
TensorView
{
public
:
ParameterizedTensorView
(
const
ngraph
::
Shape
&
shape
)
:
m_vector
(
ngraph
::
shape_size
(
shape
),
0
)
{
}
virtual
~
ParameterizedTensorView
()
{}
// Standard definitions from vector
using
element_type
=
ET
;
using
value_type
=
typename
ET
::
type
;
using
storage_type
=
std
::
vector
<
value_type
>
;
using
size_type
=
typename
storage_type
::
size_type
;
using
difference_type
=
typename
storage_type
::
difference_type
;
using
reference
=
typename
storage_type
::
reference
;
using
const_reference
=
typename
storage_type
::
const_reference
;
using
pointer
=
typename
storage_type
::
pointer
;
using
const_pointer
=
typename
storage_type
::
const_pointer
;
using
iterator
=
typename
storage_type
::
iterator
;
using
const_iterator
=
typename
storage_type
::
const_iterator
;
using
reverse_iterator
=
typename
storage_type
::
reverse_iterator
;
using
const_reverse_iterator
=
typename
storage_type
::
const_reverse_iterator
;
template
<
typename
T
>
ParameterizedTensorView
<
ET
>&
operator
=
(
const
std
::
vector
<
T
>&
value
)
{
get_vector
()
=
value
;
return
*
this
;
}
// For getting the data out
storage_type
&
get_vector
()
{
return
m_vector
;
}
protected
:
storage_type
m_vector
;
};
}
}
src/ngraph/runtime/
eigen/tensor_view.c
pp
→
src/ngraph/runtime/
utils.h
pp
View file @
da8d8a2b
...
...
@@ -12,27 +12,23 @@
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include <memory>
#include "Eigen/Dense"
#include "ngraph/ngraph.hpp"
#pragma once
using
namespace
Eigen
;
using
namespace
ngraph
::
runtime
::
eigen
;
using
namespace
ngraph
::
element
;
template
void
ngraph
::
runtime
::
eigen
::
add
<
Float32
>
(
const
PrimaryTensorView
<
Float32
>&
arg0
,
const
PrimaryTensorView
<
Float32
>&
arg1
,
PrimaryTensorView
<
Float32
>&
out
);
#include <memory>
template
void
ngraph
::
runtime
::
eigen
::
multiply
<
Float32
>
(
const
PrimaryTensorView
<
Float32
>&
arg0
,
const
PrimaryTensorView
<
Float32
>&
arg1
,
PrimaryTensorView
<
Float32
>&
out
);
#include "ngraph/runtime/call_frame.hpp"
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/types/element_type.hpp"
std
::
shared_ptr
<
ngraph
::
runtime
::
PrimaryTensorView
>
ngraph
::
runtime
::
eigen
::
make_tensor_view
(
std
::
shared_ptr
<
ngraph
::
descriptor
::
TensorView
>
tensor_view
)
namespace
ngraph
{
// For now, we only support Float32 primary tensor views
return
std
::
make_shared
<
PrimaryTensorView
<
Float32
>>
(
tensor_view
->
get_tensor_view_type
()
->
get_shape
());
namespace
runtime
{
template
<
typename
ET
>
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
ET
>>
make_tensor
(
const
Shape
&
shape
)
{
return
std
::
make_shared
<
runtime
::
ParameterizedTensorView
<
ET
>>
(
shape
);
}
}
}
test/execute.cpp
View file @
da8d8a2b
...
...
@@ -27,24 +27,24 @@ TEST(execute, test_abc)
auto
C
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
((
A
+
B
)
*
C
,
op
::
Parameters
{
A
,
B
,
C
});
auto
external
=
make_shared
<
ngraph
::
runtime
::
eigen
::
ExternalFunction
>
(
f
);
auto
external
=
make_shared
<
ngraph
::
runtime
::
ExternalFunction
>
(
f
);
auto
cf
=
external
->
make_call_frame
();
// Create some tensors for input/output
auto
a
=
make_shared
<
runtime
::
eigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
shape
);
auto
a
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
*
a
=
vector
<
float
>
{
1
,
2
,
3
,
4
};
auto
b
=
make_shared
<
runtime
::
eigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
shape
);
auto
b
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
*
b
=
vector
<
float
>
{
5
,
6
,
7
,
8
};
auto
c
=
make_shared
<
runtime
::
eigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
shape
);
auto
c
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
*
c
=
vector
<
float
>
{
9
,
10
,
11
,
12
};
auto
result
=
make_shared
<
runtime
::
eigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
shape
);
auto
result
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
(
*
cf
)(
runtime
::
PTVs
{
a
,
b
,
c
},
runtime
::
PTVs
{
result
});
(
*
cf
)(
{
a
,
b
,
c
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
54
,
80
,
110
,
144
}),
result
->
get_vector
());
(
*
cf
)(
runtime
::
PTVs
{
b
,
a
,
c
},
runtime
::
PTVs
{
result
});
(
*
cf
)(
{
b
,
a
,
c
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
54
,
80
,
110
,
144
}),
result
->
get_vector
());
(
*
cf
)(
runtime
::
PTVs
{
a
,
c
,
b
},
runtime
::
PTVs
{
result
});
(
*
cf
)(
{
a
,
c
,
b
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
50
,
72
,
98
,
128
}),
result
->
get_vector
());
}
test/runtime.cpp
View file @
da8d8a2b
...
...
@@ -19,6 +19,10 @@
#include "ngraph/ngraph.hpp"
#include "ngraph/runtime/eigen/add.hpp"
#include "ngraph/runtime/eigen/multiply.hpp"
#include "ngraph/runtime/eigen/return.hpp"
using
namespace
std
;
using
namespace
ngraph
;
using
namespace
ngraph
::
runtime
;
...
...
@@ -26,24 +30,24 @@ namespace ngeigen = ngraph::runtime::eigen;
TEST
(
runtime
,
test_add
)
{
auto
x
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
*
x
=
std
::
vector
<
float
>
{
1
,
2
,
3
,
4
};
auto
y
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
*
y
=
std
::
vector
<
float
>
{
5
,
6
,
7
,
8
};
auto
z
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
add
(
*
x
,
*
y
,
*
z
);
auto
x
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
x
->
get_vector
()
=
{
1
,
2
,
3
,
4
};
auto
y
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
y
->
get_vector
()
=
{
5
,
6
,
7
,
8
};
auto
z
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
ngraph
::
runtime
::
eigen
::
add
(
x
,
y
,
z
);
ASSERT_EQ
((
vector
<
float
>
{
6
,
8
,
10
,
12
}),
z
->
get_vector
());
}
TEST
(
runtime
,
test_multiply
)
{
auto
x
=
make_shared
<
op
::
Float32TensorConstant
>
(
Shape
{
2
,
2
});
*
x
->
get_value
()
=
std
::
vector
<
float
>
{
1
,
2
,
3
,
4
};
auto
y
=
make_shared
<
op
::
Float32TensorConstant
>
(
Shape
{
2
,
2
});
*
y
->
get_value
()
=
std
::
vector
<
float
>
{
5
,
6
,
7
,
8
};
auto
z
=
make_shared
<
op
::
Float32TensorConstant
>
(
Shape
{
2
,
2
});
multiply
(
*
x
->
get_value
(),
*
y
->
get_value
(),
*
z
->
get_value
()
);
ASSERT_EQ
((
vector
<
float
>
{
5
,
12
,
21
,
32
}),
z
->
get_v
alue
()
->
get_v
ector
());
auto
x
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
x
->
get_vector
()
=
{
1
,
2
,
3
,
4
};
auto
y
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
y
->
get_vector
()
=
{
5
,
6
,
7
,
8
};
auto
z
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
ngraph
::
runtime
::
eigen
::
multiply
(
x
,
y
,
z
);
ASSERT_EQ
((
vector
<
float
>
{
5
,
12
,
21
,
32
}),
z
->
get_vector
());
}
TEST
(
runtime
,
test_add_multiply
)
...
...
@@ -64,27 +68,23 @@ TEST(runtime, test_add_multiply)
instructions
->
push_back
(
make_shared
<
ngeigen
::
ReturnInstruction
>
());
runtime
::
CallFrame
cf
{
3
,
1
,
PTVs
{
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>>
(
Shape
{
2
,
2
})},
0
,
instructions
};
3
,
1
,
{
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
})},
0
,
instructions
};
// Create some tensors for input/output
auto
a
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
*
a
=
vector
<
float
>
{
1
,
2
,
3
,
4
};
auto
b
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
*
b
=
vector
<
float
>
{
5
,
6
,
7
,
8
};
auto
c
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
*
c
=
vector
<
float
>
{
9
,
10
,
11
,
12
};
auto
result
=
make_shared
<
ngeigen
::
PrimaryTensorView
<
element
::
Float32
>
>
(
Shape
{
2
,
2
});
auto
a
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
a
->
get_vector
()
=
{
1
,
2
,
3
,
4
};
auto
b
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
b
->
get_vector
()
=
{
5
,
6
,
7
,
8
};
auto
c
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
c
->
get_vector
()
=
{
9
,
10
,
11
,
12
};
auto
result
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
Shape
{
2
,
2
});
cf
(
PTVs
{
a
,
b
,
c
},
PTVs
{
result
});
cf
(
{
a
,
b
,
c
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
54
,
80
,
110
,
144
}),
result
->
get_vector
());
cf
(
PTVs
{
b
,
a
,
c
},
PTVs
{
result
});
cf
(
{
b
,
a
,
c
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
54
,
80
,
110
,
144
}),
result
->
get_vector
());
cf
(
PTVs
{
a
,
c
,
b
},
PTVs
{
result
});
cf
(
{
a
,
c
,
b
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
50
,
72
,
98
,
128
}),
result
->
get_vector
());
}
test/shape.cpp
View file @
da8d8a2b
...
...
@@ -20,7 +20,6 @@
using
namespace
std
;
using
namespace
ngraph
;
using
namespace
ngraph
::
runtime
::
eigen
;
TEST
(
shape
,
test_shape_size
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment