Link addr
One: Run the program
According to the previous article, after installing the Cuda software, you can use the "nvcc-v" command to view the compiler version used, I use the version information from: "Cuda compilation tools, Release 3.2, V0.2.1221."
Create a directory yourself, in which the new CU file, write code, save, you can use the terminal to switch to the corresponding directory to compile, compile the command: nvcc-o filename filename.c u, you can be a. cu file compiled into an executable file, if there is a syntax error, this will be the wrong, If not, other errors will be wrong in the run times, using the./filename to run the program, you can.
Two: Debugging procedures
If the program is wrong but did not see the results or related information, you may wish to add debugging information: Nvcc-o filename filename.cu-g, you can be added debugging information, then run with GDB: gdb./filename can enter the executable file, enter the command: R, You can run a program with debugging information, see the information about the error results, and then find the error, modify and recompile.
Three: Error Lookup
In the CUDA, there is a good error-checking function, I generally use two of them: Cut_check_error (), Cuda_safe_call (), the former can accept the most recent cudaerror_t exception, and the output of the corresponding error type, For example, to detect if a kernel function executes correctly, you can add: Cut_check_error ("Kernel execution failed") after executing the statement, and if the runtime fails, the error type is reported and output, while the latter directly outputs the error type. For example, if you want to know if a replication statement is successful, you can rewrite the statement to: Cuda_safe_call (cudamemcpy (d_data, data, size, cudamemcpyhosttodevice); The error type will be output directly.
The above function must include the header file cutil.h when used, add method see 4th.
Four: Add a path
How do I add a path? Use the "-I Path" parameter input, for example, if you want to add a header file that is cutil.h, include it in the. cu file, and view its properties to see its location as:/home/user/nvidia_gpu_computing_sdk/c/common/ Inc, then the compile time command can be written as: nvcc-i/home/user/nvidia_gpu_computing_sdk/c/common/inc-o filename Filename.cu so that the compiler finds the file and calls it, and the other paths are added like this.
V: Using Makefile programming
Create a makefile, and then enter the command:
Filename:filename.cu
Nvcc-o filename FILENAME.CU
In the terminal use command: Make filename, you can compile the build executable file, if there are multiple. cu files to compile, you can also write in the same makefile, change "filename" in "Make filename" can be compiled to build a different executable file.