이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.
다른 크기와 차원의 버퍼 재사용
R2026b크기와 형태가 서로 다른 행렬의 버퍼를 재사용할 수 있습니다. '구성 파라미터' 대화 상자에서 다른 크기와 차원의 버퍼 재사용을 선택하면 이 최적화 기능을 활성화할 수 있습니다. 이 최적화는 RAM 및 ROM 사용량을 줄이고 코드 실행 속도를 향상시킵니다.
예제 모델
DifferentSizeReuse 모델에는 크기와 차원이 서로 다른 신호들이 포함되어 있습니다.
model='DifferentSizeReuse';
open_system(model);

최적화 없이 코드 생성하기
‘구성 파라미터’ 대화 상자에서 크기와 차원이 다른 버퍼 재사용 파라미터를 off로 설정하거나, MATLAB® 명령 창에 다음을 입력하십시오:
set_param('DifferentSizeReuse','DifferentSizesBufferReuse','off');
주석 기능을 끄고 모델을 빌드합니다.
set_param('DifferentSizeReuse','GenerateComments','off'); slbuild('DifferentSizeReuse');
### Searching for referenced models in model 'DifferentSizeReuse'. ### Total of 1 models to build. ### Starting top model code generation target build for: DifferentSizeReuse ### Successful completion of build procedure for: DifferentSizeReuse Build Summary Top model targets: Model Build Reason Status Build Duration ============================================================================================================== DifferentSizeReuse Target (DifferentSizeReuse.c) did not exist. Code generated and compiled. 0h 0m 13.051s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 13.483s
최적화가 적용되지 않은 생성 코드를 확인합니다. D_Work 구조체는 다음과 같습니다:
hfile = fullfile('DifferentSizeReuse_ert_rtw',... 'DifferentSizeReuse.h'); coder.example.extractLines(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의 해당 부분은 다음과 같습니다:
cfile = fullfile('DifferentSizeReuse_ert_rtw',... 'DifferentSizeReuse.c'); coder.example.extractLines(cfile,'#include "DifferentSizeReuse.h"',... 'void DifferentSizeReuse_initialize(void)',1,0);
#include "DifferentSizeReuse.h"
#include "rtwtypes.h"
#include <math.h>
D_Work rtDWork;
ExternalInputs rtU;
ExternalOutputs rtY;
static RT_MODEL rtM_;
RT_MODEL *const rtM = &rtM_;
static void Downsample(const real_T rtu_u[16384], real_T rty_z[4096]);
static void DeltaX(const real_T rtu_u[4096], real_T rty_z[4032]);
static void DeltaY(const real_T rtu_u[4032], real_T rty_z[3969]);
static void NoninplaceableSS1(void);
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, DeltaX 및 DeltaY의 입력값과 출력값을 저장하기 위한 8개의 전역 변수가 포함되어 있습니다. 이 변수들의 크기는 서로 다릅니다.
최적화를 적용하여 코드 생성
'구성 파라미터' 대화 상자에서 신호 저장공간 재사용이 선택되어 있는지 확인하십시오.
다른 크기와 차원의 버퍼 재사용 파라미터를
on로 설정하거나, MATLAB 명령 창에 다음을 입력하십시오:
set_param('DifferentSizeReuse','DifferentSizesBufferReuse','on');
모델을 빌드합니다.
set_param('DifferentSizeReuse','GenerateComments','off'); slbuild(model);
### Searching for referenced models in model 'DifferentSizeReuse'. ### Total of 1 models to build. ### Starting top model code generation target build for: DifferentSizeReuse ### Successful completion of build procedure for: DifferentSizeReuse Build Summary Top model targets: Model Build Reason Status Build Duration ========================================================================================================================== DifferentSizeReuse Model or library DifferentSizeReuse has unsaved changes. Code generated and compiled. 0h 0m 8.8097s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 9.3281s
최적화가 적용되지 않은 생성 코드를 확인합니다. D_Work 구조체는 다음과 같습니다:
coder.example.extractLines(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의 해당 부분은 다음과 같습니다:
cfile = fullfile('DifferentSizeReuse_ert_rtw',... 'DifferentSizeReuse.c'); coder.example.extractLines(cfile,'#include "DifferentSizeReuse.h"',... 'void DifferentSizeReuse_initialize(void)',1,0);
#include "DifferentSizeReuse.h"
#include "rtwtypes.h"
#include <math.h>
D_Work rtDWork;
ExternalInputs rtU;
ExternalOutputs rtY;
static RT_MODEL rtM_;
RT_MODEL *const rtM = &rtM_;
static void Downsample(const real_T rtu_u[16384], real_T rty_z[4096]);
static void DeltaX(const real_T rtu_u[4096], real_T rty_z[4032]);
static void DeltaY(const real_T rtu_u[4032], real_T rty_z[3969]);
static void NoninplaceableSS1(void);
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, DeltaX, DeltaY의 입력 및 출력을 저장하기 위해 8개의 전역 변수 대신 3개의 전역 변수가 포함되어 있습니다. 생성 코드에서는 이러한 변수들을 사용하여 크기가 서로 다른 입력과 출력을 저장합니다.
모델을 닫으십시오.
bdclose(model)
제한 사항
크기와 형태가 서로 다른 신호에 대해 재사용을 지정하기 위해
Reusable사용자 지정 스토리지 클래스를 사용하는 경우, 다른 크기와 차원의 버퍼 재사용 파라미터를 선택해야 합니다. 그렇지 않으면 모델이 빌드되지 않습니다.코드 생성기는 버퍼를 크기가 더 작고 우선순위가 낮은 버퍼로 대체하지 않습니다.
코드 생성기는 크기와 기호 차원이 서로 다른 버퍼를 재사용하지 않습니다.