performdocking.cpp 110 KB
Newer Older
lvs's avatar
lvs committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * (C) 2013. Evopro Innovation Kft.
 *
 * performdocking.cu
 *
 * Created on: 2010.04.20.
 * Author: pechan.imre
 */

//// ------------------------
//// Correct time measurement
//// Moved from main.cpp to performdocking.cpp
//// to skip measuring build time
//#include <sys/time.h>
//// ------------------------
#include "performdocking.h"

//// --------------------------------
//// Altera OpenCL Helper Variables
//// --------------------------------
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cstring>
#include "CL/opencl.h"
#include "AOCLUtils/aocl_utils.h"

using namespace aocl_utils;

#define STRING_BUFFER_LEN 1024

// OpenCL runtime configuration
static cl_platform_id   platform      = NULL;
static cl_device_id     device        = NULL;
Leonardo Solis's avatar
Leonardo Solis committed
36
37
static cl_context       context       = NULL;

38
#if 0
Leonardo Solis's avatar
Leonardo Solis committed
39
40
// Unique command queue
static cl_command_queue command_queue = NULL;
41
#endif
lvs's avatar
lvs committed
42
43

// Kernel name, as defined in the CL file
44
45
#ifdef ENABLE_KERNEL1
static cl_command_queue command_queue1 = NULL;
lvs's avatar
lvs committed
46
47
48
49
static cl_kernel kernel1  = NULL;
static const char *name_k1 = "Krnl_GA";
#endif

50
51
#ifdef ENABLE_KERNEL2
static cl_command_queue command_queue2 = NULL;
lvs's avatar
lvs committed
52
53
54
55
static cl_kernel kernel2  = NULL;
static const char *name_k2 = "Krnl_Conform";
#endif

56
57
#ifdef ENABLE_KERNEL3
static cl_command_queue command_queue3 = NULL;
lvs's avatar
lvs committed
58
59
60
61
static cl_kernel kernel3  = NULL;
static const char *name_k3 = "Krnl_InterE";
#endif

62
63
#ifdef ENABLE_KERNEL4
static cl_command_queue command_queue4 = NULL;
lvs's avatar
lvs committed
64
65
66
67
static cl_kernel kernel4  = NULL;
static const char *name_k4 = "Krnl_IntraE";
#endif

68
69
#ifdef ENABLE_KERNEL10
static cl_command_queue command_queue10 = NULL;
lvs's avatar
lvs committed
70
71
72
73
static cl_kernel kernel10  = NULL;
static const char *name_k10 = "Krnl_Prng_GG_uchar";
#endif

74
75
#ifdef ENABLE_KERNEL6
static cl_command_queue command_queue6 = NULL;
lvs's avatar
lvs committed
76
77
78
static cl_kernel kernel6  = NULL;
static const char *name_k6 = "Krnl_Prng_GG_float";
#endif
lvs's avatar
lvs committed
79

80
81
#ifdef ENABLE_KERNEL7
static cl_command_queue command_queue7 = NULL;
lvs's avatar
lvs committed
82
83
84
static cl_kernel kernel7  = NULL;
static const char *name_k7 = "Krnl_Prng_LS_float";
#endif
lvs's avatar
lvs committed
85

86
87
#ifdef ENABLE_KERNEL12
static cl_command_queue command_queue12 = NULL;
lvs's avatar
lvs committed
88
89
90
static cl_kernel kernel12  = NULL;
static const char *name_k12 = "Krnl_LS";
#endif
lvs's avatar
lvs committed
91

92
93
#ifdef ENABLE_KERNEL14
static cl_command_queue command_queue14 = NULL;
lvs's avatar
lvs committed
94
95
96
97
static cl_kernel kernel14  = NULL;
static const char *name_k14 = "Krnl_Prng_LS2_float";
#endif

98
99
#ifdef ENABLE_KERNEL15
static cl_command_queue command_queue15 = NULL;
lvs's avatar
lvs committed
100
101
102
static cl_kernel kernel15  = NULL;
static const char *name_k15 = "Krnl_LS2";
#endif
lvs's avatar
lvs committed
103

104
105
#ifdef ENABLE_KERNEL20
static cl_command_queue command_queue20 = NULL;
lvs's avatar
lvs committed
106
107
108
109
static cl_kernel kernel20  = NULL;
static const char *name_k20 = "Krnl_Prng_LS3_float";
#endif

110
111
#ifdef ENABLE_KERNEL21
static cl_command_queue command_queue21 = NULL;
lvs's avatar
lvs committed
112
113
114
static cl_kernel kernel21  = NULL;
static const char *name_k21 = "Krnl_LS3";
#endif
lvs's avatar
lvs committed
115

lvs's avatar
lvs committed
116
#if 0
117
118
#ifdef ENABLE_KERNEL22
static cl_command_queue command_queue22 = NULL;
lvs's avatar
lvs committed
119
120
121
static cl_kernel kernel22  = NULL;
static const char *name_k22 = "Krnl_LS3_Arbiter";
#endif
lvs's avatar
lvs committed
122
123
#endif

lvs's avatar
lvs committed
124
#if 0
125
126
#ifdef ENABLE_KERNEL23
static cl_command_queue command_queue23 = NULL;
lvs's avatar
lvs committed
127
128
129
static cl_kernel kernel23  = NULL;
static const char *name_k23 = "Krnl_Conf_Arbiter";
#endif
lvs's avatar
lvs committed
130
131
#endif

lvs's avatar
lvs committed
132
#if 0
133
134
#ifdef ENABLE_KERNEL24
static cl_command_queue command_queue24 = NULL;
lvs's avatar
lvs committed
135
136
137
static cl_kernel kernel24  = NULL;
static const char *name_k24 = "Krnl_Conf_Arbiter2";
#endif
lvs's avatar
lvs committed
138
139
#endif

lvs's avatar
lvs committed
140
#if 0
141
142
#ifdef ENABLE_KERNEL25
static cl_command_queue command_queue25 = NULL;
lvs's avatar
lvs committed
143
144
145
static cl_kernel kernel25  = NULL;
static const char *name_k25 = "Krnl_Prng_LS2_ushort";
#endif
lvs's avatar
lvs committed
146
147
#endif

lvs's avatar
lvs committed
148
#if 0
149
150
#ifdef ENABLE_KERNEL26
static cl_command_queue command_queue26 = NULL;
lvs's avatar
lvs committed
151
152
static cl_kernel kernel26  = NULL;
static const char *name_k26 = "Krnl_Prng_LS3_ushort";
lvs's avatar
lvs committed
153
#endif
lvs's avatar
lvs committed
154
155
#endif

156
157
#ifdef ENABLE_KERNEL27
static cl_command_queue command_queue27 = NULL;
lvs's avatar
lvs committed
158
159
160
static cl_kernel kernel27  = NULL;
static const char *name_k27 = "Krnl_IGL_Arbiter";
#endif
lvs's avatar
lvs committed
161

