BioDynaMo  v1.05.120-25dc9790
mechanical_forces_op_cuda_kernel.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_GPU_MECHANICAL_FORCES_OP_CUDA_KERNEL_H_
16 #define CORE_GPU_MECHANICAL_FORCES_OP_CUDA_KERNEL_H_
17 
18 #include <math.h>
19 #include <stdint.h>
20 #include "stdio.h"
21 
22 #ifdef USE_CUDA
23 #include <thrust/device_ptr.h>
24 #include <thrust/device_vector.h>
25 #endif
26 
27 namespace bdm {
28 
30  public:
31  MechanicalForcesOpCudaKernel(uint32_t num_agents, uint32_t num_boxes);
33 
35  const real_t* positions, const real_t* diameter,
36  const real_t* tractor_force, const real_t* adherence,
37  const uint32_t* box_id, const real_t* mass, const real_t timestep,
38  const real_t max_displacement, const real_t squared_radius,
39  const uint32_t num_agents, uint32_t* starts, uint16_t* lengths,
40  uint64_t* timestamps, uint64_t current_timestamp, uint32_t* successors,
41  uint32_t* num_boxes_axis, real_t* cell_movements);
42 
43  void Sync() const;
44  void ResizeCellBuffers(uint32_t num_cells);
45  void ResizeGridBuffers(uint32_t num_boxes);
46 
47 #ifdef USE_CUDA
48  private:
49  thrust::device_vector<real_t3> d_positions_;
50  thrust::device_vector<real_t3> d_tractor_force_;
51  thrust::device_vector<real_t> d_adherence_;
52  thrust::device_vector<real_t> d_diameters_;
53  thrust::device_vector<real_t> d_mass_;
54  thrust::device_vector<real_t3> d_cell_movements_;
55  thrust::device_vector<uint32_t> d_box_id_;
56  thrust::device_vector<uint32_t> d_starts_;
57  thrust::device_vector<uint16_t> d_lengths_;
58  thrust::device_vector<uint32_t> d_successors_;
59  thrust::device_vector<uint64_t> d_timestamps_;
60  thrust::device_ptr<uint3> d_num_boxes_axis_;
61 #endif // USE_CUDA
62 };
63 
64 #ifndef USE_CUDA
65 // Empty implementation if CUDA is not used to avoid undefined reference linking
66 // error.
67 //
69  uint32_t num_agents, uint32_t num_boxes) {}
71 
73  const real_t* positions, const real_t* diameter,
74  const real_t* tractor_force, const real_t* adherence,
75  const uint32_t* box_id, const real_t* mass, const real_t timestep,
76  const real_t max_displacement, const real_t squared_radius,
77  const uint32_t num_agents, uint32_t* starts, uint16_t* lengths,
78  uint64_t* timestamps, uint64_t current_timestamp, uint32_t* successors,
79  uint32_t* num_boxes_axis, real_t* cell_movements) {}
80 
81 inline void MechanicalForcesOpCudaKernel::Sync() const {}
83  uint32_t num_cells) {}
85  uint32_t num_boxes) {}
86 
87 #endif // USE_CUDA
88 
89 } // namespace bdm
90 
91 #endif // CORE_GPU_MECHANICAL_FORCES_OP_CUDA_KERNEL_H_
bdm::MechanicalForcesOpCudaKernel
Definition: mechanical_forces_op_cuda_kernel.h:29
bdm::MechanicalForcesOpCudaKernel::ResizeCellBuffers
void ResizeCellBuffers(uint32_t num_cells)
Definition: mechanical_forces_op_cuda_kernel.h:82
bdm
Definition: agent.cc:39
bdm::MechanicalForcesOpCudaKernel::ResizeGridBuffers
void ResizeGridBuffers(uint32_t num_boxes)
Definition: mechanical_forces_op_cuda_kernel.h:84
bdm::MechanicalForcesOpCudaKernel::MechanicalForcesOpCudaKernel
MechanicalForcesOpCudaKernel(uint32_t num_agents, uint32_t num_boxes)
Definition: mechanical_forces_op_cuda_kernel.h:68
bdm::real_t
double real_t
Definition: real_t.h:21
math.h
bdm::MechanicalForcesOpCudaKernel::Sync
void Sync() const
Definition: mechanical_forces_op_cuda_kernel.h:81
bdm::MechanicalForcesOpCudaKernel::~MechanicalForcesOpCudaKernel
virtual ~MechanicalForcesOpCudaKernel()
bdm::MechanicalForcesOpCudaKernel::LaunchMechanicalForcesKernel
void LaunchMechanicalForcesKernel(const real_t *positions, const real_t *diameter, const real_t *tractor_force, const real_t *adherence, const uint32_t *box_id, const real_t *mass, const real_t timestep, const real_t max_displacement, const real_t squared_radius, const uint32_t num_agents, uint32_t *starts, uint16_t *lengths, uint64_t *timestamps, uint64_t current_timestamp, uint32_t *successors, uint32_t *num_boxes_axis, real_t *cell_movements)
Definition: mechanical_forces_op_cuda_kernel.h:72