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
a48a75d5
Commit
a48a75d5
authored
Oct 25, 2017
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CPU: Implement op::Convert
parent
5bf6c0ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
7 deletions
+36
-7
emitter.cpp
src/ngraph/runtime/cpu/emitter.cpp
+27
-0
emitter.hpp
src/ngraph/runtime/cpu/emitter.hpp
+1
-0
external_function.cpp
src/ngraph/runtime/cpu/external_function.cpp
+1
-0
cpu.cpp
test/cpu.cpp
+7
-7
No files found.
src/ngraph/runtime/cpu/emitter.cpp
View file @
a48a75d5
...
...
@@ -855,3 +855,30 @@ void Emitter::EMITTER_DECL(EmitBroadcast)
throw
ngraph_error
(
"Broadcast not implemented for given inputs"
);
}
}
void
Emitter
::
EMITTER_DECL
(
EmitConvert
)
{
auto
arg
=
n
->
get_arguments
().
at
(
0
);
auto
arg_tensor_type
=
dynamic_pointer_cast
<
const
TensorViewType
>
(
arg
->
get_value_type
());
assert
(
arg_tensor_type
);
auto
&
arg_element_type
=
arg_tensor_type
->
get_element_type
();
auto
result_tensor_type
=
dynamic_pointer_cast
<
const
TensorViewType
>
(
n
->
get_value_type
());
assert
(
result_tensor_type
);
auto
&
result_element_type
=
result_tensor_type
->
get_element_type
();
TU
+=
" {
\n
"
" auto arg0 = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
arg_element_type
)]
+
">("
+
to_string
(
inputs
[
0
].
get_index
())
+
");
\n
"
" auto out = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
result_element_type
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
");
\n
"
" EigenArray1d<"
+
element_type_names
[
TI
(
result_element_type
)]
+
">(out, "
EIGEN_VECTOR_FORMAT
(
outputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
") =
\n
"
" EigenArray1d<"
+
element_type_names
[
TI
(
arg_element_type
)]
+
">(arg0, "
EIGEN_VECTOR_FORMAT
(
inputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
")
\n
"
".template cast<typename "
+
element_type_names
[
TI
(
result_element_type
)]
+
"::type>();
\n
"
" }
\n
"
;
}
src/ngraph/runtime/cpu/emitter.hpp
View file @
a48a75d5
...
...
@@ -74,6 +74,7 @@ namespace ngraph
void
EMITTER_DECL
(
EmitParameterizedConstantUInt32
);
void
EMITTER_DECL
(
EmitParameterizedConstantUInt64
);
void
EMITTER_DECL
(
EmitBroadcast
);
void
EMITTER_DECL
(
EmitConvert
);
};
}
}
...
...
src/ngraph/runtime/cpu/external_function.cpp
View file @
a48a75d5
...
...
@@ -104,6 +104,7 @@ static const OpMap dispatcher{
{
TI
(
ngraph
::
op
::
ParameterizedConstant
<
ngraph
::
element
::
UInt64
>
),
&
Emitter
::
EmitParameterizedConstantUInt64
},
{
TI
(
ngraph
::
op
::
Broadcast
),
&
Emitter
::
EmitBroadcast
},
{
TI
(
ngraph
::
op
::
Convert
),
&
Emitter
::
EmitConvert
},
};
#undef TI
...
...
test/cpu.cpp
View file @
a48a75d5
...
...
@@ -1291,8 +1291,7 @@ TEST(cpu, broadcast_vector_rowwise_int64)
result
->
get_vector
());
}
/*
TEST(execute, convert_int32_float32)
TEST
(
cpu
,
convert_int32_float32
)
{
auto
shape
=
Shape
{
2
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Int32
::
element_type
(),
shape
);
...
...
@@ -1300,7 +1299,7 @@ TEST(execute, convert_int32_float32)
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Convert
>
(
A
,
element
::
Float32
::
element_type
()),
rt
,
op
::
Parameters
{
A
});
auto manager = runtime::Manager::get("
NGVM
");
auto
manager
=
runtime
::
Manager
::
get
(
"
CPU
"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
...
...
@@ -1314,7 +1313,7 @@ TEST(execute, convert_int32_float32)
ASSERT_EQ
((
vector
<
element
::
Float32
::
type
>
{
1
,
2
,
3
,
4
}),
result
->
get_vector
());
}
TEST(
execute
, convert_int32_bool)
TEST
(
cpu
,
convert_int32_bool
)
{
auto
shape
=
Shape
{
2
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Int32
::
element_type
(),
shape
);
...
...
@@ -1322,7 +1321,7 @@ TEST(execute, convert_int32_bool)
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Convert
>
(
A
,
element
::
Bool
::
element_type
()),
rt
,
op
::
Parameters
{
A
});
auto manager = runtime::Manager::get("
NGVM
");
auto
manager
=
runtime
::
Manager
::
get
(
"
CPU
"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
...
...
@@ -1336,7 +1335,7 @@ TEST(execute, convert_int32_bool)
ASSERT_EQ
((
vector
<
element
::
Bool
::
type
>
{
1
,
2
,
3
,
4
}),
result
->
get_vector
());
}
TEST(
execute
, convert_float32_bool)
TEST
(
cpu
,
convert_float32_bool
)
{
auto
shape
=
Shape
{
2
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
...
...
@@ -1344,7 +1343,7 @@ TEST(execute, convert_float32_bool)
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Convert
>
(
A
,
element
::
Bool
::
element_type
()),
rt
,
op
::
Parameters
{
A
});
auto manager = runtime::Manager::get("
NGVM
");
auto
manager
=
runtime
::
Manager
::
get
(
"
CPU
"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
...
...
@@ -1358,6 +1357,7 @@ TEST(execute, convert_float32_bool)
ASSERT_EQ
((
vector
<
element
::
Bool
::
type
>
{
1
,
2
,
3
,
4
}),
result
->
get_vector
());
}
/*
// Trivial case with no reduction axes.
TEST(execute, reduce_trivial)
{
...
...
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