lvs's avatar
lvs committed
162
#if 0
163
164
#ifdef ENABLE_KERNEL28
static cl_command_queue command_queue28 = NULL;
lvs's avatar
lvs committed
165
166
167
static cl_kernel kernel28  = NULL;
static const char *name_k28 = "Krnl_IA_pipeline_Arbiter";
#endif
lvs's avatar
lvs committed
168
169
#endif

lvs's avatar
lvs committed
170
#if 0
171
172
#ifdef ENABLE_KERNEL29
static cl_command_queue command_queue29 = NULL;
lvs's avatar
lvs committed
173
174
175
static cl_kernel kernel29  = NULL;
static const char *name_k29 = "Krnl_IA_pipeline";
#endif
lvs's avatar
lvs committed
176
177
#endif

lvs's avatar
lvs committed
178
#if 0
179
180
#ifdef ENABLE_KERNEL30
static cl_command_queue command_queue30 = NULL;
lvs's avatar
lvs committed
181
182
183
static cl_kernel kernel30  = NULL;
static const char *name_k30 = "Krnl_IA_pipeline2";
#endif
lvs's avatar
lvs committed
184
185
#endif

lvs's avatar
lvs committed
186
187
188
189
190
191
#if 0
#ifdef ENABLE_KERNEL31
static cl_command_queue command_queue31 = NULL;
static cl_kernel kernel31  = NULL;
static const char *name_k31 = "Krnl_Prng_BT_Arbiter";
#endif
lvs's avatar
lvs committed
192
193
#endif

lvs's avatar
lvs committed
194
#if 0
195
196
#ifdef ENABLE_KERNEL32
static cl_command_queue command_queue32 = NULL;
lvs's avatar
lvs committed
197
198
199
static cl_kernel kernel32  = NULL;
static const char *name_k32 = "Krnl_Prng_GG_Arbiter";
#endif
lvs's avatar
lvs committed
200
201
#endif

lvs's avatar
lvs committed
202
#if 0
203
204
#ifdef ENABLE_KERNEL33
static cl_command_queue command_queue33 = NULL;
lvs's avatar
lvs committed
205
206
207
static cl_kernel kernel33  = NULL;
static const char *name_k33 = "Krnl_Prng_LS_ushort_Arbiter";
#endif
lvs's avatar
lvs committed
208
209
#endif

lvs's avatar
lvs committed
210
#if 0
211
212
#ifdef ENABLE_KERNEL34
static cl_command_queue command_queue34 = NULL;
lvs's avatar
lvs committed
213
214
static cl_kernel kernel34  = NULL;
static const char *name_k34 = "Krnl_Prng_LS_float_Arbiter";
lvs's avatar
lvs committed
215
216
217
#endif
#endif

218
219
#ifdef ENABLE_KERNEL35
static cl_command_queue command_queue35 = NULL;
lvs's avatar
lvs committed
220
221
static cl_kernel kernel35  = NULL;
static const char *name_k35 = "Krnl_Prng_LS123_ushort";
lvs's avatar
lvs committed
222
223
#endif

224
225
#ifdef ENABLE_KERNEL36
static cl_command_queue command_queue36 = NULL;
lvs's avatar
lvs committed
226
227
static cl_kernel kernel36  = NULL;
static const char *name_k36 = "Krnl_Prng_BT_ushort_float";
lvs's avatar
lvs committed
228
229
230
231
232
233
234
#endif






235
236
#ifdef ENABLE_KERNEL37
static cl_command_queue command_queue37 = NULL;
lvs's avatar
lvs committed
237
238
static cl_kernel kernel37  = NULL;
static const char *name_k37 = "Krnl_Prng_LS4_float";
lvs's avatar
lvs committed
239
240
#endif

241
242
#ifdef ENABLE_KERNEL38
static cl_command_queue command_queue38 = NULL;
lvs's avatar
lvs committed
243
244
245
static cl_kernel kernel38  = NULL;
static const char *name_k38 = "Krnl_Prng_LS5_float";
#endif
lvs's avatar
lvs committed
246

247
248
#ifdef ENABLE_KERNEL39
static cl_command_queue command_queue39 = NULL;
lvs's avatar
lvs committed
249
250
static cl_kernel kernel39  = NULL;
static const char *name_k39 = "Krnl_LS4";
lvs's avatar
lvs committed
251
252
#endif

253
254
#ifdef ENABLE_KERNEL40
static cl_command_queue command_queue40 = NULL;
lvs's avatar
lvs committed
255
256
static cl_kernel kernel40  = NULL;
static const char *name_k40 = "Krnl_LS5";
lvs's avatar
lvs committed
257
258
259
260
261
262
263
#endif






264
265
#ifdef ENABLE_KERNEL41
static cl_command_queue command_queue41 = NULL;
lvs's avatar
lvs committed
266
267
static cl_kernel kernel41  = NULL;
static const char *name_k41 = "Krnl_Prng_LS6_float";
lvs's avatar
lvs committed
268
269
#endif

270
271
#ifdef ENABLE_KERNEL42
static cl_command_queue command_queue42 = NULL;
lvs's avatar
lvs committed
272
273
static cl_kernel kernel42  = NULL;
static const char *name_k42 = "Krnl_Prng_LS7_float";
lvs's avatar
lvs committed
274
275
#endif

276
277
#ifdef ENABLE_KERNEL43
static cl_command_queue command_queue43 = NULL;
lvs's avatar
lvs committed
278
279
static cl_kernel kernel43  = NULL;
static const char *name_k43 = "Krnl_Prng_LS8_float";
lvs's avatar
lvs committed
280
281
#endif

282
283
#ifdef ENABLE_KERNEL44
static cl_command_queue command_queue44 = NULL;
lvs's avatar
lvs committed
284
285
static cl_kernel kernel44  = NULL;
static const char *name_k44 = "Krnl_Prng_LS9_float";
lvs's avatar
lvs committed
286
287
288
289
#endif



290
291
#ifdef ENABLE_KERNEL45
static cl_command_queue command_queue45 = NULL;
lvs's avatar
lvs committed
292
293
static cl_kernel kernel45  = NULL;
static const char *name_k45 = "Krnl_LS6";
lvs's avatar
lvs committed
294
295
#endif

296
297
#ifdef ENABLE_KERNEL46
static cl_command_queue command_queue46 = NULL;
lvs's avatar
lvs committed
298
299
static cl_kernel kernel46  = NULL;
static const char *name_k46 = "Krnl_LS7";
lvs's avatar
lvs committed
300
301
#endif

