|
|
Imagine Stream ProgrammingAn Imagine application is a set of kernels connected by streams. Signal and image processing applications are easily expressed as a series of computation kernels that operate on large data streams. A kernel is a small program that is repeated for each successive element of its input streams to produce output streams for the next kernel in the application. Streams are organized as a sequence of records. Each record in a stream is a collection of related data words, such as the vertex, normal, and color information for a triangle. Stream-Level ProgrammingThe host processor executes StreamC programs. StreamC enables the host to set up data in the Imagine and to initiate kernels to perform computation on Imagine. This example StreamC code fragment loads the Stream Register File (SRF) with two streams of data, initiates a kernel to operate on the data, and then sends the results to the network. load (datin1, mem1); // Memory to SRF
load (datin2, mem2);
op (ADDSUB, datin1, datin2, datout1, datout2);
send (datout1, P2, chan0); // SRF to Network
send (datout2, P3, chan1);
The Imagine Stream Scheduler converts StreamC functions into Imagine operations. It determines dependencies between operations and allocates operation issue slots, stream-level registers, SRF entries, and memory, and performs software pipelining. The Stream Scheduler is profile based; it runs a simple allocation of the code on the Imagine simulator and determines a good allocation from the usage information derived from the first run. Kernel-Level ProgrammingImagine kernels are programmed with a C-like syntax in KernelC. The code appears to operate on a single record at one time, but the 8 clusters on Imagine each run the same kernel on different elements of the stream simultaneously. The Kernel Scheduler compiles KernelC code into VLIW instructions. This example KernelC kernel interacts with the above StreamC code. It produces two streams, c and d. The first stream is the sum of the two input streams, while the second stream is the difference of the two input streams. loop(input_stream0) {
input_stream0 >> a;
input_stream1 >> b;
c = a + b;
d = a - b;
output_stream0 << c;
output_stream1 << d;
}
Imagine repeats the kernel until the input streams (stored in the SRF by the Host Processor) are emptied. The following figures show a scheduled kernel. Figure 1 is a single pass through the stereo-depth extraction kernel. Figure 2 shows the kernel after Stream Scheduling and software pipelining.
Figure 1: One Kernel iteration
Figure 2: Scheduled and Pipelined Kernel |
|
|