Skip to content

Commit e822a4b

Browse files
authored
Remove timer outputs as they mess with type inference (#129)
Remove timer outputs as they mess with type inference
2 parents a80bdff + 5449ebc commit e822a4b

File tree

13 files changed

+101
-111
lines changed

13 files changed

+101
-111
lines changed

Manifest.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e"
99
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
1010
version = "0.5.3"
1111

12-
[[Crayons]]
13-
deps = ["Test"]
14-
git-tree-sha1 = "f621b8ef51fd2004c7cf157ea47f027fdeac5523"
15-
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
16-
version = "4.0.0"
17-
1812
[[Dates]]
1913
deps = ["Printf"]
2014
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -87,12 +81,6 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
8781
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
8882
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8983

90-
[[TimerOutputs]]
91-
deps = ["Crayons", "Printf", "Test", "Unicode"]
92-
git-tree-sha1 = "b80671c06f8f8bae08c55d67b5ce292c5ae2660c"
93-
uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
94-
version = "0.5.0"
95-
9684
[[UUIDs]]
9785
deps = ["Random", "SHA"]
9886
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1010
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
11-
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
1211

1312
[extras]
1413
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/NNlib.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module NNlib
2-
using Requires, TimerOutputs
3-
4-
const to = TimerOutput()
5-
2+
using Requires
63

74
# Include APIs
85
include("dim_helpers.jl")

src/conv.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ for (front_name, backend) in (
4545
# We only define 3d conv primitives, we reshape lower down to get 1d and 2d convolution
4646
@eval begin
4747
# im2col-accelerated function forwarding definition
48-
@timeit_debug to function $(Symbol("$(front_name)!"))(
48+
function $(Symbol("$(front_name)!"))(
4949
out::AbstractArray{T,5}, in1::AbstractArray{T,5},
5050
in2::AbstractArray{T,5}, cdims::ConvDims; kwargs...) where {T <: $G}
5151
$(Symbol("$(front_name)_$(backend)!"))(out, in1, in2, cdims; kwargs...)
@@ -106,7 +106,7 @@ for backend in (Symbol(), :_direct, :_im2col)
106106
# First make auto-allocating versions of the conv()-like calls:
107107
for name in (:conv, :depthwiseconv)
108108
@eval begin
109-
@timeit_debug to function $(Symbol("$(name)$(backend)"))(
109+
function $(Symbol("$(name)$(backend)"))(
110110
x::AbstractArray{xT,N}, w::AbstractArray{wT,N},
111111
cdims::ConvDims; kwargs...) where {xT, wT, N}
112112
y = similar(x, promote_type(xT, wT), output_size(cdims)...,
@@ -118,7 +118,7 @@ for backend in (Symbol(), :_direct, :_im2col)
118118

119119
for name in (:∇conv_data, :∇depthwiseconv_data)
120120
@eval begin
121-
@timeit_debug to function $(Symbol("$(name)$(backend)"))(
121+
function $(Symbol("$(name)$(backend)"))(
122122
dy::AbstractArray{yT,N}, w::AbstractArray{wT,N},
123123
cdims::ConvDims; kwargs...) where {yT, wT, N}
124124
dx = similar(dy, input_size(cdims)..., channels_in(cdims),
@@ -131,7 +131,7 @@ for backend in (Symbol(), :_direct, :_im2col)
131131
# We do the conv/depthwiseconv filter backprops separately, as the shape calculation
132132
# for `w` is slightly different for depthwise than for normal dense convolution.
133133
@eval begin
134-
@timeit_debug to function $(Symbol("∇conv_filter$(backend)"))(
134+
function $(Symbol("∇conv_filter$(backend)"))(
135135
x::AbstractArray{xT,N}, dy::AbstractArray{yT,N},
136136
cdims::ConvDims; kwargs...) where {xT, yT, N}
137137
dw = similar(dy, kernel_size(cdims)..., channels_in(cdims),
@@ -141,7 +141,7 @@ for backend in (Symbol(), :_direct, :_im2col)
141141
end
142142

143143
@eval begin
144-
@timeit_debug to function $(Symbol("∇depthwiseconv_filter$(backend)"))(
144+
function $(Symbol("∇depthwiseconv_filter$(backend)"))(
145145
x::AbstractArray{xT,N}, dy::AbstractArray{yT,N},
146146
cdims::ConvDims; kwargs...) where {xT, yT, N}
147147
dw = similar(dy, kernel_size(cdims)..., channel_multiplier(cdims),

src/impl/conv_direct.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ wrapper methods are available.
4444
"""
4545
conv_direct!
4646

47-
@timeit_debug to function conv_direct!(y::AbstractArray{yT,5}, x::AbstractArray{xT,5},
47+
function conv_direct!(y::AbstractArray{yT,5}, x::AbstractArray{xT,5},
4848
w::AbstractArray{wT,5}, cdims::DenseConvDims;
4949
alpha::yT = yT(1), beta = false) where {yT, xT, wT}
5050
check_dims(size(x), size(w), size(y), cdims)
@@ -114,7 +114,7 @@ Calculate the gradient imposed upon `x` in the convolution `y = x * w`.
114114
"""
115115
∇conv_data_direct!
116116

117-
@timeit_debug to function ∇conv_data_direct!(dx::AbstractArray{xT,5}, dy::AbstractArray{yT,5},
117+
function ∇conv_data_direct!(dx::AbstractArray{xT,5}, dy::AbstractArray{yT,5},
118118
w::AbstractArray{wT,5}, cdims::DenseConvDims;
119119
alpha::xT=xT(1), beta=false) where {xT, yT, wT}
120120
w = transpose_swapbatch(w[end:-1:1, end:-1:1, end:-1:1, :, :])
@@ -133,7 +133,7 @@ Calculate the gradient imposed upon `w` in the convolution `y = x * w`.
133133
"""
134134
∇conv_filter_direct!
135135

136-
@timeit_debug to function ∇conv_filter_direct!(dw::AbstractArray{wT,5}, x::AbstractArray{xT,5},
136+
function ∇conv_filter_direct!(dw::AbstractArray{wT,5}, x::AbstractArray{xT,5},
137137
dy::AbstractArray{yT,5}, cdims::DenseConvDims;
138138
alpha::wT=wT(1), beta=false) where {xT, yT, wT}
139139
x = transpose_swapbatch(x[end:-1:1, end:-1:1, end:-1:1, :, :])

src/impl/conv_im2col.jl

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ by setting `alpha` to a nonunitary value, various gain factors can be applied.
2222
Note for the particularly performance-minded, you can provide a pre-allocated `col`,
2323
which should eliminate any need for large allocations within this method.
2424
"""
25-
@timeit_debug to function conv_im2col!(
25+
function conv_im2col!(
2626
y::AbstractArray{T,5}, x::AbstractArray{T,5},
2727
w::AbstractArray{T,5}, cdims::DenseConvDims;
2828
col::AbstractArray{T,2}=similar(x, im2col_dims(cdims)),
@@ -49,12 +49,12 @@ which should eliminate any need for large allocations within this method.
4949
@inbounds for batch_idx in 1:size(x,5)
5050
# We invoke `@timeit_debug` on the outside of `im2col!()` because inference
5151
# doesn't like us putting it on the inside.
52-
@timeit_debug to "im2col!" im2col!(col, view(x, :, :, :, :, batch_idx), cdims)
52+
im2col!(col, view(x, :, :, :, :, batch_idx), cdims)
5353
GC.@preserve col, w, y, begin
5454
col_ptr = pointer(col)
5555
w_ptr = pointer(w)
5656
y_ptr = pointer(y, (batch_idx - 1)*M*N + 1)
57-
@timeit_debug to "gemm!" gemm!(Val(false), Val(false), M, N, K, alpha, col_ptr, w_ptr, beta, y_ptr)
57+
gemm!(Val(false), Val(false), M, N, K, alpha, col_ptr, w_ptr, beta, y_ptr)
5858
end
5959
end
6060
return y
@@ -66,7 +66,7 @@ end
6666
Conv backward pass onto the weights using im2col and GEMM; stores the result in `dw`.
6767
See the documentation for `conv_im2col!()` for explanation of optional parameters.
6868
"""
69-
@timeit_debug to function ∇conv_filter_im2col!(
69+
function ∇conv_filter_im2col!(
7070
dw::AbstractArray{T,5}, x::AbstractArray{T,5},
7171
dy::AbstractArray{T,5}, cdims::DenseConvDims;
7272
col::AbstractArray{T,2} = similar(dw, im2col_dims(cdims)),
@@ -95,14 +95,12 @@ See the documentation for `conv_im2col!()` for explanation of optional parameter
9595
K = prod(output_size(cdims))
9696

9797
@inbounds for batch_idx in 1:size(x,5)
98-
# We invoke `@timeit_debug` on the outside of `im2col!()` because inference
99-
# doesn't like us putting it on the inside.
100-
@timeit_debug to "im2col!" im2col!(col, view(x, :, :, :, :, batch_idx), cdims)
98+
im2col!(col, view(x, :, :, :, :, batch_idx), cdims)
10199
GC.@preserve col, dw, dy, begin
102100
col_ptr = pointer(col)
103101
dy_ptr = pointer(dy,(batch_idx - 1)*K*N + 1)
104102
dw_ptr = pointer(dw)
105-
@timeit_debug to "gemm!" gemm!(Val(true), Val(false), M, N, K, alpha, col_ptr, dy_ptr, beta, dw_ptr)
103+
gemm!(Val(true), Val(false), M, N, K, alpha, col_ptr, dy_ptr, beta, dw_ptr)
106104
end
107105

108106
# Because we accumulate over batches in this loop, we must set `beta` equal
@@ -118,7 +116,7 @@ end
118116
Conv2d backward pass onto the input using im2col and GEMM; stores the result in `dx`.
119117
See the documentation for `conv_im2col!()` for explanation of other parameters.
120118
"""
121-
@timeit_debug to function ∇conv_data_im2col!(
119+
function ∇conv_data_im2col!(
122120
dx::AbstractArray{T,5}, dy::AbstractArray{T,5},
123121
w::AbstractArray{T,5}, cdims::DenseConvDims;
124122
col::AbstractArray{T,2} = similar(dx, im2col_dims(cdims)),
@@ -149,9 +147,9 @@ See the documentation for `conv_im2col!()` for explanation of other parameters.
149147
dy_ptr = pointer(dy, (batch_idx - 1)*M*K + 1)
150148
w_ptr = pointer(w)
151149
col_ptr = pointer(col)
152-
@timeit_debug to "gemm!" gemm!(Val(false), Val(true), M, N, K, alpha, dy_ptr, w_ptr, T(0), col_ptr)
150+
gemm!(Val(false), Val(true), M, N, K, alpha, dy_ptr, w_ptr, T(0), col_ptr)
153151
end
154-
@timeit_debug to "col2im!" col2im!(view(dx, :, :, :, :, batch_idx), col, cdims)
152+
col2im!(view(dx, :, :, :, :, batch_idx), col, cdims)
155153
end
156154
return dx
157155
end
@@ -207,77 +205,74 @@ function im2col!(col::AbstractArray{T,2}, x::AbstractArray{T,4},
207205
# We begin by copying the central region of the image which requires no padding at all.
208206
# Eliminating the branches of the fully generalized version below gives us a nice
209207
# speedup on the majority of the data.
210-
@timeit_debug to "im2col!() - central region" begin
211-
@inbounds for c in 1:C_in
212-
# Unpack "central region"
213-
w_region, h_region, d_region = central_region
214-
215-
for kd in 1:kernel_d,
216-
kh in 1:kernel_h,
217-
kw in 1:kernel_w,
218-
d in d_region,
219-
h in h_region,
220-
w in w_region
221-
222-
input_kd = project(d, stride_d, pad_d_lo) + (kd - 1)*dil_d
223-
input_kh = project(h, stride_h, pad_h_lo) + (kh - 1)*dil_h
224-
input_kw = project(w, stride_w, pad_w_lo) + (kw - 1)*dil_w
225-
kidxs = kernel_index(kw, kh, kd, cdims)
208+
@inbounds for c in 1:C_in
209+
# Unpack "central region"
210+
w_region, h_region, d_region = central_region
226211

227-
xval::T = x[input_kw, input_kh, input_kd, c]
228-
col_reshaped[w, h, d, kidxs..., c] = xval
229-
end
212+
for kd in 1:kernel_d,
213+
kh in 1:kernel_h,
214+
kw in 1:kernel_w,
215+
d in d_region,
216+
h in h_region,
217+
w in w_region
218+
219+
input_kd = project(d, stride_d, pad_d_lo) + (kd - 1)*dil_d
220+
input_kh = project(h, stride_h, pad_h_lo) + (kh - 1)*dil_h
221+
input_kw = project(w, stride_w, pad_w_lo) + (kw - 1)*dil_w
222+
kidxs = kernel_index(kw, kh, kd, cdims)
223+
224+
xval::T = x[input_kw, input_kh, input_kd, c]
225+
col_reshaped[w, h, d, kidxs..., c] = xval
230226
end
231227
end
232228

229+
233230
# For each "padded region", we run the fully general version
234-
@timeit_debug to "im2col!() - padded region" begin
235-
@inbounds for (w_region, h_region, d_region) in padded_regions
236-
for c in 1:C_in,
237-
d in d_region,
238-
h in h_region,
239-
w in w_region,
240-
kd in 1:kernel_d,
241-
kh in 1:kernel_h,
242-
kw in 1:kernel_w
231+
@inbounds for (w_region, h_region, d_region) in padded_regions
232+
for c in 1:C_in,
233+
d in d_region,
234+
h in h_region,
235+
w in w_region,
236+
kd in 1:kernel_d,
237+
kh in 1:kernel_h,
238+
kw in 1:kernel_w
243239

244-
input_kd = project(d, stride_d, pad_d_lo) + (kd - 1)*dil_d
245-
input_kh = project(h, stride_h, pad_h_lo) + (kh - 1)*dil_h
246-
input_kw = project(w, stride_w, pad_w_lo) + (kw - 1)*dil_w
240+
input_kd = project(d, stride_d, pad_d_lo) + (kd - 1)*dil_d
241+
input_kh = project(h, stride_h, pad_h_lo) + (kh - 1)*dil_h
242+
input_kw = project(w, stride_w, pad_w_lo) + (kw - 1)*dil_w
247243

248-
kidxs = kernel_index(kw, kh, kd, cdims)
244+
kidxs = kernel_index(kw, kh, kd, cdims)
249245

250-
# If this d is off the edge, then deal with the entire plane
251-
# in one fell swoop, like a ravenous flock of crows. CAW CAW.
252-
if input_kd <= 0 || input_kd > depth
253-
for kh in 1:kernel_h,
254-
kw in 1:kernel_w
255-
col_reshaped[w, h, d, kidxs..., c] = T(0)
256-
end
257-
continue
258-
end
259-
260-
# Same for `h`, but in this case it's only a line, not a plane.
261-
# This results in slightly less caw'ing.
262-
if input_kh <= 0 || input_kh > height
263-
for kw in 1:kernel_w
264-
col_reshaped[w, h, d, kidxs..., c] = T(0)
265-
end
266-
continue
246+
# If this d is off the edge, then deal with the entire plane
247+
# in one fell swoop, like a ravenous flock of crows. CAW CAW.
248+
if input_kd <= 0 || input_kd > depth
249+
for kh in 1:kernel_h,
250+
kw in 1:kernel_w
251+
col_reshaped[w, h, d, kidxs..., c] = T(0)
267252
end
253+
continue
254+
end
268255

269-
# If this `w` is off the edge it and only it gets cleared out
270-
if input_kw <= 0 || input_kw > width
256+
# Same for `h`, but in this case it's only a line, not a plane.
257+
# This results in slightly less caw'ing.
258+
if input_kh <= 0 || input_kh > height
259+
for kw in 1:kernel_w
271260
col_reshaped[w, h, d, kidxs..., c] = T(0)
272-
continue
273261
end
262+
continue
263+
end
274264

275-
# Copy the data over
276-
xval::T = x[input_kw, input_kh, input_kd, c]
277-
col_reshaped[w, h, d, kidxs..., c] = xval
265+
# If this `w` is off the edge it and only it gets cleared out
266+
if input_kw <= 0 || input_kw > width
267+
col_reshaped[w, h, d, kidxs..., c] = T(0)
268+
continue
278269
end
270+
271+
# Copy the data over
272+
xval::T = x[input_kw, input_kh, input_kd, c]
273+
col_reshaped[w, h, d, kidxs..., c] = xval
279274
end
280-
end
275+
end
281276
end
282277

283278

src/impl/depthwiseconv_direct.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ channels in `x` is the last, not the second-to-last, as in a normal dense convol
1818
1919
See the docstring for `conv_direct!()` for more on the optional parameters.
2020
"""
21-
@timeit_debug to function depthwiseconv_direct!(
21+
function depthwiseconv_direct!(
2222
y::AbstractArray{yT,5}, x::AbstractArray{xT,5},
2323
w::AbstractArray{wT,5}, cdims::DepthwiseConvDims;
2424
alpha::yT = yT(1), beta::yT = yT(0)) where {yT, xT, wT}
@@ -95,7 +95,7 @@ for each batch and channel independently.
9595
"""
9696
∇depthwiseconv_data_direct!
9797

98-
@timeit_debug to function ∇depthwiseconv_data_direct!(
98+
function ∇depthwiseconv_data_direct!(
9999
dx::AbstractArray{xT,5}, dy::AbstractArray{yT,5},
100100
w::AbstractArray{wT,5}, cdims::DepthwiseConvDims;
101101
alpha::xT=xT(1), beta::xT=xT(0)) where {xT, yT, wT}
@@ -128,7 +128,7 @@ Calculate the gradient imposed upon `w` in the depthwise convolution `y = x * w`
128128
"""
129129
∇depthwiseconv_filter_direct!
130130

131-
@timeit_debug to function ∇depthwiseconv_filter_direct!(
131+
function ∇depthwiseconv_filter_direct!(
132132
dw::AbstractArray{wT,5}, x::AbstractArray{xT,5},
133133
dy::AbstractArray{yT,5}, cdims::DepthwiseConvDims;
134134
alpha::wT=wT(1),beta::wT=wT(0)) where {xT, yT, wT}

0 commit comments

Comments
 (0)