Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ package_names = ["ITensors", "NDTensors"]
package_ordering = Dict(["ITensors" => 1, "NDTensors" => 2])

function bug_report_file(package_name::String)
return "$(package_name)_bug_report.md"
return "$(package_name)_bug_report.md"
end
function feature_request_file(package_name::String)
return "$(package_name)_feature_request.md"
return "$(package_name)_feature_request.md"
end

for package_name in package_names
@show package_name
@show package_name

order = lpad(package_ordering[package_name], 2, "0")
order = lpad(package_ordering[package_name], 2, "0")

template_bug_report = bug_report_file(template_package_name)
new_bug_report = order * "_" * bug_report_file(package_name)
template_bug_report = bug_report_file(template_package_name)
new_bug_report = order * "_" * bug_report_file(package_name)

if isfile(new_bug_report)
println("File $new_bug_report already exists, skipping")
else
println("Copying $template_bug_report to $new_bug_report")
cp(template_bug_report, new_bug_report)
if isfile(new_bug_report)
println("File $new_bug_report already exists, skipping")
else
println("Copying $template_bug_report to $new_bug_report")
cp(template_bug_report, new_bug_report)

println("Replace $template_package_name with $package_name in $new_bug_report")
replace_in_file(new_bug_report, template_package_name => package_name)
println("Replace $template_package_name with $package_name in $new_bug_report")
replace_in_file(new_bug_report, template_package_name => package_name)

mv(new_bug_report, joinpath("..", new_bug_report); force=true)
end
mv(new_bug_report, joinpath("..", new_bug_report); force = true)
end

template_feature_request = feature_request_file(template_package_name)
new_feature_request = order * "_" * feature_request_file(package_name)
template_feature_request = feature_request_file(template_package_name)
new_feature_request = order * "_" * feature_request_file(package_name)

if isfile(new_feature_request)
println("File $new_feature_request already exists, skipping")
else
println("Copying $template_feature_request to $new_feature_request")
cp(template_feature_request, new_feature_request)
if isfile(new_feature_request)
println("File $new_feature_request already exists, skipping")
else
println("Copying $template_feature_request to $new_feature_request")
cp(template_feature_request, new_feature_request)

println("Replace $template_package_name with $package_name in $new_feature_request")
replace_in_file(new_feature_request, template_package_name => package_name)
println("Replace $template_package_name with $package_name in $new_feature_request")
replace_in_file(new_feature_request, template_package_name => package_name)

mv(new_feature_request, joinpath("..", new_feature_request); force=true)
end
mv(new_feature_request, joinpath("..", new_feature_request); force = true)
end
end
2 changes: 1 addition & 1 deletion NDTensors/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NDTensors"
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
authors = ["Matthew Fishman <[email protected]>"]
version = "0.4.12"
version = "0.4.13"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
26 changes: 13 additions & 13 deletions NDTensors/ext/NDTensorsAMDGPUExt/adapt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ using NDTensors: NDTensors, EmptyStorage, adapt_storagetype, emptytype
using NDTensors.AMDGPUExtensions: AMDGPUExtensions, ROCArrayAdaptor
using NDTensors.GPUArraysCoreExtensions: storagemode
using NDTensors.TypeParameterAccessors:
default_type_parameters, set_type_parameters, type_parameters
default_type_parameters, set_type_parameters, type_parameters
using Adapt: Adapt, adapt
using AMDGPU: AMDGPU, ROCArray, ROCVector
using Functors: fmap

function AMDGPUExtensions.roc(
xs; storagemode=default_type_parameters(ROCArray, storagemode)
)
return fmap(x -> adapt(ROCArrayAdaptor{storagemode}(), x), xs)
xs; storagemode = default_type_parameters(ROCArray, storagemode)
)
return fmap(x -> adapt(ROCArrayAdaptor{storagemode}(), x), xs)
end

function Adapt.adapt_storage(adaptor::ROCArrayAdaptor, xs::AbstractArray)
new_parameters = (type_parameters(xs, (eltype, ndims))..., storagemode(adaptor))
roctype = set_type_parameters(ROCArray, (eltype, ndims, storagemode), new_parameters)
return isbits(xs) ? xs : adapt(roctype, xs)
new_parameters = (type_parameters(xs, (eltype, ndims))..., storagemode(adaptor))
roctype = set_type_parameters(ROCArray, (eltype, ndims, storagemode), new_parameters)
return isbits(xs) ? xs : adapt(roctype, xs)
end

