From be94790bbe062377aaa3e848d6dd3cfa316766c3 Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Tue, 27 May 2025 09:46:39 +0200 Subject: [PATCH 01/14] fix amd --- ext/JustPICAMDGPUExt.jl | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index 75783132..bf73c4ba 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -45,25 +45,6 @@ function AMDGPU.ROCArray(::Type{T}, chain::JustPIC.MarkerChain) where {T <: Numb ) end -function AMDGPU.ROCArray(::Type{T}, chain::JustPIC.MarkerChain) where {T <: Number} - (; - cell_vertices, coords, coords0, h_vertices, h_vertices0, index, max_xcell, min_xcell, - ) = chain - coords_gpu = ntuple(i -> ROCArray(T, coords[i]), Val(length(coords))) - coords0_gpu = ntuple(i -> ROCArray(T, coords0[i]), Val(length(coords0))) - return MarkerChain( - CUDABackend, - coords_gpu, - coords0_gpu, - ROCArray(h_vertices), - ROCArray(h_vertices0), - cell_vertices, - ROCArray(Bool, index), - max_xcell, - min_xcell, - ) -end - function AMDGPU.ROCArray(::Type{T}, phase_ratios::JustPIC.PhaseRatios) where {T <: Number} (; center, vertex, Vx, Vy, Vz, yz, xz, xy) = phase_ratios return JustPIC.PhaseRatios( @@ -216,10 +197,10 @@ module _2D end function JustPIC._2D.init_particles( - ::Type{AMDGPUBackend}, nxcell, max_xcell, min_xcell, x, y, z; buffer = 1 - 1.0e-5 + ::Type{AMDGPUBackend}, nxcell, max_xcell, min_xcell, x, y; buffer = 1 - 1.0e-5 ) return init_particles( - AMDGPUBackend, nxcell, max_xcell, min_xcell, x, y, z; buffer = buffer + AMDGPUBackend, nxcell, max_xcell, min_xcell, x, y; buffer = buffer ) end From b67b3ddf36700f1984e5f6d37fa79b82c1a1bfec Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Tue, 27 May 2025 14:47:23 +0200 Subject: [PATCH 02/14] one more fix --- ext/JustPICAMDGPUExt.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index bf73c4ba..f8f8a559 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -102,11 +102,6 @@ function AMDGPU.ROCArray(chain::JustPIC.MarkerChain) ) end -function AMDGPU.ROCArray(phase_ratios::JustPIC.PhaseRatios) - (; vertex, center) = phase_ratios - return JustPIC.PhaseRatios(AMDGPUBackend, ROCArray(center), ROCArray(vertex)) -end - function AMDGPU.ROCArray(::Type{T}, CA::CellArray) where {T <: Number} ni = size(CA) # Array initializations From 9df574e12082df0e1db81428ce56dc43cfc86d83 Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Mon, 9 Jun 2025 09:53:19 +0200 Subject: [PATCH 03/14] imprt Jp.AMDGPU --- test/test_save_load.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_save_load.jl b/test/test_save_load.jl index 83a075b3..f739d6f1 100644 --- a/test/test_save_load.jl +++ b/test/test_save_load.jl @@ -98,7 +98,7 @@ const backend = JustPIC.CPUBackend if isCUDA || isAMDGPU T = isCUDA ? CuArray : ROCArray - Backend = isCUDA ? CUDABackend : AMDGPUBackend + Backend = isCUDA ? CUDABackend : JustPIC.AMDGPUBackend particles2 = Array(particles) phases2 = Array(phases) From dd1952851558fccf60f85d4ef151cc16ecbdec0f Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Mon, 9 Jun 2025 13:58:47 +0200 Subject: [PATCH 04/14] typo; fix? --- ext/JustPICAMDGPUExt.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index f8f8a559..db09e9db 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -10,7 +10,7 @@ JustPIC.TA(::Type{AMDGPUBackend}) = ROCArray function ROCCellArray( ::Type{T}, ::UndefInitializer, dims::NTuple{N, Int} ) where {T <: CellArrays.Cell, N} - return CellArrays.CellArray{T, N, 0, AMDGPU.ROCCellArrayArray{eltype(T), 3}}(undef, dims) + return CellArrays.CellArray{T, N, 0, AMDGPU.ROCCellArray{eltype(T), 3}}(undef, dims) end function ROCCellArray( ::Type{T}, ::UndefInitializer, dims::Int... From 4e8c9655eaf9b115519e8a27298e253591b99a52 Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Mon, 9 Jun 2025 14:06:19 +0200 Subject: [PATCH 05/14] another diff to CUDA --- ext/JustPICAMDGPUExt.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index db09e9db..bf9eee84 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -10,7 +10,7 @@ JustPIC.TA(::Type{AMDGPUBackend}) = ROCArray function ROCCellArray( ::Type{T}, ::UndefInitializer, dims::NTuple{N, Int} ) where {T <: CellArrays.Cell, N} - return CellArrays.CellArray{T, N, 0, AMDGPU.ROCCellArray{eltype(T), 3}}(undef, dims) + return CellArrays.CellArray{T, N, 0, AMDGPU.ROCArray{eltype(T), 3}}(undef, dims) end function ROCCellArray( ::Type{T}, ::UndefInitializer, dims::Int... From fd083552034539c8c897be97bea571177f5ba99a Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Mon, 9 Jun 2025 15:57:30 +0200 Subject: [PATCH 06/14] another bug bits the dust --- ext/JustPICAMDGPUExt.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index bf9eee84..4009718a 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -33,7 +33,7 @@ function AMDGPU.ROCArray(::Type{T}, chain::JustPIC.MarkerChain) where {T <: Numb coords_gpu = ntuple(i -> ROCArray(T, coords[i]), Val(length(coords))) coords0_gpu = ntuple(i -> ROCArray(T, coords0[i]), Val(length(coords0))) return MarkerChain( - CUDABackend, + AMDGPUBackend, coords_gpu, coords0_gpu, ROCArray(h_vertices), @@ -90,7 +90,7 @@ function AMDGPU.ROCArray(chain::JustPIC.MarkerChain) coords_gpu = ntuple(i -> ROCArray(coords[i]), Val(length(coords))) coords0_gpu = ntuple(i -> ROCArray(coords0[i]), Val(length(coords0))) return MarkerChain( - CUDABackend, + AMDGPUBackend, coords_gpu, coords0_gpu, ROCArray(h_vertices), From dbe8542eab2a111c6cdf7733b3ba91d6c3784c63 Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Mon, 9 Jun 2025 16:45:13 +0200 Subject: [PATCH 07/14] and another one --- test/test_save_load.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_save_load.jl b/test/test_save_load.jl index f739d6f1..5916d9f3 100644 --- a/test/test_save_load.jl +++ b/test/test_save_load.jl @@ -239,7 +239,7 @@ end if isCUDA || isAMDGPU T = isCUDA ? CuArray : ROCArray - Backend = isCUDA ? CUDABackend : AMDGPUBackend + Backend = isCUDA ? CUDABackend : JustPIC.AMDGPUBackend particles2 = Array(particles) phases2 = Array(phases) From a491236b247bc72be8fa6481141353a97cde0bb6 Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Tue, 10 Jun 2025 10:35:02 +0200 Subject: [PATCH 08/14] debug message --- test/test_2D.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_2D.jl b/test/test_2D.jl index 6952a056..fdb926c2 100644 --- a/test/test_2D.jl +++ b/test/test_2D.jl @@ -227,7 +227,7 @@ end values(Δ), values(Nc) ) # random position by default - + println("Backend: ", backend) # Initialise phase field particle_args = phases, = init_cell_arrays(particles, Val(1)) # cool From f3b196fdd74e425fc08cad9b7164b1ebd0223114 Mon Sep 17 00:00:00 2001 From: Albert de Montserrat Date: Tue, 10 Jun 2025 20:48:07 +0200 Subject: [PATCH 09/14] more prints --- test/test_2D.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_2D.jl b/test/test_2D.jl index fdb926c2..279ed3b2 100644 --- a/test/test_2D.jl +++ b/test/test_2D.jl @@ -227,7 +227,8 @@ end values(Δ), values(Nc) ) # random position by default - println("Backend: ", backend) + println("Type particles: ", typeof(particles)) + println("Type index: ", typeof(particles.index)) # Initialise phase field particle_args = phases, = init_cell_arrays(particles, Val(1)) # cool From 2343c69fb90ff9ecdd72cac2d65b6ec5eabbb846 Mon Sep 17 00:00:00 2001 From: Albert de Montserrat Date: Tue, 10 Jun 2025 20:50:06 +0200 Subject: [PATCH 10/14] typos --- ext/JustPICAMDGPUExt.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index ff84c7cd..2f5b8bb0 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -204,9 +204,9 @@ module _2D nxcell, max_xcell, min_xcell, - coords::NTuple{3, AbstractArray}, - dxᵢ::NTuple{3, T}, - nᵢ::NTuple{3, I}; + coords::NTuple{2, AbstractArray}, + dxᵢ::NTuple{2, T}, + nᵢ::NTuple{2, I}; buffer = 1 - 1.0e-5, ) where {T, I} return init_particles( From 16f52ccd3b813158f4b9d0250fbd9f6cc81951f4 Mon Sep 17 00:00:00 2001 From: Albert de Montserrat Date: Wed, 18 Jun 2025 10:39:40 +0200 Subject: [PATCH 11/14] `zip` not AMD-friendly... --- src/PhaseRatios/vertices.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhaseRatios/vertices.jl b/src/PhaseRatios/vertices.jl index 97fddbc6..99912b1f 100644 --- a/src/PhaseRatios/vertices.jl +++ b/src/PhaseRatios/vertices.jl @@ -37,8 +37,8 @@ end any(isnan, p) && continue # check if it's within half cell tmp = false - for x in zip(p, cell_vertex, di) - if abs(x[1] - x[2]) ≥ x[3] / 2 + for i in eachindex(p) + if abs(p[i] - cell_vertex[i]) ≥ di[i] / 2 tmp = true break end @@ -82,8 +82,8 @@ end any(isnan, p) && continue # check if it's within half cell tmp = false - for x in zip(p, cell_vertex, di) - if abs(x[1] - x[2]) ≥ x[3] / 2 + for i in eachindex(p) + if abs(p[i] - cell_vertex[i]) ≥ di[i] / 2 tmp = true break end From eaea783395aecebe4a95edd3efb9dc086aa05e7c Mon Sep 17 00:00:00 2001 From: Albert de Montserrat Date: Wed, 18 Jun 2025 10:50:33 +0200 Subject: [PATCH 12/14] i hate AMD --- src/PhaseRatios/midpoints.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhaseRatios/midpoints.jl b/src/PhaseRatios/midpoints.jl index 316d8503..ce19af03 100644 --- a/src/PhaseRatios/midpoints.jl +++ b/src/PhaseRatios/midpoints.jl @@ -18,11 +18,11 @@ end ) where {N, T} # index corresponding to the cell center - cell_center = getindex.(xci, I) + cell_center = ntuple(i -> xci[i], Val(N)) cell_face = @. cell_center + di * offsets / 2 ni = size(phases) NC = nphases(ratio_faces) - w = ntuple(_ -> zero(T), NC) + w = ntuple(_ -> zero(T), Val(NC)) # general case for offsetsᵢ in (ntuple(_ -> 0, Val(N)), offsets) From daa50d7ef6817e3c8f85a1adaad2f5ca239e8aae Mon Sep 17 00:00:00 2001 From: Albert de Montserrat Date: Wed, 18 Jun 2025 10:57:08 +0200 Subject: [PATCH 13/14] fixup --- src/PhaseRatios/midpoints.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhaseRatios/midpoints.jl b/src/PhaseRatios/midpoints.jl index ce19af03..a15e5551 100644 --- a/src/PhaseRatios/midpoints.jl +++ b/src/PhaseRatios/midpoints.jl @@ -18,7 +18,7 @@ end ) where {N, T} # index corresponding to the cell center - cell_center = ntuple(i -> xci[i], Val(N)) + cell_center = ntuple(i -> xci[i][I[i]], Val(N)) cell_face = @. cell_center + di * offsets / 2 ni = size(phases) NC = nphases(ratio_faces) From 5aca24015ee40e9bdfcb060e175dc90064fbdd6b Mon Sep 17 00:00:00 2001 From: Albert de Montserrat Date: Wed, 18 Jun 2025 11:11:46 +0200 Subject: [PATCH 14/14] fixup --- src/PhaseRatios/midpoints.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhaseRatios/midpoints.jl b/src/PhaseRatios/midpoints.jl index a15e5551..786416a3 100644 --- a/src/PhaseRatios/midpoints.jl +++ b/src/PhaseRatios/midpoints.jl @@ -22,7 +22,7 @@ end cell_face = @. cell_center + di * offsets / 2 ni = size(phases) NC = nphases(ratio_faces) - w = ntuple(_ -> zero(T), Val(NC)) + w = ntuple(_ -> zero(T), NC) # general case for offsetsᵢ in (ntuple(_ -> 0, Val(N)), offsets)