Clover Git
OpenCL 1.1 software implementation

deviceinterface.h

Go to the documentation of this file.
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 __DEVICEINTERFACE_H__
00034 #define __DEVICEINTERFACE_H__
00035 
00036 #include <CL/cl.h>
00037 #include "object.h"
00038 
00039 namespace llvm
00040 {
00041     class PassManager;
00042     class Module;
00043     class Function;
00044 }
00045 
00046 namespace Coal
00047 {
00048 
00049 class DeviceBuffer;
00050 class DeviceProgram;
00051 class DeviceKernel;
00052 
00053 class MemObject;
00054 class Event;
00055 class Program;
00056 class Kernel;
00057 
00064 class DeviceInterface : public Object
00065 {
00066     public:
00067         DeviceInterface() : Object(Object::T_Device, 0) {}
00068         virtual ~DeviceInterface() {}
00069 
00097         virtual cl_int info(cl_device_info param_name,
00098                             size_t param_value_size,
00099                             void *param_value,
00100                             size_t *param_value_size_ret) const = 0;
00101 
00108         virtual DeviceBuffer *createDeviceBuffer(MemObject *buffer, cl_int *rs) = 0;
00109 
00116         virtual DeviceProgram *createDeviceProgram(Program *program) = 0;
00117 
00125         virtual DeviceKernel *createDeviceKernel(Kernel *kernel, 
00126                                                  llvm::Function *function) = 0;
00127 
00133         virtual void pushEvent(Event *event) = 0;
00134 
00151         virtual cl_int initEventDeviceData(Event *event) = 0;
00152 
00161         virtual void freeEventDeviceData(Event *event) = 0;
00162 };
00163 
00170 class DeviceBuffer
00171 {
00172     public:
00173         DeviceBuffer() {}
00174         virtual ~DeviceBuffer() {}
00175 
00180         virtual bool allocate() = 0;
00181 
00186         virtual DeviceInterface *device() const = 0;
00187 
00192         virtual bool allocated() const = 0;
00193 
00208         virtual void *nativeGlobalPointer() const = 0;
00209 };
00210 
00214 class DeviceProgram
00215 {
00216     public:
00217         DeviceProgram() {}
00218         virtual ~DeviceProgram() {}
00219 
00242         virtual bool linkStdLib() const = 0;
00243 
00255         virtual void createOptimizationPasses(llvm::PassManager *manager,
00256                                               bool optimize) = 0;
00257 
00268         virtual bool build(llvm::Module *module) = 0;
00269 };
00270 
00274 class DeviceKernel
00275 {
00276     public:
00277         DeviceKernel() {}
00278         virtual ~DeviceKernel() {}
00279 
00285         virtual size_t workGroupSize() const = 0;
00286 
00291         virtual cl_ulong localMemSize() const = 0;
00292 
00297         virtual cl_ulong privateMemSize() const = 0;
00298 
00304         virtual size_t preferredWorkGroupSizeMultiple() const = 0;
00305 
00321         virtual size_t guessWorkGroupSize(cl_uint num_dims, cl_uint dim,
00322                                           size_t global_work_size) const = 0;
00323 };
00324 
00325 }
00326 
00327 struct _cl_device_id : public Coal::DeviceInterface
00328 {};
00329 
00330 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines