Skip to content

Commit 74a7e78

Browse files
authored
Merge pull request #190 from fredroy/fix_refresh_cuda
[BeamAdapter.CUDA] Fix for refactored SofaCUDA cmake, and overall fix compilation
2 parents f38462b + 8dd52e1 commit 74a7e78

File tree

5 files changed

+72
-101
lines changed

5 files changed

+72
-101
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.12)
2-
project(BeamAdapter VERSION 1.0)
2+
project(BeamAdapter VERSION 1.0 LANGUAGES CXX)
33

44
include(cmake/environment.cmake)
55

extensions/CUDA/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.12)
2-
project(BeamAdapter.CUDA)
2+
project(BeamAdapter.CUDA LANGUAGES CXX CUDA)
33

44
set(HEADER_FILES
55
src/BeamAdapter/CUDA/init.h

extensions/CUDA/src/BeamAdapter/CUDA/CudaInstantiations.cpp

Lines changed: 57 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
2222
#include <BeamAdapter/CUDA/config.h>
23-
#include <SofaCUDA/sofa/gpu/cuda/CudaTypes.h>
23+
#include <sofa/gpu/cuda/CudaTypes.h>
2424

2525
#include <BeamAdapter/component/WireBeamInterpolation.inl>
2626
#include <BeamAdapter/component/BeamInterpolation.inl>
@@ -36,149 +36,114 @@
3636
#include <sofa/core/behavior/Mass.inl>
3737
#include <sofa/core/Mapping.inl>
3838
#include <sofa/component/controller/MechanicalStateController.inl>
39-
#include <sofa/component/constraint/projective/FixedConstraint.inl> // for InterventionalRadiologyController
39+
#include <sofa/component/constraint/projective/FixedProjectiveConstraint.inl> // for InterventionalRadiologyController
4040

4141
#include <sofa/core/ObjectFactory.h>
4242

4343
using namespace sofa::gpu::cuda;
4444

45-
namespace sofa::component::fem::_beaminterpolation_
45+
namespace beamadapter::cuda
4646
{
4747
// template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation<CudaRigid3fTypes>;
48-
#ifdef SOFA_GPU_CUDA_DOUBLE
49-
template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation<CudaRigid3dTypes>;
50-
#endif
51-
} // namespace sofa::component::fem::_beaminterpolation_
52-
53-
namespace sofa::component::fem::_wirebeaminterpolation_
54-
{
5548
// template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation<CudaRigid3fTypes>;
56-
#ifdef SOFA_GPU_CUDA_DOUBLE
57-
template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation<CudaRigid3dTypes>;
58-
#endif
59-
} // namespace sofa::component::fem::_beaminterpolation_
60-
61-
namespace sofa::component::engine::_wirerestshape_
62-
{
6349
template class SOFA_BEAMADAPTER_CUDA_API WireRestShape<CudaRigid3fTypes>;
64-
#ifdef SOFA_GPU_CUDA_DOUBLE
65-
template class SOFA_BEAMADAPTER_CUDA_API WireRestShape<CudaRigid3dTypes>;
66-
#endif
67-
} // namespace sofa::component::engine::_wirerestshape_
68-
69-
namespace sofa::component::controller::_interventionalradiologycontroller_
70-
{
7150
template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController<CudaRigid3fTypes>;
72-
#ifdef SOFA_GPU_CUDA_DOUBLE
73-
template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController<CudaRigid3dTypes>;
74-
#endif
75-
} // namespace sofa::component::controller::_interventionalradiologycontroller_
76-
77-
namespace sofa::component::mapping::_adaptivebeammapping_
78-
{
7951
template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types>;
80-
#ifdef SOFA_GPU_CUDA_DOUBLE
81-
template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
82-
#endif
83-
} // namespace sofa::component::mapping::_adaptivebeammapping_
84-
85-
namespace sofa::component::mapping
86-
{
8752
template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types>;
88-
#ifdef SOFA_GPU_CUDA_DOUBLE
89-
template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
90-
#endif
91-
} // namespace sofa::component::mapping
92-
93-
namespace sofa::beamadapter
94-
{
9553
template class SOFA_BEAMADAPTER_CUDA_API RodMeshSection<CudaRigid3fTypes>;
9654
template class SOFA_BEAMADAPTER_CUDA_API RodSpireSection<CudaRigid3fTypes>;
9755
template class SOFA_BEAMADAPTER_CUDA_API RodStraightSection<CudaRigid3fTypes>;
9856

9957
#ifdef SOFA_GPU_CUDA_DOUBLE
58+
template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation<CudaRigid3dTypes>;
59+
template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation<CudaRigid3dTypes>;
60+
template class SOFA_BEAMADAPTER_CUDA_API WireRestShape<CudaRigid3dTypes>;
61+
template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController<CudaRigid3dTypes>;
62+
template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
63+
template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
10064
template class SOFA_BEAMADAPTER_CUDA_API RodMeshSection<CudaRigid3dTypes>;
10165
template class SOFA_BEAMADAPTER_CUDA_API RodSpireSection<CudaRigid3dTypes>;
10266
template class SOFA_BEAMADAPTER_CUDA_API RodStraightSection<CudaRigid3dTypes>;
10367
#endif
104-
} // namespace sofa::beamadapter
10568

69+
using namespace sofa::gpu::cuda;
10670

107-
namespace sofa::gpu::cuda
71+
void registerBeamAdapterCUDAComponents(sofa::core::ObjectFactory* factory)
10872
{
109-
11073
#ifdef SOFA_GPU_CUDA_DOUBLE
111-
int CudaBeamInterpolationClass = core::RegisterObject("Adaptive Beam Interpolation - Supports GPU-side computations using CUDA")
112-
// .add< sofa::component::fem::BeamInterpolation<CudaRigid3fTypes> >()
113-
.add< sofa::component::fem::BeamInterpolation<CudaRigid3dTypes> >()
114-
;
74+
factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Beam Interpolation - Supports GPU-side computations using CUDA")
75+
// .add< BeamInterpolation<CudaRigid3fTypes> >()
76+
.add< BeamInterpolation<CudaRigid3dTypes> >());
11577
#endif
11678

11779
#ifdef SOFA_GPU_CUDA_DOUBLE
118-
int CudaWireBeamInterpolationClass = core::RegisterObject("Adaptive Wire Beam Interpolation - Supports GPU-side computations using CUDA")
119-
// .add< sofa::component::fem::WireBeamInterpolation<CudaRigid3fTypes> >()
120-
.add< sofa::component::fem::WireBeamInterpolation<CudaRigid3dTypes> >()
121-
;
80+
factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Wire Beam Interpolation - Supports GPU-side computations using CUDA")
81+
// .add< WireBeamInterpolation<CudaRigid3fTypes> >()
82+
.add< WireBeamInterpolation<CudaRigid3dTypes> >());
12283
#endif
12384

