Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:03

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_MEMORY_LOCAL_BUFFER_HPP
0012 #define BOOST_COMPUTE_MEMORY_LOCAL_BUFFER_HPP
0013 
0014 #include <boost/compute/cl.hpp>
0015 #include <boost/compute/kernel.hpp>
0016 
0017 namespace boost {
0018 namespace compute {
0019 
0020 /// \class local_buffer
0021 /// \brief Represents a local memory buffer on the device.
0022 ///
0023 /// The local_buffer class represents a block of local memory on a compute
0024 /// device.
0025 ///
0026 /// This class is most commonly used to set local memory arguments for compute
0027 /// kernels:
0028 /// \code
0029 /// // set argument to a local buffer with storage for 32 float's
0030 /// kernel.set_arg(0, local_buffer<float>(32));
0031 /// \endcode
0032 ///
0033 /// \see buffer, kernel
0034 template<class T>
0035 class local_buffer
0036 {
0037 public:
0038     /// Creates a local buffer object for \p size elements.
0039     local_buffer(const size_t size)
0040         : m_size(size)
0041     {
0042     }
0043 
0044     /// Creates a local buffer object as a copy of \p other.
0045     local_buffer(const local_buffer &other)
0046         : m_size(other.m_size)
0047     {
0048     }
0049 
0050     /// Copies \p other to \c *this.
0051     local_buffer& operator=(const local_buffer &other)
0052     {
0053         if(this != &other){
0054             m_size = other.m_size;
0055         }
0056 
0057         return *this;
0058     }
0059 
0060     /// Destroys the local memory object.
0061     ~local_buffer()
0062     {
0063     }
0064 
0065     /// Returns the number of elements in the local buffer.
0066     size_t size() const
0067     {
0068         return m_size;
0069     }
0070 
0071 private:
0072     size_t m_size;
0073 };
0074 
0075 namespace detail {
0076 
0077 // set_kernel_arg specialization for local_buffer<T>
0078 template<class T>
0079 struct set_kernel_arg<local_buffer<T> >
0080 {
0081     void operator()(kernel &kernel_, size_t index, const local_buffer<T> &buffer)
0082     {
0083         kernel_.set_arg(index, buffer.size() * sizeof(T), 0);
0084     }
0085 };
0086 
0087 } // end detail namespace
0088 } // end compute namespace
0089 } // end boost namespace
0090 
0091 #endif // BOOST_COMPUTE_MEMORY_SVM_PTR_HPP