Skip to content
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

[BUG]: find_package(CCCL) cannot be called twice #1156

Closed
1 task done
ptheywood opened this issue Nov 28, 2023 · 5 comments · Fixed by #1157
Closed
1 task done

[BUG]: find_package(CCCL) cannot be called twice #1156

ptheywood opened this issue Nov 28, 2023 · 5 comments · Fixed by #1157
Assignees
Labels
bug Something isn't working right. infrastructure Shared CMake, github, etc infrastructure

Comments

@ptheywood
Copy link

Is this a duplicate?

Type of Bug

Something else

Component

Thrust

Describe the bug

If find_package(CCCL) is invoked multiple times during configuration, the second occurance will trigger a CMake Error as CCCL::Thrust already exists, i.e. it's creation is unguarded by an if(TARGET ...).

This occurs if the find_package calls are in the same CMakeLists.txt, or in separate CMakeLists.txt with an add_subdirectory(subdir) relationship (i.e. if a dependency and a parent package both require CCCL, or if multiple targets in a parent project wish to include/link against CCCL::cccl).

This occurs with the CCCL 2.2.0 distribtued with CUDA 12.2 &* 12.3, and with current main (e79b13c).

I can work around this by guarding the find_package call myself, but that would rely on dependencies also guarding that call in a complex enough project. It can also be avoided by not requesting the thrust component.

How to Reproduce

  1. Create (or ammend) an exisitng CMakeLists.txt to find_target(CCCL) twice, with the appropriate location of CCCL on the CMAKE_PREFIX_PATH, or set CCCL_DIR, or provide appropriate hints.
    e.g. in a completley fresh directory with CUDA 12.2 or 12.3 installed
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
project(mwe LANGUAGES CUDA)
# Modern CMake findCUDAToolkit for path hints
find_package(CUDAToolkit REQUIRED)
# Look for CCCL distributed with CUDA 
find_package(CCCL CONFIG REQUIRED HINTS ${CUDAToolkit_INCLUDE_DIRS} ${CUDAToolkit_LIBRARY_DIR}/cmake)
# Attempting to find CCCL again results in an error (say if a dependency found it as well), as a target cannot be recreated. 
find_package(CCCL CONFIG REQUIRED HINTS ${CUDAToolkit_INCLUDE_DIRS} ${CUDAToolkit_LIBRARY_DIR}/cmake)

Or in a subdirectory of the cccl repository

git clone https://github.com/NVIDIA/cccl
cd cccl
mkdir -p cmake-find-target-mwe && cd cmake-find-target-mwe
cat > CMakeLists.txt << EOF
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
project(mwe LANGUAGES CUDA)
# Modern CMake findCUDAToolkit for path hints
find_package(CUDAToolkit REQUIRED)
# Look for CCCL distributed with CUDA 
find_package(CCCL REQUIRED HINTS \${CMAKE_CURRENT_LIST_DIR}/../)
# Attempting to find CCCL again results in an error (say if a dependency found it as well), as a target cannot be recreated. 
find_package(CCCL REQUIRED HINTS \${CMAKE_CURRENT_LIST_DIR}/../)
EOF
  1. Attempt to configure CMake
cmake -B build
  1. An error will be thrown, e.g.:
-- Found libcudacxx: /home/ptheywood/code/tmp/cccl/libcudacxx/lib/cmake/libcudacxx/libcudacxx-config.cmake (found suitable version "2.3.0.0", minimum required is "2.3.0.0") 
-- Found Thrust: /home/ptheywood/code/tmp/cccl/thrust/thrust/cmake/thrust-config.cmake (found suitable exact version "2.3.0.0") 
-- Found CUB: /home/ptheywood/code/tmp/cccl/cub/cub/cmake/cub-config.cmake (found suitable version "2.3.0.0", minimum required is "2.3.0.0") 
-- Found CCCL: /home/ptheywood/code/tmp/cccl/lib/cmake/cccl/cccl-config.cmake (found version "2.3.0.0") 
CMake Error at /home/ptheywood/code/tmp/cccl/thrust/thrust/cmake/thrust-config.cmake:183 (add_library):
  add_library cannot create imported target "CCCL::Thrust" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /home/ptheywood/code/tmp/cccl/lib/cmake/cccl/cccl-config.cmake:82 (thrust_create_target)
  CMakeLists.txt:8 (find_package)

Expected behavior

Cmake should configure successfully

Reproduction link

No response

Operating System

Ubuntu Linux 22.04

nvidia-smi output

No response

NVCC version

No response

@ptheywood ptheywood added the bug Something isn't working right. label Nov 28, 2023
@github-actions github-actions bot added the needs triage Issues that require the team's attention label Nov 28, 2023
Copy link
Contributor

Hi @ptheywood!

Thanks for submitting this issue - the CCCL team has been notified and we'll get back to you as soon as we can!
In the mean time, feel free to add any relevant information to this issue.

@ptheywood
Copy link
Author

The offending call is:

add_library(${target_name} INTERFACE IMPORTED)

Wrapping with if(NOT TARGET ${target_name}) allows configuration to succeed, but I'm not sure if that would have any unintended consequences.

@jrhemstad
Copy link
Collaborator

Hey @ptheywood, thanks for reaching out. I'll page our resident cmake experts to weigh in here (@allisonvacanti and @robertmaynard)

@alliepiper
Copy link
Collaborator

I'll take this one. We need to check for the existence of CCCL::Thrust at https://github.com/NVIDIA/cccl/blob/main/lib/cmake/cccl/cccl-config.cmake#L81 and add a test for this.

@alliepiper alliepiper assigned alliepiper and unassigned griwes Nov 28, 2023
@alliepiper alliepiper added infrastructure Shared CMake, github, etc infrastructure and removed needs triage Issues that require the team's attention labels Nov 28, 2023
@alliepiper
Copy link
Collaborator

The check already exists in line 74, it's just missing the TARGET keyword 🤦‍♀️

    if (TARGET Thrust::Thrust AND NOT CCCL::Thrust)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right. infrastructure Shared CMake, github, etc infrastructure
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants