-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreception_kernel.c
More file actions
73 lines (64 loc) · 2.26 KB
/
reception_kernel.c
File metadata and controls
73 lines (64 loc) · 2.26 KB
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
#define MAX_LIG %(max_lig)d
#define ROW_SIZE %(row_size)d
#define POP_SIZE %(pop_size)d
/*
Kernel implementing ligand reception. Its result is pop_hit - array [1...POP_SIZE, 1...MAX_LIG] with values {0, 1},
where 1 at pop_hit[i,k] means cell i absorbed ligand k.
*/
__kernel void reception(__global int* pop_hit, __global float* env, __global float* mul_mat,
__global float* pop, __global int* receptors,
__global ranluxcl_state_t *ranluxcltab)
{
size_t env_idx = get_global_id(0);
ranluxcl_state_t ranluxclstate;
ranluxcl_download_seed(&ranluxclstate, ranluxcltab);
for (int lig_idx = 0; lig_idx < MAX_LIG; ++lig_idx)
{
float lig = env[env_idx * MAX_LIG + lig_idx];
int rec = receptors[lig_idx];
if (lig > 0)
{
float diff = 0.0f;
for (int i = 0; i < POP_SIZE; ++i)
/* for each cell we check if it gets the ligand */
{
if (rec < 0 || pop[i * ROW_SIZE + rec] > 0)
/* if cell can accept the ligand */
{
float prob = lig * mul_mat[i + POP_SIZE * env_idx];
if (prob > 0)
/* if ligand is accepted */
{
pop_hit[lig_idx + i * MAX_LIG] = 1;
diff += 1.0f;
}
}
}
env[env_idx * MAX_LIG + lig_idx] = max(0.0f, lig - diff);
}
}
ranluxcl_upload_seed(&ranluxclstate, ranluxcltab);
}
/*
Kernel updating population state according to pop_hit array calculated by reception kernel.
*/
__kernel void update_pop_with_reception(__global float* pop, __global int* pop_hit,
__global int* rec_gene, __global float* bound)
{
size_t cell_idx = get_global_id(0);
for (int lig_idx = 0; lig_idx < MAX_LIG; ++lig_idx)
{
if (pop_hit[cell_idx * MAX_LIG + lig_idx] > 0)
{
int k = rec_gene[lig_idx];
pop[cell_idx * ROW_SIZE + k] = min(pop[cell_idx * ROW_SIZE + k] + 1.0f, bound[k]);
}
}
}
/*
Kernel filling given buffer with specified value.
*/
__kernel void fill_buffer(__global int* buf, __private int x)
{
buf[get_global_id(0)] = x;
}