Skip to content

Commit

Permalink
1) Added logical support in Matlab host - otherwise, logicals were tr…
Browse files Browse the repository at this point in the history
…eated as "false"

2) Changed command syntax for profiler intergation in mex call classes
3) Modified the generic Matlab profiler functions to be clear and simple to use
  • Loading branch information
hkbinaurics committed Feb 23, 2024
1 parent 6d50ed7 commit 36dfcd7
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
function hdl_profile_data = jvxProfileNeleConfig()
hdl_profile_data = [];

% Allocate Debug handle
hdl = [];
hdl.hooks.inUse = false;

global hdl_profile_data;
if(~isempty(hdl_profile_data))
function hdl = jvxProfileConfig(hdl)

initHooks = false;
if(~isempty(hdl))
if( ...
(isfield(hdl_profile_data, 'cfg')) && ...
(isfield(hdl_profile_data, 'start')) && ...
(isfield(hdl_profile_data, 'step')) && ...
(isfield(hdl_profile_data, 'stop')))
hdl.hooks.init = hdl_profile_data;
hdl.hooks.inUse = true;
(isfield(hdl, 'cfg')) && ...
(isfield(hdl, 'start')) && ...
(isfield(hdl, 'step')) && ...
(isfield(hdl, 'stop')))
initHooks = true;
end
end

if(initHooks)
hdl.hooks.init = hdl;
hdl.hooks.inUse = true;
else
hdl.hooks.inUse = false;
end

% Set test points to "none" by default
hdl.cfg = [];
hdl.cfg.tokenTp.SELECTION_BITFIELD = '0x0';

if(hdl.hooks.inUse == true)
[hdl] = hdl.hooks.init.cfg(hdl);
else
else
warning('We need to set the profiling configuration here!');
end

warning('Populate <hdl.cfg.tokenTp> at this point to control the degree of debug output!');
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [hdl_profile_data] = jvxProfileNeleStart(hdl_profile_data)
function [hdl] = jvxProfileStart(hdl)

global inProcessing;
hdl.nFrames = inProcessing.in_frames;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [hdl_profile_data] = jvxProfileNeleStep(hdl_profile_data)
function [hdl] = jvxProfileStep(hdl)

% Get the frame count
global inProcessing;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function jvxProfileNeleStop(hdl_profile_data)
function jvxProfileStop(hdl)

runAnyway = false;
if(hdl.hooks.inUse == true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
jvxUInt32* dat_uint32 = NULL;
jvxUInt16* dat_uint16 = NULL;
jvxUInt8* dat_uint8 = NULL;
mxLogical* dat_logical = NULL;

jvxData* jvx_data = NULL;
jvxInt64* jvx_int64 = NULL;
Expand Down Expand Up @@ -95,6 +96,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
dat_uint8 = (jvxUInt8*)mxGetData(prhs);
}
else if (mxIsLogical(prhs))
{
dat_logical = (mxLogical*)mxGetData(prhs);
}

