performdocking.cpp 100 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
//// ------------------------
//// 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
27
28
static cl_context       context       = NULL;

29
#if 0
Leonardo Solis's avatar
Leonardo Solis committed
30
31
// Unique command queue
static cl_command_queue command_queue = NULL;
32
#endif
lvs's avatar
lvs committed
33

34
// Kernel name as defined in the CL file
35
36
37
38
#ifdef ENABLE_KRNL_GA
static cl_command_queue command_queue_ga = NULL;
static cl_kernel kernel_ga  = NULL;
static const char *name_krnl_ga = "Krnl_GA";
lvs's avatar
lvs committed
39
40
#endif

41
42
43
44
#ifdef ENABLE_KRNL_CONFORM
static cl_command_queue command_queue_conform = NULL;
static cl_kernel kernel_conform  = NULL;
static const char *name_krnl_conform = "Krnl_Conform";
lvs's avatar
lvs committed
45
46
#endif

47
48
49
50
#ifdef ENABLE_KRNL_INTERE
static cl_command_queue command_queue_intere = NULL;
static cl_kernel kernel_intere  = NULL;
static const char *name_krnl_intere = "Krnl_InterE";
lvs's avatar
lvs committed
51
52
#endif

53
54
55
56
#ifdef ENABLE_KRNL_INTRAE
static cl_command_queue command_queue_intrae = NULL;
static cl_kernel kernel_intrae  = NULL;
static const char *name_krnl_intrae = "Krnl_IntraE";
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#endif

#ifdef ENABLE_KRNL_PRNG_BT_USHORT_FLOAT
static cl_command_queue command_queue_prng_bt_ushort_float = NULL;
static cl_kernel kernel_prng_bt_ushort_float  = NULL;
static const char *name_krnl_prng_bt_ushort_float = "Krnl_Prng_BT_ushort_float";
#endif

#ifdef ENABLE_KRNL_PRNG_GG_UCHAR
static cl_command_queue command_queue_prng_gg_uchar = NULL;
static cl_kernel kernel_prng_gg_uchar  = NULL;
static const char *name_krnl_prng_gg_uchar = "Krnl_Prng_GG_uchar";
#endif

#ifdef ENABLE_KRNL_PRNG_GG_FLOAT
static cl_command_queue command_queue_prng_gg_float = NULL;
static cl_kernel kernel_prng_gg_float  = NULL;
static const char *name_krnl_prng_gg_float = "Krnl_Prng_GG_float";
#endif

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifdef ENABLE_KRNL_PRNG_LS123_USHORT
static cl_command_queue command_queue_prng_ls123_ushort = NULL;
static cl_kernel kernel_prng_ls123_ushort  = NULL;
static const char *name_krnl_prng_ls123_ushort = "Krnl_Prng_LS123_ushort";
#endif

#ifdef ENABLE_KRNL_PRNG_LS_FLOAT
static cl_command_queue command_queue_prng_ls_float = NULL;
static cl_kernel kernel_prng_ls_float  = NULL;
static const char *name_krnl_prng_ls_float = "Krnl_Prng_LS_float";
#endif

#ifdef ENABLE_KRNL_PRNG_LS2_FLOAT
static cl_command_queue command_queue_prng_ls2_float = NULL;
static cl_kernel kernel_prng_ls2_float  = NULL;
static const char *name_krnl_prng_ls2_float = "Krnl_Prng_LS2_float";
#endif

#ifdef ENABLE_KRNL_PRNG_LS3_FLOAT
static cl_command_queue command_queue_prng_ls3_float = NULL;
static cl_kernel kernel_prng_ls3_float  = NULL;
static const char *name_krnl_prng_ls3_float = "Krnl_Prng_LS3_float";
#endif

101
102
103
104
105
106
107
108
109
110
111
#ifdef ENABLE_KRNL_PRNG_LS4_FLOAT
static cl_command_queue command_queue_prng_ls4_float = NULL;
static cl_kernel kernel_prng_ls4_float  = NULL;
static const char *name_krnl_prng_ls4_float = "Krnl_Prng_LS4_float";
#endif

#ifdef ENABLE_KRNL_PRNG_LS5_FLOAT
static cl_command_queue command_queue_prng_ls5_float = NULL;
static cl_kernel kernel_prng_ls5_float  = NULL;
static const char *name_krnl_prng_ls5_float = "Krnl_Prng_LS5_float";
#endif
112

113
114
115
116
117
#ifdef ENABLE_KRNL_PRNG_LS6_FLOAT
static cl_command_queue command_queue_prng_ls6_float = NULL;
static cl_kernel kernel_prng_ls6_float  = NULL;
static const char *name_krnl_prng_ls6_float = "Krnl_Prng_LS6_float";
#endif
lvs's avatar
lvs committed
118

119
120
121
122
123
#ifdef ENABLE_KRNL_PRNG_LS7_FLOAT
static cl_command_queue command_queue_prng_ls7_float = NULL;
static cl_kernel kernel_prng_ls7_float  = NULL;
static const char *name_krnl_prng_ls7_float = "Krnl_Prng_LS7_float";
#endif
lvs's avatar
lvs committed
124

125
126
127
128
129
#ifdef ENABLE_KRNL_PRNG_LS8_FLOAT
static cl_command_queue command_queue_prng_ls8_float = NULL;
static cl_kernel kernel_prng_ls8_float  = NULL;
static const char *name_krnl_prng_ls8_float = "Krnl_Prng_LS8_float";
#endif
lvs's avatar
lvs committed
130

131
132
133
134
#ifdef ENABLE_KRNL_PRNG_LS9_FLOAT
static cl_command_queue command_queue_prng_ls9_float = NULL;
static cl_kernel kernel_prng_ls9_float  = NULL;
static const char *name_krnl_prng_ls9_float = "Krnl_Prng_LS9_float";
135
136
#endif

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifdef ENABLE_KRNL_LS
static cl_command_queue command_queue_ls = NULL;
static cl_kernel kernel_ls  = NULL;
static const char *name_krnl_ls = "Krnl_LS";
#endif

#ifdef ENABLE_KRNL_LS2
static cl_command_queue command_queue_ls2 = NULL;
static cl_kernel kernel_ls2  = NULL;
static const char *name_krnl_ls2 = "Krnl_LS2";
#endif

#ifdef ENABLE_KRNL_LS3
static cl_command_queue command_queue_ls3 = NULL;
static cl_kernel kernel_ls3  = NULL;
static const char *name_krnl_ls3 = "Krnl_LS3";
#endif

#ifdef ENABLE_KRNL_LS4
static cl_command_queue command_queue_ls4 = NULL;
static cl_kernel kernel_ls4  = NULL;
static const char *name_krnl_ls4 = "Krnl_LS4";
#endif

#ifdef ENABLE_KRNL_LS5
static cl_command_queue command_queue_ls5 = NULL;
static cl_kernel kernel_ls5  = NULL;
static const char *name_krnl_ls5 = "Krnl_LS5";
#endif

#ifdef ENABLE_KRNL_LS6
static cl_command_queue command_queue_ls6 = NULL;
static cl_kernel kernel_ls6  = NULL;
static const char *name_krnl_ls6 = "Krnl_LS6";
#endif

#ifdef ENABLE_KRNL_LS7
static cl_command_queue command_queue_ls7 = NULL;
static cl_kernel kernel_ls7  = NULL;
static const char *name_krnl_ls7 = "Krnl_LS7";
#endif

#ifdef ENABLE_KRNL_LS8
static cl_command_queue command_queue_ls8 = NULL;
static cl_kernel kernel_ls8  = NULL;
static const char *name_krnl_ls8 = "Krnl_LS8";
#endif

#ifdef ENABLE_KRNL_LS9
static cl_command_queue command_queue_ls9 = NULL;
static cl_kernel kernel_ls9  = NULL;
static const char *name_krnl_ls9 = "Krnl_LS9";
#endif
190

191
192
193
194
#ifdef ENABLE_KRNL_IGL_ARBITER
static cl_command_queue command_queue_igl_arbiter = NULL;
static cl_kernel kernel_igl_arbiter = NULL;
static const char *name_krnl_igl_arbiter = "Krnl_IGL_Arbiter";
195
196
#endif

lvs's avatar
lvs committed
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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
//// --------------------------------
#if defined (FIXED_POINT_INTERE)
cl_mem mem_KerConstStatic_fixpt64_atom_charges_const;
#endif
239
240
241
242
243
244
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
245
246
247
248
249
250
251
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
252
253
254
255
256
257
258
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
259
cl_mem mem_KerConstStatic_rotbonds_unit_vectors_const;
lvs's avatar
lvs committed
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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;

#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
295
296
297
298
299
300
301

#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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
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
429
430
431
432
433
434
435
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

//#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);
461
462
	dockpars.coeff_desolv  = ((float) mypars->coeffs.AD4_coeff_desolv);

