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