124-
int CudaWireRestShapenClass = core::RegisterObject("Wire Shape - Supports GPU-side computations using CUDA")
125-
.add< sofa::component::engine::WireRestShape<CudaRigid3fTypes> >()
85+
factory->registerObjects(sofa::core::ObjectRegistrationData("Wire Shape - Supports GPU-side computations using CUDA")
86+
.add< WireRestShape<CudaRigid3fTypes> >()
12687
#ifdef SOFA_GPU_CUDA_DOUBLE
127-
.add< sofa::component::engine::WireRestShape<CudaRigid3dTypes> >()
88+
.add< WireRestShape<CudaRigid3dTypes> >()
12889
#endif
129-
;
90+
);
13091

131-
int CudaAdaptiveBeamForceFieldAndMassClass = core::RegisterObject("Adaptive Beam finite elements - Supports GPU-side computations using CUDA")
132-
.add< sofa::component::forcefield::AdaptiveBeamForceFieldAndMass<CudaRigid3fTypes> >()
92+
factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Beam finite elements - Supports GPU-side computations using CUDA")
93+
.add< AdaptiveBeamForceFieldAndMass<CudaRigid3fTypes> >()
13394
#ifdef SOFA_GPU_CUDA_DOUBLE
134-
.add< sofa::component::forcefield::AdaptiveBeamForceFieldAndMass<CudaRigid3dTypes> >()
95+
.add< AdaptiveBeamForceFieldAndMass<CudaRigid3dTypes> >()
13596
#endif
136-
;
97+
);
13798

138-
int CudaInterventionalRadiologyControllerClass = core::RegisterObject("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA")
139-
.add< sofa::component::controller::InterventionalRadiologyController<CudaRigid3fTypes> >()
99+
factory->registerObjects(sofa::core::ObjectRegistrationData("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA")
100+
.add< InterventionalRadiologyController<CudaRigid3fTypes> >()
140101
#ifdef SOFA_GPU_CUDA_DOUBLE
141-
.add< sofa::component::controller::InterventionalRadiologyController<CudaRigid3dTypes> >()
102+
.add< InterventionalRadiologyController<CudaRigid3dTypes> >()
142103
#endif
143-
;
104+
);
144105

145-
int CudaAdaptiveBeamMappingClass = core::RegisterObject("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA")
146-
.add< sofa::component::mapping::AdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
106+
factory->registerObjects(sofa::core::ObjectRegistrationData("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA")
107+
.add< InterventionalRadiologyController<CudaRigid3fTypes> >()
147108
#ifdef SOFA_GPU_CUDA_DOUBLE
148-
.add< sofa::component::mapping::AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
109+
.add< InterventionalRadiologyController<CudaRigid3dTypes> >()
149110
#endif
150-
;
111+
);
151112

