1
1
function NNlib. conv! (
2
2
y:: ROCArray{T, N} , x:: ROCArray{T, N} , w:: ROCArray{T, N} , cdims:: DenseConvDims ,
3
3
) where {T <: MIOPENFloat , N}
4
- NNlib. flipkernel (cdims) || throw (ArgumentError (
5
- " MIOpen supports only cross-correlation as its convolution implementation." ))
4
+ if ! NNlib. flipkernel (cdims)
5
+ @warn """
6
+ MIOpen supports only cross-correlation (flipkernel=true).
7
+ Therefore for every regular convolution (flipkernel=false)
8
+ kernel is flipped before calculation.
9
+ For better performance, use cross-correlation (flipkernel=true)
10
+ and manually flip the kernel before `NNlib.conv` call.
11
+ """ maxlog= 1
12
+ flip_dims = ntuple (
13
+ i -> (i ≤ ndims (w) - 2 ) ? (size (w, i): - 1 : 1 ) : Colon (),
14
+ ndims (w))
15
+ w = w[flip_dims... ]
16
+ end
6
17
7
18
nd = max (0 , 4 - N)
8
19
ncdims = NNlib. insert_singleton_spatial_dimension (cdims, nd)
18
29
function NNlib. ∇conv_data! (
19
30
dx:: ROCArray{T, N} , dy:: ROCArray{T, N} , w:: ROCArray{T, N} , cdims:: DenseConvDims ,
20
31
) where {T <: MIOPENFloat , N}
21
- NNlib. flipkernel (cdims) || throw (ArgumentError (
22
- " MIOpen supports only cross-correlation as its convolution implementation." ))
32
+ if ! NNlib. flipkernel (cdims)
33
+ @warn """
34
+ MIOpen supports only cross-correlation (flipkernel=true).
35
+ Therefore for every regular convolution (flipkernel=false)
36
+ kernel is flipped before calculation.
37
+ For better performance, use cross-correlation (flipkernel=true)
38
+ and manually flip the kernel before `NNlib.conv` call.
39
+ """ maxlog= 1
40
+ flip_dims = ntuple (
41
+ i -> (i ≤ ndims (w) - 2 ) ? (size (w, i): - 1 : 1 ) : Colon (),
42
+ ndims (w))
43
+ w = w[flip_dims... ]
44
+ end
23
45
24
46
nd = max (0 , 4 - N)
25
47
ncdims = NNlib. insert_singleton_spatial_dimension (cdims, nd)
35
57
function NNlib. ∇conv_filter! (
36
58
dw:: ROCArray{T, N} , x:: ROCArray{T, N} , dy:: ROCArray{T, N} , cdims:: DenseConvDims ,
37
59
) where {T <: MIOPENFloat , N}
38
- NNlib. flipkernel (cdims) || throw (ArgumentError (
39
- " MIOpen supports only cross-correlation as its convolution implementation." ))
40
-
41
60
nd = max (0 , 4 - N)
42
61
ncdims = NNlib. insert_singleton_spatial_dimension (cdims, nd)
43
62
MIOpen.∇convolution_weight! (
@@ -46,5 +65,19 @@ function NNlib.∇conv_filter!(
46
65
NNlib. insert_singleton_spatial_dimension (x, nd);
47
66
padding= nnlib_padding (ncdims), stride= NNlib. stride (ncdims),
48
67
dilation= NNlib. dilation (ncdims), groups= NNlib. groupcount (ncdims))
68
+
69
+ if ! NNlib. flipkernel (cdims)
70
+ @warn """
71
+ MIOpen supports only cross-correlation (flipkernel=true).
72
+ Therefore for every regular convolution (flipkernel=false)
73
+ kernel is flipped before calculation.
74
+ For better performance, use cross-correlation (flipkernel=true)
75
+ and manually flip the kernel before `NNlib.conv` call.
76
+ """ maxlog= 1
77
+ flip_dims = ntuple (
78
+ i -> (i ≤ ndims (dw) - 2 ) ? (size (dw, i): - 1 : 1 ) : Colon (),
79
+ ndims (dw))
80
+ dw = dw[flip_dims... ]
81
+ end
49
82
return dw
50
83
end
0 commit comments