-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm3_test_omx.c
146 lines (122 loc) · 3.85 KB
/
m3_test_omx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "m3.c"
#define NUM_ITER 1
#define IMG_SIZE 4096
#define HISTO_SIZE 256
#define NUM_TOTAL_THREADS 5
int* histo[NUM_TOTAL_THREADS] ;
int m3_histo[HISTO_SIZE] ;
int m3_gray_level_mapping[HISTO_SIZE] ;
void* compute_histo(int* restrict image, int* restrict histo, int img_start_indx, int img_end_indx)
{
int i, j ;
for (i = 0 ; i < HISTO_SIZE ; i++) {
histo[0*HISTO_SIZE+i] = 0;
}
for (i = img_start_indx ; i < img_end_indx ; i++) {
for (j = 0; j < IMG_SIZE; ++j) {
image[i*IMG_SIZE+j] = (i*j) % 255 ;
}
}
/* Compute the image's histogram */
for (i = img_start_indx ; i < img_end_indx ; i++) {
for (j = 0; j < IMG_SIZE; ++j) {
int pix = image[i*IMG_SIZE+j] ;
histo[0*HISTO_SIZE+pix] += 1;
}
}
return NULL ;
}
void* compute_image(int* restrict image, int* restrict gray_level_mapping, int img_start_indx, int img_end_indx)
{
int i, j ;
/* Map the old gray levels in the original image to the new gray levels. */
for (i = img_start_indx ; i < img_end_indx ; i++) {
for (j = 0; j < IMG_SIZE; ++j) {
image[i*IMG_SIZE+j] = gray_level_mapping[image[i*IMG_SIZE+j]];
}
}
return NULL ;
}
void compute_gray_level_mapping()
{
int j, k ;
int cdf, pixels ;
for(j=0 ; j<NUM_TOTAL_THREADS ; j++) {
for(k=0 ; k<HISTO_SIZE ; k++) {
if(j==0)
m3_histo[k] = (histo[j])[k] ;
else
m3_histo[k] += (histo[j])[k] ;
}
}
cdf = 0 ;
pixels = (int)(IMG_SIZE * IMG_SIZE) ;
for(j=0 ; j<HISTO_SIZE ; j++) {
cdf += ((int)(m3_histo[j]))/pixels ;
m3_gray_level_mapping[j] = (int)(255 * cdf) ;
}
}
void common_wrapper(UArg arg0, UArg arg1)
{
taskArgs* t = (taskArgs*)arg0 ;
int tid = (int)arg1 ;
int i, j, k ;
for(i=0 ; i<NUM_ITER ; i++) {
if(tid == 0) {
callBarrier(0, /*lock_id=*/4) ;
System_printf("Thread indx=%d called\n",tid) ;
callLocalBarrier() ;
} else {
System_printf("Thread indx=%d called\n",tid) ;
callLocalBarrier() ;
}
compute_histo(t->buffer1, t->buffer2, t->start_indx, t->end_indx) ;
Cache_wbInv (t->buffer2, HISTO_SIZE*4, Cache_Type_ALL, FALSE) ;
if(tid == 0) {
callBarrier(1, /*lock_id=*/4) ;
compute_gray_level_mapping() ;
callLocalBarrier() ;
} else {
callLocalBarrier() ;
}
compute_image(t->buffer1, m3_gray_level_mapping, t->start_indx, t->end_indx) ;
callLocalBarrier() ;
if(tid == 0)
Cache_wbInv (t->buffer1, IMG_SIZE*IMG_SIZE*4, Cache_Type_ALL, FALSE);
}
if(tid == 0)
Event_post(edgeDetectEvent, Event_Id_00) ;
else
Event_post(edgeDetectEvent, Event_Id_01) ;
}
Int32 fxnTest1(UInt32 size, UInt32 *data)
{
FxnArgs *args = (FxnArgs *)((UInt32)data + sizeof(map_info_type));
t1.buffer1 = t2.buffer1 = (int*)args->a ;
t1.buffer2 = (int*)args->d ;
t2.buffer2 = (int*)args->e ;
histo[0] = (int*)args->b ;
histo[1] = (int*)args->c ;
histo[2] = (int*)args->d ;
histo[3] = (int*)args->e ;
histo[4] = (int*)args->f ;
t1.start_indx = t2.start_indx = args->start_indx;
t1.end_indx = t2.end_indx = args->end_indx;
int unit_work = (t2.end_indx - t1.start_indx)/2 ;
t1.end_indx = t1.start_indx + unit_work ;
t2.start_indx = t2.start_indx + unit_work ;
task0 = Task_create((Task_FuncPtr)common_wrapper, &taskParams0, &eb0);
if (task0 == NULL) {
System_abort("Task create failed");
}
task1 = Task_create((Task_FuncPtr)common_wrapper, &taskParams1, &eb1);
if (task1 == NULL) {
// System_abort("Task create failed");
}
UInt events ;
events = Event_pend(edgeDetectEvent, Event_Id_00 + Event_Id_01, Event_Id_NONE, BIOS_WAIT_FOREVER) ;
Task_delete(&task0) ;
Task_delete(&task1) ;
Uint32 reta = 1 ;
return reta ;
}