Пример #1
0
    /// Enqueues a command to copy data from \p src_buffer to
    /// \p dst_buffer.
    ///
    /// \see_opencl_ref{clEnqueueCopyBuffer}
    ///
    /// \see copy()
    event enqueue_copy_buffer(const buffer &src_buffer,
                              const buffer &dst_buffer,
                              size_t src_offset,
                              size_t dst_offset,
                              size_t size,
                              const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(src_offset + size <= src_buffer.size());
        BOOST_ASSERT(dst_offset + size <= dst_buffer.size());
        BOOST_ASSERT(src_buffer.get_context() == this->get_context());
        BOOST_ASSERT(dst_buffer.get_context() == this->get_context());

        event event_;

        cl_int ret = clEnqueueCopyBuffer(
            m_queue,
            src_buffer.get(),
            dst_buffer.get(),
            src_offset,
            dst_offset,
            size,
            events.size(),
            events.get_event_ptr(),
            &event_.get()
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return event_;
    }
Пример #2
0
io_status pstring::cdrIn(buffer& buf)
{
   primitive::cdrIn(buf);
   buf.get(v_str_ptr.loc);
   buf.get(v_sz);
   return done;
}
Пример #3
0
/**
 * Received message callback. This function is executed to process the
 * received messages. If this is a valid message, the message is
 * dispatched to the handler defined by the user.
 *
 * @param buff Message byte buffer.
 * @param rbytes Size of the message.
 * @param ec Error code.
 */
void link::recv_handler(buffer<uint8>& buff, size_t rbytes,
						const boost::system::error_code& ec)
{
	if (ec) {
		mih::message pm;

		_handler(pm, ec);

	} else {
		mih::frame* fm = mih::frame::cast(buff.get(), rbytes);

		if (fm) {
			mih::message pm(*fm);

			_handler(pm, ec);
		}
	}

	void* rbuff = buff.get();
	size_t rlen = buff.size();

	_sock.async_receive(boost::asio::buffer(rbuff, rlen),
						boost::bind(&link::recv_handler,
									this,
									bind_rv(buff),
									boost::asio::placeholders::bytes_transferred,
									boost::asio::placeholders::error));
}
Пример #4
0
/**
 * Handle the reception of an asynchronous message.
 *
 * @param buff The input message bytes.
 * @param rbytes The number of bytes of the input message.
 * @param error The error code.
 */
void udp_listener::handle_receive(buffer<uint8> &buff,
								  size_t rbytes,
								  const boost::system::error_code &error)
{
	using namespace boost;

	if (!error) {
		ODTONE_LOG(1, "(udp) received ", rbytes, " bytes.");
		ODTONE_LOG(0, "(udp) from ", _rmt_endp.address().to_string(),
		    " : ", _rmt_endp.port());

		mih::frame *pud = mih::frame::cast(buff.get(), rbytes);

		if(pud) {
			// Decode IP address
			mih::octet_string ip;
			uint16 scope = 0;
			if(_rmt_endp.address().is_v4()) {
				boost::asio::ip::address_v4 ip_addr = _rmt_endp.address().to_v4();
				ip = ip_addr.to_string();
			} else if(_rmt_endp.address().is_v6()) {
				boost::asio::ip::address_v6 ip_addr = _rmt_endp.address().to_v6();
				scope = ip_addr.scope_id();
				ip_addr.scope_id(0);
				ip = ip_addr.to_string();
			}
			// Decode port
			uint16 port = _rmt_endp.port();

			meta_message_ptr in(new meta_message(ip, scope, port, *pud));
			ODTONE_LOG(4, *pud);

			// discard messages if multicast messages are not supported
			if(utils::is_multicast(in) && !_enable_multicast) {
				ODTONE_LOG(1, "(udp) Discarding message! Reason: ",
							  "multicast messages are not supported");
			} else {
				_dispatch(in);
			}
		}
	}

	void *rbuff = buff.get();
	size_t rlen = buff.size();

	_sock.async_receive_from(asio::buffer(rbuff, rlen),
				 _rmt_endp,
				 bind(&udp_listener::handle_receive,
				      this,
				      bind_rv(buff),
				      asio::placeholders::bytes_transferred,
				      asio::placeholders::error));
}
Пример #5
0
    /// Enqueues a command to fill \p buffer with \p pattern.
    ///
    /// \see_opencl_ref{clEnqueueFillBuffer}
    ///
    /// \opencl_version_warning{1,2}
    ///
    /// \see fill()
    event enqueue_fill_buffer(const buffer &buffer,
                              const void *pattern,
                              size_t pattern_size,
                              size_t offset,
                              size_t size,
                              const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(offset + size <= buffer.size());
        BOOST_ASSERT(buffer.get_context() == this->get_context());

        event event_;

        cl_int ret = clEnqueueFillBuffer(
            m_queue,
            buffer.get(),
            pattern,
            pattern_size,
            offset,
            size,
            events.size(),
            events.get_event_ptr(),
            &event_.get()
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return event_;
    }
Пример #6
0
    /// Enqueues a command to copy data from \p src_buffer to \p dst_image.
    ///
    /// \see_opencl_ref{clEnqueueCopyBufferToImage}
    event enqueue_copy_buffer_to_image(const buffer &src_buffer,
                                       const image3d &dst_image,
                                       size_t src_offset,
                                       const size_t dst_origin[3],
                                       const size_t region[3],
                                       const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(src_buffer.get_context() == this->get_context());
        BOOST_ASSERT(dst_image.get_context() == this->get_context());

        event event_;

        cl_int ret = clEnqueueCopyBufferToImage(
            m_queue,
            src_buffer.get(),
            dst_image.get(),
            src_offset,
            dst_origin,
            region,
            events.size(),
            events.get_event_ptr(),
            &event_.get()
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return event_;
    }
Пример #7
0
    /// Enqueues a command to copy data from \p src_image to \p dst_buffer.
    ///
    /// \see_opencl_ref{clEnqueueCopyImageToBuffer}
    event enqueue_copy_image_to_buffer(const image2d &src_image,
                                       const buffer &dst_buffer,
                                       const size_t src_origin[2],
                                       const size_t region[2],
                                       size_t dst_offset,
                                       const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(src_image.get_context() == this->get_context());
        BOOST_ASSERT(dst_buffer.get_context() == this->get_context());

        const size_t src_origin3[3] = { src_origin[0], src_origin[1], size_t(0) };
        const size_t region3[3] = { region[0], region[1], size_t(1) };

        event event_;

        cl_int ret = clEnqueueCopyImageToBuffer(
            m_queue,
            src_image.get(),
            dst_buffer.get(),
            src_origin3,
            region3,
            dst_offset,
            events.size(),
            events.get_event_ptr(),
            &event_.get()
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return event_;
    }
Пример #8
0
    std::string get_buffer_identifier(const buffer &buffer,
                                      const memory_object::address_space address_space =
                                          memory_object::global_memory)
    {
        // check if we've already seen buffer
        for(size_t i = 0; i < m_stored_buffers.size(); i++){
            const detail::meta_kernel_buffer_info &bi = m_stored_buffers[i];

            if(bi.m_mem == buffer.get() &&
               bi.address_space == address_space){
                return bi.identifier;
            }
        }

        // create a new binding
        std::string identifier =
            "_buf" + lexical_cast<std::string>(m_stored_buffers.size());
        size_t index = add_arg<T *>(address_space, identifier);

        // store new buffer info
        m_stored_buffers.push_back(
            detail::meta_kernel_buffer_info(buffer, identifier, address_space, index));

        return identifier;
    }
Пример #9
0
    /// Enqueues a command to write data from host memory to \p buffer.
    /// The copy is performed asynchronously.
    ///
    /// \see_opencl_ref{clEnqueueWriteBuffer}
    ///
    /// \see copy_async()
    event enqueue_write_buffer_async(const buffer &buffer,
                                     size_t offset,
                                     size_t size,
                                     const void *host_ptr,
                                     const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(size <= buffer.size());
        BOOST_ASSERT(buffer.get_context() == this->get_context());
        BOOST_ASSERT(host_ptr != 0);

        event event_;

        cl_int ret = clEnqueueWriteBuffer(
            m_queue,
            buffer.get(),
            CL_FALSE,
            offset,
            size,
            host_ptr,
            events.size(),
            events.get_event_ptr(),
            &event_.get()
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return event_;
    }
Пример #10
0
    /// Enqueues a command to read data from \p buffer to host memory.
    ///
    /// \see_opencl_ref{clEnqueueReadBuffer}
    ///
    /// \see copy()
    void enqueue_read_buffer(const buffer &buffer,
                             size_t offset,
                             size_t size,
                             void *host_ptr,
                             const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(size <= buffer.size());
        BOOST_ASSERT(buffer.get_context() == this->get_context());
        BOOST_ASSERT(host_ptr != 0);

        cl_int ret = clEnqueueReadBuffer(
            m_queue,
            buffer.get(),
            CL_TRUE,
            offset,
            size,
            host_ptr,
            events.size(),
            events.get_event_ptr(),
            0
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }
    }
Пример #11
0
io_status dl_list::cdrIn(buffer& buf)
{
   composite::cdrIn(buf);
   v_dl_list_head.cdrIn(buf);
   v_dl_list_tail.cdrIn(buf);
   buf.get(v_num_indices);
   return done;
}
Пример #12
0
    /// Enqueues a command to unmap \p buffer from the host memory space.
    ///
    /// \see_opencl_ref{clEnqueueUnmapMemObject}
    event enqueue_unmap_buffer(const buffer &buffer,
                               void *mapped_ptr,
                               const wait_list &events = wait_list())
    {
        BOOST_ASSERT(buffer.get_context() == this->get_context());

        return enqueue_unmap_mem_object(buffer.get(), mapped_ptr, events);
    }
Пример #13
0
/**
 * Received message callback. This function is executed to process the
 * received messages. If this is a valid message, the message is
 * dispatched to the handler defined by the user.
 *
 * @param buff Message byte buffer.
 * @param rbytes Size of the message.
 * @param ec Error code.
 */
void user::recv_handler(buffer<uint8>& buff, size_t rbytes, const boost::system::error_code& ec)
{
	if (ec) {
		mih::message pm;

		_handler(pm, ec);

	} else {
		mih::frame* fm = mih::frame::cast(buff.get(), rbytes);

		if (fm) {
			mih::message pm(*fm);

			if (fm->opcode() == mih::operation::confirm) {
				handler h;

				get_handler(fm->tid(), h);
				if (h) {
					h(pm, ec);
				// Unsolicited MIH capability discover reception
				} else if(fm->sid() == mih::service::management &&
				        fm->aid() == mih::action::capability_discover) {
					_handler(pm, ec);
				} else {
					_handler(pm, boost::system::errc::make_error_code(boost::system::errc::bad_message));
				}
			} else if (fm->opcode() != mih::operation::indication) {
				_handler(pm, boost::system::errc::make_error_code(boost::system::errc::bad_message));
			} else {
				_handler(pm, ec);
			}
		}
	}

	void* rbuff = buff.get();
	size_t rlen = buff.size();

	_sock.async_receive(boost::asio::buffer(rbuff, rlen),
						boost::bind(&user::recv_handler,
									this,
									bind_rv(buff),
									boost::asio::placeholders::bytes_transferred,
									boost::asio::placeholders::error));
}
Пример #14
0
 buffer_iterator_index_expr(const buffer &buffer,
                            size_t index,
                            const memory_object::address_space address_space,
                            const IndexExpr &expr)
     : m_buffer(buffer.get(), false),
       m_index(index),
       m_address_space(address_space),
       m_expr(expr)
 {
 }
Пример #15
0
 meta_kernel_buffer_info(const buffer &buffer,
                         const std::string &id,
                         memory_object::address_space addr_space,
                         size_t i)
   : m_mem(buffer.get()),
     identifier(id),
     address_space(addr_space),
     index(i)
 {
 }
Пример #16
0
void reader()
{
    for (int x = 0; x < ITERS; ++x)
    {
        int n = buf.get();
        {
            boost::mutex::scoped_lock lock(io_mutex);
            std::cout << "received: "
                      << n << std::endl;
        }
    }
}
Пример #17
0
  friend void push(sink& s, buffer p) {
    v4l2_buffer b = {0};
    b.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    b.memory = V4L2_MEMORY_MMAP;
    b.index = p.get() - s.p->buffers;

    if(ioctl(s.p->fd.native_handle(), VIDIOC_QBUF, &b)) throw std::system_error(errno, std::system_category());
    intrusive_ptr_add_ref(p.get());

    if(atomic_exchange(&s.p->streaming, true)) {
      auto dqbuf = std::make_unique<v4l2_buffer>();
      memset(dqbuf.get(), 0, sizeof(*dqbuf.get()));
      dqbuf->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
      dqbuf->memory = V4L2_MEMORY_MMAP;
      auto dqp = dqbuf.get();

      s.p->fd.async_read_some(utils::make_ioctl_read_buffer<VIDIOC_DQBUF>(dqp), [&s, buffer = utils::move_on_copy(std::move(dqbuf))](std::error_code const& ec, std::size_t) {
        if(!ec) 
          intrusive_ptr_release(s.p->buffers + unwrap(buffer)->index);
      });
    }
  }
Пример #18
0
    /// Enqueues a command to copy a rectangular region from
    /// \p src_buffer to \p dst_buffer.
    ///
    /// \see_opencl_ref{clEnqueueCopyBufferRect}
    ///
    /// \opencl_version_warning{1,1}
    event enqueue_copy_buffer_rect(const buffer &src_buffer,
                                   const buffer &dst_buffer,
                                   const size_t src_origin[3],
                                   const size_t dst_origin[3],
                                   const size_t region[3],
                                   size_t buffer_row_pitch,
                                   size_t buffer_slice_pitch,
                                   size_t host_row_pitch,
                                   size_t host_slice_pitch,
                                   const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(src_buffer.get_context() == this->get_context());
        BOOST_ASSERT(dst_buffer.get_context() == this->get_context());

        event event_;

        cl_int ret = clEnqueueCopyBufferRect(
            m_queue,
            src_buffer.get(),
            dst_buffer.get(),
            src_origin,
            dst_origin,
            region,
            buffer_row_pitch,
            buffer_slice_pitch,
            host_row_pitch,
            host_slice_pitch,
            events.size(),
            events.get_event_ptr(),
            &event_.get()
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return event_;
    }
Пример #19
0
    /// Enqueues a command to write a rectangular region from host memory
    /// to \p buffer.
    ///
    /// \see_opencl_ref{clEnqueueWriteBufferRect}
    ///
    /// \opencl_version_warning{1,1}
    void enqueue_write_buffer_rect(const buffer &buffer,
                                   const size_t buffer_origin[3],
                                   const size_t host_origin[3],
                                   const size_t region[3],
                                   size_t buffer_row_pitch,
                                   size_t buffer_slice_pitch,
                                   size_t host_row_pitch,
                                   size_t host_slice_pitch,
                                   void *host_ptr,
                                   const wait_list &events = wait_list())
    {
        BOOST_ASSERT(m_queue != 0);
        BOOST_ASSERT(buffer.get_context() == this->get_context());
        BOOST_ASSERT(host_ptr != 0);

        cl_int ret = clEnqueueWriteBufferRect(
            m_queue,
            buffer.get(),
            CL_TRUE,
            buffer_origin,
            host_origin,
            region,
            buffer_row_pitch,
            buffer_slice_pitch,
            host_row_pitch,
            host_slice_pitch,
            host_ptr,
            events.size(),
            events.get_event_ptr(),
            0
        );

        if(ret != CL_SUCCESS){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }
    }
Пример #20
0
 device_ptr(const buffer &buffer, size_t index = 0)
     : m_buffer(buffer.get(), false),
       m_index(index)
 {
 }
Пример #21
0
 buffer_iterator(const buffer &buffer, size_t index)
     : m_buffer(buffer.get(), false),
       m_index(index)
 {
 }
Пример #22
0
io_status compressed_pstring::cdrIn(buffer& buf)
{
   pstring::cdrIn(buf);
   buf.get(v_uncompressed_sz);
   return compress_agent_id.cdrIn(buf);
}
Пример #23
0
 void read(buffer const &b, T *data, size_t s)
 {
   OVXX_TRACE("OpenCL copy %d bytes from device", s*sizeof(T));
   OVXX_OPENCL_CHECK_RESULT(clEnqueueReadBuffer,
     (get(), b.get(), CL_TRUE, 0, s*sizeof(T), data, 0, 0, 0));
 }
Пример #24
0
 void write(T const *data, buffer &b, size_t s)
 {
   OVXX_TRACE("OpenCL copy %d bytes to device", s*sizeof(T));
   OVXX_OPENCL_CHECK_RESULT(clEnqueueWriteBuffer,
     (get(), b.get(), CL_TRUE, 0, s*sizeof(T), data, 0, 0, 0));
 }
Пример #25
0
 // creates a reference for the value in buffer at index (in bytes).
 buffer_value(const buffer &buffer, size_t index)
     : m_buffer(buffer.get(), false),
       m_index(index)
 {
 }