Skip to content
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

[BUG]: Compiler fails to generate default copy assignment operator for thrust::transform_iterator #3541

Closed
1 task done
zkhatami opened this issue Jan 27, 2025 · 1 comment · Fixed by #3542
Closed
1 task done
Assignees
Labels
bug Something isn't working right.

Comments

@zkhatami
Copy link

Is this a duplicate?

Type of Bug

Compile-time Error

Component

Thrust

Describe the bug

The NVC++ stdpar fails to generate a default copy assignment operator for thrust::transform_iterator if the function object it contains is not copyable. For example, for this test case:

#include <algorithm>
#include <execution>
#include <vector>

class A {
  public:
   double* begin() { return m_v.data(); }
   double* v_end() { return m_v.data() + m_v.size(); }
   
  private:
   std::vector<double> m_v ;
} ;

void test(A &A) {
  if (std::any_of(std::execution::par, A.begin(), A.v_end(),
                  [](double v) { return v < double(0.0); })) {
  }
}

The nvc++ stdpar fails with cannot be referenced -- it is a deleted function:

nvc++ -stdpar --c++17 test.cpp

thrust/system/cuda/detail/find.h", line 134: error: function "thrust::THRUST_300000_SM_70_NVHPC_NS::zip_iterator<IteratorTuple>::operator=(const thrust::THRUST_300000_SM_70_NVHPC_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_300000_SM_70_NVHPC_NS::transform_iterator<lambda [](double)->bool, double *, bool, bool>, thrust::THRUST_300000_SM_70_NVHPC_NS::counting_iterator<std::ptrdiff_t, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default>>> &) [with IteratorTuple=cuda::std::__4::tuple<thrust::THRUST_300000_SM_70_NVHPC_NS::transform_iterator<lambda [](double)->bool, double *, bool, bool>, thrust::THRUST_300000_SM_70_NVHPC_NS::counting_iterator<std::ptrdiff_t, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default>>]" (declared implicitly) cannot be referenced -- it is a deleted function
        interval_end = end;
                     ^

This issue arises because lambdas in C++17 have a deleted copy assignment operator, causing the thrust::transform_iterator to become non-copy assignable.
From https://timsong-cpp.github.io/cppwp/n4659/expr.prim.lambda#closure-11:
The closure type associated with a lambda-expression has no default constructor and a deleted copy assignment operator.

This test has started failing after this CCCL commit that replaces the custom copy assignment operator for thrust::transform_iterator with = default:
8da3ace

How to Reproduce

To compile the test with:

nvc++ -stdpar --c++17 test.cpp

Expected behavior

The NVC++ stdpar fails with:

thrust/system/cuda/detail/find.h", line 134: error: function "thrust::THRUST_300000_SM_70_NVHPC_NS::zip_iterator<IteratorTuple>::operator=(const thrust::THRUST_300000_SM_70_NVHPC_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_300000_SM_70_NVHPC_NS::transform_iterator<lambda [](double)->bool, double *, bool, bool>, thrust::THRUST_300000_SM_70_NVHPC_NS::counting_iterator<std::ptrdiff_t, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default>>> &) [with IteratorTuple=cuda::std::__4::tuple<thrust::THRUST_300000_SM_70_NVHPC_NS::transform_iterator<lambda [](double)->bool, double *, bool, bool>, thrust::THRUST_300000_SM_70_NVHPC_NS::counting_iterator<std::ptrdiff_t, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default, thrust::THRUST_300000_SM_70_NVHPC_NS::use_default>>]" (declared implicitly) cannot be referenced -- it is a deleted function
        interval_end = end;
                     ^

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@zkhatami zkhatami added the bug Something isn't working right. label Jan 27, 2025
@github-project-automation github-project-automation bot moved this to Todo in CCCL Jan 27, 2025
bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Jan 27, 2025
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Jan 27, 2025
@bernhardmgruber
Copy link
Contributor

This for reporting this! We have a fix on this PR #3503. I pulled it out for you: #3542

bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Jan 28, 2025
bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Jan 28, 2025
@miscco miscco closed this as completed in 4567491 Jan 28, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Jan 28, 2025
@bernhardmgruber bernhardmgruber self-assigned this Jan 29, 2025
davebayer pushed a commit to davebayer/cccl that referenced this issue Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants