Skip to content

Commit f76a38d

Browse files
authored
Merge pull request #603 from LuxDL/ap/load_times
remove `NNPACK` and move `ForwardDiff` to an extension
2 parents 013aa51 + 393e830 commit f76a38d

16 files changed

+15
-599
lines changed

Project.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
99
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
1010
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
1111
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
12-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1312
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
14-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1513
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1614

1715
[weakdeps]
1816
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
1917
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
2018
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
2119
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
20+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2221
cuDNN = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd"
2322

2423
[extensions]
@@ -27,6 +26,7 @@ NNlibCUDACUDNNExt = ["CUDA", "cuDNN"]
2726
NNlibCUDAExt = "CUDA"
2827
NNlibEnzymeCoreExt = "EnzymeCore"
2928
NNlibFFTWExt = "FFTW"
29+
NNlibForwardDiffExt = "ForwardDiff"
3030

3131
[compat]
3232
AMDGPU = "0.9.4, 1"
@@ -36,12 +36,11 @@ CUDA = "4, 5"
3636
ChainRulesCore = "1.13"
3737
EnzymeCore = "0.5, 0.6, 0.7"
3838
FFTW = "1.8.0"
39+
ForwardDiff = "0.10.36"
3940
GPUArraysCore = "0.1"
4041
KernelAbstractions = "0.9.2"
4142
LinearAlgebra = "<0.0.1, 1"
42-
Pkg = "<0.0.1, 1"
4343
Random = "<0.0.1, 1"
44-
Requires = "1.0"
4544
Statistics = "1"
4645
cuDNN = "1"
4746
julia = "1.9"

benchmark/perf_report.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ for rank in (2,),
3737
(NNlib.depthwiseconv_im2col!, NNlib.∇depthwiseconv_data_im2col!, NNlib.∇depthwiseconv_filter_im2col!, DepthwiseConvDims, "im2col"),
3838
]
3939

40-
if NNlib.is_nnpack_available()
41-
push!(benchmark_items, (NNlib.conv_nnpack!, NNlib.∇conv_data_nnpack!, NNlib.∇conv_filter_nnpack!, DenseConvDims, "nnpack"))
42-
end
43-
4440
for (conv!, ∇conv_data!, ∇conv_filter!, cT, backend) in benchmark_items
4541

4642
x = zeros(Float32, repeat([N], rank)..., C_in, 1)
@@ -105,15 +101,4 @@ for rank in (2,),
105101
@show(pdims)
106102
@save "results.jld2" results
107103
end
108-
109-
if NNlib.is_nnpack_available()
110-
if NNlib.nnpack_supported_operation(pdims)
111-
t_fwd = @benchmark NNlib.maxpool_nnpack!($y, $x, $pdims)
112-
113-
add_result(t_fwd, "maxpool2d", "nnpack", pdims)
114-
115-
@show(pdims)
116-
@save "results.jld2" results
117-
end
118-
end
119104
end

ext/NNlibForwardDiffExt.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module NNlibForwardDiffExt
2+
3+
using ForwardDiff: ForwardDiff
4+
using NNlib: NNlib
5+
6+
NNlib.within_gradient(x::ForwardDiff.Dual) = true
7+
NNlib.within_gradient(x::AbstractArray{<:ForwardDiff.Dual}) = true
8+
9+
end

src/NNlib.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ using KernelAbstractions: @atomic
1212
using LinearAlgebra
1313
using LinearAlgebra.BLAS: @blasfunc, BlasInt
1414
using LinearAlgebra: AdjOrTransAbsMat, Adjoint, BlasFloat, Transpose
15-
using Pkg
1615
using Random
17-
using Requires
1816
using Statistics
1917
using Statistics: mean
2018

@@ -24,19 +22,6 @@ const Numeric = Union{AbstractArray{<:T}, T} where {T<:Number}
2422
include("dim_helpers.jl")
2523
export ConvDims, DenseConvDims, PoolDims, DepthwiseConvDims
2624

