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
cf09e68d
Commit
cf09e68d
authored
Oct 25, 2017
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CPU: Implement support for scalar and tensor constants
via op::ParameterizedConstant
parent
9f507559
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
184 additions
and
8 deletions
+184
-8
emitter.cpp
src/ngraph/runtime/cpu/emitter.cpp
+160
-0
emitter.hpp
src/ngraph/runtime/cpu/emitter.hpp
+8
-0
external_function.cpp
src/ngraph/runtime/cpu/external_function.cpp
+9
-1
cpu.cpp
test/cpu.cpp
+7
-7
No files found.
src/ngraph/runtime/cpu/emitter.cpp
View file @
cf09e68d
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include "ngraph/node.hpp"
#include "ngraph/node.hpp"
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/ops/concatenate.hpp"
#include "ngraph/ops/concatenate.hpp"
#include "ngraph/ops/constant.hpp"
#include "ngraph/ops/get_tuple_element.hpp"
#include "ngraph/ops/get_tuple_element.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
...
@@ -551,3 +552,162 @@ void Emitter::EMITTER_DECL(EmitSubtract)
...
@@ -551,3 +552,162 @@ void Emitter::EMITTER_DECL(EmitSubtract)
EIGEN_VECTOR_FORMAT
(
inputs
[
1
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
");
\n
"
EIGEN_VECTOR_FORMAT
(
inputs
[
1
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
");
\n
"
" }
\n
"
;
" }
\n
"
;
}
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantBool
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
Bool
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Bool
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Bool
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
if
(
value
[
i
])
{
TU
+=
"true"
;
}
else
{
TU
+=
"false"
;
}
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantFloat32
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
Float32
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Float32
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Float32
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
])
+
"f"
;
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantInt8
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
Int8
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Int8
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Int8
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
]);
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantInt32
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
Int32
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Int32
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Int32
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
]);
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantInt64
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
Int64
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Int64
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
Int64
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
]);
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantUInt8
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt8
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
UInt8
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
UInt8
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
]);
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantUInt32
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt32
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
UInt32
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
UInt32
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
]);
}
TU
+=
"};
\n
}
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitParameterizedConstantUInt64
)
{
auto
value
=
dynamic_cast
<
const
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt64
>*>
(
n
)
->
get_value
()
->
get_vector
();
TU
+=
" {
\n
"
" call_frame->get_parameterized_tensor_view<"
+
element_type_names
[
TI
(
ngraph
::
element
::
UInt64
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
")->get_vector() = std::vector<"
+
element_type_names
[
TI
(
ngraph
::
element
::
UInt64
)]
+
"::type>{"
;
for
(
size_t
i
=
0
;
i
<
value
.
size
();
i
++
)
{
if
(
i
)
TU
+=
", "
;
TU
+=
to_string
(
value
[
i
]);
}
TU
+=
"};
\n
}
\n
"
;
}
src/ngraph/runtime/cpu/emitter.hpp
View file @
cf09e68d
...
@@ -63,6 +63,14 @@ namespace ngraph
...
@@ -63,6 +63,14 @@ namespace ngraph
void
EMITTER_DECL
(
EmitNotEqual
);
void
EMITTER_DECL
(
EmitNotEqual
);
void
EMITTER_DECL
(
EmitSelect
);
void
EMITTER_DECL
(
EmitSelect
);
void
EMITTER_DECL
(
EmitSubtract
);
void
EMITTER_DECL
(
EmitSubtract
);
void
EMITTER_DECL
(
EmitParameterizedConstantBool
);
void
EMITTER_DECL
(
EmitParameterizedConstantFloat32
);
void
EMITTER_DECL
(
EmitParameterizedConstantInt8
);
void
EMITTER_DECL
(
EmitParameterizedConstantInt32
);
void
EMITTER_DECL
(
EmitParameterizedConstantInt64
);
void
EMITTER_DECL
(
EmitParameterizedConstantUInt8
);
void
EMITTER_DECL
(
EmitParameterizedConstantUInt32
);
void
EMITTER_DECL
(
EmitParameterizedConstantUInt64
);
};
};
}
}
...
...
src/ngraph/runtime/cpu/external_function.cpp
View file @
cf09e68d
...
@@ -89,7 +89,15 @@ static const OpMap dispatcher{{TI(ngraph::op::Add), &Emitter::EmitAdd},
...
@@ -89,7 +89,15 @@ static const OpMap dispatcher{{TI(ngraph::op::Add), &Emitter::EmitAdd},
{
TI
(
ngraph
::
op
::
Negative
),
&
Emitter
::
EmitNegative
},
{
TI
(
ngraph
::
op
::
Negative
),
&
Emitter
::
EmitNegative
},
{
TI
(
ngraph
::
op
::
NotEqual
),
&
Emitter
::
EmitNotEqual
},
{
TI
(
ngraph
::
op
::
NotEqual
),
&
Emitter
::
EmitNotEqual
},
{
TI
(
ngraph
::
op
::
Select
),
&
Emitter
::
EmitSelect
},
{
TI
(
ngraph
::
op
::
Select
),
&
Emitter
::
EmitSelect
},
{
TI
(
ngraph
::
op
::
Subtract
),
&
Emitter
::
EmitSubtract
}
{
TI
(
ngraph
::
op
::
Subtract
),
&
Emitter
::
EmitSubtract
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
Bool
>
),
&
Emitter
::
EmitParameterizedConstantBool
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
Float32
>
),
&
Emitter
::
EmitParameterizedConstantFloat32
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
Int8
>
),
&
Emitter
::
EmitParameterizedConstantInt8
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
Int32
>
),
&
Emitter
::
EmitParameterizedConstantInt32
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
Int64
>
),
&
Emitter
::
EmitParameterizedConstantInt64
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt8
>
),
&
Emitter
::
EmitParameterizedConstantUInt8
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt32
>
),
&
Emitter
::
EmitParameterizedConstantUInt32
},
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt64
>
),
&
Emitter
::
EmitParameterizedConstantUInt64
},
};
};
...
...
test/cpu.cpp
View file @
cf09e68d
...
@@ -1022,8 +1022,7 @@ TEST(cpu, subtract)
...
@@ -1022,8 +1022,7 @@ TEST(cpu, subtract)
ASSERT_EQ
((
vector
<
float
>
{
1
,
2
,
4
,
8
}),
result
->
get_vector
());
ASSERT_EQ
((
vector
<
float
>
{
1
,
2
,
4
,
8
}),
result
->
get_vector
());
}
}
/*
TEST
(
cpu
,
scalar_constant
)
TEST(execute, scalar_constant)
{
{
auto
shape
=
Shape
{};
auto
shape
=
Shape
{};
auto
t
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
auto
t
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
...
@@ -1032,7 +1031,7 @@ TEST(execute, scalar_constant)
...
@@ -1032,7 +1031,7 @@ TEST(execute, scalar_constant)
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
A
,
rt
,
op
::
Parameters
{});
auto
f
=
make_shared
<
Function
>
(
A
,
rt
,
op
::
Parameters
{});
auto manager = runtime::Manager::get("
NGVM
");
auto
manager
=
runtime
::
Manager
::
get
(
"
CPU
"
);
auto
external
=
manager
->
compile
(
f
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
auto
cf
=
backend
->
make_call_frame
(
external
);
...
@@ -1044,7 +1043,7 @@ TEST(execute, scalar_constant)
...
@@ -1044,7 +1043,7 @@ TEST(execute, scalar_constant)
ASSERT_EQ
((
vector
<
float
>
{
-
3.0
f
}),
result
->
get_vector
());
ASSERT_EQ
((
vector
<
float
>
{
-
3.0
f
}),
result
->
get_vector
());
}
}
TEST(
execute
, tensor_constant)
TEST
(
cpu
,
tensor_constant
)
{
{
auto
shape
=
Shape
{
2
,
2
,
2
};
auto
shape
=
Shape
{
2
,
2
,
2
};
auto
t
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
auto
t
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
...
@@ -1053,7 +1052,7 @@ TEST(execute, tensor_constant)
...
@@ -1053,7 +1052,7 @@ TEST(execute, tensor_constant)
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
A
,
rt
,
op
::
Parameters
{});
auto
f
=
make_shared
<
Function
>
(
A
,
rt
,
op
::
Parameters
{});
auto manager = runtime::Manager::get("
NGVM
");
auto
manager
=
runtime
::
Manager
::
get
(
"
CPU
"
);
auto
external
=
manager
->
compile
(
f
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
auto
cf
=
backend
->
make_call_frame
(
external
);
...
@@ -1065,7 +1064,7 @@ TEST(execute, tensor_constant)
...
@@ -1065,7 +1064,7 @@ TEST(execute, tensor_constant)
ASSERT_EQ
((
vector
<
float
>
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
}),
result
->
get_vector
());
ASSERT_EQ
((
vector
<
float
>
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
}),
result
->
get_vector
());
}
}
TEST(
execute
, tensor_constant_with_op)
TEST
(
cpu
,
tensor_constant_with_op
)
{
{
auto
shape
=
Shape
{
2
,
2
,
2
};
auto
shape
=
Shape
{
2
,
2
,
2
};
auto
t
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
auto
t
=
ngraph
::
runtime
::
make_tensor
<
element
::
Float32
>
(
shape
);
...
@@ -1074,7 +1073,7 @@ TEST(execute, tensor_constant_with_op)
...
@@ -1074,7 +1073,7 @@ TEST(execute, tensor_constant_with_op)
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Abs
>
(
A
),
rt
,
op
::
Parameters
{});
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Abs
>
(
A
),
rt
,
op
::
Parameters
{});
auto manager = runtime::Manager::get("
NGVM
");
auto
manager
=
runtime
::
Manager
::
get
(
"
CPU
"
);
auto
external
=
manager
->
compile
(
f
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
auto
cf
=
backend
->
make_call_frame
(
external
);
...
@@ -1086,6 +1085,7 @@ TEST(execute, tensor_constant_with_op)
...
@@ -1086,6 +1085,7 @@ TEST(execute, tensor_constant_with_op)
ASSERT_EQ
((
vector
<
float
>
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
}),
result
->
get_vector
());
ASSERT_EQ
((
vector
<
float
>
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
}),
result
->
get_vector
());
}
}
/*
TEST(execute, function_call)
TEST(execute, function_call)
{
{
// First create "f(A,B,C) = (A+B)*C".
// First create "f(A,B,C) = (A+B)*C".
...
...
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