Main Content

coder.gpuConfig

Create GPU code generation configuration

Description

cfg = coder.gpuConfig creates a CUDA® MEX configuration object cfg. To customize the GPU code generation properties, use the coder.GpuCodeConfig object stored in the GpuConfig property of cfg. To generate CUDA code, use the code configuration object with the -config option of the codegen command.

example

cfg = coder.gpuConfig(build_type) creates a code generation configuration object for the build type build_type.

example

cfg = coder.gpuConfig(build_type,"ecoder",ecoder_flag) creates a coder.EmbeddedCodeConfig object when the Embedded Coder® flag ecoder_flag is true or 1.

example

Examples

collapse all

Create a CUDA MEX configuration object, configure its GPU code properties, and generate a CUDA MEX function.

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

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

Create a MEX code configuration object by using the coder.gpuConfig function.

cfg = coder.gpuConfig;

Enable report generation by using the GenerateReport property of cfg.

cfg.GenerateReport = true;

Use a custom kernel prefix by setting the KernelNamePrefix property of the coder.GpuCodeConfig object.

cfg.GpuConfig.KernelNamePrefix = "alpha";

Generate a CUDA MEX function from VecAdd.

A = rand(20);
B = rand(20);
codegen VecAdd.m -config cfg -args {A,B};
Code generation successful: View report

Create a configuration object for the dynamic library build type. If Embedded Coder is installed, coder.gpuConfig returns a coder.EmbeddedCodeConfig object. Otherwise, coder.gpuConfig returns a coder.CodeConfig object.

cfg = coder.gpuConfig("dll");

To create a configuration object that does not use Embedded Coder, set the ecoder_flag to false.

coder.gpuConfig("dll","ecoder",false);

Input Arguments

collapse all

Output to build from the generated CUDA code, specified as "mex", "lib", "dll", or "exe". The build_type argument determines the type of the output configuration object cfg.

ValueDescriptionOutput Configuration Object If Embedded Coder Is InstalledOutput Configuration Object If Embedded Coder Is Not Installed
"mex"CUDA MEXcoder.MexCodeConfigcoder.MexCodeConfig
"lib"Static librarycoder.EmbeddedCodeConfigcoder.CodeConfig
"dll"Dynamically linked librarycoder.EmbeddedCodeConfigcoder.CodeConfig
"exe"Executable programcoder.EmbeddedCodeConfigcoder.CodeConfig

Example: cfg = coder.gpuConfig("dll");

Option to use Embedded Coder, specified as a numeric or logical 1 (true) or 0 (false). If the build_type is "dll", "lib", or "exe", the ecoder_flag determines whether the GPU code configuration object cfg uses Embedded Coder. If ecoder_flag is true or 1, the function returns a coder.EmbeddedCodeConfig object. If ecoder_flag is false or 0, the function returns a coder.CodeConfig object.

Example: cfg = coder.gpuConfig("exe","ecoder",false);

Output Arguments

collapse all

GPU code configuration object, returned as a coder.CodeConfig, coder.MexCodeConfig, or coder.EmbeddedCodeConfig object.

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