1
+ function check_support (x, k, pad, stride, dilation = 0 )
2
+ dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
3
+ pad_, stride_ = expand (Val{length (k)}, pad), expand (Val{length (k)}, stride)
4
+ ((size (x, 1 ) - k[1 ] + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - k[2 ] + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
5
+ return pad_, stride_
6
+ end
7
+
1
8
# NOTE: Commenting out the activation functions until sure what to do
2
9
3
- # relu(x::AA1) = nnp_relu_output(x, inplace ? x : similar(x), threadpool = shared_threadpool)
10
+ # relu(x::AA1) = nnp_relu_output(x, inplace ? x : similar(x), threadpool = shared_threadpool[] )
4
11
5
12
# leakyrelu(x::AA1, a = oftype(x/1, 0.01)) =
6
- # nnp_relu_output(x, inplace ? x : similar(x), negative_slope = a, threadpool = shared_threadpool)
13
+ # nnp_relu_output(x, inplace ? x : similar(x), negative_slope = a, threadpool = shared_threadpool[] )
7
14
8
15
softmax! (x:: A ) where A<: AbstractVecOrMat{Float64} = softmax! (Float32 .(x))
9
16
10
17
softmax! (x:: A ) where A<: AbstractVecOrMat{Float32} =
11
- nnp_softmax_output (x, x, threadpool = shared_threadpool)
18
+ nnp_softmax_output (x, x, threadpool = shared_threadpool[] )
12
19
13
20
softmax! (y:: A , x:: A ) where A<: AbstractVecOrMat{Float64} = softmax! (Float32 .(y), Float32 .(x))
14
21
15
22
softmax! (y:: A , x:: A ) where A<: AbstractVecOrMat{Float32} =
16
- nnp_softmax_output (x, y, threadpool = shared_threadpool)
23
+ nnp_softmax_output (x, y, threadpool = shared_threadpool[] )
17
24
18
25
softmax (x:: A ) where A<: AbstractVecOrMat{Float64} = softmax (Float32 .(x))
19
26
20
27
softmax (x:: A ) where A<: AbstractVecOrMat{Float32} =
21
- nnp_softmax_output (x, similar (x), threadpool = shared_threadpool)
28
+ nnp_softmax_output (x, similar (x), threadpool = shared_threadpool[] )
22
29
23
30
maxpool (x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float64, 4} =
24
31
maxpool (Float32 .(x), k, pad = pad, stride = stride)
25
32
26
33
function maxpool (x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float32, 4}
27
- pad_, stride_ = expand (Val{length (k)}, pad), expand (Val{length (k)}, stride)
28
- ((size (x, 1 ) - k[1 ] + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - k[2 ] + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
34
+ pad_, stride_ = check_support (x, k, pad, stride)
29
35
maxpool! (similar (x, pdims (size (x), k, pad_, stride_)), x, k, pad = pad_, stride = stride_)
30
36
end
31
37
32
38
maxpool! (y:: A , x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float64, 4} =
33
39
maxpool! (Float32 .(y), Float32 .(x), k, pad = pad, stride = stride)
34
40
35
41
maxpool! (y:: A , x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float32, 4} =
36
- nnp_max_pooling_output (x, y, k, padding = expand (Val{length (k)}, pad), stride = expand (Val{length (k)}, stride), threadpool = shared_threadpool)
42
+ nnp_max_pooling_output (x, y, k, padding = expand (Val{length (k)}, pad), stride = expand (Val{length (k)}, stride), threadpool = shared_threadpool[] )
37
43
38
44
conv (x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float64, 4} =
39
45
conv (Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo)
40
46
41
47
function conv (x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float32, 4}
42
- dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
43
- pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
44
- ((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
48
+ pad_, stride_ = check_support (x, k, pad, stride)
45
49
y = similar (x, cdims (size (x), dilation_dims (w, dilation), pad_, stride_))
46
50
b = zeros (Float32, size (y, 3 ))
47
51
conv! (y, x, w, b, pad = pad_, stride = stride_, dilation = dilation, algo = UInt32 (algo))
@@ -51,19 +55,15 @@ conv(x::A1, w::A1, b::A2; pad = 0, stride = 1, dilation = 1, algo = UInt32(0)) w
51
55
conv (Float32 .(x), Float32 .(w), Float32 .(b), pad = pad, stride = stride, dilation = dilation, algo = algo)
52
56
53
57
function conv (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} }
54
- dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
55
- pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
56
- ((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
58
+ pad_, stride_ = check_support (x, k, pad, stride)
57
59
conv! (similar (x, cdims (size (x), dilation_dims (w, dilation), pad_, stride_)), x, w, b, pad = pad_, stride = stride_, dilation = dilation, algo = UInt32 (algo))
58
60
end
59
61
60
62
crosscor (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float64, 4} , A2<: AbstractArray{Float64, 1} } =
61
63
crosscor (Float32 .(x), Float32 .(w), Float32 .(b), pad = pad, stride = stride, dilation = dilation, algo = algo)
62
64
63
65
function crosscor (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} }
64
- dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
65
- pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
66
- ((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
66
+ pad_, stride_ = check_support (x, k, pad, stride)
67
67
conv! (similar (x, cdims (size (x), dilation_dims (w, dilation), pad_, stride_)), x, w, b, pad = pad_, stride = stride_, dilation = dilation, algo = UInt32 (algo), flipkernel = 1 )
68
68
end
69
69
@@ -72,7 +72,7 @@ conv!(y::A1, x::A1, w::A1, b::A2; pad = 0, stride = 1, dilation = 1, algo = UInt
72
72
73
73
function conv! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} }
74
74
flipkernel == 0 && (w = reverse (reverse (w, dims= 1 ), dims= 2 ))
75
- nnp_convolution_output (y, x, w, b, algo = algo, padding = pad, stride = stride, threadpool = shared_threadpool)
75
+ nnp_convolution_output (y, x, w, b, algo = algo, padding = pad, stride = stride, threadpool = shared_threadpool[] )
76
76
end
77
77
78
78
crosscor! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float64, 4} , A2<: AbstractArray{Float64, 1} } =
@@ -85,9 +85,7 @@ crosscor!(y::A1, x::A1, w::A1, b::A2; pad = 0, stride = 1, dilation = 1, algo =
85
85
∇conv_data (Float32 .(dy), Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo)
86
86
87
87
function ∇conv_data (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float32, 4}
88
- dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
89
- pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
90
- ((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
88
+ pad_, stride_ = check_support (x, k, pad, stride)
91
89
∇conv_data! (zeros (Float32, size (x)), dy, x, w; pad = pad_, stride = stride_, dilation = dilation, algo = UInt32 (algo))
92
90
end
93
91
96
94
97
95
function ∇conv_data! (dx:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AbstractArray{Float32, 4}
98
96
flipkernel == 0 && (w = reverse (reverse (w, dims= 1 ), dims= 2 ))
99
- nnp_convolution_input_gradient (dx, x, dy, w, padding = pad, stride = stride, algo = algo, threadpool = shared_threadpool)
97
+ nnp_convolution_input_gradient (dx, x, dy, w, padding = pad, stride = stride, algo = algo, threadpool = shared_threadpool[] )
100
98
end
101
99
102
100
∇conv_filter (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float64, 4} =
103
101
∇conv_filter (Float32 .(dy), Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo)
104
102
105
103
function ∇conv_filter (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float32, 4}
106
- dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
107
- pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
108
- ((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
104
+ pad_, stride_ = check_support (x, k, pad, stride)
109
105
∇conv_filter! (zeros (Float32, size (w)), dy, x, w; pad = pad_, stride = stride_, dilation = dilation, algo = UInt32 (algo))
110
106
end
111
107
114
110
115
111
function ∇conv_filter! (dw:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AbstractArray{Float32, 4}
116
112
flipkernel == 0 && (w = reverse (reverse (w, dims= 1 ), dims= 2 ))
117
- dw .= nnp_convolution_kernel_gradient (dw, x, dy, w, padding = pad, stride = stride, algo = algo, threadpool = shared_threadpool)
113
+ dw .= nnp_convolution_kernel_gradient (dw, x, dy, w, padding = pad, stride = stride, algo = algo, threadpool = shared_threadpool[] )
118
114
flipkernel == 0 ? reverse (reverse (dw, dims= 1 ), dims= 2 ) : dw
119
115
end
0 commit comments