302
303
#ifdef ENABLE_KERNEL47
static cl_command_queue command_queue47 = NULL;
lvs's avatar
lvs committed
304
305
static cl_kernel kernel47  = NULL;
static const char *name_k47 = "Krnl_LS8";
lvs's avatar
lvs committed
306
307
#endif

308
309
#ifdef ENABLE_KERNEL48
static cl_command_queue command_queue48 = NULL;
lvs's avatar
lvs committed
310
311
static cl_kernel kernel48  = NULL;
static const char *name_k48 = "Krnl_LS9";
lvs's avatar
lvs committed
312
313
314
315
#endif



lvs's avatar
lvs committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

static cl_program program = NULL;

// Function prototypes
bool init();
void cleanup();
static void device_info_ulong( cl_device_id device, cl_device_info param, const char* name);
static void device_info_uint ( cl_device_id device, cl_device_info param, const char* name);
static void device_info_bool ( cl_device_id device, cl_device_info param, const char* name);
static void device_info_string( cl_device_id device, cl_device_info param, const char* name);
static void display_device_info( cl_device_id device );





//// --------------------------------
//// Host constant struct
//// --------------------------------
Dockparameters dockpars;
kernelconstant_static  KerConstStatic;
#if defined(SINGLE_COPY_POP_ENE)

#else
kernelconstant_dynamic KerConstDynamic;
#endif

//// --------------------------------
//// Host memory buffers
//// --------------------------------
float* cpu_init_populations;
float* cpu_final_populations;
float* cpu_energies;
Ligandresult* cpu_result_ligands;
unsigned int* cpu_prng_seeds;
#if defined(SINGLE_COPY_POP_ENE)
int *cpu_evals_of_runs;
int *cpu_gens_of_runs;
#endif
float* cpu_ref_ori_angles;

//// --------------------------------
//// Device memory buffers
//// --------------------------------
// Altera Issue
// Constant data holding struct data
// Created because structs containing array
// are not supported as OpenCL kernel args

#if defined (FIXED_POINT_INTERE)
cl_mem mem_KerConstStatic_fixpt64_atom_charges_const;
#endif
368
369
370
371
372
373
cl_mem mem_KerConstStatic_InterE_atom_charges_const;
cl_mem mem_KerConstStatic_InterE_atom_types_const;

cl_mem mem_KerConstStatic_IntraE_atom_charges_const;
cl_mem mem_KerConstStatic_IntraE_atom_types_const;

Leonardo Solis's avatar
Leonardo Solis committed
374
375
376
377
378
379
380
cl_mem mem_KerConstStatic_intraE_contributors_const;

cl_mem mem_KerConstStatic_reqm_const;
cl_mem mem_KerConstStatic_reqm_hbond_const;
cl_mem mem_KerConstStatic_atom1_types_reqm_const;
cl_mem mem_KerConstStatic_atom2_types_reqm_const;

lvs's avatar
lvs committed
381
382
383
384
385
386
387
cl_mem mem_KerConstStatic_VWpars_AC_const;
cl_mem mem_KerConstStatic_VWpars_BD_const;
cl_mem mem_KerConstStatic_dspars_S_const;
cl_mem mem_KerConstStatic_dspars_V_const;
cl_mem mem_KerConstStatic_rotlist_const;
cl_mem mem_KerConstStatic_ref_coords_const;
cl_mem mem_KerConstStatic_rotbonds_moving_vectors_const;
lvs's avatar
lvs committed
388
cl_mem mem_KerConstStatic_rotbonds_unit_vectors_const;
lvs's avatar
lvs committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
cl_mem mem_KerConstStatic_ref_orientation_quats_const;

/*								                  // Nr elements	// Nr bytes
cl_mem mem_atom_charges_const;		// float [MAX_NUM_OF_ATOMS];			// 90	 = 90	//360
cl_mem mem_atom_types_const;		// char  [MAX_NUM_OF_ATOMS];			// 90	 = 90	//360
cl_mem mem_intraE_contributors_const;	// char  [3*MAX_INTRAE_CONTRIBUTORS];		// 3*8128=28384 //24384	
cl_mem mem_VWpars_AC_const;		// float [MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES];	// 14*14 = 196  //784
cl_mem mem_VWpars_BD_const;		// float [MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES]; // 14*14 = 196	//784
cl_mem mem_dspars_S_const;		// float [MAX_NUM_OF_ATYPES];			// 14    = 14   //56
cl_mem mem_dspars_V_const;		// float [MAX_NUM_OF_ATYPES];			// 14    = 14   //56
cl_mem mem_rotlist_const;		// int   [MAX_NUM_OF_ROTATIONS];		// 4096  = 4096 //16384
cl_mem mem_ref_coords_x_const;		// float [MAX_NUM_OF_ATOMS];			// 90    = 90   //360
cl_mem mem_ref_coords_y_const;		// float [MAX_NUM_OF_ATOMS];			// 90    = 90   //360
cl_mem mem_ref_coords_z_const;		// float [MAX_NUM_OF_ATOMS];			// 90	 = 90   //360
cl_mem mem_rotbonds_moving_vectors_const;// float [3*MAX_NUM_OF_ROTBONDS];		// 3*32  = 96   //384
cl_mem mem_rotbonds_unit_vectors_const;	// float [3*MAX_NUM_OF_ROTBONDS];		// 3*32  = 96   //384
cl_mem mem_ref_orientation_quats_const;	// float [4*MAX_NUM_OF_RUNS];			// 4*100 = 400  //1600
*/

cl_mem mem_dockpars_fgrids;

#if defined(SEPARATE_FGRID_INTERE)
cl_mem mem_dockpars_fgrids2;
cl_mem mem_dockpars_fgrids3;
#endif

cl_mem mem_dockpars_conformations_current;
cl_mem mem_dockpars_energies_current;
/*
cl_mem mem_dockpars_prng_states;
*/

#if defined(SINGLE_COPY_POP_ENE)
cl_mem mem_evals_performed;
cl_mem mem_gens_performed;
#else
cl_mem mem_evals_and_generations_performed;
#endif


Leonardo Solis's avatar
Leonardo Solis committed
429
430
431
432
433
434
435

#if !defined(SW_EMU)
// IMPORTANT: enable this dummy global argument only for "hw" build.
// Check ../common_xilinx/utility/boards.mk
// https://forums.xilinx.com/t5/SDAccel/ERROR-KernelCheck-83-114-in-sdx-2017-4/td-p/818135
cl_mem mem_dummy;
#endif
lvs's avatar
lvs committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645






























//#if defined (FIXED_POINT_INTERE)
#if 0
//#include "defines_fixedpt_64.h"
fixedpt64* cpu_fixedpt64grids;

#endif



//// --------------------------------
//// Docking
//// --------------------------------
int docking_with_gpu(const Gridinfo*   mygrid,
	             /*const*/ float*  cpu_floatgrids,
                           Dockpars*   mypars,
		     const Liganddata* myligand_init,
		     const int*        argc,
		           char**      argv,
		           clock_t     clock_start_program)
