Error at linking stage using mexcuda

7 次查看(过去 30 天)
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

采纳的回答

Joss Knight
Joss Knight 2023-7-22
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).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with GPU Coder 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by