Coverage Report

Created: 2021-04-07 03:47

/home/liu/buildslave/linux-x64-runtests/build/test/unit/nnc/layer.norm.tests.c
Line
Count
Source
1
#include "case.h"
2
#include "ccv_case.h"
3
#include "ccv_nnc_case.h"
4
#include <ccv.h>
5
#include <nnc/ccv_nnc.h>
6
#include <nnc/ccv_nnc_easy.h>
7
#include "3rdparty/dsfmt/dSFMT.h"
8
9
TEST_SETUP()
10
{
11
  ccv_nnc_init();
12
}
13
14
TEST_CASE("implement layer norm with other symbolic graph")
15
1
{
16
1
  ccv_nnc_symbolic_graph_t* const symbolic_graph = ccv_nnc_symbolic_graph_new();
17
1
  ccv_nnc_tensor_symbol_t x = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "x");
18
1
  ccv_nnc_tensor_symbol_t sum = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "sum");
19
1
  ccv_nnc_tensor_symbol_t mean = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "mean");
20
1
  ccv_nnc_tensor_symbol_t whitening = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "whitening");
21
1
  ccv_nnc_tensor_symbol_t sqr = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "sqr");
22
1
  ccv_nnc_tensor_symbol_t varsum = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "varsum");
23
1
  ccv_nnc_tensor_symbol_t var = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "var");
24
1
  ccv_nnc_tensor_symbol_t logvar = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "logvar");
25
1
  ccv_nnc_tensor_symbol_t logvar_2 = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "logvar");
26
1
  ccv_nnc_tensor_symbol_t std = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "std");
27
1
  ccv_nnc_tensor_symbol_t inv_std = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "inv_std");
28
1
  ccv_nnc_tensor_symbol_t y = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "y");
29
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_REDUCE_SUM_FORWARD(1, 2, 3), TENSOR_SYMBOL_LIST(x), TENSOR_SYMBOL_LIST(sum), "sum");
30
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_SCALAR_MUL_FORWARD(1.0 / (4 * 4 * 10)), TENSOR_SYMBOL_LIST(sum), TENSOR_SYMBOL_LIST(mean), "mean");
31
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_ADD_FORWARD(1, -1), TENSOR_SYMBOL_LIST(x, mean), TENSOR_SYMBOL_LIST(whitening), "whitening");
32
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWPROD_FORWARD(), TENSOR_SYMBOL_LIST(whitening, whitening), TENSOR_SYMBOL_LIST(sqr), "sqr");
33
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_REDUCE_SUM_FORWARD(1, 2, 3), TENSOR_SYMBOL_LIST(sqr), TENSOR_SYMBOL_LIST(varsum), "varsum");
34
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_SCALAR_MUL_FORWARD(1.0 / (4 * 4 * 10)), TENSOR_SYMBOL_LIST(varsum), TENSOR_SYMBOL_LIST(var), "var");
35
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWLOG_FORWARD(), TENSOR_SYMBOL_LIST(var), TENSOR_SYMBOL_LIST(logvar), "log(var)");
36
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_SCALAR_MUL_FORWARD(0.5), TENSOR_SYMBOL_LIST(logvar), TENSOR_SYMBOL_LIST(logvar_2), "log(var)/2");
37
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWEXP_FORWARD(), TENSOR_SYMBOL_LIST(logvar_2), TENSOR_SYMBOL_LIST(std), "std");
38
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWDIV_FORWARD(), TENSOR_SYMBOL_LIST(NO_TENSOR_SYMBOL, std), TENSOR_SYMBOL_LIST(inv_std), "1/std");
39
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_MUL_FORWARD(1), TENSOR_SYMBOL_LIST(whitening, inv_std), TENSOR_SYMBOL_LIST(y), "y");
40
1
  ccv_nnc_graph_exec_symbol_autogen(symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
41
1
  SYMBOLIC_GRAPH_GEN(symbolic_graph, CCV_NNC_LONG_DOT_GRAPH);
42
1
  ccv_nnc_graph_t* graph = 0;
43
1
  ccv_nnc_tensor_arena_t* tensor_arena = 0;
44
1
  ccv_nnc_graph_exec_arena_t* graph_exec_arena = 0;
45
1
  ccv_nnc_symbolic_graph_compile(symbolic_graph, ccv_nnc_default_compile_params, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(symbolic_graph), &graph, &tensor_arena, &graph_exec_arena);
46
1
  GRAPH_GEN(graph, CCV_NNC_LONG_DOT_GRAPH);
47
1
  ccv_nnc_tensor_t* const x_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, x);
48
1
  dsfmt_t dsfmt;
49
1
  int i;
50
1
  dsfmt_init_gen_rand(&dsfmt, 1);
