Skip to content

Commit

Permalink
Merge pull request #294 from krasznaa/FlagDeterminationUpdate-main-20…
Browse files Browse the repository at this point in the history
…240903

Flag Determination Redesign, main branch (2024.09.09.)
  • Loading branch information
krasznaa authored Sep 20, 2024
2 parents 7fbfa83 + 63f7ab0 commit fe0112d
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 216 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ project( vecmem VERSION 1.8.0 LANGUAGES CXX )
include( GNUInstallDirs )
include( CTest )

# Set the location of the installed CMake files.
set( CMAKE_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/vecmem-${PROJECT_VERSION}" )

# Explicitly set the output directory for the binaries. Such that if this
# project is included by another project, the main project's configuration would
# win out.
Expand Down
36 changes: 36 additions & 0 deletions cmake/vecmem-check-sycl-source-compiles.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# VecMem project, part of the ACTS project (R&D line)
#
# (c) 2024 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# CMake version requirement.
cmake_minimum_required( VERSION 3.14 )

# VecMem include(s).
include( vecmem-check-sycl-code-compiles )

# Check whether a given piece of SYCL code compiles.
#
# Usage: vecmem_check_sycl_source_compiles(<code> <resultVar>
# [COMPILE_DEFINITIONS <definitions>]
# [CMAKE_FLAGS <flags>])
#
function( vecmem_check_sycl_source_compiles code resultVar )

# Return early, if the result variable already has a value.
if( DEFINED ${resultVar} )
return()
endif()

# Generate a source file with the given code.
file( WRITE
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${resultVar}.sycl"
"${code}" )

# Use the "file based" version of the function.
vecmem_check_sycl_code_compiles( ${resultVar}
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${resultVar}.sycl"
${ARGN} )

endfunction( vecmem_check_sycl_source_compiles )
19 changes: 12 additions & 7 deletions cmake/vecmem-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VecMem project, part of the ACTS project (R&D line)
#
# (c) 2021 CERN for the benefit of the ACTS project
# (c) 2021-2024 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

Expand All @@ -12,10 +12,15 @@ set( vecmem_VERSION "@PROJECT_VERSION@" )
set_and_check( vecmem_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@" )
set_and_check( vecmem_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@" )
set_and_check( vecmem_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_CMAKEDIR@" )
set_and_check( vecmem_LANGUAGE_FILE
"${vecmem_CMAKE_DIR}/vecmem-check-language.cmake" )

# Include the file listing all the imported targets and options.
include( "${vecmem_CMAKE_DIR}/vecmem-config-targets.cmake" )

# Add the current directory to CMAKE_MODULE_PATH.
list( APPEND CMAKE_MODULE_PATH "${vecmem_CMAKE_DIR}" )

# Set up additional variables, based on the imported targets. These are mostly
# just here for handling COMPONENT arguments for find_package(...).
set( vecmem_CORE_LIBRARY vecmem::core )
Expand Down Expand Up @@ -53,10 +58,10 @@ find_package_handle_standard_args( vecmem REQUIRED_VARS
# Clean up.
unset( vecmem_REQUIRED_LIBS )

# Set up the "language helper code" coming with the installation, if the
# user asks for it.
set_and_check( vecmem_LANGUAGE_FILE
"${vecmem_CMAKE_DIR}/vecmem-check-language.cmake" )
if( "${vecmem_FIND_COMPONENTS}" MATCHES "LANGUAGE" )
include( "${vecmem_LANGUAGE_FILE}" )
# (Post-)Configure the targets.
include( vecmem-setup-core )
vecmem_setup_core( vecmem::core )
if( TARGET vecmem::sycl )
include( vecmem-setup-sycl )
vecmem_setup_sycl( vecmem::sycl )
endif()
9 changes: 5 additions & 4 deletions cmake/vecmem-packaging.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VecMem project, part of the ACTS project (R&D line)
#
# (c) 2021 CERN for the benefit of the ACTS project
# (c) 2021-2024 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

Expand All @@ -9,8 +9,6 @@ include( CPack )

# Export the configuration of the project.
include( CMakePackageConfigHelpers )
set( CMAKE_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/vecmem-${PROJECT_VERSION}" )
install( EXPORT vecmem-exports
NAMESPACE "vecmem::"
FILE "vecmem-config-targets.cmake"
Expand All @@ -31,7 +29,10 @@ install( FILES
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" )

# Install the "language helper" files.
install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/vecmem-check-language.cmake"
install( FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/vecmem-check-language.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/vecmem-check-sycl-code-compiles.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/vecmem-check-sycl-source-compiles.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" )
install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/hip"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/sycl"
Expand Down
59 changes: 9 additions & 50 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Project include(s).
include( vecmem-compiler-options-cpp )
include( vecmem-check-sycl-code-compiles )
include( vecmem-check-sycl-source-compiles )

# Set up the build of the VecMem core library.
vecmem_add_library( vecmem_core core
Expand Down Expand Up @@ -200,6 +200,13 @@ target_compile_options( vecmem_core PUBLIC
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CXX>>:/Zc:__cplusplus>
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler /Zc:__cplusplus> )

# Set up the public definitions for vecmem::core, which require configuration
# tests to be made with the C++/SYCL/etc. compilers.
include( "cmake/vecmem-setup-core.cmake" )
vecmem_setup_core( vecmem_core )
install( FILES "cmake/vecmem-setup-core.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" )

# Figure out where to get <memory_resource> from.
include( CheckCXXSourceCompiles )
check_cxx_source_compiles( "
Expand Down Expand Up @@ -239,6 +246,7 @@ else()
endif()
endif()

# Figure out whether or not to include the default resource polyfill.
check_cxx_source_compiles( "
#include <${pmr_include}>
int main() {
Expand All @@ -247,46 +255,13 @@ check_cxx_source_compiles( "
return 0;
}
" VECMEM_HAVE_DEFAULT_RESOURCE)

if(NOT VECMEM_HAVE_DEFAULT_RESOURCE)
target_sources( vecmem_core
PRIVATE "src/memory/default_resource_polyfill.cpp" )
source_group( "src\\\\memory"
FILES "src/memory/default_resource_polyfill.cpp" )
endif()

# Figure out how to use various SYCL features.
if( VECMEM_BUILD_SYCL_LIBRARY )

# Test which printf function(s) is/are available.
vecmem_check_sycl_code_compiles( VECMEM_HAVE_SYCL_EXT_ONEAPI_PRINTF
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/ext_oneapi_printf_test.sycl" )
vecmem_check_sycl_code_compiles( VECMEM_HAVE_SYCL_ONEAPI_PRINTF
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/oneapi_printf_test.sycl" )

# Set up the appropriate flag with its help.
if( VECMEM_HAVE_SYCL_EXT_ONEAPI_PRINTF )
target_compile_definitions( vecmem_core PUBLIC
VECMEM_SYCL_PRINTF_FUNCTION=cl::sycl::ext::oneapi::experimental::printf )
elseif( VECMEM_HAVE_SYCL_ONEAPI_PRINTF )
target_compile_definitions( vecmem_core PUBLIC
VECMEM_SYCL_PRINTF_FUNCTION=cl::sycl::ONEAPI::experimental::printf )
else()
message( WARNING "No valid printf function found for SYCL."
" Enabling debug messages will likely not work in device code." )
target_compile_definitions( vecmem_core PUBLIC
VECMEM_SYCL_PRINTF_FUNCTION=printf VECMEM_MSG_ATTRIBUTES= )
endif()

# Test whether sycl::atomic_ref is available.
vecmem_check_sycl_code_compiles( VECMEM_HAVE_SYCL_ATOMIC_REF
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/atomic_ref_test.sycl" )
if( VECMEM_HAVE_SYCL_ATOMIC_REF )
target_compile_definitions( vecmem_core PUBLIC
VECMEM_HAVE_SYCL_ATOMIC_REF )
endif()
endif()

# Test whether we have CLZ builtins.
check_cxx_source_compiles( "
#include <intrin.h>
Expand Down Expand Up @@ -327,22 +302,6 @@ if( VECMEM_HAVE_STD_ALIGNED_ALLOC )
PRIVATE VECMEM_HAVE_STD_ALIGNED_ALLOC )
endif()

# Check if vecmem::posix_device_atomic_ref is usable.
set( CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include" )
check_cxx_source_compiles( "
#include <vecmem/memory/details/posix_device_atomic_ref.hpp>
int main() {
int foo = 0;
vecmem::posix_device_atomic_ref<int> ref{foo};
return 0;
}
" VECMEM_SUPPORT_POSIX_ATOMIC_REF )
if( VECMEM_SUPPORT_POSIX_ATOMIC_REF )
target_compile_definitions( vecmem_core
PUBLIC VECMEM_SUPPORT_POSIX_ATOMIC_REF )
endif()
unset( CMAKE_REQUIRED_INCLUDES )

# Test the public headers of vecmem::core.
if( BUILD_TESTING AND VECMEM_BUILD_TESTING )
file( GLOB vecmem_core_public_headers
Expand Down
21 changes: 0 additions & 21 deletions core/cmake/atomic_ref_test.sycl

This file was deleted.

25 changes: 0 additions & 25 deletions core/cmake/ext_oneapi_printf_test.sycl

This file was deleted.

24 changes: 0 additions & 24 deletions core/cmake/oneapi_printf_test.sycl

This file was deleted.

Loading

0 comments on commit fe0112d

Please sign in to comment.