Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JuliaGPU/KernelAbstractions.jl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 73dc4294d890ef7b11f70eeaa7cc13acf52cb197
Choose a base ref
..
head repository: JuliaGPU/KernelAbstractions.jl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 00bcec3091a4eab0fa46eb1f88f72ea482f22d95
Choose a head ref
Showing with 21 additions and 3 deletions.
  1. +20 −2 src/nditeration.jl
  2. +1 −1 test/private.jl
22 changes: 20 additions & 2 deletions src/nditeration.jl
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ end
@inline function Base.getindex(iter::FastCartesianIndices{N}, I::Vararg{Int, N}) where {N}
@boundscheck checkbounds(iter, I...)
index = map(iter.inverses, I) do inv, i
@inbounds getindex(Base.OneTo(inv.divisor), i)
@inbounds getindex(Base.OneTo(inv.divisor), i%Int32)
end
CartesianIndex(index)
end
@@ -42,14 +42,16 @@ end

function _ind2sub_recurse(inds, ind)
Base.@_inline_meta
assume(ind >= 0)
inv = inds[1]
indnext, f, l = _div(ind, inv)
(ind - l * indnext + f, _ind2sub_recurse(Base.tail(inds), indnext)...)
end

_lookup(ind, inv::SignedMultiplicativeInverse) = ind + 1
function _div(ind, inv::SignedMultiplicativeInverse)
inv.divisor == 0 && throw(DivideError())
# inv.divisor == 0 && throw(DivideError())
assume(ind >= 0)
div(ind % Int32, inv), 1, inv.divisor
end

@@ -198,4 +200,20 @@ needs to perform dynamic bounds-checking.
end
end



"""
assume(cond::Bool)
Assume that the condition `cond` is true. This is a hint to the compiler, possibly enabling
it to optimize more aggressively.
"""
@inline assume(cond::Bool) = Base.llvmcall(("""
declare void @llvm.assume(i1)
define void @entry(i8) #0 {
%cond = icmp eq i8 %0, 1
call void @llvm.assume(i1 %cond)
ret void
}
attributes #0 = { alwaysinline }""", "entry"),
Nothing, Tuple{Bool}, cond)
end #module
2 changes: 1 addition & 1 deletion test/private.jl
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ function private_testsuite(backend, ArrayT)

A = ArrayT{Int}(undef, 64, 64)
A .= 1
forloop(backend(), size(A, 1))(A, Val(size(A, 2)), ndrange = size(A, 1), workgroupsize = size(A, 1))
forloop(backend(), size(A, 1))(A, Val(size(A, 2)), ndrange = size(A, 1), workgroupsize = size(A, 1))
synchronize(backend())
@test all(Array(A)[:, 1] .== 64)
@test all(Array(A)[:, 2:end] .== 1)