File indexing completed on 2024-11-15 09:04:26
0001
0002
0003
0004
0005
0006
0007
0008
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
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
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
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
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 }
0075 }
0076 }
0077
0078 #endif