// Now, convert
switch (format)
Expand Down Expand Up @@ -167,6 +172,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint32, jvx_data, N, jvxData, );
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_data, N, jvxData, );
}
else if (dat_uint16)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_data, N, jvxData, );
Expand Down Expand Up @@ -210,6 +219,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint32, jvx_sz, N, jvxData, JVX_DATA2SIZE);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_sz, N, jvxSize, );
}
else if (dat_uint16)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_sz, N, jvxData, JVX_DATA2SIZE);
Expand Down Expand Up @@ -257,6 +270,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_int64, N, jvxData, JVX_DATA2INT64);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_int64, N, jvxInt64, );
}
else if (dat_uint8)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint8, jvx_int64, N, jvxData, JVX_DATA2INT64);
Expand Down Expand Up @@ -300,6 +317,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_int32, N, jvxData, JVX_DATA2INT32);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_int32, N, jvxInt32, );
}
else if (dat_uint8)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint8, jvx_int32, N, jvxData, JVX_DATA2INT32);
Expand Down Expand Up @@ -343,6 +364,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP_LIM(failedTransfer, dat_uint16, jvx_int16, N, jvxData, JVX_DATA2INT16, 0x7FFF, -0x7FFF);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_int16, N, jvxInt16, );
}
else if (dat_uint8)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint8, jvx_int16, N, jvxData, JVX_DATA2INT16);
Expand Down Expand Up @@ -382,6 +407,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP_LIM(failedTransfer, dat_uint32, jvx_int8, N, jvxData, JVX_DATA2INT8, 0x7F, -0x7F);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_int8, N, jvxInt8, );
}
else if (dat_uint16)
{
JVX_CONVERSION_LOOP_LIM(failedTransfer, dat_uint16, jvx_int8, N, jvxData, JVX_DATA2INT8, 0x7F, -0x7F);
Expand Down Expand Up @@ -430,6 +459,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_uint64, N, jvxData, JVX_DATA2UINT64);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_uint64, N, jvxUInt64, );
}
else if (dat_uint8)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint8, jvx_uint64, N, jvxData, JVX_DATA2UINT64);
Expand Down Expand Up @@ -473,6 +506,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_uint32, N, jvxData, JVX_DATA2UINT32);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_uint32, N, jvxUInt32, );
}
else if (dat_uint8)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint8, jvx_uint32, N, jvxData, JVX_DATA2UINT32);
Expand Down Expand Up @@ -512,6 +549,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP_LIM(failedTransfer, dat_uint32, jvx_uint16, N, jvxData, JVX_DATA2UINT16, 0xFFFF, 0);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_uint16, N, jvxUInt16, );
}
else if (dat_uint16)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_uint16, jvx_uint16, N, jvxUInt16, );
Expand Down Expand Up @@ -555,6 +596,10 @@ CjvxMatlabToCConverter::convert_mat_buf_c_buf_1_x_N(jvxHandle* data_setprops, jv
{
JVX_CONVERSION_LOOP_LIM(failedTransfer, dat_uint32, jvx_uint8, N, jvxData, JVX_DATA2UINT8, 0xFF, 0);
}
else if (dat_logical)
{
JVX_CONVERSION_LOOP(failedTransfer, dat_logical, jvx_uint8, N, jvxUInt8, );
}
else if (dat_uint16)
{
JVX_CONVERSION_LOOP_LIM(failedTransfer, dat_uint16, jvx_uint8, N, jvxData, JVX_DATA2INT8, 0xFF, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class CjvxMexCallsProfileTpl : public CjvxMexCallsTpl<T>, public CjvxMexCallsPro
protected:
struct
{
jvxCBool skipInvolveCCode = c_false;
jvxBool matlab_profiling_enabled = false;
jvxCBool skip_involve_ccode = c_false;
jvxCBool matlab_profiling_enabled = c_false;
} config;

//! temporary fields for parallel processing C and Matlab
Expand Down Expand Up @@ -116,6 +116,11 @@ class CjvxMexCallsProfileTpl : public CjvxMexCallsTpl<T>, public CjvxMexCallsPro
jvxBool engaged = false;
jvxBool skipCCode = false;

if (config.skip_involve_ccode)
{
skipCCode = true;
}

// Pass control to Matlab processing

// Check if checkbox in Matlab processing was checked
Expand All @@ -138,12 +143,7 @@ class CjvxMexCallsProfileTpl : public CjvxMexCallsTpl<T>, public CjvxMexCallsPro
{
// Run this command only once!! Need to put it here since processing information is not available in "prepare"!!
CjvxMexCallsProfiler::profile_start_in_process();
}

if (config.skipInvolveCCode)
{
skipCCode = true;
}
}

if (!skipCCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ CjvxMexCallsProfiler::profile_config_on_prepare()
jvxErrorType res = JVX_NO_ERROR;
jvxErrorType resM = JVX_NO_ERROR;
debugStartDone = false;
std::string command = "global " + CjvxMexCallsProfiler::varNameHdlMatlab + "; " + CjvxMexCallsProfiler::varNameHdlMatlab + " = " + CjvxMexCallsProfiler::commandProfileConfig + "(); ";
std::string command = "global " + CjvxMexCallsProfiler::varNameHdlMatlab + "; " +
CjvxMexCallsProfiler::varNameHdlMatlab + " = " +
CjvxMexCallsProfiler::commandProfileConfig + "(" + CjvxMexCallsProfiler::varNameHdlMatlab + "); ";
resM = _theExtCallHandler->executeExternalCommand(command.c_str());
if (resM != JVX_NO_ERROR)
{
Expand Down

0 comments on commit 36dfcd7

Please sign in to comment.