Skip to content

Commit 136cbb8

Browse files
dyudakovJaccovG
authored andcommitted
Gnu har example (#9)
* updated example har smartphone for GNU toolchain * fixed link and cmd line * updated README.md * updated Makefile - renamed PUBLIC_DIR variable. added creation of a bin directory for external lib. * updated README.md - Added some Notes for GNU part * fixed link to specific paragraph * added folder for prebuilt library, added README.md * Update README.md * Update README.md * Update README.md
1 parent e28fb6e commit 136cbb8

File tree

11 files changed

+589
-47
lines changed

11 files changed

+589
-47
lines changed

build/rules.mk

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# Copyright (c) 2019, Synopsys, Inc. All rights reserved.
2+
#
3+
# Redistribution and use in source and binary forms, with or without modification,
4+
# are permitted provided that the following conditions are met:
5+
#
6+
# 1) Redistributions of source code must retain the above copyright notice, this
7+
# list of conditions and the following disclaimer.
8+
#
9+
# 2) Redistributions in binary form must reproduce the above copyright notice,
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
#
13+
# 3) Neither the name of the <ORGANIZATION> nor the names of its contributors
14+
# may be used to endorse or promote products derived from this software
15+
# without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
18+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
128
#=============================================================
229
# OS-specific definitions
330
#=============================================================
@@ -85,11 +112,13 @@ OBJS = $(C_OBJS) $(CPP_OBJS) $(CC_OBJS) $(C_DEPNDS) $(CPP_DEPENDS) $(CC_DEPENDS
85112
#
86113
ifeq ($(TOOLCHAIN),gnu)
87114
# place to add GNU-specific common settings
88-
CFLAGS +=-fno-short-enums
115+
CFLAGS +=-fno-short-enums
116+
DEPFLAGS =
89117
else
90118
ifeq ($(TOOLCHAIN),mwdt)
91119
# place to add MWDT-specific common settings
92-
CFLAGS +=-Hon=Long_enums
120+
CFLAGS +=-Hon=Long_enums
121+
DEPFLAGS =-Hdepend=$(BUILD_DIR)/ -MD
93122
else
94123
$(error ERROR - Unsupported toolchain. Supported toolchains are 'gnu' and 'mwdt', default one is 'gnu')
95124
endif
@@ -132,7 +161,7 @@ else
132161
CFLAGS += -DRF_BUILD=0x006e
133162
CFLAGS += -DRF_BUILD=0x006e
134163
CFLAGS += -DSTATUS32=0x000a
135-
LDFLAGS += -marcv2elf
164+
LDFLAGS += -marcv2elfx
136165
LDFLAGS += -lc
137166
LDFLAGS += -lm
138167
LDFLAGS += -lnsim
@@ -160,21 +189,21 @@ ifeq ($(BUILD_DIR),)
160189
$(error cannot build C object file $@ -- BUILD_DIR variable must be set)
161190
endif
162191
@echo [CC] $<
163-
$(CC) $(CFLAGS) $(INCS) -c -Hdepend=$(BUILD_DIR)/ -MD $< -o $@
192+
$(CC) $(CFLAGS) $(INCS) -c $(DEPFLAGS) $< -o $@
164193

165194
$(CPP_OBJS): $(BUILD_DIR)/%.o: %.cpp | $(BUILD_DIR)
166195
ifeq ($(BUILD_DIR),)
167196
$(error cannot build C++ object file $@ -- BUILD_DIR variable must be set)
168197
endif
169198
@echo [CPP] $<
170-
$(CC) $(CFLAGS) $(INCS) -c -Hdepend=$(BUILD_DIR)/ -MD $< -o $@
199+
$(CC) $(CFLAGS) $(INCS) -c $(DEPFLAGS) $< -o $@
171200

172201
$(CC_OBJS): $(BUILD_DIR)/%.o: %.cc | $(BUILD_DIR)
173202
ifeq ($(BUILD_DIR),)
174203
$(error cannot build C++ object file $@ -- BUILD_DIR variable must be set)
175204
endif
176205
@echo [C++] $<
177-
$(CC) $(CFLAGS) $(INCS) -c -Hdepend=$(BUILD_DIR)/ -MD $< -o $@
206+
$(CC) $(CFLAGS) $(INCS) -c $(DEPFLAGS) $< -o $@
178207

179208
$(LIBRARY_DIR):
180209
$(MKDIR) $(call fix_platform_path, $(LIBRARY_DIR))
@@ -244,7 +273,7 @@ ELF_RUN=mdb $(MDB_ARGS) -nsim -tcf=$(TCF_FILE) -profile $(DBG_OPTS)
244273
endif
245274

246275
ifeq ($(RUN_METHOD),NSIM_DEBUG)
247-
ELF_RUN=mdb -nsim -tcf=$(TCF_FILE)
276+
ELF_RUN=mdb -nsim -tcf=$(TCF_FILE) $(DBG_OPTS)
248277
endif
249278

250279
ifeq ($(RUN_METHOD),XCAM_RUN)

examples/auxiliary/tests_aux.h

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ extern "C" {
4646
/** @def Macro for calculating number of fractionl bits. Uses container type and number of integer bits*/
4747
#define FRAQ_BITS(int_part, el_type) ((sizeof(el_type)*8)-int_part-1)
4848

49-
5049
#ifndef MAX
5150
/** @def Common Maximum macro function (two values)*/
52-
#define MAX(A,B) (((A > B)? A: B))
51+
#define MAX(A,B) (((A) > (B))? (A): (B))
5352
#endif
5453
/** @def Common Minimum macro function (two values)*/
5554
#ifndef MIN
56-
#define MIN(A,B) (((A > B)? B: A))
55+
#define MIN(A,B) (((A) > (B))? (B): (A))
5756
#endif
5857

5958
#define CEIL_DIV(num,den) (((num) + (den) - 1)/(den))
@@ -81,9 +80,40 @@ extern unsigned cycle_cnt;
8180
cycle_cnt = _timer_default_read();
8281
#else
8382
//GNU toolchain profiling
83+
static inline void test_aux_start_timer_0() {
84+
_sr(0 , 0x22);
85+
_sr(0xffffffff, 0x23);
86+
_sr(3, 0x22);
87+
_sr(0, 0x21);
88+
}
89+
90+
static inline uint32_t test_aux_read_timer_0() {
91+
return (_lr(0x21));
92+
}
93+
94+
static inline void test_aux_stop_timer_0() {
95+
_sr (0 , 0x22);
96+
}
97+
98+
static inline void test_aux_start_timer_1() {
99+
_sr(0 , 0x101);
100+
_sr(0xffffffff, 0x102);
101+
_sr(3, 0x101);
102+
_sr(0, 0x100);
103+
}
104+
105+
static inline uint32_t test_aux_read_timer_1() {
106+
return( _lr(0x100) );
107+
}
108+
109+
static inline void test_aux_stop_timer_1() {
110+
_sr (0 , 0x101);
111+
}
112+
84113
#define PROFILE(F) \
85-
cycle_cnt = 0;\
86-
F;
114+
test_aux_start_timer_0(); \
115+
F;\
116+
cycle_cnt = test_aux_read_timer_0();
87117
#endif
88118
#else
89119
#define PROFILE(F) \
@@ -147,7 +177,6 @@ test_status load_tensors_from_idx_files(
147177
mli_tensor * tensors[],
148178
uint32_t paths_num);
149179

150-
151180
/**
152181
* @brief Compare data in tensor with external reference data
153182
*

examples/example_har_smartphone/Makefile

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,72 @@
2727

2828
# default toolchain
2929
TOOLCHAIN ?= mwdt
30-
TCF_FILE ?= ../../hw/em9d.tcf
30+
31+
# default hardware config file
32+
TCF_FILE ?= ../../hw/em9d.tcf
3133

3234
# Directories and files
33-
PUBLIC_DIR ?= ../..
34-
SRC_DIRS = $(PUBLIC_DIR)/examples/example_har_smartphone \
35-
$(PUBLIC_DIR)/examples/auxiliary
35+
EMBARC_MLI_DIR ?= ../..
36+
SRC_DIRS = $(EMBARC_MLI_DIR)/examples/example_har_smartphone \
37+
$(EMBARC_MLI_DIR)/examples/auxiliary
38+
39+
INC_DIRS = . \
40+
$(EMBARC_MLI_DIR)/include\
41+
$(EMBARC_MLI_DIR)/examples/auxiliary
42+
43+
EXT_LIBS_DIR ?= $(EMBARC_MLI_DIR)/bin
44+
EXT_LIBS ?= $(EXT_LIBS_DIR)/libmli.a
45+
OUT_DIR ?= ./bin
46+
BUILD_DIR ?= ./obj
47+
OUT_NAME ?= example_har_smartphone
48+
ifeq ($(TOOLCHAIN),mwdt)
49+
# MWDT specific options
50+
CFLAGS = -Hnocopyr -Hpurge -Hheap=16K -Hstack=4K -Hfxapi -e_start -Bgrouplib -Hldopt=-q -O0
51+
else
52+
PREBUILT_LIB ?= $(EMBARC_MLI_DIR)/examples/prebuilt/libmli.a
53+
54+
# GNU toolchain specific options - correct it according to your target platform settings (see build_configuration.txt for input)
55+
#Iot DevKit config
56+
CFLAGS = -mcpu=em4_dmips -mlittle-endian -mcode-density -mdiv-rem -mswap -mnorm -mmpy-option=6 -mbarrel-shifter -mxy
3657

37-
INC_DIRS = . \
38-
$(PUBLIC_DIR)/include\
39-
$(PUBLIC_DIR)/examples/auxiliary
58+
# The embARC MLI Library specific options it according to your target platform settings
59+
#(EM5D or EM7D platform)
60+
#CFLAGS += -DV2DSP
61+
#(EM9D or EM11D platform)
62+
CFLAGS += -DV2DSP_XY
63+
#(HS45D or HS47D platform)
64+
#CFLAGS += -DV2DSP_WIDE
4065

66+
# GNU toolchain linker specific options
67+
LDFLAGS = --defsym=__DEFAULT_HEAP_SIZE=16k
68+
LDFLAGS += --defsym=__DEFAULT_STACK_SIZE=4k
69+
LDFLAGS += -Map $(OUT_DIR)/$(OUT_NAME).map
4170

42-
EXT_LIBS ?= $(PUBLIC_DIR)/bin/libmli.a
43-
OUT_DIR ?= ./bin
44-
BUILD_DIR ?= ./obj
45-
OUT_NAME ?= example_har_smartphone
46-
CFLAGS = -Hnocopyr -Hpurge -Hheap=16K -Hstack=4K -Hfxapi -e_start -Bgrouplib -Hldopt=-q -O0
71+
#specific options for run the example with the MetaWare Debuger on the nSim simulator.
72+
DBG_OPTS = -cmd="read mdb_com_gnu"
73+
endif
4774

4875
all: lib app
4976

50-
include $(PUBLIC_DIR)/build/rules.mk
77+
$(EXT_LIBS): $(EXT_LIBS_DIR)
78+
@echo Copy prebuilt library $(PREBUILT_LIB) to $@
79+
@$(CP) $(call fix_platform_path,$(PREBUILT_LIB)) $(call fix_platform_path,$@)
80+
81+
$(EXT_LIBS_DIR):
82+
$(MKDIR) $(call fix_platform_path, $@))
83+
84+
include $(EMBARC_MLI_DIR)/build/rules.mk
5185

5286
.PHONY: clean all lib cleanall app
5387
.DEFAULT: all
5488

89+
90+
ifeq ($(TOOLCHAIN),mwdt)
5591
lib:
5692
@ $(MAKE) generic_lib -C ..$(PS)..$(PS)lib$(PS)make$(PS) TCF_FILE="$(TCF_FILE)"
93+
else
94+
lib: $(EXT_LIBS)
95+
endif
5796

5897
app: generic_app
5998

examples/example_har_smartphone/README.md

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ Example shows how to work with recurrent primitives (LSTM and basic RNN) impleme
1010

1111
Quick Start
1212
--------------
13-
Here we will consider building for hw/em9d.tcf template.
1413

15-
0. embARC MLI Library must be built for required hardware configuration first. See [embARC MLI Library building and quick start](public/README.md).
14+
Example supports building using MetaWare Development tools and ARC GNU toolchain and running with MetaWare Debuger on nSim simulator.
15+
16+
### Build with MetaWare Development tools
17+
18+
Build requirements:
19+
- MetaWare Development tools version 2018.12 or higher
20+
- gmake
21+
22+
Here we will consider building for [/hw/em9d.tcf](/hw/em9d.tcf) template. This template is a default template for this example. Other templated can be also used.
23+
24+
0. embARC MLI Library must be built for required hardware configuration first. See [embARC MLI Library building and quick start](/README.md#building-and-quick-start).
1625

1726
1. Open command line and change working directory to './examples/example_har_smartphone'
1827

@@ -24,11 +33,54 @@ Here we will consider building for hw/em9d.tcf template.
2433

2534
gmake TCF_FILE=../../hw/em9d.tcf
2635

27-
4. Run example
36+
### Run example with MetaWare Debuger on nSim simulator.
2837

2938
gmake run TCF_FILE=../../hw/em9d.tcf
3039

31-
5. Result Quality shall be "S/N=1823.9 (65.2 db)"
40+
Result Quality shall be "S/N=1823.9 (65.2 db)"
41+
42+
### Build with ARC GNU toolchain
43+
44+
Here we will consider building with ARC GNU toolchain. As a platform for the assembly, we use the [IoT Devkit](https://embarc.org/embarc_osp/doc/build/html/board/iotdk.html) from [the embARC Open Software Platform (OSP)](https://embarc.org/embarc_osp/doc/build/html/introduction/introduction.html#)
45+
46+
Build requirements:
47+
- ARC GNU toolchain version 2018.09 or higher
48+
- embARC MLI Library prebuilt with MetaWare Development tools for IoT Devkit hardware configuration
49+
- gmake
50+
51+
0. Prebuilt embARC MLI Library must be copyied into the ./examples/prebuilt folder.
52+
53+
1. Open command line and change working directory to './examples/example_har_smartphone'
54+
55+
2. Clean previous build artifacts (optional)
56+
57+
gmake TOOLCHAIN=gnu clean
58+
59+
3. Build example
60+
61+
gmake TOOLCHAIN=gnu
62+
63+
Notes: IoT Devkit hardware configuration is specifed in Makefile. Additionally used memory.x linkscript file for GNU linker.
64+
65+
### Run example with MetaWare Debuger on nSim simulator.
66+
67+
Run requirements:
68+
- MetaWare Development tools version 2018.12 or higher
69+
- arcem9d.tcf file with hardware configuration of IoT Devkit for setup nSim.
70+
71+
0. Copy the [arcem9d.tcf](https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/blob/master/board/iotdk/configs/10/tcf/arcem9d.tcf) file into example folder.
72+
73+
1. Run example
74+
75+
gmake run TOOLCHAIN=gnu TCF_FILE=arcem9d.tcf
76+
77+
Result Quality shall be "S/N=1823.9 (65.2 db)"
78+
79+
Notes: Example built by ARC GNU tools is run using mdb_com_gnu script file. Modify this file to customize the example run mode. See [More Options on Building and Running](README.md#more-options-on-building-and-running)
80+
81+
### Run example without MetaWare Development tools
82+
83+
See documentation on [IoT Devkit](https://embarc.org/embarc_osp/doc/build/html/board/iotdk.html) on how to run executable built with [ARC GNU](https://embarc.org/toolchain/index.html) and [ARC open source development tools](https://embarc.org/embarc_osp/doc/build/html/index.html) on IoT Devkit.
3284

3385

3486
Example Structure
@@ -48,8 +100,13 @@ Structure of example application may be divided logically on three parts:
48100
* ../auxiliary/tests_aux.h(.c)
49101
* ../auxiliary/idx_file.h(.c)
50102

51-
Example structure also contains test vector set including small subset of pre-processed UCI HAR Smartphones dataset (20 vectors organized in IDX file format).
52-
103+
Example structure contains test vector set including small subset of pre-processed UCI HAR Smartphones dataset (20 vectors organized in IDX file format).
104+
105+
Example structure also contains auxiliary files for development tools:
106+
* arcem9d.lcf - linkscript file for MetaWare linker.
107+
* memory.x - linkscript file for GNU linker.
108+
* mdb_com_gnu - command script file for MetaWare Debugger.
109+
53110
More Options on Building and Running
54111
---------------------------------------
55112
Coefficients for trained NN model are stored in the separate compile unit (*coefficients.c) as wrapped float numbers. This allows to transform coefficients into quantized fixed point values in compile time.
@@ -69,15 +126,18 @@ No application input arguments.
69126

70127
gmake run TCF_FILE=../../hw/em9d.tcf
71128

72-
2. **Accuracy measurement for testset.** Reads vectors from input IDX file, passes it to the model, and accumulates number of successive classifications according to labels IDX file.
129+
2. **External test-set processing.** Reads vectors from input IDX file, passes it to the model, and writes it's output to the other IDX file (if input is *tests.idx* then output will be *tests.idx_out*).
130+
Input test-set path is required as argument
131+
132+
gmake run TCF_FILE=../../hw/em9d.tcf RUN_ARGS="small_test_base/tests.idx"
133+
134+
3. **Accuracy measurement for testset.** Reads vectors from input IDX file, passes it to the model, and accumulates number of successive classifications according to labels IDX file.
73135
Input test-set and labels paths are required as argument.
74136

75137
gmake run TCF_FILE=../../hw/em9d.tcf RUN_ARGS="small_test_base/tests.idx small_test_base/labels.idx"
76138

77-
3. **External test-set processing.** Reads vectors from input IDX file, passes it to the model, and writes it's output to the other IDX file (if input is *tests.idx* then output will be *tests.idx_out*).
78-
Input test-set path is required as argument
79-
80-
gmake run TCF_FILE=../../hw/em9d.tcf RUN_ARGS="small_test_base/tests.idx"
139+
Notes: If the example is compiled with GNU tools, then these modes are transferred to the application using mdb_com_gnu command script file for MetaWare Debugger.
140+
Modify this file to customize the example run mode.
81141

82142
References
83143
----------------------------

0 commit comments

Comments
 (0)