At a high level, this series of articles on programming the Cell
processor (
starting with Part 1)
- and in the
book
upon which it is based - is just a collection of instructions and
recipes for converting human-readable text files into binary
executables.This conversion process, called
building, is the subject
of this part in the series and focuses on two topics:
1. The SDK tools (ppu-gcc, spu-gcc, ppu-as,
spu-as, etc.) that
perform the build process
2. The makefiles that direct how the build
should be performed
If you're already familiar with the GNU Compiler Collection (GCC)
and its tools, you may only want to just skim this chapter.
ppu-gcc and
spu-gcc have the same options as regular GCC tools and are used in the
same way. There's also nothing new about the makefiles used to build
Cell applications.
But if you're unacquainted with GCC or you've forgotten how to use
it, follow this chapter closely. The build process for the Cell isn't
hard to understand, but there's nothing more annoying than a mysterious
ld error or misplaced library. It's better to spend time now learning
the tools than to lose time later debugging errors.
Getting Started. Most of the components in the Cell
Software Development Kit (SDK) were created by IBM, but the basic build
tools were developed by Sony. Wisely, Sony chose to base its tools on
the GCC.The GCC toolchain has gained legions of developers since its
release more than 20 years ago, and it's easy to see why: It supports a
broad number of processors, it's released under the GNU Public License,
and its compiling standards are as high as they come.
GCC tools have been ported to run on over 50 different
processor
architectures. Here we will be concerned with only two: the PowerPC
Processor Unit (PPU) and Synergistic Processor Unit (SPU).The PPU and
SPU both reside on the Cell but have different instruction sets. That
is, an application compiled to run on the PPU will not be able
to run on the SPU, and vice versa. For this reason, the SDK provides
separate sets of tools for both architectures. This part in the series
both sets in detail.
The eight SPUs perform the brunt of the Cell's computation, but we
can only interact with the Cell through its PPU.Therefore, this section
describes the PPU development tools first and the SPU tools second.
Both are based are on GCC, so the difference between the two isn't
significant.
Building Apps for the PowerPC Processor Unit (PPU)
The material presented here uses an explanation-demonstration approach.
That is, concepts are explained first and then demonstrated with
example code. This works well for theory-oriented topics such as
matrices and frequency transforms, but when it comes to detail-oriented
topics such as GCC usage, the reverse approach is better:
Start with a working example and then explain why the example works.
This way, the meaning and importance of the details become clear at the
start.
The example code available on line is divided into directories named
after chapters. Each chapter directory is divided into project
directories.A project is a set of files that combine to produce a
single application.
In the Chapter3 directory, ppu_project contains a source file called
a.c and a directory called head_dir. a.c is a simple C source file, and
its code is presented in Listing 3.1 below.
Listing 3.1 Basic PPU Source File: a.c
#include
#include "x.h"
#include "y.h"
/* Display the values of x and y */
int main() {
printf("x = %u, y = %u\n", x, y);
return 0;
}
This source file displays the values of x and y, but doesn't declare
either. These variables are declared and initialized in header files
x.h and y.h, both located in head_dir. Listings 3.2 and 3.3 below
show the code of both header files.
Listing 3.2 Simple PPU Header File: x.h
/* Declare the value of x */
unsigned int x = 4;
Listing 3.3 Simple PPU Header File: y.h
/* Declare the value of y */
unsigned int y = 9;
The goal of this example is to convert these three files into a
single executable called a. From a developer's standpoint, this
can be performed in three ways:
The long way: Execute ppu-cpp, ppu-gcc, ppu-as, and ppu-ld as
separate executables.
The short way: Execute all the executables simultaneously with
ppu-gcc.
The right way: Execute the make command, which executes
commands listed in a makefile.
Most of this series will use make to build applications, but
the long way is the most instructive and is the subject of this
discussion.
(Note:On a Cell-based system, the GCC executables are
located in /usr/bin. On an x86-based system, the GCC executables are
placed in /opt/cell/toolchain.
Figure 3.1 below depicts the four steps of the PPU build
process. For each operation, the text on the left shows the command to
be executed, and the text on the right explains what the command
accomplishes.
 |
| Figure
3.1 The PPU build process |
Let's look more closely that the stages that form the development
process: preprocessing, compiling, assembling, and linking.