Krnl_PRNG.cl 18.1 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

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

Leonardo Solis's avatar
Leonardo Solis committed
35
/*
36
		#pragma unroll
Leonardo Solis's avatar
Leonardo Solis committed
37
38
39
*/
		__attribute__((opencl_unroll_hint))
		LOOP_PRNG_BT_USHORT_FLOAT:
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
		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
55
/*
56
		bool success = false;
lvs's avatar
lvs committed
57
58
59
*/
		int success = 1;
/*
60
		if(!valid) {
lvs's avatar
lvs committed
61
*/
Leonardo Solis's avatar
Leonardo Solis committed
62
		if(valid != 0) {
63
64
65
66
			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
67

lvs's avatar
lvs committed
68
/*
69
			success = write_channel_nb_altera(chan_PRNG2GA_BT_ushort_float_prng, tmp);
lvs's avatar
lvs committed
70
*/
Leonardo Solis's avatar
Leonardo Solis committed
71

lvs's avatar
lvs committed
72
			success = write_pipe(chan_PRNG2GA_BT_ushort_float_prng, &tmp);
73
		}
lvs's avatar
lvs committed
74
75
	} /*// End of while(!valid)*/
	// End of while(valid == 0)
76
77
78
79
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
80
/*
Leonardo Solis's avatar
Leonardo Solis committed
81
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
82
83
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
84
void Krnl_Prng_GG_uchar(unsigned int  Host_seed, 
85
		        unsigned char DockConst_num_of_genes){
Leonardo Solis's avatar
Leonardo Solis committed
86

87
	uint lfsr = Host_seed;
lvs's avatar
lvs committed
88
/*
89
	bool valid = false;
lvs's avatar
lvs committed
90
91
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
92

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

103
		uchar tmp[2];
104

Leonardo Solis's avatar
Leonardo Solis committed
105
/*
106
		#pragma unroll
Leonardo Solis's avatar
Leonardo Solis committed
107
108
109
*/
		__attribute__((opencl_unroll_hint))
		LOOP_PRNG_GG_UCHAR:
110
		for(uchar i=0; i<2; i++) {
111
112
113
114
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
115
			tmp[i] = (lfsr/MAX_UINT)*DockConst_num_of_genes;
116

117
		}
lvs's avatar
lvs committed
118
/*
119
		bool success = false;
lvs's avatar
lvs committed
120
121
122
*/
		int success = 1;

123
124
125
126
		uchar2 utmp;
		utmp.x = tmp[0];
		utmp.y = tmp[1];

lvs's avatar
lvs committed
127
/*
128
		if(!valid) {
lvs's avatar
lvs committed
129
*/
Leonardo Solis's avatar
Leonardo Solis committed
130
		if(valid != 0) {
lvs's avatar
lvs committed
131
/*
132
			success = write_channel_nb_altera(chan_PRNG2GA_GG_uchar_prng, utmp);
lvs's avatar
lvs committed
133
134
*/
			success = write_pipe(chan_PRNG2GA_GG_uchar_prng, &utmp);
Leonardo Solis's avatar
Leonardo Solis committed
135
		}
136
	} // End of while(active)
Leonardo Solis's avatar
Leonardo Solis committed
137
}
Leonardo Solis's avatar
Leonardo Solis committed
138

