Skip to content

Commit

Permalink
Generalized matlab host profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
hkhauke committed Feb 7, 2024
1 parent cfc20d9 commit 0fce9f3
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 21 deletions.
1 change: 1 addition & 0 deletions sources/jvxLibraries/jvx-dsp-base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(LOCAL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/jvx_matrix/jvx_matrix.c
${CMAKE_CURRENT_SOURCE_DIR}/src/jvx_matrix/jvx_matrix_mult.c
${CMAKE_CURRENT_SOURCE_DIR}/src/jvx_matrix/jvx_matrix_rot.c
${CMAKE_CURRENT_SOURCE_DIR}/src/jvx_profiler/jvx_profiler_data_entry.c

${CMAKE_CURRENT_SOURCE_DIR}/src/jvx_conv/jvx_conv.c
${CMAKE_CURRENT_SOURCE_DIR}/include/jvx_conv/jvx_conv.h
Expand Down
14 changes: 7 additions & 7 deletions sources/jvxLibraries/jvx-dsp-base/include/jvx_dsp_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#define JVX_DSP_DATA_FORMAT_DOUBLE
#endif

//! Shortcut for complex datatypes, actually defined to support fftw
typedef struct
{
jvxData re;
jvxData im;
} jvxDataCplx;

#define jvxDspBaseErrorType jvxErrorType

#define JVX_DSP_NO_ERROR JVX_NO_ERROR
Expand Down Expand Up @@ -76,11 +83,4 @@
#define JVX_DSP_UPDATE_ALL16 JVX_LIB_UPDATE_ALL16
#define JVX_DSP_UPDATE_ALL32 JVX_LIB_UPDATE_ALL32

//! Shortcut for complex datatypes, actually defined to support fftw
typedef struct
{
jvxData re;
jvxData im;
} jvxDataCplx;

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __JVX_PROFILER_DATA_ENTRY_H__
#define __JVX_PROFILER_DATA_ENTRY_H__

#include "jvx_dsp_base.h"

struct jvx_profiler_data_entry
{
jvxSize sz;
jvxHandle* fld;
jvxCBool cplx;
};

typedef jvxErrorType(*jvx_register_entry_profiling_data_c)(struct jvx_profiler_data_entry* dat, const char* name, jvxHandle* inst);
typedef jvxErrorType(*jvx_unregister_entry_profiling_data_c)(const char* name, jvxHandle* inst);

void jvx_profiler_allocate_single_entry(struct jvx_profiler_data_entry* entry, jvxSize szFld, jvxCBool cplxFld);
void jvx_profiler_deallocate_single_entry(struct jvx_profiler_data_entry* entry);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "jvx_profiler/jvx_profiler_data_entry.h"

void jvx_profiler_allocate_single_entry(struct jvx_profiler_data_entry* entry, jvxSize szFld, jvxCBool cplxFld)
{
entry->sz = szFld;
entry->cplx = cplxFld;
assert(entry->fld == NULL);
if (entry->cplx)
{
JVX_DSP_SAFE_ALLOCATE_FIELD_Z(entry->fld, jvxDataCplx, entry->sz);
}
else
{
JVX_DSP_SAFE_ALLOCATE_FIELD_Z(entry->fld, jvxData, entry->sz);
}
}

void jvx_profiler_deallocate_single_entry(struct jvx_profiler_data_entry* entry)
{
JVX_DSP_SAFE_DELETE_FIELD(entry->fld);
entry->sz = 0;
entry->cplx = false;
}
3 changes: 3 additions & 0 deletions sources/jvxLibraries/jvxLexternalCall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include_directories(
set(LOCAL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/CjvxMexCalls.h
${CMAKE_CURRENT_SOURCE_DIR}/include/CjvxMexCallsTpl.h
${CMAKE_CURRENT_SOURCE_DIR}/include/CjvxMexCallsProfiler.h

${CMAKE_CURRENT_SOURCE_DIR}/src/CjvxMexCalls.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CjvxMexCalls_prv.cpp
Expand All @@ -23,7 +24,9 @@ set(LOCAL_MCG_FILES
)

set(LOCAL_SOURCES
${LOCAL_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/src/CjvxMexCalls.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CjvxMexCallsProfiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CjvxMexCalls_prv.cpp
${LOCAL_MCG_FILES}
${LOCAL_PCG_FILES}
Expand Down
16 changes: 2 additions & 14 deletions sources/jvxLibraries/jvxLexternalCall/include/CjvxMexCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@

#include "jvx.h"
#include "common/CjvxProperties.h"
#include "CjvxMexCallsProfiler.h"

/**
* Class to share external call handler instance between component and core mexcall handler
*///===============================================================================

class CjvxMexCallsMin
{
public:
// Reference to matlab call handler to be used throughout the components life time
// Shared between inernal and external use
IjvxExternalCall* _theExtCallHandler = nullptr;
std::string _theExtCallObjectName;

};

/**
* Class to encapsulate mexcall functoionality for integration in various classes
*///===============================================================================

class CjvxMexCalls: public IjvxExternalCallTarget, public CjvxMexCallsMin
class CjvxMexCalls: public IjvxExternalCallTarget, public CjvxMexCallsProfiler
{

private:
Expand Down
13 changes: 13 additions & 0 deletions sources/jvxLibraries/jvxLexternalCall/include/CjvxMexCallsMin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Class to share external call handler instance between component and core mexcall handler
*///===============================================================================

class CjvxMexCallsMin
{
public:
// Reference to matlab call handler to be used throughout the components life time
// Shared between inernal and external use
IjvxExternalCall* _theExtCallHandler = nullptr;
std::string _theExtCallObjectName;

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __CJVXMEXCALLSPROFILER__H__
#define __CJVXMEXCALLSPROFILER__H__

#include "jvx.h"
#include "CjvxMexCallsMin.h"

#include "jvx_profiler/jvx_profiler_data_entry.h"

class CjvxMexCallsProfiler: public CjvxMexCallsMin
{
protected:
std::string varNameHdlMatlab = "hdl_profile_data";
public:
std::map<std::string, jvx_profiler_data_entry*> registeredProfilerData;
jvxErrorType register_profiling_data(jvx_profiler_data_entry*, const std::string& nm);
jvxErrorType unregister_profiling_data(const std::string& nm);
jvxErrorType provideDataMexCall();
static jvxErrorType jvx_register_entry_profiling_data_cb(jvx_profiler_data_entry* dat, const char* name, jvxHandle* inst);
static jvxErrorType jvx_unregister_entry_profiling_data_cb(const char* name, jvxHandle* inst);
};

#endif
86 changes: 86 additions & 0 deletions sources/jvxLibraries/jvxLexternalCall/src/CjvxMexCallsProfiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "CjvxMexCallsProfiler.h"

#define AYF_COPY_TPX(fld, sz, nm, cplx) \


#define AYF_COPY_TPX_STR(entry, nm) \
AYF_COPY_TPX(entry->fld, entry->sz, nm, entry.cplx)

jvxErrorType
CjvxMexCallsProfiler::register_profiling_data(jvx_profiler_data_entry * data, const std::string& nm)
{
auto elm = registeredProfilerData.find(nm);
if (elm == registeredProfilerData.end())
{
registeredProfilerData[nm] = data;
return JVX_NO_ERROR;
}
return JVX_ERROR_DUPLICATE_ENTRY;
}

jvxErrorType
CjvxMexCallsProfiler::unregister_profiling_data(const std::string& nm)
{
auto elm = registeredProfilerData.find(nm);
if (elm != registeredProfilerData.end())
{
registeredProfilerData.erase(elm);
return JVX_NO_ERROR;
}
return JVX_ERROR_ELEMENT_NOT_FOUND;
}

jvxErrorType
CjvxMexCallsProfiler::provideDataMexCall()
{
jvxExternalDataType* passToMatlab = NULL;
for (auto& elm : registeredProfilerData)
{
if (elm.second->fld)
{
_theExtCallHandler->convertCToExternal(&passToMatlab, elm.second->fld,
elm.second->sz, JVX_DATAFORMAT_DATA, elm.second->cplx);
if (passToMatlab)
{
_theExtCallHandler->putVariableToExternal("caller", elm.first.c_str(), passToMatlab);
std::string command = "global " + varNameHdlMatlab + "; " + varNameHdlMatlab + ".tp.";
command += elm.first;
command += " = ";
command += elm.first;
command += ";";
jvxErrorType resCommand = _theExtCallHandler->executeExternalCommand(command.c_str());
if (resCommand != JVX_NO_ERROR)
{
jvxApiString astr;
_theExtCallHandler->getLastErrorReason(&astr);
_theExtCallHandler->postMessageExternal(("Last operation <" + command + "> failed, reason: <" + astr.std_str() + ">.").c_str(), true);
}
}
}
}
return JVX_NO_ERROR;
}

jvxErrorType
CjvxMexCallsProfiler::jvx_register_entry_profiling_data_cb(jvx_profiler_data_entry* dat, const char* name, jvxHandle* inst)
{
if (inst)
{
CjvxMexCallsProfiler* this_pointer = (CjvxMexCallsProfiler*)inst;
return this_pointer->register_profiling_data(dat, name);
}
return JVX_ERROR_INVALID_ARGUMENT;
}

jvxErrorType
CjvxMexCallsProfiler::jvx_unregister_entry_profiling_data_cb(const char* name, jvxHandle* inst)
{
if (inst)
{
CjvxMexCallsProfiler* this_pointer = (CjvxMexCallsProfiler*)inst;
return this_pointer->unregister_profiling_data(name);
}
return JVX_ERROR_INVALID_ARGUMENT;
}


0 comments on commit 0fce9f3

Please sign in to comment.