Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Oct 21, 2024
1 parent 5fa3595 commit eebd4b8
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/nditeration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ end

_ind2sub_recuse(::Tuple{}, ind) = (ind+1,)
function _ind2sub_recurse(indslast::NTuple{1}, ind)
@inline
Base.@_inline_meta
(_lookup(ind, indslast[1]),)
end

function _ind2sub_recurse(inds, ind)
@inline
Base.@_inline_meta
inv = inds[1]
indnext, f, l = _div(ind, inv)
(ind-l*indnext+f, _ind2sub_recurse(Base.tail(inds), indnext)...)
Expand All @@ -54,7 +54,7 @@ function _div(ind, inv::SignedMultiplicativeInverse)
end

function Base._ind2sub(inv::FastCartesianIndices, ind)
@inline
Base.@_inline_meta
_ind2sub_recurse(inv.inverses, ind-1)
end

Expand Down Expand Up @@ -151,24 +151,7 @@ Base.length(range::NDRange) = length(blocks(range))
end

Base.@propagate_inbounds function expand(ndrange::NDRange{N}, groupidx::Integer, idx::Integer) where {N}
# This causes two sdiv operations, one for each Linear to CartesianIndex
return expand(ndrange, blocks(ndrange)[groupidx], workitems(ndrange)[idx])

# The formulation below saves one sdiv
# but leads to a different index order...
# previous: julia> expand(ndrange, 1, 32*32)
# CartesianIndex(32, 32)
# now: julia> expand(ndrange, 1, 32*32)
# CartesianIndex(1024, 1)
# B = blocks(ndrange)::CartesianIndices
# W = workitems(ndrange)::CartesianIndices
# Ind = ntuple(Val(N)) do I
# Base.@_inline_meta
# b = B.indices[I]
# w = W.indices[I]
# length(b) * length(w)
# end
# CartesianIndices(Ind)[(groupidx-1)* prod(size(W)) + idx]
end

Base.@propagate_inbounds function expand(ndrange::NDRange{N}, groupidx::CartesianIndex{N}, idx::Integer) where {N}
Expand Down

0 comments on commit eebd4b8

Please sign in to comment.