[compute] 39/46: Add program::create_with_source() with vector of strings

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Dec 21 18:28:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository compute.

commit cb863b91a62a83f2e372044acdcb6718dc6be3b7
Author: Kyle Lutz <kyle.r.lutz at gmail.com>
Date:   Thu Dec 3 23:49:52 2015 -0800

    Add program::create_with_source() with vector of strings
---
 include/boost/compute/program.hpp | 24 ++++++++++++++++++++++++
 test/test_program.cpp             | 15 +++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/boost/compute/program.hpp b/include/boost/compute/program.hpp
index 218d840..7573aa0 100644
--- a/include/boost/compute/program.hpp
+++ b/include/boost/compute/program.hpp
@@ -385,6 +385,30 @@ public:
         return program(program_, false);
     }
 
+    /// Creates a new program with \p sources in \p context.
+    ///
+    /// \see_opencl_ref{clCreateProgramWithSource}
+    static program create_with_source(const std::vector<std::string> &sources,
+                                      const context &context)
+    {
+        std::vector<const char*> source_strings(sources.size());
+        for(size_t i = 0; i < sources.size(); i++){
+            source_strings[i] = sources[i].c_str();
+        }
+
+        cl_int error = 0;
+        cl_program program_ = clCreateProgramWithSource(context,
+                                                        uint_(sources.size()),
+                                                        &source_strings[0],
+                                                        0,
+                                                        &error);
+        if(!program_){
+            BOOST_THROW_EXCEPTION(opencl_error(error));
+        }
+
+        return program(program_, false);
+    }
+
     /// Creates a new program with \p file in \p context.
     ///
     /// \see_opencl_ref{clCreateProgramWithSource}
diff --git a/test/test_program.cpp b/test/test_program.cpp
index cbd82c7..e1cc8f0 100644
--- a/test/test_program.cpp
+++ b/test/test_program.cpp
@@ -55,6 +55,21 @@ BOOST_AUTO_TEST_CASE(program_source)
     BOOST_CHECK_EQUAL(std::string(source), program.source());
 }
 
+BOOST_AUTO_TEST_CASE(program_multiple_sources)
+{
+    std::vector<std::string> sources;
+    sources.push_back("__kernel void foo(__global int* x) { }\n");
+    sources.push_back("__kernel void bar(__global float* y) { }\n");
+
+    // create program from sources
+    boost::compute::program program =
+        boost::compute::program::create_with_source(sources, context);
+    program.build();
+
+    boost::compute::kernel foo = program.create_kernel("foo");
+    boost::compute::kernel bar = program.create_kernel("bar");
+}
+
 BOOST_AUTO_TEST_CASE(program_source_no_file)
 {
     // create program from a non-existant source file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/compute.git



More information about the debian-science-commits mailing list