details:
OS: Ubuntu 22.04LTS
CudaToolKit:12.9
Cards : Nvidia Titan Xp (4 cards)
CUDA Capability: 6.1
Trying to run the following simple code to demonstrate use of Thrust library. But getting error. Not able to understand what exactly is the issue here.
Code:
#include<thrust/host_vector.h>
#include <thrust/device_vector.h>
#include<thrust/generate.h>
#include <thrust/copy.h>
#include <cstdlib>
#include <cstdio>
#include <ctime>
int main(void) {
//size of the vectors
size_t inputLength = 5000000;
//declare two host_vector of float kind on CPU for storing input vector, and one for output vector
thrust::host_vector<float> hostInput1(inputLength);
thrust::host_vector<float> hostInput2(inputLength);
thrust::host_vector<float> hostOutput(inputLength);
//declare three device_vector of float kind on GPU,
// two input vectors mapped onto respective host_vectors and one output vector.
thrust::device_vector<float> deviceInput1(inputLength);
thrust::device_vector<float> deviceInput2(inputLength);
thrust::device_vector<float> deviceOutput(inputLength);
//Populate host input vectors using random number generator.
thrust::generate(hostInput1.begin(),hostInput1.end(),rand);
thrust::generate(hostInput2.begin(),hostInput2.end(),rand);
//Start timer to check how much time it takes to copy vectors, do the computation
// and copy the output back
clock_t starttime=clock();
// Copy host_vectors to device_vectors
thrust::copy(hostInput1.begin(), hostInput1.end(), deviceInput1.begin());
thrust::copy(hostInput2.begin(), hostInput2.end(), deviceInput2.begin());
//Add two vectors and get resulting vector.
thrust::transform(deviceInput1.begin(), deviceInput1.end(),
deviceInput2.begin(), deviceOutput.begin(),
thrust::plus<float>());
//Copy the computed result back to host.
thrust::copy(deviceOutput.begin(), deviceOutput.end(), hostOutput.begin());
//Stop the timer and compute the time.
clock_t stoptime=clock();
printf(" total: %lf s/n", (double)(stoptime-starttime)/CLOCKS_PER_SEC);
return 0;
}