diff --git a/CMakeLists.txt b/CMakeLists.txt index e77dd35e6cf170faedefd00c3d56db33c95b6ff9..4c484771a82eb82977e541445e9bd8b832528ddb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,10 +81,19 @@ else() endif() if (Boost_FOUND) - set(DEFINE_HAVE_BOOST "#define HAVE_BOOST") - set(DEFINE_HAVE_BOOST_IOSTREAMS "#define HAVE_BOOST_IOSTREAMS") - set(DEFINE_HAVE_BOOST_PROGRAM_OPTIONS "#define HAVE_BOOST_PROGRAM_OPTIONS") - set(DEFINE_HAVE_BOOST_UNIT_TEST_FRAMEWORK "#define HAVE_BOOST_UNIT_TEST_FRAMEWORK") + set(DEFINE_HAVE_BOOST "#define HAVE_BOOST") + set(DEFINE_HAVE_BOOST_IOSTREAMS "#define HAVE_BOOST_IOSTREAMS") + set(DEFINE_HAVE_BOOST_PROGRAM_OPTIONS "#define HAVE_BOOST_PROGRAM_OPTIONS") + set(DEFINE_HAVE_BOOST_UNIT_TEST_FRAMEWORK "#define HAVE_BOOST_UNIT_TEST_FRAMEWORK") + if (Boost_CONTEXT_FOUND) + set(DEFINE_HAVE_BOOST_CONTEXT "#define HAVE_BOOST_CONTEXT") + else() + #if context is not there CUDA_ON_CPU cannot be activated + set(CUDA_ON_CPU OFF) + endif() + if (Boost_FIBER_FOUND) + set(DEFINE_HAVE_BOOST_FIBER "#define HAVE_BOOST_FIBER") + endif() else() message( FATAL_ERROR "BOOST is required in order to install OpenFPM" ) endif() @@ -95,4 +104,5 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config/config_cmake.h.in ${CMAKE_ include_directories(SYSTEM ${MPI_INCLUDE_PATH}) add_subdirectory (src) +add_subdirectory (../openfpm_devices/ build) diff --git a/configure b/configure index 58a970ce6f68fb305ca1699444b61d7e9cd02c7d..b34c8afb1697fe5f827dd7ce3f712409fe65d6ea 100755 --- a/configure +++ b/configure @@ -1,10 +1,11 @@ -#!/bin/sh +#!/bin/bash # configure script # # # Because we moved to cmake this script emulate the configure script from autotools conf_options= +ld_lib_pathopt= # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' @@ -99,6 +100,7 @@ enable_debug with_metis with_hdf5 with_libhilbert +enable_cuda_on_cpu enable_scan_coverty enable_test_performance enable_test_coverage @@ -106,6 +108,7 @@ with_parmetis enable_se_class1 enable_se_class2 enable_se_class3 +with_alpaka with_action_on_error with_boost with_boost_libdir @@ -117,7 +120,9 @@ with_lapack with_suitesparse with_petsc with_eigen +with_vcdevel enable_gpu +enable_asan ' rm -rf build @@ -125,6 +130,8 @@ if [ ! -d "build" ]; then mkdir build fi +echo "/usr/local" > install_dir + ##### Go over all options for ac_option do @@ -229,6 +236,15 @@ do test_coverage) conf_options="$conf_options -DTEST_COVERAGE=ON" ;; + scan_coverty) + conf_options="$conf_options -DSCAN_COVERTY=ON" + ;; + cuda_on_cpu) + conf_options="$conf_options -DCUDA_ON_CPU=ON" + ;; + test_performance) + conf_options="$conf_options -DTEST_PERFORMANCE=ON" + ;; gpu) if [ x"$CXX" == x"" ]; then conf_options="$conf_options" @@ -237,6 +253,9 @@ do fi conf_options="$conf_options -DENABLE_GPU=ON" ;; + asan) + conf_options="$conf_options -DENABLE_ASAN=ON" + ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ' ;; @@ -462,16 +481,26 @@ do ;; suitesparse) conf_options="$conf_options -DSUITESPARSE_ROOT=$ac_optarg" + ld_lib_pathopt=$ac_optarg/lib ;; eigen) conf_options="$conf_options -DEIGEN3_ROOT=$ac_optarg" ;; boost) - conf_options="$conf_options -DBOOST_ROOT=$ac_optarg" + conf_options="$conf_options -DBOOST_ROOT=$ac_optarg -DBoost_NO_BOOST_CMAKE=ON" + ;; + action_on_error) + conf_options="$conf_options -DACTION_ON_ERROR=$ac_optarg" ;; mpivendor) conf_options="$conf_options -DMPI_VENDOR=$ac_optarg" ;; + vcdevel) + conf_options="$conf_options -DVc_ROOT=$ac_optarg" + ;; + alpaka) + conf_options="$conf_options -DALPAKA_ROOT=$ac_optarg" + ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac @@ -545,7 +574,7 @@ cd build ## remove enerything echo "Calling cmake ../. $conf_options" rm ../error_code -cmake ../. $conf_options +DYLD_LIBRARY_PATH=$ld_lib_pathopt cmake ../. $conf_options if [ $? != 0 ]; then #ok something went wrong the install script analyze the return code to potentially fix the problem automatically # Read the error code and exit with that diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 05e692508a90bff71485fb49f2c716f37cfc55ed..223f151122a0c58bc3c701e493a6206704972d1b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,17 +2,20 @@ cmake_minimum_required(VERSION 3.8 FATAL_ERROR) ########################### Executables -if (CUDA_ON_CPU) - add_definitions(-DCUDA_ON_CPU) +if (CUDA_FOUND OR CUDA_ON_CPU) + set(CUDA_SOURCES VCluster/cuda/VCluster_semantic_unit_cuda_tests.cu VCluster/cuda/VCluster_unit_tests.cu ) endif() -if (CUDA_FOUND) - set(CUDA_SOURCES ../../openfpm_devices/src/memory/CudaMemory.cu VCluster/cuda/VCluster_semantic_unit_cuda_tests.cu VCluster/cuda/VCluster_unit_tests.cu ) +if (CUDA_ON_CPU) + add_definitions(-DCUDA_ON_CPU -D__NVCC__ -DCUDA_GPU -DCUDART_VERSION=11000) + set_source_files_properties(${CUDA_SOURCES} PROPERTIES LANGUAGE CXX) + # set_source_files_properties(${CUDA_SOURCES} PROPERTIES COMPILE_FLAGS "-D__NVCC__ -DCUDA_GPU -DCUDART_VERSION=11000") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_definitions("-x c++") + endif() endif() - - -add_executable(vcluster_test main.cpp VCluster/VCluster.cpp ../../openfpm_devices/src/util/cudify_vars.cpp ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp VCluster/VCluster_unit_tests.cpp VCluster/VCluster_semantic_unit_tests.cpp ${CUDA_SOURCES}) +add_executable(vcluster_test main.cpp VCluster/VCluster.cpp VCluster/VCluster_unit_tests.cpp VCluster/VCluster_semantic_unit_tests.cpp ${CUDA_SOURCES}) if ( CMAKE_COMPILER_IS_GNUCC ) target_compile_options(vcluster_test PRIVATE "-Wno-deprecated-declarations") @@ -24,6 +27,8 @@ endif() add_library(vcluster STATIC VCluster/VCluster.cpp) add_library(vcluster_dl SHARED VCluster/VCluster.cpp) +add_dependencies(vcluster_test ofpmmemory) + ########################### if(CUDA_FOUND) @@ -64,6 +69,7 @@ target_include_directories (vcluster_dl PUBLIC ${ALPAKA_ROOT}/include) target_link_libraries(vcluster_test ${Boost_LIBRARIES}) target_link_libraries(vcluster_test ${PETSC_LIBRARIES}) +target_link_libraries(vcluster_test ofpmmemory) if (TEST_COVERAGE) target_link_libraries(vcluster_test -lgcov) diff --git a/src/VCluster/VCluster.cpp b/src/VCluster/VCluster.cpp index 2358ab6b3c85bb6a66180f2f233c836c57e79da9..aad5ed5e618c66afb4a69269afba7c21da086b44 100644 --- a/src/VCluster/VCluster.cpp +++ b/src/VCluster/VCluster.cpp @@ -49,3 +49,105 @@ void bt_sighandler(int sig, siginfo_t * info, void * ctx_p) exit(0); } + + + +/*! \brief Initialize the library + * + * This function MUST be called before any other function + * + */ +void openfpm_init(int *argc, char ***argv) +{ +#ifdef HAVE_PETSC + + PetscInitialize(argc,argv,NULL,NULL); + +#endif + + init_global_v_cluster_private(argc,argv); + +#ifdef SE_CLASS1 + std::cout << "OpenFPM is compiled with debug mode LEVEL:1. Remember to remove SE_CLASS1 when you go in production" << std::endl; +#endif + +#ifdef SE_CLASS2 + std::cout << "OpenFPM is compiled with debug mode LEVEL:2. Remember to remove SE_CLASS2 when you go in production" << std::endl; +#endif + +#ifdef SE_CLASS3 + std::cout << "OpenFPM is compiled with debug mode LEVEL:3. Remember to remove SE_CLASS3 when you go in production" << std::endl; +#endif + +#ifdef CUDA_ON_CPU + init_wrappers(); +#endif + + // install segmentation fault signal handler + + struct sigaction sa; + + sa.sa_sigaction = bt_sighandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + + sigaction(SIGSEGV, &sa, NULL); + + if (argc != NULL && *argc != 0) + {program_name = std::string(*argv[0]);} + + // Initialize math pre-computation tables + openfpm::math::init_getFactorization(); + + ofp_initialized = true; + +#ifdef CUDA_GPU + + // Initialize temporal memory + mem_tmp.incRef(); + + exp_tmp.incRef(); + + for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++) + { + exp_tmp2[i].incRef(); + } + + +#endif +} + + +/*! \brief Finalize the library + * + * This function MUST be called at the end of the program + * + */ +void openfpm_finalize() +{ +#ifdef HAVE_PETSC + + PetscFinalize(); + +#endif + + delete_global_v_cluster_private(); + ofp_initialized = false; + +#ifdef CUDA_GPU + + // Release memory + mem_tmp.destroy(); + mem_tmp.decRef(); + + exp_tmp.destroy(); + exp_tmp.decRef(); + + for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++) + { + exp_tmp2[i].destroy(); + exp_tmp2[i].decRef(); + } + +#endif +} \ No newline at end of file diff --git a/src/VCluster/VCluster.hpp b/src/VCluster/VCluster.hpp index 9428cce33c323281276b0a67c67eddd0b21d868c..be60f978ad2b62e17f5a2f9f4fe67ba1d67b2b3a 100644 --- a/src/VCluster/VCluster.hpp +++ b/src/VCluster/VCluster.hpp @@ -1426,61 +1426,7 @@ static inline bool is_openfpm_init() * This function MUST be called before any other function * */ -static inline void openfpm_init(int *argc, char ***argv) -{ -#ifdef HAVE_PETSC - - PetscInitialize(argc,argv,NULL,NULL); - -#endif - - init_global_v_cluster_private(argc,argv); - -#ifdef SE_CLASS1 - std::cout << "OpenFPM is compiled with debug mode LEVEL:1. Remember to remove SE_CLASS1 when you go in production" << std::endl; -#endif - -#ifdef SE_CLASS2 - std::cout << "OpenFPM is compiled with debug mode LEVEL:2. Remember to remove SE_CLASS2 when you go in production" << std::endl; -#endif - -#ifdef SE_CLASS3 - std::cout << "OpenFPM is compiled with debug mode LEVEL:3. Remember to remove SE_CLASS3 when you go in production" << std::endl; -#endif - - // install segmentation fault signal handler - - struct sigaction sa; - - sa.sa_sigaction = bt_sighandler; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - - sigaction(SIGSEGV, &sa, NULL); - - if (argc != NULL && *argc != 0) - {program_name = std::string(*argv[0]);} - - // Initialize math pre-computation tables - openfpm::math::init_getFactorization(); - - ofp_initialized = true; - -#ifdef CUDA_GPU - - // Initialize temporal memory - mem_tmp.incRef(); - - exp_tmp.incRef(); - - for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++) - { - exp_tmp2[i].incRef(); - } - - -#endif -} +void openfpm_init(int *argc, char ***argv); /*! \brief Finalize the library @@ -1488,34 +1434,7 @@ static inline void openfpm_init(int *argc, char ***argv) * This function MUST be called at the end of the program * */ -static inline void openfpm_finalize() -{ -#ifdef HAVE_PETSC - - PetscFinalize(); - -#endif - - delete_global_v_cluster_private(); - ofp_initialized = false; - -#ifdef CUDA_GPU - - // Release memory - mem_tmp.destroy(); - mem_tmp.decRef(); - - exp_tmp.destroy(); - exp_tmp.decRef(); - - for (int i = 0 ; i < MAX_NUMER_OF_PROPERTIES ; i++) - { - exp_tmp2[i].destroy(); - exp_tmp2[i].decRef(); - } - -#endif -} +void openfpm_finalize(); #endif diff --git a/src/VCluster/VCluster_base.hpp b/src/VCluster/VCluster_base.hpp index bd7ce57d5ef3672130d9b41b31d0f93d368dd321..de71b9faeceee11a899085152979c312e8c7aadf 100644 --- a/src/VCluster/VCluster_base.hpp +++ b/src/VCluster/VCluster_base.hpp @@ -25,9 +25,6 @@ #include "memory/BHeapMemory.hpp" #include "Packer_Unpacker/has_max_prop.hpp" #include "data_type/aggregate.hpp" -#if defined(CUDA_GPU) && defined(__NVCC__) -#include "util/cuda/moderngpu/launch_box.hxx" -#endif #include "util/cuda/ofp_context.hxx" #ifdef HAVE_PETSC diff --git a/src/config/config_cmake.h.in b/src/config/config_cmake.h.in index a0d62c9edc325fad8f80ce5ca11c06c068f57baf..01c196978f3feb7cb93fd2bc3d0aec46446a3162 100644 --- a/src/config/config_cmake.h.in +++ b/src/config/config_cmake.h.in @@ -32,6 +32,12 @@ ${DEFINE_HAVE_BOOST_PROGRAM_OPTIONS} /**/ /* define if the Boost::Unit_Test_Framework library is available */ ${DEFINE_HAVE_BOOST_UNIT_TEST_FRAMEWORK} /**/ +/* define if the Boost::Context library is available */ +${DEFINE_HAVE_BOOST_CONTEXT} /**/ + +/* define if the Boost::Fiber library is available */ +${DEFINE_HAVE_BOOST_FIBER} /**/ + /* Have clock time */ ${DEFINE_HAVE_CLOCK_GETTIME} /**/ @@ -104,12 +110,31 @@ ${DEFINE_HAVE_SYS_TYPES_H} /* Define to 1 if you have the <unistd.h> header file. */ ${DEFINE_HAVE_UNISTD_H} +/* Test TinyObjLoader */ +${DEFINE_HAVE_TINYOBJLOADER} + +/* ACTION to take in case of error */ +${DEFINE_ACTION_ON_ERROR} + /* Define to the sub-directory where libtool stores uninstalled libraries. */ #define LT_OBJDIR ".libs/" /* NVCC compiling */ ${DEFINE_NVCC} /**/ +/* Define if we have Alpaka */ +${DEFINE_HAVE_ALPAKA} + +/* Additional alpaka definitions */ +${ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE_DEF} +${ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE_DEF} +${ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE_DEF} +${ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE_DEF} +${ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE_DEF} +${ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE_DEF} +${ALPAKA_ACC_CPU_BT_OMP4_ENABLE_DEF} + + /* Name of package */ #define PACKAGE "openfpm_pdata" @@ -157,3 +182,5 @@ ${DEFINE_TEST_COVERAGE_MODE} /* Version number of package */ #define VERSION "1.0.0" + +#define OPENFPM_PDATA