diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mapping/linear/CudaBarycentricMappingRigid.cpp b/applications/plugins/SofaCUDA/src/SofaCUDA/component/mapping/linear/CudaBarycentricMappingRigid.cpp index 622e1c7fb2a..c8c3ce2d39d 100644 --- a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mapping/linear/CudaBarycentricMappingRigid.cpp +++ b/applications/plugins/SofaCUDA/src/SofaCUDA/component/mapping/linear/CudaBarycentricMappingRigid.cpp @@ -41,21 +41,13 @@ #include #include +using namespace sofa::defaulttype; namespace sofa::component::mapping::linear { -using namespace sofa::defaulttype; using namespace sofa::gpu::cuda; -// Register in the Factory -void registerBarycentricMapping(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the BarycentricMapping") - .add< BarycentricMapping< CudaVec3Types, Rigid3Types > >()); -} - - template <> void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { @@ -191,8 +183,17 @@ void BarycentricMapperHexahedronSetTopology; } // namespace sofa::component::mapping::linear + + +namespace sofa::gpu::cuda +{ + // Register in the Factory + void registerBarycentricMapping_3fRigid(sofa::core::ObjectFactory* factory) + { + factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the BarycentricMapping") + .add< sofa::component::mapping::linear::BarycentricMapping< CudaVec3Types, sofa::defaulttype::Rigid3Types > >()); + } +} diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/config.h.in b/applications/plugins/SofaCUDA/src/SofaCUDA/config.h.in index 6a95d2aa7ff..0773e63ffe2 100644 --- a/applications/plugins/SofaCUDA/src/SofaCUDA/config.h.in +++ b/applications/plugins/SofaCUDA/src/SofaCUDA/config.h.in @@ -19,8 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFACUDA_CONFIG_H -#define SOFACUDA_CONFIG_H +#pragma once #include @@ -42,4 +41,8 @@ # define SOFA_GPU_CUDA_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif -#endif +namespace sofa::gpu::cuda +{ + constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; + constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} // namespace sofa::gpu::cuda diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/init.cpp b/applications/plugins/SofaCUDA/src/SofaCUDA/init.cpp index 14a5c7c1a75..80453cbf2dd 100644 --- a/applications/plugins/SofaCUDA/src/SofaCUDA/init.cpp +++ b/applications/plugins/SofaCUDA/src/SofaCUDA/init.cpp @@ -27,16 +27,117 @@ namespace sofa::gpu::cuda { -//Here are just several convenient functions to help user to know what contains the plugin +// component::collision::geometry +extern void registerLineCollisionModel(sofa::core::ObjectFactory* factory); +extern void registerPointCollisionModel(sofa::core::ObjectFactory* factory); +extern void registerSphereCollisionModel(sofa::core::ObjectFactory* factory); +extern void registerTriangleCollisionModel(sofa::core::ObjectFactory* factory); + +// component::collision::response::contact +extern void registerPenalityContactForceField(sofa::core::ObjectFactory* factory); + +// component::constraint::lagrangian::correction +extern void registerLinearSolverConstraintCorrection(sofa::core::ObjectFactory* factory); +extern void registerPrecomputedConstraintCorrection(sofa::core::ObjectFactory* factory); +extern void registerUncoupledConstraintCorrection(sofa::core::ObjectFactory* factory); + +// component::constraint::lagrangian::model +extern void registerBilateralLagrangianConstraint(sofa::core::ObjectFactory* factory); + +// component::constraint::projective +extern void registerFixedProjectiveConstraint(sofa::core::ObjectFactory* factory); +extern void registerFixedTranslationProjectiveConstraint(sofa::core::ObjectFactory* factory); +extern void registerLinearMovementProjectiveConstraint(sofa::core::ObjectFactory* factory); +extern void registerLinearVelocityProjectiveConstraint(sofa::core::ObjectFactory* factory); + +// component::engine::select +extern void registerBoxROI(sofa::core::ObjectFactory* factory); +extern void registerNearestPointROI(sofa::core::ObjectFactory* factory); +extern void registerSphereROI(sofa::core::ObjectFactory* factory); + +// component::engine::transform +extern void registerIndexValueMapper(sofa::core::ObjectFactory* factory); + +// component::mapping::linear +extern void registerBarycentricMapping(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_f(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_3fRigid(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_3f(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_3f1(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_3f1_f(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_3f1_3f(sofa::core::ObjectFactory* factory); +extern void registerBarycentricMapping_3f1_d(sofa::core::ObjectFactory* factory); +extern void registerBeamLinearMapping(sofa::core::ObjectFactory* factory); +extern void registerIdentityMapping(sofa::core::ObjectFactory* factory); +extern void registerSubsetMapping(sofa::core::ObjectFactory* factory); +extern void registerSubsetMultiMapping(sofa::core::ObjectFactory* factory); + +// component::mapping::nonlinear +extern void registerRigidMapping(sofa::core::ObjectFactory* factory); + +// component::mass +extern void registerDiagonalMass(sofa::core::ObjectFactory* factory); +extern void registerMeshMatrixMass(sofa::core::ObjectFactory* factory); +extern void registerUniformMass(sofa::core::ObjectFactory* factory); + +// component::mechanicalload +extern void registerConstantForceField(sofa::core::ObjectFactory* factory); +extern void registerEllipsoidForceField(sofa::core::ObjectFactory* factory); +extern void registerLinearForceField(sofa::core::ObjectFactory* factory); +extern void registerPlaneForceField(sofa::core::ObjectFactory* factory); +extern void registerSphereForceField(sofa::core::ObjectFactory* factory); + +// component::solidmechanics::fem::elastic +extern void registerHexahedronFEMForceField(sofa::core::ObjectFactory* factory); +extern void registerTetrahedronFEMForceField(sofa::core::ObjectFactory* factory); +extern void registerTriangularFEMForceFieldOptim(sofa::core::ObjectFactory* factory); + +// component::solidmechanics::fem::hyperelastic +extern void registerStandardTetrahedralFEMForceField(sofa::core::ObjectFactory* factory); +// component::solidmechanics::spring +extern void registerMeshSpringForceField(sofa::core::ObjectFactory* factory); +extern void registerQuadBendingSprings(sofa::core::ObjectFactory* factory); +extern void registerRestShapeSpringsForceField(sofa::core::ObjectFactory* factory); +extern void registerSpringForceField(sofa::core::ObjectFactory* factory); +extern void registerTriangleBendingSprings(sofa::core::ObjectFactory* factory); + +// component::solidmechanics::tensormass +extern void registerTetrahedralTensorMassForceField(sofa::core::ObjectFactory* factory); + +// component::statecontainer +extern void registerMechanicalObject(sofa::core::ObjectFactory* factory); + +// component::visualmodel +extern void registerVisualModel(sofa::core::ObjectFactory* factory); + +// component::collision::detection::intersection +extern void registerProximityIntersection(sofa::core::ObjectFactory* factory); + +// component::topology::container::dynamic +extern void registerPointSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerEdgeSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerTriangleSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerQuadSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerTetrahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); +extern void registerHexahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory); + +// gui::component::performer; +extern void registerMouseInteractor(sofa::core::ObjectFactory* factory); + +// SofaCUDA +extern void registerTetrahedronTLEDForceField(sofa::core::ObjectFactory* factory); +extern void registerHexahedronTLEDForceField(sofa::core::ObjectFactory* factory); + +//Here are just several convenient functions to help user to know what contains the plugin extern "C" { SOFA_GPU_CUDA_API void initExternalModule(); SOFA_GPU_CUDA_API const char* getModuleName(); SOFA_GPU_CUDA_API const char* getModuleVersion(); SOFA_GPU_CUDA_API const char* getModuleLicense(); SOFA_GPU_CUDA_API const char* getModuleDescription(); -SOFA_GPU_CUDA_API const char* getModuleComponentList(); SOFA_GPU_CUDA_API bool moduleIsInitialized(); +SOFA_GPU_CUDA_API void registerObjects(sofa::core::ObjectFactory* factory); } bool isModuleInitialized = false; @@ -58,12 +159,12 @@ void initExternalModule() const char* getModuleName() { - return "SofaCUDA"; + return MODULE_NAME; } const char* getModuleVersion() { - return "1.0"; + return MODULE_VERSION; } const char* getModuleLicense() @@ -76,16 +177,71 @@ const char* getModuleDescription() return "GPU-based computing using NVIDIA CUDA"; } -const char* getModuleComponentList() +bool moduleIsInitialized() { - /// string containing the names of the classes provided by the plugin - static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET)); - return classes.c_str(); + return isModuleInitialized; } -bool moduleIsInitialized() +void registerObjects(sofa::core::ObjectFactory* factory) { - return isModuleInitialized; + registerLineCollisionModel(factory); + registerPointCollisionModel(factory); + registerSphereCollisionModel(factory); + registerTriangleCollisionModel(factory); + registerPenalityContactForceField(factory); + registerLinearSolverConstraintCorrection(factory); + registerPrecomputedConstraintCorrection(factory); + registerUncoupledConstraintCorrection(factory); + registerBilateralLagrangianConstraint(factory); + registerFixedProjectiveConstraint(factory); + registerFixedTranslationProjectiveConstraint(factory); + registerLinearMovementProjectiveConstraint(factory); + registerLinearVelocityProjectiveConstraint(factory); + registerBoxROI(factory); + registerNearestPointROI(factory); + registerSphereROI(factory); + registerIndexValueMapper(factory); + registerBarycentricMapping(factory); + registerBarycentricMapping_f(factory); + registerBarycentricMapping_3fRigid(factory); + registerBarycentricMapping_3f(factory); + registerBarycentricMapping_3f1(factory); + registerBarycentricMapping_3f1_f(factory); + registerBarycentricMapping_3f1_3f(factory); + registerBarycentricMapping_3f1_d(factory); + registerBeamLinearMapping(factory); + registerIdentityMapping(factory); + registerSubsetMapping(factory); + registerSubsetMultiMapping(factory); + registerRigidMapping(factory); + registerDiagonalMass(factory); + registerMeshMatrixMass(factory); + registerUniformMass(factory); + registerConstantForceField(factory); + registerEllipsoidForceField(factory); + registerLinearForceField(factory); + registerPlaneForceField(factory); + registerSphereForceField(factory); + registerHexahedronFEMForceField(factory); + registerTetrahedronFEMForceField(factory); + registerTriangularFEMForceFieldOptim(factory); + registerStandardTetrahedralFEMForceField(factory); + registerMeshSpringForceField(factory); + registerQuadBendingSprings(factory); + registerRestShapeSpringsForceField(factory); + registerSpringForceField(factory); + registerTriangleBendingSprings(factory); + registerTetrahedralTensorMassForceField(factory); + registerMechanicalObject(factory); + registerVisualModel(factory); + registerProximityIntersection(factory); + registerPointSetGeometryAlgorithms(factory); + registerEdgeSetGeometryAlgorithms(factory); + registerTriangleSetGeometryAlgorithms(factory); + registerQuadSetGeometryAlgorithms(factory); + registerTetrahedronSetGeometryAlgorithms(factory); + registerHexahedronSetGeometryAlgorithms(factory); + registerMouseInteractor(factory); } } diff --git a/applications/plugins/SofaCUDA/src/sofa/gpu/cuda/CudaSetTopology.cpp b/applications/plugins/SofaCUDA/src/sofa/gpu/cuda/CudaSetTopology.cpp index 2d5c1204009..fecc1158cdd 100644 --- a/applications/plugins/SofaCUDA/src/sofa/gpu/cuda/CudaSetTopology.cpp +++ b/applications/plugins/SofaCUDA/src/sofa/gpu/cuda/CudaSetTopology.cpp @@ -50,49 +50,80 @@ using namespace sofa::core; using namespace sofa::gpu::cuda; using namespace sofa::core::behavior; -/* -/// Cross product for 3-elements vectors. -template< class Real> -Real areaProduct(const Vec3r1& a, const Vec3r1& b) -{ - return Vec<3,Real>(a.y()*b.z() - a.z()*b.y(), - a.z()*b.x() - a.x()*b.z(), - a.x()*b.y() - a.y()*b.x()).norm(); -} +//////////////////////////////// +//////// Point //////// +//////////////////////////////// +#ifdef SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API PointSetGeometryAlgorithms; +#endif // SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API PointSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API PointSetGeometryAlgorithms; -/// Volume (triple product) for 3-elements vectors. -template -inline real tripleProduct(const Vec3r1& a, const Vec3r1& b,const Vec3r1 &c) -{ - return dot(a,cross(b,c)); -} -*/ +//////////////////////////////// +//////// Edge //////// +//////////////////////////////// +#ifdef SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API EdgeSetGeometryAlgorithms; +#endif // SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API EdgeSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API EdgeSetGeometryAlgorithms; + //////////////////////////////// -//////// Point //////// +//////// Triangle //////// //////////////////////////////// +#ifdef SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API TriangleSetGeometryAlgorithms; +#endif // SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API TriangleSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API TriangleSetGeometryAlgorithms; -void registerPointSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) -{ - factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the PointSetGeometryAlgorithms") + +//////////////////////////////// +//////// Quad //////// +//////////////////////////////// #ifdef SOFA_GPU_CUDA_DOUBLE - .add< PointSetGeometryAlgorithms >() +template class SOFA_GPU_CUDA_API QuadSetGeometryAlgorithms; #endif // SOFA_GPU_CUDA_DOUBLE - .add< PointSetGeometryAlgorithms >() - .add< PointSetGeometryAlgorithms >()); -} +template class SOFA_GPU_CUDA_API QuadSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API QuadSetGeometryAlgorithms; + +//////////////////////////////// +//////// Tetrahedron //////// +//////////////////////////////// #ifdef SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API PointSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API TetrahedronSetGeometryAlgorithms; #endif // SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API PointSetGeometryAlgorithms; -template class SOFA_GPU_CUDA_API PointSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API TetrahedronSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API TetrahedronSetGeometryAlgorithms; //////////////////////////////// -//////// Edge //////// +//////// Hexahedron //////// //////////////////////////////// +#ifdef SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API HexahedronSetGeometryAlgorithms; +#endif // SOFA_GPU_CUDA_DOUBLE +template class SOFA_GPU_CUDA_API HexahedronSetGeometryAlgorithms; +template class SOFA_GPU_CUDA_API HexahedronSetGeometryAlgorithms; + +} // namespace sofa::component::topology::container::dynamic + +namespace sofa::gpu::cuda +{ +using namespace sofa::component::topology::container::dynamic; + +void registerPointSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the PointSetGeometryAlgorithms") +#ifdef SOFA_GPU_CUDA_DOUBLE + .add< PointSetGeometryAlgorithms >() +#endif // SOFA_GPU_CUDA_DOUBLE + .add< PointSetGeometryAlgorithms >() + .add< PointSetGeometryAlgorithms >()); +} void registerEdgeSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) { @@ -104,17 +135,6 @@ void registerEdgeSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) .add< EdgeSetGeometryAlgorithms >()); } -#ifdef SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API EdgeSetGeometryAlgorithms; -#endif // SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API EdgeSetGeometryAlgorithms; -template class SOFA_GPU_CUDA_API EdgeSetGeometryAlgorithms; - - -//////////////////////////////// -//////// Triangle //////// -//////////////////////////////// - void registerTriangleSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) { factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the TriangleSetGeometryAlgorithms") @@ -125,17 +145,6 @@ void registerTriangleSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) .add< TriangleSetGeometryAlgorithms >()); } -#ifdef SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API TriangleSetGeometryAlgorithms; -#endif // SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API TriangleSetGeometryAlgorithms; -template class SOFA_GPU_CUDA_API TriangleSetGeometryAlgorithms; - - -//////////////////////////////// -//////// Quad //////// -//////////////////////////////// - void registerQuadSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) { factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the QuadSetGeometryAlgorithms") @@ -145,18 +154,6 @@ void registerQuadSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) .add< QuadSetGeometryAlgorithms >() .add< QuadSetGeometryAlgorithms >()); } - -#ifdef SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API QuadSetGeometryAlgorithms; -#endif // SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API QuadSetGeometryAlgorithms; -template class SOFA_GPU_CUDA_API QuadSetGeometryAlgorithms; - - -//////////////////////////////// -//////// Tetrahedron //////// -//////////////////////////////// - void registerTetrahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) { factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the TetrahedronSetGeometryAlgorithms") @@ -167,17 +164,6 @@ void registerTetrahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory .add< TetrahedronSetGeometryAlgorithms >()); } -#ifdef SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API TetrahedronSetGeometryAlgorithms; -#endif // SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API TetrahedronSetGeometryAlgorithms; -template class SOFA_GPU_CUDA_API TetrahedronSetGeometryAlgorithms; - - -//////////////////////////////// -//////// Hexahedron //////// -//////////////////////////////// - void registerHexahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) { factory->registerObjects(sofa::core::ObjectRegistrationData("Supports GPU-side computations using CUDA for the HexahedronSetGeometryAlgorithms") @@ -188,10 +174,4 @@ void registerHexahedronSetGeometryAlgorithms(sofa::core::ObjectFactory* factory) .add< HexahedronSetGeometryAlgorithms >()); } -#ifdef SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API HexahedronSetGeometryAlgorithms; -#endif // SOFA_GPU_CUDA_DOUBLE -template class SOFA_GPU_CUDA_API HexahedronSetGeometryAlgorithms; -template class SOFA_GPU_CUDA_API HexahedronSetGeometryAlgorithms; - -} // namespace sofa::component::topology::container::dynamic +} // namespace sofa::gpu::cuda