-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wct/simplevarinfo-fixes
- Loading branch information
Showing
13 changed files
with
124 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
steps: | ||
- label: "Julia v1" | ||
plugins: | ||
- JuliaCI/julia#v1: | ||
version: "1" | ||
- JuliaCI/julia-test#v1: ~ | ||
- JuliaCI/julia-coverage#v1: | ||
codecov: true | ||
agents: | ||
queue: "juliagpu" | ||
cuda: "*" | ||
if: build.message !~ /\[skip tests\]/ | ||
timeout_in_minutes: 60 | ||
env: | ||
TEST_GROUP: "gpu" |
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,65 @@ | ||
module TapirCUDAExt | ||
|
||
using LinearAlgebra, Random, Tapir | ||
|
||
using Base: IEEEFloat | ||
using CUDA: CuArray, cu | ||
|
||
import Tapir: | ||
MinimalCtx, | ||
rrule!!, | ||
@is_primitive, | ||
tangent_type, | ||
zero_tangent, | ||
randn_tangent, | ||
increment!!, | ||
set_to_zero!!, | ||
_add_to_primal, | ||
_diff, | ||
_dot, | ||
_scale, | ||
TestUtils, | ||
CoDual, | ||
NoPullback | ||
|
||
import Tapir.TestUtils: populate_address_map!, AddressMap, __increment_should_allocate | ||
|
||
# Tell Tapir.jl how to handle CuArrays. | ||
|
||
tangent_type(::Type{P}) where {P<:CuArray{<:IEEEFloat}} = P | ||
zero_tangent(x::CuArray{<:IEEEFloat}) = zero(x) | ||
function randn_tangent(rng::AbstractRNG, x::CuArray{Float32}) | ||
return cu(randn(rng, Float32, size(x)...)) | ||
end | ||
TestUtils.has_equal_data(x::P, y::P) where {P<:CuArray{<:IEEEFloat}} = x == y | ||
increment!!(x::P, y::P) where {P<:CuArray{<:IEEEFloat}} = x .+= y | ||
__increment_should_allocate(::Type{<:CuArray{<:IEEEFloat}}) = true | ||
set_to_zero!!(x::CuArray{<:IEEEFloat}) = x .= 0 | ||
_add_to_primal(x::P, y::P) where {P<:CuArray{<:IEEEFloat}} = x + y | ||
_diff(x::P, y::P) where {P<:CuArray{<:IEEEFloat}} = x - y | ||
_dot(x::P, y::P) where {P<:CuArray{<:IEEEFloat}} = Float64(dot(x, y)) | ||
_scale(x::Float64, y::P) where {T<:IEEEFloat, P<:CuArray{T}} = T(x) * y | ||
function populate_address_map!(m::AddressMap, p::CuArray, t::CuArray) | ||
k = pointer_from_objref(p) | ||
v = pointer_from_objref(t) | ||
haskey(m, k) && (@assert m[k] == v) | ||
m[k] = v | ||
return m | ||
end | ||
|
||
# Basic rules for operating on CuArrays. | ||
|
||
@is_primitive( | ||
MinimalCtx, | ||
Tuple{Type{<:CuArray}, UndefInitializer, Vararg{Int, N}} where {N}, | ||
) | ||
function rrule!!( | ||
p::CoDual{Type{P}}, | ||
init::CoDual{UndefInitializer}, | ||
dims::CoDual{Int}... | ||
) where {P<:CuArray{<:Base.IEEEFloat}} | ||
_dims = map(primal, dims) | ||
y = CoDual(P(undef, _dims), P(undef, _dims)) | ||
return y, NoPullback(p, init, dims...) | ||
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using CUDA | ||
|
||
@testset "cuda" begin | ||
|
||
# Check we can operate on CuArrays. | ||
test_tangent( | ||
Xoshiro(123456), | ||
CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}(undef, 8, 8); | ||
interface_only=false, | ||
) | ||
|
||
# Check we can instantiate a CuArray. | ||
interp = Tapir.TapirInterpreter() | ||
TestUtils.test_derived_rule( | ||
sr(123456), CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, undef, 256; | ||
interp, perf_flag=:none, interface_only=true, is_primitive=true, | ||
) | ||
end |
Oops, something went wrong.