helper.cc 2.1 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);
47
    default:
48
      PADDLE_THROW("Not support type: %d", kt);
49 50 51 52
      return "NOT JITKernel";
  }
  return nullptr;
}
53
#undef ONE_CASE
54

T
tensor-tang 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68
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;
  }
69 70
  PADDLE_THROW("Not support type: %s, or forget to add this case", act);

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

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