@@ -45,6 +45,7 @@ Base.size(g::CuDeviceArray) = g.dims
45
45
Base. sizeof (x:: CuDeviceArray ) = Base. elsize (x) * length (x)
46
46
47
47
# we store the array length too; computing prod(size) is expensive
48
+ Base. size (g:: CuDeviceArray{<:Any,1} ) = (g. len,)
48
49
Base. length (g:: CuDeviceArray ) = g. len
49
50
50
51
Base. pointer (x:: CuDeviceArray{T,<:Any,A} ) where {T,A} = Base. unsafe_convert (LLVMPtr{T,A}, x)
@@ -78,7 +79,11 @@ Base.unsafe_convert(::Type{LLVMPtr{T,A}}, x::CuDeviceArray{T,<:Any,A}) where {T,
78
79
end
79
80
80
81
@device_function @inline function arrayref (A:: CuDeviceArray{T} , index:: Integer ) where {T}
81
- @boundscheck checkbounds (A, index)
82
+ # simplified bounds check to avoid the OneTo construction, which calls `max`
83
+ # and breaks elimination of redundant bounds checks in the generated code.
84
+ # @boundscheck checkbounds(A, index)
85
+ @boundscheck index <= length (A) || Base. throw_boundserror (A, index)
86
+
82
87
if Base. isbitsunion (T)
83
88
arrayref_union (A, index)
84
89
else
120
125
end
121
126
122
127
@device_function @inline function arrayset (A:: CuDeviceArray{T} , x:: T , index:: Integer ) where {T}
123
- @boundscheck checkbounds (A, index)
128
+ # simplified bounds check (see `arrayref`)
129
+ # @boundscheck checkbounds(A, index)
130
+ @boundscheck index <= length (A) || Base. throw_boundserror (A, index)
131
+
124
132
if Base. isbitsunion (T)
125
133
arrayset_union (A, x, index)
126
134
else
151
159
end
152
160
153
161
@device_function @inline function const_arrayref (A:: CuDeviceArray{T} , index:: Integer ) where {T}
154
- @boundscheck checkbounds (A, index)
162
+ # simplified bounds check (see `arrayset`)
163
+ # @boundscheck checkbounds(A, index)
164
+ @boundscheck index <= length (A) || Base. throw_boundserror (A, index)
165
+
155
166
align = alignment (A)
156
167
unsafe_cached_load (pointer (A), index, Val (align))
157
168
end
0 commit comments