【问题标题】:CUDA Dynamic Parallelism MakeFileCUDA 动态并行 MakeFile
【发布时间】:2017-06-14 18:42:06
【问题描述】:

这是我第一个使用动态并行的程序,我无法编译代码。我需要能够为我在大学的研究项目运行这个,任何帮助将不胜感激:

我收到以下错误:

/cm/shared/apps/cuda50/toolkit/5.0.35/bin/nvcc -m64 -dc  -gencode arch=compute_35,code=sm_35 -rdc=true -dlink -po maxrregcount=16 -I/cm/shared/apps/cuda50/toolkit/5.0.35 -I. -I.. -I../../common/inc -o BlackScholes.o -c BlackScholes.cu
g++ -m64 -I/cm/shared/apps/cuda50/toolkit/5.0.35 -I. -I.. -I../../common/inc -o BlackScholes_gold.o -c BlackScholes_gold.cpp
g++ -m64 -o BlackScholes BlackScholes.o BlackScholes_gold.o -L/cm/shared/apps/cuda50/toolkit/5.0.35/lib64 -lcudart -lcudadevrt
BlackScholes.o: In function `__sti____cudaRegisterAll_47_tmpxft_000059cb_00000000_6_BlackScholes_cpp1_ii_c58990ec()':
tmpxft_000059cb_00000000-3_BlackScholes.cudafe1.cpp:(.text+0x1354): undefined reference to `__cudaRegisterLinkedBinary_47_tmpxft_000059cb_00000000_6_BlackScholes_cpp1_ii_c58990ec'
collect2: ld returned 1 exit status
make: *** [BlackScholes] Error 1

我有一个 cpp 文件,一个 cu 文件和一个 cuh 文件。我的 makefile 的重要部分如下:

# CUDA code generation flags
#GENCODE_SM10    := -gencode arch=compute_10,code=sm_10
GENCODE_SM20     := -gencode arch=compute_20,code=sm_20
GENCODE_SM30     := -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35
GENCODE_SM35     := -gencode arch=compute_35,code=sm_35
#GENCODE_FLAGS    := $(GENCODE_SM10) $(GENCODE_SM20) $(GENCODE_SM30)
GENCODE_FLAGS    := $(GENCODE_SM35)

# OS-specific build flags
ifneq ($(DARWIN),)
      LDFLAGS   := -Xlinker -rpath $(CUDA_LIB_PATH) -L$(CUDA_LIB_PATH) -lcudart -lcudadevrt
      CCFLAGS   := -arch $(OS_ARCH)
else
  ifeq ($(OS_SIZE),32)
      LDFLAGS   := -L$(CUDA_LIB_PATH) -lcudart -lcudadevrt
      CCFLAGS   := -m32
  else
      LDFLAGS   := -L$(CUDA_LIB_PATH) -lcudart -lcudadevrt
      CCFLAGS   := -m64
  endif
endif

# OS-architecture specific flags
ifeq ($(OS_SIZE),32)
      NVCCFLAGS := -m32 -dc
else
      NVCCFLAGS := -m64 -dc
endif

# Debug build flags
ifeq ($(dbg),1)
      CCFLAGS   += -g
      NVCCFLAGS += -g -G
      TARGET := debug
else
      TARGET := release
endif


# Common includes and paths for CUDA
INCLUDES      := -I$(CUDA_INC_PATH) -I. -I.. -I../../common/inc

# Additional parameters
MAXRREGCOUNT  :=  -po maxrregcount=16

# Target rules
all: build

build: BlackScholes

BlackScholes.o: BlackScholes.cu
        $(NVCC) $(NVCCFLAGS) $(EXTRA_NVCCFLAGS) $(GENCODE_FLAGS) -rdc=true -dlink $(MAXRREGCOUNT) $(INCLUDES) -o $@ -c $<

BlackScholes_gold.o: BlackScholes_gold.cpp
        $(GCC) $(CCFLAGS) $(INCLUDES) -o $@ -c $<

BlackScholes: BlackScholes.o BlackScholes_gold.o
        $(GCC) $(CCFLAGS) -o $@ $+ $(LDFLAGS) $(EXTRA_LDFLAGS)
        mkdir -p ../../bin/$(OSLOWER)/$(TARGET)
        cp $@ ../../bin/$(OSLOWER)/$(TARGET)
    enter code here

run: build
        ./BlackScholes

【问题讨论】:

    标签: c cuda


    【解决方案1】:

    当使用主机链接器 (g++) 最终链接可执行文件时,以及使用可重定位设备代码 (nvcc -dc) 时,需要执行中间设备代码链接步骤。

    来自documentation

    If you want to invoke the device and host linker separately, you can do:
    
    nvcc –arch=sm_20 –dc a.cu b.cu
    nvcc –arch=sm_20 –dlink a.o b.o –o link.o
    g++ a.o b.o link.o –L<path> -lcudart
    

    由于您在编译行中指定了-dc,因此您将获得仅编译操作(就像您已将-c 指定给g++ 一样)。

    这是一个经过修改/浓缩的Makefile,应该会告诉您所涉及的内容:

    GENCODE_SM35     := -gencode arch=compute_35,code=sm_35
    GENCODE_FLAGS    := $(GENCODE_SM35)
    
    LDFLAGS   := -L/usr/local/cuda/lib64 -lcudart -lcudadevrt
    CCFLAGS   := -m64
    
    NVCCFLAGS := -m64 -dc
    
    NVCC := nvcc
    GCC := g++
    
    # Debug build flags
    ifeq ($(dbg),1)
          CCFLAGS   += -g
          NVCCFLAGS += -g -G
          TARGET := debug
    else
          TARGET := release
    endif
    
    
    # Common includes and paths for CUDA
    INCLUDES      := -I/usr/local/cuda/include -I. -I..
    
    # Additional parameters
    MAXRREGCOUNT  :=  -po maxrregcount=16
    
    # Target rules
    all: build
    
    build: BlackScholes
    
    BlackScholes.o: BlackScholes.cu
            $(NVCC) $(NVCCFLAGS) $(EXTRA_NVCCFLAGS) $(GENCODE_FLAGS) $(MAXRREGCOUNT) $(INCLUDES) -o $@ $<
            $(NVCC) -dlink  $(GENCODE_FLAGS) $(MAXRREGCOUNT)  -o bs_link.o $@
    
    BlackScholes_gold.o: BlackScholes_gold.cpp
            $(GCC) $(CCFLAGS) $(INCLUDES) -o $@ -c $<
    
    BlackScholes: BlackScholes.o BlackScholes_gold.o bs_link.o
            $(GCC) $(CCFLAGS) -o $@ $+ $(LDFLAGS) $(EXTRA_LDFLAGS)
    
    run: build
            ./BlackScholes
    

    【讨论】:

    • 我需要将“-lcudadevrt”附加到“Command”的字符串(即“nvcc -lcudadevrt”),然后它就起作用了。非常感谢您的帮助罗伯特。 :-)
    • 是的,我认为还需要为中间步骤添加它,这意味着我的 Makefile 可以通过同时为中间 (-dlink) 链接步骤指定 $(LDFLAGS) 来修改。
    猜你喜欢
    • 2013-10-20
    • 1970-01-01
    • 2023-03-17
    • 2017-12-25
    • 1970-01-01
    • 2015-03-05
    • 2015-08-27
    • 2012-06-06
    相关资源
    最近更新 更多