function NDTensors.adapt_storagetype(
adaptor::ROCArrayAdaptor, ::Type{EmptyStorage{ElT,StoreT}}
) where {ElT,StoreT}
roctype = set_type_parameters(
ROCVector, (eltype, storagemode), (ElT, storagemode(adaptor))
)
return emptytype(adapt_storagetype(roctype, StoreT))
adaptor::ROCArrayAdaptor, ::Type{EmptyStorage{ElT, StoreT}}
) where {ElT, StoreT}
roctype = set_type_parameters(
ROCVector, (eltype, storagemode), (ElT, storagemode(adaptor))
)
return emptytype(adapt_storagetype(roctype, StoreT))
end
2 changes: 1 addition & 1 deletion NDTensors/ext/NDTensorsAMDGPUExt/append.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ using NDTensors.Expose: Exposed, unexpose

## Warning this append function uses scalar indexing and is therefore extremely slow
function Base.append!(Ecollection::Exposed{<:ROCArray}, collections...)
return @allowscalar append!(unexpose(Ecollection), collections...)
return @allowscalar append!(unexpose(Ecollection), collections...)
end
36 changes: 18 additions & 18 deletions NDTensors/ext/NDTensorsAMDGPUExt/copyto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ using LinearAlgebra: LinearAlgebra, Adjoint
using AMDGPU: ROCArray

# Same definition as `MtlArray`.
function Base.copy(src::Exposed{<:ROCArray,<:Base.ReshapedArray})
return reshape(copy(parent(src)), size(unexpose(src)))
function Base.copy(src::Exposed{<:ROCArray, <:Base.ReshapedArray})
return reshape(copy(parent(src)), size(unexpose(src)))
end

function Base.copy(
src::Exposed{
<:ROCArray,<:SubArray{<:Any,<:Any,<:Base.ReshapedArray{<:Any,<:Any,<:Adjoint}}
},
)
return copy(@view copy(expose(parent(src)))[parentindices(unexpose(src))...])
src::Exposed{
<:ROCArray, <:SubArray{<:Any, <:Any, <:Base.ReshapedArray{<:Any, <:Any, <:Adjoint}},
},
)
return copy(@view copy(expose(parent(src)))[parentindices(unexpose(src))...])
end

function Base.copyto!(dest::Exposed{<:ROCArray}, src::Exposed{<:ROCArray,<:SubArray})
copyto!(dest, expose(copy(src)))
return unexpose(dest)
function Base.copyto!(dest::Exposed{<:ROCArray}, src::Exposed{<:ROCArray, <:SubArray})
copyto!(dest, expose(copy(src)))
return unexpose(dest)
end

function Base.copyto!(
dest::Exposed{<:ROCArray}, src::Exposed{<:ROCArray,<:Base.ReshapedArray}
)
copyto!(dest, expose(parent(src)))
return unexpose(dest)
dest::Exposed{<:ROCArray}, src::Exposed{<:ROCArray, <:Base.ReshapedArray}
)
copyto!(dest, expose(parent(src)))
return unexpose(dest)
end

function Base.copyto!(
dest::Exposed{<:ROCArray}, src::Exposed{<:ROCArray,<:LinearAlgebra.Transpose}
)
copyto!(expose(transpose(dest)), expose(parent(src)))
return unexpose(dest)
dest::Exposed{<:ROCArray}, src::Exposed{<:ROCArray, <:LinearAlgebra.Transpose}
)
copyto!(expose(transpose(dest)), expose(parent(src)))
return unexpose(dest)
end
14 changes: 7 additions & 7 deletions NDTensors/ext/NDTensorsAMDGPUExt/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ using NDTensors.Expose: Exposed, expose, parent, unexpose
using NDTensors.GPUArraysCoreExtensions: cpu

function Base.getindex(E::Exposed{<:ROCArray})
return @allowscalar unexpose(E)[]
return @allowscalar unexpose(E)[]
end

function Base.setindex!(E::Exposed{<:ROCArray}, x::Number)
@allowscalar unexpose(E)[] = x
return unexpose(E)
@allowscalar unexpose(E)[] = x
return unexpose(E)
end

