Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.12)
project(BeamAdapter VERSION 1.0)
project(BeamAdapter VERSION 1.0 LANGUAGES CXX)

include(cmake/environment.cmake)

Expand Down
2 changes: 1 addition & 1 deletion extensions/CUDA/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.12)
project(BeamAdapter.CUDA)
project(BeamAdapter.CUDA LANGUAGES CXX CUDA)

set(HEADER_FILES
src/BeamAdapter/CUDA/init.h
Expand Down
149 changes: 57 additions & 92 deletions extensions/CUDA/src/BeamAdapter/CUDA/CudaInstantiations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <BeamAdapter/CUDA/config.h>
#include <SofaCUDA/sofa/gpu/cuda/CudaTypes.h>
#include <sofa/gpu/cuda/CudaTypes.h>

#include <BeamAdapter/component/WireBeamInterpolation.inl>
#include <BeamAdapter/component/BeamInterpolation.inl>
Expand All @@ -36,149 +36,114 @@
#include <sofa/core/behavior/Mass.inl>
#include <sofa/core/Mapping.inl>
#include <sofa/component/controller/MechanicalStateController.inl>
#include <sofa/component/constraint/projective/FixedConstraint.inl> // for InterventionalRadiologyController
#include <sofa/component/constraint/projective/FixedProjectiveConstraint.inl> // for InterventionalRadiologyController

#include <sofa/core/ObjectFactory.h>

using namespace sofa::gpu::cuda;

namespace sofa::component::fem::_beaminterpolation_
namespace beamadapter::cuda
{
// template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation<CudaRigid3fTypes>;
#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation<CudaRigid3dTypes>;
#endif
} // namespace sofa::component::fem::_beaminterpolation_

namespace sofa::component::fem::_wirebeaminterpolation_
{
// template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation<CudaRigid3fTypes>;
#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation<CudaRigid3dTypes>;
#endif
} // namespace sofa::component::fem::_beaminterpolation_

namespace sofa::component::engine::_wirerestshape_
{
template class SOFA_BEAMADAPTER_CUDA_API WireRestShape<CudaRigid3fTypes>;
#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API WireRestShape<CudaRigid3dTypes>;
#endif
} // namespace sofa::component::engine::_wirerestshape_

namespace sofa::component::controller::_interventionalradiologycontroller_
{
template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController<CudaRigid3fTypes>;
#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController<CudaRigid3dTypes>;
#endif
} // namespace sofa::component::controller::_interventionalradiologycontroller_

namespace sofa::component::mapping::_adaptivebeammapping_
{
template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types>;
#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
#endif
} // namespace sofa::component::mapping::_adaptivebeammapping_

namespace sofa::component::mapping
{
template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types>;
#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
#endif
} // namespace sofa::component::mapping

namespace sofa::beamadapter
{
template class SOFA_BEAMADAPTER_CUDA_API RodMeshSection<CudaRigid3fTypes>;
template class SOFA_BEAMADAPTER_CUDA_API RodSpireSection<CudaRigid3fTypes>;
template class SOFA_BEAMADAPTER_CUDA_API RodStraightSection<CudaRigid3fTypes>;

#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_BEAMADAPTER_CUDA_API BeamInterpolation<CudaRigid3dTypes>;
template class SOFA_BEAMADAPTER_CUDA_API WireBeamInterpolation<CudaRigid3dTypes>;
template class SOFA_BEAMADAPTER_CUDA_API WireRestShape<CudaRigid3dTypes>;
template class SOFA_BEAMADAPTER_CUDA_API InterventionalRadiologyController<CudaRigid3dTypes>;
template class SOFA_BEAMADAPTER_CUDA_API AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
template class SOFA_BEAMADAPTER_CUDA_API MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types>;
template class SOFA_BEAMADAPTER_CUDA_API RodMeshSection<CudaRigid3dTypes>;
template class SOFA_BEAMADAPTER_CUDA_API RodSpireSection<CudaRigid3dTypes>;
template class SOFA_BEAMADAPTER_CUDA_API RodStraightSection<CudaRigid3dTypes>;
#endif
} // namespace sofa::beamadapter

using namespace sofa::gpu::cuda;

namespace sofa::gpu::cuda
void registerBeamAdapterCUDAComponents(sofa::core::ObjectFactory* factory)
{

#ifdef SOFA_GPU_CUDA_DOUBLE
int CudaBeamInterpolationClass = core::RegisterObject("Adaptive Beam Interpolation - Supports GPU-side computations using CUDA")
// .add< sofa::component::fem::BeamInterpolation<CudaRigid3fTypes> >()
.add< sofa::component::fem::BeamInterpolation<CudaRigid3dTypes> >()
;
factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Beam Interpolation - Supports GPU-side computations using CUDA")
// .add< BeamInterpolation<CudaRigid3fTypes> >()
.add< BeamInterpolation<CudaRigid3dTypes> >());
#endif

#ifdef SOFA_GPU_CUDA_DOUBLE
int CudaWireBeamInterpolationClass = core::RegisterObject("Adaptive Wire Beam Interpolation - Supports GPU-side computations using CUDA")
// .add< sofa::component::fem::WireBeamInterpolation<CudaRigid3fTypes> >()
.add< sofa::component::fem::WireBeamInterpolation<CudaRigid3dTypes> >()
;
factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Wire Beam Interpolation - Supports GPU-side computations using CUDA")
// .add< WireBeamInterpolation<CudaRigid3fTypes> >()
.add< WireBeamInterpolation<CudaRigid3dTypes> >());
#endif

