Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VReo > Reo__Matrix_Mult
view main.c @ 3:a6b3cab179b1
Added no-measurments option for platforms without support. Added static X86, ARM
and basic Kalray build support. This branch requires the longjmp versions of
libprt and libvreo
| author | Philipe Louchtch - de Raadt |
|---|---|
| date | Sat, 12 Jul 2014 20:21:47 +0200 |
| parents | 1b61e0c00512 |
| children |
line source
1 #ifdef RTEMS
3 #include <mppa/osconfig.h>
5 #endif
7 #include <stdlib.h>
8 #include <PR__include/PR__WL.h>
10 #include "Matrix_Mult.h"
11 #include "Reo__Matrix_Mult/Reo__Matrix_Mult.h"
13 void set_up_performance_counters();
15 // =============================================================================
17 int numIterations;
19 int main(int argc, char **argv)
20 { Matrix *leftMatrix, *rightMatrix, *resultMatrix;
21 ParamBag *paramBag;
22 MatrixMultWorkUnit **workUnits;
23 VPParams *vpParams, **vpParamsArray;
24 // ProdParams *prodParams;
25 // ConsParams *consParams;
26 int32 numUnitsToMake, vpIdx;
27 PRProcess *matrixMultProcess;
29 DEBUG__printf(TRUE, "arguments -- numIter: %s | path: %s", argv[1], argv[2] );
30 if(argc < 3) {printf("give: num iter and path to param file on cmd line\n"); exit(1);}
31 numIterations = atoi(argv[1]);
32 numUnitsToMake = NUM_PROD-1; //defined by Reo circuit generator
34 printf("[reo] Settings: %i workers, %i iterations | file: %s \n", NUM_PROD, numIterations, argv[2]);
36 set_up_performance_counters();
38 //read parameters, from file whose path is given on command line
39 paramBag = makeParamBag();
40 readParamFileIntoBag( argv[2], paramBag );
41 initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag );
44 PR__start();
45 PR__set_app_info( "matrix multiply prod cons in Reo" );
46 ParamStruc *inputInfo = getParamFromBag( "inputInfo", paramBag );
47 PR__set_input_info( inputInfo->strValue );
49 resultMatrix = PR__malloc( sizeof(Matrix) );
50 resultMatrix->array = PR__malloc( leftMatrix->numRows * rightMatrix->numCols * sizeof(double) );
51 resultMatrix->numCols = rightMatrix->numCols;
52 resultMatrix->numRows = leftMatrix->numRows;
53 workUnits = divideWork( leftMatrix, rightMatrix, resultMatrix,
54 numUnitsToMake );
56 /* For now, don't need any params inside producer function other than
57 * the work unit. Also, don't need any params at all inside cons function.
58 * So, just send the array of work units to the seed Fn, which will pass it
59 * along to the create_VP part of circuit creation, which will copy the
60 * elements of the array into the param structs given as initData to the
61 * VPs, as they are created.
62 *Need a dummy work unit added to end of work-unit array, to avoid a seg
63 * fault -- just did a bad hack inside divideWork.
64 */
65 matrixMultProcess = PR__create_process( &matrix_mult__seed_Fn,
66 workUnits );
68 PR__wait_for_process_to_end(matrixMultProcess);
69 PR__wait_for_all_activity_to_end();
70 DEBUG__printf(dbgAppFlow, "activity ended, about to call PR__shutdown");
71 fflush(stdout);
72 PR__shutdown();
74 printf("Something with done..\n\n");
75 usleep(1000);
76 fflush(stdout);
78 exit(0);
79 }
81 // =============================================================================
83 /*Initializes the performance counters, and opens the file descriptors used
84 * to read from the performance counters
85 */
86 void set_up_performance_counters() {
87 int i;
89 #ifdef MEASURE_PERF
90 //setup performance counters
91 struct perf_event_attr hw_event;
92 memset(&hw_event,0,sizeof(hw_event));
93 hw_event.type = PERF_TYPE_HARDWARE;
94 hw_event.size = sizeof(hw_event);
95 hw_event.disabled = 0;
96 hw_event.freq = 0;
97 hw_event.inherit = 1; /* children inherit it */
98 hw_event.pinned = 1; /* must always be on PMU */
99 hw_event.exclusive = 0; /* only group on PMU */
100 hw_event.exclude_user = 0; /* don't count user */
101 hw_event.exclude_kernel = 1; /* ditto kernel */
102 hw_event.exclude_hv = 1; /* ditto hypervisor */
103 hw_event.exclude_idle = 1; /* don't count when idle */
104 hw_event.mmap = 0; /* include mmap data */
105 hw_event.comm = 0; /* include comm data */
107 for( i = 0; i < NUM_CORES; i++ )
108 {
109 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
110 cycles_counter_fd[i] = syscall(__NR_perf_event_open, &hw_event,
111 0,//pid_t pid,
112 i,//int cpu,
113 -1,//int group_fd,
114 0//unsigned long flags
115 );
116 if (cycles_counter_fd[i]<0) {
117 fprintf(stderr,"On core %d: ",i);
118 perror("Failed to open cycles counter");
119 }
120 }
122 int cycles_counter_main_fd;
123 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
124 hw_event.exclude_kernel=0;
125 cycles_counter_main_fd = syscall(__NR_perf_event_open, &hw_event,
126 0,//pid_t pid,
127 -1,//int cpu,
128 -1,//int group_fd,
129 0//unsigned long flags
130 );
131 if (cycles_counter_main_fd<0) {
132 perror("Failed to open main cycles counter");
133 }
135 #endif
136 }
