All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lazy_program_compiler.hpp
Go to the documentation of this file.
#ifndef VIENNACL_DEVICE_SPECIFIC_LAZY_PROGRAM_COMPILER_HPP
#define VIENNACL_DEVICE_SPECIFIC_LAZY_PROGRAM_COMPILER_HPP
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <map>
#include "viennacl/ocl/context.hpp"
namespace viennacl
{
namespace device_specific
{
class lazy_program_compiler
{
public:
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){ }
lazy_program_compiler(viennacl::ocl::context * ctx, std::string const & name, bool force_recompilation) : ctx_(ctx), name_(name), force_recompilation_(force_recompilation){ }
void add(std::string const & src) { src_+=src; }
std::string const & src() const { return src_; }
viennacl::ocl::program & program()
{
if (force_recompilation_ && ctx_->has_program(name_))
ctx_->delete_program(name_);
if (!ctx_->has_program(name_))
{
#ifdef VIENNACL_BUILD_INFO
std::cerr << "Creating program " << program_name << std::endl;
#endif
ctx_->add_program(src_, name_);
#ifdef VIENNACL_BUILD_INFO
std::cerr << "Done creating program " << program_name << std::endl;
#endif
}
return ctx_->get_program(name_);
}
private:
viennacl::ocl::context * ctx_;
std::string name_;
std::string src_;
bool force_recompilation_;
};
}
}
#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