3

I am working on Visual Studio 2008, using CUDA 5.0. I am using CUDA Runtime API as a build rule.
I am trying to compile a single test.cu file that contains a main function and one global kernel. Both the main function and the kernel contain external library function calls which I have compiled using the same CUDA environment, with relocatable device code flag enabled, and NVCC compilation type as -c. The test.cu compiles well, but during linking it outputs the following error:

1>Linking...
1>test.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_43_tmpxft_00001888_00000000_8_test_cpp1_ii_98e63e3a referenced in function "void __cdecl __sti____cudaRegisterAll_43_tmpxft_00001888_00000000_8_test_cpp1_ii_98e63e3a(void)" (?__sti____cudaRegisterAll_43_tmpxft_00001888_00000000_8_test_cpp1_ii_98e63e3a@@YAXXZ)

I searched for __cudaRegisterLinkedBinary and found out that it is defined in crt/host_rintime.h in CUDA v5.0, but there is no such thing in v4.2.

crt/host_runtime.h:#define __REGISTERFUNCNAME_CORE(X) __cudaRegisterLinkedBinary##X 
crt/host_runtime.h:#define ____cudaRegisterLinkedBinary(X)

So I suspect it might be related to separate compilation feature that was added with v5.0, am I correct?

Could anyone help me in resolving the error? If it is a problem due to separate compilation of .cu files, then does it mean that I have to put all kernels in one single .cu file to solve it?

osgx
  • 90,338
  • 53
  • 357
  • 513
Meriko
  • 161
  • 2
  • 11
  • I solved the problem. Visual studio uses its own linker (link.exe) during linking, although compiling is done with nvcc. Using nvcc during linking solves the problem. Thus both the compilation and linking steps should be done only with nvcc. – Meriko Dec 18 '12 at 16:54
  • 2
    If you solved the problem, could you add your solution as a short answer to this question (this is allowed here)? You will later be able to accept it, and it will leave it in an easy to see place for others, as well as getting this question off the unanswered list. Thank you. – talonmies Aug 18 '13 at 11:15

2 Answers2

2

This problem has been faced at the following two threads:

Question about cudaRegisterLinkedBinary referenced in function __cudaRegisterAll

and

device-link.obj / cudaRegisterLinkedBinary error

Vitality
  • 20,705
  • 4
  • 108
  • 146
1

I have met the same error. It looks like my problem is related to the separate compilation. (I'm new to CUDA, so I will be obliged if someone could confirm it or provide a better explanation.)

First of all, my fix with Visual Studio is to go to properties -> CUDA C/C++ -> Common and toggle "Yes" to "Generate Relocatable Device Code". According to https://forums.developer.nvidia.com/t/how-to-separately-compile-a-kernel-in-visual-studio/80385, you will also need to make sure that the "NVCC Compilation Type" is "Generate hybrid object file".

According to the NVCC documentation, the issue related to the first fix is that NVCC embeds relocatable device code in the host object, and calls nvlink to link the device cade, which is then linked with the host objects to form the final program. The issue with the second fix is that there is CUDA host code being generated implicitly from the ".cu" files. This host code needs to be passed to the host linker.

The docuemntation links are: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-options-for-separate-compilation and https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#implicit-cuda-host-code