Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/device/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Base.size(g::oneDeviceArray) = g.dims
Base.sizeof(x::oneDeviceArray) = Base.elsize(x) * length(x)

# we store the array length too; computing prod(size) is expensive
Base.size(g::oneDeviceArray{<:Any, 1}) = (g.len,)
Base.length(g::oneDeviceArray) = g.len

Base.pointer(x::oneDeviceArray{T,<:Any,A}) where {T,A} = Base.unsafe_convert(LLVMPtr{T,A}, x)
Expand Down Expand Up @@ -81,7 +82,11 @@ Base.unsafe_convert(::Type{LLVMPtr{T,A}}, x::oneDeviceArray{T,<:Any,A}) where {T
end

@device_function @inline function arrayref(A::oneDeviceArray{T}, index::Integer) where {T}
@boundscheck checkbounds(A, index)
# simplified bounds check to avoid the OneTo construction, which calls `max`
# and breaks elimination of redundant bounds checks in the generated code.
#@boundscheck checkbounds(A, index)
@boundscheck index <= length(A) || Base.throw_boundserror(A, index)

if isbitstype(T)
arrayref_bits(A, index)
else #if isbitsunion(T)
Expand Down Expand Up @@ -123,7 +128,10 @@ end
end

@device_function @inline function arrayset(A::oneDeviceArray{T}, x::T, index::Integer) where {T}
@boundscheck checkbounds(A, index)
# simplified bounds check (see `arrayref`)
#@boundscheck checkbounds(A, index)
@boundscheck index <= length(A) || Base.throw_boundserror(A, index)

if isbitstype(T)
arrayset_bits(A, x, index)
else #if isbitsunion(T)
Expand Down Expand Up @@ -154,7 +162,10 @@ end
end

@device_function @inline function const_arrayref(A::oneDeviceArray{T}, index::Integer) where {T}
@boundscheck checkbounds(A, index)
# simplified bounds check (see `arrayset`)
#@boundscheck checkbounds(A, index)
@boundscheck index <= length(A) || Base.throw_boundserror(A, index)

align = alignment(A)
unsafe_cached_load(pointer(A), index, Val(align))
end
Expand Down
Loading