need syntax explanation from smoke particles demo

I see this code in the smoke particles demo that comes with cuda, can someone explain the syntax to me?
struct integrate_functor
{
template
device
void operator()(Tuple t) //question 1
{
volatile float4 posData = thrust::get<2>(t); //question 2

}

Questions:

  1. this is defining an operator overload, right? How do you read this? Is it declaring the parens () as an operator that takes a Tuple t argument? What is the purpose of doing this?
  2. what does the <2> syntax mean? Is this standard c++ or is this a cuda extension?

If there’s a manual I should have read to get this from, please let me know.

thanks, rikm

These questions are straddling between C++ and thrust questions.

A tuple is a collection of objects or types that can be referred to as a single entity. Something like a struct.

A functor is a C++ function object:

[url]http://www.cprogramming.com/tutorial/functors-function-objects-in-c++.html[/url]

It is often defined using a struct or class definition. For the purposes of that particular struct, the void operator()… statement is indeed an operator overload of the unary operator () (although there is actually no base operator defined in this case.) A unary operator takes one argument, which in this case happens to be a tuple. The templated nature of this functor definition allows the compiler to generate a unique functor for each different kind of tuple for which the code makes sense.

Thrust uses tuples for a variety of purposes, most commonly associated with a zip iterator, which provides a convenient way to handle data in a AoS format while the underlying storage is actually SoA (and therefore better for CUDA data access.)

The thrust::get<?>() is a member function of the tuple class which retrieves the ?th element of the tuple. (it can also be used to set the ?th element of the tuple, somewhat non-intuitively for the usage of “get”)

The thrust quick start guide is a reasonable place to start:

[url]GitHub - NVIDIA/thrust: The C++ parallel algorithms library.

You’ll get a brief intro to functor definitions, how they’re used by thrust. After that, focus on zip iterator to learn about tuples and how they are used.

Again, these could all be abstracted down to a more basic C++ description, but the context here is clearly thrust, a C++ template library.

thanks txbob. Haven’t got to the thrust guide yet, but the functor link was really useful. appreciate the quick response.