MCPcopy Create free account
hub / github.com/apache/singa / TEST

Function TEST

test/singa/test_operation_rnn.cc:29–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28#ifdef USE_CUDNN
29TEST(OperationRNN, tranining) {
30 auto cuda = std::make_shared<singa::CudaGPU>();
31
32 size_t hidden_size = 7;
33 int seq_length = 5;
34 size_t batch_size = 6;
35 size_t feature_size = 3;
36 size_t num_layers = 1;
37 int bdirect = 0;
38
39 Shape s_s{num_layers * (bdirect ? 2 : 1), batch_size, hidden_size};
40 Shape y_s{seq_length, batch_size, hidden_size * (bdirect ? 2 : 1)};
41
42 // x
43 Tensor x(Shape{seq_length, batch_size, feature_size}, cuda);
44 Gaussian(0.0f, 1.0f, &x);
45
46 // x hidden states and cell states
47 Tensor hx(s_s, cuda);
48 Tensor cx(s_s, cuda);
49 hx.SetValue(0.0f);
50 cx.SetValue(0.0f);
51
52 // y dy
53 Tensor y(y_s, cuda);
54 Tensor dy(y_s, cuda);
55 Gaussian(0.0f, 1.0f, &y);
56 Gaussian(0.0f, 1.0f, &dy);
57
58 // y hidden states and cell states
59 Tensor dhy(s_s, cuda);
60 Tensor dcy(s_s, cuda);
61 Gaussian(0.0f, 1.0f, &dhy);
62 Gaussian(0.0f, 1.0f, &dcy);
63
64 // init handle and weights
65 CudnnRNNHandle rnn_handle(x, hidden_size);
66 Tensor W(Shape{rnn_handle.weights_size}, cuda);
67 Gaussian(0.0f, 1.0f, &W);
68
69 // forward and backward passes
70 auto outputs = GpuRNNForwardTraining(x, hx, cx, W, rnn_handle);
71 auto outputs2 = GpuRNNForwardInference(x, hx, cx, W, rnn_handle);
72 auto output3 = GpuRNNBackwardx(y, dy, dhy, dcy, W, hx, cx, rnn_handle);
73 auto dW = GpuRNNBackwardW(x, hx, y, rnn_handle);
74}
75
76TEST(OperationRNNEx, tranining) {
77 auto cuda = std::make_shared<singa::CudaGPU>();

Callers

nothing calls this directly

Calls 12

GpuRNNForwardTrainingFunction · 0.85
GpuRNNForwardInferenceFunction · 0.85
GpuRNNBackwardxFunction · 0.85
GpuRNNBackwardWFunction · 0.85
GpuRNNForwardTrainingExFunction · 0.85
GpuRNNForwardInferenceExFunction · 0.85
GpuRNNBackwardxExFunction · 0.85
GpuRNNBackwardWExFunction · 0.85
GaussianFunction · 0.50
SetValueMethod · 0.45
CopyDataFromHostPtrMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected