Skip to content

Commit b817710

Browse files
Added support for CMSIS Event Recorder to the Compute Graph.
Added also more customization options for the compute graph.
1 parent 142dcec commit b817710

File tree

16 files changed

+146
-37
lines changed

16 files changed

+146
-37
lines changed

ARM.CMSIS-DSP.pdsc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<file category="header" name="ComputeGraph/cg/static/src/GenericNodes.h"/>
112112
<file category="include" name="ComputeGraph/cg/static/nodes/cpp/"/>
113113
<file category="include" name="ComputeGraph/cg/static/src/"/>
114+
<file category="other" name="ComputeGraph/cg.scvd" />
114115
</files>
115116
</component>
116117
</components>

ComputeGraph/cg.scvd

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Project: CMSIS DSP Library
5+
Title: cg.SCVD
6+
Description: Event definitions for use in Keil MDK
7+
8+
$Date: 19 September 2022
9+
10+
Target Processor: Cortex-M and Cortex-A cores
11+
12+
13+
Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.
14+
15+
SPDX-License-Identifier: Apache-2.0
16+
17+
Licensed under the Apache License, Version 2.0 (the License); you may
18+
not use this file except in compliance with the License.
19+
You may obtain a copy of the License at
20+
21+
www.apache.org/licenses/LICENSE-2.0
22+
23+
Unless required by applicable law or agreed to in writing, software
24+
distributed under the License is distributed on an AS IS BASIS, WITHOUT
25+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
See the License for the specific language governing permissions and
27+
limitations under the License.
28+
29+
-->
30+
31+
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
32+
<component name="CMSIS-DSP Compute Graph" version="1.0.0"/> <!-- name and version of the component -->
33+
34+
<events>
35+
<group name="CMSIS-DSP Compute Graph">
36+
<component name="Scheduler" brief="CG" no="0x01" prefix="EvrSchedCG_" info="CG Static Scheduler"/>
37+
</group>
38+
39+
<event id="0x0100 + 0x00" level="API" property="ScheduleIteration" info="New iteration of scheduling loop" value="nb=%d[val1]" />
40+
41+
<event id="0x0100 + 0x01" level="API" property="NodeExecution" info="Execution of a node" value="ID=%d[val1]" />
42+
43+
<event id="0x0100 + 0x02" level="NodeError" property="Error" info="Error during execution of a node" value="err=%d[val1]" />
44+
45+
46+
</events>
47+
48+
</component_viewer>

ComputeGraph/cg/static/src/GenericNodes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,13 @@ class Duplicate3<IN,inputSize,
389389
}
390390

391391
#endif
392+
393+
#if !defined(CG_BEFORE_ITERATION)
394+
#define CG_BEFORE_ITERATION
395+
#endif
396+
397+
#if !defined(CG_AFTER_ITERATION)
398+
#define CG_AFTER_ITERATION
399+
#endif
400+
392401
#endif

