-
Notifications
You must be signed in to change notification settings - Fork 63
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
1 parent
71123bd
commit 9fac54f
Showing
3 changed files
with
16 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
module MLDataDevicesChainRulesExt | ||
|
||
using Adapt: Adapt | ||
using MLDataDevices: CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice,OneAPIDevice, ReactantDevice | ||
using ChainRules: OneElement | ||
using MLDataDevices: CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, ReactantDevice | ||
|
||
Adapt.adapt_storage(::CPUDevice, x::OneElement) = x | ||
for Dev in (CUDADevice, AMDGPUDevice, MetalDevice, ReactantDevice) | ||
|
||
for Dev in (CUDADevice, AMDGPUDevice, MetalDevice, OneAPIDevice, ReactantDevice) | ||
# use `@eval` to avoid ambiguity with adapt_storage(::CUDADevice, ::AbstractArray) | ||
@eval Adapt.adapt_storage(to::$Dev, x::OneElement) = Adapt.adapt(to, collect(x)) | ||
end | ||
|
||
for Dev in (CUDADevice, AMDGPUDevice) | ||
# use `@eval` to avoid ambiguity with adapt_storage(::CUDADevice{Nothing}, ::AbstractArray) | ||
@eval Adapt.adapt_storage(to::$Dev, x::OneElement) = Adapt.adapt(to, collect(x)) | ||
end | ||
|
||
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,15 +1,20 @@ | ||
module MLDataDevicesZygoteExt | ||
|
||
using Adapt: Adapt | ||
using MLDataDevices: CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, ReactantDevice | ||
using MLDataDevices: CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, OneAPIDevice, ReactantDevice | ||
using Zygote: OneElement | ||
|
||
Adapt.adapt_storage(::CPUDevice, x::OneElement) = x | ||
|
||
for Dev in (CUDADevice, AMDGPUDevice, MetalDevice, ReactantDevice) | ||
for Dev in (CUDADevice, AMDGPUDevice, MetalDevice, OneAPIDevice, ReactantDevice) | ||
# use `@eval` to avoid ambiguity with adapt_storage(::CUDADevice, ::AbstractArray) | ||
@eval Adapt.adapt_storage(to::$Dev, x::OneElement) = Adapt.adapt(to, collect(x)) | ||
end | ||
|
||
for Dev in (CUDADevice, AMDGPUDevice) | ||
# use `@eval` to avoid ambiguity with adapt_storage(::CUDADevice{Nothing}, ::AbstractArray) | ||
@eval Adapt.adapt_storage(to::$Dev{Nothing}, x::OneElement) = Adapt.adapt(to, collect(x)) | ||
end | ||
|
||
end | ||
|