Skip to content

Removing @generated functions #66

Description

@leios

Right now, there is a mess of @generated functions in run/fractal_flame.jl. In principle, these can be removed by...

@kernel function naive_chaos_kernel!(points, n, H_fxs, H_kwargs,
                                     H_clrs, H_clr_kwargs,
                                     H_probs, H_fnums,
                                     layer_values, layer_reds, layer_greens,
                                     layer_blues, layer_alphas, frame, bounds,
                                     bin_widths, num_ignore, max_range)

    tid = @index(Global,Linear)

    pt = Ref(point(0.0,0.0))
    pt[] = points[tid]
    dims = Fae.dims(pt[])

    clr = Ref(RGBA{Float32}(0,0,0,0))

    seed = quick_seed(tid)
    fid = create_fid(H_probs, H_fnums, seed)

    for i = 1:n
        # quick way to tell if in range to be calculated or not
        sketchy_sum = absum(pt[])
        
        if sketchy_sum < max_range
            if length(H_fnums) > 1 || H_fnums[1] > 1
                seed = simple_rand(seed)
                fid = create_fid(H_probs, H_fnums, seed)
            else
                fid = UInt(1)
            end
            choices = find_random_fxs(fid, H_fnums, H_probs)

            #ntuple(Val(choices)) do k
            for k in NTuple(Val.(choices))
                Base.@_inline_meta
                pt[] = H_fxs[k](pt[].y, pt[].x, frame; H_kwargs[k]...)
                clr[] = H_clrs[k](pt[].y, pt[].x, clr[], frame; H_clr_kwargs[k]...)
            end

            histogram_output!(layer_values, layer_reds, layer_greens,
                              layer_blues, layer_alphas, pt[], clr[],
                              bounds, dims, bin_widths, i, num_ignore)
        end
    end

    @inbounds points[tid] = pt[]

end

ie, finding some way to iterate through known values with ntuple, like: https://github.com/CliMA/ClimateMachine.jl/blob/2e0b6b7d97719e410d12a8596c98d5db7f891dbf/src/Numerics/DGMethods/remainder.jl#L510

I couldn't quite figure out how to go from the tuple of ints to an ntuple of vals.

The core issue is that LLVM cannot optimize on the tuple of functions because each function is a unique type, so it cannot be stored as an ntuple to begin with.

This discussion was introduced in #64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions