-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
284 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.2.30" | ||
version = "0.3.0" | ||
|
||
[deps] | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module NDTensorsAMDGPUExt | ||
|
||
include("append.jl") | ||
include("copyto.jl") | ||
include("set_types.jl") | ||
include("adapt.jl") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using GPUArraysCore: @allowscalar | ||
using AMDGPU: ROCArray | ||
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...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
using NDTensors.TypeParameterAccessors: TypeParameterAccessors | ||
using NDTensors.GPUArraysCoreExtensions: storagemode | ||
using Adapt: Adapt | ||
using CUDA: CUDA, CuArray, CuVector | ||
using Functors: fmap | ||
using NDTensors: NDTensors, EmptyStorage, adapt_storagetype, emptytype | ||
using NDTensors.CUDAExtensions: CUDAExtensions, CuArrayAdaptor | ||
using NDTensors.GPUArraysCoreExtensions: storagemode | ||
using NDTensors.TypeParameterAccessors: | ||
default_type_parameter, set_type_parameters, type_parameters | ||
|
||
## TODO make this work for unified. This works but overwrites CUDA's adapt_storage. This fails for emptystorage... | ||
function CUDAExtensions.cu(xs; unified::Bool=false) | ||
return fmap( | ||
x -> adapt(CuArrayAdaptor{unified ? Mem.UnifiedBuffer : Mem.DeviceBuffer}(), x), xs | ||
) | ||
function CUDAExtensions.cu(xs; storagemode=default_type_parameter(CuArray, storagemode)) | ||
return fmap(x -> adapt(CuArrayAdaptor{storagemode}(), x), xs) | ||
end | ||
|
||
## Could do this generically | ||
function Adapt.adapt_storage(adaptor::CuArrayAdaptor, xs::AbstractArray) | ||
ElT = eltype(xs) | ||
BufT = storagemode(adaptor) | ||
N = ndims(xs) | ||
return isbits(xs) ? xs : adapt(CuArray{ElT,N,BufT}, 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, xs::Type{EmptyStorage{ElT,StoreT}} | ||
adaptor::CuArrayAdaptor, ::Type{EmptyStorage{ElT,StoreT}} | ||
) where {ElT,StoreT} | ||
BufT = storagemode(adaptor) | ||
return NDTensors.emptytype(NDTensors.adapt_storagetype(CuVector{ElT,BufT}, StoreT)) | ||
cutype = set_type_parameters(CuVector, (eltype, storagemode), (ElT, storagemode(adaptor))) | ||
return emptytype(adapt_storagetype(cutype, StoreT)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using GPUArraysCore: @allowscalar | ||
using CUDA: CuArray | ||
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...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
using CUDA: CuArray | ||
using NDTensors: NDTensors | ||
|
||
NDTensors.default_svd_alg(::Type{<:CuArray}, a) = "qr_algorithm" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
iscu(::Type{<:CuArray}) = true | ||
using CUDA: CuArray | ||
using NDTensors: NDTensors | ||
|
||
NDTensors.iscu(::Type{<:CuArray}) = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
using NDTensors.MetalExtensions: MetalExtensions | ||
using NDTensors.GPUArraysCoreExtensions: GPUArraysCoreExtensions, set_storagemode | ||
using NDTensors.TypeParameterAccessors: specify_type_parameters, type_parameters | ||
using Adapt: Adapt, adapt | ||
using Functors: fmap | ||
using Metal: MtlArray, MtlVector, DefaultStorageMode | ||
using NDTensors: NDTensors, EmptyStorage, adapt_storagetype, emptytype | ||
using NDTensors.Expose: Exposed | ||
using NDTensors.MetalExtensions: MetalExtensions, MtlArrayAdaptor | ||
using NDTensors.GPUArraysCoreExtensions: GPUArraysCoreExtensions | ||
using NDTensors.TypeParameterAccessors: set_type_parameters, type_parameters | ||
|
||
GPUArraysCoreExtensions.cpu(e::Exposed{<:MtlArray}) = adapt(Array, e) | ||
|
||
function MetalExtensions.mtl(xs; storage=DefaultStorageMode) | ||
return adapt(set_storagemode(MtlArray, storage), xs) | ||
function MetalExtensions.mtl(xs; storagemode=DefaultStorageMode) | ||
return fmap(x -> adapt(MtlArrayAdaptor{storagemode}(), x), xs) | ||
end | ||
|
||
# More general than the version in Metal.jl | ||
## TODO Rewrite this using a custom `MtlArrayAdaptor` which will be written in `MetalExtensions`. | ||
function Adapt.adapt_storage(arraytype::Type{<:MtlArray}, xs::AbstractArray) | ||
params = type_parameters(xs) | ||
arraytype_specified = specify_type_parameters(arraytype, params) | ||
return isbitstype(typeof(xs)) ? xs : convert(arraytype_specified, xs) | ||
function Adapt.adapt_storage(adaptor::MtlArrayAdaptor, xs::AbstractArray) | ||
new_parameters = (type_parameters(xs, (eltype, ndims))..., storagemode(adaptor)) | ||
mtltype = set_type_parameters(MtlArray, (eltype, ndims, storagemode), new_parameters) | ||
return isbits(xs) ? xs : adapt(mtltype, xs) | ||
end | ||
|
||
function NDTensors.adapt_storagetype( | ||
adaptor::MtlArrayAdaptor, ::Type{EmptyStorage{ElT,StoreT}} | ||
) where {ElT,StoreT} | ||
mtltype = set_type_parameters( | ||
MtlVector, (eltype, storagemode), (ElT, storagemode(adaptor)) | ||
) | ||
return emptytype(adapt_storagetype(mtltype, StoreT)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# This circumvents an issues that `MtlArray` can't call `resize!`. | ||
# TODO: Raise an issue with Metal.jl. | ||
function NDTensors.append!!(::Type{<:MtlArray}, collection, collections...) | ||
return vcat(collection, collections...) | ||
## Right now append! is broken on metal because of a missing resize! function | ||
## but make this available in the next release this will allow metal to work working | ||
using GPUArraysCore: @allowscalar | ||
using Metal: MtlArray | ||
using NDTensors.Expose: Exposed, unexpose | ||
|
||
## Warning this append function uses scalar indexing and is therefore extremely slow | ||
function Base.append!(Ecollection::Exposed{<:MtlArray}, collections...) | ||
return @allowscalar append!(unexpose(Ecollection), collections...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
2a6afa5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register subdir=NDTensors
2a6afa5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/104820
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
2a6afa5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
2a6afa5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/104822
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: