Clover Git
OpenCL 1.1 software implementation
|
00001 /* 00002 * Copyright (c) 2011, Denis Steckelmacher <steckdenis@yahoo.fr> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Neither the name of the copyright holder nor the 00013 * names of its contributors may be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00017 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 00020 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00023 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00033 #ifndef __COMMANDQUEUE_H__ 00034 #define __COMMANDQUEUE_H__ 00035 00036 #include "object.h" 00037 00038 #include <CL/cl.h> 00039 #include <pthread.h> 00040 00041 #include <map> 00042 #include <list> 00043 00044 namespace Coal 00045 { 00046 00047 class Context; 00048 class DeviceInterface; 00049 class Event; 00050 00058 class CommandQueue : public Object 00059 { 00060 public: 00061 CommandQueue(Context *ctx, 00062 DeviceInterface *device, 00063 cl_command_queue_properties properties, 00064 cl_int *errcode_ret); 00065 ~CommandQueue(); 00066 00072 cl_int queueEvent(Event *event); 00073 00078 cl_int info(cl_command_queue_info param_name, 00079 size_t param_value_size, 00080 void *param_value, 00081 size_t *param_value_size_ret) const; 00082 00093 cl_int setProperty(cl_command_queue_properties properties, 00094 cl_bool enable, 00095 cl_command_queue_properties *old_properties); 00096 00101 cl_int checkProperties() const; 00102 00139 void pushEventsOnDevice(); 00140 00151 void cleanEvents(); 00152 00159 void flush(); 00160 00167 void finish(); 00168 00175 Event **events(unsigned int &count); 00176 00177 private: 00178 DeviceInterface *p_device; 00179 cl_command_queue_properties p_properties; 00180 00181 std::list<Event *> p_events; 00182 pthread_mutex_t p_event_list_mutex; 00183 pthread_cond_t p_event_list_cond; 00184 bool p_flushed; 00185 }; 00186 00197 class Event : public Object 00198 { 00199 public: 00206 enum Type 00207 { 00208 NDRangeKernel = CL_COMMAND_NDRANGE_KERNEL, 00209 TaskKernel = CL_COMMAND_TASK, 00210 NativeKernel = CL_COMMAND_NATIVE_KERNEL, 00211 ReadBuffer = CL_COMMAND_READ_BUFFER, 00212 WriteBuffer = CL_COMMAND_WRITE_BUFFER, 00213 CopyBuffer = CL_COMMAND_COPY_BUFFER, 00214 ReadImage = CL_COMMAND_READ_IMAGE, 00215 WriteImage = CL_COMMAND_WRITE_IMAGE, 00216 CopyImage = CL_COMMAND_COPY_IMAGE, 00217 CopyImageToBuffer = CL_COMMAND_COPY_IMAGE_TO_BUFFER, 00218 CopyBufferToImage = CL_COMMAND_COPY_BUFFER_TO_IMAGE, 00219 MapBuffer = CL_COMMAND_MAP_BUFFER, 00220 MapImage = CL_COMMAND_MAP_IMAGE, 00221 UnmapMemObject = CL_COMMAND_UNMAP_MEM_OBJECT, 00222 Marker = CL_COMMAND_MARKER, 00223 AcquireGLObjects = CL_COMMAND_ACQUIRE_GL_OBJECTS, 00224 ReleaseGLObjects = CL_COMMAND_RELEASE_GL_OBJECTS, 00225 ReadBufferRect = CL_COMMAND_READ_BUFFER_RECT, 00226 WriteBufferRect = CL_COMMAND_WRITE_BUFFER_RECT, 00227 CopyBufferRect = CL_COMMAND_COPY_BUFFER_RECT, 00228 User = CL_COMMAND_USER, 00229 Barrier, 00230 WaitForEvents 00231 }; 00232 00236 enum Status 00237 { 00238 Queued = CL_QUEUED, 00239 Submitted = CL_SUBMITTED, 00240 Running = CL_RUNNING, 00241 Complete = CL_COMPLETE 00242 }; 00243 00247 typedef void (CL_CALLBACK *event_callback)(cl_event, cl_int, void *); 00248 00253 struct CallbackData 00254 { 00255 event_callback callback; 00256 void *user_data; 00257 }; 00258 00262 enum Timing 00263 { 00264 Queue, 00265 Submit, 00266 Start, 00267 End, 00268 Max 00269 }; 00270 00271 public: 00280 Event(CommandQueue *parent, 00281 Status status, 00282 cl_uint num_events_in_wait_list, 00283 const Event **event_wait_list, 00284 cl_int *errcode_ret); 00285 00286 void freeDeviceData(); 00287 virtual ~Event(); 00293 virtual Type type() const = 0; 00294 00303 bool isDummy() const; 00304 00314 void setStatus(Status status); 00315 00320 void setDeviceData(void *data); 00321 00329 void updateTiming(Timing timing); 00330 00335 Status status() const; 00336 00345 void waitForStatus(Status status); 00346 00351 void *deviceData(); 00352 00359 const Event **waitEvents(cl_uint &count) const; 00360 00368 void setCallback(cl_int command_exec_callback_type, 00369 event_callback callback, 00370 void *user_data); 00371 00376 cl_int info(cl_event_info param_name, 00377 size_t param_value_size, 00378 void *param_value, 00379 size_t *param_value_size_ret) const; 00380 00385 cl_int profilingInfo(cl_profiling_info param_name, 00386 size_t param_value_size, 00387 void *param_value, 00388 size_t *param_value_size_ret) const; 00389 private: 00390 cl_uint p_num_events_in_wait_list; 00391 const Event **p_event_wait_list; 00392 00393 pthread_cond_t p_state_change_cond; 00394 pthread_mutex_t p_state_mutex; 00395 00396 Status p_status; 00397 void *p_device_data; 00398 std::multimap<Status, CallbackData> p_callbacks; 00399 00400 cl_uint p_timing[Max]; 00401 }; 00402 00403 } 00404 00405 struct _cl_command_queue : public Coal::CommandQueue 00406 {}; 00407 00408 struct _cl_event : public Coal::Event 00409 {}; 00410 00411 #endif