-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnn_weightLayer.h
More file actions
91 lines (78 loc) · 3.03 KB
/
nn_weightLayer.h
File metadata and controls
91 lines (78 loc) · 3.03 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) 2023 Jeff Boody
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#ifndef nn_weightLayer_H
#define nn_weightLayer_H
#include "../libcc/jsmn/cc_jsmnStream.h"
#include "../libcc/jsmn/cc_jsmnWrapper.h"
#include "../libvkk/vkk.h"
#include "nn_layer.h"
// XAVIER is default
#define NN_WEIGHT_LAYER_FLAG_XAVIER 0x0001
#define NN_WEIGHT_LAYER_FLAG_HE 0x0002
#define NN_WEIGHT_LAYER_FLAG_DISABLE_BIAS 0x0010
#define NN_WEIGHT_LAYER_FLAG_NORM_SN 0x0100
#define NN_WEIGHT_LAYER_FLAG_NORM_BSSN 0x0200
typedef struct nn_weightLayer_s
{
nn_layer_t base;
int flags;
// weights, bias, output
// bs; // batch size
// nc; // node count
// X; // dim(bs,1,1,xd)
nn_tensor_t* X; // dim(bs,1,1,xd) (reference)
nn_tensor_t* W; // dim(nc,1,1,xd)
nn_tensor_t* B; // dim(nc,1,1,1)
nn_tensor_t* Y; // dim(bs,1,1,nc)
// Adam - moment estimates
nn_tensor_t* MW; // dim(nc,1,1,xd)
nn_tensor_t* VW; // dim(nc,1,1,xd)
nn_tensor_t* MB; // dim(nc,1,1,1)
nn_tensor_t* VB; // dim(nc,1,1,1)
// forward gradients
// dY_dB; // 1
// dY_dX; // W : dim(nc,1,1,xd)
// dY_dW; // X : dim(bs,1,1,xd)
// backprop gradients
// dL_dY; // dim(bs,1,1,nc)
nn_tensor_t* dL_dW; // dim(nc,1,1,xd)
nn_tensor_t* dL_dB; // dim(nc,1,1,1)
nn_tensor_t* dL_dX; // dim(bs,1,1,xd)
// stats
nn_tensorStats_t* stats_Y;
nn_tensorStats_t* stats_dL_dX;
vkk_buffer_t* sb013_param;
vkk_uniformSet_t* us0;
vkk_uniformSet_t* us1_fp;
vkk_uniformSet_t* us1_bp;
} nn_weightLayer_t;
nn_weightLayer_t* nn_weightLayer_new(nn_arch_t* arch,
nn_dim_t* dimX,
nn_dim_t* dimW,
int flags);
void nn_weightLayer_delete(nn_weightLayer_t** _self);
nn_weightLayer_t* nn_weightLayer_import(nn_arch_t* arch,
cc_jsmnVal_t* val);
int nn_weightLayer_export(nn_weightLayer_t* self,
cc_jsmnStream_t* stream);
#endif