Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CUDA和C++;具有文件夹结构-通用makefile_C++_Cuda_Makefile_Generic Programming - Fatal编程技术网

C++ CUDA和C++;具有文件夹结构-通用makefile

C++ CUDA和C++;具有文件夹结构-通用makefile,c++,cuda,makefile,generic-programming,C++,Cuda,Makefile,Generic Programming,我想写一个通用的makefile来编译和链接我的所有模块 文件夹结构: \include ----+Common.h ----+Graph.h ----+GraphColoringCPU.h ----+GraphColoringGPU.cuh ----+LogCreate.h \obj <- initially empty, all .o files ---- ... \src ----+Common.cu ----+Graph.cpp ----+GraphColoringCPU.cpp

我想写一个通用的makefile来编译和链接我的所有模块

文件夹结构:

\include
----+Common.h
----+Graph.h
----+GraphColoringCPU.h
----+GraphColoringGPU.cuh
----+LogCreate.h
\obj <- initially empty, all .o files
---- ...
\src
----+Common.cu
----+Graph.cpp
----+GraphColoringCPU.cpp
----+GraphColoringGPU.cu
----+LogCreate.cpp
----+main.cu
+Makefile
+main <- target, missing before 'make'
实际生成文件生成输出:

nvcc -ccbin /usr/bin -dlink -I. -I/usr/local/cuda/include -gencode arch=compute_20,code=sm_20 --compiler-options -Wall -G -lcublas_device -lcudadevrt -lcublas -lcudart obj/Common.ch.o obj/GraphColoringGPU.cuh.o obj/kernel.cu.o  -o obj/link.o
nvlink fatal   : Could not open input file 'obj/Common.ch.o'
make: *** [obj/link.o] Error 255
我知道它试图在没有正确顺序的情况下编译,但我不知道如何更改它

正确顺序规则:

1) Compile all '.cu' files using 'nvcc -dc' and places suitable '.o' files into \obj folder 
2) Link all '.o' files (where sources are .cu files) using 'nvcc -dlink' into 'link.o' file (and place it into \obj folder) 
3) Compile all '.cpp' files using 'g++ -c' and places suitable '.o' files into \obj folder 
4) Links all '.o' files into target 'main' (and place it in main folder)

谢谢你的建议。

我知道我已经非常接近写正确的make了。我试过命令“makemain”它。。。成功了(需要一些小的改变)

下面是正在工作的Makefile(省略了未更改的代码):

#选项
OBJS_CU=$(OBJ)/Common.ch.o$(OBJ)/GraphColoringGPU.cuh.o$(OBJ)/main.CU.o
OBJS=$(OBJ)/Graph.cpp.o$(OBJ)/LogCreate.cpp.o$(OBJ)/GraphColoringCPU.cpp.o$(OBJ)/link.o
目标=主要
LINKLINE=$(LINK)-o$(TARGET)$(OBJS\u-CU)$(OBJS)$(LIB\u-CUDA)
.后缀:.c.cpp.h.cu.cuh.o
$(OBJ)/%.cuh.o:$(SRC)/%.cu$(INC)/%.cuh
$(NVCC)$(NVCCFLAGS)-dc$<-o$@
$(OBJ)/%.ch.o:$(SRC)/%.cu$(INC)/%.h
$(NVCC)$(NVCCFLAGS)-dc$<-o$@
$(OBJ)/%.cu.o:$(SRC)/%.cu
$(NVCC)$(NVCCFLAGS)-dc$<-o$@
$(OBJ)/link.o:
$(NVCC)$(NVCCFLAGS)-dlink$(OBJS_CU)-o$@
$(OBJ)/%.cpp.o:$(SRC)/%.cpp$(INC)/%.h
$(CXX)$(CXXFLAGS)-c$<-o$@
$(目标):$(OBJS_CU)$(OBJS)Makefile
$(链接行)

另外,如果$(TARGET)的规则是第一条规则,那么简单的“make”就足以正常工作。

您愿意使用CMake吗?它有非常好的CUDA支持。我从来没有听说过它,但也许我可以使用它,除非它必须安装。我正在使用我学生的服务器,因此我没有太多访问权限和写入权限。如果已经安装了cmake(服务器上安装了Ubuntu12.04),我可以使用它。请添加您的解决方案作为答案,而不是对您的问题进行编辑[这完全可以]。稍后您可以接受您的答案,这将使问题从未回答列表中删除谢谢您发布的答案没有问题,我希望它可以帮助其他人:)
nvcc -ccbin /usr/bin -dlink -I. -I/usr/local/cuda/include -gencode arch=compute_20,code=sm_20 --compiler-options -Wall -G -lcublas_device -lcudadevrt -lcublas -lcudart obj/Common.ch.o obj/GraphColoringGPU.cuh.o obj/kernel.cu.o  -o obj/link.o
nvlink fatal   : Could not open input file 'obj/Common.ch.o'
make: *** [obj/link.o] Error 255
1) Compile all '.cu' files using 'nvcc -dc' and places suitable '.o' files into \obj folder 
2) Link all '.o' files (where sources are .cu files) using 'nvcc -dlink' into 'link.o' file (and place it into \obj folder) 
3) Compile all '.cpp' files using 'g++ -c' and places suitable '.o' files into \obj folder 
4) Links all '.o' files into target 'main' (and place it in main folder)
# Options
OBJS_CU = $(OBJ)/Common.ch.o $(OBJ)/GraphColoringGPU.cuh.o $(OBJ)/main.cu.o 
OBJS = $(OBJ)/Graph.cpp.o $(OBJ)/LogCreate.cpp.o $(OBJ)/GraphColoringCPU.cpp.o $(OBJ)/link.o 
TARGET = main
LINKLINE = $(LINK) -o $(TARGET) $(OBJS_CU) $(OBJS) $(LIB_CUDA)

.SUFFIXES: .c .cpp .h .cu .cuh .o

$(OBJ)/%.cuh.o: $(SRC)/%.cu $(INC)/%.cuh
    $(NVCC) $(NVCCFLAGS) -dc $< -o $@

$(OBJ)/%.ch.o: $(SRC)/%.cu $(INC)/%.h
    $(NVCC) $(NVCCFLAGS) -dc $< -o $@

$(OBJ)/%.cu.o: $(SRC)/%.cu
    $(NVCC) $(NVCCFLAGS) -dc $< -o $@

$(OBJ)/link.o:
    $(NVCC) $(NVCCFLAGS) -dlink $(OBJS_CU) -o $@    

$(OBJ)/%.cpp.o: $(SRC)/%.cpp $(INC)/%.h
    $(CXX) $(CXXFLAGS) -c $< -o $@

$(TARGET): $(OBJS_CU) $(OBJS) Makefile
    $(LINKLINE)