Commit 4080599e authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed main CMakeLists.txt to work on Arch Linux

parent 3535b12a
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ option(OFFLINE_BUILD "Offline build (i.e. without downloading libraries such as
option(WITH_CUDA "Build with CUDA support" ON)
set(WITH_CUDA_ARCH "auto" CACHE STRING "Build for these CUDA architectures")
option(WITH_HIP "Build with HIP support" ON)
set(WITH_HIP_PLATFORM "nvcc" CACHE STRING "HIP backend compiler." )
#set(WITH_HIP_PLATFORM "nvcc" CACHE STRING "HIP backend compiler." )
option(WITH_OPENMP "Build with OpenMP support" ON)
option(WITH_MPI "Build with MPI support" ON)
option(WITH_GMP "Build with GMP support" OFF)
@@ -38,7 +38,7 @@ option(BUILD_DOC "Build examples included in the documentation" OFF)

# set cmake's include path so that we can include modules from
# the cmake directory in the TNL repository
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )

# install paths relative to the cmake's prefix
set( TNL_TARGET_INCLUDE_DIRECTORY "include/TNL" )
@@ -112,7 +112,7 @@ elseif( CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
endif()

# disable GCC's infamous "maybe-uninitialized" warning (it produces mostly false positives)
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT ${WITH_HIP} )
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
   set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized" )
endif()

@@ -123,7 +123,7 @@ endif()

# enable address sanitizer (does not work with MPI due to many false positives, does not work with nvcc at all)
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
   if( NOT ${WITH_MPI} AND NOT ${WITH_CUDA} )
   if( NOT ${WITH_MPI} AND NOT ${WITH_CUDA} AND NOT ${WITH_HIP} )
      set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" )
      set( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS_DEBUG "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS_DEBUG} -fsanitize=address -fsanitize=undefined" )
      set( CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address -fsanitize=undefined" )
@@ -152,6 +152,7 @@ if( DEFINED ENV{CI_JOB_NAME} OR ${CMAKE_GENERATOR} STREQUAL "Ninja" )
   elseif( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
      set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color" )
   endif()
   list(APPEND HIP_HIPCC_FLAGS -fcolor-diagnostics)
endif()

# add the filesystem library to all targets
@@ -187,6 +188,12 @@ endif()
#
if( OPENMP_FOUND AND ${WITH_OPENMP} )
   set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENMP ${OpenMP_CXX_FLAGS}" )

   # OpenMP libraries have to be added explicitly for HIP
   # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_STANDARD_LIBRARIES.html
   # FIXME: ${OpenMP_CXX_LIBRARIES} is a ;-list and does not contain "-l"
   #list( APPEND CMAKE_HIP_STANDARD_LIBRARIES ${OpenMP_CXX_LIBRARIES} )
   list( APPEND CMAKE_HIP_STANDARD_LIBRARIES "-lgomp -lpthread" )
endif()

####
@@ -262,12 +269,24 @@ endif()
# Check for HIP - TODO: Put this after CUDA check when we do not need to build
#                       everything with hipcc ... or we can just build everything with HIP ... who knows? :)
#
if(NOT DEFINED HIP_PATH)
    if(NOT DEFINED ENV{HIP_PATH})
        set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
    else()
        set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
    endif()
endif()
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})

if( ${WITH_HIP} )
   find_package(HIP)
   if(HIP_FOUND)
   if( ${HIP_FOUND} )
      set(BUILD_HIP TRUE)
      # available variables: HIP_HIPCC_FLAGS, HIP_HCC_FLAGS, HIP_CLANG_FLAGS, HIP_NVCC_FLAGS
      list(APPEND HIP_HIPCC_FLAGS -std=c++14 -DHAVE_HIP)

      #set(CMAKE_HIPCXX_FLAGS ${CMAKE_HIPCXX_FLAGS} -I${HIP_ROOT_DIR}/include -DHAVE_HIP -DHIP_PLATFORM=nvcc )
      set(CMAKE_HIPCXX_FLAGS ${CMAKE_HIPCXX_FLAGS} -DHAVE_HIP -DHIP_PLATFORM=nvcc )
      #set(CMAKE_HIPCXX_FLAGS ${CMAKE_HIPCXX_FLAGS} -DHAVE_HIP )
      #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${HIP_ROOT_DIR}/include -DHAVE_HIP -I/usr/lib/llvm-8/include/openmp -L/usr/lib/llvm-8/lib -lomp -fopenmp")
      #set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_INIT} -L/usr/lib/llvm-8/lib} )
      #set(CMAKE_CXX_COMPILER "${HIP_ROOT_DIR}/bin/hipcc" )
