Clover Git
OpenCL 1.1 software implementation

kernel.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 __KERNEL_H__
00034 #define __KERNEL_H__
00035 
00036 #include "object.h"
00037 
00038 #include <CL/cl.h>
00039 
00040 #include <vector>
00041 #include <string>
00042 
00043 namespace llvm
00044 {
00045     class Function;
00046     class Module;
00047 }
00048 
00049 namespace Coal
00050 {
00051 
00052 class Program;
00053 class DeviceInterface;
00054 class DeviceKernel;
00055 
00065 class Kernel : public Object
00066 {
00067     public:
00072         Kernel(Program *program);
00073         ~Kernel();
00074 
00082         class Arg
00083         {
00084             public:
00088                 enum File
00089                 {
00090                     Private = 0,  
00091                     Global = 1,   
00092                     Local = 2,    
00093                     Constant = 3  
00094                 };
00095 
00099                 enum Kind
00100                 {
00101                     Invalid,      
00102                     Int8,         
00103                     Int16,        
00104                     Int32,        
00105                     Int64,        
00106                     Float,        
00107                     Double,       
00108                     Buffer,       
00109                     Image2D,      
00110                     Image3D,      
00111                     Sampler       
00112                 };
00113 
00120                 Arg(unsigned short vec_dim, File file, Kind kind);
00121                 ~Arg();
00122 
00131                 void alloc();
00132                 
00138                 void loadData(const void *data);
00139                 
00153                 void setAllocAtKernelRuntime(size_t size);
00154                 
00159                 void refineKind(Kind kind);
00160 
00170                 bool operator !=(const Arg &b);
00171 
00183                 size_t valueSize() const;
00184                 unsigned short vecDim() const;                 
00185                 File file() const;                             
00186                 Kind kind() const;                             
00187                 bool defined() const;                          
00188                 size_t allocAtKernelRuntime() const;           
00189                 const void *value(unsigned short index) const; 
00190                 const void *data() const;                      
00192             private:
00193                 unsigned short p_vec_dim;
00194                 File p_file;
00195                 Kind p_kind;
00196                 void *p_data;
00197                 bool p_defined;
00198                 size_t p_runtime_alloc;
00199         };
00200 
00228         cl_int addFunction(DeviceInterface *device, llvm::Function *function,
00229                            llvm::Module *module);
00230 
00236         llvm::Function *function(DeviceInterface *device) const;
00237         
00250         cl_int setArg(cl_uint index, size_t size, const void *value);
00251 
00252         unsigned int numArgs() const;             
00253         const Arg &arg(unsigned int index) const; 
00256         DeviceKernel *deviceDependentKernel(DeviceInterface *device) const;
00257 
00258         bool argsSpecified() const;               
00259         bool hasLocals() const;                   
00265         cl_int info(cl_kernel_info param_name,
00266                     size_t param_value_size,
00267                     void *param_value,
00268                     size_t *param_value_size_ret) const;
00269 
00275         cl_int workGroupInfo(DeviceInterface *device,
00276                              cl_kernel_work_group_info param_name,
00277                              size_t param_value_size,
00278                              void *param_value,
00279                              size_t *param_value_size_ret) const;
00280 
00281     private:
00282         std::string p_name;
00283         bool p_has_locals;
00284 
00285         struct DeviceDependent
00286         {
00287             DeviceInterface *device;
00288             DeviceKernel *kernel;
00289             llvm::Function *function;
00290             llvm::Module *module;
00291         };
00292 
00293         std::vector<DeviceDependent> p_device_dependent;
00294         std::vector<Arg> p_args;
00295         DeviceDependent null_dep;
00296 
00297         const DeviceDependent &deviceDependent(DeviceInterface *device) const;
00298         DeviceDependent &deviceDependent(DeviceInterface *device);
00299 };
00300 
00301 }
00302 
00303 struct _cl_kernel : public Coal::Kernel
00304 {};
00305 
00306 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines