高性能计算

cell环境下的程序的两种编译方法

2009年4月10日 阅读(278)

一.通过cell提供的makefile的支持,这需要建立makefile,并且在makefile里include一个cell的公共文件部分
完整实例,请参考:http://www.ibm.com/developerworks/cn/linux/l-cn-cellprogramming/index.html

比如这样一个文件结构:一个test文件下,有两个子文件夹spu,ppu,某个下面又有一个相应的.c文件,我们希望最后生成一个统一的test可执行文件。

makefile应该这样写:
[root@wq_desktop test]# more Makefile
DIRS = spu ppu
include /opt/cell/sdk/buildutils/make.footer

[root@wq_desktop test]# more ppu/Makefile
PROGRAM_ppu :=  ../test
IMPORTS = ../spu/libtest_spu.a -lspe2 -lpthread
include /opt/cell/sdk/buildutils/make.footer

[root@wq_desktop test]# more spu/Makefile
PROGRAMS_spu    := test_spu
LIBRARY_embed   := libtest_spu.a
include /opt/cell/sdk/buildutils/make.footer

分析上面的makefile写法,得出一个统一的书写模式如下:

二.独立使用spu-gcc及ppu32-gcc,ppu32-embedspu命令,这样需要在命令中,加入必须的-I -L选项。

比如针对上面文件结构下的命令分别是:
spu-gcc -g -o test_spu test_spu.c
ppu32-embedspu test_spu test_spu spu.a
ppu32-gcc -g -o test test_p.c spu.a -lspe2 -lpthread

经测试,这个test也是可以在模拟器中正常运行,而上一篇提到的,没有输出结果,是因为我以前试验时,曾经注释掉了test_p.c里的#include <stdio.h>以及printf语句

注意观察,ppu32-embedspu的用法如下:
Usage: embedspu [flags] symbol_name input_filename output_filename

        input_filename:  SPU ELF executable to be embedded
        output_filename: Resulting PowerPC object file
        symbol_name:     Name of program handle struct to be defined
        flags:           GCC flags defining PowerPC object file format
                         (e.g. -m32 or -m64)

其中symbol_name,是要从ppu的.c文件中查看是如何定义的,查看后看到这么一句,extern spe_program_handle_t test_spu;也就是symbol_name就是test_spu

You Might Also Like