Hauptinhalt

coder.GpuCodeConfig

Configuration parameters for CUDA code generation from MATLAB code

Description

coder.GpuCodeConfig objects specify the code configuration parameters for generating NVIDIA® CUDA® code from MATLAB® code. Use the properties of the coder.GpuCodeConfig object to customize CUDA features, such as kernel launch parameters, NVIDIA code libraries, and CUDA compute capability.

Creation

To create a coder.GpuCodeConfig object, first create one of these code configuration objects by using the coder.gpuConfig function:

The GpuConfig property of the configuration object contains a coder.GpuCodeConfig object.

Properties

expand all

Option to generate GPU code, specified as numeric or 1 (true) or 0 (false). For more information, see Generate GPU Code.

Example: cfg.GpuConfig.Enabled = true

Memory allocation mode to use in the generated CUDA code, specified as "discrete" or "unified". For more information, see Malloc mode.

Example: cfg.GpuConfig.MallocMode = "discrete"

Custom kernel name prefixes, specified as a character vector or string scalar. For more information, see Kernel name prefix.

Example: cfg.GpuConfig.KernelNamePrefix = "myKernel"

Option to replace math function calls with NVIDIA cuBLAS library calls, specified as numeric or 1 (true) or 0 (false). For more information, see Enable cuBLAS.

Example: cfg.GpuConfig.EnableCUBLAS = true

Option to replace math function calls with NVIDIA cuSOLVER library calls, specified as numeric or logical 1 (true) or 0 (false). For more information, see Enable cuSOLVER.

Example: cfg.GpuConfig.EnableCUSOLVER = true

Option to replace fft function calls with NVIDIA cuFFT library calls, specified as numeric or logical 1 (true) or 0 (false). For more information, see Enable cuFFT.

Example: cfg.GpuConfig.EnableCUFFT = true

Option to check for errors in generated CUDA code, specified as numeric or logical 1 (true) or 0 (false). Use this property to check for errors in CUDA API calls and kernel launches. For more information, see Safe build.

Example: cfg.GpuConfig.SafeBuild = true

Minimum compute capability required to run generated CUDA code, specified as one of these values.

  • "Auto"

  • "3.2"

  • "3.5"

  • "3.7"

  • "5.0"

  • "5.2"

  • "5.3"

  • "6.0"

  • "6.1"

  • "6.2"

  • "7.0"

  • "7.2"

  • "7.5"

  • "8.0"

  • "8.6"

  • "8.7"

  • "8.9"

  • "9.0"

For more information, see Minimum compute capability.

Example: cfg.GpuConfig.ComputeCapability = "6.1"

Name of the NVIDIA virtual GPU architecture for which to compile the CUDA input files, specified as a character or string scalar. For more information, see Custom compute capability.

Example: cfg.GpuConfig.CustomComputeCapability = "-arch=compute_50"

Additional flags to pass to the GPU compiler, specified as a character vector or string scalar. For more information, see Compiler flags.

Example: cfg.GpuConfig.CompilerFlags = "--fmad=false"

Stack limit per GPU thread in bytes, specified as an integer. For more information, see Stack limit.

Example: cfg.GpuConfig.StackLimitPerThread = 1024

Maximum number of blocks created during a kernel launch, specified as an integer. For more information, see Maximum blocks per kernel.

Example: cfg.GpuConfig.MaximumBlocksPerKernel = 1024

Option to use GPU memory manager, specified as numeric or logical 1 (true) or 0 (false). For more information, see Enable GPU memory manager.

Example: cfg.GpuConfig.EnableMemoryManager = true

CUDA device selection, specified as the numeric value of the device ID. For more information, see GPU device ID.

Example: cfg.GpuConfig.SelectCudaDevice = 0

Examples

collapse all

Create a configuration object to generate a CUDA MEX function from a MATLAB function. Then, use the GpuConfig property of the configuration object to modify the coder.GpuCodeConfig object. In this example, enable the option to replace math function with calls to the NVIDIA cuBLAS library.

Write a MATLAB function, vecAdd, that adds two inputs.

function [C] = VecAdd(A,B) %#codegen
coder.gpu.kernelfun(); 
C = A + B;
end

To generate a MEX function, create a code generation configuration object.

cfg = coder.gpuConfig("mex");

Enable the code generation report.

cfg.GpuConfig.EnableCUBLAS = true;
cfg.GenerateReport = true;

Generate a MEX function in the current folder by using the -config option and the configuration object.

% Generate a MEX function and code generation report
codegen -config cfg -args {zeros(512,512,"double"),zeros(512,512,"double")} VecAdd

Limitations

  • On Windows® platforms, the generated makefiles for standalone targets, such as dynamic libraries, static libraries, and executables, do not set the /MT or /MD compiler flags. These flags direct the Visual Studio® compiler to use the multithread library. By default, Visual Studio uses the /MT flag during compilation. To pass other compiler-specific flags, use the CompilerFlags property. For example, to specify the /MD flag for a configuration object cfg, enter this code :

    cfg.GpuConfig.CompilerFlags = "-Xcompiler /MD";
    

  • The nvcc compiler supports a limited set of file suffixes. For example, if object file contains version numbers, compilation may fail. In such cases, create symbolic links or specify "-Xlinker" in the CompilerFlags property.

Alternative Functionality

App

You can use the GPU Coder app to configure the code generator and generate CUDA code. For more information, see Generate Code by Using the GPU Coder App.

Version History

Introduced in R2017b

expand all