I'm learning CUDA, and in plenty of example code I see block and grid dimensions being set like this:
dim3 dimGrid(numBlocks);
dim3 dimBlock(numThreadsPerBlock);
exampleKernel<<<dimGrid, dimBlock>>>(input);
I understand that a line like dim3 dimGrid(numBlocks);
is initialising dimGrid, a variable of dim3 type, to have numBlocks
as its x value - but I'm not sure how this works.
I would have just assumed it was normal C++ syntax, but for C++ I thought that the line has to be written like this:
dim3 dimGrid = dim3(numBlocks);
Otherwise you get "the most vexing parse". So I'm assuming that the interpretation of those lines as a variable assignment is special behaviour by CUDA's NVCC compiler, but I can't find anything that confirms this.
Am I right that this is what is happening, or is there something else I don't understand about how this works?
This is normal C++ syntax, you can try it yourself with a minimal working example.
#include <iostream>
using namespace std;
class A {
int _x;
public:
A(int x) : _x(x) {}
int x() const { return _x; }
};
int main() {
A first(3);
cout << first.x() << endl; // "3"
return 0;
}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With