Skip to main content

Rocky Solver SDK 2025 R2

api_cuda_particles

Last update: 16.07.2025
1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
2#pragma once
3
4#include <rocky20/api/device/api_device_particles.hpp>
5#include <rocky20/api/device/api_cuda.hpp>
6
7namespace rocky::cuda
8{
9
10template <typename Callable>
11void dispatch_particles_kernel(
12 IRockyModel &model,
13 Callable h_particle_f_ptr,
14 void **udf_devices_data
15)
16{
17 if (model.get_number_of_active_particles() <= 0)
18 return;
19
20 for (int i=0; i<model.get_number_of_devices(); i++)
21 {
22 CUDA_SET_DEVICE(model.get_device_id(i));
23
24 void *udf_device_data = udf_devices_data[i];
25 device::execute_particles_function<CudaBackend><<<CD_NBLOCKS, CD_NTHREADS>>>(
26 model.get_device_data(i), model.get_current_time(),
27 h_particle_f_ptr, udf_device_data
28 );
29 }
30
31 // Sync all GPUs
32 sync_devices(model);
33}
34
35template <typename Callable>
36__global__ void execute_instantaneous_breakage_function_kernel(
37 SDeviceModel* device_data, int device_id,
38 Callable instantaneous_breakage_f_ptr,
39 void* udf_device_data,
40 cu_real time_curr
41)
42{
43 device::compute_instantaneous_breakage<CudaBackend>(
44 device_data, device_id,
45 instantaneous_breakage_f_ptr, udf_device_data,
46 time_curr
47 );
48}
49
50template <typename Callable>
51void dispatch_instantaneous_breakage_kernel(
52 IRockyModel& model,
53 Callable h_instantaneous_breakage_f_ptr,
54 void** udf_devices_data
55)
56{
57 for (int i = 0; i < model.get_number_of_devices(); i++)
58 {
59 void* udf_device_data = udf_devices_data[i];
60 SDeviceModel* device_data = model.get_device_data(i);
61
62 CUDA_SET_DEVICE(model.get_device_id(i));
63 rocky::cuda::execute_instantaneous_breakage_function_kernel<<<CD_NBLOCKS, CD_NTHREADS>>>(
64 device_data,
65 i,
66 h_instantaneous_breakage_f_ptr,
67 udf_device_data,
68 model._impl->iteration.current_time);
69 }
70
71 //Sync all GPUs
72 sync_devices(model);
73}
74
75} // namespace rocky::cuda
Definition rocky_api.h:58
int get_number_of_devices() const
Definition rocky_api.cpp:173
int get_number_of_active_particles() const
Definition rocky_api.cpp:153
double get_current_time() const
Definition rocky_api.cpp:143
int get_device_id(int device_index) const
Definition rocky_api.cpp:178

Connect with Ansys