coder.loop.tile - Tile for-loops in the generated code - MATLAB (original) (raw)
Main Content
Tile for
-loops in the generated code
Since R2023a
Syntax
Description
coder.loop.tile("[loopID](#mw%5F8a83a537-d65d-427a-bd3f-2b0cb2b48278)",[tileSize](#mw%5F54438e92-fdf7-442b-b731-9084b2f196de),"[tiledLoopId](#mw%5Fe2d76df3-03bf-44d7-a487-9d232c200642)")
prompts the code generator to apply a tile transform the loop with loop index nameloopID
in the generated code. This creates an outer loop that is tiled according to the tileSize
value and the inner loop index is set to the value of loopID
.
Use this transform to reduce iteration space of a loop into smaller blocks. This involves partitioning a large array from memory into smaller blocks that fit into your cache size. Use this transform when you have limited cache availability.
For more information about loop optimizations, see Optimize Loops in Generated Code.
[loopObj](#mw%5Fcda6aea1-4795-4a68-b1b5-d3e0d822f899) = coder.loop.tile(___)
creates a loop control object with transformSchedule
property set tocoder.loop.tile
. Use the apply
method to apply the transform to the specified loop.
Examples
Use the coder.loop.tile
function to apply the tile transform to a for
-loop. Provide the loopId
, tileSize
, and tileLoopId
.
Define a MATLABĀ® function tileForLoopTransform
that performs addition on a matrix.
type tileForLoopTransform
function out = tileForLoopTransform out = zeros(100);
coder.loop.tile('i',10,'ii'); for i = 1:100 for j = 1:100 out(i,j) = out(i,j) + j; end end
Generate code for this function at the command line.
codegen tileForLoopTransform.m -config:lib
Warning: Code generation is using a coder.EmbeddedCodeConfig object. Because Embedded Coder is not installed, this might cause some Embedded Coder features to fail.
Code generation successful (with warnings): View report
Inspect the code generated for the function. An additional tile loop with loop identifier ii
is included in the generated code.
type(fullfile("codegen","lib","tileForLoopTransform","tileForLoopTransform.c"))
/*
- Prerelease License - for engineering feedback and testing purposes
- only. Not for sale.
- File: tileForLoopTransform.c
- MATLAB Coder version : 25.1
- C/C++ source code generated on : 01-Feb-2025 08:01:02 */
/* Include Files */ #include "tileForLoopTransform.h" #include <string.h>
/* Function Definitions / /
- Arguments : double out[10000]
- Return Type : void */ void tileForLoopTransform(double out[10000]) { int i; int ii; int j; memset(&out[0], 0, 10000U * sizeof(double)); for (ii = 0; ii <= 99; ii += 10) { for (i = ii; i <= ii + 9; i++) { for (j = 0; j < 100; j++) { int out_tmp; out_tmp = i + 100 * j; out[out_tmp] += (double)j + 1.0; } } } }
/*
- File trailer for tileForLoopTransform.c
- [EOF] */
Input Arguments
for
loop identifier or index name to tile, specified as a character vector a string scalar.
Data Types: char
| string
Size of the new tile loop, specified as a numeric value.
Data Types: single
| double
New tiled loop index name, specified as a string scalar or character vector
Data Types: char
| string
Output Arguments
Loop control object with transformSchedule
property set tocoder.loop.tile
.
Version History
Introduced in R2023a