Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

add depthwise_conv* overloads for CUDA#22

Open
DhairyaLGandhi wants to merge 2 commits into
masterfrom
dg/depth
Open

add depthwise_conv* overloads for CUDA#22
DhairyaLGandhi wants to merge 2 commits into
masterfrom
dg/depth

Conversation

@DhairyaLGandhi
Copy link
Copy Markdown
Member

No description provided.

Comment thread src/cudnn/conv.jl
Comment on lines +99 to +112
function depthwise_conv!(y::DenseCuArray{T}, x::DenseCuArray{T}, w::DenseCuArray{T}, cdims::DepthwiseConvDims;
alpha = 1, beta = 0, algo = -1) where T <: CUDNNFloat
conv!(y, x, w, cims; alpha, beta, algo)
end

function ∇depthwise_conv_filter!(dw::DenseCuArray{T}, x::DenseCuArray{T}, dy::DenseCuArray{T},
cdims::ConvDims; alpha = 1, beta = 0, algo = -1) where T <: CUDNNFloat
∇conv_filter!(dw, x, dy, cdims; alpha, beta, algo)
end

function ∇depthwise_conv_data!(dx::DenseCuArray{T}, dy::DenseCuArray{T}, w::DenseCuArray{T},
cdims::ConvDims; alpha = 1, beta = 0, algo = -1) where T <: CUDNNFloat
∇conv_data!(dx, dy, w, cdims; alpha, beta, algo)
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't have to be cuda specific, we can add them to NNlib and remove the specific implementations (after a performance comparison)

Copy link
Copy Markdown
Member Author

@DhairyaLGandhi DhairyaLGandhi Jul 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add what to nnlib, sorry? This package is specific to GPU functionality.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly these methods, with AbstractArray arguments, i.e. fallback on conv

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, we probably want to retain the cpu kernels anyway. Without explicitly having and launching Julia with many threads, grouped convolutions would scale with the number of groups.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be true for any implementation, specialized or not

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> x′ = rand(Float32, 28, 28, 4, 2);

julia> w′ = rand(Float32, 3, 3, 4, 30);

julia> cdims = DenseConvDims(x′, w′, groups = 4)

julia> @btime conv($x′, $w′, $cdims);
 362.792 μs (86 allocations: 736.36 KiB) # -t1
 236.368 μs (94 allocations: 831.89 KiB) # -t2
 232.137 μs (94 allocations: 831.89 KiB) # -t4

julia> @btime depthwiseconv($x′, $(permutedims(w′, (1,2,4,3))));
 348.914 μs (42 allocations: 731.03 KiB) # -t1
 156.558 μs (47 allocations: 826.53 KiB) # -t2
 161.059 μs (47 allocations: 826.53 KiB) # -t4

This is with https://github.com/DhairyaLGandhi/NNlib.jl#dg/g2 which has a couple of fixes pending a PR.

Copy link
Copy Markdown
Member

@ToucheSir ToucheSir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, just needs a couple tests in https://github.com/FluxML/NNlibCUDA.jl/blob/master/test/conv.jl (I know the implementation is technically covered indirectly now, but there's no guarantee these methods will forward to the conv ones forever).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants