Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convolution regression #23

Open
cafaxo opened this issue Dec 4, 2022 · 1 comment
Open

Convolution regression #23

cafaxo opened this issue Dec 4, 2022 · 1 comment

Comments

@cafaxo
Copy link

cafaxo commented Dec 4, 2022

Using StrideArraysCore 0.3.17, the following works as expected:

julia> using StrideArraysCore, LoopVectorization, BenchmarkTools

julia> using LayoutPointers: zero_offsets

julia> function conv!(f::F, _C, _A, _K, _b) where {F}
           C = zero_offsets(_C)
           A = zero_offsets(_A)
           K = zero_offsets(_K)
           b = zero_offsets(_b)

           @turbo for j₁ ∈ axes(C, 1), j₂ ∈ axes(C, 2), o ∈ axes(K, 4)
               s = zero(eltype(C))
               for k₁ ∈ axes(K, 1), k₂ ∈ axes(K, 2), i ∈ axes(K, 3)
                   s += A[j₁+k₁, j₂+k₂, i] * K[k₁, k₂, i, o]
               end
               C[j₁, j₂, o] = f(s + b[o])
           end

           return nothing
       end
conv! (generic function with 1 method)

julia> randn_stridearray(size...) = StrideArray(randn(Float32, size...), static.(size));

julia> C = randn_stridearray(8, 8, 4);

julia> A = randn_stridearray(10, 10, 4);

julia> K = randn_stridearray(3, 3, 4, 4);

julia> b = randn_stridearray(4);

julia> @btime conv!($identity, $C, $A, $K, $b)
  213.707 ns (0 allocations: 0 bytes)

(I am using the convolution code from SimpleChains.jl)
After upgrading to StrideArraysCore 0.4.1, I get

julia> @btime conv!($identity, $C, $A, $K, $b)
  316.417 μs (1728 allocations: 101.50 KiB)
@chriselrod
Copy link
Member

Thanks for the issue; fixed by 9d3f77d for Julia 1.7 and newer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants