1 2 3 4 5 6 7 8 | [root@wq_desktop ~]# mkdir -p test test/ppu test/spu [root@wq_desktop ~]# cd test [root@wq_desktop test]# vi Makefile [root@wq_desktop test]# vi ppu/Makefile [root@wq_desktop test]# vi spu/Makefile [root@wq_desktop test]# vi ppu/test_p.c [root@wq_desktop test]# vi spu/test_spu.c [root@wq_desktop test]# make |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | [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 [root@wq_desktop test]# more ppu/test_p.c #include <pthread.h> #include <libspe2.h> #define SPU_THREADS 2 extern spe_program_handle_t test_spu; void *ppu_pthread_function(void *arg) { spe_context_ptr_t ctx; unsigned int entry = SPE_DEFAULT_ENTRY; ctx = *((spe_context_ptr_t *)arg); if (spe_context_run(ctx, &entry, 0, NULL, NULL, NULL) < 0) { perror ("Failed running context"); return NULL; } pthread_exit(NULL); } int main ( ) { int i; spe_context_ptr_t ctxs[SPU_THREADS]; pthread_t threads[SPU_THREADS]; for(i=0; i<SPU_THREADS; i++) { if ((ctxs = spe_context_create (0, NULL)) == NULL) { perror ("Failed creating context"); return -1; } if (spe_program_load (ctxs, &test_spu)) { perror ("Failed loading program"); return -1; } if (pthread_create (&threads, NULL, &ppu_pthread_function, &ctxs)) { perror ("Failed creating thread"); return -1; } } for (i=0; i<SPU_THREADS; i++) { if (pthread_join (threads, NULL)) { perror("Failed pthread_join"); return -1; } } return (0); } [root@wq_desktop test]# more spu/test_spu.c #include <stdio.h> int main() { int a[4] = {120, 230, 580, 970}; float b[4] = {1.8, 1.98, 0.68, 0.7}; int c[4] = {0}; int i = 0; for( i = 0; i < 4; i ++ ) { c = a * b; printf("c[%d] = %d\n", i, c); } return 0; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |