The testbench executables in the previous sections did not define or use SPM components. This section shows how to build component-based versions of spm_demo and run them on the host or on DSP MIPS. It builds a single executable that contains the file_in, gsr and file_out components.
To build a functional mode version of the component-based application and run it on the host, type:
$ spc -o ../build/sp16_functional/bin/app_host -z \
file_io.c gsr_pipeline.sc components/gsr.c \
components/file_in.c components/file_out.c \
components/main.c
$ ../build/sp16_functional/bin/app_host data/sample.bmp data/result.bmp
To build a DSP MIPS executable version of the component-based application and simulate it, type:
$ spc -o ../build/sp16_release/bin/app_dsp_only \
file_io.c gsr_pipeline.sc components/gsr.c \
components/file_in.c components/file_out.c \
components/main.c
$ spsim ../build/sp16_release/bin/app_dsp_only data/sample.bmp data/result.bmp
To run the same DSP MIPS executable on stream processor hardware, transfer app_dsp_only and sample.bmp to the device filesystem, then type:
$ sprun app_dsp_only sample.bmp result.bmp
The complete spm_demo application consists of a System MIPS executable and a DSP MIPS executable. The System MIPS executable contains the file_in and file_out components of the application, compiled from sources file_io.c, components/file_in.c, and components/file_out.c. It also contains the main function that starts SPM, creates component instances, creates connections, and issues initialization commands to the instances, compiled from source components/main.c. spc option -m sp16_sys builds an SP16 System MIPS executable app_sys:
$ spc -o ../build/sp16_release/bin/app_sys -m sp16_sys \
file_io.c components/file_in.c components/file_out.c \
components/main.c
The DSP MIPS executable contains the gsr component of the spm_demo application. The gsr component must run on DSP MIPS, as it contains Stream code that must run on DSP MIPS and kernels that must run on the DPU. The gsr component source is in files gsr_pipeline.sc and components/gsr.c. To build the DSP MIPS executable app_dsp:
$ spc -o ../build/sp16_release/bin/app_dsp gsr_pipeline.sc components/gsr.c
To run the complete application on stream processor hardware, download bitmap file sample.bmp and executable files app_sys and app_dsp to the filesystem of a stream processor device, then log into the board. Make sure the downloaded app_sys is executable and type:
$ ./app_sys sample.bmp result.bmp
Here the System MIPS program loads DSP MIPS image file app_dsp by default.
To build the SP8 version of the complete spm_demo application, use option -m sp8_sys to compile the System MIPS program and option -m sp8 to compile the DSP MIPS program:
$ spc -o ../build/sp8_release/bin/app_sys -m sp8_sys \
file_io.c components/file_in.c components/file_out.c \
components/main.c
$ spc -o ../build/sp8_release/bin/app_dsp -m sp8 \
gsr_pipeline.sc components/gsr.c
Then download sample.bmp, app_sys, and app_dsp to the filesystem of a stream processor device, log into the board, make sure app_sys is executable, and type:
$ ./app_sys sample.bmp result.bmp
8.5.1Initialization file
The System MIPS application main in components/main.c includes code to load a DSP MIPS image, to create component instances, to create connections, and to issue initialization commands. As described in section Initialization file above, this code is conditionalized #if !defined(INIT_FILE). If components/main.c is compiled with spc -D INIT_FILE, the resulting executable expects special SPM option --spm_init_file=file to supply an initialization file that specifies the required initialization instead. For example:
$ spc -o ../build/spi16_release/bin/app_sys_init -m sp16_sys -D INIT_FILE \
file_io.c components/file_in.c components/file_out.c \
components/main.c
$ spc -o ../build/spi16_release/bin/app_dsp gsr_pipeline.sc components/gsr.c
To run the application on stream processor hardware using an initialization file, download bitmap file sample.bmp, executable files app_sys_init and app_dsp, and initialization file components/init.xml to the filesystem of a stream processor device, then log into the board. Make sure the downloaded app_sys_init is executable and type:
$ ./app_sys_init --spi_init_file=init.xml
The filenames of the DSP MIPS image file, input file, and output file are hardcoded in initialization file init.xml, so no other command line arguments to app_sys_init are needed.
8.6Logs
The spm_demo application source includes spi_log calls that write runtime messages to the built-in debug and error logs. In addition, the gsr component calls spi_log_new to create a log named gsr. By default, SPM runs programs with all error log levels enabled (error log enable mask 0xFFFFFFFF) and all debug log levels disabled (debug log enable mask 0). It also disables all user-defined logs (gsr log enable mask 0).
The following examples use the functional version of spm_demo to demonstrate logging. When you run the functional mode executable testbench, it prints the following output:
$ ../build/sp16_functional/bin/testbench data/sample.bmp data/result.bmp
Read input file...
Perform green screen removal...
Write output file...
Done!
The messages here are from printf calls in testbench/spimain.c. If you run testbench with gsr logging enabled, it prints additional information during gsr execution:
$ ../build/sp16_functional/bin/testbench --spi_log_mask=gsr,1 \
data/sample.bmp data/result.bmp
Read input file...
Perform green screen removal...
gsr::__spi_testbench__ (1222899576285671936 ns): gsr_pipeline:
gsr::__spi_testbench__ (1222899576292269056 ns): Find background color...
gsr::__spi_testbench__ (1222899577647095808 ns): Background color: abbe20
gsr::__spi_testbench__ (1222899577647770880 ns): Replace background color...
Write output file...
Done!
Within the spm_demo components, some conditions generate output to the debug log rather than to the error log; this allows a component to report an error but continue execution. For example, suppose the user specifies the input .bmp file with a nonexistent filename:
$ ../build/sp16_functional/bin/testbench foo.bmp data/result.bmp
Read input file...
read bitmap file "foo.bmp" failed
These messages are from printf statements in testbench/spimain.c. For additional detail, enable debug level 1:
$ ../build/sp16_functional/bin/testbench --spi_log_mask=debug,1 \
foo.bmp data/result.bmp
Read input file...
debug::__spi_testbench__ (1222900070227181056 ns): cannot open "foo.bmp" for
reading
read bitmap file "foo.bmp" failed
Share with your friends: |