| rev |
line source |
|
seanhalle@0
|
1 #include <malloc.h>
|
|
seanhalle@0
|
2 #include <stdlib.h>
|
|
seanhalle@0
|
3 #include <PR__include/PR__WL.h>
|
|
seanhalle@0
|
4
|
|
seanhalle@0
|
5 #include "Matrix_Mult.h"
|
|
seanhalle@0
|
6 #include "Reo__Matrix_Mult/Reo__Matrix_Mult.h"
|
|
seanhalle@0
|
7
|
|
seanhalle@0
|
8 void set_up_performance_counters();
|
|
seanhalle@0
|
9
|
|
seanhalle@0
|
10 // =============================================================================
|
|
seanhalle@0
|
11
|
|
seanhalle@0
|
12 int NUM_ITER;
|
|
seanhalle@0
|
13
|
|
seanhalle@0
|
14
|
|
seanhalle@0
|
15 int main(int argc, char **argv)
|
|
seanhalle@0
|
16 { Matrix *leftMatrix, *rightMatrix, *resultMatrix;
|
|
seanhalle@0
|
17 ParamBag *paramBag;
|
|
seanhalle@1
|
18 MatrixMultWorkUnit **workUnits;
|
|
seanhalle@1
|
19 VPParams *vpParams, **vpParamsArray;
|
|
seanhalle@1
|
20 // ProdParams *prodParams;
|
|
seanhalle@1
|
21 // ConsParams *consParams;
|
|
seanhalle@1
|
22 int32 numUnitsToMake, vpIdx;
|
|
seanhalle@1
|
23 PRProcess *matrixMultProcess;
|
|
seanhalle@0
|
24
|
|
seanhalle@1
|
25 DEBUG__printf(TRUE, "arguments -- numIter: %s | path: %s", argv[1], argv[2] );
|
|
seanhalle@1
|
26 if(argc < 3) {printf("give: num iter and path to param file on cmd line\n"); exit(1);}
|
|
seanhalle@0
|
27 NUM_ITER = atoi(argv[1]);
|
|
seanhalle@1
|
28 numUnitsToMake = NUM_PROD; //defined by Reo circuit generator
|
|
seanhalle@1
|
29
|
|
seanhalle@1
|
30 printf("[reo] Settings: %i workers, %i iterations | file: %s \n", NUM_PROD, NUM_ITER, argv[2]);
|
|
seanhalle@1
|
31
|
|
seanhalle@1
|
32 set_up_performance_counters();
|
|
seanhalle@0
|
33
|
|
seanhalle@0
|
34 //read parameters, from file whose path is given on command line
|
|
seanhalle@0
|
35 paramBag = makeParamBag();
|
|
seanhalle@0
|
36 readParamFileIntoBag( argv[2], paramBag );
|
|
seanhalle@0
|
37 initialize_Input_Matrices_Via( &leftMatrix, &rightMatrix, paramBag );
|
|
seanhalle@0
|
38
|
|
seanhalle@0
|
39
|
|
seanhalle@1
|
40 PR__start();
|
|
seanhalle@1
|
41 PR__set_app_info( "matrix multiply prod cons in Reo" );
|
|
seanhalle@1
|
42 ParamStruc *inputInfo = getParamFromBag( "inputInfo", paramBag );
|
|
seanhalle@1
|
43 PR__set_input_info( inputInfo->strValue );
|
|
seanhalle@0
|
44
|
|
seanhalle@1
|
45 resultMatrix = PR__malloc( sizeof(Matrix) );
|
|
seanhalle@1
|
46 resultMatrix->array = PR__malloc( leftMatrix->numRows * rightMatrix->numCols * sizeof(double) );
|
|
seanhalle@1
|
47 resultMatrix->numCols = rightMatrix->numCols;
|
|
seanhalle@1
|
48 resultMatrix->numRows = leftMatrix->numRows;
|
|
seanhalle@1
|
49 workUnits = divideWork( leftMatrix, rightMatrix, resultMatrix,
|
|
seanhalle@1
|
50 numUnitsToMake );
|
|
seanhalle@0
|
51
|
|
seanhalle@1
|
52 /* For now, don't need any params inside producer function other than
|
|
seanhalle@1
|
53 * the work unit. Also, don't need any params at all inside cons function.
|
|
seanhalle@1
|
54 * So, just send the array of work units to the seed Fn, which will pass it
|
|
seanhalle@1
|
55 * along to the create_VP part of circuit creation, which will copy the
|
|
seanhalle@1
|
56 * elements of the array into the param structs given as initData to the
|
|
seanhalle@1
|
57 * VPs, as they are created.
|
|
seanhalle@1
|
58 *Need a dummy work unit added to end of work-unit array, to avoid a seg
|
|
seanhalle@1
|
59 * fault -- just did a bad hack inside divideWork.
|
|
seanhalle@1
|
60 //Now, create params struct for each producer -- holds work unit
|
|
seanhalle@1
|
61 for( vpIdx=0; vpIdx<numUnitsToMake; vpIdx++)
|
|
seanhalle@1
|
62 {
|
|
seanhalle@1
|
63 vpParams = PR__malloc( sizeof(VPParams) );
|
|
seanhalle@1
|
64 prodParams = PR__malloc( sizeof(ProdParams) );
|
|
seanhalle@1
|
65
|
|
seanhalle@1
|
66 vpParams->initData = prodParams;
|
|
seanhalle@1
|
67 vpParamsArray[vpIdx] = vpParams;
|
|
seanhalle@1
|
68 }
|
|
seanhalle@1
|
69 //create params for consumer
|
|
seanhalle@1
|
70
|
|
seanhalle@1
|
71 vpParams = PR__malloc( sizeof(VPParams) );
|
|
seanhalle@1
|
72 = malloc( sizeof(ProdParams) );
|
|
seanhalle@1
|
73
|
|
seanhalle@1
|
74 vpParams->initData =
|
|
seanhalle@1
|
75 vpParamsArray[vpIdx] = vpParams; //this last entry is for the consumer
|
|
seanhalle@1
|
76 */
|
|
seanhalle@1
|
77
|
|
seanhalle@1
|
78 matrixMultProcess = PR__create_process( &matrix_mult__seed_Fn,
|
|
seanhalle@1
|
79 workUnits );
|
|
seanhalle@1
|
80
|
|
seanhalle@1
|
81 PR__wait_for_process_to_end(matrixMultProcess);
|
|
seanhalle@1
|
82 PR__wait_for_all_activity_to_end();
|
|
seanhalle@0
|
83 fflush(stdout);
|
|
seanhalle@1
|
84 PR__shutdown();
|
|
seanhalle@0
|
85
|
|
seanhalle@0
|
86 exit(0);
|
|
seanhalle@0
|
87 }
|
|
seanhalle@0
|
88
|
|
seanhalle@0
|
89 // =============================================================================
|
|
seanhalle@0
|
90
|
|
seanhalle@0
|
91 /*Initializes the performance counters, and opens the file descriptors used
|
|
seanhalle@0
|
92 * to read from the performance counters
|
|
seanhalle@0
|
93 */
|
|
seanhalle@0
|
94 void set_up_performance_counters() {
|
|
seanhalle@0
|
95 int i;
|
|
seanhalle@0
|
96
|
|
seanhalle@0
|
97 #ifdef MEASURE_PERF
|
|
seanhalle@0
|
98 //setup performance counters
|
|
seanhalle@0
|
99 struct perf_event_attr hw_event;
|
|
seanhalle@0
|
100 memset(&hw_event,0,sizeof(hw_event));
|
|
seanhalle@0
|
101 hw_event.type = PERF_TYPE_HARDWARE;
|
|
seanhalle@0
|
102 hw_event.size = sizeof(hw_event);
|
|
seanhalle@0
|
103 hw_event.disabled = 0;
|
|
seanhalle@0
|
104 hw_event.freq = 0;
|
|
seanhalle@0
|
105 hw_event.inherit = 1; /* children inherit it */
|
|
seanhalle@0
|
106 hw_event.pinned = 1; /* must always be on PMU */
|
|
seanhalle@0
|
107 hw_event.exclusive = 0; /* only group on PMU */
|
|
seanhalle@0
|
108 hw_event.exclude_user = 0; /* don't count user */
|
|
seanhalle@0
|
109 hw_event.exclude_kernel = 1; /* ditto kernel */
|
|
seanhalle@0
|
110 hw_event.exclude_hv = 1; /* ditto hypervisor */
|
|
seanhalle@0
|
111 hw_event.exclude_idle = 1; /* don't count when idle */
|
|
seanhalle@0
|
112 hw_event.mmap = 0; /* include mmap data */
|
|
seanhalle@0
|
113 hw_event.comm = 0; /* include comm data */
|
|
seanhalle@0
|
114
|
|
seanhalle@0
|
115 for( i = 0; i < NUM_CORES; i++ )
|
|
seanhalle@0
|
116 {
|
|
seanhalle@0
|
117 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
|
|
seanhalle@0
|
118 cycles_counter_fd[i] = syscall(__NR_perf_event_open, &hw_event,
|
|
seanhalle@0
|
119 0,//pid_t pid,
|
|
seanhalle@0
|
120 i,//int cpu,
|
|
seanhalle@0
|
121 -1,//int group_fd,
|
|
seanhalle@0
|
122 0//unsigned long flags
|
|
seanhalle@0
|
123 );
|
|
seanhalle@0
|
124 if (cycles_counter_fd[i]<0) {
|
|
seanhalle@0
|
125 fprintf(stderr,"On core %d: ",i);
|
|
seanhalle@0
|
126 perror("Failed to open cycles counter");
|
|
seanhalle@0
|
127 }
|
|
seanhalle@0
|
128 }
|
|
seanhalle@0
|
129
|
|
seanhalle@0
|
130 int cycles_counter_main_fd;
|
|
seanhalle@0
|
131 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles
|
|
seanhalle@0
|
132 hw_event.exclude_kernel=0;
|
|
seanhalle@0
|
133 cycles_counter_main_fd = syscall(__NR_perf_event_open, &hw_event,
|
|
seanhalle@0
|
134 0,//pid_t pid,
|
|
seanhalle@0
|
135 -1,//int cpu,
|
|
seanhalle@0
|
136 -1,//int group_fd,
|
|
seanhalle@0
|
137 0//unsigned long flags
|
|
seanhalle@0
|
138 );
|
|
seanhalle@0
|
139 if (cycles_counter_main_fd<0) {
|
|
seanhalle@0
|
140 perror("Failed to open main cycles counter");
|
|
seanhalle@0
|
141 }
|
|
seanhalle@0
|
142
|
|
seanhalle@0
|
143 #endif
|
|
seanhalle@0
|
144 }
|
|
seanhalle@0
|
145
|