Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPU setting] device id #71

Merged
merged 1 commit into from
Feb 2, 2024
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
13 changes: 10 additions & 3 deletions unidock/src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ bug reporting, license agreements, and more information. \n";
std::string score_file("scores.txt");

positional_options_description positional; // remains empty
// GPU Device id to use
int device_id = 0;

options_description inputs("Input");
inputs.add_options()("receptor", value<std::string>(&rigid_name),
Expand Down Expand Up @@ -281,7 +283,9 @@ bug reporting, license agreements, and more information. \n";
"output filename (directory + prefix name) for maps. Option --force_even_voxels may be "
"needed to comply with .map format");
options_description advanced("Advanced options (see the manual)");
advanced.add_options()("score_only", bool_switch(&score_only),
advanced.add_options()("device_id", value<int>(&device_id)->default_value(0),
"GPU device id to use (default 0)")
("score_only", bool_switch(&score_only),
"score only - search space can be omitted")(
"score_file", value<std::string>(&score_file)->default_value(score_file),
"score only output file in batch mode, with 'score_only' option")(
Expand Down Expand Up @@ -498,7 +502,8 @@ bug reporting, license agreements, and more information. \n";

std::vector<double> box_size = {size_x, size_y, size_z};
simulation_container sc(seed, num_modes, refine_step, out_dir,
ligand_index, paired_batch_size, box_size, local_only, max_step, verbosity, exhaustiveness);
ligand_index, paired_batch_size, box_size, local_only, max_step,
verbosity, exhaustiveness, device_id);

int res = sc.prime();
if (res <= 0)
Expand Down Expand Up @@ -766,7 +771,9 @@ bug reporting, license agreements, and more information. \n";
if (sf_name.compare("ad4") == 0) ad4 = true;
cudaGetDeviceCount(&deviceCount);
if (deviceCount > 0) {
cudaSetDevice(0);
checkCUDA(cudaSetDevice(device_id));

printf("Set GPU device id to %d\n", device_id);
cudaMemGetInfo(&avail, &total);
printf("Available Memory = %dMiB Total Memory = %dMiB\n",
int(avail / 1024 / 1024), int(total / 1024 / 1024));
Expand Down
9 changes: 6 additions & 3 deletions unidock/src/main/simulation_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct simulation_container
int m_seed = 5;
int m_num_modes = 9;
int m_refine_steps = 3;
int m_device_id = 0;

std::vector<std::string> m_complex_names;
std::string m_config_json_path;
Expand All @@ -79,7 +80,8 @@ struct simulation_container
int local_only,
int max_step,
int verbosity,
int exh):
int exh,
int device_id):

m_seed(seed),
m_num_modes(num_modes),
Expand All @@ -93,7 +95,8 @@ struct simulation_container
m_verbosity(verbosity),
m_exhaustiveness(exh),
m_isGPU(true),
m_successful_property_count (0)
m_successful_property_count (0),
m_device_id(device_id)
{
//m_out_phrase = util_random_string(5);
}
Expand Down Expand Up @@ -490,7 +493,7 @@ struct simulation_container
vina_cuda_worker vcw(m_seed, m_num_modes, m_refine_steps, props[i].center_x, props[i].center_y,
props[i].center_z, props[i].protein_name,props[i].ligand_name,
local_only, std::vector<double>{props[i].box_x, props[i].box_y, props[i].box_z}, m_max_global_steps, m_verbosity,
m_exhaustiveness, workdir, input_dir, out_phrase);
m_exhaustiveness, workdir, input_dir, out_phrase, m_device_id);
try
{
int ret = vcw.launch();
Expand Down
6 changes: 5 additions & 1 deletion unidock/src/main/vina_cuda_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class vina_cuda_worker : public Vina
double center_z;
std::string protein_name;
std::string ligand_name;
int m_device_id = 0;
void init(std::string out_phrase)
{
out_dir = workdir + "/" + out_phrase;
Expand All @@ -88,6 +89,7 @@ class vina_cuda_worker : public Vina
boost::filesystem::create_directory(out_dir);
}
m_seed = seed;
checkCUDA(cudaSetDevice(m_device_id));
}
public:
vina_cuda_worker(
Expand All @@ -106,7 +108,8 @@ class vina_cuda_worker : public Vina
int exh,
std::string workdir,
std::string input_dir,
std::string out_phrase):
std::string out_phrase,
int device_id):

seed(seed),
num_modes(num_modes),
Expand All @@ -125,6 +128,7 @@ class vina_cuda_worker : public Vina
ligand_name(ligand_name),
local_only(local_only),
out_dir(out_phrase),
m_device_id(device_id),
Vina{"vina", 0, seed, verbosity, false, NULL}
{
init(out_phrase);
Expand Down
Loading