Back to home page

sPhenix code displayed by LXR

 
 

    


Warning, /acts/cmake/FindSYCL.cmake is written in an unsupported language. File is not indexed.

0001 # This file is part of the Acts project.
0002 #
0003 # Copyright (C) 2020 CERN for the benefit of the Acts project
0004 #
0005 # This Source Code Form is subject to the terms of the Mozilla Public
0006 # License, v. 2.0. If a copy of the MPL was not distributed with this
0007 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 #
0009 # This module is used to find out whether the C++ compiler set up to build the
0010 # project is able to compile SYCL code. If so, it provides helper variables
0011 # to the project configuration to set up the build of SYCL
0012 # libraries/executables.
0013 #
0014 # Variable(s) set up by the module:
0015 #  - SYCL_FOUND: Boolean, set to TRUE when SYCL compilation is available.
0016 #  - acts_target_setup_sycl( <target> [DEPENDENCY PUBLIC|PRIVATE|INTERFACE] ):
0017 #       Helper function for setting up a target (library or executable) for
0018 #       "SYCL compilation". Provides an optional argument for specifying
0019 #       how/whether the target exposes this SYCL dependency.
0020 #
0021 # Technical/internal variable(s) set up by the module:
0022 #  - SYCL_builtin_FOUND: Boolean, set to TRUE when the C++ compiler can itself
0023 #                        understand/build SYCL code.
0024 #  - SYCL_builtin_TARGETS: List of strings with the target platforms that the
0025 #                          compiler can generate code for.
0026 #  - SYCL_INCLUDE_DIR: Directory holding the (try)SYCL header(s).
0027 #
0028 # Variable(s) used to control the module's behaviour:
0029 #  - SYCL_FLAGS: A list of compiler options that triggers a "SYCL build" from
0030 #                the configured C++ compiler. Can be used to pass extra flags
0031 #                to the SYCL compilation, if needed.
0032 #  - SYCL_SEARCH_SUPPORT_LIBRARIES: A list of library (object file) names (more
0033 #       like "name fragments") to include in linking SYCL binaries. By default
0034 #       the code only looks for libsycl-glibc.o (or libsycl-msvc.o on Windows),
0035 #       and libsycl-cmath.o. But one may need to use other object files (for
0036 #       complex or 64-bit mathematics) coming with the Intel compiler as well.
0037 #
0038 # A typical use of the module would look like:
0039 #
0040 #  find_package( SYCL )
0041 #  if( SYCL_FOUND )
0042 #     atlas_add_library( SYCLAidedLibrary ... )
0043 #     acts_target_setup_sycl( SYCLAidedLibrary DEPENDENCY PRIVATE )
0044 #  endif()
0045 #
0046 
0047 # This module needs at least CMake 3.13.
0048 cmake_minimum_required( VERSION 3.13 )
0049 
0050 # We use CMake's built-in modules, used to look for SYCL capabilities.
0051 include( CheckIncludeFileCXX )
0052 include( CheckCXXSourceCompiles )
0053 include( CMakeParseArguments )
0054 include( FindPackageHandleStandardArgs )
0055 set( CMAKE_REQUIRED_QUIET TRUE )
0056 
0057 # Greet the user.
0058 if( NOT SYCL_FIND_QUIETLY )
0059    message( STATUS "Checking if ${CMAKE_CXX_COMPILER} is SYCL capable..." )
0060 endif()
0061 
0062 # Set up the flag(s) needed for SYCL code compilation.
0063 set( SYCL_FLAGS "-fsycl" CACHE STRING
0064    "Compiler flags to use for SYCL compilation" )
0065 mark_as_advanced( SYCL_FLAGS )
0066 
0067 # First check if the compiler is able to compile code using <CL/sycl.hpp> on
0068 # its own, without any additional headers.
0069 check_include_file_cxx( "CL/sycl.hpp" SYCL_builtin_FOUND "${SYCL_FLAGS}" )
0070 
0071 # If that worked, we must be using a Clang version that understands sycl
0072 # natively.
0073 if( SYCL_builtin_FOUND )
0074    # Mark that SYCL is found.
0075    if( NOT SYCL_FIND_QUIETLY )
0076       message( STATUS
0077          "Checking if ${CMAKE_CXX_COMPILER} is SYCL capable... success" )
0078       message( STATUS "Checking for available SYCL target(s)..." )
0079    endif()
0080    set( SYCL_FOUND TRUE )
0081    # Figure out which SYCL target platforms are available.
0082    set( SYCL_POSSIBLE_TARGETS "spir64-unknown-unknown-sycldevice"
0083       CACHE STRING "List of targets to check the availability of" )
0084    mark_as_advanced( SYCL_POSSIBLE_TARGETS )
0085    set( SYCL_builtin_TARGETS )
0086    foreach( _target ${SYCL_POSSIBLE_TARGETS} )
0087       set( CMAKE_REQUIRED_FLAGS "-fsycl -fsycl-targets=${_target}" )
0088       check_cxx_source_compiles( "
0089          #include <CL/sycl.hpp>
0090          int main() {
0091             cl::sycl::platform::get_platforms();
0092             return 0;
0093          }
0094          " _syclTarget${_target}Found )
0095       if( _syclTarget${_target}Found )
0096          if( NOT SYCL_FIND_QUIETLY )
0097             message( STATUS "  - Found target: ${_target}" )
0098          endif()
0099          list( APPEND SYCL_builtin_TARGETS ${_target} )
0100       endif()
0101       unset( _syclTarget${_target}Found )
0102    endforeach()
0103    if( NOT SYCL_FIND_QUIETLY )
0104       message( STATUS "Checking for available SYCL target(s)... done" )
0105    endif()
0106    if( NOT "${SYCL_builtin_TARGETS}" STREQUAL "" )
0107       string( REPLACE ";" "," _targets "${SYCL_builtin_TARGETS}" )
0108       list( APPEND SYCL_FLAGS "-fsycl-targets=${_targets}" )
0109       unset( _targets )
0110    endif()
0111    # Look for object files holding SYCL device code, which would be needed for
0112    # the final binaries.
0113    set( SYCL_SEARCH_SUPPORT_LIBRARIES "" CACHE STRING
0114       "List of support libraries / object files to look for and link" )
0115    mark_as_advanced( SYCL_SEARCH_SUPPORT_LIBRARIES )
0116    get_filename_component( _compilerDir "${CMAKE_CXX_COMPILER}" DIRECTORY )
0117    set( SYCL_SUPPORT_LIBRARIES )
0118    foreach( _supportLib ${SYCL_SEARCH_SUPPORT_LIBRARIES} )
0119       find_file( SYCL_${_supportLib}_OBJECT_FILE
0120          NAMES "libsycl-${_supportLib}${CMAKE_CXX_OUTPUT_EXTENSION}"
0121          PATHS "${_compilerDir}"
0122          PATH_SUFFIXES "../lib" "../lib64" )
0123       if( SYCL_${_supportLib}_OBJECT_FILE )
0124          list( APPEND SYCL_SUPPORT_LIBRARIES
0125             "${SYCL_${_supportLib}_OBJECT_FILE}" )
0126       endif()
0127    endforeach()
0128    unset( _compilerDir )
0129    # Set up the acts_target_setup_sycl function.
0130    if( NOT COMMAND acts_target_setup_sycl )
0131       function( acts_target_setup_sycl targetName )
0132          cmake_parse_arguments( ARG "" "DEPENDENCY" "" ${ARGN} )
0133          if( NOT ARG_DEPENDENCY )
0134             set( ARG_DEPENDENCY "PRIVATE" )
0135          endif()
0136          target_compile_options( ${targetName} ${ARG_DEPENDENCY} ${SYCL_FLAGS} )
0137          target_link_options( ${targetName} ${ARG_DEPENDENCY} ${SYCL_FLAGS} )
0138          target_sources( ${targetName} ${ARG_DEPENDENCY}
0139             ${SYCL_SUPPORT_LIBRARIES} )
0140       endfunction( acts_target_setup_sycl )
0141    endif()
0142 else()
0143    if( NOT SYCL_FIND_QUIETLY )
0144       message( STATUS
0145          "Checking if ${CMAKE_CXX_COMPILER} is SYCL capable... failure" )
0146       message( STATUS "Looking for the (tri)SYCL header(s)..." )
0147    endif()
0148    # If the compiler is not providing SYCL capabilities itself, check if we
0149    # have the (tri)SYCL headers available somewhere.
0150    find_path( SYCL_INCLUDE_DIR
0151       NAMES "CL/sycl.hpp" "SYCL/sycl.hpp" "triSYCL/sycl.hpp"
0152       PATH_SUFFIXES include ${CMAKE_INSTALL_INCLUDEDIR} include/triSYCL
0153       ${CMAKE_INSTALL_INCLUDEDIR}/triSYCL
0154       DOC "Location of the (tri)SYCL header(s)" )
0155    # Look for Boost as well, as these headers need it.
0156    if( SYCL_FIND_QUIETLY )
0157       find_package( Boost QUIET )
0158    else()
0159       find_package( Boost )
0160    endif()
0161    # Check if we found everything.
0162    if( SYCL_INCLUDE_DIR AND Boost_FOUND )
0163       # Mark that SYCL is found.
0164       if( NOT SYCL_FIND_QUIETLY )
0165          message( STATUS "Found (tri)SYCL headers: ${SYCL_INCLUDE_DIR}" )
0166       endif()
0167       set( SYCL_FOUND TRUE )
0168       # Set up the acts_target_setup_sycl function.
0169       if( NOT COMMAND acts_target_setup_sycl )
0170          function( acts_target_setup_sycl targetName )
0171             cmake_parse_arguments( ARG "" "DEPENDENCY" "" ${ARGN} )
0172             if( NOT ARG_DEPENDENCY )
0173                set( ARG_DEPENDENCY "PRIVATE" )
0174             endif()
0175             target_include_directories( ${targetName} SYSTEM ${ARG_DEPENDENCY}
0176                ${Boost_INCLUDE_DIRS} ${SYCL_INCLUDE_DIR} )
0177             target_link_libraries( ${targetName} ${ARG_DEPENDENCY}
0178                ${Boost_LIBRARIES} )
0179          endfunction( acts_target_setup_sycl )
0180       endif()
0181    else()
0182       # We did not find a viable SYCL version.
0183       if( NOT SYCL_FIND_QUIETLY )
0184          message( STATUS "Looking for the (tri)SYCL header(s)... failure" )
0185       endif()
0186       set( SYCL_FOUND FALSE )
0187    endif()
0188 endif()
0189 
0190 # Handle the standard find_package(...) arguments explicitly.
0191 find_package_handle_standard_args( SYCL
0192    REQUIRED_VARS CMAKE_CXX_COMPILER SYCL_FOUND )