Skip to content

Commit

Permalink
Added support for CMSIS Event Recorder to the Compute Graph.
Browse files Browse the repository at this point in the history
Added also more customization options for the compute graph.
  • Loading branch information
christophe0606 committed Sep 20, 2022
1 parent 142dcec commit b817710
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 37 deletions.
1 change: 1 addition & 0 deletions ARM.CMSIS-DSP.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<file category="header" name="ComputeGraph/cg/static/src/GenericNodes.h"/>
<file category="include" name="ComputeGraph/cg/static/nodes/cpp/"/>
<file category="include" name="ComputeGraph/cg/static/src/"/>
<file category="other" name="ComputeGraph/cg.scvd" />
</files>
</component>
</components>
Expand Down
48 changes: 48 additions & 0 deletions ComputeGraph/cg.scvd
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Project: CMSIS DSP Library
Title: cg.SCVD
Description: Event definitions for use in Keil MDK
$Date: 19 September 2022
Target Processor: Cortex-M and Cortex-A cores
Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the License); you may
not use this file except in compliance with the License.
You may obtain a copy of the License at
www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
<component name="CMSIS-DSP Compute Graph" version="1.0.0"/> <!-- name and version of the component -->

<events>
<group name="CMSIS-DSP Compute Graph">
<component name="Scheduler" brief="CG" no="0x01" prefix="EvrSchedCG_" info="CG Static Scheduler"/>
</group>

<event id="0x0100 + 0x00" level="API" property="ScheduleIteration" info="New iteration of scheduling loop" value="nb=%d[val1]" />

<event id="0x0100 + 0x01" level="API" property="NodeExecution" info="Execution of a node" value="ID=%d[val1]" />

<event id="0x0100 + 0x02" level="NodeError" property="Error" info="Error during execution of a node" value="err=%d[val1]" />


</events>

</component_viewer>
9 changes: 9 additions & 0 deletions ComputeGraph/cg/static/src/GenericNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,13 @@ class Duplicate3<IN,inputSize,
}

#endif

#if !defined(CG_BEFORE_ITERATION)
#define CG_BEFORE_ITERATION
#endif

#if !defined(CG_AFTER_ITERATION)
#define CG_AFTER_ITERATION
#endif

#endif
1 change: 1 addition & 0 deletions ComputeGraph/documentation/example1.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ There are other fields for the configuration:
- `memoryOptimization` : Experimental. It is attempting to reuse buffer memory and share it between several FIFOs
- `pathToSDFModule` : Path to the Python SDF module so that the generated Python code can find it
- `codeArray` : Experimental. When a schedule is very long, representing it as a sequence of function calls is not good for the code size of the generated solution. When this option is enabled, the schedule is described with an array. It implies that the pure function calls cannot be inlined any more and are replaced by new nodes which are automatically generated.
- `eventRecorder` : Enable the support for the CMSIS Event Recorder.

In the example 1, we are passing a variable to initialize the node of type ProcessingNode. So, it would be great if this variable was an argument of the scheduler function. So we define:

Expand Down
1 change: 1 addition & 0 deletions Scripts/git/gen_pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ PACK_BASE_FILES="
ComputeGraph/cg/static/nodes/cpp/ToReal.h
ComputeGraph/cg/static/nodes/cpp/Unzip.h
ComputeGraph/cg/static/nodes/cpp/Zip.h
ComputeGraph/cg.scvd
"

# Specify file names to be deleted from pack build directory
Expand Down
2 changes: 1 addition & 1 deletion cmsisdsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


# CMSIS-DSP Commit hash used to build the wrapper
commit_hash="89610e31cbb3c67067f5bfbcacb338fd7910023e"
commit_hash="142dcec5c333781c2299fe43824545cc57a5bcb0"

# True if development version of CMSIS-DSP used
# (So several CMSIS-DSP versions may have same version number hence the commit hash)
Expand Down
4 changes: 2 additions & 2 deletions cmsisdsp/cg/static/scheduler/ccode.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def gencode(sched,directory,config):
htemplate = env.get_template("code.h")


cfile=os.path.join(directory,"scheduler.cpp")
hfile=os.path.join(directory,"scheduler.h")
cfile=os.path.join(directory,"%s.cpp" % config.schedulerCFileName)
hfile=os.path.join(directory,"%s.h" % config.schedulerCFileName)

nbFifos = len(sched._graph._allFIFOs)

Expand Down
15 changes: 15 additions & 0 deletions cmsisdsp/cg/static/scheduler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def __init__(self):
# Display FIFO buffers in graph instead of datatype
self.displayFIFOBuf = False

# Enable support for CMSIS Event Recorder
self.eventRecorder = False

# Name of AppNode file
self.appNodesCName = "AppNodes.h"
self.appNodesPythonName = "appnodes"

# Name of custom file
self.customCName = "custom.h"
self.customPythonName = "custom"

# Name of scheduler source and header files
self.schedulerCFileName = "scheduler"
self.schedulerPythonFileName = "sched"


@property
def debug(self):
Expand Down
2 changes: 1 addition & 1 deletion cmsisdsp/cg/static/scheduler/pythoncode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def gencode(sched,directory,config):

template = env.get_template("code.py")

cfile=os.path.join(directory,"sched.py")
cfile=os.path.join(directory,"sched.py" % config.schedulerPythonFileName)


with open(cfile,"w") as f:
Expand Down
36 changes: 14 additions & 22 deletions cmsisdsp/cg/static/scheduler/templates/code.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
{% extends "commonc.cpp" %}
/*
Generated with CMSIS-DSP Compute Graph Scripts.
The generated code is not covered by CMSIS-DSP license.
The support classes and code is covered by CMSIS-DSP license.
*/

{% if config.dumpFIFO %}
#define DEBUGSCHED 1
{% endif %}

#include "arm_math.h"
#include "custom.h"
#include "GenericNodes.h"
#include "AppNodes.h"
#include "scheduler.h"

{% macro optionalargs() -%}
{% if config.cOptionalArgs %},{{config.cOptionalArgs}}{% endif %}
{% endmacro -%}

{% block schedArray %}
{% endblock %}
Expand All @@ -33,8 +11,21 @@ The support classes and code is covered by CMSIS-DSP license.
{% endif %}
{
/* Run a schedule iteration */
{% if config.eventRecorder -%}
EventRecord2 (Evt_Scheduler, nbSchedule, 0);
{% endif -%}
CG_BEFORE_ITERATION;
{% for s in schedule %}
{% if config.eventRecorder -%}
EventRecord2 (Evt_Node, {{nodes[s].codeID}}, 0);
{% endif -%}
{{nodes[s].cRun()}}
{% if config.eventRecorder -%}
if (cgStaticError<0)
{
EventRecord2 (Evt_Error, cgStaticError, 0);
}
{% endif -%}
CHECKERROR;
{% if config.dumpFIFO %}
{% for fifoID in sched.outputFIFOs(nodes[s]) %}
Expand All @@ -47,6 +38,7 @@ The support classes and code is covered by CMSIS-DSP license.
{% if config.debug %}
debugCounter--;
{% endif %}
CG_AFTER_ITERATION;
nbSchedule++;
}

