Krnl_PRNG.cl 20.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
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
	uint2 lfsr;
	lfsr.x = Host_seed1;
	lfsr.y = Host_seed2;
25
26

	nb_pipe_status valid = PIPE_STATUS_FAILURE;
27
	
28
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
29
	LOOP_WHILE_PRNG_BT_USHORT_FLOAT:
30
	while(valid != PIPE_STATUS_SUCCESS) {	
31
/*
32
		bool active = true;
33
34
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
35
		valid = read_pipe(chan_GA2PRNG_BT_ushort_float_off, &active);
36
37
38
39

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

Leonardo Solis's avatar
Leonardo Solis committed
40
		__attribute__((opencl_unroll_hint))
Leonardo Solis's avatar
Leonardo Solis committed
41
		LOOP_FOR_PRNG_BT_USHORT_FLOAT:
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
		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;
		}
57
58
59
60

		nb_pipe_status success = PIPE_STATUS_FAILURE;

		if(valid != PIPE_STATUS_SUCCESS) {
61
62
63
64
65
66
67
68
69
70
71
			// 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
72

lvs's avatar
lvs committed
73
			success = write_pipe(chan_PRNG2GA_BT_ushort_float_prng, &tmp);
74
		}
75
	} // End of while(valid != PIPE_STATUS_SUCCESS)
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
85
86
87
88
void Krnl_Prng_GG_uchar(
			unsigned int  Host_seed, 
		        unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
89
90
			// IMPORTANT: enable this dummy global argument only for "hw" build.
			// Check ../common_xilinx/utility/boards.mk
91
92
93
94
95
		        // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
			,
			__global int *dummy
#endif
){
96
	uint lfsr = Host_seed;
Leonardo Solis's avatar
Leonardo Solis committed
97

98
99
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

100
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
101
	LOOP_WHILE_PRNG_GG_UCHAR:
102
	while(valid != PIPE_STATUS_SUCCESS) {
103
/*
104
		bool active = true;
105
106
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
107
		valid = read_pipe(chan_GA2PRNG_GG_uchar_off, &active);		
lvs's avatar
lvs committed
108

109
		uchar tmp[2];
110

Leonardo Solis's avatar
Leonardo Solis committed
111
		__attribute__((opencl_unroll_hint))
Leonardo Solis's avatar
Leonardo Solis committed
112
		LOOP_FOR_PRNG_GG_UCHAR:
113
		for(uchar i=0; i<2; i++) {
114
115
116
117
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
118
			tmp[i] = (lfsr/MAX_UINT)*DockConst_num_of_genes;
119

120
		}
121
122

		nb_pipe_status success = PIPE_STATUS_FAILURE;
lvs's avatar
lvs committed
123

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

128
		if(valid != PIPE_STATUS_SUCCESS) {
lvs's avatar
lvs committed
129
			success = write_pipe(chan_PRNG2GA_GG_uchar_prng, &utmp);
Leonardo Solis's avatar
Leonardo Solis committed
130
		}
131
	} // while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
132
}
Leonardo Solis's avatar
Leonardo Solis committed
133

lvs's avatar
lvs committed
134
/*
Leonardo Solis's avatar
Leonardo Solis committed
135
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
136
137
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
138
139
140
141
142
void Krnl_Prng_GG_float(
			unsigned int  Host_seed,
		        unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
143
144
			// IMPORTANT: enable this dummy global argument only for "hw" build.
			// Check ../common_xilinx/utility/boards.mk
145
146
147
148
149
		        // 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
150
151
	uint lfsr = Host_seed;

152
153
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

154
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
155
	LOOP_WHILE_PRNG_GG_FLOAT:
156
	while(valid != PIPE_STATUS_SUCCESS) {
157
/*
Leonardo Solis's avatar
Leonardo Solis committed
158
		bool active = true;
159
160
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
161
		valid = read_pipe(chan_GA2PRNG_GG_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
162

163
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
164
		LOOP_FOR_PRNG_GG_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
165
166
167
168
169
170
171
172
		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;

173
174
175
			nb_pipe_status success = PIPE_STATUS_FAILURE;

			if(valid != PIPE_STATUS_SUCCESS) {
lvs's avatar
lvs committed
176
				success = write_pipe(chan_PRNG2GA_GG_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
177
178
			}
		}
179
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
180
}
Leonardo Solis's avatar
Leonardo Solis committed
181
182
183

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

#if !defined(SW_EMU)
201
202
			    // IMPORTANT: enable this dummy global argument only for "hw" build.
			    // Check ../common_xilinx/utility/boards.mk
203
204
205
206
207
		            // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
			    ,
			    __global int *dummy
#endif
){
208
	uint lfsr[9];
Leonardo Solis's avatar
Leonardo Solis committed
209
210
211
212
213
	lfsr[0] = Host_seed1;
	lfsr[1] = Host_seed2;
	lfsr[2] = Host_seed3;
	lfsr[3] = Host_seed4;
	lfsr[4] = Host_seed5;
214
215
216
217
	lfsr[5] = Host_seed6;
	lfsr[6] = Host_seed7;
	lfsr[7] = Host_seed8;
	lfsr[8] = Host_seed9;
Leonardo Solis's avatar
Leonardo Solis committed
218

219
	nb_pipe_status valid = PIPE_STATUS_FAILURE;
Leonardo Solis's avatar
Leonardo Solis committed
220

221
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
222
	LOOP_WHILE_PRNG_LS123_USHORT:
223
	while(valid != PIPE_STATUS_SUCCESS) {
224
/*
Leonardo Solis's avatar
Leonardo Solis committed
225
		bool active = true;
226
227
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
228
		valid  = read_pipe(chan_GA2PRNG_LS123_ushort_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
229

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

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

263
		nb_pipe_status success = PIPE_STATUS_FAILURE;
lvs's avatar
lvs committed
264

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

276
		if(valid != PIPE_STATUS_SUCCESS) {
lvs's avatar
lvs committed
277
			success = write_pipe(chan_PRNG2GA_LS123_ushort_prng, &tmp123);
Leonardo Solis's avatar
Leonardo Solis committed
278
279
		}

280
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
281
}
282
283
284

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

#if !defined(SW_EMU)
294
295
			// IMPORTANT: enable this dummy global argument only for "hw" build.
			// Check ../common_xilinx/utility/boards.mk
296
297
298
299
300
 		        // 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
301
302
	uint lfsr = Host_seed;

303
304
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

305
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
306
	LOOP_WHILE_PRNG_LS_FLOAT:
307
	while(valid != PIPE_STATUS_SUCCESS) {
308
/*
Leonardo Solis's avatar
Leonardo Solis committed
309
		bool active = true;
310
311
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
312
		valid  = read_pipe(chan_GA2PRNG_LS_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
313
	
314
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
315
		LOOP_FOR_PRNG_LS_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
316
317
318
319
320
321
322
		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;
323
324

			nb_pipe_status success = PIPE_STATUS_FAILURE;
Leonardo Solis's avatar
Leonardo Solis committed
325
326
327

			#if defined (FIXED_POINT_LS1)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
328
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
329
				success = write_pipe(chan_PRNG2LS_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
330
331
			}
			#else
332
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
333
				success = write_pipe(chan_PRNG2LS_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
334
			}
Leonardo Solis's avatar
Leonardo Solis committed
335
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
336
		}
337
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
338
}
Leonardo Solis's avatar
Leonardo Solis committed
339

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

#if !defined(SW_EMU)
349
350
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
351
352
353
354
355
 		         // 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
356
357
	uint lfsr = Host_seed;

358
359
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

360
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
361
	LOOP_WHILE_PRNG_LS2_FLOAT:
362
	while(valid != PIPE_STATUS_SUCCESS) {
363
/*
Leonardo Solis's avatar
Leonardo Solis committed
364
		bool active = true;
365
366
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
367
		valid  = read_pipe(chan_GA2PRNG_LS2_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
368
	
369
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
370
		LOOP_FOR_PRNG_LS2_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
371
372
373
374
375
376
377
		for(uchar i=0; i<DockConst_num_of_genes; i++) {
			float tmp;
			uchar lsb;
			lsb = lfsr & 0x01u;
			lfsr >>= 1;
			lfsr ^= (-lsb) & 0xA3000000u;
			tmp = (0.999999f/MAX_UINT)*lfsr;
378
379

			nb_pipe_status success = PIPE_STATUS_FAILURE;
Leonardo Solis's avatar
Leonardo Solis committed
380
381
382

			#if defined (FIXED_POINT_LS2)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
383
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
384
				success = write_pipe(chan_PRNG2LS2_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
385
386
			}
			#else
387
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
388
				success = write_pipe(chan_PRNG2LS2_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
389
			}
Leonardo Solis's avatar
Leonardo Solis committed
390
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
391
		}
392
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
393
}
Leonardo Solis's avatar
Leonardo Solis committed
394

lvs's avatar
lvs committed
395
/*
Leonardo Solis's avatar
Leonardo Solis committed
396
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
397
398
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
399
400
401
402
403
void Krnl_Prng_LS3_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
404
405
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
406
407
408
409
410
 		         // 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
411
412
	uint lfsr = Host_seed;

413
414
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

415
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
416
	LOOP_WHILE_PRNG_LS3_FLOAT:
417
	while(valid != PIPE_STATUS_SUCCESS) {
418
/*
Leonardo Solis's avatar
Leonardo Solis committed
419
		bool active = true;
420
421
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
422
		valid  = read_pipe(chan_GA2PRNG_LS3_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
423
	
424
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
425
		LOOP_FOR_PRNG_LS3_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
426
427
428
429
430
431
432
		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;
433
434

			nb_pipe_status success = PIPE_STATUS_FAILURE;
Leonardo Solis's avatar
Leonardo Solis committed
435
436
437

			#if defined (FIXED_POINT_LS3)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
438
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
439
				success = write_pipe(chan_PRNG2LS3_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
440
441
442
			}

			#else
443
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
444
				success = write_pipe(chan_PRNG2LS3_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
445
			}
Leonardo Solis's avatar
Leonardo Solis committed
446
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
447
		}
448
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
449
}
Leonardo Solis's avatar
Leonardo Solis committed
450

lvs's avatar
lvs committed
451
/*
Leonardo Solis's avatar
Leonardo Solis committed
452
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
453
454
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
455
456
457
458
459
void Krnl_Prng_LS4_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
460
461
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
462
463
464
465
466
 		         // 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
467
468
	uint lfsr = Host_seed;

469
470
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

471
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
472
	LOOP_WHILE_PRNG_LS4_FLOAT:
473
	while(valid != PIPE_STATUS_SUCCESS) {
474
/*
Leonardo Solis's avatar
Leonardo Solis committed
475
		bool active = true;
476
477
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
478
		valid  = read_pipe(chan_GA2PRNG_LS4_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
479
	
480
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
481
		LOOP_FOR_PRNG_LS4_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
482
483
484
485
486
487
488
		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;
489
490

			nb_pipe_status success = PIPE_STATUS_FAILURE;
Leonardo Solis's avatar
Leonardo Solis committed
491

492
			#if defined (FIXED_POINT_LS4)
Leonardo Solis's avatar
Leonardo Solis committed
493
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
494
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
495
				success = write_pipe(chan_PRNG2LS4_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
496
497
			}
			#else
498
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
499
				success = write_pipe(chan_PRNG2LS4_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
500
501
502
			}
			#endif
		}
503
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
504
505
}

lvs's avatar
lvs committed
506
/*
Leonardo Solis's avatar
Leonardo Solis committed
507
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
508
509
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
510
511
512
513
514
void Krnl_Prng_LS5_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
515
516
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
517
518
519
520
521
 		         // 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
522
523
	uint lfsr = Host_seed;

524
525
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

526
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
527
	LOOP_WHILE_PRNG_LS5_FLOAT:
528
	while(valid != PIPE_STATUS_SUCCESS) {
529
/*
Leonardo Solis's avatar
Leonardo Solis committed
530
		bool active = true;
531
532
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
533
		valid  = read_pipe(chan_GA2PRNG_LS5_float_off, &active);
Leonardo Solis's avatar
Leonardo Solis committed
534
	
535
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
536
		LOOP_FOR_PRNG_LS5_FLOAT:
Leonardo Solis's avatar
Leonardo Solis committed
537
538
539
540
541
542
543
		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;
544
545

			nb_pipe_status success = PIPE_STATUS_FAILURE;
Leonardo Solis's avatar
Leonardo Solis committed
546

547
			#if defined (FIXED_POINT_LS5)
Leonardo Solis's avatar
Leonardo Solis committed
548
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
549
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
550
				success = write_pipe(chan_PRNG2LS5_float_prng, (float*) &fixpt_tmp);
Leonardo Solis's avatar
Leonardo Solis committed
551
552
			}
			#else
553
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
554
				success = write_pipe(chan_PRNG2LS5_float_prng, &tmp);
Leonardo Solis's avatar
Leonardo Solis committed
555
556
557
			}
			#endif
		}
558
	} // End of while(valid != PIPE_STATUS_SUCCESS)
Leonardo Solis's avatar
Leonardo Solis committed
559
}
560

lvs's avatar
lvs committed
561
/*
562
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
563
564
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
565
566
567
568
569
void Krnl_Prng_LS6_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
570
571
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
572
573
574
575
576
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
577
578
	uint lfsr = Host_seed;

579
580
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

581
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
582
	LOOP_WHILE_PRNG_LS6_FLOAT:
583
	while(valid != PIPE_STATUS_SUCCESS) {
584
/*
585
		bool active = true;
586
587
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
588
		valid  = read_pipe(chan_GA2PRNG_LS6_float_off, &active);
589
	
590
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
591
		LOOP_FOR_PRNG_LS6_FLOAT:
592
593
594
595
596
597
598
		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;
599
600

			nb_pipe_status success = PIPE_STATUS_FAILURE;
601
602
603

			#if defined (FIXED_POINT_LS6)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
604
605

			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
606
				success = write_pipe(chan_PRNG2LS6_float_prng, (float*) &fixpt_tmp);
607
608
			}
			#else
609
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
610
				success = write_pipe(chan_PRNG2LS6_float_prng, &tmp);
611
612
613
614
615
616
			}
			#endif
		}
	} // End of while(active)
}

lvs's avatar
lvs committed
617
/*
618
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
619
620
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
621
622
623
624
625
void Krnl_Prng_LS7_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
626
627
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
628
629
630
631
632
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
633
634
	uint lfsr = Host_seed;

635
636
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

637
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
638
	LOOP_WHILE_PRNG_LS7_FLOAT:
639
	while(valid != PIPE_STATUS_SUCCESS) {
640
/*
641
		bool active = true;
642
643
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
644
		valid  = read_pipe(chan_GA2PRNG_LS7_float_off, &active);
645
	
646
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
647
		LOOP_FOR_PRNG_LS7_FLOAT:
648
649
650
651
652
653
654
		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;
655
656

			nb_pipe_status success = PIPE_STATUS_FAILURE;
657
658
659

			#if defined (FIXED_POINT_LS7)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
660
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
661
				success = write_pipe(chan_PRNG2LS7_float_prng, (float*) &fixpt_tmp);
662
663
			}
			#else
664
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
665
				success = write_pipe(chan_PRNG2LS7_float_prng, &tmp);
666
667
668
			}
			#endif
		}
669
	} // End of while(valid != PIPE_STATUS_SUCCESS)
670
671
}

lvs's avatar
lvs committed
672
/*
673
__kernel __attribute__ ((max_global_work_dim(0)))
lvs's avatar
lvs committed
674
675
*/
__kernel __attribute__ ((reqd_work_group_size(1,1,1)))
676
677
678
679
680
void Krnl_Prng_LS8_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
681
682
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
683
684
685
686
687
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
688
689
	uint lfsr = Host_seed;

690
691
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

692
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
693
	LOOP_WHILE_PRNG_LS8_FLOAT:
694
	while(valid != PIPE_STATUS_SUCCESS) {
695
/*
696
		bool active = true;
697
698
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
699
		valid  = read_pipe(chan_GA2PRNG_LS8_float_off, &active);
700
	
701
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
702
		LOOP_FOR_PRNG_LS8_FLOAT:
703
704
705
706
707
708
709
		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;
710
711

			nb_pipe_status success = PIPE_STATUS_FAILURE;
712
713
714

			#if defined (FIXED_POINT_LS8)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
715
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
716
				success = write_pipe(chan_PRNG2LS8_float_prng, (float*) &fixpt_tmp);
717
718
			}
			#else
719
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
720
				success = write_pipe(chan_PRNG2LS8_float_prng, &tmp);
721
722
723
			}
			#endif
		}
724
	} // End of while(valid != PIPE_STATUS_SUCCESS)
725
726
}

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
735
void Krnl_Prng_LS9_float(
			 unsigned int  Host_seed,
			 unsigned char DockConst_num_of_genes

#if !defined(SW_EMU)
736
737
			 // IMPORTANT: enable this dummy global argument only for "hw" build.
			 // Check ../common_xilinx/utility/boards.mk
738
739
740
741
742
 		         // https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
		         , 
         		 __global int *dummy
#endif
){
743
744
	uint lfsr = Host_seed;

745
746
	nb_pipe_status valid = PIPE_STATUS_FAILURE;

747
	__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
748
	LOOP_WHILE_PRNG_LS9_FLOAT:
749
	while(valid != PIPE_STATUS_SUCCESS) {
750
/*
751
		bool active = true;
752
753
*/
		int active;
Leonardo Solis's avatar
Leonardo Solis committed
754
		valid  = read_pipe(chan_GA2PRNG_LS9_float_off, &active);
755
	
756
		__attribute__((xcl_pipeline_loop))
Leonardo Solis's avatar
Leonardo Solis committed
757
		LOOP_FOR_PRNG_LS9_FLOAT:
758
759
760
761
762
763
764
		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;
765
766

			nb_pipe_status success = PIPE_STATUS_FAILURE;
767
768
769

			#if defined (FIXED_POINT_LS9)
			fixedpt fixpt_tmp = fixedpt_fromfloat(tmp);
770
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
771
				success = write_pipe(chan_PRNG2LS9_float_prng, (float*) &fixpt_tmp);
772
773
			}
			#else
774
			if(valid != PIPE_STATUS_SUCCESS) {
Leonardo Solis's avatar
Leonardo Solis committed
775
				success = write_pipe(chan_PRNG2LS9_float_prng, &tmp);
776
777
778
			}
			#endif
		}
779
	} // End of while(valid != PIPE_STATUS_SUCCESS)
780
}
Leonardo Solis's avatar
Leonardo Solis committed
781
782
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------