1
votes

I have a code by name mexCodeCuda.cu which uses dynamic parallelism. In the matlab interface, when I try to execute the following commands, I get the following error :

system('nvcc --compile mexCodeCuda.cu -o mexCodeCuda.o --compiler-options -fPIC -m64 -rdc=true -gencode arch=compute_35,code=sm_35 -O3 -lineinfo -use_fast_math -lcudadevrt -I/cm/shared/apps/MATLAB/extern/include')

system('nvcc -arch=sm_35 -dlink mexCodeCuda.o -o dlink.o')

eval('mex mexCodeCuda.o dlink.o -L'CUDA_LIB_PATH '-lcudart')

It gives the following error :

Error using mex
/usr/bin/ld: dlink.o: relocation R_X86_64_32S against `__nv_module_id' can
not be used when making a shared object; recompile with -fPIC
dlink.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status

Can anyone help me ? Thanks in advance...

1
Did you try rerunning mex and the other nvcc with -fPIC? - chappjc
When I added -fPIC to the second nvcc, it raised an error nvcc fatal : Unknown option 'fPIC' Running with mex throws the following error: Unknown MEX argument '-fPIC'. - Jagannath
When you added -fPIC to the second nvcc, did you actually do --compiler-options -fPIC - Tom
After adding --compiler-options -fPIC to the second nvcc, it compiled but when I run eval(without fPIC inside eval) it throws an error : Error using mex dlink.o: In function __cudaRegisterLinkedBinary_65_tmpxft_00007d13_00000000_9_cuda_device_runtime_compute_50_cpp1_ii_5f6993ef': link.stub:(.text+0xab): undefined reference to __fatbinwrap_65_tmpxft_00007d13_00000000_9_cuda_device_runtime_compute_50_cpp1_ii_5f6993ef' collect2: error: ld returned 1 exit status - Jagannath
I suspect you need to specify the cudadevrt runtime option on the mex command, just as you have with the first nvcc call. And you may need to add -fPIC to the mex linking via LDCXXFLAGS or LDFLAGS. - chappjc

1 Answers

1
votes

A few changes:

  • Add -fPIC to the second nvcc command (using --compiler-options, just as you did with the first nvcc).
  • Specify the cudadevrt runtime option on the mex command (-lcudadevrt), just as you have with the first nvcc call.
  • And you may need to add -fPIC to the mex linking via LDCXXFLAGS or LDFLAGS. Not sure.