From 3fc04364c9fb29400bdecd04dc681bcf905f7028 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 25 Feb 2026 16:09:21 +0900 Subject: [PATCH 1/2] rapatriate code from sofacuda --- CMakeLists.txt | 2 + extensions/CMakeLists.txt | 6 ++ extensions/CUDA/CMakeLists.txt | 30 +++++++ extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in | 9 ++ .../CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp | 79 ++++++++++++++++++ .../CUDA/src/sofa/qt/cuda/CudaDataWidget.h | 62 ++++++++++++++ extensions/CUDA/src/sofa/qt/cuda/config.h.in | 40 +++++++++ extensions/CUDA/src/sofa/qt/cuda/init.cpp | 83 +++++++++++++++++++ extensions/CUDA/src/sofa/qt/cuda/init.h | 30 +++++++ 9 files changed, 341 insertions(+) create mode 100644 extensions/CMakeLists.txt create mode 100644 extensions/CUDA/CMakeLists.txt create mode 100644 extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in create mode 100644 extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp create mode 100644 extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.h create mode 100644 extensions/CUDA/src/sofa/qt/cuda/config.h.in create mode 100644 extensions/CUDA/src/sofa/qt/cuda/init.cpp create mode 100644 extensions/CUDA/src/sofa/qt/cuda/init.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c0cf65d..d928935 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -438,3 +438,5 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows) include(windeployqt) windeployqt(${PROJECT_NAME} ${CMAKE_BINARY_DIR}/bin bin) endif() + +add_subdirectory(extensions) diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt new file mode 100644 index 0000000..0c9a428 --- /dev/null +++ b/extensions/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.22) + +find_package(Sofa.Config) + +sofa_add_subdirectory(plugin CUDA Sofa.Qt.CUDA) + diff --git a/extensions/CUDA/CMakeLists.txt b/extensions/CUDA/CMakeLists.txt new file mode 100644 index 0000000..e73655b --- /dev/null +++ b/extensions/CUDA/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.22) +project(Sofa.Qt.CUDA LANGUAGES CXX CUDA) + +set(SOFAQTCUDA_SOURCE_DIR "src/sofa/qt/cuda") +set(HEADER_FILES + ${SOFAQTCUDA_SOURCE_DIR}/init.h + ${SOFAQTCUDA_SOURCE_DIR}/config.h.in + ${SOFAQTCUDA_SOURCE_DIR}/CudaDataWidget.h +) + +set(SOURCE_FILES + ${SOFAQTCUDA_SOURCE_DIR}/init.cpp + ${SOFAQTCUDA_SOURCE_DIR}/CudaDataWidget.cpp +) + +sofa_find_package(Sofa.Qt REQUIRED) +sofa_find_package(SofaCUDA REQUIRED) + +add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) +target_link_libraries(${PROJECT_NAME} Sofa.Qt) +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" +) diff --git a/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in b/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in new file mode 100644 index 0000000..330b9d4 --- /dev/null +++ b/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in @@ -0,0 +1,9 @@ +# CMake package configuration file for the BeamAdapter.CUDA library + +@PACKAGE_GUARD@ +@PACKAGE_INIT@ + +find_package(Sofa.Qt QUIET REQUIRED) +find_package(SofaCUDA QUIET REQUIRED) + +check_required_components(Sofa.Qt.CUDA) diff --git a/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp b/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp new file mode 100644 index 0000000..eace46e --- /dev/null +++ b/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp @@ -0,0 +1,79 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include +#include +#include +#include +#include +#include + +namespace sofa::qt +{ +using sofa::helper::Creator; +using namespace sofa::type; +using namespace sofa::defaulttype; + +Creator > > DWClass_Vec12i("default", true); + +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; + +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; + +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; + +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_GPU_CUDA_API TDataWidget >; + + +Creator, TABLE_HORIZONTAL > > DWClass_cudaVectori("default", true); +Creator, TABLE_HORIZONTAL > > DWClass_cudaVectorui("default", true); +Creator, TABLE_HORIZONTAL > > DWClass_cudaVectorf("default", true); +Creator, TABLE_HORIZONTAL > > DWClass_cudaVectord("default", true); + +Creator > > DWClass_cudaVectorVec1i("default", true); +Creator > > DWClass_cudaVectorVec2i("default", true); +Creator > > DWClass_cudaVectorVec3i("default", true); +Creator > > DWClass_cudaVectorVec4i("default", true); + +Creator > > DWClass_cudaVectorVec1f("default", true); +Creator > > DWClass_cudaVectorVec2f("default", true); +Creator > > DWClass_cudaVectorVec3f("default", true); +Creator > > DWClass_cudaVectorVec4f("default", true); + +Creator > > DWClass_cudaVectorVec1d("default", true); +Creator > > DWClass_cudaVectorVec2d("default", true); +Creator > > DWClass_cudaVectorVec3d("default", true); +Creator > > DWClass_cudaVectorVec4d("default", true); + + +} // namespace sofa::qt diff --git a/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.h b/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.h new file mode 100644 index 0000000..d3c2ad0 --- /dev/null +++ b/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.h @@ -0,0 +1,62 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include +#include + +namespace sofa::qt +{ +//////////////////////////////////////////////////////////////// +/// variable-sized vectors support +//////////////////////////////////////////////////////////////// + +template +class vector_data_trait < sofa::gpu::cuda::CudaVector > +{ +public: + typedef sofa::gpu::cuda::CudaVector data_type; + typedef T value_type; + enum { NDIM = 1 }; + static int size(const data_type& d) { + return d.size(); + } + static const char* header(const data_type& /*d*/, int /*i*/ = 0) + { + return nullptr; + } + static const value_type* get(const data_type& d, int i = 0) + { + return ((unsigned)i < (unsigned)size(d)) ? &(d[i]) : nullptr; + } + static void set(const value_type& v, data_type& d, int i = 0) + { + if ((unsigned)i < (unsigned)size(d)) + d[i] = v; + } + static void resize(int s, data_type& d) + { + d.resize(s); + } +}; + + +} // namespace sofa::qt diff --git a/extensions/CUDA/src/sofa/qt/cuda/config.h.in b/extensions/CUDA/src/sofa/qt/cuda/config.h.in new file mode 100644 index 0000000..d4d6bb0 --- /dev/null +++ b/extensions/CUDA/src/sofa/qt/cuda/config.h.in @@ -0,0 +1,40 @@ +/****************************************************************************** +* BeamAdapter plugin * +* (c) 2006 Inria, University of Lille, CNRS * +* * +* 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 . * +******************************************************************************* +* Authors: see Authors.md * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include +#include + +#define SOFA_QT_CUDA_VERSION @PROJECT_VERSION@ + +#ifdef SOFA_BUILD_SOFA_QT_CUDA +# define SOFA_TARGET @PROJECT_NAME@ +# define SOFA_QT_CUDA_API SOFA_EXPORT_DYNAMIC_LIBRARY +#else +# define SOFA_QT_CUDA_API SOFA_IMPORT_DYNAMIC_LIBRARY +#endif + +namespace sofa::qt::cuda +{ + constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; + constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} // namespace sofa::qt::cuda diff --git a/extensions/CUDA/src/sofa/qt/cuda/init.cpp b/extensions/CUDA/src/sofa/qt/cuda/init.cpp new file mode 100644 index 0000000..502f69d --- /dev/null +++ b/extensions/CUDA/src/sofa/qt/cuda/init.cpp @@ -0,0 +1,83 @@ +/****************************************************************************** +* BeamAdapter plugin * +* (c) 2006 Inria, University of Lille, CNRS * +* * +* 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 . * +******************************************************************************* +* Authors: see Authors.md * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include + +#include +#include + +namespace sofa::qt::cuda +{ + +extern "C" { + SOFA_QT_CUDA_API void initExternalModule(); + SOFA_QT_CUDA_API const char* getModuleLicense(); + SOFA_QT_CUDA_API const char* getModuleName(); + SOFA_QT_CUDA_API const char* getModuleVersion(); + SOFA_QT_CUDA_API const char* getModuleDescription(); + SOFA_QT_CUDA_API void registerObjects(sofa::core::ObjectFactory* factory); +} + +void init() +{ + static bool first = true; + if (first) + { + // make sure that this plugin is registered into the PluginManager + sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME); + + first = false; + } +} + +//Here are just several convenient functions to help user to know what contains the plugin + +void initExternalModule() +{ + init(); +} + +const char* getModuleLicense() +{ + return "LGPL"; +} + +const char* getModuleName() +{ + return MODULE_NAME; +} + +const char* getModuleVersion() +{ + return MODULE_VERSION; +} + +const char* getModuleDescription() +{ + return "CUDA extension of the Sofa.Qt plugin."; +} + +void registerObjects(sofa::core::ObjectFactory* factory) +{ + SOFA_UNUSED(factory); +} + +} // namespace sofa::qt::cuda diff --git a/extensions/CUDA/src/sofa/qt/cuda/init.h b/extensions/CUDA/src/sofa/qt/cuda/init.h new file mode 100644 index 0000000..817b961 --- /dev/null +++ b/extensions/CUDA/src/sofa/qt/cuda/init.h @@ -0,0 +1,30 @@ +/****************************************************************************** +* BeamAdapter plugin * +* (c) 2006 Inria, University of Lille, CNRS * +* * +* 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 . * +******************************************************************************* +* Authors: see Authors.md * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +namespace sofa::qt::cuda +{ + +void SOFA_QT_CUDA_API init(); + +} // namespace sofa::qt::cuda From a1a8be437274ac2dc1337c5709a019d6c1611ca1 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Thu, 26 Feb 2026 10:57:56 +0900 Subject: [PATCH 2/2] use the correct macro for imp/exp symbols --- extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in | 2 +- .../CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in b/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in index 330b9d4..6b0c77b 100644 --- a/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in +++ b/extensions/CUDA/Sofa.Qt.CUDAConfig.cmake.in @@ -1,4 +1,4 @@ -# CMake package configuration file for the BeamAdapter.CUDA library +# CMake package configuration file for the Sofa.QT.CUDA library @PACKAGE_GUARD@ @PACKAGE_INIT@ diff --git a/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp b/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp index eace46e..2c29868 100644 --- a/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp +++ b/extensions/CUDA/src/sofa/qt/cuda/CudaDataWidget.cpp @@ -19,6 +19,8 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ +#include + #include #include #include @@ -34,25 +36,25 @@ using namespace sofa::defaulttype; Creator > > DWClass_Vec12i("default", true); -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; -template class SOFA_GPU_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; +template class SOFA_QT_CUDA_API TDataWidget >; Creator, TABLE_HORIZONTAL > > DWClass_cudaVectori("default", true);