Citando la guida di riferimento del CCDA COMPILER DRIVER NVCC, Sezione 3.2.8. "Opzioni strumento generico":
--Werror kind
Make warnings of the specified kinds into errors. The following is the list of warning kinds accepted by this option:
cross-execution-space-call
Be more strict about unsupported cross execution space calls. The compiler will generate an error instead of a warning for a call from a __host__ __device__
to a __host__
function.
Pertanto, effettuare le seguenti operazioni:
Progetto -> Proprietà -> Proprietà di configurazione -> CUDA C/C++ -> Command Line -> Ottica aggiuntivi -> aggiungi - Werror cross-esecuzione-spazio-chiamare
Questo programma di test
#include <cuda.h>
#include <cuda_runtime.h>
void foo() { int a = 2;}
__host__ __device__ void test() {
int tId = 1;
foo();
}
int main(int argc, char **argv) { }
restituisce il seguente avviso
warning : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed
senza l'opzione sopra menzionato compilazione aggiuntiva e restituisce il seguente errore
Error 3 error : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed
con la suddetta opzione di compilazione aggiuntiva.
Perché non si tratta di un errore di progettazione? Ho appena provato nvcc a compilarlo correttamente (con solo l'avvertenza che hai menzionato): '__host__ int c() {return 0; } __host__ __device__ void b() {int a = c();} __global__ void a() {b();} /*...*/ a <<<1, 1 > >>(); 'e la riga' a = c(); 'è trasformato in una lettura da 0:' mov.u32% r1, 0; ld.volatile.u32% r2, [% r1]; "che non può * mai * funzionare e certamente non è quello che intendevo. Perché il compilatore dovrebbe procedere con questo? – masterxilo