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