summaryrefslogtreecommitdiff
path: root/src/clpp11.hpp
diff options
context:
space:
mode:
authorIvan Shapovalov <intelfx@intelfx.name>2016-11-26 13:32:54 +0300
committerIvan Shapovalov <intelfx@intelfx.name>2017-01-24 02:42:59 +0300
commit8e1c084c9329fe1842e9a3eeeaa46248dec460a5 (patch)
tree2204a99a71c961d63f48e0e6401feabb35063e4b /src/clpp11.hpp
parentee4124dcbc37b92207d0590524e8246e71811a48 (diff)
src/clpp11.hpp: do not store program source/binary in Program
The stored source/binary does not seem to serve any purpose, yet its presence makes Program a heavy (not pure refcounted) object, which is undesired esp. because it is copied from the cache in the hot path.
Diffstat (limited to 'src/clpp11.hpp')
-rw-r--r--src/clpp11.hpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/clpp11.hpp b/src/clpp11.hpp
index 0383f53a..d73c57be 100644
--- a/src/clpp11.hpp
+++ b/src/clpp11.hpp
@@ -355,33 +355,31 @@ using ContextPointer = cl_context*;
// Enumeration of build statuses of the run-time compilation process
enum class BuildStatus { kSuccess, kError, kInvalid };
-// C++11 version of 'cl_program'. Additionally holds the program's source code.
+// C++11 version of 'cl_program'.
class Program {
public:
// Note that there is no constructor based on the regular OpenCL data-type because of extra state
// Source-based constructor with memory management
- explicit Program(const Context &context, std::string source):
- program_(new cl_program, [](cl_program* p) { CheckErrorDtor(clReleaseProgram(*p)); delete p; }),
- length_(source.length()),
- source_(std::move(source)),
- source_ptr_(&source_[0]) {
+ explicit Program(const Context &context, const std::string &source):
+ program_(new cl_program, [](cl_program* p) { CheckErrorDtor(clReleaseProgram(*p)); delete p; }) {
+ const char *source_ptr = &source[0];
+ size_t length = source.length();
auto status = CL_SUCCESS;
- *program_ = clCreateProgramWithSource(context(), 1, &source_ptr_, &length_, &status);
+ *program_ = clCreateProgramWithSource(context(), 1, &source_ptr, &length, &status);
CLError::Check(status, "clCreateProgramWithSource");
}
// Binary-based constructor with memory management
explicit Program(const Device &device, const Context &context, const std::string& binary):
- program_(new cl_program, [](cl_program* p) { CheckErrorDtor(clReleaseProgram(*p)); delete p; }),
- length_(binary.length()),
- source_(binary),
- source_ptr_(&source_[0]) {
+ program_(new cl_program, [](cl_program* p) { CheckErrorDtor(clReleaseProgram(*p)); delete p; }) {
+ const char *binary_ptr = &binary[0];
+ size_t length = binary.length();
auto status1 = CL_SUCCESS;
auto status2 = CL_SUCCESS;
const cl_device_id dev = device();
- *program_ = clCreateProgramWithBinary(context(), 1, &dev, &length_,
- reinterpret_cast<const unsigned char**>(&source_ptr_),
+ *program_ = clCreateProgramWithBinary(context(), 1, &dev, &length,
+ reinterpret_cast<const unsigned char**>(&binary_ptr),
&status1, &status2);
CLError::Check(status1, "clCreateProgramWithBinary (binary status)");
CLError::Check(status2, "clCreateProgramWithBinary");
@@ -421,9 +419,6 @@ class Program {
const cl_program& operator()() const { return *program_; }
private:
std::shared_ptr<cl_program> program_;
- size_t length_;
- std::string source_; // Note: the source can also be a binary or IR
- const char* source_ptr_;
};
// =================================================================================================