2017-02-06 4 views
2

Ich habe Cuda 8.0 auf meinem Rechner installiert (Linux SL7) auch, ich habe den Schub 1.8.1 heruntergeladen und ersetzen die vorhandene Schubbibliothek mit dem neuen 1.8.1.Schub in Cuda Kernel

Soweit ich weiß ab Schub 1,8 wird Schub unterstützt und kann in den Kernen verwendet werden. Ich zitiere aus ihrer Website:

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

jedoch, wenn ich die Anwendung mit dem Nsight Eclipse bauen, es zeigt mir diesen Fehler:

calling a __host__ function("thrust::sort") from a __global__ function("mykernel") is not allowed.

Bitte jede Beratung?

hier ist mein Code:

#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; 
} 
+0

Mögliche Duplikate von [Thrust in User geschrieben Kernel] (http://StackOverflow.com/Questions/5510715/Thrust-inside-User-Written-Kernels) – Soeren

Antwort

7

Sie richtig sind. Thrust 1.8 und neuer unterstützen Algorithmusaufrufe innerhalb des Gerätecodes. Um dies zu nutzen, müssen Sie jedoch die neue execution policies verwenden, damit die Bibliothek im Gerätecode ordnungsgemäß funktioniert.

Wenn Sie die Version von sort verwenden, die eine Ausführungspolitik wie folgt enthält:

__global__ void mykernel(int* a, int* b) 
{ 
    thrust::sort(thrust::device, a, a + 10); 
} 

sollten Sie den Code finden kompiliert korrekt.

+0

Danke, es funktioniert jetzt gut. –

Verwandte Themen