PandA-2024.02
histogram.c
Go to the documentation of this file.
1 #define NUM_ACCELS 6
2 #define MAX_NUM 100
3 #define NUM_BINS 5
4 #define BIN_MAX_NUM MAX_NUM/NUM_BINS
5 //#define ARRAY_SIZE 60
6 //#define ARRAY_SIZE 120
7 //#define ARRAY_SIZE 6000
8 #define ARRAY_SIZE 36000
9 #define OPS_PER_ACCEL ARRAY_SIZE/NUM_ACCELS
10 
11 #include <stdio.h>
12 #include "histogram.h"
13 
14 void histogram (int * input, int * output, int max_idx)
15 {
16  int i, num;
17  int temp[5] = {0, 0, 0, 0, 0};
18  //make local variables here instead of reading and writing to global memory each time???
19  for (i = 0; i < max_idx; i++)
20  {
21 // printf ("%d\n", input[startidx]);
22  num = input[i];
23  if (num > 0 && num <= BIN_MAX_NUM)
24  {
25 // output[0]+=1;
26  temp[0] += 1;
27  }
28  else if (num > BIN_MAX_NUM && num <= (BIN_MAX_NUM * 2))
29  {
30 // output[1]+=1;
31  temp[1] += 1;
32  }
33  else if (num > (BIN_MAX_NUM * 2) && num <= (BIN_MAX_NUM * 3))
34  {
35 // output[2]+=1;
36  temp[2] += 1;
37  }
38  else if (num > (BIN_MAX_NUM * 3) && num <= (BIN_MAX_NUM * 4))
39  {
40 // output[3]+=1;
41  temp[3] += 1;
42  }
43  else
44  {
45 // output[4]+=1;
46  temp[4] += 1;
47  }
48  }
49 
50  for (i = 0; i < NUM_BINS; i++)
51  {
52  output[i] += temp[i];
53  }
54 
55 }
56 
57 int main ()
58 {
59 
60  int i, j;
61  int main_result = 0;
62 
63  #pragma omp parallel for num_threads(NUM_ACCELS) private(i)
64  for (i = 0; i < NUM_ACCELS; i++)
65  {
67  }
68 
69  //could have been done with locks inside accelerator
70  //combine the results
71  for (i = 0; i < NUM_BINS; i++)
72  {
73  for (j = 0; j < NUM_ACCELS; j++)
74  {
76  }
77  }
78 
79  //check the results
80  for (i = 0; i < NUM_BINS; i++)
81  {
82  main_result += (output_array[i] == expected_array[i]);
83  }
84 
85  //check final result
86  printf ("Result: %d\n", main_result);
87  if (main_result == NUM_BINS)
88  {
89  printf("RESULT: PASS\n");
90  return 0;
91  }
92  else
93  {
94  printf("RESULT: FAIL\n");
95  return 1;
96  }
97 }
void histogram(int *input, int *output, int max_idx)
Definition: histogram.c:11
int input[SIZE]
Definition: hash.h:1
int expected_array[NUM_BINS]
Definition: histogram.h:4
int main_result
Definition: mips.c:38
volatile int output[DIM_Y][DIM_X]
Definition: los.h:1
int main()
Definition: histogram.c:49
int output_array[NUM_BINS]
Definition: histogram.h:3
#define NUM_BINS
Definition: histogram.c:3
#define BIN_MAX_NUM
Definition: histogram.c:4
#define NUM_ACCELS
Definition: histogram.c:1
int input_array[ARRAY_SIZE]
Definition: histogram.h:1
#define OPS_PER_ACCEL
Definition: histogram.c:9
int output_array_accel[NUM_BINS *NUM_ACCELS]
Definition: histogram.h:6

Generated on Mon Feb 12 2024 13:02:48 for PandA-2024.02 by doxygen 1.8.13