CUDA & C++ NVCC limit

I try to simplify my problem in order to let you get it easily for this reason i prefered working in small project with 4 files :

my_vector.cu : program which initialise host & device vectors and launch kernel_function.

my_vector_kernel.cu : program which declare a kernel function.

my_vector.h : header where i declare a simple class which use standard template library.

and finally my CMakeLists.txt.

Then for having a better idea about my project i will attach code source below.

The problem it s when i include my header file my compiler (nvcc) does not accept this declaration :

typename my_vector::iterator it_best_element()

{

typename my_vector<EOT>::iterator it = std::max_element(begin(), end());

return it;

}

it gives me this kind of error : “my_vector.h(22): error: nontype “my_vector::iterator” is not a type name” .

And it accepts this declaration :

typename vector::iterator it_best_element()

{

typename vector<EOT>::iterator it = max_element(begin(), end());

return it;

}

knowing that my class “my_vector” inherited from std::vector ( template class my_vector:public std::vector )!

Thanks to think to help me if you have any ideas !

my_vector.h:

#include

#include

#include

using namespace std;

template

class my_vector:public vector{

using vector::operator;

using vector::begin;

using vector::end;

using vector::resize;

using vector::size;

using vector::iterator;

my_vector(unsigned _size = 0, EOT _value = EOT())

:vector(_size, _value)

{}

/* My compilator nvcc don’t agree this declaration*/

typename my_vector::iterator it_best_element()

{

typename my_vector<EOT>::iterator it = std::max_element(begin(), end());

return it;

}

/* My compilator nvcc accept this use of my iterator */

/*

typename vector<EOT>::iterator it_best_element() 

{

typename vector<EOT>::iterator it = max_element(begin(), end());

return it;

}

*/

}

Are you sure this is an nvcc problem, not a c++ coding problem?

I am not an c++ expert and cannot help too much. My only suggestion is to comment out the cuda-related definition in your code, and compile it with a regular c++ compiler. If it compiles, then nvcc indeed has a bug. Otherwise, a c++ mailing list/forum might be a better place to ask for help.

Thanks Tan for your answer! so i just simplify the problem in this class example but normally the big project turn perfectly with this kind of declaration without any compilation errors (g++) and even for this class example the g++ accept that ! therefore i thought that is a nvcc problem!

Then the solution is to play with declaration to let a both nvcc & gcc compilers accept that :
my_vector.h:
#include
#include
#include
using namespace std;

template
class my_vector:public vector{

using vector::operator;
using vector::begin;
using vector::end;
using vector::resize;
using vector::size;
typedef typename vector::iterator iterator;

my_vector(unsigned _size = 0, EOT _value = EOT())
:vector(_size, _value)
{}

my_vector::iterator it_best_element()
{
my_vector::iterator it = std::max_element(begin(), end());
return it;
}
}

Thanks for your help.

Glad to know you fixed the problem.

If you haven’t done it, don’t forget to file a bug report to nvidia.

Glad to know you fixed the problem.

If you haven’t done it, don’t forget to file a bug report to nvidia.