Skip to content

Commit 0361db4

Browse files
committed
Address feedback
1 parent eaaff4c commit 0361db4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/KernelAbstractions.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,17 @@ allocates an array using unified memory if the backend supports it. Use
541541
!!! note
542542
Backend implementations **must** implement `allocate(::NewBackend, T, dims::Tuple)`
543543
"""
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)))
544+
allocate(backend::Backend, T::Type, dims...; kwargs...) = allocate(backend, T, dims; kwargs...)
545+
function allocate(backend::Backend, T::Type, dims::Tuple; unified::Union{Nothing, Bool} = nothing)
546+
if isnothing(unified)
547+
throw(MethodError(allocate, (backend, T, dims)))
548+
elseif unified
549+
throw(ArgumentError("`$(typeof(backend))` either does not support unified memory or it has not yet defined `allocate(backend::$backend, T::Type, dims::Tuple; unified::Bool)`"))
550+
else
551+
allocate(backend, T, dims)
552+
end
553+
end
554+
546555

547556
"""
548557
zeros(::Backend, Type, dims...; unified=false)::AbstractArray
@@ -551,8 +560,8 @@ Allocate a storage array appropriate for the computational backend filled with z
551560
`unified` allocates an array using unified memory if the backend supports it.
552561
"""
553562
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)
563+
function zeros(backend::Backend, ::Type{T}, dims::Tuple; kwargs...) where {T}
564+
data = allocate(backend, T, dims...; kwargs...)
556565
fill!(data, zero(T))
557566
return data
558567
end
@@ -564,8 +573,8 @@ Allocate a storage array appropriate for the computational backend filled with o
564573
`unified` allocates an array using unified memory if the backend supports it.
565574
"""
566575
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)
576+
function ones(backend::Backend, ::Type{T}, dims::Tuple; kwargs...) where {T}
577+
data = allocate(backend, T, dims; kwargs...)
569578
fill!(data, one(T))
570579
return data
571580
end
@@ -577,9 +586,9 @@ Returns whether unified memory arrays are supported by the backend.
577586
578587
!!! note
579588
Backend implementations **must** implement this function
580-
only if they **do not** support unified memory.
589+
only if they **do** support unified memory.
581590
"""
582-
supports_unified(::Backend) = true
591+
supports_unified(::Backend) = false
583592

584593
"""
585594
supports_atomics(::Backend)::Bool

0 commit comments

Comments
 (0)