Device code generated from -stdpar versus thrust

Thanks for the explanation Mat. Not sure how many other people will want to compile Thrust code with nvc++ using CMake besides me but it would be fantastic when it is eventually fully supported.

The reason why I insist on using nvc++ goes back to my other forum topic where you told me that the C++ standard library is not yet supported in device code. I’d like to use Thrust for the random library functionality until it is supported natively in nvc++, at which time I can just switch the random library I’m using instead of switching the compiler as well. Does that sound reasonable? Also do you have an estimate for when on device will be added to nvc++?

FYI, the reason why I added -x cu to the compile command for the Thrust example is because I get the following error when it’s omitted:

$ nvc++ main.cpp
"main.cpp", line 1: catastrophic error: cannot open source file "thrust/host_vector.h"
  #include <thrust/host_vector.h>
                                 ^

1 catastrophic error detected in the compilation of "main.cpp".
Compilation terminated.

If I add the include path explicitly then nvc++ can find the header, but I then get this error:

$ nvc++ -I /opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/11.4/include main.cpp
"/opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/11.4/include/thrust/system/detail/generic/sort.inl", line 191: error: static assertion failed with "unimplemented for this system"
    THRUST_STATIC_ASSERT_MSG(
    ^
          detected during:
            instantiation of "void thrust::system::detail::generic::stable_sort(thrust::execution_policy<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::cuda_cub::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" at line 83 of "/opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/11.4/include/thrust/detail/sort.inl"
            instantiation of "void thrust::stable_sort(const thrust::detail::execution_policy_base<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::cuda_cub::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" at line 63
            instantiation of "void thrust::system::detail::generic::sort(thrust::execution_policy<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::cuda_cub::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" at line 56 of "/opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/11.4/include/thrust/detail/sort.inl"
            instantiation of "void thrust::sort(const thrust::detail::execution_policy_base<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::cuda_cub::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" at line 49
            instantiation of "void thrust::system::detail::generic::sort(thrust::execution_policy<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator) [with DerivedPolicy=thrust::cuda_cub::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>]" at line 41 of "/opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/11.4/include/thrust/detail/sort.inl"
            instantiation of "void thrust::sort(const thrust::detail::execution_policy_base<DerivedPolicy> &, RandomAccessIterator, RandomAccessIterator) [with DerivedPolicy=thrust::cuda_cub::tag, RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>]" at line 215 of "/opt/nvidia/hpc_sdk/Linux_x86_64/21.9/cuda/11.4/include/thrust/detail/sort.inl"
            instantiation of "void thrust::sort(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>]" at line 19 of "main.cpp"

1 error detected in the compilation of "main.cpp".

Are you sure that -x cu is not doing anything? As far as I can tell it is the only way to add all the necessary dependencies to compile the Thrust example with nvc++.