test_activation_op.cc 1.6 KB
Newer Older
L
Luo Tao 已提交
1 2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

L
Luo Tao 已提交
3 4 5
   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
L
Luo Tao 已提交
6

L
Luo Tao 已提交
7
   http://www.apache.org/licenses/LICENSE-2.0
L
Luo Tao 已提交
8

L
Luo Tao 已提交
9 10 11 12 13
   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
   limitations under the License. */
L
Luo Tao 已提交
14 15 16

#include <gtest/gtest.h>
#include "paddle/fluid/framework/op_registry.h"
L
Luo Tao 已提交
17
#include "paddle/fluid/inference/tensorrt/convert/ut_helper.h"
L
Luo Tao 已提交
18 19 20 21 22

namespace paddle {
namespace inference {
namespace tensorrt {

N
nhzlx 已提交
23
void test_activation(std::string act_type) {
L
Luo Tao 已提交
24
  framework::Scope scope;
L
Luo Tao 已提交
25
  std::unordered_set<std::string> parameters;
N
nhzlx 已提交
26
  TRTConvertValidation validator(10, parameters, scope, 1000);
N
nhzlx 已提交
27 28
  validator.DeclInputVar("act-X", nvinfer1::Dims2(10, 6));
  validator.DeclOutputVar("act-Out", nvinfer1::Dims2(10, 6));
L
Luo Tao 已提交
29 30 31

  // Prepare Op description
  framework::OpDesc desc;
N
nhzlx 已提交
32 33 34
  desc.SetType(act_type);
  desc.SetInput("X", {"act-X"});
  desc.SetOutput("Out", {"act-Out"});
L
Luo Tao 已提交
35 36 37 38 39

  LOG(INFO) << "set OP";
  validator.SetOp(*desc.Proto());
  LOG(INFO) << "execute";

N
nhzlx 已提交
40
  validator.Execute(5);
L
Luo Tao 已提交
41 42
}

N
nhzlx 已提交
43 44 45 46 47 48
TEST(ReluOpConverter, main) { test_activation("relu"); }

TEST(SigmoidOpConverter, main) { test_activation("sigmoid"); }

TEST(TanhOpConverter, main) { test_activation("tanh"); }

L
Luo Tao 已提交
49 50 51
}  // namespace tensorrt
}  // namespace inference
}  // namespace paddle
Y
Yan Chunwei 已提交
52

L
Luo Tao 已提交
53
USE_OP(relu);
N
nhzlx 已提交
54 55
USE_OP(sigmoid);
USE_OP(tanh);