Clover Git
OpenCL 1.1 software implementation

program.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 __PROGRAM_H__
00034 #define __PROGRAM_H__
00035 
00036 #include "object.h"
00037 
00038 #include <CL/cl.h>
00039 #include <string>
00040 #include <vector>
00041 
00042 namespace llvm
00043 {
00044     class MemoryBuffer;
00045     class Module;
00046     class Function;
00047 }
00048 
00049 namespace Coal
00050 {
00051 
00052 class Context;
00053 class Compiler;
00054 class DeviceInterface;
00055 class DeviceProgram;
00056 class Kernel;
00057 
00067 class Program : public Object
00068 {
00069     public:
00074         Program(Context *ctx);
00075         ~Program();
00076 
00080         enum Type
00081         {
00082             Invalid, 
00083             Source,  
00084             Binary   
00085         };
00086 
00090         enum State
00091         {
00092             Empty,   
00093             Loaded,  
00094             Built,   
00095             Failed,  
00096         };
00097 
00112         cl_int loadSources(cl_uint count, const char **strings,
00113                            const size_t *lengths);
00114 
00133         cl_int loadBinaries(const unsigned char **data, const size_t *lengths,
00134                             cl_int *binary_status, cl_uint num_devices,
00135                             DeviceInterface * const*device_list);
00136 
00153         cl_int build(const char *options,
00154                      void (CL_CALLBACK *pfn_notify)(cl_program program,
00155                                                     void *user_data),
00156                      void *user_data, cl_uint num_devices,
00157                      DeviceInterface * const*device_list);
00158 
00159         Type type() const;   
00160         State state() const; 
00168         Kernel *createKernel(const std::string &name, cl_int *errcode_ret);
00169         
00175         std::vector<Kernel *> createKernels(cl_int *errcode_ret);
00176         
00182         DeviceProgram *deviceDependentProgram(DeviceInterface *device) const;
00183 
00188         cl_int info(cl_program_info param_name,
00189                     size_t param_value_size,
00190                     void *param_value,
00191                     size_t *param_value_size_ret) const;
00192 
00198         cl_int buildInfo(DeviceInterface *device,
00199                          cl_program_build_info param_name,
00200                          size_t param_value_size,
00201                          void *param_value,
00202                          size_t *param_value_size_ret) const;
00203 
00204     private:
00205         Type p_type;
00206         State p_state;
00207         std::string p_source;
00208 
00209         struct DeviceDependent
00210         {
00211             DeviceInterface *device;
00212             DeviceProgram *program;
00213             std::string unlinked_binary;
00214             llvm::Module *linked_module;
00215             Compiler *compiler;
00216         };
00217 
00218         std::vector<DeviceDependent> p_device_dependent;
00219         DeviceDependent p_null_device_dependent;
00220 
00221         void setDevices(cl_uint num_devices, DeviceInterface * const*devices);
00222         DeviceDependent &deviceDependent(DeviceInterface *device);
00223         const DeviceDependent &deviceDependent(DeviceInterface *device) const;
00224         std::vector<llvm::Function *> kernelFunctions(DeviceDependent &dep);
00225 };
00226 
00227 }
00228 
00229 struct _cl_program : public Coal::Program
00230 {};
00231 
00232 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines