Krnl_PRNG.cl 17.9 KB
Newer Older
Leonardo Solis's avatar
Leonardo Solis committed
1
// --------------------------------------------------------------------------
2
3
// PRNG generators are implemented as Linear Feedback Shift Registers (LFSR)
// All are 32-bit LFRS, feedback taps: 30, 20, 26, 25
Leonardo Solis's avatar
Leonardo Solis committed
4
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
5
/*
6
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
7
8
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
9
10
11
12
13
14
15
void Krnl_Prng_BT_ushort_float(unsigned int Host_seed1,
			       unsigned int Host_seed2,
			       unsigned int DockConst_pop_size){

	uint2 lfsr;
	lfsr.x = Host_seed1;
	lfsr.y = Host_seed2;
lvs's avatar
lvs committed
16
/*
17
	bool valid  = false;
lvs's avatar
lvs committed
18
19
*/
	int valid = 1;
20
	
lvs's avatar
lvs committed
21
/*
22
	while(!valid) {	
lvs's avatar
lvs committed
23
*/
Leonardo Solis's avatar
Leonardo Solis committed
24
25
	while(valid != 0) {	

26
		bool active = true;
lvs's avatar
lvs committed
27
/*
28
		active = read_channel_nb_altera(chan_Arbiter_BT_ushort_float_off, &valid);
lvs's avatar
lvs committed
29
30
*/
		valid = read_pipe(chan_Arbiter_BT_ushort_float_off, &active);
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

		uint   u_tmp[4]; // used as short in GA
		float  f_tmp[4];	

		#pragma unroll
		for(uchar i=0; i<4; i++) {
			uchar2 lsb;

			lsb.x = lfsr.x & 0x01u;
			lsb.y = lfsr.y & 0x01u;

			lfsr.x >>= 1;
			lfsr.y >>= 1;

			lfsr.x ^= (-lsb.x) & 0xA3000000u;
			lfsr.y ^= (-lsb.y) & 0xA3000000u;

			u_tmp[i] = (lfsr.x/MAX_UINT)*DockConst_pop_size;
			f_tmp[i] = (0.999999f/MAX_UINT)*lfsr.y;
		}
lvs's avatar
lvs committed
51
/*
52
		bool success = false;
lvs's avatar
lvs committed
53
54
55
*/
		int success = 1;
/*
56
		if(!valid) {
lvs's avatar
lvs committed
57
*/
Leonardo Solis's avatar
Leonardo Solis committed
58
		if(valid != 0) {
59
60
61
62
			float8 tmp = {*(float*)&u_tmp[0], f_tmp[0],
				      *(float*)&u_tmp[1], f_tmp[1],
				      *(float*)&u_tmp[2], f_tmp[2],
				      *(float*)&u_tmp[3], f_tmp[3]};
Leonardo Solis's avatar
Leonardo Solis committed
63

lvs's avatar
lvs committed
64
/*
65
			success = write_channel_nb_altera(chan_PRNG2GA_BT_ushort_float_prng, tmp);
lvs's avatar
lvs committed
66
*/
Leonardo Solis's avatar
Leonardo Solis committed
67

lvs's avatar
lvs committed
68
			success = write_pipe(chan_PRNG2GA_BT_ushort_float_prng, &tmp);
69
		}
lvs's avatar
lvs committed
70
71
	} /*// End of while(!valid)*/
	// End of while(valid == 0)
72
73
74
75
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
76
/*
Leonardo Solis's avatar
Leonardo Solis committed
77
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
78
79
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
80
void Krnl_Prng_GG_uchar(unsigned int  Host_seed, 
81
		        unsigned char DockConst_num_of_genes){
Leonardo Solis's avatar
Leonardo Solis committed
82

83
	uint lfsr = Host_seed;
lvs's avatar
lvs committed
84
/*
85
	bool valid = false;
lvs's avatar
lvs committed
86
87
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
88

lvs's avatar
lvs committed
89
/*
90
	while(!valid) {
lvs's avatar
lvs committed
91
*/
Leonardo Solis's avatar
Leonardo Solis committed
92
	while(valid != 0) {
93
		bool active = true;
lvs's avatar
lvs committed
94
/*
95
		active = read_channel_nb_altera(chan_Arbiter_GG_uchar_off, &valid);
lvs's avatar
lvs committed
96
97
98
*/
		valid = read_pipe(chan_Arbiter_GG_uchar_off, &active);		

99
		uchar tmp[2];
100

101
102
		#pragma unroll
		for(uchar i=0; i<2; i++) {
103
104
105
106
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
107
			tmp[i] = (lfsr/MAX_UINT)*DockConst_num_of_genes;
108

109
		}
lvs's avatar
lvs committed
110
/*
111
		bool success = false;
lvs's avatar
lvs committed
112
113
114
*/
		int success = 1;

115
116
117
118
		uchar2 utmp;
		utmp.x = tmp[0];
		utmp.y = tmp[1];

lvs's avatar
lvs committed
119
/*
120
		if(!valid) {
lvs's avatar
lvs committed
121
*/
Leonardo Solis's avatar
Leonardo Solis committed
122
		if(valid != 0) {
lvs's avatar
lvs committed
123
/*
124
			success = write_channel_nb_altera(chan_PRNG2GA_GG_uchar_prng, utmp);
lvs's avatar
lvs committed
125
126
*/
			success = write_pipe(chan_PRNG2GA_GG_uchar_prng, &utmp);
Leonardo Solis's avatar
Leonardo Solis committed
127
		}
128
	} // End of while(active)
Leonardo Solis's avatar
Leonardo Solis committed
129
}
Leonardo Solis's avatar
Leonardo Solis committed
130

lvs's avatar
lvs committed
131
/*
Leonardo Solis's avatar
Leonardo Solis committed
132
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
133
134
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
135
136
137
138
void Krnl_Prng_GG_float(unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
139
/*
Leonardo Solis's avatar
Leonardo Solis committed
140
	bool valid = false;
lvs's avatar
lvs committed
141
142
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
143

lvs's avatar
lvs committed
144
/*
Leonardo Solis's avatar
Leonardo Solis committed
145
	while(!valid) {
lvs's avatar
lvs committed
146
*/
Leonardo Solis's avatar
Leonardo Solis committed
147
	while(valid != 0) {
lvs's avatar
lvs committed
148

Leonardo Solis's avatar
Leonardo Solis committed
149
		bool active = true;
lvs's avatar
lvs committed
150
/*
Leonardo Solis's avatar
Leonardo Solis committed
151
		active = read_channel_nb_altera(chan_Arbiter_GG_float_off, &valid);
lvs's avatar
lvs committed
152
153
*/
		valid = read_pipe(chan_Arbiter_GG_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
154
155
156
157
158
159
160
161
162

		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;

lvs's avatar
lvs committed
163
/*
Leonardo Solis's avatar
Leonardo Solis committed
164
			bool success = false;
lvs's avatar
lvs committed
165
166
167
*/
			int success = 1;
/*
Leonardo Solis's avatar
Leonardo Solis committed
168
			if(!valid) {
lvs's avatar
lvs committed
169
*/
Leonardo Solis's avatar
Leonardo Solis committed
170
			if(valid != 0) {
lvs's avatar
lvs committed
171
/*
Leonardo Solis's avatar
Leonardo Solis committed
172
				success = write_channel_nb_altera(chan_PRNG2GA_GG_float_prng, tmp);
lvs's avatar
lvs committed
173
174
*/
				success = write_pipe(chan_PRNG2GA_GG_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
175
176
177
178
			}
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
179
180
181

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
182
/*
Leonardo Solis's avatar
Leonardo Solis committed
183
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
184
185
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
186
187
188
189
190
void Krnl_Prng_LS123_ushort(unsigned int Host_seed1,
			    unsigned int Host_seed2, 
			    unsigned int Host_seed3,
			    unsigned int Host_seed4,
			    unsigned int Host_seed5, 
191
192
193
194
			    unsigned int Host_seed6, 
			    unsigned int Host_seed7,
			    unsigned int Host_seed8,
			    unsigned int Host_seed9, 
Leonardo Solis's avatar
Leonardo Solis committed
195
196
197
		            unsigned int DockConst_pop_size){


198
	uint lfsr[9];
Leonardo Solis's avatar
Leonardo Solis committed
199
200
201
202
203
	lfsr[0] = Host_seed1;
	lfsr[1] = Host_seed2;
	lfsr[2] = Host_seed3;
	lfsr[3] = Host_seed4;
	lfsr[4] = Host_seed5;
204
205
206
207
	lfsr[5] = Host_seed6;
	lfsr[6] = Host_seed7;
	lfsr[7] = Host_seed8;
	lfsr[8] = Host_seed9;
Leonardo Solis's avatar
Leonardo Solis committed
208

lvs's avatar
lvs committed
209
/*
Leonardo Solis's avatar
Leonardo Solis committed
210
	bool valid = false;
lvs's avatar
lvs committed
211
212
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
213

lvs's avatar
lvs committed
214
/*
Leonardo Solis's avatar
Leonardo Solis committed
215
	while(!valid) {
lvs's avatar
lvs committed
216
*/
Leonardo Solis's avatar
Leonardo Solis committed
217
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
218
		bool active = true;
lvs's avatar
lvs committed
219
/*
Leonardo Solis's avatar
Leonardo Solis committed
220
		active  = read_channel_nb_altera(chan_Arbiter_LS123_ushort_off, &valid);
lvs's avatar
lvs committed
221
222
*/
		valid  = read_pipe(chan_Arbiter_LS123_ushort_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
223

224
		ushort tmp[9];
Leonardo Solis's avatar
Leonardo Solis committed
225
226
		
		#pragma unroll
227
228
		for (uint i=0; i<9; i++){
			uchar  lsb[9];
Leonardo Solis's avatar
Leonardo Solis committed
229
230
231
232
233
234
			lsb [i] = lfsr[i] & 0x01u;
			lfsr[i] >>= 1;
			lfsr[i] ^= (-lsb[i]) & 0xA3000000u;
			tmp [i] = (DockConst_pop_size/MAX_UINT)*lfsr[i];
		}

235
		// To avoid having same entities undergoing LS simultaneously
Leonardo Solis's avatar
Leonardo Solis committed
236
		if (
237
238
239
240
241
242
243
244
			(tmp[0] == tmp[1]) || (tmp[0] == tmp[2]) || (tmp[0] == tmp[3]) || (tmp[0] == tmp[4]) || (tmp[0] == tmp[5]) || (tmp[0] == tmp[6]) || (tmp[0] == tmp[7]) || (tmp[0] == tmp[8]) ||
 			(tmp[1] == tmp[2]) || (tmp[1] == tmp[3]) || (tmp[1] == tmp[4]) || (tmp[1] == tmp[5]) || (tmp[1] == tmp[6]) || (tmp[1] == tmp[7]) || (tmp[1] == tmp[8]) ||
			(tmp[2] == tmp[3]) || (tmp[2] == tmp[4]) || (tmp[2] == tmp[5]) || (tmp[2] == tmp[6]) || (tmp[2] == tmp[7]) || (tmp[2] == tmp[8]) ||
			(tmp[3] == tmp[4]) || (tmp[3] == tmp[5]) || (tmp[3] == tmp[6]) || (tmp[3] == tmp[7]) || (tmp[3] == tmp[8]) ||
			(tmp[4] == tmp[5]) || (tmp[4] == tmp[6]) || (tmp[4] == tmp[7]) || (tmp[4] == tmp[8]) ||
			(tmp[5] == tmp[6]) || (tmp[5] == tmp[7]) || (tmp[5] == tmp[8]) ||
			(tmp[6] == tmp[7]) || (tmp[6] == tmp[8]) ||
			(tmp[7] == tmp[8])
Leonardo Solis's avatar
Leonardo Solis committed
245
246
247
248
249
		) {
			tmp[1] = tmp[0] + 1;
			tmp[2] = tmp[1] + 2;
			tmp[3] = tmp[2] + 3;
			tmp[4] = tmp[3] + 4;
250
251
252
253
			tmp[5] = tmp[4] + 5;
			tmp[6] = tmp[5] + 6;
			tmp[7] = tmp[6] + 7;
			tmp[8] = tmp[7] + 8;
Leonardo Solis's avatar
Leonardo Solis committed
254
255
		}

lvs's avatar
lvs committed
256
/*
Leonardo Solis's avatar
Leonardo Solis committed
257
		bool success = false;
lvs's avatar
lvs committed
258
259
260
*/
		int success = 1;

261
		ushort16 tmp123;
Leonardo Solis's avatar
Leonardo Solis committed
262
263
264
265
266
		tmp123.s0 = tmp[0];
		tmp123.s1 = tmp[1];
		tmp123.s2 = tmp[2];
		tmp123.s3 = tmp[3];
		tmp123.s4 = tmp[4];
267
268
269
270
		tmp123.s5 = tmp[5];
		tmp123.s6 = tmp[6];
		tmp123.s7 = tmp[7];
		tmp123.s8 = tmp[8];
Leonardo Solis's avatar
Leonardo Solis committed
271

lvs's avatar
lvs committed
272
/*
Leonardo Solis's avatar
Leonardo Solis committed
273
		if(!valid) {
lvs's avatar
lvs committed
274
*/
Leonardo Solis's avatar
Leonardo Solis committed
275
		if(valid != 0) {
lvs's avatar
lvs committed
276
/*
Leonardo Solis's avatar
Leonardo Solis committed
277
			success = write_channel_nb_altera(chan_PRNG2GA_LS123_ushort_prng, tmp123);
lvs's avatar
lvs committed
278
279
*/
			success = write_pipe(chan_PRNG2GA_LS123_ushort_prng, &tmp123);
Leonardo Solis's avatar
Leonardo Solis committed
280
281
282
283
		}

	} // End of while(active)
}
284
285
286

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
287
/*
Leonardo Solis's avatar
Leonardo Solis committed
288
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
289
290
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
291
292
293
294
void Krnl_Prng_LS_float(unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
295
/*
Leonardo Solis's avatar
Leonardo Solis committed
296
	bool valid = false;
lvs's avatar
lvs committed
297
298
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
299

lvs's avatar
lvs committed
300
/*
Leonardo Solis's avatar
Leonardo Solis committed
301
	while(!valid) {
lvs's avatar
lvs committed
302
*/
Leonardo Solis's avatar
Leonardo Solis committed
303
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
304
		bool active = true;
lvs's avatar
lvs committed
305
/*
Leonardo Solis's avatar
Leonardo Solis committed
306
		active  = read_channel_nb_altera(chan_Arbiter_LS_float_off, &valid);
lvs's avatar
lvs committed
307
308
*/
		valid  = read_pipe(chan_Arbiter_LS_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
309
310
311
312
313
314
315
316
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
317
/*
Leonardo Solis's avatar
Leonardo Solis committed
318
			bool success = false;
lvs's avatar
lvs committed
319
320
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
321
322
323

			#if defined (FIXED_POINT_LS1)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
324
/*
Leonardo Solis's avatar
Leonardo Solis committed
325
			if(!valid) {
lvs's avatar
lvs committed
326
*/
Leonardo Solis's avatar
Leonardo Solis committed
327
			if(valid == 1) {
lvs's avatar
lvs committed
328
/*
Leonardo Solis's avatar
Leonardo Solis committed
329
				success = write_channel_nb_altera(chan_PRNG2GA_LS_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
330
331
*/
				success = write_pipe(chan_PRNG2GA_LS_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
332
333
			}
			#else
lvs's avatar
lvs committed
334
/*
Leonardo Solis's avatar
Leonardo Solis committed
335
			if(!valid) {
lvs's avatar
lvs committed
336
*/
Leonardo Solis's avatar
Leonardo Solis committed
337
			if(valid != 0) {
lvs's avatar
lvs committed
338
/*
Leonardo Solis's avatar
Leonardo Solis committed
339
				success = write_channel_nb_altera(chan_PRNG2GA_LS_float_prng, tmp);
lvs's avatar
lvs committed
340
341
*/
				success = write_pipe(chan_PRNG2GA_LS_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
342
			}
Leonardo Solis's avatar
Leonardo Solis committed
343
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
344
345
346
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
347

lvs's avatar
lvs committed
348
/*
Leonardo Solis's avatar
Leonardo Solis committed
349
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
350
351
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
352
353
354
355
void Krnl_Prng_LS2_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
356
/*
Leonardo Solis's avatar
Leonardo Solis committed
357
	bool valid = false;
lvs's avatar
lvs committed
358
359
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
360

lvs's avatar
lvs committed
361
/*
Leonardo Solis's avatar
Leonardo Solis committed
362
	while(!valid) {
lvs's avatar
lvs committed
363
*/
Leonardo Solis's avatar
Leonardo Solis committed
364
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
365
		bool active = true;
lvs's avatar
lvs committed
366
/*
Leonardo Solis's avatar
Leonardo Solis committed
367
		active  = read_channel_nb_altera(chan_Arbiter_LS2_float_off, &valid);
lvs's avatar
lvs committed
368
369
*/
		valid  = read_pipe(chan_Arbiter_LS2_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
370
371
372
373
374
375
376
377
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
378
/*
Leonardo Solis's avatar
Leonardo Solis committed
379
			bool success = false;
lvs's avatar
lvs committed
380
381
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
382
383
384

			#if defined (FIXED_POINT_LS2)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
385
/*
Leonardo Solis's avatar
Leonardo Solis committed
386
			if(!valid) {
lvs's avatar
lvs committed
387
*/
Leonardo Solis's avatar
Leonardo Solis committed
388
			if(valid != 0) {
lvs's avatar
lvs committed
389
/*
Leonardo Solis's avatar
Leonardo Solis committed
390
				success = write_channel_nb_altera(chan_PRNG2GA_LS2_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
391
392
*/
				success = write_pipe(chan_PRNG2GA_LS2_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
393
394
			}
			#else
lvs's avatar
lvs committed
395
/*
Leonardo Solis's avatar
Leonardo Solis committed
396
			if(!valid) {
lvs's avatar
lvs committed
397
*/
Leonardo Solis's avatar
Leonardo Solis committed
398
			if(valid != 0) {
lvs's avatar
lvs committed
399
/*
Leonardo Solis's avatar
Leonardo Solis committed
400
				success = write_channel_nb_altera(chan_PRNG2GA_LS2_float_prng, tmp);
lvs's avatar
lvs committed
401
402
*/
				success = write_pipe(chan_PRNG2GA_LS2_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
403
			}
Leonardo Solis's avatar
Leonardo Solis committed
404
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
405
406
407
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
408

lvs's avatar
lvs committed
409
/*
Leonardo Solis's avatar
Leonardo Solis committed
410
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
411
412
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
413
414
415
416
void Krnl_Prng_LS3_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
417
/*
Leonardo Solis's avatar
Leonardo Solis committed
418
	bool valid = false;
lvs's avatar
lvs committed
419
420
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
421

lvs's avatar
lvs committed
422
/*
Leonardo Solis's avatar
Leonardo Solis committed
423
	while(!valid) {
lvs's avatar
lvs committed
424
*/
Leonardo Solis's avatar
Leonardo Solis committed
425
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
426
		bool active = true;
lvs's avatar
lvs committed
427
/*
Leonardo Solis's avatar
Leonardo Solis committed
428
		active  = read_channel_nb_altera(chan_Arbiter_LS3_float_off, &valid);
lvs's avatar
lvs committed
429
430
*/
		valid  = read_pipe(chan_Arbiter_LS3_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
431
432
433
434
435
436
437
438
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
439
/*
Leonardo Solis's avatar
Leonardo Solis committed
440
			bool success = false;
lvs's avatar
lvs committed
441
442
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
443
444
445

			#if defined (FIXED_POINT_LS3)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
446
/*
Leonardo Solis's avatar
Leonardo Solis committed
447
			if(!valid) {
lvs's avatar
lvs committed
448
*/
Leonardo Solis's avatar
Leonardo Solis committed
449
			if(valid != 0) {
lvs's avatar
lvs committed
450
/*
Leonardo Solis's avatar
Leonardo Solis committed
451
				success = write_channel_nb_altera(chan_PRNG2GA_LS3_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
452
453
*/
				success = write_pipe(chan_PRNG2GA_LS3_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
454
455
456
			}

			#else
lvs's avatar
lvs committed
457
/*
Leonardo Solis's avatar
Leonardo Solis committed
458
			if(!valid) {
lvs's avatar
lvs committed
459
*/
Leonardo Solis's avatar
Leonardo Solis committed
460
			if(valid != 0) {
lvs's avatar
lvs committed
461
/*
Leonardo Solis's avatar
Leonardo Solis committed
462
				success = write_channel_nb_altera(chan_PRNG2GA_LS3_float_prng, tmp);
lvs's avatar
lvs committed
463
464
*/
				success = write_pipe(chan_PRNG2GA_LS3_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
465
			}
Leonardo Solis's avatar
Leonardo Solis committed
466
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
467
468
469
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
470

lvs's avatar
lvs committed
471
/*
Leonardo Solis's avatar
Leonardo Solis committed
472
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
473
474
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
475
476
477
478
void Krnl_Prng_LS4_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
479
/*
Leonardo Solis's avatar
Leonardo Solis committed
480
	bool valid = false;
lvs's avatar
lvs committed
481
482
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
483

lvs's avatar
lvs committed
484
/*
Leonardo Solis's avatar
Leonardo Solis committed
485
	while(!valid) {
lvs's avatar
lvs committed
486
*/
Leonardo Solis's avatar
Leonardo Solis committed
487
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
488
		bool active = true;
lvs's avatar
lvs committed
489
/*
Leonardo Solis's avatar
Leonardo Solis committed
490
		active  = read_channel_nb_altera(chan_Arbiter_LS4_float_off, &valid);
lvs's avatar
lvs committed
491
492
*/
		valid  = read_pipe(chan_Arbiter_LS4_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
493
494
495
496
497
498
499
500
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
501
/*
Leonardo Solis's avatar
Leonardo Solis committed
502
			bool success = false;
lvs's avatar
lvs committed
503
504
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
505

506
			#if defined (FIXED_POINT_LS4)
Leonardo Solis's avatar
Leonardo Solis committed
507
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
508
/*
Leonardo Solis's avatar
Leonardo Solis committed
509
			if(!valid) {
lvs's avatar
lvs committed
510
*/
Leonardo Solis's avatar
Leonardo Solis committed
511
			if(valid != 0) {
lvs's avatar
lvs committed
512
/*
Leonardo Solis's avatar
Leonardo Solis committed
513
				success = write_channel_nb_altera(chan_PRNG2GA_LS4_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
514
515
*/
				success = write_pipe(chan_PRNG2GA_LS4_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
516
517
			}
			#else
lvs's avatar
lvs committed
518
/*
Leonardo Solis's avatar
Leonardo Solis committed
519
			if(!valid) {
lvs's avatar
lvs committed
520
*/
Leonardo Solis's avatar
Leonardo Solis committed
521
			if(valid != 0) {
lvs's avatar
lvs committed
522
/*
Leonardo Solis's avatar
Leonardo Solis committed
523
				success = write_channel_nb_altera(chan_PRNG2GA_LS4_float_prng, tmp);
lvs's avatar
lvs committed
524
525
*/
				success = write_pipe(chan_PRNG2GA_LS4_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
526
527
528
529
530
531
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
532
/*
Leonardo Solis's avatar
Leonardo Solis committed
533
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
534
535
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
536
537
538
539
void Krnl_Prng_LS5_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
540
/*
Leonardo Solis's avatar
Leonardo Solis committed
541
	bool valid = false;
lvs's avatar
lvs committed
542
543
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
544

lvs's avatar
lvs committed
545
/*
Leonardo Solis's avatar
Leonardo Solis committed
546
	while(!valid) {
lvs's avatar
lvs committed
547
*/
Leonardo Solis's avatar
Leonardo Solis committed
548
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
549
		bool active = true;
lvs's avatar
lvs committed
550
/*
Leonardo Solis's avatar
Leonardo Solis committed
551
		active  = read_channel_nb_altera(chan_Arbiter_LS5_float_off, &valid);
lvs's avatar
lvs committed
552
553
*/
		valid  = read_pipe(chan_Arbiter_LS5_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
554
555
556
557
558
559
560
561
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
562
/*
Leonardo Solis's avatar
Leonardo Solis committed
563
			bool success = false;
lvs's avatar
lvs committed
564
565
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
566

567
			#if defined (FIXED_POINT_LS5)
Leonardo Solis's avatar
Leonardo Solis committed
568
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
569
/*
Leonardo Solis's avatar
Leonardo Solis committed
570
			if(!valid) {
lvs's avatar
lvs committed
571
*/
Leonardo Solis's avatar
Leonardo Solis committed
572
			if(valid != 0) {
lvs's avatar
lvs committed
573
/*
Leonardo Solis's avatar
Leonardo Solis committed
574
				success = write_channel_nb_altera(chan_PRNG2GA_LS5_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
575
576
*/
				success = write_pipe(chan_PRNG2GA_LS5_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
577
578
			}
			#else
lvs's avatar
lvs committed
579
/*
Leonardo Solis's avatar
Leonardo Solis committed
580
			if(!valid) {
lvs's avatar
lvs committed
581
*/
Leonardo Solis's avatar
Leonardo Solis committed
582
			if(valid != 0) {
lvs's avatar
lvs committed
583
/*
Leonardo Solis's avatar
Leonardo Solis committed
584
				success = write_channel_nb_altera(chan_PRNG2GA_LS5_float_prng, tmp);
lvs's avatar
lvs committed
585
586
*/
				success = write_pipe(chan_PRNG2GA_LS5_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
587
588
589
590
591
			}
			#endif
		}
	} // End of while(active)
}
592

lvs's avatar
lvs committed
593
/*
594
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
595
596
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
597
598
599
600
void Krnl_Prng_LS6_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
601
/*
602
	bool valid = false;
lvs's avatar
lvs committed
603
604
*/
	int valid = 1;
605

lvs's avatar
lvs committed
606
/*
607
	while(!valid) {
lvs's avatar
lvs committed
608
*/
Leonardo Solis's avatar
Leonardo Solis committed
609
	while(valid != 0) {
610
		bool active = true;
lvs's avatar
lvs committed
611
/*
612
		active  = read_channel_nb_altera(chan_Arbiter_LS6_float_off, &valid);
lvs's avatar
lvs committed
613
614
*/
		valid  = read_pipe(chan_Arbiter_LS6_float_off, &active);
615
616
617
618
619
620
621
622
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
623
/*
624
			bool success = false;
lvs's avatar
lvs committed
625
626
*/
			int success = 1;
627
628
629

			#if defined (FIXED_POINT_LS6)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
630
/*
631
			if(!valid) {
lvs's avatar
lvs committed
632
*/
Leonardo Solis's avatar
Leonardo Solis committed
633
			if(valid != 0) {
lvs's avatar
lvs committed
634
/*
635
				success = write_channel_nb_altera(chan_PRNG2GA_LS6_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
636
637
*/
				success = write_pipe(chan_PRNG2GA_LS6_float_prng, (float*) &fixpt_tmp);
638
639
			}
			#else
lvs's avatar
lvs committed
640
/*
641
			if(!valid) {
lvs's avatar
lvs committed
642
*/
Leonardo Solis's avatar
Leonardo Solis committed
643
			if(valid != 0) {
lvs's avatar
lvs committed
644
/*
645
				success = write_channel_nb_altera(chan_PRNG2GA_LS6_float_prng, tmp);
lvs's avatar
lvs committed
646
647
*/
				success = write_pipe(chan_PRNG2GA_LS6_float_prng, &tmp);
648
649
650
651
652
653
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
654
/*
655
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
656
657
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
658
659
660
661
void Krnl_Prng_LS7_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
662
/*
663
	bool valid = false;
lvs's avatar
lvs committed
664
665
*/
	int valid = 1;
666

lvs's avatar
lvs committed
667
/*
668
	while(!valid) {
lvs's avatar
lvs committed
669
*/
Leonardo Solis's avatar
Leonardo Solis committed
670
	while(valid != 0) {
671
		bool active = true;
lvs's avatar
lvs committed
672
/*
673
		active  = read_channel_nb_altera(chan_Arbiter_LS7_float_off, &valid);
lvs's avatar
lvs committed
674
675
*/
		valid  = read_pipe(chan_Arbiter_LS7_float_off, &active);
676
677
678
679
680
681
682
683
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
684
/*
685
			bool success = false;
lvs's avatar
lvs committed
686
687
*/
			int success = 1;
688
689
690

			#if defined (FIXED_POINT_LS7)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
691
/*
692
			if(!valid) {
lvs's avatar
lvs committed
693
*/
Leonardo Solis's avatar
Leonardo Solis committed
694
			if(valid != 0) {
lvs's avatar
lvs committed
695
/*
696
				success = write_channel_nb_altera(chan_PRNG2GA_LS7_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
697
698
*/
				success = write_pipe(chan_PRNG2GA_LS7_float_prng, (float*) &fixpt_tmp);
699
700
			}
			#else
lvs's avatar
lvs committed
701
/*
702
			if(!valid) {
lvs's avatar
lvs committed
703
*/
Leonardo Solis's avatar
Leonardo Solis committed
704
			if(valid != 0) {
lvs's avatar
lvs committed
705
/*
706
				success = write_channel_nb_altera(chan_PRNG2GA_LS7_float_prng, tmp);
lvs's avatar
lvs committed
707
708
*/
				success = write_pipe(chan_PRNG2GA_LS7_float_prng, &tmp);
709
710
711
712
713
714
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
715
/*
716
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
717
718
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
719
720
721
722
void Krnl_Prng_LS8_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
723
/*
724
	bool valid = false;
lvs's avatar
lvs committed
725
726
*/
	int valid = 1;
727

lvs's avatar
lvs committed
728
/*
729
	while(!valid) {
lvs's avatar
lvs committed
730
*/
Leonardo Solis's avatar
Leonardo Solis committed
731
	while(valid != 0) {
732
		bool active = true;
lvs's avatar
lvs committed
733
/*
734
		active  = read_channel_nb_altera(chan_Arbiter_LS8_float_off, &valid);
lvs's avatar
lvs committed
735
736
*/
		valid  = read_pipe(chan_Arbiter_LS8_float_off, &active);
737
738
739
740
741
742
743
744
	
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
lvs's avatar
lvs committed
745
/*
746
			bool success = false;
lvs's avatar
lvs committed
747
748
*/
			int success = 1;
749
750
751

			#if defined (FIXED_POINT_LS8)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
752
/*
753
			if(!valid) {
lvs's avatar
lvs committed
754
*/
Leonardo Solis's avatar
Leonardo Solis committed
755
			if(valid != 0) {
lvs's avatar
lvs committed
756
/*
757
				success = write_channel_nb_altera(chan_PRNG2GA_LS8_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
758
759
*/
				success = write_pipe(chan_PRNG2GA_LS8_float_prng, (float*) &fixpt_tmp);
760
761
			}
			#else
lvs's avatar
lvs committed
762
/*
763
			if(!valid) {
lvs's avatar
lvs committed
764
*/
Leonardo Solis's avatar
Leonardo Solis committed
765
			if(valid != 0) {
lvs's avatar
lvs committed
766
/*
767
				success = write_channel_nb_altera(chan_PRNG2GA_LS8_float_prng, tmp);
lvs's avatar
lvs committed
768
769
*/
				success = write_pipe(chan_PRNG2GA_LS8_float_prng, &tmp);
770
771
772
773
774
775
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
776
/*
777
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
778
779
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
780
781
782
783
void Krnl_Prng_LS9_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
784
/*
785
	bool valid = false;
lvs's avatar
lvs committed
786
787
*/
	int valid = 1;
788

lvs's avatar
lvs committed
789
/*