JayBeams  0.1
Another project to have fun coding.
build_simple_kernel.cpp
Go to the documentation of this file.
2 #include <jb/log.hpp>
3 
4 #include <fstream>
5 
6 boost::compute::kernel jb::opencl::build_simple_kernel(
7  boost::compute::context context, boost::compute::device device,
8  char const* code, char const* kernel_name) {
9  auto program = build_simple_program(context, device, code);
10  return boost::compute::kernel(program, kernel_name);
11 }
12 
13 boost::compute::kernel jb::opencl::build_simple_kernel(
14  boost::compute::context context, boost::compute::device device,
15  std::istream& code, char const* kernel_name) {
16  auto program = build_simple_program(context, device, code);
17  return boost::compute::kernel(program, kernel_name);
18 }
19 
20 boost::compute::program jb::opencl::build_simple_program(
21  boost::compute::context context, boost::compute::device device,
22  char const* code) {
23  // ... create the program, a program may consist of multiple sources
24  // and have many kernels in it, but in our case it is rather simple ...
25  boost::compute::program program =
26  boost::compute::program::create_with_source(code, context);
27  try {
28  program.build();
29  } catch (boost::compute::opencl_error const& ex) {
30  JB_LOG(error) << "errors building program: " << ex.what() << "\n"
31  << program.build_log() << "\n";
32  throw;
33  }
34  return program;
35 }
36 
37 boost::compute::program jb::opencl::build_simple_program(
38  boost::compute::context context, boost::compute::device device,
39  std::istream& code) {
40  std::string tmp;
41  std::string line;
42  while (std::getline(code, line)) {
43  tmp += line;
44  tmp += "\n";
45  }
46  return build_simple_program(context, device, tmp.c_str());
47 }
boost::compute::kernel build_simple_kernel(boost::compute::context context, boost::compute::device device, char const *code, char const *kernel_name)
Build a simple program (one where everything is in a single string) and get a kernel from it...
boost::compute::program build_simple_program(boost::compute::context context, boost::compute::device device, char const *code)
Convenience function to build a simple program and return it.
#define JB_LOG(lvl)
Definition: log.hpp:70