@@ -400,7 +419,7 @@ message( " OFFLINE_BUILD = ${OFFLINE_BUILD}" )
message( "   WITH_CUDA = ${WITH_CUDA}" )
message( "   WITH_CUDA_ARCH = ${WITH_CUDA_ARCH}" )
message( "   WITH_HIP = ${WITH_HIP}" )
message( "   WITH_HIP_PLATFORM = ${WITH_HIP_PLATFORM}" )
#message( "   WITH_HIP_PLATFORM = ${WITH_HIP_PLATFORM}" )
message( "   WITH_OPENMP = ${WITH_OPENMP}" )
message( "   WITH_MPI = ${WITH_MPI}" )
message( "   WITH_GMP = ${WITH_GMP}" )

cmake/FindHIP.cmake

deleted100644 → 0
+0 −573

File deleted.

Preview size limit exceeded, changes collapsed.

cmake/FindHIP/run_hipcc.cmake

deleted100644 → 0
+0 −168
Original line number Diff line number Diff line
###############################################################################
# Runs commands using HIPCC
###############################################################################

###############################################################################
# This file runs the hipcc commands to produce the desired output file
# along with the dependency file needed by CMake to compute dependencies.
#
# Input variables:
#
# verbose:BOOL=<>               OFF: Be as quiet as possible (default)
#                               ON : Describe each step
# build_configuration:STRING=<> Build configuration. Defaults to Debug.
# generated_file:STRING=<>      File to generate. Mandatory argument.

if(NOT build_configuration)
    set(build_configuration Debug)
endif()
if(NOT generated_file)
    message(FATAL_ERROR "You must specify generated_file on the command line")
endif()

# Set these up as variables to make reading the generated file easier
set(HIP_HIPCC_EXECUTABLE "@HIP_HIPCC_EXECUTABLE@") # path
set(HIP_HIPCONFIG_EXECUTABLE "@HIP_HIPCONFIG_EXECUTABLE@") #path
set(HIP_HOST_COMPILER "@HIP_HOST_COMPILER@") # path
set(CMAKE_COMMAND "@CMAKE_COMMAND@") # path
set(HIP_run_make2cmake "@HIP_run_make2cmake@") # path
set(HCC_HOME "@HCC_HOME@") #path

@HIP_HOST_FLAGS@
@_HIP_HIPCC_FLAGS@
@_HIP_HCC_FLAGS@
@_HIP_NVCC_FLAGS@
set(HIP_HIPCC_INCLUDE_ARGS "@HIP_HIPCC_INCLUDE_ARGS@") # list (needs to be in quotes to handle spaces properly)

set(cmake_dependency_file "@cmake_dependency_file@") # path
set(source_file "@source_file@") # path
set(host_flag "@host_flag@") # bool

# Determine compiler and compiler flags
execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --platform OUTPUT_VARIABLE HIP_PLATFORM OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT host_flag)
    set(__CC ${HIP_HIPCC_EXECUTABLE})
    if(HIP_PLATFORM STREQUAL "hcc")
        if(NOT "x${HCC_HOME}" STREQUAL "x")
            set(ENV{HCC_HOME} ${HCC_HOME})
        endif()
        set(__CC_FLAGS ${HIP_HIPCC_FLAGS} ${HIP_HCC_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_HCC_FLAGS_${build_configuration}})
    else()
        set(__CC_FLAGS ${HIP_HIPCC_FLAGS} ${HIP_NVCC_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_NVCC_FLAGS_${build_configuration}})
    endif()
else()
    set(__CC ${HIP_HOST_COMPILER})
    set(__CC_FLAGS ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}})
endif()
set(__CC_INCLUDES ${HIP_HIPCC_INCLUDE_ARGS})

