changeset 1:dcd83cefb980

check , ppe_only, show time , function add.
author yutaka@localhost.localdomain
date Tue, 06 Apr 2010 22:52:33 +0900
parents 68a98d68d62a
children 1e1b0d280427
files Makefile include/Sys.h ppe/Manager.cc ppe/Menu.cc ppe/Run.cc ppe/Sys.cc spe/Run.cc spe/SpeSentry.cc
diffstat 8 files changed, 245 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Mar 28 19:47:00 2010 +0900
+++ b/Makefile	Tue Apr 06 22:52:33 2010 +0900
@@ -13,16 +13,13 @@
 PPESRC = $(shell ls ppe/*.cc)
 SPESRC = $(shell ls spe/*.cc)
 
-#PPEOBJ = $(PPESRC:.cc=.o)
-#SPEOBJ = $(SPESRC:.cc=.o)
-
 all: $(PPETARGET) $(SPETARGET)
 
 $(PPETARGET): $(PPEOBJ)
 	$(PPECC) $(PPELIB) $(INC) $(PPESRC) -o $@
 
 $(SPETARGET): $(SPEOBJ)
-	$(SPECC) $(INC) $(SPESRC) -o $@
+	$(SPECC) $(SPELIB) $(INC) $(SPESRC) -o $@
 
 clean:
 	rm -f $(PPETARGET) $(SPETARGET)
--- a/include/Sys.h	Sun Mar 28 19:47:00 2010 +0900
+++ b/include/Sys.h	Tue Apr 06 22:52:33 2010 +0900
@@ -2,4 +2,5 @@
 
 void* allocate(int size);
 int size_fix(int size, int fix);
+void fix_type(send_params_t *send_params_t, void *buff);
 send_params_t task_allocate(int size);
--- a/ppe/Manager.cc	Sun Mar 28 19:47:00 2010 +0900
+++ b/ppe/Manager.cc	Tue Apr 06 22:52:33 2010 +0900
@@ -3,15 +3,95 @@
 #include <libspe2.h>
 #include <pthread.h>
 #include <time.h>
+#include <unistd.h>
 #include "Manager.h"
 #include "MailCommand.h"
 #include "SIZE.h"
 #include "Sys.h"
 #include "Spe.h"
 #include "Menu.h"
+#include "Run.h"
 #include "params.h"
 
 void
+ppe_run(send_params_head_t *head, int tmphead_num)
+{
+
+  send_params_head_t *tmphead;
+  send_params_t *tmp = (send_params_t*)allocate(sizeof(send_params_t));
+  
+  //printf("hoge1\n");
+
+  for (int j = 0; j < tmphead_num; j++) {
+
+    //printf("hoge\n");
+
+    for (tmphead = (send_params_head_t*)head[j].next_task; tmphead != 0; tmphead = (send_params_head_t*)tmphead->next_task) {
+
+      fix_type(tmp, (void*)tmphead);
+
+      int *out = (int*)tmp->head->ea_out;
+      int *in = (int*)tmp->buff;
+
+      //printf("in[%d] %f\n",i,in[i]);
+      //printf("out[%d] %f\n",i,out[i]);
+      
+      run(in, out, tmp->head->size_out);
+	
+      //printf("out_spe[%d] %f\n",i,out_spe[i]);
+      //printf("out[%d] %f\n",i,out[i]);
+      
+
+    }
+    
+  }
+
+}
+
+void
+check_output(send_params_head_t *head, int tmphead_num)
+{
+
+  send_params_head_t *tmphead;
+  send_params_t *tmp = (send_params_t*)allocate(sizeof(send_params_t));
+  
+  for (int j = 0; j < tmphead_num; j++) {
+
+    for (tmphead = (send_params_head_t*)head[j].next_task; tmphead != 0; tmphead = (send_params_head_t*)tmphead->next_task) {
+
+      fix_type(tmp, (void*)tmphead);
+
+      int *out = (int*)tmp->head->ea_out;
+      int *out_spe = (int*)allocate(tmp->head->size_out);
+      int *in = (int*)tmp->buff;
+
+      //printf("in[%d] %f\n",i,in[i]);
+      //printf("out[%d] %f\n",i,out[i]);
+      
+      run(in, out_spe, tmp->head->size_out);
+	
+      //printf("out_spe[%d] %f\n",i,out_spe[i]);
+      //printf("out[%d] %f\n",i,out[i]);
+
+      for (int i = 0; i < tmp->head->size_out / sizeof(int); i++) {
+	
+	printf("out_spe[%d] %d\n",i,out_spe[i]);
+
+	if (out_spe[i] != out[i]) {
+	  printf("!\n");
+	}
+
+      }
+      
+      free(out_spe);
+
+    }
+    
+  }
+
+}
+
+void
 send_task_params(int &head_num, int &index, send_params_head_t *head,
 		 spe_context_ptr_t spe, int &flag)
 {
@@ -43,6 +123,45 @@
 main(int argc, char *argv[])
 {
 
+  clock_t prog_s = 0;
+  clock_t prog_e = 0;
+
+  prog_s = clock();
+
+  clock_t create_s = 0;
+  clock_t create_e = 0;
+  clock_t run_s = 0;
+  clock_t run_e = 0;
+
+  int opt;
+  int check_flag = 0;
+  int time_flag = 0;
+  int ppe_flag = 0;
+
+  while ( (opt = getopt(argc, argv, "ctp")) != -1) {
+    switch( opt ) {
+    case 'c' : check_flag = 1; break;
+    case 't' : time_flag = 1; break;
+    case 'p' : ppe_flag = 1; break;
+    }
+  }
+
+  if (ppe_flag) {
+
+    int head_num;
+    send_params_head_t *head = menu(head_num);
+    ppe_run(head, head_num);
+
+    prog_e = clock();
+    
+    if (time_flag) {
+      printf("program_run_time %f\n",(double)(prog_e - prog_s)/CLOCKS_PER_SEC);
+    }
+
+    return 0;
+
+  }
+
   spe_program_handle_t *prog;
   //スタック上にとるのはだめだめ。malloc
   spe_context_ptr_t spe[SPE_NUM];
@@ -55,19 +174,17 @@
   int all_spe_run_end = SPE_NUM;
   int flag = 0;
 
-
-  clock_t start = 0,end = 0;
-  //start = clock();
-
   int head_num = 0;
+  create_s = clock();
   send_params_head_t *head = menu(head_num);
-
-  //end = clock();  
-  //printf("task create %f\n",(double)(end-start)/CLOCKS_PER_SEC);
+  create_e = clock();
+  int tmphead_num = head_num;
 
   int index = 0;
   unsigned int data = 0;
 
+  run_s = clock();
+
   //mail check
   while(flag != all_spe_run_end) {
     
@@ -78,19 +195,35 @@
 	//spe wait come task
 	//ppe send task or run end request mail for spe
 	if (data == WANT_DATA) {
+	  //printf("spe %p\n",spe[i]);
 	  send_task_params(head_num, index, head, spe[i], flag);
 	}
 
       }
 
     }// end for
-
  
   }//end while mail check
 
   spe_run_endwait(spe,thread,SPE_NUM);
   spe_image_close(prog);
 
+  run_e = clock();
+
+  if (check_flag) {
+    printf("check now\n");
+    check_output(head, tmphead_num);
+  }
+
+  prog_e = clock();
+
+  if (time_flag) {
+    printf("create_task_time %f\n",(double)(create_e - create_s)/CLOCKS_PER_SEC);
+    printf("run_calc_time %f\n",(double)(run_e - run_s)/CLOCKS_PER_SEC);
+    printf("program_run_time %f\n",(double)(prog_e - prog_s)/CLOCKS_PER_SEC);
+  }
+
+  //head[0]
 
   return 0;
 
--- a/ppe/Menu.cc	Sun Mar 28 19:47:00 2010 +0900
+++ b/ppe/Menu.cc	Tue Apr 06 22:52:33 2010 +0900
@@ -17,8 +17,8 @@
   int in_size  = (task_size - sizeof(send_params_head_t)) * all_task_num;
   int out_size = (task_size - sizeof(send_params_head_t)) * all_task_num;
 
-  float *in;
-  float *out = (float*)allocate(out_size);
+  int *in;
+  int *out = (int*)allocate(out_size);
 
   int partition_size = task_size - sizeof(send_params_head_t);
   send_params_t *send_params = (send_params_t*)allocate(sizeof(send_params_t)*all_task_num);
@@ -28,9 +28,9 @@
   for (int i = 0; i < all_task_num; i++) {
 
     send_params[i] = task_allocate(task_size); // header と、in サイズを確保するよ。
-    in = (float*)send_params[i].buff;
+    in = (int*)send_params[i].buff;
     
-    for (int j = 0; j < partition_size / sizeof(float); j++) {
+    for (int j = 0; j < partition_size / sizeof(int); j++) {
       in[j] = j;
       //printf("%f\n",in[j]);
     }
@@ -45,7 +45,7 @@
     head[i].next_task = (unsigned long) send_params[index].head;
     head[i].next_task_size = task_size;
 
-    head[i].ea_out   = (unsigned long) &out[(index * partition_size) / sizeof(float)];
+    head[i].ea_out   = (unsigned long) &out[(index * partition_size) / sizeof(int)];
     head[i].size_out = partition_size;
 
     head[i].pin_in   = 0;
@@ -59,7 +59,7 @@
       send_params[index].head->next_task      = (unsigned long) send_params[index+1].head;
       send_params[index].head->next_task_size = task_size;
 
-      send_params[index].head->ea_out = (unsigned long) &out[((index) * partition_size) / sizeof(float)];
+      send_params[index].head->ea_out = (unsigned long) &out[((index) * partition_size) / sizeof(int)];
       send_params[index].head->size_out = partition_size;
 
       send_params[index].head->pin_in = 0;
@@ -74,7 +74,7 @@
     send_params[index].head->next_task      = 0;
     send_params[index].head->next_task_size = 0;
 
-    send_params[index].head->ea_out = (unsigned long) &out[(index) * partition_size / sizeof(float)];
+    send_params[index].head->ea_out = (unsigned long) &out[(index) * partition_size / sizeof(int)];
 
     //printf("[PPE] %p\n",(unsigned long)send_params[index].head->ea_out);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ppe/Run.cc	Tue Apr 06 22:52:33 2010 +0900
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include "Run.h"
+
+void
+run(void *in, void *out, int data_length)
+{
+
+  for (int i = 0; i < data_length / sizeof(int); i++) {
+
+    int *in_spe  = (int*)in;
+    int *out_spe = (int*)out;
+
+    //printf("in_spe %d\n",in_spe[i]);
+
+    out_spe[i] = 1;
+
+    for (int j = 2; j < in_spe[i]; j++) {
+
+      //printf("hogehoge\n");
+
+      if ( in_spe[i] % j == 0) {
+	out_spe[i] = 0;
+	break;
+      }
+
+    }
+
+    //if (out_spe[i] == 1) {
+    //  printf("in_spe[%d] %d\n",i,in_spe[i]);
+    //}
+
+    /*
+    out_spe[i] = in_spe[i] + 1;
+
+    out_spe[i] = out_spe[i] + 1;
+    out_spe[i] = out_spe[i]*out_spe[i];
+    out_spe[i] = out_spe[i] + 1;
+    */
+    //printf("[SPE]int_spe %f\n",in_spe[i]);
+
+    //printf("[SPE]outt_spe %f\n",out_spe[i]);
+
+
+
+  }
+
+}
--- a/ppe/Sys.cc	Sun Mar 28 19:47:00 2010 +0900
+++ b/ppe/Sys.cc	Tue Apr 06 22:52:33 2010 +0900
@@ -26,6 +26,19 @@
 
 }
 
