From 8a5e49429b1ec34826aa7f1ba5646314f2a62299 Mon Sep 17 00:00:00 2001 From: Rubydragon Date: Fri, 9 Aug 2024 12:21:49 +0200 Subject: [PATCH] Don't eval in generated function return --- src/QEDprocesses_patch.jl | 23 +++++------------------ src/code_gen/function.jl | 34 ++++++++++++++++------------------ 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/QEDprocesses_patch.jl b/src/QEDprocesses_patch.jl index 282d713..b982467 100644 --- a/src/QEDprocesses_patch.jl +++ b/src/QEDprocesses_patch.jl @@ -1,25 +1,12 @@ # patch QEDprocesses # see issue https://github.com/QEDjl-project/QEDprocesses.jl/issues/77 @inline function QEDprocesses.number_particles( - proc_def::QEDbase.AbstractProcessDefinition, - ::Type{PS}, + proc_def::QEDbase.AbstractProcessDefinition, ::Type{PS} ) where { - DIR <: QEDbase.ParticleDirection, - PT <: QEDbase.AbstractParticleType, - EL <: AbstractFourMomentum, - PS <: ParticleStateful{DIR, PT, EL}, + DIR<:QEDbase.ParticleDirection, + PT<:QEDbase.AbstractParticleType, + EL<:AbstractFourMomentum, + PS<:ParticleStateful{DIR,PT,EL}, } return QEDprocesses.number_particles(proc_def, DIR(), PT()) end - -@inline function QEDcore.ParticleStateful{DIR, SPECIES}( - mom::AbstractFourMomentum, -) where {DIR <: ParticleDirection, SPECIES <: AbstractParticleType} - return ParticleStateful(DIR(), SPECIES(), mom) -end - -@inline function QEDcore.ParticleStateful{DIR, SPECIES, EL}( - mom::EL, -) where {DIR <: ParticleDirection, SPECIES <: AbstractParticleType, EL <: AbstractFourMomentum} - return ParticleStateful(DIR(), SPECIES(), mom) -end diff --git a/src/code_gen/function.jl b/src/code_gen/function.jl index 50b3df6..163fa41 100644 --- a/src/code_gen/function.jl +++ b/src/code_gen/function.jl @@ -16,9 +16,7 @@ function get_compute_function(graph::DAG, instance, machine::Machine) "function compute_$(functionId)(data_input::$(input_type(instance))) $(initCaches); $(assignInputs); $code; return $resSym; end", ) - func = eval(expr) - - return func + return expr end """ @@ -35,22 +33,22 @@ function get_cuda_kernel(graph::DAG, instance, machine::Machine) functionId = to_var_name(UUIDs.uuid1(rng[1])) resSym = eval(gen_access_expr(entry_device(tape.machine), tape.outputSymbol)) - expr = Meta.parse("function compute_$(functionId)(input_vector, output_vector, n::Int64) - id = (blockIdx().x - 1) * blockDim().x + threadIdx().x - if (id > n) - return - end - @inline data_input = input_vector[id] - $(initCaches) - $(assignInputs) - $code - @inline output_vector[id] = $resSym - return nothing - end") + expr = Meta.parse( + "function compute_$(functionId)(input_vector, output_vector, n::Int64) + id = (blockIdx().x - 1) * blockDim().x + threadIdx().x + if (id > n) + return + end + @inline data_input = input_vector[id] + $(initCaches) + $(assignInputs) + $code + @inline output_vector[id] = $resSym + return nothing + end" + ) - func = eval(expr) - - return func + return expr end """