cross_map_normal_op.h 1.9 KB
Newer Older
H
hedaoyuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

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. */

#pragma once

#include "paddle/math/Matrix.h"

namespace paddle {

H
hedaoyuan 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
enum DeviceType {
  DEVICE_TYPE_UNSPECIFIED = 0,
  DEVICE_TYPE_CPU = 1,
  DEVICE_TYPE_GPU = 2,
};

template <DeviceType Device>
struct MatrixT;

template <>
struct MatrixT<DEVICE_TYPE_CPU> {
  using type = CpuMatrix;
};

template <>
struct MatrixT<DEVICE_TYPE_GPU> {
  using type = GpuMatrix;
};

template <DeviceType Device>
H
hedaoyuan 已提交
41
struct CrossMapNormal {
H
hedaoyuan 已提交
42 43 44
  void operator()(typename MatrixT<Device>::type& outputs,
                  typename MatrixT<Device>::type& denoms,
                  typename MatrixT<Device>::type& inputs,
H
hedaoyuan 已提交
45 46 47 48 49 50 51 52
                  size_t channels,
                  size_t imgSizeH,
                  size_t imgSizeW,
                  size_t sizeX,
                  real scale,
                  real pow);
};

H
hedaoyuan 已提交
53
template <DeviceType Device>
H
hedaoyuan 已提交
54
struct CrossMapNormalGrad {
H
hedaoyuan 已提交
55 56 57 58 59
  void operator()(typename MatrixT<Device>::type& inputsGrad,
                  typename MatrixT<Device>::type& inputsValue,
                  typename MatrixT<Device>::type& outputsGrad,
                  typename MatrixT<Device>::type& outputsValue,
                  typename MatrixT<Device>::type& denoms,
H
hedaoyuan 已提交
60 61 62 63 64 65 66 67 68
                  size_t channels,
                  size_t imgSizeH,
                  size_t imgSizeW,
                  size_t sizeX,
                  real scale,
                  real pow);
};

}  // namespace paddle