miopen.cmake 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
if(NOT WITH_ROCM)
    return()
endif()

# Now we don't support ROCm on windows
if(WIN32)
    return()
endif()

set(MIOPEN_ROOT ${ROCM_PATH}/miopen CACHE PATH "MIOPEN ROOT")

find_path(MIOPEN_INCLUDE_DIR "miopen/miopen.h"
    PATHS ${MIOPEN_ROOT} ${MIOPEN_ROOT}/include ${MIOPEN_ROOT}/local/include
          $ENV{MIOPEN_ROOT} $ENV{MIOPEN_ROOT}/include $ENV{MIOPEN_ROOT}/local/include
          NO_DEFAULT_PATH
)

get_filename_component(__libpath_hist ${CUDA_CUDART_LIBRARY} PATH)

find_library(MIOPEN_LIBRARY NAMES "libMIOpen.so"
    PATHS ${MIOPEN_ROOT} ${MIOPEN_ROOT}/lib ${MIOPEN_ROOT}/lib64 ${__libpath_hist} 
          $ENV{MIOPEN_ROOT} $ENV{MIOPEN_ROOT}/lib $ENV{MIOPEN_ROOT}/lib64 
          NO_DEFAULT_PATH 
    DOC "Path to MIOpen library.")

if(MIOPEN_INCLUDE_DIR AND MIOPEN_LIBRARY)
    set(MIOPEN_FOUND ON)
else()
    set(MIOPEN_FOUND OFF)
endif()

macro(find_miopen_version miopen_header_file) 
    file(READ ${miopen_header_file} MIOPEN_VERSION_FILE_CONTENTS)
    get_filename_component(MIOPEN_LIB_PATH ${MIOPEN_LIBRARY} DIRECTORY)

    string(REGEX MATCH "define MIOPEN_VERSION_MAJOR +([0-9]+)" MIOPEN_MAJOR_VERSION
        "${MIOPEN_VERSION_FILE_CONTENTS}")
    string(REGEX REPLACE "define MIOPEN_VERSION_MAJOR +([0-9]+)" "\\1"
        MIOPEN_MAJOR_VERSION "${MIOPEN_MAJOR_VERSION}")
    string(REGEX MATCH "define MIOPEN_VERSION_MINOR +([0-9]+)" MIOPEN_MINOR_VERSION
        "${MIOPEN_VERSION_FILE_CONTENTS}")
    string(REGEX REPLACE "define MIOPEN_VERSION_MINOR +([0-9]+)" "\\1"
        MIOPEN_MINOR_VERSION "${MIOPEN_MINOR_VERSION}")
    string(REGEX MATCH "define MIOPEN_VERSION_PATCH +([0-9]+)" MIOPEN_PATCH_VERSION
        "${MIOPEN_VERSION_FILE_CONTENTS}")
    string(REGEX REPLACE "define MIOPEN_VERSION_PATCH +([0-9]+)" "\\1"
        MIOPEN_PATCH_VERSION "${MIOPEN_PATCH_VERSION}")
    string(REGEX MATCH "define MIOPEN_VERSION_TWEAK +([0-9]+)" MIOPEN_TWEAK_VERSION
        "${MIOPEN_VERSION_FILE_CONTENTS}")
    string(REGEX REPLACE "define MIOPEN_VERSION_TWEAK +([0-9]+)" "\\1"
        MIOPEN_TWEAK_VERSION "${MIOPEN_TWEAK_VERSION}")

    if(NOT MIOPEN_MAJOR_VERSION)
        set(MIOPEN_VERSION "???")
    else()
        add_definitions("-DMIOPEN_MAJOR_VERSION=\"${MIOPEN_MAJOR_VERSION}\"")
        math(EXPR MIOPEN_VERSION
            "${MIOPEN_MAJOR_VERSION} * 1000 +
             ${MIOPEN_MINOR_VERSION} * 10 + ${MIOPEN_PATCH_VERSION}")
        message(STATUS "Current MIOpen header is ${MIOPEN_INCLUDE_DIR}/miopen/miopen.h "
          "Current MIOpen version is v${MIOPEN_MAJOR_VERSION}.${MIOPEN_MINOR_VERSION}.${MIOPEN_PATCH_VERSION}. ")
    endif()
endmacro()

if(MIOPEN_FOUND)
  find_miopen_version(${MIOPEN_INCLUDE_DIR}/miopen/version.h) 
endif()