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
55ac615b
Commit
55ac615b
authored
Oct 10, 2017
by
Adam Procter
Committed by
Scott Cyphers
Oct 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement elementwise exp (#187)
* Add elementwise exp to VM * Formatting
parent
9657490e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
0 deletions
+79
-0
exp.hpp
src/ngraph/runtime/ngvm/eigen/exp.hpp
+53
-0
external_function.cpp
src/ngraph/runtime/ngvm/external_function.cpp
+3
-0
execute.cpp
test/execute.cpp
+23
-0
No files found.
src/ngraph/runtime/ngvm/eigen/exp.hpp
0 → 100644
View file @
55ac615b
// ----------------------------------------------------------------------------
// 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
ExpInstruction
:
public
Instruction
{
public
:
ExpInstruction
(
TensorViewInfo
arg
,
TensorViewInfo
out
)
:
m_arg
(
arg
)
,
m_out
(
out
)
{
}
virtual
void
execute
(
CallFrame
&
call_frame
)
const
override
{
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_out
)
=
EigenArray1d
<
ET
,
fmt
::
V
>
(
call_frame
,
m_arg
).
exp
();
}
protected
:
TensorViewInfo
m_arg
;
TensorViewInfo
m_out
;
};
}
}
}
}
src/ngraph/runtime/ngvm/external_function.cpp
View file @
55ac615b
...
...
@@ -32,6 +32,7 @@
#include "ngraph/ops/divide.hpp"
#include "ngraph/ops/dot.hpp"
#include "ngraph/ops/equal.hpp"
#include "ngraph/ops/exp.hpp"
#include "ngraph/ops/function_call.hpp"
#include "ngraph/ops/get_tuple_element.hpp"
#include "ngraph/ops/greater.hpp"
...
...
@@ -66,6 +67,7 @@
#include "ngraph/runtime/ngvm/eigen/divide.hpp"
#include "ngraph/runtime/ngvm/eigen/dot.hpp"
#include "ngraph/runtime/ngvm/eigen/equal.hpp"
#include "ngraph/runtime/ngvm/eigen/exp.hpp"
#include "ngraph/runtime/ngvm/eigen/greater_eq.hpp"
#include "ngraph/runtime/ngvm/eigen/greater_than.hpp"
#include "ngraph/runtime/ngvm/eigen/less_eq.hpp"
...
...
@@ -323,6 +325,7 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map()
static
OpMap
op_map
;
if
(
!
initialized
)
{
REGISTER_NUMERIC_UNOP
(
op
::
Exp
,
eigen
::
ExpInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Log
,
eigen
::
LogInstruction
);
REGISTER_NUMERIC_UNOP
(
op
::
Negative
,
eigen
::
NegateInstruction
);
...
...
test/execute.cpp
View file @
55ac615b
...
...
@@ -1860,3 +1860,26 @@ TEST(type_prop, reshape_m2m_dim_change_transpose)
(
*
cf
)({
a
},
{
result
});
ASSERT_EQ
((
vector
<
float
>
{
1
,
3
,
5
,
2
,
4
,
6
}),
result
->
get_vector
());
}
TEST
(
execute
,
exp
)
{
auto
shape
=
Shape
{
8
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
result_type
=
make_shared
<
TensorViewType
>
(
element
::
Float32
::
element_type
(),
shape
);
auto
f
=
make_shared
<
Function
>
(
make_shared
<
op
::
Exp
>
(
A
),
result_type
,
op
::
Parameters
{
A
});
auto
manager
=
runtime
::
Manager
::
get
(
"NGVM"
);
auto
external
=
manager
->
compile
(
f
);
auto
backend
=
manager
->
allocate_backend
();
auto
cf
=
backend
->
make_call_frame
(
external
);
// Create some tensors for input/output
auto
a
=
backend
->
make_parameterized_tensor_view
<
element
::
Float32
>
(
shape
);
*
a
=
vector
<
float
>
{
-
4
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
};
auto
result
=
backend
->
make_parameterized_tensor_view
<
element
::
Float32
>
(
shape
);
(
*
cf
)({
a
},
{
result
});
ASSERT_EQ
(
(
vector
<
float
>
{
expf
(
-
4
),
expf
(
-
3
),
expf
(
-
2
),
expf
(
-
1
),
expf
(
0
),
expf
(
1
),
expf
(
2
),
expf
(
3
)}),
result
->
get_vector
());
}
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