Dear all,
I’ve faced the following problem. I have a shared library that uses CUDA. It has both C++ and CUDA parts and compiled as follows:
CUDA_SDK:=$(HOME)/NVIDIA_GPU_Computing_SDK/C
CUDA_BASE:=/usr/local/cuda
CC:=g++
NVCC:=nvcc
INCLUDE:=-I/usr/include -I$(CUDA_BASE)/include -I$(CUDA_SDK)/common/inc -I/usr/local/include/opencv2
INCLUDE_CUDA:=-I$(CUDA_BASE)/include -I$(CUDA_SDK)/common/inc
FLAGS:=-O3 -MMD -Wall -fPIC -g -c -ggdb
LIBS:=-L/usr/local/lib -L$(CUDA_SDK)/lib -L$(CUDA_BASE)/lib64 -lcudart -lcutil_x86_64 -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_video -lopencv_gpu
HEADERS:=$(wildcard *.h)
OBJECTS:=$(patsubst %.cpp,%.o,$(wildcard *.cpp)) cuda_code.o
TARGET:=libMyCuda
all: $(OBJECTS)
$(CC) $(LIBS) --shared -o $(TARGET).so $(OBJECTS)
%.o: %.cpp
$(CC) $(INCLUDE) $(FLAGS) $< -o $@
cuda_code.o:
$(NVCC) $(INCLUDE_CUDA) segmentation.cu --ptxas-options=-v -c --compiler-options -O3 -arch=compute_13 -code=sm_13 --compiler-options '-fPIC'
This library is used in the main application. If the main application is compiled with g++ linking the mentioned library, everything works fine and CUDA calls look like that:
MainApp -> libMyCuda -> cuda_function()
.
However, the main application is split in modules now and every module is a separate shared library. Thus there is one module that calls CUDA functions, and now CUDA calls look like:
MainApp -> libModule -> libMyCuda -> cuda_function()
.
So there are more than one library linked between the main program and CUDA functions. And now I’m facing the following problem. CUDA memory allocations work fine (cudaMalloc), but later, calling cudaMemset() I’m getting ‘cudaErrorInvalidValue’ error and my program just crashes… I cannot find a reason for that, since the library works fine in the first case.
Does anybody have an idea what can be the reason? I suspect that something weird happens on the linking stage… But I’m really confused.
Any suggestions are kindly welcome!
Thanks a lot in advance,
Salzis