NVIDIA / NVIDIA/cccl

thrust::copy_if with host or TBB execution policy doesn't use TBB

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

Description

When compiled for the TBB host system, this:
```
int i[10];
int o[10];
thrust::copy_if(i, i + 10, o, [](int a){ return true; });
```
ends up dispatching thrust::system::tbb::detail::copy_if, which uses TBB (as expected).

However, specifying an execution policy:
```
thrust::copy_if(thrust::host, i, i + 10, o, [](int a){ return true; });
```
or
```
thrust::copy_if(thrust::tbb::par, i, i + 10, o, [](int a){ return true; });
```
ends up dispatching thrust::system::detail::sequential::copy_if, which does NOT use TBB. It uses the non-parallel sequential implementation.

Looking at backtraces in gdb it appears that thrust::copy_if with no execution policy ends up using thrust::system::tbb::detail::tag as the execution policy type, instead of thrust::system::tbb::detail::par_t (which is what thrust::host and thrust::tbb::par are). Indeed:

```
thrust::copy_if(thrust::system::tbb::detail::tag(), i, i + 10, o, [](int a){ return true; });
```
does in fact use the TBB implementation of copy_if. However, from the documentation this does not appear to be the prescribed way of doing this; moreover thrust::host and thrust::tbb::par do dispatch TBB implementations in other calls (copy, for_each, etc.)

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.