I have trouble understanding counting_iterator
in thrust library for CUDA. What is its purpose and how is it used? Is it available in other programming languages such as C++ also?
相关问题
- Achieving the equivalent of a variable-length (loc
- The behavior of __CUDA_ARCH__ macro
- Setting Nsight to run with existing Makefile proje
- Usage of anonymous functions in arrayfun with GPU
- Does CUDA allow multiple applications on same gpu
相关文章
- How to downgrade to cuda 10.0 in arch linux?
- How can I unpack (destructure) elements from a vec
- Insert into vector with conditional iterator
- What's the relation between nvidia driver, cud
- Cloning iterators in Java
- How can I use 100% of VRAM on a secondary GPU from
- What is the equivalent of boost::make_transform_it
- How to copy an iterator to another one?
As a further example, which is a slight modification of @talonmies answer, you can emulate Matlab's
linspace
command by the following codeThe above code will return
exacltly as
linspace(3.87,7.11,20)
.A counting iterator is just an iterator which returns the next value from a sequence which is advanced each time the iterator is incremented. The simplest possible example is something like this:
which does this when compiled and run:
ie. the counting iterator was initialised with a value of one, and each time the iterator is incremented, we get the next value in the counting sequence, ie. 1,2,3,4,5....
Where counting increments come in handy in thrust is any time you need a sequence to fill a vector or manipulate in a transform iterator or functor. The counting iterator removes the need to explicitly create and fill a vector with the sequence you require. For example (from my answer to this Stack Overflow question):
which produces a device vector filled with the sequence 0, 0, 0, 1, 1, 1, 2, 2 ,2, 3, 3, 3.