51
1.28k
  for (i = 0; i < 8 * 4 * 4 * 10; 
i++1.28k
)
52
1.28k
    x_tensor->data.f32[i] = dsfmt_genrand_open_close(&dsfmt);
53
1
  ccv_nnc_symbolic_graph_t* const layer_norm_symbolic_graph = ccv_nnc_symbolic_graph_new();
54
1
  ccv_nnc_tensor_symbol_t bx = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "x");
55
1
  ccv_nnc_tensor_symbol_t by = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "y");
56
1
  ccv_nnc_tensor_symbol_t scale = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 1, 4, 4, 10), "scale");
57
1
  ccv_nnc_tensor_symbol_t bias = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 1, 4, 4, 10), "bias");
58
1
  ccv_nnc_tensor_symbol_t saved_mean = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "saved_mean");
59
1
  ccv_nnc_tensor_symbol_t saved_inv_std = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "saved_inv_std");
60
1
  ccv_nnc_graph_exec_symbol_new(layer_norm_symbolic_graph, CMD_SET_FORWARD(1), 0, 0, TENSOR_SYMBOL_LIST(scale), "set_scale");
61
1
  ccv_nnc_graph_exec_symbol_new(layer_norm_symbolic_graph, CMD_SET_FORWARD(0), 0, 0, TENSOR_SYMBOL_LIST(bias), "set_bias");
62
1
  ccv_nnc_graph_exec_symbol_new(layer_norm_symbolic_graph, CMD_LAYER_NORM_FORWARD(0, 1, 2, 3), TENSOR_SYMBOL_LIST(bx, scale, bias), TENSOR_SYMBOL_LIST(by, saved_mean, saved_inv_std), "layer_norm");
63
1
  ccv_nnc_graph_exec_symbol_autogen(layer_norm_symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
64
1
  ccv_nnc_graph_t* layer_norm_graph = 0;
65
1
  ccv_nnc_tensor_arena_t* layer_norm_tensor_arena = 0;
66
1
  ccv_nnc_graph_exec_arena_t* layer_norm_graph_exec_arena = 0;
67
1
  ccv_nnc_symbolic_graph_compile(layer_norm_symbolic_graph, ccv_nnc_default_compile_params, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(layer_norm_symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(layer_norm_symbolic_graph), &layer_norm_graph, &layer_norm_tensor_arena, &layer_norm_graph_exec_arena);
68
1
  ccv_nnc_tensor_t* const bx_tensor = ccv_nnc_tensor_from_symbol(layer_norm_tensor_arena, bx);
69
1
  memcpy(bx_tensor->data.f32, x_tensor->data.f32, sizeof(float) * 8 * 4 * 4 * 10);
70
1
  ccv_nnc_graph_run(graph, 0, TRAVERSE_FULL, 0, 0);
71
1
  ccv_nnc_graph_run(layer_norm_graph, 0, TRAVERSE_FULL, 0, 0);
72
1
  ccv_nnc_tensor_t* const y_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, y);
73
1
  ccv_nnc_tensor_t* const by_tensor = ccv_nnc_tensor_from_symbol(layer_norm_tensor_arena, by);
74
1
  REQUIRE_TENSOR_EQ(y_tensor, by_tensor, "graph computed result should match batch norm op result");
75
1
  ccv_nnc_symbolic_graph_free(symbolic_graph);
76
1
  ccv_nnc_tensor_arena_free(tensor_arena);
77
1
  ccv_nnc_graph_exec_arena_free(graph_exec_arena);
78
1
  ccv_nnc_graph_free(graph);
79
1
  ccv_nnc_symbolic_graph_free(layer_norm_symbolic_graph);
80
1
  ccv_nnc_tensor_arena_free(layer_norm_tensor_arena);
81
1
  ccv_nnc_graph_exec_arena_free(layer_norm_graph_exec_arena);
82
1
  ccv_nnc_graph_free(layer_norm_graph);
83
1
}
84
85
TEST_CASE("compare layer norm gradient with other symbolic graph")
86
1
{
87
1
  ccv_nnc_symbolic_graph_t* const symbolic_graph = ccv_nnc_symbolic_graph_new();
88
1
  ccv_nnc_tensor_symbol_t x = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "x");
89
1
  ccv_nnc_tensor_symbol_t sum = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "sum");
90
1
  ccv_nnc_tensor_symbol_t mean = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "mean");
91
1
  ccv_nnc_tensor_symbol_t whitening = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "whitening");
92
1
  ccv_nnc_tensor_symbol_t sqr = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "sqr");
93
1
  ccv_nnc_tensor_symbol_t varsum = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "varsum");
94
1
  ccv_nnc_tensor_symbol_t var = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "var");
95
1
  ccv_nnc_tensor_symbol_t logvar = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "logvar");
96
1
  ccv_nnc_tensor_symbol_t logvar_2 = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "logvar");
97
1
  ccv_nnc_tensor_symbol_t std = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "std");
98
1
  ccv_nnc_tensor_symbol_t inv_std = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "inv_std");
99
1
  ccv_nnc_tensor_symbol_t y = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "y");
100
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_REDUCE_SUM_FORWARD(1, 2, 3), TENSOR_SYMBOL_LIST(x), TENSOR_SYMBOL_LIST(sum), "sum");
101
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_SCALAR_MUL_FORWARD(1.0 / (4 * 4 * 10)), TENSOR_SYMBOL_LIST(sum), TENSOR_SYMBOL_LIST(mean), "mean");
102
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_ADD_FORWARD(1, -1), TENSOR_SYMBOL_LIST(x, mean), TENSOR_SYMBOL_LIST(whitening), "whitening");
103
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWPROD_FORWARD(), TENSOR_SYMBOL_LIST(whitening, whitening), TENSOR_SYMBOL_LIST(sqr), "sqr");
104
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_REDUCE_SUM_FORWARD(1, 2, 3), TENSOR_SYMBOL_LIST(sqr), TENSOR_SYMBOL_LIST(varsum), "varsum");
105
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_SCALAR_MUL_FORWARD(1.0 / (4 * 4 * 10)), TENSOR_SYMBOL_LIST(varsum), TENSOR_SYMBOL_LIST(var), "var");
106
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWLOG_FORWARD(), TENSOR_SYMBOL_LIST(var), TENSOR_SYMBOL_LIST(logvar), "log(var)");
107
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_SCALAR_MUL_FORWARD(0.5), TENSOR_SYMBOL_LIST(logvar), TENSOR_SYMBOL_LIST(logvar_2), "log(var)/2");
108
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWEXP_FORWARD(), TENSOR_SYMBOL_LIST(logvar_2), TENSOR_SYMBOL_LIST(std), "std");
109
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWDIV_FORWARD(), TENSOR_SYMBOL_LIST(NO_TENSOR_SYMBOL, std), TENSOR_SYMBOL_LIST(inv_std), "1/std");
110
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_MUL_FORWARD(1), TENSOR_SYMBOL_LIST(whitening, inv_std), TENSOR_SYMBOL_LIST(y), "y");
111
1
  ccv_nnc_graph_exec_symbol_autogen(symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
112
1
  ccv_nnc_symbolic_graph_backward(symbolic_graph, TENSOR_SYMBOL_LIST(y), TENSOR_SYMBOL_LIST(x), SYMBOLIC_GRAPH_SOURCES(symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(symbolic_graph));
113
1
  ccv_nnc_graph_exec_symbol_autogen(symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
114
1
  ccv_nnc_tensor_symbol_t dy = ccv_nnc_tensor_symbol_for_backward(symbolic_graph, y);
115
1
  ccv_nnc_tensor_symbol_t dx = ccv_nnc_tensor_symbol_for_backward(symbolic_graph, x);
116
1
  SYMBOLIC_GRAPH_GEN(symbolic_graph, CCV_NNC_LONG_DOT_GRAPH);
117
1
  ccv_nnc_graph_t* graph = 0;
118
1
  ccv_nnc_tensor_arena_t* tensor_arena = 0;
119
1
  ccv_nnc_graph_exec_arena_t* graph_exec_arena = 0;
120
1
  ccv_nnc_symbolic_graph_compile(symbolic_graph, ccv_nnc_default_compile_params, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(symbolic_graph), &graph, &tensor_arena, &graph_exec_arena);
121
1
  GRAPH_GEN(graph, CCV_NNC_LONG_DOT_GRAPH);
122
1
  ccv_nnc_tensor_t* const x_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, x);
123
1
  dsfmt_t dsfmt;
124
1
  int i;
125
1
  dsfmt_init_gen_rand(&dsfmt, 1);
126
1.28k
  for (i = 0; i < 8 * 4 * 4 * 10; 
i++1.28k
)
127
1.28k
    x_tensor->data.f32[i] = dsfmt_genrand_open_close(&dsfmt);
128
1
  ccv_nnc_symbolic_graph_t* const layer_norm_symbolic_graph = ccv_nnc_symbolic_graph_new();
129
1
  ccv_nnc_tensor_symbol_t bx = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "x");
130
1
  ccv_nnc_tensor_symbol_t by = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 4, 4, 10), "y");
131
1
  ccv_nnc_tensor_symbol_t scale = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 1, 4, 4, 10), "scale");
132
1
  ccv_nnc_tensor_symbol_t bias = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 1, 4, 4, 10), "bias");
