SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
device_cl.h
Go to the documentation of this file.
1 
5 #ifndef DEVICE_CL_H
6 #define DEVICE_CL_H
7 
8 #ifdef SKEPU_OPENCL
9 
10 #include <iostream>
11 #ifdef USE_MAC_OPENCL
12 #include <OpenCL/opencl.h>
13 #else
14 #include <CL/cl.h>
15 #endif
16 
17 #include "deviceprop_cl.h"
18 
19 namespace skepu
20 {
21 
37 class Device_CL
38 {
39 
40 private:
41 
42  cl_device_type m_type;
43  openclDeviceProp m_deviceProp;
44 
45  cl_device_id m_device;
46  cl_context m_context;
47  cl_command_queue m_queue;
48 
49  int m_maxThreads;
50  size_t m_maxBlocks;
51 
57  void getDeviceProps(cl_device_id device)
58  {
59  for(std::vector<openclGenProp>::iterator it = m_deviceProp.propertyList.begin(); it != m_deviceProp.propertyList.end(); ++it)
60  {
61  cl_int err;
62  err = clGetDeviceInfo(device, it->param_name, it->param_value_size, it->param_value, NULL);
63  if(err != CL_SUCCESS){std::cerr<<"Error adding property value CL!!\n";}
64  }
65  }
66 
67 
68 public:
69 
70  Device_CL(cl_device_id id, cl_device_type type, cl_context context, cl_command_queue queue)
71  {
72  m_device = id;
73  m_type = type;
74  m_context = context;
75  m_queue = queue;
76 
77  getDeviceProps(id);
78 
79  m_maxThreads = getMaxBlockSize()>>1;
80  m_maxBlocks = (size_t)((size_t)1<<(m_deviceProp.DEVICE_ADDRESS_BITS-1))*2-1;
81  }
82 
91  Device_CL(cl_device_id id, cl_device_type type, cl_context context)
92  {
93  m_device = id;
94  m_type = type;
95  m_context = context;
96 
97  getDeviceProps(id);
98 
99  m_maxThreads = getMaxBlockSize()>>1;
100  m_maxBlocks = (size_t)((size_t)1<<(m_deviceProp.DEVICE_ADDRESS_BITS-1))*2-1;
101 
102  cl_int err;
103 
104  //Create a command-queue on the GPU device
105  m_queue = clCreateCommandQueue(m_context, m_device, 0, &err);
106  if(err != CL_SUCCESS){std::cerr<<"Error creating queue!!\n" <<err <<"\n";}
107  }
108 
113  {
114  clReleaseCommandQueue(m_queue);
115  clReleaseContext(m_context);
116  std::cout<<"Release Device_cl\n";
117  }
118 
122  size_t getMaxBlockSize() const {return m_deviceProp.DEVICE_MAX_WORK_GROUP_SIZE;}
123 
127  cl_uint getNumComputeUnits() const {return m_deviceProp.DEVICE_MAX_COMPUTE_UNITS;}
128 
132  cl_ulong getGlobalMemSize() const {return m_deviceProp.DEVICE_GLOBAL_MEM_SIZE;}
133 
137  cl_ulong getSharedMemPerBlock() const {return m_deviceProp.DEVICE_LOCAL_MEM_SIZE;}
138 
142  int getMaxThreads() const
143  {
144  #ifdef SKEPU_MAX_GPU_THREADS
145  return SKEPU_MAX_GPU_THREADS;
146  #else
147  return m_maxThreads;
148  #endif
149  }
150 
154  size_t getMaxBlocks() const {return m_maxBlocks;}
155 
159  const cl_context& getContext() const {return m_context;}
160 
164  const cl_command_queue& getQueue() const {return m_queue;}
165 
166 // cl_command_queue* getQueuePointer() const {return &m_queue;}
167 
171  cl_device_type getType() const {return m_type;}
172 
176  cl_device_id getDeviceID() const {return m_device;}
177 
178 };
179 
180 
181 }
182 
183 #endif
184 
185 #endif
186 
cl_ulong getSharedMemPerBlock() const
Definition: device_cl.h:137
Definition: deviceprop_cl.h:46
int getMaxThreads() const
Definition: device_cl.h:142
cl_device_type getType() const
Definition: device_cl.h:171
const cl_command_queue & getQueue() const
Definition: device_cl.h:164
cl_uint getNumComputeUnits() const
Definition: device_cl.h:127
const cl_context & getContext() const
Definition: device_cl.h:159
Device_CL(cl_device_id id, cl_device_type type, cl_context context)
Definition: device_cl.h:91
~Device_CL()
Definition: device_cl.h:112
cl_device_id getDeviceID() const
Definition: device_cl.h:176
A class representing an OpenCL device.
Definition: device_cl.h:37
Declares a struct used to store OpenCL device properties.
size_t getMaxBlockSize() const
Definition: device_cl.h:122
cl_ulong getGlobalMemSize() const
Definition: device_cl.h:132
size_t getMaxBlocks() const
Definition: device_cl.h:154