@@ -49,16 +49,41 @@ find_library(NCCL_LIBRARIES
49
49
include (FindPackageHandleStandardArgs)
50
50
find_package_handle_standard_args(NCCL DEFAULT_MSG NCCL_INCLUDE_DIRS NCCL_LIBRARIES)
51
51
52
- if (NCCL_FOUND)
52
+ if (NCCL_FOUND) # obtaining NCCL version and some sanity checks
53
53
set (NCCL_HEADER_FILE "${NCCL_INCLUDE_DIRS} /nccl.h" )
54
- message (STATUS "Determining NCCL version from the header file: ${NCCL_HEADER_FILE} " )
55
- file (STRINGS ${NCCL_HEADER_FILE} NCCL_MAJOR_VERSION_DEFINED
56
- REGEX "^[ \t ]*#define[ \t ]+NCCL_MAJOR[ \t ]+[0-9]+.*$" LIMIT_COUNT 1)
57
- if (NCCL_MAJOR_VERSION_DEFINED)
58
- string (REGEX REPLACE "^[ \t ]*#define[ \t ]+NCCL_MAJOR[ \t ]+" ""
59
- NCCL_MAJOR_VERSION ${NCCL_MAJOR_VERSION_DEFINED} )
60
- message (STATUS "NCCL_MAJOR_VERSION: ${NCCL_MAJOR_VERSION} " )
54
+ message (STATUS "Determining NCCL version from ${NCCL_HEADER_FILE} ..." )
55
+ set (OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} )
56
+ list (APPEND CMAKE_REQUIRED_INCLUDES ${NCCL_INCLUDE_DIRS} )
57
+ include (CheckCXXSymbolExists)
58
+ check_cxx_symbol_exists(NCCL_VERSION_CODE nccl.h NCCL_VERSION_DEFINED)
59
+
60
+ if (NCCL_VERSION_DEFINED)
61
+ set (file "${PROJECT_BINARY_DIR} /detect_nccl_version.cc" )
62
+ file (WRITE ${file} "
63
+ #include <iostream>
64
+ #include <nccl.h>
65
+ int main()
66
+ {
67
+ std::cout << NCCL_MAJOR << '.' << NCCL_MINOR << '.' << NCCL_PATCH << std::endl;
68
+
69
+ int x;
70
+ ncclGetVersion(&x);
71
+ return x == NCCL_VERSION_CODE;
72
+ }
73
+ " )
74
+ try_run (NCCL_VERSION_MATCHED compile_result ${PROJECT_BINARY_DIR} ${file}
75
+ RUN_OUTPUT_VARIABLE NCCL_VERSION_FROM_HEADER
76
+ LINK_LIBRARIES ${NCCL_LIBRARIES} )
77
+ if (NOT NCCL_VERSION_MATCHED)
78
+ message (FATAL_ERROR "Found NCCL header version and library version do not match! \
79
+ (include: ${NCCL_INCLUDE_DIRS} , library: ${NCCL_LIBRARIES} ) Please set NCCL_INCLUDE_DIR and NCCL_LIB_DIR manually." )
80
+ endif ()
81
+ message (STATUS "NCCL version: ${NCCL_VERSION_FROM_HEADER} " )
82
+ else ()
83
+ message (STATUS "NCCL version < 2.3.5-5" )
61
84
endif ()
85
+ set (CMAKE_REQUIRED_INCLUDES ${OLD_CMAKE_REQUIRED_INCLUDES} )
86
+
62
87
message (STATUS "Found NCCL (include: ${NCCL_INCLUDE_DIRS} , library: ${NCCL_LIBRARIES} )" )
63
88
mark_as_advanced (NCCL_ROOT_DIR NCCL_INCLUDE_DIRS NCCL_LIBRARIES)
64
89
endif ()
0 commit comments