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
24
*/
	while(valid == 0) {	
25
		bool active = true;
lvs's avatar
lvs committed
26
/*
27
		active = read_channel_nb_altera(chan_Arbiter_BT_ushort_float_off, &valid);
lvs's avatar
lvs committed
28
29
*/
		valid = read_pipe(chan_Arbiter_BT_ushort_float_off, &active);
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

		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
50
/*
51
		bool success = false;
lvs's avatar
lvs committed
52
53
54
*/
		int success = 1;
/*
55
		if(!valid) {
lvs's avatar
lvs committed
56
57
*/
		if(valid == 0) {
58
59
60
61
			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]};
lvs's avatar
lvs committed
62
/*
63
			success = write_channel_nb_altera(chan_PRNG2GA_BT_ushort_float_prng, tmp);
lvs's avatar
lvs committed
64
65
*/
			success = write_pipe(chan_PRNG2GA_BT_ushort_float_prng, &tmp);
66
		}
lvs's avatar
lvs committed
67
68
	} /*// End of while(!valid)*/
	// End of while(valid == 0)
69
70
71
72
}

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

80
	uint lfsr = Host_seed;
lvs's avatar
lvs committed
81
/*
82
	bool valid = false;
lvs's avatar
lvs committed
83
84
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
85

lvs's avatar
lvs committed
86
/*
87
	while(!valid) {
lvs's avatar
lvs committed
88
89
*/
	while(valid == 0) {
90
		bool active = true;
lvs's avatar
lvs committed
91
/*
92
		active = read_channel_nb_altera(chan_Arbiter_GG_uchar_off, &valid);
lvs's avatar
lvs committed
93
94
95
*/
		valid = read_pipe(chan_Arbiter_GG_uchar_off, &active);		

96
		uchar tmp[2];
97

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

106
		}
lvs's avatar
lvs committed
107
/*
108
		bool success = false;
lvs's avatar
lvs committed
109
110
111
*/
		int success = 1;

