helper.cc 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
 *
 * 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
 * limitations under the License. */

#include "paddle/fluid/operators/jit/helper.h"
T
tensor-tang 已提交
16
#include <algorithm>  // tolower
17
#include "paddle/fluid/platform/enforce.h"
18 19 20 21 22

namespace paddle {
namespace operators {
namespace jit {

23 24 25 26
#define ONE_CASE(key) \
  case key:           \
    return #key

27 28
const char* to_string(KernelType kt) {
  switch (kt) {
29 30 31 32 33 34 35 36 37 38 39
    ONE_CASE(vmul);
    ONE_CASE(vadd);
    ONE_CASE(vaddrelu);
    ONE_CASE(vsub);
    ONE_CASE(vscal);
    ONE_CASE(vaddbias);
    ONE_CASE(vrelu);
    ONE_CASE(videntity);
    ONE_CASE(vexp);
    ONE_CASE(vsigmoid);
    ONE_CASE(vtanh);
T
tensor-tang 已提交
40 41
    ONE_CASE(lstmctht);
    ONE_CASE(lstmc1h1);
42 43 44
    ONE_CASE(gruh1);
    ONE_CASE(gruhtpart1);
    ONE_CASE(gruhtpart2);
45 46
    ONE_CASE(crfdecoding);
    ONE_CASE(layernorm);
T
tensor-tang 已提交
47
    ONE_CASE(nchw16cmulnc);
48
    default:
T
tensor-tang 已提交
49
      PADDLE_THROW("Not support type: %d, or forget to add it.", kt);
50 51 52 53
      return "NOT JITKernel";
  }
  return nullptr;
}
54
#undef ONE_CASE
55

T
tensor-tang 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69
KernelType to_kerneltype(const std::string& act) {
  std::string lower = act;
  std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
  if (lower == "relu" || lower == "vrelu") {
    return vrelu;
  } else if (lower == "identity" || lower == "videntity" || lower == "") {
    return videntity;
  } else if (lower == "exp" || lower == "vexp") {
    return vexp;
  } else if (lower == "sigmoid" || lower == "vsigmoid") {
    return vsigmoid;
  } else if (lower == "tanh" || lower == "vtanh") {
    return vtanh;
  }
70 71
  PADDLE_THROW("Not support type: %s, or forget to add this case", act);

T
tensor-tang 已提交
72 73 74
  return non_kernel;
}

75 76 77
}  // namespace jit
}  // namespace operators
}  // namespace paddle