FAST  3.2.0
Framework for Heterogeneous Medical Image Computing and Visualization
ExecutionDevice.hpp
Go to the documentation of this file.
1 #ifndef EXECUTIONDEVICE_HPP_
2 #define EXECUTIONDEVICE_HPP_
3 
4 #include "FAST/Object.hpp"
6 
7 namespace fast {
8 
9 class FAST_EXPORT ExecutionDevice : public Object {
10  public:
11  typedef std::shared_ptr<ExecutionDevice> pointer;
12  bool isHost() {return mIsHost;};
13  virtual ~ExecutionDevice() {};
14  static std::string getStaticNameOfClass() {
15  return "ExecutionDevice";
16  }
17  protected:
18  bool mIsHost;
19  std::weak_ptr<ExecutionDevice> mPtr;
20 
21 };
22 
23 class DeviceManager; // Forward declaration
24 class FAST_EXPORT Host : public ExecutionDevice {
25  public:
26  typedef std::shared_ptr<Host> pointer;
28  static Host::pointer instance = Host::New();
29  return instance;
30  }
31  static std::string getStaticNameOfClass() {
32  return "Host";
33  }
34  // Declare factory method New private
35  private:
36  static Host::pointer New() {
37  Host* ptr = new Host();
38  Host::pointer smartPtr(ptr);
39  ptr->setPtr(smartPtr);
40 
41  return smartPtr;
42  }
43  void setPtr(Host::pointer ptr) {
44  mPtr = ptr;
45  }
46  Host() {
47  mIsHost = true;
48  }
49 
50 };
51 
52 
59 };
60 
66 };
67 
68 class FAST_EXPORT OpenCLDevice : public ExecutionDevice {
70  public:
71  cl::CommandQueue getCommandQueue();
72  cl::Device getDevice();
73 
74  int createProgramFromSource(std::string filename, std::string buildOptions = "", bool caching = true);
75  int createProgramFromSource(std::vector<std::string> filenames, std::string buildOptions = "");
76  int createProgramFromString(std::string code, std::string buildOptions = "");
77  int createProgramFromSourceWithName(std::string programName, std::string filename, std::string buildOptions = "");
78  int createProgramFromSourceWithName(std::string programName, std::vector<std::string> filenames, std::string buildOptions = "");
79  int createProgramFromStringWithName(std::string programName, std::string code, std::string buildOptions = "");
80  cl::Program getProgram(unsigned int i);
81  cl::Program getProgram(std::string name);
82  bool hasProgram(std::string name);
83 
84  bool isImageFormatSupported(cl_channel_order order, cl_channel_type type, cl_mem_object_type imageType);
85  bool isOpenGLInteropSupported();
86 
87  //OpenCLPlatformVendor getPlatformVendor();
88  //DeviceVendor getDeviceVendor();
89 
90  cl::CommandQueue getQueue(unsigned int i);
91  cl::Device getDevice(unsigned int i);
92  cl::Device getDevice(cl::CommandQueue queue);
93  cl::Context getContext();
94  cl::Platform getPlatform();
95 
96  OpenCLDevice(std::vector<cl::Device> devices, unsigned long* glContext = NULL);
97  unsigned long * getGLContext() { return mGLContext; };
98  std::string getName() {
99  return getDevice().getInfo<CL_DEVICE_NAME>();
100  }
101  bool isWritingTo3DTexturesSupported();
102  RuntimeMeasurementsManager::pointer getRunTimeMeasurementManager();
103  ~OpenCLDevice();
104  private:
105  OpenCLDevice();
106  unsigned long * mGLContext;
107  cl::Program writeBinary(std::string filename, std::string buildOptions);
108  cl::Program readBinary(std::string filename);
109  cl::Program buildProgramFromBinary(std::string filename, std::string buildOptions);
110  cl::Program buildSources(cl::Program::Sources source, std::string buildOptions);
111 
112  cl::Context context;
113  std::vector<cl::CommandQueue> queues;
114  std::map<std::string, int> programNames;
115  std::vector<cl::Program> programs;
116  std::vector<cl::Device> devices;
117  cl::Platform platform;
118 
119  bool profilingEnabled;
121 
122 };
123 
124 } // end namespace fast
125 
126 #endif /* EXECUTIONDEVICE_HPP_ */
Object.hpp
fast::ExecutionDevice::pointer
std::shared_ptr< ExecutionDevice > pointer
Definition: ExecutionDevice.hpp:11
fast::ExecutionDevice::isHost
bool isHost()
Definition: ExecutionDevice.hpp:12
fast::ExecutionDevice
Definition: ExecutionDevice.hpp:9
fast::OpenCLPlatformVendor
OpenCLPlatformVendor
Definition: ExecutionDevice.hpp:53
fast::PLATFORM_VENDOR_APPLE
@ PLATFORM_VENDOR_APPLE
Definition: ExecutionDevice.hpp:54
fast::OpenCLDevice
Definition: ExecutionDevice.hpp:68
fast
Definition: AffineTransformation.hpp:7
fast::Object
Definition: Object.hpp:34
fast::PLATFORM_VENDOR_INTEL
@ PLATFORM_VENDOR_INTEL
Definition: ExecutionDevice.hpp:56
fast::ExecutionDevice::mPtr
std::weak_ptr< ExecutionDevice > mPtr
Definition: ExecutionDevice.hpp:19
fast::PLATFORM_VENDOR_UKNOWN
@ PLATFORM_VENDOR_UKNOWN
Definition: ExecutionDevice.hpp:58
FAST_OBJECT
#define FAST_OBJECT(className)
Definition: Object.hpp:9
fast::PLATFORM_VENDOR_NVIDIA
@ PLATFORM_VENDOR_NVIDIA
Definition: ExecutionDevice.hpp:57
fast::ExecutionDevice::~ExecutionDevice
virtual ~ExecutionDevice()
Definition: ExecutionDevice.hpp:13
fast::Host
Definition: ExecutionDevice.hpp:24
fast::DeviceVendor
DeviceVendor
Definition: ExecutionDevice.hpp:61
fast::PLATFORM_VENDOR_AMD
@ PLATFORM_VENDOR_AMD
Definition: ExecutionDevice.hpp:55
fast::Host::getStaticNameOfClass
static std::string getStaticNameOfClass()
Definition: ExecutionDevice.hpp:31
fast::OpenCLDevice::getGLContext
unsigned long * getGLContext()
Definition: ExecutionDevice.hpp:97
fast::Object::pointer
std::shared_ptr< Object > pointer
Definition: Object.hpp:36
fast::DEVICE_VENDOR_AMD
@ DEVICE_VENDOR_AMD
Definition: ExecutionDevice.hpp:62
fast::ExecutionDevice::mIsHost
bool mIsHost
Definition: ExecutionDevice.hpp:18
RuntimeMeasurementManager.hpp
fast::DeviceManager
Definition: DeviceManager.hpp:14
fast::ExecutionDevice::getStaticNameOfClass
static std::string getStaticNameOfClass()
Definition: ExecutionDevice.hpp:14
fast::DEVICE_VENDOR_UKNOWN
@ DEVICE_VENDOR_UKNOWN
Definition: ExecutionDevice.hpp:65
fast::OpenCLDevice::getName
std::string getName()
Definition: ExecutionDevice.hpp:98
fast::Host::pointer
std::shared_ptr< Host > pointer
Definition: ExecutionDevice.hpp:26
fast::DEVICE_VENDOR_INTEL
@ DEVICE_VENDOR_INTEL
Definition: ExecutionDevice.hpp:63
fast::Host::getInstance
static Host::pointer getInstance()
Definition: ExecutionDevice.hpp:27
fast::DEVICE_VENDOR_NVIDIA
@ DEVICE_VENDOR_NVIDIA
Definition: ExecutionDevice.hpp:64