133
1
  ccv_nnc_tensor_symbol_t saved_mean = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "saved_mean");
134
1
  ccv_nnc_tensor_symbol_t saved_inv_std = ccv_nnc_tensor_symbol_new(layer_norm_symbolic_graph, CPU_TENSOR_NHWC(32F, 8, 1, 1, 1), "saved_inv_std");
135
1
  ccv_nnc_graph_exec_symbol_new(layer_norm_symbolic_graph, CMD_SET_FORWARD(1), 0, 0, TENSOR_SYMBOL_LIST(scale), "set_scale");
136
1
  ccv_nnc_graph_exec_symbol_new(layer_norm_symbolic_graph, CMD_SET_FORWARD(0), 0, 0, TENSOR_SYMBOL_LIST(bias), "set_bias");
137
1
  ccv_nnc_graph_exec_symbol_new(layer_norm_symbolic_graph, CMD_LAYER_NORM_FORWARD(0, 1, 2, 3), TENSOR_SYMBOL_LIST(bx, scale, bias), TENSOR_SYMBOL_LIST(by, saved_mean, saved_inv_std), "layer_norm");
138
1
  ccv_nnc_graph_exec_symbol_autogen(layer_norm_symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
139
1
  ccv_nnc_symbolic_graph_backward(layer_norm_symbolic_graph, TENSOR_SYMBOL_LIST(by), TENSOR_SYMBOL_LIST(bx, scale, bias), SYMBOLIC_GRAPH_SOURCES(layer_norm_symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(layer_norm_symbolic_graph));
140
1
  ccv_nnc_graph_exec_symbol_autogen(layer_norm_symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS);
141
1
  ccv_nnc_tensor_symbol_t dby = ccv_nnc_tensor_symbol_for_backward(layer_norm_symbolic_graph, by);
142
1
  ccv_nnc_tensor_symbol_t dbx = ccv_nnc_tensor_symbol_for_backward(layer_norm_symbolic_graph, bx);
143
1
  ccv_nnc_graph_t* layer_norm_graph = 0;
144
1
  ccv_nnc_tensor_arena_t* layer_norm_tensor_arena = 0;
145
1
  ccv_nnc_graph_exec_arena_t* layer_norm_graph_exec_arena = 0;
146
1
  ccv_nnc_symbolic_graph_compile(layer_norm_symbolic_graph, ccv_nnc_default_compile_params, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(layer_norm_symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(layer_norm_symbolic_graph), &layer_norm_graph, &layer_norm_tensor_arena, &layer_norm_graph_exec_arena);
147
1
  ccv_nnc_tensor_t* const bx_tensor = ccv_nnc_tensor_from_symbol(layer_norm_tensor_arena, bx);
148
1
  ccv_nnc_tensor_t* const dy_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, dy);
149
1
  ccv_nnc_tensor_t* const dby_tensor = ccv_nnc_tensor_from_symbol(layer_norm_tensor_arena, dby);
150
1.28k
  for (i = 0; i < 8 * 4 * 4 * 10; 
i++1.28k
)
151
1.28k
    dby_tensor->data.f32[i] = dy_tensor->data.f32[i] = dsfmt_genrand_open_close(&dsfmt) * 2 - 1;
152
1
  memcpy(bx_tensor->data.f32, x_tensor->data.f32, sizeof(float) * 8 * 4 * 4 * 10);
153
1
  ccv_nnc_graph_run(graph, 0, TRAVERSE_FULL, 0, 0);
154
1
  ccv_nnc_graph_run(layer_norm_graph, 0, TRAVERSE_FULL, 0, 0);
155
1
  ccv_nnc_tensor_t* const dx_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, dx);
156
1
  ccv_nnc_tensor_t* const dbx_tensor = ccv_nnc_tensor_from_symbol(layer_norm_tensor_arena, dbx);
157
1
  REQUIRE_TENSOR_EQ(dx_tensor, dbx_tensor, "graph computed result should match layer norm op result");
158
1
  ccv_nnc_symbolic_graph_free(symbolic_graph);
159
1
  ccv_nnc_tensor_arena_free(tensor_arena);
160
1
  ccv_nnc_graph_exec_arena_free(graph_exec_arena);
161
1
  ccv_nnc_graph_free(graph);
162
1
  ccv_nnc_symbolic_graph_free(layer_norm_symbolic_graph);
163
1
  ccv_nnc_tensor_arena_free(layer_norm_tensor_arena);
164
1
  ccv_nnc_graph_exec_arena_free(layer_norm_graph_exec_arena);
165
1
  ccv_nnc_graph_free(layer_norm_graph);
166
1
}
167
168
#include "case_main.h"