ComputeGraph/documentation/example1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ There are other fields for the configuration:
181181
- `memoryOptimization` : Experimental. It is attempting to reuse buffer memory and share it between several FIFOs
182182
- `pathToSDFModule` : Path to the Python SDF module so that the generated Python code can find it
183183
- `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.
184+
- `eventRecorder` : Enable the support for the CMSIS Event Recorder.
184185

185186
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:
186187

Scripts/git/gen_pack.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ PACK_BASE_FILES="
122122
ComputeGraph/cg/static/nodes/cpp/ToReal.h
123123
ComputeGraph/cg/static/nodes/cpp/Unzip.h
124124
ComputeGraph/cg/static/nodes/cpp/Zip.h
125+
ComputeGraph/cg.scvd
125126
"
126127

127128
# Specify file names to be deleted from pack build directory

cmsisdsp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

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

2828
# True if development version of CMSIS-DSP used
2929
# (So several CMSIS-DSP versions may have same version number hence the commit hash)

cmsisdsp/cg/static/scheduler/ccode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def gencode(sched,directory,config):
5858
htemplate = env.get_template("code.h")
5959

6060

61-
cfile=os.path.join(directory,"scheduler.cpp")
62-
hfile=os.path.join(directory,"scheduler.h")
61+
cfile=os.path.join(directory,"%s.cpp" % config.schedulerCFileName)
62+
hfile=os.path.join(directory,"%s.h" % config.schedulerCFileName)
6363

6464
nbFifos = len(sched._graph._allFIFOs)
6565

cmsisdsp/cg/static/scheduler/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ def __init__(self):
7474
# Display FIFO buffers in graph instead of datatype
7575
self.displayFIFOBuf = False
7676

77+
# Enable support for CMSIS Event Recorder
78+
self.eventRecorder = False
79+
80+
# Name of AppNode file
81+
self.appNodesCName = "AppNodes.h"
82+
self.appNodesPythonName = "appnodes"
83+
84+
# Name of custom file
85+
self.customCName = "custom.h"
86+
self.customPythonName = "custom"
87+
88+
# Name of scheduler source and header files
89+
self.schedulerCFileName = "scheduler"
90+
self.schedulerPythonFileName = "sched"
91+
7792

7893
@property
7994
def debug(self):

cmsisdsp/cg/static/scheduler/pythoncode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def gencode(sched,directory,config):
4040

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

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

4545

4646
with open(cfile,"w") as f:

cmsisdsp/cg/static/scheduler/templates/code.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
11
{% extends "commonc.cpp" %}
2-
/*
3-
4-
Generated with CMSIS-DSP Compute Graph Scripts.
5-
The generated code is not covered by CMSIS-DSP license.
6-
7-
The support classes and code is covered by CMSIS-DSP license.
8-
9-
*/
10-
11-
{% if config.dumpFIFO %}
12-
#define DEBUGSCHED 1
13-
{% endif %}
14-
15-
#include "arm_math.h"
16-
#include "custom.h"
17-
#include "GenericNodes.h"
18-
#include "AppNodes.h"
19-
#include "scheduler.h"
20-
21-
{% macro optionalargs() -%}
22-
{% if config.cOptionalArgs %},{{config.cOptionalArgs}}{% endif %}
23-
{% endmacro -%}
242

253
{% block schedArray %}
264
{% endblock %}
@@ -33,8 +11,21 @@ The support classes and code is covered by CMSIS-DSP license.
3311
{% endif %}
3412
{
3513
/* Run a schedule iteration */
14+
{% if config.eventRecorder -%}
15+
EventRecord2 (Evt_Scheduler, nbSchedule, 0);
16+
{% endif -%}
17+
CG_BEFORE_ITERATION;
3618
{% for s in schedule %}
19+
{% if config.eventRecorder -%}
20+
EventRecord2 (Evt_Node, {{nodes[s].codeID}}, 0);
21+
{% endif -%}
3722
{{nodes[s].cRun()}}
23+
{% if config.eventRecorder -%}
24+
if (cgStaticError<0)
25+
{
26+
EventRecord2 (Evt_Error, cgStaticError, 0);
27+
}
28+
{% endif -%}
3829
CHECKERROR;
3930
{% if config.dumpFIFO %}
4031
{% for fifoID in sched.outputFIFOs(nodes[s]) %}
@@ -47,6 +38,7 @@ The support classes and code is covered by CMSIS-DSP license.
4738
{% if config.debug %}
4839
debugCounter--;
4940
{% endif %}
41+
CG_AFTER_ITERATION;
5042
nbSchedule++;
5143
}
5244

cmsisdsp/cg/static/scheduler/templates/code.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ extern "C"
1919
{
2020
#endif
2121

22+
{% if config.eventRecorder %}
23+
#include "EventRecorder.h"
24+
25+
#define EvtSched 0x01
26+
27+
#define Evt_Scheduler EventID (EventLevelAPI, EvtSched, 0x00)
28+
#define Evt_Node EventID (EventLevelAPI, EvtSched, 0x01)
29+
#define Evt_Error EventID (EventLevelError, EvtSched, 0x02)
30+
31+
{% endif %}
32+
2233
extern uint32_t {{config.schedName}}(int *error{{optionalargs()}});
2334

2435
#ifdef __cplusplus

cmsisdsp/cg/static/scheduler/templates/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import numpy as np
1212
import cmsisdsp as dsp
1313
from cmsisdsp.cg.static.nodes.simu import *
14-
from appnodes import *
15-
from custom import *
14+
from {{config.appNodesPythonName}} import *
15+
from {{config.customPythonName}} import *
1616

1717
{% macro optionalargs() -%}
1818
{% if config.pyOptionalArgs %}{{config.pyOptionalArgs}}{% endif %}

cmsisdsp/cg/static/scheduler/templates/codeArray.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ The support classes and code is covered by CMSIS-DSP license.
1212
{% endif %}
1313

1414
#include "arm_math.h"
15-
#include "custom.h"
15+
#include "{{config.customCName}}"
1616
#include "GenericNodes.h"
17-
#include "AppNodes.h"
18-
#include "scheduler.h"
17+
#include "{{config.appNodesCName}}"
18+
#include "{{config.schedulerCFileName}}.h"
1919

2020
{% macro optionalargs() -%}
2121
{% if config.cOptionalArgs %},{{config.cOptionalArgs}}{% endif %}
@@ -116,15 +116,29 @@ uint32_t {{config.schedName}}(int *error{{optionalargs()}})
116116
{% endif %}
117117
{
118118
/* Run a schedule iteration */
119+
{% if config.eventRecorder -%}
120+
EventRecord2 (Evt_Scheduler, nbSchedule, 0);
121+
{% endif -%}
122+
CG_BEFORE_ITERATION;
119123
for(unsigned long id=0 ; id < {{schedLen}}; id++)
120124
{
121125
unsigned int nodeId = schedule[id];
126+
{% if config.eventRecorder -%}
127+
EventRecord2 (Evt_Node, nodeId, 0);
128+
{% endif -%}
122129
cgStaticError = nodeArray[nodeId]->run();
130+
{% if config.eventRecorder -%}
131+
if (cgStaticError<0)
132+
{
133+
EventRecord2 (Evt_Error, cgStaticError, 0);
134+
}
135+
{% endif -%}
123136
CHECKERROR;
124137
}
125138
{% if config.debug %}
126139
debugCounter--;
127140
{% endif %}
141+
CG_AFTER_ITERATION;
128142
nbSchedule++;
129143
}
130144

cmsisdsp/cg/static/scheduler/templates/codeSwitch.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,40 @@ static unsigned int schedule[{{schedLen}}]=
2020
{% endif %}
2121
{
2222
/* Run a schedule iteration */
23+
{% if config.eventRecorder -%}
24+
EventRecord2 (Evt_Scheduler, nbSchedule, 0);
25+
{% endif -%}
26+
CG_BEFORE_ITERATION;
2327
for(unsigned long id=0 ; id < {{schedLen}}; id++)
2428
{
29+
{% if config.eventRecorder -%}
30+
EventRecord2 (Evt_Node, schedule[id], 0);
31+
{% endif -%}
2532
switch(schedule[id])
2633
{
2734
{% for nodeID in range(nbNodes) -%}
2835
case {{nodeID}}:
2936
{
3037
{{nodes[nodeID].cRun()}}
31-
CHECKERROR;
3238
}
3339
break;
3440

35-
{% endfor %}default:
41+
{% endfor -%}
42+
default:
3643
break;
3744
}
45+
{% if config.eventRecorder -%}
46+
if (cgStaticError<0)
47+
{
48+
EventRecord2 (Evt_Error, cgStaticError, 0);
49+
}
50+
{% endif -%}
51+
CHECKERROR;
3852
}
3953
{% if config.debug %}
4054
debugCounter--;
4155
{% endif %}
56+
CG_AFTER_ITERATION;
4257
nbSchedule++;
4358
}
4459

cmsisdsp/cg/static/scheduler/templates/commonc.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ The support classes and code is covered by CMSIS-DSP license.
1212
{% endif %}
1313

1414
#include "arm_math.h"
15-
#include "custom.h"
15+
#include "{{config.customCName}}"
1616
#include "GenericNodes.h"
17-
#include "AppNodes.h"
18-
#include "scheduler.h"
17+
#include "{{config.appNodesCName}}"
18+
#include "{{config.schedulerCFileName}}.h"
19+
20+
1921

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

cmsisdsp/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Python wrapper version
2-
__version__ = "1.7.1"
2+
__version__ = "1.8.0"

0 commit comments

Comments
 (0)