lvs's avatar
lvs committed
139
/*
Leonardo Solis's avatar
Leonardo Solis committed
140
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
141
142
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
143
144
145
146
void Krnl_Prng_GG_float(unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
147
/*
Leonardo Solis's avatar
Leonardo Solis committed
148
	bool valid = false;
lvs's avatar
lvs committed
149
150
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
151

lvs's avatar
lvs committed
152
/*
Leonardo Solis's avatar
Leonardo Solis committed
153
	while(!valid) {
lvs's avatar
lvs committed
154
*/
Leonardo Solis's avatar
Leonardo Solis committed
155
	while(valid != 0) {
lvs's avatar
lvs committed
156

Leonardo Solis's avatar
Leonardo Solis committed
157
		bool active = true;
lvs's avatar
lvs committed
158
/*
Leonardo Solis's avatar
Leonardo Solis committed
159
		active = read_channel_nb_altera(chan_Arbiter_GG_float_off, &valid);
lvs's avatar
lvs committed
160
161
*/
		valid = read_pipe(chan_Arbiter_GG_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
162
163
164
165
166
167
168
169
170

		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
171
/*
Leonardo Solis's avatar
Leonardo Solis committed
172
			bool success = false;
lvs's avatar
lvs committed
173
174
175
*/
			int success = 1;
/*
Leonardo Solis's avatar
Leonardo Solis committed
176
			if(!valid) {
lvs's avatar
lvs committed
177
*/
Leonardo Solis's avatar
Leonardo Solis committed
178
			if(valid != 0) {
lvs's avatar
lvs committed
179
/*
Leonardo Solis's avatar
Leonardo Solis committed
180
				success = write_channel_nb_altera(chan_PRNG2GA_GG_float_prng, tmp);
lvs's avatar
lvs committed
181
182
*/
				success = write_pipe(chan_PRNG2GA_GG_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
183
184
185
186
			}
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
187
188
189

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
190
/*
Leonardo Solis's avatar
Leonardo Solis committed
191
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
192
193
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
194
195
196
197
198
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, 
199
200
201
202
			    unsigned int Host_seed6, 
			    unsigned int Host_seed7,
			    unsigned int Host_seed8,
			    unsigned int Host_seed9, 
Leonardo Solis's avatar
Leonardo Solis committed
203
204
205
		            unsigned int DockConst_pop_size){


206
	uint lfsr[9];
Leonardo Solis's avatar
Leonardo Solis committed
207
208
209
210
211
	lfsr[0] = Host_seed1;
	lfsr[1] = Host_seed2;
	lfsr[2] = Host_seed3;
	lfsr[3] = Host_seed4;
	lfsr[4] = Host_seed5;
212
213
214
215
	lfsr[5] = Host_seed6;
	lfsr[6] = Host_seed7;
	lfsr[7] = Host_seed8;
	lfsr[8] = Host_seed9;
Leonardo Solis's avatar
Leonardo Solis committed
216

lvs's avatar
lvs committed
217
/*
Leonardo Solis's avatar
Leonardo Solis committed
218
	bool valid = false;
lvs's avatar
lvs committed
219
220
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
221

lvs's avatar
lvs committed
222
/*
Leonardo Solis's avatar
Leonardo Solis committed
223
	while(!valid) {
lvs's avatar
lvs committed
224
*/
Leonardo Solis's avatar
Leonardo Solis committed
225
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
226
		bool active = true;
lvs's avatar
lvs committed
227
/*
Leonardo Solis's avatar
Leonardo Solis committed
228
		active  = read_channel_nb_altera(chan_Arbiter_LS123_ushort_off, &valid);
lvs's avatar
lvs committed
229
230
*/
		valid  = read_pipe(chan_Arbiter_LS123_ushort_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
231

232
		ushort tmp[9];
Leonardo Solis's avatar
Leonardo Solis committed
233
		
Leonardo Solis's avatar
Leonardo Solis committed
234
/*
Leonardo Solis's avatar
Leonardo Solis committed
235
		#pragma unroll
Leonardo Solis's avatar
Leonardo Solis committed
236
237
238
*/
		__attribute__((opencl_unroll_hint))
		LOOP_PRNG_LS123_USHORT:
239
240
		for (uint i=0; i<9; i++){
			uchar  lsb[9];
Leonardo Solis's avatar
Leonardo Solis committed
241
242
243
244
245
246
			lsb [i] = lfsr[i] & 0x01u;
			lfsr[i] >>= 1;
			lfsr[i] ^= (-lsb[i]) & 0xA3000000u;
			tmp [i] = (DockConst_pop_size/MAX_UINT)*lfsr[i];
		}

247
		// To avoid having same entities undergoing LS simultaneously
Leonardo Solis's avatar
Leonardo Solis committed
248
		if (
249
250
251
252
253
254
255
256
			(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
257
258
259
260
261
		) {
			tmp[1] = tmp[0] + 1;
			tmp[2] = tmp[1] + 2;
			tmp[3] = tmp[2] + 3;
			tmp[4] = tmp[3] + 4;
262
263
264
265
			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
266
267
		}

lvs's avatar
lvs committed
268
/*
Leonardo Solis's avatar
Leonardo Solis committed
269
		bool success = false;
lvs's avatar
lvs committed
270
271
272
*/
		int success = 1;

273
		ushort16 tmp123;
Leonardo Solis's avatar
Leonardo Solis committed
274
275
276
277
278
		tmp123.s0 = tmp[0];
		tmp123.s1 = tmp[1];
		tmp123.s2 = tmp[2];
		tmp123.s3 = tmp[3];
		tmp123.s4 = tmp[4];
279
280
281
282
		tmp123.s5 = tmp[5];
		tmp123.s6 = tmp[6];
		tmp123.s7 = tmp[7];
		tmp123.s8 = tmp[8];
Leonardo Solis's avatar
Leonardo Solis committed
283

lvs's avatar
lvs committed
284
/*
Leonardo Solis's avatar
Leonardo Solis committed
285
		if(!valid) {
lvs's avatar
lvs committed
286
*/
Leonardo Solis's avatar
Leonardo Solis committed
287
		if(valid != 0) {
lvs's avatar
lvs committed
288
/*
Leonardo Solis's avatar
Leonardo Solis committed
289
			success = write_channel_nb_altera(chan_PRNG2GA_LS123_ushort_prng, tmp123);
lvs's avatar
lvs committed
290
291
*/
			success = write_pipe(chan_PRNG2GA_LS123_ushort_prng, &tmp123);
Leonardo Solis's avatar
Leonardo Solis committed
292
293
294
295
		}

	} // End of while(active)
}
296
297
298

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
299
/*
Leonardo Solis's avatar
Leonardo Solis committed
300
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
301
302
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
303
304
305
306
void Krnl_Prng_LS_float(unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
307
/*
Leonardo Solis's avatar
Leonardo Solis committed
308
	bool valid = false;
lvs's avatar
lvs committed
309
310
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
311

lvs's avatar
lvs committed
312
/*
Leonardo Solis's avatar
Leonardo Solis committed
313
	while(!valid) {
lvs's avatar
lvs committed
314
*/
Leonardo Solis's avatar
Leonardo Solis committed
315
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
316
		bool active = true;
lvs's avatar
lvs committed
317
/*
Leonardo Solis's avatar
Leonardo Solis committed
318
		active  = read_channel_nb_altera(chan_Arbiter_LS_float_off, &valid);
lvs's avatar
lvs committed
319
320
*/
		valid  = read_pipe(chan_Arbiter_LS_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
321
322
323
324
325
326
327
328
	
		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
329
/*
Leonardo Solis's avatar
Leonardo Solis committed
330
			bool success = false;
lvs's avatar
lvs committed
331
332
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
333
334
335

			#if defined (FIXED_POINT_LS1)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
336
/*
Leonardo Solis's avatar
Leonardo Solis committed
337
			if(!valid) {
lvs's avatar
lvs committed
338
*/
339
			if(valid != 0) {
lvs's avatar
lvs committed
340
/*
Leonardo Solis's avatar
Leonardo Solis committed
341
				success = write_channel_nb_altera(chan_PRNG2GA_LS_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
342
343
*/
				success = write_pipe(chan_PRNG2GA_LS_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
344
345
			}
			#else
lvs's avatar
lvs committed
346
/*
Leonardo Solis's avatar
Leonardo Solis committed
347
			if(!valid) {
lvs's avatar
lvs committed
348
*/
Leonardo Solis's avatar
Leonardo Solis committed
349
			if(valid != 0) {
lvs's avatar
lvs committed
350
/*
Leonardo Solis's avatar
Leonardo Solis committed
351
				success = write_channel_nb_altera(chan_PRNG2GA_LS_float_prng, tmp);
lvs's avatar
lvs committed
352
353
*/
				success = write_pipe(chan_PRNG2GA_LS_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
354
			}
Leonardo Solis's avatar
Leonardo Solis committed
355
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
356
357
358
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
359

lvs's avatar
lvs committed
360
/*
Leonardo Solis's avatar
Leonardo Solis committed
361
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
362
363
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
364
365
366
367
void Krnl_Prng_LS2_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
368
/*
Leonardo Solis's avatar
Leonardo Solis committed
369
	bool valid = false;
lvs's avatar
lvs committed
370
371
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
372

lvs's avatar
lvs committed
373
/*
Leonardo Solis's avatar
Leonardo Solis committed
374
	while(!valid) {
lvs's avatar
lvs committed
375
*/
Leonardo Solis's avatar
Leonardo Solis committed
376
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
377
		bool active = true;
lvs's avatar
lvs committed
378
/*
Leonardo Solis's avatar
Leonardo Solis committed
379
		active  = read_channel_nb_altera(chan_Arbiter_LS2_float_off, &valid);
lvs's avatar
lvs committed
380
381
*/
		valid  = read_pipe(chan_Arbiter_LS2_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
382
383
384
385
386
387
388
389
	
		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
390
/*
Leonardo Solis's avatar
Leonardo Solis committed
391
			bool success = false;
lvs's avatar
lvs committed
392
393
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
394
395
396

			#if defined (FIXED_POINT_LS2)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
397
/*
Leonardo Solis's avatar
Leonardo Solis committed
398
			if(!valid) {
lvs's avatar
lvs committed
399
*/
Leonardo Solis's avatar
Leonardo Solis committed
400
			if(valid != 0) {
lvs's avatar
lvs committed
401
/*
Leonardo Solis's avatar
Leonardo Solis committed
402
				success = write_channel_nb_altera(chan_PRNG2GA_LS2_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
403
404
*/
				success = write_pipe(chan_PRNG2GA_LS2_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
405
406
			}
			#else
lvs's avatar
lvs committed
407
/*
Leonardo Solis's avatar
Leonardo Solis committed
408
			if(!valid) {
lvs's avatar
lvs committed
409
*/
Leonardo Solis's avatar
Leonardo Solis committed
410
			if(valid != 0) {
lvs's avatar
lvs committed
411
/*
Leonardo Solis's avatar
Leonardo Solis committed
412
				success = write_channel_nb_altera(chan_PRNG2GA_LS2_float_prng, tmp);
lvs's avatar
lvs committed
413
414
*/
				success = write_pipe(chan_PRNG2GA_LS2_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
415
			}
Leonardo Solis's avatar
Leonardo Solis committed
416
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
417
418
419
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
420

lvs's avatar
lvs committed
421
/*
Leonardo Solis's avatar
Leonardo Solis committed
422
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
423
424
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
425
426
427
428
void Krnl_Prng_LS3_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
429
/*
Leonardo Solis's avatar
Leonardo Solis committed
430
	bool valid = false;
lvs's avatar
lvs committed
431
432
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
433

lvs's avatar
lvs committed
434
/*
Leonardo Solis's avatar
Leonardo Solis committed
435
	while(!valid) {
lvs's avatar
lvs committed
436
*/
Leonardo Solis's avatar
Leonardo Solis committed
437
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
438
		bool active = true;
lvs's avatar
lvs committed
439
/*
Leonardo Solis's avatar
Leonardo Solis committed
440
		active  = read_channel_nb_altera(chan_Arbiter_LS3_float_off, &valid);
lvs's avatar
lvs committed
441
442
*/
		valid  = read_pipe(chan_Arbiter_LS3_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
443
444
445
446
447
448
449
450
	
		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
451
/*
Leonardo Solis's avatar
Leonardo Solis committed
452
			bool success = false;
lvs's avatar
lvs committed
453
454
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
455
456
457

			#if defined (FIXED_POINT_LS3)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
458
/*
Leonardo Solis's avatar
Leonardo Solis committed
459
			if(!valid) {
lvs's avatar
lvs committed
460
*/
Leonardo Solis's avatar
Leonardo Solis committed
461
			if(valid != 0) {
lvs's avatar
lvs committed
462
/*
Leonardo Solis's avatar
Leonardo Solis committed
463
				success = write_channel_nb_altera(chan_PRNG2GA_LS3_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
464
465
*/
				success = write_pipe(chan_PRNG2GA_LS3_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
466
467
468
			}

			#else
lvs's avatar
lvs committed
469
/*
Leonardo Solis's avatar
Leonardo Solis committed
470
			if(!valid) {
lvs's avatar
lvs committed
471
*/
Leonardo Solis's avatar
Leonardo Solis committed
472
			if(valid != 0) {
lvs's avatar
lvs committed
473
/*
Leonardo Solis's avatar
Leonardo Solis committed
474
				success = write_channel_nb_altera(chan_PRNG2GA_LS3_float_prng, tmp);
lvs's avatar
lvs committed
475
476
*/
				success = write_pipe(chan_PRNG2GA_LS3_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
477
			}
Leonardo Solis's avatar
Leonardo Solis committed
478
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
479
480
481
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
482

lvs's avatar
lvs committed
483
/*
Leonardo Solis's avatar
Leonardo Solis committed
484
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
485
486
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
487
488
489
490
void Krnl_Prng_LS4_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
491
/*
Leonardo Solis's avatar
Leonardo Solis committed
492
	bool valid = false;
lvs's avatar
lvs committed
493
494
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
495

lvs's avatar
lvs committed
496
/*
Leonardo Solis's avatar
Leonardo Solis committed
497
	while(!valid) {
lvs's avatar
lvs committed
498
*/
Leonardo Solis's avatar
Leonardo Solis committed
499
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
500
		bool active = true;
lvs's avatar
lvs committed
501
/*
Leonardo Solis's avatar
Leonardo Solis committed
502
		active  = read_channel_nb_altera(chan_Arbiter_LS4_float_off, &valid);
lvs's avatar
lvs committed
503
504
*/
		valid  = read_pipe(chan_Arbiter_LS4_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
505
506
507
508
509
510
511
512
	
		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
513
/*
Leonardo Solis's avatar
Leonardo Solis committed
514
			bool success = false;
lvs's avatar
lvs committed
515
516
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
517

518
			#if defined (FIXED_POINT_LS4)
Leonardo Solis's avatar
Leonardo Solis committed
519
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
520
/*
Leonardo Solis's avatar
Leonardo Solis committed
521
			if(!valid) {
lvs's avatar
lvs committed
522
*/
Leonardo Solis's avatar
Leonardo Solis committed
523
			if(valid != 0) {
lvs's avatar
lvs committed
524
/*
Leonardo Solis's avatar
Leonardo Solis committed
525
				success = write_channel_nb_altera(chan_PRNG2GA_LS4_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
526
527
*/
				success = write_pipe(chan_PRNG2GA_LS4_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
528
529
			}
			#else
lvs's avatar
lvs committed
530
/*
Leonardo Solis's avatar
Leonardo Solis committed
531
			if(!valid) {
lvs's avatar
lvs committed
532
*/
Leonardo Solis's avatar
Leonardo Solis committed
533
			if(valid != 0) {
lvs's avatar
lvs committed
534
/*
Leonardo Solis's avatar
Leonardo Solis committed
535
				success = write_channel_nb_altera(chan_PRNG2GA_LS4_float_prng, tmp);
lvs's avatar
lvs committed
536
537
*/
				success = write_pipe(chan_PRNG2GA_LS4_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
538
539
540
541
542
543
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
544
/*
Leonardo Solis's avatar
Leonardo Solis committed
545
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
546
547
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
Leonardo Solis's avatar
Leonardo Solis committed
548
549
550
551
void Krnl_Prng_LS5_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
552
/*
Leonardo Solis's avatar
Leonardo Solis committed
553
	bool valid = false;
lvs's avatar
lvs committed
554
555
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
556

lvs's avatar
lvs committed
557
/*
Leonardo Solis's avatar
Leonardo Solis committed
558
	while(!valid) {
lvs's avatar
lvs committed
559
*/
Leonardo Solis's avatar
Leonardo Solis committed
560
	while(valid != 0) {
Leonardo Solis's avatar
Leonardo Solis committed
561
		bool active = true;
lvs's avatar
lvs committed
562
/*
Leonardo Solis's avatar
Leonardo Solis committed
563
		active  = read_channel_nb_altera(chan_Arbiter_LS5_float_off, &valid);
lvs's avatar
lvs committed
564
565
*/
		valid  = read_pipe(chan_Arbiter_LS5_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
566
567
568
569
570
571
572
573
	
		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
574
/*
Leonardo Solis's avatar
Leonardo Solis committed
575
			bool success = false;
lvs's avatar
lvs committed
576
577
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
578

579
			#if defined (FIXED_POINT_LS5)
Leonardo Solis's avatar
Leonardo Solis committed
580
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
581
/*
Leonardo Solis's avatar
Leonardo Solis committed
582
			if(!valid) {
lvs's avatar
lvs committed
583
*/
Leonardo Solis's avatar
Leonardo Solis committed
584
			if(valid != 0) {
lvs's avatar
lvs committed
585
/*
Leonardo Solis's avatar
Leonardo Solis committed
586
				success = write_channel_nb_altera(chan_PRNG2GA_LS5_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
587
588
*/
				success = write_pipe(chan_PRNG2GA_LS5_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
589
590
			}
			#else
lvs's avatar
lvs committed
591
/*
Leonardo Solis's avatar
Leonardo Solis committed
592
			if(!valid) {
lvs's avatar
lvs committed
593
*/
Leonardo Solis's avatar
Leonardo Solis committed
594
			if(valid != 0) {
lvs's avatar
lvs committed
595
/*
Leonardo Solis's avatar
Leonardo Solis committed
596
				success = write_channel_nb_altera(chan_PRNG2GA_LS5_float_prng, tmp);
lvs's avatar
lvs committed
597
598
*/
				success = write_pipe(chan_PRNG2GA_LS5_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
599
600
601
602
603
			}
			#endif
		}
	} // End of while(active)
}
604

lvs's avatar
lvs committed
605
/*
606
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
607
608
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
609
610
611
612
void Krnl_Prng_LS6_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
613
/*
614
	bool valid = false;
lvs's avatar
lvs committed
615
616
*/
	int valid = 1;
617

lvs's avatar
lvs committed
618
/*
619
	while(!valid) {
lvs's avatar
lvs committed
620
*/
Leonardo Solis's avatar
Leonardo Solis committed
621
	while(valid != 0) {
622
		bool active = true;
lvs's avatar
lvs committed
623
/*
624
		active  = read_channel_nb_altera(chan_Arbiter_LS6_float_off, &valid);
lvs's avatar
lvs committed
625
626
*/
		valid  = read_pipe(chan_Arbiter_LS6_float_off, &active);
627
628
629
630
631
632
633
634
	
		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
635
/*
636
			bool success = false;
lvs's avatar
lvs committed
637
638
*/
			int success = 1;
639
640
641

			#if defined (FIXED_POINT_LS6)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
642
/*
643
			if(!valid) {
lvs's avatar
lvs committed
644
*/
Leonardo Solis's avatar
Leonardo Solis committed
645
			if(valid != 0) {
lvs's avatar
lvs committed
646
/*
647
				success = write_channel_nb_altera(chan_PRNG2GA_LS6_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
648
649
*/
				success = write_pipe(chan_PRNG2GA_LS6_float_prng, (float*) &fixpt_tmp);
650
651
			}
			#else
lvs's avatar
lvs committed
652
/*
653
			if(!valid) {
lvs's avatar
lvs committed
654
*/
Leonardo Solis's avatar
Leonardo Solis committed
655
			if(valid != 0) {
lvs's avatar
lvs committed
656
/*
657
				success = write_channel_nb_altera(chan_PRNG2GA_LS6_float_prng, tmp);
lvs's avatar
lvs committed
658
659
*/
				success = write_pipe(chan_PRNG2GA_LS6_float_prng, &tmp);
660
661
662
663
664
665
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
666
/*
667
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
668
669
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
670
671
672
673
void Krnl_Prng_LS7_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
674
/*
675
	bool valid = false;
lvs's avatar
lvs committed
676
677
*/
	int valid = 1;
678

lvs's avatar
lvs committed
679
/*
680
	while(!valid) {
lvs's avatar
lvs committed
681
*/
Leonardo Solis's avatar
Leonardo Solis committed
682
	while(valid != 0) {
683
		bool active = true;
lvs's avatar
lvs committed
684
/*
685
		active  = read_channel_nb_altera(chan_Arbiter_LS7_float_off, &valid);
lvs's avatar
lvs committed
686
687
*/
		valid  = read_pipe(chan_Arbiter_LS7_float_off, &active);
688
689
690
691
692
693
694
695
	
		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
696
/*
697
			bool success = false;
lvs's avatar
lvs committed
698
699
*/
			int success = 1;
700
701
702

			#if defined (FIXED_POINT_LS7)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
703
/*
704
			if(!valid) {
lvs's avatar
lvs committed
705
*/
Leonardo Solis's avatar
Leonardo Solis committed
706
			if(valid != 0) {
lvs's avatar
lvs committed
707
/*
708
				success = write_channel_nb_altera(chan_PRNG2GA_LS7_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
709
710
*/
				success = write_pipe(chan_PRNG2GA_LS7_float_prng, (float*) &fixpt_tmp);
711
712
			}
			#else
lvs's avatar
lvs committed
713
/*
714
			if(!valid) {
lvs's avatar
lvs committed
715
*/
Leonardo Solis's avatar
Leonardo Solis committed
716
			if(valid != 0) {
lvs's avatar
lvs committed
717
/*
718
				success = write_channel_nb_altera(chan_PRNG2GA_LS7_float_prng, tmp);
lvs's avatar
lvs committed
719
720
*/
				success = write_pipe(chan_PRNG2GA_LS7_float_prng, &tmp);
721
722
723
724
725
726
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
727
/*
728
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
729
730
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
731
732
733
734
void Krnl_Prng_LS8_float(unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes){

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
735
/*
736
	bool valid = false;
lvs's avatar
lvs committed
737
738
*/
	int valid = 1;
739

lvs's avatar
lvs committed
740
/*
741
	while(!valid) {
lvs's avatar
lvs committed
742
*/
Leonardo Solis's avatar
Leonardo Solis committed
743
	while(valid != 0) {
744
		bool active = true;
lvs's avatar
lvs committed
745
/*
746
		active  = read_channel_nb_altera(chan_Arbiter_LS8_float_off, &valid);
lvs's avatar
lvs committed
747
748
*/
		valid  = read_pipe(chan_Arbiter_LS8_float_off, &active);
749
750
751
752
753
754
755
756
	
		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
757
/*
758
			bool success = false;
lvs's avatar
lvs committed
759
760
*/
			int success = 1;
761
762
763

			#if defined (FIXED_POINT_LS8)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
764
/*
765
			if(!valid) {
lvs's avatar
lvs committed
766
*/
Leonardo Solis's avatar
Leonardo Solis committed
767
			if(valid != 0) {
lvs's avatar
lvs committed
768
/*
769
				success = write_channel_nb_altera(chan_PRNG2GA_LS8_float_prng, *(float*) &fixpt_tmp);
lvs's avatar
lvs committed
770
771
*/
				success = write_pipe(chan_PRNG2GA_LS8_float_prng, (float*) &fixpt_tmp);
772
773
			}
			#else
lvs's avatar
lvs committed
774
/*
775
			if(!valid) {
lvs's avatar
lvs committed
776
*/
Leonardo Solis's avatar
Leonardo Solis committed
777
			if(valid != 0) {
lvs's avatar
lvs committed
778
/*
779
				success = write_channel_nb_altera(chan_PRNG2GA_LS8_float_prng, tmp);
lvs's avatar
lvs committed
780
781
*/
				success = write_pipe(chan_PRNG2GA_LS8_float_prng, &tmp);
782
783
784
785
786
787
			}
			#endif
		}
	} // End of while(active)
}