27-
is_nnpack_available() = false
28-
29-
@init @require NNPACK_jll="a6bfbf70-4841-5cb9-aa18-3a8ad3c413ee" begin
30-
if isdefined(NNPACK_jll, :libnnpack)
31-
include("nnpack/NNPACK.jl")
32-
else
33-
@warn "NNPACK not available for your platform: " *
34-
"$( Pkg.BinaryPlatforms.platform_name(Pkg.BinaryPlatforms.platform_key_abi()))" *
35-
"($( Pkg.BinaryPlatforms.triplet(Pkg.BinaryPlatforms.platform_key_abi())))
36-
You will be able to use only the default Julia NNlib backend"
37-
end
38-
end
39-
4025
include("activations.jl")
4126
for f in ACTIVATIONS
4227
@eval export $(f)
@@ -95,11 +80,6 @@ export upsample_nearest, ∇upsample_nearest,
9580
include("gather.jl")
9681
include("scatter.jl")
9782
include("utils.jl")
98-
@init @require ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" begin
99-
using .ForwardDiff
100-
within_gradient(x::ForwardDiff.Dual) = true
101-
within_gradient(x::AbstractArray{<:ForwardDiff.Dual}) = true
102-
end
10383

10484
include("sampling.jl")
10585
include("functions.jl")

src/conv.jl

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ end
7676
# Let's generate auto-allocating versions of all our functions, for all backends.
7777
# We `@timeit` these methods separately, as we want to know how much time is spent in
7878
# allocation. :P
79-
for backend in (Symbol(), :_direct, :_im2col, :_nnpack)
79+
for backend in (Symbol(), :_direct, :_im2col)
8080
# First make auto-allocating versions of the conv()-like calls:
8181
for name in (:conv, :depthwiseconv)
8282
@eval begin
@@ -134,7 +134,7 @@ end
134134
# since we can specialize on sizes.
135135
for front_name in (:conv, :∇conv_data, :∇conv_filter,
136136
:depthwiseconv, :∇depthwiseconv_data, :∇depthwiseconv_filter)
137-
for backend in (Symbol(), :_direct, :_im2col) ## NNPACK is only for 2d conv
137+
for backend in (Symbol(), :_direct, :_im2col)
138138
for N in (3, 4)
139139
@eval begin
140140
function $(Symbol("$(front_name)$(backend)!"))(
@@ -381,26 +381,3 @@ function rrule(::typeof(∇conv_filter), x, dy, cdims; kw...)
381381
end
382382
return ∇conv_filter(x, dy, cdims; kw...), ∇conv_filter_pullback
383383
end
384-
385-
# Use NNPACK if it is available and the operation is supported
386-
# commented out 'till proper benchmarking and more correctness test are performed
387-
# if is_nnpack_available()
388-
# function conv(x::Array{Float32, 4}, w::Array{Float32, 4},
389-
# cdims::DenseConvDims{2, K, C_in, C_out, (1, 1), P, (1, 1), F};
390-
# kwargs...) where {K, C_in, C_out, P, F}
391-
# return conv_nnpack(x, w, cdims; kwargs...)
392-
# end
393-
394-
# function ∇conv_data(dy::Array{Float32, 4}, w::Array{Float32, 4},
395-
# cdims::DenseConvDims{2, K, C_in, C_out, (1, 1), P, (1, 1), F};
396-
# kwargs...) where {K, C_in, C_out, P, F}
397-
# return ∇conv_data_nnpack(dy, w, cdims; kwargs...)
398-
# end
399-
400-
# function ∇conv_filter(x::Array{Float32, 4}, dy::Array{Float32, 4},
401-
# cdims::DenseConvDims{2, K, C_in, C_out, (1, 1), P, (1, 1), F};
402-
# kwargs...) where {K, C_in, C_out, P, F}
403-
# return ∇conv_filter_nnpack(x, dy, cdims; kwargs...)
404-
# end
405-
# end
406-
########################################################

src/nnpack/NNPACK.jl

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/nnpack/error.jl

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/nnpack/impl.jl

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/nnpack/interface.jl

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)