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

Fixed compiler fail for elu #358

Merged
merged 1 commit into from
Apr 12, 2022
Merged
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
1 change: 1 addition & 0 deletions include/tim/vx/ops/activations.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ DECLARE_NO_PARAMETER_ACTIVATION(SoftRelu)

class Elu : public DirectMapOp {
public:
Elu(Graph* graph);
Elu(Graph* graph, float alpha);
std::shared_ptr<Operation> Clone(
std::shared_ptr<Graph>& graph) const override;
Expand Down
2 changes: 2 additions & 0 deletions src/tim/vx/ops/activations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ DEFINE_NO_PARAMETER_ACTIVATION(SoftRelu, VSI_NN_OP_SOFTRELU)

#undef DEFINE_NO_PARAMETER_ACTIVATION

Elu::Elu(Graph* graph) : Elu(graph, 1) {}

Elu::Elu(Graph* graph, float alpha)
: DirectMapOp(graph, VSI_NN_OP_ELU), alpha_(alpha) {
this->impl()->node()->nn_param.elu.alpha = alpha_;
Expand Down
29 changes: 29 additions & 0 deletions src/tim/vx/ops/activations_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,35 @@ TEST(Elu, shape_5_1_fp32) {
auto input_tensor = graph->CreateTensor(input_spec);
auto output_tensor = graph->CreateTensor(output_spec);

std::vector<float> in_data = {-2.5, -0.1, 0, 0.55, 99};
std::vector<float> golden = {-0.917915, -0.0951626, 0, 0.55, 99};

EXPECT_TRUE(
input_tensor->CopyDataToTensor(in_data.data(), in_data.size() * 4));

auto op = graph->CreateOperation<tim::vx::ops::Elu>();
(*op).BindInputs({input_tensor}).BindOutputs({output_tensor});

EXPECT_TRUE(graph->Compile());
EXPECT_TRUE(graph->Run());
std::vector<float> output(5, 0);
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
EXPECT_TRUE(ArraysMatch(golden, output, 1e-5f));
}

TEST(Elu, shape_5_1_fp32_a) {
auto ctx = tim::vx::Context::Create();
auto graph = ctx->CreateGraph();

tim::vx::ShapeType io_shape({5, 1});
tim::vx::TensorSpec input_spec(tim::vx::DataType::FLOAT32, io_shape,
tim::vx::TensorAttribute::INPUT);
tim::vx::TensorSpec output_spec(tim::vx::DataType::FLOAT32, io_shape,
tim::vx::TensorAttribute::OUTPUT);

auto input_tensor = graph->CreateTensor(input_spec);
auto output_tensor = graph->CreateTensor(output_spec);

std::vector<float> in_data = {-2.5, -0.1, 0, 0.55, 99};
std::vector<float> golden = {-0.458957, -0.0475813, 0, 0.55, 99};

Expand Down