主要内容

重用缓冲区的大小和尺寸

您可以重用为矩阵缓冲区,有不同的大小和形状。在配置参数对话框,您启用这个优化选择重用缓冲区的大小和尺寸。这种优化减少RAM和ROM的使用和改进代码的执行速度。

示例模型

该模型DifferentSizeReuse包含信号不同的大小和尺寸。

模型=“DifferentSizeReuse”;open_system(模型);

没有生成代码优化

在配置参数对话框中,设置重用缓冲区的大小和尺寸参数或在MATLAB®命令窗口中,输入:

set_param (“DifferentSizeReuse”,“DifferentSizesBufferReuse”,“关闭”);

关闭评论和构建模型。

set_param (“DifferentSizeReuse”,“GenerateComments”,“关闭”);slbuild (“DifferentSizeReuse”);
# # #开始构建过程:DifferentSizeReuse # # #成功完成构建过程:DifferentSizeReuse模型建立目标:总结构建模型重建行动的原因= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = DifferentSizeReuse代码生成和编译。代码生成信息文件不存在。1 1模型的建立(0模型已经更新)构建持续时间:0 h 0米31.195秒

查看生成的代码没有优化。的D_Work结构是:

hfile = fullfile (“DifferentSizeReuse_ert_rtw”,“DifferentSizeReuse.h”);rtwdemodbtype (hfile“typedef struct {”,'}D_Work ',1,1);
typedef struct {real_T ComplextoRealImag_o1 [16384];real_T ComplextoRealImag_o2 [16384];real_T z [3969];real_T z_n [3969];real_T z_j [4032];real_T z_m [4032];real_T z_g [4096];real_T z_e [4096];}D_Work;

的部分DifferentSizeReuse.c是:

用= fullfile (“DifferentSizeReuse_ert_rtw”,“DifferentSizeReuse.c”);rtwdemodbtype(用“# include“DifferentSizeReuse.h””,“空白DifferentSizeReuse_initialize(空白)1 0);
# include“DifferentSizeReuse。h rtwtypes # include。h”# include <数学。h > D_Work rtDWork;ExternalInputs rtU;ExternalOutputs而无;静态RT_MODEL rtM_;RT_MODEL * const rtM = &rtM_;静态孔隙Downsample (const real_T rtu_u [16384], real_T rty_z [4096]);静态孔隙△(const real_T rtu_u [4096], real_T rty_z [4032]);静态孔隙δy (const real_T rtu_u [4032], real_T rty_z [3969]);静态孔隙NoninplaceableSS1(无效); static void NoninplaceableSS2(void); static void NoninplaceableSS3(void); static void Downsample(const real_T rtu_u[16384], real_T rty_z[4096]) { int32_T tmp; int32_T tmp_0; int32_T tmp_1; int32_T x; int32_T y; for (x = 0; x < 64; x++) { for (y = 0; y < 64; y++) { tmp_0 = (y + 1) << 1; tmp_1 = (x + 1) << 1; tmp = ((tmp_0 - 2) << 7) + tmp_1; tmp_0 = ((tmp_0 - 1) << 7) + tmp_1; rty_z[x + (y << 6)] = (((rtu_u[tmp - 2] + rtu_u[tmp - 1]) + rtu_u[tmp_0 - 2]) + rtu_u[tmp_0 - 1]) / 4.0; } } } static void NoninplaceableSS1(void) { Downsample(rtDWork.ComplextoRealImag_o1, rtDWork.z_e); Downsample(rtDWork.ComplextoRealImag_o2, rtDWork.z_g); } static void DeltaX(const real_T rtu_u[4096], real_T rty_z[4032]) { int32_T tmp; int32_T x; int32_T y; for (x = 0; x < 63; x++) { for (y = 0; y < 64; y++) { tmp = (y << 6) + x; rty_z[x + 63 * y] = fabs(rtu_u[tmp] - rtu_u[tmp + 1]); } } } static void NoninplaceableSS2(void) { DeltaX(rtDWork.z_e, rtDWork.z_m); DeltaX(rtDWork.z_g, rtDWork.z_j); } static void DeltaY(const real_T rtu_u[4032], real_T rty_z[3969]) { int32_T i; for (i = 0; i < 3969; i++) { rty_z[i] = fabs(rtu_u[i] - rtu_u[i + 63]); } } static void NoninplaceableSS3(void) { DeltaY(rtDWork.z_m, rtDWork.z_n); DeltaY(rtDWork.z_j, rtDWork.z); } void DifferentSizeReuse_step(void) { int32_T i; for (i = 0; i < 16384; i++) { rtDWork.ComplextoRealImag_o1[i] = rtU.ComplexData[i].re; rtDWork.ComplextoRealImag_o2[i] = rtU.ComplexData[i].im; } NoninplaceableSS1(); NoninplaceableSS2(); NoninplaceableSS3(); for (i = 0; i < 3969; i++) { rtY.Out1[i].re = rtDWork.z_n[i]; rtY.Out1[i].im = rtDWork.z[i]; } }

D_work结构包含八个全局变量的输入和输出Downsample,,δy。这些变量有不同的大小。

生成代码的优化

  1. 在配置参数对话框,确认信号存储重用被选中。

  2. 设置重用缓冲区的大小和尺寸参数或在MATLAB命令窗口中,输入:

set_param (“DifferentSizeReuse”,“DifferentSizesBufferReuse”,“上”);

构建的模型。

set_param (“DifferentSizeReuse”,“GenerateComments”,“关闭”);slbuild(模型);
# # #开始构建过程:DifferentSizeReuse # # #成功完成构建过程:DifferentSizeReuse模型建立目标:总结构建模型重建行动的原因= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = DifferentSizeReuse代码生成和编译。生成的代码是过时了。1 1模型的建立(0模型已经更新)构建持续时间:0 h 0米17.912秒

查看生成的代码没有优化。的D_Work结构是:

rtwdemodbtype (hfile“typedef struct {”,'}D_Work ',1,1);
typedef struct {real_T z [4096];real_T z_n [16384];real_T z_a [16384];}D_Work;

的部分DifferentSizeReuse.c是:

用= fullfile (“DifferentSizeReuse_ert_rtw”,“DifferentSizeReuse.c”);rtwdemodbtype(用“# include“DifferentSizeReuse.h””,“空白DifferentSizeReuse_initialize(空白)1 0);
# include“DifferentSizeReuse。h rtwtypes # include。h”# include <数学。h > D_Work rtDWork;ExternalInputs rtU;ExternalOutputs而无;静态RT_MODEL rtM_;RT_MODEL * const rtM = &rtM_;静态孔隙Downsample (const real_T rtu_u [16384], real_T rty_z [4096]);静态孔隙△(const real_T rtu_u [4096], real_T rty_z [4032]);静态孔隙δy (const real_T rtu_u [4032], real_T rty_z [3969]);静态孔隙NoninplaceableSS1(无效); static void NoninplaceableSS2(void); static void NoninplaceableSS3(void); static void Downsample(const real_T rtu_u[16384], real_T rty_z[4096]) { int32_T tmp; int32_T tmp_0; int32_T tmp_1; int32_T x; int32_T y; for (x = 0; x < 64; x++) { for (y = 0; y < 64; y++) { tmp_0 = (y + 1) << 1; tmp_1 = (x + 1) << 1; tmp = ((tmp_0 - 2) << 7) + tmp_1; tmp_0 = ((tmp_0 - 1) << 7) + tmp_1; rty_z[x + (y << 6)] = (((rtu_u[tmp - 2] + rtu_u[tmp - 1]) + rtu_u[tmp_0 - 2]) + rtu_u[tmp_0 - 1]) / 4.0; } } } static void NoninplaceableSS1(void) { Downsample(rtDWork.z_n, rtDWork.z); Downsample(rtDWork.z_a, &rtDWork.z_n[0]); } static void DeltaX(const real_T rtu_u[4096], real_T rty_z[4032]) { int32_T tmp; int32_T x; int32_T y; for (x = 0; x < 63; x++) { for (y = 0; y < 64; y++) { tmp = (y << 6) + x; rty_z[x + 63 * y] = fabs(rtu_u[tmp] - rtu_u[tmp + 1]); } } } static void NoninplaceableSS2(void) { DeltaX(rtDWork.z, &rtDWork.z_a[0]); DeltaX(&rtDWork.z_n[0], &rtDWork.z[0]); } static void DeltaY(const real_T rtu_u[4032], real_T rty_z[3969]) { int32_T i; for (i = 0; i < 3969; i++) { rty_z[i] = fabs(rtu_u[i] - rtu_u[i + 63]); } } static void NoninplaceableSS3(void) { DeltaY(&rtDWork.z_a[0], &rtDWork.z_n[0]); DeltaY(&rtDWork.z[0], &rtDWork.z_a[0]); } void DifferentSizeReuse_step(void) { int32_T i; for (i = 0; i < 16384; i++) { rtDWork.z_n[i] = rtU.ComplexData[i].re; rtDWork.z_a[i] = rtU.ComplexData[i].im; } NoninplaceableSS1(); NoninplaceableSS2(); NoninplaceableSS3(); for (i = 0; i < 3969; i++) { rtY.Out1[i].re = rtDWork.z_n[i]; rtY.Out1[i].im = rtDWork.z_a[i]; } }

D_work现在结构包含三个全局变量,而不是八个全局变量的输入和输出Downsample,,δy。生成的代码使用这些变量的大小不同的输入和输出。

关闭模型和代码生成报告。

bdclose rtwdemoclean(模型);

限制

  • 如果你使用一个可重用的定制的存储类指定重用信号有不同的大小和形状,你必须选择重用缓冲区的大小和尺寸参数。否则,不建立模型。

  • 代码生成器以较低的优先级不能代替一个缓冲缓冲区小一号。

  • 代码生成器并不重用缓冲区有不同的大小和符号维度。

另请参阅

相关的话题