Skip to content

Commit

Permalink
Introduce CUDA extension (#259)
Browse files Browse the repository at this point in the history
* Introduce CUDA extension

* CUDA template specialization

* Change folder hierarchy according to the guidelines
  • Loading branch information
alxbilger authored Feb 8, 2024
1 parent 4ef05c2 commit 1a87c27
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,6 @@ if(SOFTROBOTS_BUILD_TESTS)
add_subdirectory(tests)
endif()

sofa_add_subdirectory(plugin extensions/CUDA SoftRobots.CUDA)

include(cmake/packaging.cmake)
31 changes: 31 additions & 0 deletions extensions/CUDA/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.12)
project(SoftRobots.CUDA)

set(HEADER_FILES
src/SoftRobots/CUDA/init.h
src/SoftRobots/CUDA/config.h.in
)

set(SOURCE_FILES
src/SoftRobots/CUDA/init.cpp

src/SoftRobots/CUDA/component/forcefield/CUDAPartialRigidificationForceField.cpp
src/SoftRobots/CUDA/component/forcefield/CUDAPipeForceField.cpp
src/SoftRobots/CUDA/component/forcefield/CUDAPREquivalentStiffnessForceField.cpp
)

sofa_find_package(SoftRobots REQUIRED)
sofa_find_package(SofaCUDA REQUIRED)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} SoftRobots)
target_link_libraries(${PROJECT_NAME} SofaCUDA)

sofa_create_package_with_targets(
PACKAGE_NAME ${PROJECT_NAME}
PACKAGE_VERSION ${Sofa_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
RELOCATABLE "plugins"
)
9 changes: 9 additions & 0 deletions extensions/CUDA/SoftRobots.CUDAConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CMake package configuration file for the SoftRobots.CUDA library

@PACKAGE_GUARD@
@PACKAGE_INIT@

find_package(SoftRobots QUIET REQUIRED)
find_package(SofaCUDA QUIET REQUIRED)

check_required_components(SoftRobots.CUDA)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Plugin SoftRobots *
* *
* This plugin is also distributed under the GNU LGPL (Lesser General *
* Public License) license with the same conditions than SOFA. *
* *
* Contributors: Defrost team (INRIA, University of Lille, CNRS, *
* Ecole Centrale de Lille) *
* *
* Contact information: https://project.inria.fr/softrobot/contact/ *
******************************************************************************/
#include <SoftRobots/CUDA/config.h>
#include <SofaCUDA/sofa/gpu/cuda/CudaTypes.h>
#include <SoftRobots/component/forcefield/PREquivalentStiffnessForceField.inl>
#include <sofa/core/ObjectFactory.h>

namespace softrobots::forcefield
{
template class SOFA_SOFTROBOTS_CUDA_API PREquivalentStiffnessForceField<sofa::gpu::cuda::CudaRigid3fTypes>;

#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_SOFTROBOTS_CUDA_API PREquivalentStiffnessForceField<sofa::gpu::cuda::CudaRigid3dTypes>;
#endif
}

int CUDAPREquivalentStiffnessForceFieldClass = sofa::core::RegisterObject("Supports GPU-side computations using CUDA")
.add< softrobots::forcefield::PREquivalentStiffnessForceField<sofa::gpu::cuda::CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< softrobots::forcefield::PREquivalentStiffnessForceField<sofa::gpu::cuda::CudaRigid3dTypes> >()
#endif
;

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Plugin SoftRobots *
* *
* This plugin is also distributed under the GNU LGPL (Lesser General *
* Public License) license with the same conditions than SOFA. *
* *
* Contributors: Defrost team (INRIA, University of Lille, CNRS, *
* Ecole Centrale de Lille) *
* *
* Contact information: https://project.inria.fr/softrobot/contact/ *
******************************************************************************/
#include <SoftRobots/CUDA/config.h>
#include <SofaCUDA/sofa/gpu/cuda/CudaTypes.h>
#include <SoftRobots/component/forcefield/PartialRigidificationForceField.inl>
#include <sofa/core/ObjectFactory.h>

namespace softrobots::forcefield
{
template class SOFA_SOFTROBOTS_CUDA_API PartialRigidificationForceField<sofa::gpu::cuda::CudaVec3fTypes, sofa::gpu::cuda::CudaRigid3fTypes>;

#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_SOFTROBOTS_CUDA_API PartialRigidificationForceField<sofa::gpu::cuda::CudaVec3dTypes, sofa::gpu::cuda::CudaRigid3dTypes>;
#endif
}

int CUDAPartialRigidificationForceFieldClass = sofa::core::RegisterObject("Supports GPU-side computations using CUDA")
.add< softrobots::forcefield::PartialRigidificationForceField<sofa::gpu::cuda::CudaVec3fTypes, sofa::gpu::cuda::CudaRigid3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< softrobots::forcefield::PartialRigidificationForceField<sofa::gpu::cuda::CudaVec3dTypes, sofa::gpu::cuda::CudaRigid3dTypes> >()
#endif
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Plugin SoftRobots *
* *
* This plugin is also distributed under the GNU LGPL (Lesser General *
* Public License) license with the same conditions than SOFA. *
* *
* Contributors: Defrost team (INRIA, University of Lille, CNRS, *
* Ecole Centrale de Lille) *
* *
* Contact information: https://project.inria.fr/softrobot/contact/ *
******************************************************************************/
#include <SoftRobots/CUDA/config.h>
#include <SofaCUDA/sofa/gpu/cuda/CudaTypes.h>
#include <SoftRobots/component/forcefield/PipeForceField.inl>
#include <sofa/core/ObjectFactory.h>

namespace softrobots::forcefield
{
template class SOFA_SOFTROBOTS_CUDA_API PipeForceField<sofa::gpu::cuda::CudaVec3fTypes>;

#ifdef SOFA_GPU_CUDA_DOUBLE
template class SOFA_SOFTROBOTS_CUDA_API PipeForceField<sofa::gpu::cuda::CudaVec3dTypes>;
#endif
}

int CUDAPipeForceFieldClass = sofa::core::RegisterObject("Supports GPU-side computations using CUDA")
.add< softrobots::forcefield::PipeForceField<sofa::gpu::cuda::CudaVec3fTypes> >()
#ifdef SOFA_GPU_CUDA_DOUBLE
.add< softrobots::forcefield::PipeForceField<sofa::gpu::cuda::CudaVec3dTypes> >()
#endif
;
43 changes: 43 additions & 0 deletions extensions/CUDA/src/SoftRobots/CUDA/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Plugin SoftRobots *
* *
* This plugin is also distributed under the GNU LGPL (Lesser General *
* Public License) license with the same conditions than SOFA. *
* *
* Contributors: Defrost team (INRIA, University of Lille, CNRS, *
* Ecole Centrale de Lille) *
* *
* Contact information: https://project.inria.fr/softrobot/contact/ *
******************************************************************************/
#pragma once

#include <sofa/config.h>

#ifdef SOFA_BUILD_SOFTROBOTS_CUDA
# define SOFA_TARGET @PROJECT_NAME@
# define SOFA_SOFTROBOTS_CUDA_API SOFA_EXPORT_DYNAMIC_LIBRARY
#else
# define SOFA_SOFTROBOTS_CUDA_API SOFA_IMPORT_DYNAMIC_LIBRARY
#endif

namespace softrobots::cuda
{
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
} // namespace softrobots::cuda
71 changes: 71 additions & 0 deletions extensions/CUDA/src/SoftRobots/CUDA/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Plugin SoftRobots *
* *
* This plugin is also distributed under the GNU LGPL (Lesser General *
* Public License) license with the same conditions than SOFA. *
* *
* Contributors: Defrost team (INRIA, University of Lille, CNRS, *
* Ecole Centrale de Lille) *
* *
* Contact information: https://project.inria.fr/softrobot/contact/ *
******************************************************************************/
#include <SoftRobots/CUDA/init.h>
#include <sofa/core/ObjectFactory.h>
namespace softrobots::cuda
{

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();
}

void initExternalModule()
{
init();
}

const char* getModuleName()
{
return MODULE_NAME;
}

const char* getModuleVersion()
{
return MODULE_VERSION;
}

void init()
{
static bool first = true;
if (first)
{
first = false;
}
}

const char* getModuleComponentList()
{
/// 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();
}

} // namespace softrobots::cuda
35 changes: 35 additions & 0 deletions extensions/CUDA/src/SoftRobots/CUDA/init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Plugin SoftRobots *
* *
* This plugin is also distributed under the GNU LGPL (Lesser General *
* Public License) license with the same conditions than SOFA. *
* *
* Contributors: Defrost team (INRIA, University of Lille, CNRS, *
* Ecole Centrale de Lille) *
* *
* Contact information: https://project.inria.fr/softrobot/contact/ *
******************************************************************************/
#pragma once

#include <SoftRobots/CUDA/config.h>

namespace softrobots::cuda
{
SOFA_SOFTROBOTS_CUDA_API void init();
} // namespace softrobots::cuda
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public :
typedef typename DataTypes::Deriv Deriv;
typedef typename Coord::Pos Pos;
typedef typename Coord::Quat Quaternion;
typedef sofa::type::vector<Coord> VecCoord;
typedef sofa::type::vector<Deriv> VecDeriv;
typedef typename DataTypes::VecCoord VecCoord;
typedef typename DataTypes::VecDeriv VecDeriv;
typedef sofa::Data<VecCoord> DataVecCoord;
typedef sofa::Data<VecDeriv> DataVecDeriv;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <fstream>

#include <SoftRobots/component/forcefield/PartialRigidificationForceField.h>
#include <sofa/core/behavior/MixedInteractionForceField.inl>

namespace softrobots::forcefield
{
Expand Down

0 comments on commit 1a87c27

Please sign in to comment.