@@ -390,60 +390,95 @@ if(hwloc_targ_SOURCE_DIR)
390390 endif ()
391391endif ()
392392
393- # Fetch L0 loader only if needed i.e.: if building L0 provider is ON and L0
394- # headers are not provided by the user (via setting UMF_LEVEL_ZERO_INCLUDE_DIR).
395- if (UMF_BUILD_LEVEL_ZERO_PROVIDER AND (NOT UMF_LEVEL_ZERO_INCLUDE_DIR))
396- set (LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git" )
397- set (LEVEL_ZERO_LOADER_TAG v1.21.9)
398-
399- message (
400- STATUS
401- "Fetching L0 loader (${LEVEL_ZERO_LOADER_TAG} ) from ${LEVEL_ZERO_LOADER_REPO} ..."
402- )
393+ if (UMF_BUILD_LEVEL_ZERO_PROVIDER)
394+ if (UMF_BUILD_GPU_TESTS OR UMF_BUILD_GPU_EXAMPLES)
395+ # Level Zero loader library is required to build Level Zero GPU tests
396+ # and examples
397+ find_package (ZE_LOADER REQUIRED ze_loader)
398+ else ()
399+ find_package (ZE_LOADER OPTIONAL ze_loader)
400+ endif ()
403401
404- FetchContent_Declare(
405- level-zero-loader
406- GIT_REPOSITORY ${LEVEL_ZERO_LOADER_REPO}
407- GIT_TAG ${LEVEL_ZERO_LOADER_TAG}
408- EXCLUDE_FROM_ALL )
409- # Only populate the repo - we don't need to build it
410- FetchContent_Populate(level-zero-loader)
411-
412- set (LEVEL_ZERO_INCLUDE_DIRS
413- ${level-zero-loader_SOURCE_DIR}/include
414- CACHE PATH "Path to Level Zero headers" )
415- message (STATUS "LEVEL_ZERO_INCLUDE_DIRS = ${LEVEL_ZERO_INCLUDE_DIRS} " )
416- elseif (UMF_BUILD_LEVEL_ZERO_PROVIDER)
417- # Only header is needed to build UMF
418- set (LEVEL_ZERO_INCLUDE_DIRS ${UMF_LEVEL_ZERO_INCLUDE_DIR} )
402+ # If the Level Zero headers are not provided by the user and not found in
403+ # the system, we will fetch them for the repo
404+ if (UMF_LEVEL_ZERO_INCLUDE_DIR)
405+ set (LEVEL_ZERO_INCLUDE_DIRS ${UMF_LEVEL_ZERO_INCLUDE_DIR} )
406+ elseif (ZE_LOADER_INCLUDE_DIR)
407+ set (LEVEL_ZERO_INCLUDE_DIRS ${ZE_LOADER_INCLUDE_DIR} )
408+ else ()
409+ set (LEVEL_ZERO_LOADER_REPO
410+ "https://github.com/oneapi-src/level-zero.git" )
411+ set (LEVEL_ZERO_LOADER_TAG v1.21.9)
412+
413+ message (STATUS "Fetching Level Zero loader (${LEVEL_ZERO_LOADER_TAG} ) "
414+ "from ${LEVEL_ZERO_LOADER_REPO} ..." )
415+ FetchContent_Declare(
416+ level-zero-loader
417+ GIT_REPOSITORY ${LEVEL_ZERO_LOADER_REPO}
418+ GIT_TAG ${LEVEL_ZERO_LOADER_TAG}
419+ EXCLUDE_FROM_ALL )
420+ # Only populate the repo - we don't need to build it
421+ FetchContent_Populate(level-zero-loader)
422+
423+ set (LEVEL_ZERO_INCLUDE_DIRS
424+ ${level-zero-loader_SOURCE_DIR}/include
425+ CACHE PATH "Path to Level Zero headers" )
426+ endif ()
419427 message (STATUS "LEVEL_ZERO_INCLUDE_DIRS = ${LEVEL_ZERO_INCLUDE_DIRS} " )
428+
429+ if (ZE_LOADER_LIBRARIES)
430+ set (UMF_LEVEL_ZERO_ENABLED TRUE )
431+ else ()
432+ message (
433+ STATUS
434+ "Disabling tests and examples that use the Level Zero Provider "
435+ "because the Level Zero libraries they require were not found." )
436+ endif ()
420437endif ()
421438
422- # Fetch CUDA only if needed i.e.: if building CUDA provider is ON and CUDA
423- # headers are not provided by the user (via setting UMF_CUDA_INCLUDE_DIR).
424- if (UMF_BUILD_CUDA_PROVIDER AND (NOT UMF_CUDA_INCLUDE_DIR))
425- set (CUDA_REPO
426- "https://gitlab.com/nvidia/headers/cuda-individual/cudart.git" )
427- set (CUDA_TAG cuda-12.5.1)
439+ if (UMF_BUILD_CUDA_PROVIDER)
440+ if (UMF_BUILD_GPU_TESTS OR UMF_BUILD_GPU_EXAMPLES)
441+ # CUDA library is required to build CUDA GPU tests and examples
442+ find_package (CUDA REQUIRED cuda)
443+ else ()
444+ find_package (CUDA OPTIONAL cuda)
445+ endif ()
428446
429- message (STATUS "Fetching CUDA (${CUDA_TAG} ) from ${CUDA_REPO} ..." )
447+ # If the CUDA headers are not provided by the user and not found in the
448+ # system, we will fetch them for the repo
430449
431- FetchContent_Declare(
432- cuda-headers
433- GIT_REPOSITORY ${CUDA_REPO}
434- GIT_TAG ${CUDA_TAG}
435- EXCLUDE_FROM_ALL )
436- # Only populate the repo - we don't need to build it
437- FetchContent_Populate(cuda-headers)
438-
439- set (CUDA_INCLUDE_DIRS
440- ${cuda-headers_SOURCE_DIR}
441- CACHE PATH "Path to CUDA headers" )
442- message (STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS} " )
443- elseif (UMF_BUILD_CUDA_PROVIDER)
444- # Only header is needed to build UMF
445- set (CUDA_INCLUDE_DIRS ${UMF_CUDA_INCLUDE_DIR} )
450+ if (UMF_CUDA_INCLUDE_DIR)
451+ set (CUDA_INCLUDE_DIRS ${UMF_CUDA_INCLUDE_DIR} )
452+ elseif (CUDA_INCLUDE_DIR)
453+ set (CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIR} )
454+ else ()
455+ set (CUDA_REPO
456+ "https://gitlab.com/nvidia/headers/cuda-individual/cudart.git" )
457+ set (CUDA_TAG cuda-12.5.1)
458+
459+ message (
460+ STATUS "Fetching CUDA (${CUDA_TAG} ) headers from ${CUDA_REPO} ..." )
461+ FetchContent_Declare(
462+ cuda-headers
463+ GIT_REPOSITORY ${CUDA_REPO}
464+ GIT_TAG ${CUDA_TAG}
465+ EXCLUDE_FROM_ALL )
466+ # Only populate the repo - we don't need to build it
467+ FetchContent_Populate(cuda-headers)
468+
469+ set (CUDA_INCLUDE_DIRS
470+ ${cuda-headers_SOURCE_DIR}
471+ CACHE PATH "Path to CUDA headers" )
472+ endif ()
446473 message (STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS} " )
474+
475+ if (CUDA_LIBRARIES)
476+ set (UMF_CUDA_ENABLED TRUE )
477+ else ()
478+ message (
479+ STATUS "Disabling tests and examples that use the CUDA Provider "
480+ "because the CUDA libraries they require were not found." )
481+ endif ()
447482endif ()
448483
449484# Build the umfd target in a separate directory with Debug configuration
@@ -711,18 +746,6 @@ else()
711746 )
712747endif ()
713748
714- if ((UMF_BUILD_GPU_TESTS OR UMF_BUILD_GPU_EXAMPLES) AND UMF_BUILD_CUDA_PROVIDER)
715- find_package (CUDA REQUIRED cuda)
716- if (CUDA_LIBRARIES)
717- set (UMF_CUDA_ENABLED TRUE )
718- else ()
719- message (
720- STATUS "Disabling tests and examples that use the CUDA provider "
721- "because the CUDA libraries they require were not found." )
722- endif ()
723- # TODO do the same for ze_loader
724- endif ()
725-
726749add_subdirectory (src)
727750
728751if (UMF_BUILD_TESTS)
0 commit comments