Closed recke-a closed 1 year ago
Hey @recke-a. Luckily (or perhaps unluckily) I've run into this kind of problem numerous times and so I knew what to look for 🙂.
The problem is the const Iterator begin
member of your finite_sequence_repeat_iterator
.
When a class has a const data member, the compiler implicitly deletes the copy assignment operator: example. This has caused me so much headache in the past that I almost never use const data members in classes anymore.
Several Thrust algorithms use copy-assignment (many in places where they probably shouldn't), so when your iterator has a deleted copy assignment iterator, it will fail.
The good news is that the fix is easy. Your example compiles just fine if I remove the const
: https://godbolt.org/z/P84axYjTc
Dear jrhemstad,
many thanks for your helpful response. In fact, having a const member variable begin here actually does not make any sense. It is private and the only functions that access it are the constructor and the dereference function which is defined as a const function and cannot change member variables.
I will send that to the CUDA guys, too to close the thread.
Kind regards Andreas
Hi,
I started this thread in the CUDA forum https://forums.developer.nvidia.com/t/issues-when-compiling-code-using-thrust-iterator-adaptor-with-nvcc/252669/4 and I was asked by Robert Crovella to file it here.
I tried to use a customized iterator (slightly changed code from the iterator_adaptor example) and I happened to get stuck with a compiler error about a deleted function.
The problem appeared with different settings now, but the first time after I updated to CUDA 12.1 including Thrust. I tried to boil it down to a simple example:
I used
nvcc -arch=sm_52 --std=c++20 --extended-lambda --default-stream per-thread -c UnitTestRepeatIterator.cu -o UnitTestRepeatIterator
to compile the program.Which then led to the following error message:
Interestingly, when I use thrust::copy with this iterator, no error message appears. It seems that it has something to do with a missing or deleted copy assignment operator.
In fact, the only difference to the example code for thrust::iterator_adaptor is that the
return *(begin + (this->base() - begin) / n);
is nowreturn *(begin + (this->base() - begin) % n);
in line 38.Of course, I can find a workaround by using a mixture of transform_iterator and permutation_iterator to achieve the same effect, but iterator_adaptor is meant to work, too, which is the reason why I filed this issue.
I hope someone has an idea of how to solve this.
Kind regards Andreas