changeset 1564:4e1899c693f0 draft

add getTime,and check_data function
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Fri, 15 Mar 2013 06:59:19 +0900
parents 948bafd61d96
children 4ef32873b5be
files TaskManager/Cell/spe/SpeTaskManagerImpl.cc example/multiply/main.cc
diffstat 2 files changed, 43 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.cc	Tue Mar 12 17:06:42 2013 +0900
+++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.cc	Fri Mar 15 06:59:19 2013 +0900
@@ -21,7 +21,6 @@
 void SpeTaskManagerImpl::export_task_log() {}
 
 void SpeTaskManagerImpl::print_arch() { printf("SpeTaskManagerImpl\n"); }
-//void SpeTaskManagerImpl::set_NDRange(void* ndr){}
 // Odd
 #ifndef __CERIUM_FIFO__
 
--- a/example/multiply/main.cc	Tue Mar 12 17:06:42 2013 +0900
+++ b/example/multiply/main.cc	Fri Mar 15 06:59:19 2013 +0900
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/time.h>
 #include "TaskManager.h"
 #include "Func.h"
 /*
@@ -10,6 +11,7 @@
     size_t lws[3];
 } ND_RANGE_T, *ND_RANGE_T_PTR;
 */
+
 extern void task_init(void);
 static int task = 1;
 static int length = DATA_NUM;
@@ -18,9 +20,30 @@
 
 float *A,*B,*C;
 
+static double st_time;
+static double ed_time;
+
+static double
+getTime() {
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return tv.tv_sec + (double)tv.tv_usec*1e-6;
+}
+
 static void
-print_result()
-{
+check_data() {
+    for(int i=0; i<length;i++) {
+        if (A[i]*B[i]!=C[i]) {
+            printf("Multiplication went wrong.\n");
+            return;
+        }
+        printf("Multiplication was succeeded.\n");
+        return;
+    }
+}
+
+static void
+print_result() {
     printf("---\n");
     for (int i =0;i<length;i++) {
         printf("%f * %f = %f \n",A[i],B[i],C[i]);
@@ -28,6 +51,16 @@
     printf("---\n");
 }
 
+
+void
+init(int args, char *argv[]) {
+    for (int i = 1; argv[i]; ++i) {
+        if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) {
+            length = atoi(argv[++i]);
+        } 
+    }
+}
+
 void
 multi_init(TaskManager *manager)
 {
@@ -40,6 +73,7 @@
         A[i]=(float)(i+1000);
         B[i]=(float)i/10.f;
     }
+    st_time = getTime();
     /**
      * Create Task
      *   create_task(Task ID);
@@ -47,14 +81,13 @@
 
     ND_RANGE_T_PTR ndr = new ND_RANGE_T;
     ndr->dimension = 1;
-    ndr->gws[0] = 100; ndr->gws[1] = 1; ndr->gws[2] = 1;
+    ndr->gws[0] = length; ndr->gws[1] = 1; ndr->gws[2] = 1;
     ndr->lws[0] = 1;   ndr->lws[1] = 1; ndr->lws[2] = 1;
     manager->set_NDRange(ndr);
 
     multiply = manager->create_task(MULTIPLY_TASK);
-    multiply->set_param(0,(memaddr)&ndr);
     multiply->nd_range();
-    multiply->set_cpu(SPE_ANY);
+    multiply->set_cpu(GPU_0);
 
     /**
      * Set of Input Data
@@ -83,10 +116,11 @@
 int
 TMmain(TaskManager *manager,int argc, char *argv[])
 {
+    st_time = getTime();
+    init(argc, argv);
     // Task Register
     //   ppe/task_init.cc
     task_init();
-
     for (int i = 0; i < task; ++i) {
         multi_init(manager);
     }
@@ -99,5 +133,8 @@
 void
 TMend(TaskManager *manager)
 {
+    ed_time = getTime();
     print_result();
+    check_data();
+    printf("Time: %0.6f\n",ed_time-st_time);
 }