@@ -48,6 +48,7 @@ Base.size(g::oneDeviceArray) = g.dims
48
48
Base. sizeof (x:: oneDeviceArray ) = Base. elsize (x) * length (x)
49
49
50
50
# we store the array length too; computing prod(size) is expensive
51
+ Base. size (g:: oneDeviceArray{<:Any, 1} ) = (g. len,)
51
52
Base. length (g:: oneDeviceArray ) = g. len
52
53
53
54
Base. pointer (x:: oneDeviceArray{T,<:Any,A} ) where {T,A} = Base. unsafe_convert (LLVMPtr{T,A}, x)
@@ -81,7 +82,11 @@ Base.unsafe_convert(::Type{LLVMPtr{T,A}}, x::oneDeviceArray{T,<:Any,A}) where {T
81
82
end
82
83
83
84
@device_function @inline function arrayref (A:: oneDeviceArray{T} , index:: Integer ) where {T}
84
- @boundscheck checkbounds (A, index)
85
+ # simplified bounds check to avoid the OneTo construction, which calls `max`
86
+ # and breaks elimination of redundant bounds checks in the generated code.
87
+ # @boundscheck checkbounds(A, index)
88
+ @boundscheck index <= length (A) || Base. throw_boundserror (A, index)
89
+
85
90
if isbitstype (T)
86
91
arrayref_bits (A, index)
87
92
else # if isbitsunion(T)
123
128
end
124
129
125
130
@device_function @inline function arrayset (A:: oneDeviceArray{T} , x:: T , index:: Integer ) where {T}
126
- @boundscheck checkbounds (A, index)
131
+ # simplified bounds check (see `arrayref`)
132
+ # @boundscheck checkbounds(A, index)
133
+ @boundscheck index <= length (A) || Base. throw_boundserror (A, index)
134
+
127
135
if isbitstype (T)
128
136
arrayset_bits (A, x, index)
129
137
else # if isbitsunion(T)
154
162
end
155
163
156
164
@device_function @inline function const_arrayref (A:: oneDeviceArray{T} , index:: Integer ) where {T}
157
- @boundscheck checkbounds (A, index)
165
+ # simplified bounds check (see `arrayset`)
166
+ # @boundscheck checkbounds(A, index)
167
+ @boundscheck index <= length (A) || Base. throw_boundserror (A, index)
168
+
158
169
align = alignment (A)
159
170
unsafe_cached_load (pointer (A), index, Val (align))
160
171
end
0 commit comments