+void
+fix_type(send_params_t *send_params, void *buff)
+{
+
+  char *p;
+  p = (char*)buff;
+  p = p + sizeof(send_params_head_t);
+
+  send_params->head = (send_params_head_t*)buff;
+  send_params->buff = p;
+
+}
+
 send_params_t
 task_allocate(int size)
 {
@@ -34,18 +47,12 @@
     printf("allocate size is not multiple of 16\n");
   }
 
-  char *buff;
   int alignment = 16;
   send_params_t send_params;
 
-  void *head;
-  posix_memalign(&head, alignment, size);
-
-  buff = (char*)head;
-  buff = buff + sizeof(send_params_head_t);
-
-  send_params.head = (send_params_head_t*)head;
-  send_params.buff = buff;
+  void *buff;
+  posix_memalign(&buff, alignment, size);
+  fix_type(&send_params, buff);
 
   return send_params;
 
--- a/spe/Run.cc	Sun Mar 28 19:47:00 2010 +0900
+++ b/spe/Run.cc	Tue Apr 06 22:52:33 2010 +0900
@@ -5,21 +5,41 @@
 run(void *in, void *out, int data_length)
 {
 
-  for (int i = 0; i < data_length / sizeof(float); i++) {
+  for (int i = 0; i < data_length / sizeof(int); i++) {
+
+    int *in_spe  = (int*)in;
+    int *out_spe = (int*)out;
 
+    //printf("in_spe %d\n",in_spe[i]);
+
+    out_spe[i] = 1;
+
+    for (int j = 2; j < in_spe[i]; j++) {
 
-    
-    float *in_spe  = (float*)in;
-    float *out_spe = (float*)out;
+      if ( in_spe[i] % j == 0) {
+	out_spe[i] = 0;
+	break;
+      }
 
-    //printf("%f\n",in_spe[i]);
-    
+    }
+
+    //if (out_spe[i] == 1) {
+    //  printf("in_spe[%d] %d\n",i,in_spe[i]);
+    //}
+
+    /*
     out_spe[i] = in_spe[i] + 1;
 
     out_spe[i] = out_spe[i] + 1;
     out_spe[i] = out_spe[i]*out_spe[i];
     out_spe[i] = out_spe[i] + 1;
+    */
     //printf("[SPE]int_spe %f\n",in_spe[i]);
+
+    //printf("[SPE]outt_spe %f\n",out_spe[i]);
+
+
+
   }
 
 }
--- a/spe/SpeSentry.cc	Sun Mar 28 19:47:00 2010 +0900
+++ b/spe/SpeSentry.cc	Tue Apr 06 22:52:33 2010 +0900
@@ -97,12 +97,12 @@
 	//printf("[SPE] data %p\n",data);
 
 	dma_get(head, data, sizeof(send_params_head_t), head_tag);
-	dma_wait(head_tag);
+	dma_wait_time += dma_wait(head_tag);
 
 	input_buff[0] = allocate(head->next_task_size);
 
 	dma_get(input_buff[0], head->next_task, head->next_task_size, in_tag[0]);
-	dma_wait(in_tag[0]);
+	dma_wait_time += dma_wait(in_tag[0]);
 
 	fix_type(send_params,input_buff[0]);
 
@@ -130,8 +130,8 @@
 
 	  free(input_buff[cur]);
 
-	  dma_wait(in_tag[cur^1]);
-	  dma_wait(out_tag[cur^1]);
+	  dma_wait_time += dma_wait(in_tag[cur^1]);
+	  dma_wait_time += dma_wait(out_tag[cur^1]);
 	  //printf("hoge");
 
 	  free(output_buff[cur^1]);
@@ -147,8 +147,6 @@
 	}//while
  
 
-
-
 	  void *in  = send_params->buff;
 
 	  //printf("hoge");
@@ -166,12 +164,10 @@
 
 	  free(input_buff[cur]);
 
-	  dma_wait(out_tag[cur] | out_tag[cur^1] );
+	  dma_wait_time += dma_wait(out_tag[cur] | out_tag[cur^1] );
 	  free(output_buff[cur]);
 	  free(output_buff[cur^1]);
 
-
- 
 	  spu_write_out_mbox(WANT_DATA);
 	  //printf("[SPE] send mail\n");
 	  
@@ -182,6 +178,7 @@
 
   }//while
 
+  printf("dma_wait_time %d\n",dma_wait_time);
 
   return 0;