CUDA编译和链接 [英] CUDA compilation and Linking
问题描述
我有主机编译器( g ++ ),设备文件(例如d_A.cu等)编译的主机文件(比如h_A.cpp等)由设备编译器编译( nvcc )和主机设备文件(例如主机函数,内核调用等)(例如h_d_A.cu) nvcc )。
I have host files (say h_A.cpp, etc) which can be compiled by host compiler (g++), device files (say d_A.cu, etc) to be compiled by device compiler (nvcc) and host-device files i.e., host functions, kernel call, etc (say h_d_A.cu) to be compiled by device compiler (nvcc).
设备端编译
nvcc -arch=sm_20 -dc d_A.cu -o d_A.o $(INCLUDES)
/ ,因为该文件可能调用/具有可重定位设备功能* /
/* -dc since the file may call / have relocatable device functions */
主机端编译
g++ -c h_A.cpp -o h_A.o $(INCLUDES, FLAGS)
设备链接建议此处
nvcc -arch=sm_20 -dlink d_A.o -o link.o
/ *链接由于可重定位设备函数* /
/* Linkage due to relocatable device functions */
我正在为项目使用Makefile。现在,我的查询是,我如何形成最终的可执行?
我试过了,
I am using Makefile for the project. Now, the query i have is, how do i form the final executable? I have tried,
1. g++ h_A.o link.o –L<path> -lcudart
Error: relocation 0 has invalid symbol index 10
2. g++ h_A.o link.o –lcudadevrt –L<path> –lcudart
Error: undefined reference to phase2(int*, int) //where phase2 is my __global__ kernel.
推荐答案
抱歉,找到我错过的对象,同时形成最终的可执行文件。
Sorry, Found out the problem i missed to include device objects while forming the final executable.
更正了语法。
g++ h_A.o d_A.o link.o –L<path> -lcudart
这篇关于CUDA编译和链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!