1 //---------------------------------------------------------------------------// 2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> 3 // 4 // Distributed under the Boost Software License, Version 1.0 5 // See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt 7 // 8 // See http://boostorg.github.com/compute for more information. 9 //---------------------------------------------------------------------------// 10 11 #ifndef BOOST_COMPUTE_MEMORY_LOCAL_BUFFER_HPP 12 #define BOOST_COMPUTE_MEMORY_LOCAL_BUFFER_HPP 13 14 #include <boost/compute/cl.hpp> 15 #include <boost/compute/kernel.hpp> 16 17 namespace boost { 18 namespace compute { 19 20 /// \class local_buffer 21 /// \brief Represents a local memory buffer on the device. 22 /// 23 /// The local_buffer class represents a block of local memory on a compute 24 /// device. 25 /// 26 /// This class is most commonly used to set local memory arguments for compute 27 /// kernels: 28 /// \code 29 /// // set argument to a local buffer with storage for 32 float's 30 /// kernel.set_arg(0, local_buffer<float>(32)); 31 /// \endcode 32 /// 33 /// \see buffer, kernel 34 template<class T> 35 class local_buffer 36 { 37 public: 38 /// Creates a local buffer object for \p size elements. local_buffer(const size_t size)39 local_buffer(const size_t size) 40 : m_size(size) 41 { 42 } 43 44 /// Creates a local buffer object as a copy of \p other. local_buffer(const local_buffer & other)45 local_buffer(const local_buffer &other) 46 : m_size(other.m_size) 47 { 48 } 49 50 /// Copies \p other to \c *this. operator =(const local_buffer & other)51 local_buffer& operator=(const local_buffer &other) 52 { 53 if(this != &other){ 54 m_size = other.m_size; 55 } 56 57 return *this; 58 } 59 60 /// Destroys the local memory object. ~local_buffer()61 ~local_buffer() 62 { 63 } 64 65 /// Returns the number of elements in the local buffer. size() const66 size_t size() const 67 { 68 return m_size; 69 } 70 71 private: 72 size_t m_size; 73 }; 74 75 namespace detail { 76 77 // set_kernel_arg specialization for local_buffer<T> 78 template<class T> 79 struct set_kernel_arg<local_buffer<T> > 80 { operator ()boost::compute::detail::set_kernel_arg81 void operator()(kernel &kernel_, size_t index, const local_buffer<T> &buffer) 82 { 83 kernel_.set_arg(index, buffer.size() * sizeof(T), 0); 84 } 85 }; 86 87 } // end detail namespace 88 } // end compute namespace 89 } // end boost namespace 90 91 #endif // BOOST_COMPUTE_MEMORY_SVM_PTR_HPP 92