Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:34:46

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_PIPE_HPP
0012 #define BOOST_COMPUTE_PIPE_HPP
0013 
0014 #include <boost/compute/cl.hpp>
0015 #include <boost/compute/context.hpp>
0016 #include <boost/compute/memory_object.hpp>
0017 #include <boost/compute/exception/opencl_error.hpp>
0018 #include <boost/compute/detail/get_object_info.hpp>
0019 
0020 // pipe objects require opencl 2.0
0021 #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 /// \class pipe
0027 /// \brief A FIFO data pipe
0028 ///
0029 /// \opencl_version_warning{2,0}
0030 ///
0031 /// \see memory_object
0032 class pipe : public memory_object
0033 {
0034 public:
0035     /// Creates a null pipe object.
0036     pipe()
0037         : memory_object()
0038     {
0039     }
0040 
0041     /// Creates a pipe object for \p mem. If \p retain is \c true, the
0042     /// reference count for \p mem will be incremented.
0043     explicit pipe(cl_mem mem, bool retain = true)
0044         : memory_object(mem, retain)
0045     {
0046     }
0047 
0048     /// Creates a new pipe in \p context.
0049     pipe(const context &context,
0050          uint_ pipe_packet_size,
0051          uint_ pipe_max_packets,
0052          cl_mem_flags flags = read_write,
0053          const cl_pipe_properties *properties = 0)
0054     {
0055         cl_int error = 0;
0056         m_mem = clCreatePipe(context,
0057                              flags,
0058                              pipe_packet_size,
0059                              pipe_max_packets,
0060                              properties,
0061                              &error);
0062         if(!m_mem){
0063             BOOST_THROW_EXCEPTION(opencl_error(error));
0064         }
0065     }
0066 
0067     /// Creates a new pipe object as a copy of \p other.
0068     pipe(const pipe &other)
0069         : memory_object(other)
0070     {
0071     }
0072 
0073     /// Copies the pipe object from \p other to \c *this.
0074     pipe& operator=(const pipe &other)
0075     {
0076         if(this != &other){
0077             memory_object::operator=(other);
0078         }
0079 
0080         return *this;
0081     }
0082 
0083     #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
0084     /// Move-constructs a new pipe object from \p other.
0085     pipe(pipe&& other) BOOST_NOEXCEPT
0086         : memory_object(std::move(other))
0087     {
0088     }
0089 
0090     /// Move-assigns the pipe from \p other to \c *this.
0091     pipe& operator=(pipe&& other) BOOST_NOEXCEPT
0092     {
0093         memory_object::operator=(std::move(other));
0094 
0095         return *this;
0096     }
0097     #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
0098 
0099     /// Destroys the pipe object.
0100     ~pipe()
0101     {
0102     }
0103 
0104     /// Returns the packet size.
0105     uint_ packet_size() const
0106     {
0107         return get_info<uint_>(CL_PIPE_PACKET_SIZE);
0108     }
0109 
0110     /// Returns the max number of packets.
0111     uint_ max_packets() const
0112     {
0113         return get_info<uint_>(CL_PIPE_MAX_PACKETS);
0114     }
0115 
0116     /// Returns information about the pipe.
0117     ///
0118     /// \see_opencl2_ref{clGetPipeInfo}
0119     template<class T>
0120     T get_info(cl_pipe_info info) const
0121     {
0122         return detail::get_object_info<T>(clGetPipeInfo, m_mem, info);
0123     }
0124 
0125     /// \overload
0126     template<int Enum>
0127     typename detail::get_object_info_type<pipe, Enum>::type get_info() const;
0128 };
0129 
0130 /// \internal_ define get_info() specializations for pipe
0131 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(pipe,
0132     ((cl_uint, CL_PIPE_PACKET_SIZE))
0133     ((cl_uint, CL_PIPE_MAX_PACKETS))
0134 )
0135 
0136 namespace detail {
0137 
0138 // set_kernel_arg specialization for pipe
0139 template<>
0140 struct set_kernel_arg<pipe>
0141 {
0142     void operator()(kernel &kernel_, size_t index, const pipe &pipe_)
0143     {
0144         kernel_.set_arg(index, pipe_.get());
0145     }
0146 };
0147 
0148 } // end detail namespace
0149 } // end compute namespace
0150 } // end boost namespace
0151 
0152 #endif // BOOST_COMPUTE_CL_VERSION_2_0
0153 
0154 #endif // BOOST_COMPUTE_PIPE_HPP