/* The function performs the docking algorithm and generates the corresponding result files.
parameter mygrid:
		describes the grid
		filled with get_gridinfo()
parameter cpu_floatgrids:
		points to the memory region containing the grids
		filled with get_gridvalues_f()
parameter mypars:
		describes the docking parameters
		filled with get_commandpars()
parameter myligand_init:
		describes the ligands
		filled with get_liganddata()
parameters argc and argv:
		are the corresponding command line arguments parameter clock_start_program:
		contains the state of the clock tick counter at the beginning of the program
filled with clock() */
{
	//// ------------------------
	//// OpenCL Host Setup
        //// ------------------------
	if(!init()) {
    		return -1;
  	}
	printf("Init complete!\n"); fflush(stdout);

	Liganddata myligand_reference;
	//Dockparameters dockpars;
	

//#if defined (FIXED_POINT_INTERE)
#if 0
	size_t size_fixedpt64grids;
#else
	size_t size_floatgrids;

	#if defined(SEPARATE_FGRID_INTERE)
	size_t size_floatgrids2;
	size_t size_floatgrids3;
	#endif

#endif

	size_t size_populations;
	size_t size_energies;
	size_t size_prng_seeds;
#if defined(SINGLE_COPY_POP_ENE)
	size_t size_evals_of_runs;
#endif

	clock_t clock_start_docking;
	clock_t	clock_stop_docking;
	clock_t clock_stop_program_before_clustering;

	//allocating CPU memory for initial populations
#if defined(SINGLE_COPY_POP_ENE)
	size_populations = mypars->num_of_runs * mypars->pop_size * ACTUAL_GENOTYPE_LENGTH * sizeof(float);
#else
	//size_populations = mypars->pop_size * GENOTYPE_LENGTH_IN_GLOBMEM * sizeof(float);
	size_populations = mypars->pop_size * ACTUAL_GENOTYPE_LENGTH * sizeof(float);
#endif
        cpu_init_populations = (float*) alignedMalloc(size_populations);
	memset(cpu_init_populations, 0, size_populations);

	//allocating CPU memory for results
#if defined(SINGLE_COPY_POP_ENE)
	size_energies = mypars->num_of_runs * mypars->pop_size * sizeof(float);
#else
	size_energies = mypars->pop_size * sizeof(float);
#endif
	cpu_energies = (float*) alignedMalloc(size_energies);		
	cpu_result_ligands = (Ligandresult*) alignedMalloc(sizeof(Ligandresult)*(mypars->num_of_runs));	
	cpu_final_populations = (float*) alignedMalloc(size_populations);

	//allocating memory in CPU for reference orientation angles
#if defined(SINGLE_COPY_POP_ENE)
	cpu_ref_ori_angles = (float*) alignedMalloc(mypars->num_of_runs*3*sizeof(float));
#else
	cpu_ref_ori_angles = (float*) alignedMalloc(3*sizeof(float));
#endif

	//generating initial populations and random orientation angles of reference ligand
	//(ligand will be moved to origo and scaled as well)
	myligand_reference = *myligand_init;
	gen_initpop_and_reflig(mypars, cpu_init_populations, cpu_ref_ori_angles, &myligand_reference, mygrid);

	//allocating memory in CPU for pseudorandom number generator seeds and
	//generating them (seed for each thread during GA)
	unsigned int num_of_prng_blocks = 25;
	size_prng_seeds = num_of_prng_blocks * mypars->num_of_runs * sizeof(unsigned int);
	cpu_prng_seeds = (unsigned int*) alignedMalloc(size_prng_seeds);
	genseed(time(NULL));	//initializing seed generator

	for (unsigned int i=0; i<num_of_prng_blocks*mypars->num_of_runs; i++) {
#if defined (REPRO)
		cpu_prng_seeds[i] = 1u;
#else
		cpu_prng_seeds[i] = genseed(0u);
#endif
	}

	//srand(time(NULL));

#if defined(SINGLE_COPY_POP_ENE)
	// allocating memory in CPU for evaluation counters
	size_evals_of_runs = mypars->num_of_runs*sizeof(int);
	cpu_evals_of_runs = (int*) alignedMalloc(size_evals_of_runs);
	memset(cpu_evals_of_runs, 0, size_evals_of_runs);

	// allocating memory in CPU for generation counters
	cpu_gens_of_runs = (int*) alignedMalloc(size_evals_of_runs);
	memset(cpu_gens_of_runs, 0, size_evals_of_runs);
#endif

	//preparing the constant data fields for the GPU
	// ----------------------------------------------------------------------
	// The original function does CUDA calls initializing const Kernel data.
	// We create a struct to hold those constants
	// and return them <here> (<here> = where prepare_const_fields_for_gpu() is called),
	// so we can send them to Kernels from <here>, instead of from calcenergy.cpp as originally.
	// ----------------------------------------------------------------------
#if defined(SINGLE_COPY_POP_ENE)
	if (prepare_conststatic_fields_for_gpu(&myligand_reference, mypars, cpu_ref_ori_angles, &KerConstStatic) == 1)
#else
	if (prepare_conststatic_fields_for_gpu(&myligand_reference, mypars, &KerConstStatic) == 1)
#endif
		return 1;

	//preparing parameter struct
	dockpars.num_of_atoms  = ((unsigned char) myligand_reference.num_of_atoms);
	dockpars.num_of_atypes = ((unsigned char) myligand_reference.num_of_atypes);
	dockpars.num_of_intraE_contributors = ((unsigned int) myligand_reference.num_of_intraE_contributors);
	dockpars.gridsize_x    = ((unsigned char)  mygrid->size_xyz[0]);
	dockpars.gridsize_y    = ((unsigned char)  mygrid->size_xyz[1]);
	dockpars.gridsize_z    = ((unsigned char)  mygrid->size_xyz[2]);
	dockpars.g1	       = dockpars.gridsize_x ;
	dockpars.g2	       = dockpars.gridsize_x * dockpars.gridsize_y;
	dockpars.g3	       = dockpars.gridsize_x * dockpars.gridsize_y * dockpars.gridsize_z;
	dockpars.grid_spacing  = ((float) mygrid->spacing);
	dockpars.rotbondlist_length = ((unsigned int) NUM_OF_THREADS_PER_BLOCK*(myligand_reference.num_of_rotcyc));
	dockpars.coeff_elec    = ((float) mypars->coeffs.scaled_AD4_coeff_elec);
	dockpars.coeff_desolv  = ((float) mypars->coeffs.AD4_coeff_desolv);
	// L30nardoSV added
	dockpars.num_of_energy_evals = (unsigned int) mypars->num_of_energy_evals;
	dockpars.num_of_generations  = (unsigned int) mypars->num_of_generations;

	dockpars.pop_size      = (unsigned int) mypars->pop_size;
	dockpars.num_of_genes  = (unsigned int)(myligand_reference.num_of_rotbonds + 6);
	dockpars.tournament_rate = (mypars->tournament_rate)/100;//dockpars.tournament_rate = mypars->tournament_rate;
	dockpars.crossover_rate  = (mypars->crossover_rate)/100; //dockpars.crossover_rate  = mypars->crossover_rate;
	dockpars.mutation_rate   = (mypars->mutation_rate)/100;	 //dockpars.mutation_rate   = mypars->mutation_rate;
	dockpars.abs_max_dang    = mypars->abs_max_dang;
	dockpars.abs_max_dmov    = mypars->abs_max_dmov;
	dockpars.lsearch_rate    = mypars->lsearch_rate;
	dockpars.num_of_lsentities = (unsigned int) (mypars->lsearch_rate/100.0*mypars->pop_size + 0.5);
	dockpars.rho_lower_bound   = mypars->rho_lower_bound;
	dockpars.base_dmov_mul_sqrt3 = mypars->base_dmov_mul_sqrt3;
	dockpars.base_dang_mul_sqrt3 = mypars->base_dang_mul_sqrt3;
	dockpars.cons_limit        = (unsigned int) mypars->cons_limit;
	dockpars.max_num_of_iters  = (unsigned int) mypars->max_num_of_iters;
	dockpars.qasp = mypars->qasp;
Leonardo Solis's avatar
Leonardo Solis committed
646
	dockpars.smooth = mypars->smooth;
lvs's avatar
lvs committed
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686

/*
// passed correctly
printf("%i %i\n", dockpars.num_of_intraE_contributors, myligand_reference.num_of_intraE_contributors);
*/

	// these variables hold multiplications between kernel-constants
	// better calculate them here and then pass them to Krnl_GA
	const float two_absmaxdmov = 2.0 * dockpars.abs_max_dmov;
	const float two_absmaxdang = 2.0 * dockpars.abs_max_dang;

	// these variables hold multiplications between kernel-constants
	// better calculate them here and then pass them to Krnl_InterE and Krnl_InterE2
	#if defined(SEPARATE_FGRID_INTERE)

	#else
	const unsigned int mul_tmp2 = dockpars.num_of_atypes * dockpars.g3;
	const unsigned int mul_tmp3 = (dockpars.num_of_atypes + 1) * dockpars.g3;
	#endif

	// this variable holds a multiplication between kernel-constants
	// better calculate them it and then pass them to Krnl_IntraE and Krnl_IntraE2
	const unsigned int square_num_of_atypes = dockpars.num_of_atypes * dockpars.num_of_atypes;

	// num of rotbonds
	const unsigned char num_rotbonds = myligand_reference.num_of_rotbonds;

 	//allocating GPU memory for populations, floatgrids,
	//energies, evaluation counters and random number generator states
//#if defined (FIXED_POINT_INTERE)
#if 0
	size_fixedpt64grids = (sizeof(fixedpt64)) * (mygrid->num_of_atypes+2) * (mygrid->size_xyz[0]) * (mygrid->size_xyz[1]) * (mygrid->size_xyz[2]);
#else
	#if defined(SEPARATE_FGRID_INTERE)
	size_floatgrids = sizeof(float) * mygrid->num_of_atypes * mygrid->size_xyz[0]*mygrid->size_xyz[1]* mygrid->size_xyz[2];
	size_floatgrids2= sizeof(float) * mygrid->size_xyz[0] * mygrid->size_xyz[1] * mygrid->size_xyz[2];
	size_floatgrids3= sizeof(float) * mygrid->size_xyz[0] * mygrid->size_xyz[1] * mygrid->size_xyz[2];
	#else
	size_floatgrids = (sizeof(float)) * (mygrid->num_of_atypes+2) * (mygrid->size_xyz[0]) * (mygrid->size_xyz[1]) * (mygrid->size_xyz[2]);
	#endif
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#endif



// -----------------------------------------------------------------------------------------------------
// Hardware specific
// Specifiying exact memory bank from host code
// Only valid if 4 banks are available (AWS)
	cl_mem_ext_ptr_t d_bank0_ext; // Krnl_GA
	cl_mem_ext_ptr_t d_bank1_ext; // Krnl_Conform
	cl_mem_ext_ptr_t d_bank2_ext; // Krnl_InterE
	cl_mem_ext_ptr_t d_bank3_ext; // Krnl_IntraE

	d_bank0_ext.flags = XCL_MEM_DDR_BANK0;
	d_bank0_ext.obj   = NULL;
	d_bank0_ext.param = 0;

	d_bank1_ext.flags = XCL_MEM_DDR_BANK1;
	d_bank1_ext.obj   = NULL;
	d_bank1_ext.param = 0;

	d_bank2_ext.flags = XCL_MEM_DDR_BANK2;
	d_bank2_ext.obj   = NULL;
	d_bank2_ext.param = 0;

	d_bank3_ext.flags = XCL_MEM_DDR_BANK3;
	d_bank3_ext.obj   = NULL;
	d_bank3_ext.param = 0;

// Replacing common buffer creation with 
// a Xilinx-specific where DDR banks can be specified
#if 0
lvs's avatar
lvs committed
719
720
721
722
723
724
725
726
727
728
#if defined (FIXED_POINT_INTERE)
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATOMS*sizeof(fixedpt64),                &mem_KerConstStatic_fixpt64_atom_charges_const);
#endif
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATOMS*sizeof(float),                    &mem_KerConstStatic_atom_charges_const);

	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATOMS*sizeof(char),                     &mem_KerConstStatic_atom_types_const);

