GPU Coder: nvlink error when targeting NVIDIA Jetson/DRIVE with debugging enabled

10 views (last 30 days)
I encounter the same error when targeting NVIDIA Jetson & DRIVE with debugging enabled.
In Simulink:
I have a Simulink model that I’m trying to deploy to an NVIDIA Jetson board. The model contains a MATLAB Function block to perform sort on the GPU using the gpucoder.sort function.
[~,<indexOutput>] = gpucoder.sort(<input>)
The model is configured to generate GPU code and deploy to the NVIDIA Jetson/Drive hardware. In addition, I have set the Debug mode parameter in the Code Generation > Build Configuration pane. When I build the model, the generated code fails to link on the target during the compilation phase with a nvlink error. A snippet of the error is shown below:
nvlink error : Undefined reference to 'cudaDeviceSynchronize' in '<Model>.o'
nvlink error : Undefined reference to 'cudaPeekAtLastError' in '<Model>.o'
nvlink error : Undefined reference to 'cudaGetParameterBuffer' in '<Model>.o'
nvlink error : Undefined reference to 'cudaLaunchDevice' in '<Model>.o'
nvlink error : Undefined reference to 'cudaGetErrorString' in '<Model>.o'
I have been successful deploying other models using the same configuration. But this combination of gpucoder.sort and debug mode fails with the aforementioned error.
In MATLAB:
Instead of using Simulink, I created an entry-point function in MATLAB with a similar code signature and attempted GPU code generation by using a code configuration object set for Jetson/Drive targeting.
cfg = coder.gpuConfig('exe');
cfg.Hardware = coder.hardware('NVIDIA Jetson'); % For NVIDIA Jetson
cfg.GenerateExampleMain = 'GenerateCodeAndCompile';
cfg.BuildConfiguration = 'Debug';
codegen -config cfg -args {<required arguments>} <function> -report
I encounter the same error as before.
nvlink error : Undefined reference to 'cudaDeviceSynchronize' in '<function>.o'
nvlink error : Undefined reference to 'cudaPeekAtLastError' in '<function>.o'
nvlink error : Undefined reference to 'cudaGetParameterBuffer' in '<function>.o'
nvlink error : Undefined reference to 'cudaLaunchDevice' in '<function>.o'
nvlink error : Undefined reference to 'cudaGetErrorString' in '<function>.o'
Are there additional options that need to be enabled? How can I resolve this?

Accepted Answer

Bill Chou
Bill Chou on 12 Oct 2020
Background
gpucoder.sort()takes advantage of the Thrust Library for generating kernels on the GPU. Certain Thrust APIs take advantage of the dynamic parallelism feature of CUDA. Compiling CUDA code that contains dynamic parallelism on NVIDIA embedded boards may result in a linker error because of unrecognizable symbols, similar to the one above.
There are two possible scenarios where enabling debug mode can cause the nvlink errors:
  • A MATLAB entry-point function or a Simulink MATLAB Function block directly calls gpucoder.sort
  • A built-in function calls gpucoder.sort. For example, a deep learning object detector such as yolov2ObjectDetector
The issue is also observed when these models use the XCP-based External Mode functionality. Because External Mode relies on the presence of debug symbols to access both signals and parameters variables for calibration and measurement (in accordance to the ASAM MCD-1-XCP communication protocol), the debug mode is automatically enabled even if the parameter is not explicitly set.
To fix these linker error(s), it is recommended to provide the linker with the compute capability of the board. For GPU Coder, you must set the compute capability of the GPU device on the board through the code configuration object or Simulink configuration parameters.
Identify the Compute Capability of the Target Platform
To get the compute capability of the board, create a live hardware connection to the board as follows:
hwobj = jetson('<IpAddress>','<userName>','<passWord>'); % For NVIDIA Jetson
hwobj = drive('<IpAddress>','<userName>','<passWord>'); % For NVIDIA Drive
Get the compute capability of the board as follows:
computeCapability = num2str(hwobj.GPUInfo.ComputeCapability); % For NVIDIA Jetson
computeCapability = num2str(hwobj.GPUInfo(<GPU ID>).ComputeCapability); % For NVIDIA Drive
In Simulink
To set the compute capability of the model to that of the board programmatically, enter the following command in the MATLAB Command Window:
set_param('<modelName>','GPUComputeCapability',computeCapability);
In MATLAB
For GPU code generation from MATLAB, set the compute capability in the code configuration object.
cfg.GpuConfig.ComputeCapability = computeCapability; % GPU Config object

More Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!