Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

add command line option #711

Merged
merged 4 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion include/votca/xtp/cudamatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CudaMatrix {

void reshape(Index rows, Index cols) {
assert(rows * cols == size() &&
"reshape cannot change the shape of the matrix");
"reshape cannot change the size of the matrix only the shape");
_cols = cols;
_ld = rows;
}
Expand Down
1 change: 1 addition & 0 deletions include/votca/xtp/cudapipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CudaPipeline {
cublasHandle_t _handle;

// Asynchronous stream

cudaStream_t _stream;
};

Expand Down
12 changes: 5 additions & 7 deletions include/votca/xtp/openmp_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ namespace xtp {
class OpenMP_CUDA {
public:
OpenMP_CUDA();
static Index UsingGPUs() {
#ifdef USE_CUDA
return count_available_gpus();
#else
return 0;
#endif
}
static Index UsingGPUs();
static Index AvailableGPUs();
static void SetNoGPUs(Index number);

// 3c multiply
void setOperators(const std::vector<Eigen::MatrixXd>& tensor,
Expand Down Expand Up @@ -155,6 +151,8 @@ class OpenMP_CUDA {
bool inside_Parallel_region_;
Index threadID_parent_;

static Index number_of_gpus;

Index getParentThreadId(Index OpenmpThreadId) const;

Index getLocalThreadId(Index ParentThreadId) const;
Expand Down
27 changes: 25 additions & 2 deletions src/libxtp/openmp_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@
namespace votca {
namespace xtp {

// Has to be declared because of
// https://stackoverflow.com/questions/9110487/undefined-reference-to-a-static-member
Index OpenMP_CUDA::number_of_gpus=0;

Index OpenMP_CUDA::UsingGPUs() { return number_of_gpus; }

Index OpenMP_CUDA::AvailableGPUs() {
#ifdef USE_CUDA
return count_available_gpus();
#else
return 0;
#endif
}

void OpenMP_CUDA::SetNoGPUs(Index number) {
if (number < 0 || number > AvailableGPUs()) {
number_of_gpus = AvailableGPUs();
} else {
number_of_gpus = number;
}
}

OpenMP_CUDA::OpenMP_CUDA() {

inside_Parallel_region_ = OPENMP::InsideActiveParallelRegion();
Expand All @@ -31,7 +53,7 @@ OpenMP_CUDA::OpenMP_CUDA() {
cpus_.resize(getNumberThreads());

#ifdef USE_CUDA
Index no_gpus = count_available_gpus();
Index no_gpus = UsingGPUs();
gpus_.clear();
if (inside_Parallel_region_) {
if (threadID_parent_ < no_gpus) {
Expand Down Expand Up @@ -465,7 +487,8 @@ Eigen::MatrixXd OpenMP_CUDA::getReductionVar() {
for (Index i = 0; i < Index(gpus_.size()); i++) {
GPU_data& gpu = gpus_[i];
gpu.activateGPU();
cpus_[i].reduce() = *(gpu.temp.back());
Eigen::MatrixXd temp=*(gpu.temp.back());
JensWehner marked this conversation as resolved.
Show resolved Hide resolved
cpus_[i].reduce()+=temp;
}
#endif
for (Index i = 1; i < Index(cpus_.size()); i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/libxtp/xtpapplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

// Local VOTCA includes
#include "votca/xtp/version.h"
#include "votca/xtp/votca_xtp_config.h"
#include "votca/xtp/xtpapplication.h"
#include "votca/xtp/openmp_cuda.h"

namespace votca {
namespace xtp {
Expand Down Expand Up @@ -79,6 +79,9 @@ bool XtpApplication::EvaluateOptions() {
StopExecution();
return true;
}
#ifdef USE_CUDA
OpenMP_CUDA::SetNoGPUs(OptionsMap()["gpus"].as<Index>());
#endif

if (OptionsMap().count("description")) {
CheckRequired("description", "no " + CalculatorType() + " is given");
Expand Down