scalar.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 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. #ifndef BOOST_COMPUTE_CONTAINER_DETAIL_SCALAR_HPP
  11. #define BOOST_COMPUTE_CONTAINER_DETAIL_SCALAR_HPP
  12. #include <boost/compute/buffer.hpp>
  13. #include <boost/compute/event.hpp>
  14. #include <boost/compute/detail/read_write_single_value.hpp>
  15. namespace boost {
  16. namespace compute {
  17. namespace detail {
  18. // scalar<T> provides a trivial "container" that stores a
  19. // single value in a memory buffer on a compute device
  20. template<class T>
  21. class scalar
  22. {
  23. public:
  24. typedef T value_type;
  25. scalar(const context &context)
  26. : m_buffer(context, sizeof(T))
  27. {
  28. }
  29. ~scalar()
  30. {
  31. }
  32. T read(command_queue &queue) const
  33. {
  34. return read_single_value<T>(m_buffer, 0, queue);
  35. }
  36. event write(const T &value, command_queue &queue)
  37. {
  38. return write_single_value<T>(value, m_buffer, 0, queue);
  39. }
  40. const buffer& get_buffer() const
  41. {
  42. return m_buffer;
  43. }
  44. private:
  45. buffer m_buffer;
  46. };
  47. } // end detail namespace
  48. } // end compute namespace
  49. } // end boost namespace
  50. #endif // BOOST_COMPUTE_CONTAINER_DETAIL_SCALAR_HPP