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 36000
6 #define OPS_PER_ACCEL ARRAY_SIZE/NUM_ACCELS
7 
8 #include <stdio.h>
9 #include "histogram.h"
10 
11 void histogram (int * input, int * output, int max_idx)
12 {
13  int i, num;
14  int temp0 = 0, temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0, temp5 = 0;
15  //make local variables here instead of reading and writing to global memory each time
16  for (i = 0; i < max_idx; i++)
17  {
18  num = input[i];
19  if (num > 0 && num <= BIN_MAX_NUM)
20  {
21  temp0 += 1;
22  }
23  else if (num > BIN_MAX_NUM && num <= (BIN_MAX_NUM * 2))
24  {
25  temp1 += 1;
26  }
27  else if (num > (BIN_MAX_NUM * 2) && num <= (BIN_MAX_NUM * 3))
28  {
29  temp2 += 1;
30  }
31  else if (num > (BIN_MAX_NUM * 3) && num <= (BIN_MAX_NUM * 4))
32  {
33  temp3 += 1;
34  }
35  else
36  {
37  temp4 += 1;
38  }
39  }
40  printf("%d\n", temp0);
41  output[0] += temp0;
42  output[1] += temp1;
43  output[2] += temp2;
44  output[3] += temp3;
45  output[4] += temp4;
46 
47 }
48 
49 int main ()
50 {
51 
52  int i, j;
53  int main_result = 0;
54 
55  #pragma omp simd
56  for (i = 0; i < NUM_ACCELS; i++)
57  {
59  }
60 
61  //combine the results
62  for (i = 0; i < NUM_BINS; i++)
63  {
64  for (j = 0; j < NUM_ACCELS; j++)
65  {
67  }
68  }
69 
70  //check the results
71  for (i = 0; i < NUM_BINS; i++)
72  {
73  main_result += (output_array[i] == expected_array[i]);
74  }
75 
76  //check final result
77  printf ("Result: %d\n", main_result);
78  if (main_result == NUM_BINS)
79  {
80  printf("RESULT: PASS\n");
81  return 0;
82  }
83  else
84  {
85  printf("RESULT: FAIL\n");
86  return 1;
87  }
88 }
void histogram(int *input, int *output, int max_idx)
Definition: histogram.c:11
#define NUM_BINS
Definition: histogram.c:3
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:6
int input_array[ARRAY_SIZE]
Definition: histogram.h:1
#define BIN_MAX_NUM
Definition: histogram.c:4
#define NUM_ACCELS
Definition: histogram.c:1
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