Krnl_PRNG.cl 21.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
void Krnl_Prng_BT_ushort_float(
			       unsigned int Host_seed1,
11
			       unsigned int Host_seed2,
12
13
14
			       unsigned int DockConst_pop_size

#if !defined(SW_EMU)
15
16
			      // IMPORTANT: enable this dummy global argument only for "hw" build.
			      // Check ../common_xilinx/utility/boards.mk
17
18
19
20
21
			      // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
			      ,
			      __global int *dummy
#endif
){
22
23
24
25

	uint2 lfsr;
	lfsr.x = Host_seed1;
	lfsr.y = Host_seed2;
lvs's avatar
lvs committed
26
/*
27
	bool valid  = false;
lvs's avatar
lvs committed
28
29
*/
	int valid = 1;
30
	
lvs's avatar
lvs committed
31
/*
32
	while(!valid) {	
lvs's avatar
lvs committed
33
*/
34
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
35
	LOOP_WHILE_PRNG_BT_USHOT_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
36
	while(valid != 0) {	
37
/*
38
		bool active = true;
39
40
*/
		int active;
lvs's avatar
lvs committed
41
		valid = read_pipe(chan_Arbiter_BT_ushort_float_off, &active);
42
43
44
45

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

Leonardo Solis's avatar
Leonardo Solis committed
46
		__attribute__((opencl_unroll_hint))
Leonardo Solis's avatar
Leonardo Solis committed
47
		LOOP_FOR_PRNG_BT_USHORT_FLOAT:
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
		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
63
/*
64
		bool success = false;
lvs's avatar
lvs committed
65
66
67
*/
		int success = 1;
/*
68
		if(!valid) {
lvs's avatar
lvs committed
69
*/
Leonardo Solis's avatar
Leonardo Solis committed
70
		if(valid != 0) {
71
/*
72
73
74
75
			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]};
76
77
78
79
80
81
82
83
84
85
86
87
*/
			// Check "Krnl_GA"
			// To surpass error in hw_emu
			float u_tmp_float_0 = u_tmp[0];
			float u_tmp_float_1 = u_tmp[1];
			float u_tmp_float_2 = u_tmp[2];
			float u_tmp_float_3 = u_tmp[3];

			float8 tmp = {u_tmp_float_0, f_tmp[0],
				      u_tmp_float_1, f_tmp[1],
				      u_tmp_float_2, f_tmp[2],
				      u_tmp_float_3, f_tmp[3]};
Leonardo Solis's avatar
Leonardo Solis committed
88

lvs's avatar
lvs committed
89
			success = write_pipe(chan_PRNG2GA_BT_ushort_float_prng, &tmp);
90
		}
lvs's avatar
lvs committed
91
92
	} /*// End of while(!valid)*/
	// End of while(valid == 0)
93
94
95
96
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
97
/*
Leonardo Solis's avatar
Leonardo Solis committed
98
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
99
100
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
101
102
103
104
105
void Krnl_Prng_GG_uchar(
			unsigned int  Host_seed, 
		        unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
106
107
			// IMPORTANT: enable this dummy global argument only for "hw" build.
			// Check ../common_xilinx/utility/boards.mk
108
109
110
111
112
		        // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
			,
			__global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
113

114
	uint lfsr = Host_seed;
lvs's avatar
lvs committed
115
/*
116
	bool valid = false;
lvs's avatar
lvs committed
117
118
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
119

lvs's avatar
lvs committed
120
/*
121
	while(!valid) {
lvs's avatar
lvs committed
122
*/
123
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
124
	LOOP_WHILE_PRNG_GG_UCHAR:
Leonardo Solis's avatar
Leonardo Solis committed
125
	while(valid != 0) {
126
/*
127
		bool active = true;
128
129
*/
		int active;
lvs's avatar
lvs committed
130
131
		valid = read_pipe(chan_Arbiter_GG_uchar_off, &active);		

132
		uchar tmp[2];
133

Leonardo Solis's avatar
Leonardo Solis committed
134
		__attribute__((opencl_unroll_hint))
Leonardo Solis's avatar
Leonardo Solis committed
135
		LOOP_FOR_PRNG_GG_UCHAR:
136
		for(uchar i=0; i<2; i++) {
137
138
139
140
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
141
			tmp[i] = (lfsr/MAX_UINT)*DockConst_num_of_genes;
142

143
		}
lvs's avatar
lvs committed
144
/*
145
		bool success = false;
lvs's avatar
lvs committed
146
147
148
*/
		int success = 1;

149
150
151
152
		uchar2 utmp;
		utmp.x = tmp[0];
		utmp.y = tmp[1];

lvs's avatar
lvs committed
153
/*
154
		if(!valid) {
lvs's avatar
lvs committed
155
*/
Leonardo Solis's avatar
Leonardo Solis committed
156
		if(valid != 0) {
lvs's avatar
lvs committed
157
			success = write_pipe(chan_PRNG2GA_GG_uchar_prng, &utmp);
Leonardo Solis's avatar
Leonardo Solis committed
158
		}
159
	} // End of while(active)
Leonardo Solis's avatar
Leonardo Solis committed
160
}
Leonardo Solis's avatar
Leonardo Solis committed
161

