summaryrefslogtreecommitdiff
path: root/boost/compute/program.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:24:46 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:25:39 +0900
commit4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch)
treefd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/compute/program.hpp
parentb5c87084afaef42b2d058f68091be31988a6a874 (diff)
downloadboost-upstream/1.65.0.tar.gz
boost-upstream/1.65.0.tar.bz2
boost-upstream/1.65.0.zip
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/compute/program.hpp')
-rw-r--r--boost/compute/program.hpp81
1 files changed, 69 insertions, 12 deletions
diff --git a/boost/compute/program.hpp b/boost/compute/program.hpp
index 7573aa02e6..e953d7a89e 100644
--- a/boost/compute/program.hpp
+++ b/boost/compute/program.hpp
@@ -272,13 +272,15 @@ public:
}
}
- #if defined(CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
+ #if defined(BOOST_COMPUTE_CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
/// Compiles the program with \p options.
///
/// \opencl_version_warning{1,2}
///
/// \see_opencl_ref{clCompileProgram}
- void compile(const std::string &options = std::string())
+ void compile(const std::string &options = std::string(),
+ const std::vector<std::pair<std::string, program> > &headers =
+ std::vector<std::pair<std::string, program> >())
{
const char *options_string = 0;
@@ -286,9 +288,36 @@ public:
options_string = options.c_str();
}
- cl_int ret = clCompileProgram(
- m_program, 0, 0, options_string, 0, 0, 0, 0, 0
- );
+ cl_int ret;
+ if (headers.empty())
+ {
+ ret = clCompileProgram(
+ m_program, 0, 0, options_string, 0, 0, 0, 0, 0
+ );
+ }
+ else
+ {
+ std::vector<const char*> header_names(headers.size());
+ std::vector<cl_program> header_programs(headers.size());
+ for (size_t i = 0; i < headers.size(); ++i)
+ {
+ header_names[i] = headers[i].first.c_str();
+ header_programs[i] = headers[i].second.m_program;
+ }
+
+ ret = clCompileProgram(
+ m_program,
+ 0,
+ 0,
+ options_string,
+ static_cast<cl_uint>(headers.size()),
+ header_programs.data(),
+ header_names.data(),
+ 0,
+ 0
+ );
+ }
+
if(ret != CL_SUCCESS){
BOOST_THROW_EXCEPTION(opencl_error(ret));
@@ -329,7 +358,7 @@ public:
return program(program_, false);
}
- #endif // CL_VERSION_1_2
+ #endif // BOOST_COMPUTE_CL_VERSION_1_2
/// Returns the build log.
std::string build_log() const
@@ -432,6 +461,33 @@ public:
return create_with_source(source, context);
}
+ /// Creates a new program with \p files in \p context.
+ ///
+ /// \see_opencl_ref{clCreateProgramWithSource}
+ static program create_with_source_file(const std::vector<std::string> &files,
+ const context &context)
+ {
+ std::vector<std::string> sources(files.size());
+
+ for(size_t i = 0; i < files.size(); ++i) {
+ // open file stream
+ std::ifstream stream(files[i].c_str());
+
+ if(stream.fail()){
+ BOOST_THROW_EXCEPTION(std::ios_base::failure("failed to create stream."));
+ }
+
+ // read source
+ sources[i] = std::string(
+ (std::istreambuf_iterator<char>(stream)),
+ std::istreambuf_iterator<char>()
+ );
+ }
+
+ // create program
+ return create_with_source(sources, context);
+ }
+
/// Creates a new program with \p binary of \p binary_size in
/// \p context.
///
@@ -489,7 +545,7 @@ public:
return create_with_binary(&binary[0], binary.size(), context);
}
- #if defined(CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
+ #if defined(BOOST_COMPUTE_CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
/// Creates a new program with the built-in kernels listed in
/// \p kernel_names for \p devices in \p context.
///
@@ -516,7 +572,7 @@ public:
return program(program_, false);
}
- #endif // CL_VERSION_1_2
+ #endif // BOOST_COMPUTE_CL_VERSION_1_2
/// Create a new program with \p source in \p context and builds it with \p options.
/**
@@ -543,10 +599,11 @@ public:
.process( options )
.process( source )
;
+ std::string hash_string = hash;
// Try to get cached program binaries:
try {
- boost::optional<program> prog = load_program_binary(hash, context);
+ boost::optional<program> prog = load_program_binary(hash_string, context);
if (prog) {
prog->build(options);
@@ -575,7 +632,7 @@ public:
#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
// Save program binaries for future reuse.
- save_program_binary(hash, prog);
+ save_program_binary(hash_string, prog);
#endif
return prog;
@@ -637,12 +694,12 @@ BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(program,
((std::vector<unsigned char *>, CL_PROGRAM_BINARIES))
)
-#ifdef CL_VERSION_1_2
+#ifdef BOOST_COMPUTE_CL_VERSION_1_2
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(program,
((size_t, CL_PROGRAM_NUM_KERNELS))
((std::string, CL_PROGRAM_KERNEL_NAMES))
)
-#endif // CL_VERSION_1_2
+#endif // BOOST_COMPUTE_CL_VERSION_1_2
} // end compute namespace
} // end boost namespace