Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
CUDA和C的生成文件_C_Cuda_Makefile_Nvcc - Fatal编程技术网

CUDA和C的生成文件

CUDA和C的生成文件,c,cuda,makefile,nvcc,C,Cuda,Makefile,Nvcc,我正在从事一个使用.c和.cu文件的项目。最初的包完全是用C编写的,并且有自己的Makefile(它工作得非常好)。我将.cu文件添加到项目中,现在我想修改Makefile,以便它将所有内容都编译在一起 以下是我的尝试: CC = nvcc SOURCEDIR = ../sourcedir EXE = it #C_SOURCES = $(wildcard $(SOURCEDIR)/*.c) #CU_SOURCES = $(wildcard $(SOURCEDIR)/*.cu) SOU

我正在从事一个使用.c和.cu文件的项目。最初的包完全是用C编写的,并且有自己的Makefile(它工作得非常好)。我将.cu文件添加到项目中,现在我想修改Makefile,以便它将所有内容都编译在一起

以下是我的尝试:

CC = nvcc

SOURCEDIR = ../sourcedir

EXE   = it

#C_SOURCES = $(wildcard $(SOURCEDIR)/*.c)
#CU_SOURCES = $(wildcard $(SOURCEDIR)/*.cu)

SOURCES  = $(SOURCEDIR)/it.c \
           $(SOURCEDIR)/em.c \
           $(SOURCEDIR)/art.c \
           $(SOURCEDIR)/cg.c \
           $(SOURCEDIR)/amatrix.c \
           $(SOURCEDIR)/itreadargs.c \
           $(SOURCEDIR)/sparse.c \
           $(SOURCEDIR)/misc.c \
           $(SOURCEDIR)/eval.c \
           $(SOURCEDIR)/imgtools.c \
           $(SOURCEDIR)/calc.c \
           $(SOURCEDIR)/egif_lib.c \
           $(SOURCEDIR)/dgif_lib.c \
           $(SOURCEDIR)/gif_err.c \
           $(SOURCEDIR)/gif_hash.c
        
CU_SOURCES = $(SOURCEDIR)/cg_cuda.cu

H_FILES = $(wildcard $(IDIR)/*.h)

IDIR      = -I../include

OBJS        = $(SOURCES:.c=.o)
CU_OBJS = $(CU_SOURCES:.cu=.o)

CFLAGS     = -O3 
#-finline-functions -Winline -Wall -falign-loops=2 -falign-jumps=2 -falign-functions=2 -Wstrict-prototypes

NVCCFLAGS  = -arch=sm_20

#CFLAGS      = -g -Wstrict-prototypes -Winline -Wall

LFLAGS      = -lm


$(EXE) : $(OBJS) $(CU_OBJS) 
    $(CC) $(CFLAGS) $(NVCCFLAGS) -o $@ $?

$(SOURCEDIR)/%.o : $(SOURCEDIR)/%.c $(H_FILES)
    $(CC) $(CFLAGS) $(IDIR) -c -o $@ $<

$(SOURCEDIR)/%.o : $(SOURCEDIR)/%.cu $(H_FILES)
    $(CC) $(NVCCFLAGS) $(IDIR) -c -o $@ $<


clean:
    rm -f $(OBJS) $(EXE)

感谢您耐心阅读我的帖子。

好吧,这将需要几次迭代。尝试此操作并对结果进行评论:

CC = nvcc

SOURCEDIR = ../sourcedir

EXE   = it

SOURCES  = $(SOURCEDIR)/it.c \
           $(SOURCEDIR)/em.c \
           $(SOURCEDIR)/art.c \
           $(SOURCEDIR)/cg.c \
           $(SOURCEDIR)/amatrix.c \
           $(SOURCEDIR)/itreadargs.c \
           $(SOURCEDIR)/sparse.c \
           $(SOURCEDIR)/misc.c \
           $(SOURCEDIR)/eval.c \
           $(SOURCEDIR)/imgtools.c \
           $(SOURCEDIR)/calc.c \
           $(SOURCEDIR)/egif_lib.c \
           $(SOURCEDIR)/dgif_lib.c \
           $(SOURCEDIR)/gif_err.c \
           $(SOURCEDIR)/gif_hash.c

IDIR      = -I../include

OBJS        = $(SOURCES:.c=.o)

CFLAGS     = -O3

NVCCFLAGS  = -arch=sm_20

LFLAGS      = -lm

$(EXE) : $(OBJS) $(SOURCEDIR)/cg_cuda.o
    $(CC) $(CFLAGS) -o $@ $^ $(LFLAGS)

$(SOURCEDIR)/%.o : $(SOURCEDIR)/%.c
    $(CC) $(NVCCFLAGS) $(IDIR) -c -o $@ $<

$(SOURCEDIR)/%.o : $(SOURCEDIR)/%.cu $(H_FILES)
    $(CC) $(NVCCFLAGS) $(IDIR) -c -o $@ $<

clean:
    rm -f $(OBJS) $(EXE)
CC=nvcc
SOURCEDIR=../SOURCEDIR
EXE=it
SOURCES=$(SOURCEDIR)/it.c\
$(SOURCEDIR)/em.c\
$(SOURCEDIR)/第c条\
$(SOURCEDIR)/cg.c\
$(SOURCEDIR)/amatrix.c\
$(SOURCEDIR)/itreadargs.c\
$(SOURCEDIR)/sparse.c\
$(SOURCEDIR)/misc.c\
$(SOURCEDIR)/eval.c\
$(SOURCEDIR)/imgtools.c\
$(SOURCEDIR)/calc.c\
$(SOURCEDIR)/egif_lib.c\
$(SOURCEDIR)/dgif_lib.c\
$(SOURCEDIR)/gif\u err.c\
$(SOURCEDIR)/gif\u hash.c
IDIR=-I../include
OBJS=$(来源:.c=.o)
CFLAGS=-O3
NVCCFLAGS=-arch=sm_20
LFLAGS=-lm
$(EXE):$(OBJS)$(SOURCEDIR)/cg_cuda.o
$(CC)$(CFLAGS)-o$@$^$(LFLAGS)
$(SOURCEDIR)/%.o:$(SOURCEDIR)/%.c
$(CC)$(NVCCFLAGS)$(IDIR)-c-o$@$<
$(SOURCEDIR)/%.o:$(SOURCEDIR)/%.cu$(H_文件)
$(CC)$(NVCCFLAGS)$(IDIR)-c-o$@$<
清洁:
rm-f$(OBJS)$(EXE)
编辑:第二轮
我已经修改了makefile。尝试
makeclean;制作
,并记录结果。然后尝试
make../sourcedir/cg_cuda.o

编辑:第三轮

好的,再试一次:
makeclean;确保

在引入
.cu
文件之前,您确定该操作有效吗?无论如何,我建议您尝试将
$?
更改为
$^
;我也可以发布原始的Makefile。。。也许这会有助于我需要添加的内容,以便.cu文件也可以编译。您没有为我们提供足够的信息(例如错误消息)来确定确切的问题,但您在这两个makefile之间做了许多小更改。尝试二进制搜索:编写一个只包含这些更改的一半的makefile,看看它是否有效。如果您发现有一个更改产生了差异,但仍然没有意义,请让我们知道。下面是错误的一部分(对于每个定义的函数,我得到了许多类似的行):所有.cu文件必须在同一个编译单元中编译。make:警告:文件
Makefile'在未来有3e+02秒的修改时间nvcc-O3-o it../sourcedir/it.o../sourcedir/em.o../sourcedir/cg.o../sourcedir/amatrix.o../sourcedir/itreadargs.o../sourcedir/sparse.o../sourcedir/misc.o../sourcedir/eval.o../sourcedir/imgtools.o../sourcedir/calc.o../sourcedir/egif_lib.o../sourcedir/dgif_lib.o../sourcedir/gif_err.o../sourcedir/gif_hash.o-lm../sourcedir/it.o:在函数
main中:it.c:(.text+0x188):对“CG_CUDA”集合的未定义引用2:ld返回1个退出状态make:**[it]错误1我第一次运行make时生成了一系列警告,但第二次我只在上面发布了错误。我意识到这并不能直接回答您的问题,但我发现使用cmake对于cuda项目来说要容易得多。我指定cmake列表文件,然后让cmake为我生成生成文件。如果有兴趣,我可以给你一个简单的例子项目如何工作。很抱歉回复这么晚,但我有问题的机器运行CUDA,无法尝试你的建议。谢谢你的耐心!用于清洁;make:make:Warning:File
Makefile'在未来的修改时间为3.9e+02秒nvcc-O3-o it../sourcedir/it.o../sourcedir/em.o../sourcedir/art.o../sourcedir/cg.o../sourcedir/itreadargs.o../sourcedir/sparse.o../sourcedir/misc.o../sourcedir/eval.o../sourcedir/imgtools.o../sourcedir/calc.o../sourcedir/calc.o../sourcedir/egif_lib.o../sourcedir/dgif_lib.o../sourcedir/gif_err.o../sourcedir/gif_hash.o-lm../sourcedir/it.o:In function
main::it.c:(.text+0x5b9):对“CG_CUDA”集合的未定义引用2:ld返回1退出状态make:**[it]错误1
CC := gcc

SOURCEDIR := ../sourcedir

EXE   := it

SOURCES  := $(SOURCEDIR)/it.c \
           $(SOURCEDIR)/em.c \
           $(SOURCEDIR)/art.c \
           $(SOURCEDIR)/cg.c \
           $(SOURCEDIR)/amatrix.c \
           $(SOURCEDIR)/itreadargs.c \
           $(SOURCEDIR)/sparse.c \
           $(SOURCEDIR)/misc.c \
           $(SOURCEDIR)/eval.c \
           $(SOURCEDIR)/imgtools.c \
           $(SOURCEDIR)/calc.c \
           $(SOURCEDIR)/egif_lib.c \
           $(SOURCEDIR)/dgif_lib.c \
           $(SOURCEDIR)/gif_err.c \
           $(SOURCEDIR)/gif_hash.c
        
CU_SOURCES := $(SOURCEDIR)/cg_cuda.cu

IDIR      := ../include

INCLUDES := -I../include

H_FILES := $(IDIR)/analyze.h \
           $(IDIR)/calc.h \
           $(IDIR)/eval.h \
           $(IDIR)/gif_hash.h \
           $(IDIR)/gif_lib.h \
           $(IDIR)/imgtools.h \
           $(IDIR)/iradon.h \
           $(IDIR)/iradoninc.h \
           $(IDIR)/it.h \
           $(IDIR)/itini.h \
           $(IDIR)/misc.h \
           $(IDIR)/sparse.h         

CFLAGS := -g -O3

NVCCFLAGS  := -g -G -O3 -arch=sm_20

LDFLAGS     := -lGL -lGLU -lglut -lpthread -lcuda

HOST_OBJ := $(SOURCES:.c=.c.o)
DEVICE_OBJ := $(CU_SOURCES:.cu=.cu.o)

%.c.o : %.c $(HFILES)
    $(CC) -c $(INCLUDES) $(CFLAGS) $< -o $@

%.cu.o : %.cu $(H_FILES)
    nvcc -c $(INCLUDES) $(NVFLAGS) $< -o $@ 


$(EXE): $(HOST_OBJ) $(DEVICE_OBJ)
    nvcc $(NVFLAGS) $(LDFLAGS) $(INCLUDES) -o $@ $^

clean:
    rm -f $(OBJS) $(EXE)
nvcc  -lGL -lGLU -lglut -lpthread -lcuda -I../include -o it ../sourcedir/it.c.o ../sourcedir/em.c.o ../sourcedir/art.c.o ../sourcedir/cg.c.o ../sourcedir/amatrix.c.o ../sourcedir/itreadargs.c.o ../sourcedir/sparse.c.o ../sourcedir/misc.c.o ../sourcedir/eval.c.o ../sourcedir/imgtools.c.o ../sourcedir/calc.c.o ../sourcedir/egif_lib.c.o ../sourcedir/dgif_lib.c.o ../sourcedir/gif_err.c.o ../sourcedir/gif_hash.c.o ../sourcedir/cg_cuda.cu.o
../sourcedir/it.c.o: In function `main':
/home/vburca/CUDA_Research_2012/Recon2D/it/../sourcedir/it.c:280: undefined reference to `CG_CUDA'
../sourcedir/cg_cuda.cu.o: In function `CGUpdateAddVector(Vector*, Vector*, Vector*, float)':
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x44): undefined reference to `Error(char*, ...)'
../sourcedir/cg_cuda.cu.o: In function `CG_CUDA(SparseMatrix*, Vector*, Vector*)':
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x15f): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x18c): undefined reference to `ReadFIF(char*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x1a2): undefined reference to `ImageToVector(Image*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x1b8): undefined reference to `FreeImage(Image*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x1c7): undefined reference to `DeviationVector(Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x248): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x255): undefined reference to `InitVector(int)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x269): undefined reference to `InitVector(int)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x27d): undefined reference to `InitVector(int)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x291): undefined reference to `InitVector(int)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x2a5): undefined reference to `InitVector(int)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x2c0): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x2e0): undefined reference to `MultSparseMatrixVector(SparseMatrix*, Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x328): undefined reference to `MultSparseTMatrixVector(SparseMatrix*, Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x37c): undefined reference to `MultSparseMatrixVector(SparseMatrix*, Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x395): undefined reference to `MultVectorVector(Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x3b1): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x3fb): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x414): undefined reference to `MultVectorVector(Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x47b): undefined reference to `ConstrainVector(Vector*, float, float)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x4ce): undefined reference to `MultSparseTMatrixVector(SparseMatrix*, Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x4e7): undefined reference to `MultVectorVector(Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x55b): undefined reference to `MultSparseMatrixVector(SparseMatrix*, Vector*, Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x581): undefined reference to `SaveIteration(Vector*, int, char*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x5ab): undefined reference to `L2NormVector(Vector*, Vector*, float)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x602): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x61f): undefined reference to `VectorToImage(Vector*, int, int)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x650): undefined reference to `L2NormVector(Vector*, Vector*, float)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x66a): undefined reference to `Print(int, char*, ...)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x679): undefined reference to `FreeVector(Vector*)'
tmpxft_00004e1d_00000000-1_cg_cuda.cudafe1.cpp:(.text+0x69c): undefined reference to `RenameImage(Image*, char*)'
collect2: ld returned 1 exit status
make: *** [it] Error 1
CC = nvcc

SOURCEDIR = ../sourcedir

EXE   = it

SOURCES  = $(SOURCEDIR)/it.c \
           $(SOURCEDIR)/em.c \
           $(SOURCEDIR)/art.c \
           $(SOURCEDIR)/cg.c \
           $(SOURCEDIR)/amatrix.c \
           $(SOURCEDIR)/itreadargs.c \
           $(SOURCEDIR)/sparse.c \
           $(SOURCEDIR)/misc.c \
           $(SOURCEDIR)/eval.c \
           $(SOURCEDIR)/imgtools.c \
           $(SOURCEDIR)/calc.c \
           $(SOURCEDIR)/egif_lib.c \
           $(SOURCEDIR)/dgif_lib.c \
           $(SOURCEDIR)/gif_err.c \
           $(SOURCEDIR)/gif_hash.c

IDIR      = -I../include

OBJS        = $(SOURCES:.c=.o)

CFLAGS     = -O3

NVCCFLAGS  = -arch=sm_20

LFLAGS      = -lm

$(EXE) : $(OBJS) $(SOURCEDIR)/cg_cuda.o
    $(CC) $(CFLAGS) -o $@ $^ $(LFLAGS)

$(SOURCEDIR)/%.o : $(SOURCEDIR)/%.c
    $(CC) $(NVCCFLAGS) $(IDIR) -c -o $@ $<

$(SOURCEDIR)/%.o : $(SOURCEDIR)/%.cu $(H_FILES)
    $(CC) $(NVCCFLAGS) $(IDIR) -c -o $@ $<

clean:
    rm -f $(OBJS) $(EXE)