Open edejong-caltech opened 2 months ago
Some notes from todays discussion:
function foo(a)
b = zeros(size(a))
for i = 1:length(a)
b[i]+=rand()
end
return b
end
# non-allocating, but still mutating
function foo!(a, b)
for i = 1:length(a)
b[i]+=rand()
end
return b
end
# stack-allocated, much better
foo(a) = map(a_i->rand(), a)
@assert
is not allowed -> use error
, and don't capture variables in the error message
Vector
-> Tuple
/ StaticArrays.SArray
Use map
over initializing / + loops, when applicable
Add JET & @allocated
tests to functions we expect to be in tendency kernels
If a function is only used during initialization, then we can leave these for a later time?
norm = zeros(FT, sum(NProgMoms))
n_dist = length(NProgMoms)
for (i, n_mom) in enumerate(NProgMoms)
for j in 1:n_mom
norm[get_dist_moment_ind(NProgMoms, i, j)] = norms[1] * norms[2]^(j - 1)
end
end
Use concrete eltypes in structs (e.g., in CoalescenceTensor
):
struct CoalescenceTensor{FT} <: KernelTensor{FT}
c::Array{FT}
to
struct CoalescenceTensor{FT, AFT <: AbstractArray{FT}} <: KernelTensor{FT}
c::AFT
(maybe) remove keyword arguments, which are not always well supported inside gpu kernels
Remove runtime allocations:
collect
- explicit allocationreshape
- explicit allocation[getproperty(dist, p) for p in params]
- remove use of list comprehensionsArray{Symbol, 1}/Matrix{}(...)
- remove explicit array construction -> y = floor.(x)
can allocate or cause issues, maybe just use map
findall
ones(...)
/ zeros(...)
[C_1_1]
makes a vector (assumes Vector
type)intersect
@views
are likely problematicDict
s are not allowed (on CPU or GPU kernels) -> NamedTuple
s, or custom structs
julia> typeof((;a=1, b=2.0))
@NamedTuple{a::Int64, b::Float64}
```julia
Remove n, θ = get_params(dist)[2]
-> (;n, θ) = dist
Remove
function get_params(dist::PrimitiveParticleDistribution{FT}) where {FT <: Real}
params = Array{Symbol, 1}(collect(propertynames(dist)))
values = Array{FT, 1}([getproperty(dist, p) for p in params])
return params, values
end
entirely
Re: making Coalescence.jl GPU compatible...
update_coal_ints
should return an SVector
Q, R, S
update_moments!
, maybe pass the current moments in insteadfinite_2d_integrals
as a local map, rather than updating coal_data
(Q, R, S) = get_coalescence_integral_qrs...
coal_data
, and keep local and global variables separateGet rid of intialize_coalescence_data
It seems like we need to take a several steps to make Cloudy compatible with ClimaAtmos...
Next steps will include: