?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/compute.zip
???????
PK g^�[�˒�� � # exception/program_build_failure.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2017 Kristian Popov <kristian.popov@outlook.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_EXCEPTION_PROGRAM_BUILD_FAILURE_HPP #define BOOST_COMPUTE_EXCEPTION_PROGRAM_BUILD_FAILURE_HPP #include <string> #include <boost/compute/exception/opencl_error.hpp> namespace boost { namespace compute { /// \class program_build_failure /// \brief A failure when building OpenCL program /// /// Instances of this class are thrown when OpenCL program build fails. /// Extends opencl_error by saving a program build log so it can be used /// for testing, debugging, or logging purposes. /// /// \see opencl_error class program_build_failure : public opencl_error { public: /// Creates a new program_build_failure exception object for \p error /// and \p build_log. explicit program_build_failure(cl_int error, const std::string& build_log) throw() : opencl_error(error), m_build_log(build_log) { } /// Destroys the program_build_failure object. ~program_build_failure() throw() { } /// Retrieve the log of a failed program build. std::string build_log() const throw() { return m_build_log; } private: std::string m_build_log; }; } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_EXCEPTION_PROGRAM_BUILD_FAILURE_HPP PK g^�[ R/? exception/context_error.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_EXCEPTION_CONTEXT_ERROR_HPP #define BOOST_COMPUTE_EXCEPTION_CONTEXT_ERROR_HPP #include <exception> namespace boost { namespace compute { class context; /// \class context_error /// \brief A run-time OpenCL context error. /// /// The context_error exception is thrown when the OpenCL context encounters /// an error condition. Boost.Compute is notified of these error conditions by /// registering an error handler when creating context objects (via the /// \c pfn_notify argument to the \c clCreateContext() function). /// /// This exception is different than the opencl_error exception which is thrown /// as a result of error caused when calling a single OpenCL API function. /// /// \see opencl_error class context_error : public std::exception { public: /// Creates a new context error exception object. context_error(const context *context, const char *errinfo, const void *private_info, size_t private_info_size) throw() : m_context(context), m_errinfo(errinfo), m_private_info(private_info), m_private_info_size(private_info_size) { } /// Destroys the context error object. ~context_error() throw() { } /// Returns a string with a description of the error. const char* what() const throw() { return m_errinfo; } /// Returns a pointer to the context object which generated the error /// notification. const context* get_context_ptr() const throw() { return m_context; } /// Returns a pointer to the private info memory block. const void* get_private_info_ptr() const throw() { return m_private_info; } /// Returns the size of the private info memory block. size_t get_private_info_size() const throw() { return m_private_info_size; } private: const context *m_context; const char *m_errinfo; const void *m_private_info; size_t m_private_info_size; }; } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_EXCEPTION_CONTEXT_ERROR_HPP PK g^�[Km�'� � ) exception/unsupported_extension_error.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_EXCEPTION_UNSUPPORTED_EXTENSION_ERROR_HPP #define BOOST_COMPUTE_EXCEPTION_UNSUPPORTED_EXTENSION_ERROR_HPP #include <exception> #include <sstream> #include <string> namespace boost { namespace compute { /// \class unsupported_extension_error /// \brief Exception thrown when attempting to use an unsupported /// OpenCL extension. /// /// This exception is thrown when the user attempts to use an OpenCL /// extension which is not supported on the platform and/or device. /// /// An example of this is attempting to use CL-GL sharing on a non-GPU /// device. /// /// \see opencl_error class unsupported_extension_error : public std::exception { public: /// Creates a new unsupported extension error exception object indicating /// that \p extension is not supported by the OpenCL platform or device. explicit unsupported_extension_error(const char *extension) throw() : m_extension(extension) { std::stringstream msg; msg << "OpenCL extension " << extension << " not supported"; m_error_string = msg.str(); } /// Destroys the unsupported extension error object. ~unsupported_extension_error() throw() { } /// Returns the name of the unsupported extension. std::string extension_name() const throw() { return m_extension; } /// Returns a string containing a human-readable error message containing /// the name of the unsupported exception. const char* what() const throw() { return m_error_string.c_str(); } private: std::string m_extension; std::string m_error_string; }; } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_EXCEPTION_UNSUPPORTED_EXTENSION_ERROR_HPP PK g^�[���) ) exception/no_device_found.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_EXCEPTION_NO_DEVICE_FOUND_HPP #define BOOST_COMPUTE_EXCEPTION_NO_DEVICE_FOUND_HPP #include <exception> namespace boost { namespace compute { /// \class no_device_found /// \brief Exception thrown when no OpenCL device is found /// /// This exception is thrown when no valid OpenCL device can be found. /// /// \see opencl_error class no_device_found : public std::exception { public: /// Creates a new no_device_found exception object. no_device_found() throw() { } /// Destroys the no_device_found exception object. ~no_device_found() throw() { } /// Returns a string containing a human-readable error message. const char* what() const throw() { return "No OpenCL device found"; } }; } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_EXCEPTION_NO_DEVICE_FOUND_HPP PK g^�[�E�3 3 exception/opencl_error.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_EXCEPTION_OPENCL_ERROR_HPP #define BOOST_COMPUTE_EXCEPTION_OPENCL_ERROR_HPP #include <exception> #include <string> #include <sstream> #include <boost/compute/cl.hpp> namespace boost { namespace compute { /// \class opencl_error /// \brief A run-time OpenCL error. /// /// The opencl_error class represents an error returned from an OpenCL /// function. /// /// \see context_error class opencl_error : public std::exception { public: /// Creates a new opencl_error exception object for \p error. explicit opencl_error(cl_int error) throw() : m_error(error), m_error_string(to_string(error)) { } /// Destroys the opencl_error object. ~opencl_error() throw() { } /// Returns the numeric error code. cl_int error_code() const throw() { return m_error; } /// Returns a string description of the error. std::string error_string() const throw() { return m_error_string; } /// Returns a C-string description of the error. const char* what() const throw() { return m_error_string.c_str(); } /// Static function which converts the numeric OpenCL error code \p error /// to a human-readable string. /// /// For example: /// \code /// std::cout << opencl_error::to_string(CL_INVALID_KERNEL_ARGS) << std::endl; /// \endcode /// /// Will print "Invalid Kernel Arguments". /// /// If the error code is unknown (e.g. not a valid OpenCL error), a string /// containing "Unknown OpenCL Error" along with the error number will be /// returned. static std::string to_string(cl_int error) { switch(error){ case CL_SUCCESS: return "Success"; case CL_DEVICE_NOT_FOUND: return "Device Not Found"; case CL_DEVICE_NOT_AVAILABLE: return "Device Not Available"; case CL_COMPILER_NOT_AVAILABLE: return "Compiler Not Available"; case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "Memory Object Allocation Failure"; case CL_OUT_OF_RESOURCES: return "Out of Resources"; case CL_OUT_OF_HOST_MEMORY: return "Out of Host Memory"; case CL_PROFILING_INFO_NOT_AVAILABLE: return "Profiling Information Not Available"; case CL_MEM_COPY_OVERLAP: return "Memory Copy Overlap"; case CL_IMAGE_FORMAT_MISMATCH: return "Image Format Mismatch"; case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image Format Not Supported"; case CL_BUILD_PROGRAM_FAILURE: return "Build Program Failure"; case CL_MAP_FAILURE: return "Map Failure"; case CL_INVALID_VALUE: return "Invalid Value"; case CL_INVALID_DEVICE_TYPE: return "Invalid Device Type"; case CL_INVALID_PLATFORM: return "Invalid Platform"; case CL_INVALID_DEVICE: return "Invalid Device"; case CL_INVALID_CONTEXT: return "Invalid Context"; case CL_INVALID_QUEUE_PROPERTIES: return "Invalid Queue Properties"; case CL_INVALID_COMMAND_QUEUE: return "Invalid Command Queue"; case CL_INVALID_HOST_PTR: return "Invalid Host Pointer"; case CL_INVALID_MEM_OBJECT: return "Invalid Memory Object"; case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "Invalid Image Format Descriptor"; case CL_INVALID_IMAGE_SIZE: return "Invalid Image Size"; case CL_INVALID_SAMPLER: return "Invalid Sampler"; case CL_INVALID_BINARY: return "Invalid Binary"; case CL_INVALID_BUILD_OPTIONS: return "Invalid Build Options"; case CL_INVALID_PROGRAM: return "Invalid Program"; case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid Program Executable"; case CL_INVALID_KERNEL_NAME: return "Invalid Kernel Name"; case CL_INVALID_KERNEL_DEFINITION: return "Invalid Kernel Definition"; case CL_INVALID_KERNEL: return "Invalid Kernel"; case CL_INVALID_ARG_INDEX: return "Invalid Argument Index"; case CL_INVALID_ARG_VALUE: return "Invalid Argument Value"; case CL_INVALID_ARG_SIZE: return "Invalid Argument Size"; case CL_INVALID_KERNEL_ARGS: return "Invalid Kernel Arguments"; case CL_INVALID_WORK_DIMENSION: return "Invalid Work Dimension"; case CL_INVALID_WORK_GROUP_SIZE: return "Invalid Work Group Size"; case CL_INVALID_WORK_ITEM_SIZE: return "Invalid Work Item Size"; case CL_INVALID_GLOBAL_OFFSET: return "Invalid Global Offset"; case CL_INVALID_EVENT_WAIT_LIST: return "Invalid Event Wait List"; case CL_INVALID_EVENT: return "Invalid Event"; case CL_INVALID_OPERATION: return "Invalid Operation"; case CL_INVALID_GL_OBJECT: return "Invalid GL Object"; case CL_INVALID_BUFFER_SIZE: return "Invalid Buffer Size"; case CL_INVALID_MIP_LEVEL: return "Invalid MIP Level"; case CL_INVALID_GLOBAL_WORK_SIZE: return "Invalid Global Work Size"; #ifdef BOOST_COMPUTE_CL_VERSION_1_2 case CL_COMPILE_PROGRAM_FAILURE: return "Compile Program Failure"; case CL_LINKER_NOT_AVAILABLE: return "Linker Not Available"; case CL_LINK_PROGRAM_FAILURE: return "Link Program Failure"; case CL_DEVICE_PARTITION_FAILED: return "Device Partition Failed"; case CL_KERNEL_ARG_INFO_NOT_AVAILABLE: return "Kernel Argument Info Not Available"; case CL_INVALID_PROPERTY: return "Invalid Property"; case CL_INVALID_IMAGE_DESCRIPTOR: return "Invalid Image Descriptor"; case CL_INVALID_COMPILER_OPTIONS: return "Invalid Compiler Options"; case CL_INVALID_LINKER_OPTIONS: return "Invalid Linker Options"; case CL_INVALID_DEVICE_PARTITION_COUNT: return "Invalid Device Partition Count"; #endif // BOOST_COMPUTE_CL_VERSION_1_2 #ifdef BOOST_COMPUTE_CL_VERSION_2_0 case CL_INVALID_PIPE_SIZE: return "Invalid Pipe Size"; case CL_INVALID_DEVICE_QUEUE: return "Invalid Device Queue"; #endif default: { std::stringstream s; s << "Unknown OpenCL Error (" << error << ")"; return s.str(); } } } private: cl_int m_error; std::string m_error_string; }; } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_EXCEPTION_OPENCL_ERROR_HPP PK g^�[�]i buffer.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_BUFFER_HPP #define BOOST_COMPUTE_BUFFER_HPP #include <boost/compute/config.hpp> #include <boost/compute/context.hpp> #include <boost/compute/exception.hpp> #include <boost/compute/memory_object.hpp> #include <boost/compute/detail/get_object_info.hpp> namespace boost { namespace compute { // forward declarations class command_queue; /// \class buffer /// \brief A memory buffer on a compute device. /// /// The buffer class represents a memory buffer on a compute device. /// /// Buffers are allocated within a compute context. For example, to allocate /// a memory buffer for 32 float's: /// /// \snippet test/test_buffer.cpp constructor /// /// Once created, data can be copied to and from the buffer using the /// \c enqueue_*_buffer() methods in the command_queue class. For example, to /// copy a set of \c int values from the host to the device: /// \code /// int data[] = { 1, 2, 3, 4 }; /// /// queue.enqueue_write_buffer(buf, 0, 4 * sizeof(int), data); /// \endcode /// /// Also see the copy() algorithm for a higher-level interface to copying data /// between the host and the device. For a higher-level, dynamically-resizable, /// type-safe container for data on a compute device, use the vector<T> class. /// /// Buffer objects have reference semantics. Creating a copy of a buffer /// object simply creates another reference to the underlying OpenCL memory /// object. To create an actual copy use the buffer::clone() method. /// /// \see context, command_queue class buffer : public memory_object { public: /// Creates a null buffer object. buffer() : memory_object() { } /// Creates a buffer object for \p mem. If \p retain is \c true, the /// reference count for \p mem will be incremented. explicit buffer(cl_mem mem, bool retain = true) : memory_object(mem, retain) { } /// Create a new memory buffer in of \p size with \p flags in /// \p context. /// /// \see_opencl_ref{clCreateBuffer} buffer(const context &context, size_t size, cl_mem_flags flags = read_write, void *host_ptr = 0) { cl_int error = 0; m_mem = clCreateBuffer(context, flags, (std::max)(size, size_t(1)), host_ptr, &error); if(!m_mem){ BOOST_THROW_EXCEPTION(opencl_error(error)); } } /// Creates a new buffer object as a copy of \p other. buffer(const buffer &other) : memory_object(other) { } /// Copies the buffer object from \p other to \c *this. buffer& operator=(const buffer &other) { if(this != &other){ memory_object::operator=(other); } return *this; } #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES /// Move-constructs a new buffer object from \p other. buffer(buffer&& other) BOOST_NOEXCEPT : memory_object(std::move(other)) { } /// Move-assigns the buffer from \p other to \c *this. buffer& operator=(buffer&& other) BOOST_NOEXCEPT { memory_object::operator=(std::move(other)); return *this; } #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES /// Destroys the buffer object. ~buffer() { } /// Returns the size of the buffer in bytes. size_t size() const { return get_memory_size(); } /// \internal_ size_t max_size() const { return get_context().get_device().max_memory_alloc_size(); } /// Returns information about the buffer. /// /// \see_opencl_ref{clGetMemObjectInfo} template<class T> T get_info(cl_mem_info info) const { return get_memory_info<T>(info); } /// \overload template<int Enum> typename detail::get_object_info_type<buffer, Enum>::type get_info() const; /// Creates a new buffer with a copy of the data in \c *this. Uses /// \p queue to perform the copy. buffer clone(command_queue &queue) const; #if defined(BOOST_COMPUTE_CL_VERSION_1_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) /// Creates a new buffer out of this buffer. /// The new buffer is a sub region of this buffer. /// \p flags The mem_flags which should be used to create the new buffer /// \p origin The start index in this buffer /// \p size The size of the new sub buffer /// /// \see_opencl_ref{clCreateSubBuffer} /// /// \opencl_version_warning{1,1} buffer create_subbuffer(cl_mem_flags flags, size_t origin, size_t size) { BOOST_ASSERT(origin + size <= this->size()); BOOST_ASSERT(origin % (get_context(). get_device(). get_info<CL_DEVICE_MEM_BASE_ADDR_ALIGN>() / 8) == 0); cl_int error = 0; cl_buffer_region region = { origin, size }; cl_mem mem = clCreateSubBuffer(m_mem, flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &error); if(!mem){ BOOST_THROW_EXCEPTION(opencl_error(error)); } return buffer(mem, false); } #endif // BOOST_COMPUTE_CL_VERSION_1_1 }; /// \internal_ define get_info() specializations for buffer BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(buffer, ((cl_mem_object_type, CL_MEM_TYPE)) ((cl_mem_flags, CL_MEM_FLAGS)) ((size_t, CL_MEM_SIZE)) ((void *, CL_MEM_HOST_PTR)) ((cl_uint, CL_MEM_MAP_COUNT)) ((cl_uint, CL_MEM_REFERENCE_COUNT)) ((cl_context, CL_MEM_CONTEXT)) ) #ifdef BOOST_COMPUTE_CL_VERSION_1_1 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(buffer, ((cl_mem, CL_MEM_ASSOCIATED_MEMOBJECT)) ((size_t, CL_MEM_OFFSET)) ) #endif // BOOST_COMPUTE_CL_VERSION_1_1 namespace detail { // set_kernel_arg specialization for buffer template<> struct set_kernel_arg<buffer> { void operator()(kernel &kernel_, size_t index, const buffer &buffer_) { kernel_.set_arg(index, buffer_.get()); } }; } // end detail namespace } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_BUFFER_HPP PK g^�[�s�� � allocator.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_ALLOCATOR_HPP #define BOOST_COMPUTE_ALLOCATOR_HPP /// \file /// /// Meta-header to include all Boost.Compute allocator headers. #include <boost/compute/allocator/buffer_allocator.hpp> #include <boost/compute/allocator/pinned_allocator.hpp> #endif // BOOST_COMPUTE_ALLOCATOR_HPP PK g^�[��^R R type_traits.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_TYPE_TRAITS_HPP #define BOOST_COMPUTE_TYPE_TRAITS_HPP #include <boost/compute/type_traits/common_type.hpp> #include <boost/compute/type_traits/is_device_iterator.hpp> #include <boost/compute/type_traits/is_fundamental.hpp> #include <boost/compute/type_traits/is_vector_type.hpp> #include <boost/compute/type_traits/make_vector_type.hpp> #include <boost/compute/type_traits/result_of.hpp> #include <boost/compute/type_traits/scalar_type.hpp> #include <boost/compute/type_traits/type_definition.hpp> #include <boost/compute/type_traits/type_name.hpp> #include <boost/compute/type_traits/vector_size.hpp> #endif // BOOST_COMPUTE_TYPE_TRAITS_HPP PK g^�[!&u u core.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_CORE_HPP #define BOOST_COMPUTE_CORE_HPP /// \file /// /// Meta-header to include all Boost.Compute core headers. #include <boost/compute/buffer.hpp> #include <boost/compute/command_queue.hpp> #include <boost/compute/config.hpp> #include <boost/compute/context.hpp> #include <boost/compute/device.hpp> #include <boost/compute/event.hpp> #include <boost/compute/kernel.hpp> #include <boost/compute/types.hpp> #include <boost/compute/memory_object.hpp> #include <boost/compute/platform.hpp> #include <boost/compute/program.hpp> #include <boost/compute/system.hpp> #include <boost/compute/user_event.hpp> #include <boost/compute/version.hpp> #endif // BOOST_COMPUTE_CORE_HPP PK g^�[��B��D �D kernel.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_KERNEL_HPP #define BOOST_COMPUTE_KERNEL_HPP #include <string> #include <boost/assert.hpp> #include <boost/utility/enable_if.hpp> #include <boost/optional.hpp> #include <boost/compute/cl_ext.hpp> // cl_khr_subgroups #include <boost/compute/config.hpp> #include <boost/compute/exception.hpp> #include <boost/compute/program.hpp> #include <boost/compute/platform.hpp> #include <boost/compute/type_traits/is_fundamental.hpp> #include <boost/compute/detail/diagnostic.hpp> #include <boost/compute/detail/get_object_info.hpp> #include <boost/compute/detail/assert_cl_success.hpp> namespace boost { namespace compute { namespace detail { template<class T> struct set_kernel_arg; } // end detail namespace /// \class kernel /// \brief A compute kernel. /// /// \see command_queue, program class kernel { public: /// Creates a null kernel object. kernel() : m_kernel(0) { } /// Creates a new kernel object for \p kernel. If \p retain is /// \c true, the reference count for \p kernel will be incremented. explicit kernel(cl_kernel kernel, bool retain = true) : m_kernel(kernel) { if(m_kernel && retain){ clRetainKernel(m_kernel); } } /// Creates a new kernel object with \p name from \p program. kernel(const program &program, const std::string &name) { cl_int error = 0; m_kernel = clCreateKernel(program.get(), name.c_str(), &error); if(!m_kernel){ BOOST_THROW_EXCEPTION(opencl_error(error)); } } /// Creates a new kernel object as a copy of \p other. kernel(const kernel &other) : m_kernel(other.m_kernel) { if(m_kernel){ clRetainKernel(m_kernel); } } /// Copies the kernel object from \p other to \c *this. kernel& operator=(const kernel &other) { if(this != &other){ if(m_kernel){ clReleaseKernel(m_kernel); } m_kernel = other.m_kernel; if(m_kernel){ clRetainKernel(m_kernel); } } return *this; } #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES /// Move-constructs a new kernel object from \p other. kernel(kernel&& other) BOOST_NOEXCEPT : m_kernel(other.m_kernel) { other.m_kernel = 0; } /// Move-assigns the kernel from \p other to \c *this. kernel& operator=(kernel&& other) BOOST_NOEXCEPT { if(m_kernel){ clReleaseKernel(m_kernel); } m_kernel = other.m_kernel; other.m_kernel = 0; return *this; } #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES /// Destroys the kernel object. ~kernel() { if(m_kernel){ BOOST_COMPUTE_ASSERT_CL_SUCCESS( clReleaseKernel(m_kernel) ); } } #if defined(BOOST_COMPUTE_CL_VERSION_2_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) /// Creates a new kernel object based on a shallow copy of /// the undelying OpenCL kernel object. /// /// \opencl_version_warning{2,1} /// /// \see_opencl21_ref{clCloneKernel} kernel clone() { cl_int ret = 0; cl_kernel k = clCloneKernel(m_kernel, &ret); return kernel(k, false); } #endif // BOOST_COMPUTE_CL_VERSION_2_1 /// Returns a reference to the underlying OpenCL kernel object. cl_kernel& get() const { return const_cast<cl_kernel &>(m_kernel); } /// Returns the function name for the kernel. std::string name() const { return get_info<std::string>(CL_KERNEL_FUNCTION_NAME); } /// Returns the number of arguments for the kernel. size_t arity() const { return get_info<cl_uint>(CL_KERNEL_NUM_ARGS); } /// Returns the program for the kernel. program get_program() const { return program(get_info<cl_program>(CL_KERNEL_PROGRAM)); } /// Returns the context for the kernel. context get_context() const { return context(get_info<cl_context>(CL_KERNEL_CONTEXT)); } /// Returns information about the kernel. /// /// \see_opencl_ref{clGetKernelInfo} template<class T> T get_info(cl_kernel_info info) const { return detail::get_object_info<T>(clGetKernelInfo, m_kernel, info); } /// \overload template<int Enum> typename detail::get_object_info_type<kernel, Enum>::type get_info() const; #if defined(BOOST_COMPUTE_CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) /// Returns information about the argument at \p index. /// /// For example, to get the name of the first argument: /// \code /// std::string arg = kernel.get_arg_info<std::string>(0, CL_KERNEL_ARG_NAME); /// \endcode /// /// Note, this function requires that the program be compiled with the /// \c "-cl-kernel-arg-info" flag. For example: /// \code /// program.build("-cl-kernel-arg-info"); /// \endcode /// /// \opencl_version_warning{1,2} /// /// \see_opencl_ref{clGetKernelArgInfo} template<class T> T get_arg_info(size_t index, cl_kernel_arg_info info) const { return detail::get_object_info<T>( clGetKernelArgInfo, m_kernel, info, static_cast<cl_uint>(index) ); } /// \overload template<int Enum> typename detail::get_object_info_type<kernel, Enum>::type get_arg_info(size_t index) const; #endif // BOOST_COMPUTE_CL_VERSION_1_2 /// Returns work-group information for the kernel with \p device. /// /// \see_opencl_ref{clGetKernelWorkGroupInfo} template<class T> T get_work_group_info(const device &device, cl_kernel_work_group_info info) const { return detail::get_object_info<T>(clGetKernelWorkGroupInfo, m_kernel, info, device.id()); } #if defined(BOOST_COMPUTE_CL_VERSION_2_1) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) /// Returns sub-group information for the kernel with \p device. Returns a null /// optional if \p device is not 2.1 device, or is not 2.0 device with support /// for cl_khr_subgroups extension. /// /// \opencl_version_warning{2,1} /// \see_opencl21_ref{clGetKernelSubGroupInfo} /// \see_opencl2_ref{clGetKernelSubGroupInfoKHR} template<class T> boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info, const size_t input_size, const void * input) const { if(device.check_version(2, 1)) { return detail::get_object_info<T>( clGetKernelSubGroupInfo, m_kernel, info, device.id(), input_size, input ); } else if(!device.check_version(2, 0) || !device.supports_extension("cl_khr_subgroups")) { return boost::optional<T>(); } // Only CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE and CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE // are supported in cl_khr_subgroups extension for 2.0 devices. else if(info != CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE && info != CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE) { return boost::optional<T>(); } BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS(); clGetKernelSubGroupInfoKHR_fn clGetKernelSubGroupInfoKHR_fptr = reinterpret_cast<clGetKernelSubGroupInfoKHR_fn>( reinterpret_cast<size_t>( device.platform().get_extension_function_address("clGetKernelSubGroupInfoKHR") ) ); BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS(); return detail::get_object_info<T>( clGetKernelSubGroupInfoKHR_fptr, m_kernel, info, device.id(), input_size, input ); } /// \overload template<class T> boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info) const { return get_sub_group_info<T>(device, info, 0, 0); } /// \overload template<class T> boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info, const size_t input) const { return get_sub_group_info<T>(device, info, sizeof(size_t), &input); } #endif // BOOST_COMPUTE_CL_VERSION_2_1 #if defined(BOOST_COMPUTE_CL_VERSION_2_0) && !defined(BOOST_COMPUTE_CL_VERSION_2_1) /// Returns sub-group information for the kernel with \p device. Returns a null /// optional if cl_khr_subgroups extension is not supported by \p device. /// /// \opencl_version_warning{2,0} /// \see_opencl2_ref{clGetKernelSubGroupInfoKHR} template<class T> boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info, const size_t input_size, const void * input) const { if(!device.check_version(2, 0) || !device.supports_extension("cl_khr_subgroups")) { return boost::optional<T>(); } BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS(); clGetKernelSubGroupInfoKHR_fn clGetKernelSubGroupInfoKHR_fptr = reinterpret_cast<clGetKernelSubGroupInfoKHR_fn>( reinterpret_cast<size_t>( device.platform().get_extension_function_address("clGetKernelSubGroupInfoKHR") ) ); BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS(); return detail::get_object_info<T>( clGetKernelSubGroupInfoKHR_fptr, m_kernel, info, device.id(), input_size, input ); } #endif // defined(BOOST_COMPUTE_CL_VERSION_2_0) && !defined(BOOST_COMPUTE_CL_VERSION_2_1) #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) /// \overload template<class T> boost::optional<T> get_sub_group_info(const device &device, cl_kernel_sub_group_info info, const std::vector<size_t> input) const { BOOST_ASSERT(input.size() > 0); return get_sub_group_info<T>(device, info, input.size() * sizeof(size_t), &input[0]); } #endif // BOOST_COMPUTE_CL_VERSION_2_0 /// Sets the argument at \p index to \p value with \p size. /// /// \see_opencl_ref{clSetKernelArg} void set_arg(size_t index, size_t size, const void *value) { BOOST_ASSERT(index < arity()); cl_int ret = clSetKernelArg(m_kernel, static_cast<cl_uint>(index), size, value); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(opencl_error(ret)); } } /// Sets the argument at \p index to \p value. /// /// For built-in types (e.g. \c float, \c int4_), this is equivalent to /// calling set_arg(index, sizeof(type), &value). /// /// Additionally, this method is specialized for device memory objects /// such as buffer and image2d. This allows for them to be passed directly /// without having to extract their underlying cl_mem object. /// /// This method is also specialized for device container types such as /// vector<T> and array<T, N>. This allows for them to be passed directly /// as kernel arguments without having to extract their underlying buffer. /// /// For setting local memory arguments (e.g. "__local float *buf"), the /// local_buffer<T> class may be used: /// \code /// // set argument to a local buffer with storage for 32 float's /// kernel.set_arg(0, local_buffer<float>(32)); /// \endcode template<class T> void set_arg(size_t index, const T &value) { // if you get a compilation error pointing here it means you // attempted to set a kernel argument from an invalid type. detail::set_kernel_arg<T>()(*this, index, value); } /// \internal_ void set_arg(size_t index, const cl_mem mem) { set_arg(index, sizeof(cl_mem), static_cast<const void *>(&mem)); } /// \internal_ void set_arg(size_t index, const cl_sampler sampler) { set_arg(index, sizeof(cl_sampler), static_cast<const void *>(&sampler)); } /// \internal_ void set_arg_svm_ptr(size_t index, void* ptr) { #ifdef BOOST_COMPUTE_CL_VERSION_2_0 cl_int ret = clSetKernelArgSVMPointer(m_kernel, static_cast<cl_uint>(index), ptr); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(opencl_error(ret)); } #else (void) index; (void) ptr; BOOST_THROW_EXCEPTION(opencl_error(CL_INVALID_ARG_VALUE)); #endif } #ifndef BOOST_COMPUTE_NO_VARIADIC_TEMPLATES /// Sets the arguments for the kernel to \p args. template<class... T> void set_args(T&&... args) { BOOST_ASSERT(sizeof...(T) <= arity()); _set_args<0>(args...); } #endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED) /// Sets additional execution information for the kernel. /// /// \opencl_version_warning{2,0} /// /// \see_opencl2_ref{clSetKernelExecInfo} void set_exec_info(cl_kernel_exec_info info, size_t size, const void *value) { cl_int ret = clSetKernelExecInfo(m_kernel, info, size, value); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(opencl_error(ret)); } } #endif // BOOST_COMPUTE_CL_VERSION_2_0 /// Returns \c true if the kernel is the same at \p other. bool operator==(const kernel &other) const { return m_kernel == other.m_kernel; } /// Returns \c true if the kernel is different from \p other. bool operator!=(const kernel &other) const { return m_kernel != other.m_kernel; } /// \internal_ operator cl_kernel() const { return m_kernel; } /// \internal_ static kernel create_with_source(const std::string &source, const std::string &name, const context &context) { return program::build_with_source(source, context).create_kernel(name); } private: #ifndef BOOST_COMPUTE_NO_VARIADIC_TEMPLATES /// \internal_ template<size_t N> void _set_args() { } /// \internal_ template<size_t N, class T, class... Args> void _set_args(T&& arg, Args&&... rest) { set_arg(N, arg); _set_args<N+1>(rest...); } #endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES private: cl_kernel m_kernel; }; inline kernel program::create_kernel(const std::string &name) const { return kernel(*this, name); } /// \internal_ define get_info() specializations for kernel BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(kernel, ((std::string, CL_KERNEL_FUNCTION_NAME)) ((cl_uint, CL_KERNEL_NUM_ARGS)) ((cl_uint, CL_KERNEL_REFERENCE_COUNT)) ((cl_context, CL_KERNEL_CONTEXT)) ((cl_program, CL_KERNEL_PROGRAM)) ) #ifdef BOOST_COMPUTE_CL_VERSION_1_2 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(kernel, ((std::string, CL_KERNEL_ATTRIBUTES)) ) #endif // BOOST_COMPUTE_CL_VERSION_1_2 /// \internal_ define get_arg_info() specializations for kernel #ifdef BOOST_COMPUTE_CL_VERSION_1_2 #define BOOST_COMPUTE_DETAIL_DEFINE_KERNEL_GET_ARG_INFO_SPECIALIZATION(result_type, value) \ namespace detail { \ template<> struct get_object_info_type<kernel, value> { typedef result_type type; }; \ } \ template<> inline result_type kernel::get_arg_info<value>(size_t index) const { \ return get_arg_info<result_type>(index, value); \ } BOOST_COMPUTE_DETAIL_DEFINE_KERNEL_GET_ARG_INFO_SPECIALIZATION(cl_kernel_arg_address_qualifier, CL_KERNEL_ARG_ADDRESS_QUALIFIER) BOOST_COMPUTE_DETAIL_DEFINE_KERNEL_GET_ARG_INFO_SPECIALIZATION(cl_kernel_arg_access_qualifier, CL_KERNEL_ARG_ACCESS_QUALIFIER) BOOST_COMPUTE_DETAIL_DEFINE_KERNEL_GET_ARG_INFO_SPECIALIZATION(std::string, CL_KERNEL_ARG_TYPE_NAME) BOOST_COMPUTE_DETAIL_DEFINE_KERNEL_GET_ARG_INFO_SPECIALIZATION(cl_kernel_arg_type_qualifier, CL_KERNEL_ARG_TYPE_QUALIFIER) BOOST_COMPUTE_DETAIL_DEFINE_KERNEL_GET_ARG_INFO_SPECIALIZATION(std::string, CL_KERNEL_ARG_NAME) #endif // BOOST_COMPUTE_CL_VERSION_1_2 namespace detail { // set_kernel_arg implementation for built-in types template<class T> struct set_kernel_arg { typename boost::enable_if<is_fundamental<T> >::type operator()(kernel &kernel_, size_t index, const T &value) { kernel_.set_arg(index, sizeof(T), &value); } }; // set_kernel_arg specialization for char (different from built-in cl_char) template<> struct set_kernel_arg<char> { void operator()(kernel &kernel_, size_t index, const char c) { kernel_.set_arg(index, sizeof(char), &c); } }; } // end detail namespace } // end namespace compute } // end namespace boost #endif // BOOST_COMPUTE_KERNEL_HPP PK g^�[����j j interop/eigen/core.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP #define BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP #include <Eigen/Core> #include <boost/compute/command_queue.hpp> #include <boost/compute/algorithm/copy_n.hpp> #include <boost/compute/iterator/buffer_iterator.hpp> #include <boost/compute/type_traits/type_name.hpp> namespace boost { namespace compute { /// Copies \p matrix to \p buffer. template<class Derived> inline void eigen_copy_matrix_to_buffer(const Eigen::PlainObjectBase<Derived> &matrix, buffer_iterator<typename Derived::Scalar> buffer, command_queue &queue = system::default_queue()) { ::boost::compute::copy_n(matrix.data(), matrix.size(), buffer, queue); } /// Copies \p buffer to \p matrix. template<class Derived> inline void eigen_copy_buffer_to_matrix(const buffer_iterator<typename Derived::Scalar> buffer, Eigen::PlainObjectBase<Derived> &matrix, command_queue &queue = system::default_queue()) { ::boost::compute::copy_n(buffer, matrix.size(), matrix.data(), queue); } /// Converts an \c Eigen::Matrix4f to a \c float16_. inline float16_ eigen_matrix4f_to_float16(const Eigen::Matrix4f &matrix) { float16_ result; std::memcpy(&result, matrix.data(), 16 * sizeof(float)); return result; } /// Converts an \c Eigen::Matrix4d to a \c double16_. inline double16_ eigen_matrix4d_to_double16(const Eigen::Matrix4d &matrix) { double16_ result; std::memcpy(&result, matrix.data(), 16 * sizeof(double)); return result; } } // end compute namespace } // end boost namespace BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2i, int2) BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4i, int4) BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2f, float2) BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4f, float4) BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2f, float8) BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4f, float16) BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2d, double2) BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4d, double4) BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2d, double8) BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4d, double16) #endif // BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP PK g^�[{�Si i interop/eigen.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_INTEROP_EIGEN_HPP #define BOOST_COMPUTE_INTEROP_EIGEN_HPP #include <boost/compute/interop/eigen/core.hpp> #endif // BOOST_COMPUTE_INTEROP_EIGEN_HPP PK g^�[�FQ� � interop/opengl/acquire.hppnu �[��� //---------------------------------------------------------------------------// // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP #define BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP #include <boost/compute/command_queue.hpp> #include <boost/compute/interop/opengl/cl_gl.hpp> #include <boost/compute/interop/opengl/opengl_buffer.hpp> #include <boost/compute/types/fundamental.hpp> #include <boost/compute/utility/wait_list.hpp> namespace boost { namespace compute { /// Enqueues a command to acquire the specified OpenGL memory objects. /// /// \see_opencl_ref{clEnqueueAcquireGLObjects} inline event opengl_enqueue_acquire_gl_objects(const uint_ num_objects, const cl_mem *mem_objects, command_queue &queue, const wait_list &events = wait_list()) { BOOST_ASSERT(queue != 0); event event_; cl_int ret = clEnqueueAcquireGLObjects(queue.get(), num_objects, mem_objects, events.size(), events.get_event_ptr(), &event_.get()); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(opencl_error(ret)); } return event_; } /// Enqueues a command to release the specified OpenGL memory objects. /// /// \see_opencl_ref{clEnqueueReleaseGLObjects} inline event opengl_enqueue_release_gl_objects(const uint_ num_objects, const cl_mem *mem_objects, command_queue &queue, const wait_list &events = wait_list()) { BOOST_ASSERT(queue != 0); event event_; cl_int ret = clEnqueueReleaseGLObjects(queue.get(), num_objects, mem_objects, events.size(), events.get_event_ptr(), &event_.get()); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(opencl_error(ret)); } return event_; } /// Enqueues a command to acquire the specified OpenGL buffer. /// /// \see_opencl_ref{clEnqueueAcquireGLObjects} inline event opengl_enqueue_acquire_buffer(const opengl_buffer &buffer, command_queue &queue, const wait_list &events = wait_list()) { BOOST_ASSERT(buffer.get_context() == queue.get_context()); return opengl_enqueue_acquire_gl_objects(1, &buffer.get(), queue, events); } /// Enqueues a command to release the specified OpenGL buffer. /// /// \see_opencl_ref{clEnqueueReleaseGLObjects} inline event opengl_enqueue_release_buffer(const opengl_buffer &buffer, command_queue &queue, const wait_list &events = wait_list()) { BOOST_ASSERT(buffer.get_context() == queue.get_context()); return opengl_enqueue_release_gl_objects(1, &buffer.get(), queue, events); } } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP PK g^�[f/76 6 &