Main Content

Configure GPU Code Generation

You can use the GPU Coder™ configuration options to customize generated CUDA® code. After you specify the type of output you want to generate, use configuration objects or the GPU Coder app to configure the code generator.

Configure Code Generation Using a Configuration Object

To customize the configuration programmatically, create a configuration object using the coder.gpuConfig function. The coder.gpuConfig function creates a different configuration object depending on the output type.

Output Type

Example Creation

Object Type

Standalone source code, executables, or libraries
cfg = coder.gpuConfig("dll"); 
cfg = coder.gpuConfig("lib"); 
cfg = coder.gpuConfig("exe");

coder.EmbeddedCodeConfig, if Embedded Coder®, is installed

coder.CodeConfig if Embedded Coder is not installed

MEX Functions
cfg = coder.gpuConfig("mex");

coder.MexCodeConfig

You can use the configuration object properties to specify the configuration settings. To set a property on the configuration object, use dot notation. For example, to generate a report, set the GenerateReport property of a configuration object cfg to true.

cfg.GenerateReport = true;
To access GPU-specific parameters, use the GpuConfig property of a configuration object. For example, to configure an object cfg to use a stack limit of 2048 bytes per GPU thread in the generated CUDA code, use the GpuConfig property.
cfg.GpuConfig.StackLimitPerThread = 2048;

Configure Code Generation Using the GPU Coder App

To customize the configuration options using the GPU Coder app:

  1. In the GPU Coder tab, set the Build Type. The available configuration parameters depend on the selected build type.

  2. In the GPU Coder tab, click Settings. For library, executable, or source code builds, the Settings button opens the Standalone Code Generation Settings window. For MEX builds, the Settings button opens the MEX Code Generation Settings window.

To access GPU code configuration parameters, in the left pane of either window, click GPU Code.

Parameter Differences Between GPU Coder and MATLAB Coder

GPU Coder shares configuration parameters with MATLAB® Coder™. However, some configuration parameters have fixed values that are required for GPU code generation. Some configuration parameters also have different default values.

Parameters with Fixed Values

This table lists the parameter values that you cannot change when using the GPU Coder app. These values are required for GPU code generation. If you change these values programmatically, the code generator ignores the values you specify.

Parameters with Different Default Values

Some parameters in the GPU Coder app have different default values than the parameters in the MATLAB Coder app. However, you can set these parameters to different values in the GPU Coder app or by using the properties of a configuration object.

This table lists the parameters that have different default values in the GPU Coder app.

See Also

| | |

Topics