Skip to main content

Rocky Solver SDK 2024 R2

api_cuda_joints

Last update: 17.07.2025
1#pragma once
2
3#include <rocky20/api/device/api_device_joints.hpp>
4#include <rocky20/api/device/api_cuda.hpp>
5
6namespace rocky::cuda
7{
8
9template <typename Callable>
10void dispatch_joints_kernel(
11 IRockyModel &model,
12 Callable h_joint_f_ptr,
13 void **udf_devices_data
14)
15{
16 for (int i = 0; i < model.get_number_of_devices(); i++)
17 {
18 void *udf_device_data = udf_devices_data[i];
19 SDeviceModel *device_data = model.get_device_data(i);
20
21 CUDA_SET_DEVICE(model.get_device_id(i));
22 device::execute_joints_function<CudaBackend><<<CD_NBLOCKS, CD_NTHREADS>>>(
23 device_data, i, model.get_current_time(),
24 h_joint_f_ptr,
25 udf_device_data
26 );
27 }
28
29 //Sync all GPUs
30 sync_devices(model);
31}
32
33template <typename Callable>
34__global__ void execute_joint_forces_function_kernel(
35 SDeviceModel *device_data, int device_id,
36 Callable joint_f_ptr,
37 void *udf_device_data
38)
39{
40 device::compute_joint_forces<CudaBackend>(
41 device_data, device_id,
42 joint_f_ptr, udf_device_data
43 );
44}
45
46template <typename Callable>
47__global__ void execute_joint_breakage_function_kernel(
48 SDeviceModel* device_data, int device_id,
49 Callable joint_breakage_f_ptr,
50 void* udf_device_data,
51 typename CudaBackend::atomic_int_ptr nbreak_joints_a,
52 cu_real time_curr
53)
54{
55 device::compute_joint_breakage<CudaBackend>(
56 device_data, device_id,
57 joint_breakage_f_ptr, udf_device_data,
58 nbreak_joints_a,
59 time_curr
60 );
61}
62
63template <typename Callable>
64void dispatch_joint_forces_kernel(
65 IRockyModel &model,
66 Callable h_joint_f_ptr,
67 void **udf_devices_data
68)
69{
70 for (int i = 0; i < model.get_number_of_devices(); i++)
71 {
72 void *udf_device_data = udf_devices_data[i];
73 SDeviceModel *device_data = model.get_device_data(i);
74
75 CUDA_SET_DEVICE(model.get_device_id(i));
76 rocky::cuda::execute_joint_forces_function_kernel << <CD_NBLOCKS, CD_NTHREADS >> > (
77 device_data, i,
78 h_joint_f_ptr,
79 udf_device_data
80 );
81 }
82
83 //Sync all GPUs
84 sync_devices(model);
85}
86
87template <typename Callable>
88void dispatch_joint_breakage_kernel(
89 IRockyModel& model,
90 Callable h_joint_breakage_f_ptr,
91 void** udf_devices_data
92)
93{
94 for (int i = 0; i < model.get_number_of_devices(); i++)
95 {
96 void* udf_device_data = udf_devices_data[i];
97 SDeviceModel* device_data = model.get_device_data(i);
98
99 CUDA_SET_DEVICE(model.get_device_id(i));
100 rocky::cuda::execute_joint_breakage_function_kernel <<<CD_NBLOCKS, CD_NTHREADS >>> (
101 device_data, i,
102 h_joint_breakage_f_ptr,
103 udf_device_data,
104 &(model._impl->device_models[i].gen->nbreak_joints),
105 model._impl->iteration.current_time
106 );
107 }
108
109 //Sync all GPUs
110 sync_devices(model);
111}
112
113} // namespace rocky::cuda
Definition rocky_api.h:60
int get_number_of_devices() const
Definition rocky_api.cpp:159
double get_current_time() const
Definition rocky_api.cpp:129
int get_device_id(int device_index) const
Definition rocky_api.cpp:164

Connect with Ansys