]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/compute/include/boost/compute/pipe.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / pipe.hpp
CommitLineData
7c673cae
FG
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_PIPE_HPP
12#define BOOST_COMPUTE_PIPE_HPP
13
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>
19
20// pipe objects require opencl 2.0
21#if defined(CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
22
23namespace boost {
24namespace compute {
25
26/// \class pipe
27/// \brief A FIFO data pipe
28///
29/// \opencl_version_warning{2,0}
30///
31/// \see memory_object
32class pipe : public memory_object
33{
34public:
35 /// Creates a null pipe object.
36 pipe()
37 : memory_object()
38 {
39 }
40
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)
45 {
46 }
47
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)
54 {
55 cl_int error = 0;
56 m_mem = clCreatePipe(context,
57 flags,
58 pipe_packet_size,
59 pipe_max_packets,
60 properties,
61 &error);
62 if(!m_mem){
63 BOOST_THROW_EXCEPTION(opencl_error(error));
64 }
65 }
66
67 /// Creates a new pipe object as a copy of \p other.
68 pipe(const pipe &other)
69 : memory_object(other)
70 {
71 }
72
73 /// Copies the pipe object from \p other to \c *this.
74 pipe& operator=(const pipe &other)
75 {
76 if(this != &other){
77 memory_object::operator=(other);
78 }
79
80 return *this;
81 }
82
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))
87 {
88 }
89
90 /// Move-assigns the pipe from \p other to \c *this.
91 pipe& operator=(pipe&& other) BOOST_NOEXCEPT
92 {
93 memory_object::operator=(std::move(other));
94
95 return *this;
96 }
97 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
98
99 /// Destroys the pipe object.
100 ~pipe()
101 {
102 }
103
104 /// Returns the packet size.
105 uint_ packet_size() const
106 {
107 return get_info<uint_>(CL_PIPE_PACKET_SIZE);
108 }
109
110 /// Returns the max number of packets.
111 uint_ max_packets() const
112 {
113 return get_info<uint_>(CL_PIPE_MAX_PACKETS);
114 }
115
116 /// Returns information about the pipe.
117 ///
118 /// \see_opencl2_ref{clGetPipeInfo}
119 template<class T>
120 T get_info(cl_pipe_info info) const
121 {
122 return detail::get_object_info<T>(clGetPipeInfo, m_mem, info);
123 }
124
125 /// \overload
126 template<int Enum>
127 typename detail::get_object_info_type<pipe, Enum>::type get_info() const;
128};
129
130/// \internal_ define get_info() specializations for pipe
131BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(pipe,
132 ((cl_uint, CL_PIPE_PACKET_SIZE))
133 ((cl_uint, CL_PIPE_MAX_PACKETS))
134)
135
136namespace detail {
137
138// set_kernel_arg specialization for pipe
139template<>
140struct set_kernel_arg<pipe>
141{
142 void operator()(kernel &kernel_, size_t index, const pipe &pipe_)
143 {
144 kernel_.set_arg(index, pipe_.get());
145 }
146};
147
148} // end detail namespace
149} // end compute namespace
150} // end boost namespace
151
152#endif // CL_VERSION_2_0
153
154#endif // BOOST_COMPUTE_PIPE_HPP