The following complete example causes an "invalid argument" exception due to the sort function if I have the "Generate relocatable device code" flag set to true (using Visual Studio 2013 & Cuda 7.5), but works just fine when it is false.
This is a problem for me in a bigger project with classes where I need this flag to be true.
Am I making a mistake somewhere?
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "thrust\sort.h"
#include "thrust\device_ptr.h"
#define cudaCheck(x) { cudaError_t err = x; if (err != cudaSuccess) { printf("Cuda error: %s in %s at %s:%d\n", cudaGetErrorString(err), #x, __FILE__, __LINE__); assert(0); } }
int main() {
const int N = 6;
int keys2[N] = { 1, 4, 2, 8, 5, 7 };
char values[N] = { 'a', 'b', 'c', 'd', 'e', 'f' };
int* dkeys;
cudaCheck(cudaMalloc((void**)&dkeys, sizeof(int) * N));
char* dvalues;
cudaCheck(cudaMalloc((void**)&dvalues, sizeof(char) * N));
cudaCheck(cudaMemcpy(dkeys, keys2, sizeof(int) * N, cudaMemcpyHostToDevice));
cudaCheck(cudaMemcpy(dvalues, values, sizeof(char) * N, cudaMemcpyHostToDevice));
thrust::device_ptr<int> tkeys(dkeys);
thrust::device_ptr<char> tvalues(dvalues);
thrust::sort_by_key(tkeys, tkeys + N, tvalues);
cudaCheck(cudaDeviceSynchronize());
return 0;
}