Commit 2bc7c000 authored by lvs's avatar lvs
Browse files

first pipe usage in kernel

parent 5a625be3
This diff is collapsed.
/*
* (C) 2013. Evopro Innovation Kft.
*
* calcenergy.h
*
* Created on: 2010.04.20.
* Author: pechan.imre
*/
#ifndef CALCENERGY_H_
#define CALCENERGY_H_
#include <math.h>
#include <stdio.h>
#include "defines.h"
#include "miscellaneous.h"
#include "processligand.h"
#include "getparameters.h"
// This struct is passed to the GPU global functions (OpenCL kernels) as input.
// Its members are parameters related to the ligand, the grid
// and the genetic algorithm, or they are pointers of GPU (ADM FPGA) memory areas
// used for storing different data such as the current
// and the next population genotypes and energies, the grids,
// the evaluation counters and the random number generator states.
typedef struct
{
unsigned char num_of_atoms;
unsigned char num_of_atypes;
unsigned int num_of_intraE_contributors;
unsigned char gridsize_x;
unsigned char gridsize_y;
unsigned char gridsize_z;
unsigned char g1;
unsigned int g2;
unsigned int g3;
float grid_spacing;
unsigned int rotbondlist_length;
float coeff_elec;
float coeff_desolv;
/*
float* conformations_current;
float* energies_current;
float* conformations_next;
float* energies_next;
int* evals_of_new_entities;
unsigned int* prng_states;
*/
// L30nardoSV added
unsigned int num_of_energy_evals;
unsigned int num_of_generations;
unsigned int pop_size;
unsigned int num_of_genes;
float tournament_rate;
float crossover_rate;
float mutation_rate;
float abs_max_dmov;
float abs_max_dang;
float lsearch_rate;
unsigned int num_of_lsentities;
float rho_lower_bound;
float base_dmov_mul_sqrt3;
float base_dang_mul_sqrt3;
unsigned int cons_limit;
unsigned int max_num_of_iters;
float qasp;
} Dockparameters;
// ----------------------------------------------------------------------
// L30nardoSV modified
// 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() was called),
// so we can send them to kernels from <here>, instead of from calcenergy.cpp
// as originally.
// ----------------------------------------------------------------------
// Constant struct
/*
typedef struct
{
float atom_charges_const[MAX_NUM_OF_ATOMS];
char atom_types_const [MAX_NUM_OF_ATOMS];
char intraE_contributors_const[3*MAX_INTRAE_CONTRIBUTORS];
float VWpars_AC_const [MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES];
float VWpars_BD_const [MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES];
float dspars_S_const [MAX_NUM_OF_ATYPES];
float dspars_V_const [MAX_NUM_OF_ATYPES];
int rotlist_const [MAX_NUM_OF_ROTATIONS];
float ref_coords_x_const[MAX_NUM_OF_ATOMS];
float ref_coords_y_const[MAX_NUM_OF_ATOMS];
float ref_coords_z_const[MAX_NUM_OF_ATOMS];
float rotbonds_moving_vectors_const[3*MAX_NUM_OF_ROTBONDS];
float rotbonds_unit_vectors_const [3*MAX_NUM_OF_ROTBONDS];
//float ref_orientation_quats_const [4*MAX_NUM_OF_RUNS];
float ref_orientation_quats_const [4];
} kernelconstant;
*/
#include "CL/opencl.h"
#if defined (FIXED_POINT_CONFORM) || defined (FIXED_POINT_LS1) || defined (FIXED_POINT_LS2) || defined (FIXED_POINT_LS3)
#include "defines_fixedpt.h"
#endif
#if defined (FIXED_POINT_INTERE) || (FIXED_POINT_INTRAE)
#include "defines_fixedpt_64.h"
#endif
// As struct members are used as host buffers
// they are aligned to multiples of 64 bytes (power of 2).
// This solves aligment problem
typedef struct
{
#if defined (FIXED_POINT_INTERE)
fixedpt64 fixpt64_atom_charges_const[MAX_NUM_OF_ATOMS] __attribute__ ((aligned (1024)));
#endif
float atom_charges_const[MAX_NUM_OF_ATOMS] __attribute__ ((aligned (512)));
char atom_types_const [MAX_NUM_OF_ATOMS] __attribute__ ((aligned (128)));
/*
char intraE_contributors_const[3*MAX_INTRAE_CONTRIBUTORS] __attribute__ ((aligned (32768)));
*/
cl_char3 intraE_contributors_const[MAX_INTRAE_CONTRIBUTORS] __attribute__ ((aligned (32768)));
float VWpars_AC_const [MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES] __attribute__ ((aligned (1024)));
float VWpars_BD_const [MAX_NUM_OF_ATYPES*MAX_NUM_OF_ATYPES] __attribute__ ((aligned (1024)));
float dspars_S_const [MAX_NUM_OF_ATYPES] __attribute__ ((aligned (64)));
float dspars_V_const [MAX_NUM_OF_ATYPES] __attribute__ ((aligned (64)));
int rotlist_const [MAX_NUM_OF_ROTATIONS] __attribute__ ((aligned (4096)));
#if defined (FIXED_POINT_CONFORM)
// fixed-point
cl_int3 ref_coords_const[MAX_NUM_OF_ATOMS] __attribute__ ((aligned (2048)));
cl_int3 rotbonds_moving_vectors_const[MAX_NUM_OF_ROTBONDS] __attribute__ ((aligned (512)));
cl_int3 rotbonds_unit_vectors_const [MAX_NUM_OF_ROTBONDS] __attribute__ ((aligned (512)));
#else
// floating-point (original)
cl_float3 ref_coords_const[MAX_NUM_OF_ATOMS] __attribute__ ((aligned (2048)));
cl_float3 rotbonds_moving_vectors_const[MAX_NUM_OF_ROTBONDS] __attribute__ ((aligned (512)));
cl_float3 rotbonds_unit_vectors_const [MAX_NUM_OF_ROTBONDS] __attribute__ ((aligned (512)));
#endif
#if defined(SINGLE_COPY_POP_ENE)
#if defined (FIXED_POINT_CONFORM)
// fixed-point
//fixedpt ref_orientation_quats_const [4*MAX_NUM_OF_RUNS] __attribute__ ((aligned (512)));
cl_int4 ref_orientation_quats_const [MAX_NUM_OF_RUNS] __attribute__ ((aligned (512)));
#else
// floating-point (original)
//float ref_orientation_quats_const [4*MAX_NUM_OF_RUNS] __attribute__ ((aligned (512)));
cl_float4 ref_orientation_quats_const [MAX_NUM_OF_RUNS] __attribute__ ((aligned (512)));
#endif
#endif
} kernelconstant_static;
// As struct members are used as host buffers
// they are aligned to multiples of 64 bytes (power of 2).
// This is added for the sake of completion
// cl_float3 is made of 4 floats, its size is 16 bytes
#if defined(SINGLE_COPY_POP_ENE)
#else
typedef struct
{
#if defined (FIXED_POINT_CONFORM)
// fixed-point
fixedpt ref_orientation_quats_const [4] __attribute__ ((aligned (64)));
#else
// floating-point (original)
float ref_orientation_quats_const [4] __attribute__ ((aligned (64)));
#endif
} kernelconstant_dynamic;
#endif
/*
int prepare_const_fields_for_gpu(Liganddata* myligand_reference,
Dockpars* mypars,
float* cpu_ref_ori_angles,
kernelconstant* KerConst);
*/
int prepare_conststatic_fields_for_gpu(Liganddata* myligand_reference,
Dockpars* mypars,
#if defined(SINGLE_COPY_POP_ENE)
float* cpu_ref_ori_angles,
#endif
kernelconstant_static* KerConstStatic);
#if defined(SINGLE_COPY_POP_ENE)
#else
int prepare_constdynamic_fields_for_gpu(Liganddata* myligand_reference,
Dockpars* mypars,
float* cpu_ref_ori_angles,
kernelconstant_dynamic* KerConstDynamic);
#endif
void make_reqrot_ordering(char number_of_req_rotations[MAX_NUM_OF_ATOMS],
char atom_id_of_numrots[MAX_NUM_OF_ATOMS],
int num_of_atoms);
int gen_rotlist(Liganddata* myligand,
int rotlist[MAX_NUM_OF_ROTATIONS]);
#endif /* CALCENERGY_H_ */
/*
* (C) 2013. Evopro Innovation Kft.
*
* getparameters.h
*
* Created on: 2008.10.22.
* Author: pechan.imre
*/
#ifndef GETPARAMETERS_H_
#define GETPARAMETERS_H_
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "defines.h"
#include "processligand.h"
#include "processgrid.h"
#include "miscellaneous.h"
typedef struct
{
double AD4_coeff_vdW;
double AD4_coeff_hb;
double scaled_AD4_coeff_elec;
double AD4_coeff_desolv;
double AD4_coeff_tors;
} AD4_free_energy_coeffs;
typedef struct
//Struct which contains the docking parameters (partly parameters for fpga)
{
unsigned long num_of_energy_evals;
unsigned long num_of_generations;
float abs_max_dmov;
float abs_max_dang;
float mutation_rate;
float crossover_rate;
float lsearch_rate;
unsigned long num_of_ls;
float tournament_rate;
float rho_lower_bound;
float base_dmov_mul_sqrt3;
float base_dang_mul_sqrt3;
unsigned long cons_limit;
unsigned long max_num_of_iters;
unsigned long pop_size;
char initpop_gen_or_loadfile;
char gen_pdbs;
char fldfile [128];
char ligandfile [128];
float ref_ori_angles [3];
unsigned long num_of_runs;
char reflig_en_reqired;
char unbound_model;
AD4_free_energy_coeffs coeffs;
char handle_symmetry;
char gen_finalpop;
char gen_best;
char resname [128];
float qasp;
float rmsd_tolerance;
} Dockpars;
int get_filenames_and_ADcoeffs(const int*,
char**,
Dockpars*);
void get_commandpars(const int*,
char**,
double*,
Dockpars*);
void gen_initpop_and_reflig(Dockpars* mypars,
float* init_populations,
float* ref_ori_angles,
Liganddata* myligand,
const Gridinfo* mygrid);
#endif /* GETPARAMETERS_H_ */
/*
* (C) 2013. Evopro Innovation Kft.
*
* miscallenous.h
*
* Created on: 2008.09.29.
* Author: pechan.imre
*/
#ifndef MISCELLANEOUS_H_
#define MISCELLANEOUS_H_
#include <time.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define PI 3.1415926535
//Visual C++ linear congruential generator constants
#define RAND_A_GS 214013u
#define RAND_C_GS 2531011u
typedef struct
//Struct which describes a quaternion.
{
double q;
double x;
double y;
double z;
} Quaternion;
#define trilin_interpol(cube, weights) (cube[0][0][0]*weights[0][0][0] +cube[1][0][0]*weights[1][0][0] +cube[0][1][0]*weights[0][1][0] +cube[1][1][0]*weights[1][1][0] +cube[0][0][1]*weights[0][0][1] +cube[1][0][1]*weights[1][0][1] +cube[0][1][1]*weights[0][1][1] +cube[1][1][1]*weights[1][1][1])
//macro that calculates the trilinear interpolation,
//the first parameter is a 2*2*2 array of the values of the function
//in the vertices of the cube,
//and the second one is a 2*2*2 array of the interpolation weights
int float2fracint(double, int);
long long float2fraclint(double, int);
//double timer_gets(void);
double myrand(void);
unsigned int myrand_int(unsigned int);
double distance(const double [], const double []);
void vec_point2line(const double [], const double [], const double [], double []);
void rotate(double [], const double [], const double [], const double*, int);
double angle_of_vectors(const double [], const double []);
void vec_crossprod(const double [], const double [], double []);
void get_trilininterpol_weights(double [][2][2], const double*, const double*, const double*);
void get_trilininterpol_weights_f(float [][2][2], const float*, const float*, const float*);
void print_binary_string(unsigned long long);
int stricmp(const char*, const char*);
unsigned int genseed(unsigned int init);
#endif /* MISCELLANEOUS_H_ */
/*
* (C) 2013. Evopro Innovation Kft.
*
* performdocking.h
*
* Created on: 2010.05.26.
* Author: pechan.imre
*/
#ifndef PERFORMDOCKING_H_
#define PERFORMDOCKING_H_
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include <math.h>
#include "processgrid.h"
#include "miscellaneous.h"
#include "processligand.h"
#include "getparameters.h"
#include "calcenergy.h"
#include "processresult.h"
#include <CL/opencl.h>
//#include "commonMacros.h"
//#include "listAttributes.h"
//#include "Platforms.h"
//#include "Devices.h"
//#include "Contexts.h"
//#include "CommandQueues.h"
//#include "Programs.h"
#include "Kernels.h"
//#include "ImportBinary.h"
//#include "ImportSource.h"
#include "BufferObjects.h"
#define ELAPSEDSECS(stop,start) ((float) stop-start)/((float) CLOCKS_PER_SEC)
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);
double check_progress(int* evals_of_runs,
int generation_cnt,
int max_num_of_evals,
int max_num_of_gens,
int num_of_runs);
#endif /* PERFORMDOCKING_H_ */
/*
* (C) 2013. Evopro Innovation Kft.
*
* processgrid.h
*
* Created on: 2008.09.30.
* Author: pechan.imre
*/
#ifndef PROCESSGRID_H_
#define PROCESSGRID_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
// L30nardoSV
#include <libgen.h>
// libgen.h contains basename() and dir() from a fullpath name
// Specific: to open correctly grid map field fiels and associated files
// Not only during real execution but also SDAccel cpu-, hw-emulation
// http://ask.systutorials.com/681/get-the-directory-path-and-file-name-from-absolute-path-linux
#include "miscellaneous.h"
#define getvalue_4Darr(mempoi, grinf, t, z, y, x) *(mempoi + (grinf).size_xyz[0] * (y + (grinf).size_xyz[1] * (z + (grinf).size_xyz[2]*t)) + x)
#define getvalue_4Darr_withsize(mempoi, gridsize_xyz, t, z, y, x) *(mempoi + gridsize_xyz[0]*(y + gridsize_xyz[1] * (z + gridsize_xyz[2]*t)) + x)
//The macro helps to access the grid point values
//which were read from external files with get_gridvalues function.
//The first parameter is a pointer which points to the memory area storing the data.
//The second one is the corresponding grid info (parameter of get_gridinfo function).
//The other parameters are the type index, z, y and x coordinates of the grid point.
typedef struct
//Struct which can contain all the important informations which derives from .gpf and .xyz files.
{
// L30nardoSV
char* grid_file_path; // Added to store the full path of the grid file
char receptor_name [64];
int size_xyz [3];
double spacing;
double size_xyz_angstr [3];
char grid_types [16][3];
int num_of_atypes;
double origo_real_xyz [3];
} Gridinfo;
int get_gridinfo(const char*, Gridinfo*);
int get_gridvalues_f(const Gridinfo* mygrid,
float** fgrids);
#endif /* PROCESSGRID_H_ */
/*
* (C) 2013. Evopro Innovation Kft.
*
* processligand.h
*
* Created on: 2008.09.30.
* Author: pechan.imre
*/
#ifndef PROCESSLIGAND_H_
#define PROCESSLIGAND_H_
#include "defines.h"
#include "processgrid.h"
#include "miscellaneous.h"
#define ATYPE_NUM 22
typedef struct
//Struct which contains ligand information. The fields contain the following information:
//num_of_atoms: Number of ligand atoms.
//num_of_atypes: Number of different atom types in the ligand.
//num_of_rotbonds: Number of rotatable bonds in the ligand.
//atom_types: Each row (first index) contain an atom type (as two characters),
// the row index is equal to the atom type code.
//atom_idxyzq: Each row describes one atom of the ligand.
// The columns (second index) contain the atom type code, x, y and z coordinate
// (in Angstroms) and electrical charge of the atom.
// The row index is equal to the index of the current atom.
//rotbonds: Each row corresponds to one rotatable bond of the ligand.
// The rotatable bond is described with the indexes of the
// two atoms which are connected to each other by the bond.
// The row index is equal to the index of the rotatable bond.
//atom_rotbonds: The array contains the rotatable bonds - atoms assignment.
// If the element atom_rotbonds[atom index][rotatable bond index] is equal to 1,
// it means,that the atom must be rotated if the bond rotates.
// A 0 means the opposite.
//atom_rigid_structures: The array contains the ridig structure ID of the atoms.
// If the atom_rigid_structures[atom1 index] = atom_rigid_structures[atom2 index],
// it means, that the atoms are in the same rigid molecule fragment.
// Rigid structures are seperated by branches in the pdbqt file.
//bonds: If the element bonds[atom index][atom index] is equal to 1,
// a bond exists between the atoms.
//intraE_contributors: If the element [atom index][atom index] is equal to 1,
// the energy contribution of the two atoms must be included in
// intramolecular energy calculation,
// which requires that there is at least one rotatable bond between the atoms and
// their interaction type is not 1-2, 1-3 or 1-4
//VWpars_x: The matrices contain the A, B, C and D Van der Waals parameters for the ligand atom types.
// The VWpars_A [atom type code of atom 1][atom type code of atom 2] element is equal
// to the A parameter for these types, the VWpars_B contains the B parameters in the
// same manner etc.
//volume, solpar: these fields are similar to VWpars_x-s,
// they contain the atoms' volume and solvation parameter.
//num_of_rotations_required:
//num_of_intraE_contributors:
//rotbonds_moving_vectors, rotbonds_unit_vectors: the vectors required for rotation around the
// corresponding rotatable bond (the first index is
// the index of the rotatable bond). When rotating
// a point around the bond with ID i, first it must be moved
// according to rotbonds_moving_vectors [i], then must be rotated
// around the line which crosses the origo and is parallel to
// rotbonds_unit_vectors [i], then it must be moved back with
// -1*rotbonds_moving_vectors [i].
// WARNING: after calling calc_conform for a Liganddata structure,
// the orientation of the molecule will be changed, and these
// vecotrs will be unvalid, so they must be calculated again if
// it is necessary.
{
int num_of_atoms;
int num_of_atypes;
int num_of_rotbonds;
char atom_types [14][3]; //in the case of arrays, the first index is called row index,
double atom_idxyzq [256][5]; //the second is called column index
int rotbonds [32][2];
char atom_rotbonds [256][32];
int atom_rigid_structures [256];
char bonds [256][256];
char intraE_contributors [256][256];
double VWpars_A [14][14];
double VWpars_B [14][14];
double VWpars_C [14][14];
double VWpars_D [14][14];
double volume [14];
double solpar [14];
int num_of_rotations_required;
int num_of_intraE_contributors;
int num_of_rotcyc;
double rotbonds_moving_vectors [32][3];
double rotbonds_unit_vectors [32][3];
} Liganddata;
int init_liganddata(const char*, Liganddata*, Gridinfo*);
int set_liganddata_typeid(Liganddata*, int, const char*);
void get_intraE_contributors(Liganddata*);
int get_bonds(Liganddata*);
int get_VWpars(Liganddata*, const double, const double);
void get_moving_and_unit_vectors(Liganddata*);
int get_liganddata(const char*, Liganddata*, const double, const double);
int gen_new_pdbfile(const char*, const char*, const Liganddata*);
void get_movvec_to_origo(const Liganddata*, double []);
void move_ligand(Liganddata*, const double []);
void scale_ligand(Liganddata*, const double);
double calc_rmsd(const Liganddata*, const Liganddata*, const int);
double calc_ddd_Mehler_Solmajer(double);
int is_H_bond(const char*, const char*);
void print_ref_lig_energies_f(Liganddata,
Gridinfo,
const float*,
const float,
const float,
const float);