kernel1.cl 5.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*

OCLADock, an OpenCL implementation of AutoDock 4.2 running a Lamarckian Genetic Algorithm
Copyright (C) 2017 TU Darmstadt, Embedded Systems and Applications Group, Germany. All rights reserved.

AutoDock is a Trade Mark of the Scripps Research Institute.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/
Leonardo Solis's avatar
Leonardo Solis committed
23
__kernel void __attribute__ ((reqd_work_group_size(NUM_OF_THREADS_PER_BLOCK,1,1)))
24
25
gpu_calc_initpop(	
			char   dockpars_num_of_atoms,
Leonardo Solis's avatar
Leonardo Solis committed
26
27
28
29
30
			char   dockpars_num_of_atypes,
			int    dockpars_num_of_intraE_contributors,
			char   dockpars_gridsize_x,
			char   dockpars_gridsize_y,
			char   dockpars_gridsize_z,
31
32
33
							    		// g1 = gridsize_x
			uint   dockpars_gridsize_x_times_y, 		// g2 = gridsize_x * gridsize_y
			uint   dockpars_gridsize_x_times_y_times_z,	// g3 = gridsize_x * gridsize_y * gridsize_z
Leonardo Solis's avatar
Leonardo Solis committed
34
			float  dockpars_grid_spacing,
35
	 __global const float* restrict dockpars_fgrids, // This is too large to be allocated in __constant 
Leonardo Solis's avatar
Leonardo Solis committed
36
37
38
			int    dockpars_rotbondlist_length,
			float  dockpars_coeff_elec,
			float  dockpars_coeff_desolv,
39
40
41
	 __global const float* restrict dockpars_conformations_current,
	 __global       float* restrict dockpars_energies_current,
	 __global       int*   restrict dockpars_evals_of_new_entities,
Leonardo Solis's avatar
Leonardo Solis committed
42
43
			int    dockpars_pop_size,
			float  dockpars_qasp,
44
45
46
	     __constant float* atom_charges_const,
             __constant char*  atom_types_const,
	     __constant char*  intraE_contributors_const,
lvs's avatar
lvs committed
47
48
49
                      	float  dockpars_smooth,
	     __constant float* reqm,
	     __constant float* reqm_hbond,
50
51
52
53
54
55
56
57
58
59
60
             __constant float* VWpars_AC_const,
             __constant float* VWpars_BD_const,
             __constant float* dspars_S_const,
             __constant float* dspars_V_const,
             __constant int*   rotlist_const,
             __constant float* ref_coords_x_const,
             __constant float* ref_coords_y_const,
             __constant float* ref_coords_z_const,
             __constant float* rotbonds_moving_vectors_const,
             __constant float* rotbonds_unit_vectors_const,
             __constant float* ref_orientation_quats_const
Leonardo Solis's avatar
Leonardo Solis committed
61
){
62
63
64
65
        // Some OpenCL compilers don't allow declaring 
	// local variables within non-kernel functions.
	// These local variables must be declared in a kernel, 
	// and then passed to non-kernel functions.
66
	__local float  genotype[ACTUAL_GENOTYPE_LENGTH];
67
68
69
	__local float  energy;
	__local int    run_id;

Leonardo Solis's avatar
Leonardo Solis committed
70
71
72
73
	__local float calc_coords_x[MAX_NUM_OF_ATOMS];
	__local float calc_coords_y[MAX_NUM_OF_ATOMS];
	__local float calc_coords_z[MAX_NUM_OF_ATOMS];
	__local float partial_energies[NUM_OF_THREADS_PER_BLOCK];
74
75
76
	#if defined (DEBUG_ENERGY_KERNEL1)
	__local float partial_interE[NUM_OF_THREADS_PER_BLOCK];
	__local float partial_intraE[NUM_OF_THREADS_PER_BLOCK];
77
	#endif
Leonardo Solis's avatar
Leonardo Solis committed
78

79
	// Copying genotype from global memory
Leonardo Solis's avatar
Leonardo Solis committed
80
	event_t ev = async_work_group_copy(genotype,
Leonardo Solis's avatar
Leonardo Solis committed
81
82
			                   dockpars_conformations_current + GENOTYPE_LENGTH_IN_GLOBMEM*get_group_id(0),
			                   GENOTYPE_LENGTH_IN_GLOBMEM, 0);
Leonardo Solis's avatar
Leonardo Solis committed
83

84
85
	// Determining run-ID
	if (get_local_id(0) == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
86
		run_id = get_group_id(0) / dockpars_pop_size;
87
	}
Leonardo Solis's avatar
Leonardo Solis committed
88

lvs's avatar
lvs committed
89
90
91
	// Asynchronous copy should be finished by here
	wait_group_events(1,&ev);

92
93
94
	// Evaluating initial genotypes
	barrier(CLK_LOCAL_MEM_FENCE);

Leonardo Solis's avatar
Leonardo Solis committed
95
96
	// =============================================================
	gpu_calc_energy(dockpars_rotbondlist_length,
Leonardo Solis's avatar
Leonardo Solis committed
97
98
99
100
			dockpars_num_of_atoms,
			dockpars_gridsize_x,
			dockpars_gridsize_y,
			dockpars_gridsize_z,
101
102
103
							    	// g1 = gridsize_x
			dockpars_gridsize_x_times_y, 		// g2 = gridsize_x * gridsize_y
			dockpars_gridsize_x_times_y_times_z,	// g3 = gridsize_x * gridsize_y * gridsize_z
Leonardo Solis's avatar
Leonardo Solis committed
104
105
106
107
108
109
110
111
112
113
			dockpars_fgrids,
			dockpars_num_of_atypes,
			dockpars_num_of_intraE_contributors,
			dockpars_grid_spacing,
			dockpars_coeff_elec,
			dockpars_qasp,
			dockpars_coeff_desolv,
			genotype,
			&energy,
			&run_id,
114
115
116
117
			// Some OpenCL compilers don't allow declaring 
			// local variables within non-kernel functions.
			// These local variables must be declared in a kernel, 
			// and then passed to non-kernel functions.
Leonardo Solis's avatar
Leonardo Solis committed
118
119
120
121
			calc_coords_x,
			calc_coords_y,
			calc_coords_z,
			partial_energies,
122
			#if defined (DEBUG_ENERGY_KERNEL1)
123
124
125
			partial_interE,
			partial_intraE,
			#endif
Leonardo Solis's avatar
Leonardo Solis committed
126

Leonardo Solis's avatar
Leonardo Solis committed
127
128
129
	                atom_charges_const,
		        atom_types_const,
			intraE_contributors_const,
lvs's avatar
lvs committed
130
131
132
			dockpars_smooth,
			reqm,
			reqm_hbond,
Leonardo Solis's avatar
Leonardo Solis committed
133
134
135
136
137
138
139
140
141
142
			VWpars_AC_const,
			VWpars_BD_const,
			dspars_S_const,
			dspars_V_const,
			rotlist_const,
			ref_coords_x_const,
			ref_coords_y_const,
			ref_coords_z_const,
			rotbonds_moving_vectors_const,
			rotbonds_unit_vectors_const,
143
144
			ref_orientation_quats_const
			);
Leonardo Solis's avatar
Leonardo Solis committed
145
146
	// =============================================================

Leonardo Solis's avatar
Leonardo Solis committed
147
148
149
	if (get_local_id(0) == 0) {
		dockpars_energies_current[get_group_id(0)] = energy;
		dockpars_evals_of_new_entities[get_group_id(0)] = 1;
150
151
152
153

		#if defined (DEBUG_ENERGY_KERNEL1)
		printf("%-18s [%-5s]---{%-5s}   [%-10.8f]---{%-10.8f}\n", "-ENERGY-KERNEL1-", "GRIDS", "INTRA", partial_interE[0], partial_intraE[0]);
		#endif
Leonardo Solis's avatar
Leonardo Solis committed
154
	}
Leonardo Solis's avatar
Leonardo Solis committed
155
}