/*
	mallocBufferObject(context,CL_MEM_READ_ONLY, 3*MAX_INTRAE_CONTRIBUTORS*sizeof(char),            &mem_KerConstStatic_intraE_contributors_const);
*/
Leonardo Solis's avatar
Leonardo Solis committed
729
730
731
732
733
734
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_INTRAE_CONTRIBUTORS*sizeof(cl_char3),          &mem_KerConstStatic_intraE_contributors_const);

        mallocBufferObject(context,CL_MEM_READ_ONLY, ATYPE_NUM*sizeof(float),				&mem_KerConstStatic_reqm_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, ATYPE_NUM*sizeof(float),				&mem_KerConstStatic_reqm_hbond_const);
  	mallocBufferObject(context,CL_MEM_READ_ONLY, ATYPE_NUM*sizeof(unsigned int),			&mem_KerConstStatic_atom1_types_reqm_const);
  	mallocBufferObject(context,CL_MEM_READ_ONLY, ATYPE_NUM*sizeof(unsigned int),                    &mem_KerConstStatic_atom2_types_reqm_const);
lvs's avatar
lvs committed
735
736
737
738
739
740
741
742
743
744

	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float), &mem_KerConstStatic_VWpars_AC_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float), &mem_KerConstStatic_VWpars_BD_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATYPES*sizeof(float), 			&mem_KerConstStatic_dspars_S_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATYPES*sizeof(float), 			&mem_KerConstStatic_dspars_V_const);
	#if defined (FIXED_POINT_CONFORM)
	// fixed-point
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTATIONS*sizeof(fixedpt), 		&mem_KerConstStatic_rotlist_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATOMS*sizeof(cl_int3), 		        &mem_KerConstStatic_ref_coords_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTBONDS*sizeof(cl_int3), 		&mem_KerConstStatic_rotbonds_moving_vectors_const);
lvs's avatar
lvs committed
745
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTBONDS*sizeof(cl_int3), 		&mem_KerConstStatic_rotbonds_unit_vectors_const);
lvs's avatar
lvs committed
746
747
748
749
750
751
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_RUNS*sizeof(cl_int4),			&mem_KerConstStatic_ref_orientation_quats_const);
	#else
	// floating-point (original)
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTATIONS*sizeof(int), 			&mem_KerConstStatic_rotlist_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ATOMS*sizeof(cl_float3), 		&mem_KerConstStatic_ref_coords_const);
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTBONDS*sizeof(cl_float3), 		&mem_KerConstStatic_rotbonds_moving_vectors_const);
lvs's avatar
lvs committed
752
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTBONDS*sizeof(cl_float3), 		&mem_KerConstStatic_rotbonds_unit_vectors_const);
lvs's avatar
lvs committed
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_RUNS*sizeof(cl_float4),			&mem_KerConstStatic_ref_orientation_quats_const);
	#endif

