BatchwiseMultiplicativeDropout.cpp 1.49 KB
Newer Older
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
1
2
3
// Copyright 2016-present, Facebook, Inc.
// All rights reserved.
//
Benjamin Graham's avatar
Benjamin Graham committed
4
// This source code is licensed under the BSD-style license found in the
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
5
6
7
8
9
10
11
12
13
14
15
// 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(
Michal Pandy's avatar
Michal Pandy committed
16
17
    /*cuda float*/ at::Tensor &input_features,
    /*cuda float*/ at::Tensor &output_features, /*cuda float*/ at::Tensor &noise,
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
18
19
20
21
    T alpha) {
  output_features.resize_as_(input_features);
  auto nActive = input_features.size(0);
  auto nPlanes = input_features.size(1);
22
  bmd_f(input_features.data_ptr<T>(), output_features.data_ptr<T>(), noise.data_ptr<T>(),
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
23
24
25
26
27
        nActive, nPlanes, alpha);
}

template <typename T>
void cuda_BatchwiseMultiplicativeDropout_updateGradInput(
Michal Pandy's avatar
Michal Pandy committed
28
29
30
31
    /*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) {
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
32
33
34
  d_input_features.resize_as_(d_output_features);
  auto nActive = input_features.size(0);
  auto nPlanes = input_features.size(1);
35
36
  bmd_b(input_features.data_ptr<T>(), d_input_features.data_ptr<T>(),
        d_output_features.data_ptr<T>(), noise.data_ptr<T>(), nActive, nPlanes, alpha);
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
37
}