File: dnn_dropout_desc.c

package info (click to toggle)
theano 1.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 30,752 kB
  • sloc: python: 141,182; ansic: 9,505; makefile: 259; sh: 214; pascal: 81
file content (45 lines) | stat: -rw-r--r-- 1,348 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
#section support_code

int dnn_dropout_desc(float dropout, unsigned long long seed,
                     PyGpuContextObject *c,
                     cudnnDropoutDescriptor_t *odesc,
                     PyGpuArrayObject **ostates,
                     cudnnHandle_t _handle) {
  PyGpuArrayObject *states;
  cudnnDropoutDescriptor_t desc;
  size_t states_sz;
  cudnnStatus_t err;

  cuda_enter(c->ctx);
  err = cudnnCreateDropoutDescriptor(&desc);
  if (err != CUDNN_STATUS_SUCCESS) {
    PyErr_SetString(PyExc_RuntimeError, "Can't create dropout descriptor");
    cuda_exit(c->ctx);
    return -1;
  }

  /* Can't fail according to docs */
  cudnnDropoutGetStatesSize(_handle, &states_sz);
  
  states = pygpu_empty(1, &states_sz, GA_UBYTE, GA_C_ORDER, c, Py_None);
  if (states == NULL) {
    cudnnDestroyDropoutDescriptor(desc);
    cuda_exit(c->ctx);
    return -1;
  }

  err = cudnnSetDropoutDescriptor(desc, _handle, dropout,
                                  PyGpuArray_DEV_DATA(states),
                                  states_sz, seed);
  if (err != CUDNN_STATUS_SUCCESS) {
    PyErr_SetString(PyExc_RuntimeError, "Can't set dropout descriptor");
    Py_DECREF((PyObject *)states);
    cudnnDestroyDropoutDescriptor(desc);
    cuda_exit(c->ctx);
    return -1;
  }
  cuda_exit(c->ctx);
  *odesc = desc;
  *ostates = states;
  return 0;
}