У меня есть cuda 8.0, установленный на моей машине (Linux SL7), также я загрузил тягу 1.8.1 и заменил существующую платформу тяги новым 1.8.1.thrust in cuda kernel
Насколько я знаю, начиная с тяги 1,8 тяга поддерживается и может использоваться в ядрах. Я цитирую с их сайта:
Thrust 1.8.0 introduces support for algorithm invocation from CUDA __device__ code, support for CUDA streams, and algorithm performance improvements. Users may now invoke Thrust algorithms from CUDA __device__ code
однако, когда я построить приложение, использующее затмение Nsight, он показывает мне эту ошибку:
calling a __host__ function("thrust::sort") from a __global__ function("mykernel") is not allowed.
Пожалуйста, любой посоветуете?
вот мой код:
#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <stdio.h>
#include <cuda_runtime.h>
#include <cuda.h>
#include <thrust/sort.h>
#include <thrust/execution_policy.h>
__global__ void mykernel(int* a, int* b)
{
thrust::sort(a, a + 10);
}
int main(void)
{
int a[10] = { 0, 9, 7, 3, 1, 6, 4, 5, 2, 8 };
int b[10];
int *d_a, *d_c;
cudaMalloc((void**)&d_a, 10 * sizeof(int));
cudaMalloc((void**)&d_c, 10 * sizeof(int));
std::cout << "A\n";
for (int i = 0; i < 10; ++i) {
std::cout << a[i] << " ";
}
cudaMemcpy(d_a, a, 10 * sizeof(int), cudaMemcpyHostToDevice);
mykernel<<<1, 1> > >(d_a, d_c);
cudaMemcpy(a, d_c, 10 * sizeof(int), cudaMemcpyDeviceToHost);
std::cout << "\nA\n";
for (int i = 0; i < 10; ++i) {
std::cout << a[i] << " ";
}
cudaFree(d_a);
cudaFree(d_c);
return 0;
}
Возможный дубликат [Thrust внутри написанных пользователем ядер] (http://stackoverflow.com/questions/5510715/thrust-inside-user-written-kernels) – Soeren