lvs's avatar
lvs committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
	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
481
	dockpars.smooth = mypars->smooth;
lvs's avatar
lvs committed
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

	// 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

 	//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
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
#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
542
543
544
545
546
547
548
549
550
551
#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
552
553
554
555
556
557
	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
558
559
560
561
562
563
564
565
566
567

	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
568
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTBONDS*sizeof(cl_int3), 		&mem_KerConstStatic_rotbonds_unit_vectors_const);
lvs's avatar
lvs committed
569
570
571
572
573
574
	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
575
	mallocBufferObject(context,CL_MEM_READ_ONLY, MAX_NUM_OF_ROTBONDS*sizeof(cl_float3), 		&mem_KerConstStatic_rotbonds_unit_vectors_const);
lvs's avatar
lvs committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
	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);
599
600
601
602
603
604
#endif
#endif



#if defined (FIXED_POINT_INTERE)
Leonardo Solis's avatar
Leonardo Solis committed
605
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(fixedpt64),                &d_bank1_ext/*&d_bank2_ext*/, &mem_KerConstStatic_fixpt64_atom_charges_const);	
lvs's avatar
lvs committed
606
#endif
Leonardo Solis's avatar
Leonardo Solis committed
607
608
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(float),                    &d_bank1_ext/*&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_bank1_ext/*&d_bank2_ext*/, &mem_KerConstStatic_InterE_atom_types_const);	// InterE
609

Leonardo Solis's avatar
Leonardo Solis committed
610
611
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ATOMS*sizeof(float),                    &d_bank1_ext/*&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_bank1_ext/*&d_bank3_ext*/, &mem_KerConstStatic_IntraE_atom_types_const);	// IntraE
612
613
614
615

/*
	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
*/
Leonardo Solis's avatar
Leonardo Solis committed
616
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_INTRAE_CONTRIBUTORS*sizeof(cl_char3),          &d_bank1_ext/*&d_bank3_ext*/, &mem_KerConstStatic_intraE_contributors_const);	// IntraE
617

Leonardo Solis's avatar
Leonardo Solis committed
618
619
620
621
622
623
624
625
626
        mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, ATYPE_NUM*sizeof(float),			        &d_bank1_ext/*&d_bank3_ext*/, &mem_KerConstStatic_reqm_const);			// IntraE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, ATYPE_NUM*sizeof(float),			        &d_bank1_ext/*&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_bank1_ext/*&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_bank1_ext/*&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_bank1_ext/*&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_bank1_ext/*&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_bank1_ext/*&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_bank1_ext/*&d_bank3_ext*/, &mem_KerConstStatic_dspars_V_const);		// IntraE
627
628
	#if defined (FIXED_POINT_CONFORM)
	// fixed-point
Leonardo Solis's avatar
Leonardo Solis committed
629
630
631
632
633
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTATIONS*sizeof(fixedpt), 		&d_bank0_ext/*&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_bank0_ext/*&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_bank0_ext/*&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_bank0_ext/*&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_bank0_ext/*&d_bank1_ext*/, &mem_KerConstStatic_ref_orientation_quats_const);		// Conform
634
635
	#else
	// floating-point (original)
Leonardo Solis's avatar
Leonardo Solis committed
636
637
638
639
640
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, MAX_NUM_OF_ROTATIONS*sizeof(int), 			&d_bank0_ext/*&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_bank0_ext/*&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_bank0_ext/*&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_bank0_ext/*&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_bank0_ext/*&d_bank1_ext*/, &mem_KerConstStatic_ref_orientation_quats_const);		// Conform
641
642
643
644
645
646
	#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
Leonardo Solis's avatar
Leonardo Solis committed
647
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_floatgrids,   		&d_bank1_ext/*&d_bank2_ext*/,	&mem_dockpars_fgrids);	// InterE
648
649

	#if defined(SEPARATE_FGRID_INTERE)
Leonardo Solis's avatar
Leonardo Solis committed
650
651
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_floatgrids2,   	&d_bank1_ext/*&d_bank2_ext*/,	&mem_dockpars_fgrids2);	// InterE
	mallocBufferObject(context,CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX,size_floatgrids3,   	&d_bank1_ext/*&d_bank2_ext*/,	&mem_dockpars_fgrids3);	// InterE
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
	#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
681
682
683
684
685
686
687

#if defined(SINGLE_COPY_POP_ENE)

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

688
689
#if defined (FIXED_POINT_INTERE)
	#if 0