//#if defined (FIXED_POINT_INTERE)
#if 0
	mallocBufferObject(context,CL_MEM_READ_ONLY,size_fixedpt64grids,   	&mem_dockpars_fgrids);
#else
	mallocBufferObject(context,CL_MEM_READ_ONLY,size_floatgrids,   		&mem_dockpars_fgrids);

	#if defined(SEPARATE_FGRID_INTERE)
	mallocBufferObject(context,CL_MEM_READ_ONLY,size_floatgrids2,   	&mem_dockpars_fgrids2);
	mallocBufferObject(context,CL_MEM_READ_ONLY,size_floatgrids3,   	&mem_dockpars_fgrids3);
	#endif
#endif

	mallocBufferObject(context,CL_MEM_READ_WRITE,size_populations,  	&mem_dockpars_conformations_current);
	mallocBufferObject(context,CL_MEM_READ_WRITE,size_energies,    		&mem_dockpars_energies_current);

#if defined(SINGLE_COPY_POP_ENE)
	mallocBufferObject(context,CL_MEM_WRITE_ONLY,size_evals_of_runs,  	&mem_evals_performed);
	mallocBufferObject(context,CL_MEM_WRITE_ONLY,size_evals_of_runs,  	&mem_gens_performed);
#else
	mallocBufferObject(context,CL_MEM_WRITE_ONLY,2*sizeof(unsigned int),  	&mem_evals_and_generations_performed);
776
777
778
779
780
781
782
#endif
#endif



#if defined (FIXED_POINT_INTERE)
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(fixedpt64),                &d_bank2_ext, &mem_KerConstStatic_fixpt64_atom_charges_const);	
lvs's avatar
lvs committed
783
#endif
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(float),                    &d_bank2_ext, &mem_KerConstStatic_InterE_atom_charges_const);	// InterE
  	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(char),                     &d_bank2_ext, &mem_KerConstStatic_InterE_atom_types_const);	// InterE

	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(float),                    &d_bank3_ext, &mem_KerConstStatic_IntraE_atom_charges_const);	// IntraE
  	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(char),                     &d_bank3_ext, &mem_KerConstStatic_IntraE_atom_types_const);	// IntraE

/*
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, 3*MAX_INTRAE_CONTRIBUTORS*sizeof(char),            &d_bank3_ext, &mem_KerConstStatic_intraE_contributors_const);	// IntraE
*/
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_INTRAE_CONTRIBUTORS*sizeof(cl_char3),          &d_bank3_ext, &mem_KerConstStatic_intraE_contributors_const);	// IntraE

        mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, ATYPE_NUM*sizeof(float),			        &d_bank3_ext, &mem_KerConstStatic_reqm_const);			// IntraE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, ATYPE_NUM*sizeof(float),			        &d_bank3_ext, &mem_KerConstStatic_reqm_hbond_const);		// IntraE
  	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, ATYPE_NUM*sizeof(unsigned int),		        &d_bank3_ext, &mem_KerConstStatic_atom1_types_reqm_const);	// IntraE
  	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, ATYPE_NUM*sizeof(unsigned int),                    &d_bank3_ext, &mem_KerConstStatic_atom2_types_reqm_const);	// IntraE

	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float), &d_bank3_ext, &mem_KerConstStatic_VWpars_AC_const);		// IntraE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float), &d_bank3_ext, &mem_KerConstStatic_VWpars_BD_const);		// IntraE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATYPES*sizeof(float), 		        &d_bank3_ext, &mem_KerConstStatic_dspars_S_const);		// IntraE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATYPES*sizeof(float), 			&d_bank3_ext, &mem_KerConstStatic_dspars_V_const);		// IntraE
	#if defined (FIXED_POINT_CONFORM)
	// fixed-point
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTATIONS*sizeof(fixedpt), 		&d_bank1_ext, &mem_KerConstStatic_rotlist_const);			// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(cl_int3), 		        &d_bank1_ext, &mem_KerConstStatic_ref_coords_const);			// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTBONDS*sizeof(cl_int3), 		&d_bank1_ext, &mem_KerConstStatic_rotbonds_moving_vectors_const);	// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTBONDS*sizeof(cl_int3), 		&d_bank1_ext, &mem_KerConstStatic_rotbonds_unit_vectors_const);		// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_RUNS*sizeof(cl_int4),			&d_bank1_ext, &mem_KerConstStatic_ref_orientation_quats_const);		// Conform
	#else
	// floating-point (original)
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTATIONS*sizeof(int), 			&d_bank1_ext, &mem_KerConstStatic_rotlist_const);			// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(cl_float3), 		&d_bank1_ext, &mem_KerConstStatic_ref_coords_const); 			// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTBONDS*sizeof(cl_float3), 		&d_bank1_ext, &mem_KerConstStatic_rotbonds_moving_vectors_const);	// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTBONDS*sizeof(cl_float3), 		&d_bank1_ext, &mem_KerConstStatic_rotbonds_unit_vectors_const);		// Conform
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_RUNS*sizeof(cl_float4),			&d_bank1_ext, &mem_KerConstStatic_ref_orientation_quats_const);		// Conform
	#endif

