File indexing completed on 2025-01-30 09:34:46
0001
0002
0003
0004
0005
0006
0007
0008
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
0021 #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
0022
0023 namespace boost {
0024 namespace compute {
0025
0026
0027
0028
0029
0030
0031
0032 class pipe : public memory_object
0033 {
0034 public:
0035
0036 pipe()
0037 : memory_object()
0038 {
0039 }
0040
0041
0042
0043 explicit pipe(cl_mem mem, bool retain = true)
0044 : memory_object(mem, retain)
0045 {
0046 }
0047
0048
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
0068 pipe(const pipe &other)
0069 : memory_object(other)
0070 {
0071 }
0072
0073
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
0085 pipe(pipe&& other) BOOST_NOEXCEPT
0086 : memory_object(std::move(other))
0087 {
0088 }
0089
0090
0091 pipe& operator=(pipe&& other) BOOST_NOEXCEPT
0092 {
0093 memory_object::operator=(std::move(other));
0094
0095 return *this;
0096 }
0097 #endif
0098
0099
0100 ~pipe()
0101 {
0102 }
0103
0104
0105 uint_ packet_size() const
0106 {
0107 return get_info<uint_>(CL_PIPE_PACKET_SIZE);
0108 }
0109
0110
0111 uint_ max_packets() const
0112 {
0113 return get_info<uint_>(CL_PIPE_MAX_PACKETS);
0114 }
0115
0116
0117
0118
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
0126 template<int Enum>
0127 typename detail::get_object_info_type<pipe, Enum>::type get_info() const;
0128 };
0129
0130
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
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 }
0149 }
0150 }
0151
0152 #endif
0153
0154 #endif