152-
int CudaMultiAdaptiveBeamMappingClass = core::RegisterObject("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA")
153-
.add< sofa::component::mapping::MultiAdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
113+
factory->registerObjects(sofa::core::ObjectRegistrationData("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA")
114+
.add< AdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
154115
#ifdef SOFA_GPU_CUDA_DOUBLE
155-
.add< sofa::component::mapping::MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
116+
.add< AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
156117
#endif
157-
;
118+
);
158119

159-
const int CudaRodMeshSectionClass = core::RegisterObject("Class defining a Rod Section using a MeshLoader and material parameters using CUDA.")
160-
.add< sofa::beamadapter::RodMeshSection<CudaRigid3fTypes> >()
120+
factory->registerObjects(sofa::core::ObjectRegistrationData("Set the positions and velocities of points attached to a beam using linear interpolation between DOFs - Supports GPU-side computations using CUDA")
121+
.add< MultiAdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
161122
#ifdef SOFA_GPU_CUDA_DOUBLE
162-
.add< sofa::beamadapter::RodMeshSection<CudaRigid3dTypes> >()
123+
.add< MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
163124
#endif
164-
;
125+
);
165126

166-
const int CudaRodSpireSectionClass = core::RegisterObject("Class defining a rod spire section, defining material and geometry parameters using CUDA.")
167-
.add< sofa::beamadapter::RodSpireSection<CudaRigid3fTypes> >()
127+
factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a Rod Section using a MeshLoader and material parameters using CUDA.")
128+
.add< RodMeshSection<CudaRigid3fTypes> >()
168129
#ifdef SOFA_GPU_CUDA_DOUBLE
169-
.add< sofa::beamadapter::RodSpireSection<CudaRigid3dTypes> >()
130+
.add< RodMeshSection<CudaRigid3dTypes> >()
170131
#endif
171-
;
132+
);
172133

173-
const int CudaRodStraightSectionClass = core::RegisterObject("Class defining a rod straight section Material, defining material and geometry parameters using CUDA.")
174-
.add< sofa::beamadapter::RodStraightSection<CudaRigid3fTypes> >()
134+
factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a rod spire section, defining material and geometry parameters using CUDA.")
135+
.add< RodSpireSection<CudaRigid3fTypes> >()
175136
#ifdef SOFA_GPU_CUDA_DOUBLE
176-
.add< sofa::beamadapter::RodStraightSection<CudaRigid3dTypes> >()
137+
.add< RodSpireSection<CudaRigid3dTypes> >()
177138
#endif
178-
;
139+
);
179140

141+
factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a rod straight section Material, defining material and geometry parameters using CUDA.")
142+
.add< RodStraightSection<CudaRigid3fTypes> >()
143+
#ifdef SOFA_GPU_CUDA_DOUBLE
144+
.add< RodStraightSection<CudaRigid3dTypes> >()
145+
#endif
146+
);
147+
}
180148

181-
182-
183-
} // namespace sofa::gpu::cuda
184-
149+
} // namespace beamadapter

extensions/CUDA/src/BeamAdapter/CUDA/init.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@
2222
#include <BeamAdapter/CUDA/init.h>
2323
#include <BeamAdapter/initBeamAdapter.h>
2424
#include <SofaCUDA/init.h>
25+
2526
#include <sofa/core/ObjectFactory.h>
27+
#include <sofa/helper/system/PluginManager.h>
28+
2629
namespace beamadapter::cuda
2730
{
2831

32+
extern void registerBeamAdapterCUDAComponents(sofa::core::ObjectFactory* factory);
33+
2934
extern "C" {
3035
SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule();
3136
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName();
3237
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion();
33-
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleComponentList();
38+
SOFA_BEAMADAPTER_API void registerObjects(sofa::core::ObjectFactory* factory);
3439
}
3540

3641
void initExternalModule()
@@ -53,17 +58,18 @@ void init()
5358
static bool first = true;
5459
if (first)
5560
{
56-
sofa::component::initBeamAdapter();
61+
// make sure that this plugin is registered into the PluginManager
62+
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);
63+
64+
beamadapter::initBeamAdapter();
5765
sofa::gpu::cuda::init();
5866
first = false;
5967
}
6068
}
6169

62-
const char* getModuleComponentList()
70+
void registerObjects(sofa::core::ObjectFactory* factory)
6371
{
64-
/// string containing the names of the classes provided by the plugin
65-
static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(MODULE_NAME);
66-
return classes.c_str();
72+
registerBeamAdapterCUDAComponents(factory);
6773
}
6874

6975
} // namespace beamadapter::cuda

src/BeamAdapter/component/engine/WireRestShape.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void WireRestShape<DataTypes>::getMechanicalSampling(Real &dx, const Real x_curv
198198
Real x_used = x_curv - EPSILON;
199199

200200
const Real totalLength = this->getLength();
201-
x_used = std::clamp(x_used, 0.0, totalLength);
201+
x_used = std::clamp(x_used, static_cast<Real>(0.0), totalLength);
202202

203203
const type::vector<Real>& keyPts = d_keyPoints.getValue();
204204

0 commit comments

Comments
 (0)