Error at linking stage using mexcuda

9 views (last 30 days)
I have a large scale simulation project using mexcuda interface. In the past I put all the codes in a few files mixed with declaration and initialization in the header file, obviously this is not good practise, but it comiles ok and runs without problem. Now the work is getting more complicated and I decided to do it properly with header file and code file sperately, compile into obj files and link them together. But I am having issue at the last linking stage. It is complaining about:
error LNK2019: unresolved external symbol __cudaRegisterLinkedBinary
It is probably related to the compile settings, I do have to use the NVCC_FLAGS=-rdc=true flag to turn on "Generate Relocatable Device Code" since some host function and device kernels are seperated into different files. The other potential solution is to turn on "Generate hybrid object file", based on the following post, but I am not sure how exactly to set that in NVCC_FLAGS.
I have attached the error log from mexcuda here, any ideas to resolve this issue is greatly appreciated. Thanks

Accepted Answer

Joss Knight
Joss Knight on 22 Jul 2023
Relocatable device code needs to be linked by nvcc using -dlink before it can be linked to host code using the C linker, so you'd need to call mexcuda multiple times, first with -c -rdc to generate relocatable object files, then with -dlink to create executable object files, then one more time passing all the object files so they can be linked.
Instead, you can try just calling mexcuda with the -dynamic flag (and without setting -rdc yourself), which essentially does all this for you (although it will also statically link the cudadevrt library which may cause some bloat).

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!