ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
lazy_program_compiler.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_DEVICE_SPECIFIC_LAZY_PROGRAM_COMPILER_HPP
2 #define VIENNACL_DEVICE_SPECIFIC_LAZY_PROGRAM_COMPILER_HPP
3 
4 /* =========================================================================
5  Copyright (c) 2010-2015, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
21 
26 #include <map>
27 
28 #include "viennacl/ocl/context.hpp"
29 
30 namespace viennacl
31 {
32 
33 namespace device_specific
34 {
35 
37  {
38  public:
39 
40  lazy_program_compiler(viennacl::ocl::context * ctx, std::string const & name, std::string const & src, bool force_recompilation) : ctx_(ctx), name_(name), src_(src), force_recompilation_(force_recompilation){ }
41  lazy_program_compiler(viennacl::ocl::context * ctx, std::string const & name, bool force_recompilation) : ctx_(ctx), name_(name), force_recompilation_(force_recompilation){ }
42 
43  void add(std::string const & src) { src_+=src; }
44 
45  std::string const & src() const { return src_; }
46 
48  {
49  if (force_recompilation_ && ctx_->has_program(name_))
50  ctx_->delete_program(name_);
51  if (!ctx_->has_program(name_))
52  {
53 #ifdef VIENNACL_BUILD_INFO
54  std::cerr << "Creating program " << program_name << std::endl;
55 #endif
56  ctx_->add_program(src_, name_);
57 #ifdef VIENNACL_BUILD_INFO
58  std::cerr << "Done creating program " << program_name << std::endl;
59 #endif
60  }
61  return ctx_->get_program(name_);
62  }
63 
64  private:
66  std::string name_;
67  std::string src_;
68  bool force_recompilation_;
69  };
70 
71 }
72 
73 }
74 #endif
viennacl::ocl::program & get_program(std::string const &name)
Returns the program with the provided name.
Definition: context.hpp:532
void delete_program(std::string const &name)
Delete the program with the provided name.
Definition: context.hpp:514
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
viennacl::ocl::program & add_program(cl_program p, std::string const &prog_name)
Adds a program to the context.
Definition: context.hpp:368
Represents an OpenCL context within ViennaCL.
Wrapper class for an OpenCL program.
Definition: program.hpp:42
lazy_program_compiler(viennacl::ocl::context *ctx, std::string const &name, std::string const &src, bool force_recompilation)
bool has_program(std::string const &name)
Returns whether the program with the provided name exists or not.
Definition: context.hpp:571
lazy_program_compiler(viennacl::ocl::context *ctx, std::string const &name, bool force_recompilation)