ViennaCL - The Vienna Computing Library  1.2.0
program.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_OCL_PROGRAM_HPP_
2 #define VIENNACL_OCL_PROGRAM_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2011, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8 
9  -----------------
10  ViennaCL - The Vienna Computing Library
11  -----------------
12 
13  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
14 
15  (A list of authors and contributors can be found in the PDF manual)
16 
17  License: MIT (X11), see file LICENSE in the base directory
18 ============================================================================= */
19 
24 #include <string>
25 #include <vector>
26 #include "viennacl/ocl/forwards.h"
27 #include "viennacl/ocl/handle.hpp"
28 #include "viennacl/ocl/kernel.hpp"
29 
30 namespace viennacl
31 {
32  namespace ocl
33  {
34  class program
35  {
36  friend class kernel;
37 
38  typedef std::vector<viennacl::ocl::kernel> KernelContainer;
39 
40  public:
41  program() {}
42  program(viennacl::ocl::handle<cl_program> const & h, std::string const & prog_name = std::string()) : handle_(h), name_(prog_name) {}
43 
44  program(program const & other)
45  {
46  handle_ = other.handle_;
47  name_ = other.name_;
48  kernels_ = other.kernels_;
49  }
50 
52  {
53  handle_ = other.handle_;
54  name_ = other.name_;
55  kernels_ = other.kernels_;
56  return *this;
57  }
58 
59  std::string const & name() const { return name_; }
60 
62  viennacl::ocl::kernel & add_kernel(std::string const & kernel_name)
63  {
64  viennacl::ocl::kernel temp(handle_, kernel_name);
65  kernels_.push_back(temp);
66  return kernels_.back();
67  }
68 
70  viennacl::ocl::kernel & get_kernel(std::string const & name)
71  {
72  //std::cout << "Requiring kernel " << name << " from program " << name_ << std::endl;
73  for (KernelContainer::iterator it = kernels_.begin();
74  it != kernels_.end();
75  ++it)
76  {
77  if (it->name() == name)
78  return *it;
79  }
80  std::cerr << "ViennaCL: FATAL ERROR: Could not find kernel '" << name << "'" << std::endl;
81  std::cout << "Number of kernels in program: " << kernels_.size() << std::endl;
82  assert(!"Kernel not found");
83  return kernels_[0]; //return a defined object
84  }
85 
86  private:
87  const viennacl::ocl::handle<cl_program> & handle() const { return handle_; }
88 
90  std::string name_;
91  KernelContainer kernels_;
92  };
93  } //namespace ocl
94 } //namespace viennacl
95 
96 
97 #endif