-
Notifications
You must be signed in to change notification settings - Fork 208
[DOC]: Improve documentation for cmake usage #4452
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
Comments
It is a bit of a mess -- things have changed over the years and need to be cleaned up. I'll look into updating the docs to make this more cohesive. To answer your question: https://nvidia.github.io/cccl/thrust/cmake_options.html is for configuring and building the thrust tests/examples as part of a developer build. The options listed there are not available in the installed CMake packages. The CCCL package provides Thrust and is the preferred way to include Thrust. By default, CCCL defines a Your first example was most of the way there, it just needed to define that variable:
https://github.com/NVIDIA/cccl/blob/main/lib/cmake/thrust/README.md describes in more detail how to configure thrust as a user. The If you want to use both TBB and OMP from the same build you can use
|
Thank you for the fast reply I appreciate the help. I have tried your solutions and I have a couple of follow-up questions
// main.cpp
#include <iostream>
#include <thrust/device_vector.h>
int main()
{
#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CPP
std::cout << "Thrust device system is CPP\n";
#elif THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_TBB
std::cout << "Thrust device system is TBB\n";
#elif THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_OMP
std::cout << "Thrust device system is OMP\n";
#elif THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA
std::cout << "Thrust device system is CUDA\n";
#endif
return 0;
} |
These variables are marked as advanced and hidden by default, since most users of CCCL just want the CUDA backend. You'll need to toggle advanced mode (press
Something like this should work:
This can be overridden by setting the
Yes, this is still the preferred way to check in-source which system is used. |
Is this a duplicate?
Is this for new documentation, or an update to existing docs?
Update
Describe the incorrect/future/missing documentation
I am trying to write a
CMakeLists.txt
file for my project that depends on thrust. For the sake of argument here is a minimal mainI want to compile this program for various values of the the
THRUST_DEVICE_SYSTEM
i.e.g++ -O2 -Wall -std=c++17 -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP main.cpp -o main -I<path/to/thrust/thrust>
g++ -fopenmp -O2 -Wall -std=c++17 -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP main.cpp -o main -I<path/to/thrust/thrust>
nvcc --compiler-bindir g++ -O2 -x cu -std=c++17 main.cpp -o main -I<path/to/thrust/thrust>
My problem is that I do not find instructions of how to achieve this with the cmake configuration provided in cccl. In the cccl README https://github.com/NVIDIA/cccl there is a (short) paragraph telling me that cccl should be configured with cmake and I can install it using
(which I did) and to follow the example https://github.com/NVIDIA/cccl/tree/main/examples/basic for the rest. That example essentially tells me to use the CPM package manager to find cccl and that I can compile for a GPU, however the other two possibilities (CPP and OMP) are not discussed.
This link https://nvidia.github.io/cccl/thrust/cmake_options.html essentially lists a couple of options that I should see using
cmake-gui
but it does not tell me anything about what cmake targets are defined that have those options.Finally, I found this hidden https://github.com/NVIDIA/cccl/blob/main/lib/cmake/thrust/README.md which tells me that there is a
thrust_create_target
function but since the file is so tugged away in a sub-folder I am unsure if this is still a maintained feature or just a remainder of the thrust integration into cccl.My first issue is that I now have four different places that describe cmake behaviour in cccl/thrust but none describe how I achieve my above goal. Could you update your documentation in this regard?
Here is what I tried so far
Configuring and building leads to a valid GPU build with
THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA
. But how do I compile forCPP
andOMP
?Here, I get a warning from cmake that
THRUST_DEVICE_SYSTEM
was not used by the project and the build still compiles for a GPU. This leaves me a bit at a loss as to how the options from https://nvidia.github.io/cccl/thrust/cmake_options.html are supposed to appear?Works the same as Attempt 1? So which should I use? Is there a difference?
Now this actually compiles my target for
CPP
andOMP
, but unfortunately it fails forCUDA
because the file ending is wrong and thec++
compiler is invoked instead ofnvcc
. Also, contrary to the documentation https://github.com/NVIDIA/cccl/blob/main/lib/cmake/thrust/README.md theTHRUST_DEVICE_SYSTEM
option does not appear in mycmake-gui
onlyTHRUST_DISPATCH_TYPE
. I would also like to selectively load theCUDA
language only if the user wants to compile for cuda. How do I do this?At this point I don't know how to proceed, I am still learning CMake and I would greatly appreciate a working example that achieves what I want in cmake.
If this is a correction, please provide a link to the incorrect documentation. If this is a new documentation request, please link to where you have looked.
Places I have looked:
https://github.com/NVIDIA/cccl
https://github.com/NVIDIA/cccl/tree/main/examples/basic
https://nvidia.github.io/cccl/thrust/cmake_options.html
https://github.com/NVIDIA/cccl/blob/main/lib/cmake/thrust/README.md
The text was updated successfully, but these errors were encountered: