1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_PIPE_HPP
12 #define BOOST_COMPUTE_PIPE_HPP
14 #include <boost/compute/cl.hpp>
15 #include <boost/compute/context.hpp>
16 #include <boost/compute/memory_object.hpp>
17 #include <boost/compute/exception/opencl_error.hpp>
18 #include <boost/compute/detail/get_object_info.hpp>
20 // pipe objects require opencl 2.0
21 #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
27 /// \brief A FIFO data pipe
29 /// \opencl_version_warning{2,0}
31 /// \see memory_object
32 class pipe : public memory_object
35 /// Creates a null pipe object.
41 /// Creates a pipe object for \p mem. If \p retain is \c true, the
42 /// reference count for \p mem will be incremented.
43 explicit pipe(cl_mem mem, bool retain = true)
44 : memory_object(mem, retain)
48 /// Creates a new pipe in \p context.
49 pipe(const context &context,
50 uint_ pipe_packet_size,
51 uint_ pipe_max_packets,
52 cl_mem_flags flags = read_write,
53 const cl_pipe_properties *properties = 0)
56 m_mem = clCreatePipe(context,
63 BOOST_THROW_EXCEPTION(opencl_error(error));
67 /// Creates a new pipe object as a copy of \p other.
68 pipe(const pipe &other)
69 : memory_object(other)
73 /// Copies the pipe object from \p other to \c *this.
74 pipe& operator=(const pipe &other)
77 memory_object::operator=(other);
83 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
84 /// Move-constructs a new pipe object from \p other.
85 pipe(pipe&& other) BOOST_NOEXCEPT
86 : memory_object(std::move(other))
90 /// Move-assigns the pipe from \p other to \c *this.
91 pipe& operator=(pipe&& other) BOOST_NOEXCEPT
93 memory_object::operator=(std::move(other));
97 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
99 /// Destroys the pipe object.
104 /// Returns the packet size.
105 uint_ packet_size() const
107 return get_info<uint_>(CL_PIPE_PACKET_SIZE);
110 /// Returns the max number of packets.
111 uint_ max_packets() const
113 return get_info<uint_>(CL_PIPE_MAX_PACKETS);
116 /// Returns information about the pipe.
118 /// \see_opencl2_ref{clGetPipeInfo}
120 T get_info(cl_pipe_info info) const
122 return detail::get_object_info<T>(clGetPipeInfo, m_mem, info);
127 typename detail::get_object_info_type<pipe, Enum>::type get_info() const;
130 /// \internal_ define get_info() specializations for pipe
131 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(pipe,
132 ((cl_uint, CL_PIPE_PACKET_SIZE))
133 ((cl_uint, CL_PIPE_MAX_PACKETS))
138 // set_kernel_arg specialization for pipe
140 struct set_kernel_arg<pipe>
142 void operator()(kernel &kernel_, size_t index, const pipe &pipe_)
144 kernel_.set_arg(index, pipe_.get());
148 } // end detail namespace
149 } // end compute namespace
150 } // end boost namespace
152 #endif // BOOST_COMPUTE_CL_VERSION_2_0
154 #endif // BOOST_COMPUTE_PIPE_HPP