Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.OpenCL
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ LIB_OPENCL = -lOpenCL
UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
CPP = clang++
# In case ScoreP (for profiling/tracing) is used,
# need to link to a *.dylib for instrumentation
ifneq (,$(findstring scorep,$(CPP)))
Expand Down
2 changes: 1 addition & 1 deletion common/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum {C=0,N=1,O=2,H=3,XX=4,P=5,S=6}; // see "bond_index" in the "AD4.1_bound.da
#define MAX_INTRAE_CONTRIBUTORS (MAX_NUM_OF_ATOMS * MAX_NUM_OF_ATOMS)
#define MAX_NUM_OF_ROTATIONS (MAX_NUM_OF_ATOMS * MAX_NUM_OF_ROTBONDS)
#define MAX_POPSIZE 2048
#define MAX_NUM_OF_RUNS 1000
#define MAX_NUM_OF_RUNS 8192
#define MAX_NUM_GRIDPOINTS 256

// Must be larger than or equal to MAX_NUM_OF_ROTBONDS+6
Expand Down
6 changes: 3 additions & 3 deletions host/inc/autostop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class AutoStop{
inline void print_intro(unsigned long num_of_generations, unsigned long num_of_energy_evals)
{
para_printf("\nExecuting docking runs, stopping automatically after either reaching %.2f kcal/mol standard deviation of\nthe best molecules of the last 4 * %u generations, %lu generations, or %lu evaluations:\n\n",stopstd,as_frequency,num_of_generations,num_of_energy_evals);
para_printf("Generations | Evaluations | Threshold | Average energy of best 10%% | Samples | Best energy\n");
para_printf("Generations | Evaluations | Threshold | Average energy of best 10%% | Samples | Best Inter + Intra\n");
para_printf("------------+--------------+------------------+------------------------------+---------+-------------------\n");
}

Expand Down Expand Up @@ -221,7 +221,7 @@ class AutoStop{
inline void output_final_stddev(int generation_cnt, const float* energies, unsigned long total_evals){
if (autostopped){
para_printf("------------+--------------+------------------+------------------------------+---------+-------------------\n");
para_printf("\n%43s evaluation after reaching\n%40.2f +/-%8.2f kcal/mol combined.\n%34i samples, best energy %8.2f kcal/mol.\n","Finished",average(&average_sd2_N[0]),stddev(&average_sd2_N[0]),(unsigned int)average_sd2_N[2],overall_best_energy);
para_printf("\n%43s evaluation after reaching\n%40.2f +/-%8.2f kcal/mol combined.\n%31i samples, best inter + intra %8.2f kcal/mol.\n","Finished",average(&average_sd2_N[0]),stddev(&average_sd2_N[0]),(unsigned int)average_sd2_N[2],overall_best_energy);
} else {
// Stopped without autostop; output stddev statistics regardless

Expand All @@ -230,7 +230,7 @@ class AutoStop{

para_printf("%11u | %12lu |%8.2f kcal/mol |%8.2f +/-%8.2f kcal/mol |%8i |%8.2f kcal/mol\n",generation_cnt,total_evals/num_of_runs,threshold,curr_avg,curr_std,bestN,overall_best_energy);
para_printf("------------+--------------+------------------+------------------------------+---------+-------------------\n");
para_printf("\n%43s evaluation after reaching\n%33lu evaluations. Best energy %8.2f kcal/mol.\n","Finished",total_evals/num_of_runs,overall_best_energy);
para_printf("\n%43s evaluation after reaching\n%30lu evaluations. Best inter + intra %8.2f kcal/mol.\n","Finished",total_evals/num_of_runs,overall_best_energy);
}
fflush(stdout);
}
Expand Down
3 changes: 2 additions & 1 deletion host/inc/getparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ int get_commandpars(
char**,
double*,
Dockpars*,
const bool late_call = true
const bool late_call = true,
const int batch_nr = -1
);

std::vector<ReceptorAtom> read_receptor_atoms(
Expand Down
4 changes: 4 additions & 0 deletions host/inc/miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ void vec_point2line(const double [], const double [], const double [], double []

void rotate(double [], const double [], const double [], const double*, int);

bool is_dirname(const char* filename);

bool has_absolute_path(const char* filename);

std::string get_base_filename(const char* filename);

std::string get_filepath(const char* filename);

// trim input string range -- careful: no range checking
Expand Down
33 changes: 28 additions & 5 deletions host/src/getparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <algorithm>
#include <cctype>
#include <locale>
#include <sys/stat.h>

#include "getparameters.h"

Expand Down Expand Up @@ -1333,7 +1334,8 @@ int get_commandpars(
char** argv,
double* spacing,
Dockpars* mypars,
const bool late_call
const bool late_call,
const int batch_nr
)
// The function processes the command line arguments given with the argc and argv parameters,
// and fills the proper fields of mypars according to that. If a parameter was not defined
Expand All @@ -1353,22 +1355,22 @@ int get_commandpars(
char* basefile = mypars->ligandfile;
if(!mypars->free_roaming_ligand) basefile = mypars->flexresfile;
if(mypars->xrayligandfile==NULL){
mypars->xrayligandfile = strdup(basefile); // By default xray-ligand file is the same as the randomized input ligand
mypars->xrayligandfile = strdup(basefile); // By default xray-ligand file is the same as the randomized input ligand
}
if(mypars->xml2dlg){
if(strlen(mypars->load_xml)>4){ // .xml = 4 chars
i=strlen(mypars->load_xml)-4;
mypars->resname = (char*)malloc((i+1)*sizeof(char));
strncpy(mypars->resname,mypars->load_xml,i); // Default is ligand file basename
mypars->resname[i]='\0';
mypars->resname[i] = '\0';
} else if(!mypars->resname) mypars->resname = strdup("docking"); // Fallback to old default
} else{
if(!mypars->resname){ // only need to set if it's not set yet
if(strlen(basefile)>6){ // .pdbqt = 6 chars
i=strlen(basefile)-6;
mypars->resname = (char*)malloc((i+1)*sizeof(char));
strncpy(mypars->resname,basefile,i); // Default is ligand file basename
mypars->resname[i]='\0';
mypars->resname[i] = '\0';
} else mypars->resname = strdup("docking"); // Fallback to old default
}
}
Expand Down Expand Up @@ -1986,7 +1988,28 @@ int get_commandpars(
{
arg_recognized = 1;
free(mypars->resname); // as we assign a default value dynamically created to it
mypars->resname = strdup(argv [i+1]);
if(is_dirname(argv [i+1])){
struct stat res_stat;
int res_int = stat(argv [i+1], &res_stat);
if ((res_int != 0) || !(res_stat.st_mode & S_IFDIR)){
printf("\nError: Specified directory \"%s\" for output files with `--resnam` does not exist.\n",argv [i+1]);
exit(12);
}
char* basefile = mypars->ligandfile;
if(!mypars->free_roaming_ligand) basefile = mypars->flexresfile;
if(mypars->xml2dlg) basefile = mypars->load_xml;
std::string dir_res = get_filepath(argv [i+1]) + "/" + get_base_filename(basefile);
mypars->resname = strdup(dir_res.c_str());
} else{
if(batch_nr>0){
char* nrtmp = strdup(std::to_string(batch_nr).c_str());
mypars->resname = (char*)malloc((strlen(argv [i+1])+strlen(nrtmp)+2)*sizeof(char));
strcpy(mypars->resname, argv [i+1]);
strcat(mypars->resname,"_");
strcat(mypars->resname, nrtmp);
free(nrtmp);
} else mypars->resname = strdup(argv [i+1]);
}
}

// Argument: use modified QASP (from VirtualDrug) instead of original one used by AutoDock
Expand Down
12 changes: 11 additions & 1 deletion host/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int main(int argc, char* argv[])
}
#endif
// Set up run profiles for timing
bool get_profiles = true; // hard-coded switch to use ALS's job profiler
bool get_profiles = ((filelist.filename!=NULL) || (initial_pars.dpffile!=NULL)); // hard-coded switch to use ALS's job profiler
Profiler profiler;
for (int i=0;i<n_files;i++){
profiler.p.push_back(Profile(i));
Expand Down Expand Up @@ -410,6 +410,16 @@ int main(int argc, char* argv[])
para_printf(" Ligand file: %s\n", mypars.ligandfile); fflush(stdout);
if(mypars.flexresfile)
para_printf(" Flexible residue: %s\n", mypars.flexresfile);
if(mypars.output_dlg || mypars.output_xml){
para_printf(" Output file: %s", mypars.resname);
if(mypars.output_dlg){
para_printf(".dlg");
if(mypars.output_xml) para_printf(" (+ xml)");
} else{
if(mypars.output_xml) para_printf(".xml");
}
para_printf("\n");
}
fflush(stdout);
} else para_printf("\n");
// End idling timer, start exec timer
Expand Down
38 changes: 27 additions & 11 deletions host/src/miscellaneous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/


#include <sys/stat.h>

#include "miscellaneous.h"

float map2float(const char* c)
Expand Down Expand Up @@ -257,6 +259,15 @@ void rotate(double point [], const double movvec [], const double normvec [], co
point [0], point [1], point [2]);
}

bool is_dirname(const char* filename)
{
if((filename[strlen(filename)-1] == '/') ||
(filename[strlen(filename)-1] == '\\')) return true;
struct stat res_stat;
int res_int = stat(filename, &res_stat);
return (res_stat.st_mode & S_IFDIR);
}

bool has_absolute_path(const char* filename)
{
#ifndef _WIN32
Expand All @@ -269,19 +280,24 @@ bool has_absolute_path(const char* filename)
#endif
}

std::string get_base_filename(const char* filename)
{
std::string result = filename;
std::size_t path = result.find_last_of("/\\");
if(path == std::string::npos) path = 0; else path++;
result = result.substr(path);
return result.substr(0, result.find_last_of("."));
}

std::string get_filepath(const char* filename)
{
#ifndef _WIN32
char* ts1 = strdup(filename);
std::string result = dirname(ts1);
free(ts1);
return result;
#else
char drive_tmp[_MAX_DRIVE];
char path_tmp[_MAX_DIR];
_splitpath(filename, drive_tmp, path_tmp, NULL, NULL);
return drive_tmp + path_tmp;
#endif
std::string result = filename;
std::size_t path = result.find_last_of("/\\");
if(path == std::string::npos){
if(is_dirname(filename)) return filename;
return ".";
}
return result.substr(0, path);
}

#if 0
Expand Down
72 changes: 35 additions & 37 deletions host/src/performdocking.cpp.Cuda
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,6 @@ void setup_gpu_for_docking(
status = cudaMalloc((void**)&(tData.pMem_fgrids), cData.preallocated_gridsize*sizeof(float));
RTERROR(status, "pMem_fgrids: failed to allocate GPU memory.\n");
}
size_t size_populations = MAX_NUM_OF_RUNS * MAX_POPSIZE * GENOTYPE_LENGTH_IN_GLOBMEM*sizeof(float);
status = cudaMalloc((void**)&(tData.pMem_conformations1), size_populations);
RTERROR(status, "pMem_conformations1: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_conformations2), size_populations);
RTERROR(status, "pMem_conformations2: failed to allocate GPU memory.\n");
size_t size_energies = MAX_POPSIZE * MAX_NUM_OF_RUNS * sizeof(float);
status = cudaMalloc((void**)&(tData.pMem_energies1), size_energies);
RTERROR(status, "pMem_energies1: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_energies2), size_energies);
RTERROR(status, "pMem_energies2: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_evals_of_new_entities), MAX_POPSIZE*MAX_NUM_OF_RUNS*sizeof(int));
RTERROR(status, "pMem_evals_of_new_Entities: failed to allocate GPU memory.\n");
size_t size_evals_of_runs = MAX_NUM_OF_RUNS*sizeof(int);
#if defined (MAPPED_COPY)
status = cudaMallocManaged((void**)&(tData.pMem_gpu_evals_of_runs), size_evals_of_runs, cudaMemAttachGlobal);
#else
status = cudaMalloc((void**)&(tData.pMem_gpu_evals_of_runs), size_evals_of_runs);
#endif
RTERROR(status, "pMem_gpu_evals_of_runs: failed to allocate GPU memory.\n");
size_t blocksPerGridForEachEntity = MAX_POPSIZE * MAX_NUM_OF_RUNS;
size_t size_prng_seeds = blocksPerGridForEachEntity * NUM_OF_THREADS_PER_BLOCK * sizeof(unsigned int);
status = cudaMalloc((void**)&(tData.pMem_prng_states), size_prng_seeds);
RTERROR(status, "pMem_prng_states: failed to allocate GPU memory.\n");
}
void finish_gpu_from_docking(
GpuData& cData,
Expand Down Expand Up @@ -241,20 +218,6 @@ void finish_gpu_from_docking(
status = cudaFree(tData.pMem_fgrids);
RTERROR(status, "cudaFree: error freeing pMem_fgrids");
}
status = cudaFree(tData.pMem_conformations1);
RTERROR(status, "cudaFree: error freeing pMem_conformations1");
status = cudaFree(tData.pMem_conformations2);
RTERROR(status, "cudaFree: error freeing pMem_conformations2");
status = cudaFree(tData.pMem_energies1);
RTERROR(status, "cudaFree: error freeing pMem_energies1");
status = cudaFree(tData.pMem_energies2);
RTERROR(status, "cudaFree: error freeing pMem_energies2");
status = cudaFree(tData.pMem_evals_of_new_entities);
RTERROR(status, "cudaFree: error freeing pMem_evals_of_new_entities");
status = cudaFree(tData.pMem_gpu_evals_of_runs);
RTERROR(status, "cudaFree: error freeing pMem_gpu_evals_of_runs");
status = cudaFree(tData.pMem_prng_states);
RTERROR(status, "cudaFree: error freeing pMem_prng_states");
free(tData.device_name);
}

Expand Down Expand Up @@ -357,6 +320,26 @@ parameters argc and argv:
size_evals_of_runs = mypars->num_of_runs*sizeof(int);
sim_state.cpu_evals_of_runs.resize(size_evals_of_runs);
memset(sim_state.cpu_evals_of_runs.data(), 0, size_evals_of_runs);

// allocating memory blocks for GPU
status = cudaMalloc((void**)&(tData.pMem_conformations1), size_populations);
RTERROR(status, "pMem_conformations1: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_conformations2), size_populations);
RTERROR(status, "pMem_conformations2: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_energies1), size_energies);
RTERROR(status, "pMem_energies1: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_energies2), size_energies);
RTERROR(status, "pMem_energies2: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_evals_of_new_entities), MAX_POPSIZE*MAX_NUM_OF_RUNS*sizeof(int));
RTERROR(status, "pMem_evals_of_new_Entities: failed to allocate GPU memory.\n");
#if defined (MAPPED_COPY)
status = cudaMallocManaged((void**)&(tData.pMem_gpu_evals_of_runs), size_evals_of_runs, cudaMemAttachGlobal);
#else
status = cudaMalloc((void**)&(tData.pMem_gpu_evals_of_runs), size_evals_of_runs);
#endif
RTERROR(status, "pMem_gpu_evals_of_runs: failed to allocate GPU memory.\n");
status = cudaMalloc((void**)&(tData.pMem_prng_states), size_prng_seeds);
RTERROR(status, "pMem_prng_states: failed to allocate GPU memory.\n");

// preparing the constant data fields for the GPU
kernelconstant_interintra* KerConst_interintra = new kernelconstant_interintra;
Expand Down Expand Up @@ -893,6 +876,21 @@ parameters argc and argv:

free(cpu_prng_seeds);

status = cudaFree(tData.pMem_conformations1);
RTERROR(status, "cudaFree: error freeing pMem_conformations1");
status = cudaFree(tData.pMem_conformations2);
RTERROR(status, "cudaFree: error freeing pMem_conformations2");
status = cudaFree(tData.pMem_energies1);
RTERROR(status, "cudaFree: error freeing pMem_energies1");
status = cudaFree(tData.pMem_energies2);
RTERROR(status, "cudaFree: error freeing pMem_energies2");
status = cudaFree(tData.pMem_evals_of_new_entities);
RTERROR(status, "cudaFree: error freeing pMem_evals_of_new_entities");
status = cudaFree(tData.pMem_gpu_evals_of_runs);
RTERROR(status, "cudaFree: error freeing pMem_gpu_evals_of_runs");
status = cudaFree(tData.pMem_prng_states);
RTERROR(status, "cudaFree: error freeing pMem_prng_states");

delete KerConst_interintra;
delete KerConst_intracontrib;
delete KerConst_intra;
Expand Down
37 changes: 1 addition & 36 deletions host/src/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <sys/stat.h>

#include "filelist.hpp"
#include "processgrid.h"
Expand Down Expand Up @@ -345,43 +344,9 @@ int setup(
//------------------------------------------------------------
// Capturing algorithm parameters (command line args)
//------------------------------------------------------------
char* orig_resname;
if(mypars->resname)
orig_resname = strdup(mypars->resname); // need to copy it since it might get free'd in the next line
else
orig_resname = strdup(""); // need an empty string for later if no resname has been specified

if(get_commandpars(&argc, argv, &(mygrid->spacing), mypars)<0)
if(get_commandpars(&argc, argv, &(mygrid->spacing), mypars, true, (filelist.nfiles>1)?i_file+1:0)<0)
return 1;

// command-line specified resname with more than one file
if (!mypars->xml2dlg){ // if the user specified an xml file, that's the one we want to use
if ((strcmp(orig_resname,mypars->resname)!=0) && (filelist.nfiles>1)){ // use resname as prefix
char* tmp = (char*)malloc(strlen(mypars->resname)+strlen(orig_resname)+1);
// take care of potential directory path
long long dir = strrchr(orig_resname,'/')-orig_resname+1;
if(dir>0){
strncpy(tmp, orig_resname, dir);
tmp[dir]='\0';
strcat(tmp, mypars->resname);
strcat(tmp, &orig_resname[dir]);
} else{
strcpy(tmp, mypars->resname);
strcat(tmp, orig_resname);
}
free(mypars->resname);
mypars->resname = tmp;
}
}
free(orig_resname);

struct stat res_stat;
int res_int = stat(get_filepath(mypars->resname).c_str(), &res_stat);
if ((res_int != 0) || !(res_stat.st_mode & S_IFDIR)){
printf("\nError: Specified directory \"%s\" for output files (e.g. with `--resnam`) does not exist.\n",get_filepath(mypars->resname).c_str());
exit(11);
}

Gridinfo mydummygrid;
// if -lxrayfile provided, then read xray ligand data
if (mypars->given_xrayligandfile)
Expand Down