• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/data/development/ViennaCL/ViennaCL-1.1.2/viennacl/ocl/program.hpp

Go to the documentation of this file.
00001 /* =======================================================================
00002    Copyright (c) 2010, Institute for Microelectronics, TU Vienna.
00003    http://www.iue.tuwien.ac.at
00004                              -----------------
00005                      ViennaCL - The Vienna Computing Library
00006                              -----------------
00007                             
00008    authors:    Karl Rupp                          rupp@iue.tuwien.ac.at
00009                Florian Rudolf                     flo.rudy+viennacl@gmail.com
00010                Josef Weinbub                      weinbub@iue.tuwien.ac.at
00011 
00012    license:    MIT (X11), see file LICENSE in the ViennaCL base directory
00013 ======================================================================= */
00014 
00015 #ifndef _VIENNACL_PROGRAM_HPP_
00016 #define _VIENNACL_PROGRAM_HPP_
00017 
00022 #include <string>
00023 #include <vector>
00024 #include "viennacl/ocl/forwards.h"
00025 #include "viennacl/ocl/handle.hpp"
00026 #include "viennacl/ocl/kernel.hpp"
00027 
00028 namespace viennacl
00029 {
00030   namespace ocl
00031   {
00032     class program
00033     {
00034       friend class kernel;
00035       
00036       typedef std::vector<viennacl::ocl::kernel>    KernelContainer;
00037       
00038     public:
00039       program() {}
00040       program(viennacl::ocl::handle<cl_program> const & h, std::string const & prog_name = std::string()) : handle_(h), name_(prog_name) {}
00041       
00042       program(program const & other)
00043       {
00044         handle_ = other.handle_;
00045         name_ = other.name_;
00046         kernels_ = other.kernels_;
00047       }
00048       
00049       viennacl::ocl::program & operator=(const program & other)
00050       {
00051         handle_ = other.handle_;
00052         name_ = other.name_;
00053         kernels_ = other.kernels_;
00054         return *this;
00055       }
00056 
00057       std::string const & name() const { return name_; }
00058       
00060       viennacl::ocl::kernel & add_kernel(std::string const & kernel_name)
00061       {
00062         viennacl::ocl::kernel temp(handle_, kernel_name);
00063         kernels_.push_back(temp);
00064         return kernels_.back();
00065       }
00066       
00068       viennacl::ocl::kernel & get_kernel(std::string const & name)
00069       {
00070         //std::cout << "Requiring kernel " << name << " from program " << name_ << std::endl;
00071         for (KernelContainer::iterator it = kernels_.begin();
00072               it != kernels_.end();
00073              ++it)
00074         {
00075           if (it->name() == name)
00076             return *it;
00077         }
00078         std::cerr << "ViennaCL: FATAL ERROR: Could not find kernel '" << name << "'" << std::endl;
00079         assert(!"Kernel not found");
00080         return kernels_[0];  //return a defined object
00081       }
00082 
00083     private:
00084       const viennacl::ocl::handle<cl_program> & handle() const { return handle_; }
00085       
00086       viennacl::ocl::handle<cl_program> handle_;
00087       std::string name_;
00088       KernelContainer kernels_;
00089     };
00090   } //namespace ocl
00091 } //namespace viennacl
00092 
00093 
00094 #endif

Generated on Sat May 21 2011 20:36:50 for ViennaCL - The Vienna Computing Library by  doxygen 1.7.1