From 55f98119a87ecef704d1f986e2a34066ec090bb3 Mon Sep 17 00:00:00 2001 From: Gilles Grospellier Date: Sun, 4 Feb 2024 10:05:37 +0100 Subject: [PATCH] [poisson] Fix configuration - Detect 'cuSparse' from 'CUDAToolkit' - Remove setting of 'CUDA_ARCHITECTURES' - Fix compilation with cusparse. --- poisson/CMakeLists.txt | 17 ++++++++--------- poisson/CusparseBiliAssembly.hxx | 9 +++------ poisson/FemModule.cc | 3 +-- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/poisson/CMakeLists.txt b/poisson/CMakeLists.txt index 1c01563..44d4bd6 100644 --- a/poisson/CMakeLists.txt +++ b/poisson/CMakeLists.txt @@ -1,11 +1,11 @@ set (USE_CUSPARSE_ADD OFF) if (ARCANE_HAS_CUDA) - find_library(CUSPARSE_LIB cusparse HINTS ${CUDA_TOOLKIT_ROOT_DIR}/lib64) - if(CUSPARSE_LIB) - message(STATUS "CUSPARSE found: ${CUSPARSE_LIB}. Arcane installation has CUDA. Enabling features that depends of Cusparse.") - message(STATUS "Arcane has been compiled with cuda. Enabling features that need CUDA.") + if (TARGET CUDA::cusparse) + message(STATUS "cuSPARSE is available. Enabling cusparse assembly") set(USE_CUSPARSE_ADD ON) + else() + message(STATUS "cuSPARSE is not available") endif() endif() @@ -32,12 +32,8 @@ target_sources(Poisson PRIVATE arcane_accelerator_add_to_target(Poisson) if(USE_CUSPARSE_ADD) - target_link_libraries(Poisson PRIVATE ${CUSPARSE_LIB}) endif() -set_target_properties(Poisson PROPERTIES CUDA_ARCHITECTURES "72") - - arcane_generate_axl(Fem) arcane_add_arcane_libraries_to_target(Poisson) target_include_directories(Poisson PUBLIC . ${CMAKE_CURRENT_BINARY_DIR}) @@ -56,7 +52,10 @@ configure_file(${MSH_DIR}/L-shape-3D.msh ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) target_link_libraries(Poisson PUBLIC FemUtils) -target_compile_definitions(Poisson PRIVATE $<$:USE_CUSPARSE_ADD>) +if (USE_CUSPARSE_ADD) + target_compile_definitions(Poisson PRIVATE USE_CUSPARSE_ADD) + target_link_libraries(Poisson PRIVATE CUDA::cusparse) +endif() target_compile_definitions(Poisson PRIVATE $<$:ARCANE_HAS_ACCELERATOR>) find_program(GMSH NAMES gmsh) diff --git a/poisson/CusparseBiliAssembly.hxx b/poisson/CusparseBiliAssembly.hxx index d62820f..a93b8c1 100644 --- a/poisson/CusparseBiliAssembly.hxx +++ b/poisson/CusparseBiliAssembly.hxx @@ -1,4 +1,4 @@ -// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*- +// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*- //----------------------------------------------------------------------------- // Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com) // See the top-level COPYRIGHT file for details. @@ -227,7 +227,6 @@ _computeCusparseElementMatrix(cusparseCsr& result, cusparseCsr& global, Cell cel CHECK_CUDA(cudaFree(local.csrCol)); CHECK_CUDA(cudaFree(local.csrRow)); CHECK_CUSPARSE(cusparseDestroyMatDescr(local.desc)); - } /*---------------------------------------------------------------------------*/ @@ -293,15 +292,13 @@ _assembleCusparseBilinearOperatorTRIA3() CHECK_CUDA(cudaFree(res1.csrCol)); CHECK_CUDA(cudaFree(res1.csrVal)); - _computeCusparseElementMatrix(res1, res2, cell, handle, node_dof, - t); + _computeCusparseElementMatrix(res1, res2, cell, handle, node_dof); } //computation of the local matrix and adding it in the global one else { CHECK_CUDA(cudaFree(res2.csrCol)); CHECK_CUDA(cudaFree(res2.csrVal)); - _computeCusparseElementMatrix(res2, res1, cell, handle, node_dof, - t); + _computeCusparseElementMatrix(res2, res1, cell, handle, node_dof); } i++; } diff --git a/poisson/FemModule.cc b/poisson/FemModule.cc index 9259428..5d95a32 100644 --- a/poisson/FemModule.cc +++ b/poisson/FemModule.cc @@ -409,7 +409,6 @@ _doStationarySolve() #ifdef USE_CUSPARSE_ADD if (m_use_cusparse_add) { - cusparseHandle_t handle; _assembleCusparseBilinearOperatorTRIA3(); if (m_cache_warming != 1) { m_time_stats->resetStats("AssembleCusparseBilinearOperator"); @@ -418,8 +417,8 @@ _doStationarySolve() } } } - #endif + if (m_use_coo) { m_linear_system.clearValues(); _assembleCooBilinearOperatorTRIA3();