Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PC_DEVICE_PARALLEL_SCATTERED_VECTOR_HPP
- #define PC_DEVICE_PARALLEL_SCATTERED_VECTOR_HPP
- #include "pc/defines.hpp"
- #include <iostream>
- #include <boost/shared_ptr.hpp>
- #include "pc/misc/vector_traits.hpp"
- #include "pc/device/all_devices.hpp"
- using namespace pc::misc;
- using namespace pc::device;
- namespace pc { namespace device { namespace parallel
- {
- template <class VectorType>
- struct GPUProxyVector
- {
- typedef VectorType vector_type;
- typedef boost::shared_ptr<vector_type> vector_ptr_type;
- typedef pc::misc::VectorTraits<vector_type> vector_traits_type;
- typedef typename vector_traits_type::value_type value_type;
- typedef pc::device::WorkerManager<GPU> workers_type;
- typedef boost::shared_ptr<workers_type> workers_ptr_type;
- protected:
- private:
- workers_ptr_type workers_;
- DEVICE_MEMOREIS(value_type, GPU) values_;
- };
- template <class HType, class DType>
- struct ScatteredBase
- {
- typedef HType h_type;
- typedef boost::shared_ptr<h_type> h_ptr_type;
- typedef DType d_type;
- typedef boost::shared_ptr<d_type> d_ptr_type;
- typedef pc::device::WorkerManager<GPU> workers_type;
- typedef boost::shared_ptr<workers_type> workers_ptr_type;
- ScatteredBase()
- : hDirty_(false)
- , dDirty_(false)
- {
- }
- ScatteredBase(const h_ptr_type & h)
- : h_(h)
- , hDirty_(true)
- , dDirty_(false)
- {
- }
- const h_type & constGet() const
- {
- #ifdef PARALLEL_DEBUG
- std::cout << ">> constGet()" << std::endl;
- #endif
- return *h_;
- }
- h_type & get()
- {
- #ifdef PARALLEL_DEBUG
- std::cout << ">> get()" << std::endl;
- #endif
- return *h_;
- }
- const d_type & constGetDeviceProxy() const
- {
- #ifdef PARALLEL_DEBUG
- std::cout << ">> constGetDeviceProxy()" << std::endl;
- #endif
- return *d_;
- }
- d_type & getDeviceProxy()
- {
- #ifdef PARALLEL_DEBUG
- std::cout << ">> getDeviceProxy()" << std::endl;
- #endif
- return *d_;
- }
- protected:
- void setH(const h_ptr_type & h)
- {
- h_ = h;
- hDirty_ = true;
- }
- void sync(bool isConstAccess)
- {
- ASSERT(!(hDirty_ && dDirty_), "both is dirty, lost!");
- if (!hDirty_ && !dDirty_) return;
- if (hDirty_)
- {
- ASSERT(h_, "invalid h, but h is set to dirty");
- // send to workers...
- hDirty_ = !isConstAccess;
- void sync(bool isConstAccess)
- {
- #ifdef HAVE_GPU
- // user WorkerManager<GPU> to copy to and from device
- // workers->scatter
- ASSERT(!(hDirty_ && dDirty_), "error");
- if(!hDirty_ && !dDirty_) return;
- if(hDirty)
- {
- workers->recv...;
- hDirty_ = !isConstAccess;
- }
- if(dDirty_)
- {
- workers->send...;
- dDirty_ = !isConstAccess;
- }
- #endif
- }
- private:
- bool hDirty_;
- bool dDirty_;
- h_ptr_type h_;
- d_ptr_type d_;
- workers_ptr_type workers_;
- };
- template <class HType>
- struct ScatteredVector : public ScatteredBase<HType>
- {
- typedef HType vector_type;
- typedef boost::shared_ptr<vector_type> vector_ptr_type;
- typedef pc::misc::VectorTraits<vector_type> vector_traits_type;
- typedef typename vector_traits_type::value_type value_type;
- /*!
- @brief C'tor for host only
- */
- ScatteredVector(unsigned int length)
- {
- set_h(traits_type::makePtr(length));
- }
- /*!
- @brief C'tor for host only
- */
- ScatteredVector(const vector_ptr_type & v)
- : ScatteredBase(v)
- {
- }
- };
- }}} // namespaces
- #endif
Add Comment
Please, Sign In to add comment