Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ELU #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ void ActivationParamLayerTest::Infer() {
inferRequest.Infer();
}


void ActivationParamLayerTest::SetUp() {
InferenceEngine::Precision netPrecision;
std::pair<std::vector<size_t>, std::vector<size_t>> shapes;
Expand Down
3 changes: 3 additions & 0 deletions ngraph/core/include/ngraph/op/elu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ namespace ngraph
clone_with_new_inputs(const OutputVector& new_args) const override;

double get_alpha() const { return m_alpha; }

bool evaluate(const HostTensorVector& outputs,
const HostTensorVector& inputs) const override;
private:
double m_alpha;
};
Expand Down
2 changes: 1 addition & 1 deletion ngraph/core/include/ngraph/runtime/reference/elu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace ngraph
{
for (size_t i = 0; i < count; i++)
{
out[i] = arg[i] < 0 ? alpha * (std::exp(arg[i]) - 1.0) : arg[i];
out[i] = arg[i] < T(0) ? T(alpha * (std::exp(arg[i]) - 1.0)) : arg[i];
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions ngraph/core/src/op/elu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//*****************************************************************************

#include <ngraph/runtime/reference/elu.hpp>
#include "ngraph/op/elu.hpp"
#include "ngraph/attribute_visitor.hpp"
#include "ngraph/builder/autobroadcast.hpp"
Expand Down Expand Up @@ -48,3 +49,37 @@ shared_ptr<Node> op::Elu::clone_with_new_inputs(const OutputVector& new_args) co
check_new_args_count(this, new_args);
return make_shared<Elu>(new_args.at(0), m_alpha);
}


template <element::Type_t ET>
bool evaluate(const HostTensorPtr& arg,const HostTensorPtr& out, double alpha)
{
runtime::reference::elu(arg->get_data_ptr<ET>(),
out->get_data_ptr<ET>(),
shape_size(arg->get_shape()),
alpha);
return true;
}

bool evaluate_elu(const HostTensorPtr& arg, const HostTensorPtr& out, double alpha)
{
bool rc = true;
switch (arg->get_element_type())
{
TYPE_CASE(i8)(arg, out, alpha);
break;
TYPE_CASE(bf16)(arg, out, alpha);
break;
TYPE_CASE(f16)(arg, out, alpha);
break;
TYPE_CASE(f32)(arg, out, alpha);
break;
default: rc = false; break;
}
return rc;
}


bool op::v0::Elu::evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const {
return evaluate_elu(inputs[0], outputs[0], m_alpha);
}