CUDA COMPILER DRIVER NVCC संदर्भ मार्गदर्शिका, खंड 3.2.8 का उद्धरण। "सामान्य उपकरण विकल्प":
परियोजना -> गुण -> विन्यास गुण -> CUDA C/C++ -> कमांड लाइन -> अतिरिक्त प्रकाशिकी -> जोड़ने -:
--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.
इसलिए, निम्न कार्य करें Werror पार निष्पादन-अंतरिक्ष फोन
इस परीक्षा कार्यक्रम
#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) { }
रिटर्न निम्न चेतावनी
warning : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed
ऊपर उल्लेख अतिरिक्त संकलन विकल्प के बिना और निम्नलिखित त्रुटि देता है
Error 3 error : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed
साथ ऊपर अतिरिक्त संकलन विकल्प उल्लेख
।
यह डिज़ाइन द्वारा कोई त्रुटि क्यों नहीं है? मैंने बस सफलतापूर्वक एनवीसीसी को संकलित किया (केवल आपके द्वारा वर्णित चेतावनी के साथ): '__host__ int c() {वापसी 0; } __host__ __device__ void b() {int a = c();} __global__ शून्य() {b();} /*...*/ <<<1, 1 > >>(); 'और रेखा' ए = सी(); '0 से पढ़ा गया है: 'mov.u32% r1, 0; ld.volatile.u32% आर 2, [% आर 1]; 'जो * कभी * काम नहीं कर सकता और निश्चित रूप से मेरा इरादा नहीं था। संकलक इस के साथ क्यों आगे बढ़ना चाहिए? – masterxilo