I have some code to copy past in different function / kernel.
I saw something about metaprogramming but I have to admit that this is very opaque for me …
I would like to know if I can define a quote that contain the code and eval this quote in a function / cuda kernel ?
I have 3 expressions
free_energy_1 = :(0.25*ar*ρ + ...) free_energy_2 = :( - 0.5*ap*(ρ-ρcr)*P + ... ) free_energy_3 = :( - 0.5*ap*(ρ-ρcr)*P2 + ...) )
and I would like to define a variable in a function (CUDA kernel in this case) such that
f = eval(free_energy_1) + eval(free_energy_2) + eval(free_energy_3)
The Idea is to have many kernels where
f can use only
free_ernegy_2, or both, or… But I don’t want to repeat my code
0.25*ar*ρ + ... in each of this kernel. Also repeating this code makes it difficult when I want to edit one of this
free_energy, because then I have to change it everywhere…
This is not working, that why I ask for help.
I can make some part working using macro, for example for indexing my 2D grid:
macro indexing_2D() esc(quote i = (blockIdx().x - 1) * blockDim().x + threadIdx().x j = (blockIdx().y - 1) * blockDim().y + threadIdx().y end) end
and then, inside my kernel I can call
@indexing_2D and it declares my
This is not very useful, but I am trying to learn with “stupid” example.
Thank you for your help,
At this point anything can be useful