Skip to content

Commit

Permalink
Migrate to KA 0.9
Browse files Browse the repository at this point in the history
* Ported to KA 0.9 API
* Project.toml for tests
  • Loading branch information
michel2323 committed Apr 18, 2023
1 parent c327078 commit 3ebc6bc
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 87 deletions.
21 changes: 3 additions & 18 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExaTron"
uuid = "28b18bf8-76f9-41ea-81fa-0f922810b349"
authors = ["Youngdae Kim <[email protected]>", "François Pacaud <[email protected]>", "Kibaek Kim <[email protected]>", "Michel Schanen <[email protected]>"]
version = "2.1.3"
version = "3.0.0"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand All @@ -13,22 +13,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
KernelAbstractions = "0.8"
KernelAbstractions = "0.9"
Requires = "1"
TOML = "1"
julia = "1.7"

[extras]
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDAKernels = "72cfdca4-0801-4ab0-bf6a-d52aa10adc57"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
ROCKernels = "7eb9e9f0-4bd3-4c4c-8bef-26bd9629d9b9"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["AMDGPU", "CUDA", "CUDAKernels", "KernelAbstractions", "PowerModels", "Random", "ROCKernels", "SparseArrays", "StatsBase", "Test"]
julia = "1.8"
2 changes: 0 additions & 2 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[deps]
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDAKernels = "72cfdca4-0801-4ab0-bf6a-d52aa10adc57"
ExaTronKernels = "dec458bd-9b7b-4867-ad20-20d9a112d608"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ROCKernels = "7eb9e9f0-4bd3-4c4c-8bef-26bd9629d9b9"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
60 changes: 32 additions & 28 deletions examples/admm/acopf_admm_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function get_generator_data(data::OPFData, ::KA.CPU)
return pgmin,pgmax,qgmin,qgmax,c2,c1,c0
end

function get_generator_data(data::OPFData, ::CUDADevice)
function get_generator_data(data::OPFData, ::CUDABackend)
ngen = length(data.generators)

pgmin = CuArray{Float64}(undef, ngen)
Expand Down Expand Up @@ -109,7 +109,7 @@ function get_bus_data(data::OPFData, ::KA.CPU)
return FrStart,FrIdx,ToStart,ToIdx,GenStart,GenIdx,Pd,Qd
end

function get_bus_data(data::OPFData, ::CUDADevice)
function get_bus_data(data::OPFData, ::CUDABackend)
nbus = length(data.buses)

FrIdx = [l for b=1:nbus for l in data.FromLines[b]]
Expand Down Expand Up @@ -194,7 +194,7 @@ function get_branch_data(data::OPFData, device::KA.CPU)
ybus.YttR, ybus.YttI, ybus.YtfR, ybus.YtfI, frBound, toBound
end

function get_branch_data(data::OPFData, device::CUDADevice)
function get_branch_data(data::OPFData, device::CUDABackend)
buses = data.buses
lines = data.lines
BusIdx = data.BusIdx
Expand Down Expand Up @@ -492,40 +492,44 @@ function admm_solve!(env::AdmmEnv, sol::SolutionOneLevel; iterlim=800, scale=1e-
break
end
else
wait(copy_data_kernel(env.device, 64, mod.nvar)(mod.nvar, sol.u_prev, sol.u_curr, dependencies=Event(env.device)))
wait(copy_data_kernel(env.device, 64, mod.nvar)(mod.nvar, sol.v_prev, sol.v_curr, dependencies=Event(env.device)))
wait(copy_data_kernel(env.device, 64, mod.nvar)(mod.nvar, sol.l_prev, sol.l_curr, dependencies=Event(env.device)))
copy_data_kernel(env.device, 64, mod.nvar)(mod.nvar, sol.u_prev, sol.u_curr)
copy_data_kernel(env.device, 64, mod.nvar)(mod.nvar, sol.v_prev, sol.v_curr)
copy_data_kernel(env.device, 64, mod.nvar)(mod.nvar, sol.l_prev, sol.l_curr)
KA.synchronize(env.device)

generator_kernel(mod.gen_mod, data.baseMVA, sol.u_curr, sol.v_curr, sol.l_curr, sol.rho, env.device)

wait(polar_kernel(env.device, 32, mod.nline*32)(mod.n, mod.nline, mod.line_start, scale,
sol.u_curr, sol.v_curr, sol.l_curr, sol.rho,
shift_lines, env.membuf, mod.YffR, mod.YffI, mod.YftR, mod.YftI,
mod.YttR, mod.YttI, mod.YtfR, mod.YtfI, mod.FrBound, mod.ToBound,
dependencies=Event(env.device)
)
polar_kernel(env.device, 32, mod.nline*32)(
mod.n, mod.nline, mod.line_start, scale,
sol.u_curr, sol.v_curr, sol.l_curr, sol.rho,
shift_lines, env.membuf, mod.YffR, mod.YffI, mod.YftR, mod.YftI,
mod.YttR, mod.YttI, mod.YtfR, mod.YtfI, mod.FrBound, mod.ToBound
)
wait(bus_kernel(env.device, 32, mod.nbus)(data.baseMVA, mod.nbus, mod.gen_mod.gen_start, mod.line_start,
mod.FrStart, mod.FrIdx, mod.ToStart, mod.ToIdx, mod.GenStart,
mod.GenIdx, mod.Pd, mod.Qd, sol.u_curr, sol.v_curr, sol.l_curr,
sol.rho, mod.YshR, mod.YshI,
dependencies=Event(env.device)
)
KA.synchronize(env.device)

bus_kernel(env.device, 32, mod.nbus)(
data.baseMVA, mod.nbus, mod.gen_mod.gen_start, mod.line_start,
mod.FrStart, mod.FrIdx, mod.ToStart, mod.ToIdx, mod.GenStart,
mod.GenIdx, mod.Pd, mod.Qd, sol.u_curr, sol.v_curr, sol.l_curr,
sol.rho, mod.YshR, mod.YshI
)
KA.synchronize(env.device)

wait(update_multiplier_kernel(env.device, 32, mod.nvar)(mod.nvar, sol.l_curr,
sol.u_curr, sol.v_curr, sol.rho,
dependencies=Event(env.device)
)
update_multiplier_kernel(env.device, 32, mod.nvar)(
mod.nvar, sol.l_curr,
sol.u_curr, sol.v_curr, sol.rho
)
wait(primal_residual_kernel(env.device, 32, mod.nvar)(mod.nvar, sol.rp, sol.u_curr, sol.v_curr,
dependencies=Event(env.device)
)
KA.synchronize(env.device)

primal_residual_kernel(env.device, 32, mod.nvar)(
mod.nvar, sol.rp, sol.u_curr, sol.v_curr
)
wait(dual_residual_kernel(env.device, 32, mod.nvar)(mod.nvar, sol.rd, sol.v_prev, sol.v_curr, sol.rho,
dependencies=Event(env.device)
)
KA.synchronize(env.device)

dual_residual_kernel(env.device, 32, mod.nvar)(
mod.nvar, sol.rd, sol.v_prev, sol.v_curr, sol.rho
)
KA.synchronize(env.device)

gpu_primres = norm(sol.rp)
gpu_dualres = norm(sol.rd)
Expand Down
2 changes: 1 addition & 1 deletion examples/admm/environment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ AdmmEnv(opfdata::OPFData, device::KA.CPU, rho_pq, rho_va; options...) = AdmmEnv{
opfdata, rho_pq, rho_va; device=device, options...
)

AdmmEnv(opfdata::OPFData, device::CUDADevice, rho_pq, rho_va; options...) = AdmmEnv{Float64, CuArray{Float64, 1}, CuArray{Int, 1}, CuArray{Float64, 2}}(
AdmmEnv(opfdata::OPFData, device::CUDABackend, rho_pq, rho_va; options...) = AdmmEnv{Float64, CuArray{Float64, 1}, CuArray{Int, 1}, CuArray{Float64, 2}}(
opfdata, rho_pq, rho_va; device=device, options...
)

Expand Down
9 changes: 5 additions & 4 deletions examples/admm/generator_kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ function generator_kernel(
)
nblk = div(gen_mod.ngen, 32, RoundUp)
nblk
wait(generator_kernel(device, 32, gen_mod.ngen)(baseMVA, gen_mod.ngen, gen_mod.gen_start,
u, v, l, rho, gen_mod.pgmin, gen_mod.pgmax, gen_mod.qgmin, gen_mod.qgmax, gen_mod.c2, gen_mod.c1,
dependencies=Event(device)
)
generator_kernel(device, 32, gen_mod.ngen)(
baseMVA, gen_mod.ngen, gen_mod.gen_start,
u, v, l, rho, gen_mod.pgmin, gen_mod.pgmax, gen_mod.qgmin, gen_mod.qgmax, gen_mod.c2, gen_mod.c1
)
KA.synchronize(device)

return 0.0
end

Expand Down
4 changes: 1 addition & 3 deletions examples/opf.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using KernelAbstractions
using AMDGPU
using ROCKernels
using CUDA
using CUDAKernels

# One day for Intel GPUs
# using oneAPI
Expand Down Expand Up @@ -32,7 +30,7 @@ rho_va = parse(Float64, ARGS[2])
max_iter = parse(Int, ARGS[3])
# Indicate which GPU device to use
device = CPU()
# device = CUDADevice()
# device = CUDABackend()
# device = ROCDevice()
# verbose = 0: No output
# verbose = 1: Final result metrics
Expand Down
Loading

0 comments on commit 3ebc6bc

Please sign in to comment.