CUDA CUDA编译错误 [英] CUDA compilation errors on Mac

查看:458
本文介绍了CUDA CUDA编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下Makefile来编译CUDA C程序。这与我在大多数C项目中使用的模式大致相同。

I'm using the following Makefile to compile a CUDA C program. This follows pretty much the same pattern that I use in most of my C projects.

TARGET = bfs

GCC = nvcc
CUDA_INSTALL_PATH := /Developer/NVIDIA/CUDA-7.5
LIBS := -I. -I$(CUDA_INSTALL_PATH)/include
CUDA_LIBS := -L$(CUDA_INSTALL_PATH)/lib -lcudart

SRCDIR = src
OBJDIR = obj
BINDIR = bin
INClDIR = includes

SOURCES := $(wildcard $(SRCDIR)/*.cu)
INCLUDES := $(wildcard $(INClDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cu=$(OBJDIR)/%.o)
rm = rm -f

$(BINDIR)/$(TARGET): $(OBJECTS)
    mkdir -p $(BINDIR)
    $(GCC) -o $@ $(LIBS) -c $(OBJECTS)
    @echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cu
    @$(GCC) $(LIBS) -c *.cu -o $@
    @echo "Compiled "$<" successfully!"

.PHONEY: clean
clean:
    @$(rm)   $(OBJECTS)
    @echo "Cleanup complete!"
remove: clean
    @$(rm) $(BINDIR)/$(TARGET)
    @echo "Executable removed!"

我收到以下错误

mkdir -p bin
nvcc -o bin/bfs -I. -I/Developer/NVIDIA/CUDA-7.5/include -c obj/main.o obj/square.o
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
make: *** [bin/bfs] Error 1

推荐答案

这似乎对我有用:

TARGET = bfs

SRCDIR = src
OBJDIR = obj
BINDIR = bin
INClDIR = includes

CUDA_INSTALL_PATH := /usr/local/cuda
GCC := $(CUDA_INSTALL_PATH)/bin/nvcc
LIBS := -I. -I$(SRCDIR) -I$(CUDA_INSTALL_PATH)/include -I$(INClDIR)
CUDA_LIBS := -L$(CUDA_INSTALL_PATH)/lib64 -lcudart

SOURCES := $(wildcard $(SRCDIR)/*.cu)
INCLUDES := $(wildcard $(INClDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cu=$(OBJDIR)/%.o)
rm = rm -f

$(BINDIR)/$(TARGET) : $(OBJECTS)
        mkdir -p $(BINDIR)
        $(GCC) -o $@  $(OBJECTS)
        @echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cu
        @$(GCC) $(LIBS) -c $(SRCDIR)/*.cu -odir $(OBJDIR)
        @echo "Compiled "$<" successfully!"

.PHONEY: clean
clean:
        @$(rm)   $(OBJECTS)
        @echo "Cleanup complete!"
remove: clean
        @$(rm) $(BINDIR)/$(TARGET)
        @echo "Executable removed!"

我在linux上测试过。您需要将 CUDA_INSTALL_PATH 更改回您机器上的任何位置。

I tested on linux. You will need to change CUDA_INSTALL_PATH back to wherever it is on your machine.

请注意,在编译步骤中使用 *。cu 会导致单一调用 nvcc 以编译所有源文件。这本身没有什么问题,但它只会生成一个编译...成功!消息,因为只有一个调用 nvcc 来创建所有对象。

Note that your use of *.cu on the compile step results in a single invocation of nvcc to compile all the source files. There's nothing wrong with this per se, but it will only generate a single "Compiled ... successfully!" message, as there is only one invocation of nvcc to create all the objects.

这篇关于CUDA CUDA编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