//#if defined (FIXED_POINT_INTERE)
#if 0
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_fixedpt64grids,   	&d_bank2_ext,	&mem_dockpars_fgrids);	// InterE
#else
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_floatgrids,   		&d_bank2_ext,	&mem_dockpars_fgrids);	// InterE

	#if defined(SEPARATE_FGRID_INTERE)
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_floatgrids2,   	&d_bank2_ext,	&mem_dockpars_fgrids2);	// InterE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_floatgrids3,   	&d_bank2_ext,	&mem_dockpars_fgrids3);	// InterE
	#endif
#endif

	mallocBufferObject(context,CL_MEM_READ_WRITE | CL_MEM_EXT_PTR_XILINX,size_populations,  	&d_bank0_ext,	&mem_dockpars_conformations_current);	// GA
	mallocBufferObject(context,CL_MEM_READ_WRITE | CL_MEM_EXT_PTR_XILINX,size_energies,    		&d_bank0_ext,	&mem_dockpars_energies_current);	// GA

#if defined(SINGLE_COPY_POP_ENE)
	mallocBufferObject(context,CL_MEM_WRITE_ONLY | CL_MEM_EXT_PTR_XILINX,size_evals_of_runs,  	&d_bank0_ext,	&mem_evals_performed);			// GA
					
	mallocBufferObject(context,CL_MEM_WRITE_ONLY | CL_MEM_EXT_PTR_XILINX,size_evals_of_runs,  	&d_bank0_ext,	&mem_gens_performed);			// GA
#else
	mallocBufferObject(context,CL_MEM_WRITE_ONLY | CL_MEM_EXT_PTR_XILINX,2*sizeof(unsigned int),  	&d_bank0_ext,	&mem_evals_and_generations_performed);	// GA
#endif















// -----------------------------------------------------------------------------------------------------

lvs's avatar
lvs committed
858
859
860
861
862
863
864

#if defined(SINGLE_COPY_POP_ENE)

#else
	unsigned int array_evals_and_generations_performed [2]; // [0]: evals, [1]: generations 
#endif

865
866
867
868
869
#if defined (FIXED_POINT_INTERE)
	#if 0
	memcopyBufferObjectToDevice(command_queue/*1*/,mem_KerConstStatic_fixpt64_atom_charges_const,            &KerConstStatic.fixpt64_atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(fixedpt64));
	#endif
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_fixpt64_atom_charges_const,            &KerConstStatic.fixpt64_atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(fixedpt64));
lvs's avatar
lvs committed
870
#endif
871
872
873
874
875
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_InterE_atom_charges_const,            &KerConstStatic.atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(float));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_InterE_atom_types_const,              &KerConstStatic.atom_types_const[0],              MAX_NUM_OF_ATOMS*sizeof(char));

	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_IntraE_atom_charges_const,            &KerConstStatic.atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(float));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_IntraE_atom_types_const,              &KerConstStatic.atom_types_const[0],              MAX_NUM_OF_ATOMS*sizeof(char));
lvs's avatar
lvs committed
876
877
878
879

/*
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_intraE_contributors_const,     &KerConstStatic.intraE_contributors_const[0],     3*MAX_INTRAE_CONTRIBUTORS*sizeof(char));
*/
880
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_intraE_contributors_const,     &KerConstStatic.intraE_contributors_const[0],     MAX_INTRAE_CONTRIBUTORS*sizeof(cl_char3));
Leonardo Solis's avatar
Leonardo Solis committed
881

882
883
884
885
886
887
888
889
890
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_reqm_const,         	     &KerConstStatic.reqm_const,           	           ATYPE_NUM*sizeof(float));
  	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_reqm_hbond_const,              &KerConstStatic.reqm_hbond_const,                 ATYPE_NUM*sizeof(float));
  	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_atom1_types_reqm_const,        &KerConstStatic.atom1_types_reqm_const,           ATYPE_NUM*sizeof(unsigned int));
  	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_atom2_types_reqm_const,        &KerConstStatic.atom2_types_reqm_const,           ATYPE_NUM*sizeof(unsigned int));

	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_VWpars_AC_const,               &KerConstStatic.VWpars_AC_const[0],               MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_VWpars_BD_const,               &KerConstStatic.VWpars_BD_const[0],               MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_dspars_S_const,                &KerConstStatic.dspars_S_const[0], 	       MAX_NUM_OF_ATYPES*sizeof(float));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_dspars_V_const,                &KerConstStatic.dspars_V_const[0], 	       MAX_NUM_OF_ATYPES*sizeof(float));
lvs's avatar
lvs committed
891
892
	#if defined (FIXED_POINT_CONFORM)
	// fixed-point
893
894
895
896
897
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_rotlist_const,                 &KerConstStatic.rotlist_const[0], 		       MAX_NUM_OF_ROTATIONS*sizeof(fixedpt));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_ref_coords_const, 	     &KerConstStatic.ref_coords_const[0],              MAX_NUM_OF_ATOMS*sizeof(cl_int3));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_rotbonds_moving_vectors_const, &KerConstStatic.rotbonds_moving_vectors_const[0], MAX_NUM_OF_ROTBONDS*sizeof(cl_int3));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_rotbonds_unit_vectors_const,   &KerConstStatic.rotbonds_unit_vectors_const[0],   MAX_NUM_OF_ROTBONDS*sizeof(cl_int3));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_ref_orientation_quats_const,   &KerConstStatic.ref_orientation_quats_const[0],   MAX_NUM_OF_RUNS*sizeof(cl_int4));
lvs's avatar
lvs committed
898
899
	#else
	// floating-point (original)
900
901
902
903
904
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_rotlist_const,                 &KerConstStatic.rotlist_const[0], 		       MAX_NUM_OF_ROTATIONS*sizeof(int));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_ref_coords_const, 	     &KerConstStatic.ref_coords_const[0],              MAX_NUM_OF_ATOMS*sizeof(cl_float3));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_rotbonds_moving_vectors_const, &KerConstStatic.rotbonds_moving_vectors_const[0], MAX_NUM_OF_ROTBONDS*sizeof(cl_float3));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_rotbonds_unit_vectors_const,   &KerConstStatic.rotbonds_unit_vectors_const[0],   MAX_NUM_OF_ROTBONDS*sizeof(cl_float3));
	memcopyBufferObjectToDevice(command_queue1,mem_KerConstStatic_ref_orientation_quats_const,   &KerConstStatic.ref_orientation_quats_const[0],   MAX_NUM_OF_RUNS*sizeof(cl_float4));
lvs's avatar
lvs committed
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
	#endif

