SkePU  1.2
 All Classes Namespaces Files Functions Variables 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 
20 namespace skepu
21 {
22 
36 class Device_CL
37 {
38 
39 private:
40 
41  cl_device_type m_type;
42  openclDeviceProp m_deviceProp;
43 
44  cl_device_id m_device;
45  cl_context m_context;
46  cl_command_queue m_queue;
47 
48  size_t m_maxThreads;
49  size_t m_maxBlocks;
50 
56  void getDeviceProps(cl_device_id device)
57  {
58  for(std::vector<openclGenProp>::iterator it = m_deviceProp.propertyList.begin(); it != m_deviceProp.propertyList.end(); ++it)
59  {
60  cl_int err;
61  err = clGetDeviceInfo(device, it->param_name, it->param_value_size, it->param_value, NULL);
62  if(err != CL_SUCCESS)
63  {
64  std::cerr<<"Error adding property value CL!!\n";
65  }
66  }
67  }
68 
69 
70 public:
71 
80  Device_CL(cl_device_id id, cl_device_type type, cl_context context)
81  {
82  m_device = id;
83  m_type = type;
84  m_context = context;
85 
86  getDeviceProps(id);
87 
88  m_maxThreads = getMaxBlockSize()>>1;
89  m_maxBlocks = (size_t)((size_t)1<<(m_deviceProp.DEVICE_ADDRESS_BITS-1))*2-1;
90 
91  cl_int err;
92 
93  //Create a command-queue on the GPU device
94  m_queue = clCreateCommandQueue(m_context, m_device, 0, &err);
95  if(err != CL_SUCCESS)
96  {
97  std::cerr<<"Error creating queue!!\n" <<err <<"\n";
98  }
99  }
100 
105  {
106  clReleaseCommandQueue(m_queue);
107  clReleaseContext(m_context);
108  std::cout<<"Release Device_cl\n";
109  }
110 
114  size_t getMaxBlockSize() const
115  {
116  return m_deviceProp.DEVICE_MAX_WORK_GROUP_SIZE;
117  }
118 
122  cl_uint getNumComputeUnits() const
123  {
124  return m_deviceProp.DEVICE_MAX_COMPUTE_UNITS;
125  }
126 
130  cl_ulong getGlobalMemSize() const
131  {
132  return m_deviceProp.DEVICE_GLOBAL_MEM_SIZE;
133  }
134 
138  cl_ulong getSharedMemPerBlock() const
139  {
140  return m_deviceProp.DEVICE_LOCAL_MEM_SIZE;
141  }
142 
146  int getMaxThreads() const
147  {
148 #ifdef SKEPU_MAX_GPU_THREADS
149  return SKEPU_MAX_GPU_THREADS;
150 #else
151  return m_maxThreads;
152 #endif
153  }
154 
158  size_t getMaxBlocks() const
159  {
160 #ifdef SKEPU_MAX_GPU_BLOCKS
161  return SKEPU_MAX_GPU_BLOCKS;
162 #else
163  return m_maxBlocks;
164 #endif
165  }
166 
170  const cl_context& getContext() const
171  {
172  return m_context;
173  }
174 
178  const cl_command_queue& getQueue() const
179  {
180  return m_queue;
181  }
182 
186  cl_device_type getType() const
187  {
188  return m_type;
189  }
190 
194  cl_device_id getDeviceID() const
195  {
196  return m_device;
197  }
198 
199 };
200 
201 
202 }
203 
204 #endif
205 
206 #endif
207 
208 
cl_ulong getSharedMemPerBlock() const
Definition: device_cl.h:138
Definition: deviceprop_cl.h:46
int getMaxThreads() const
Definition: device_cl.h:146
cl_device_type getType() const
Definition: device_cl.h:186
const cl_command_queue & getQueue() const
Definition: device_cl.h:178
cl_uint getNumComputeUnits() const
Definition: device_cl.h:122
const cl_context & getContext() const
Definition: device_cl.h:170
Device_CL(cl_device_id id, cl_device_type type, cl_context context)
Definition: device_cl.h:80
~Device_CL()
Definition: device_cl.h:104
cl_device_id getDeviceID() const
Definition: device_cl.h:194
A class representing an OpenCL device.
Definition: device_cl.h:36
Declares a struct used to store OpenCL device properties.
size_t getMaxBlockSize() const
Definition: device_cl.h:114
cl_ulong getGlobalMemSize() const
Definition: device_cl.h:130
size_t getMaxBlocks() const
Definition: device_cl.h:158