Expand Down
11 changes: 11 additions & 0 deletions cmsisdsp/cg/static/scheduler/templates/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ extern "C"
{
#endif

{% if config.eventRecorder %}
#include "EventRecorder.h"

#define EvtSched 0x01

#define Evt_Scheduler EventID (EventLevelAPI, EvtSched, 0x00)
#define Evt_Node EventID (EventLevelAPI, EvtSched, 0x01)
#define Evt_Error EventID (EventLevelError, EvtSched, 0x02)

{% endif %}

extern uint32_t {{config.schedName}}(int *error{{optionalargs()}});

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions cmsisdsp/cg/static/scheduler/templates/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import numpy as np
import cmsisdsp as dsp
from cmsisdsp.cg.static.nodes.simu import *
from appnodes import *
from custom import *
from {{config.appNodesPythonName}} import *
from {{config.customPythonName}} import *

{% macro optionalargs() -%}
{% if config.pyOptionalArgs %}{{config.pyOptionalArgs}}{% endif %}
Expand Down
20 changes: 17 additions & 3 deletions cmsisdsp/cg/static/scheduler/templates/codeArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ The support classes and code is covered by CMSIS-DSP license.
{% endif %}

#include "arm_math.h"
#include "custom.h"
#include "{{config.customCName}}"
#include "GenericNodes.h"
#include "AppNodes.h"
#include "scheduler.h"
#include "{{config.appNodesCName}}"
#include "{{config.schedulerCFileName}}.h"

{% macro optionalargs() -%}
{% if config.cOptionalArgs %},{{config.cOptionalArgs}}{% endif %}
Expand Down Expand Up @@ -116,15 +116,29 @@ uint32_t {{config.schedName}}(int *error{{optionalargs()}})
{% endif %}
{
/* Run a schedule iteration */
{% if config.eventRecorder -%}
EventRecord2 (Evt_Scheduler, nbSchedule, 0);
{% endif -%}
CG_BEFORE_ITERATION;
for(unsigned long id=0 ; id < {{schedLen}}; id++)
{
unsigned int nodeId = schedule[id];
{% if config.eventRecorder -%}
EventRecord2 (Evt_Node, nodeId, 0);
{% endif -%}
cgStaticError = nodeArray[nodeId]->run();
{% if config.eventRecorder -%}
if (cgStaticError<0)
{
EventRecord2 (Evt_Error, cgStaticError, 0);
}
{% endif -%}
CHECKERROR;
}
{% if config.debug %}
debugCounter--;
{% endif %}
CG_AFTER_ITERATION;
nbSchedule++;
}

Expand Down
19 changes: 17 additions & 2 deletions cmsisdsp/cg/static/scheduler/templates/codeSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,40 @@ static unsigned int schedule[{{schedLen}}]=
{% endif %}
{
/* Run a schedule iteration */
{% if config.eventRecorder -%}
EventRecord2 (Evt_Scheduler, nbSchedule, 0);
{% endif -%}
CG_BEFORE_ITERATION;
for(unsigned long id=0 ; id < {{schedLen}}; id++)
{
{% if config.eventRecorder -%}
EventRecord2 (Evt_Node, schedule[id], 0);
{% endif -%}
switch(schedule[id])
{
{% for nodeID in range(nbNodes) -%}
case {{nodeID}}:
{
{{nodes[nodeID].cRun()}}
CHECKERROR;
}
break;

{% endfor %}default:
{% endfor -%}
default:
break;
}
{% if config.eventRecorder -%}
if (cgStaticError<0)
{
EventRecord2 (Evt_Error, cgStaticError, 0);
}
{% endif -%}
CHECKERROR;
}
{% if config.debug %}
debugCounter--;
{% endif %}
CG_AFTER_ITERATION;
nbSchedule++;
}

Expand Down
8 changes: 5 additions & 3 deletions cmsisdsp/cg/static/scheduler/templates/commonc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ The support classes and code is covered by CMSIS-DSP license.
{% endif %}

#include "arm_math.h"
#include "custom.h"
#include "{{config.customCName}}"
#include "GenericNodes.h"
#include "AppNodes.h"
#include "scheduler.h"
#include "{{config.appNodesCName}}"
#include "{{config.schedulerCFileName}}.h"



{% macro optionalargs() -%}
{% if config.cOptionalArgs %},{{config.cOptionalArgs}}{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion cmsisdsp/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Python wrapper version
__version__ = "1.7.1"
__version__ = "1.8.0"

0 comments on commit b817710

Please sign in to comment.