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

Add GPU pipeline #89

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
62 changes: 62 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
steps:
- label: "CUDA with julia {{matrix.julia}}"
plugins:
- JuliaCI/julia#v1:
version: "{{matrix.julia}}"
- JuliaCI/julia-test#v1:
test_args: "--quickfail"
agents:
queue: "juliagpu"
cuda: "*"
timeout_in_minutes: 60
env:
GROUP: "GPU"
ADVANCEDVI_TEST_CUDA: "true"
matrix:
setup:
julia:
- "1.10"

- label: "Metal with julia {{matrix.julia}}"
plugins:
- JuliaCI/julia#v1:
version: "{{matrix.julia}}"
- JuliaCI/julia-test#v1:
test_args: "--quickfail"
agents:
queue: "juliaecosystem"
os: "macos"
arch: "aarch64"

if: build.message !~ /\[skip tests\]/
timeout_in_minutes: 60
env:
GROUP: "GPU"
ADVANCEDVI_TEST_METAL: "true"
matrix:
setup:
julia:
- "1.10"

- label: "AMD GPU with Julia {{matrix.julia}}"
plugins:
- JuliaCI/julia#v1:
version: "{{matrix.julia}}"
- JuliaCI/julia-test#v1:
test_args: "--quickfail"
agents:
queue: "juliagpu"
rocm: "*"
rocmgpu: "*"
timeout_in_minutes: 60
env:
JULIA_AMDGPU_CORE_MUST_LOAD: "1"
JULIA_AMDGPU_HIP_MUST_LOAD: "1"
JULIA_AMDGPU_DISABLE_ARTIFACTS: "1"
GROUP: "GPU"
ADVANCEDVI_TEST_AMDGPU: "true"
JULIA_NUM_THREADS: 4
matrix:
setup:
julia:
- "1.10"
9 changes: 5 additions & 4 deletions src/objectives/elbo/repgradelbo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ function estimate_objective(obj::RepGradELBO, q, prob; n_samples::Int=obj.n_samp
end

function estimate_repgradelbo_ad_forward(params′, aux)
@unpack rng, obj, problem, adtype, restructure, q_stop = aux
@unpack device_rng, obj, problem, adtype, restructure, q_stop = aux
q = restructure_ad_forward(adtype, restructure, params′)
samples, entropy = reparam_with_entropy(rng, q, q_stop, obj.n_samples, obj.entropy)
samples, entropy = reparam_with_entropy(device_rng, q, q_stop, obj.n_samples, obj.entropy)
energy = estimate_energy_with_samples(problem, samples)
elbo = energy + entropy
return -elbo
Expand All @@ -109,11 +109,12 @@ function estimate_gradient!(
prob,
params,
restructure,
state,
state;
device_rng::Random.AbstractRNG = rng,
)
q_stop = restructure(params)
aux = (
rng=rng,
device_rng=device_rng,
adtype=adtype,
obj=obj,
problem=prob,
Expand Down
4 changes: 3 additions & 1 deletion src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function optimize(
prog=ProgressMeter.Progress(
max_iter; desc="Optimizing", barlen=31, showspeed=true, enabled=show_progress
),
kwargs...
)
params, restructure = Optimisers.destructure(deepcopy(q_init))
opt_st = maybe_init_optimizer(state_init, optimizer, params)
Expand All @@ -83,7 +84,8 @@ function optimize(
params,
restructure,
obj_st,
objargs...,
objargs...;
kwargs...
)
stat = merge(stat, stat′)

Expand Down
5 changes: 5 additions & 0 deletions test/gpu/amdgpu.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@testset "amdgpu" begin
AMDGPU.ones(Float32, 16)
AMDGPU.randn(Float32, 16, 16)
end
4 changes: 4 additions & 0 deletions test/gpu/cuda.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

@testset "cuda" begin
CUDA.zeros(2, 3)
end
5 changes: 5 additions & 0 deletions test/gpu/metal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@testset "metal" begin
mtl(zeros(1,3); storage=Metal.SharedStorage)
Metal.randn(Float32, 16, 32)
end
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,27 @@ if GROUP == "All" || GROUP == "Inference"
include("inference/repgradelbo_locationscale.jl")
include("inference/repgradelbo_locationscale_bijectors.jl")
end

if GROUP == "GPU"
if get(ENV, "ADVANCEDVI_TEST_CUDA", "false") == "true"
Pkg.add("CUDA")
using CUDA
include("gpu/cuda.jl")
end

if get(ENV, "ADVANCEDVI_TEST_METAL", "false") == "true"
Pkg.add("Metal")
using Metal
if Metal.functional()
include("gpu/metal.jl")
end
end

if get(ENV, "ADVANCEDVI_TEST_AMDGPU", "false") == "true"
Pkg.add("AMDGPU")
using AMDGPU
if AMDGPU.functional() && AMDGPU.functional(:MIOpen)
include("gpu/amdgpu.jl")
end
end
end
Loading