Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] Fix broken broadcast operation on GPU #1532

Merged
merged 19 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions NDTensors/test/test_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ NDTensors.dim(i::MyInd) = i.dim
@test A[2, 2] == Aview[1, 1]
end

## Testing A .= α .* B .+ β .* A
C = copy(A)
@allowscalar fill!(B, zero(elt))
β = elt(2)
α = elt(1)
permutedims!!(A, B, (1, 2), (a, b) -> +(*(β, a), *(α, b)))
@allowscalar 2 .* C == A
randn!(B)
C = copy(A)
A = permutedims!!(A, B, (1, 2), (a, b) -> +(*(β, a), *(α, b)))
@allowscalar for i in 1:3, j in 1:4
@test A[i, j] == α * B[i, j] + β * C[i, j]
end

## add elt around 2.0 to preserve the eltype of A.
@test data(A * elt(2.0)) == data(elt(2.0) * A)

Expand Down
12 changes: 11 additions & 1 deletion src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ end
# C .= β .* C .+ α .* A .* B
#

struct axpby{Alpha,Beta} <: Function
alpha::Alpha
beta::Beta
end

(f::axpby)(y, x) = x * f.alpha + y * f.beta

## TODO this code doesn't actually get called
function Base.copyto!(
T::ITensor,
Expand All @@ -414,7 +421,10 @@ function Base.copyto!(
A, C = C, A
end
if !isnothing(A) && !isnothing(C) && !isnothing(α) && !isnothing(β)
map!((r, t) -> β * r + α * t, T, T, A)

# map!((r, t) -> β * r + α * t, T, T, A)

mtfishman marked this conversation as resolved.
Show resolved Hide resolved
map!(axpby(α, β), T, T, A)
else
bc_bc_α = find_type(Broadcasted, bc_α.args)
if isnothing(α)
Expand Down
Loading