Go to the documentation of this file.00001
00005 #ifndef DEVICE_CL_H
00006 #define DEVICE_CL_H
00007
00008 #ifdef SKEPU_OPENCL
00009
00010 #include <iostream>
00011 #include <CL/cl.h>
00012
00013 #include "deviceprop_cl.h"
00014
00015 namespace skepu
00016 {
00017
00033 class Device_CL
00034 {
00035
00036 private:
00037
00038 cl_device_type m_type;
00039 openclDeviceProp m_deviceProp;
00040
00041 cl_device_id m_device;
00042 cl_context m_context;
00043 cl_command_queue m_queue;
00044
00045 int m_maxThreads;
00046 size_t m_maxBlocks;
00047
00053 void getDeviceProps(cl_device_id device)
00054 {
00055 for(std::vector<openclGenProp>::iterator it = m_deviceProp.propertyList.begin(); it != m_deviceProp.propertyList.end(); ++it)
00056 {
00057 cl_int err;
00058 err = clGetDeviceInfo(device, it->param_name, it->param_value_size, it->param_value, NULL);
00059 if(err != CL_SUCCESS){std::cerr<<"Error adding property value CL!!\n";}
00060 }
00061 }
00062
00063
00064 public:
00065
00074 Device_CL(cl_device_id id, cl_device_type type, cl_context context)
00075 {
00076 m_device = id;
00077 m_type = type;
00078 m_context = context;
00079
00080 getDeviceProps(id);
00081
00082 m_maxThreads = getMaxBlockSize()>>1;
00083 m_maxBlocks = (size_t)((size_t)1<<(m_deviceProp.DEVICE_ADDRESS_BITS-1))*2-1;
00084
00085 cl_int err;
00086
00087
00088 m_queue = clCreateCommandQueue(m_context, m_device, 0, &err);
00089 if(err != CL_SUCCESS){std::cerr<<"Error creating queue!!\n" <<err <<"\n";}
00090 }
00091
00095 ~Device_CL()
00096 {
00097 clReleaseCommandQueue(m_queue);
00098 clReleaseContext(m_context);
00099 }
00100
00104 size_t getMaxBlockSize() const {return m_deviceProp.DEVICE_MAX_WORK_GROUP_SIZE;}
00105
00109 cl_uint getNumComputeUnits() const {return m_deviceProp.DEVICE_MAX_COMPUTE_UNITS;}
00110
00114 cl_ulong getGlobalMemSize() const {return m_deviceProp.DEVICE_GLOBAL_MEM_SIZE;}
00115
00119 cl_ulong getSharedMemPerBlock() const {return m_deviceProp.DEVICE_LOCAL_MEM_SIZE;}
00120
00124 int getMaxThreads() const {return m_maxThreads;}
00125
00129 size_t getMaxBlocks() const {return m_maxBlocks;}
00130
00134 const cl_context& getContext() const {return m_context;}
00135
00139 const cl_command_queue& getQueue() const {return m_queue;}
00140
00144 cl_device_type getType() const {return m_type;}
00145
00149 cl_device_id getDeviceID() const {return m_device;}
00150
00151 };
00152
00153
00154 }
00155
00156 #endif
00157
00158 #endif