-
Notifications
You must be signed in to change notification settings - Fork 1
/
utilities.go
240 lines (188 loc) · 6.01 KB
/
utilities.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package cnn
import (
"io"
"github.com/dereklstinson/gocudnn/cudart/crtutil"
"github.com/dereklstinson/gocunets/devices/gpu/nvidia/cudnn"
)
/*
//SaveImagesToFile saves images do file
func (c *Layer) SaveImagesToFile(dir string) error {
return c.w.SaveImagesToFile(dir)
}
//WeightImgs returns 2d array of images
func (c *Layer) WeightImgs() ([][]image.Image, [][]image.Image, error) {
return c.w.Images()
}
*/
//LoadWValues will load a slice into cuda memory for the Weights.
func (c *Layer) LoadWValues(handle *cudnn.Handler, slice interface{}, length int) error {
/* ptr, err := gocudnn.MakeGoPointer(slice)
if err != nil {
return err
}
*/
return c.w.LoadValuesFromSLice(handle, slice, int32(length))
}
//LoadWvaluesEX takes a reader and coppies the bytes over to the weights
func (c *Layer) LoadWvaluesEX(handle *cudnn.Handler, r io.Reader) error {
rw := crtutil.NewReadWriter(c.w, c.w.SIB(), handle.Stream())
_, err := io.Copy(rw, r)
return err
}
//LoadBiasValues will load a slice into cuda memory for the Weights.
func (c *Layer) LoadBiasValues(handle *cudnn.Handler, slice interface{}, length int) error {
/*ptr, err := gocudnn.MakeGoPointer(slice)
if err != nil {
return err
}*/
return c.bias.LoadValuesFromSLice(handle, slice, int32(length))
}
//LoadBiasValuesEX takes a reader and coppies the bytes over to the bias
func (c *Layer) LoadBiasValuesEX(handle *cudnn.Handler, r io.Reader) error {
rw := crtutil.NewReadWriter(c.bias, c.bias.SIB(), handle.Stream())
_, err := io.Copy(rw, r)
return err
}
/*
//LoaddWValues will load a slice into cuda memory for the delta Weights.
func (c *Layer) LoaddWValues(handle *cudnn.Handler, slice interface{}) error {
ptr, err := gocudnn.MakeGoPointer(slice)
if err != nil {
return err
}
return c.w.LoadDeltaTValues(handle, ptr)
}
/*
//BiasImgs returns 2d array of images
func (c *Layer) BiasImgs() ([][]image.Image, [][]image.Image, error) {
return c.bias.Images()
}
*/
//WeightsFillSlice will fill a slice with the weight values
func (c *Layer) WeightsFillSlice(h *cudnn.Handler, input interface{}, length int) error {
return c.w.FillSlice(h, input)
// return c.w.T().Memer().FillSlice(input)
}
//DeltaWeightsFillSlice will fill the weights with values
func (c *Layer) DeltaWeightsFillSlice(h *cudnn.Handler, input interface{}, length int) error {
return c.w.FillSlice(h, input)
// return c.w.DeltaT().Memer().FillSlice(input)
}
/*
//SetupWStatReducers builds the statistic reducers for the w part of the Weights and bias
func (c *Layer) SetupWStatReducers(handle *cudnn.Handler) (err error) {
err = c.w.SetXStatReducers(handle)
if err != nil {
return err
}
err = c.bias.SetXStatReducers(handle)
if err != nil {
return err
}
return nil
}
//SetupDWStatReducers b builds the statistic reducers for the dw part of the Weights and bias
func (c *Layer) SetupDWStatReducers(handle *cudnn.Handler) (err error) {
err = c.dw.SetXStatReducers(handle)
if err != nil {
return err
}
err = c.dbias.SetXStatReducers(handle)
if err != nil {
return err
}
return nil
}
*/
/*
Weights
*/
//WMax returns the Max weight value for the layer.
func (c *Layer) WMax(handle *cudnn.Handler) (float32, error) {
return c.w.MaxX(handle)
}
//WMin returns the Min weight value for the layer
func (c *Layer) WMin(handle *cudnn.Handler) (float32, error) {
return c.w.MinX(handle)
}
// WAvg returns the avg weight value for the layer
func (c *Layer) WAvg(handle *cudnn.Handler) (float32, error) {
return c.w.AvgX(handle)
}
// WNorm1 returns the norm1 weight value for the layer
func (c *Layer) WNorm1(handle *cudnn.Handler) (float32, error) {
return c.w.Norm1X(handle)
}
// WNorm2 returns the norm2 weight value for the layer
func (c *Layer) WNorm2(handle *cudnn.Handler) (float32, error) {
return c.w.Norm2X(handle)
}
/*
Bias
*/
//BMax returns the Max bias value for the layer
func (c *Layer) BMax(handle *cudnn.Handler) (float32, error) {
return c.bias.MaxX(handle)
}
//BMin returns the Min bias value for the layer
func (c *Layer) BMin(handle *cudnn.Handler) (float32, error) {
return c.bias.MinX(handle)
}
// BAvg returns the avg weight value for the layer
func (c *Layer) BAvg(handle *cudnn.Handler) (float32, error) {
return c.bias.AvgX(handle)
}
// BNorm1 returns the norm1 bias value for the layer
func (c *Layer) BNorm1(handle *cudnn.Handler) (float32, error) {
return c.bias.Norm1X(handle)
}
// BNorm2 returns the norm2 bias value for the layer
func (c *Layer) BNorm2(handle *cudnn.Handler) (float32, error) {
return c.bias.Norm2X(handle)
}
/*
Delta Weights
*/
//DWMax returns the Max delta weight value for the layer
func (c *Layer) DWMax(handle *cudnn.Handler) (float32, error) {
return c.dw.MaxX(handle)
}
//DWMin returns the Min delta weight value for the layer
func (c *Layer) DWMin(handle *cudnn.Handler) (float32, error) {
return c.dw.MinX(handle)
}
// DWAvg returns the avg delta weight value for the layer
func (c *Layer) DWAvg(handle *cudnn.Handler) (float32, error) {
return c.dw.AvgX(handle)
}
// DWNorm1 returns the norm1 delta weight value for the layer
func (c *Layer) DWNorm1(handle *cudnn.Handler) (float32, error) {
return c.dw.Norm1X(handle)
}
// DWNorm2 returns the norm2 delta weight value for the layer
func (c *Layer) DWNorm2(handle *cudnn.Handler) (float32, error) {
return c.dw.Norm2X(handle)
}
/*
Delta Bias
*/
//DBMax returns the Max delta bias value for the layer
func (c *Layer) DBMax(handle *cudnn.Handler) (float32, error) {
return c.dbias.MaxX(handle)
}
//DBMin returns the Min delta bias value for the layer
func (c *Layer) DBMin(handle *cudnn.Handler) (float32, error) {
return c.dbias.MinX(handle)
}
// DBAvg returns the avg delta bias value for the layer
func (c *Layer) DBAvg(handle *cudnn.Handler) (float32, error) {
return c.dbias.AvgX(handle)
}
// DBNorm1 returns the norm1 delta bias value for the layer
func (c *Layer) DBNorm1(handle *cudnn.Handler) (float32, error) {
return c.dbias.Norm1X(handle)
}
// DBNorm2 returns the norm2 delta bias value for the layer
func (c *Layer) DBNorm2(handle *cudnn.Handler) (float32, error) {
return c.dbias.Norm2X(handle)
}