Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:01

0001 // Boost.uBLAS
0002 //
0003 // Copyright (c) 2018 Fady Essam
0004 // Copyright (c) 2018 Stefan Seefeld
0005 //
0006 // Distributed under the Boost Software License, Version 1.0.
0007 // (See accompanying file LICENSE_1_0.txt or
0008 // copy at http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #ifndef boost_numeric_ublas_opencl_vector_hpp_
0011 #define boost_numeric_ublas_opencl_vector_hpp_
0012 
0013 #include <boost/numeric/ublas/opencl/library.hpp>
0014 #include <boost/numeric/ublas/functional.hpp>
0015 #include <boost/compute/core.hpp>
0016 #include <boost/compute/algorithm.hpp>
0017 #include <boost/compute/buffer.hpp>
0018 #include <boost/compute/container/vector.hpp>
0019 
0020 namespace boost { namespace numeric { namespace ublas { namespace opencl {
0021 
0022 class storage;
0023 
0024 namespace compute = boost::compute;
0025 
0026 } // namespace opencl
0027 
0028 template <class T>
0029 class vector<T, opencl::storage> : public boost::compute::vector<T>
0030 {
0031   typedef std::size_t size_type;
0032 public:
0033   vector() : compute::vector<T>() {}
0034   vector(size_type size, compute::context context)
0035     : compute::vector<T>(size, context)
0036   { device_ = context.get_device();}
0037   vector(size_type size, T value, compute::command_queue queue)
0038     : compute::vector<T>(size, value, queue.get_context())
0039   {
0040     queue.finish();
0041     device_ = queue.get_device();
0042   }
0043 
0044   template <typename A>
0045   vector(vector<T, A> const &v, compute::command_queue &queue)
0046     : vector(v.size(), queue.get_context())
0047   {
0048     this->from_host(v, queue);
0049   }
0050   
0051 
0052   const compute::device device() const { return device_;}
0053   compute::device device() { return device_;}
0054 
0055   template<class A>
0056   void from_host(ublas::vector<T, A> const &v, compute::command_queue & queue)
0057   {
0058     assert(this->device() == queue.get_device());
0059     compute::copy(v.begin(),
0060           v.end(),
0061           this->begin(),
0062           queue);
0063     queue.finish();
0064   }
0065 
0066   template<class A>
0067   void to_host(ublas::vector<T, A>& v, compute::command_queue& queue) const
0068   {
0069     assert(this->device() == queue.get_device());
0070     compute::copy(this->begin(),
0071           this->end(),
0072           v.begin(),
0073           queue);
0074     queue.finish();
0075   }
0076 
0077   void fill(T value, compute::command_queue & queue)
0078   {
0079     assert(this->device() == queue.get_device());
0080     compute::fill(this->begin(), this->end(), value, queue);
0081     queue.finish();
0082   }
0083 
0084 private:
0085   compute::device device_;
0086 };
0087 
0088 }}}
0089 
0090 #endif