MATLAB GPU coder 使用心得

How to use MATLAB GPU coder

    • Environment Configuration
    • Opertation Process

Environment Configuration

• Windows 10
• Visual Studio 2013/2015/2017/2019
• MATLAB (2017 or above) app: MATLAB coder, GPU coder, Parallel computing toolbox
• MATLAB Support for MinGW-w64 C/C++ Compiler
• Hardware: NVIDIA GPUs.

MATLAB GPU coder 使用心得_第1张图片 MATLAB GPU coder 使用心得_第2张图片

Opertation Process

(1) Select a function you want to compute in GPUs, e.g. “TrajectoryByPoints_40_TPP_GPU.m” . Then click Next.
Note: File writing is forbidden in a function file.

MATLAB GPU coder 使用心得_第3张图片

(2) Select a file to test the types and dimensions of input parameters. You can define the input types automatically or manually. Then click Next.

MATLAB GPU coder 使用心得_第4张图片

(3) You can precompile the function in this section by choosing Check for Issues, or just click Next to ignore. This section helps to determine whether it works for GPUs, even your computer does not have a GPU device.

MATLAB GPU coder 使用心得_第5张图片 MATLAB GPU coder 使用心得_第6张图片

(4) Select MEX in the build type and Functions in Interface style. You can also define generate properties in more settings. Then click generate.

MATLAB GPU coder 使用心得_第7张图片 MATLAB GPU coder 使用心得_第8张图片

(5) If there is no error in above steps, you can get a project with the file name: “Trajectory ByPoints_40_TPP_GPU_mex.mexw64”. Now you can replace former function TrajectoryBy Points_40_TPP_GPU(…) in the main file with TrajectoryByPoints_40_TPP_GPU_mex.

(6) If you want to compute in several GPUs, e.g. 4 NVidia1080 Ti, you can choose the following method, although it is not the best choice:

parpool('local',4);
parfor i = 1:4
    gpuDevice(i);
Result{i}=TrajectoryByPoints_40_TPP_GPU_mex(points,ZerAmp,ZerCali,Path_File,suffixChar,rotate);
end
delete(gcp('nocreate'));

你可能感兴趣的:(MATLAB GPU coder 使用心得)