PandA-2024.02
histogram.c
Go to the documentation of this file.
1 #define NUM_ACCELS 8
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 temp0 = 0, temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0, temp5 = 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  temp0 += 1;
27  }
28  else if (num > BIN_MAX_NUM && num <= (BIN_MAX_NUM * 2))
29  {
30 // output[1]+=1;
31  temp1 += 1;
32  }
33  else if (num > (BIN_MAX_NUM * 2) && num <= (BIN_MAX_NUM * 3))
34  {
35 // output[2]+=1;
36  temp2 += 1;
37  }
38  else if (num > (BIN_MAX_NUM * 3) && num <= (BIN_MAX_NUM * 4))
39  {
40 // output[3]+=1;
41  temp3 += 1;
42  }
43  else
44  {
45 // output[4]+=1;
46  temp4 += 1;
47  }
48  }
49  printf("%d\n", temp0);
50  output[0] += temp0;
51  output[1] += temp1;
52  output[2] += temp2;
53  output[3] += temp3;
54  output[4] += temp4;
55 
56 }
57 
58 int main ()
59 {
60 
61  int i, j;
62  int main_result = 0;
63 
64  #pragma omp simd
65  for (i = 0; i < NUM_ACCELS; i++)
66  {
68  }
69 
70  //could have been done with locks inside accelerator
71  //combine the results
72  for (i = 0; i < NUM_BINS; i++)
73  {
74  for (j = 0; j < NUM_ACCELS; j++)
75  {
77  }
78  }
79 
80  //check the results
81  for (i = 0; i < NUM_BINS; i++)
82  {
83  main_result += (output_array[i] == expected_array[i]);
84  }
85 
86  //check final result
87  printf ("Result: %d\n", main_result);
88  if (main_result == NUM_BINS)
89  {
90  printf("RESULT: PASS\n");
91  return 0;
92  }
93  else
94  {
95  printf("RESULT: FAIL\n");
96  return 1;
97  }
98 }
void histogram(int *input, int *output, int max_idx)
Definition: histogram.c:11
#define NUM_ACCELS
Definition: histogram.c:1
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 OPS_PER_ACCEL
Definition: histogram.c:9
#define NUM_BINS
Definition: histogram.c:3
int input_array[ARRAY_SIZE]
Definition: histogram.h:1
#define BIN_MAX_NUM
Definition: histogram.c:4
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