JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Suboptimal Choice of the Vecotrization Level for Image Convolution
- Vorherrschende Sprache
- Julia
- Sterne
- 789
- Forks
- 73
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
The following image convolution code shows a case where the choice of the vecotrization level is not optimized:
```julia
using BenchmarkTools;
using LoopVectorization;
function _Conv2DValidA!( mO :: Matrix{T}, mI :: Matrix{T}, mK :: Matrix{T} ) where {T <: AbstractFloat}
numRowsI, numColsI = size(mI);
numRowsK, numColsK = size(mK);
for jj ∈ 1:(numColsI - numColsK + 1)
@turbo for ii in 1:(numRowsI - numRowsK + 1)
sumVal = zero(T);
for nn ∈ 1:numColsK, mm ∈ 1:numRowsK
@inbounds sumVal += mK[mm, nn] * mI[ii - mm + numRowsK, jj - nn + numColsK];
end
mO[ii, jj] = sumVal;
end
end
end
function _Conv2DValidB!( mO :: Matrix{T}, mI :: Matrix{T}, mK :: Matrix{T} ) where {T <: AbstractFloat}
numRowsI, numColsI = size(mI);
numRowsK, numColsK = size(mK);
@turbo for jj ∈ 1:(numColsI - numColsK + 1)
for ii in 1:(numRowsI - numRowsK + 1)
sumVal = zero(T);
for nn ∈ 1:numColsK, mm ∈ 1:numRowsK
@inbounds sumVal += mK[mm, nn] * mI[ii - mm + numRowsK, jj - nn + numColsK];
end
mO[ii, jj] = sumVal;
end
end
end
numRowsA = 1000;
numColsA = 1000;
numRowsK = 5;
numColsK = 5;
mA = rand(numRowsA, numColsA);
mK = rand(numRowsK, numColsK);
mO = zeros((numRowsA, numColsA) .- (numRowsK, numColsK) .+ 1);
@benchmark _Conv2DValidA!(mO, mA, mK) #
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Start by running the benchmark in issue #514 and comparing _Conv2DValidA! with _Conv2DValidB!, focusing on the two placements of @turbo in the provided Julia reproducer. Review LoopVectorization's handling of nested loops and vectorization levels; done means the reported performance difference is explained and the relevant behavior is improved or documented.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- julia
- Bereich
- performance
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100