Skip to content

Commit

Permalink
Fixing norm for AMD
Browse files Browse the repository at this point in the history
  • Loading branch information
michel2323 committed Nov 18, 2022
1 parent 5cd5dcd commit a406d0c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
AMDGPU = "=0.4.2"
AMDGPU = "0.4"
CUDA = "3.4"
ExaTron = "2"
FileIO = "1.14"
Expand Down
10 changes: 4 additions & 6 deletions src/interface/solve_acopf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ function solve_acopf(case::String;
elseif use_gpu && isa(ka_device, Nothing)
CUDA.device!(gpu_no)
TD = CuArray{Float64,1}; TI = CuArray{Int,1}; TM = CuArray{Float64,2}
elseif use_gpu && isa(ka_device, KA.Device)
if has_cuda_gpu()
elseif has_cuda_gpu()
TD = CuArray{Float64,1}; TI = CuArray{Int,1}; TM = CuArray{Float64,2}
elseif has_rocm_gpu()
TD = ROCArray{Float64,1}; TI = ROCArray{Int,1}; TM = ROCArray{Float64,2}
end
elseif has_rocm_gpu()
TD = ROCArray{Float64,1}; TI = ROCArray{Int,1}; TM = ROCArray{Float64,2}
else
error("Inconsistent device selection use_gpu=$use_gpu and ka_device=$(typepof(ka_device))")
error("Inconsistent device selection use_gpu=$use_gpu and ka_device=$(typeof(ka_device))")
end

env = AdmmEnv{T,TD,TI,TM}(case, rho_pq, rho_va; case_format=case_format,
Expand Down
2 changes: 1 addition & 1 deletion src/models/acopf/acopf_admm_prepoststep_ka.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function admm_outer_prestep(
device
)
sol, info = mod.solution, mod.info
info.norm_z_prev = norm(sol.z_curr)
info.norm_z_prev = norm(sol.z_curr, device)
return
end

Expand Down
8 changes: 4 additions & 4 deletions src/models/acopf/acopf_admm_update_residual_ka.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function admm_update_residual(
)
wait(ev)

info.primres = norm(sol.rp)
info.dualres = norm(sol.rd)
info.norm_z_curr = norm(sol.z_curr)
info.mismatch = norm(sol.Ax_plus_By)
info.primres = norm(sol.rp, device)
info.dualres = norm(sol.rd, device)
info.norm_z_curr = norm(sol.z_curr, device)
info.mismatch = norm(sol.Ax_plus_By, device)

return
end
24 changes: 24 additions & 0 deletions src/utils/utilities_ka.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ end
c[tx] = a[tx] - b[tx]
end
end
@kernel function norm_kernel(::Val{n}, x,
y
) where {n}
tx = @index(Local, Linear)
bx = @index(Group, Linear)

_x = @localmem Float64 (n,)
_x[tx] = x[tx]
@synchronize

v = ExaTron.dnrm2(n, _x, 1, tx)
if bx == 1 && tx == 1
y[1] = v
end
@synchronize

end
function LinearAlgebra.norm(x, device)
y = KAArray{Float64}(1, device)
n = length(x)
wait(norm_kernel(device,n)(Val{n}(), x, y,ndrange=(n,),dependencies=Event(device)))
ret = y |> Array
return ret[1]
end
2 changes: 1 addition & 1 deletion test/algorithms/acopf_update_cpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@
@test mod.info.status == :Solved
@test mod.info.outer == 20
@test mod.info.cumul == 1232
@test isapprox(mod.info.objval, 129645.676; atol=1e-3)
@test isapprox(mod.info.objval, 129645.676; rtol=1e-6)
end
4 changes: 3 additions & 1 deletion test/algorithms/acopf_update_ka.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if CUDA.has_cuda_gpu() || AMDGPU.has_rocm_gpu()
end
if AMDGPU.has_rocm_gpu()
using ROCKernels
# Set for crusher login node to avoid other users
AMDGPU.default_device!(AMDGPU.devices()[2])
function ExaAdmm.KAArray{T}(n::Int, device::ROCDevice) where {T}
return ROCArray{T}(undef, n)
end
Expand All @@ -31,7 +33,7 @@ end
if isa(device, KA.CPU)
TD = Array{Float64,1}; TI = Array{Int,1}; TM = Array{Float64,2}
env = ExaAdmm.AdmmEnv{T,TD,TI,TM}(case, rho_pq, rho_va; use_gpu=false, ka_device=device, verbose=verbose)
else isa(device, ROCDevice)
else
if CUDA.has_cuda_gpu()
TD = CuArray{Float64,1}; TI = CuArray{Int,1}; TM = CuArray{Float64,2}
elseif AMDGPU.has_rocm_gpu()
Expand Down

0 comments on commit a406d0c

Please sign in to comment.