Example of minimum model declaration
UDF
When Kokkos selected backend is on host, (either Serial, OpenMP or Threads), user-defined-model can be loaded at runtime and modified without compile the whole program. The UDF models can be program is the almost same way as regular model but with some limitations. The build can be done with the udf_build script, in order to select model user has to: set the model name as: udf_model and set the envar : BIOMC_LIB_UDF to the absolute .so path.
export BIOMC_LIB_UDF=$(pwd)/path/lib_udf_model_custom.so
UDF models can only be selected when the backend is set to host because the model definition and declaration are handled separately during the compilation step. The model is loaded through a shared library mechanism (e.g., dlopen on Linux), but this introduces some limitations. For instance, some optimizations, such as the size of views, cannot be performed at runtime, which may result in slower performance in some cases. However, udf can't be used with device backend like CUDA, where the kernel must be known at compile time. While CUDA runtime can load PTX code dynamically, this would require writing and compiling CUDA code separately, which is not the intended approach in the Kokkos framework.
#ifndef __EXAMPLE_MODEL_HPP__
#define __EXAMPLE_MODEL_HPP__
#include <common/traits.hpp>
#include <mc/prng/prng_extension.hpp>
#include <mc/traits.hpp>
#include <models/uptake.hpp>
#include <models/utils.hpp>
#include <string_view>
struct ModelExample
{
enum class particle_var : int
{
mass = 0,
a,
__COUNT__
};
static constexpr std::size_t n_var = INDEX_FROM_ENUM(particle_var::__COUNT__);
static constexpr std::string_view name =
"example";
using uniform_weight =
std::true_type;
using Self = ModelExample;
using FloatType = float;
using SelfParticle =
KOKKOS_INLINE_FUNCTION
static void init(
const MC::pool_type& random_pool,
std::size_t idx,
const SelfParticle& arr);
KOKKOS_INLINE_FUNCTION static double mass(std::size_t idx,
const SelfParticle& arr);
FloatType d_t,
std::size_t idx,
const SelfParticle& arr,
KOKKOS_INLINE_FUNCTION
static void division(
const MC::pool_type& random_pool,
std::size_t idx,
std::size_t idx2,
const SelfParticle& arr,
const SelfParticle& buffer_arr);
KOKKOS_INLINE_FUNCTION static void
contribution(std::size_t idx,
std::size_t position,
double weight,
const SelfParticle& arr,
};
CHECK_MODEL(ModelExample)
#endif
Kokkos::Subview< KernelConcentrationType, int, decltype(Kokkos::ALL)> LocalConcentration
Definition alias.hpp:105
Status
Definition alias.hpp:58
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:39
decltype( Kokkos::Experimental::create_scatter_view(kernelContribution())) ContributionView
Definition alias.hpp:88
Kokkos::View< F *[Nd], Kokkos::LayoutRight > ParticlesModel
Definition alias.hpp:19