function Base.getindex(E::Exposed{<:ROCArray,<:Adjoint}, i, j)
return (expose(parent(E))[j, i])'
function Base.getindex(E::Exposed{<:ROCArray, <:Adjoint}, i, j)
return (expose(parent(E))[j, i])'
end

Base.any(f, E::Exposed{<:ROCArray,<:NDTensors.Tensor}) = any(f, data(unexpose(E)))
Base.any(f, E::Exposed{<:ROCArray, <:NDTensors.Tensor}) = any(f, data(unexpose(E)))

function Base.print_array(io::IO, E::Exposed{<:ROCArray})
return Base.print_array(io, expose(cpu(E)))
return Base.print_array(io, expose(cpu(E)))
end
12 changes: 6 additions & 6 deletions NDTensors/ext/NDTensorsAMDGPUExt/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ using Adapt: adapt
using AMDGPU: ROCMatrix

function LinearAlgebra.svd(A::Exposed{<:ROCMatrix}; kwargs...)
U, S, V = svd(cpu(A))
return roc.((U, S, V))
U, S, V = svd(cpu(A))
return roc.((U, S, V))
end

## TODO currently AMDGPU doesn't have ql so make a ql function
function Expose.ql(A::Exposed{<:ROCMatrix})
Q, L = ql(expose(cpu(A)))
return adapt(unwrap_array_type(A), Matrix(Q)), adapt(unwrap_array_type(A), L)
Q, L = ql(expose(cpu(A)))
return adapt(unwrap_array_type(A), Matrix(Q)), adapt(unwrap_array_type(A), L)
end
function Expose.ql_positive(A::Exposed{<:ROCMatrix})
Q, L = ql_positive(expose(cpu(A)))
return adapt(unwrap_array_type(A), Matrix(Q)), adapt(unwrap_array_type(A), L)
Q, L = ql_positive(expose(cpu(A)))
return adapt(unwrap_array_type(A), Matrix(Q)), adapt(unwrap_array_type(A), L)
end
58 changes: 29 additions & 29 deletions NDTensors/ext/NDTensorsAMDGPUExt/mul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@ using AMDGPU: ROCArray

# This was calling generic matrix multiplication.
function LinearAlgebra.mul!(
CM::Exposed{<:ROCArray,<:LinearAlgebra.Transpose},
AM::Exposed{<:ROCArray},
BM::Exposed{<:ROCArray},
α,
β,
)
mul!(transpose(CM), transpose(BM), transpose(AM), α, β)
return unexpose(CM)
CM::Exposed{<:ROCArray, <:LinearAlgebra.Transpose},
AM::Exposed{<:ROCArray},
BM::Exposed{<:ROCArray},
α,
β,
)
mul!(transpose(CM), transpose(BM), transpose(AM), α, β)
return unexpose(CM)
end

# This was calling generic matrix multiplication.
function LinearAlgebra.mul!(
CM::Exposed{<:ROCArray,<:LinearAlgebra.Adjoint},
AM::Exposed{<:ROCArray},
BM::Exposed{<:ROCArray},
α,
β,
)
mul!(CM', BM', AM', α, β)
return unexpose(CM)
CM::Exposed{<:ROCArray, <:LinearAlgebra.Adjoint},
AM::Exposed{<:ROCArray},
BM::Exposed{<:ROCArray},
α,
β,
)
mul!(CM', BM', AM', α, β)
return unexpose(CM)
end

# Fix issue in AMDGPU.jl where it cannot distinguish
# Transpose{Reshape{Adjoint{ROCArray}}} as a ROCArray and calls generic matmul
function LinearAlgebra.mul!(
CM::Exposed{<:ROCArray},
AM::Exposed{<:ROCArray},
BM::Exposed{
<:ROCArray,
<:LinearAlgebra.Transpose{
<:Any,<:Base.ReshapedArray{<:Any,<:Any,<:LinearAlgebra.Adjoint}
},
},
α,
β,
)
mul!(CM, AM, expose(transpose(copy(expose(parent(BM))))), α, β)
return unexpose(CM)
CM::Exposed{<:ROCArray},
AM::Exposed{<:ROCArray},
BM::Exposed{
<:ROCArray,
<:LinearAlgebra.Transpose{
<:Any, <:Base.ReshapedArray{<:Any, <:Any, <:LinearAlgebra.Adjoint},
},
},
α,
β,
)
mul!(CM, AM, expose(transpose(copy(expose(parent(BM))))), α, β)
return unexpose(CM)
end
26 changes: 13 additions & 13 deletions NDTensors/ext/NDTensorsAMDGPUExt/permutedims.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ using NDTensors.Expose: Exposed, expose, parent, unexpose
using AMDGPU: ROCArray

