MagmaDNN  1.0
c++NeuralNetworkFramework
softmaxop.h
1 
2 #pragma once
3 
4 #include "compute/operation.h"
5 #include "tensor/tensor.h"
6 #include "utilities_internal.h"
7 #include "math/softmax.h"
8 
9 #if defined(_HAS_CUDA_)
10 #include "cudnn.h"
11 #endif
12 
13 namespace magmadnn {
14 namespace op {
15 
16 template <typename T>
17 class SoftmaxOp : public Operation<T> {
18 public:
19  SoftmaxOp(Operation<T> *input, bool copy=true, bool needs_grad=true);
20 
21 
22  std::string to_string() { return "Softmax(" + input->to_string() + ")"; }
23 protected:
24  Tensor<T> *_eval(bool recompute);
26 
27  Operation<T> *input;
28  Tensor<T> *input_tensor;
29 
30  #if defined(_HAS_CUDA_)
31  void init_settings();
32 
33  math::cudnn_softmax_settings_t settings;
34  math::cudnn_softmax_grad_settings_t grad_settings;
35  #endif
36 
37  bool copy;
38 
39 };
40 
41 template <typename T>
42 SoftmaxOp<T>* softmax(Operation<T> *input, bool copy=true, bool needs_grad=true);
43 
44 } // namespace op
45 } // namespace magmadnn
Tensor< T > * _eval(bool recompute)
Definition: softmaxop.cpp:24
Definition: addop.cpp:11
std::string to_string()
Definition: softmaxop.h:22
Definition: tensor.h:34
Definition: softmaxop.h:17
virtual Tensor< T > * grad(Operation< T > *consumer, Operation< T > *var, Tensor< T > *grad, bool recompute=true)
Definition: operation.h:93
virtual std::string to_string()=0
Definition: operation.h:18
Variable< T > * var(std::string name, Tensor< T > *val)
Definition: variable.cpp:73
Tensor< T > * _grad(Operation< T > *consumer, Operation< T > *var, Tensor< T > *grad)
Definition: softmaxop.cpp:42