NVIDIA / NVIDIA/cccl

[FEA]: Update example.cu in example_project to verify library version

Open
#543 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
487
Avg merge
2d 7h
Merged PRs (30d)
296

Description

### Is this a duplicate?

- [X] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this request and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)

### Area

Infrastructure

### Is your feature request related to a problem? Please describe.

As maintainers of CCCL, we rely on the [`example_project`](https://github.com/NVIDIA/cccl/tree/main/examples/example_project) to be a canonical example for how users can use CCCL from GitHub with cmake. To verify that this project works as expected, we build and run it as part of our CI process.

One of the things we want to verify is that we are successfully using the headers fetched from GitHub and not inadvertently using the CCCL headers from the CTK.

### Describe the solution you'd like

In order to verify that the `example.cu` finds the correct version of the CCCL headers, we can query the component versions found via cmake and pass those as preprocessor definitions to the `example_project` target. We can then update `example.cu` to compare the actual library version against these expected values.

Using `CCCL_VERSION` as an example, we can update the `CMakeLists.txt`:
```
# If CCCL_VERSION is defined (assuming the CCCL project provides this variable)
if(DEFINED CCCL_VERSION)
# Pass the version as a preprocessor definition to the example_project
target_compile_definitions(example_project PRIVATE EXPECTED_CCCL_VERSION="${CCCL_VERSION}")
endif()
```

And then in the `example.cu` file:
```
#include
#include
#include
#include

constexpr static auto actual_cccl_version = CCCL_VERSION;

static_assert(actual_cccl_version == EXPECTED_CCCL_VERSION,
"Mismatched CCCL_VERSION: Expected version from CMake does not match the actual version included in the source. "
"This likely means CCCL headers are inadvertently found from the CTK.");
```

I don't think we actually define `CCCL_VERSION` today, but the idea is to do this with `THRUST_VERSION`, `CUB_VERSION`, etc.

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.