lvs's avatar
lvs committed
162
/*
Leonardo Solis's avatar
Leonardo Solis committed
163
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
164
165
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
166
167
168
169
170
void Krnl_Prng_GG_float(
			unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
171
172
			// IMPORTANT: enable this dummy global argument only for "hw" build.
			// Check ../common_xilinx/utility/boards.mk
173
174
175
176
177
		        // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		        ,
		        __global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
178
179

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
180
/*
Leonardo Solis's avatar
Leonardo Solis committed
181
	bool valid = false;
lvs's avatar
lvs committed
182
183
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
184

lvs's avatar
lvs committed
185
/*
Leonardo Solis's avatar
Leonardo Solis committed
186
	while(!valid) {
lvs's avatar
lvs committed
187
*/
188
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
189
	LOOP_WHILE_PRNG_GG_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
190
	while(valid != 0) {
191
/*
Leonardo Solis's avatar
Leonardo Solis committed
192
		bool active = true;
193
194
*/
		int active;
lvs's avatar
lvs committed
195
		valid = read_pipe(chan_Arbiter_GG_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
196

197
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
198
		LOOP_FOR_PRNG_GG_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
199
200
201
202
203
204
205
206
		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
207
/*
Leonardo Solis's avatar
Leonardo Solis committed
208
			bool success = false;
lvs's avatar
lvs committed
209
210
211
*/
			int success = 1;
/*
Leonardo Solis's avatar
Leonardo Solis committed
212
			if(!valid) {
lvs's avatar
lvs committed
213
*/
Leonardo Solis's avatar
Leonardo Solis committed
214
			if(valid != 0) {
lvs's avatar
lvs committed
215
				success = write_pipe(chan_PRNG2GA_GG_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
216
217
218
219
			}
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
220
221
222

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
223
/*
Leonardo Solis's avatar
Leonardo Solis committed
224
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
225
226
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
227
228
void Krnl_Prng_LS123_ushort(
			    unsigned int Host_seed1,
Leonardo Solis's avatar
Leonardo Solis committed
229
230
231
232
			    unsigned int Host_seed2, 
			    unsigned int Host_seed3,
			    unsigned int Host_seed4,
			    unsigned int Host_seed5, 
233
234
235
236
			    unsigned int Host_seed6, 
			    unsigned int Host_seed7,
			    unsigned int Host_seed8,
			    unsigned int Host_seed9, 
237
238
239
		            unsigned int DockConst_pop_size

#if !defined(SW_EMU)
240
241
			    // IMPORTANT: enable this dummy global argument only for "hw" build.
			    // Check ../common_xilinx/utility/boards.mk
242
243
244
245
246
		            // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
			    ,
			    __global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
247
248


249
	uint lfsr[9];
Leonardo Solis's avatar
Leonardo Solis committed
250
251
252
253
254
	lfsr[0] = Host_seed1;
	lfsr[1] = Host_seed2;
	lfsr[2] = Host_seed3;
	lfsr[3] = Host_seed4;
	lfsr[4] = Host_seed5;
255
256
257
258
	lfsr[5] = Host_seed6;
	lfsr[6] = Host_seed7;
	lfsr[7] = Host_seed8;
	lfsr[8] = Host_seed9;
Leonardo Solis's avatar
Leonardo Solis committed
259

lvs's avatar
lvs committed
260
/*
Leonardo Solis's avatar
Leonardo Solis committed
261
	bool valid = false;
lvs's avatar
lvs committed
262
263
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
264

lvs's avatar
lvs committed
265
/*
Leonardo Solis's avatar
Leonardo Solis committed
266
	while(!valid) {
lvs's avatar
lvs committed
267
*/
268
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
269
	LOOP_WHILE_PRNG_LS123_USHORT:
Leonardo Solis's avatar
Leonardo Solis committed
270
	while(valid != 0) {
271
/*
Leonardo Solis's avatar
Leonardo Solis committed
272
		bool active = true;
273
274
*/
		int active;
lvs's avatar
lvs committed
275
		valid  = read_pipe(chan_Arbiter_LS123_ushort_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
276

277
		ushort tmp[9];
Leonardo Solis's avatar
Leonardo Solis committed
278
		
Leonardo Solis's avatar
Leonardo Solis committed
279
		__attribute__((opencl_unroll_hint))
Leonardo Solis's avatar
Leonardo Solis committed
280
		LOOP_FOR_PRNG_LS123_USHORT:
281
282
		for (uint i=0; i<9; i++){
			uchar  lsb[9];
Leonardo Solis's avatar
Leonardo Solis committed
283
284
285
286
287
288
			lsb [i] = lfsr[i] & 0x01u;
			lfsr[i] >>= 1;
			lfsr[i] ^= (-lsb[i]) & 0xA3000000u;
			tmp [i] = (DockConst_pop_size/MAX_UINT)*lfsr[i];
		}

289
		// To avoid having same entities undergoing LS simultaneously
Leonardo Solis's avatar
Leonardo Solis committed
290
		if (
291
292
293
294
295
296
297
298
			(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
299
300
301
302
303
		) {
			tmp[1] = tmp[0] + 1;
			tmp[2] = tmp[1] + 2;
			tmp[3] = tmp[2] + 3;
			tmp[4] = tmp[3] + 4;
304
305
306
307
			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
308
309
		}

lvs's avatar
lvs committed
310
/*
Leonardo Solis's avatar
Leonardo Solis committed
311
		bool success = false;
lvs's avatar
lvs committed
312
313
314
*/
		int success = 1;

315
		ushort16 tmp123;
Leonardo Solis's avatar
Leonardo Solis committed
316
317
318
319
320
		tmp123.s0 = tmp[0];
		tmp123.s1 = tmp[1];
		tmp123.s2 = tmp[2];
		tmp123.s3 = tmp[3];
		tmp123.s4 = tmp[4];
321
322
323
324
		tmp123.s5 = tmp[5];
		tmp123.s6 = tmp[6];
		tmp123.s7 = tmp[7];
		tmp123.s8 = tmp[8];
Leonardo Solis's avatar
Leonardo Solis committed
325

lvs's avatar
lvs committed
326
/*
Leonardo Solis's avatar
Leonardo Solis committed
327
		if(!valid) {
lvs's avatar
lvs committed
328
*/
Leonardo Solis's avatar
Leonardo Solis committed
329
		if(valid != 0) {
lvs's avatar
lvs committed
330
			success = write_pipe(chan_PRNG2GA_LS123_ushort_prng, &tmp123);
Leonardo Solis's avatar
Leonardo Solis committed
331
332
333
334
		}

	} // End of while(active)
}
335
336
337

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
lvs's avatar
lvs committed
338
/*
Leonardo Solis's avatar
Leonardo Solis committed
339
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
340
341
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
342
343
344
345
346
void Krnl_Prng_LS_float(
			unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
347
348
			// IMPORTANT: enable this dummy global argument only for "hw" build.
			// Check ../common_xilinx/utility/boards.mk
349
350
351
352
353
 		        // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
			,
			__global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
354
355

	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
*/
364
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
365
	LOOP_WHILE_PRNG_LS_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
366
	while(valid != 0) {
367
/*
Leonardo Solis's avatar
Leonardo Solis committed
368
		bool active = true;
369
370
*/
		int active;
lvs's avatar
lvs committed
371
		valid  = read_pipe(chan_Arbiter_LS_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
372
	
373
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
374
		LOOP_FOR_PRNG_LS_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
375
376
377
378
379
380
381
		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
382
/*
Leonardo Solis's avatar
Leonardo Solis committed
383
			bool success = false;
lvs's avatar
lvs committed
384
385
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
386
387
388

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

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

#if !defined(SW_EMU)
416
417
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
418
419
420
421
422
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
423
424

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
425
/*
Leonardo Solis's avatar
Leonardo Solis committed
426
	bool valid = false;
lvs's avatar
lvs committed
427
428
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
429

lvs's avatar
lvs committed
430
/*
Leonardo Solis's avatar
Leonardo Solis committed
431
	while(!valid) {
lvs's avatar
lvs committed
432
*/
433
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
434
	LOOP_WHILE_PRNG_LS2_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
435
	while(valid != 0) {
436
/*
Leonardo Solis's avatar
Leonardo Solis committed
437
		bool active = true;
438
439
*/
		int active;
lvs's avatar
lvs committed
440
		valid  = read_pipe(chan_Arbiter_LS2_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
441
	
442
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
443
		LOOP_FOR_PRNG_LS2_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
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_LS2)
			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
				success = write_pipe(chan_PRNG2GA_LS2_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
463
464
			}
			#else
lvs's avatar
lvs committed
465
/*
Leonardo Solis's avatar
Leonardo Solis committed
466
			if(!valid) {
lvs's avatar
lvs committed
467
*/
Leonardo Solis's avatar
Leonardo Solis committed
468
			if(valid != 0) {
lvs's avatar
lvs committed
469
				success = write_pipe(chan_PRNG2GA_LS2_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
470
			}
Leonardo Solis's avatar
Leonardo Solis committed
471
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
472
473
474
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
475

lvs's avatar
lvs committed
476
/*
Leonardo Solis's avatar
Leonardo Solis committed
477
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
478
479
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
480
481
482
483
484
void Krnl_Prng_LS3_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
485
486
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
487
488
489
490
491
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
492
493

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
494
/*
Leonardo Solis's avatar
Leonardo Solis committed
495
	bool valid = false;
lvs's avatar
lvs committed
496
497
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
498

lvs's avatar
lvs committed
499
/*
Leonardo Solis's avatar
Leonardo Solis committed
500
	while(!valid) {
lvs's avatar
lvs committed
501
*/
502
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
503
	LOOP_WHILE_PRNG_LS3_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
504
	while(valid != 0) {
505
/*
Leonardo Solis's avatar
Leonardo Solis committed
506
		bool active = true;
507
508
*/
		int active;
lvs's avatar
lvs committed
509
		valid  = read_pipe(chan_Arbiter_LS3_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
510
	
511
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
512
		LOOP_FOR_PRNG_LS3_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
513
514
515
516
517
518
519
		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
520
/*
Leonardo Solis's avatar
Leonardo Solis committed
521
			bool success = false;
lvs's avatar
lvs committed
522
523
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
524
525
526

			#if defined (FIXED_POINT_LS3)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
527
/*
Leonardo Solis's avatar
Leonardo Solis committed
528
			if(!valid) {
lvs's avatar
lvs committed
529
*/
Leonardo Solis's avatar
Leonardo Solis committed
530
			if(valid != 0) {
lvs's avatar
lvs committed
531
				success = write_pipe(chan_PRNG2GA_LS3_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
532
533
534
			}

			#else
lvs's avatar
lvs committed
535
/*
Leonardo Solis's avatar
Leonardo Solis committed
536
			if(!valid) {
lvs's avatar
lvs committed
537
*/
Leonardo Solis's avatar
Leonardo Solis committed
538
			if(valid != 0) {
lvs's avatar
lvs committed
539
				success = write_pipe(chan_PRNG2GA_LS3_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
540
			}
Leonardo Solis's avatar
Leonardo Solis committed
541
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
542
543
544
		}
	} // End of while(active)
}
Leonardo Solis's avatar
Leonardo Solis committed
545

lvs's avatar
lvs committed
546
/*
Leonardo Solis's avatar
Leonardo Solis committed
547
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
548
549
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
550
551
552
553
554
void Krnl_Prng_LS4_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
555
556
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
557
558
559
560
561
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
562
563

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
564
/*
Leonardo Solis's avatar
Leonardo Solis committed
565
	bool valid = false;
lvs's avatar
lvs committed
566
567
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
568

lvs's avatar
lvs committed
569
/*
Leonardo Solis's avatar
Leonardo Solis committed
570
	while(!valid) {
lvs's avatar
lvs committed
571
*/
572
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
573
	LOOP_WHILE_PRNG_LS4_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
574
	while(valid != 0) {
575
/*
Leonardo Solis's avatar
Leonardo Solis committed
576
		bool active = true;
577
578
*/
		int active;
lvs's avatar
lvs committed
579
		valid  = read_pipe(chan_Arbiter_LS4_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
580
	
581
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
582
		LOOP_FOR_PRNG_LS4_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
583
584
585
586
587
588
589
		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
590
/*
Leonardo Solis's avatar
Leonardo Solis committed
591
			bool success = false;
lvs's avatar
lvs committed
592
593
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
594

595
			#if defined (FIXED_POINT_LS4)
Leonardo Solis's avatar
Leonardo Solis committed
596
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
597
/*
Leonardo Solis's avatar
Leonardo Solis committed
598
			if(!valid) {
lvs's avatar
lvs committed
599
*/
Leonardo Solis's avatar
Leonardo Solis committed
600
			if(valid != 0) {
lvs's avatar
lvs committed
601
				success = write_pipe(chan_PRNG2GA_LS4_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
602
603
			}
			#else
lvs's avatar
lvs committed
604
/*
Leonardo Solis's avatar
Leonardo Solis committed
605
			if(!valid) {
lvs's avatar
lvs committed
606
*/
Leonardo Solis's avatar
Leonardo Solis committed
607
			if(valid != 0) {
lvs's avatar
lvs committed
608
				success = write_pipe(chan_PRNG2GA_LS4_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
609
610
611
612
613
614
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
615
/*
Leonardo Solis's avatar
Leonardo Solis committed
616
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
617
618
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
619
620
621
622
623
void Krnl_Prng_LS5_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
624
625
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
626
627
628
629
630
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
Leonardo Solis's avatar
Leonardo Solis committed
631
632

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
633
/*
Leonardo Solis's avatar
Leonardo Solis committed
634
	bool valid = false;
lvs's avatar
lvs committed
635
636
*/
	int valid = 1;
Leonardo Solis's avatar
Leonardo Solis committed
637

lvs's avatar
lvs committed
638
/*
Leonardo Solis's avatar
Leonardo Solis committed
639
	while(!valid) {
lvs's avatar
lvs committed
640
*/
641
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
642
	LOOP_WHILE_PRNG_LS5_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
643
	while(valid != 0) {
644
/*
Leonardo Solis's avatar
Leonardo Solis committed
645
		bool active = true;
646
647
*/
		int active;
lvs's avatar
lvs committed
648
		valid  = read_pipe(chan_Arbiter_LS5_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
649
	
650
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
651
		LOOP_FOR_PRNG_LS5_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
652
653
654
655
656
657
658
		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
659
/*
Leonardo Solis's avatar
Leonardo Solis committed
660
			bool success = false;
lvs's avatar
lvs committed
661
662
*/
			int success = 1;
Leonardo Solis's avatar
Leonardo Solis committed
663

664
			#if defined (FIXED_POINT_LS5)
Leonardo Solis's avatar
Leonardo Solis committed
665
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
666
/*
Leonardo Solis's avatar
Leonardo Solis committed
667
			if(!valid) {
lvs's avatar
lvs committed
668
*/
Leonardo Solis's avatar
Leonardo Solis committed
669
			if(valid != 0) {
lvs's avatar
lvs committed
670
				success = write_pipe(chan_PRNG2GA_LS5_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
671
672
			}
			#else
lvs's avatar
lvs committed
673
/*
Leonardo Solis's avatar
Leonardo Solis committed
674
			if(!valid) {
lvs's avatar
lvs committed
675
*/
Leonardo Solis's avatar
Leonardo Solis committed
676
			if(valid != 0) {
lvs's avatar
lvs committed
677
				success = write_pipe(chan_PRNG2GA_LS5_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
678
679
680
681
682
			}
			#endif
		}
	} // End of while(active)
}
683

lvs's avatar
lvs committed
684
/*
685
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
686
687
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
688
689
690
691
692
void Krnl_Prng_LS6_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
693
694
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
695
696
697
698
699
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
700
701

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
702
/*
703
	bool valid = false;
lvs's avatar
lvs committed
704
705
*/
	int valid = 1;
706

lvs's avatar
lvs committed
707
/*
708
	while(!valid) {
lvs's avatar
lvs committed
709
*/
710
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
711
	LOOP_WHILE_PRNG_LS6_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
712
	while(valid != 0) {
713
/*
714
		bool active = true;
715
716
*/
		int active;
lvs's avatar
lvs committed
717
		valid  = read_pipe(chan_Arbiter_LS6_float_off, &active);
718
	
719
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
720
		LOOP_FOR_PRNG_LS6_FLOAT:
721
722
723
724
725
726
727
		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
728
/*
729
			bool success = false;
lvs's avatar
lvs committed
730
731
*/
			int success = 1;
732
733
734

			#if defined (FIXED_POINT_LS6)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
735
/*
736
			if(!valid) {
lvs's avatar
lvs committed
737
*/
Leonardo Solis's avatar
Leonardo Solis committed
738
			if(valid != 0) {
lvs's avatar
lvs committed
739
				success = write_pipe(chan_PRNG2GA_LS6_float_prng, (float*) &fixpt_tmp);
740
741
			}
			#else
lvs's avatar
lvs committed
742
/*
743
			if(!valid) {
lvs's avatar
lvs committed
744
*/
Leonardo Solis's avatar
Leonardo Solis committed
745
			if(valid != 0) {
lvs's avatar
lvs committed
746
				success = write_pipe(chan_PRNG2GA_LS6_float_prng, &tmp);
747
748
749
750
751
752
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
753
/*
754
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
755
756
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
757
758
759
760
761
void Krnl_Prng_LS7_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
762
763
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
764
765
766
767
768
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
769
770

	uint lfsr = Host_seed;
lvs's avatar
lvs committed
771
/*
772
	bool valid = false;
lvs's avatar
lvs committed
773
774
*/
	int valid = 1;
775

lvs's avatar
lvs committed
776
/*
777
	while(!valid) {
lvs's avatar
lvs committed
778
*/
779
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
780
	LOOP_WHILE_PRNG_LS7_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
781
	while(valid != 0) {
782
/*
783
		bool active = true;
784
785
*/
		int active;
lvs's avatar
lvs committed
786
		valid  = read_pipe(chan_Arbiter_LS7_float_off, &active);
787
	
788
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
789
		LOOP_FOR_PRNG_LS7_FLOAT:
790
791
792
793
794
795
796
		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
797
/*
798
			bool success = false;
lvs's avatar
lvs committed
799
800
*/
			int success = 1;
801
802
803

			#if defined (FIXED_POINT_LS7)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
lvs's avatar
lvs committed
804
/*
805
			if(!valid) {
lvs's avatar
lvs committed
806
*/
Leonardo Solis's avatar
Leonardo Solis committed
807
			if(valid != 0) {
lvs's avatar
lvs committed
808
				success = write_pipe(chan_PRNG2GA_LS7_float_prng, (float*