690
	memcopyBufferObjectToDevice(command_queue,mem_KerConstStatic_fixpt64_atom_charges_const,            &KerConstStatic.fixpt64_atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(fixedpt64));
691
	#endif
692
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_fixpt64_atom_charges_const,            &KerConstStatic.fixpt64_atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(fixedpt64));
lvs's avatar
lvs committed
693
#endif
694
695
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_InterE_atom_charges_const,            &KerConstStatic.atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(float));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_InterE_atom_types_const,              &KerConstStatic.atom_types_const[0],              MAX_NUM_OF_ATOMS*sizeof(char));
696

697
698
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_IntraE_atom_charges_const,            &KerConstStatic.atom_charges_const[0],            MAX_NUM_OF_ATOMS*sizeof(float));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_IntraE_atom_types_const,              &KerConstStatic.atom_types_const[0],              MAX_NUM_OF_ATOMS*sizeof(char));
lvs's avatar
lvs committed
699
700

/*
701
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_intraE_contributors_const,     &KerConstStatic.intraE_contributors_const[0],     3*MAX_INTRAE_CONTRIBUTORS*sizeof(char));
lvs's avatar
lvs committed
702
*/
703
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_intraE_contributors_const,     &KerConstStatic.intraE_contributors_const[0],     MAX_INTRAE_CONTRIBUTORS*sizeof(cl_char3));
Leonardo Solis's avatar
Leonardo Solis committed
704

705
706
707
708
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_reqm_const,         	     &KerConstStatic.reqm_const,           	           ATYPE_NUM*sizeof(float));
  	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_reqm_hbond_const,              &KerConstStatic.reqm_hbond_const,                 ATYPE_NUM*sizeof(float));
  	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_atom1_types_reqm_const,        &KerConstStatic.atom1_types_reqm_const,           ATYPE_NUM*sizeof(unsigned int));
  	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_atom2_types_reqm_const,        &KerConstStatic.atom2_types_reqm_const,           ATYPE_NUM*sizeof(unsigned int));
709

710
711
712
713
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_VWpars_AC_const,               &KerConstStatic.VWpars_AC_const[0],               MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_VWpars_BD_const,               &KerConstStatic.VWpars_BD_const[0],               MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES*sizeof(float));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_dspars_S_const,                &KerConstStatic.dspars_S_const[0], 	       MAX_NUM_OF_ATYPES*sizeof(float));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_dspars_V_const,                &KerConstStatic.dspars_V_const[0], 	       MAX_NUM_OF_ATYPES*sizeof(float));
lvs's avatar
lvs committed
714
715
	#if defined (FIXED_POINT_CONFORM)
	// fixed-point
716
717
718
719
720
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_rotlist_const,                 &KerConstStatic.rotlist_const[0], 		       MAX_NUM_OF_ROTATIONS*sizeof(fixedpt));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_ref_coords_const, 	     &KerConstStatic.ref_coords_const[0],              MAX_NUM_OF_ATOMS*sizeof(cl_int3));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_rotbonds_moving_vectors_const, &KerConstStatic.rotbonds_moving_vectors_const[0], MAX_NUM_OF_ROTBONDS*sizeof(cl_int3));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_rotbonds_unit_vectors_const,   &KerConstStatic.rotbonds_unit_vectors_const[0],   MAX_NUM_OF_ROTBONDS*sizeof(cl_int3));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_ref_orientation_quats_const,   &KerConstStatic.ref_orientation_quats_const[0],   MAX_NUM_OF_RUNS*sizeof(cl_int4));
lvs's avatar
lvs committed
721
722
	#else
	// floating-point (original)
723
724
725
726
727
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_rotlist_const,                 &KerConstStatic.rotlist_const[0], 		       MAX_NUM_OF_ROTATIONS*sizeof(int));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_ref_coords_const, 	     &KerConstStatic.ref_coords_const[0],              MAX_NUM_OF_ATOMS*sizeof(cl_float3));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_rotbonds_moving_vectors_const, &KerConstStatic.rotbonds_moving_vectors_const[0], MAX_NUM_OF_ROTBONDS*sizeof(cl_float3));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_rotbonds_unit_vectors_const,   &KerConstStatic.rotbonds_unit_vectors_const[0],   MAX_NUM_OF_ROTBONDS*sizeof(cl_float3));
	memcopyBufferObjectToDevice(command_queue_ga,mem_KerConstStatic_ref_orientation_quats_const,   &KerConstStatic.ref_orientation_quats_const[0],   MAX_NUM_OF_RUNS*sizeof(cl_float4));
