GlobeEngine
GPUProgramFactory.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_GPUProgram_h
10 #define GlobeEngine_GPUProgram_h
11 
12 #include "OpenGL_Includes.h"
13 #include <iostream>
14 #include <string>
15 #include <vector>
16 #ifdef __APPLE__
17 #include <OpenCL/cl.h>
18 #else
19 #include <CL/cl.h>
20 #endif
21 #include "fstream"
22 
23 namespace ge {
24  struct GPUProgram
25  {
26  cl_program program;
27  std::vector<cl_kernel> kernels;
28  };
29 
31  {
32  public:
33  enum DeviceType { GPU, CPU }; //VERTEX, FRAGMENT, GEOMETRY };
34 
35  public:
38 
39  void clear();
40  void destroy();
41  void create();
42  GPUProgram* load(std::string _inputPath);
43  void createKernel(GPUProgram* _inputProgram,std::string _kernelName);
44  std::string readFile(std::string fileName);
45  void getOpenGLError(std::string _input);
46 
47  // display informations
48  void displayPlatformInfo(cl_platform_id firstPlatformID);
49  void displayPlatformSpecificInfo(cl_platform_id firstPlatformID, cl_platform_info _info, std::string _comment);
50  void displayDeviceInfo(cl_device_id _deviceID);
51  void displayDeviceSpecificInfo(cl_device_id _deviceID, cl_device_info _info, std::string _comment, int _type);
52 
53  // OpenCL one to one wrapper with error handling
54  cl_mem createBuffer(cl_mem_flags _flags, size_t _size, void* _host_ptr, cl_int* _errcode_ret);
55  void setKernelArg(cl_kernel _kernel, cl_uint _arg_index, size_t _arg_size, const void* _arg_value);
56  void enqueueNDRangeKernel(cl_kernel _kernel,cl_uint _work_dim,const size_t* _global_work_offset,const size_t* _global_work_size,const size_t* _local_work_size,cl_uint _num_events_in_wait_list,const cl_event* _event_wait_list,cl_event* _event);
57  void enqueueReadBuffer(cl_mem _buffer, cl_bool _blocking_read, size_t _offset, size_t _cb, void* _ptr, cl_uint _num_events_in_wait_list, const cl_event* _event_wait_list, cl_event* _event);
58  void finishCommands();
59 
60  // cleanup functions
61  void cleanup();
62  void cleanupProgram(GPUProgram* _input);
63  void resetCommandQueue();
64 
65  // get and set
66  cl_command_queue getCommandQueue();
67  cl_context getContext();
68  private:
69  cl_context context;
70  cl_device_id* devices;
71  DeviceType devicetype;
72  cl_command_queue command_queue;
73 
74  // error handling
75  cl_int errorNum;
76  };
77 }
78 
79 #endif
std::string readFile(std::string fileName)
Definition: GPUProgramFactory.cpp:151
cl_command_queue getCommandQueue()
Definition: GPUProgramFactory.cpp:400
DeviceType
Definition: GPUProgramFactory.h:33
void finishCommands()
Definition: GPUProgramFactory.cpp:384
~GPUProgramFactory()
Definition: GPUProgramFactory.h:37
void enqueueReadBuffer(cl_mem _buffer, cl_bool _blocking_read, size_t _offset, size_t _cb, void *_ptr, cl_uint _num_events_in_wait_list, const cl_event *_event_wait_list, cl_event *_event)
Definition: GPUProgramFactory.cpp:293
Definition: GPUProgramFactory.h:24
void cleanup()
Definition: GPUProgramFactory.cpp:171
void displayDeviceInfo(cl_device_id _deviceID)
Definition: GPUProgramFactory.cpp:237
Definition: GPUProgramFactory.h:33
void enqueueNDRangeKernel(cl_kernel _kernel, cl_uint _work_dim, const size_t *_global_work_offset, const size_t *_global_work_size, const size_t *_local_work_size, cl_uint _num_events_in_wait_list, const cl_event *_event_wait_list, cl_event *_event)
Definition: GPUProgramFactory.cpp:323
void create()
Definition: GPUProgramFactory.cpp:19
GPUProgramFactory()
Definition: GPUProgramFactory.h:36
cl_program program
Definition: GPUProgramFactory.h:26
std::vector< cl_kernel > kernels
Definition: GPUProgramFactory.h:27
GPUProgram * load(std::string _inputPath)
Definition: GPUProgramFactory.cpp:94
void displayPlatformSpecificInfo(cl_platform_id firstPlatformID, cl_platform_info _info, std::string _comment)
Definition: GPUProgramFactory.cpp:227
void createKernel(GPUProgram *_inputProgram, std::string _kernelName)
Definition: GPUProgramFactory.cpp:129
cl_context getContext()
Definition: GPUProgramFactory.cpp:405
void cleanupProgram(GPUProgram *_input)
Definition: GPUProgramFactory.cpp:192
void clear()
Definition: GPUProgramFactory.cpp:9
void destroy()
Definition: GPUProgramFactory.cpp:14
cl_mem createBuffer(cl_mem_flags _flags, size_t _size, void *_host_ptr, cl_int *_errcode_ret)
Definition: GPUProgramFactory.cpp:283
void setKernelArg(cl_kernel _kernel, cl_uint _arg_index, size_t _arg_size, const void *_arg_value)
Definition: GPUProgramFactory.cpp:365
Definition: AvalancheTrainingSimulationEngine.h:28
void resetCommandQueue()
Definition: GPUProgramFactory.cpp:179
Definition: GPUProgramFactory.h:33
void getOpenGLError(std::string _input)
Definition: GPUProgramFactory.cpp:205
void displayPlatformInfo(cl_platform_id firstPlatformID)
Definition: GPUProgramFactory.cpp:218
Definition: GPUProgramFactory.h:30
void displayDeviceSpecificInfo(cl_device_id _deviceID, cl_device_info _info, std::string _comment, int _type)
Definition: GPUProgramFactory.cpp:257