Fixed compiler fail for elu (#358)

Signed-off-by: Chen Xin <jack.chen@verisilicon.com>

Co-authored-by: Chen Xin <jack.chen@verisilicon.com>
This commit is contained in:
chxin66 2022-04-12 18:42:50 +08:00 committed by GitHub
parent e8ca6b8ee3
commit c033cfc582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -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;

View File

@ -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_;

View File

@ -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};