alpaka-group / vikunja

Vikunja is a performance portable algorithm library that defines functions operating on ranges of elements for a variety of purposes . It supports the execution on multi-core CPUs and various GPUs. Vikunja uses alpaka to implement platform-independent primitives such as reduce or transform.
https://vikunja.readthedocs.io/en/latest/
Mozilla Public License 2.0
14 stars 5 forks source link

ConstantIterator #62

Open AntonReinhard opened 2 years ago

AntonReinhard commented 2 years ago
SimeonEhrig commented 2 years ago

@bernhardmgruber Can you please review it.

SimeonEhrig commented 2 years ago

If the whole point of this iterator is to just return the same value whenever dereferences, I see no need to store an index. Then all iterator functions that move the iterator become noops. When do you need the index of the iterator?

You can probably make all member functions of ConstantIterator constexpr and noexcept.

The index is required for begin and end pointer:

ConstantIterator c_begin(10);
ConstantIterator c_end = c_begin + 4;

for(; c_begin < c_end; ++c_begin){
   std::cout << *c_begin << " "; // 10 10 10 10
}

Do you have a better idea?

bernhardmgruber commented 2 years ago

The index is required for begin and end pointer:

ConstantIterator c_begin(10);
ConstantIterator c_end = c_begin + 4;

for(; c_begin < c_end; ++c_begin){
   std::cout << *c_begin << " "; // 10 10 10 10
}

No, makes perfect sense now :D Without the index you would have an infinite range.

SimeonEhrig commented 2 years ago

@AntonReinhard Can you please rebase to the current master. I removed the C++ 14 support. New default is C++ 17.

AntonReinhard commented 2 years ago

Ah, I knew you had to include for the spaceship operator: https://godbolt.org/z/soa55sP73 Apparently gcc somehow handles it without, but clang needs it, because the return type of the defaulted operator<=> is the std::strong_ordered type, which is defined in

SimeonEhrig commented 2 years ago

Two points:

Can you execute your results on a local system or Taurus? If not, we have a Quadro V100 in our dev system. I can execute the benchmarks and send you the results.

SimeonEhrig commented 2 years ago

By the way, I was aware about the wrong results on the serial backend in the reduce benchmark. I think, it is a precession problem of float and the many summations on a single value. But I had no time yet to investigate this.