lvs's avatar
lvs committed
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
	#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++;

					
				}
	}

768
	memcopyBufferObjectToDevice(command_queue_ga,mem_dockpars_fgrids, 	cpu_fixedpt64grids,       size_fixedpt64grids);
lvs's avatar
lvs committed
769
#else
770
	memcopyBufferObjectToDevice(command_queue_ga,mem_dockpars_fgrids, 	cpu_floatgrids,       size_floatgrids);
lvs's avatar
lvs committed
771
772

	#if defined(SEPARATE_FGRID_INTERE)
773
774
	memcopyBufferObjectToDevice(command_queue_ga,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_queue_ga,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
775
776
777
778
779
	#endif
#endif

	clock_start_docking = clock();

780
#ifdef ENABLE_KRNL_GA
lvs's avatar
lvs committed
781
	#if defined(SINGLE_COPY_POP_ENE)
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
        setKernelArg(kernel_ga,0,  sizeof(mem_dockpars_conformations_current),    &mem_dockpars_conformations_current);
        setKernelArg(kernel_ga,1,  sizeof(mem_dockpars_energies_current),         &mem_dockpars_energies_current);
	setKernelArg(kernel_ga,2,  sizeof(mem_evals_performed),   		&mem_evals_performed);
	setKernelArg(kernel_ga,3,  sizeof(mem_gens_performed),    		&mem_gens_performed);
	setKernelArg(kernel_ga,4,  sizeof(unsigned int),                  	&dockpars.pop_size);
	setKernelArg(kernel_ga,5,  sizeof(unsigned int),                 		&dockpars.num_of_energy_evals);
	setKernelArg(kernel_ga,6,  sizeof(unsigned int),                 		&dockpars.num_of_generations);
	setKernelArg(kernel_ga,7,  sizeof(float),                          	&dockpars.tournament_rate);
	setKernelArg(kernel_ga,8,  sizeof(float),                          	&dockpars.mutation_rate);
	setKernelArg(kernel_ga,9,  sizeof(float),                          	&dockpars.abs_max_dmov);
	setKernelArg(kernel_ga,10, sizeof(float),                          	&dockpars.abs_max_dang);
	setKernelArg(kernel_ga,11, sizeof(float),                                 &two_absmaxdmov);
	setKernelArg(kernel_ga,12, sizeof(float),                                 &two_absmaxdang);
	setKernelArg(kernel_ga,13, sizeof(float),                          	&dockpars.crossover_rate);
	setKernelArg(kernel_ga,14, sizeof(unsigned int),                          &dockpars.num_of_lsentities);
	setKernelArg(kernel_ga,15, sizeof(unsigned char),                         &dockpars.num_of_genes);
	//setKernelArg(kernel_ga,16, sizeof(unsigned short),                      run_cnt);
	//setKernelArg(kernel_ga,17, sizeof(unsigned int),                        offset_pop);
	//setKernelArg(kernel_ga,18, sizeof(unsigned int),                        offset_ene);
lvs's avatar
lvs committed
801
	#else
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
        setKernelArg(kernel_ga,0,  sizeof(mem_dockpars_conformations_current),    &mem_dockpars_conformations_current);
        setKernelArg(kernel_ga,1,  sizeof(mem_dockpars_energies_current),         &mem_dockpars_energies_current);
	setKernelArg(kernel_ga,2,  sizeof(mem_evals_and_generations_performed),   &mem_evals_and_generations_performed);
	setKernelArg(kernel_ga,3,  sizeof(unsigned int),                  	&dockpars.pop_size);
	setKernelArg(kernel_ga,4,  sizeof(unsigned int),                 		&dockpars.num_of_energy_evals);
	setKernelArg(kernel_ga,5,  sizeof(unsigned int),                 		&dockpars.num_of_generations);
	setKernelArg(kernel_ga,6,  sizeof(float),                          	&dockpars.tournament_rate);
	setKernelArg(kernel_ga,7,  sizeof(float),                          	&dockpars.mutation_rate);
	setKernelArg(kernel_ga,8,  sizeof(float),                          	&dockpars.abs_max_dmov);
	setKernelArg(kernel_ga,9,  sizeof(float),                          	&dockpars.abs_max_dang);
	setKernelArg(kernel_ga,10, sizeof(float),                                 &two_absmaxdmov);
	setKernelArg(kernel_ga,11, sizeof(float),                                 &two_absmaxdang);
	setKernelArg(kernel_ga,12, sizeof(float),                          	&dockpars.crossover_rate);
	setKernelArg(kernel_ga,13, sizeof(unsigned int),                          &dockpars.num_of_lsentities);
	setKernelArg(kernel_ga,14, sizeof(unsigned char),                         &dockpars.num_of_genes);
lvs's avatar
lvs committed
817
	#endif
818
#endif // End of ENABLE_KRNL_GA
lvs's avatar
lvs committed
819

820
#ifdef ENABLE_KRNL_CONFORM
821
822
823
824
825
826
827
	setKernelArg(kernel_conform,0,  sizeof(mem_KerConstStatic_rotlist_const),      	   &mem_KerConstStatic_rotlist_const);
	setKernelArg(kernel_conform,1,  sizeof(mem_KerConstStatic_ref_coords_const),              &mem_KerConstStatic_ref_coords_const);
	setKernelArg(kernel_conform,2,  sizeof(mem_KerConstStatic_rotbonds_moving_vectors_const), &mem_KerConstStatic_rotbonds_moving_vectors_const);
	setKernelArg(kernel_conform,3,  sizeof(mem_KerConstStatic_rotbonds_unit_vectors_const),   &mem_KerConstStatic_rotbonds_unit_vectors_const);
	setKernelArg(kernel_conform,4,  sizeof(unsigned int),       &dockpars.rotbondlist_length);
	setKernelArg(kernel_conform,5,  sizeof(unsigned char),      &dockpars.num_of_atoms);
	setKernelArg(kernel_conform,6,  sizeof(unsigned char),      &dockpars.num_of_genes);
lvs's avatar
lvs committed
828
/*
829
	setKernelArg(kernel_conform,8,  sizeof(mem_KerConstStatic_ref_orientation_quats_const),   &mem_KerConstStatic_ref_orientation_quats_const);
lvs's avatar
lvs committed
830
*/
831
	setKernelArg(kernel_conform,7,  sizeof(mem_KerConstStatic_ref_orientation_quats_const),   &mem_KerConstStatic_ref_orientation_quats_const);
lvs's avatar
lvs committed
832
833
834
835
836
	#if defined(SINGLE_COPY_POP_ENE)

	#else
		#if defined (FIXED_POINT_CONFORM)
	// fixed-point
837
838
839
840
	setKernelArg(kernel_conform,8,  sizeof(fixedpt),            &KerConstDynamic.ref_orientation_quats_const[0]);
	setKernelArg(kernel_conform,9,  sizeof(fixedpt),            &KerConstDynamic.ref_orientation_quats_const[1]);
	setKernelArg(kernel_conform,10, sizeof(fixedpt),            &KerConstDynamic.ref_orientation_quats_const[2]);
	setKernelArg(kernel_conform,11, sizeof(fixedpt),            &KerConstDynamic.ref_orientation_quats_const[3]);
lvs's avatar
lvs committed
841
842
		#else
	// floating-point (original)
843
844
845
846
	setKernelArg(kernel_conform,8,  sizeof(float),              &KerConstDynamic.ref_orientation_quats_const[0]);
	setKernelArg(kernel_conform,9,  sizeof(float),              &KerConstDynamic.ref_orientation_quats_const[1]);
	setKernelArg(kernel_conform,10, sizeof(float),              &KerConstDynamic.ref_orientation_quats_const[2]);
	setKernelArg(kernel_conform,11, sizeof(float),              &KerConstDynamic.ref_orientation_quats_const[3]);
lvs's avatar
lvs committed
847
848
		#endif
	#endif
849
#endif // End of ENABLE_KRNL_CONFORM
lvs's avatar
lvs committed
850
851
852
853


	unsigned char gridsizex_minus1 = dockpars.gridsize_x - 1;
	unsigned char gridsizey_minus1 = dockpars.gridsize_y - 1;
lvs's avatar
lvs committed
854
855
856
857
858
	unsigned char gridsizez_minus1 = dockpars.gridsize_z - 1;

#if defined (FIXED_POINT_INTERE)

#else
lvs's avatar
lvs committed
859
860
	float fgridsizex_minus1 = (float) gridsizex_minus1;
	float fgridsizey_minus1 = (float) gridsizey_minus1;
lvs's avatar
lvs committed
861
862
	float fgridsizez_minus1 = (float) gridsizez_minus1;

lvs's avatar
lvs committed
863
864
865
#endif


866
#ifdef ENABLE_KRNL_INTERE
867
        setKernelArg(kernel_intere,0,  sizeof(mem_dockpars_fgrids),                    &mem_dockpars_fgrids);
lvs's avatar
lvs committed
868
	#if defined (FIXED_POINT_INTERE)
869
	setKernelArg(kernel_intere,1,  sizeof(mem_KerConstStatic_fixpt64_atom_charges_const),  &mem_KerConstStatic_fixpt64_atom_charges_const);
lvs's avatar
lvs committed
870
	#else
871
	setKernelArg(kernel_intere,1,  sizeof(mem_KerConstStatic_InterE_atom_charges_const),  &mem_KerConstStatic_InterE_atom_charges_const);
lvs's avatar
lvs committed
872
	#endif
873
874
875
876
877
	setKernelArg(kernel_intere,2,  sizeof(mem_KerConstStatic_InterE_atom_types_const),    &mem_KerConstStatic_InterE_atom_types_const);
	setKernelArg(kernel_intere,3,  sizeof(unsigned char),                          &dockpars.g1);
	setKernelArg(kernel_intere,4,  sizeof(unsigned int),                           &dockpars.g2);
	setKernelArg(kernel_intere,5,  sizeof(unsigned int),                           &dockpars.g3);
	setKernelArg(kernel_intere,6,  sizeof(unsigned char),                          &dockpars.num_of_atoms);
lvs's avatar
lvs committed
878
879

	#if defined (FIXED_POINT_INTERE)
880
881
882
	setKernelArg(kernel_intere,7,  sizeof(unsigned char),                          &gridsizex_minus1);
	setKernelArg(kernel_intere,8,  sizeof(unsigned char),                          &gridsizey_minus1);
	setKernelArg(kernel_intere,9,  sizeof(unsigned char),                          &gridsizez_minus1);
lvs's avatar
lvs committed
883
	#else
884
885
886
	setKernelArg(kernel_intere,7,  sizeof(float),                          	 &fgridsizex_minus1);
	setKernelArg(kernel_intere,8,  sizeof(float),                          	 &fgridsizey_minus1);
	setKernelArg(kernel_intere,9,  sizeof(float),                          	 &fgridsizez_minus1);
lvs's avatar
lvs committed
887
	#endif
lvs's avatar
lvs committed
888
889

	#if defined(SEPARATE_FGRID_INTERE)
890
891
	setKernelArg(kernel_intere,10, sizeof(mem_dockpars_fgrids2),                   &mem_dockpars_fgrids2);
	setKernelArg(kernel_intere,11, sizeof(mem_dockpars_fgrids3),                   &mem_dockpars_fgrids3);
lvs's avatar
lvs committed
892
	#else
893
894
	setKernelArg(kernel_intere,10, sizeof(unsigned int),                           &mul_tmp2);
	setKernelArg(kernel_intere,11, sizeof(unsigned int),                           &mul_tmp3);
lvs's avatar
lvs committed
895
	#endif
896
897
#endif // End of ENABLE_KRNL_INTERE

898
#ifdef ENABLE_KRNL_INTRAE
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
	setKernelArg(kernel_intrae,0,  sizeof(mem_KerConstStatic_IntraE_atom_charges_const),        &mem_KerConstStatic_IntraE_atom_charges_const);
	setKernelArg(kernel_intrae,1,  sizeof(mem_KerConstStatic_IntraE_atom_types_const),          &mem_KerConstStatic_IntraE_atom_types_const);
	setKernelArg(kernel_intrae,2,  sizeof(mem_KerConstStatic_intraE_contributors_const), &mem_KerConstStatic_intraE_contributors_const);

  	setKernelArg(kernel_intrae,3,  sizeof(dockpars.smooth),                              &dockpars.smooth);
  	setKernelArg(kernel_intrae,4,  sizeof(mem_KerConstStatic_reqm_const),                &mem_KerConstStatic_reqm_const);
  	setKernelArg(kernel_intrae,5,  sizeof(mem_KerConstStatic_reqm_hbond_const),          &mem_KerConstStatic_reqm_hbond_const);
  	setKernelArg(kernel_intrae,6,  sizeof(mem_KerConstStatic_atom1_types_reqm_const),    &mem_KerConstStatic_atom1_types_reqm_const);
  	setKernelArg(kernel_intrae,7,  sizeof(mem_KerConstStatic_atom2_types_reqm_const),    &mem_KerConstStatic_atom2_types_reqm_const);

	setKernelArg(kernel_intrae,8,  sizeof(mem_KerConstStatic_VWpars_AC_const),           &mem_KerConstStatic_VWpars_AC_const);
	setKernelArg(kernel_intrae,9,  sizeof(mem_KerConstStatic_VWpars_BD_const),           &mem_KerConstStatic_VWpars_BD_const);
	setKernelArg(kernel_intrae,10, sizeof(mem_KerConstStatic_dspars_S_const),            &mem_KerConstStatic_dspars_S_const);
	setKernelArg(kernel_intrae,11, sizeof(mem_KerConstStatic_dspars_V_const),            &mem_KerConstStatic_dspars_V_const);

	setKernelArg(kernel_intrae,12, sizeof(unsigned char),                    	       &dockpars.num_of_atoms);
	setKernelArg(kernel_intrae,13, sizeof(unsigned int),                     	       &dockpars.num_of_intraE_contributors);
	setKernelArg(kernel_intrae,14, sizeof(float),                          	       &dockpars.grid_spacing);
	setKernelArg(kernel_intrae,15, sizeof(unsigned char),                    	       &dockpars.num_of_atypes);
	setKernelArg(kernel_intrae,16, sizeof(float),                          	       &dockpars.coeff_elec);
	setKernelArg(kernel_intrae,17, sizeof(float),                          	       &dockpars.qasp);
920
	setKernelArg(kernel_intrae,18, sizeof(float),                          	       &dockpars.coeff_desolv);
921
922
#endif // End of ENABLE_KRNL_INTRAE

923
#ifdef ENABLE_KRNL_PRNG_BT_USHORT_FLOAT
924
925
926
927
928
929
930
	setKernelArg(kernel_prng_bt_ushort_float,2, sizeof(unsigned int),  &dockpars.pop_size);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_bt_ushort_float,3, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_BT_USHORT_FLOAT

931
#ifdef ENABLE_KRNL_PRNG_GG_UCHAR
932
933
934
935
936
937
	setKernelArg(kernel_prng_gg_uchar,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_gg_uchar,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_GG_UCHAR
lvs's avatar
lvs committed
938

939
#ifdef ENABLE_KRNL_PRNG_GG_FLOAT
940
	setKernelArg(kernel_prng_gg_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);
Leonardo Solis's avatar
Leonardo Solis committed
941
942

	#if !defined(SW_EMU)
943
	setKernelArg(kernel_prng_gg_float,2, sizeof(mem_dummy),   &mem_dummy);
Leonardo Solis's avatar
Leonardo Solis committed
944
	#endif
945
946
#endif // End of ENABLE_KRNL_PRNG_GG_FLOAT

947
#ifdef ENABLE_KRNL_PRNG_LS123_USHORT
948
949
950
951
952
953
954
	setKernelArg(kernel_prng_ls123_ushort,9, sizeof(unsigned int),  &dockpars.pop_size);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls123_ushort,10, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_LS123_USHORT

955
#ifdef ENABLE_KRNL_PRNG_LS_FLOAT
956
957
958
959
960
961
962
	setKernelArg(kernel_prng_ls_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls_float,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_LS_FLOAT

963
#ifdef ENABLE_KRNL_PRNG_LS2_FLOAT
964
965
966
967
968
969
970
	setKernelArg(kernel_prng_ls2_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls2_float,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_LS2_FLOAT

971
#ifdef ENABLE_KRNL_PRNG_LS3_FLOAT
972
973
974
975
976
977
978
	setKernelArg(kernel_prng_ls3_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls3_float,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_LS3_FLOAT

979
#ifdef ENABLE_KRNL_PRNG_LS4_FLOAT
980
981
982
983
984
985
986
	setKernelArg(kernel_prng_ls4_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls4_float,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_LS4_FLOAT

987
#ifdef ENABLE_KRNL_PRNG_LS5_FLOAT
988
989
990
991
992
993
994
	setKernelArg(kernel_prng_ls5_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls5_float,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
#endif // End of ENABLE_KRNL_PRNG_LS5_FLOAT

995
#ifdef ENABLE_KRNL_PRNG_LS6_FLOAT
996
997
998
999
1000
	setKernelArg(kernel_prng_ls6_float,1, sizeof(unsigned char),  &dockpars.num_of_genes);

	#if !defined(SW_EMU)
	setKernelArg(kernel_prng_ls6_float,2, sizeof(mem_dummy),   &mem_dummy);
	#endif
For faster browsing, not all history is shown. View entire blame