-
Notifications
You must be signed in to change notification settings - Fork 0
/
vecAltinorKernel.cl
95 lines (78 loc) · 1.96 KB
/
vecAltinorKernel.cl
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
#define BLACK_SPACE 'X'
#define CL_LOG ( 0 )
#define CL_LOG_VERBOSE ( 0 )
__kernel void matchVectors(
__global const uchar *a,
__global const uchar *b,
volatile __global uint *c,
__global uint *signature_length,
__global uint *parts,
__global uint *payload_length)
{
uint n = get_global_id(0); // or get_global_id
*c = 0;
#if ( CL_LOG_VERBOSE != 0 )
printf( "CL, signature_length: %u\n", *signature_length);
printf( "CL, parts: %u\n", *parts);
printf( "CL, payload_length: %u\n", *payload_length);
printf( "CL, get_global_id: %u\n", n);
#endif
for ( int i = 0; i < *parts; i++ )
{
uint p = n;
uint q = ( (*payload_length) * i ) + n;
#if ( CL_LOG != 0 )
printf( "a[%u]=%c, b[%u]=%c", p, a[p], q, b[q] );
#endif
if ( p == 0 )
{
*c = 0;
}
if ( ( a[p] ^ b[q] ) == 0 )
{
if ( b[q] != BLACK_SPACE )
{
atomic_inc(c);
#if ( CL_LOG != 0 )
// printf( "a[%u]=%c, b[%u]=%c", p, a[p], q, b[q] );
#endif
}
else // Consider removing this and using the sum of two consequent executions - in case
*c = 0; // the signature is divided between the end of packet N and the begging of packet N+1
}
barrier( CLK_GLOBAL_MEM_FENCE );
if ( *c == *signature_length )
return;
}
}
/*
Not used yet. Consider adding a barrier and re-test. Don't forget to change the
size_t globalItemSize = rows * cols; instead of PAYLOAD_LEN
*/
__kernel void matchVectorsAlternative(
__global const uchar *a,
__global const uchar *b,
volatile __global uint *c,
__global uint *signature_length,
__global uint *parts,
__global uint *payload_length)
{
uint n = get_global_id(0);
uint p = n % (*payload_length);
uint q = n;
if ( p == 0 )
*c = 0;
if ( ( a[p] ^ b[q] ) == 0 )
{
if ( b[q] != BLACK_SPACE )
{
atomic_inc(c);
#if ( CL_LOG != 0 )
// printf( "a[%u]=%c, b[%u]=%c", p, a[p], q, b[q] );
#endif
}
}
if ( *c == *signature_length )
return;
// printf( "NG CL, p: %u | q: %u\n", p, q );
}