This section introduces the use of the Stream compiler spc from a command line to compile programs. It shows how to run the resulting programs on the host PC, under the simulator spsim, or on stream processor hardware. Directory demos/spm_demo/src in the installed Stream distribution contains the spm_demo application sources. Stream Reference Manual describes the usage of each Stream tool.
The next chapter describes the use of the Stream integrated development environment spide to build programs rather than using the command-line tools. The executables built from the command line in this chapter are in the same locations as the executables spide builds.
8.1Functional mode: Run on host
Compiling a Stream program with spc option -m testbench builds a testbench version of the program. The entry point of a testbench version is spi_main, not main. A testbench executable starts the Stream programming model runtime before it calls spi_main, so the program source does not need to call spi_spm_start explicitly.
Compiling a Stream program with spc option -z builds a functional version of the program. A functional executable runs directly on the host PC, not on a stream processor device. Functional mode programs provide quick turnaround for debugging. Programmers typically use functional mode to debug basic program functionality (for example, kernel correctness).
The following command builds an SP16 functional testbench version testbench of spm_demo from sources file_io.c, gsr_pipeline.sc, and testbench/spimain.c. From the spm_demo source directory, type:
$ mkdir -p ../build/sp16_functional/bin
$ spc -o ../build/sp16_functional/bin/testbench -m testbench -z \
file_io.c gsr_pipeline.sc testbench/spimain.c
Subdirectory data contains a sample bitmap image sample.bmp. spm_demo takes command line arguments to specify an input file and an output file. To run the functional version of the program:
$ ../build/sp16_functional/bin/testbench data/sample.bmp data/result.bmp
You can use any image viewer to view the bitmap files. Below, the original image sample.bmp is on the left and the image after green screen removal result.bmp is on the right. (If you are viewing this page in black and white, it may be difficult to see the difference.)
You can also compile and run a functional version of spm_demo for SP8 rather than SP16. Add -m sp8 to the spc command line:
$ mkdir -p ../build/sp8_functional/bin
$ spc -o ../build/sp8_functional/bin/testbench -m sp8 -m testbench -z \
file_io.c gsr_pipeline.sc testbench/spimain.c
$ ../build/sp8_functional/bin/testbench data/sample.bmp data/result.bmp
8.2Simulate with spsim
To build a testbench version of spm_demo for execution under the simulator spsim or for execution on stream processor hardware, type:
$ mkdir -p ../build/sp16_release/bin
$ spc -o ../build/sp16_release/bin/testbench -m testbench \
file_io.c gsr_pipeline.sc testbench/spimain.c
spsim simulates a stream program that runs on DSP MIPS. To simulate the DSP MIPS executable with spsim, type:
$ spsim ../build/sp16_release/bin/testbench data/sample.bmp data/result.bmp
This simulates the file i/o required to read and write a file of roughly 1Mb size, so it takes several minutes to run.
You can compile a testbench version of spm_demo for SP8 by using spc option -m sp8. The spsim command to simulate the SP8 program does not require any special flags; it automatically detects that the program runs on SP8.
$ mkdir -p ../build/sp8_release/bin
$ spc -o ./build/sp8_release/bin/testbench -m testbench -m sp8 \
file_io.c gsr_pipeline.sc testbench/spimain.c
$ spsim ../build/sp8_release/bin/testbench data/sample.bmp data/result.bmp
The testbench executable image built in the preceding section runs on the DSP MIPS of a stream processor hardware device as well as under the simulator spsim. Transfer executable image testbench and sample bitmap image sample.bmp to the device filesystem. For example, using scp and assuming the device is at IP address 172.18.18.88:
$ scp -p ../build/sp16_release/bin/testbench data/sample.bmp \
root@172.18.18.88:/tmp
Log in to System MIPS Linux running on the device (for example, by using telnet 172.18.18.88) and cd to the appropriate directory. Then use the sprun command to load and execute the DSP MIPS image:
$ sprun testbench sample.bmp result.bmp
If sprun reports an error such as “failed to open...”, reset DSP MIPS with sprun -s, then try again.
Similarly, to run the testbench SP8 image on hardware, transfer the SP8 version of testbench and sample.bmp to the device filesystem, then type the same sprun command as above. No special options are necessary; sprun automatically detects that the executable is for SP8. An SP16 board can run both SP16 and SP8 executables, but an SP8 board can only run SP8 executables.
You can use the Stream Processors Storm-1 hardware development kit (HDK) on-board web interface to download and execute a program image. Enter the URL of the development board (for example, http://w.x.y.z, where w.x.y.z is the IP address of the board) in the browser address bar to bring up the main on-board web page:
Click on Run Program to bring up the Run Program page:
The Upload and run a DSP MIPS image option uploads and runs a DSP MIPS program that does not require command line arguments. Since spm_demo requires command-line arguments, you should use the Upload file to the /tmp directory on the board and Execute Linux command options instead.
-
Hit the Browse... button for the Upload file to the /tmp directory on the board option.
-
Browse to the bitmap input file sample.bmp and hit Upload to upload it.
-
Browse to the SP16 release DSP MIPS executable testbench and hit Upload to upload it.
-
Enter the Linux command:
cd /tmp; sprun testbench sample.bmp result.bmp
-
Hit Execute. The program runs and the browser displays the output captured from sprun:
The sprun output starts with a banner from the SPI Monitor; the monitor performs communication between System MIPS and DSP MIPS. Then it shows the output from spm_demo. Finally, it shows a message from sprun indicating that the DSP MIPS program terminated.
Share with your friends: |