Is there a way to turn off function specialization for a function or all functions

5 visualizaciones (últimos 30 días)
I do not want any function specialization as I'm targeting code generation for a small memory footprint. Is there a way to turn this off for all fucntions in a project, or for all invocations of a function?
There is coder.ignoreSize and coder.ignoreConst but it requires modifying each invocation of a function to add the coder.ignoreSize or coder.ignoreConst.

Respuesta aceptada

Denis Gurchenkov
Denis Gurchenkov el 16 de Ag. de 2022
Hi Nathan, no, unfortunately there is no blanket way to do so.
Specialization happens in 3 cases:
  • Calls to a function with inputs of different types (like foo(1) vs foo('hello')). Those are unavoidable.
  • Calls to a function with inputs of different sizes. This you can prevent by coder.ignoreSize at call sites. You can create a thin wrapper on the function that contains ignore size and calls the main function, so you don't have to modify each call site.
  • Calls to a function with constant inputs of different values (that's where you'd use ignoreConst). This should not happen unless the function really needs those constant inputs.
If you are able to attach an example shoing the pain, what kind of function you have and how it gets unnecesarily specialized, I can pass this to the development team and ask to take into consideration. But for a quick workaround, unfortunately, creating thin wrappers that use coder.ignoreSize and/or Const are the only optins I can think of.
  2 comentarios
Nathan Royer
Nathan Royer el 16 de Ag. de 2022
I'm having a function where I pass in a struct. Coder is creating an API that takes individual values of the struct and adding them to the API:
% Structure that gets passed into cnsf_fuse_calibrated_data
pdata = struct('sample_period', struct('accel', 0.01, 'gyro', 0.01, 'mag', 0.01), ...
'stamped_cal_est', struct('value', 0, 'value2', 0, 'etc', 0), ...
'mi_st', struct('value1', 0, 'etc', 0), .. ...
'q_last', [1 0 0 0], 'g_last', [0 0 0]);
% API for cnsf_fuse_calibrated_data
function [quaternion] = cnsf_fuse_calibrated_data(pdata, ...
accel_timestamp, gyro_timestamp, mag_timestamp, ...
calibrated_accel, calibrated_gyro, calibrated_mag, ...
motion_intensity, mag_consistency)
% code here
end
Then coder generates the following two functions for me:
/* Generated from an internal function call */
void b_cnsf_fuse_calibrated_data(
float pdata_sample_period_gyro,
const stamped_cal_est_t *pdata_stamped_cal_est, const mi_st_t *pdata_mi_st,
const float pdata_q_last[4], const float pdata_g_last[3],
const float accel_timestamp_data[], int accel_timestamp_size,
const float gyro_timestamp_data[], const float mag_timestamp_data[],
int mag_timestamp_size, const float calibrated_accel_data[],
const int calibrated_accel_size[2], const float calibrated_gyro_data[],
const int calibrated_gyro_size[2], const float calibrated_mag_data[],
const int calibrated_mag_size[2], const float motion_intensity_data[],
const float mag_consistency_data[], float quaternion_data[],
int quaternion_size[2]);
/* generated from codegen command line */
extern void cnsf_fuse_calibrated_data(
const cnsf_pdata_t *pdata, const float accel_timestamp_data[],
const int accel_timestamp_size[1], const float gyro_timestamp_data[],
const int gyro_timestamp_size[1], const float mag_timestamp_data[],
const int mag_timestamp_size[1], const float calibrated_accel_data[],
const int calibrated_accel_size[2], const float calibrated_gyro_data[],
const int calibrated_gyro_size[2], const float calibrated_mag_data[],
const int calibrated_mag_size[2], const float motion_intensity_data[],
const int motion_intensity_size[1], const float mag_consistency_data[],
const int mag_consistency_size[1], float quaternion_data[],
int quaternion_size[2]);
I want only the second function.
Jon
Jon el 5 de Mayo de 2023
Nathan, I realize this is probably too late for you ... but today I learned about the undocumented config argument cfg.EnableStructExplosion which prevents just this sort of thing.
(I think in your case, having your function defined as an entry point would also allow you to specify the exact API.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre C Shared Library Integration en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by