Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:04:26

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 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_DETAIL_READ_WRITE_SINGLE_VALUE_HPP
0012 #define BOOST_COMPUTE_DETAIL_READ_WRITE_SINGLE_VALUE_HPP
0013 
0014 #include <boost/throw_exception.hpp>
0015 
0016 #include <boost/compute/buffer.hpp>
0017 #include <boost/compute/event.hpp>
0018 #include <boost/compute/exception.hpp>
0019 #include <boost/compute/command_queue.hpp>
0020 
0021 namespace boost {
0022 namespace compute {
0023 namespace detail {
0024 
0025 // reads and returns a single value at index in the buffer
0026 template<class T>
0027 inline T read_single_value(const buffer &buffer,
0028                            size_t index,
0029                            command_queue &queue)
0030 {
0031     BOOST_ASSERT(index < buffer.size() / sizeof(T));
0032     BOOST_ASSERT(buffer.get_context() == queue.get_context());
0033 
0034     T value;
0035     queue.enqueue_read_buffer(buffer,
0036                               sizeof(T) * index,
0037                               sizeof(T),
0038                               &value);
0039     return value;
0040 }
0041 
0042 // reads and returns a the first value in the buffer
0043 template<class T>
0044 inline T read_single_value(const buffer &buffer, command_queue &queue)
0045 {
0046     return read_single_value<T>(buffer, 0, queue);
0047 }
0048 
0049 // writes a single value at index to the buffer
0050 template<class T>
0051 inline event write_single_value(const T &value,
0052                                 const buffer &buffer,
0053                                 size_t index,
0054                                 command_queue &queue)
0055 {
0056     BOOST_ASSERT(index < buffer.size() / sizeof(T));
0057     BOOST_ASSERT(buffer.get_context() == queue.get_context());
0058 
0059     return queue.enqueue_write_buffer(buffer,
0060                                       index * sizeof(T),
0061                                       sizeof(T),
0062                                       &value);
0063 }
0064 
0065 // writes value to the first location in buffer
0066 template<class T>
0067 inline void write_single_value(const T &value,
0068                                const buffer &buffer,
0069                                command_queue &queue)
0070 {
0071     write_single_value<T>(value, buffer, 0, queue);
0072 }
0073 
0074 } // end detail namespace
0075 } // end compute namespace
0076 } // end boost namespace
0077 
0078 #endif // BOOST_COMPUTE_DETAIL_READ_WRITE_SINGLE_VALUE_HPP