1# Build file for the C10 HIP. This directory doesn't actually contain 2# any files; these files are copied over by the HIPIFY script in tools/amd_build 3# 4# At the moment, this cmake is NOT standalone 5 6include(../../cmake/public/utils.cmake) 7 8if(BUILD_LIBTORCHLESS) 9 find_library(C10_HIP_LIB c10_hip PATHS $ENV{LIBTORCH_LIB_PATH} NO_DEFAULT_PATH) 10endif() 11 12# ---[ Configure macro file. 13set(C10_HIP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) # used in cmake_macros.h.in 14configure_file( 15 ${CMAKE_CURRENT_LIST_DIR}/impl/hip_cmake_macros.h.in 16 ${CMAKE_BINARY_DIR}/c10/hip/impl/hip_cmake_macros.h) 17 18# NB: All previous cu files are renamed into cc files. This isn't tested at the 19# moment. 20file(GLOB C10_HIP_SRCS 21 *.cpp 22 *.cc 23 impl/*.cpp 24 impl/*.cc 25 ) 26 27# Mark the cc files as HIP files, so we call the compiler. (They have to be 28# suffixed with cc, because the hcc compiler won't accept them otherwise.) 29file(GLOB __c10_hip_srcs_cpp *.cc impl/*.cc) 30set_source_files_properties(${__c10_hip_srcs_cpp} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) 31 32file(GLOB_RECURSE C10_HIP_HEADERS *.h) 33 34if(NOT BUILD_LIBTORCHLESS) 35 hip_add_library(c10_hip ${C10_HIP_SRCS} ${C10_HIP_HEADERS}) 36 37 # Propagate HIP_CXX_FLAGS that were set from Dependencies.cmake 38 target_compile_options(c10_hip PRIVATE ${HIP_CXX_FLAGS}) 39 40 # caffe2_hip adds a bunch of dependencies like rocsparse, but c10/hip is supposed to be 41 # minimal. I'm not sure if we need hip_hcc or not; for now leave it out 42 43 # If building shared library, set dllimport/dllexport proper. 44 target_compile_options(c10_hip PRIVATE "-DC10_HIP_BUILD_MAIN_LIB") 45 # Enable hidden visibility if compiler supports it. 46 if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) 47 target_compile_options(c10_hip PRIVATE "-fvisibility=hidden") 48 endif() 49 50 # ---[ Dependency of c10_hip 51 target_link_libraries(c10_hip PUBLIC ${C10_LIB} hip::amdhip64) 52 53 target_include_directories( 54 c10_hip PUBLIC 55 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..> 56 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> 57 $<INSTALL_INTERFACE:include>) 58 install(TARGETS c10_hip EXPORT Caffe2Targets DESTINATION lib) 59 set(C10_HIP_LIB c10_hip) 60endif() 61 62add_subdirectory(test) 63 64# ---[ Installation 65install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 66 DESTINATION include 67 FILES_MATCHING PATTERN "*.h") 68install(FILES ${CMAKE_BINARY_DIR}/c10/hip/impl/hip_cmake_macros.h 69 DESTINATION include/c10/hip/impl) 70