|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +# |
| 18 | +# Variables used by this module, they can change the default behaviour and need |
| 19 | +# to be set before calling find_package: |
| 20 | +# |
| 21 | +# NCCL_ROOT - When set, this path is inspected instead of standard library |
| 22 | +# locations as the root of the NCCL installation. |
| 23 | +# The environment variable NCCL_ROOT overrides this variable. |
| 24 | +# |
| 25 | +# This module defines |
| 26 | +# Nccl_FOUND, whether nccl has been found |
| 27 | +# NCCL_INCLUDE_DIR, directory containing header |
| 28 | +# NCCL_LIBRARY, directory containing nccl library |
| 29 | +# This module assumes that the user has already called find_package(CUDA) |
| 30 | + |
| 31 | +macro(find_nccl use_nccl) |
| 32 | + if(${use_nccl} MATCHES ${IS_FALSE_PATTERN}) |
| 33 | + return() |
| 34 | + endif() |
| 35 | + if(${use_nccl} MATCHES ${IS_TRUE_PATTERN}) |
| 36 | + find_path(NCCL_INCLUDE_DIR NAMES nccl.h) |
| 37 | + find_library(NCCL_LIBRARY NAMES nccl) |
| 38 | + else() |
| 39 | + find_path(NCCL_INCLUDE_DIR NAMES nccl.h HINTS ${use_nccl} ${use_nccl}/include) |
| 40 | + find_library(NCCL_LIBRARY NAMES nccl HINTS ${use_nccl} ${use_nccl}/lib) |
| 41 | + endif() |
| 42 | + include(FindPackageHandleStandardArgs) |
| 43 | + find_package_handle_standard_args(Nccl DEFAULT_MSG NCCL_INCLUDE_DIR NCCL_LIBRARY) |
| 44 | + if (Nccl_FOUND) |
| 45 | + message(STATUS "Found NCCL_LIBRARY: ${NCCL_LIBRARY}") |
| 46 | + message(STATUS "Found NCCL_INCLUDE_DIR: ${NCCL_INCLUDE_DIR}") |
| 47 | + add_library(nccl SHARED IMPORTED) |
| 48 | + set_target_properties(nccl |
| 49 | + PROPERTIES |
| 50 | + INTERFACE_INCLUDE_DIRECTORIES "${NCCL_INCLUDE_DIR}" |
| 51 | + IMPORTED_LOCATION "${NCCL_LIBRARY}") |
| 52 | + else() |
| 53 | + message(STATUS "NCCL not found") |
| 54 | + endif() |
| 55 | + mark_as_advanced(NCCL_INCLUDE_DIR NCCL_LIBRARY) |
| 56 | +endmacro(find_nccl) |
0 commit comments