Mercurial > hg > Game > Cerium
view TaskManager/test/GpuRunTest/GpuRunTest.cc @ 1516:e544f9747169 draft
fix gpu kernel source
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 08 Nov 2012 17:20:10 +0900 |
parents | b3644b73d2cf |
children | 57317332f6ef |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <sys/stat.h> #include "types.h" #include "TaskManager.h" #include "GpuFunc.h" #define DEFAULT 5 static long int length = DEFAULT; static int task = 1; extern void task_init(void); char usr_help_str[] = "GpuRun [length]\n"; void print_data(int *data, int size, const char *title) { printf("%s ---\n", title); for ( int i = 0; i < size; i++) { printf("%2d ", data[i]); } printf("\n"); } /** * タスク終了後の data1, data2 の確認 */ void twice_result(SchedTask *s, void *a, void *b) { int* data = (int*)a; long length = (long)b; print_data(data, length, "after"); } int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-length") == 0) { length = atoi(argv[++i]); } else if (strcmp(argv[i], "-count") == 0) { task = atoi(argv[++i]); } } return 0; } void tester(int *indata, int *outdata, int num) { //チェック int check = 0; for (int c=0; c<num; c++) { if(outdata[c] == indata[c]*2) { check++; } } printf("Computed '%d/%d' correct values\n",check,num); } void test(TaskManager *manager) { int *indata = new int[length]; int *outdata = new int[length]; for (int c=0; c < length ;c++) { indata[c] = c; } print_data(indata, length, "before"); HTaskPtr twice = manager->create_task(Twice); twice->set_param(0, (memaddr)length); twice->set_inData(0, indata, sizeof (int)*length); twice->set_outData(0, outdata, sizeof (int)*length); twice->set_cpu(GPU_0); /* * set_post() で ppe task を渡せるようにしたい */ twice->set_post(twice_result, (void*)outdata, (void*)length); twice->spawn(); } int TMmain(TaskManager *manager, int argc, char* argv[]) { if (init(argc, argv) < 0) { return -1; } task_init(); for (int i = 0; i < task; ++i) { test(manager); } return 0; } /* end */