//#if defined (FIXED_POINT_INTERE)
#if 0
/*
	cpu_fixedpt64grids = (fixedpt64*) alignedMalloc((sizeof(fixedpt64))*(mygrid->num_of_atypes+2)*
						  			    (mygrid->size_xyz[0])*
			   					            (mygrid->size_xyz[1])*
									    (mygrid->size_xyz[2]));
*/
	cpu_fixedpt64grids = (fixedpt64*) alignedMalloc(size_fixedpt64grids);

	float* mypoi;
	fixedpt64* myqoi;
	mypoi = cpu_floatgrids;
	myqoi = cpu_fixedpt64grids;

	for (int t=0; t < mygrid->num_of_atypes+2; t++) {
		//reading values
		for (int z=0; z < mygrid->size_xyz[2]; z++)
			for (int y=0; y < mygrid->size_xyz[1]; y++)
				for (int x=0; x < mygrid->size_xyz[0]; x++)
				{
					//fscanf(fp, "%f", mypoi);
					//mypoi++;
					float tmp_grids = *mypoi;
					mypoi++;
					*myqoi = fixedpt64_fromfloat(tmp_grids);

					// test to prove that it requires 32.32
					// and 16.16 is not enough
					//fixedpt myqoi16 = fixedpt_fromfloat(tmp_grids);
					//printf("%-10f %-10f %-10f\n", tmp_grids, fixedpt64_tofloat(*myqoi), fixedpt_tofloat(myqoi16));
					
					myqoi++;

					
				}
	}

	memcopyBufferObjectToDevice(command_queue1,mem_dockpars_fgrids, 	cpu_fixedpt64grids,       size_fixedpt64grids);
#else
947
	memcopyBufferObjectToDevice(command_queue1,mem_dockpars_fgrids, 	cpu_floatgrids,       size_floatgrids);
lvs's avatar
lvs committed
948
949

	#if defined(SEPARATE_FGRID_INTERE)
950
951
	memcopyBufferObjectToDevice(command_queue1,mem_dockpars_fgrids2, 	cpu_floatgrids + mygrid->num_of_atypes     * mygrid->size_xyz[0]*mygrid->size_xyz[1]* mygrid->size_xyz[2],       size_floatgrids2);
	memcopyBufferObjectToDevice(command_queue1,mem_dockpars_fgrids3, 	cpu_floatgrids + (mygrid->num_of_atypes+1) * mygrid->size_xyz[0]*mygrid->size_xyz[1]* mygrid->size_xyz[2],       size_floatgrids3);
lvs's avatar
lvs committed
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
	#endif
#endif

	clock_start_docking = clock();

#ifdef ENABLE_KERNEL1 // Krnl_GA
	#if defined(SINGLE_COPY_POP_ENE)
        setKernelArg(kernel1,0,  sizeof(mem_dockpars_conformations_current),    &mem_dockpars_conformations_current);
        setKernelArg(kernel1,1,  sizeof(mem_dockpars_energies_current),         &mem_dockpars_energies_current);
	setKernelArg(kernel1,2,  sizeof(mem_evals_performed),   		&mem_evals_performed);
	setKernelArg(kernel1,3,  sizeof(mem_gens_performed),    		&mem_gens_performed);
	setKernelArg(kernel1,4,  sizeof(unsigned int),                  	&dockpars.pop_size);
	setKernelArg(kernel1,5,  sizeof(unsigned int),                 		&dockpars.num_of_energy_evals);
	setKernelArg(kernel1,6,  sizeof(unsigned int),                 		&dockpars.num_of_generations);
	setKernelArg(kernel1,7,  sizeof(float),                          	&dockpars.tournament_rate);
	setKernelArg(kernel1,8,  sizeof(float),                          	&dockpars.mutation_rate);
	setKernelArg(kernel1,9,  sizeof(float),                          	&dockpars.abs_max_dmov);
	setKernelArg(kernel1,10, sizeof(float),                          	&dockpars.abs_max_dang);
	setKernelArg(kernel1,11, sizeof(float),                                 &two_absmaxdmov);
	setKernelArg(kernel1,12, sizeof(float),                                 &two_absmaxdang);
	setKernelArg(kernel1,13, sizeof(float),                          	&dockpars.crossover_rate);
	setKernelArg(kernel1,14, sizeof(unsigned int),                          &dockpars.num_of_lsentities);
	setKernelArg(kernel1,15, sizeof(unsigned char),                         &dockpars.num_of_genes);
	//setKernelArg(kernel1,16, sizeof(unsigned short),                      run_cnt);
	//setKernelArg(kernel1,17, sizeof(unsigned int),                        offset_pop);
	//setKernelArg(kernel1,18, sizeof(unsigned int),                        offset_ene);
	#else
        setKernelArg(kernel1,0,  sizeof(mem_dockpars_conformations_current),    &mem_dockpars_conformations_current);
        setKernelArg(kernel1,1,  sizeof(mem_dockpars_energies_current),         &mem_dockpars_energies_current);
	setKernelArg(kernel1,2,  sizeof(mem_evals_and_generations_performed),   &mem_evals_and_generations_performed);
	setKernelArg(kernel1,3,  sizeof(unsigned int),                  	&dockpars.pop_size);
	setKernelArg(kernel1,4,  sizeof(unsigned int),                 		&dockpars.num_of_energy_evals);
	setKernelArg(kernel1,5,  sizeof(unsigned int),                 		&dockpars.num_of_generations);
	setKernelArg(kernel1,6,  sizeof(float),                          	&dockpars.tournament_rate);
	setKernelArg(kernel1,7,  sizeof(float),                          	&dockpars.mutation_rate);
	setKernelArg(kernel1,8,  sizeof(float),                          	&dockpars.abs_max_dmov);
	setKernelArg(kernel1,9,  sizeof(float),                          	&dockpars.abs_max_dang);
	setKernelArg(kernel1,10, sizeof(float),                                 &two_absmaxdmov);
	setKernelArg(kernel1,11, sizeof(float),                                 &two_absmaxdang);
	setKernelArg(kernel1,12, sizeof(float),                          	&dockpars.crossover_rate);
	setKernelArg(kernel1,13, sizeof(unsigned int),                          &dockpars.num_of_lsentities);
	setKernelArg(kernel1,14, sizeof(unsigned char),                         &dockpars.num_of_genes);
	#endif
#endif // End of ENABLE_KERNEL1

#ifdef ENABLE_KERNEL2 // Krnl_Conform
	setKernelArg(kernel2,0,  sizeof(mem_KerConstStatic_rotlist_const),      	   &mem_KerConstStatic_rotlist_const);
	setKernelArg(kernel2,1,  sizeof(mem_KerConstStatic_ref_coords_const),              &mem_KerConstStatic_ref_coords_const);
	setKernelArg(kernel2,2,  sizeof(mem_KerConstStatic_rotbonds_moving_vectors_const), &mem_KerConstStatic_rotbonds_moving_vectors_const);
For faster browsing, not all history is shown. View entire blame