function Base.permutedims!(
Edest::Exposed{<:ROCArray,<:Base.ReshapedArray}, Esrc::Exposed{<:ROCArray}, perm
)
Aperm = permutedims(Esrc, perm)
copyto!(expose(parent(Edest)), expose(Aperm))
return unexpose(Edest)
Edest::Exposed{<:ROCArray, <:Base.ReshapedArray}, Esrc::Exposed{<:ROCArray}, perm
)
Aperm = permutedims(Esrc, perm)
copyto!(expose(parent(Edest)), expose(Aperm))
return unexpose(Edest)
end

# There is an issue in AMDGPU where if Edest is a reshaped{<:Adjoint}
# .= can fail. So instead force Esrc into the shape of parent(Edest)
function Base.permutedims!(
Edest::Exposed{<:ROCArray,<:Base.ReshapedArray{<:Any,<:Any,<:Adjoint}},
Esrc::Exposed{<:ROCArray},
perm,
f,
)
Aperm = reshape(permutedims(Esrc, perm), size(parent(Edest)))
parent(Edest) .= f.(parent(Edest), Aperm)
return unexpose(Edest)
Edest::Exposed{<:ROCArray, <:Base.ReshapedArray{<:Any, <:Any, <:Adjoint}},
Esrc::Exposed{<:ROCArray},
perm,
f,
)
Aperm = reshape(permutedims(Esrc, perm), size(parent(Edest)))
parent(Edest) .= f.(parent(Edest), Aperm)
return unexpose(Edest)
end
20 changes: 10 additions & 10 deletions NDTensors/ext/NDTensorsCUDAExt/adapt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ using NDTensors: NDTensors, EmptyStorage, adapt_storagetype, emptytype
using NDTensors.CUDAExtensions: CUDAExtensions, CuArrayAdaptor
using NDTensors.GPUArraysCoreExtensions: storagemode
using NDTensors.TypeParameterAccessors:
default_type_parameters, set_type_parameters, type_parameters
default_type_parameters, set_type_parameters, type_parameters

function CUDAExtensions.cu(xs; storagemode=default_type_parameters(CuArray, storagemode))
return fmap(x -> adapt(CuArrayAdaptor{storagemode}(), x), xs)
function CUDAExtensions.cu(xs; storagemode = default_type_parameters(CuArray, storagemode))
return fmap(x -> adapt(CuArrayAdaptor{storagemode}(), x), xs)
end

## Could do this generically
function Adapt.adapt_storage(adaptor::CuArrayAdaptor, xs::AbstractArray)
params = (type_parameters(xs, (eltype, ndims))..., storagemode(adaptor))
cutype = set_type_parameters(CuArray, (eltype, ndims, storagemode), params)
return isbits(xs) ? xs : adapt(cutype, xs)
params = (type_parameters(xs, (eltype, ndims))..., storagemode(adaptor))
cutype = set_type_parameters(CuArray, (eltype, ndims, storagemode), params)
return isbits(xs) ? xs : adapt(cutype, xs)
end

function NDTensors.adapt_storagetype(
adaptor::CuArrayAdaptor, ::Type{EmptyStorage{ElT,StoreT}}
) where {ElT,StoreT}
cutype = set_type_parameters(CuVector, (eltype, storagemode), (ElT, storagemode(adaptor)))
return emptytype(adapt_storagetype(cutype, StoreT))
adaptor::CuArrayAdaptor, ::Type{EmptyStorage{ElT, StoreT}}
) where {ElT, StoreT}
cutype = set_type_parameters(CuVector, (eltype, storagemode), (ElT, storagemode(adaptor)))
return emptytype(adapt_storagetype(cutype, StoreT))
end
2 changes: 1 addition & 1 deletion NDTensors/ext/NDTensorsCUDAExt/append.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ using NDTensors.Expose: Exposed, unexpose

## Warning this append function uses scalar indexing and is therefore extremely slow
function Base.append!(Ecollection::Exposed{<:CuArray}, collections...)
return @allowscalar append!(unexpose(Ecollection), collections...)
return @allowscalar append!(unexpose(Ecollection), collections...)
end
Loading
Loading