I am trying to build and run the Thrust example code in Visual Studio 2010 with the latest version (7.0) of CUDA and the THURST install that comes with it. I cannot get the example code to build and run.
By eliminating parts of the code, I found the problem to be with the thrust::sort(..) call. Host vectors work great, but device vectors produce the following compile error:
1>c:\program files\nvidia gpu computing toolkit\cuda\v7.0\include\thrust\system\cuda\detail\sort.inl(203): error C2027: use of undefined type 'thrust::detail::STATIC_ASSERTION_FAILURE'
This is the example code I'm using that won't compile which is largely out of the CUDA trust example at https://developer.nvidia.com/Thrust
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <algorithm>
#include <cstdlib>
#include <time.h>
int main(void)
{
// generate 32M random numbers serially
thrust::host_vector<int> h_vec(32 << 20);
std::generate(h_vec.begin(), h_vec.end(), rand);
// transfer data to the device
thrust::device_vector<int> d_vec = h_vec;
// sort data on the device (This breaks the compile)
thrust::sort(d_vec.begin(), d_vec.end());
// sort data on the host (This works just fine)
thrust::sort(h_vec.begin(), d_vec.end());
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
return 0;
}
Playing around I found that if you comment out the line that uses the device vector:
// thrust::sort(d_vec.begin(), d_vec.end());
but leave the line that uses the host vector:
thrust::sort(h_vec.begin(), d_vec.end());
it compiles and runs just fine, though the sort seems to be running on the host.
How do I get the example code to compile and run so the sort will take place on the device vector and not the host vector?
My system configuration includes:
- Visual Studio 2010 / SP1 installed
- Windows 7 pro, 64bit
- CUDA 7.0 Development kit
- NVIDA Quadro K4000 with recent drivers
.cu
and compile withnvcc
. – Jared Hoberockthrust::sort(h_vec.begin(), d_vec.end());
, probably simplest just to delete it, as it's not doing anything useful for the given program. If you want to retain it, change thed_vec.end()
toh_vec.end()
. – Robert Crovella