Xmipp  v3.23.11-Nereus
Public Member Functions | Protected Member Functions | List of all members
Alignment::ProgAlignSignificantGPU< T > Class Template Reference

#include <align_significant_gpu.h>

Inheritance diagram for Alignment::ProgAlignSignificantGPU< T >:
Inheritance graph
[legend]
Collaboration diagram for Alignment::ProgAlignSignificantGPU< T >:
Collaboration graph
[legend]

Public Member Functions

void defineParams () override
 
void readParams () override
 
void show () const override
 
- Public Member Functions inherited from Alignment::AProgAlignSignificant< T >
virtual void run () override
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Protected Member Functions

std::vector< AlignmentEstimationalign (const T *ref, const T *others) override
 
void updateRefs (T *refs, const T *others, const std::vector< Assignment > &assignments) override
 
- Protected Member Functions inherited from Alignment::AProgAlignSignificant< T >
virtual void check () const
 
const SettingsgetSettings ()
 
ctpl::thread_poolgetThreadPool ()
 
void updateRefXmd (size_t refIndex, std::vector< Assignment > &images)
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 

Additional Inherited Members

- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

template<typename T>
class Alignment::ProgAlignSignificantGPU< T >

Definition at line 45 of file align_significant_gpu.h.

Member Function Documentation

◆ align()

template<typename T >
std::vector< AlignmentEstimation > Alignment::ProgAlignSignificantGPU< T >::align ( const T *  ref,
const T *  others 
)
overrideprotectedvirtual

Implements Alignment::AProgAlignSignificant< T >.

Definition at line 73 of file align_significant_gpu.cpp.

73  {
74  auto s = this->getSettings();
75 
76  auto &pool = this->getThreadPool();
77  auto futures = std::vector<std::future<void>>();
78  auto result = std::vector<AlignmentEstimation>();
79  for (size_t n = 0; n < s.refDims.n(); ++n) {
80  result.emplace_back(s.otherDims.n());
81  }
82 
83  auto f = [this](int threadId, const T *ref, const Dimensions &refDims,
84  const T *others, const Dimensions &otherDims,
85  unsigned device,
86  AlignmentEstimation *dest) {
87  align(ref, refDims, others, otherDims, device, dest);
88  };
89  size_t step = s.refDims.n() / m_devices.size();
90  for (size_t devIndex = 0; devIndex < m_devices.size(); ++devIndex) {
91  size_t offset = devIndex * step;
92  size_t toProcess = std::min(step, s.refDims.n() - offset);
93  futures.emplace_back(pool.push(f,
94  ref + (offset * s.refDims.sizeSingle()),
95  s.refDims.copyForN(toProcess),
96  others, s.otherDims,
97  m_devices.at(devIndex),
98  result.data() + offset));
99  }
100  for (auto &f : futures) {
101  f.get();
102  }
103  std::cout << "Done" << std::endl;
104  return result;
105 }
void min(Image< double > &op1, const Image< double > &op2)
double * f
std::vector< AlignmentEstimation > align(const T *ref, const T *others) override
ctpl::thread_pool & getThreadPool()
int * n

◆ defineParams()

template<typename T >
void Alignment::ProgAlignSignificantGPU< T >::defineParams ( )
overridevirtual

Function in which the param of each Program are defined.

Reimplemented from Alignment::AProgAlignSignificant< T >.

Definition at line 31 of file align_significant_gpu.cpp.

31  {
33  this->addParamsLine(" [--dev <...>] : space-separated list of GPU device(s) to use. Single, 0th GPU used by default");
34 }
virtual void defineParams() override
void addParamsLine(const String &line)

◆ readParams()

template<typename T >
void Alignment::ProgAlignSignificantGPU< T >::readParams ( )
overridevirtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from Alignment::AProgAlignSignificant< T >.

Definition at line 47 of file align_significant_gpu.cpp.

47  {
49  // read GPU
50  StringVector devs;
51  this->getListParam("--dev", devs);
52  if (devs.empty()) {
53  devs.emplace_back("0"); // by default, use one GPU, 0th
54  }
55  auto noOfAvailableDevices = GPU::getDeviceCount();
56  for (auto &a : devs) {
57  int d = std::stoi(a);
58  if (0 > d) {
59  REPORT_ERROR(ERR_ARG_INCORRECT, "Invalid GPU device '" + a + "' (must be non-negative number)");
60  }
61  // FIXME DS uncomment once we are decided if we want to run multiple executions on the same GPU
62 // if (std::find(m_devices.begin(), m_devices.end(), d) != m_devices.end()) {
63 // REPORT_ERROR(ERR_ARG_INCORRECT, "Invalid GPU device '" + a + "' (repeated index)");
64 // }
65  if (d >= noOfAvailableDevices) {
66  REPORT_ERROR(ERR_ARG_INCORRECT, "Invalid GPU device '" + a + "' (index higher than number of available devices)");
67  }
68  m_devices.emplace_back(d);
69  }
70 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void getListParam(const char *param, StringVector &list)
std::vector< String > StringVector
Definition: xmipp_strings.h:35
doublereal * d
virtual void readParams() override
Incorrect argument received.
Definition: xmipp_error.h:113
static int getDeviceCount()
Definition: gpu.cpp:118
doublereal * a

◆ show()

template<typename T >
void Alignment::ProgAlignSignificantGPU< T >::show ( ) const
overridevirtual

Show parameters

Reimplemented from Alignment::AProgAlignSignificant< T >.

Definition at line 37 of file align_significant_gpu.cpp.

37  {
39  std::cout << "Device(s) :";
40  for (auto d : m_devices) {
41  std::cout << " " << d;
42  }
43  std::cout << std::endl;
44 }
doublereal * d
virtual void show() const override

◆ updateRefs()

template<typename T >
void Alignment::ProgAlignSignificantGPU< T >::updateRefs ( T *  refs,
const T *  others,
const std::vector< Assignment > &  assignments 
)
overrideprotectedvirtual

Implements Alignment::AProgAlignSignificant< T >.

Definition at line 256 of file align_significant_gpu.cpp.

259  {
260  auto s = this->getSettings();
261 
262  auto &pool = this->getThreadPool();
263  auto futures = std::vector<std::future<void>>();
264 
265  auto f = [this, &assignments](int threadId, T *ref, const Dimensions &refDims,
266  const T *others, const Dimensions &otherDims,
267  unsigned device,
268  size_t refOffset) {
269  updateRefs(ref, refDims, others, otherDims, assignments, device, refOffset);
270  };
271  size_t step = s.refDims.n() / m_devices.size();
272  for (size_t devIndex = 0; devIndex < m_devices.size(); ++devIndex) {
273  size_t offset = devIndex * step;
274  size_t toProcess = std::min(step, s.refDims.n() - offset);
275  futures.emplace_back(pool.push(f,
276  refs,
277  s.refDims.copyForN(toProcess),
278  others, s.otherDims,
279  m_devices.at(devIndex),
280  offset));
281  }
282  for (auto &f : futures) {
283  f.get();
284  }
285  std::cout << "Done" << std::endl;
286 }
void min(Image< double > &op1, const Image< double > &op2)
double * f
void updateRefs(T *refs, const T *others, const std::vector< Assignment > &assignments) override
ctpl::thread_pool & getThreadPool()

The documentation for this class was generated from the following files: