GteComputeModel.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 
12 // Expose this define if you want GPGPU support in computing any algorithms
13 // that have a GPU implemetnation. Alternatively, your application can
14 // define this in the project settings so that you do not have to edit this
15 // source file.
16 //
17 //#define GTE_COMPUTE_MODEL_ALLOW_GPGPU
18 
19 // The ComputeModel class allows you to select the type of hardware to use
20 // in your computational algorithms.
21 //
22 // If your computational algorithm requires the GPU, set 'inEngine' to the
23 // object that will execute the compute shaders. If your algorithm
24 // requires CPU multithreading, set the 'inNumThreads' to the desired
25 // number of threads, presumably 2 or larger. You can query for the number
26 // of concurrent hardware threads using std::thread::hardware_concurrency().
27 // If you want single-threaded computations (on the main thread), set
28 // inNumThreads to 1. An example of using this class is
29 //
30 // ComputeModel cmodel(...);
31 // if (cmodel.engine)
32 // {
33 // ComputeUsingGPU(...);
34 // }
35 // else if (cmodel.numThreads > 1)
36 // {
37 // ComputeUsingCPUMultipleThreads();
38 // }
39 // else
40 // {
41 // ComputeUsingCPUSingleThread();
42 // }
43 // See GenerateMeshUV<Real>::SolveSystem(...) for a concrete example.
44 //
45 // Of course, your algorithm can interpret cmodel anyway it likes. For
46 // example, you might ignore cmodel.engine if all you care about is
47 // multithreading on the CPU.
48 
49 #if defined(GTE_COMPUTE_MODEL_ALLOW_GPGPU)
50 #include <memory>
51 #endif
52 
53 namespace gte
54 {
55 
56 #if defined(GTE_COMPUTE_MODEL_ALLOW_GPGPU)
57 class GraphicsEngine;
58 class ProgramFactory;
59 #endif
60 
62 {
63 public:
64  // Construction and destruction. You may derive from this class to make
65  // additional behavior available to your algorithms. For example, you
66  // might add a callback function to report progress of the algorithm.
67  virtual ~ComputeModel()
68  {
69  }
70 
72  :
73  numThreads(1)
74  {
75  }
76 
77  ComputeModel(unsigned int inNumThreads)
78  :
79  numThreads(inNumThreads > 0 ? inNumThreads : 1)
80  {
81  }
82 
83 #if defined(GTE_COMPUTE_MODEL_ALLOW_GPGPU)
84  ComputeModel(unsigned int inNumThreads,
85  std::shared_ptr<GraphicsEngine> const& inEngine,
86  std::shared_ptr<ProgramFactory> const& inFactory)
87  :
88  numThreads(inNumThreads > 0 ? inNumThreads : 1),
89  engine(inEngine),
90  factory(inFactory)
91  {
92  }
93 #endif
94 
95  unsigned int numThreads;
96 #if defined(GTE_COMPUTE_MODEL_ALLOW_GPGPU)
97  std::shared_ptr<GraphicsEngine> engine;
98  std::shared_ptr<ProgramFactory> factory;
99 #endif
100 };
101 
102 }
virtual ~ComputeModel()
unsigned int numThreads
ComputeModel(unsigned int inNumThreads)
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59