在cuda中用pinned内存+asyn,可以既缩短数据传输时间,又可以让cpu执行和gpu overlap
#include <thrust/host_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <thrust/device_vector.h>
#include <cstdlib>
#include <iostream>
#include <sys/time.h>
#include <algorithm>
// CUDA runtime
#include <cuda_runtime.h>
// includes
#include <helper_functions.h> // helper for shared functions common to CUDA SDK samples
#include <helper_cuda.h> // helper functions for CUDA error checking and initialization
using namespace std;
#define NUM_ELEM (1024*1024*4)
double getNow(){
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec*1000000 + t.tv_usec;
}
void cpu_sort(thrust::host_vector<int> host_array){
vector<int> array(NUM_ELEM);
for(