### ### "THE BEER-WARE LICENSE": ### Alberto Ramos wrote this file. As long as you retain this ### notice you can do whatever you want with this stuff. If we meet some ### day, and you think this stuff is worth it, you can buy me a beer in ### return. ### ### file: ScalarAction.jl ### created: Tue Oct 5 11:53:49 2021 ### function scalar_action(U, Phi, lp::SpaceParm, sp::ScalarParm, ymws::YMworkspace{T}) where {T <: AbstractFloat} @timeit "Scalar action" begin CUDA.@sync begin CUDA.@cuda threads=lp.bsz blocks=lp.rsz krnl_act!(ymws.rm, U, Phi, sp, lp) end end S = CUDA.reduce(+, ymws.rm) return S end function krnl_act!(act, U::AbstractArray{TG}, Phi::AbstractArray{TS}, sp::ScalarParm{NP,T}, lp::SpaceParm{N,M,D}) where {TG,TS,NP,T,N,M,D} b, r = CUDA.threadIdx().x, CUDA.blockIdx().x Ush = @cuStaticSharedMem(TG, (D,N)) Psh = @cuStaticSharedMem(TS, (D,NP)) for id in 1:N Ush[b,id] = U[b,id,r] end for i in 1:NP Psh[b,i] = Phi[b,i,r] end sync_threads() S = zero(eltype(act)) for id in 1:N bu, ru = up((b, r), id, lp) for i in 1:NP if ru == r Pup = Psh[bu,i] else Pup = Phi[bu,i,ru] end S += -2*sp.kap[i]*dot(Psh[b,i],Ush[b,id]*Pup) end end for i in 1:NP sdot = dot(Psh[b,i],Psh[b,i]) S += sdot + sp.eta[i]*(sdot - 1)^2 end I = point_coord((b,r), lp) act[I] = S return nothing end function krnl_act!(act, U::AbstractArray{TG}, Phi::AbstractArray{TS}, sp::ScalarParm{2,T}, lp::SpaceParm{N,M,D}) where {TG,TS,T,N,M,D} b, r = CUDA.threadIdx().x, CUDA.blockIdx().x Ush = @cuStaticSharedMem(TG, (D,N)) Psh = @cuStaticSharedMem(TS, (D,2)) for id in 1:N Ush[b,id] = U[b,id,r] end for i in 1:2 Psh[b,i] = Phi[b,i,r] end sync_threads() S = zero(eltype(act)) for id in 1:N bu, ru = up((b, r), id, lp) for i in 1:2 if ru == r Pup = Psh[bu,i] else Pup = Phi[bu,i,ru] end S += -2*sp.kap[i]*dot(Psh[b,i],Ush[b,id]*Pup) end end for i in 1:2 sdot = dot(Psh[b,i],Psh[b,i]) S += sdot + sp.eta[i]*(sdot - 1)^2 end S += 2*sp.muh*dot(Psh[b,1], Psh[b,2]) I = point_coord((b,r), lp) act[I] = S return nothing end