ViennaCL - The Vienna Computing Library: viennacl/device_specific/lazy_program_compiler.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2016, 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
36 class lazy_program_compiler
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
47 viennacl::ocl::program & program()
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:
65 viennacl::ocl::context * ctx_;
66 std::string name_;
67 std::string src_;
68 bool force_recompilation_;
69 };
70
71 }
72
73 }
74 #endif
viennacl::ocl::context::get_program
viennacl::ocl::program & get_program(std::string const &name)
Returns the program with the provided name.
Definition: context.hpp:532
viennacl::ocl::context::delete_program
void delete_program(std::string const &name)
Delete the program with the provided name.
Definition: context.hpp:514
viennacl::ocl::context
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
viennacl::device_specific::lazy_program_compiler
Definition: lazy_program_compiler.hpp:36
viennacl::ocl::context::add_program
viennacl::ocl::program & add_program(cl_program p, std::string const &prog_name)
Adds a program to the context.
Definition: context.hpp:368
context.hpp
Represents an OpenCL context within ViennaCL.
viennacl::ocl::program
Wrapper class for an OpenCL program.
Definition: program.hpp:42
viennacl::device_specific::lazy_program_compiler::lazy_program_compiler
lazy_program_compiler(viennacl::ocl::context *ctx, std::string const &name, std::string const &src, bool force_recompilation)
Definition: lazy_program_compiler.hpp:40
viennacl::ocl::context::has_program
bool has_program(std::string const &name)
Returns whether the program with the provided name exists or not.
Definition: context.hpp:571
viennacl::device_specific::lazy_program_compiler::lazy_program_compiler
lazy_program_compiler(viennacl::ocl::context *ctx, std::string const &name, bool force_recompilation)
Definition: lazy_program_compiler.hpp:41
viennacl::device_specific::lazy_program_compiler::program
viennacl::ocl::program & program()
Definition: lazy_program_compiler.hpp:47
viennacl::device_specific::lazy_program_compiler::add
void add(std::string const &src)
Definition: lazy_program_compiler.hpp:43
viennacl::device_specific::lazy_program_compiler::src
std::string const & src() const
Definition: lazy_program_compiler.hpp:45