Skip to content

Commit

Permalink
Avoid some unnecessary copies
Browse files Browse the repository at this point in the history
  • Loading branch information
pxl-th committed Jul 6, 2024
1 parent 9f3db70 commit 11c9317
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/host/gpunumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ AN.number(g::GPUNumber) = @allowscalar g.val[]
maybe_number(g::GPUNumber) = AN.number(g)
maybe_number(g) = g

number_type(::GPUNumber{T}) where T = eltype(T)

# When operations involve other `::Number` types,
# do not convert back to `GPUNumber`.
AN.like(::Type{<: GPUNumber}, x) = x

# When broadcasting, just pass the array itself.
Base.broadcastable(g::GPUNumber) = g.val

# Overload to avoid copies.
Base.one(g::GPUNumber) = one(number_type(g))
Base.zero(g::GPUNumber) = zero(number_type(g))
Base.identity(g::GPUNumber) = g

0 comments on commit 11c9317

Please sign in to comment.