BatchwiseMultiplicativeDropout.cpp 1.45 KB
Newer Older
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2016-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.

template <typename T>
void bmd_f(T *input_features, T *output_features, T *noise, Int nActive,
           Int nPlanes, T alpha);
template <typename T>
void bmd_b(T *input_features, T *d_input_features, T *d_output_features,
           T *noise, Int nActive, Int nPlanes, T alpha);

template <typename T>
void cuda_BatchwiseMultiplicativeDropout_updateOutput(
    /*cuda float*/ at::Tensor input_features,
    /*cuda float*/ at::Tensor output_features, /*cuda float*/ at::Tensor noise,
    T alpha) {
  output_features.resize_as_(input_features);
  auto nActive = input_features.size(0);
  auto nPlanes = input_features.size(1);
  bmd_f(input_features.data<T>(), output_features.data<T>(), noise.data<T>(),
        nActive, nPlanes, alpha);
}

template <typename T>
void cuda_BatchwiseMultiplicativeDropout_updateGradInput(
    /*cuda float*/ at::Tensor input_features,
    /*cuda float*/ at::Tensor d_input_features,
    /*cuda float*/ at::Tensor d_output_features,
    /*cuda float*/ at::Tensor noise, T alpha) {
  d_input_features.resize_as_(d_output_features);
  auto nActive = input_features.size(0);
  auto nPlanes = input_features.size(1);
  bmd_b(input_features.data<T>(), d_input_features.data<T>(),
        d_output_features.data<T>(), noise.data<T>(), nActive, nPlanes, alpha);
}