112
113
114
115
		uchar2 utmp;
		utmp.x = tmp[0];
		utmp.y = tmp[1];

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
136
/*
Leonardo Solis's avatar
Leonardo Solis committed
137
	bool valid = false;
lvs's avatar
lvs committed
138
139
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
140

lvs's avatar
lvs committed
141
/*
Leonardo Solis's avatar
Leonardo Solis committed
142
	while(!valid) {
lvs's avatar
lvs committed
143
144
145
*/
	while(valid == 0) {

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

		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
160
/*
Leonardo Solis's avatar
Leonardo Solis committed
161
			bool success = false;
lvs's avatar
lvs committed
162
163
164
*/
			int success = 1;
/*
Leonardo Solis's avatar
Leonardo Solis committed
165
			if(!valid) {
lvs's avatar
lvs committed
166
167
*/
			if(valid == 0) {
lvs's avatar
lvs committed
168
/*
Leonardo Solis's avatar
Leonardo Solis committed
169
				success = write_channel_nb_altera(chan_PRNG2GA_GG_float_prng, tmp);
lvs's avatar
lvs committed
170
171
*/
				success = write_pipe(chan_PRNG2GA_GG_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
172
173
174
175
			}
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
176
177
178

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
179
/*
Leonardo Solis's avatar
Leonardo Solis committed
180
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
181
182
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
183
184
185
186
187
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, 
188
189
190
191
			    unsigned int Host_seed6, 
			    unsigned int Host_seed7,
			    unsigned int Host_seed8,
			    unsigned int Host_seed9, 
Leonardo Solis's avatar
Leonardo Solis committed
192
193
194
		            unsigned int DockConst_pop_size){


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

lvs's avatar
lvs committed
206
/*
Leonardo Solis's avatar
Leonardo Solis committed
207
	bool valid = false;
lvs's avatar
lvs committed
208
209
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
210

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

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

232
		// To avoid having same entities undergoing LS simultaneously
Leonardo Solis's avatar
Leonardo Solis committed
233
		if (
234
235
236
237
238
239
240
241
			(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
242
243
244
245
246
		) {
			tmp[1] = tmp[0] + 1;
			tmp[2] = tmp[1] + 2;
			tmp[3] = tmp[2] + 3;
			tmp[4] = tmp[3] + 4;
247
248
249
250
			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
251
252
		}

lvs's avatar
lvs committed
253
/*
Leonardo Solis's avatar
Leonardo Solis committed
254
		bool success = false;
lvs's avatar
lvs committed
255
256
257
*/
		int success = 1;

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

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

	} // End of while(active)
}
281
282
283

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
292
/*
Leonardo Solis's avatar
Leonardo Solis committed
293
	bool valid = false;
lvs's avatar
lvs committed
294
295
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
296

lvs's avatar
lvs committed
297
/*
Leonardo Solis's avatar
Leonardo Solis committed
298
	while(!valid) {
lvs's avatar
lvs committed
299
300
*/
	while(valid == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
301
		bool active = true;
lvs's avatar
lvs committed
302
/*
Leonardo Solis's avatar
Leonardo Solis committed
303
		active  = read_channel_nb_altera(chan_Arbiter_LS_float_off, &valid);
lvs's avatar
lvs committed
304
305
*/
		valid  = read_pipe(chan_Arbiter_LS_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
306
307
308
309
310
311
312
313
	
		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
314
/*
Leonardo Solis's avatar
Leonardo Solis committed
315
			bool success = false;
lvs's avatar
lvs committed
316
317
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
318
319
320

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
353
/*
Leonardo Solis's avatar
Leonardo Solis committed
354
	bool valid = false;
lvs's avatar
lvs committed
355
356
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
357

lvs's avatar
lvs committed
358
/*
Leonardo Solis's avatar
Leonardo Solis committed
359
	while(!valid) {
lvs's avatar
lvs committed
360
361
*/
	while(valid == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
362
		bool active = true;
lvs's avatar
lvs committed
363
/*
Leonardo Solis's avatar
Leonardo Solis committed
364
		active  = read_channel_nb_altera(chan_Arbiter_LS2_float_off, &valid);
lvs's avatar
lvs committed
365
366
*/
		valid  = read_pipe(chan_Arbiter_LS2_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
367
368
369
370
371
372
373
374
	
		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
375
/*
Leonardo Solis's avatar
Leonardo Solis committed
376
			bool success = false;
lvs's avatar
lvs committed
377
378
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
379
380
381

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
414
/*
Leonardo Solis's avatar
Leonardo Solis committed
415
	bool valid = false;
lvs's avatar
lvs committed
416
417
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
418

lvs's avatar
lvs committed
419
/*
Leonardo Solis's avatar
Leonardo Solis committed
420
	while(!valid) {
lvs's avatar
lvs committed
421
422
*/
	while(valid == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
423
		bool active = true;
lvs's avatar
lvs committed
424
/*
Leonardo Solis's avatar
Leonardo Solis committed
425
		active  = read_channel_nb_altera(chan_Arbiter_LS3_float_off, &valid);
lvs's avatar
lvs committed
426
427
*/
		valid  = read_pipe(chan_Arbiter_LS3_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
428
429
430
431
432
433
434
435
	
		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
436
/*
Leonardo Solis's avatar
Leonardo Solis committed
437
			bool success = false;
lvs's avatar
lvs committed
438
439
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
440
441
442

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

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
476
/*
Leonardo Solis's avatar
Leonardo Solis committed
477
	bool valid = false;
lvs's avatar
lvs committed
478
479
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
480

lvs's avatar
lvs committed
481
/*
Leonardo Solis's avatar
Leonardo Solis committed
482
	while(!valid) {
lvs's avatar
lvs committed
483
484
*/
	while(valid == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
485
		bool active = true;
lvs's avatar
lvs committed
486
/*
Leonardo Solis's avatar
Leonardo Solis committed
487
		active  = read_channel_nb_altera(chan_Arbiter_LS4_float_off, &valid);
lvs's avatar
lvs committed
488
489
*/
		valid  = read_pipe(chan_Arbiter_LS4_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
490
491
492
493
494
495
496
497
	
		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
498
/*
Leonardo Solis's avatar
Leonardo Solis committed
499
			bool success = false;
lvs's avatar
lvs committed
500
501
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
502

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
537
/*
Leonardo Solis's avatar
Leonardo Solis committed
538
	bool valid = false;
lvs's avatar
lvs committed
539
540
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
541

lvs's avatar
lvs committed
542
/*
Leonardo Solis's avatar
Leonardo Solis committed
543
	while(!valid) {
lvs's avatar
lvs committed
544
545
*/
	while(valid == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
546
		bool active = true;
lvs's avatar
lvs committed
547
/*
Leonardo Solis's avatar
Leonardo Solis committed
548
		active  = read_channel_nb_altera(chan_Arbiter_LS5_float_off, &valid);
lvs's avatar
lvs committed
549
550
*/
		valid  = read_pipe(chan_Arbiter_LS5_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
551
552
553
554
555
556
557
558
	
		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
559
/*
Leonardo Solis's avatar
Leonardo Solis committed
560
			bool success = false;
lvs's avatar
lvs committed
561
562
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
563

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
598
/*
599
	bool valid = false;
lvs's avatar
lvs committed
600
601
*/
	int valid = 1;
602

lvs's avatar
lvs committed
603
/*
604
	while(!valid) {
lvs's avatar
lvs committed
605
606
*/
	while(valid == 0) {
607
		bool active = true;
lvs's avatar
lvs committed
608
/*
609
		active  = read_channel_nb_altera(chan_Arbiter_LS6_float_off, &valid);
lvs's avatar
lvs committed
610
611
*/
		valid  = read_pipe(chan_Arbiter_LS6_float_off, &active);
612
613
614
615
616
617
618
619
	
		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
620
/*
621
			bool success = false;
lvs's avatar
lvs committed
622
623
*/
			int success = 1;
624
625
626

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
659
/*
660
	bool valid = false;
lvs's avatar
lvs committed
661
662
*/
	int valid = 1;
663

lvs's avatar
lvs committed
664
/*
665
	while(!valid) {
lvs's avatar
lvs committed
666
667
*/
	while(valid == 0) {
668
		bool active = true;
lvs's avatar
lvs committed
669
/*
670
		active  = read_channel_nb_altera(chan_Arbiter_LS7_float_off, &valid);
lvs's avatar
lvs committed
671
672
*/
		valid  = read_pipe(chan_Arbiter_LS7_float_off, &active);
673
674
675
676
677
678
679
680
	
		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
681
/*
682
			bool success = false;
lvs's avatar
lvs committed
683
684
*/
			int success = 1;
685
686
687

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
720
/*
721
	bool valid = false;
lvs's avatar
lvs committed
722
723
*/
	int valid = 1;
724

lvs's avatar
lvs committed
725
/*
726
	while(!valid) {
lvs's avatar
lvs committed
727
728
*/
	while(valid == 0) {
729
		bool active = true;
lvs's avatar
lvs committed
730
/*
731
		active  = read_channel_nb_altera(chan_Arbiter_LS8_float_off, &valid);
lvs's avatar
lvs committed
732
733
*/
		valid  = read_pipe(chan_Arbiter_LS8_float_off, &active);
734
735
736
737
738
739
740
741
	
		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
742
/*
743
			bool success = false;
lvs's avatar
lvs committed
744
745
*/
			int success = 1;
746
747
748

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

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

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
781
/*
782
	bool valid = false;
lvs's avatar
lvs committed
783
784
*/
	int valid = 1;
785

lvs's avatar
lvs committed
786
/*
787
	while(!valid) {
lvs's avatar
lvs committed
788
789
*/
	while(valid == 0) {
790
		bool active = true;
lvs's avatar
lvs committed
791
/*
792
		active  = read_channel_nb_altera(chan_Arbiter_LS9_float_off, &valid);
lvs's avatar
lvs committed
793
794
*/
		valid  = read_pipe(chan_Arbiter_LS9_float_off, &active);
795
796
797
798
799
800
801
802
	
		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
803
/*
804
			bool success = false;
lvs's avatar
lvs committed
805
806
*/
			int success = 1;
807
808
809

			#if defined (FIXED_POINT_LS9)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
810
/*
811
			if(!valid) {
lvs's avatar
lvs committed
812
813
*/
			if(valid == 0) {
lvs's avatar
lvs committed
814
/*
815
				success = write_channel_nb_altera(chan_PRNG2GA_LS9_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
816
817
*/
				success = write_pipe(chan_PRNG2GA_LS9_float_prng, (float*) &fixpt_tmp);
818
819
			}
			#else
lvs's avatar
lvs committed
820
/*
821
			if(!valid) {
lvs's avatar
lvs committed
822
823
*/
			if(valid == 0) {
lvs's avatar
lvs committed
824
/*
825
				success = write_channel_nb_altera(chan_PRNG2GA_LS9_float_prng, tmp);
lvs's avatar
lvs committed
826
827
*/
				success = write_pipe(chan_PRNG2GA_LS9_float_prng, &tmp);
828
829
830
831
832
			}
			#endif
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
833
834
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------