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 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 CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Version 2022-dev
- adapted tokenizer api (#707)
- move OpenMP detection to tools (#709)
- refactored applications (#710)
- add command line option for number of gpus (#711)

Version 2021.1 (released XX.03.21)
==================================
Expand Down
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
24 changes: 23 additions & 1 deletion 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
5 changes: 4 additions & 1 deletion src/libxtp/xtpapplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <votca/tools/propertyiomanipulator.h>

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

namespace votca {
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