################################################################################ # # MIT License # # Copyright (c) 2020 Advanced Micro Devices, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ################################################################################ cmake_minimum_required( VERSION 3.15 ) # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if( NOT MSVC_IDE AND NOT CMAKE_BUILD_TYPE ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) endif() # Default installation path if(WIN32) set(CMAKE_INSTALL_PREFIX "/opt/rocm/x86_64-w64-mingw32" CACHE PATH "") else() set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "") endif() project ( fin C CXX ) find_package(ROCM REQUIRED PATHS /opt/rocm) include(ROCMInstallTargets) include(ROCMPackageConfigHelpers) include(ROCMSetupVersion) include(ROCMInstallSymlinks) include(ROCMCreatePackage) include(CheckCXXCompilerFlag) # Build library with beta apis add_definitions("-DMIOPEN_BETA_API=1") option( BUILD_DEV "Build for development only" OFF) rocm_setup_version(VERSION 1.0.0) list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ) include(TargetFlags) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.3") message(FATAL_ERROR "MIOpen requires at least gcc 5.3") endif() endif() include(CheckCXXLinkerFlag) check_cxx_linker_flag(stdc++fs HAS_LIB_STD_FILESYSTEM) ############################################################ # require C++20 add_compile_options(-std=c++20) ############################################################ # OPTION - MIOpen Backend # - OpenCL # - HCC check_cxx_compiler_flag("--cuda-host-only -x hip" HAS_HIP) if(CMAKE_CXX_COMPILER MATCHES ".*hcc" OR CMAKE_CXX_COMPILER MATCHES ".*hipcc" OR HAS_HIP) set(FIN_DEFAULT_BACKEND "HIP") else() set(FIN_DEFAULT_BACKEND "OpenCL") endif() if(WIN32 AND CMAKE_CROSSCOMPILING) set(WINE_CMD "wine") else() set(WINE_CMD) endif() list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/hcc /opt/rocm/hip) set( FIN_BACKEND ${FIN_DEFAULT_BACKEND} CACHE STRING "Which of MIOpens's backends to use?" ) set_property( CACHE FIN_BACKEND PROPERTY STRINGS OpenCL HIP HIPOC ) # HIP is always required find_package(hip REQUIRED PATHS /opt/rocm) # OpenCL 1.2 if( FIN_BACKEND STREQUAL "OpenCL") message(STATUS "OpenCL Backend") set(FIN_BACKEND_OPENCL 1) find_package( OpenCL REQUIRED ) find_program(FIN_HIP_COMPILER hcc PATH_SUFFIXES bin PATHS /opt/rocm ) find_package(miopengemm PATHS /opt/rocm) endif() # HIP if( FIN_BACKEND STREQUAL "HIP" OR FIN_BACKEND STREQUAL "HIPOC") message(STATUS "HIP Backend") set(FIN_BACKEND_HIP 1) if(CMAKE_CXX_COMPILER MATCHES ".*hcc") link_libraries(stdc++) # A hack to make this work without the device enumerator link_libraries(-amdgpu-target=gfx803 -amdgpu-target=gfx900 -Wno-unused-command-line-argument) CHECK_CXX_COMPILER_FLAG("-amdgpu-target=gfx906 -Werror" GFX_906_FLAG_VALID) if(GFX_906_FLAG_VALID) link_libraries(-amdgpu-target=gfx906) endif() CHECK_CXX_COMPILER_FLAG(-amdgpu-target=gfx908 -Werror, GFX_908_FLAG_VALID) if(GFX_908_FLAG_VALID) link_libraries(-amdgpu-target=gfx908) endif() # end hack else() # Hcc's clang always defines __HCC__ even when not using hcc driver add_definitions(-U__HCC__) endif() # end hack set(MIOPEN_HIP_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "") endif() message( STATUS "${FIN_BACKEND} backend selected." ) # find_package for miopen is broken on the OpenCL backend # look for and register extractkernel find_program(EXTRACTKERNEL_BIN extractkernel PATH_SUFFIXES bin PATHS /opt/rocm ) if(CMAKE_CXX_COMPILER MATCHES ".*hcc") if(EXTRACTKERNEL_BIN) message(STATUS "extractkernel found: ${EXTRACTKERNEL_BIN}") set(EXTRACTKERNEL_BIN "${EXTRACTKERNEL_BIN}") else() message(FATAL_ERROR "extractkernel not found") endif() endif() find_path(HALF_INCLUDE_DIR half.hpp HINTS ${CMAKE_INSTALL_PREFIX} PATH_SUFFIXES include include/half) message(STATUS "HALF_INCLUDE_DIR: ${HALF_INCLUDE_DIR}") include_directories(${HALF_INCLUDE_DIR}) option( BUILD_SHARED_LIBS "Build as a shared library" ON ) set(MIOPEN_PACKAGE_REQS "rocm-utils, hip-hcc") set(CPACK_DEBIAN_PACKAGE_DEPENDS "${MIOPEN_PACKAGE_REQS}, rocm-opencl-dev") set(CPACK_RPM_PACKAGE_REQUIRES "${MIOPEN_PACKAGE_REQS}, rocm-opencl-devel") rocm_create_package( NAME fin-${FIN_BACKEND} DESCRIPTION "Fin MIOpen Driver" MAINTAINER "Tuna Devs