NVIDIA / NVIDIA/cccl

[FEA]: Would be nice to have a conversion function to `CUdeviceptr` in `thrust::device_ptr`

Open
#4,896 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

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

Thrust

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

The data type `CUdeviceptr` is used rather extensively in OptiX and it is really cumbersome to write something like this:

```cpp
check(optixAccelBuild(ctx, nullptr, &accelOptions, buildInputs.data(), buildInputs.size(), reinterpret_cast(tempBuffer.data().get()), bufferSizes.tempSizeInBytes, reinterpret_cast(gasBuffer.data().get()), bufferSizes.outputSizeInBytes, &handle, nullptr, 0));
```

Especially as `CUdeviceptr` is conceptually the exact same as `thrust::device_ptr`

### Describe the solution you'd like

It would be nice to have an implicit conversion function to `CUdeviceptr`:

```cpp
/*! \brief Converts this \c device_ptr to a raw \c CUdeviceptr.
*/
_CCCL_HOST_DEVICE operator CUdeviceptr() const {
return reinterpret_cast(super_t::get());
}
```

so that such calls simplify to:

```cpp
check(optixAccelBuild(ctx, nullptr, &accelOptions, buildInputs.data(), buildInputs.size(), tempBuffer.data(), bufferSizes.tempSizeInBytes, gasBuffer.data(), bufferSizes.outputSizeInBytes, &handle, nullptr, 0));
```

### 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.