【问题标题】:How to link other .o, .so, .a files to current cuda compliation如何将其他 .o、.so、.a 文件链接到当前的 cuda 编译
【发布时间】:2016-06-06 10:42:05
【问题描述】:

我想将 libcudart.so 链接到我的 cuda 代码,以便对这些函数的引用应该可用。当我在 .so 文件或 .o 文件上触发 readelf -Ws 时,它会显示多个 UND(未定义)条目。请帮忙。

nvcc -c cuda/spmv/dispatch-float-float.cu -o cuda/spmv/dispatch-float-float.o -O2 -v -I. -gencode arch=compute_30,code=sm_30 -DCUDA_ARCH=30 --ptxas-options -v --cudafe-options --diag_suppress=code_is_unreachable --compiler-options -fPIC --compiler-options -fpermissive

这是我的编译代码。它不会从 libcudart.so 文件链接 CUDA 函数,并且 CUDA 函数保持未定义。


这是我的 Makefile,请提出更改建议。

NVCC = nvcc
CUDA_PATH = $(shell which $(NVCC) | sed s@/bin/nvcc@@)

CUDA_ARCH = 35

CUDA_INCLUDE := -I$(CUDA_PATH)/include/

CXXWARN := -Wall -Wno-sign-compare
CXXOPT  := -O2
CXXFLAGS := $(CXXOPT) -g $(CXXWARN) -fPIC -I. $(CUDA_INCLUDE)

NVCCFLAGS := -O2 -v -I. -gencode arch=compute_$(CUDA_ARCH),code=sm_$(CUDA_ARCH) \
    -DCUDA_ARCH=$(CUDA_ARCH) \
    --ptxas-options -v \
    --cudafe-options --diag_suppress=code_is_unreachable \
    --compiler-options -fPIC

LIB = libispm0-pic.a
all: $(LIB)

SPMV_OBJS  = cuda/spmv/dispatch-float-float.o cuda/spmv/dispatch-double-float.o cuda/spmv/dispatch-double-double.o
EXTRA_OBJS = util/cuda/sblas.o fastainv/fastainv.o util/cuda/initialize.o
OBJS = $(SPMV_OBJS) $(EXTRA_OBJS)

$(LIB): $(OBJS)
    ar cr $@ $^

cuda/spmv/dispatch-%.o: cuda/spmv/dispatch-%.cu
    $(NVCC) -c $< -o $@ $(NVCCFLAGS) --compiler-options -fpermissive
    objcopy --localize-hidden $@

util/cuda/%.o: util/cuda/%.cu
    $(NVCC) -c $< -o $@ $(NVCCFLAGS)

fastainv/fastainv.o: fastainv/fastainv.cpp
    $(CXX) -c $< -o $@ $(CXXFLAGS)

clean:
    -rm $(OBJS) $(LIB)

【问题讨论】:

    标签: c++ c linux cuda centos


    【解决方案1】:

    所以你的意思是你想静态链接到 -lcudart 以便这些引用总是由操作系统加载程序解析。

    在最近的 CUDA 工具包中,nvcc 接受标志

    --cudart{none|shared|static} (-cudart)
    共享/动态 CUDA 运行时库,或静态 CUDA 运行时库。 此选项的允许值:'none'、'shared'、'static'。

    所以也许您可以尝试将 --cudart static 添加到您的 make 规则中。

    【讨论】:

    • 如何包含在 make 规则中。请帮忙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    相关资源
    最近更新 更多