@@ -532,40 +532,55 @@ get_backend(::Array) = CPU()
532532Adapt. adapt_storage (:: CPU , a:: Array ) = a
533533
534534"""
535- allocate(::Backend, Type, dims...)::AbstractArray
535+ allocate(::Backend, Type, dims...; unified=false )::AbstractArray
536536
537- Allocate a storage array appropriate for the computational backend.
537+ Allocate a storage array appropriate for the computational backend. `unified`
538+ allocates an array using unified memory if the backend supports it. Use
539+ [`supports_unified`](@ref) to determine whether it is supported by a backend.
538540
539541!!! note
540542 Backend implementations **must** implement `allocate(::NewBackend, T, dims::Tuple)`
541543"""
542- allocate (backend:: Backend , T:: Type , dims... ) = allocate (backend, T, dims)
543- allocate (backend:: Backend , T:: Type , dims:: Tuple ) = throw (MethodError (allocate, (backend, T, dims)))
544+ allocate (backend:: Backend , T:: Type , dims... ; unified = false ) = allocate (backend, T, dims; unified )
545+ allocate (backend:: Backend , T:: Type , dims:: Tuple ; unified = false ) = throw (MethodError (allocate, (backend, T, dims)))
544546
545547"""
546- zeros(::Backend, Type, dims...)::AbstractArray
548+ zeros(::Backend, Type, dims...; unified=false )::AbstractArray
547549
548550Allocate a storage array appropriate for the computational backend filled with zeros.
551+ `unified` allocates an array using unified memory if the backend supports it.
549552"""
550- zeros (backend:: Backend , T:: Type , dims... ) = zeros (backend, T, dims)
551- function zeros (backend:: Backend , :: Type{T} , dims:: Tuple ) where {T}
552- data = allocate (backend, T, dims... )
553+ zeros (backend:: Backend , T:: Type , dims... ; kwargs ... ) = zeros (backend, T, dims; kwargs ... )
554+ function zeros (backend:: Backend , :: Type{T} , dims:: Tuple ; unified = false ) where {T}
555+ data = allocate (backend, T, dims... ; unified )
553556 fill! (data, zero (T))
554557 return data
555558end
556559
557560"""
558- ones(::Backend, Type, dims...)::AbstractArray
561+ ones(::Backend, Type, dims...; unified=false )::AbstractArray
559562
560563Allocate a storage array appropriate for the computational backend filled with ones.
564+ `unified` allocates an array using unified memory if the backend supports it.
561565"""
562- ones (backend:: Backend , T:: Type , dims... ) = ones (backend, T, dims)
563- function ones (backend:: Backend , :: Type{T} , dims:: Tuple ) where {T}
564- data = allocate (backend, T, dims)
566+ ones (backend:: Backend , T:: Type , dims... ; kwargs ... ) = ones (backend, T, dims; kwargs ... )
567+ function ones (backend:: Backend , :: Type{T} , dims:: Tuple ; unified = false ) where {T}
568+ data = allocate (backend, T, dims; unified )
565569 fill! (data, one (T))
566570 return data
567571end
568572
573+ """
574+ supports_unified(::Backend)::Bool
575+
576+ Returns whether unified memory arrays are supported by the backend.
577+
578+ !!! note
579+ Backend implementations **must** implement this function
580+ only if they **do not** support unified memory.
581+ """
582+ supports_unified (:: Backend ) = true
583+
569584"""
570585 supports_atomics(::Backend)::Bool
571586
0 commit comments