# hip_execute_process - Executes a command with optional command echo and status message.
#   status     - Status message to print if verbose is true
#   command    - COMMAND argument from the usual execute_process argument structure
#   ARGN       - Remaining arguments are the command with arguments
#   HIP_result - Return value from running the command
macro(hip_execute_process status command)
    set(_command ${command})
    if(NOT "x${_command}" STREQUAL "xCOMMAND")
        message(FATAL_ERROR "Malformed call to hip_execute_process.  Missing COMMAND as second argument. (command = ${command})")
    endif()
    if(verbose)
        execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
        # Build command string to print
        set(hip_execute_process_string)
        foreach(arg ${ARGN})
            # Escape quotes if any
            string(REPLACE "\"" "\\\"" arg ${arg})
            # Surround args with spaces with quotes
            if(arg MATCHES " ")
                list(APPEND hip_execute_process_string "\"${arg}\"")
            else()
                list(APPEND hip_execute_process_string ${arg})
            endif()
        endforeach()
        # Echo the command
        execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${hip_execute_process_string})
    endif()
    # Run the command
    execute_process(COMMAND ${ARGN} RESULT_VARIABLE HIP_result)
endmacro()

# Delete the target file
hip_execute_process(
    "Removing ${generated_file}"
    COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
    )

# Generate the dependency file
hip_execute_process(
    "Generating dependency file: ${cmake_dependency_file}.pre"
    COMMAND "${__CC}"
    -M
    "${source_file}"
    -o "${cmake_dependency_file}.pre"
    ${__CC_FLAGS}
    ${__CC_INCLUDES}
    )

if(HIP_result)
    message(FATAL_ERROR "Error generating ${generated_file}")
endif()

# Generate the cmake readable dependency file to a temp file
hip_execute_process(
    "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
    COMMAND "${CMAKE_COMMAND}"
    -D "input_file:FILEPATH=${cmake_dependency_file}.pre"
    -D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
    -D "verbose=${verbose}"
    -P "${HIP_run_make2cmake}"
    )

if(HIP_result)
    message(FATAL_ERROR "Error generating ${generated_file}")
endif()

# Copy the file if it is different
hip_execute_process(
    "Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}"
    COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}"
    )

if(HIP_result)
    message(FATAL_ERROR "Error generating ${generated_file}")
endif()

# Delete the temporary file
hip_execute_process(
    "Removing ${cmake_dependency_file}.tmp and ${cmake_dependency_file}.pre"
    COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${cmake_dependency_file}.pre"
    )

if(HIP_result)
    message(FATAL_ERROR "Error generating ${generated_file}")
endif()

# Generate the output file
hip_execute_process(
    "Generating ${generated_file}"
    COMMAND "${__CC}"
    -c
    "${source_file}"
    -o "${generated_file}"
    ${__CC_FLAGS}
    ${__CC_INCLUDES}
    )

if(HIP_result)
    # Make sure that we delete the output file
    hip_execute_process(
        "Removing ${generated_file}"
        COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
        )
    message(FATAL_ERROR "Error generating file ${generated_file}")
else()
    if(verbose)
        message("Generated ${generated_file} successfully.")
    endif()
endif()
# vim: ts=4:sw=4:expandtab:smartindent
+0 −50
Original line number Diff line number Diff line
###############################################################################
# Computes dependencies using HIPCC
###############################################################################

###############################################################################
# This file converts dependency files generated using hipcc to a format that
# cmake can understand.

# Input variables:
#
# input_file:STRING=<> Dependency file to parse. Required argument
# output_file:STRING=<> Output file to generate. Required argument

if(NOT input_file OR NOT output_file)
    message(FATAL_ERROR "You must specify input_file and output_file on the command line")
endif()

file(READ ${input_file} depend_text)

if (NOT "${depend_text}" STREQUAL "")
    string(REPLACE " /" "\n/" depend_text ${depend_text})
    string(REGEX REPLACE "^.*:" "" depend_text ${depend_text})
    string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})

    set(dependency_list "")

    foreach(file ${depend_text})
        string(REGEX REPLACE "^ +" "" file ${file})
        if(NOT EXISTS "${file}")
            message(WARNING " Removing non-existent dependency file: ${file}")
            set(file "")
        endif()

        if(NOT IS_DIRECTORY "${file}")
            get_filename_component(file_absolute "${file}" ABSOLUTE)
            list(APPEND dependency_list "${file_absolute}")
        endif()
    endforeach()
endif()

# Remove the duplicate entries and sort them.
list(REMOVE_DUPLICATES dependency_list)
list(SORT dependency_list)

foreach(file ${dependency_list})
    set(hip_hipcc_depend "${hip_hipcc_depend} \"${file}\"\n")
endforeach()

file(WRITE ${output_file} "# Generated by: FindHIP.cmake. Do not edit.\nSET(HIP_HIPCC_DEPEND\n ${hip_hipcc_depend})\n\n")
# vim: ts=4:sw=4:expandtab:smartindent