int CudaWireRestShapenClass = core::RegisterObject("Wire Shape - Supports GPU-side computations using CUDA")
.add< sofa::component::engine::WireRestShape<CudaRigid3fTypes> >()
factory->registerObjects(sofa::core::ObjectRegistrationData("Wire Shape - Supports GPU-side computations using CUDA")
.add< WireRestShape<CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::component::engine::WireRestShape<CudaRigid3dTypes> >()
.add< WireRestShape<CudaRigid3dTypes> >()
#endif
;
);

int CudaAdaptiveBeamForceFieldAndMassClass = core::RegisterObject("Adaptive Beam finite elements - Supports GPU-side computations using CUDA")
.add< sofa::component::forcefield::AdaptiveBeamForceFieldAndMass<CudaRigid3fTypes> >()
factory->registerObjects(sofa::core::ObjectRegistrationData("Adaptive Beam finite elements - Supports GPU-side computations using CUDA")
.add< AdaptiveBeamForceFieldAndMass<CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::component::forcefield::AdaptiveBeamForceFieldAndMass<CudaRigid3dTypes> >()
.add< AdaptiveBeamForceFieldAndMass<CudaRigid3dTypes> >()
#endif
;
);

int CudaInterventionalRadiologyControllerClass = core::RegisterObject("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA")
.add< sofa::component::controller::InterventionalRadiologyController<CudaRigid3fTypes> >()
factory->registerObjects(sofa::core::ObjectRegistrationData("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA")
.add< InterventionalRadiologyController<CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::component::controller::InterventionalRadiologyController<CudaRigid3dTypes> >()
.add< InterventionalRadiologyController<CudaRigid3dTypes> >()
#endif
;
);

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")
.add< sofa::component::mapping::AdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
factory->registerObjects(sofa::core::ObjectRegistrationData("Provides a Mouse & Keyboard user control on an EdgeSet Topology - Supports GPU-side computations using CUDA")
.add< InterventionalRadiologyController<CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::component::mapping::AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
.add< InterventionalRadiologyController<CudaRigid3dTypes> >()
#endif
;
);

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")
.add< sofa::component::mapping::MultiAdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
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")
.add< AdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::component::mapping::MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
.add< AdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
#endif
;
);

const int CudaRodMeshSectionClass = core::RegisterObject("Class defining a Rod Section using a MeshLoader and material parameters using CUDA.")
.add< sofa::beamadapter::RodMeshSection<CudaRigid3fTypes> >()
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")
.add< MultiAdaptiveBeamMapping<CudaRigid3fTypes, defaulttype::Vec3Types> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::beamadapter::RodMeshSection<CudaRigid3dTypes> >()
.add< MultiAdaptiveBeamMapping<CudaRigid3dTypes, defaulttype::Vec3Types> >()
#endif
;
);

const int CudaRodSpireSectionClass = core::RegisterObject("Class defining a rod spire section, defining material and geometry parameters using CUDA.")
.add< sofa::beamadapter::RodSpireSection<CudaRigid3fTypes> >()
factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a Rod Section using a MeshLoader and material parameters using CUDA.")
.add< RodMeshSection<CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::beamadapter::RodSpireSection<CudaRigid3dTypes> >()
.add< RodMeshSection<CudaRigid3dTypes> >()
#endif
;
);

const int CudaRodStraightSectionClass = core::RegisterObject("Class defining a rod straight section Material, defining material and geometry parameters using CUDA.")
.add< sofa::beamadapter::RodStraightSection<CudaRigid3fTypes> >()
factory->registerObjects(sofa::core::ObjectRegistrationData("Class defining a rod spire section, defining material and geometry parameters using CUDA.")
.add< RodSpireSection<CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< sofa::beamadapter::RodStraightSection<CudaRigid3dTypes> >()
.add< RodSpireSection<CudaRigid3dTypes> >()
#endif
;
);

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



} // namespace sofa::gpu::cuda

} // namespace beamadapter
18 changes: 12 additions & 6 deletions extensions/CUDA/src/BeamAdapter/CUDA/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
#include <BeamAdapter/CUDA/init.h>
#include <BeamAdapter/initBeamAdapter.h>
#include <SofaCUDA/init.h>

#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace beamadapter::cuda
{

extern void registerBeamAdapterCUDAComponents(sofa::core::ObjectFactory* factory);

extern "C" {
SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleComponentList();
SOFA_BEAMADAPTER_API void registerObjects(sofa::core::ObjectFactory* factory);
}

void initExternalModule()
Expand All @@ -53,17 +58,18 @@ void init()
static bool first = true;
if (first)
{
sofa::component::initBeamAdapter();
// make sure that this plugin is registered into the PluginManager
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);

beamadapter::initBeamAdapter();
sofa::gpu::cuda::init();
first = false;
}
}

const char* getModuleComponentList()
void registerObjects(sofa::core::ObjectFactory* factory)
{
/// string containing the names of the classes provided by the plugin
static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(MODULE_NAME);
return classes.c_str();
registerBeamAdapterCUDAComponents(factory);
}

} // namespace beamadapter::cuda
2 changes: 1 addition & 1 deletion src/BeamAdapter/component/engine/WireRestShape.inl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void WireRestShape<DataTypes>::getMechanicalSampling(Real &dx, const Real x_curv
Real x_used = x_curv - EPSILON;

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

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

Expand Down
Loading