Skip to content

Fix cuda_shared_memory standalone example #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/cmake/FindCUDA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2024 Intel Corporation
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

message(STATUS "Checking for module 'cuda' using find_library()")

find_library(CUDA_LIBRARY NAMES libcuda cuda)
set(CUDA_LIBRARIES ${CUDA_LIBRARY})

get_filename_component(CUDA_LIB_DIR ${CUDA_LIBRARIES} DIRECTORY)
set(CUDA_LIBRARY_DIRS ${CUDA_LIB_DIR})

if(WINDOWS)
find_file(CUDA_DLL NAMES "bin/cuda.dll" "cuda.dll")
get_filename_component(CUDA_DLL_DIR ${CUDA_DLL} DIRECTORY)
set(CUDA_DLL_DIRS ${CUDA_DLL_DIR})
endif()

if(CUDA_LIBRARY)
message(STATUS " Found cuda using find_library()")
message(STATUS " CUDA_LIBRARIES = ${CUDA_LIBRARIES}")
message(STATUS " CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}")
message(STATUS " CUDA_LIBRARY_DIRS = ${CUDA_LIBRARY_DIRS}")
if(WINDOWS)
message(STATUS " CUDA_DLL_DIRS = ${CUDA_DLL_DIRS}")
endif()
else()
set(MSG_NOT_FOUND "cuda NOT found (set CMAKE_PREFIX_PATH to point the "
"location)")
if(CUDA_FIND_REQUIRED)
message(FATAL_ERROR ${MSG_NOT_FOUND})
else()
message(WARNING ${MSG_NOT_FOUND})
endif()
endif()
16 changes: 12 additions & 4 deletions examples/cuda_shared_memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if(NOT LIBHWLOC_FOUND)
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
endif()

find_package(CUDA REQUIRED cuda)

include(FetchContent)

set(CUDA_REPO "https://gitlab.com/nvidia/headers/cuda-individual/cudart.git")
Expand All @@ -43,17 +45,23 @@ set(CUDA_INCLUDE_DIRS
${cuda-headers_SOURCE_DIR}
CACHE PATH "Path to CUDA headers")
message(STATUS "CUDA include directory: ${CUDA_INCLUDE_DIRS}")

# build the example
set(EXAMPLE_NAME umf_example_cuda_shared_memory)
add_executable(${EXAMPLE_NAME} cuda_shared_memory.c)
target_include_directories(
${EXAMPLE_NAME} PRIVATE ${CUDA_INCLUDE_DIRS} ${LIBUMF_INCLUDE_DIRS}
${UMF_EXAMPLE_DIR}/common)
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARY_DIRS}
${LIBHWLOC_LIBRARY_DIRS})
target_link_directories(
${EXAMPLE_NAME}
PRIVATE
${LIBUMF_LIBRARY_DIRS}
${LIBHWLOC_LIBRARY_DIRS}
${CUDA_LIBRARY_DIRS})
target_link_options(${EXAMPLE_NAME} PRIVATE "-Wl,--start-group")
target_link_libraries(${EXAMPLE_NAME} PRIVATE stdc++ libdisjoint_pool.a cuda
${LIBUMF_LIBRARIES})
target_link_libraries(
${EXAMPLE_NAME} PRIVATE stdc++ libdisjoint_pool.a ${CUDA_LIBRARIES}
${LIBUMF_LIBRARIES})

# an optional part - adds a test of this example
add_test(
Expand Down
Loading