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

/data/development/ViennaCL/dev/viennacl/ocl/program.hpp

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

Generated on Fri Dec 30 2011 23:20:43 for ViennaCL - The Vienna Computing Library by  doxygen 1.7.1