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
33944997
Commit
33944997
authored
Oct 24, 2017
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CPU: Implement op::Log, op::Maximum and op::Negative
parent
cb8dc1d0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
8 deletions
+65
-8
emitter.cpp
src/ngraph/runtime/cpu/emitter.cpp
+51
-0
emitter.hpp
src/ngraph/runtime/cpu/emitter.hpp
+3
-0
external_function.cpp
src/ngraph/runtime/cpu/external_function.cpp
+4
-1
cpu.cpp
test/cpu.cpp
+7
-7
No files found.
src/ngraph/runtime/cpu/emitter.cpp
View file @
33944997
...
...
@@ -441,3 +441,54 @@ void Emitter::EMITTER_DECL(EmitLessEq)
EIGEN_VECTOR_FORMAT
(
inputs
[
1
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
")).template cast<char>();
\n
"
" }
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitLog
)
{
const
element
::
Type
&
et
=
(
dynamic_pointer_cast
<
const
TensorViewType
>
(
n
->
get_arguments
().
at
(
0
)
->
get_value_type
()))
->
get_element_type
();
TU
+=
" {
\n
"
" auto arg0 = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
inputs
[
0
].
get_index
())
+
");
\n
"
" auto out = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
");
\n
"
" EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(out, "
EIGEN_VECTOR_FORMAT
(
outputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
") =
\n
"
" Eigen::log(EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(arg0, "
EIGEN_VECTOR_FORMAT
(
inputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
"));
\n
"
" }
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitMaximum
)
{
const
element
::
Type
&
et
=
(
dynamic_pointer_cast
<
const
TensorViewType
>
(
n
->
get_arguments
().
at
(
0
)
->
get_value_type
()))
->
get_element_type
();
TU
+=
" {
\n
"
" auto arg0 = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
inputs
[
0
].
get_index
())
+
");
\n
"
" auto arg1 = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
inputs
[
1
].
get_index
())
+
");
\n
"
" auto out = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
");
\n
"
" EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(out, "
EIGEN_VECTOR_FORMAT
(
outputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
") =
\n
"
" EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(arg0, "
EIGEN_VECTOR_FORMAT
(
inputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
").max("
" EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(arg1, "
EIGEN_VECTOR_FORMAT
(
inputs
[
1
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
"));
\n
"
" }
\n
"
;
}
void
Emitter
::
EMITTER_DECL
(
EmitNegative
)
{
const
element
::
Type
&
et
=
(
dynamic_pointer_cast
<
const
TensorViewType
>
(
n
->
get_arguments
().
at
(
0
)
->
get_value_type
()))
->
get_element_type
();
TU
+=
" {
\n
"
" auto arg0 = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
inputs
[
0
].
get_index
())
+
");
\n
"
" auto out = call_frame->get_tensor_view_data<"
+
element_type_names
[
TI
(
et
)]
+
">("
+
to_string
(
outputs
[
0
].
get_index
())
+
");
\n
"
" EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(out, "
EIGEN_VECTOR_FORMAT
(
outputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
") =
\n
"
" -EigenArray1d<"
+
element_type_names
[
TI
(
et
)]
+
">(arg0, "
EIGEN_VECTOR_FORMAT
(
inputs
[
0
].
get_layout
<
DenseTensorViewLayout
>
()
->
get_size
())
");
\n
"
" }
\n
"
;
}
src/ngraph/runtime/cpu/emitter.hpp
View file @
33944997
...
...
@@ -57,6 +57,9 @@ namespace ngraph
void
EMITTER_DECL
(
EmitGreaterEq
);
void
EMITTER_DECL
(
EmitLess
);
void
EMITTER_DECL
(
EmitLessEq
);
void
EMITTER_DECL
(
EmitLog
);
void
EMITTER_DECL
(
EmitMaximum
);
void
EMITTER_DECL
(
EmitNegative
);
};
}
...
...
src/ngraph/runtime/cpu/external_function.cpp
View file @
33944997
...
...
@@ -83,7 +83,10 @@ static const OpMap dispatcher{{TI(ngraph::op::Add), &Emitter::EmitAdd},
{
TI
(
ngraph
::
op
::
Greater
),
&
Emitter
::
EmitGreater
},
{
TI
(
ngraph
::
op
::
GreaterEq
),
&
Emitter
::
EmitGreaterEq
},
{
TI
(
ngraph
::
op
::
Less
),
&
Emitter
::
EmitLess
},
{
TI
(
ngraph
::
op
::
LessEq
),
&
Emitter
::
EmitLessEq
}
{
TI
(
ngraph
::
op
::
LessEq
),
&
Emitter
::
EmitLessEq
},
{
TI
(
ngraph
::
op
::
Log
),
&
Emitter
::
EmitLog
},
{
TI
(
ngraph
::
op
::
Maximum
),
&
Emitter
::
EmitMaximum
},
{
TI
(
ngraph
::
op
::
Negative
),
&
Emitter
::
EmitNegative
}
};
...
...
test/cpu.cpp
View file @
33944997
...
...
@@ -876,15 +876,14 @@ TEST(cpu, lesseq)
ASSERT_EQ
((
vector
<
char
>
{
1
,
0
,
1
,
0
,
1
,
1
,
0
,
1
}),
result
->
get_vector
());
}
/*
TEST(execute, log)
TEST
(
cpu
,
log
)
{
auto
shape
=
Shape
{
2
,
2
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Log
>
(
A
),
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
);
...
...
@@ -903,7 +902,7 @@ TEST(execute, log)
ASSERT_EQ
(
loga
,
result
->
get_vector
());
}
TEST(
execute
, maximum)
TEST
(
cpu
,
maximum
)
{
auto
shape
=
Shape
{
2
,
2
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
...
...
@@ -911,7 +910,7 @@ TEST(execute, maximum)
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Maximum
>
(
A
,
B
),
rt
,
op
::
Parameters
{
A
,
B
});
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
);
...
...
@@ -927,14 +926,14 @@ TEST(execute, maximum)
ASSERT_EQ
((
vector
<
float
>
{
1
,
8
,
4
,
17
,
0
,
0.5
,
2
,
1.5
}),
result
->
get_vector
());
}
TEST(
execute
, negative)
TEST
(
cpu
,
negative
)
{
auto
shape
=
Shape
{
2
,
3
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
rt
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Negative
>
(
A
),
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
);
...
...
@@ -948,6 +947,7 @@ TEST(execute, negative)
ASSERT_EQ
((
vector
<
float
>
{
-
1
,
2
,
0
,
4.8
f
,
-
8.6
f
,
8.6
f
}),
result
->
get_vector
());
}
/*
TEST(execute, notequal)
{
auto shape = Shape{2, 2, 2};
...
...
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