I’m getting some very odd warnings using thrust::sort… This code compiles fine:
thrust::device_vector<int> indices(count);
thrust::sort(indices.begin(), indices.end(), thrust::greater<int>());
Now, if I go to header file where thrust::greater is defined, copy it into my code and rename the template class to “MySorter”, eg.
template<typename T>
struct Sorter
{
...
and then try
thrust::sort(indices.begin(), indices.end(), Sorter<int>());
I get pages and page of compiler warnings about converting signed to unsigned 64-bit ints:
warning C4244: 'argument' : conversion from '__int64' to 'const size_t', possible loss of data
Am I missing something? Is there some compiler magic which allows the SDK version to compile warning-free? Compiling under Visual Studio 2012, Cuda 6.5.
can you provide a simple, complete example? Which file did you pull the thrust::greater definition out of?
The file is thrust/functional.h, line 557. Here’s a standalone sample:
#include <stdio.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/copy.h>
#include <thrust/fill.h>
#include <thrust/sequence.h>
#include <thrust/sort.h>
template<typename T>
struct Sorter
{
/*! \typedef first_argument_type
* \brief The type of the function object's first argument.
*/
typedef T first_argument_type;
/*! \typedef second_argument_type
* \brief The type of the function object's second argument.
*/
typedef T second_argument_type;
/*! \typedef result_type
* \brief The type of the function object's result;
*/
typedef bool result_type;
/*! Function call operator. The return value is <tt>lhs > rhs</tt>.
*/
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs > rhs;}
}; // end greater
int main()
{
#if 1
// i get warnings
const int count = 100;
thrust::device_vector<int> indices(count);
thrust::sort(indices.begin(), indices.end(), Sorter<int>());
#else
// i am warning free
const int count = 100;
thrust::device_vector<int> indices(count);
thrust::sort(indices.begin(), indices.end(), thrust::greater<int>());
#endif
return 0;
}
I was able to see the issue with cuda 6.5 and VS2013 (also). I was not able to reproduce it with CUDA 5.0/VS2010. I was not able to reproduce the issue on linux. I can’t explain it.
You might get more direct assistance by asking about it on the thrust users group mailing list:
[url]Redirecting to Google Groups