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

Using find_package(CUDAQ REQUIRED) in CMake does not work #2513

Open
3 of 4 tasks
diehlpk opened this issue Jan 15, 2025 · 5 comments
Open
3 of 4 tasks

Using find_package(CUDAQ REQUIRED) in CMake does not work #2513

diehlpk opened this issue Jan 15, 2025 · 5 comments

Comments

@diehlpk
Copy link

diehlpk commented Jan 15, 2025

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!

Describe the bug

Using find_package(CUDAQ REQUIRED) in a CMake project results in the following error

-- The CUDA Quantum compiler identification is NVQ++ - /opt/nvidia/cudaq/bin/nvq++
-- Number of NVIDIA GPUs detected: 1
-- CUDA Quantum Target = nvidia
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDAQ_CREATE_SHARED_LIBRARY
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDAQ_CREATE_SHARED_LIBRARY
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Steps to reproduce the bug

Using the latest image and include include find_package(CUDAQ REQUIRED) in your CMake project.

Expected behavior

I would assume that CMAKE_CUDAQ_CREATE_SHARED_LIBRARY should be set, since I am not sure what provide. It seems that On or Off does not work.

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

  • CUDA-Q version:
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

No response

@scothalverson
Copy link

I think I have resolved this for Patrick. Needed to add set_target_properties(LIB_NAME PROPERTIES LINKER_LANGUAGE CXX) to CMake to get C++ libraries to link properly. Waiting on Patrick to confirm this works for him.

@diehlpk
Copy link
Author

diehlpk commented Jan 22, 2025

Yes, that works for me.

@diehlpk
Copy link
Author

diehlpk commented Jan 24, 2025

@scothalverson I a use include(FetchContent), I get the following error

-- Number of NVIDIA GPUs detected: 1
-- CUDA Quantum Target = nvidia
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDAQ_ARCHIVE_CREATE
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDAQ_ARCHIVE_FINISH
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

@diehlpk
Copy link
Author

diehlpk commented Jan 27, 2025

It seems that set(CMAKE_CUDAQ_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") does the trick and I can compile the code again.

@amccaskey
Copy link
Collaborator

amccaskey commented Jan 27, 2025

Hey @diehlpk and @scothalverson .

Try to add the following before find_package(CUDAQ REQUIRED).

set(CUDAQ_LIBRARY_MODE ON)

Historically, there was some early implementation work that tried to expose CUDA-Q as a CMake language (enable_language(CUDAQ)). This was found to be brittle and we've since moved to better approaches. the CUDA_LIBRARY_MODE flag will disable this early work. Ultimately this should become the default IMO. Checkout the https://github.com/nvidia/cudaqx repo for a great reference on how to build off of CUDA-Q with CMake.

An interesting pattern that others will likely want to follow can be found in the cudaqx repo - separate compilation of host and qpu code. Checkout cmake/Modules/CUDA-QX.cmake there for a function that users can leverage to use nvq++ on known quantum kernel source files cudaqx_add_device_code. IMO this should be part of CUDA-Q so others can use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants