Elrod
March 2, 2024, 7:54pm
11
Ahmed_Salih:
struct DimensionalData{D, T <: AbstractFloat}
vectors::Tuple{Vararg{Vector{T}, D}}
V::StructArray{SVector{D, T}, 1, Tuple{Vararg{Vector{T}, D}}}
As @Benny has said, this will result in type instabilities. It should probably be
struct DimensionalData{D, T <: AbstractFloat}
vectors::Tuple{Vararg{Vector{T}, D}}
V::StructArray{SVector{D, T}, 1, Tuple{Vararg{Vector{T}, D}}, Int}
If you still get allocations, then you may need to PR StrideArraysCore
to add explicit support for StructArrays
as a pkg extension. Basically, object_and_preserve
should turn the inner vectors into PtrArray
s
@generated function _object_and_preserve(x::T) where {T}
# q = if sizeof(T) > 64
# Expr(:block, :(rx = $(ManualMemory.Reference)(x)), :((rx, rx)))
# elseif isbitstype(T)
q = isbitstype(T) ? :((x, nothing)) : :((x, x))
Expr(:block, Expr(:meta, :inline), q)
end
@inline object_and_preserve(x) = _object_and_preserve(x)
@inline object_and_preserve(x::String) = (x, x)
@inline object_and_preserve(A::AbstractArray{T}) where {T<:NativeTypes} =
array_object_and_preserve(ArrayInterface.device(A), A)
@inline function object_and_preserve(A::AbstractArray{T}) where {T}
if isbitstype(T) && ArrayInterface.device(A) === ArrayInterface.CPUPointer()
(PtrArray(A), preserve_buffer(A))
else
(A, A)
end
end
This file has been truncated. show original
2 Likes